@punks/cli 5.2.0 → 5.2.2

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 (91) hide show
  1. package/README.md +2 -2
  2. package/dist/BASELINE_CHANGELOG.md +46 -1
  3. package/dist/CHANGELOG.md +37 -0
  4. package/dist/baseline/scaffold-baseline/baseline.json +15 -5
  5. package/dist/baseline/scaffold-baseline/data/catalog/packs.json +2 -0
  6. package/dist/baseline/scaffold-baseline/data/catalog/skills.json +16 -0
  7. package/dist/baseline/scaffold-baseline/data/hooks/format-edited-file.mjs +459 -318
  8. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.d.ts +1 -0
  9. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.mjs +98 -27
  10. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +156 -8
  11. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.d.mts +55 -0
  12. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.mjs +329 -0
  13. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.test.ts +864 -0
  14. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.d.mts +97 -0
  15. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.mjs +658 -0
  16. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.test.ts +614 -0
  17. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
  18. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/commands.md +8 -9
  19. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
  20. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +28 -24
  21. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/wiki-structure.md +16 -0
  22. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/SKILL.md +21 -16
  23. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +1 -1
  24. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +16 -4
  25. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/SKILL.md +65 -0
  26. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/assets/ARCHITECTURE-TEMPLATE.md +119 -0
  27. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/references/artifact-contract.md +200 -0
  28. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +11 -3
  29. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/architecture-convergence.md +19 -4
  30. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/plan-schema.md +17 -3
  31. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/SKILL.md +38 -20
  32. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +11 -0
  33. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/readiness.md +40 -0
  34. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +8 -0
  35. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/SKILL.md +4 -2
  36. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
  37. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/lifecycle.md +23 -10
  38. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/brainstorm/SKILL.md +22 -0
  39. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
  40. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +3 -2
  41. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +6 -3
  42. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/plan.md +4 -2
  43. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +5 -1
  44. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +15 -9
  45. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/spec.md +13 -26
  46. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/artifact-state.md +39 -1
  47. package/dist/baseline/scaffold-baseline/skills/phases/requirements-phase/SKILL.md +31 -14
  48. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/prepare-review.md +12 -4
  49. package/dist/baseline/scaffold-baseline.json +5 -5
  50. package/dist/baseline/scaffold-baseline.tgz +0 -0
  51. package/dist/data/hooks/format-edited-file.d.mts +5 -0
  52. package/dist/data/hooks/format-edited-file.mjs +282 -333
  53. package/dist/data/scripts/commit-gate-runner.mjs +98 -27
  54. package/dist/data/scripts/managed-lint-runner.d.mts +55 -0
  55. package/dist/data/scripts/managed-lint-runner.mjs +329 -0
  56. package/dist/data/scripts/managed-lint.d.mts +97 -0
  57. package/dist/data/scripts/managed-lint.mjs +658 -0
  58. package/dist/index.js +86 -1184
  59. package/dist/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
  60. package/dist/skills/agnostic/cli/hi-cli/references/commands.md +8 -9
  61. package/dist/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
  62. package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +15 -11
  63. package/dist/skills/agnostic/cli/hi-cli/references/wiki-structure.md +16 -0
  64. package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +21 -16
  65. package/dist/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +1 -1
  66. package/dist/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +16 -4
  67. package/dist/skills/agnostic/planning/create-architecture/SKILL.md +65 -0
  68. package/dist/skills/agnostic/planning/create-architecture/assets/ARCHITECTURE-TEMPLATE.md +119 -0
  69. package/dist/skills/agnostic/planning/create-architecture/references/artifact-contract.md +200 -0
  70. package/dist/skills/agnostic/planning/create-plan/SKILL.md +11 -3
  71. package/dist/skills/agnostic/planning/create-plan/references/architecture-convergence.md +19 -4
  72. package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +17 -3
  73. package/dist/skills/agnostic/planning/create-spec/SKILL.md +38 -20
  74. package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +11 -0
  75. package/dist/skills/agnostic/planning/create-spec/references/readiness.md +40 -0
  76. package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +8 -0
  77. package/dist/skills/agnostic/planning/implement-spec/SKILL.md +4 -2
  78. package/dist/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
  79. package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +23 -10
  80. package/dist/skills/agnostic/requirements/brainstorm/SKILL.md +22 -0
  81. package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
  82. package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +3 -2
  83. package/dist/skills/phases/delivery-phase/SKILL.md +6 -3
  84. package/dist/skills/phases/delivery-phase/phases/plan.md +4 -2
  85. package/dist/skills/phases/delivery-phase/phases/review.md +5 -1
  86. package/dist/skills/phases/delivery-phase/phases/router.md +15 -9
  87. package/dist/skills/phases/delivery-phase/phases/spec.md +13 -26
  88. package/dist/skills/phases/delivery-phase/references/artifact-state.md +39 -1
  89. package/dist/skills/phases/requirements-phase/SKILL.md +31 -14
  90. package/dist/skills/phases/review-phase/phases/prepare-review.md +12 -4
  91. package/package.json +3 -2
