From 05589dbc9f3eb0eed906eec754b990b1ade48f12 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Thu, 8 Oct 2026 21:19:28 +0200 Subject: [PATCH 1/5] =?UTF-8?q?test:=20reproduce=20#422=20=E2=80=94=20the?= =?UTF-8?q?=20it.fails=20status=20test=20passes=20for=20the=20wrong=20reas?= =?UTF-8?q?on=20and=20nothing=20pins=20the=20human=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/daemon-lifecycle.test.ts | 10 +---- src/expected-failures.test.ts | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/expected-failures.test.ts diff --git a/e2e/daemon-lifecycle.test.ts b/e2e/daemon-lifecycle.test.ts index 95baae3b9..dd87182e6 100644 --- a/e2e/daemon-lifecycle.test.ts +++ b/e2e/daemon-lifecycle.test.ts @@ -49,18 +49,12 @@ describe("daemon lifecycle & recovery", () => { expect(status.json).toMatchObject({ daemon: { health: "running" } }); }); - // Suspected bug: `simlock daemon status` always writes raw JSON via `writeResult` - // (src/cli/index.ts `runDaemon`, the "status" branch) regardless of `--json`, - // unlike its siblings `daemon start`/`daemon stop` which both branch on - // `values.json` to print "Daemon running"/"Daemon stopping" in human mode. This - // contradicts docs/CLI.md ("`daemon ` ... default to a - // human-oriented view ... and accept `--json`"). See final report. - it.fails("daemon status prints a human-oriented view by default", async () => { + it("daemon status prints a human-oriented view by default", async () => { const env = await withDaemon({ mode: "running" }); const statusHuman = await env.cli(["daemon", "status"]); expect(statusHuman.code).toBe(0); - expect(statusHuman.stdout).toContain("Daemon running"); + expect(statusHuman.stdout.split("\n")[0]).toBe("Daemon: running (worker)"); }); it("stops while a detached lease is still outstanding", async () => { diff --git a/src/expected-failures.test.ts b/src/expected-failures.test.ts new file mode 100644 index 000000000..69380eeea --- /dev/null +++ b/src/expected-failures.test.ts @@ -0,0 +1,69 @@ +import { execFileSync } from "node:child_process"; +import { readFileSync, statSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { describe, expect, it } from "vitest"; + +import { stripComments } from "./test-support/imports.js"; + +const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), ".."); + +/** + * A call that registers a test written to pass by failing: `it.fails`, `test.fails`, + * `describe.fails`, and the same on `.each(...)` or `.skipIf(...)`. An `it.skip` or `it.todo` + * says plainly that it proved nothing; an expected failure reports green while proving nothing, + * which is what makes it invisible to a suite read from the top. + * + * Read from comment-stripped text (the same scanner every boundary test uses), so prose that + * merely names the API is not a hit. + */ +const EXPECTED_FAILURE = /\b(?:it|test|describe)(?:\.[A-Za-z]+(?:\([^()]*\))?)*\.fails\s*\(/; + +/** + * Every tracked test file. Enumerated from `git ls-files` rather than a directory walk, so the + * check sees every test in the repository -- `src/`, `e2e/` and `ui/` alike -- and not only the + * directories this file names (testing rule 4). + */ +const testFiles = execFileSync( + "git", + ["ls-files", "-z", "--", "*.test.ts", "*.test.tsx", "*.spec.ts"], + { cwd: REPO_ROOT, encoding: "utf8" }, +) + .split("\0") + .filter((name) => name.length > 0) + // A path deleted from the working tree is still listed by `git ls-files`; only regular files + // can be read. + .filter((name) => { + try { + return statSync(join(REPO_ROOT, name)).isFile(); + } catch { + return false; + } + }); + +describe("the tracked test files", () => { + it("were enumerated from the git index, in `src/`, `e2e/` and `ui/` alike", () => { + // Without this, a pathspec or a `cwd` that matched nothing would leave the scan below with no + // file to read and the suite would pass while checking no test at all. One file from each tree + // proves the scan reaches all three: `e2e/` is where the file this rule is about lives. + for (const tree of ["src", "e2e", "ui"]) { + expect( + testFiles.some((name) => name.startsWith(`${tree}/`)), + `no tracked test file found under ${tree}/`, + ).toBe(true); + } + }); + + it("hold no test written to pass by failing", () => { + const offenders = testFiles.flatMap((name) => + stripComments(readFileSync(join(REPO_ROOT, name), "utf8")) + .split("\n") + .flatMap((line, index) => + EXPECTED_FAILURE.test(line) ? [`${name}:${index + 1}: ${line.trim()}`] : [], + ), + ); + + expect(offenders).toEqual([]); + }); +}); From a1534a01d85edeb99897da69bc07474597b82a0c Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 16 Oct 2026 20:45:38 +0200 Subject: [PATCH 2/5] test(cli): pin the human view of daemon status at unit cost The unit layer could not see it at all: deleting formatStatus from the daemon status branch left every unit test green. This kills that mutation where a mutation sweep runs it cheapest. --- src/cli/index.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cli/index.test.ts b/src/cli/index.test.ts index 8ac17bc70..5318dc039 100644 --- a/src/cli/index.test.ts +++ b/src/cli/index.test.ts @@ -1334,6 +1334,19 @@ describe("CLI: daemon status (ADR 0003 §11)", () => { expect(launched).toBe(false); }); + it("prints the human view for daemon status when --json is absent", async () => { + const output = outputCapture(); + + await expect( + runCli( + ["daemon", "status"], + output.environmentWith({ connectExistingAdmin: async () => fakeClient() }), + ), + ).resolves.toBe(0); + + expect(output.stdout.split("\n")[0]).toBe("Daemon: running (worker)"); + }); + it("asks the daemon to purge orphans only once the operator has confirmed", async () => { const output = outputCapture(); const seen: unknown[] = []; From 3562ec947095e8c188f9a29cc7578c450b9c44b5 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 16 Oct 2026 20:50:12 +0200 Subject: [PATCH 3/5] test: keep the meta-test's comments inside architecture rule 17 CI's comment lint judged the repro's doc blocks; the checks they explain are already named in their test titles, so each comment keeps only what the code does not show. --- src/expected-failures.test.ts | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/expected-failures.test.ts b/src/expected-failures.test.ts index 69380eeea..bd68b48b7 100644 --- a/src/expected-failures.test.ts +++ b/src/expected-failures.test.ts @@ -9,22 +9,11 @@ import { stripComments } from "./test-support/imports.js"; const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), ".."); -/** - * A call that registers a test written to pass by failing: `it.fails`, `test.fails`, - * `describe.fails`, and the same on `.each(...)` or `.skipIf(...)`. An `it.skip` or `it.todo` - * says plainly that it proved nothing; an expected failure reports green while proving nothing, - * which is what makes it invisible to a suite read from the top. - * - * Read from comment-stripped text (the same scanner every boundary test uses), so prose that - * merely names the API is not a hit. - */ +// why: matched against comment-stripped text, so prose that merely names the API is not a hit. const EXPECTED_FAILURE = /\b(?:it|test|describe)(?:\.[A-Za-z]+(?:\([^()]*\))?)*\.fails\s*\(/; -/** - * Every tracked test file. Enumerated from `git ls-files` rather than a directory walk, so the - * check sees every test in the repository -- `src/`, `e2e/` and `ui/` alike -- and not only the - * directories this file names (testing rule 4). - */ +// why: enumerated from `git ls-files` rather than a directory walk, so the scan reaches every +// tree the rule covers and not only the ones this file happens to name (testing rule 4). const testFiles = execFileSync( "git", ["ls-files", "-z", "--", "*.test.ts", "*.test.tsx", "*.spec.ts"], @@ -32,8 +21,8 @@ const testFiles = execFileSync( ) .split("\0") .filter((name) => name.length > 0) - // A path deleted from the working tree is still listed by `git ls-files`; only regular files - // can be read. + // why: `git ls-files` still lists a path deleted from the working tree, and only a regular + // file can be read. .filter((name) => { try { return statSync(join(REPO_ROOT, name)).isFile(); @@ -44,9 +33,8 @@ const testFiles = execFileSync( describe("the tracked test files", () => { it("were enumerated from the git index, in `src/`, `e2e/` and `ui/` alike", () => { - // Without this, a pathspec or a `cwd` that matched nothing would leave the scan below with no - // file to read and the suite would pass while checking no test at all. One file from each tree - // proves the scan reaches all three: `e2e/` is where the file this rule is about lives. + // why: a pathspec or a `cwd` that matched nothing would leave the scan below with no file to + // read, and the rule would read as covered while proving nothing. for (const tree of ["src", "e2e", "ui"]) { expect( testFiles.some((name) => name.startsWith(`${tree}/`)), From 3f0ee70b5d4d8d7e3960feb83e92f8ab99794353 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 16 Oct 2026 21:13:49 +0200 Subject: [PATCH 4/5] test: close the multi-line hole in the expected-failure scan why: the guard scanned line by line, so a call whose table spans lines (`it.fails.each([...])\n(...)`) passed it, and the file read as covered while the rule did not reach it (testing rule 4). The scan now matches a whole comment-stripped file, allows a modifier on either side of `fails` (`it.only.fails` and `it.fails.each` are both real chains in vitest), and pins the shapes it must catch and the ones it must leave alone as two tables. --- src/expected-failures.test.ts | 93 ++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 7 deletions(-) diff --git a/src/expected-failures.test.ts b/src/expected-failures.test.ts index bd68b48b7..85ca5373e 100644 --- a/src/expected-failures.test.ts +++ b/src/expected-failures.test.ts @@ -9,8 +9,39 @@ import { stripComments } from "./test-support/imports.js"; const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), ".."); -// why: matched against comment-stripped text, so prose that merely names the API is not a hit. -const EXPECTED_FAILURE = /\b(?:it|test|describe)(?:\.[A-Za-z]+(?:\([^()]*\))?)*\.fails\s*\(/; +/** + * why: matched against a whole comment-stripped file rather than line by line, so a call whose + * table spans several lines is still found, and prose that merely names the API is not a hit. + * why: the modifier chain is allowed on both sides of `fails` because that is where vitest puts it + * (`it.only` and `fails.each` are both real modifiers there), and a guard with a hole reads as + * coverage the suite no longer has. + */ +const EXPECTED_FAILURE = + /\b(?:it|test|describe)(?:\.[A-Za-z]+(?:\([^()]*\))?)*\.fails\b(?:\.[A-Za-z]+(?:\([^()]*\))?)*\(/g; + +// why: each chain is held in pieces and without its arguments, because a string holding the whole +// call is text the scan below reads and this file would then name itself as an offender. +const expectedFailureSpellings: { shape: string; parts: string[] }[] = [ + { shape: "it.fails", parts: ["it", "fails"] }, + { shape: "test.fails", parts: ["test", "fails"] }, + { shape: "describe.fails", parts: ["describe", "fails"] }, + { shape: "it.skipIf(false).fails", parts: ["it", "skipIf(false)", "fails"] }, + { shape: "it.only.fails", parts: ["it", "only", "fails"] }, + { shape: "it.fails.each", parts: ["it", "fails", "each([[1, 2]])"] }, + { shape: "it.fails.only", parts: ["it", "fails", "only"] }, + { shape: "it.fails.concurrent", parts: ["it", "fails", "concurrent"] }, + { shape: "it.fails.skipIf", parts: ["it", "fails", "skipIf(flag)"] }, +]; + +// why: a matcher that fires on `it.skip` or a bare `it` would hold back code the suite needs, so +// the shapes it must leave alone are pinned beside the ones it must catch. +const otherRegistrations: { shape: string; parts: string[] }[] = [ + { shape: "it.skip", parts: ["it", "skip"] }, + { shape: "it.todo", parts: ["it", "todo"] }, + { shape: "it.only", parts: ["it", "only"] }, + { shape: "it", parts: ["it"] }, + { shape: "expect(promise).rejects.toThrow", parts: ["expect(promise)", "rejects", "toThrow"] }, +]; // why: enumerated from `git ls-files` rather than a directory walk, so the scan reaches every // tree the rule covers and not only the ones this file happens to name (testing rule 4). @@ -31,6 +62,16 @@ const testFiles = execFileSync( } }); +function expectedFailuresIn(text: string, name: string): string[] { + const stripped = stripComments(text); + const found: string[] = []; + for (const match of stripped.matchAll(EXPECTED_FAILURE)) { + const line = stripped.slice(0, match.index).split("\n").length; + found.push(`${name}:${line}: ${(match[0] ?? "").split("\n")[0]?.trim() ?? ""}`); + } + return found; +} + describe("the tracked test files", () => { it("were enumerated from the git index, in `src/`, `e2e/` and `ui/` alike", () => { // why: a pathspec or a `cwd` that matched nothing would leave the scan below with no file to @@ -45,13 +86,51 @@ describe("the tracked test files", () => { it("hold no test written to pass by failing", () => { const offenders = testFiles.flatMap((name) => - stripComments(readFileSync(join(REPO_ROOT, name), "utf8")) - .split("\n") - .flatMap((line, index) => - EXPECTED_FAILURE.test(line) ? [`${name}:${index + 1}: ${line.trim()}`] : [], - ), + expectedFailuresIn(readFileSync(join(REPO_ROOT, name), "utf8"), name), ); expect(offenders).toEqual([]); }); }); + +describe("the expected-failure matcher", () => { + it.each(expectedFailureSpellings)("finds the expected failure in `$shape`", ({ parts }) => { + const call = `${parts.join(".")}("a title", () => {})`; + + expect(expectedFailuresIn(call, "probe.test.ts")).toHaveLength(1); + }); + + it.each(otherRegistrations)("finds no expected failure in `$shape`", ({ parts }) => { + const call = `${parts.join(".")}("a title", () => {})`; + + expect(expectedFailuresIn(call, "probe.test.ts")).toEqual([]); + }); + + it("matches a call whose table is written across several lines", () => { + // why: the call's head is assembled here rather than written out, because a string holding + // the whole call is text the scanner reads and would count against this file. + const call = [ + `${["it", "fails", "each"].join(".")}([`, + " [1, 2],", + "])(", + ' "a title",', + " (a, b) => {},", + ")", + ].join("\n"); + + // why: the expected offender is rebuilt from `call` rather than written out, because a string + // holding the whole call is text this file's own scan reads, and it would then name itself. + expect(expectedFailuresIn(call, "probe.test.ts")).toEqual([ + `probe.test.ts:1: ${call.split("\n")[0]}`, + ]); + }); + + it("does not report a hit for prose that only names the API", () => { + // why: built in pieces for the same reason as the call above — a string holding the whole call + // is text this file's own scan reads, and it would then name itself. + const named = `// ${["it", "fails", "each([[1, 2]])"].join(".")}("a title", () => {})`; + const withProse = [named, 'it.todo("a title")'].join("\n"); + + expect(expectedFailuresIn(withProse, "probe.test.ts")).toEqual([]); + }); +}); From 23836566f9e9e5cb2b6c6b2d6e45f2823e532007 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 16 Oct 2026 21:30:59 +0200 Subject: [PATCH 5/5] test: report an expected-failure offender on the line the call is written on why: stripComments dropped a block comment without its newlines, so the meta-test's report pointed a reader at the header above the call rather than at the call itself. The strip now leaves a block comment's newlines in place, and the meta-test pins the reported line for a call written below a multi-line header. --- src/expected-failures.test.ts | 17 +++++++++++++++++ src/test-support/imports.ts | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/expected-failures.test.ts b/src/expected-failures.test.ts index 85ca5373e..2fd860dc2 100644 --- a/src/expected-failures.test.ts +++ b/src/expected-failures.test.ts @@ -125,6 +125,23 @@ describe("the expected-failure matcher", () => { ]); }); + it("reports the line the call is written on, even below a multi-line comment", () => { + // why: the offender is reported as path and line so a reader opens the file at the right + // place; a comment stripped without its newlines would point them at the header instead. + const file = [ + "/*", + " * a header", + " * of several", + " */", + `${["it", "fails"].join(".")}("a title", () => {})`, + ].join("\n"); + // why: the expected report line is assembled from pieces like the calls above, because a + // string holding the whole call is text this file's own scan reads, and it would name itself. + expect(expectedFailuresIn(file, "probe.test.ts")).toEqual([ + `probe.test.ts:5: ${["it", "fails("].join(".")}`, + ]); + }); + it("does not report a hit for prose that only names the API", () => { // why: built in pieces for the same reason as the call above — a string holding the whole call // is text this file's own scan reads, and it would then name itself. diff --git a/src/test-support/imports.ts b/src/test-support/imports.ts index 88ed861bb..7ee8b4175 100644 --- a/src/test-support/imports.ts +++ b/src/test-support/imports.ts @@ -19,7 +19,11 @@ export const srcDir = dirname(dirname(fileURLToPath(import.meta.url))); * naming a forbidden import) is never mistaken for a real one. Good enough for this repo's * source, which never puts `//` inside an import specifier string. */ export function stripComments(source: string): string { - return source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, ""); + // why: a block comment leaves its newlines behind, so a report that counts lines in the + // stripped text names the line the reported code is actually written on. + return source + .replace(/\/\*[\s\S]*?\*\//g, (block) => block.replace(/[^\n]/g, "")) + .replace(/\/\/.*$/gm, ""); } /**