Skip to content

feat(core,auth,store,audit)!: hermetic test runs with declared seeds; expectJson; resolved captures in failures (#930) - #947

Merged
jimhoyd merged 4 commits into
mainfrom
claude/fixtures-hermetic-930
Sep 29, 2026
Merged

jimhoyd merged 4 commits into
mainfrom
claude/fixtures-hermetic-930

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Fixes #930

All three items from the second agent-workflow trial.

1. Hermetic test runs with a declared seed

Design. urlcode test, urlcode audit, urlcode benchmark and the MCP server's run_tests never touch the site's live data. Everything goes through the generic extension contract. Core imports no package (the boundary check passes).

  • loadOperatorHost(..., { hermetic: true }) creates a fresh temporary directory and exposes it through a Symbol.for slot (the same pattern as the revision pin). It imports host.mjs under a query of its own, so every run composes its own extensions, and close() removes the directory after the extensions release it.

  • HostContext gains data (<site>/data, or the run's temporary directory) and hermetic.

  • A hermetic host keeps every file under data, whatever the operator's options or environment name. It creates what an operator would (schema, a throwaway signing secret). Only then may it declare RuntimeExtension.seedSchema.

  • Core reads the project's optional tests/seed.json, an object keyed by extension name. It validates each entry against that registration's seedSchema and passes it as ExtensionActivation.seed. This happens only on the first activation of the run: never after a restart step, a reload, dev, serve or validate.

  • An entry is refused before serving (invalid-seed) when:

    • it names an extension that is not registered;
    • the extension's registration has no seedSchema;
    • it does not match the schema.

    So a seed cannot reach live data, even if a caller passes the harness its own non-hermetic registrations.

  • auth: in a hermetic run it uses a fresh database, a random secret (it ignores database, secretFile and BETTER_AUTH_SECRET), and runs migrate at activation. The seed {"auth": {"users": [{id, email, password, name?}]}} creates accounts through Better Auth's own adapter and password hashing, with fixed ids.

  • store: in a hermetic run it uses a fresh database (it ignores database and STORE_DATABASE). The seed {"store": {"members": {"<membership collection>": ["<principal id>"]}}} adds members as urlcode-store members add does: actor operator, audited when audit: true.

  • audit: in a hermetic run it uses a fresh database.

  • dev, serve, validate and routes keep using <site>/data. validate stays the preflight for what serve will use, including a missing secret or unmigrated tables, which test:proof still asserts.

  • CI: the action's Validate step is now static, and Test and Audit run hermetically with host-file. CI therefore provisions no account, membership, migration or data/auth.secret.

Why this shape: the data is declarative JSON beside tests/requests.json, and each extension owns its seed shape through the existing registration contract. Core only routes it, so a third-party extension opts in the same way.

2. expectJson

expectJson: {"/balance": 100, "/owner/tags": ["a","b"]} takes RFC 6901 pointers ("" is the whole body; ~0 and ~1 are escapes).

  • Values compare by deep equality: object key order is ignored, array order is not.
  • At most 16 pointers, each at most 8 segments.
  • Strings take {{name}} references. A string that is exactly one reference to a number or boolean kept by a json capture stands for that value, so "/balance": "{{bal}}" matches 100.
  • It counts as an assertion for coverage.
  • A mismatch reports check: "json" with the pointer, the expected value and the actual value.

3. Resolved captures in failure output

  • A failing urlcode test case prints path as sent (/probe/acct-7f3a/100), plus fixturePath as written when that differs.
  • json and header captures are shown resolved. A capture declared "secret": true, and any cookie, is still redacted as {{name}} / <cookie NAME>.
  • verify-deployment still names fixtures as written, because a live deployment's values can be real.

Evidence

  • test/hermetic-accounts.test.ts runs end to end with the real auth and store extensions:
    • The site has an owned collection, a readers mount gated by the reviewers membership, and host options pointing at a "live" store path and a missing secret.
    • It passes 6/6 twice in a row with no migrate, create-user or members add.
    • Neither data/ nor the live path is ever created.
    • A seed naming a non-membership collection is refused.
  • test/hermetic-host.test.ts:
    • Each hermetic load gets a distinct data directory, which is removed on close.
    • The seed reaches the first activation only, not after a restart; two runs each seed once.
    • Unknown, schemaless and invalid seeds are refused.
  • test/fixture-json.test.ts covers pointer matching and escapes, mismatch reports, typed whole references, the resolved path with fixturePath, secret redaction, audit coverage and file-level refusals.
  • packages/auth/test/auth.test.ts: a hermetic host ignores the site database and secret, migrates, seeds ann and signs in with identity.userId === "ann". A non-hermetic registration declares no seedSchema.
  • The Better Auth and Auth.js proofs declare app/tests/seed.json. The Auth.js proof's setup now uses fixed ids, so its reviewer membership can be seeded. test:proof and test:proof:authjs pass.
  • npm run verify is green, including every workspace, audit:packages, test:addons, test:proof, test:proof:authjs and test:ecosystem. npm run test:package is green.
  • Package budgets were re-measured on Node 26, plus ~800 bytes for Node 24 and ~3 KiB of headroom:
    Package Packed Unpacked
    core 1021513 4038619
    auth 19155 60229
    store 134276 518485

Breaking:

  • Captured json/header values now print in urlcode test failures; mark credential captures secret: true.
  • HostContext has two new fields, so a host hook that checks its exact keys needs updating.

Docs: READINESS (a new "Test data and seeds" section, plus expectJson and the output rules), EXTENSIONS ("Hermetic runs and test seeds" and the host ctx), CI and action.yml, STORE, the auth and store READMEs, the CHANGELOGs, a new RIM-EXT-HERMETIC-001 card, FRAMEWORK, AI-AUTHORING, llms.txt and the starter AGENTS.md.

Limits

  • Hermeticity is only as good as each extension. A third-party extension that ignores HostContext.data can still read or write whatever its options name. The Auth.js proof's provider, for example, still reads the users.json that setup writes. Core cannot enforce this, and the README says so.
  • validate and routes with --host-file still activate against the site's data by design.
  • CI passing is not an independent security review.

🤖 Generated with Claude Code

… expectJson; resolved captures in failures (#930)

Test, audit and benchmark (and MCP run_tests) never touch the site's live data.
With --host-file, loadOperatorHost composes the host on a fresh temporary data
directory (a module URL of its own, so host.mjs runs again per run) and
removes it on close. composeHost hands every extension host() two new
HostContext fields, data and hermetic. The first-party extensions keep every
file there, whatever database/STORE_DATABASE/secretFile name; auth creates
Better Auth's tables at activation and signs with a throwaway secret.

A hermetic registration may declare seedSchema. Core reads the project's
tests/seed.json, validates each entry against the named registration's
seedSchema and passes it as ExtensionActivation.seed to the first activation
of the run only (never after a restart step, a reload, dev, serve or validate).
An entry for an unregistered extension, or one without a seedSchema, is
refused before serving, so a seed cannot reach live data. auth seeds users
with fixed ids; store seeds membership members as `members add` does.

Fixtures gain expectJson: RFC 6901 pointers to the value each must equal
(deep equality), with {{name}} references, a whole reference standing for the
number or boolean a json capture kept. It counts as an assertion for coverage.

urlcode test prints a failing case's path as sent (fixturePath as written when
different). json and header captures are shown; a capture declared
secret: true, and any cookie, stays {{name}} / <cookie NAME>.
verify-deployment still names fixtures as written.

The GitHub action validates statically and runs test/audit hermetically, so CI
provisions no account, membership, migration or auth secret. The Better Auth
and Auth.js proofs declare their seeds. Docs: READINESS (test data and seeds,
expectJson, output), EXTENSIONS (hermetic runs), CI, STORE, auth/store READMEs,
RIM-EXT-HERMETIC-001, llms.txt, starter AGENTS.md. Package budgets re-measured.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 29, 2026 18:31
jimhoyd and others added 3 commits September 29, 2026 14:15
--local-review and hermetic runs compose: the store-credits recipe seeds its issuer from tests/seed.json instead of
adding it to the live database, and the recipe tests assert nothing reaches the configured database.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Fixtures: hermetic test databases and seeds; assert one JSON property; resolved captures in failures

1 participant