Skip to content

Commit 7d5a78c

Browse files
committed
test(server): assert the Codex thread id on resume and fork
Replay ignores this config key, so resume and fork had no coverage of it. The harness now observes raw client requests too.
1 parent c99e933 commit 7d5a78c

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ const CODEX_TEST_RUNTIME_POLICY = ProviderAdapter.ProviderAdapterV2RuntimePolicy
486486
interactionMode: "default",
487487
cwd: "/workspace",
488488
});
489+
const T3_THREAD_ENV_KEY = "shell_environment_policy.set.T3CODE_THREAD_ID";
490+
const threadEnvOf = (params: unknown) =>
491+
Predicate.hasProperty(params, "config") && Predicate.hasProperty(params.config, T3_THREAD_ENV_KEY)
492+
? params.config[T3_THREAD_ENV_KEY]
493+
: undefined;
489494

490495
function makeCodexTestAppThread(input: {
491496
readonly threadId: ThreadId;
@@ -1180,6 +1185,13 @@ describe("CodexAdapterV2 post-settle continuation", () => {
11801185
onRequest(method, params).pipe(
11811186
Effect.andThen(client.request(method, params)),
11821187
),
1188+
raw: {
1189+
...client.raw,
1190+
request: (method, params) =>
1191+
onRequest(method, params).pipe(
1192+
Effect.andThen(client.raw.request(method, params)),
1193+
),
1194+
},
11831195
}) satisfies CodexClient.CodexAppServerClient["Service"],
11841196
),
11851197
Effect.provide(context),
@@ -2399,18 +2411,50 @@ describe("CodexAdapterV2 post-settle continuation", () => {
23992411
label: "thread/resume",
24002412
frame: { id: 3, result: { thread: { id: nativeThreadId, updatedAt: 1782622450 } } },
24012413
},
2414+
{
2415+
type: "expect_outbound",
2416+
label: "thread/resume without an app thread",
2417+
frame: {
2418+
id: 4,
2419+
method: "thread/resume",
2420+
params: {
2421+
threadId: nativeThreadId,
2422+
excludeTurns: true,
2423+
config: CodexAdapterV2.CODEX_THREAD_CONFIG,
2424+
},
2425+
},
2426+
},
2427+
{
2428+
type: "emit_inbound",
2429+
label: "thread/resume without an app thread",
2430+
frame: { id: 4, result: { thread: { id: nativeThreadId, updatedAt: 1782622450 } } },
2431+
},
24022432
],
24032433
});
2404-
const harness = yield* makeCodexReplayHarness(transcript);
2434+
const resumeThreadEnvs: Array<unknown> = [];
2435+
const harness = yield* makeCodexReplayHarness(
2436+
transcript,
2437+
() => Effect.void,
2438+
(method, params) =>
2439+
Effect.sync(() => {
2440+
if (method === "thread/resume") resumeThreadEnvs.push(threadEnvOf(params));
2441+
}),
2442+
);
24052443
const resumed = yield* harness.runtime.resumeThread({
24062444
providerThread: harness.providerThread,
24072445
modelSelection: CODEX_TEST_MODEL_SELECTION,
24082446
runtimePolicy: CODEX_TEST_RUNTIME_POLICY,
24092447
});
2448+
yield* harness.runtime.resumeThread({
2449+
providerThread: { ...harness.providerThread, appThreadId: null },
2450+
modelSelection: CODEX_TEST_MODEL_SELECTION,
2451+
runtimePolicy: CODEX_TEST_RUNTIME_POLICY,
2452+
});
24102453

24112454
assert.equal(resumed.nativeThreadRef?.nativeId, nativeThreadId);
24122455
assert.equal(resumed.status, "idle");
24132456
assert.equal(DateTime.toEpochMillis(resumed.updatedAt), 1782622450000);
2457+
assert.deepEqual(resumeThreadEnvs, [harness.threadId, undefined]);
24142458
}).pipe(
24152459
Effect.provide(
24162460
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
@@ -7380,12 +7424,14 @@ describe("CodexAdapterV2 post-settle continuation", () => {
73807424
],
73817425
});
73827426
const outbound: Array<string> = [];
7427+
const forkThreadEnvs: Array<unknown> = [];
73837428
const harness = yield* makeCodexReplayHarness(
73847429
transcript,
73857430
() => Effect.void,
7386-
(method) =>
7431+
(method, params) =>
73877432
Effect.sync(() => {
73887433
outbound.push(method);
7434+
if (method === "thread/fork") forkThreadEnvs.push(threadEnvOf(params));
73897435
}),
73907436
);
73917437
const now = yield* DateTime.now;
@@ -7415,6 +7461,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
74157461
assert.notEqual(forkedProviderThread.id, harness.providerThread.id);
74167462
assert.equal(forkedProviderThread.forkedFrom?.providerTurnId, firstTurn.id);
74177463
assert.deepEqual(outbound.slice(-2), ["thread/turns/list", "thread/revert"]);
7464+
assert.deepEqual(forkThreadEnvs, ["thread-fork-paginated-fallback-target"]);
74187465
}).pipe(
74197466
Effect.scoped,
74207467
Effect.provide(

0 commit comments

Comments
 (0)