diff --git a/lib/applications/proposedRegistration/__tests__/operations.test.ts b/lib/applications/proposedRegistration/__tests__/operations.test.ts index 2e7a12257..394cd9421 100644 --- a/lib/applications/proposedRegistration/__tests__/operations.test.ts +++ b/lib/applications/proposedRegistration/__tests__/operations.test.ts @@ -166,6 +166,20 @@ describe("unwired create/read transaction binding", () => { create(request(), input, { policy, storage: {} } as ProposedDependencies), ).rejects.toThrow("unavailable"); }); + it.each(["df7be4c65b98924373b38c7d257f4b1c1820d6b7", "wrong"])( + "rejects incompatible database descriptor %s before either storage port", + async databaseHead => { + const deps = dependencies(); + const incompatible = { + ...deps, + policy: { ...policy, databaseHead }, + } as ProposedDependencies; + await expect(create(request(), input, incompatible)).rejects.toThrow(); + await expect(read(request(), selected, incompatible)).rejects.toThrow(); + expect(deps.storage.create).not.toHaveBeenCalled(); + expect(deps.storage.read).not.toHaveBeenCalled(); + }, + ); it("uses bytewise canonical ordering and preserves development loopback eligibility", async () => { const body = { name: "字", diff --git a/lib/applications/proposedRegistration/proposedRegistrationContract.ts b/lib/applications/proposedRegistration/proposedRegistrationContract.ts index 8f529b085..9633f4895 100644 --- a/lib/applications/proposedRegistration/proposedRegistrationContract.ts +++ b/lib/applications/proposedRegistration/proposedRegistrationContract.ts @@ -4,7 +4,7 @@ export const proposedPolicySchema = z .object({ status: z.literal("proposed_unadopted"), version: z.literal("proposed-personal-v1"), - databaseHead: z.literal("df7be4c65b98924373b38c7d257f4b1c1820d6b7"), + databaseHead: z.literal("f507a77696f20429f977df9885d6c8c11a5f304b"), }) .strict(); const revision = z.number().int().min(1).max(Number.MAX_SAFE_INTEGER); diff --git a/scripts/application-registration-proposal/README.md b/scripts/application-registration-proposal/README.md index 7f295e6f4..94b10cd10 100644 --- a/scripts/application-registration-proposal/README.md +++ b/scripts/application-registration-proposal/README.md @@ -1,10 +1,10 @@ # Inactive application registration adapter -This domain-only candidate binds proposed create/read calls to the existing nonprovisioning REST authentication path. It is not registered as a route or MCP tool and has no concrete database caller or production factory. The injected policy descriptor identifies an unadopted contract; it grants no authority. SQL personal enrollment and named entitlements remain required in the proposed storage boundary. +This inactive candidate binds proposed create/read calls to the existing nonprovisioning REST authentication path. It is not registered as a route or MCP tool and has no concrete database caller or production factory. The injected policy descriptor identifies an unadopted contract; it grants no authority. SQL personal enrollment and named entitlements remain required in the proposed storage boundary. `node scripts/application-registration-proposal/run.mjs` executes the dedicated suite. The ordinary Vitest configuration deliberately excludes it. `.github/workflows/application-registration-proposal.yml` runs this command on every PR to main, including changes to any shared auth, validator, compiler or dependency input. CI checks the exact PR head with read-only permissions and no retained checkout credentials. A local pass is not a CI result. -The launcher creates a synthetic environment and temporary home, preloads network denial before Vitest/config/auth imports, disables Vite dotenv discovery and stops its owned process group before deleting temporary files. An uncertain process inventory preserves the directory and fails. Installed Vite 7.3.0 implements `envDir: false` by returning an empty dotenv filename list; the separately retained local qualification controls also used synthetic poison values in all four dotenv filenames and the ambient environment. Those poison controls are recorded in the sealed local review packet and are not injected by the ordinary CI launcher. Provider fetch, SDK verification, Supabase database access, Stripe and email are substituted leaves. Auth orchestration, API-key hashing/expiry handling, existing-account selection, evidence validation and canonical registration validation are real source calls. These tests do not establish cryptographic verification, hosted entitlement enforcement or real MCP authentication parity. +The launcher creates a synthetic environment and temporary home, preloads network denial before Vitest/config/auth imports, disables Vite dotenv discovery and stops its owned process group before deleting temporary files. An uncertain process inventory preserves the directory and fails. Installed Vite 7.3.0 implements `envDir: false` by returning an empty dotenv filename list; the separately retained local qualification controls also used synthetic poison values in all four dotenv filenames and the ambient environment. Those poison controls are recorded in the sealed local review packet and are not injected by the ordinary CI launcher. Provider fetch, SDK verification, Supabase database access, Stripe and email are substituted leaves. Auth orchestration, API-key hashing/expiry handling, existing-account selection, evidence validation and canonical registration validation are real source calls. These tests do not establish provider cryptographic verification, hosted entitlement enforcement or authenticated deployed MCP acceptance. The accepted unregistered direct-SDK transport is described in [the MCP composition contract](../../docs/internal/mcp-existing-application-actor.md#inactive-direct-sdk-transport-composition). ## Transaction and recovery contract @@ -14,12 +14,16 @@ Read input resource UUIDs accept uppercase aliases and are lowered after UUID va ## SQL evidence and source pins -`source-bindings.json` records immutable API/SQL source heads and hashes. Before loading tests, the launcher recomputes every locally available `apiInputs` hash and the golden file hash and checks its database head. A mismatch fails qualification and requires a reviewed evidence refresh. External database source and local capture-driver/log hashes are provenance references verified in the sealed source-review packet; those external files are not present in this API checkout and are not reverified by API CI. `receipt-golden.json` contains actual create/read outputs from disposable PostgreSQL 15.10 with UTF8 encoding, using database proposal commit `df7be4c65b98924373b38c7d257f4b1c1820d6b7`. The capture used the proposal's existing supervised fixture runner, explicitly enrolled a synthetic UUID actor, granted create authority, invoked SQL create, explicitly granted named read authority and invoked SQL read. Create and read receipts were equal. The fixture reported worker group, postmaster and socket absence. No hosted database was contacted and no production migration or entitlement was applied. The capture driver and execution logs are retained in the coordinator's local audit packet; the golden file is synthetic evidence, not a receipt for a deployed application. +`source-bindings.json` records immutable API/SQL source heads and hashes. Before loading tests, the launcher recomputes every locally available `apiInputs` hash and the golden file hash and checks its database head. A mismatch fails qualification and requires a reviewed evidence refresh. External database source and local capture-driver/log hashes are provenance references verified in the sealed source-review packet; those external files are not present in this API checkout and are not reverified by API CI. `receipt-golden.json` contains actual create/read outputs from disposable PostgreSQL 15.10 with UTF8 encoding, using accepted local database proposal commit `f507a77696f20429f977df9885d6c8c11a5f304b`. The capture used the proposal's existing supervised fixture runner, explicitly enrolled a synthetic UUID actor, granted create authority, invoked SQL create, explicitly granted named read authority and invoked SQL read. Create and read receipts were equal. The fixture reported worker group, postmaster and socket absence. No hosted database was contacted and no production migration or entitlement was applied. The capture driver and execution logs are retained in the coordinator's local audit packet; the golden file is synthetic evidence, not a receipt for a deployed application. -The original API baseline was `1fff6b55b8c1b98826c375f99b4f4f66a5ba201c`; this candidate now composes the accepted OAuth PR1268 merge `5605ee143afc4ebcdba9ba33dc7b48378c70a47f`. Its shared REST expiry resolver repairs the former MCP API-key expiry omission. That omission is historical after this source merge; it does not establish original-actor evidence, nonprovisioning Privy behavior or runtime acceptance. The fixture named “HTTP-shaped JSON and MCP-shaped argument” tests input projection only; fresh nonprovisioning MCP handoff remains unresolved. Database PR138 is a separate unmerged/unapplied proposal. All runtime activation and publication remain gated by coordinator review. +The original API baseline and OAuth PR1268 merge remain historical provenance in the manifest. This compatibility candidate preserves accepted transport source `2606c9104dff3731f59d56d00bba121d2a8e47ba` and normally composes its accepted API1272 main merge `f8ec0bee58726b16f7e42b86169c6a7307a4b1b4`, whose tree equals that source. Its existing 128 controlled domain/verifier/transport cases are preserved, with explicit old-head/mismatched-descriptor rejection added for create and read before either storage port. + +The previous golden was captured from `df7be4c65b98924373b38c7d257f4b1c1820d6b7`. The current golden is a new SQL capture from the accepted local successor, with new generated IDs and timestamp, not a relabeling of that historical fixture. The capture used PostgreSQL15.10 UTF8 and Python3.12.4; driver and log hashes refer to that new capture. Database PR138 remains draft, unmerged and unapplied; accepting a local successor is not publication or migration approval. + +The successor reserves `P2101` for changed retry fingerprints and stale entitlement revisions on new requests. `42501` remains denial. Both definite conflicts use the existing proposed domain `conflict` kind; no raw SQL error text or broad SQLSTATE family may classify an error. Unknown transport outcomes retain the original operation/key/input without automatic retry. The compatibility portion updates the strict descriptor and actual receipt evidence. The included disposable `sql-composition/` suite now pins this Database successor and the accepted API compatibility source, and qualifies create-only P2101 mapping through the actual domain against local PostgreSQL15/17. It preserves denied and unknown outcomes, including read P2101, and separately labels synthetic error controls. This is test-only joined evidence, not a production SQL adapter or public registration availability. See [the joined qualification contract](./sql-composition/README.md) for source and runtime boundaries. ## Authentication qualifications The independent source review at API baseline 1fff6b55 identified boundaries retained here: Privy existing-account lookup still requires an external authenticated profile GET; `self` observes the absence of an override and does not prove personal enrollment. Existing REST API-key expiry rejects parseable elapsed timestamps but treats missing or malformed timestamps as non-expiring; the tests explicitly preserve that inherited behavior without adding a second verifier. Evidence contains no expiry epoch. Verification can race with credential revocation or profile/email remapping before the storage call; SQL does not receive a credential for atomic revalidation. -`executionResources` remains exactly unresolved. Guard-unit forged-evidence negatives establish structural rejection only, not cryptographic delegated-token rejection. Existing OAuth wrappers perform separate grant revalidation; that does not provide this adapter's original-actor evidence or personal enrollment. No MCP accountId/authInfo is adapted into an invented request credential. The separately owned OAuth expiry repair is included unchanged through the accepted merge. The MCP Privy fallback can still provision accounts and the MCP handoff still does not supply this strict verifier-produced original-actor evidence. +`executionResources` remains exactly unresolved. Guard-unit forged-evidence negatives establish structural rejection only, not cryptographic delegated-token rejection. Existing OAuth wrappers perform separate grant revalidation; that does not provide this adapter's original-actor evidence or personal enrollment. No MCP accountId/authInfo is adapted into an invented request credential. The separately owned OAuth expiry repair is included unchanged through the accepted merge. The legacy public MCP Privy fallback can still provision accounts. The separately accepted opt-in existing-account verifier and unregistered transport provide controlled original-actor handoff evidence, as described in the MCP composition contract; the public route is unchanged and no deployed handoff is claimed. diff --git a/scripts/application-registration-proposal/receipt-golden.json b/scripts/application-registration-proposal/receipt-golden.json index 646e371e6..8535e401f 100644 --- a/scripts/application-registration-proposal/receipt-golden.json +++ b/scripts/application-registration-proposal/receipt-golden.json @@ -1,5 +1,5 @@ { - "databaseHead": "df7be4c65b98924373b38c7d257f4b1c1820d6b7", + "databaseHead": "f507a77696f20429f977df9885d6c8c11a5f304b", "serverVersion": "15.10 (Homebrew)", "serverEncoding": "UTF8", "input": { @@ -51,19 +51,19 @@ "https://music.example/return" ], "workspace_id": "11111111-1111-4111-8111-111111111111", - "application_id": "cbbb51b5-aca4-405c-9a97-aee7612b0cd4", + "application_id": "1dec8fc0-2cec-4653-859b-53e0a83fc9a1", "allowed_origins": [ "https://music.example", "https://preview.example" ] }, - "receipt_id": "c5ac9418-b749-4e6b-966b-6d5a3314c73d", + "receipt_id": "989252ef-7470-475c-9527-fb64c2619e94", "environment": "production", - "recorded_at": "2026-11-18T02:41:27.506401+00:00", + "recorded_at": "2026-11-18T05:12:41.526502+00:00", "workspace_id": "11111111-1111-4111-8111-111111111111", "evidence_kind": "disposable_parent_assertion", "policy_status": "proposed_unadopted", - "application_id": "cbbb51b5-aca4-405c-9a97-aee7612b0cd4", + "application_id": "1dec8fc0-2cec-4653-859b-53e0a83fc9a1", "policy_version": "proposed-personal-v1", "runtime_enabled": false, "access_activated": false, @@ -98,19 +98,19 @@ "https://music.example/return" ], "workspace_id": "11111111-1111-4111-8111-111111111111", - "application_id": "cbbb51b5-aca4-405c-9a97-aee7612b0cd4", + "application_id": "1dec8fc0-2cec-4653-859b-53e0a83fc9a1", "allowed_origins": [ "https://music.example", "https://preview.example" ] }, - "receipt_id": "c5ac9418-b749-4e6b-966b-6d5a3314c73d", + "receipt_id": "989252ef-7470-475c-9527-fb64c2619e94", "environment": "production", - "recorded_at": "2026-11-18T02:41:27.506401+00:00", + "recorded_at": "2026-11-18T05:12:41.526502+00:00", "workspace_id": "11111111-1111-4111-8111-111111111111", "evidence_kind": "disposable_parent_assertion", "policy_status": "proposed_unadopted", - "application_id": "cbbb51b5-aca4-405c-9a97-aee7612b0cd4", + "application_id": "1dec8fc0-2cec-4653-859b-53e0a83fc9a1", "policy_version": "proposed-personal-v1", "runtime_enabled": false, "access_activated": false, diff --git a/scripts/application-registration-proposal/source-bindings.json b/scripts/application-registration-proposal/source-bindings.json index df4f1a58d..3be7d8479 100644 --- a/scripts/application-registration-proposal/source-bindings.json +++ b/scripts/application-registration-proposal/source-bindings.json @@ -1,6 +1,6 @@ { "apiBaseline": "5605ee143afc4ebcdba9ba33dc7b48378c70a47f", - "databaseHead": "df7be4c65b98924373b38c7d257f4b1c1820d6b7", + "databaseHead": "f507a77696f20429f977df9885d6c8c11a5f304b", "policyStatus": "proposed_unadopted", "apiInputs": { "lib/auth/validateAuthContext.ts": "055ac2965db8487c8f67d74c549101d866968ed507d295498ed4485d62867c28", @@ -15,10 +15,10 @@ }, "databaseInputs": { "proposals/application-registration-2104/protocol-composition.py": "377791d3ef4a26103bd046609d4b8dbf8f63a3d475aa2c72faeba68b553aada5", - "proposals/application-registration-2104/registration.sql": "472440d1540a79eb34255efcbc7a6286bb394e1f3779e7ed6a6b7ace33cd9074", + "proposals/application-registration-2104/registration.sql": "3377dd6f86bdf3052a2dd00b66380540764e07a763003f6a1c46192c336e6409", "proposals/application-registration-2104/parents.sql": "2a1096eadf1ee947f2b1d6bb88f5750e26436ee8ea82ae1f306a279da8b41c2d", "proposals/application-registration-2104/qualification-bootstrap.sql": "6c318540735e46c8ace40cd686bf7cc1851fb3296b5a123d29e287f94be35c05", - "proposals/application-registration-2104/test_registration.py": "ca498687ee4983767f2cf592dfd424a954fe17d0acaa04e18ae9960ed62f3a16", + "proposals/application-registration-2104/test_registration.py": "4051b2581646cea5ac2d36a23d5d5e6271dd02cbf0997e0792623289914d230c", "proposals/application-proof-2104/proposal.sql": "2cf96399422cfc1e68b0578b7aeb7b58a97c56303d85b91ee6cf862329f6c86c", "proposals/application-proof-2104/fixture.sql": "b4435b1c5546d471c33b758f1ac8a7fd8ca199071b08cc541f4cb199e6412668", "proposals/application-proof-2104/test_configuration.py": "43b686a33660dfb8bfd7b26c4827a74527cc430466567311726cb54881406cad", @@ -27,11 +27,14 @@ "proposals/application-proof-2104/fixture-authority.sql": "0a2715a5a4f93c349df06d25a6334d513350f225a36af71ae8694fe1914c4c99", "proposals/application-proof-2104/configuration.sql": "148819c1363929e990bf2cfd67bae02f7567c2e2e2a05732cb17ea2248bad3b1" }, - "goldenSha256": "357e2c82f6b9473d024cf6472bdec8d670de64531c0a51fa0843b94f1e70c1fe", - "captureDriverSha256": "86f6b0de4d43aadec92154a8fd9e51407eb4837f081f0e6d6ffae75455da595f", - "goldenCaptureLogSha256": "0eb40678c48643d87d2515c68236e62b23f2faf874f6794053b418378e071d6f", + "goldenSha256": "4b386f6dd38d689e08bb7f230ed2873a9764a3bc6f3038ca36cfc2442e1fb129", + "captureDriverSha256": "b9f4342e278704c8767f0a738f35b3c8f92ff84a6b0cedc49074d9602cdfa2dd", + "goldenCaptureLogSha256": "56cc23432ad600743f07d5d2b04f7b7e08c8c677e100293bbd975334002f1135", "scope": "No route, MCP registration, concrete Supabase adapter, factory, hosted execution, deployment or policy adoption", "originalApiBaseline": "1fff6b55b8c1b98826c375f99b4f4f66a5ba201c", "acceptedOAuthMerge": "5605ee143afc4ebcdba9ba33dc7b48378c70a47f", - "adapterBeforeComposition": "ce271f4be5570cb0774d582a5e1b832e406aec7f" + "adapterBeforeComposition": "ce271f4be5570cb0774d582a5e1b832e406aec7f", + "acceptedTransportSource": "2606c9104dff3731f59d56d00bba121d2a8e47ba", + "previousDatabaseHead": "df7be4c65b98924373b38c7d257f4b1c1820d6b7", + "acceptedTransportMerge": "f8ec0bee58726b16f7e42b86169c6a7307a4b1b4" } diff --git a/scripts/application-registration-proposal/sql-composition/README.md b/scripts/application-registration-proposal/sql-composition/README.md index 0bf05234a..6f5d2ef76 100644 --- a/scripts/application-registration-proposal/sql-composition/README.md +++ b/scripts/application-registration-proposal/sql-composition/README.md @@ -2,9 +2,11 @@ This harness joins the existing unwired API create/read domain to the exact inactive Database 138 proposal in an owned disposable PostgreSQL cluster. It is not a production storage adapter, credential verifier, route, MCP tool or policy adoption. -The actual REST authentication orchestration uses the existing controlled SDK/profile/Supabase leaves. Only explicit synthetic actors are enrolled by fixture setup. Domain calls execute one parameterized SQL function each, with setup/readback queries counted separately. No management permission is granted by create. Real SQL authorization errors `42501` map to denied; generic `P0001` failures remain `outcome_unknown` and are never classified from message text. +The actual REST authentication orchestration uses the existing controlled SDK/profile/Supabase leaves. Only explicit synthetic actors are enrolled by fixture setup. Domain calls execute one parameterized SQL function each, with setup/readback queries counted separately. No management permission is granted by create. Real SQL authorization errors `42501` map to denied. Only create-operation `P2101` maps to the existing conflict kind. Generic `P0001`, adjacent/unrecognized codes, transport failures and read-operation `P2101` remain `outcome_unknown`; no message text or SQLSTATE family is used for classification. -The loss-of-response case drops the result only after actual SQL commit. Recovery explicitly reauthenticates and reuses the original key/input, then compares the SQL receipt and row count. No production retry ledger or automatic retry exists. Returned UUIDs/timestamps/flags are validated by the real domain parser; input-only read aliases remain supported. +The selected source pair is accepted local Database `f507a77696f20429f977df9885d6c8c11a5f304b` and accepted documented API successor `0769bc1957fce38bd6b847d342eae904044ae821` (the manifest's acceptedApiComposition). That successor inherits the reviewed joined qualification; `784bee20b3e0fe61e67ed156c7f3a39a08a441b2` remains the original pre-joined compatibility source recorded as originalApiCompatibility. The original apiMerge is retained as historical provenance. The policy descriptor and Database pins must match this pair; the historical df7 qualification is not reused as successor evidence. + +The loss-of-response case drops the result only after actual SQL commit. Recovery explicitly reauthenticates and reuses the original key/input, then compares the SQL receipt and row count. Altered original intent now produces the definite conflict while preserving the original receipt and all five table contents. New-key stale revision, same-key fingerprint changes and authorized exact replay after revision advance are covered separately. No production retry ledger or automatic retry exists. Returned UUIDs/timestamps/flags are validated by the real domain parser; input-only read aliases remain supported. Resolve the intended Node executable to an absolute path first, then run from the API repository with a minimal parent environment and explicit local source and tool paths: @@ -19,14 +21,16 @@ env -i PATH=/usr/bin:/bin LANG=C LC_ALL=C TZ=UTC "$node_path" \ The minimal parent environment prevents ambient `NODE_OPTIONS` from executing code before the launcher can scrub its child. Do not supply a real `HOME` or an env file. Dependency installation happens separately and is outside this process-containment claim. -The final local PostgreSQL 15.10/17.7 qualification and fault controls used Node 24.18.0. The separate loader-defect reproduction used Node 23.6.1. Node 22 has not been qualified by this local suite. +The successor local PostgreSQL 15.10/17.7 qualification uses Node 24.18.0. Earlier unchanged-runner fault controls also used Node 24.18.0 and remain historical evidence, not new successor executions. The separate loader-defect reproduction used Node 23.6.1. Node 22 has not been qualified by this local suite. Optional `--fault signal`, `--fault timeout`, or `--fault worker-exit` controls initialize a real guarded Node descendant, then deliberately interrupt the supervisor, time out its worker, or exit its worker while the child remains alive. Each retains an expected nonzero exit, but the launcher reports `COMPOSITION_FAULT_RESULT.passed=true` only after validating the expected exit, initialized Node lineage and both worker/cluster cleanup receipts. A nonzero exit alone is not a passing fault control. These are lifecycle controls, not functional SQL passes. The launcher verifies pinned files, tracked API source against the accepted revision (allowing only this eight-path qualification slice), and the exact Database head. It compares actual file bytes and types against Git blobs without trusting index flags, stat caches or clean filters. Environment files are never opened, including the tracked example; dotenv loading remains disabled. The accepted revision must be an ancestor of HEAD, and cumulative committed changes must stay within the same eight paths. Unexpected tracked differences, nonignored untracked files, and ignored executable sources under the API/auth and qualification directories fail before the worker starts. It then imports the reviewed database supervisor. That owner creates a UTF8 cluster without TCP listeners, scrubs the environment, owns the worker process group and verifies worker/postmaster/socket absence before removal. Node imports network denial before auth code; direct TCP/UDP creation and inbound TCP listening are denied; the PostgreSQL connector accepts only the registered owned Unix socket. The raw connector remains module-private; the global cross-import handle can only reinstall the lease-checked guard. Native guard initialization is required in the runner and each Vitest worker before the shared authentication setup. Native DNS lookup/resolve/reverse and Resolver constructors are denied in callback and promise APIs. Vitest receives only a fixed synthetic localhost answer; this never invokes OS or DNS resolution. A Node 23.6.1 loader defect can retain socket stat state during cached module-path resolution. The guard validates the owned directory after each socket stat, preserving both checks and avoiding that stale state. Dotenv is disabled. No hosted DSN, ambient credentials or arbitrary external socket is accepted. -Qualification targets PostgreSQL 15 and 17. This suite is distinct from the 45-case adapter suite and ordinary Unit CI. It requires the explicitly pinned Database checkout and is not evidence of a hosted RPC, least-privilege deployment, live enrollment or public App 2104 availability. Personal policy, production authority provisioning, retention, actual MCP nonprovisioning/original-actor handoff and client acceptance remain separate. Database 138 remains draft/unmerged/unapplied. +Qualification targets PostgreSQL 15 and 17. This suite is distinct from the 130-case controlled adapter/MCP suite and ordinary Unit CI. It requires the explicitly pinned Database checkout and is not evidence of a hosted RPC, least-privilege deployment, live enrollment or public App 2104 availability. Personal policy, production authority provisioning, retention, deployed MCP nonprovisioning/original-actor handoff and client acceptance remain separate. Database 138 remains draft/unmerged/unapplied. -The eight qualification paths are the test code under review, not self-authenticating inputs. Record their exact commit and file hashes with each evidence packet; changing a guard, launcher or assertion invalidates earlier qualification evidence. Other tracked API inputs, including the legacy golden receipt, are checked against the accepted Git tree. This SQL suite reads real SQL receipts and does not use that golden as its result oracle. The guard is an in-process test boundary, not an OS sandbox for hostile code. +The eight qualification paths are the test code under review, not self-authenticating inputs. Record their exact commit and file hashes with each evidence packet; changing a guard, launcher or assertion invalidates earlier qualification evidence. Other tracked API inputs, including the freshly captured D golden receipt, are checked against the accepted Git tree. This SQL suite reads real SQL receipts and does not use that golden as its result oracle. The guard is an in-process test boundary, not an OS sandbox for hostile code. The outer watchdog reports cleanup as unconfirmed if the supervisor cannot finish its bounded cleanup. It preserves the recorded lease for inspection; it does not claim that killing the supervisor or its group would remove separately sessioned workers and PostgreSQL. The focused fault controls do not exercise that outer watchdog. + +Independent error controls use a session-local `pg_temp` function that emits structured SQLSTATE with the deliberately misleading message “idempotency conflict”. For those calls only, the test port executes that single synthetic SQL query instead of registration/read; these are classification controls, not failures observed from the real registration function. The transport negative throws before the SQL query and is likewise synthetic. Every attempt still enters one domain storage port; setup/readback queries are separately counted. Full row snapshots of applications, environments, origins, receipts and requests prove counts and historical values are unchanged, and subsequent original-key replay/read returns the original receipt. The separate committed-response-loss case executes the actual registration commit. diff --git a/scripts/application-registration-proposal/sql-composition/qualification.test.ts b/scripts/application-registration-proposal/sql-composition/qualification.test.ts index e09d74dbd..c743a7472 100644 --- a/scripts/application-registration-proposal/sql-composition/qualification.test.ts +++ b/scripts/application-registration-proposal/sql-composition/qualification.test.ts @@ -37,6 +37,7 @@ const sql = new Client({ const calls: Array<{ operation: "create" | "read"; state: string; parameters: number }> = []; let fixtureQueries = 0; let dropCommittedResponse = false; +let injectedFailure: "P0001" | "P2102" | "P2101" | "transport" | undefined; let server: { version: string; encoding: string }; const fixtureQuery = async (text: string, values: unknown[] = []) => { fixtureQueries++; @@ -47,13 +48,18 @@ const execute = async (operation: "create" | "read", text: string, values: unkno calls.push(observation); let result; try { - result = await sql.query(text, values); + if (injectedFailure === "transport") + throw new Error("Synthetic transport loss: idempotency conflict"); + result = injectedFailure + ? await sql.query("SELECT pg_temp.qualification_failure($1::text)", [injectedFailure]) + : await sql.query(text, values); observation.state = "committed"; } catch (error) { const code = (error as { code?: string }).code; observation.state = code ?? "unclassified"; // P0001 includes multiple unrelated failures. Never classify it from exception text. if (code === "42501") throw new ProposedStorageFailure("denied"); + if (operation === "create" && code === "P2101") throw new ProposedStorageFailure("conflict"); throw error; } if (dropCommittedResponse && operation === "create") { @@ -67,7 +73,7 @@ const dependencies: ProposedDependencies = { policy: { status: "proposed_unadopted", version: "proposed-personal-v1", - databaseHead: "df7be4c65b98924373b38c7d257f4b1c1820d6b7", + databaseHead: "f507a77696f20429f977df9885d6c8c11a5f304b", }, storage: { create: (call: ProposedCreateCall) => @@ -124,8 +130,23 @@ const grantRead = async (application: string) => [actorA, application], ); +const registrationState = async () => { + const tables = ["applications", "environments", "origins", "receipts", "requests"]; + const state: Record = {}; + for (const table of tables) { + state[table] = ( + await fixtureQuery( + `SELECT to_jsonb(t) AS row FROM application_registration_proposal.${table} t ORDER BY to_jsonb(t)::text`, + ) + ).rows.map(value => value.row); + } + return state; +}; + beforeAll(async () => { await sql.connect(); + await fixtureQuery(`CREATE FUNCTION pg_temp.qualification_failure(code text) RETURNS jsonb + LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'idempotency conflict' USING ERRCODE=code; END $$`); const metadata = await fixtureQuery( "SELECT current_setting('server_version') AS version,current_setting('server_encoding') AS encoding", ); @@ -138,6 +159,7 @@ beforeAll(async () => { }); beforeEach(async () => { dropCommittedResponse = false; + injectedFailure = undefined; await fixtureQuery("TRUNCATE application_registration_proposal.personal_principals CASCADE"); await fixtureQuery( "INSERT INTO application_registration_proposal.personal_principals(account_id) VALUES($1::uuid),($2::uuid)", @@ -256,6 +278,7 @@ describe("actual domain to exact disposable SQL proposal", () => { await fixtureQuery("SELECT result FROM application_registration_proposal.receipts") ).rows[0].result; expect(await register()).toEqual(original); + const saved = await registrationState(); expect( ( await fixtureQuery( @@ -268,25 +291,70 @@ describe("actual domain to exact disposable SQL proposal", () => { ...input, registration: { ...input.registration, name: "Changed original intent" }, }), - ).rejects.toMatchObject({ kind: "outcome_unknown" }); - expect(calls.at(-1)?.state).toBe("P0001"); + ).rejects.toMatchObject({ kind: "conflict" }); + expect(calls.at(-1)?.state).toBe("P2101"); + expect(await registrationState()).toEqual(saved); expect( (await fixtureQuery("SELECT result FROM application_registration_proposal.receipts")).rows[0] .result, ).toEqual(original); }); - it("does not infer a conflict class from another generic P0001 failure", async () => { + it("classifies both definite conflict sites without changing original rows", async () => { + const empty = await registrationState(); await expect(register({ ...input, expected_entitlement_revision: 2 })).rejects.toMatchObject({ - kind: "outcome_unknown", + kind: "conflict", }); - expect(calls.at(-1)?.state).toBe("P0001"); - expect( - ( - await fixtureQuery( - "SELECT count(*)::int AS n FROM application_registration_proposal.applications", - ) - ).rows[0].n, - ).toBe(0); + expect(calls.at(-1)?.state).toBe("P2101"); + expect(await registrationState()).toEqual(empty); + const original = await register(); + const saved = await registrationState(); + for (const changed of [ + { ...input, expected_entitlement_revision: 2 }, + { ...input, registration: { ...input.registration, environment: "development" } }, + ]) { + await expect(register(changed)).rejects.toMatchObject({ kind: "conflict" }); + expect(calls.at(-1)?.state).toBe("P2101"); + expect(await registrationState()).toEqual(saved); + } + await fixtureQuery( + "UPDATE application_registration_proposal.create_entitlements SET revision=2 WHERE actor=$1::uuid", + [actorA], + ); + expect(await register()).toEqual(original); + await expect( + register({ ...input, idempotency_key: "new-stale-revision" }), + ).rejects.toMatchObject({ kind: "conflict" }); + expect(calls.at(-1)?.state).toBe("P2101"); + expect(await registrationState()).toEqual(saved); + }); + it.each(["P0001", "P2102", "transport"] as const)( + "keeps independent %s failure unknown despite misleading conflict text", + async failure => { + const original = await register(); + const saved = await registrationState(); + injectedFailure = failure; + await expect(register()).rejects.toMatchObject({ kind: "outcome_unknown" }); + expect(calls.at(-1)?.state).toBe(failure === "transport" ? "unclassified" : failure); + expect(await registrationState()).toEqual(saved); + injectedFailure = undefined; + expect(await register()).toEqual(original); + expect(await registrationState()).toEqual(saved); + }, + ); + it("does not classify a read P2101 as a create conflict", async () => { + const original = await register(); + await grantRead(original.application_id); + const saved = await registrationState(); + injectedFailure = "P2101"; + await expect( + oneStorage(() => read(request(), select(original), dependencies)), + ).rejects.toMatchObject({ kind: "outcome_unknown" }); + expect(calls.at(-1)?.state).toBe("P2101"); + expect(await registrationState()).toEqual(saved); + injectedFailure = undefined; + expect(await oneStorage(() => read(request(), select(original), dependencies))).toEqual( + original, + ); }); it("rechecks SQL authority before replay and read, and fresh auth before storage", async () => { const receipt = await register(); @@ -296,6 +364,12 @@ describe("actual domain to exact disposable SQL proposal", () => { [actorA], ); await expect(register()).rejects.toMatchObject({ kind: "denied" }); + const saved = await registrationState(); + await expect(register({ ...input, expected_entitlement_revision: 2 })).rejects.toMatchObject({ + kind: "denied", + }); + expect(calls.at(-1)?.state).toBe("42501"); + expect(await registrationState()).toEqual(saved); await fixtureQuery( "UPDATE application_registration_proposal.management_entitlements SET enabled=false WHERE actor=$1::uuid", [actorA], diff --git a/scripts/application-registration-proposal/sql-composition/source-bindings.json b/scripts/application-registration-proposal/sql-composition/source-bindings.json index 02e56c4d4..17dd526e2 100644 --- a/scripts/application-registration-proposal/sql-composition/source-bindings.json +++ b/scripts/application-registration-proposal/sql-composition/source-bindings.json @@ -1,6 +1,6 @@ { "apiMerge": "38ee9828635881526ac9f8b304626739ef1813f8", - "databaseHead": "df7be4c65b98924373b38c7d257f4b1c1820d6b7", + "databaseHead": "f507a77696f20429f977df9885d6c8c11a5f304b", "apiInputs": { "lib/auth/validateAuthContext.ts": "055ac2965db8487c8f67d74c549101d866968ed507d295498ed4485d62867c28", "lib/applications/applicationRegistrationSchema.ts": "5bfb55ded25eae323bea02b535d6fb010eec5b2a767b891a13b86e4c91427a30", @@ -10,10 +10,10 @@ "tsconfig.json": "b32629dbc2af272f06db2eb3c5e6bd249183a72cec77481e624b0a4086c10d93", "lib/keys/getApiKeyDetails.ts": "68813ca17af04703ded1efc25d8c6864aaa1f7b9c297ddeadb44c6c10220c644", "lib/mcp/__tests__/verifyApiKeyExpiry.test.ts": "1b4b18f8147217734b9b1d89418a57ae23c968e6046109d072469b7735fdd1bc", - "vercel.json": "3321280d5e9e9c4fbba06651418ffb0f5716418acdddc8f889f618ac8eca0fa3", + "vercel.json": "4b3dfd36dbd274213a3ccf2d6bfbfa9be1ba6be26ea71946828f535e1bbfbf8a", "lib/applications/proposedRegistration/readProposedApplicationRegistration.ts": "ca358e8de64b51550f9be50f55d9189a665ca1a38d722a7850f1d31be43ae134", "lib/applications/proposedRegistration/validateProposedRegistrationActor.ts": "c56077ada47829f3ba20a618eaf0ae3ccfd67d9cf38db72e13939e57f89b8902", - "lib/applications/proposedRegistration/proposedRegistrationContract.ts": "e4c355f112b2a21ada49ab2146318837f13d2cd66e59e3f8a08569d055162fed", + "lib/applications/proposedRegistration/proposedRegistrationContract.ts": "0162487073c4e70dfc88179a49d6577980dcbb8a945e0a3778498e00f307b6e8", "lib/applications/proposedRegistration/projectProposedRegistration.ts": "a3075ece761fa2a419dc48bf5c6cbfd8a6b2f0dc41e4d361f2695229022203af", "lib/applications/proposedRegistration/assertProposedRegistrationReceipt.ts": "cd8c2aae288df9f245386e630fc179435db5986da9def01fa4b154a1860698c7", "lib/applications/proposedRegistration/createProposedApplicationRegistration.ts": "0322dfd63e51314cfe7bcc5d5544127291574f3c1c8152fb536a3e1c6e4afef0", @@ -23,10 +23,10 @@ }, "databaseInputs": { "proposals/application-registration-2104/protocol-composition.py": "377791d3ef4a26103bd046609d4b8dbf8f63a3d475aa2c72faeba68b553aada5", - "proposals/application-registration-2104/registration.sql": "472440d1540a79eb34255efcbc7a6286bb394e1f3779e7ed6a6b7ace33cd9074", + "proposals/application-registration-2104/registration.sql": "3377dd6f86bdf3052a2dd00b66380540764e07a763003f6a1c46192c336e6409", "proposals/application-registration-2104/parents.sql": "2a1096eadf1ee947f2b1d6bb88f5750e26436ee8ea82ae1f306a279da8b41c2d", "proposals/application-registration-2104/qualification-bootstrap.sql": "6c318540735e46c8ace40cd686bf7cc1851fb3296b5a123d29e287f94be35c05", - "proposals/application-registration-2104/test_registration.py": "ca498687ee4983767f2cf592dfd424a954fe17d0acaa04e18ae9960ed62f3a16", + "proposals/application-registration-2104/test_registration.py": "4051b2581646cea5ac2d36a23d5d5e6271dd02cbf0997e0792623289914d230c", "proposals/application-proof-2104/proposal.sql": "2cf96399422cfc1e68b0578b7aeb7b58a97c56303d85b91ee6cf862329f6c86c", "proposals/application-proof-2104/fixture.sql": "b4435b1c5546d471c33b758f1ac8a7fd8ca199071b08cc541f4cb199e6412668", "proposals/application-proof-2104/test_configuration.py": "43b686a33660dfb8bfd7b26c4827a74527cc430466567311726cb54881406cad", @@ -37,5 +37,6 @@ "proposals/application-registration-2104/sources.json": "a617bc3acc14f1cc8af2dfa951eebff0da2e406a4299c5842427f1980560e744" }, "qualification": "Disposable test-only composition; no production factory or hosted target", - "acceptedApiComposition": "a2a6d6b70644fcda5b89c5bbec281573b2dab9e9" + "acceptedApiComposition": "0769bc1957fce38bd6b847d342eae904044ae821", + "originalApiCompatibility": "784bee20b3e0fe61e67ed156c7f3a39a08a441b2" }