Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

serverRuntimeStartup.test.ts

95 lines3.3 KB

1import { DEFAULT_MODEL_BY_PROVIDER } from "@t3tools/contracts";
2import { assert, it } from "@effect/vitest";
3import { Deferred, Effect, Fiber, Option, Ref } from "effect";
4​
5import { AnalyticsService } from "./telemetry/Services/AnalyticsService.ts";
6import { ProjectionSnapshotQuery } from "./orchestration/Services/ProjectionSnapshotQuery.ts";
7import {
8 getAutoBootstrapDefaultModelSelection,
9 launchStartupHeartbeat,
10 makeCommandGate,
11 ServerRuntimeStartupError,
12} from "./serverRuntimeStartup.ts";
13​
14it("uses the canonical Codex default for auto-bootstrapped model selection", () => {
15 assert.deepStrictEqual(getAutoBootstrapDefaultModelSelection(), {
16 provider: "codex",
17 model: DEFAULT_MODEL_BY_PROVIDER.codex,
18 });
19});
20​
21it.effect("enqueueCommand waits for readiness and then drains queued work", () =>
22 Effect.scoped(
23 Effect.gen(function* () {
24 const executionCount = yield* Ref.make(0);
25 const commandGate = yield* makeCommandGate;
26​
27 const queuedCommandFiber = yield* commandGate
28 .enqueueCommand(Ref.updateAndGet(executionCount, (count) => count + 1))
29 .pipe(Effect.forkScoped);
30​
31 yield* Effect.yieldNow;
32 assert.equal(yield* Ref.get(executionCount), 0);
33​
34 yield* commandGate.signalCommandReady;
35​
36 const result = yield* Fiber.join(queuedCommandFiber);
37 assert.equal(result, 1);
38 assert.equal(yield* Ref.get(executionCount), 1);
39 }),
40 ),
41);
42​
43it.effect("enqueueCommand fails queued work when readiness fails", () =>
44 Effect.scoped(
45 Effect.gen(function* () {
46 const commandGate = yield* makeCommandGate;
47 const failure = yield* Deferred.make<void, never>();
48​
49 const queuedCommandFiber = yield* commandGate
50 .enqueueCommand(Deferred.await(failure).pipe(Effect.as("should-not-run")))
51 .pipe(Effect.forkScoped);
52​
53 yield* commandGate.failCommandReady(
54 new ServerRuntimeStartupError({
55 message: "startup failed",
56 }),
57 );
58​
59 const error = yield* Effect.flip(Fiber.join(queuedCommandFiber));
60 assert.equal(error.message, "startup failed");
61 }),
62 ),
63);
64​
65it.effect("launchStartupHeartbeat does not block the caller while counts are loading", () =>
66 Effect.scoped(
67 Effect.gen(function* () {
68 const releaseCounts = yield* Deferred.make<void, never>();
69​
70 yield* launchStartupHeartbeat.pipe(
71 Effect.provideService(ProjectionSnapshotQuery, {
72 getSnapshot: () => Effect.die("unused"),
73 getShellSnapshot: () => Effect.die("unused"),
74 getCounts: () =>
75 Deferred.await(releaseCounts).pipe(
76 Effect.as({
77 projectCount: 2,
78 threadCount: 3,
79 }),
80 ),
81 getActiveProjectByWorkspaceRoot: () => Effect.succeed(Option.none()),
82 getProjectShellById: () => Effect.succeed(Option.none()),
83 getFirstActiveThreadIdByProjectId: () => Effect.succeed(Option.none()),
84 getThreadCheckpointContext: () => Effect.succeed(Option.none()),
85 getThreadShellById: () => Effect.succeed(Option.none()),
86 getThreadDetailById: () => Effect.succeed(Option.none()),
87 }),
88 Effect.provideService(AnalyticsService, {
89 record: () => Effect.void,
90 flush: Effect.void,
91 }),
92 );
93 }),
94 ),
95);