paperlint 20.1.0 → 20.1.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 (86) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.github/workflows/ci.yml +7 -0
  3. package/CLAUDE.md +2 -2
  4. package/CONTRIBUTING.md +2 -2
  5. package/{action.harness.mjs → action.test.mjs} +147 -138
  6. package/dist/domain/paper-layout.d.ts +18 -6
  7. package/dist/domain/paper-layout.d.ts.map +1 -1
  8. package/dist/domain/paper-layout.js +44 -38
  9. package/dist/domain/paper-layout.js.map +1 -1
  10. package/dist/eslint-rules/papers.js +1 -1
  11. package/dist/folder-layout-hook.js +1 -1
  12. package/dist/latex-log.d.ts +1 -1
  13. package/dist/latex-log.js +1 -1
  14. package/dist/latex-loop.d.ts +1 -1
  15. package/dist/latex-loop.js +1 -1
  16. package/dist/lib/paper-config.d.ts +3 -3
  17. package/dist/lib/paper-config.js +3 -3
  18. package/docs/e2e.md +9 -9
  19. package/docs/install.md +11 -11
  20. package/docs/rules/paper/allowed-files-only.md +31 -28
  21. package/docs/testing.md +3 -4
  22. package/eslint-rules/{install-path-literals.harness.mjs → install-path-literals.test.mjs} +14 -13
  23. package/eslint-rules/{latex-language.harness.mjs → latex-language-rules.test.mjs} +61 -51
  24. package/eslint-rules/{paper-stages.harness.mjs → paper-stages-rule.test.mjs} +66 -69
  25. package/eslint-rules/{papers.harness.mjs → papers.test.mjs} +41 -30
  26. package/eslint-rules/papers.ts +1 -1
  27. package/eslint-rules/{pdf-last-page-balance.harness.mjs → pdf-last-page-balance.test.mjs} +27 -15
  28. package/eslint-rules/{temp-root-realpath.harness.mjs → temp-root-realpath.test.mjs} +24 -24
  29. package/eslint-rules/{tex-build.harness.mjs → tex-build.test.mjs} +292 -271
  30. package/eslint.config.mjs +15 -2
  31. package/fixtures/pdf-facts/README.md +1 -1
  32. package/fixtures/render-paper/build-clean.sh +1 -1
  33. package/fixtures/toolchain-mirror/install-tl +1 -1
  34. package/lib/{agent-cli-version.harness.mjs → agent-cli-version.test.mjs} +17 -18
  35. package/lib/{paper-config.harness.mjs → paper-config.test.mjs} +21 -20
  36. package/lib/paper-config.ts +3 -3
  37. package/lib/{skill-trigger-cases.harness.mjs → skill-trigger-cases-carrier.test.mjs} +78 -115
  38. package/package.json +3 -3
  39. package/presets/acm-acmsmall.jsonc +1 -1
  40. package/scripts/check-workflow.test.ts +368 -0
  41. package/scripts/check.ts +2 -2
  42. package/scripts/eslint-file-length.mjs +9 -9
  43. package/scripts/eslint-report-guard.mjs +1 -1
  44. package/scripts/eslint-report-guard.test.mjs +1 -1
  45. package/scripts/harness-api.test.ts +7 -46
  46. package/scripts/{rules-see-files.harness.mjs → rules-see-files-rule.test.mjs} +10 -6
  47. package/scripts/rules-see-files.mjs +1 -1
  48. package/skills/paper-pipeline/{paper-pipeline.harness.mjs → paper-pipeline.test.mjs} +45 -46
  49. package/skills/paper-pipeline/scripts/{consumer.harness.mjs → consumer-paths.test.mjs} +66 -59
  50. package/skills/paper-pipeline/scripts/consumer.mjs +3 -3
  51. package/skills/paper-pipeline/scripts/{extract-ref-facts.harness.mjs → extract-ref-facts-cli.test.mjs} +29 -31
  52. package/skills/paper-pipeline/scripts/fixtures/real-bib/refs.bib +1 -1
  53. package/skills/paper-pipeline/scripts/{generated-code.harness.mjs → generated-code-fixtures.test.mjs} +39 -46
  54. package/skills/render-paper/{extract-pdf-facts.harness.ts → extract-pdf-facts.test.ts} +20 -13
  55. package/skills/render-paper/{render-paper.harness.mjs → render-paper.test.mjs} +41 -40
  56. package/src/adapters/pdfjs/fill.test.ts +1 -1
  57. package/src/{build-engine.harness.mjs → build-engine-prepare.test.mjs} +98 -81
  58. package/src/{build.harness.mjs → build-fake-tex.test.mjs} +61 -28
  59. package/src/{cli.harness.mjs → cli-e2e.test.mjs} +109 -103
  60. package/src/cli.test.ts +2 -2
  61. package/src/{doctor.harness.mjs → doctor-install.test.mjs} +28 -29
  62. package/src/domain/paper-layout.test.ts +89 -49
  63. package/src/domain/paper-layout.ts +61 -42
  64. package/src/{engine.harness.mjs → engine.test.mjs} +120 -106
  65. package/src/facts-file.test.ts +1 -1
  66. package/src/folder-layout-hook.test.ts +1 -1
  67. package/src/folder-layout-hook.ts +1 -1
  68. package/src/folder-layout-rule.test.ts +1 -1
  69. package/src/{hooks-settings.harness.ts → hooks-settings.test.ts} +161 -146
  70. package/src/latex-log.test.ts +395 -0
  71. package/src/latex-log.ts +1 -1
  72. package/src/latex-loop.test.ts +553 -0
  73. package/src/latex-loop.ts +1 -1
  74. package/src/layout-docs.test.ts +47 -0
  75. package/src/{link-skills.harness.ts → link-skills-fs.test.ts} +26 -26
  76. package/src/{new-paper.harness.mjs → new-paper-scaffold.test.mjs} +31 -19
  77. package/src/{pdf-facts.harness.ts → pdf-facts-tables.test.ts} +28 -22
  78. package/src/{pdf-geometry.harness.ts → pdf-geometry.test.ts} +93 -75
  79. package/src/{rules-config.harness.ts → rules-config.test.ts} +41 -31
  80. package/src/{structure.harness.ts → structure.test.ts} +12 -10
  81. package/src/{tex-requirements.harness.ts → tex-requirements-tables.test.ts} +106 -85
  82. package/src/{toolchain.harness.mjs → toolchain-mirror.test.mjs} +204 -186
  83. package/scripts/check.harness.ts +0 -343
  84. package/scripts/harness-api.frozen.json +0 -41
  85. package/src/latex-log.harness.ts +0 -382
  86. package/src/latex-loop.harness.ts +0 -515
