Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devloop",
"version": "0.10.2",
"version": "0.10.3",
"description": "Generische agentische Dev-Loop-Kette: /devloop:specify|spec-to-tests|implement|critic|loop + Bindungs-Anker (Wächter-Vorbedingung, content-gebundene Stopps, CI-Required-Check). Projektübergreifend.",
"author": { "name": "Tobias Mogdans" }
}
5 changes: 4 additions & 1 deletion dist/cli/verify-unskip.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ if (isSpecBranch(headBranch)) {
process.stdout.write(JSON.stringify({ ok: true, skipped: "spec-PR (devloop/spec/*)" }) + "\n");
process.exit(0);
}
const TEST_FILE = /\.(test|spec)\.[jt]sx?$/;
// What counts as a test file: vitest's DEFAULT include (**/*.{test,spec}.?(c|m)[jt]s?(x)).
// Limit: a project with its own `include`, or another runner, can run files this does not name
// (see #21).
const TEST_FILE = /\.(test|spec)\.[cm]?[jt]sx?$/;
// The glob list is read from the BASE ref first: the scope that is already on the protected
// branch decides, so a PR cannot loosen the seam for itself. Only if the file does not exist on
// base do we fall back to the checkout (a repo adopting the file — that PR necessarily touches
Expand Down
56 changes: 56 additions & 0 deletions docs/2026-11-25-verify-unskip-testendungen-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# verify-unskip: Testdatei = was vitest per Default einsammelt — Design

> devloop, Issue #23. Die Unskip-Naht erkennt Testdateien an einer festen Endung, die enger ist als
> das Default-Include von vitest. Dateien dazwischen führt vitest aus, die Naht prüft sie nicht.
> Status: **abgenommen** (2026-11-25).

## Ist-Zustand (main, e565b3e — v0.10.2)

- `src/cli/verify-unskip.ts:37`: `TEST_FILE = /\.(test|spec)\.[jt]sx?$/` — einzige Stelle im Code,
die eine Testdatei definiert.
- vitest 2.1.9 (Repo-Stand) Default-Include: `**/*.{test,spec}.?(c|m)[jt]s?(x)`.
- Lücke: `.mts`, `.cts`, `.mjs`, `.cjs` (und `.mtsx`/`.ctsx`/`.mjsx`/`.cjsx`). Gemessen (Critic zu
#19/#20): neue `test/evil.test.mts` mit aktivem `test("evil")` → Naht `ok: true` auf main wie auf
dem Stand von #24, vitest: `✓ test/evil.test.mts (1 test)`.

## Anforderungen (EARS)

- **REQ-TESTEXT-1** *(ubiquitous)* — `verify-unskip` soll jeden geänderten Pfad als Testdatei
behandeln, dessen Dateiname auf `.test.` oder `.spec.` gefolgt von der Endung
`?(c|m)[jt]s?(x)` endet — genau die Menge des vitest-Default-Includes. Regex-Form:
`/\.(test|spec)\.[cm]?[jt]sx?$/`.
- **REQ-TESTEXT-2** *(ubiquitous)* — Pfade, die das vitest-Default-Include nicht trifft, bleiben
keine Testdateien (z. B. `foo.mts`, `foo.test.json`, `foo.test.d.ts`,
`foo.test-d.ts`). Alles andere an der Naht bleibt unverändert.

## Detektoren (Wirkung) und Mutationsproben

CLI-Tests gegen `dist/cli/verify-unskip.js` in echten temporären Git-Repos (Default-Scope):

| Fall | Erwartung | tötet Mutation |
|---|---|---|
| neue aktive `t/a.test.mts`, `t/b.test.cts`, `t/c.spec.mjs`, `t/d.test.cjs` (je eigener Lauf) | Exit 1, Datei in `violations` | alter Regex |
| neue aktive `t/e.test.mtsx` | Exit 1 | `x`-Suffix für c/m vergessen |
| bestehende `t/f.test.mts` geskippt, PR entfernt nur `.skip` | Exit 0, Datei in `checked` | — (Gegenprobe) |
| neue aktive `t/g.mts` (ohne `.test.`) | Exit 0, nicht in `checked` | Regex zu weit (`.test.` optional) |
| neue aktive `t/h.test.xts` bzw. `t/i.test.json` | Exit 0, nicht in `checked` | Regex zu weit (beliebiger Präfixbuchstabe / beliebige Endung) |
| Abgleich: jede Datei der obigen Liste mit `vitest list` (bzw. `vitest run`) im Test-Repo gegengeprüft — Naht-Menge == vitest-Menge | gleich | Abweichung Regex ↔ vitest |

Der letzte Detektor prüft die Wirkung (vitest sammelt genau diese Dateien ein), nicht nur die
Regex-Form. Ist `vitest list` im Test nicht praktikabel, wird der Abgleich einmalig gemessen und
im PR dokumentiert.

## Bekannte Grenzen

- **Eigenes `include` in der vitest-Config des Ziel-Repos** (oder ein anderer Runner, z. B. Jests
`__tests__/**`) wird nicht gelesen. Robust wäre, die Testdateien über den Runner selbst zu
sammeln — gehört zu #21.
- **Groß/Klein-Schreibung der Endung** (`.TEST.TS`): vitest-Globs sind auf Linux
case-sensitiv, der Regex ebenso. Auf case-insensitiven Dateisystemen nicht betrachtet.
- **Default-Exclude von vitest wird nicht nachgebildet** (`node_modules/`, `dist/`, `cypress/`,
`.{idea,git,cache,output,temp}/`, `*.config.*`). Testnamen in diesen Ordnern prüft die Naht,
obwohl vitest sie nicht ausführt. Das ist eine Überprüfung, kein Durchlass. Derselbe Fehlalarm
bestand schon für `.js`/`.ts` und trifft jetzt auch `.mjs`/`.cjs`/`.mts`/`.cts`. Er betrifft nur
Repos, die solche Dateien committen (Critic zu #23, F1).
- **Verzeichnis-Symlinks**, denen vitest folgt, sieht die Naht nicht. Das bestand schon vorher
und liegt außerhalb von REQ-TESTEXT → #25.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devloop",
"version": "0.10.2",
"version": "0.10.3",
"private": true,
"type": "module",
"license": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion src/cli/verify-unskip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ if (isSpecBranch(headBranch)) {
process.exit(0);
}

const TEST_FILE = /\.(test|spec)\.[jt]sx?$/;
// What counts as a test file: vitest's DEFAULT include (**/*.{test,spec}.?(c|m)[jt]s?(x)).
// Limit: a project with its own `include`, or another runner, can run files this does not name
// (see #21).
const TEST_FILE = /\.(test|spec)\.[cm]?[jt]sx?$/;

// The glob list is read from the BASE ref first: the scope that is already on the protected
// branch decides, so a PR cannot loosen the seam for itself. Only if the file does not exist on
Expand Down
155 changes: 155 additions & 0 deletions test/cli/verify-unskip-testendungen.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { test, expect, beforeEach, afterEach } from "vitest";
import { execFileSync, spawnSync } from "node:child_process";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { fileURLToPath } from "node:url";
import { dirname, join, relative, resolve } from "node:path";

// Issue #23: what verify-unskip treats as a test file must equal what vitest collects by default
// (**/*.{test,spec}.?(c|m)[jt]s?(x)). Real git repos, default scope (no managed-tests.json).

const here = dirname(fileURLToPath(import.meta.url));
const cli = resolve(here, "../../dist/cli/verify-unskip.js");
const vitestBin = resolve(here, "../../node_modules/vitest/vitest.mjs");

let repo: string;
const git = (...args: string[]) =>
execFileSync("git", ["-C", repo, ...args], {
encoding: "utf8",
env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" },
});
const commit = (m: string) => git("-c", "commit.gpgsign=false", "commit", "-q", "-m", m);
const put = (rel: string, content: string) => {
mkdirSync(dirname(join(repo, rel)), { recursive: true });
writeFileSync(join(repo, rel), content);
};
const run = () => spawnSync("node", [cli, repo, "main"], { encoding: "utf8" });
const files = (list: { file: string }[]) => list.map((v) => v.file);

const ACTIVE = `import { test } from "vitest";\ntest("evil", () => {});\n`;
const SKIPPED = `import { test } from "vitest";\ntest.skip("REQ-X-1 later", () => {});\n`;
const UNSKIPPED = SKIPPED.replace("test.skip(", "test(");

beforeEach(() => {
repo = mkdtempSync(join(tmpdir(), "devloop-testext-"));
git("init", "-q", "-b", "main");
git("config", "user.name", "t");
git("config", "user.email", "t@t");
git("config", "core.quotePath", "true");
put("README.md", "base\n");
git("add", "-A");
commit("base");
git("checkout", "-q", "-b", "devloop/impl");
});
afterEach(() => rmSync(repo, { recursive: true, force: true }));

const addCommit = (rel: string, content: string) => {
put(rel, content);
git("add", "-A");
commit(`implement: add ${rel}`);
};

// ---- REQ-TESTEXT-1: the extra extensions are test files (each file in its own run) ----

for (const f of ["t/a.test.mts", "t/b.test.cts", "t/c.spec.mjs", "t/d.test.cjs", "t/e.test.mtsx"]) {
test(`[REQ-TESTEXT-1] new active ${f} is a violation (exit 1)`, () => {
addCommit(f, ACTIVE);
const r = run();
expect(r.status).toBe(1);
const out = JSON.parse(r.stdout);
expect(out.ok).toBe(false);
expect(files(out.violations)).toEqual([f]);
expect(out.checked).toEqual([f]);
});
}

test("[REQ-TESTEXT-1] counter-probe: existing skipped t/f.test.mts with only .skip removed passes and is checked", () => {
git("checkout", "-q", "main");
put("t/f.test.mts", SKIPPED);
git("add", "-A");
commit("base: skipped .mts test");
git("checkout", "-q", "-b", "devloop/impl2");
addCommit("t/f.test.mts", UNSKIPPED);
const r = run();
expect(r.status).toBe(0);
const out = JSON.parse(r.stdout);
expect(out.violations).toEqual([]);
expect(out.checked).toEqual(["t/f.test.mts"]);
});

// ---- REQ-TESTEXT-2: not-too-wide (counter-probes; green against the old regex by construction) ----

for (const f of ["t/g.mts", "t/h.test.xts", "t/i.test.json", "t/j.test.d.ts", "t/k.test-d.ts", "t/a.TEST.ts", "t/b.Test.TS"]) {
test(`[REQ-TESTEXT-2] new active ${f} is NOT a test file (exit 0, not checked)`, () => {
addCommit(f, ACTIVE);
const r = run();
expect(r.status).toBe(0);
const out = JSON.parse(r.stdout);
expect(out.ok).toBe(true);
expect(out.checked).toEqual([]);
expect(out.unmanaged).toEqual([]);
expect(out.violations).toEqual([]);
});
}

// Ordinary case: an EXISTING non-test file whose name merely ends in "test"/"spec" letters is changed.
for (const f of ["t/latest.ts", "t/contest.js"]) {
test(`[REQ-TESTEXT-2] existing ${f} (no dot before 'test') changed by the PR is NOT a test file (exit 0, not checked)`, () => {
git("checkout", "-q", "main");
put(f, ACTIVE);
git("add", "-A");
commit(`base: ${f}`);
git("checkout", "-q", "-b", "devloop/impl-ordinary");
addCommit(f, ACTIVE + "// changed by the PR\n");
const r = run();
expect(r.status).toBe(0);
const out = JSON.parse(r.stdout);
expect(out.ok).toBe(true);
expect(out.checked).toEqual([]);
expect(out.unmanaged).toEqual([]);
expect(out.violations).toEqual([]);
});
}

// ---- Effect: seam set == the set vitest collects by default ----

test("[REQ-TESTEXT-1] the seam's checked set equals the set vitest collects (vitest list) for the table's files", () => {
const all = [
"t/a.test.mts", "t/b.test.cts", "t/c.spec.mjs", "t/d.test.cjs", "t/e.test.mtsx", "t/f.test.mts",
"t/g.mts", "t/h.test.xts", "t/i.test.json", "t/j.test.d.ts", "t/k.test-d.ts",
"t/l.test.ts", "t/m.spec.jsx", "t/n.test.js",
"t/latest.ts", "t/contest.js", "t/o.TEST.ts", "t/p.Test.TS",
];
put("package.json", '{"type":"module"}\n');
git("add", "-A");
commit("implement: package.json");
for (const f of all) {
// f is skipped (like an existing spec-authored test), everything else active
put(f, f === "t/f.test.mts" ? SKIPPED : ACTIVE);
}
git("add", "-A");
commit("implement: all files of the table");

const t0 = Date.now();
const v = spawnSync("node", [vitestBin, "list", "--json", "--filesOnly", "--root", repo], {
cwd: repo,
encoding: "utf8",
timeout: 60_000,
maxBuffer: 16 * 1024 * 1024,
});
const elapsed = Date.now() - t0;
expect(v.status, v.stderr).toBe(0);
const listed = JSON.parse(v.stdout) as { file: string }[];
const vitestSet = [...new Set(listed.map((e) => relative(repo, e.file).split("\\").join("/")))].sort();
// Sanity: vitest really collected the repo (otherwise an empty == empty comparison proves nothing).
expect(vitestSet).toContain("t/l.test.ts");
expect(vitestSet).toContain("t/e.test.mtsx");
expect(vitestSet).not.toContain("t/g.mts");
// vitest collects none of the near-miss names (no dot before test/spec; upper/mixed case)
for (const f of ["t/latest.ts", "t/contest.js", "t/o.TEST.ts", "t/p.Test.TS"]) expect(vitestSet).not.toContain(f);

const r = run();
const out = JSON.parse(r.stdout);
expect([...out.checked].sort()).toEqual(vitestSet);
expect(elapsed).toBeLessThan(20_000);
});
Loading