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

providerStatusCache.test.ts

177 lines5.1 KB

1import * as NodeServices from "@effect/platform-node/NodeServices";
2import type { ServerProvider } from "@t3tools/contracts";
3import { assert, it } from "@effect/vitest";
4import { Effect, FileSystem } from "effect";
5​
6import {
7 hydrateCachedProvider,
8 readProviderStatusCache,
9 resolveProviderStatusCachePath,
10 writeProviderStatusCache,
11} from "./providerStatusCache.ts";
12​
13const makeProvider = (
14 provider: ServerProvider["provider"],
15 overrides?: Partial<ServerProvider>,
16): ServerProvider => ({
17 provider,
18 enabled: true,
19 installed: true,
20 version: "1.0.0",
21 status: "ready",
22 auth: { status: "authenticated" },
23 checkedAt: "2026-04-11T00:00:00.000Z",
24 models: [],
25 slashCommands: [],
26 skills: [],
27 ...overrides,
28});
29​
30it.layer(NodeServices.layer)("providerStatusCache", (it) => {
31 it.effect("writes and reads provider status snapshots", () =>
32 Effect.gen(function* () {
33 const fs = yield* FileSystem.FileSystem;
34 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-provider-cache-" });
35 const codexProvider = makeProvider("codex");
36 const claudeProvider = makeProvider("claudeAgent", {
37 status: "warning",
38 auth: { status: "unknown" },
39 });
40 const openCodeProvider = makeProvider("opencode", {
41 status: "warning",
42 auth: { status: "unknown", type: "opencode" },
43 });
44 const codexPath = resolveProviderStatusCachePath({
45 cacheDir: tempDir,
46 provider: "codex",
47 });
48 const claudePath = resolveProviderStatusCachePath({
49 cacheDir: tempDir,
50 provider: "claudeAgent",
51 });
52 const openCodePath = resolveProviderStatusCachePath({
53 cacheDir: tempDir,
54 provider: "opencode",
55 });
56​
57 yield* writeProviderStatusCache({
58 filePath: codexPath,
59 provider: codexProvider,
60 });
61 yield* writeProviderStatusCache({
62 filePath: claudePath,
63 provider: claudeProvider,
64 });
65 yield* writeProviderStatusCache({
66 filePath: openCodePath,
67 provider: openCodeProvider,
68 });
69​
70 assert.deepStrictEqual(yield* readProviderStatusCache(codexPath), codexProvider);
71 assert.deepStrictEqual(yield* readProviderStatusCache(claudePath), claudeProvider);
72 assert.deepStrictEqual(yield* readProviderStatusCache(openCodePath), openCodeProvider);
73 }),
74 );
75​
76 it("hydrates cached provider status while preserving current settings-derived models", () => {
77 const cachedCodex = makeProvider("codex", {
78 checkedAt: "2026-04-10T12:00:00.000Z",
79 models: [
80 {
81 slug: "gpt-5-mini",
82 name: "GPT-5 Mini",
83 isCustom: false,
84 capabilities: {
85 reasoningEffortLevels: [],
86 supportsFastMode: false,
87 supportsThinkingToggle: false,
88 contextWindowOptions: [],
89 promptInjectedEffortLevels: [],
90 },
91 },
92 ],
93 message: "Cached message",
94 skills: [
95 {
96 name: "github:gh-fix-ci",
97 path: "/tmp/skills/gh-fix-ci/SKILL.md",
98 enabled: true,
99 displayName: "CI Debug",
100 },
101 ],
102 });
103 const fallbackCodex = makeProvider("codex", {
104 models: [
105 {
106 slug: "gpt-5.4",
107 name: "GPT-5.4",
108 isCustom: false,
109 capabilities: {
110 reasoningEffortLevels: [],
111 supportsFastMode: false,
112 supportsThinkingToggle: false,
113 contextWindowOptions: [],
114 promptInjectedEffortLevels: [],
115 },
116 },
117 ],
118 message: "Pending refresh",
119 });
120​
121 assert.deepStrictEqual(
122 hydrateCachedProvider({
123 cachedProvider: cachedCodex,
124 fallbackProvider: fallbackCodex,
125 }),
126 {
127 ...fallbackCodex,
128 models: [
129 ...fallbackCodex.models,
130 {
131 slug: "gpt-5-mini",
132 name: "GPT-5 Mini",
133 isCustom: false,
134 capabilities: {
135 reasoningEffortLevels: [],
136 supportsFastMode: false,
137 supportsThinkingToggle: false,
138 contextWindowOptions: [],
139 promptInjectedEffortLevels: [],
140 },
141 },
142 ],
143 installed: cachedCodex.installed,
144 version: cachedCodex.version,
145 status: cachedCodex.status,
146 auth: cachedCodex.auth,
147 checkedAt: cachedCodex.checkedAt,
148 slashCommands: cachedCodex.slashCommands,
149 skills: cachedCodex.skills,
150 message: cachedCodex.message,
151 },
152 );
153 });
154​
155 it("ignores stale cached enabled state when the provider is now disabled", () => {
156 const cachedCodex = makeProvider("codex", {
157 checkedAt: "2026-04-10T12:00:00.000Z",
158 message: "Cached ready status",
159 });
160 const disabledFallback = makeProvider("codex", {
161 enabled: false,
162 installed: false,
163 version: null,
164 status: "disabled",
165 auth: { status: "unknown" },
166 message: "Codex is disabled in T3 Code settings.",
167 });
168​
169 assert.deepStrictEqual(
170 hydrateCachedProvider({
171 cachedProvider: cachedCodex,
172 fallbackProvider: disabledFallback,
173 }),
174 disabledFallback,
175 );
176 });
177});