@@ -0,0 +1,864 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import {
3
+ mkdtempSync,
4
+ mkdirSync,
5
+ writeFileSync,
6
+ rmSync,
7
+ symlinkSync,
8
+ readFileSync,
9
+ existsSync,
10
+ } from "node:fs";
11
+ import os from "node:os";
12
+ import path from "node:path";
13
+ import { describe, it, expect } from "vitest";
14
+ import * as Schema from "effect/Schema";
15
+ import { runManagedLint } from "./managed-lint-runner.mjs";
16
+
17
+ const decoded = (source: string) => Schema.decodeUnknownSync(Schema.UnknownFromJsonString)(source);
18
+ const semantic = (source: string) => {
19
+ const value = decoded(source);
20
+ if (
21
+ typeof value !== "object" ||
22
+ value === null ||
23
+ !("results" in value) ||
24
+ !Array.isArray(value.results)
25
+ ) {
26
+ throw new Error("Expected owner results");
27
+ }
28
+ return value.results.map((owner: unknown) => {
29
+ if (
30
+ typeof owner !== "object" ||
31
+ owner === null ||
32
+ !("command" in owner) ||
33
+ !("diagnostics" in owner)
34
+ ) {
35
+ throw new Error("Expected owner result");
36
+ }
37
+ return { command: owner.command, diagnostics: owner.diagnostics };
38
+ });
39
+ };
40
+ const runner = path.join(import.meta.dirname, "managed-lint-runner.mjs");
41
+ const noFilesNotice = "No files found to lint. Please check your paths and ignore patterns.\n";
42
+ const emptyOutput = `${noFilesNotice}${JSON.stringify({ diagnostics: [], number_of_files: 0 })}`;
43
+ const withEmptyOwner = (run: (root: string, version: string) => void) => {
44
+ const root = mkdtempSync(path.join(os.tmpdir(), "managed-runner-empty-"));
45
+ try {
46
+ mkdirSync(path.join(root, ".devpunks/specs/lint"), { recursive: true });
47
+ symlinkSync(
48
+ path.resolve(import.meta.dirname, "../../../../../node_modules"),
49
+ path.join(root, "node_modules"),
50
+ "dir",
51
+ );
52
+ const tool = Schema.decodeUnknownSync(Schema.Struct({ version: Schema.String }))(
53
+ decoded(readFileSync(path.join(root, "node_modules/oxlint/package.json"), "utf-8")),
54
+ );
55
+ writeFileSync(path.join(root, "package.json"), '{"type":"module"}\n');
56
+ writeFileSync(
57
+ path.join(root, "oxlint.config.ts"),
58
+ 'export default {ignorePatterns: ["oxlint.config.ts"]};\n',
59
+ );
60
+ writeFileSync(
61
+ path.join(root, ".devpunks/settings.json"),
62
+ JSON.stringify({ lint: { scopes: ["."] } }),
63
+ );
64
+ writeFileSync(
65
+ path.join(root, ".devpunks/specs/lint/selection.json"),
66
+ JSON.stringify({
67
+ managedLint: {
68
+ exclude: [],
69
+ routes: [
70
+ {
71
+ config: "oxlint.config.ts",
72
+ inputs: [],
73
+ maxWarnings: 0,
74
+ scope: ".",
75
+ tool: { package: "oxlint", version: tool.version },
76
+ },
77
+ ],
78
+ scopes: ["."],
79
+ version: 1,
80
+ },
81
+ }),
82
+ );
83
+ run(root, tool.version);
84
+ } finally {
85
+ rmSync(root, { force: true, recursive: true });
86
+ }
87
+ };
88
+ describe("managed lint execution", () => {
89
+ it("runs Node-shebang tools under Bun without exposing unrelated PATH entries", () => {
90
+ withEmptyOwner((root, version) => {
91
+ const ambient = path.join(root, "ambient-bin");
92
+ mkdirSync(ambient);
93
+ symlinkSync(process.execPath, path.join(ambient, "node"));
94
+ writeFileSync(path.join(ambient, "unrelated-lint-tool"), "#!/bin/sh\nexit 0\n", {
95
+ mode: 0o755,
96
+ });
97
+ rmSync(path.join(root, "node_modules"));
98
+ mkdirSync(path.join(root, "node_modules/oxlint/bin"), { recursive: true });
99
+ writeFileSync(
100
+ path.join(root, "node_modules/oxlint/package.json"),
101
+ JSON.stringify({ bin: "bin/oxlint", name: "oxlint", type: "module", version }),
102
+ );
103
+ writeFileSync(
104
+ path.join(root, "node_modules/oxlint/bin/oxlint"),
105
+ `#!/usr/bin/env node
106
+ import { spawnSync } from "node:child_process";
107
+ if (process.versions.bun || spawnSync("unrelated-lint-tool").error?.code !== "ENOENT") {
108
+ process.exit(2);
109
+ }
110
+ process.stdout.write('{"diagnostics":[]}');
111
+ `,
112
+ { mode: 0o755 },
113
+ );
114
+ const result = spawnSync(
115
+ // oxlint-disable-next-line effecttsgo/process-env -- Test selects the installed Bun executable.
116
+ process.env.HI_TEST_BUN_PATH ?? "bun",
117
+ [runner, "--root", root, "--format", "json"],
118
+ {
119
+ encoding: "utf-8",
120
+ // oxlint-disable-next-line effecttsgo/process-env -- Test controls the child process environment.
121
+ env: { ...process.env, PATH: [ambient, process.env.PATH].join(path.delimiter) },
122
+ },
123
+ );
124
+ expect({ status: result.status, stderr: result.stderr }).toStrictEqual({
125
+ status: 0,
126
+ stderr: "",
127
+ });
128
+ expect(decoded(result.stdout)).toMatchObject({ code: 0, status: "clean" });
129
+ });
130
+ });
131
+
132
+ it.each(["missing", "conflict", "stale", "no-scopes"])(
133
+ "skips excluded-only work with %s selection",
134
+ (state) => {
135
+ withEmptyOwner((root) => {
136
+ const exclude = ["examples/**"];
137
+ writeFileSync(
138
+ path.join(root, ".devpunks/settings.json"),
139
+ JSON.stringify({
140
+ lint: state === "no-scopes" ? { exclude } : { exclude, scopes: ["."] },
141
+ }),
142
+ );
143
+ const artifact = path.join(root, ".devpunks/specs/lint/selection.json");
144
+ if (state === "missing" || state === "no-scopes") {
145
+ rmSync(artifact);
146
+ }
147
+ if (state === "conflict") {
148
+ writeFileSync(artifact, JSON.stringify({ lintEvidence: { status: "conflict" } }));
149
+ }
150
+ // The stale artifact retains its original exclude list and tool identity.
151
+ const invoke = (args: string[]) =>
152
+ spawnSync(process.execPath, [runner, "--root", root, "--format", "json", ...args], {
153
+ cwd: root,
154
+ encoding: "utf-8",
155
+ });
156
+ for (const file of ["apps/wiki/page.tsx", "examples/fixture/source.ts"]) {
157
+ const result = invoke(["--", file]);
158
+ expect({ output: decoded(result.stdout), status: result.status }).toMatchObject({
159
+ output: { code: 0, results: [], status: "clean" },
160
+ status: 0,
161
+ });
162
+ }
163
+ for (const args of [
164
+ [],
165
+ ["--", "source.ts"],
166
+ ["--", "apps/wiki/page.tsx", "source.ts"],
167
+ ["--scope", "not-selected", "--", "apps/wiki/page.tsx"],
168
+ ["--", ".devpunks/settings.json"],
169
+ ["--", ".devpunks/specs/lint/selection.json"],
170
+ ]) {
171
+ expect(invoke(args).status).toBe(2);
172
+ }
173
+ expect(invoke(["--scope", ".", "--", "apps/wiki/page.tsx"]).status).toBe(
174
+ state === "no-scopes" ? 2 : 0,
175
+ );
176
+ });
177
+ },
178
+ );
179
+
180
+ it.each([
181
+ { evidence: "oxlint.config.ts", file: "oxlint.config.ts" },
182
+ { evidence: "shared/renamed-policy.json", file: "shared/renamed-policy.json" },
183
+ { evidence: "package.json#scripts.lint", file: "package.json" },
184
+ ])(
185
+ "preserves migration authority for $evidence before no-work detection",
186
+ ({ evidence, file }) => {
187
+ withEmptyOwner((root) => {
188
+ mkdirSync(path.join(root, "owner"));
189
+ writeFileSync(path.join(root, "owner/package.json"), "{}");
190
+ writeFileSync(
191
+ path.join(root, ".devpunks/settings.json"),
192
+ JSON.stringify({ lint: { exclude: ["examples/**"], scopes: ["owner"] } }),
193
+ );
194
+ writeFileSync(
195
+ path.join(root, ".devpunks/specs/lint/selection.json"),
196
+ JSON.stringify({
197
+ lintEvidence: {
198
+ conflicts: [{ path: evidence, reason: "Unresolved authored lint authority" }],
199
+ status: "conflict",
200
+ },
201
+ managedLint: { exclude: ["examples/**"], routes: [], scopes: ["owner"], version: 1 },
202
+ }),
203
+ );
204
+ for (const requested of [file, "apps/wiki/page.tsx", "examples/demo.ts"]) {
205
+ const isAuthority = requested === file;
206
+ const result = spawnSync(
207
+ process.execPath,
208
+ [runner, "--root", root, "--format", "json", "--", requested],
209
+ { cwd: root, encoding: "utf-8" },
210
+ );
211
+ expect(result.status).toBe(isAuthority ? 2 : 0);
212
+ expect(decoded(result.stdout)).toMatchObject({
213
+ status: isAuthority ? "conflict" : "clean",
214
+ });
215
+ }
216
+ spawnSync("git", ["init", "-q"], { cwd: root });
217
+ writeFileSync(
218
+ path.join(root, ".devpunks/scaffold-manifest.json"),
219
+ JSON.stringify({ managedFiles: [] }),
220
+ );
221
+ const preview = spawnSync(
222
+ process.execPath,
223
+ [path.resolve(import.meta.dirname, "../hooks/format-edited-file.mjs"), "preview", file],
224
+ { cwd: root, encoding: "utf-8" },
225
+ );
226
+ expect(decoded(preview.stdout)).toMatchObject({
227
+ failures: [expect.objectContaining({ command: "managed lint selection" })],
228
+ result: "operational_failure",
229
+ });
230
+ });
231
+ },
232
+ );
233
+
234
+ it("retains excluded dependency failures while skipping unrelated package boundaries", () => {
235
+ withEmptyOwner((root, version) => {
236
+ mkdirSync(path.join(root, "nested"));
237
+ writeFileSync(path.join(root, "nested/package.json"), "{}");
238
+ writeFileSync(
239
+ path.join(root, ".devpunks/settings.json"),
240
+ JSON.stringify({ lint: { exclude: ["oxlint.config.ts", "wiki/**"], scopes: ["."] } }),
241
+ );
242
+ writeFileSync(
243
+ path.join(root, ".devpunks/specs/lint/selection.json"),
244
+ JSON.stringify({
245
+ managedLint: {
246
+ exclude: [],
247
+ routes: [
248
+ {
249
+ config: "oxlint.config.ts",
250
+ inputs: ["wiki/policy.json"],
251
+ maxWarnings: 0,
252
+ scope: ".",
253
+ tool: { package: "oxlint", version },
254
+ },
255
+ ],
256
+ scopes: ["."],
257
+ version: 1,
258
+ },
259
+ }),
260
+ );
261
+ const invoke = (file: string) =>
262
+ spawnSync(process.execPath, [runner, "--root", root, "--format", "json", "--", file], {
263
+ cwd: root,
264
+ encoding: "utf-8",
265
+ });
266
+ expect(invoke("nested/source.ts").status).toBe(0);
267
+ for (const file of [
268
+ "wiki/policy.json",
269
+ "oxlint.config.ts",
270
+ ".devpunks/settings.json",
271
+ ".devpunks/specs/lint/selection.json",
272
+ ]) {
273
+ expect(invoke(file).status).toBe(2);
274
+ }
275
+ writeFileSync(
276
+ path.join(root, ".devpunks/settings.json"),
277
+ JSON.stringify({ lint: { scopes: ["nested"] } }),
278
+ );
279
+ rmSync(path.join(root, ".devpunks/specs/lint/selection.json"));
280
+ expect(invoke("unrelated/source.ts").status).toBe(0);
281
+ });
282
+ });
283
+
284
+ it("requires software scope selection when the settings file is absent without running lint", () => {
285
+ withEmptyOwner((root) => {
286
+ rmSync(path.join(root, ".devpunks/settings.json"));
287
+ const marker = path.join(root, "lint-ran");
288
+ writeFileSync(path.join(root, "source.ts"), "export const value = 1;\n");
289
+ writeFileSync(
290
+ path.join(root, "oxlint.config.ts"),
291
+ `import { writeFileSync } from "node:fs";\nwriteFileSync(${JSON.stringify(marker)}, "executed");\nexport default {};\n`,
292
+ );
293
+ const result = spawnSync(process.execPath, [runner, "--root", root, "--format", "json"], {
294
+ cwd: root,
295
+ encoding: "utf-8",
296
+ });
297
+ expect(result.status).toBe(2);
298
+ expect(decoded(result.stdout)).toStrictEqual({
299
+ code: 2,
300
+ diagnostics: [expect.stringContaining(".devpunks/settings.json lint.scopes")],
301
+ status: "selection-needed",
302
+ });
303
+ expect(result.stderr).toContain(".devpunks/settings.json lint.scopes");
304
+ expect(existsSync(marker)).toBeFalsy();
305
+ });
306
+ });
307
+
308
+ it.each([null, [], { lint: [] }, { lint: null }])(
309
+ "rejects malformed settings before exclusion proof: %j",
310
+ (settings) => {
311
+ withEmptyOwner((root) => {
312
+ writeFileSync(path.join(root, ".devpunks/settings.json"), JSON.stringify(settings));
313
+ const result = spawnSync(
314
+ process.execPath,
315
+ [runner, "--root", root, "--format", "json", "--", "wiki/page.ts"],
316
+ { cwd: root, encoding: "utf-8" },
317
+ );
318
+ expect(result.status).toBe(2);
319
+ expect(decoded(result.stdout)).toMatchObject({ code: 2, status: "conflict" });
320
+ });
321
+ },
322
+ );
323
+
324
+ it("rejects invalid explicit paths before empty-work proof", async () => {
325
+ const root = mkdtempSync(path.join(os.tmpdir(), "managed-runner-invalid-"));
326
+ try {
327
+ mkdirSync(path.join(root, ".devpunks"));
328
+ writeFileSync(
329
+ path.join(root, ".devpunks/settings.json"),
330
+ JSON.stringify({ lint: { exclude: ["**"], scopes: ["."] } }),
331
+ );
332
+ await Promise.all(
333
+ ["../source.ts", "/source.ts", "wiki/../source.ts"].map(async (file) => {
334
+ await expect(runManagedLint({ paths: [file], root })).resolves.toMatchObject({
335
+ code: 2,
336
+ status: "conflict",
337
+ });
338
+ }),
339
+ );
340
+ } finally {
341
+ rmSync(root, { force: true, recursive: true });
342
+ }
343
+ });
344
+
345
+ it("leaves bundled host command arguments to the host", () => {
346
+ const root = mkdtempSync(path.join(os.tmpdir(), "managed-runner-host-"));
347
+ try {
348
+ const entry = path.join(root, "entry.mjs");
349
+ const bundle = path.join(root, "host.mjs");
350
+ writeFileSync(
351
+ entry,
352
+ `import { runManagedLint } from ${JSON.stringify(runner)};\nconsole.log(typeof runManagedLint);\n`,
353
+ );
354
+ const built = spawnSync(
355
+ process.env.HI_TEST_BUN_PATH ?? "bun",
356
+ ["build", entry, "--target=node", "--format=esm", "--outfile", bundle],
357
+ { encoding: "utf-8" },
358
+ );
359
+ expect({ status: built.status, stderr: built.stderr }).toStrictEqual({
360
+ status: 0,
361
+ stderr: "",
362
+ });
363
+ for (const host of [entry, bundle]) {
364
+ const result = spawnSync(process.execPath, [host, "--help"], {
365
+ cwd: root,
366
+ encoding: "utf-8",
367
+ });
368
+ expect({
369
+ status: result.status,
370
+ stderr: result.stderr,
371
+ stdout: result.stdout,
372
+ }).toStrictEqual({ status: 0, stderr: "", stdout: "function\n" });
373
+ }
374
+ } finally {
375
+ rmSync(root, { force: true, recursive: true });
376
+ }
377
+ });
378
+
379
+ const nativeLaunchError: unknown = expect.objectContaining({ code: "EACCES" });
380
+
381
+ it.each([
382
+ {
383
+ error: undefined,
384
+ executable: true,
385
+ kind: "malformed-output",
386
+ name: "native exit",
387
+ signal: null,
388
+ source: "process.exitCode = 7;",
389
+ status: 7,
390
+ },
391
+ {
392
+ error: undefined,
393
+ executable: true,
394
+ kind: "process",
395
+ name: "interruption",
396
+ signal: "SIGTERM",
397
+ source: 'process.kill(process.pid, "SIGTERM");',
398
+ status: null,
399
+ },
400
+ {
401
+ error: nativeLaunchError,
402
+ executable: false,
403
+ kind: "process",
404
+ name: "launch failure",
405
+ signal: null,
406
+ source: "",
407
+ status: null,
408
+ },
409
+ ])(
410
+ "preserves $name evidence beside normalized failure",
411
+ async ({ source, executable, status, signal, error, kind }) => {
412
+ const root = mkdtempSync(path.join(os.tmpdir(), "managed-runner-witness-"));
413
+ try {
414
+ mkdirSync(path.join(root, ".devpunks/specs/lint"), { recursive: true });
415
+ mkdirSync(path.join(root, "node_modules/oxlint/bin"), { recursive: true });
416
+ writeFileSync(path.join(root, "package.json"), "{}");
417
+ writeFileSync(path.join(root, "source.ts"), "console.log(1);");
418
+ writeFileSync(path.join(root, "oxlint.config.ts"), "export default {};");
419
+ writeFileSync(
420
+ path.join(root, ".devpunks/settings.json"),
421
+ JSON.stringify({ lint: { scopes: ["."] } }),
422
+ );
423
+ writeFileSync(
424
+ path.join(root, ".devpunks/specs/lint/selection.json"),
425
+ JSON.stringify({
426
+ managedLint: {
427
+ exclude: [],
428
+ routes: [
429
+ {
430
+ config: "oxlint.config.ts",
431
+ inputs: [],
432
+ maxWarnings: 0,
433
+ scope: ".",
434
+ tool: { package: "oxlint", version: "1.80.0" },
435
+ },
436
+ ],
437
+ scopes: ["."],
438
+ version: 1,
439
+ },
440
+ }),
441
+ );
442
+ writeFileSync(
443
+ path.join(root, "node_modules/oxlint/package.json"),
444
+ JSON.stringify({ bin: "bin/oxlint", name: "oxlint", version: "1.80.0" }),
445
+ );
446
+ writeFileSync(
447
+ path.join(root, "node_modules/oxlint/bin/oxlint"),
448
+ `#!/usr/bin/env node\n${source}\n`,
449
+ { mode: executable ? 0o755 : 0o644 },
450
+ );
451
+ const result = await runManagedLint({ root });
452
+ expect(result).toMatchObject({
453
+ code: 2,
454
+ results: [{ code: 2, error, failure: { kind, phase: "lint" }, signal, status }],
455
+ status: "operational-failure",
456
+ });
457
+ } finally {
458
+ rmSync(root, { force: true, recursive: true });
459
+ }
460
+ },
461
+ );
462
+
463
+ it.each([true, false])(
464
+ "succeeds without lint source and retains context (module type: %s)",
465
+ (moduleType) => {
466
+ withEmptyOwner((root, version) => {
467
+ if (!moduleType) {
468
+ writeFileSync(path.join(root, "package.json"), "{}\n");
469
+ }
470
+ const result = spawnSync(process.execPath, [runner, "--root", root, "--format", "json"], {
471
+ cwd: root,
472
+ encoding: "utf-8",
473
+ });
474
+ expect(result.status).toBe(0);
475
+ expect(decoded(result.stdout)).toMatchObject({
476
+ code: 0,
477
+ results: [
478
+ {
479
+ code: 0,
480
+ command: {
481
+ args: [
482
+ "--config",
483
+ path.join(root, "oxlint.config.ts"),
484
+ "--disable-nested-config",
485
+ "--max-warnings",
486
+ "0",
487
+ "--format",
488
+ "json",
489
+ "--",
490
+ "oxlint.config.ts",
491
+ "package.json",
492
+ ],
493
+ config: path.join(root, "oxlint.config.ts"),
494
+ cwd: root,
495
+ executable: path.join(root, "node_modules/oxlint/bin/oxlint"),
496
+ scope: ".",
497
+ toolVersion: version,
498
+ },
499
+ diagnostics: [],
500
+ },
501
+ ],
502
+ status: "clean",
503
+ });
504
+ expect(result.stdout).toContain("No files found to lint.");
505
+ });
506
+ },
507
+ );
508
+
509
+ it.each([true, false])(
510
+ "classifies ordinary clean and finding reports (module type: %s)",
511
+ (moduleType) => {
512
+ withEmptyOwner((root) => {
513
+ if (!moduleType) {
514
+ writeFileSync(path.join(root, "package.json"), "{}\n");
515
+ }
516
+ writeFileSync(path.join(root, "source.ts"), "console.log(1);\n");
517
+ const invoke = () =>
518
+ spawnSync(
519
+ process.execPath,
520
+ [runner, "--root", root, "--format", "json", "--", "source.ts"],
521
+ { cwd: root, encoding: "utf-8" },
522
+ );
523
+ writeFileSync(
524
+ path.join(root, "oxlint.config.ts"),
525
+ 'export default {rules: {"no-console": "off"}};\n',
526
+ );
527
+ const clean = invoke();
528
+ expect(clean.status).toBe(0);
529
+ expect(decoded(clean.stdout)).toMatchObject({
530
+ results: [{ code: 0, diagnostics: [], signal: null, status: 0 }],
531
+ status: "clean",
532
+ });
533
+ writeFileSync(
534
+ path.join(root, "oxlint.config.ts"),
535
+ 'export default {rules: {"no-console": "error"}};\n',
536
+ );
537
+ const findings = invoke();
538
+ expect(findings.status).toBe(1);
539
+ expect(decoded(findings.stdout)).toMatchObject({
540
+ results: [
541
+ {
542
+ code: 1,
543
+ diagnostics: [expect.objectContaining({ filename: "source.ts" })],
544
+ signal: null,
545
+ status: 1,
546
+ },
547
+ ],
548
+ status: "findings",
549
+ });
550
+ });
551
+ },
552
+ );
553
+
554
+ it("honors ignored source without removing lint coverage when the policy changes", () => {
555
+ withEmptyOwner((root) => {
556
+ writeFileSync(path.join(root, "source.ts"), "console.log(1);\n");
557
+ writeFileSync(
558
+ path.join(root, "oxlint.config.ts"),
559
+ 'export default {ignorePatterns: ["oxlint.config.ts", "source.ts"], rules: {"no-console": "error"}};\n',
560
+ );
561
+ const invoke = () =>
562
+ spawnSync(process.execPath, [runner, "--format", "json", "--", "source.ts"], {
563
+ cwd: root,
564
+ encoding: "utf-8",
565
+ });
566
+ const ignored = invoke();
567
+ expect(ignored.status).toBe(0);
568
+ expect(decoded(ignored.stdout)).toMatchObject({
569
+ results: [{ diagnostics: [] }],
570
+ status: "clean",
571
+ });
572
+ writeFileSync(
573
+ path.join(root, "oxlint.config.ts"),
574
+ 'export default {ignorePatterns: ["oxlint.config.ts"], rules: {"no-console": "error"}};\n',
575
+ );
576
+ const included = invoke();
577
+ expect(included.status).toBe(1);
578
+ expect(decoded(included.stdout)).toMatchObject({
579
+ results: [{ diagnostics: [expect.objectContaining({ filename: "source.ts" })] }],
580
+ status: "findings",
581
+ });
582
+ });
583
+ });
584
+
585
+ it("keeps staged non-source formatting checks active when lint has no work", () => {
586
+ withEmptyOwner((root) => {
587
+ for (const args of [
588
+ ["init", "-q"],
589
+ ["add", "--", "package.json"],
590
+ ]) {
591
+ const result = spawnSync("git", args, { cwd: root, encoding: "utf-8" });
592
+ if (result.status !== 0) {
593
+ throw new Error(`Git fixture failed: ${result.stderr}`);
594
+ }
595
+ }
596
+ writeFileSync(
597
+ path.join(root, ".devpunks/contracts.json"),
598
+ JSON.stringify([
599
+ {
600
+ execution: { formatCheck: "files", lint: "files" },
601
+ formatCheck: "oxfmt --check {files}",
602
+ lint: `node '${runner}' --format json -- {files}`,
603
+ path: ".",
604
+ },
605
+ ]),
606
+ );
607
+ const before = readFileSync(path.join(root, "package.json"), "utf-8");
608
+ const gate = path.join(import.meta.dirname, "commit-gate-runner.mjs");
609
+ const invoke = () =>
610
+ spawnSync(process.execPath, [gate, "--contracts", ".devpunks/contracts.json"], {
611
+ cwd: root,
612
+ encoding: "utf-8",
613
+ });
614
+ const unformatted = invoke();
615
+ expect(unformatted.status).toBe(1);
616
+ expect(decoded(unformatted.stdout)).toMatchObject({ code: 0, status: "clean" });
617
+ expect(unformatted.stderr).toContain("Commit Gate formatCheck failed");
618
+ expect(readFileSync(path.join(root, "package.json"), "utf-8")).toBe(before);
619
+ const formatted = spawnSync(path.join(root, "node_modules/.bin/oxfmt"), ["package.json"], {
620
+ cwd: root,
621
+ encoding: "utf-8",
622
+ });
623
+ expect({ formatter: formatted.status, gate: invoke().status }).toStrictEqual({
624
+ formatter: 0,
625
+ gate: 0,
626
+ });
627
+ });
628
+ });
629
+
630
+ it.each([
631
+ {
632
+ kind: "config-load",
633
+ name: "clean JSON with configuration stderr",
634
+ status: 0,
635
+ stderr: "Failed to load configuration\n",
636
+ stdout: '{"diagnostics":[]}',
637
+ },
638
+ {
639
+ kind: "config-load",
640
+ name: "findings JSON with configuration stderr",
641
+ status: 1,
642
+ stderr: "Failed to load configuration\n",
643
+ stdout: '{"diagnostics":[{"message":"Failure"}]}',
644
+ },
645
+ {
646
+ kind: "config-load",
647
+ name: "forged module warning suffix",
648
+ status: 0,
649
+ stderr:
650
+ "(node:123) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///tmp/config.ts is not specified and it doesn't parse as CommonJS. Configuration failed\n",
651
+ stdout: '{"diagnostics":[]}',
652
+ },
653
+ {
654
+ kind: "config-load",
655
+ name: "module warning followed by error",
656
+ status: 1,
657
+ stderr:
658
+ "(node:123) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///tmp/config.ts is not specified and it doesn't parse as CommonJS.\nConfiguration failed\n",
659
+ stdout: '{"diagnostics":[{"message":"Failure"}]}',
660
+ },
661
+ {
662
+ kind: "process",
663
+ name: "ordinary stderr",
664
+ status: 0,
665
+ stderr: "Unexpected internal error\n",
666
+ stdout: '{"diagnostics":[]}',
667
+ },
668
+ {
669
+ kind: "config-load",
670
+ name: "native config parse output",
671
+ phase: "config",
672
+ status: 2,
673
+ stdout: "Failed to parse oxlint configuration file.\nInvalid property",
674
+ },
675
+ {
676
+ kind: "config-load",
677
+ name: "malformed output with configuration stderr",
678
+ status: 1,
679
+ stderr: "Failed to load configuration\n",
680
+ stdout: "not json",
681
+ },
682
+ { kind: "process", name: "unproven empty diagnostics", stdout: '{"diagnostics":[]}' },
683
+ {
684
+ kind: "process",
685
+ name: "zero files without the notice",
686
+ stdout: '{"diagnostics":[],"number_of_files":0}',
687
+ },
688
+ { name: "missing file count", stdout: `${noFilesNotice}{"diagnostics":[]}` },
689
+ {
690
+ name: "nonzero file count",
691
+ stdout: `${noFilesNotice}{"diagnostics":[],"number_of_files":1}`,
692
+ },
693
+ {
694
+ name: "invalid file count",
695
+ stdout: `${noFilesNotice}{"diagnostics":[],"number_of_files":"0"}`,
696
+ },
697
+ { name: "malformed JSON", stdout: `${noFilesNotice}{ malformed` },
698
+ { name: "trailing error output", stdout: `${emptyOutput}\nConfiguration error` },
699
+ {
700
+ name: "contradictory diagnostics",
701
+ stdout: `${noFilesNotice}{"diagnostics":[{"message":"Failure"}],"number_of_files":0}`,
702
+ },
703
+ { name: "unexpected notice", stdout: `Configuration failed\n${emptyOutput}` },
704
+ { kind: "process", name: "tool error status", status: 2, stdout: emptyOutput },
705
+ {
706
+ kind: "config-load",
707
+ name: "stderr error",
708
+ stderr: "Failed to load configuration\n",
709
+ stdout: emptyOutput,
710
+ },
711
+ { executable: false, kind: "process", name: "tool launch failure", stdout: "" },
712
+ ])(
713
+ "keeps $name operational and preserves the tool output",
714
+ ({
715
+ stdout,
716
+ status = 1,
717
+ stderr = "",
718
+ executable = true,
719
+ kind = "malformed-output",
720
+ phase = "lint",
721
+ }) => {
722
+ withEmptyOwner((root, version) => {
723
+ rmSync(path.join(root, "node_modules"));
724
+ mkdirSync(path.join(root, "node_modules/oxlint/bin"), { recursive: true });
725
+ writeFileSync(
726
+ path.join(root, "node_modules/oxlint/package.json"),
727
+ JSON.stringify({ bin: "bin/oxlint", name: "oxlint", type: "module", version }),
728
+ );
729
+ writeFileSync(
730
+ path.join(root, "node_modules/oxlint/bin/oxlint"),
731
+ `#!/usr/bin/env node\nprocess.stdout.write(${JSON.stringify(stdout)});\nprocess.stderr.write(${JSON.stringify(stderr)});\nprocess.exitCode = ${status};\n`,
732
+ { mode: executable ? 0o755 : 0o644 },
733
+ );
734
+ const result = spawnSync(process.execPath, [runner, "--root", root, "--format", "json"], {
735
+ cwd: root,
736
+ encoding: "utf-8",
737
+ });
738
+ const launchError: unknown = expect.stringContaining("EACCES");
739
+ expect(result.status).toBe(2);
740
+ expect(decoded(result.stdout)).toMatchObject({
741
+ code: 2,
742
+ results: [
743
+ {
744
+ code: 2,
745
+ command: {
746
+ config: path.join(root, "oxlint.config.ts"),
747
+ cwd: root,
748
+ executable: path.join(root, "node_modules/oxlint/bin/oxlint"),
749
+ toolVersion: version,
750
+ },
751
+ failure: { kind, phase },
752
+ stderr: executable ? stderr : launchError,
753
+ stdout,
754
+ },
755
+ ],
756
+ status: "operational-failure",
757
+ });
758
+ });
759
+ },
760
+ );
761
+
762
+ it("uses identical explicit policy from root and owner cwd and excludes nested projects", () => {
763
+ const root = mkdtempSync(path.join(os.tmpdir(), "managed-runner-parity-"));
764
+ try {
765
+ const scope = "apps/web";
766
+ const owner = path.join(root, scope);
767
+ mkdirSync(path.join(owner, "test/fixture"), { recursive: true });
768
+ mkdirSync(path.join(root, ".devpunks/specs/lint"), { recursive: true });
769
+ symlinkSync(
770
+ path.resolve(import.meta.dirname, "../../../../../node_modules"),
771
+ path.join(root, "node_modules"),
772
+ "dir",
773
+ );
774
+ const tool: unknown = JSON.parse(
775
+ readFileSync(path.join(root, "node_modules/oxlint/package.json"), "utf-8"),
776
+ );
777
+ if (typeof tool !== "object" || tool === null || !("version" in tool)) {
778
+ throw new Error("Missing installed Oxlint identity");
779
+ }
780
+ writeFileSync(path.join(owner, "package.json"), "{}");
781
+ writeFileSync(path.join(owner, "test/fixture/package.json"), "{}");
782
+ writeFileSync(path.join(owner, "test/fixture/bad.ts"), "console.log(2)");
783
+ writeFileSync(path.join(owner, "source.ts"), "console.log(1)");
784
+ writeFileSync(
785
+ path.join(owner, "oxlint.config.ts"),
786
+ 'export default {rules: {"no-console": "error"}};',
787
+ );
788
+ writeFileSync(
789
+ path.join(root, ".devpunks/settings.json"),
790
+ JSON.stringify({ lint: { scopes: [scope] } }),
791
+ );
792
+ writeFileSync(
793
+ path.join(root, ".devpunks/specs/lint/selection.json"),
794
+ JSON.stringify({
795
+ managedLint: {
796
+ exclude: [],
797
+ routes: [
798
+ {
799
+ config: `${scope}/oxlint.config.ts`,
800
+ inputs: ["policy.json"],
801
+ maxWarnings: 0,
802
+ scope,
803
+ tool: { package: "oxlint", version: tool.version },
804
+ },
805
+ ],
806
+ scopes: [scope],
807
+ version: 1,
808
+ },
809
+ }),
810
+ );
811
+ const invoke = (cwd: string, files: string[]) =>
812
+ spawnSync(process.execPath, [runner, "--format", "json", ...files], {
813
+ cwd,
814
+ encoding: "utf-8",
815
+ });
816
+ const rootResult = invoke(root, ["--", "apps/web/source.ts"]);
817
+ const ownerResult = invoke(owner, ["--", "source.ts"]);
818
+ expect(semantic(ownerResult.stdout)).toStrictEqual(semantic(rootResult.stdout));
819
+ expect(rootResult.stdout).toContain("no-console");
820
+ const excluded = invoke(root, ["--", "apps/web/test/fixture/bad.ts"]);
821
+ const dependency = invoke(root, ["--", "policy.json"]);
822
+ writeFileSync(path.join(owner, "oxlint.config.ts"), "export default {invalid: true};");
823
+ const failure = spawnSync(process.execPath, [runner], { cwd: root, encoding: "utf-8" });
824
+ expect({
825
+ dependency: dependency.status,
826
+ excluded: excluded.status,
827
+ excludedDiagnostics: excluded.stdout.includes("no-console"),
828
+ failure: failure.status,
829
+ fixtureDiagnostics: dependency.stdout.includes("test/fixture/bad.ts"),
830
+ owner: ownerResult.status,
831
+ root: rootResult.status,
832
+ }).toStrictEqual({
833
+ dependency: 1,
834
+ excluded: 0,
835
+ excludedDiagnostics: false,
836
+ failure: 2,
837
+ fixtureDiagnostics: false,
838
+ owner: 1,
839
+ root: 1,
840
+ });
841
+ } finally {
842
+ rmSync(root, { force: true, recursive: true });
843
+ }
844
+ });
845
+
846
+ it("requires authored selection and accepts an intentionally empty selection", () => {
847
+ const root = mkdtempSync(path.join(os.tmpdir(), "managed-runner-"));
848
+ try {
849
+ mkdirSync(path.join(root, ".devpunks"));
850
+ writeFileSync(path.join(root, ".devpunks/settings.json"), "{}");
851
+ const missing = spawnSync(process.execPath, [runner, "--root", root], { encoding: "utf-8" });
852
+ expect(missing.status).toBe(2);
853
+ expect(missing.stderr).toContain("lint.scopes");
854
+ writeFileSync(
855
+ path.join(root, ".devpunks/settings.json"),
856
+ JSON.stringify({ lint: { scopes: [] } }),
857
+ );
858
+ const disabled = spawnSync(process.execPath, [runner, "--root", root], { encoding: "utf-8" });
859
+ expect(disabled.status).toBe(0);
860
+ } finally {
861
+ rmSync(root, { force: true, recursive: true });
862
+ }
863
+ });
864
+ });