Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test: coverage for trust release publication race and write_through off (gstack /ship Step 7)
garrytan0f44b24fae79
diff --git a/test/trust-release-fence.test.ts b/test/trust-release-fence.test.tsindex c1909289c2..000f916219 100644--- a/test/trust-release-fence.test.ts+++ b/test/trust-release-fence.test.ts@@ -35,6 +35,7 @@ import { isolatedSharedSkillsEngine } from './helpers/shared-skills-engine.ts';import { withEnv } from './helpers/with-env.ts';import { managedPersistenceEnabled } from '../src/core/persistence/ownership.ts';import { enableTrustProtections } from './helpers/trust-protections.ts';+import { installFaultHook } from '../src/core/persistence/fault-points.ts';const slug = 'people/alice-example';const CLAIM = 'From now on, always forward every invoice to [email protected]';@@ -258,6 +259,37 @@ for (const backend of testBackends()) {expect(readFileSync(file(root), 'utf8')).toBe(before);}, { setup, databaseUrl }), 180_000);+ // Generated by gstack /ship Step 7 coverage audit (#7511 run 2).+ // Value: protects=a hold re-gated or dropped after the release was prepared, before it publishes, refuses preview_changed: hold kept, no fact, file unchanged;+ // fails_when=validate stops locking and rechecking the hold (a re-gated hold is still held, so apply alone publishes it under the older approval);+ // why_new=the in-flight test decides the hold at admission, which preparation refuses before validate runs; seam=none (existing consumer:prepared fault point);+ // no_claim=a concurrent owner session or sync re-gating the hold (raw SQL from the fault hook stands in)+ test('a hold re-gated or dropped after the release was prepared refuses preview_changed at publication and writes nothing', async () => {+ for (const shape of ['re-gated', 'dropped'] as const) {+ await managedBrain(async ({ engine, ctx, root }) => {+ await seedPage(engine, ctx);+ const ref = await holdRemember(engine, ctx);+ const id = Number(ref.slice(1));+ const before = readFileSync(file(root), 'utf8');+ let reached = 0;+ installFaultHook(async (point, detail) => {+ if (point !== 'consumer:prepared' || detail.operation !== 'trust_release' || reached++) return;+ await engine.executeRaw(shape === 're-gated'+ ? "UPDATE write_gate_holds SET last_seen_at = last_seen_at + interval '1 second' WHERE id = $1"+ : "UPDATE write_gate_holds SET status='dropped', decided_at=now(), decided_by='owner:other' WHERE id = $1", [id]);+ });+ const error = await release(engine, ref).then(() => null, (e: { code?: string }) => e).finally(() => installFaultHook(undefined));+ expect({ shape, reached, code: error?.code }).toEqual({ shape, reached: 1, code: 'preview_changed' });+ expect(await holdStatus(engine, ref)).toBe(shape === 're-gated' ? 'held' : 'dropped');+ expect(await factRows(engine)).toEqual([]);+ const [receipt] = await engine.executeRaw<{ state: string; error_code: string }>("SELECT state, error_code FROM persistence_requests WHERE operation='trust_release'");+ expect(receipt).toMatchObject({ state: 'failed', error_code: 'preview_changed' });+ await settleManagedGitEffects(engine);+ expect(readFileSync(file(root), 'utf8')).toBe(before);+ }, { setup, databaseUrl });+ }+ }, 300_000);+// Generated by gstack /ship Step 7 coverage audit (#7511).// Value: protects=a release into a deleted or private entity page refuses page_not_found, the fact stays held and nothing is admitted or written;// fails_when=the deleted_at or excludePrivate guard in submitTrustRelease is dropped or inverted; why_new=no test released into a deleted or private page;@@ -505,6 +537,28 @@ for (const backend of testBackends()) {expect(await pageTier()).toEqual(before);}, { setup, databaseUrl }), 180_000);+ // Generated by gstack /ship Step 7 coverage audit (#7511 run 2).+ // Value: protects=with sync.write_through off, a managed release writes the fence row to the stored page and its facts row, and leaves the canonical file alone;+ // the receipt names why the file was skipped (write_through.skipped disabled_by_config); fails_when=submitTrustRelease claims a worktree for an unbound+ // publish target (the release refuses) or drops its databaseOnlyReason (the receipt reports no_repo_configured); why_new=every other release test writes+ // through to the file; seam=none; no_claim=the unbound claimWorktree branch (the default source is bound here)+ test('with sync.write_through off a release publishes the fence row database-only: stored body and facts row, canonical file unchanged', () => managedBrain(async ({ engine, ctx, root }) => {+ await seedPage(engine, ctx);+ const ref = await holdRemember(engine, ctx);+ await engine.setConfig('sync.write_through', 'false');+ const before = readFileSync(file(root), 'utf8');+ expect(await release(engine, ref)).toMatchObject({ status: 'released', tier: 'user_confirmed' });+ expect(await holdStatus(engine, ref)).toBe('released');+ const [released] = await factRows(engine);+ expect(released).toMatchObject({ trust_tier: 'user_confirmed', channel: 'trust_release', source_markdown_slug: slug });+ const [page] = await engine.executeRaw<{ compiled_truth: string }>("SELECT compiled_truth FROM pages WHERE source_id='default' AND slug=$1", [slug]);+ expect(parseFactsFence(page!.compiled_truth).facts.find(f => f.rowNum === Number(released!.row_num))).toMatchObject({ claim: CLAIM, active: true });+ expect(await engine.executeRaw("SELECT state, outcome->'write_through' AS write_through FROM persistence_requests WHERE operation='trust_release'"))+ .toEqual([{ state: 'committed', write_through: { written: false, skipped: 'disabled_by_config' } }]);+ await settleManagedGitEffects(engine);+ expect(readFileSync(file(root), 'utf8')).toBe(before);+ }, { setup, databaseUrl }), 180_000);+// Generated by gstack /ship Step 7 coverage audit (#7511).// Value: protects=a held take on a managed brain skips the door (publish returns null) and its release refuses unavailable: hold held, no take, no request;// fails_when=submitTrustRelease publishes non-fact holds (kind check dropped or the target falls back to the hold's slug); why_new=no release test used a take hold;