Public: anyone can read this; the crew can change it.

Every /api/v1 answer the suite reads is checked against openapi.json, not onl… #17961

Closed opened this

Picked up by mason; no pull came of it (failed) · 10+ runs · run

opened this

Every /api/v1 answer the suite reads is checked against openapi.json, not only the pull detail

#17944 asked for a contract test "run over the route samples the tests already produce". #17945 added the checker (test/support/conforms.ts) and calls it from one test, test/approval-base.test.ts, so a silent type change on any other route (issues, comments, lists, /user/repos) still ships green and breaks the iOS app the same way approvedAt did.

Change, in the suite's existing preload (test/helpers/preload.ts, which bunfig.toml loads for every bun test):

  1. Build the document once, lazily: openapi("https://forge.test", "test", "admin") (src/contract/openapi.ts), and from its paths a list of { method, regex, literals } where each {param} becomes [^/]+, anchored ^…$, and literals counts the segments without a param.
  2. Wrap globalThis.fetch (only under bun test, like the afterEach #17354 guards). After the real fetch: if the request method is GET, the URL's pathname starts with /api/v1/, the status is 200 and the content-type is application/json, match the pathname (no query) against the list; on several matches take the one with the most literal segments (so /issues/search beats /issues/{number}). If the route declares a 200 application/json schema, run disagreements(await res.clone().json(), schema, doc). Skip silently when no route matches or none is declared.
  3. When the list is not empty, throw Error(\GET ${pathname} disagrees with openapi.json (#17944): ${list.join("; ")}\) so the test that read it goes red, naming the field.

Before turning step 3 on: run the full suite once with step 3 only collecting, and fix every disagreement it lists in the schema (src/contract/openapi/schemas/*), declaring the type the route already serves, since that is what clients decode today. Never change a served type to satisfy the schema. Add any bend found to "Known bends" in docs/features/api-shape-changes.md. Then turn the throw on, and change that page's sentence "A route's tests add the same check as they gain samples" to say every API answer a test reads is checked.

Test: test/support/conforms.test.ts gains a case that starts a forgeHttp server whose GET /api/v1/repos/{o}/{n}/pulls/{n} answer has approvedAt as an object, and expects the wrapped fetch to reject with "$.approvedAt: is object, declared string|null". It fails without the preload change. The explicit check in approval-base.test.ts can stay.

No change to production code or to any served shape.

4 earlier comments · 2 events
commented

For the test, a stub is simpler than a real forge: Bun.serve({ port: 0, fetch: () => Response.json({ ...a valid PullDetail sample..., approvedAt: { at: "x" } }) }), then await expect(fetch(\${url}/api/v1/repos/a/b/pulls/1\)).rejects.toThrow("$.approvedAt: is object, declared string|null"). A valid sample answer must pass through untouched in the same test, so the wrapper is shown not to fire on a conforming answer.

the crew's run was interrupted: provider limit, resumes 22:23 UTC — every subscription this repository may use is resting (API Error: 402 This request requires more credits, or fewer max_tokens. You requested up to 128000 tokens, but can only afford 4000. To increase, visit https://)
the crew's run was interrupted: provider limit, resumes 23:54 UTC — every subscription this repository may use is resting (API Error: 402 This request requires more credits, or fewer max_tokens. You requested up to 128000 tokens, but can only afford 4000. To increase, visit https://)
commented

The collecting run of the full suite is still going in the background, so step 3's throw is not on yet. Nothing is committed or pushed.

What exists in the clone:

  • Wrapper: test/helpers/contract-fetch.ts wraps fetch, and the preload loads it only under bun test. With FORGE_CONTRACT_COLLECT set it prints disagreements as CONTRACT … lines instead of throwing.
  • Tests: test/support/conforms.test.ts has two new cases. One expects the wrapped fetch to reject with $.approvedAt: is object, declared string|null. The other shows a conforming sample, an undeclared route and a non-API path passing untouched. The file passes (3 tests).
  • Doc: the sentence in docs/features/api-shape-changes.md is reworded to say every API answer a test reads is checked.

Still to do once the suite finishes:

  1. Fix each listed disagreement in src/contract/openapi/schemas/*, declaring the type the route already serves.
  2. Add any bends found to "Known bends".
  3. Turn the throw on by dropping the FORGE_CONTRACT_COLLECT branch.
  4. Run bun scripts/gate.ts --explain and --fix, bun x tsc --noEmit and the suites that cover the change, then commit and push.
commented

Parked by the crew: the run ended without a pull: no changes pushed: The collecting run of the full suite is still going in the background, so step 3's throw is not on yet. Nothing is committed or pushed.

commented

Parked by the crew: the run ended without a pull: no changes pushed (timeout)

Parked twice since a person last spoke here, so it is the planner's now. Every reason:

  1. the run ended without a pull: no changes pushed: The collecting run of the full suite is still going in the background, so step 3's throw is not on yet. Nothing is committed or pushed
  2. the run ended without a pull: no changes pushed (timeout)

The planner splits it, replaces it with a fresh issue, or defers it; a person can also say what to try. Nothing starts here until then, and the board lists it.

commented

Split: both runs stalled waiting on one background full-suite collecting run. Now four pieces, none needing a full-suite run: #17985 the wrapper in collect mode with its test, #17986 schema fixes for test/api-*, #17987 schema fixes for the other files that read /api/v1, #17988 turn the throw on and update the doc. scout's clone notes above describe #17985 almost exactly.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs