fix: block stale paired IPC and duplicate finalize turns
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { _initTestDatabase } from './db.js';
|
||||
import { _initTestDatabase, createPairedTask } from './db.js';
|
||||
import {
|
||||
executeBotOnlyPairedFollowUpAction,
|
||||
executePendingPairedTurn,
|
||||
} from './message-runtime-flow.js';
|
||||
import {
|
||||
claimPairedTurnExecution,
|
||||
resetPairedFollowUpScheduleState,
|
||||
schedulePairedFollowUpOnce,
|
||||
type ScheduledPairedFollowUpIntentKind,
|
||||
@@ -123,6 +124,79 @@ describe('executeBotOnlyPairedFollowUpAction', () => {
|
||||
'Skipped duplicate paired pending turn requeue while task state was unchanged',
|
||||
);
|
||||
});
|
||||
|
||||
it('skips inline finalize when the same finalize-owner turn revision was already claimed elsewhere', async () => {
|
||||
const task: PairedTask = {
|
||||
id: 'task-inline-finalize-dedup',
|
||||
chat_jid: 'group@test',
|
||||
group_folder: 'test-group',
|
||||
owner_service_id: 'claude',
|
||||
reviewer_service_id: 'codex-main',
|
||||
title: null,
|
||||
source_ref: 'HEAD',
|
||||
plan_notes: null,
|
||||
review_requested_at: '2026-03-30T00:00:00.000Z',
|
||||
round_trip_count: 1,
|
||||
status: 'merge_ready',
|
||||
arbiter_verdict: null,
|
||||
arbiter_requested_at: null,
|
||||
completion_reason: null,
|
||||
created_at: '2026-03-30T00:00:00.000Z',
|
||||
updated_at: '2026-03-30T00:05:00.000Z',
|
||||
};
|
||||
const executeTurn = vi.fn();
|
||||
const log = {
|
||||
info: vi.fn(),
|
||||
} as any;
|
||||
|
||||
createPairedTask(task as any);
|
||||
|
||||
expect(
|
||||
claimPairedTurnExecution({
|
||||
chatJid: 'group@test',
|
||||
runId: 'run-existing-finalize-owner',
|
||||
task,
|
||||
intentKind: 'finalize-owner-turn',
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
const result = await executeBotOnlyPairedFollowUpAction({
|
||||
action: {
|
||||
kind: 'inline-finalize',
|
||||
task,
|
||||
cursor: 42,
|
||||
},
|
||||
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-inline-finalize',
|
||||
channel: {} as any,
|
||||
log,
|
||||
saveState: vi.fn(),
|
||||
lastAgentTimestamps: {},
|
||||
executeTurn,
|
||||
schedulePairedFollowUp: vi.fn(() => true),
|
||||
closeStdin: vi.fn(),
|
||||
});
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(executeTurn).not.toHaveBeenCalled();
|
||||
expect(log.info).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
chatJid: 'group@test',
|
||||
taskId: 'task-inline-finalize-dedup',
|
||||
taskStatus: 'merge_ready',
|
||||
handoffMode: 'inline-finalize',
|
||||
}),
|
||||
'Skipped inline merge_ready finalize because the task revision was already claimed elsewhere',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('executePendingPairedTurn', () => {
|
||||
|
||||
Reference in New Issue
Block a user