@devries-cameron20 / t3code Mirror · read-only
Fork 0

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 21, 03:37 UTC

main
ts 124 lines 4.55 KB
Raw
1 import { describe, expect, it } from "@effect/vitest";
2
3 import { buildProof, readSide } from "./prove-scenario.ts";
4
5 const report = (
6 exitCode: number,
7 error?: { code: string; message: string },
8 status = error ? "failed" : "passed",
9 ) => ({
10 run: {
11 results: [
12 { titlePath: ["Another scenario the run did not select"], attempts: [] },
13 {
14 titlePath: ["Tab reaches the submit button"],
15 attempts: [
16 {
17 status,
18 steps: [
19 { api: "app.open", label: "/pair#token=secret", status: "passed" },
20 { api: "expect.toBeFocused", label: "Continue", status: error ? "failed" : "passed" },
21 ],
22 ...(error === undefined ? {} : { error }),
23 artifacts: [
24 { kind: "screenshot", path: "tab/attempt-1/screenshots/001-after-tab.png" },
25 { kind: "video", path: "tab/attempt-1/video/video.webm" },
26 ],
27 },
28 ],
29 },
30 ],
31 },
32 });
33
34 const passed = report(0);
35 const failed = report(1, { code: "ASSERTION_FAILED", message: "expected: focused" });
36 // The control the scenario clicks is missing: the scenario is broken, the bug is not shown.
37 const brokenScenario = report(1, { code: "LOCATOR_NOT_FOUND", message: "no node" });
38 // A file with two tests: the first passes, so reading only it would hide the second.
39 const twoTests = { run: { results: [...passed.run.results, ...failed.run.results] } };
40 // e2e exits 0 when the test skips itself at runtime.
41 const skipped = report(0, undefined, "skipped");
42
43 describe("prove-scenario", () => {
44 it.each([
45 { base: failed, head: passed, failsOnBase: true, passesOnHead: true, verdict: /^Proven/ },
46 // A "fix" for behavior that never happens: the scenario must fail before it can prove.
47 {
48 base: passed,
49 head: passed,
50 failsOnBase: false,
51 passesOnHead: true,
52 verdict: /passes on base/,
53 },
54 { base: failed, head: failed, failsOnBase: true, passesOnHead: false, verdict: /still fails/ },
55 {
56 base: brokenScenario,
57 head: passed,
58 failsOnBase: false,
59 passesOnHead: true,
60 verdict: /could not run on base/,
61 },
62 {
63 base: failed,
64 head: skipped,
65 failsOnBase: true,
66 passesOnHead: false,
67 verdict: /could not run on head/,
68 },
69 {
70 base: failed,
71 head: twoTests,
72 failsOnBase: true,
73 passesOnHead: false,
74 verdict: /could not run on head .*exactly one/,
75 },
76 // e2e writes no report when the app does not start.
77 {
78 base: undefined,
79 head: passed,
80 failsOnBase: false,
81 passesOnHead: true,
82 verdict: /could not run on base/,
83 },
84 ])("reports $verdict", (row) => {
85 const proof = buildProof(
86 readSide("aaaaaaaaaaaa", "/out/base/results", row.base),
87 readSide("bbbbbbbbbbbb", "/out/head/results", row.head),
88 (path) => path,
89 );
90 expect(proof).toMatchObject({ failsOnBase: row.failsOnBase, passesOnHead: row.passesOnHead });
91 expect(proof.verdict).toMatch(row.verdict);
92 });
93
94 it("tells a scenario that stopped from an app that did not start", () => {
95 const side = (report: Parameters<typeof readSide>[2]) =>
96 readSide("aaaaaaaaaaaa", "/out/base/results", report);
97 const head = readSide("bbbbbbbbbbbb", "/out/head/results", passed);
98 // A control the scenario did not find: the app ran, so the scenario is what needs fixing.
99 const stopped = buildProof(side(brokenScenario), head, (path) => path);
100 expect(stopped.couldNotRun).toBe("scenario");
101 expect(stopped.verdict).toMatch(/fix the scenario/);
102 const noApp = buildProof(side(undefined), head, (path) => path);
103 expect(noApp.couldNotRun).toBe("app");
104 expect(noApp.verdict).not.toMatch(/fix the scenario/);
105 expect(buildProof(side(failed), head, (path) => path).couldNotRun).toBeNull();
106 });
107
108 it("labels captures with their side and commit and keeps the pairing token out", () => {
109 const proof = buildProof(
110 readSide("aaaaaaaaaaaa", "/out/base/results", failed),
111 readSide("bbbbbbbbbbbb", "/out/head/results", passed),
112 (path) => `https://files.example${path}`,
113 );
114 expect(proof.markdown).toContain("| | Base `aaaaaaaaaa` | Head `bbbbbbbbbb` |");
115 expect(proof.markdown).toContain(
116 "![Base aaaaaaaaaa: after tab](https://files.example/out/base/results/tab/attempt-1/screenshots/001-after-tab.png)",
117 );
118 expect(proof.videos).toEqual([
119 "/out/base/results/tab/attempt-1/video/video.webm",
120 "/out/head/results/tab/attempt-1/video/video.webm",
121 ]);
122 expect(JSON.stringify(proof)).not.toContain("secret");
123 });
124 });