test(runner): allow accepted plan ACPX session resets

This commit is contained in:
Dotta 2026-09-03 08:34:08 -05:00
parent 41a96da703
commit f9f798f320
3 changed files with 68 additions and 17 deletions

View File

@ -15,6 +15,37 @@ export interface ObservableProviderSessionRun {
contextSnapshot?: Record<string, unknown> | null;
}
export function acceptedPlanSessionResetFailures(
provider: "codex" | "opencode" | "acpx",
previousSessionId: string | null | undefined,
current: ObservableProviderSessionRun,
): string[] | null {
const context = record(current.contextSnapshot);
const acceptedPlanReset =
context.forceFreshSession === true &&
context.workspaceRefreshReason === "accepted_plan_confirmation" &&
context.source === "issue.interaction.accept" &&
context.interactionStatus === "accepted";
if (!acceptedPlanReset) return null;
const failures: string[] = [];
if (current.sessionIdBefore) {
failures.push(
`expected accepted Plan run ${current.id} to start without a prior provider session`,
);
}
if (
previousSessionId &&
current.sessionIdAfter &&
current.sessionIdAfter === previousSessionId
) {
failures.push(
`expected accepted Plan run ${current.id} to rotate the ${provider} provider session`,
);
}
return failures;
}
function record(value: unknown): Record<string, unknown> {
return value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
@ -89,23 +120,13 @@ export function providerSessionContinuityFailures(
if (index === 0) continue;
const previousSessionId = runs[index - 1]?.sessionIdAfter;
const context = record(current.contextSnapshot);
const acceptedPlanReset =
context.forceFreshSession === true &&
context.workspaceRefreshReason === "accepted_plan_confirmation" &&
context.source === "issue.interaction.accept" &&
context.interactionStatus === "accepted";
if (acceptedPlanReset) {
if (current.sessionIdBefore) {
failures.push(
`expected accepted Plan run ${current.id} to start without a prior provider session`,
);
}
if (previousSessionId && currentSessionId === previousSessionId) {
failures.push(
`expected accepted Plan run ${current.id} to rotate the ${provider} provider session`,
);
}
const acceptedPlanResetFailures = acceptedPlanSessionResetFailures(
provider,
previousSessionId,
current,
);
if (acceptedPlanResetFailures) {
failures.push(...acceptedPlanResetFailures);
continue;
}

View File

@ -10,6 +10,7 @@ import { runnerE2EServerControlPaths } from "./harness-env.js";
import { setupLiveFixtures, type LiveFixtureValues } from "./live-fixtures.js";
import { evaluateMatcher, type MatcherResult } from "./matchers.js";
import {
acceptedPlanSessionResetFailures,
isControlPlaneGovernedResponseWait,
isNonExecutingReviewFenceRun,
numberedPlanStepCount,
@ -1542,6 +1543,16 @@ for (const execution of executions) {
);
continue;
}
const acceptedPlanResetFailures =
acceptedPlanSessionResetFailures(
"acpx",
previousSessionId,
current,
);
if (acceptedPlanResetFailures) {
invariantFailures.push(...acceptedPlanResetFailures);
continue;
}
if (previousSessionId === currentSessionId) continue;
const currentEvents =
runEventsByRun.find((captured) => captured.runId === current.id)

View File

@ -8,6 +8,7 @@ import { RunnerApi } from "./api.js";
import { FixtureRegistry } from "./fixture-registry.js";
import { classifyFailure, shouldRetryFailure } from "./failure-classifier.js";
import {
acceptedPlanSessionResetFailures,
assertIsolatedServerEnvironment,
buildPaperclipServerEnvironment,
resolvePaperclipRunnerBinaryForHarness,
@ -415,6 +416,24 @@ describe("runner E2E run observations", () => {
).toEqual([
"expected codex to preserve its provider session for run resumed",
]);
expect(
acceptedPlanSessionResetFailures(
"acpx",
initial.sessionIdAfter,
acceptedPlan,
),
).toEqual([]);
expect(
acceptedPlanSessionResetFailures("acpx", initial.sessionIdAfter, {
...acceptedPlan,
sessionIdBefore: initial.sessionIdAfter,
}),
).toEqual([
"expected accepted Plan run accepted-plan to start without a prior provider session",
]);
expect(
acceptedPlanSessionResetFailures("acpx", initial.sessionIdAfter, resumed),
).toBeNull();
});
});