@webpieces/rules-config 0.4.843 → 0.4.844

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.
Files changed (54) hide show
  1. package/package.json +9 -4
  2. package/src/abstract-rule.d.ts +1 -1
  3. package/src/abstract-rule.js.map +1 -1
  4. package/src/api-doc-rules-config.d.ts +1 -2
  5. package/src/api-doc-rules-config.js +9 -10
  6. package/src/api-doc-rules-config.js.map +1 -1
  7. package/src/api-lib-spelling-configs.d.ts +2 -2
  8. package/src/api-lib-spelling-configs.js +9 -9
  9. package/src/api-lib-spelling-configs.js.map +1 -1
  10. package/src/index.d.ts +2 -4
  11. package/src/index.js +10 -11
  12. package/src/index.js.map +1 -1
  13. package/src/main-sync-guard-configs.d.ts +2 -2
  14. package/src/main-sync-guard-configs.js +7 -7
  15. package/src/main-sync-guard-configs.js.map +1 -1
  16. package/src/match-rules-config.d.ts +2 -1
  17. package/src/match-rules-config.js +2 -2
  18. package/src/match-rules-config.js.map +1 -1
  19. package/src/no-client-creation-config.d.ts +2 -2
  20. package/src/no-client-creation-config.js +8 -8
  21. package/src/no-client-creation-config.js.map +1 -1
  22. package/src/no-root-union-config.d.ts +2 -2
  23. package/src/no-root-union-config.js +5 -5
  24. package/src/no-root-union-config.js.map +1 -1
  25. package/src/no-state-paths-config.d.ts +2 -2
  26. package/src/no-state-paths-config.js +7 -7
  27. package/src/no-state-paths-config.js.map +1 -1
  28. package/src/no-utility-types-config.d.ts +2 -2
  29. package/src/no-utility-types-config.js +6 -6
  30. package/src/no-utility-types-config.js.map +1 -1
  31. package/src/required-type-suffix-config.d.ts +2 -2
  32. package/src/required-type-suffix-config.js +8 -8
  33. package/src/required-type-suffix-config.js.map +1 -1
  34. package/src/rule-configs.d.ts +2 -10
  35. package/src/rule-configs.js +156 -171
  36. package/src/rule-configs.js.map +1 -1
  37. package/src/rule-pack-registry.d.ts +31 -0
  38. package/src/rule-pack-registry.js +175 -0
  39. package/src/rule-pack-registry.js.map +1 -0
  40. package/src/rule-schemas.d.ts +1 -1
  41. package/src/rule-schemas.js +3 -0
  42. package/src/rule-schemas.js.map +1 -1
  43. package/src/seed-entry.js +4 -0
  44. package/src/seed-entry.js.map +1 -1
  45. package/src/tag-truth-configs.d.ts +2 -2
  46. package/src/tag-truth-configs.js +30 -30
  47. package/src/tag-truth-configs.js.map +1 -1
  48. package/src/validate-config.js.map +1 -1
  49. package/src/field-def.d.ts +0 -24
  50. package/src/field-def.js +0 -59
  51. package/src/field-def.js.map +0 -1
  52. package/src/spec-temp-dirs.d.ts +0 -37
  53. package/src/spec-temp-dirs.js +0 -113
  54. package/src/spec-temp-dirs.js.map +0 -1
