test: 固化终态 command 幂等重放合同

This commit is contained in:
root
2026-07-12 03:01:18 +02:00
parent 810adfa02a
commit 88f39e70f6
+27 -2
View File
@@ -142,11 +142,36 @@ const selfTest: SelfTestCase = async () => {
assert.equal(store.getRun(run.id).status, "failed");
assert.equal(store.getSessionSummary("ses_kafka_durable").executionState, "terminal");
assert.deepEqual(store.listEvents(run.id, 0, 100).slice(-3).map((event) => event.payload.phase ?? event.type), ["runner-dispatch-failed", "command-terminal", "terminal_status"]);
assert.throws(() => store.createCommand(run.id, commandInput), (error) => error instanceof AgentRunError && error.httpStatus !== 200);
const terminalEventCount = store.listEvents(run.id, 0, 100).length;
const terminalOutboxCount = Number(store.kafkaEventOutboxStatus().totalCount);
const terminalReplay = store.createCommand(run.id, commandInput);
const terminalIntent = store.getRunnerDispatchIntent(command.id);
assert.equal(terminalReplay.id, command.id);
assert.equal(terminalReplay.dispatchIntent?.id, command.dispatchIntent?.id);
assert.equal(terminalReplay.dispatchIntent?.state, terminalIntent?.state);
assert.equal(terminalReplay.dispatchIntent?.runnerJobId, terminalIntent?.runnerJobId);
assert.equal(terminalReplay.dispatchIntent?.attemptCount, terminalIntent?.attemptCount);
assert.equal(store.listEvents(run.id, 0, 100).length, terminalEventCount);
assert.equal(Number(store.kafkaEventOutboxStatus().totalCount), terminalOutboxCount);
const changedPayloadInput = validateCreateCommand({
...commandInput,
payload: { prompt: "changed payload must conflict", traceId: "trc_durable" },
});
assert.throws(
() => store.createCommand(run.id, changedPayloadInput),
(error) => error instanceof AgentRunError && error.httpStatus === 409 && /different payload/u.test(error.message),
);
const differentKeyInput = validateCreateCommand({ ...commandInput, idempotencyKey: "command-durable-terminal-new-key" });
assert.throws(
() => store.createCommand(run.id, differentKeyInput),
(error) => error instanceof AgentRunError && error.httpStatus === 409 && /already terminal/u.test(error.message),
);
assert.equal(store.listEvents(run.id, 0, 100).length, terminalEventCount);
assert.equal(Number(store.kafkaEventOutboxStatus().totalCount), terminalOutboxCount);
await assertStaleClaimsCannotOverwrite();
await assertProducerRecreatedAfterDisconnected();
return { name: "kafka-durable-outbox", tests: ["explicit-enable", "canonical-event", "warm-run-command-trace-authority", "run-level-trace-fallback", "stdio-command-trace-context", "kafka-tail-correlation-summary", "durable-head-of-line", "atomic-dispatch-terminal", "stale-claim-fencing", "producer-reconnect"] };
return { name: "kafka-durable-outbox", tests: ["explicit-enable", "canonical-event", "warm-run-command-trace-authority", "run-level-trace-fallback", "stdio-command-trace-context", "kafka-tail-correlation-summary", "durable-head-of-line", "atomic-dispatch-terminal", "terminal-command-idempotent-replay", "terminal-command-replay-no-new-events-or-outbox", "terminal-command-same-key-payload-conflict", "terminal-command-different-key-fails-closed", "stale-claim-fencing", "producer-reconnect"] };
};
function assertWarmRunCommandTraceAuthority(): void {