@@ -30,6 +30,7 @@ import { |
30 | 30 | ThreadId, |
31 | 31 | } from "@t3tools/contracts"; |
32 | 32 | import { assert, describe, it } from "@effect/vitest"; |
| 33 | +import * as Clock from "effect/Clock"; |
33 | 34 | import * as Context from "effect/Context"; |
34 | 35 | import * as DateTime from "effect/DateTime"; |
35 | 36 | import * as Deferred from "effect/Deferred"; |
@@ -45,6 +46,8 @@ import * as Schema from "effect/Schema"; |
45 | 46 | import * as Scope from "effect/Scope"; |
46 | 47 | import * as Stream from "effect/Stream"; |
47 | 48 | import { Tool } from "effect/unstable/ai"; |
| 49 | +import { TestClock } from "effect/testing"; |
| 50 | +import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"; |
48 | 51 | import { formatClaudeResumeCompactionQuestion } from "@t3tools/shared/claudeCompaction"; |
49 | 52 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
50 | 53 | import { SpawnExecutableResolution } from "@t3tools/shared/shell"; |
@@ -1607,6 +1610,54 @@ describe("ClaudeAdapterV2 attachments", () => { |
1607 | 1610 | }); |
1608 | 1611 |
|
1609 | 1612 | describe("ClaudeAdapterV2 native fork", () => { |
| 1613 | + it.effect("times out and terminates a stalled history worker", () => |
| 1614 | + Effect.gen(function* () { |
| 1615 | + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; |
| 1616 | + const spawned = yield* Deferred.make<ChildProcessSpawner.ChildProcessHandle>(); |
| 1617 | + const stalledSpawner = { |
| 1618 | + ...spawner, |
| 1619 | + spawn: () => |
| 1620 | + Effect.gen(function* () { |
| 1621 | + const child = yield* spawner.spawn( |
| 1622 | + ChildProcess.make(process.execPath, ["-e", "setInterval(() => {}, 1000)"]), |
| 1623 | + ); |
| 1624 | + yield* Deferred.succeed(spawned, child); |
| 1625 | + return child; |
| 1626 | + }), |
| 1627 | + }; |
| 1628 | + const fork = yield* Effect.gen(function* () { |
| 1629 | + const runner = yield* ClaudeAdapterV2.ClaudeAgentSdkQueryRunner; |
| 1630 | + return yield* runner.forkSession({ |
| 1631 | + environment: {}, |
| 1632 | + sessionId: NodeCrypto.randomUUID(), |
| 1633 | + options: {}, |
| 1634 | + threadId: ThreadId.make("fork-target"), |
| 1635 | + providerSessionId: ProviderSessionId.make("fork-session"), |
| 1636 | + }); |
| 1637 | + }).pipe( |
| 1638 | + Effect.provide(ClaudeAdapterV2.claudeAgentSdkQueryRunnerLiveLayer), |
| 1639 | + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, stalledSpawner), |
| 1640 | + Effect.provide( |
| 1641 | + Layer.succeed(ProviderEventLoggers.ProviderEventLoggers, { |
| 1642 | + native: undefined, |
| 1643 | + canonical: undefined, |
| 1644 | + }), |
| 1645 | + ), |
| 1646 | + Effect.forkChild, |
| 1647 | + ); |
| 1648 | + const child = yield* Deferred.await(spawned); |
| 1649 | + yield* TestClock.adjust("30 seconds"); |
| 1650 | + const error = yield* Fiber.join(fork).pipe( |
| 1651 | + Effect.flip, |
| 1652 | + Effect.timeout("2 seconds"), |
| 1653 | + Effect.provideService(Clock.Clock, Clock.Clock.defaultValue()), |
| 1654 | + ); |
| 1655 | + assert.equal(error.method, "forkSession"); |
| 1656 | + assert.include(String(error.cause), "Timeout"); |
| 1657 | + assert.equal(yield* child.isRunning, false); |
| 1658 | + }).pipe(Effect.provide(NodeServices.layer), Effect.scoped), |
| 1659 | + ); |
| 1660 | + |
1610 | 1661 | it.effect( |
1611 | 1662 | "forks history from the provider environment without changing the server environment", |
1612 | 1663 | () => |
|