The best way to control Claude Code, Codex and more from any computer or phone

main
ts 67 lines 2.75 KB
Raw
1 import { assert, describe, it } from "@effect/vitest";
2 import { type ModelSelection, ProviderInstanceId } from "@t3tools/contracts";
3 import * as Effect from "effect/Effect";
4 import * as Fiber from "effect/Fiber";
5 import * as Option from "effect/Option";
6 import * as TestClock from "effect/testing/TestClock";
7
8 import { makeClaudeCodeModelRoutes } from "./ClaudeCodeModelRoutes.ts";
9 import {
10 BUNDLED_CLAUDE_MODEL_CATALOG,
11 resolveClaudeCatalogApiModelId,
12 } from "./ClaudeModelCatalog.ts";
13
14 describe("Claude Code model routes", () => {
15 it.effect(
16 "a turn that starts before the first probe settles waits and then gets its routes",
17 () =>
18 Effect.gen(function* () {
19 const haiku = {
20 instanceId: ProviderInstanceId.make("claudeAgent"),
21 model: "claude-haiku-4-5",
22 } satisfies ModelSelection;
23 const routes = yield* makeClaudeCodeModelRoutes(
24 () => Effect.succeed("same settings"),
25 "/state",
26 );
27 const early = yield* routes
28 .route(BUNDLED_CLAUDE_MODEL_CATALOG, "/project")
29 .pipe(Effect.forkChild({ startImmediately: true }));
30 yield* routes.record([
31 { value: "haiku", resolvedModel: "us.anthropic.claude-haiku-4-5-20251001-v1:0" },
32 ]);
33 yield* routes.settle;
34 assert.strictEqual(
35 resolveClaudeCatalogApiModelId(yield* Fiber.join(early), haiku),
36 "haiku",
37 );
38
39 // A first check that never reaches the probe still releases waiting turns.
40 const unprobed = yield* makeClaudeCodeModelRoutes(
41 () => Effect.succeed("same settings"),
42 "/state",
43 );
44 const waiting = yield* unprobed
45 .route(BUNDLED_CLAUDE_MODEL_CATALOG, "/project")
46 .pipe(Effect.forkChild({ startImmediately: true }));
47 yield* unprobed.settle;
48 assert.strictEqual(yield* Fiber.join(waiting), BUNDLED_CLAUDE_MODEL_CATALOG);
49
50 const stuck = yield* makeClaudeCodeModelRoutes(
51 () => Effect.succeed("same settings"),
52 "/state",
53 );
54 const fallback = yield* stuck
55 .route(BUNDLED_CLAUDE_MODEL_CATALOG, "/project")
56 .pipe(Effect.forkChild({ startImmediately: true }));
57 yield* TestClock.adjust("2 minutes");
58 assert.strictEqual(yield* Fiber.join(fallback), BUNDLED_CLAUDE_MODEL_CATALOG);
59 // Later turns, steers and effort changes do not wait for the stuck probe again.
60 const later = yield* stuck
61 .route(BUNDLED_CLAUDE_MODEL_CATALOG, "/project")
62 .pipe(Effect.timeoutOption("1 second"), Effect.forkChild({ startImmediately: true }));
63 yield* TestClock.adjust("1 second");
64 assert.deepStrictEqual(yield* Fiber.join(later), Option.some(BUNDLED_CLAUDE_MODEL_CATALOG));
65 }),
66 );
67 });