Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(trust): the owner-actions stub supersede_fact handler is restored after its test (registerTrustProposalHandler returns the restore); a later file in the same bun process got the stub and accepted supersessions without applying them (shard 3: trust-owner-actions at 107, trust-guarded-supersession at 126). Forced probe: the two files in one bun test fail 2 before, pass 25 after

garrytana6591343299e
diff --git a/src/core/trust/proposals.ts b/src/core/trust/proposals.ts
index 6fde12ba35..b559eb6bfc 100644
--- a/src/core/trust/proposals.ts
+++ b/src/core/trust/proposals.ts
@@ -195,8 +195,11 @@ export interface TrustProposalHandler {
}
const handlers = new Map<TrustProposalAction, TrustProposalHandler>();
-export function registerTrustProposalHandler(action: TrustProposalAction, handler: TrustProposalHandler): void {
+/** Registers the handler for an action; returns the call that puts the previous registration back (a test stub must restore it: the registry is process-global). */
+export function registerTrustProposalHandler(action: TrustProposalAction, handler: TrustProposalHandler): () => void {
+ const previous = handlers.get(action);
handlers.set(action, handler);
+ return () => { if (previous) handlers.set(action, previous); else handlers.delete(action); };
}
/**
diff --git a/test/trust-owner-actions.test.ts b/test/trust-owner-actions.test.ts
index 191de51bcb..4121a1a229 100644
--- a/test/trust-owner-actions.test.ts
+++ b/test/trust-owner-actions.test.ts
@@ -271,22 +271,26 @@ describe('trust proposals through the owner (ENG-4, CEO-12)', () => {
const { id } = await engine.transaction(tx => insertTrustProposal(tx, { action: 'supersede_fact', sourceId: b.sourceId,
target: { table: 'facts', id: oldId }, related: { table: 'facts', id: newId }, before: { prior_tier: 'user_confirmed' }, after: { tier: 'agent_written' }, proposer: 'remember.replaces' }));
const calls: unknown[] = [];
- registerTrustProposalHandler('supersede_fact', {
+ // The handler registry is process-global: the real supersede_fact handler comes back after this test, or every
+ // later file in the same `bun test` process (shard order decides which) accepts supersessions without applying them.
+ const restoreHandler = registerTrustProposalHandler('supersede_fact', {
async accept(e, proposal, ctx) {
calls.push(ctx.confirmation);
await transitionTrustProposal(e, proposal.id, 'pending', 'accepted');
return decisionResult(proposal, 'accept', 'accepted');
},
});
- nonTty();
- expect((await failure(ownerDo(b, { action: 'confirm', ref: `tp${id}` }))).code).toBe('confirmation_required');
- expect(calls).toHaveLength(0);
- tty('wrong');
- expect((await failure(ownerDo(b, { action: 'confirm', ref: `tp${id}` }))).code).toBe('confirmation_required');
- tty(`tp${id}`);
- expect(await ownerDo(b, { action: 'confirm', ref: `tp${id}` })).toMatchObject({ status: 'accepted' });
- expect(calls).toEqual([{ via: 'tty' }]);
- expect((await failure(ownerDo(b, { action: 'confirm', ref: `tp${id}` }))).code).toBe('invalid_params');
+ try {
+ nonTty();
+ expect((await failure(ownerDo(b, { action: 'confirm', ref: `tp${id}` }))).code).toBe('confirmation_required');
+ expect(calls).toHaveLength(0);
+ tty('wrong');
+ expect((await failure(ownerDo(b, { action: 'confirm', ref: `tp${id}` }))).code).toBe('confirmation_required');
+ tty(`tp${id}`);
+ expect(await ownerDo(b, { action: 'confirm', ref: `tp${id}` })).toMatchObject({ status: 'accepted' });
+ expect(calls).toEqual([{ via: 'tty' }]);
+ expect((await failure(ownerDo(b, { action: 'confirm', ref: `tp${id}` }))).code).toBe('invalid_params');
+ } finally { restoreHandler(); }
}), 60_000);
});