@@ -12,9 +12,10 @@
12
12
  * for nothing — and a reformat of the user's own file is a change they did not ask for;
13
13
  * - a doctor that says "wired" over nothing, or offers a remedy `init` then refuses to apply.
14
14
  *
15
- * ⚠️ Assertions at the TOP LEVEL: `vigiles test` imports the file and counts "did not throw"
16
- * as a pass.
15
+ * The tests run in order, on the temp projects the earlier ones made.
17
16
  */
17
+ import { afterAll, describe, expect, it } from "vitest";
18
+ import { failureMessage } from "../lib/check.ts";
18
19
  import {
19
20
  existsSync,
20
21
  mkdirSync,
@@ -26,7 +27,6 @@ import {
26
27
  } from "node:fs";
27
28
  import { tmpdir } from "node:os";
28
29
  import { join } from "node:path";
29
- import { createChecker } from "../lib/check.ts";
30
30
  import { isDeepStrictEqual } from "node:util";
31
31
  import { z } from "zod";
32
32
  import type { Merge, Settings } from "./hooks-settings.ts";
@@ -54,20 +54,28 @@ const { claudeCodeHookProtocol } = await import("vigiles/claude-code");
54
54
  const merge: Merge = (e, c, m) =>
55
55
  claudeCodeHookProtocol.mergeRegistrations(e, c, m);
56
56
 
57
- const check = createChecker();
57
+ // A failed check is recorded and the rest of the test keeps running.
58
+ const check = (label: string, cond: unknown, detail?: unknown): void => {
59
+ expect.soft(cond, failureMessage(label, detail)).toBeTruthy();
60
+ };
58
61
 
59
62
  // ── the contract with vigiles, checked before anything relies on it ──────────────────────
60
- check(
61
- "🔴 vigiles/claude-code exports claudeCodeHookProtocol.mergeRegistrations — the merge init calls",
62
- typeof claudeCodeHookProtocol.mergeRegistrations === "function",
63
- );
63
+ it("the contract with vigiles, checked before anything relies on it", () => {
64
+ check(
65
+ "🔴 vigiles/claude-code exports claudeCodeHookProtocol.mergeRegistrations — the merge init calls",
66
+ typeof claudeCodeHookProtocol.mergeRegistrations === "function",
67
+ );
68
+ });
64
69
 
65
70
  // ── the one source: plugin/hooks/hooks.json ─────────────────────────────────────────────
66
71
  const wiring = shippedWiring();
67
- check(
68
- "the hook names are DERIVED from hooks.json — three, in its order",
69
- wiring.names.join() === "submission-confirm,paper-folder-layout,lint-edited",
70
- );
72
+ it("the one source: plugin/hooks/hooks.json", () => {
73
+ check(
74
+ "the hook names are DERIVED from hooks.json — three, in its order",
75
+ wiring.names.join() ===
76
+ "submission-confirm,paper-folder-layout,lint-edited",
77
+ );
78
+ });
71
79
  // ── settings written by hand: shapes Claude Code would ignore are skipped, not crashed on ──
72
80
  const MALFORMED = {
73
81
  PreToolUse: "npx paperlint hook submission-confirm",
@@ -75,12 +83,14 @@ const MALFORMED = {
75
83
  Stop: [{ hooks: [{ type: "command" }, null] }],
76
84
  };
77
85
  const zero = { ours: 0, other: 0, places: 0 };
78
- check(
79
- "an event that is not a list, an entry with no `hooks` list, a handler with no command → no commands",
80
- JSON.stringify(wiredCounts({ hooks: MALFORMED }, wiring.names)) ===
81
- JSON.stringify(wiring.names.map((name) => ({ name, ...zero }))),
82
- );
83
- {
86
+ it("settings written by hand: shapes Claude Code would ignore are skipped, not crashed on", () => {
87
+ check(
88
+ "an event that is not a list, an entry with no `hooks` list, a handler with no command → no commands",
89
+ JSON.stringify(wiredCounts({ hooks: MALFORMED }, wiring.names)) ===
90
+ JSON.stringify(wiring.names.map((name) => ({ name, ...zero }))),
91
+ );
92
+ });
93
+ it("a wiring file without `hooks` names no hook", () => {
84
94
  const file = join(tmpdir(), `paperlint-no-hooks-${String(process.pid)}.json`);
85
95
  writeFileSync(file, "{}\n");
86
96
  let thrown = "";
@@ -95,72 +105,80 @@ check(
95
105
  thrown === `${file} names no paperlint hook — there is nothing to wire`,
96
106
  thrown,
97
107
  );
98
- }
108
+ });
99
109
 
100
110
  const work = realpathSync(mkdtempSync(join(tmpdir(), "paperlint-hooks-")));
101
- try {
102
- const empty = join(work, "empty-hooks.json");
103
- writeFileSync(empty, '{"hooks":{}}');
104
- let threw = false;
105
- try {
106
- shippedWiring(empty);
107
- } catch {
108
- threw = true;
109
- }
110
- check(
111
- "a wiring file naming no hook THROWS — wiring nothing must not read as wired",
112
- threw,
113
- );
111
+ afterAll(() => {
112
+ rmSync(work, { recursive: true, force: true });
113
+ });
114
114
 
115
- const malformed = join(work, "malformed-hooks.json");
116
- writeFileSync(
117
- malformed,
118
- '{"hooks":{"PreToolUse":[{"hooks":[{"type":"command"}]}]}}',
119
- );
120
- let why = "";
121
- try {
122
- shippedWiring(malformed);
123
- } catch (e) {
124
- why = e instanceof Error ? e.message : String(e);
125
- }
126
- check(
127
- "a wiring file whose `hooks` is not Claude Code's shape THROWS, naming the shape",
128
- why.startsWith(`${malformed}: "hooks" is not a map of event`),
129
- why,
130
- );
115
+ describe("the hooks land in .claude/settings.json once", () => {
116
+ it("a wiring file that is empty or malformed THROWS", () => {
117
+ const empty = join(work, "empty-hooks.json");
118
+ writeFileSync(empty, '{"hooks":{}}');
119
+ let threw = false;
120
+ try {
121
+ shippedWiring(empty);
122
+ } catch {
123
+ threw = true;
124
+ }
125
+ check(
126
+ "a wiring file naming no hook THROWS — wiring nothing must not read as wired",
127
+ threw,
128
+ );
131
129
 
132
- // ── which spelling runs which hook ─────────────────────────────────────────────────────
133
- const ours = `node "\${CLAUDE_PROJECT_DIR}/${MANAGED_BY}" hook submission-confirm`;
134
- const cases: [string, { name: string; ours: boolean } | null][] = [
135
- [ours, { name: "submission-confirm", ours: true }],
136
- [
137
- `node "$CLAUDE_PROJECT_DIR/${MANAGED_BY}" hook lint-edited`,
138
- { name: "lint-edited", ours: true },
139
- ],
140
- [
141
- `node "$CLAUDE_PROJECT_DIR/node_modules/vigiles/dist/cli.js" hook-runtime run-program "$CLAUDE_PROJECT_DIR/node_modules/paperlint/hooks/submission-confirm.hook.mjs"`,
142
- { name: "submission-confirm", ours: false },
143
- ],
144
- [
145
- `npx paperlint hook paper-folder-layout`,
146
- { name: "paper-folder-layout", ours: false },
147
- ],
148
- [
149
- `npx paperlint hook paper-folder-layout`,
150
- { name: "paper-folder-layout", ours: false },
151
- ],
152
- [
153
- `node /abs/proj/node_modules/paperlint/bin/paperlint.mjs hook submission-confirm`,
154
- { name: "submission-confirm", ours: false },
155
- ],
156
- [`node my-own-lint.mjs`, null],
157
- [`node node_modules/paperlint/bin/paperlint.mjs lint`, null],
158
- ];
159
- for (const [cmd, want] of cases)
130
+ const malformed = join(work, "malformed-hooks.json");
131
+ writeFileSync(
132
+ malformed,
133
+ '{"hooks":{"PreToolUse":[{"hooks":[{"type":"command"}]}]}}',
134
+ );
135
+ let why = "";
136
+ try {
137
+ shippedWiring(malformed);
138
+ } catch (e) {
139
+ why = e instanceof Error ? e.message : String(e);
140
+ }
160
141
  check(
161
- `hookRun(${cmd.slice(0, 60)}…) → ${JSON.stringify(want)}`,
162
- JSON.stringify(hookRun(cmd)) === JSON.stringify(want),
142
+ "a wiring file whose `hooks` is not Claude Code's shape THROWS, naming the shape",
143
+ why.startsWith(`${malformed}: "hooks" is not a map of event`),
144
+ why,
163
145
  );
146
+ });
147
+
148
+ // ── which spelling runs which hook ─────────────────────────────────────────────────────
149
+ it("which spelling runs which hook", () => {
150
+ const ours = `node "\${CLAUDE_PROJECT_DIR}/${MANAGED_BY}" hook submission-confirm`;
151
+ const cases: [string, { name: string; ours: boolean } | null][] = [
152
+ [ours, { name: "submission-confirm", ours: true }],
153
+ [
154
+ `node "$CLAUDE_PROJECT_DIR/${MANAGED_BY}" hook lint-edited`,
155
+ { name: "lint-edited", ours: true },
156
+ ],
157
+ [
158
+ `node "$CLAUDE_PROJECT_DIR/node_modules/vigiles/dist/cli.js" hook-runtime run-program "$CLAUDE_PROJECT_DIR/node_modules/paperlint/hooks/submission-confirm.hook.mjs"`,
159
+ { name: "submission-confirm", ours: false },
160
+ ],
161
+ [
162
+ `npx paperlint hook paper-folder-layout`,
163
+ { name: "paper-folder-layout", ours: false },
164
+ ],
165
+ [
166
+ `npx paperlint hook paper-folder-layout`,
167
+ { name: "paper-folder-layout", ours: false },
168
+ ],
169
+ [
170
+ `node /abs/proj/node_modules/paperlint/bin/paperlint.mjs hook submission-confirm`,
171
+ { name: "submission-confirm", ours: false },
172
+ ],
173
+ [`node my-own-lint.mjs`, null],
174
+ [`node node_modules/paperlint/bin/paperlint.mjs lint`, null],
175
+ ];
176
+ for (const [cmd, want] of cases)
177
+ check(
178
+ `hookRun(${cmd.slice(0, 60)}…) → ${JSON.stringify(want)}`,
179
+ JSON.stringify(hookRun(cmd)) === JSON.stringify(want),
180
+ );
181
+ });
164
182
 
165
183
  const project = (name: string, settings?: Settings | string) => {
166
184
  const dir = join(work, name);
@@ -182,7 +200,7 @@ try {
182
200
  };
183
201
 
184
202
  // ── a fresh project ────────────────────────────────────────────────────────────────────
185
- {
203
+ it("a fresh project", () => {
186
204
  const dir = join(work, "fresh");
187
205
  mkdirSync(dir);
188
206
  const r = wireHooks(dir, merge, wiring);
@@ -200,10 +218,10 @@ try {
200
218
  "🔴 a second run changes NOTHING — byte-identical, status `present`",
201
219
  again.status === "present" && text(dir) === before,
202
220
  );
203
- }
221
+ });
204
222
 
205
223
  // ── the user's own hooks and keys survive ──────────────────────────────────────────────
206
- {
224
+ it("the user's own hooks and keys survive", () => {
207
225
  const dir = project("user", {
208
226
  permissions: { allow: ["Bash(ls:*)"] },
209
227
  hooks: {
@@ -231,10 +249,10 @@ try {
231
249
  (c) => c.ours === wiring.times[c.name],
232
250
  ),
233
251
  );
234
- }
252
+ });
235
253
 
236
254
  // ── already wired, in someone else's formatting → the file is not touched ──────────────
237
- {
255
+ it("already wired, in someone else's formatting → the file is not touched", () => {
238
256
  const wired = merge({}, wiring.compiled, MANAGED_BY);
239
257
  const fourSpaces = JSON.stringify(wired, null, 4);
240
258
  const dir = project("formatted", fourSpaces);
@@ -243,10 +261,10 @@ try {
243
261
  "🔴 wired already → nothing is rewritten, not even to our indentation",
244
262
  r.status === "present" && text(dir) === fourSpaces,
245
263
  );
246
- }
264
+ });
247
265
 
248
266
  // ── another spelling of the same hook → write NOTHING ──────────────────────────────────
249
- {
267
+ it("another spelling of the same hook → write NOTHING", () => {
250
268
  const handWired = {
251
269
  hooks: {
252
270
  PreToolUse: [
@@ -291,10 +309,10 @@ try {
291
309
  "(control) vigiles' merge alone would wire submission-confirm TWICE here",
292
310
  c?.ours === 1 && c.other === 1,
293
311
  );
294
- }
312
+ });
295
313
 
296
314
  // ── a file that does not parse is reported, never overwritten ──────────────────────────
297
- {
315
+ it("a file that does not parse is reported, never overwritten", () => {
298
316
  const dir = project("broken", "{ not json");
299
317
  const r = wireHooks(dir, merge, wiring);
300
318
  check(
@@ -305,68 +323,65 @@ try {
305
323
  "an array is not a settings object either",
306
324
  readSettings(project("array", "[]\n")).status === "unparsable",
307
325
  );
308
- }
326
+ });
309
327
 
310
328
  // ── doctor's section ───────────────────────────────────────────────────────────────────
329
+ let docs = 0;
311
330
  const doc = (settings?: Settings | string) => {
312
- const dir = project(`doc-${String(check.count)}`, settings);
331
+ const dir = project(`doc-${String(++docs)}`, settings);
313
332
  return doctorHooks(dir, wiring).lines.join("\n");
314
333
  };
315
- const wiredOnce = merge({}, wiring.compiled, MANAGED_BY);
316
- check(
317
- "wired as shipped → ✓ wired, with the fresh-clone consequence",
318
- /✓ wired — submission-confirm, paper-folder-layout, lint-edited, each as shipped/.test(
319
- doc(wiredOnce),
320
- ) && /cannot run until `npm install`/.test(doc(wiredOnce)),
321
- );
322
- check(
323
- "nothing wired → ⚠ not wired, with the remedy",
324
- /⚠ not wired — none of the 3 hooks/.test(doc({})),
325
- );
326
- const twice = PreToolUseSettings.parse(structuredClone(wiredOnce));
327
- twice.hooks.PreToolUse[0]?.hooks.push({
328
- type: "command",
329
- command: "npx paperlint hook submission-confirm",
330
- });
331
- const twiceText = doc(twice);
332
- check(
333
- "🔴 the same hook under two spellings → ⚠ wired TWICE, naming it with its count",
334
- /wired TWICE/.test(twiceText) &&
335
- /submission-confirm ×2/.test(twiceText) &&
336
- !/✓ wired/.test(twiceText),
337
- );
338
- const handPartial = doc({
339
- hooks: {
340
- PreToolUse: [
341
- {
342
- matcher: "Bash",
343
- hooks: [
344
- { type: "command", command: "npx paperlint hook lint-edited" },
345
- ],
346
- },
347
- ],
348
- },
334
+ it("doctor's section", () => {
335
+ const wiredOnce = merge({}, wiring.compiled, MANAGED_BY);
336
+ check(
337
+ "wired as shipped → ✓ wired, with the fresh-clone consequence",
338
+ /✓ wired — submission-confirm, paper-folder-layout, lint-edited, each as shipped/.test(
339
+ doc(wiredOnce),
340
+ ) && /cannot run until `npm install`/.test(doc(wiredOnce)),
341
+ );
342
+ check(
343
+ "nothing wired → ⚠ not wired, with the remedy",
344
+ /⚠ not wired — none of the 3 hooks/.test(doc({})),
345
+ );
346
+ const twice = PreToolUseSettings.parse(structuredClone(wiredOnce));
347
+ twice.hooks.PreToolUse[0]?.hooks.push({
348
+ type: "command",
349
+ command: "npx paperlint hook submission-confirm",
350
+ });
351
+ const twiceText = doc(twice);
352
+ check(
353
+ "🔴 the same hook under two spellings → ⚠ wired TWICE, naming it with its count",
354
+ /wired TWICE/.test(twiceText) &&
355
+ /submission-confirm ×2/.test(twiceText) &&
356
+ !/✓ wired/.test(twiceText),
357
+ );
358
+ const handPartial = doc({
359
+ hooks: {
360
+ PreToolUse: [
361
+ {
362
+ matcher: "Bash",
363
+ hooks: [
364
+ { type: "command", command: "npx paperlint hook lint-edited" },
365
+ ],
366
+ },
367
+ ],
368
+ },
369
+ });
370
+ check(
371
+ "🔴 partly wired BY HAND → the remedy is NOT `npx paperlint init`, which would refuse to write",
372
+ /partly wired — missing: submission-confirm, paper-folder-layout/.test(
373
+ handPartial,
374
+ ) && /writes nothing then/.test(handPartial),
375
+ );
376
+ check(
377
+ "an unparsable file is named in doctor, not crashed on",
378
+ /does not parse/.test(
379
+ doctorHooks(project("doc-broken", "{"), wiring).lines.join("\n"),
380
+ ),
381
+ );
382
+ check(
383
+ "(the scratch projects exist — nothing above was vacuous)",
384
+ existsSync(work),
385
+ );
349
386
  });
350
- check(
351
- "🔴 partly wired BY HAND → the remedy is NOT `npx paperlint init`, which would refuse to write",
352
- /partly wired — missing: submission-confirm, paper-folder-layout/.test(
353
- handPartial,
354
- ) && /writes nothing then/.test(handPartial),
355
- );
356
- check(
357
- "an unparsable file is named in doctor, not crashed on",
358
- /does not parse/.test(
359
- doctorHooks(project("doc-broken", "{"), wiring).lines.join("\n"),
360
- ),
361
- );
362
- check(
363
- "(the scratch projects exist — nothing above was vacuous)",
364
- existsSync(work),
365
- );
366
- } finally {
367
- rmSync(work, { recursive: true, force: true });
368
- }
369
-
370
- console.log(
371
- `✓ ${String(check.count)} assertions passed — the hooks land in .claude/settings.json once`,
372
- );
387
+ });