跳到正文
cccskills
免费在 GitHub 公开

pact-contract-testing

Authors and verifies Pact consumer-driven contract tests across the full Pact lifecycle - consumer tests producing pact files, publishing to the Pact Broker, provider verification, and `can-i-deploy` deployment gates. Use when introducing a new HTTP/JSON API contract between two services, diagnosing breaking changes, or wiring contract verification into CI.

中文简介正在准备中。当前显示原文说明。

testland/qa星标 13(GitHub 13 + cccskills 0)

实测评分 未实测

查看安装方法

包含的文件(13)

  • SKILL.md7.9 KB
  • .tessl-plugin/plugin.json496 B
  • evals/broker-has-the-pact-but-every-row-says-unknown/criteria.json7.5 KB
  • evals/broker-has-the-pact-but-every-row-says-unknown/task.md13.7 KB
  • evals/deploy-gate-blocks-a-hotfix-on-an-unchanged-service/criteria.json6.7 KB
  • evals/deploy-gate-blocks-a-hotfix-on-an-unchanged-service/task.md11.9 KB
  • evals/provider-seed-change-turned-the-contract-red/criteria.json6.7 KB
  • evals/provider-seed-change-turned-the-contract-red/task.md15.6 KB
  • evals/provider-team-offers-to-write-everyones-pacts/criteria.json7.6 KB
  • evals/provider-team-offers-to-write-everyones-pacts/task.md13.5 KB
  • evals/two-integrations-one-ticket-one-vendor-wont-verify/criteria.json6.6 KB
  • evals/two-integrations-one-ticket-one-vendor-wont-verify/task.md12.1 KB
  • references/ci-pipelines.md1.7 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

pact-contract-testing

Overview

Pact is a code-first tool for consumer-driven contract tests over HTTP and message integrations (pact-overview). The contract is a side-effect of the consumer's tests - each test documents one request/response pair, and only the parts the consumer actually uses get tested.

The lifecycle has five steps (pact-how-it-works):

  1. Consumer test runs against a Pact mock server using the Pact DSL.
  2. The framework writes a pact file (JSON) capturing every given() → uponReceiving() → withRequest() → willRespondWith() interaction.
  3. The pact file is published to the Pact Broker.
  4. The provider verifies the pact: each recorded request is replayed against the running provider and responses are checked against the contract.
  5. can-i-deploy queries the Broker matrix to confirm the candidate version has a green verification against every consumer/provider already deployed in the target environment (can-i-deploy).

When to use

  • Two or more services communicate over HTTP/JSON or a message bus.
  • The team owns both consumer and provider - Pact requires provider buy-in for verification.
  • You want a safety net richer than schema comparison: contract-by-example asserts what consumers actually use, not the full provider surface.
  • The repo already imports @pact-foundation/pact, pact-jvm-consumer, pact-python, etc., or a .pact/ directory is present.

If the API has no consumers under your control (public or third-party APIs), prefer openapi-contract-diff - schema diffs need no consumer coordination.

Authoring (consumer side)

Install (Node example)

npm install --save-dev @pact-foundation/pact

(Per pact-js.)

Consumer test with PactV3

const { PactV3, MatchersV3 } = require('@pact-foundation/pact');
const { like, eachLike } = MatchersV3;

const provider = new PactV3({
  consumer: 'web-app',
  provider: 'pet-service',
  dir: path.resolve(process.cwd(), 'pacts'),
});

describe('Pet Service consumer', () => {
  it('returns a list of dogs', async () => {
    provider
      .given('I have a list of dogs')
      .uponReceiving('a request for all dogs with the builder pattern')
      .withRequest({
        method: 'GET',
        path: '/dogs',
        headers: { Accept: 'application/json' },
      })
      .willRespondWith({
        status: 200,
        headers: { 'Content-Type': 'application/json' },
        body: eachLike({
          id: like(1),
          name: like('Rex'),
        }),
      });

    await provider.executeTest(async (mockServer) => {
      const response = await fetch(`${mockServer.url}/dogs`);
      expect(response.status).toBe(200);
    });
  });
});

(Adapted from pact-js.)

given() describes a provider state the verifier sets up later. Matchers like like() and eachLike() assert type/shape rather than exact values, so the provider isn't bound to fixture-specific data.

Where pact files are written

By default, PactV3 writes pact files to ./pacts/ relative to the process CWD (pact-js). Each consumer/provider pair produces one JSON file: <consumer>-<provider>.json.

Publishing to the Pact Broker

The Broker is the central registry for pact files and verification results. Publishing happens after the consumer tests pass:

npx pact-broker publish ./pacts \
  --consumer-app-version=$(git rev-parse HEAD) \
  --branch=$(git rev-parse --abbrev-ref HEAD) \
  --broker-base-url=$PACT_BROKER_BASE_URL \
  --broker-token=$PACT_BROKER_TOKEN

The Broker stores (overview):

  • The pact files themselves.
  • Provider verification results per consumer version.
  • Tags and branches that map app versions to lifecycle environments (e.g. production, staging, main).

Tagging by branch + the Git SHA as consumer-app-version is the canonical pattern - can-i-deploy queries the matrix using these identifiers.

Provider verification

const { Verifier } = require('@pact-foundation/pact');

new Verifier({
  providerBaseUrl: 'http://localhost:8081',
  pactBrokerUrl: process.env.PACT_BROKER_BASE_URL,
  pactBrokerToken: process.env.PACT_BROKER_TOKEN,
  provider: 'pet-service',
  providerVersion: process.env.GIT_SHA,
  providerVersionBranch: process.env.GIT_BRANCH,
  publishVerificationResult: true,
  consumerVersionSelectors: [
    { mainBranch: true },
    { deployedOrReleased: true },
  ],
}).verifyProvider();

