1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Path from "effect/Path";
6
7import packageJson from "../../package.json" with { type: "json" };
8import {
9 makePersistedServerRuntimeState,
10 persistServerRuntimeState,
11} from "../serverRuntimeState.ts";
12import { describeServerProcess } from "./triage.ts";
13
14it.effect("reports the version the running server recorded, not the CLI's", () =>
15 Effect.gen(function* () {
16 const fs = yield* FileSystem.FileSystem;
17 const path = yield* Path.Path;
18 const statePath = path.join(
19 yield* fs.makeTempDirectoryScoped({ prefix: "t3-triage-" }),
20 "server-runtime.json",
21 );
22 // The test process stands in for the server, so its pid is alive.
23 const state = yield* makePersistedServerRuntimeState({
24 config: { host: undefined, devUrl: undefined },
25 port: 3773,
26 });
27 yield* persistServerRuntimeState({ path: statePath, state });
28
29 assert.equal(
30 yield* describeServerProcess(statePath),
31 `running (pid ${String(process.pid)}, http://127.0.0.1:3773, version ${packageJson.version})`,
32 );
33 }).pipe(Effect.provide(NodeServices.layer)),
34);
35
36it.effect("says the server version is unknown when the state file has none", () =>
37 Effect.gen(function* () {
38 const fs = yield* FileSystem.FileSystem;
39 const path = yield* Path.Path;
40 const statePath = path.join(
41 yield* fs.makeTempDirectoryScoped({ prefix: "t3-triage-" }),
42 "server-runtime.json",
43 );
44 // A server from before versions were recorded, such as the 0.0.43 desktop
45 // app in #13337.
46 yield* fs.writeFileString(
47 statePath,
48 JSON.stringify({
49 version: 1,
50 pid: process.pid,
51 port: 3773,
52 origin: "http://127.0.0.1:3773",
53 startedAt: "2026-09-24T00:08:56.777Z",
54 }),
55 );
56
57 assert.equal(
58 yield* describeServerProcess(statePath),
59 `running (pid ${String(process.pid)}, http://127.0.0.1:3773, version not recorded)`,
60 );
61 }).pipe(Effect.provide(NodeServices.layer)),
62);