The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 23:15 UTC
test: exercise guards hidden by ineffective assertions (#21848)
Julius Marminge committed
Oct 19, 2026 at 20:12 UTC
212811488bf14c4e2af6a967b3908cf77f1658b0
17 files changed
+188
-105
apps/desktop/src/wsl/DesktopWslEnvironment.test.ts
+22
-17
@@ -359,23 +359,6 @@ describe("WSL runtime cache", () => {
359
expect(deleted).toBeGreaterThan(kept);
360
});
361
362
- it("treats a runtime whose executable no longer runs as a cache miss", () => {
363
- const script = buildWslRuntimeInstallScript(
364
- "/mnt/c/Program Files/T3 Code/wsl-runtime.tar.gz",
365
- "1.2.3-x64",
366
- "b".repeat(64),
367
- );
368
-
369
- expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null');
370
-
371
- const entryCheckDefined = script.indexOf("runtime_entry_runs() {");
372
- const readinessDefined = script.indexOf("runtime_is_ready() {");
373
- const readyShortCircuit = script.indexOf("if runtime_is_ready; then");
374
- expect(entryCheckDefined).toBeGreaterThan(-1);
375
- expect(entryCheckDefined).toBeLessThan(readinessDefined);
376
- expect(readinessDefined).toBeLessThan(readyShortCircuit);
377
- });
378
-
362
it("re-hashes the executable against the digest the install recorded", () => {
363
const script = buildWslRuntimeInstallScript(
364
"/mnt/c/Program Files/T3 Code/wsl-runtime.tar.gz",
@@ -624,6 +607,28 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
607
expect(restored.stdout).toBe(SERVER_ENTRY_SOURCE);
608
});
609
610
+ it("reinstalls an executable that fails --version despite a matching recorded digest", () => {
611
+ const fixture = createFixture();
612
+ expect(fixture.install().status).toBe(0);
613
+ const brokenEntry = "#!/bin/sh\nexit 42\n";
614
+ const corrupt = runShell(
615
+ [
616
+ "set -eu",
617
+ `printf '%s' ${sh(brokenEntry)} > ${sh(fixture.serverEntry)}`,
618
+ `chmod +x ${sh(fixture.serverEntry)}`,
619
+ `sha256sum ${sh(fixture.serverEntry)} | cut -d ' ' -f 1 > ${sh(`${fixture.runtimeRoot}/.t3code-wsl-runtime-ready`)}`,
620
+ ].join("\n"),
621
+ );
622
+ expect(corrupt.status, corrupt.stderr).toBe(0);
623
+ expect(runShell(`${sh(fixture.serverEntry)} --version`).status).toBe(42);
624
+
625
+ const repaired = fixture.install();
626
+ expect(repaired.status, repaired.stderr).toBe(0);
627
+ expect(parseWslRuntimeRoot(repaired.stdout)).toBe(fixture.runtimeRoot);
628
+ expect(runShell(`cat ${sh(fixture.serverEntry)}`).stdout).toBe(SERVER_ENTRY_SOURCE);
629
+ expect(runShell(`${sh(fixture.serverEntry)} --version`).status).toBe(0);
630
+ });
631
+
632
it("falls back instead of launching a corrupted cache it cannot reinstall", () => {
633
const fixture = createFixture();
634
expect(fixture.install().status).toBe(0);
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+1
-1
@@ -58,7 +58,7 @@ import type { QueuedRunEdit } from "../../state/queued-run-edit";
58
import type { FollowUpBehavior } from "../../lib/followUpBehavior";
59
import type { ActiveTurnComposerAction } from "@t3tools/client-runtime/state/composer-dispatch";
60
import * as Haptics from "expo-haptics";
61
-import { useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
61
+import { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
62
import {
63
AppState,
64
Keyboard,
apps/server/src/assets/AssetAccess.test.ts
+28
-11
@@ -7,6 +7,7 @@ import {
7
AssetPreviewTypeValidationError,
8
ThreadId,
9
TurnItemId,
10
+ type ToolActivityNativeAppReference,
11
} from "@t3tools/contracts";
12
import { PROJECT_FAVICON_FALLBACK_MARKER } from "@t3tools/shared/projectFavicon";
13
import { MCP_APP_MAX_HTML_BYTES } from "@t3tools/shared/mcpApp";
@@ -1082,21 +1083,37 @@ describe("AssetAccess", () => {
1083
});
1084
}).pipe(Effect.provide(layerTest)),
1085
);
1085
- it.effect("issues signed native application icon capabilities", () =>
1086
- Effect.gen(function* () {
1087
- const result = yield* issueAssetUrl({
1088
- resource: {
1089
- _tag: "native-app-icon",
1090
- app: { _tag: "app-id", appId: "com.example.Editor" },
1091
- },
1092
- });
1086
+ it.effect("issues signed native application icon capabilities", () => {
1087
+ const resolvedApps: Array<ToolActivityNativeAppReference> = [];
1088
+ return Effect.gen(function* () {
1089
+ const app = { _tag: "app-id", appId: "com.example.Editor" } as const;
1090
+ const result = yield* issueAssetUrl({ resource: { _tag: "native-app-icon", app } });
1091
1092
expect(result.relativeUrl).toMatch(
1093
new RegExp(`^${ASSET_ROUTE_PREFIX}/[^/]+/native-app-icon\\.png$`, "u"),
1094
);
1097
- expect(result.expiresAt).toBeGreaterThan(0);
1098
- }).pipe(Effect.provide(layerTest)),
1099
- );
1095
+ const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
1096
+ const separator = suffix.indexOf("/");
1097
+ const token = suffix.slice(0, separator);
1098
+ const name = suffix.slice(separator + 1);
1099
+ expect(yield* resolveAsset(token, name)).toEqual({ kind: "file", path: "/icons/editor.png" });
1100
+ expect(yield* resolveAsset(`${token}tampered`, name)).toBeNull();
1101
+ expect(resolvedApps).toEqual([app]);
1102
+ }).pipe(
1103
+ Effect.provide(
1104
+ Layer.merge(
1105
+ layerTest,
1106
+ Layer.succeed(NativeAppIconResolver.NativeAppIconResolver, {
1107
+ resolve: (app) =>
1108
+ Effect.sync(() => {
1109
+ resolvedApps.push(app);
1110
+ return "/icons/editor.png";
1111
+ }),
1112
+ }),
1113
+ ),
1114
+ ),
1115
+ );
1116
+ });
1117
1118
it.effect("serves document attachments inline when a viewer requests it", () =>
1119
Effect.gen(function* () {
apps/server/src/environmentTheme.test.ts
+11
-2
@@ -142,11 +142,20 @@ it.layer(NodeServices.layer)("environment theme", (it) => {
142
path.join(environmentThemesDir, "shared-light.json"),
143
encodeThemeFile(SHARED_THEME),
144
);
145
- const first = yield* environmentTheme.streamChanges.pipe(Stream.runHead);
145
+ const seen = yield* Queue.unbounded<ReadonlyArray<{ readonly id: string }>>();
146
+ yield* Stream.runForEach(environmentTheme.streamChanges, (themes) =>
147
+ Queue.offer(seen, themes),
148
+ ).pipe(Effect.forkScoped);
149
assert.deepEqual(
147
- Option.getOrNull(first)?.map((theme) => theme.id),
150
+ (yield* Queue.take(seen)).map((theme) => theme.id),
151
["nightfall", "shared-light"],
152
);
153
+ yield* fs.remove(path.join(environmentThemesDir, "nightfall.json"));
154
+ yield* currentThemes;
155
+ assert.deepEqual(
156
+ (yield* Queue.take(seen)).map((theme) => theme.id),
157
+ ["shared-light"],
158
+ );
159
}),
160
),
161
);
apps/server/src/keybindings.test.ts
+3
@@ -602,6 +602,9 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
602
const [first, second] = yield* Effect.gen(function* () {
603
const keybindings = yield* Keybindings.Keybindings;
604
const firstLoad = (yield* keybindings.loadConfigState).keybindings;
605
+ yield* writeKeybindingsConfig(keybindingsConfigPath, [
606
+ { key: "mod+shift+y", command: "script.run-tests.run" },
607
+ ]);
608
const secondLoad = (yield* keybindings.loadConfigState).keybindings;
609
return [firstLoad, secondLoad] as const;
610
});
apps/server/src/preview/Manager.test.ts
+5
-4
@@ -6,6 +6,7 @@ import { PreviewUrlNormalizationError } from "@t3tools/shared/preview";
6
import * as Effect from "effect/Effect";
7
import * as Layer from "effect/Layer";
8
import * as PubSub from "effect/PubSub";
9
+import * as TestClock from "effect/testing/TestClock";
10
import { expect } from "vite-plus/test";
11
12
import * as ServerConfig from "../config.ts";
@@ -459,12 +460,12 @@ it.layer(layer)("PreviewManager", (it) => {
460
const threadId = freshThreadId();
461
const manager = yield* PreviewManager.PreviewManager;
462
const first = yield* manager.open({ threadId, url: "http://localhost:5173" });
463
+ yield* TestClock.adjust("1 second");
464
const second = yield* manager.open({ threadId, url: "http://localhost:3000" });
465
+ yield* TestClock.adjust("1 second");
466
+ yield* manager.navigate({ threadId, tabId: first.tabId, url: "http://localhost:5173/next" });
467
const result = yield* manager.list({ threadId });
464
- expect(result.sessions).toHaveLength(2);
465
- const ids = result.sessions.map((s) => s.tabId);
466
- expect(ids).toContain(first.tabId);
467
- expect(ids).toContain(second.tabId);
468
+ expect(result.sessions.map((s) => s.tabId)).toEqual([second.tabId, first.tabId]);
469
}),
470
);
471
apps/web/src/hooks/useThreadActions.undo.test.ts
+1
-2
@@ -162,9 +162,8 @@ describe("archive Undo", () => {
162
163
it("shows no Undo when the archive failed", async () => {
164
commands.archive.mockResolvedValue({ _tag: "Failure", cause: new Error("nope") });
165
- const add = vi.spyOn(toastManager, "add").mockReturnValue("toast");
165
await useThreadActions().archiveThread(target);
167
- expect(add).not.toHaveBeenCalled();
166
+ expect(useThreadUndoNotice.getState().notice).toBeNull();
167
});
168
});
169
apps/web/src/onboarding/firstRun.logic.test.ts
+18
-14
@@ -321,6 +321,17 @@ const bootstrapThread = {
321
runtime: null,
322
};
323
324
+const freshBootstrap = {
325
+ primaryEnvironmentId,
326
+ serverCwd: "/projects/current",
327
+ bootstrapProjectId: bootstrapProject.id,
328
+ bootstrapThreadId: bootstrapThread.id,
329
+ bootstrapProjectCreated: true,
330
+ bootstrapThreadCreated: true,
331
+ projects: [bootstrapProject],
332
+ threads: [bootstrapThread],
333
+};
334
+
335
describe("isFreshFirstRunWorkspace", () => {
336
it("accepts an empty workspace", () => {
337
expect(
@@ -394,8 +405,7 @@ describe("isFreshFirstRunWorkspace", () => {
405
it("rejects projects from another environment even when their paths match", () => {
406
expect(
407
isFreshFirstRunWorkspace({
397
- primaryEnvironmentId,
398
- serverCwd: "/projects/current",
408
+ ...freshBootstrap,
409
projects: [{ ...bootstrapProject, environmentId: "remote-environment" }],
410
threads: [],
411
}),
@@ -405,8 +415,7 @@ describe("isFreshFirstRunWorkspace", () => {
415
it("rejects threads from another environment", () => {
416
expect(
417
isFreshFirstRunWorkspace({
408
- primaryEnvironmentId,
409
- serverCwd: "/projects/current",
418
+ ...freshBootstrap,
419
projects: [bootstrapProject],
420
threads: [{ ...bootstrapThread, environmentId: "remote-environment" }],
421
}),
@@ -416,8 +425,7 @@ describe("isFreshFirstRunWorkspace", () => {
425
it("rejects a thread that does not belong to the bootstrap project", () => {
426
expect(
427
isFreshFirstRunWorkspace({
419
- primaryEnvironmentId,
420
- serverCwd: "/projects/current",
428
+ ...freshBootstrap,
429
projects: [bootstrapProject],
430
threads: [{ ...bootstrapThread, projectId: "another-project" }],
431
}),
@@ -427,8 +435,7 @@ describe("isFreshFirstRunWorkspace", () => {
435
it("rejects a thread when there is no bootstrap project", () => {
436
expect(
437
isFreshFirstRunWorkspace({
430
- primaryEnvironmentId,
431
- serverCwd: "/projects/current",
438
+ ...freshBootstrap,
439
projects: [],
440
threads: [bootstrapThread],
441
}),
@@ -438,8 +445,7 @@ describe("isFreshFirstRunWorkspace", () => {
445
it("rejects a bootstrap thread that already has a user message", () => {
446
expect(
447
isFreshFirstRunWorkspace({
441
- primaryEnvironmentId,
442
- serverCwd: "/projects/current",
448
+ ...freshBootstrap,
449
projects: [bootstrapProject],
450
threads: [
451
{
@@ -454,8 +460,7 @@ describe("isFreshFirstRunWorkspace", () => {
460
it("rejects a bootstrap thread that has started a turn", () => {
461
expect(
462
isFreshFirstRunWorkspace({
457
- primaryEnvironmentId,
458
- serverCwd: "/projects/current",
463
+ ...freshBootstrap,
464
projects: [bootstrapProject],
465
threads: [{ ...bootstrapThread, latestRun: { id: "first-run" } }],
466
}),
@@ -465,8 +470,7 @@ describe("isFreshFirstRunWorkspace", () => {
470
it("rejects a bootstrap thread that has a provider session", () => {
471
expect(
472
isFreshFirstRunWorkspace({
468
- primaryEnvironmentId,
469
- serverCwd: "/projects/current",
473
+ ...freshBootstrap,
474
projects: [bootstrapProject],
475
threads: [{ ...bootstrapThread, runtime: { status: "ready" } }],
476
}),
apps/web/src/promptStashStore.test.ts
+24
-11
@@ -238,7 +238,12 @@ describe("promptStashStore", () => {
238
environmentId: EnvironmentId.make("environment-1"),
239
};
240
241
- store.stashEntry({ ...makeEntry({ id: "with-file" }), files: [file] });
241
+ writePromptStashStorageForTest(
242
+ JSON.stringify({
243
+ version: 2,
244
+ state: { entries: [{ ...makeEntry({ id: "with-file" }), files: [file] }] },
245
+ }),
246
+ );
247
store.finalizeEntryImages("with-file", {
248
attachments: [],
249
droppedImageNames: [],
@@ -289,8 +294,7 @@ describe("promptStashStore", () => {
294
});
295
296
describe("prompt stash context records", () => {
292
- it("keeps the records behind a stashed prompt's chips", () => {
293
- const store = usePromptStashStore.getState();
297
+ it("restores the records behind a persisted prompt's chips", () => {
298
const records = [
299
{
300
version: 1 as const,
@@ -304,14 +308,23 @@ describe("prompt stash context records", () => {
308
text: "boom",
309
},
310
];
307
- store.stashEntry({
308
- id: "entry-records",
309
- createdAt: "2026-01-01T00:00:00.000Z",
310
- prompt: "see [Terminal 1 line 4](t3-context://v1/terminal/ctx-1)",
311
- attachments: [],
312
- droppedImageNames: [],
313
- records,
314
- });
311
+ writePromptStashStorageForTest(
312
+ JSON.stringify({
313
+ version: 2,
314
+ state: {
315
+ entries: [
316
+ {
317
+ id: "entry-records",
318
+ createdAt: "2026-01-01T00:00:00.000Z",
319
+ prompt: "see [Terminal 1 line 4](t3-context://v1/terminal/ctx-1)",
320
+ attachments: [],
321
+ droppedImageNames: [],
322
+ records,
323
+ },
324
+ ],
325
+ },
326
+ }),
327
+ );
328
const taken = usePromptStashStore.getState().takeEntry("entry-records");
329
expect(taken.entry?.records).toEqual(records);
330
});
apps/web/src/providerInstances.test.ts
+2
-2
@@ -1,4 +1,5 @@
1
import {
2
+ DEFAULT_MODEL_BY_PROVIDER,
3
ProjectId,
4
ProviderDriverKind,
5
ProviderInstanceId,
@@ -520,8 +521,7 @@ describe("getDefaultProviderInstanceModel", () => {
521
providers,
522
ProviderInstanceId.make("claudeAgent"),
523
);
523
- expect(typeof resolved).toBe("string");
524
- expect(resolved?.length).toBeGreaterThan(0);
524
+ expect(resolved).toBe(DEFAULT_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")]);
525
});
526
527
it("honors the instance's declared default before model-list order", () => {
apps/web/src/terminal/ghostty/keyCodes.test.ts
+19
-5
@@ -1,4 +1,5 @@
1
import { describe, expect, it } from "vite-plus/test";
2
+import ghosttyKeyHeader from "../../../../../native/libghostty-vt/include/ghostty/vt/key/event.h?raw";
3
4
import {
5
ghosttyConsumedMods,
@@ -8,11 +9,24 @@ import {
9
} from "./keyCodes";
10
11
describe("ghosttyKeyForCode", () => {
11
- it("keeps the tail of the pinned Ghostty key enum in order", () => {
12
- expect(ghosttyKeyForCode("F25")).toBe(ghosttyKeyForCode("F24") + 1);
13
- expect(ghosttyKeyForCode("PrintScreen")).toBe(ghosttyKeyForCode("FnLock") + 1);
14
- expect(ghosttyKeyForCode("Pause")).toBe(ghosttyKeyForCode("ScrollLock") + 1);
15
- expect(ghosttyKeyForCode("Paste")).toBe(ghosttyKeyForCode("Cut") + 1);
12
+ it("matches the pinned native key enum after the function keys", () => {
13
+ const enumBody = ghosttyKeyHeader.slice(
14
+ ghosttyKeyHeader.indexOf("GHOSTTY_KEY_UNIDENTIFIED"),
15
+ ghosttyKeyHeader.indexOf("GHOSTTY_KEY_MAX_VALUE"),
16
+ );
17
+ const keys = [...enumBody.matchAll(/GHOSTTY_KEY_([A-Z0-9_]+)/g)].map((match) => match[1]);
18
+ for (const [code, native] of [
19
+ ["F24", "F24"],
20
+ ["F25", "F25"],
21
+ ["FnLock", "FN_LOCK"],
22
+ ["PrintScreen", "PRINT_SCREEN"],
23
+ ["ScrollLock", "SCROLL_LOCK"],
24
+ ["Pause", "PAUSE"],
25
+ ["Paste", "PASTE"],
26
+ ]) {
27
+ expect(keys).toContain(native);
28
+ expect(ghosttyKeyForCode(code!)).toBe(keys.indexOf(native));
29
+ }
30
});
31
});
32
apps/web/src/terminal/ghostty/surface.test.ts
+8
-4
@@ -1,4 +1,5 @@
1
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
2
+import * as appearanceFonts from "../../appearanceFonts";
3
4
import { GhosttyTerminalCore, type GhosttyCell, type GhosttyRow } from "./core";
5
import {
@@ -1594,10 +1595,13 @@ describe("terminal font resolution", () => {
1595
});
1596
1597
it("ignores proportional families the cell grid cannot lay out", () => {
1597
- // Node has no canvas, so the probe answers "monospace" and the
1598
- // family is kept; the guard is exercised in the browser instead.
1599
- const stack = terminalFontFamily("Helvetica Neue");
1600
- expect(stack.endsWith("monospace")).toBe(true);
1598
+ const probe = vi.spyOn(appearanceFonts, "isMonospaceFamily").mockReturnValueOnce(false);
1599
+ try {
1600
+ expect(terminalFontFamily("Helvetica Neue")).toBe(DEFAULT_TERMINAL_FONT_FAMILY);
1601
+ expect(probe).toHaveBeenCalledWith('"Helvetica Neue"');
1602
+ } finally {
1603
+ probe.mockRestore();
1604
+ }
1605
});
1606
1607
it("quotes families the canvas font shorthand would otherwise reject", () => {
infra/relay/src/agentActivity/ApnsProviderTokens.test.ts
+8
-1
@@ -2,6 +2,8 @@
2
import * as NodeCrypto from "node:crypto";
3
4
import { describe, expect, it } from "@effect/vitest";
5
+import { vi } from "vite-plus/test";
6
+import { p256 } from "@noble/curves/nist";
7
import * as Effect from "effect/Effect";
8
import * as Redacted from "effect/Redacted";
9
import * as Schema from "effect/Schema";
@@ -61,12 +63,17 @@ describe("ApnsProviderTokens", () => {
63
64
it.effect("serves repeat pushes from the isolate cache without re-signing", () => {
65
ApnsProviderTokens.__resetApnsProviderTokenCacheForTest();
66
+ const sign = vi.spyOn(p256, "sign");
67
return Effect.gen(function* () {
68
const tokens = yield* ApnsProviderTokens.ApnsProviderTokens;
69
const first = yield* tokens.getJwt({ ...signingInput, issuedAtUnixSeconds: WINDOW + 10 });
70
const again = yield* tokens.getJwt({ ...signingInput, issuedAtUnixSeconds: WINDOW + 500 });
71
expect(again).toBe(first);
72
+ expect(sign).toHaveBeenCalledTimes(1);
73
ApnsProviderTokens.__resetApnsProviderTokenCacheForTest();
70
- }).pipe(Effect.provide(ApnsProviderTokens.layer));
74
+ }).pipe(
75
+ Effect.provide(ApnsProviderTokens.layer),
76
+ Effect.ensuring(Effect.sync(() => sign.mockRestore())),
77
+ );
78
});
79
});
infra/relay/src/agentActivity/DeliveryAttempts.test.ts
+7
-3
@@ -1,5 +1,7 @@
1
import * as NodeCryptoLayer from "@effect/platform-node/NodeCrypto";
2
import { describe, expect, it } from "@effect/vitest";
3
+import type { SQL } from "drizzle-orm";
4
+import { PgDialect } from "drizzle-orm/pg-core";
5
import * as Effect from "effect/Effect";
6
import * as Layer from "effect/Layer";
7
@@ -274,7 +276,7 @@ describe("DeliveryAttempts", () => {
276
277
it.effect("completes a claimed source job with the APNs outcome", () => {
278
const updatedValues: Array<Record<string, unknown>> = [];
277
- const whereClauses: Array<unknown> = [];
279
+ const whereClauses: Array<SQL> = [];
280
const fakeDb = {
281
update: (table: unknown) => {
282
expect(table).toBe(relayDeliveryAttempts);
@@ -282,7 +284,7 @@ describe("DeliveryAttempts", () => {
284
set: (values: Record<string, unknown>) => {
285
updatedValues.push(values);
286
return {
285
- where: (clause: unknown) => {
287
+ where: (clause: SQL) => {
288
whereClauses.push(clause);
289
return Effect.void;
290
},
@@ -301,7 +303,9 @@ describe("DeliveryAttempts", () => {
303
apnsId: "apns-id",
304
});
305
304
- expect(whereClauses).toHaveLength(1);
306
+ expect(whereClauses.map((clause) => new PgDialect().sqlToQuery(clause))).toEqual([
307
+ { sql: '"relay_delivery_attempts"."source_job_id" = $1', params: ["job-1"] },
308
+ ]);
309
expect(updatedValues).toEqual([
310
{
311
createdAt: expect.any(String),
infra/relay/src/auth/DpopProofs.test.ts
+9
-6
@@ -1,4 +1,6 @@
1
import { describe, expect, it } from "@effect/vitest";
2
+import type { SQL } from "drizzle-orm";
3
+import { PgDialect } from "drizzle-orm/pg-core";
4
import * as DateTime from "effect/DateTime";
5
import * as Effect from "effect/Effect";
6
import * as Layer from "effect/Layer";
@@ -73,15 +75,13 @@ describe("DpopProofReplay", () => {
75
});
76
77
it.effect("prunes expired proof rows from the maintenance path", () => {
76
- const calls: Array<string> = [];
78
+ const conditions: Array<SQL> = [];
79
const fakeDb = {
80
delete: (table: unknown) => {
81
expect(table).toBe(relayDpopProofs);
80
- calls.push("delete");
82
return {
82
- where: (condition: unknown) => {
83
- expect(condition).toBeDefined();
84
- calls.push("delete.where");
83
+ where: (condition: SQL) => {
84
+ conditions.push(condition);
85
return Effect.void;
86
},
87
};
@@ -91,7 +91,10 @@ describe("DpopProofReplay", () => {
91
return Effect.gen(function* () {
92
const replay = yield* DpopProofs.DpopProofReplay;
93
yield* replay.pruneExpired;
94
- expect(calls).toEqual(["delete", "delete.where"]);
94
+ const now = DateTime.formatIso(yield* DateTime.now);
95
+ expect(conditions.map((condition) => new PgDialect().sqlToQuery(condition))).toEqual([
96
+ { sql: '"relay_dpop_proofs"."expires_at" < $1', params: [now] },
97
+ ]);
98
}).pipe(
99
Effect.provide(DpopProofs.layer.pipe(Layer.provide(Layer.succeed(RelayDb.RelayDb, fakeDb)))),
100
);
infra/relay/src/environments/ManagedEndpointAllocations.test.ts
+14
-10
@@ -3,6 +3,7 @@ import * as Effect from "effect/Effect";
3
import * as Layer from "effect/Layer";
4
import * as Option from "effect/Option";
5
import { PgDialect } from "drizzle-orm/pg-core";
6
+import type { SQL } from "drizzle-orm";
7
8
import * as RelayDb from "../db.ts";
9
import { relayManagedEndpointAllocations } from "../persistence/schema.ts";
@@ -286,15 +287,18 @@ describe("ManagedEndpointAllocations", () => {
287
);
288
289
it.effect("returns a claim generation only when deprovision wins the allocation CAS", () => {
290
+ const conditions: SQL[] = [];
291
+ const results = [[{ generation: 8 }], []];
292
const fakeDb = {
293
update: (table: unknown) => {
294
expect(table).toBe(relayManagedEndpointAllocations);
295
return {
296
set: (_values: { readonly updatedAt: string }) => {
297
return {
295
- where: () => ({
296
- returning: () => Effect.succeed([{ generation: 8 }]),
297
- }),
298
+ where: (condition: SQL) => {
299
+ conditions.push(condition);
300
+ return { returning: () => Effect.succeed(results.shift() ?? []) };
301
+ },
302
};
303
},
304
};
@@ -303,14 +307,14 @@ describe("ManagedEndpointAllocations", () => {
307
308
return Effect.gen(function* () {
309
const allocations = yield* ManagedEndpointAllocations.ManagedEndpointAllocations;
306
- const generation = yield* allocations.claimDeprovision({
307
- userId: "user-1",
308
- environmentId: "environment-1",
309
- generation: 7,
310
- });
310
+ const input = { userId: "user-1", environmentId: "environment-1", generation: 7 };
311
312
- expect(generation).toBe(8);
313
- expect(generation).not.toBeNull();
312
+ expect(yield* allocations.claimDeprovision(input)).toBe(8);
313
+ expect(yield* allocations.claimDeprovision(input)).toBeNull();
314
+ expect(new PgDialect().sqlToQuery(conditions[0]!)).toEqual({
315
+ sql: '(((("relay_managed_endpoint_allocations"."user_id" = $1) and ("relay_managed_endpoint_allocations"."environment_id" = $2))) and ("relay_managed_endpoint_allocations"."generation" = $3))',
316
+ params: ["user-1", "environment-1", 7],
317
+ });
318
}).pipe(Effect.provide(layerWithDb(fakeDb)));
319
});
320
packages/contracts/src/terminal.test.ts
+8
-12
@@ -125,18 +125,14 @@ describe("TerminalOpenInput", () => {
125
expect(parsed.providerInstanceId).toBe("codex_work");
126
});
127
128
- it("rejects invalid env keys", () => {
129
- expect(
130
- decodes(TerminalOpenInput, {
131
- threadId: "thread-1",
132
- cwd: "/tmp/project",
133
- cols: 100,
134
- rows: 24,
135
- env: {
136
- "bad-key": "1",
137
- },
138
- }),
139
- ).toBe(false);
128
+ it("drops invalid env keys while retaining valid overrides", () => {
129
+ const parsed = decodeSync(TerminalOpenInput, {
130
+ threadId: "thread-1",
131
+ terminalId: DEFAULT_TERMINAL_ID,
132
+ cwd: "/tmp/project",
133
+ env: { "bad-key": "1", GOOD_KEY: "2" },
134
+ });
135
+ expect(parsed.env).toEqual({ GOOD_KEY: "2" });
136
});
137
138
it("rejects invalid provider instance ids", () => {