Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ jobs:
- run: npm run build
- run: npm test

- name: Generated code for the synthetic fixture compiles (TypeScript and Python)
# tests/fixtures/coverage/kitchen-sink.yaml exercises every template: nested bodies, all parameter
# kinds, error responses, scenarios. Generated, never run (no server), but it must compile.
run: |
npx tsx src/cli.ts generate tests/fixtures/coverage/kitchen-sink.yaml --deps tests/fixtures/coverage/kitchen-sink.deps.json --tests-dir tests/api-ks --max-cases 500 -o reports/ks --fail-on never
npx tsc --noEmit
npx tsx src/cli.ts generate tests/fixtures/coverage/kitchen-sink.yaml --deps tests/fixtures/coverage/kitchen-sink.deps.json --tests-dir tests/api-ks-python --lang python --max-cases 500 -o reports/ks-python --fail-on never
python -m py_compile $(find tests/api-ks-python -name '*.py')
npx tsx src/cli.ts registry validate tests/api-ks/_support/cases.json --spec tests/fixtures/coverage/kitchen-sink.yaml --require-spec > /dev/null
# TypeScript / Python parity on every template: the same active cases.
node -e '
const active = (f) => Object.entries(require(f).cases).filter(([, c]) => c.status !== "retired").map(([id]) => id).sort();
const ts = active("./tests/api-ks/_support/cases.json"), py = active("./tests/api-ks-python/_support/cases.json");
console.log("kitchen sink cases:", ts.length, "TypeScript /", py.length, "Python");
if (JSON.stringify(ts) !== JSON.stringify(py)) process.exit(1);
'
rm -rf tests/api-ks tests/api-ks-python

- name: Start demo API
run: |
nohup npm run demo > demo-api.log 2>&1 &
Expand All @@ -53,7 +71,7 @@ jobs:
'

- name: Generate tests (resource/method/functional|contract|scenarios) and run them once
run: npx tsx src/cli.ts generate demo-api/openapi.yaml -u http://localhost:3100 --allow-write --run -o reports/generate --fail-on never
run: npx tsx src/cli.ts generate demo-api/openapi.yaml -u http://localhost:3100 --scenarios demo-api/scenarios.json --allow-write --run -o reports/generate --fail-on never

- name: Self-check - generated suite fails only on the known defect
run: |
Expand All @@ -65,17 +83,44 @@ jobs:
if (JSON.stringify(bad) !== JSON.stringify(["stats/get/contract"]) || passed < 10) process.exit(1);
'

- name: Self-check - every physical test has its own registered case ID; registry and manifest are valid
run: |
node -e '
const c = require("./reports/generate/report.json").generated.caseIdCheck;
console.log(JSON.stringify(c));
if (!c || c.tests < 10 || c.missing.length || c.duplicates.length || c.unregistered.length) process.exit(1);
'
npx tsx src/cli.ts registry validate tests/api/_support/cases.json --spec demo-api/openapi.yaml --require-spec > /dev/null
npx tsx src/cli.ts manifest validate --tests-dir tests/api
# Coverage gaps are exactly the expected ones: a new gap or a silently vanished one fails.
node -e '
const got = require("./reports/generate/coverage-gaps.json").summary.gapsByCode;
const want = require("./demo-api/expected-gaps.json");
console.log("coverage gaps:", JSON.stringify(got));
if (JSON.stringify(got) !== JSON.stringify(want)) { console.log("expected:", JSON.stringify(want)); process.exit(1); }
'

