Repository navigation
Description
Part of #2540.
Context
createApp records each turn's governance policy with an inline statement passed as recordPolicy to createGovernedTurns (packages/ui-server/src/app.ts:571-575):
recordPolicy: (turnId, origin, profile, policy) => db.query(`INSERT INTO turn_governance_policy
(turn_id, origin, profile, policy_hash, source, policy, errors, admitted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)packages/ui-server/tests/governance-policy.test.ts:39-41 builds its fixture with its own copy of that statement, and its assertions then read turn_governance_policy back (:62, :79, :126). A change to the production recorder (a dropped column, a different admitted_at, a renamed origin) cannot fail these tests: they test the copy. governedTurns calls the recorder at packages/ui-server/src/brain/governed-turn.ts:156.
git grep -n "INSERT INTO turn_governance_policy" -- packages testsScope
- Move the recorder into one named function in
packages/ui-server/src(for example besidecreateGovernancePolicyReaderinsrc/brain/governance-policy.ts), taking the UI database and returning therecordPolicycallback. createAppandtests/governance-policy.test.tsboth use that function. The test may still inject a fixed clock if it needs a deterministicadmitted_at; it must not restate the SQL.
Out of scope
- Changing the
turn_governance_policyschema, what is recorded or when. - The other governance-policy test assertions, and the rest of
createApp(ui-server: createApp's boot-failure cleanup skips the storage cache and history flush that close() performs #2514 and its refactor follow-up).
Acceptance criteria
-
git grep -n "INSERT INTO turn_governance_policy" -- packages testsfinds exactly one site, inpackages/ui-server/src. -
createAppandtests/governance-policy.test.tscall the same exported recorder. - Mutation receipt in the PR: dropping the
errorsvalue (or another recorded column) from the production recorder makes a namedgovernance-policy.test.tsassertion fail; restoring it passes. -
bun run test packages/ui-server/tests/governance-policy.test.tsandbun run typecheckpass.
Verification
git grep -n "INSERT INTO turn_governance_policy" -- packages tests
bun run test packages/ui-server/tests/governance-policy.test.ts
bun run typecheckContract impact
None. Internal to @schlessera/brain-ui-server; no entry export, wire or schema change.
2026-10-24: filed from #2540's shared-context finding, which no child owned.
Activity
schlessera commentedon Nov 11, 2026
Mutation receipt, which #3961's body did not carry. Run on the epic tip
da8b092b7: inrecordPolicy(packages/ui-server/src/brain/governed-turn-writes.ts), I replaced the recordederrorsvalue with"[]".bun run test packages/ui-server/tests/governance-policy.test.tsthen failed 25 pass / 1 fail oninvalid edits retain the last actual policy/hash and record the validation notice; invalid-first uses defaults(toBeGreaterThan). After restoring the line it passed 26 / 0.git grep -n "INSERT INTO turn_governance_policy" -- packages testsfinds the one site,packages/ui-server/src/brain/governed-turn-writes.ts:21. This issue closes once the epic's shake-out runs pass.schlessera commentedon Nov 11, 2026
Delivered by #3961, which merged into
epic/3855-test-healthasef36102bf(the push in #3855). It landed in the combined merge without proof of its own; the gate, typecheck andcheck:prpassed on the combined branch. The epic's two exhaustive runs ondc2439551, 42996974186 and 42997012467, then passed. GitHub does not applyClosesfor a pull request into a non-default branch, so I'm closing this by hand. The change reachesmainwith the epic's single landing pull request.