Skip to content

Commit 2200c7c

Browse files
committed
fix(ci): vider l'arriéré de types des tests et fermer le cliquet
Le job « Typecheck (tests) » échouait : 75 erreurs pour un BASELINE de 66. Le dépassement est antérieur à cette PR — le tip vierge en comptait déjà 75 — quelqu'un a franchi le cliquet sans relever la baseline. Plutôt que relever, on corrige. Les 75 erreurs étaient presque toutes des fixtures auxquelles il manquait un champ requis par leur propre schéma : un asset sans `cameraTrack`, un clip sans `reason`, un document déclaré `AxcutDocument` mais de forme v3. Autrement dit des tests qui ne vérifiaient pas la forme qu'ils prétendaient vérifier — les compléter n'est pas cosmétique. Aucun fichier de production touché. Aucun `any`, `@ts-expect-error` ni `@ts-ignore` ajouté ; le diff est net-négatif de 15 casts (10 `as never` sur `tool.invoke`, 3 `as unknown as`, 1 `as AxcutDocument`). Aucune assertion supprimée ni assouplie ; deux tests se retrouvent renforcés — le fixture de `sceneDescription` reliait clip et asset par `undefined === undefined`, et `operations.test.ts` échoue désormais bruyamment sur un `sourceEndSec` absent au lieu de fausser un total en silence. Le cliquet disparaît, comme son propre commentaire le demandait (« delete this job's baseline logic at zero ») : le job devient un `tsc -p tsconfig.test.json --noEmit` sec. Il perd le tableau de résumé, et gagne un mode d'échec net. Les fixtures qui modélisent le contrat courant lisent maintenant la version sur `axcutSchemaVersion` au lieu de la redire. Une exception documentée sur place : dans `EditorEmptyState.test.tsx` le fixture est construit dans `vi.hoisted`, qui s'exécute avant l'initialisation des imports, donc la constante y est inaccessible et le littéral reste. Le titre de la PR est corrigé séparément : `rebase(...)` n'est pas un type Conventional Commits accepté par le job « Validate PR title ».
1 parent 02fe7d8 commit 2200c7c

27 files changed

Lines changed: 354 additions & 174 deletions

‎.github/workflows/ci.yml‎

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,24 @@ jobs:
3434
typecheck-tests:
3535
name: Typecheck (tests)
3636
runs-on: ubuntu-latest
37-
# A RATCHET, not a gate. tsconfig.json includes only src + electron and
38-
# excludes **/*.test.ts, so no test file has ever been typechecked, and
39-
# vitest transpiles without checking — fixture types have drifted from the
40-
# schemas they claim to build for years. Failing on the whole backlog would
41-
# put a red X on every PR that nobody can fix, and a check everyone ignores
42-
# is worse than no check. So: fail only if the count GROWS. Lower BASELINE
43-
# whenever you fix some; delete this job's baseline logic at zero.
37+
# A GATE now, and the baseline logic is gone — as its own comment instructed
38+
# ("delete this job's baseline logic at zero"). The history: tsconfig.json
39+
# includes only src + electron and excludes **/*.test.ts, and vitest
40+
# transpiles without checking, so no test file had ever been typechecked and
41+
# fixture types had drifted from the schemas they claim to build for years.
42+
# Failing on that whole backlog at once would have put a red X on every PR
43+
# that nobody could fix, so the job shipped as a ratchet (fail only if the
44+
# count GROWS), walked down 80 -> 74 -> 71 -> 66. The backlog is now cleared:
45+
# every fixture carries the fields its schema actually requires, which is
46+
# the point — a fixture missing `cameraTrack` or `reason` was not testing
47+
# the shape it claimed to. Keep it at zero. If a genuine error is not worth
48+
# fixing on the spot, fix the fixture anyway: re-introducing a baseline
49+
# re-opens the drift this closed.
4450
steps:
4551
- uses: actions/checkout@v4
4652
- uses: ./.github/actions/setup
47-
- name: Typecheck tests against a baseline
48-
shell: bash
49-
env:
50-
BASELINE: 66
51-
run: |
52-
set -uo pipefail
53-
COUNT=$(npx tsc -p tsconfig.test.json --noEmit 2>&1 | grep -c 'error TS' || true)
54-
{
55-
echo "## Test-file typecheck"
56-
echo ""
57-
echo "| | |"
58-
echo "|---|---|"
59-
echo "| Errors now | ${COUNT} |"
60-
echo "| Baseline | ${BASELINE} |"
61-
} >> "$GITHUB_STEP_SUMMARY"
62-
if [ "${COUNT}" -gt "${BASELINE}" ]; then
63-
echo "::error::Test-file type errors went ${BASELINE} -> ${COUNT}. Fix the new ones, or raise BASELINE in ci.yml with a reason."
64-
npx tsc -p tsconfig.test.json --noEmit 2>&1 | grep 'error TS' || true
65-
exit 1
66-
fi
67-
if [ "${COUNT}" -lt "${BASELINE}" ]; then
68-
echo "::notice::Test-file type errors down to ${COUNT} (baseline ${BASELINE}). Lower BASELINE in ci.yml to lock the win in."
69-
fi
53+
- name: Typecheck tests
54+
run: npx tsc -p tsconfig.test.json --noEmit
7055

7156
docs:
7257
name: Docs

‎electron/ai-edition/chat-service.test.ts‎

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { tmpdir } from "node:os";
2+
import path from "node:path";
13
import { beforeEach, describe, expect, it } from "vitest";
24
import { type AxcutDocument, createEmptyDocument } from "../../src/lib/ai-edition/schema";
35
import {
@@ -8,6 +10,7 @@ import {
810
runTimelineOperation,
911
selectSession,
1012
} from "./chat-service";
13+
import { DocumentService } from "./document-service";
1114
import type { LlmConfigStore } from "./llm-config-store";
1215

1316
describe("chat-service sessions", () => {
@@ -126,6 +129,8 @@ describe("runTimelineOperation", () => {
126129
label: "Rec",
127130
originalPath: "/tmp/r.mp4",
128131
durationSec: 60,
132+
// Screen-only recording: no webcam track attached.
133+
cameraTrack: null,
129134
},
130135
],
131136
timeline: {
@@ -147,20 +152,42 @@ describe("runTimelineOperation", () => {
147152
};
148153
}
149154

155+
// runTimelineOperation takes the concrete DocumentService, which owns private
156+
// state (projectsRoot, the per-project write queue), so no object literal can
157+
// stand in for it. Subclassing keeps the stub a real DocumentService while
158+
// replacing the only two methods runTimelineOperation calls with in-memory
159+
// versions — nothing here touches the filesystem, so projectsRoot is never
160+
// read and no directory is created.
161+
class StubDocumentService extends DocumentService {
162+
constructor(readonly file: { stored: AxcutDocument | undefined }) {
163+
super(path.join(tmpdir(), "openscreen-chat-service-test-unused"));
164+
}
165+
166+
override async getProject(): Promise<AxcutDocument> {
167+
if (!this.file.stored) throw new Error("no document");
168+
return this.file.stored;
169+
}
170+
171+
override async saveProject(doc: AxcutDocument): Promise<AxcutDocument> {
172+
this.file.stored = doc;
173+
return doc;
174+
}
175+
}
176+
177+
// Same stub, but both disk-facing methods fail — the "disk is dead" path.
178+
class BrokenDocumentService extends StubDocumentService {
179+
override async getProject(): Promise<AxcutDocument> {
180+
throw new Error("disk is dead");
181+
}
182+
183+
override async saveProject(): Promise<AxcutDocument> {
184+
throw new Error("disk is dead");
185+
}
186+
}
187+
150188
function makeDocumentsStub() {
151-
const initial = makeDocument();
152-
const file: { stored: AxcutDocument | undefined } = { stored: initial };
153-
const documents = {
154-
async getProject(_id: string): Promise<AxcutDocument> {
155-
if (!file.stored) throw new Error("no document");
156-
return file.stored;
157-
},
158-
async saveProject(doc: AxcutDocument): Promise<AxcutDocument> {
159-
file.stored = doc;
160-
return doc;
161-
},
162-
};
163-
return { documents, file };
189+
const file: { stored: AxcutDocument | undefined } = { stored: makeDocument() };
190+
return { documents: new StubDocumentService(file), file };
164191
}
165192

166193
it("applies the op, persists, and records an assistant summary", async () => {
@@ -185,14 +212,7 @@ describe("runTimelineOperation", () => {
185212
});
186213

187214
it("returns success:false on getProject failure", async () => {
188-
const documents = {
189-
async getProject() {
190-
throw new Error("disk is dead");
191-
},
192-
async saveProject() {
193-
throw new Error("disk is dead");
194-
},
195-
};
215+
const documents = new BrokenDocumentService({ stored: makeDocument() });
196216
const s = createSession("proj_run_err");
197217
const result = await runTimelineOperation(
198218
"proj_run_err",

‎electron/ai-edition/deep-agent/service.test.ts‎

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// and read tools were announced only by the lying emission.
1616

1717
import { ChatAnthropic } from "@langchain/anthropic";
18+
import type { StructuredToolInterface } from "@langchain/core/tools";
1819
import { ChatOpenAI } from "@langchain/openai";
1920
import { describe, expect, it } from "vitest";
2021
import {
@@ -169,10 +170,20 @@ function recordingSink(): { sink: OpenScreenAgentSink; events: SinkEvent[] } {
169170
};
170171
}
171172

173+
/** `buildTools` returns a tuple with a DISTINCT type per tool, one per zod
174+
* schema, so `tools.find(...)` is a 19-way union — and `.invoke` is generic, a
175+
* shape TypeScript will not call through a union (TS2349). Widening to the
176+
* interface every one of them implements is what the model is handed anyway:
177+
* `createAgent` takes them as `ClientTool`, i.e. exactly this. Nothing the
178+
* tests read is lost — `name`, `description`, `schema` and `invoke` all live on
179+
* the interface. */
180+
type BuiltTool = StructuredToolInterface;
181+
172182
function toolsFor(document: AxcutDocument) {
173183
const { sink, events } = recordingSink();
174184
const holder = { current: document };
175-
return { tools: buildTools(holder, sink), events, holder };
185+
const tools: BuiltTool[] = buildTools(holder, sink);
186+
return { tools, events, holder };
176187
}
177188

178189
describe("the tool surface handed to the model", () => {
@@ -242,7 +253,7 @@ describe("the sink announces each call exactly once, with the real verdict", ()
242253
const { tools, events } = toolsFor(document);
243254
const tool = tools.find((t) => t.name === name);
244255
if (!tool) throw new Error(`${name} is not built`);
245-
await tool.invoke(args as never);
256+
await tool.invoke(args);
246257

247258
expect(events.map((e) => e.kind)).toEqual(["toolStart", "toolEnd"]);
248259
expect(events[0].name).toBe(name);
@@ -270,7 +281,7 @@ describe("the sink announces each call exactly once, with the real verdict", ()
270281
const { tools, events } = toolsFor(document);
271282
const tool = tools.find((t) => t.name === "getTranscript");
272283
if (!tool) throw new Error("getTranscript is not built");
273-
const result = await tool.invoke({} as never);
284+
const result = await tool.invoke({});
274285

275286
expect(String(result)).toContain("No transcript");
276287
expect(events).toHaveLength(2);
@@ -283,12 +294,12 @@ describe("the sink announces each call exactly once, with the real verdict", ()
283294

284295
const refused = tools.find((t) => t.name === "setZoom");
285296
if (!refused) throw new Error("setZoom is not built");
286-
await refused.invoke({ zoomId: "zoom_nope" } as never);
297+
await refused.invoke({ zoomId: "zoom_nope" });
287298
expect(holder.current).toBe(before);
288299

289300
const write = tools.find((t) => t.name === "addTrim");
290301
if (!write) throw new Error("addTrim is not built");
291-
await write.invoke({ startSec: 1, endSec: 2 } as never);
302+
await write.invoke({ startSec: 1, endSec: 2 });
292303
expect(holder.current).not.toBe(before);
293304
expect(holder.current.timeline.trimRanges).toHaveLength(2);
294305
});
@@ -389,20 +400,20 @@ describe("the prompt when the user has turned project edits off", () => {
389400
describe("the tools when the user has turned project edits off", () => {
390401
it("still builds all 18 — the model has to be able to NAME the edit", () => {
391402
const { sink } = recordingSink();
392-
const tools = buildTools({ current: fixtureDocument() }, sink, false);
403+
const tools: BuiltTool[] = buildTools({ current: fixtureDocument() }, sink, false);
393404
expect(tools.map((t) => t.name)).toEqual(OPENSCREEN_TOOLS);
394405
});
395406

396407
it("refuses every write through the tool, and the sink says so", async () => {
397408
const holder = { current: fixtureDocument() };
398409
const { sink, events } = recordingSink();
399-
const tools = buildTools(holder, sink, false);
410+
const tools: BuiltTool[] = buildTools(holder, sink, false);
400411
const before = holder.current;
401412

402413
for (const name of OPENSCREEN_TOOLS.filter((n) => isMutatingTool(n))) {
403414
const tool = tools.find((t) => t.name === name);
404415
if (!tool) throw new Error(`${name} is not built`);
405-
const result = await tool.invoke((ARGS[name] ?? {}) as never);
416+
const result = await tool.invoke(ARGS[name] ?? {});
406417
expect(JSON.parse(String(result)).code, name).toBe("consent_required");
407418
}
408419
// Not one of them advanced the document.
@@ -413,10 +424,14 @@ describe("the tools when the user has turned project edits off", () => {
413424
});
414425

415426
it("leaves the reads working", async () => {
416-
const tools = buildTools({ current: fixtureDocument() }, recordingSink().sink, false);
427+
const tools: BuiltTool[] = buildTools(
428+
{ current: fixtureDocument() },
429+
recordingSink().sink,
430+
false,
431+
);
417432
const read = tools.find((t) => t.name === "getCurrentDocument");
418433
if (!read) throw new Error("getCurrentDocument is not built");
419-
expect(JSON.parse(String(await read.invoke({} as never))).primaryAssetId).toBe("asset_1");
434+
expect(JSON.parse(String(await read.invoke({}))).primaryAssetId).toBe("asset_1");
420435
});
421436
});
422437

@@ -451,10 +466,10 @@ const SAMPLES = (() => {
451466

452467
async function invokeCursorTool(runtime: Parameters<typeof buildTools>[3]) {
453468
const { sink, events } = recordingSink();
454-
const tools = buildTools({ current: fixtureDocument() }, sink, true, runtime);
469+
const tools: BuiltTool[] = buildTools({ current: fixtureDocument() }, sink, true, runtime);
455470
const tool = tools.find((t) => t.name === "getCursorTrack");
456471
if (!tool) throw new Error("getCursorTrack is not built");
457-
const result = await tool.invoke({} as never);
472+
const result = await tool.invoke({});
458473
return { payload: JSON.parse(String(result)), events };
459474
}
460475

@@ -518,12 +533,12 @@ describe("cursor telemetry reaches the model", () => {
518533
},
519534
};
520535
const { sink } = recordingSink();
521-
const tools = buildTools({ current: fixtureDocument() }, sink, true, runtime);
536+
const tools: BuiltTool[] = buildTools({ current: fixtureDocument() }, sink, true, runtime);
522537
const tool = tools.find((t) => t.name === "getCursorTrack");
523538
if (!tool) throw new Error("getCursorTrack is not built");
524539

525-
await tool.invoke({} as never);
526-
await tool.invoke({ assetId: "asset_1" } as never);
540+
await tool.invoke({});
541+
await tool.invoke({ assetId: "asset_1" });
527542

528543
// Both resolve to the primary asset — the wrapper and the executor must
529544
// agree on which asset is being reported, or the answer describes one and
@@ -544,11 +559,13 @@ describe("cursor telemetry reaches the model", () => {
544559
},
545560
};
546561
const { sink } = recordingSink();
547-
const tools = buildTools({ current: fixtureDocument() }, sink, true, runtime);
562+
const tools: BuiltTool[] = buildTools({ current: fixtureDocument() }, sink, true, runtime);
548563
const tool = tools.find((t) => t.name === "getCursorTrack");
549564
if (!tool) throw new Error("getCursorTrack is not built");
550565

551-
await tool.invoke({ assetId: "asset_1", path: "/etc/passwd" } as never);
566+
// The extra `path` is the point of the test: the model is allowed to ask
567+
// for anything, and the tool must ignore what it did not declare.
568+
await tool.invoke({ assetId: "asset_1", path: "/etc/passwd" });
552569

553570
expect(seen).toEqual([{ originalPath: fixtureDocument().assets[0].originalPath }]);
554571
});

‎electron/ai-edition/document-service.test.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import os from "node:os";
33
import path from "node:path";
44
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55
import type { AxcutDocument } from "../../src/lib/ai-edition/schema";
6+
import { axcutSchemaVersion } from "../../src/lib/ai-edition/schema";
67
import { DocumentNotFoundError, DocumentService, ProjectFileError } from "./document-service";
78

89
async function makeTempDir(): Promise<string> {
@@ -34,7 +35,7 @@ describe("DocumentService", () => {
3435
const filePath = path.join(tempDir, `${doc.project.id}.openscreen`);
3536
const raw = await fs.readFile(filePath, "utf8");
3637
expect(JSON.parse(raw)).toMatchObject({
37-
schemaVersion: 7,
38+
schemaVersion: axcutSchemaVersion,
3839
project: { title: "Demo Project" },
3940
});
4041
});
@@ -142,7 +143,7 @@ describe("DocumentService", () => {
142143
it("removes the asset and cascades clips + trimRanges", async () => {
143144
const doc = await service.createProject("P");
144145
const withAsset = await service.addAsset(doc.project.id, { path: "/tmp/a.mp4" });
145-
const assetId = withAsset.assets[0]?.id;
146+
const assetId = withAsset.assets[0]?.id ?? "";
146147
expect(assetId).toBeTruthy();
147148

148149
// Manually add a clip + trimRange so we can verify cascade
@@ -159,6 +160,7 @@ describe("DocumentService", () => {
159160
timelineEndSec: 1,
160161
wordRefs: [],
161162
origin: "system",
163+
reason: "",
162164
},
163165
],
164166
trimRanges: [
@@ -168,12 +170,13 @@ describe("DocumentService", () => {
168170
startSec: 0,
169171
endSec: 1,
170172
origin: "user",
173+
reason: "",
171174
},
172175
],
173176
},
174177
});
175178

176-
const after = await service.removeAsset(docWithTimeline.project.id, assetId ?? "");
179+
const after = await service.removeAsset(docWithTimeline.project.id, assetId);
177180
expect(after.assets).toHaveLength(0);
178181
expect(after.timeline.clips).toHaveLength(0);
179182
expect(after.timeline.trimRanges).toHaveLength(0);

‎electron/native-bridge/services/compositorViewService.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ describe("resolveSceneAssetPaths", () => {
281281
Object.defineProperty(process, "resourcesPath", originalResourcesPath);
282282
}
283283
if (originalVitePublic === undefined) {
284-
delete process.env.VITE_PUBLIC;
284+
// `NodeJS.ProcessEnv.VITE_PUBLIC` is declared non-optional (electron-env.d.ts),
285+
// so `delete` is rejected outright even though main.ts only assigns it at
286+
// startup and it really is absent under vitest. Reflect deletes the same key.
287+
Reflect.deleteProperty(process.env, "VITE_PUBLIC");
285288
} else {
286289
process.env.VITE_PUBLIC = originalVitePublic;
287290
}
@@ -292,6 +295,10 @@ describe("resolveSceneAssetPaths", () => {
292295
return JSON.parse(resolveSceneAssetPaths(JSON.stringify(scene)));
293296
}
294297

298+
/** What `resolveSceneAssetPaths` writes into `cursor.cursorSprites` — same shape the
299+
* service declares for the sprite map it builds. */
300+
type ResolvedSprite = { path: string; hotspotX: number; hotspotY: number };
301+
295302
it("resolves a bundled wallpaper to the extraResources copy, not the unreadable asar path", () => {
296303
const out = resolved({ background: { kind: "image", path: "/wallpapers/wallpaper1.jpg" } });
297304

@@ -324,7 +331,7 @@ describe("resolveSceneAssetPaths", () => {
324331

325332
// The whole point of the fraction: it survives the size slider. A hotspot in source
326333
// pixels would have to be rescaled at draw time, and drifted when it wasn't.
327-
for (const [type, sprite] of Object.entries(sprites)) {
334+
for (const [type, sprite] of Object.entries<ResolvedSprite>(sprites)) {
328335
expect(sprite.hotspotX, type).toBeGreaterThanOrEqual(0);
329336
expect(sprite.hotspotX, type).toBeLessThanOrEqual(1);
330337
expect(sprite.hotspotY, type).toBeGreaterThanOrEqual(0);

0 commit comments

Comments
 (0)