- name: Generate Python tests (pytest + requests) and run them once
run: |
pip install pytest requests jsonschema
npx tsx src/cli.ts generate demo-api/openapi.yaml -u http://localhost:3100 --allow-write --run --lang python --tests-dir tests/api-python -o reports/generate-python --fail-on never
npx tsx src/cli.ts generate demo-api/openapi.yaml -u http://localhost:3100 --scenarios demo-api/scenarios.json --allow-write --run --lang python --tests-dir tests/api-python -o reports/generate-python --fail-on never
node -e '
const r = require("./reports/generate-python/report.json");
const bad = r.generated.scenarios.filter(s => s.status === "CONTRACT_MISMATCH" || s.status === "TEST_FAILURE").map(s => s.name);
const passed = r.generated.scenarios.filter(s => s.status === "PASS").length;
console.log("failing:", bad, "passed:", passed);
if (JSON.stringify(bad) !== JSON.stringify(["stats/get/contract"]) || passed < 10) process.exit(1);
const c = r.generated.caseIdCheck;
console.log(JSON.stringify(c));
if (!c || c.tests < 10 || c.missing.length || c.duplicates.length || c.unregistered.length) process.exit(1);
// TypeScript and Python generate the same active cases (retired ones are history).
const active = (f) => Object.entries(require(f).cases).filter(([, c]) => c.status !== "retired").map(([id]) => id).sort();
const ts = active("./tests/api/_support/cases.json");
const py = active("./tests/api-python/_support/cases.json");
if (JSON.stringify(ts) !== JSON.stringify(py)) { console.log("TS/Python case sets differ"); process.exit(1); }
'
npx tsx src/cli.ts registry validate tests/api-python/_support/cases.json --spec demo-api/openapi.yaml --require-spec > /dev/null
npx tsx src/cli.ts manifest validate --tests-dir tests/api-python

- name: Analyse the legacy example project (init + run)
working-directory: examples/legacy-project
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Unreleased

- **Coverage completeness** (see docs/SUPPORT_MATRIX.md):
- one physical test → one stable case ID (vocabulary v2: `accepted-value`, `invalid-credentials`, `method-not-allowed`, `precondition-failed`), checked on the real run (Playwright report, pytest collection); cases no longer generated become tombstones;
- recursive request-body negative cases at any depth, exactly one broken rule each (verified with ajv), configurable limit `--max-cases` with dropped cases reported;
- query / header / cookie / path parameter cases, array serialization by style / explode, required header / cookie parameters sent in every call;
- stricter response contract in TypeScript and Python alike: headers, no body for 204 / 205 / 304 / HEAD / no content, empty body, text schemas, writeOnly; what is not checked is said;
- documented errors with safe triggers: 401 invalid credentials, 405, 409 (deps `conflictOn`), 412, 415; 403 / 429 / others as gaps;
- boundary-valid query values, deps `echoes`, sampler fixes (multipleOf, exclusive bounds, uniqueItems), uncovered oneOf / anyOf branches reported;
- reviewed business scenarios (`--scenarios`, `scenarios validate`, schemas/scenarios.schema.json) and repeated delete;
- `coverage-gaps.json`: summary by machine code, per-suite status, unchecked statuses / request media types / security alternatives;
- CI: case-ID checks, registry and manifest validation, TypeScript / Python parity, the synthetic fixture must compile, expected coverage gaps.
- **Stable case IDs** (step 3 of docs/OPENAPI_CHANGE_TRIGGER.md, core): every generated test carries `ata:<subject>:<suite>:<polarity>:<location>:<rule>` (Playwright annotation `caseId`, pytest marker `api_case_id`). `generate` writes `_support/cases.json` (operations, cases, CRUD scenario definitions; existing UIDs kept, removed operations retired, never rebuilt), `_support/generation-manifest.json` (file ownership and canonical hashes, written last) and `_support/openapi.snapshot.meta.json`, which makes the snapshot a `diff` baseline. New `registry validate [path] [--spec] [--require-spec]` and `manifest validate`. Case ID encoding / parsing and the rule vocabulary v1 with its allowed combinations follow the design.
- **`diff`: semantic diff of two OpenAPI specs** (step 1 of docs/OPENAPI_CHANGE_TRIGGER.md). Writes `changes.json` (schema in `schemas/changes.schema.json`) and, with `--format markdown`, `changes.md`: operations added / removed / moved (rename detection with the documented thresholds; uncertain links marked `review`), `operationId` and path parameter renames, parameter, request and response changes, schema constraint changes per facet and direction, example / default changes, servers. Deterministic `operationUid` per operation. Formatting, descriptions, `$ref` layout, equivalent `allOf` and 3.0 ↔ 3.1 nullable give no changes. Compatibility verdicts come from oasdiff `1.34.1` (`OASDIFF_BIN` or `PATH`, not bundled; version pinned). Baseline: `--base`, else the Git merge base; otherwise `BLOCKED: BASE_SPEC_MISSING`. URLs need `--allow-network`; private and metadata hosts are denied unless allowed. Exit codes 0 / 1 (`--fail-on breaking | blocked | unknown`, repeatable, default `blocked`) / 2 (configuration).
- **A failed create check no longer leaves data:** the resource helper's `create()` removes the record before failing when a check after the request fails (e.g. the API answers an undocumented `201` where the spec says `200`). Before, the test failed before cleanup was registered, and the record stayed (found on Toolshop favorites).
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ Generated files are overwritten when the spec changes; put hand-written cases in

