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

The test files outside api-* read no answer that disagrees with openapi.json #18001

opened this

Merged 14h 44m ago, live in production

The suite's contract check now only checks /api/v1 answers that this forge's own server wrote. Answers from stub servers inside the tests are no longer checked. All 1037 test files outside api- that read /api/v1/ now print no CONTRACT line.

Notes

opened this

The suite's contract check now only checks /api/v1 answers that this forge's own server wrote. Answers from stub servers inside the tests are no longer checked. All 1037 test files outside api-* that read /api/v1/ now print no CONTRACT line.

What the 430 lines were. None came from a route in this forge. They came from stub servers in the tests that answer under the same /api/v1/ prefix:

  • Fake Forgejo origins (origins*, fork-flow, propose-via-fork, view-source and others): their GET /api/v1/repos/{o}/{r} answers an integer id, and their /api/v1/repos/issues/search answers a bare array.
  • Minimal stub pull and review bodies (cli-pulls, cli-ship, mirror-pulls, thanks, origin-verdicts-counted, talk-bring).

Declaring those shapes in openapi.json would describe some other forge, not this one. So no schema changes, no served type changes, and nothing goes under "Known bends" in docs/features/api-shape-changes.md.

What changed.

  • test/helpers/contract-fetch.ts: before checking an answer, the wrapper looks for two headers that only securityFloor (src/http/respond.ts) sets: permissions-policy and cross-origin-opener-policy. Every answer this forge writes carries them; a test's Response.json stub doesn't. An answer without them is passed through unchecked.
  • test/support/conforms.test.ts: the wrapper's own test server now sends its answers through securityFloor, as the forge does. That test changed because the behaviour it tests changed. A new test adds a second stub with no floor headers and checks that its wrong-typed answer is not checked. It fails if the new check is removed.
  • No new function looks like an existing one: the gate's "duplicate functions" rule passes. I didn't run scripts/similar.ts separately.

To confirm real answers are still checked, I temporarily declared /api/v1/search's moreCode as a string. test/search.test.ts then printed 37 CONTRACT lines, and I reverted the change.

Before → after, CONTRACT lines per batch of 50 files:

batch000102030405060708091011121314151617181920
before00659243450003612934780231109
after000000000000000000000

Batches are the sorted output of grep -rl /api/v1/ test/ --include=*.test.ts | grep -v ^test/api-, cut every 50 lines.

Not done here: one test, test/mcp/forks.test.ts ("the private fork's owner sees it, with its parent named"), fails the same way on the base without this change. The MCP answer now has a words field that the test's expected value doesn't list, so I left it alone.

To try it: run bun test test/support/conforms.test.ts. Then run bun test on any batch above (for example test/view-source.test.ts test/fork-flow.test.ts) and grep ^CONTRACT the output: it finds nothing.

Checks run: bun scripts/gate.ts --explain (32 of 32 rules pass), bun x tsc --noEmit, and the 155 files scripts/fast.ts names, in three batches, all passing.

🤖 Generated with Claude Code

Closes #17987

commented

The suite's contract check now only checks /api/v1 answers that this forge's own server wrote. Answers from stub servers inside the tests are no longer checked. All 1037 test files outside api-* that read /api/v1/ now print no CONTRACT line.

What the 430 lines were. None came from a route in this forge. They came from stub servers in the tests that answer under the same /api/v1/ prefix:

  • Fake Forgejo origins (origins*, fork-flow, propose-via-fork, view-source and others): their GET /api/v1/repos/{o}/{r} answers an integer id, and their /api/v1/repos/issues/search answers a bare array.
  • Minimal stub pull and review bodies (cli-pulls, cli-ship, mirror-pulls, thanks, origin-verdicts-counted, talk-bring).

Declaring those shapes in openapi.json would describe some other forge, not this one. So no schema changes, no served type changes, and nothing goes under "Known bends" in docs/features/api-shape-changes.md.

What changed.

  • test/helpers/contract-fetch.ts: before checking an answer, the wrapper looks for two headers that only securityFloor (src/http/respond.ts) sets: permissions-policy and cross-origin-opener-policy. Every answer this forge writes carries them; a test's Response.json stub doesn't. An answer without them is passed through unchecked.
  • test/support/conforms.test.ts: the wrapper's own test server now sends its answers through securityFloor, as the forge does. That test changed because the behaviour it tests changed. A new test adds a second stub with no floor headers and checks that its wrong-typed answer is not checked. It fails if the new check is removed.
  • No new function looks like an existing one: the gate's "duplicate functions" rule passes. I didn't run scripts/similar.ts separately.

To confirm real answers are still checked, I temporarily declared /api/v1/search's moreCode as a string. test/search.test.ts then printed 37 CONTRACT lines, and I reverted the change.

Before → after, CONTRACT lines per batch of 50 files:

batch000102030405060708091011121314151617181920
before00659243450003612934780231109
after000000000000000000000

Batches are the sorted output of grep -rl /api/v1/ test/ --include=*.test.ts | grep -v ^test/api-, cut every 50 lines.

Not done here: one test, test/mcp/forks.test.ts ("the private fork's owner sees it, with its parent named"), fails the same way on the base without this change. The MCP answer now has a words field that the test's expected value doesn't list, so I left it alone.

To try it: run bun test test/support/conforms.test.ts. Then run bun test on any batch above (for example test/view-source.test.ts test/fork-flow.test.ts) and grep ^CONTRACT the output: it finds nothing.

Checks run: bun scripts/gate.ts --explain (32 of 32 rules pass), bun x tsc --noEmit, and the 155 files scripts/fast.ts names, in three batches, all passing.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs