Skip to content

Multi-step fixtures: capture, restart step, data-isolation helper (refs #256) - #303

Merged
jimhoyd merged 2 commits into
mainfrom
feat/256-multi-step-fixtures
Sep 20, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
feat/256-multi-step-fixtures

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #256 (does not close it).

What

  • tests/requests.json entries may be {"steps": [...]}: ordered requests with capture (JSON body path or single header) and {{name}} substitution, plus {"restart": true}, which closes and restarts the runtime on the same project and data directory.
  • startServer gains dataDir / isolateData (offered as URLCODE_DATA_DIR); startServer({port: 0}) is the in-process helper. urlcode test and urlcode audit use a per-run temp data dir.
  • --target decision: verify-deployment cannot restart a live deployment, so a fixture containing a restart step is skipped whole, with a notes entry and a skipped log event (never silent, does not fail the run). auditProject on an app that cannot restart refuses.
  • Bounds: 50 steps/fixture, 5 restarts/fixture, 20/file, 16 captures/step, 4096-byte values, 1 MiB capture body, 10000 requests/file. Static check that every {{name}} is captured by an earlier step.
  • Secrets: captured values never reach logs, reports or errors; failures print the fixture as written. A failed step fails the rest of its fixture without sending them.
  • Docs: READINESS.md (Multi-step fixtures, coverage counting), DEPLOYMENT-CHECKS.md; [Request]: Multi-step fixtures with captured values, a restart step and quiet test output #256 row removed from OPEN-DECISIONS.md. Executable example: examples/lifecycle. Tests: test/fixture-steps.test.ts.

Verification

npm run verify passes (lint, typecheck, check incl. check:docs, build, tests, workspaces).

Open decision

To let the example read the data directory without an operator policy pinned to the project hash, startServer with a data dir grants only {env: URLCODE_DATA_DIR} for that run (grantDataDir in RuntimeOptions). Maintainer should confirm this narrow test-harness grant is acceptable.

🤖 Generated with Claude Code

…ion test helper (#256)

Ordered steps in tests/requests.json share captured values through {{name}}
substitution. A restart step closes and restarts the runtime on the same
project and data directory. startServer gains dataDir/isolateData. audit and
test run restart steps; verify-deployment skips such fixtures explicitly.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jimhoyd
jimhoyd force-pushed the feat/256-multi-step-fixtures branch from 7bb25e9 to 3fdbcda Compare September 20, 2026 16:10
@jimhoyd
jimhoyd enabled auto-merge (squash) September 20, 2026 16:10
@jimhoyd

jimhoyd commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer decision on the open question (grantDataDir): accepted, with conditions.

Why: under the trust-by-default model (docs/OPEN-DECISIONS.md), a grant controls what URLCode supplies, not what trusted code can access. Trusted function/middleware routes already run in-process and can read process.env, so the harness supplying one variable to them in a test run adds no capability. Requiring an operator policy pinned to the project hash for a throwaway test directory adds ceremony, not protection.

Conditions (please confirm each in the diff; not verified by the maintainer):

  1. Test runs only. Never enabled by a project's own YAML, or by a production serve/dev start. Only the test and audit harness may set it.
  2. One exact variable. It grants URLCODE_DATA_DIR and nothing else, no wildcard.
  3. Trusted routes only. It must not apply to sandbox: true routes. Those keep needing an explicit, revision-pinned grant, per AGENTS.md ("preserve that sandboxed path's isolation exactly as-is"). This is the condition that matters most.
  4. Visible. audit output and docs/READINESS.md state that the harness grant exists.

If any condition is not met, fix it before merge. Also please explain or fix the failing container check. Merge follows the usual protected-branch process.

@jimhoyd

jimhoyd commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator Author

What blocks merge: the container check fails, which also fails verify-complete. Every other check passes.

Failing step: "Smoke test isolated functions in constrained container" (.github/workflows/ci.yml:255), which runs urlcode test on examples/assets in a container started with --read-only --cap-drop ALL and the project mounted :ro. It exits 1 with only "Operation failed; check project files, module dependencies and command options".

Hypothesis (not reproduced, code not read): this PR makes urlcode test and urlcode audit use a per-run temp data directory. In a --read-only container there may be no writable place to create one, which would make this a regression for the read-only test setup, not flakiness.

Options if that is the cause:

  1. Fall back to an in-memory or otherwise safe location when the default data directory is not writable.
  2. Add --tmpfs /tmp to that smoke test. This loosens what the "constrained container" test proves, so weigh it deliberately.
  3. Make the error name the path it could not write, whatever the fix.

Please confirm the cause by running the smoke-test command locally before choosing.

The container smoke test runs it on a read-only filesystem, where mkdtemp
failed. Run without offering URLCODE_DATA_DIR instead.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jimhoyd
jimhoyd merged commit 014603d into main Sep 20, 2026
20 checks passed
@jimhoyd
jimhoyd deleted the feat/256-multi-step-fixtures branch September 20, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant