diff --git a/src/db.test.ts b/src/db.test.ts index 10d880f..ccc42b9 100644 --- a/src/db.test.ts +++ b/src/db.test.ts @@ -35,7 +35,6 @@ import { getPairedTaskById, getPairedWorkspace, getRouterStateForService, - isPairedRoomJid, getSession, getTaskById, listPairedWorkspacesForTask, @@ -796,7 +795,7 @@ describe('paired room registration', () => { ]); expect(getExplicitRoomMode('dc:123')).toBeUndefined(); expect(getEffectiveRoomMode('dc:123')).toBe('tribunal'); - expect(isPairedRoomJid('dc:123')).toBe(true); + expect(getEffectiveRuntimeRoomMode('dc:123')).toBe('tribunal'); }); it('does not mark solo rooms as paired', () => { @@ -809,7 +808,7 @@ describe('paired room registration', () => { }); expect(getRegisteredAgentTypesForJid('dc:solo')).toEqual(['claude-code']); - expect(isPairedRoomJid('dc:solo')).toBe(false); + expect(getEffectiveRuntimeRoomMode('dc:solo')).toBe('single'); }); it('keeps inferred room mode available when no explicit override exists', () => { @@ -831,7 +830,6 @@ describe('paired room registration', () => { expect(getExplicitRoomMode('dc:legacy-paired')).toBeUndefined(); expect(getEffectiveRoomMode('dc:legacy-paired')).toBe('tribunal'); expect(getEffectiveRuntimeRoomMode('dc:legacy-paired')).toBe('tribunal'); - expect(isPairedRoomJid('dc:legacy-paired')).toBe(true); }); it('backfills inferred room modes for legacy SQL rows missing room_settings', () => { @@ -899,7 +897,6 @@ describe('paired room registration', () => { expect(getExplicitRoomMode('dc:legacy-sql')).toBeUndefined(); expect(getEffectiveRoomMode('dc:legacy-sql')).toBe('tribunal'); expect(getEffectiveRuntimeRoomMode('dc:legacy-sql')).toBe('tribunal'); - expect(isPairedRoomJid('dc:legacy-sql')).toBe(true); }); it('lets explicit single override dual registration for paired-room checks', () => { @@ -923,7 +920,6 @@ describe('paired room registration', () => { expect(getExplicitRoomMode('dc:explicit-single')).toBe('single'); expect(getEffectiveRoomMode('dc:explicit-single')).toBe('single'); expect(getEffectiveRuntimeRoomMode('dc:explicit-single')).toBe('single'); - expect(isPairedRoomJid('dc:explicit-single')).toBe(false); }); it('lets explicit tribunal become runnable when the configured reviewer can run on the solo registration', () => { @@ -944,14 +940,12 @@ describe('paired room registration', () => { expect(getEffectiveRuntimeRoomMode('dc:explicit-tribunal')).toBe( 'tribunal', ); - expect(isPairedRoomJid('dc:explicit-tribunal')).toBe(true); clearExplicitRoomMode('dc:explicit-tribunal'); expect(getExplicitRoomMode('dc:explicit-tribunal')).toBeUndefined(); expect(getEffectiveRoomMode('dc:explicit-tribunal')).toBe('single'); expect(getEffectiveRuntimeRoomMode('dc:explicit-tribunal')).toBe('single'); - expect(isPairedRoomJid('dc:explicit-tribunal')).toBe(false); }); it('keeps explicit tribunal non-runnable when the configured reviewer service is unavailable', () => { @@ -969,7 +963,6 @@ describe('paired room registration', () => { expect(getEffectiveRuntimeRoomMode('dc:explicit-tribunal-codex')).toBe( 'single', ); - expect(isPairedRoomJid('dc:explicit-tribunal-codex')).toBe(false); }); }); diff --git a/src/db.ts b/src/db.ts index 1cfd03a..d389576 100644 --- a/src/db.ts +++ b/src/db.ts @@ -1974,7 +1974,12 @@ export function inferRoomModeFromRegisteredAgentTypes( return types.has('claude-code') && types.has('codex') ? 'tribunal' : 'single'; } -export function inferRoomModeForJid(jid: string): RoomMode { +/** + * Internal registration/backfill helper. + * This infers the stored room mode from current registrations and must not be + * treated as runtime source-of-truth by callers. + */ +function inferStoredRoomModeForJid(jid: string): RoomMode { return inferRoomModeFromRegisteredAgentTypes( getRegisteredAgentTypesForJid(jid), ); @@ -2022,7 +2027,7 @@ function upsertStoredRoomMode( } function syncInferredRoomModeForJid(chatJid: string): void { - upsertStoredRoomMode(chatJid, inferRoomModeForJid(chatJid), 'inferred'); + upsertStoredRoomMode(chatJid, inferStoredRoomModeForJid(chatJid), 'inferred'); } export function getExplicitRoomMode(chatJid: string): RoomMode | undefined { @@ -2070,10 +2075,6 @@ export function getEffectiveRuntimeRoomMode(chatJid: string): RoomMode { : 'single'; } -export function isPairedRoomJid(jid: string): boolean { - return getEffectiveRuntimeRoomMode(jid) === 'tribunal'; -} - function backfillStoredRoomModes(database: Database): void { const rows = database .prepare( diff --git a/src/duplicate-suppression.test.ts b/src/duplicate-suppression.test.ts index 3fe2379..af938af 100644 --- a/src/duplicate-suppression.test.ts +++ b/src/duplicate-suppression.test.ts @@ -7,11 +7,11 @@ import { createProducedWorkItem, getOpenWorkItem, setRegisteredGroup, - isPairedRoomJid, getLastBotFinalMessage, markWorkItemDelivered, } from './db.js'; import { normalizeMessageForDedupe } from './router.js'; +import { hasReviewerLease } from './service-routing.js'; import { isDuplicateOfLastBotFinal } from './message-runtime.js'; beforeEach(() => { @@ -52,7 +52,7 @@ const setupChat = (jid: string) => { ); }; -describe('isPairedRoomJid', () => { +describe('hasReviewerLease', () => { it('returns true when both claude-code and codex are registered', () => { const jid = 'dc:paired-room'; @@ -72,7 +72,7 @@ describe('isPairedRoomJid', () => { agentType: 'codex', }); - expect(isPairedRoomJid(jid)).toBe(true); + expect(hasReviewerLease(jid)).toBe(true); }); it('returns false when only claude-code is registered', () => { @@ -86,7 +86,7 @@ describe('isPairedRoomJid', () => { agentType: 'claude-code', }); - expect(isPairedRoomJid(jid)).toBe(false); + expect(hasReviewerLease(jid)).toBe(false); }); it('returns false when only codex is registered', () => { @@ -100,7 +100,7 @@ describe('isPairedRoomJid', () => { agentType: 'codex', }); - expect(isPairedRoomJid(jid)).toBe(false); + expect(hasReviewerLease(jid)).toBe(false); }); }); @@ -209,7 +209,7 @@ describe('isDuplicateOfLastBotFinal (runtime function)', () => { ); // Verify it's a paired room - expect(isPairedRoomJid(jid)).toBe(true); + expect(hasReviewerLease(jid)).toBe(true); // Verify duplicate detection works via the actual runtime function expect( @@ -246,7 +246,7 @@ describe('isDuplicateOfLastBotFinal (runtime function)', () => { ); // Verify it's NOT a paired room - expect(isPairedRoomJid(jid)).toBe(false); + expect(hasReviewerLease(jid)).toBe(false); // Duplicate check should be bypassed (return false) expect(isDuplicateOfLastBotFinal(jid, 'DONE — Task completed')).toBe(false);