@@ -1,24 +0,0 @@
1
- type FieldType = 'string' | 'number' | 'boolean' | 'string[]' | 'object[]';
2
- export declare class FieldDef {
3
- readonly type: FieldType;
4
- readonly enumValues?: readonly string[] | undefined;
5
- readonly optional: boolean;
6
- readonly nullable: boolean;
7
- readonly nonEmpty: boolean;
8
- readonly elementSchema?: Readonly<Record<string, FieldDef>> | undefined;
9
- constructor(type: FieldType, enumValues?: readonly string[] | undefined, optional?: boolean, nullable?: boolean, nonEmpty?: boolean, elementSchema?: Readonly<Record<string, FieldDef>> | undefined);
10
- /** Marks a field as optional (omittable) in the config schema. */
11
- static optional(type: FieldType, enumValues?: readonly string[]): FieldDef;
12
- /** A REQUIRED string field that also accepts `null` (present-but-unset). */
13
- static nullableString(): FieldDef;
14
- /** A REQUIRED `string[]` that must hold at least one string. */
15
- static nonEmptyStrings(): FieldDef;
16
- /** A REQUIRED list of objects (possibly empty), each validated against `elementSchema`. */
17
- static objects(elementSchema: Readonly<Record<string, FieldDef>>): FieldDef;
18
- /** A REQUIRED, non-empty list of objects, each validated against `elementSchema`. */
19
- static nonEmptyObjects(elementSchema: Readonly<Record<string, FieldDef>>): FieldDef;
20
- }
21
- export type SchemaShape<T> = {
22
- [K in keyof Required<T>]: FieldDef;
23
- };
24
- export {};
package/src/field-def.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FieldDef = void 0;
4
- class FieldDef {
5
- type;
6
- enumValues;
7
- optional;
8
- nullable;
9
- nonEmpty;
10
- elementSchema;
11
- constructor(type, enumValues,
12
- // When true, the field is omittable: the missing-rule snippet lists it
13
- // as optional rather than as a required copy-paste field.
14
- optional = false,
15
- // When true, JSON `null` is an accepted value in addition to `type`. Used for a REQUIRED
16
- // field whose "unset" state must still be visible in the config (e.g. turnOffRuleWhileOnBranch:
17
- // null means "no branch / always on") — required so it is always present, nullable so it can be
18
- // present-but-unset without inventing a sentinel string.
19
- nullable = false,
20
- // When true, an array field (`string[]` / `object[]`) must hold at least one element — for a list
21
- // whose emptiness would mean "judge nothing" while reading as "configured".
22
- nonEmpty = false,
23
- // For `object[]` only: the schema EVERY element is validated against (unknown keys, missing
24
- // required keys, types, non-emptiness), exactly like a rule entry's own fields.
25
- elementSchema) {
26
- this.type = type;
27
- this.enumValues = enumValues;
28
- this.optional = optional;
29
- this.nullable = nullable;
30
- this.nonEmpty = nonEmpty;
31
- this.elementSchema = elementSchema;
32
- }
33
- /** Marks a field as optional (omittable) in the config schema. */
34
- static optional(type, enumValues) {
35
- return new FieldDef(type, enumValues, true);
36
- }
37
- /** A REQUIRED string field that also accepts `null` (present-but-unset). */
38
- // webpieces-disable no-function-outside-class -- static factory, matches sibling FieldDef.optional
39
- static nullableString() {
40
- return new FieldDef('string', undefined, false, true);
41
- }
42
- /** A REQUIRED `string[]` that must hold at least one string. */
43
- // webpieces-disable no-function-outside-class -- static factory, matches sibling FieldDef.optional
44
- static nonEmptyStrings() {
45
- return new FieldDef('string[]', undefined, false, false, true);
46
- }
47
- /** A REQUIRED list of objects (possibly empty), each validated against `elementSchema`. */
48
- // webpieces-disable no-function-outside-class -- static factory, matches sibling FieldDef.optional
49
- static objects(elementSchema) {
50
- return new FieldDef('object[]', undefined, false, false, false, elementSchema);
51
- }
52
- /** A REQUIRED, non-empty list of objects, each validated against `elementSchema`. */
53
- // webpieces-disable no-function-outside-class -- static factory, matches sibling FieldDef.optional
54
- static nonEmptyObjects(elementSchema) {
55
- return new FieldDef('object[]', undefined, false, false, true, elementSchema);
56
- }
57
- }
58
- exports.FieldDef = FieldDef;
59
- //# sourceMappingURL=field-def.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-def.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/field-def.ts"],"names":[],"mappings":";;;AAIA,MAAa,QAAQ;IAEJ;IACA;IAGA;IAKA;IAGA;IAGA;IAhBb,YACa,IAAe,EACf,UAA8B;IACvC,uEAAuE;IACvE,0DAA0D;IACjD,WAAoB,KAAK;IAClC,yFAAyF;IACzF,gGAAgG;IAChG,gGAAgG;IAChG,yDAAyD;IAChD,WAAoB,KAAK;IAClC,kGAAkG;IAClG,4EAA4E;IACnE,WAAoB,KAAK;IAClC,4FAA4F;IAC5F,gFAAgF;IACvE,aAAkD;QAflD,SAAI,GAAJ,IAAI,CAAW;QACf,eAAU,GAAV,UAAU,CAAoB;QAG9B,aAAQ,GAAR,QAAQ,CAAiB;QAKzB,aAAQ,GAAR,QAAQ,CAAiB;QAGzB,aAAQ,GAAR,QAAQ,CAAiB;QAGzB,kBAAa,GAAb,aAAa,CAAqC;IAC5D,CAAC;IAEJ,kEAAkE;IAClE,MAAM,CAAC,QAAQ,CAAC,IAAe,EAAE,UAA8B;QAC3D,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,4EAA4E;IAC5E,mGAAmG;IACnG,MAAM,CAAC,cAAc;QACjB,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1D,CAAC;IAED,gEAAgE;IAChE,mGAAmG;IACnG,MAAM,CAAC,eAAe;QAClB,OAAO,IAAI,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACnE,CAAC;IAED,2FAA2F;IAC3F,mGAAmG;IACnG,MAAM,CAAC,OAAO,CAAC,aAAiD;QAC5D,OAAO,IAAI,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;IACnF,CAAC;IAED,qFAAqF;IACrF,mGAAmG;IACnG,MAAM,CAAC,eAAe,CAAC,aAAiD;QACpE,OAAO,IAAI,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;IAClF,CAAC;CACJ;AAhDD,4BAgDC","sourcesContent":["// `object[]` is a list of JSON objects, each validated against the field's `elementSchema` (e.g.\n// required-type-suffix's `entries`: `[{ \"paths\": [...], \"suffixes\": [...] }]`).\ntype FieldType = 'string' | 'number' | 'boolean' | 'string[]' | 'object[]';\n\nexport class FieldDef {\n constructor(\n readonly type: FieldType,\n readonly enumValues?: readonly string[],\n // When true, the field is omittable: the missing-rule snippet lists it\n // as optional rather than as a required copy-paste field.\n readonly optional: boolean = false,\n // When true, JSON `null` is an accepted value in addition to `type`. Used for a REQUIRED\n // field whose \"unset\" state must still be visible in the config (e.g. turnOffRuleWhileOnBranch:\n // null means \"no branch / always on\") — required so it is always present, nullable so it can be\n // present-but-unset without inventing a sentinel string.\n readonly nullable: boolean = false,\n // When true, an array field (`string[]` / `object[]`) must hold at least one element — for a list\n // whose emptiness would mean \"judge nothing\" while reading as \"configured\".\n readonly nonEmpty: boolean = false,\n // For `object[]` only: the schema EVERY element is validated against (unknown keys, missing\n // required keys, types, non-emptiness), exactly like a rule entry's own fields.\n readonly elementSchema?: Readonly<Record<string, FieldDef>>,\n ) {}\n\n /** Marks a field as optional (omittable) in the config schema. */\n static optional(type: FieldType, enumValues?: readonly string[]): FieldDef {\n return new FieldDef(type, enumValues, true);\n }\n\n /** A REQUIRED string field that also accepts `null` (present-but-unset). */\n // webpieces-disable no-function-outside-class -- static factory, matches sibling FieldDef.optional\n static nullableString(): FieldDef {\n return new FieldDef('string', undefined, false, true);\n }\n\n /** A REQUIRED `string[]` that must hold at least one string. */\n // webpieces-disable no-function-outside-class -- static factory, matches sibling FieldDef.optional\n static nonEmptyStrings(): FieldDef {\n return new FieldDef('string[]', undefined, false, false, true);\n }\n\n /** A REQUIRED list of objects (possibly empty), each validated against `elementSchema`. */\n // webpieces-disable no-function-outside-class -- static factory, matches sibling FieldDef.optional\n static objects(elementSchema: Readonly<Record<string, FieldDef>>): FieldDef {\n return new FieldDef('object[]', undefined, false, false, false, elementSchema);\n }\n\n /** A REQUIRED, non-empty list of objects, each validated against `elementSchema`. */\n // webpieces-disable no-function-outside-class -- static factory, matches sibling FieldDef.optional\n static nonEmptyObjects(elementSchema: Readonly<Record<string, FieldDef>>): FieldDef {\n return new FieldDef('object[]', undefined, false, false, true, elementSchema);\n }\n}\n\n// Enforces that a static SCHEMA has exactly the same keys as the config class.\n// Add a field to the class → TS errors until SCHEMA is updated.\n// Add to SCHEMA without adding to class → TS errors (extra property).\nexport type SchemaShape<T> = { [K in keyof Required<T>]: FieldDef };\n"]}
@@ -1,37 +0,0 @@
1
- /**
2
- * Creates `$TMPDIR` scratch directories for specs and testkits, and reaps every one of them when the
3
- * process exits.
4
- *
5
- * Use the shared `specTempDirs` instance — the reaper is registered per-instance, so a caller that
6
- * constructs its own gets a second `exit` listener and no benefit.
7
- */
8
- export declare class SpecTempDirs {
9
- private readonly created;
10
- private reaperRegistered;
11
- /**
12
- * `fs.mkdtempSync` under `os.tmpdir()`, with the path remembered for cleanup.
13
- *
14
- * `prefix` keeps the existing `wp-<area>-` convention so a leaked tree still names its creator; the
15
- * trailing dash matters because mkdtemp appends six random characters directly onto it.
16
- */
17
- make(prefix: string): string;
18
- /**
19
- * `make`, with symlinks resolved.
20
- *
21
- * macOS hands back `/var/folders/...` from `os.tmpdir()` while `/var` is a symlink to `/private/var`,
22
- * so a fixture that compares a path it was given against one the code under test computed sees two
23
- * different strings for the same directory. Specs that do that comparison call this instead.
24
- */
25
- makeReal(prefix: string): string;
26
- /**
27
- * Removes every directory this instance created, then forgets them.
28
- *
29
- * Deliberately never throws: it runs from an `exit` handler where a throw would replace a passing
30
- * test run's exit code with a crash, and a scratch directory that cannot be removed is a leak, not a
31
- * failure. Callers may also invoke it directly — a long suite that wants its fixtures gone before the
32
- * end of the run.
33
- */
34
- reapAll(): void;
35
- private registerReaper;
36
- }
37
- export declare const specTempDirs: SpecTempDirs;
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.specTempDirs = exports.SpecTempDirs = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("fs"));
6
- const os = tslib_1.__importStar(require("os"));
7
- const path = tslib_1.__importStar(require("path"));
8
- // The Vitest setup loads this leaf before per-spec fs mocks; keep filesystem services lazy.
9
- const to_error_1 = require("@webpieces/tooling-common/to-error");
10
- // ---------------------------------------------------------------------------
11
- // ONE OWNER FOR EVERY `$TMPDIR` SCRATCH TREE THE TOOLING CREATES.
12
- //
13
- // THE DEFECT. Every `packages/tooling/**` spec builds its fixture with
14
- // `specTempDirs.make('wp-<something>-')` and NONE of them removed it afterwards.
15
- // Measured on one developer machine: 270,200 abandoned `wp-*` directories out of 286,270 total entries
16
- // in `$TMPDIR` — 64,828 of them from `vitest.setup.mts` alone, which mints one isolated `$HOME` per test
17
- // FILE per run. The cost is not disk (every `wp-*` prefix together is under 1 GiB; the `$HOME` dirs are
18
- // empty by design) — it is INODES and the fact that `$TMPDIR` stops being inspectable: `ls` takes ~30s
19
- // and `du` takes minutes, which is how this went unnoticed for as long as it did.
20
- //
21
- // WHY `$TMPDIR` AND NOT `.webpieces/`, WHICH IS WHERE EVERYTHING ELSE GOES. Because for a TEST fixture
22
- // the whole point is to be outside the repo, and two separate mechanisms depend on that:
23
- // - `vitest.setup.mts` mints a throwaway `$HOME` so a spec cannot read the developer's real
24
- // `~/.webpieces/config.json`. A fake HOME inside the repo defeats its own isolation.
25
- // - The fixtures `git init` and `git worktree add` INSIDE themselves. A nested git repo under the real
26
- // repo root is what breaks the nx graph — the same hazard that makes `.claude/worktrees/` a
27
- // mandatory gitignore entry.
28
- // So the location was never the bug. The missing cleanup was.
29
- //
30
- // WHO ACTUALLY CALLS `reapAll`, AND WHY IT IS NOT A LINE IN EACH SPEC. An `afterAll` written into each
31
- // of the 212 call sites is a line somebody has to remember, forever, in every new spec — precisely the
32
- // discipline already demonstrated not to hold here. Instead `vitest.setup.mts` calls `reapAll()` in ONE
33
- // global `afterAll`, so a call site swaps `fs.mkdtempSync(...)` for `specTempDirs.make(...)` and there
34
- // is no other half to forget.
35
- //
36
- // THE `exit` REAPER BELOW IS THE SECONDARY BELT, NOT THE PRIMARY ONE — and the first cut of this file
37
- // had that backwards. It relied on `process.on('exit')` alone, and a 145-file tooling run then left
38
- // exactly 145 `wp-vitest-home-` directories behind: a 100% miss. The cause is `pool: 'forks'` (see
39
- // vitest.config.mts) — vitest KILLS its workers rather than letting them exit, and a killed process runs
40
- // no exit handler. The handler stays because it costs one listener and does fire for the non-vitest
41
- // callers (testkits driven from plain node scripts), but nothing here should depend on it.
42
- //
43
- // SO CLEANUP IS BEST-EFFORT BY CONSTRUCTION, at two levels: a worker killed mid-file skips the
44
- // `afterAll` too. That residue is why `CleanTmp` sweeps aged `wp-*` out of `$TMPDIR` via
45
- // `TmpScratchSweeper` — belt, braces, and a sweep for what both of them miss.
46
- // ---------------------------------------------------------------------------
47
- /**
48
- * Creates `$TMPDIR` scratch directories for specs and testkits, and reaps every one of them when the
49
- * process exits.
50
- *
51
- * Use the shared `specTempDirs` instance — the reaper is registered per-instance, so a caller that
52
- * constructs its own gets a second `exit` listener and no benefit.
53
- */
54
- class SpecTempDirs {
55
- created = [];
56
- reaperRegistered = false;
57
- /**
58
- * `fs.mkdtempSync` under `os.tmpdir()`, with the path remembered for cleanup.
59
- *
60
- * `prefix` keeps the existing `wp-<area>-` convention so a leaked tree still names its creator; the
61
- * trailing dash matters because mkdtemp appends six random characters directly onto it.
62
- */
63
- make(prefix) {
64
- this.registerReaper();
65
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
66
- this.created.push(dir);
67
- return dir;
68
- }
69
- /**
70
- * `make`, with symlinks resolved.
71
- *
72
- * macOS hands back `/var/folders/...` from `os.tmpdir()` while `/var` is a symlink to `/private/var`,
73
- * so a fixture that compares a path it was given against one the code under test computed sees two
74
- * different strings for the same directory. Specs that do that comparison call this instead.
75
- */
76
- makeReal(prefix) {
77
- return fs.realpathSync(this.make(prefix));
78
- }
79
- /**
80
- * Removes every directory this instance created, then forgets them.
81
- *
82
- * Deliberately never throws: it runs from an `exit` handler where a throw would replace a passing
83
- * test run's exit code with a crash, and a scratch directory that cannot be removed is a leak, not a
84
- * failure. Callers may also invoke it directly — a long suite that wants its fixtures gone before the
85
- * end of the run.
86
- */
87
- reapAll() {
88
- const dirs = this.created.splice(0, this.created.length);
89
- for (const dir of dirs) {
90
- // webpieces-disable no-unmanaged-exceptions -- chokepoint: this runs from vitest's afterAll and
91
- // from an exit handler, where a throw would turn a passing run into a crash over a scratch dir
92
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
93
- try {
94
- fs.rmSync(dir, { recursive: true, force: true });
95
- }
96
- catch (err) {
97
- const error = (0, to_error_1.toError)(err);
98
- process.stderr.write(`SpecTempDirs: could not remove ${dir}: ${error.message}\n`);
99
- }
100
- }
101
- }
102
- // One listener per instance, added lazily so a process that never makes a fixture never registers.
103
- registerReaper() {
104
- if (this.reaperRegistered)
105
- return;
106
- this.reaperRegistered = true;
107
- process.on('exit', () => this.reapAll());
108
- }
109
- }
110
- exports.SpecTempDirs = SpecTempDirs;
111
- // The shared instance — the reaper and the created-list are per-instance, so every caller must use this.
112
- exports.specTempDirs = new SpecTempDirs();
113
- //# sourceMappingURL=spec-temp-dirs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spec-temp-dirs.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/spec-temp-dirs.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,+CAAyB;AACzB,mDAA6B;AAC7B,4FAA4F;AAC5F,iEAA6D;AAE7D,8EAA8E;AAC9E,kEAAkE;AAClE,EAAE;AACF,uEAAuE;AACvE,iFAAiF;AACjF,uGAAuG;AACvG,yGAAyG;AACzG,wGAAwG;AACxG,uGAAuG;AACvG,kFAAkF;AAClF,EAAE;AACF,uGAAuG;AACvG,yFAAyF;AACzF,8FAA8F;AAC9F,yFAAyF;AACzF,yGAAyG;AACzG,gGAAgG;AAChG,iCAAiC;AACjC,8DAA8D;AAC9D,EAAE;AACF,uGAAuG;AACvG,uGAAuG;AACvG,wGAAwG;AACxG,uGAAuG;AACvG,8BAA8B;AAC9B,EAAE;AACF,sGAAsG;AACtG,oGAAoG;AACpG,mGAAmG;AACnG,yGAAyG;AACzG,oGAAoG;AACpG,2FAA2F;AAC3F,EAAE;AACF,+FAA+F;AAC/F,yFAAyF;AACzF,8EAA8E;AAC9E,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAa,YAAY;IACJ,OAAO,GAAa,EAAE,CAAC;IAChC,gBAAgB,GAAG,KAAK,CAAC;IAEjC;;;;;OAKG;IACH,IAAI,CAAC,MAAc;QACf,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;QAC3D,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,OAAO,GAAG,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,MAAc;QACnB,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;;OAOG;IACH,OAAO;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACzD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,gGAAgG;YAChG,+FAA+F;YAC/F,8DAA8D;YAC9D,IAAI,CAAC;gBACD,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACrD,CAAC;YAAC,OAAO,GAAY,EAAE,CAAC;gBACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;gBAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,GAAG,KAAK,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;YACtF,CAAC;QACL,CAAC;IACL,CAAC;IAED,mGAAmG;IAC3F,cAAc;QAClB,IAAI,IAAI,CAAC,gBAAgB;YAAE,OAAO;QAClC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAS,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACnD,CAAC;CACJ;AAzDD,oCAyDC;AAED,yGAAyG;AAC5F,QAAA,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\n// The Vitest setup loads this leaf before per-spec fs mocks; keep filesystem services lazy.\nimport { toError } from '@webpieces/tooling-common/to-error';\n\n// ---------------------------------------------------------------------------\n// ONE OWNER FOR EVERY `$TMPDIR` SCRATCH TREE THE TOOLING CREATES.\n//\n// THE DEFECT. Every `packages/tooling/**` spec builds its fixture with\n// `specTempDirs.make('wp-<something>-')` and NONE of them removed it afterwards.\n// Measured on one developer machine: 270,200 abandoned `wp-*` directories out of 286,270 total entries\n// in `$TMPDIR` — 64,828 of them from `vitest.setup.mts` alone, which mints one isolated `$HOME` per test\n// FILE per run. The cost is not disk (every `wp-*` prefix together is under 1 GiB; the `$HOME` dirs are\n// empty by design) — it is INODES and the fact that `$TMPDIR` stops being inspectable: `ls` takes ~30s\n// and `du` takes minutes, which is how this went unnoticed for as long as it did.\n//\n// WHY `$TMPDIR` AND NOT `.webpieces/`, WHICH IS WHERE EVERYTHING ELSE GOES. Because for a TEST fixture\n// the whole point is to be outside the repo, and two separate mechanisms depend on that:\n// - `vitest.setup.mts` mints a throwaway `$HOME` so a spec cannot read the developer's real\n// `~/.webpieces/config.json`. A fake HOME inside the repo defeats its own isolation.\n// - The fixtures `git init` and `git worktree add` INSIDE themselves. A nested git repo under the real\n// repo root is what breaks the nx graph — the same hazard that makes `.claude/worktrees/` a\n// mandatory gitignore entry.\n// So the location was never the bug. The missing cleanup was.\n//\n// WHO ACTUALLY CALLS `reapAll`, AND WHY IT IS NOT A LINE IN EACH SPEC. An `afterAll` written into each\n// of the 212 call sites is a line somebody has to remember, forever, in every new spec — precisely the\n// discipline already demonstrated not to hold here. Instead `vitest.setup.mts` calls `reapAll()` in ONE\n// global `afterAll`, so a call site swaps `fs.mkdtempSync(...)` for `specTempDirs.make(...)` and there\n// is no other half to forget.\n//\n// THE `exit` REAPER BELOW IS THE SECONDARY BELT, NOT THE PRIMARY ONE — and the first cut of this file\n// had that backwards. It relied on `process.on('exit')` alone, and a 145-file tooling run then left\n// exactly 145 `wp-vitest-home-` directories behind: a 100% miss. The cause is `pool: 'forks'` (see\n// vitest.config.mts) — vitest KILLS its workers rather than letting them exit, and a killed process runs\n// no exit handler. The handler stays because it costs one listener and does fire for the non-vitest\n// callers (testkits driven from plain node scripts), but nothing here should depend on it.\n//\n// SO CLEANUP IS BEST-EFFORT BY CONSTRUCTION, at two levels: a worker killed mid-file skips the\n// `afterAll` too. That residue is why `CleanTmp` sweeps aged `wp-*` out of `$TMPDIR` via\n// `TmpScratchSweeper` — belt, braces, and a sweep for what both of them miss.\n// ---------------------------------------------------------------------------\n\n/**\n * Creates `$TMPDIR` scratch directories for specs and testkits, and reaps every one of them when the\n * process exits.\n *\n * Use the shared `specTempDirs` instance — the reaper is registered per-instance, so a caller that\n * constructs its own gets a second `exit` listener and no benefit.\n */\nexport class SpecTempDirs {\n private readonly created: string[] = [];\n private reaperRegistered = false;\n\n /**\n * `fs.mkdtempSync` under `os.tmpdir()`, with the path remembered for cleanup.\n *\n * `prefix` keeps the existing `wp-<area>-` convention so a leaked tree still names its creator; the\n * trailing dash matters because mkdtemp appends six random characters directly onto it.\n */\n make(prefix: string): string {\n this.registerReaper();\n const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));\n this.created.push(dir);\n return dir;\n }\n\n /**\n * `make`, with symlinks resolved.\n *\n * macOS hands back `/var/folders/...` from `os.tmpdir()` while `/var` is a symlink to `/private/var`,\n * so a fixture that compares a path it was given against one the code under test computed sees two\n * different strings for the same directory. Specs that do that comparison call this instead.\n */\n makeReal(prefix: string): string {\n return fs.realpathSync(this.make(prefix));\n }\n\n /**\n * Removes every directory this instance created, then forgets them.\n *\n * Deliberately never throws: it runs from an `exit` handler where a throw would replace a passing\n * test run's exit code with a crash, and a scratch directory that cannot be removed is a leak, not a\n * failure. Callers may also invoke it directly — a long suite that wants its fixtures gone before the\n * end of the run.\n */\n reapAll(): void {\n const dirs = this.created.splice(0, this.created.length);\n for (const dir of dirs) {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: this runs from vitest's afterAll and\n // from an exit handler, where a throw would turn a passing run into a crash over a scratch dir\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n fs.rmSync(dir, { recursive: true, force: true });\n } catch (err: unknown) {\n const error = toError(err);\n process.stderr.write(`SpecTempDirs: could not remove ${dir}: ${error.message}\\n`);\n }\n }\n }\n\n // One listener per instance, added lazily so a process that never makes a fixture never registers.\n private registerReaper(): void {\n if (this.reaperRegistered) return;\n this.reaperRegistered = true;\n process.on('exit', (): void => this.reapAll());\n }\n}\n\n// The shared instance — the reaper and the created-list are per-instance, so every caller must use this.\nexport const specTempDirs = new SpecTempDirs();\n"]}