`generate --draft-pr` commits the tests and the report on a new branch and opens a GitHub Draft PR. It never pushes to the default branch or merges.

## What is covered, and what is not

Coverage is reported, never implied. The full keyword-by-keyword table is in [docs/SUPPORT_MATRIX.md](docs/SUPPORT_MATRIX.md); every check that could not be generated is in `coverage-gaps.json` with a machine code and its exact location.

**Derived from the spec alone (deterministic):**
- request bodies, recursively (`request.body#/items/*/sku`): required, type, null, enum, const, lengths, pattern, format, bounds, multipleOf, array and object size, uniqueItems, additionalProperties; one broken rule per case;
- query, header, cookie and path parameters, arrays in their documented style;
- documented successes, documented enum values and valid limits of query parameters (one test and one case ID each);
- responses: status, Content-Type, headers, JSON / text schema, no body where none is documented, writeOnly;
- documented errors with a safe trigger: 400 / 422, 401 (missing and invalid credentials), 404, 405 (GET only), 412, 415.

**Needs your confirmation (deps or scenarios file):** CRUD chains and cleanup, 409 conflicts (`conflictOn`), fields a create returns as sent (`echoes`), values taken from existing data (`fill`), and every business flow (`--scenarios`): state transitions, parent → child, login / refresh, list / search / pagination.

**Never generated (reported as gaps):** 403 without a reviewed role setup, 429, a 405 that would need an unsafe method, oneOf / anyOf branches other than the one sent, rules that cannot be broken without breaking another, media types other than JSON / text, and anything the spec does not state.

## Options

| Option | Default | |
Expand Down
5 changes: 5 additions & 0 deletions demo-api/expected-gaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MISSING_CLEANUP": 2,
"MISSING_RESOURCE_SOURCE": 1,
"MISSING_RESPONSE_SCHEMA": 1
}
27 changes: 27 additions & 0 deletions demo-api/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"scenarios": [
{
"id": "items.read-created",
"title": "an item that was just created can be read by its id",
"polarity": "positive",
"primary": "read",
"steps": [
{ "name": "create", "operationId": "createItem", "phase": "setup", "body": { "name": "Scenario item", "price": 5, "tags": ["scenario"] }, "expect": "201", "save": { "itemId": "/id" } },
{ "name": "read", "operationId": "getItem", "phase": "action", "params": { "itemId": "{itemId}" }, "expect": "200" },
{ "operationId": "deleteItem", "phase": "cleanup", "params": { "itemId": "{itemId}" } }
]
},
{
"id": "items.gone-after-delete",
"title": "an item that was deleted cannot be read any more",
"polarity": "negative",
"primary": "read",
"steps": [
{ "name": "create", "operationId": "createItem", "phase": "setup", "body": { "name": "Scenario item", "price": 5 }, "expect": "201", "save": { "itemId": "/id" } },
{ "name": "delete", "operationId": "deleteItem", "phase": "setup", "params": { "itemId": "{itemId}" }, "expect": "204" },
{ "name": "read", "operationId": "getItem", "phase": "action", "params": { "itemId": "{itemId}" }, "expect": "404" },
{ "operationId": "deleteItem", "phase": "cleanup", "params": { "itemId": "{itemId}" } }
]
}
]
}
Loading
Loading