Skip to content

ui-server: the governance-policy tests record policy with their own copy of createApp's INSERT #2758

Closed

Description

@schlessera

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 tests

Scope

  • Move the recorder into one named function in packages/ui-server/src (for example beside createGovernancePolicyReader in src/brain/governance-policy.ts), taking the UI database and returning the recordPolicy callback.
  • createApp and tests/governance-policy.test.ts both use that function. The test may still inject a fixed clock if it needs a deterministic admitted_at; it must not restate the SQL.

Out of scope

Acceptance criteria

  • git grep -n "INSERT INTO turn_governance_policy" -- packages tests finds exactly one site, in packages/ui-server/src.
  • createApp and tests/governance-policy.test.ts call the same exported recorder.
  • Mutation receipt in the PR: dropping the errors value (or another recorded column) from the production recorder makes a named governance-policy.test.ts assertion fail; restoring it passes.
  • bun run test packages/ui-server/tests/governance-policy.test.ts and bun run typecheck pass.

Verification

git grep -n "INSERT INTO turn_governance_policy" -- packages tests
bun run test packages/ui-server/tests/governance-policy.test.ts
bun run typecheck

Contract 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

  1. added
    type: test
    area: ui-server
    priority: p2
    agent-ready
    on Oct 24, 2026
  2. added this to the 0.45.0 milestone on Nov 10, 2026
  3. schlessera commented on Nov 11, 2026

    @schlessera
    OwnerAuthor

    Mutation receipt, which #3961's body did not carry. Run on the epic tip da8b092b7: in recordPolicy (packages/ui-server/src/brain/governed-turn-writes.ts), I replaced the recorded errors value with "[]". bun run test packages/ui-server/tests/governance-policy.test.ts then failed 25 pass / 1 fail on invalid 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 tests finds the one site, packages/ui-server/src/brain/governed-turn-writes.ts:21. This issue closes once the epic's shake-out runs pass.

  4. schlessera commented on Nov 11, 2026

    @schlessera
    OwnerAuthor

    Delivered by #3961, which merged into epic/3855-test-health as ef36102bf (the push in #3855). It landed in the combined merge without proof of its own; the gate, typecheck and check:pr passed on the combined branch. The epic's two exhaustive runs on dc2439551, 42996974186 and 42997012467, then passed. GitHub does not apply Closes for a pull request into a non-default branch, so I'm closing this by hand. The change reaches main with the epic's single landing pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-serverpriority: p2type: test

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions