@agentvibes/guardrails 0.2.4 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -25
- package/dist/cli.js +8 -6
- package/dist/cli.js.map +1 -1
- package/dist/doctor.js +6 -15
- package/dist/doctor.js.map +1 -1
- package/dist/jsxSuppressTest.js +15 -9
- package/dist/jsxSuppressTest.js.map +1 -1
- package/dist/metricsCollect.js +113 -97
- package/dist/metricsCollect.js.map +1 -1
- package/dist/oxcAst.d.ts +27 -0
- package/dist/oxcAst.js +82 -0
- package/dist/oxcAst.js.map +1 -0
- package/dist/pipeOutputTest.d.ts +1 -0
- package/dist/pipeOutputTest.js +54 -0
- package/dist/pipeOutputTest.js.map +1 -0
- package/dist/presetDrift.d.ts +1 -16
- package/dist/presetDrift.js +13 -29
- package/dist/presetDrift.js.map +1 -1
- package/dist/presetDriftTest.js +76 -130
- package/dist/presetDriftTest.js.map +1 -1
- package/dist/verify.js +4 -13
- package/dist/verify.js.map +1 -1
- package/dist/verifyDiff.js +10 -3
- package/dist/verifyDiff.js.map +1 -1
- package/package.json +7 -5
package/dist/oxcAst.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CallExpression, type Node, type Program } from "oxc-parser";
|
|
2
|
+
export interface ParsedFile {
|
|
3
|
+
program: Program;
|
|
4
|
+
/** 1-based line of a UTF-16 offset — oxc-parser reports UTF-16 offsets, as `text` indexes. */
|
|
5
|
+
lineAt: (offset: number) => number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* `.tsx` and `.jsx` both parse as TSX, as `ts.ScriptKind.TSX` did, so a `.jsx`
|
|
9
|
+
* file carrying TypeScript syntax still parses. Parentheses are kept as
|
|
10
|
+
* `ParenthesizedExpression` nodes (oxc's default), matching the TypeScript AST,
|
|
11
|
+
* where `observer((fn))` does not unwrap to the function either.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseFile(file: string, text: string): ParsedFile;
|
|
14
|
+
/** The member(s) of the node union whose `type` can be `K` (a Function's `type` is itself a union). */
|
|
15
|
+
export type NodeOf<K extends Node["type"]> = Node extends infer N ? N extends {
|
|
16
|
+
type: infer T;
|
|
17
|
+
} ? K extends T ? N : never : never : never;
|
|
18
|
+
/** `ts.isX(node)` for the ESTree: narrows by `type`. */
|
|
19
|
+
export declare function isKind<K extends Node["type"]>(node: Node, ...kinds: K[]): node is NodeOf<K>;
|
|
20
|
+
/** Every direct child node, the ESTree counterpart of `ts.Node.forEachChild`. */
|
|
21
|
+
export declare function forEachChild(node: Node, visit: (child: Node) => void): void;
|
|
22
|
+
/**
|
|
23
|
+
* `foo()` → "foo", `a.foo()` / `a?.foo()` → "foo", `a.#foo()` → "#foo";
|
|
24
|
+
* anything else (computed, parenthesized, `super()`) has no name — the same
|
|
25
|
+
* answers the TypeScript-AST version gave for Identifier / PropertyAccess.
|
|
26
|
+
*/
|
|
27
|
+
export declare function calleeName(node: CallExpression): string | undefined;
|
package/dist/oxcAst.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
/**
|
|
3
|
+
* `.tsx` and `.jsx` both parse as TSX, as `ts.ScriptKind.TSX` did, so a `.jsx`
|
|
4
|
+
* file carrying TypeScript syntax still parses. Parentheses are kept as
|
|
5
|
+
* `ParenthesizedExpression` nodes (oxc's default), matching the TypeScript AST,
|
|
6
|
+
* where `observer((fn))` does not unwrap to the function either.
|
|
7
|
+
*/
|
|
8
|
+
export function parseFile(file, text) {
|
|
9
|
+
const lang = file.endsWith(".tsx") || file.endsWith(".jsx") ? "tsx" : "ts";
|
|
10
|
+
const { program } = parseSync(file, text, { lang, preserveParens: true });
|
|
11
|
+
const starts = [0];
|
|
12
|
+
for (let i = 0; i < text.length; i++) {
|
|
13
|
+
if (text.charCodeAt(i) === 10)
|
|
14
|
+
starts.push(i + 1);
|
|
15
|
+
}
|
|
16
|
+
const lineAt = (offset) => {
|
|
17
|
+
let lo = 0;
|
|
18
|
+
let hi = starts.length - 1;
|
|
19
|
+
while (lo < hi) {
|
|
20
|
+
const mid = (lo + hi + 1) >> 1;
|
|
21
|
+
if ((starts[mid] ?? 0) <= offset)
|
|
22
|
+
lo = mid;
|
|
23
|
+
else
|
|
24
|
+
hi = mid - 1;
|
|
25
|
+
}
|
|
26
|
+
return lo + 1;
|
|
27
|
+
};
|
|
28
|
+
return { program, lineAt };
|
|
29
|
+
}
|
|
30
|
+
/** `ts.isX(node)` for the ESTree: narrows by `type`. */
|
|
31
|
+
export function isKind(node, ...kinds) {
|
|
32
|
+
return kinds.some((k) => k === node.type);
|
|
33
|
+
}
|
|
34
|
+
function isNode(value) {
|
|
35
|
+
return (typeof value === "object" && value !== null && "type" in value && typeof value.type === "string");
|
|
36
|
+
}
|
|
37
|
+
// Keys that can hold a child, per node type. A field's value kind is fixed by
|
|
38
|
+
// the node type (an `init` is a node or null, never a string), so the first node
|
|
39
|
+
// of a type fixes the list; walking every own key of every node through
|
|
40
|
+
// `Object.entries` was the single largest cost of `metrics` on a 4000-file repo.
|
|
41
|
+
const childKeys = new Map();
|
|
42
|
+
function childKeysOf(node) {
|
|
43
|
+
const known = childKeys.get(node.type);
|
|
44
|
+
if (known !== undefined)
|
|
45
|
+
return known;
|
|
46
|
+
const keys = Object.entries(node)
|
|
47
|
+
.filter(([key, value]) => key !== "parent" && typeof value === "object")
|
|
48
|
+
.map(([key]) => key);
|
|
49
|
+
childKeys.set(node.type, keys);
|
|
50
|
+
return keys;
|
|
51
|
+
}
|
|
52
|
+
/** Every direct child node, the ESTree counterpart of `ts.Node.forEachChild`. */
|
|
53
|
+
export function forEachChild(node, visit) {
|
|
54
|
+
for (const key of childKeysOf(node)) {
|
|
55
|
+
const value = Reflect.get(node, key);
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
for (const item of value) {
|
|
58
|
+
if (isNode(item))
|
|
59
|
+
visit(item);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (isNode(value)) {
|
|
63
|
+
visit(value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `foo()` → "foo", `a.foo()` / `a?.foo()` → "foo", `a.#foo()` → "#foo";
|
|
69
|
+
* anything else (computed, parenthesized, `super()`) has no name — the same
|
|
70
|
+
* answers the TypeScript-AST version gave for Identifier / PropertyAccess.
|
|
71
|
+
*/
|
|
72
|
+
export function calleeName(node) {
|
|
73
|
+
const callee = node.callee;
|
|
74
|
+
if (isKind(callee, "Identifier"))
|
|
75
|
+
return callee.name;
|
|
76
|
+
if (isKind(callee, "MemberExpression") && !callee.computed) {
|
|
77
|
+
const property = callee.property;
|
|
78
|
+
return isKind(property, "PrivateIdentifier") ? `#${property.name}` : property.name;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=oxcAst.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oxcAst.js","sourceRoot":"","sources":["../src/oxcAst.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,SAAS,EAAE,MAAM,YAAY,CAAC;AAarF;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,IAAY;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1E,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,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M,EAAE,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC3D,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QACjC,OAAO,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;IACrF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { packageRoot } from "./packagePaths.js";
|
|
6
|
+
// `--json` read through a pipe must arrive whole (is-5cc188b7). The CLI used to
|
|
7
|
+
// end with `process.exit(code)`; stdout to a pipe is asynchronous in Node, so
|
|
8
|
+
// everything past the first 64 KiB the pipe buffer took was dropped — measured
|
|
9
|
+
// `metrics --json . | wc -c` = 65536 against 128389 bytes redirected to a file.
|
|
10
|
+
// The fixture is sized to produce well over 64 KiB, so the old CLI fails here.
|
|
11
|
+
const CLI = join(packageRoot, "dist", "cli.js");
|
|
12
|
+
const COMPONENTS = 400;
|
|
13
|
+
function sh(cwd, script) {
|
|
14
|
+
const res = spawnSync("sh", ["-c", script], {
|
|
15
|
+
cwd,
|
|
16
|
+
encoding: "utf8",
|
|
17
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
18
|
+
});
|
|
19
|
+
if (res.error)
|
|
20
|
+
throw res.error;
|
|
21
|
+
return { status: res.status ?? -1, stdout: res.stdout };
|
|
22
|
+
}
|
|
23
|
+
function main() {
|
|
24
|
+
const dir = mkdtempSync(join(tmpdir(), "guardrails-pipe-"));
|
|
25
|
+
try {
|
|
26
|
+
for (let i = 0; i < COMPONENTS; i++) {
|
|
27
|
+
writeFileSync(join(dir, `Card${i}.tsx`), `export const Card${i} = ({ a, b }: { a: string; b: number }) => <div title={a}>{b}</div>;\n`);
|
|
28
|
+
}
|
|
29
|
+
sh(dir, "git init -q && git add -A");
|
|
30
|
+
const toFile = sh(dir, `node "${CLI}" metrics --json . > out.json`);
|
|
31
|
+
const fileBytes = readFileSync(join(dir, "out.json"), "utf8");
|
|
32
|
+
const piped = sh(dir, `node "${CLI}" metrics --json . | cat`);
|
|
33
|
+
if (fileBytes.length <= 64 * 1024) {
|
|
34
|
+
console.error(`FAIL pipe-output: fixture produced only ${fileBytes.length} bytes — it must exceed 64 KiB to test anything`);
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
if (toFile.status !== piped.status) {
|
|
38
|
+
console.error(`FAIL pipe-output: exit ${piped.status} through a pipe, ${toFile.status} to a file`);
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
if (piped.stdout !== fileBytes) {
|
|
42
|
+
console.error(`FAIL pipe-output: ${piped.stdout.length} bytes through a pipe, ${fileBytes.length} to a file`);
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
JSON.parse(piped.stdout);
|
|
46
|
+
console.log(` ok pipe-output: ${fileBytes.length} bytes through a pipe, identical to the file`);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
rmSync(dir, { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
process.exitCode = main();
|
|
54
|
+
//# sourceMappingURL=pipeOutputTest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeOutputTest.js","sourceRoot":"","sources":["../src/pipeOutputTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAA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
7
7
|
}
|
|
8
|
-
/** Every biome config in the tree, repo-root-relative, excluding
|
|
8
|
+
/** Every biome config in the tree, repo-root-relative, excluding node_modules. */
|
|
9
9
|
export declare function findBiomeConfigs(root: string): string[];
|
|
10
10
|
/**
|
|
11
11
|
* Everything wrong with `root`'s biome configuration; [] when it conforms.
|
|
12
12
|
* `root` is the repo being checked, not this package.
|
|
13
13
|
*/
|
|
14
14
|
export declare function presetDrift(root: string): DriftFinding[];
|
|
15
|
-
/**
|
|
16
|
-
* Whether drift GATES in this repo, from `[biome] preset = "enforced"` in
|
|
17
|
-
* `.agentvibes/project.toml`.
|
|
18
|
-
*
|
|
19
|
-
* Opt-in per repo, then flipped (owner, 2026-09-06). Failing every repo the day
|
|
20
|
-
* this shipped would have turned 5 of the 7 repos that run this gate red —
|
|
21
|
-
* SiteCraftMonorepo, faceless-photo-lib, agent-session-observatory, tg-gallery,
|
|
22
|
-
* merkle-substrate — before the migration issue for each was worked, blocking
|
|
23
|
-
* unrelated work in all five. Each child of epic is-a70a5963 adds the line as
|
|
24
|
-
* its last step; when the last child lands, this default flips to enforced.
|
|
25
|
-
*
|
|
26
|
-
* Unenforced is NOT silent: `verify` prints the drift as a note and `doctor`
|
|
27
|
-
* always reports it. What the flag decides is the exit code, not the message.
|
|
28
|
-
*/
|
|
29
|
-
export declare function presetEnforced(cwd: string): boolean;
|
|
30
15
|
/** The one-line message the gate prints; "" when there is no drift. */
|
|
31
16
|
export declare function driftMessage(findings: DriftFinding[]): string;
|
package/dist/presetDrift.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { join, relative, resolve } from "node:path";
|
|
3
3
|
import { packageRoot } from "./packagePaths.js";
|
|
4
|
-
import { readTomlTable } from "./tomlTable.js";
|
|
5
4
|
// Preset-drift guard (is-9c7a78d7). The migration epic is-a70a5963 collapses 37
|
|
6
5
|
// hand-rolled biome configs into one preset; nothing stopped a repo from
|
|
7
6
|
// re-growing its own the week after. Owner's rule, 2026-09-03: «we should only
|
|
@@ -20,6 +19,11 @@ import { readTomlTable } from "./tomlTable.js";
|
|
|
20
19
|
// turns `noConsole` off for some paths (a CLI has to print), or
|
|
21
20
|
// `noEmptyBlockStatements` off for TEST paths (see OVERRIDABLE).
|
|
22
21
|
//
|
|
22
|
+
// Drift GATES in every repo: `verify` exits 2 and `doctor` exits 1, as the
|
|
23
|
+
// acceptance of is-9c7a78d7 requires. Up to 0.2.4 it gated only where a repo
|
|
24
|
+
// had opted in with `[biome] preset = "enforced"`; that line is now inert, and
|
|
25
|
+
// a repo that has not migrated goes red the day it upgrades guardrails.
|
|
26
|
+
//
|
|
23
27
|
// A repo with no biome config at all is not drifting and reports nothing —
|
|
24
28
|
// there is no config to have re-grown. `guardrails doctor` still shows it as
|
|
25
29
|
// absent, and `guardrails init` writes one.
|
|
@@ -59,17 +63,14 @@ function testScoped(entry) {
|
|
|
59
63
|
const positive = raw.filter((g) => typeof g === "string" && !g.startsWith("!"));
|
|
60
64
|
return positive.length > 0 && positive.every((g) => TEST_PATH.test(g));
|
|
61
65
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
".claude",
|
|
71
|
-
]);
|
|
72
|
-
/** Every biome config in the tree, repo-root-relative, excluding SKIP_DIRS. */
|
|
66
|
+
// Only node_modules: a dependency's own biome.json is not this repo's config.
|
|
67
|
+
// Every other directory is walked, build output and dot-directories included —
|
|
68
|
+
// a config under dist/, .claude/ or .next/ is still a second config, and the
|
|
69
|
+
// acceptance criterion names node_modules as the one exception (is-9c7a78d7).
|
|
70
|
+
// Consequence: an agent worktree kept inside the repo (`.claude/worktrees/<n>/`)
|
|
71
|
+
// carries its own biome.json and is reported locally; CI checkouts have none.
|
|
72
|
+
const SKIP_DIRS = new Set(["node_modules"]);
|
|
73
|
+
/** Every biome config in the tree, repo-root-relative, excluding node_modules. */
|
|
73
74
|
export function findBiomeConfigs(root) {
|
|
74
75
|
const out = [];
|
|
75
76
|
const visit = (dir) => {
|
|
@@ -237,23 +238,6 @@ export function presetDrift(root) {
|
|
|
237
238
|
}
|
|
238
239
|
return findings;
|
|
239
240
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Whether drift GATES in this repo, from `[biome] preset = "enforced"` in
|
|
242
|
-
* `.agentvibes/project.toml`.
|
|
243
|
-
*
|
|
244
|
-
* Opt-in per repo, then flipped (owner, 2026-09-06). Failing every repo the day
|
|
245
|
-
* this shipped would have turned 5 of the 7 repos that run this gate red —
|
|
246
|
-
* SiteCraftMonorepo, faceless-photo-lib, agent-session-observatory, tg-gallery,
|
|
247
|
-
* merkle-substrate — before the migration issue for each was worked, blocking
|
|
248
|
-
* unrelated work in all five. Each child of epic is-a70a5963 adds the line as
|
|
249
|
-
* its last step; when the last child lands, this default flips to enforced.
|
|
250
|
-
*
|
|
251
|
-
* Unenforced is NOT silent: `verify` prints the drift as a note and `doctor`
|
|
252
|
-
* always reports it. What the flag decides is the exit code, not the message.
|
|
253
|
-
*/
|
|
254
|
-
export function presetEnforced(cwd) {
|
|
255
|
-
return readTomlTable(join(cwd, ".agentvibes", "project.toml"), "biome").preset === "enforced";
|
|
256
|
-
}
|
|
257
241
|
/** The one-line message the gate prints; "" when there is no drift. */
|
|
258
242
|
export function driftMessage(findings) {
|
|
259
243
|
if (findings.length === 0)
|
package/dist/presetDrift.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presetDrift.js","sourceRoot":"","sources":["../src/presetDrift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBA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AC;AAED,uEAAuE;AACvE,MAAM,UAAU,YAAY,CAAC,QAAwB;IACnD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,OAAO,uBAAuB,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAoC,gBAAgB,gDAAgD,CAAC;AAC7K,CAAC"}
|
package/dist/presetDriftTest.js
CHANGED
|
@@ -1,57 +1,50 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
5
|
import { packageRoot } from "./packagePaths.js";
|
|
6
6
|
import { presetDrift } from "./presetDrift.js";
|
|
7
7
|
// Fixtures for the preset-drift guard (is-9c7a78d7). The migration epic
|
|
8
8
|
// is-a70a5963 collapses 37 hand-rolled biome configs into one preset; this is
|
|
9
9
|
// what stops a repo re-growing its own afterwards.
|
|
10
10
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
11
|
+
// The fixtures live in test/preset-drift/ (see its README): `valid/` must pass,
|
|
12
|
+
// `invalid/<key>--<name>.json` must report drift with that finding key. Every
|
|
13
|
+
// one is run through the library AND the CLI, because the exit codes are the
|
|
14
|
+
// gate: drift fails `verify` (exit 2) and `doctor` (exit 1) in every repo, with
|
|
15
|
+
// no opt-in anywhere in the tree.
|
|
16
|
+
const FIXTURES = join(packageRoot, "test", "preset-drift");
|
|
15
17
|
const CLEAN_TS = "export const two = 1 + 1;\n";
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
extends: ["@agentvibes/guardrails/biome"],
|
|
20
|
-
// Scoping its own paths is the repo's business, not the preset's.
|
|
21
|
-
files: { includes: ["**/*.ts", "!**/dist"] },
|
|
22
|
-
// A CLI has to print; this is the one rule an override may touch.
|
|
23
|
-
overrides: [{ includes: ["src/**"], linter: { rules: { suspicious: { noConsole: "off" } } } }],
|
|
24
|
-
}, null, 2);
|
|
25
|
-
const NO_EXTENDS = JSON.stringify({ formatter: { indentWidth: 4 } }, null, 2);
|
|
26
|
-
const OWN_KEYS = JSON.stringify({
|
|
27
|
-
extends: ["@agentvibes/guardrails/biome"],
|
|
28
|
-
formatter: { lineWidth: 80 },
|
|
29
|
-
linter: { rules: { style: { useConst: "off" } } },
|
|
30
|
-
assist: { enabled: false },
|
|
31
|
-
javascript: { formatter: { quoteStyle: "single" } },
|
|
32
|
-
json: { formatter: { indentWidth: 4 } },
|
|
33
|
-
}, null, 2);
|
|
34
|
-
const WIDE_OVERRIDE = JSON.stringify({
|
|
35
|
-
extends: ["@agentvibes/guardrails/biome"],
|
|
36
|
-
overrides: [
|
|
37
|
-
{ includes: ["src/**"], linter: { rules: { style: { useConst: "off" } } } },
|
|
38
|
-
{ includes: ["gen/**"], formatter: { enabled: false } },
|
|
39
|
-
],
|
|
40
|
-
}, null, 2);
|
|
41
|
-
function makeRepo(opts) {
|
|
18
|
+
/** Write one fixture tree (path → JSON value, or raw text) into a fresh temp repo. */
|
|
19
|
+
function materialise(file) {
|
|
20
|
+
const tree = JSON.parse(readFileSync(file, "utf8"));
|
|
42
21
|
const dir = mkdtempSync(join(tmpdir(), "guardrails-preset-"));
|
|
43
22
|
writeFileSync(join(dir, "a.ts"), CLEAN_TS);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
writeFileSync(join(dir, "packages", "web", "biome.json"), opts.secondConfig);
|
|
23
|
+
for (const [path, content] of Object.entries(tree)) {
|
|
24
|
+
const target = join(dir, path);
|
|
25
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
26
|
+
writeFileSync(target, typeof content === "string" ? content : `${JSON.stringify(content, null, 2)}\n`);
|
|
49
27
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
return dir;
|
|
29
|
+
}
|
|
30
|
+
function loadFixtures() {
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const kind of ["valid", "invalid"]) {
|
|
33
|
+
for (const file of readdirSync(join(FIXTURES, kind)).sort()) {
|
|
34
|
+
if (!file.endsWith(".json"))
|
|
35
|
+
continue;
|
|
36
|
+
const base = file.replace(/\.json$/, "");
|
|
37
|
+
const path = join(FIXTURES, kind, file);
|
|
38
|
+
const tree = JSON.parse(readFileSync(path, "utf8"));
|
|
39
|
+
out.push({
|
|
40
|
+
name: `${kind}/${base}`,
|
|
41
|
+
expectKey: kind === "valid" ? undefined : base.split("--")[0],
|
|
42
|
+
dir: materialise(path),
|
|
43
|
+
extraConfigs: Object.keys(tree).filter((p) => p !== "biome.json" && /(^|\/)biome\.jsonc?$/.test(p)),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
53
46
|
}
|
|
54
|
-
return
|
|
47
|
+
return out;
|
|
55
48
|
}
|
|
56
49
|
function run(cwd, command) {
|
|
57
50
|
const res = spawnSync("node", [join(packageRoot, "dist", "cli.js"), command], {
|
|
@@ -70,110 +63,63 @@ function expectStep(step, ok, detail) {
|
|
|
70
63
|
console.log(` ok preset-drift: ${step}`);
|
|
71
64
|
return true;
|
|
72
65
|
}
|
|
66
|
+
function checkFixture(f) {
|
|
67
|
+
const findings = presetDrift(f.dir);
|
|
68
|
+
const shown = JSON.stringify(findings, null, 2);
|
|
69
|
+
const verify = run(f.dir, "verify");
|
|
70
|
+
const doctor = run(f.dir, "doctor");
|
|
71
|
+
if (f.expectKey === undefined) {
|
|
72
|
+
return (expectStep(`${f.name}: no drift`, findings.length === 0, shown) &&
|
|
73
|
+
expectStep(`${f.name}: verify exits 0`, verify.status === 0 && !verify.out.includes("biome preset drift"), `exit ${verify.status}\n${verify.out}`) &&
|
|
74
|
+
expectStep(`${f.name}: doctor prints "no drift" and exits 0`, doctor.status === 0 && doctor.out.includes("biome preset no drift"), `exit ${doctor.status}\n${doctor.out}`));
|
|
75
|
+
}
|
|
76
|
+
return (expectStep(`${f.name}: drift with key "${f.expectKey}"`, findings.some((x) => x.key === f.expectKey), shown) &&
|
|
77
|
+
expectStep(`${f.name}: verify exits 2 and names the drift`, verify.status === 2 && verify.out.includes("biome preset drift"), `exit ${verify.status}\n${verify.out}`) &&
|
|
78
|
+
expectStep(`${f.name}: doctor exits 1 and prints DRIFT`, doctor.status === 1 && doctor.out.includes("biome preset DRIFT"), `exit ${doctor.status}\n${doctor.out}`) &&
|
|
79
|
+
// A second config is reported by PATH, wherever it sits — dist/, .git/ and
|
|
80
|
+
// .claude/ included — in both commands' output.
|
|
81
|
+
(f.expectKey !== "extra-config" ||
|
|
82
|
+
expectStep(`${f.name}: verify and doctor name ${f.extraConfigs.join(", ")}`, f.extraConfigs.every((p) => verify.out.includes(p) && doctor.out.includes(p)), `verify:\n${verify.out}\ndoctor:\n${doctor.out}`)));
|
|
83
|
+
}
|
|
73
84
|
function main() {
|
|
74
|
-
const
|
|
75
|
-
const make = (o) => {
|
|
76
|
-
const r = makeRepo(o);
|
|
77
|
-
repos.push(r);
|
|
78
|
-
return r;
|
|
79
|
-
};
|
|
85
|
+
const fixtures = loadFixtures();
|
|
80
86
|
try {
|
|
81
87
|
let ok = true;
|
|
82
|
-
|
|
83
|
-
const conforming = make({ biome: CONFORMING });
|
|
84
|
-
ok =
|
|
85
|
-
expectStep("a conforming config reports no drift (extends + files + noConsole override)", presetDrift(conforming.dir).length === 0, JSON.stringify(presetDrift(conforming.dir), null, 2)) && ok;
|
|
86
|
-
const noBiome = make({});
|
|
87
|
-
ok =
|
|
88
|
-
expectStep("a repo with no biome config at all reports no drift", presetDrift(noBiome.dir).length === 0, JSON.stringify(presetDrift(noBiome.dir), null, 2)) && ok;
|
|
89
|
-
const noExtends = make({ biome: NO_EXTENDS });
|
|
90
|
-
ok =
|
|
91
|
-
expectStep("(a) a config that does not extend the preset is drift", presetDrift(noExtends.dir).some((f) => f.key === "extends"), JSON.stringify(presetDrift(noExtends.dir), null, 2)) && ok;
|
|
92
|
-
const ownKeys = make({ biome: OWN_KEYS });
|
|
93
|
-
const ownDetail = presetDrift(ownKeys.dir).find((f) => f.key === "own-keys")?.detail ?? "";
|
|
94
|
-
ok =
|
|
95
|
-
expectStep("(b) formatter, linter, assist, javascript.formatter and json.formatter are all named", ["formatter", "linter", "assist", "javascript.formatter", "json.formatter"].every((k) => ownDetail.includes(k)), ownDetail) && ok;
|
|
96
|
-
const wide = make({ biome: WIDE_OVERRIDE });
|
|
97
|
-
const wideDetail = presetDrift(wide.dir).find((f) => f.key === "overrides")?.detail ?? "";
|
|
98
|
-
ok =
|
|
99
|
-
expectStep("(b) an override touching anything but suspicious.noConsole is drift", wideDetail.includes("overrides[0]") && wideDetail.includes("overrides[1].formatter"), wideDetail) && ok;
|
|
100
|
-
// The test-scoped noEmptyBlockStatements carve-out (owner's call,
|
|
101
|
-
// 2026-09-07). Three directions, because a carve-out that is not scoped is
|
|
102
|
-
// the rule switched off through a loophole.
|
|
103
|
-
const TEST_OVERRIDE = {
|
|
104
|
-
$schema: "https://biomejs.dev/schemas/2.5.10/schema.json",
|
|
105
|
-
extends: ["@agentvibes/guardrails/biome"],
|
|
106
|
-
overrides: [
|
|
107
|
-
{
|
|
108
|
-
includes: ["**/__tests__/**", "**/*.test.ts", "**/*.test.tsx"],
|
|
109
|
-
linter: { rules: { suspicious: { noEmptyBlockStatements: "off" } } },
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
};
|
|
113
|
-
const scoped = make({ biome: JSON.stringify(TEST_OVERRIDE) });
|
|
114
|
-
ok =
|
|
115
|
-
expectStep("(b) noEmptyBlockStatements off for test paths only is NOT drift", presetDrift(scoped.dir).every((f) => f.key !== "overrides"), JSON.stringify(presetDrift(scoped.dir))) && ok;
|
|
116
|
-
const unscoped = make({
|
|
117
|
-
biome: JSON.stringify({
|
|
118
|
-
...TEST_OVERRIDE,
|
|
119
|
-
overrides: [
|
|
120
|
-
{
|
|
121
|
-
includes: ["src/**"],
|
|
122
|
-
linter: { rules: { suspicious: { noEmptyBlockStatements: "off" } } },
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
}),
|
|
126
|
-
});
|
|
127
|
-
const unscopedDetail = presetDrift(unscoped.dir).find((f) => f.key === "overrides")?.detail ?? "";
|
|
128
|
-
ok =
|
|
129
|
-
expectStep("(b) the same override on src/** IS drift — the carve-out is for tests", unscopedDetail.includes("noEmptyBlockStatements"), unscopedDetail) && ok;
|
|
130
|
-
const mixed = make({
|
|
131
|
-
biome: JSON.stringify({
|
|
132
|
-
...TEST_OVERRIDE,
|
|
133
|
-
overrides: [
|
|
134
|
-
{
|
|
135
|
-
includes: ["**/__tests__/**", "src/**"],
|
|
136
|
-
linter: { rules: { suspicious: { noEmptyBlockStatements: "off" } } },
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
}),
|
|
140
|
-
});
|
|
141
|
-
const mixedDetail = presetDrift(mixed.dir).find((f) => f.key === "overrides")?.detail ?? "";
|
|
142
|
-
ok =
|
|
143
|
-
expectStep("(b) one non-test glob among the test globs IS drift", mixedDetail.includes("noEmptyBlockStatements"), mixedDetail) && ok;
|
|
144
|
-
const second = make({ biome: CONFORMING, secondConfig: CONFORMING });
|
|
145
|
-
ok =
|
|
146
|
-
expectStep("(c) a second biome.json in the tree is drift even when both conform", presetDrift(second.dir).some((f) => f.key === "extra-config"), JSON.stringify(presetDrift(second.dir), null, 2)) && ok;
|
|
147
|
-
// ── the opt-in switch, through the CLI ───────────────────────────────
|
|
148
|
-
const unenforced = make({ biome: NO_EXTENDS });
|
|
149
|
-
const u = run(unenforced.dir, "verify");
|
|
150
|
-
ok =
|
|
151
|
-
expectStep("unenforced: verify SAYS the drift and still exits 0", u.status === 0 && u.out.includes("biome preset drift") && u.out.includes("Not gated here"), `exit ${u.status}\n${u.out}`) && ok;
|
|
152
|
-
const enforced = make({ biome: NO_EXTENDS, enforced: true });
|
|
153
|
-
const e = run(enforced.dir, "verify");
|
|
88
|
+
const kinds = new Set(fixtures.filter((f) => f.expectKey).map((f) => f.expectKey));
|
|
154
89
|
ok =
|
|
155
|
-
expectStep("
|
|
156
|
-
|
|
157
|
-
|
|
90
|
+
expectStep("fixtures cover all five drift keys", ["extends", "own-keys", "overrides", "extra-config", "no-root-config"].every((k) => kinds.has(k)), [...kinds].join(", ")) && ok;
|
|
91
|
+
for (const f of fixtures)
|
|
92
|
+
ok = checkFixture(f) && ok;
|
|
93
|
+
// The message has to name WHAT drifted, not only that something did.
|
|
94
|
+
const byName = (n) => fixtures.find((f) => f.name === n);
|
|
95
|
+
const own = byName("invalid/own-keys--restates-preset");
|
|
96
|
+
const ownDetail = own
|
|
97
|
+
? (presetDrift(own.dir).find((x) => x.key === "own-keys")?.detail ?? "")
|
|
98
|
+
: "";
|
|
158
99
|
ok =
|
|
159
|
-
expectStep("
|
|
160
|
-
const
|
|
100
|
+
expectStep("own-keys names formatter, linter, assist, javascript.formatter and json.formatter", ["formatter", "linter", "assist", "javascript.formatter", "json.formatter"].every((k) => ownDetail.includes(k)), ownDetail) && ok;
|
|
101
|
+
const wide = byName("invalid/overrides--other-rule");
|
|
102
|
+
const wideDetail = wide
|
|
103
|
+
? (presetDrift(wide.dir).find((x) => x.key === "overrides")?.detail ?? "")
|
|
104
|
+
: "";
|
|
161
105
|
ok =
|
|
162
|
-
expectStep("
|
|
163
|
-
const
|
|
106
|
+
expectStep("overrides names each offending entry by index", wideDetail.includes("overrides[0]") && wideDetail.includes("overrides[1].formatter"), wideDetail) && ok;
|
|
107
|
+
const noBiome = mkdtempSync(join(tmpdir(), "guardrails-preset-"));
|
|
108
|
+
writeFileSync(join(noBiome, "a.ts"), CLEAN_TS);
|
|
164
109
|
ok =
|
|
165
|
-
expectStep("
|
|
110
|
+
expectStep("a repo with no biome config at all reports no drift", presetDrift(noBiome).length === 0, JSON.stringify(presetDrift(noBiome))) && ok;
|
|
111
|
+
rmSync(noBiome, { recursive: true, force: true });
|
|
166
112
|
console.log("");
|
|
167
113
|
if (!ok) {
|
|
168
114
|
console.error("preset-drift assertions FAILED");
|
|
169
115
|
return 1;
|
|
170
116
|
}
|
|
171
|
-
console.log(
|
|
117
|
+
console.log(`preset-drift fixtures passed (${fixtures.length} fixtures)`);
|
|
172
118
|
return 0;
|
|
173
119
|
}
|
|
174
120
|
finally {
|
|
175
|
-
for (const
|
|
176
|
-
rmSync(
|
|
121
|
+
for (const f of fixtures)
|
|
122
|
+
rmSync(f.dir, { recursive: true, force: true });
|
|
177
123
|
}
|
|
178
124
|
}
|
|
179
125
|
process.exit(main());
|