@@ -1284,6 +1284,96 @@ describe("ClaudeAdapterV2 executable path", () => {
12841284 );
12851285});
12861286
1287+ describe("ClaudeAdapterV2 resumeThread", () => {
1288+ it.effect("fails for a transcript without messages so a fresh session replaces it", () =>
1289+ Effect.scoped(
1290+ Effect.gen(function* () {
1291+ const fileSystem = yield* FileSystem.FileSystem;
1292+ const path = yield* Path.Path;
1293+ const configDir = yield* fileSystem.makeTempDirectoryScoped({
1294+ prefix: "t3-claude-empty-session-",
1295+ });
1296+ const projectDir = path.join(configDir, "projects", "-workspace");
1297+ yield* fileSystem.makeDirectory(projectDir, { recursive: true });
1298+ // What a CLI stopped before it saved the first prompt leaves behind.
1299+ yield* fileSystem.writeFileString(
1300+ path.join(projectDir, "native-thread-empty.jsonl"),
1301+ [
1302+ `{"type":"last-prompt","lastPrompt":"hello","sessionId":"native-thread-empty"}`,
1303+ `{"type":"atis-latch","atis":"","sessionId":"native-thread-empty"}`,
1304+ `{"type":"cost-state","sessionId":"native-thread-empty","totalCostUSD":0}`,
1305+ "",
1306+ ].join("\n"),
1307+ );
1308+ yield* fileSystem.writeFileString(
1309+ path.join(projectDir, "native-thread-saved.jsonl"),
1310+ `{"type":"user","message":{"role":"user","content":"hello"},"sessionId":"native-thread-saved"}\n`,
1311+ );
1312+ const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
1313+ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1314+ settings: DEFAULT_CLAUDE_SETTINGS,
1315+ environment: { CLAUDE_CONFIG_DIR: configDir },
1316+ attachmentsDir: configDir,
1317+ fileSystem,
1318+ path,
1319+ crypto: yield* Crypto.Crypto,
1320+ idAllocator: yield* IdAllocator.IdAllocatorV2,
1321+ queryRunner: {
1322+ allocateSessionId: Effect.succeed("native-thread-empty"),
1323+ open: () => Effect.die("unused"),
1324+ forkSession: () => Effect.die("unused"),
1325+ subagentLaunchToolUseId: () => Effect.succeed(null),
1326+ assertComplete: Effect.void,
1327+ },
1328+ });
1329+ const threadId = ThreadId.make("thread-claude-empty-session");
1330+ const runtime = yield* adapter.openSession({
1331+ threadId,
1332+ providerSessionId: ProviderSessionId.make("provider-session-claude-empty-session"),
1333+ modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1334+ runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1335+ });
1336+ const providerThread = yield* runtime.ensureThread({
1337+ threadId,
1338+ modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1339+ runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1340+ });
1341+
1342+ const error = yield* Effect.flip(runtime.resumeThread({ providerThread }));
1343+ assert.equal(error._tag, "ProviderAdapterResumeThreadError");
1344+
1345+ const saved = yield* runtime.resumeThread({
1346+ providerThread: {
1347+ ...providerThread,
1348+ nativeThreadRef: {
1349+ driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
1350+ nativeId: "native-thread-saved",
1351+ strength: "strong",
1352+ },
1353+ },
1354+ });
1355+ assert.equal(saved.nativeThreadRef?.nativeId, "native-thread-saved");
1356+
1357+ const missing = yield* runtime.resumeThread({
1358+ providerThread: {
1359+ ...providerThread,
1360+ nativeThreadRef: {
1361+ driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
1362+ nativeId: "native-thread-missing",
1363+ strength: "strong",
1364+ },
1365+ },
1366+ });
1367+ assert.equal(missing.nativeThreadRef?.nativeId, "native-thread-missing");
1368+ }),
1369+ ).pipe(
1370+ Effect.provide(
1371+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1372+ ),
1373+ ),
1374+ );
1375+ });
1376+
12871377describe("ClaudeAdapterV2 resume compaction", () => {
12881378 it.effect("resolves and cancels the SDK resume dialog through structured runtime input", () =>
12891379 Effect.scoped(
0 commit comments