(Adapted from pact-js.)

consumerVersionSelectors controls which consumer pacts get verified - mainBranch plus deployedOrReleased keeps the provider compatible with both the latest consumer work and what's in production (pact-how-it-works). publishVerificationResult: true is what updates the matrix - without it the broker has no record of this provider version's verification status.

Provider states

For each consumer interaction with a given(<state>), the provider test setup must register a hook that puts the system into that state before replay. Using Express:

new Verifier({
  ...
  stateHandlers: {
    'I have a list of dogs': async () => {
      await db.dogs.bulkInsert([{ id: 1, name: 'Rex' }]);
      return { description: 'dogs seeded' };
    },
  },
}).verifyProvider();

State setup that fails causes the matching interaction to fail verification.

can-i-deploy - deployment gate

Per can-i-deploy:

pact-broker can-i-deploy \
  --pacticipant pet-service \
  --version $(git rev-parse HEAD) \
  --to-environment production
FlagRequiredEffect
--pacticipantyesApplication (consumer or provider) name.
--versionyesApp version string (typically the Git SHA).
--to-environmentoptionalTarget environment to check against. Omit to check against latest.

Exit codes (can-i-deploy):

  • 0 - "Computer says yes \o/" - safe to deploy.
  • 1 - "Computer says no" - at least one matrix cell is missing or failed.

The output includes a markdown-style matrix of consumer/provider version pairs with verification status and links to detailed verification results.

Recording deployments

After deploying, record the deployment so subsequent can-i-deploy queries see the new "currently deployed" baseline:

pact-broker record-deployment \
  --pacticipant pet-service \
  --version $(git rev-parse HEAD) \
  --environment production

Skipping this step is the most common reason can-i-deploy returns spurious "no" verdicts.

CI integration

Wire publish -> verify -> can-i-deploy into the pipeline for both sides. Full consumer and provider GitHub Actions steps are in references/ci-pipelines.md.

can-i-deploy is the actual gate - pact verification happens in step 1, but a green verification alone doesn't prove every paired version is compatible.

References

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Builds a CI gate that fails the build on **new** WCAG / a11y violations introduced by a PR while grandfathering pre-existing violations on a per-rule / per-page baseline. Aggregates verdicts from axe-core / pa11y / Lighthouse a11y / WAVE / IBM Equal Access scans. Use when a project has accumulated a11y debt and a strict "zero violations" gate would block every PR - the ratchet pattern lets the team ship while preventing regressions.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Workflow skill that builds an A/B-test validity checklist from an experiment proposal, walking the canonical design-correctness gates - pre-registered OEC/power/guardrails, randomization unit + SRM check, assignment integrity, telemetry, peeking discipline, novelty/primacy, post-experiment SRM re-check - into a per-experiment checklist + sign-off form. Use when launching, auditing, or governing an experiment. For pitfall mechanics (guardrails, peeking) see experiment-results-interpreter's references; to read an already-valid result use experiment-results-interpreter; for per-SDK harness tests use experiment-sdk-testing - this gates DESIGN, not SDK code.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

The single install-flow skill: the reference contract for the PWA install flow (installability gate fields, `beforeinstallprompt` handshake, per-platform paths - Android WebAPK / iOS Share menu / Firefox no-op - and the `display-mode` post-install signal, in references/install-flow-reference.md) plus the build-an-X workflow that emits the Add-to-Home-Screen suite. Walks the four-stage timeline, emitting one test per gate cell per [web.dev/articles/install-criteria][install-criteria], the deferred-prompt → `prompt()` → `userChoice` chain per [web.dev/articles/customize-install][customize-install], the iOS Safari manual-metadata branch (`apple-touch-icon`) per [web.dev/learn/pwa/installation][learn-pwa], and the post-install `(display-mode: standalone)` MQ assertion. Output: a Playwright spec with per-stage cells plus a coverage matrix. Use when a PWA's manifest, icons, or install handler change, when install conversion drops at an unknown stage, or when triaging a flaky install assertion.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Build-an-X workflow that uses an LLM to map existing tests to spec sections - given a spec doc + the test suite, the LLM identifies which tests cover which sections, surfaces uncovered sections (gap), and recommends specific tests to add. Output is a coverage matrix per spec ID. Scope is mapping tests that already exist and naming the gaps, not authoring tests for new acceptance criteria. Use when a spec doc and a test suite both exist but nobody can say which requirements are actually covered - before a release sign-off, an audit, or a decision about where to spend the next round of test effort.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Generates tests from natural-language specs (acceptance criteria, user stories, requirements) using an LLM, with confidence scoring per test case (LLM self-assessment plus heuristics: assertion quality, naming, completeness), batching uncertain cases for human review, and integration with the team's existing test framework. Use when the user asks to generate unit tests from acceptance criteria, convert user stories to test cases, automate test creation from requirements, or augment a spec-driven test suite with AI-generated stubs that are then curated before merge.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Configures Allure Report (test-runner adapter install, `allure-results` directory wiring, `categories.json` for failure classification, `history-trend.json` retention via the copy-history-between-runs pattern), runs the Allure CLI to convert `allure-results` to a static HTML site, and uploads the report as a CI artifact. Use when the team needs richer test reporting than JUnit XML - step-level attachments, per-test history, retry tracking, and severity / epic / feature labeling across framework-agnostic adapters (pytest, Jest, JUnit, TestNG, NUnit, Mocha). As a rich static HTML report generator, it is the open-source alternative to the sunset ExtentReports (JVM/.NET per-test HTML narrative); for hosted cross-run flakiness analytics rather than a static per-run report use currents-integration.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

查看 testland 的全部技能

报告此技能的问题