Finalize turn-role invariants and legacy migration cutover

This commit is contained in:
ejclaw
2026-04-10 11:44:34 +09:00
parent 7753ee46f0
commit c67bd1c622
45 changed files with 15014 additions and 1381 deletions

View File

@@ -1,7 +1,10 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { _initTestDatabase } from './db.js';
import { executeBotOnlyPairedFollowUpAction } from './message-runtime-flow.js';
import {
executeBotOnlyPairedFollowUpAction,
executePendingPairedTurn,
} from './message-runtime-flow.js';
import {
resetPairedFollowUpScheduleState,
schedulePairedFollowUpOnce,
@@ -121,3 +124,56 @@ describe('executeBotOnlyPairedFollowUpAction', () => {
);
});
});
describe('executePendingPairedTurn', () => {
it('passes the explicit pending role through as forcedRole', async () => {
const executeTurn = vi.fn(async () => ({
outputStatus: 'success' as const,
deliverySucceeded: true,
visiblePhase: 'final',
}));
const result = await executePendingPairedTurn({
pendingTurn: {
prompt: 'pending owner follow-up',
channel: {} as any,
cursor: null,
taskId: 'task-pending-owner-follow-up',
taskUpdatedAt: '2026-03-30T00:00:00.000Z',
intentKind: 'owner-follow-up',
role: 'owner',
},
chatJid: 'group@test',
group: {
name: 'Test Group',
folder: 'test-group',
trigger: '@Andy',
added_at: '2026-03-30T00:00:00.000Z',
requiresTrigger: false,
agentType: 'codex',
},
runId: 'run-pending-owner-forced-role',
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn() } as any,
saveState: vi.fn(),
lastAgentTimestamps: {},
executeTurn,
getFixedRoleChannelName: () => 'discord-review',
});
expect(result).toBe(true);
expect(executeTurn).toHaveBeenCalledWith(
expect.objectContaining({
deliveryRole: 'owner',
forcedRole: 'owner',
pairedTurnIdentity: {
turnId:
'task-pending-owner-follow-up:2026-03-30T00:00:00.000Z:owner-follow-up',
taskId: 'task-pending-owner-follow-up',
taskUpdatedAt: '2026-03-30T00:00:00.000Z',
intentKind: 'owner-follow-up',
role: 'owner',
},
}),
);
});
});