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.
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/ci.yml +7 -0
- package/CLAUDE.md +2 -2
- package/CONTRIBUTING.md +2 -2
- package/{action.harness.mjs → action.test.mjs} +147 -138
- package/dist/domain/paper-layout.d.ts +18 -6
- package/dist/domain/paper-layout.d.ts.map +1 -1
- package/dist/domain/paper-layout.js +44 -38
- package/dist/domain/paper-layout.js.map +1 -1
- package/dist/eslint-rules/papers.js +1 -1
- package/dist/folder-layout-hook.js +1 -1
- package/dist/latex-log.d.ts +1 -1
- package/dist/latex-log.js +1 -1
- package/dist/latex-loop.d.ts +1 -1
- package/dist/latex-loop.js +1 -1
- package/dist/lib/paper-config.d.ts +3 -3
- package/dist/lib/paper-config.js +3 -3
- package/docs/e2e.md +9 -9
- package/docs/install.md +11 -11
- package/docs/rules/paper/allowed-files-only.md +31 -28
- package/docs/testing.md +3 -4
- package/eslint-rules/{install-path-literals.harness.mjs → install-path-literals.test.mjs} +14 -13
- package/eslint-rules/{latex-language.harness.mjs → latex-language-rules.test.mjs} +61 -51
- package/eslint-rules/{paper-stages.harness.mjs → paper-stages-rule.test.mjs} +66 -69
- package/eslint-rules/{papers.harness.mjs → papers.test.mjs} +41 -30
- package/eslint-rules/papers.ts +1 -1
- package/eslint-rules/{pdf-last-page-balance.harness.mjs → pdf-last-page-balance.test.mjs} +27 -15
- package/eslint-rules/{temp-root-realpath.harness.mjs → temp-root-realpath.test.mjs} +24 -24
- package/eslint-rules/{tex-build.harness.mjs → tex-build.test.mjs} +292 -271
- package/eslint.config.mjs +15 -2
- package/fixtures/pdf-facts/README.md +1 -1
- package/fixtures/render-paper/build-clean.sh +1 -1
- package/fixtures/toolchain-mirror/install-tl +1 -1
- package/lib/{agent-cli-version.harness.mjs → agent-cli-version.test.mjs} +17 -18
- package/lib/{paper-config.harness.mjs → paper-config.test.mjs} +21 -20
- package/lib/paper-config.ts +3 -3
- package/lib/{skill-trigger-cases.harness.mjs → skill-trigger-cases-carrier.test.mjs} +78 -115
- package/package.json +3 -3
- package/presets/acm-acmsmall.jsonc +1 -1
- package/scripts/check-workflow.test.ts +368 -0
- package/scripts/check.ts +2 -2
- package/scripts/eslint-file-length.mjs +9 -9
- package/scripts/eslint-report-guard.mjs +1 -1
- package/scripts/eslint-report-guard.test.mjs +1 -1
- package/scripts/harness-api.test.ts +7 -46
- package/scripts/{rules-see-files.harness.mjs → rules-see-files-rule.test.mjs} +10 -6
- package/scripts/rules-see-files.mjs +1 -1
- package/skills/paper-pipeline/{paper-pipeline.harness.mjs → paper-pipeline.test.mjs} +45 -46
- package/skills/paper-pipeline/scripts/{consumer.harness.mjs → consumer-paths.test.mjs} +66 -59
- package/skills/paper-pipeline/scripts/consumer.mjs +3 -3
- package/skills/paper-pipeline/scripts/{extract-ref-facts.harness.mjs → extract-ref-facts-cli.test.mjs} +29 -31
- package/skills/paper-pipeline/scripts/fixtures/real-bib/refs.bib +1 -1
- package/skills/paper-pipeline/scripts/{generated-code.harness.mjs → generated-code-fixtures.test.mjs} +39 -46
- package/skills/render-paper/{extract-pdf-facts.harness.ts → extract-pdf-facts.test.ts} +20 -13
- package/skills/render-paper/{render-paper.harness.mjs → render-paper.test.mjs} +41 -40
- package/src/adapters/pdfjs/fill.test.ts +1 -1
- package/src/{build-engine.harness.mjs → build-engine-prepare.test.mjs} +98 -81
- package/src/{build.harness.mjs → build-fake-tex.test.mjs} +61 -28
- package/src/{cli.harness.mjs → cli-e2e.test.mjs} +109 -103
- package/src/cli.test.ts +2 -2
- package/src/{doctor.harness.mjs → doctor-install.test.mjs} +28 -29
- package/src/domain/paper-layout.test.ts +89 -49
- package/src/domain/paper-layout.ts +61 -42
- package/src/{engine.harness.mjs → engine.test.mjs} +120 -106
- package/src/facts-file.test.ts +1 -1
- package/src/folder-layout-hook.test.ts +1 -1
- package/src/folder-layout-hook.ts +1 -1
- package/src/folder-layout-rule.test.ts +1 -1
- package/src/{hooks-settings.harness.ts → hooks-settings.test.ts} +161 -146
- package/src/latex-log.test.ts +395 -0
- package/src/latex-log.ts +1 -1
- package/src/latex-loop.test.ts +553 -0
- package/src/latex-loop.ts +1 -1
- package/src/layout-docs.test.ts +47 -0
- package/src/{link-skills.harness.ts → link-skills-fs.test.ts} +26 -26
- package/src/{new-paper.harness.mjs → new-paper-scaffold.test.mjs} +31 -19
- package/src/{pdf-facts.harness.ts → pdf-facts-tables.test.ts} +28 -22
- package/src/{pdf-geometry.harness.ts → pdf-geometry.test.ts} +93 -75
- package/src/{rules-config.harness.ts → rules-config.test.ts} +41 -31
- package/src/{structure.harness.ts → structure.test.ts} +12 -10
- package/src/{tex-requirements.harness.ts → tex-requirements-tables.test.ts} +106 -85
- package/src/{toolchain.harness.mjs → toolchain-mirror.test.mjs} +204 -186
- package/scripts/check.harness.ts +0 -343
- package/scripts/harness-api.frozen.json +0 -41
- package/src/latex-log.harness.ts +0 -382
- package/src/latex-loop.harness.ts +0 -515
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Colocated test for `eslint-rules/papers.mjs`.
|
|
3
|
-
* Run: `npx vigiles test eslint-rules/papers.harness.mjs`
|
|
4
3
|
*
|
|
5
4
|
* FOUR PARTS:
|
|
6
5
|
* I. THE DEFAULT AND THE DECLARATION — the two ways a root is chosen.
|
|
@@ -13,10 +12,10 @@
|
|
|
13
12
|
* in this package. This is the assertion that makes the package reusable, and it is the
|
|
14
13
|
* one that will fail first when someone "just hard-codes it for now".
|
|
15
14
|
*
|
|
16
|
-
*
|
|
17
|
-
* not throw" as success; an exported `tests` object is run by nothing.
|
|
15
|
+
* Each part is one vitest `it`; an assertion that throws fails it.
|
|
18
16
|
*/
|
|
19
17
|
import assert from "node:assert/strict";
|
|
18
|
+
import { afterAll, it, vi } from "vitest";
|
|
20
19
|
import { PAPERS_DIR_FIELD } from "../lib/paper-config.ts";
|
|
21
20
|
import {
|
|
22
21
|
mkdirSync,
|
|
@@ -33,13 +32,16 @@ import { fileURLToPath } from "node:url";
|
|
|
33
32
|
|
|
34
33
|
import { DEFAULT_PAPERS_ROOT, paperFiles, papersRoot } from "./papers.ts";
|
|
35
34
|
|
|
35
|
+
// Several tests here run real ESLint, spawn processes or walk the repository.
|
|
36
|
+
vi.setConfig({ testTimeout: 120_000 });
|
|
37
|
+
|
|
36
38
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
37
39
|
const ROOT = join(HERE, "..");
|
|
38
40
|
|
|
39
41
|
const TMP = realpathSync(mkdtempSync(join(tmpdir(), "papers-root-")));
|
|
40
42
|
// Registered immediately, not at the end: assertions throw, and cleanup at the bottom of a
|
|
41
43
|
// file never runs in exactly the runs that are red.
|
|
42
|
-
|
|
44
|
+
afterAll(() => rmSync(TMP, { recursive: true, force: true }));
|
|
43
45
|
|
|
44
46
|
/** A throwaway repository with the given directories already on disk. */
|
|
45
47
|
const repoWith = (...dirs) => {
|
|
@@ -53,7 +55,7 @@ const declaring = (papers) => ({ [PAPERS_DIR_FIELD]: papers });
|
|
|
53
55
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
54
56
|
// I. THE DEFAULT AND THE DECLARATION
|
|
55
57
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
56
|
-
{
|
|
58
|
+
it("I. THE DEFAULT AND THE DECLARATION: a consumer that declares nothing gets the default", () => {
|
|
57
59
|
const repo = repoWith(DEFAULT_PAPERS_ROOT);
|
|
58
60
|
for (const [label, pkg] of [
|
|
59
61
|
["no paperlint.json at all", undefined],
|
|
@@ -65,18 +67,25 @@ const declaring = (papers) => ({ [PAPERS_DIR_FIELD]: papers });
|
|
|
65
67
|
DEFAULT_PAPERS_ROOT,
|
|
66
68
|
`${label}: a consumer that declares nothing must get the default "${DEFAULT_PAPERS_ROOT}"`,
|
|
67
69
|
);
|
|
68
|
-
}
|
|
70
|
+
});
|
|
69
71
|
|
|
70
72
|
// A declared root wins, including a nested one — the first consumer's is two levels deep, and
|
|
71
73
|
// a helper that only handled a single path segment would work on every fixture and fail there.
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
79
|
-
|
|
74
|
+
it("I. THE DEFAULT AND THE DECLARATION: a declared root wins, including a nested one", () => {
|
|
75
|
+
for (const declared of [
|
|
76
|
+
"papers",
|
|
77
|
+
"docs/papers",
|
|
78
|
+
"writing/drafts",
|
|
79
|
+
"a/b/c/d",
|
|
80
|
+
]) {
|
|
81
|
+
const repo = repoWith(declared);
|
|
82
|
+
assert.equal(
|
|
83
|
+
papersRoot(declaring(declared), repo),
|
|
84
|
+
declared,
|
|
85
|
+
`a declared root must be returned as declared: ${declared}`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
80
89
|
|
|
81
90
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
82
91
|
// II. THE REFUSALS — and the message each one carries
|
|
@@ -84,7 +93,7 @@ for (const declared of ["papers", "docs/papers", "writing/drafts", "a/b/c/d"]) {
|
|
|
84
93
|
// 🔴 THE CENTRAL ONE. A root that is not on disk must STOP the config from loading, because
|
|
85
94
|
// the alternative is not "wrong findings" but NO findings — and a run with no findings is
|
|
86
95
|
// byte-identical to a run that checked everything and passed.
|
|
87
|
-
{
|
|
96
|
+
it("II. THE REFUSALS: a root that is not on disk stops the config from loading", () => {
|
|
88
97
|
const repo = repoWith("somewhere-else");
|
|
89
98
|
assert.throws(
|
|
90
99
|
() => papersRoot(declaring("writing/drafts"), repo),
|
|
@@ -114,16 +123,18 @@ for (const declared of ["papers", "docs/papers", "writing/drafts", "a/b/c/d"]) {
|
|
|
114
123
|
e.message.includes(`{ "${PAPERS_DIR_FIELD}": "path/to/papers" }`),
|
|
115
124
|
"a missing root reached by DEFAULTING must say so and show the declaration to add",
|
|
116
125
|
);
|
|
117
|
-
}
|
|
126
|
+
});
|
|
118
127
|
|
|
119
128
|
// Shapes that are present but unusable. Left unchecked, `""` is the worst of them: it makes
|
|
120
129
|
// every glob `"/*/paper.tex"` — rooted at the filesystem, matching nothing, silently.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
it("II. THE REFUSALS: shapes that are present but unusable", () => {
|
|
131
|
+
for (const bad of ["", null, 0, false, [], {}, 42])
|
|
132
|
+
assert.throws(
|
|
133
|
+
() => papersRoot(declaring(bad), TMP),
|
|
134
|
+
(e) => e instanceof TypeError && /non-empty string/.test(e.message),
|
|
135
|
+
`a "papers" of ${JSON.stringify(bad)} must be refused as a type error, not coerced`,
|
|
136
|
+
);
|
|
137
|
+
});
|
|
127
138
|
|
|
128
139
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
129
140
|
// III. PROPERTIES NOBODY SEES
|
|
@@ -131,7 +142,7 @@ for (const bad of ["", null, 0, false, [], {}, 42])
|
|
|
131
142
|
// 🔴 THE RETURNED ROOT MUST STAY RELATIVE. ESLint resolves `files:` globs against the config's
|
|
132
143
|
// directory; an absolute path there is a different pattern with different behaviour, and the
|
|
133
144
|
// breakage would show up as "the rule stopped matching", i.e. as silence.
|
|
134
|
-
{
|
|
145
|
+
it("III. PROPERTIES NOBODY SEES: the returned root stays relative", () => {
|
|
135
146
|
const repo = repoWith("writing/drafts");
|
|
136
147
|
const got = papersRoot(declaring("writing/drafts"), repo);
|
|
137
148
|
assert.equal(
|
|
@@ -144,14 +155,14 @@ for (const bad of ["", null, 0, false, [], {}, 42])
|
|
|
144
155
|
false,
|
|
145
156
|
"the root must not carry the base directory",
|
|
146
157
|
);
|
|
147
|
-
}
|
|
158
|
+
});
|
|
148
159
|
|
|
149
160
|
// 🔴 `baseDir` DECIDES, NOT `process.cwd()`. This is the assertion that pins the reason the
|
|
150
161
|
// parameter exists: cwd is wherever the editor, the CI step or the hook runtime happened to
|
|
151
162
|
// start, and in a git worktree it can be an entirely different checkout. A helper that quietly
|
|
152
163
|
// used cwd would pass every test run from the repository root and fail in exactly the setups
|
|
153
164
|
// nobody runs tests in.
|
|
154
|
-
{
|
|
165
|
+
it("III. PROPERTIES NOBODY SEES: baseDir decides, not process.cwd()", () => {
|
|
155
166
|
const real = repoWith("writing/drafts");
|
|
156
167
|
const empty = repoWith("unrelated");
|
|
157
168
|
assert.equal(papersRoot(declaring("writing/drafts"), real), "writing/drafts");
|
|
@@ -161,11 +172,11 @@ for (const bad of ["", null, 0, false, [], {}, 42])
|
|
|
161
172
|
"baseDir must be what is consulted — the same declaration must fail against a base that " +
|
|
162
173
|
"does not contain the root",
|
|
163
174
|
);
|
|
164
|
-
}
|
|
175
|
+
});
|
|
165
176
|
|
|
166
177
|
// Every glob set is derived from the root, and NONE of them is spelled out independently: a
|
|
167
178
|
// set that forgot to interpolate would keep matching the previous consumer's layout.
|
|
168
|
-
{
|
|
179
|
+
it("III. PROPERTIES NOBODY SEES: every glob set is derived from the root", () => {
|
|
169
180
|
const sets = paperFiles("R");
|
|
170
181
|
const names = Object.keys(sets).sort();
|
|
171
182
|
assert.deepEqual(
|
|
@@ -194,7 +205,7 @@ for (const bad of ["", null, 0, false, [], {}, 42])
|
|
|
194
205
|
other[name].map((g) => g.replace(/^Q\//, "")),
|
|
195
206
|
`${name}: the two roots did not produce the same shapes — something is hard-coded`,
|
|
196
207
|
);
|
|
197
|
-
}
|
|
208
|
+
});
|
|
198
209
|
|
|
199
210
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
200
211
|
// IV. THE ACCEPTANCE CRITERION OF THE EXTRACTION
|
|
@@ -204,7 +215,7 @@ for (const bad of ["", null, 0, false, [], {}, 42])
|
|
|
204
215
|
// read once, a test runs every time. The forbidden word is the first consumer's own directory
|
|
205
216
|
// name; it may appear ONLY in this file (as the value under test) and in prose that documents
|
|
206
217
|
// the decision.
|
|
207
|
-
{
|
|
218
|
+
it("IV. THE ACCEPTANCE CRITERION OF THE EXTRACTION: no consumer-specific path anywhere in this package", () => {
|
|
208
219
|
// ⚠️ THE ONLY LEGITIMATE OCCURRENCE OF THIS WORD IN THE PACKAGE, and it is here out of
|
|
209
220
|
// necessity: it is the SUBJECT of the assert. The fixtures above deliberately use neutral
|
|
210
221
|
// paths (`writing/drafts`) — until 2026-09-12 they carried the consumer's real directory name,
|
|
@@ -252,4 +263,4 @@ for (const bad of ["", null, 0, false, [], {}, 42])
|
|
|
252
263
|
`one possible user, which is the thing the extraction exists to undo. The root belongs ` +
|
|
253
264
|
`in the consumer's package.json — see eslint-rules/papers.mjs`,
|
|
254
265
|
);
|
|
255
|
-
}
|
|
266
|
+
});
|
package/eslint-rules/papers.ts
CHANGED
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
* running that script has one net, not two.
|
|
67
67
|
*
|
|
68
68
|
* ⚠️ THE EXAMPLES IN THIS FILE ARE DELIBERATELY GENERIC (`docs/papers`), and that is ENFORCED
|
|
69
|
-
* rather than a style preference: `papers.
|
|
69
|
+
* rather than a style preference: `papers.test.mjs` part IV fails if the first consumer's own
|
|
70
70
|
* directory name appears anywhere in this package outside the test itself. It caught this very
|
|
71
71
|
* docblock on 2026-09-11, where the example used the real value. An exemption list is what turns
|
|
72
72
|
* such a check into decoration, so there is exactly one exemption: the file asserting it.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Colocated test for `eslint-rules/pdf-last-page-balance.mjs` (`pdf/last-page-balance`).
|
|
3
|
-
* Run: `npx vigiles test eslint-rules/pdf-last-page-balance.harness.mjs`
|
|
4
3
|
*
|
|
5
4
|
* The rule is driven the way a consumer drives it: through paperlint's own `buildConfig`, with the
|
|
6
5
|
* rule turned on by a `rules` block in the settings — not through a config invented here. Each
|
|
@@ -24,7 +23,10 @@ import { dirname, join } from "node:path";
|
|
|
24
23
|
import { fileURLToPath } from "node:url";
|
|
25
24
|
import { ESLint } from "eslint";
|
|
26
25
|
import { texLanguage } from "./latex-language.ts";
|
|
27
|
-
import {
|
|
26
|
+
import { afterAll, expect, it, vi } from "vitest";
|
|
27
|
+
|
|
28
|
+
// Several tests here run real ESLint, spawn processes or walk the repository.
|
|
29
|
+
vi.setConfig({ testTimeout: 120_000 });
|
|
28
30
|
|
|
29
31
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
30
32
|
const { parseFacts, judgeColumns, DEFAULT_TOLERANCE_PT } = await import(
|
|
@@ -32,7 +34,11 @@ const { parseFacts, judgeColumns, DEFAULT_TOLERANCE_PT } = await import(
|
|
|
32
34
|
);
|
|
33
35
|
const { buildConfig } = await import(join(HERE, "..", "src", "cli.ts"));
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
/** One soft assertion: a failed check does not stop the checks after it in the same test. */
|
|
38
|
+
const check = (label, cond, detail) =>
|
|
39
|
+
expect
|
|
40
|
+
.soft(cond, detail === undefined ? label : `${label}\n${detail}`)
|
|
41
|
+
.toBe(true);
|
|
36
42
|
|
|
37
43
|
const TEX =
|
|
38
44
|
"% a paper\n\\documentclass[sigconf]{acmart}\n\\begin{document}x\\end{document}\n";
|
|
@@ -93,8 +99,11 @@ async function lint(
|
|
|
93
99
|
}
|
|
94
100
|
const only = (msgs) => msgs.filter((m) => m.ruleId === "pdf/last-page-balance");
|
|
95
101
|
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
// Set by the "fires" test, read by the "quiet" one: the tests run in order.
|
|
103
|
+
let unb;
|
|
104
|
+
|
|
105
|
+
// ── pure: parsing the facts and judging the columns ──────────────────────────────────
|
|
106
|
+
it("pure: parsing the facts and judging the columns", () => {
|
|
98
107
|
check(
|
|
99
108
|
"parseFacts: a schema-1 file is refused by name",
|
|
100
109
|
parseFacts(JSON.stringify({ schema: 1 })).messageId === "schema",
|
|
@@ -115,9 +124,11 @@ try {
|
|
|
115
124
|
?.messageId === "unbalanced",
|
|
116
125
|
);
|
|
117
126
|
check("the default tolerance is 120 pt", DEFAULT_TOLERANCE_PT === 120);
|
|
127
|
+
});
|
|
118
128
|
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
// ── fires ───────────────────────────────────────────────────────────────────────────
|
|
130
|
+
it("fires", async () => {
|
|
131
|
+
unb = paper("unbalanced", facts(MEASURED(621.5, 264.8)));
|
|
121
132
|
const u = only(await lint([join(unb, "paper.tex")]));
|
|
122
133
|
check(
|
|
123
134
|
"🔴 an unbalanced last page is a finding, with both heights and the difference",
|
|
@@ -179,8 +190,10 @@ try {
|
|
|
179
190
|
"schema-1 facts are refused, not read with new meanings",
|
|
180
191
|
only(await lint([join(old, "paper.tex")]))[0]?.messageId === "schema",
|
|
181
192
|
);
|
|
193
|
+
});
|
|
182
194
|
|
|
183
|
-
|
|
195
|
+
// ── the facts' optional spellings, and a paper.tex the rule cannot place the finding in ──
|
|
196
|
+
it("the facts' optional spellings, and a paper.tex the rule cannot place the finding in", async () => {
|
|
184
197
|
check(
|
|
185
198
|
"parseFacts: no schema at all, or JSON null, is schema `null` — named, not crashed on",
|
|
186
199
|
parseFacts("{}").data?.got === "null" &&
|
|
@@ -239,8 +252,10 @@ try {
|
|
|
239
252
|
mem.length === 1 && mem[0].line === 1 && mem[0].messageId === "unbalanced",
|
|
240
253
|
JSON.stringify(fromMemory.messages),
|
|
241
254
|
);
|
|
255
|
+
});
|
|
242
256
|
|
|
243
|
-
|
|
257
|
+
// ── quiet ───────────────────────────────────────────────────────────────────────────
|
|
258
|
+
it("quiet", async () => {
|
|
244
259
|
const bal = paper("balanced", facts(MEASURED(464.2, 461.5)));
|
|
245
260
|
const stub = paper("stub", facts({ kind: "stub", words: 12 }));
|
|
246
261
|
const review = paper("review", facts({ kind: "review", line_numbers: 60 }));
|
|
@@ -260,10 +275,7 @@ try {
|
|
|
260
275
|
"🔴 OFF BY DEFAULT: with no `rules` block, an unbalanced paper gets no finding",
|
|
261
276
|
only(await lint([join(unb, "paper.tex")], [])).length === 0,
|
|
262
277
|
);
|
|
263
|
-
}
|
|
278
|
+
});
|
|
279
|
+
afterAll(() => {
|
|
264
280
|
rmSync(root, { recursive: true, force: true });
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
console.log(
|
|
268
|
-
`✓ ${String(check.count)} assertions passed — pdf/last-page-balance: fires on unbalanced and unjudgeable, quiet on balanced/stub/review/off`,
|
|
269
|
-
);
|
|
281
|
+
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `local/temp-root-realpath` — both halves on real ESLint, plus the corpus itself.
|
|
3
3
|
*
|
|
4
|
-
* 🔴 WHY THIS
|
|
4
|
+
* 🔴 WHY THIS TEST EXISTS AT ALL, rather than stopping at the twenty-four fixes. The
|
|
5
5
|
* defect (issue #9) ONLY REPRODUCES ON macOS: there `/var` is a symlink to `/private/var`,
|
|
6
6
|
* and one directory gets two spellings. On Linux `realpathSync` is the identity, so no
|
|
7
7
|
* behavioral test can tell a fixed root apart from a broken one: removing the wrapper leaves
|
|
8
8
|
* the run GREEN. The only check that can even go red on Linux is structural: ask the AST
|
|
9
9
|
* whether the root is resolved at the point it's created. That is exactly why it is written
|
|
10
|
-
* as a linter rule and not an assert inside someone's
|
|
10
|
+
* as a linter rule and not an assert inside someone's test.
|
|
11
11
|
*
|
|
12
|
-
* ⚠️ And a boundary, so
|
|
12
|
+
* ⚠️ And a boundary, so this test isn't mistaken for more: it asserts that the IDIOM is in
|
|
13
13
|
* place, not that macOS is now green. The latter is only checked on macOS, and CI here is one
|
|
14
14
|
* `ubuntu-latest` — recorded as a known limit, not papered over.
|
|
15
15
|
*
|
|
@@ -19,9 +19,13 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import assert from "node:assert/strict";
|
|
21
21
|
import { ESLint } from "eslint";
|
|
22
|
-
import {
|
|
22
|
+
import { it, vi } from "vitest";
|
|
23
23
|
import localRules from "./temp-root-realpath.ts";
|
|
24
24
|
|
|
25
|
+
// A test here lints the whole repository: ~72 s alone, up to 224 s beside the rest of the suite
|
|
26
|
+
// under coverage on 4 cores (measured 2026-11-24), so the limit only catches a hang.
|
|
27
|
+
vi.setConfig({ testTimeout: 600_000 });
|
|
28
|
+
|
|
25
29
|
const eslint = new ESLint({
|
|
26
30
|
overrideConfigFile: true,
|
|
27
31
|
overrideConfig: [
|
|
@@ -45,7 +49,7 @@ const HEAD =
|
|
|
45
49
|
const cases = [];
|
|
46
50
|
|
|
47
51
|
// ── 1. FIRES: a root from `tmpdir()` with no resolve — exactly the shape from issue #9.
|
|
48
|
-
{
|
|
52
|
+
it("1. FIRES: a root from `tmpdir()` with no resolve — exactly the shape from issue #9", async () => {
|
|
49
53
|
const m = await on(
|
|
50
54
|
`${HEAD}const TMP = mkdtempSync(join(tmpdir(), "probe-"));\n`,
|
|
51
55
|
);
|
|
@@ -68,11 +72,11 @@ const cases = [];
|
|
|
68
72
|
cases.push(
|
|
69
73
|
"mkdtempSync(join(tmpdir(), …)) with no resolve → a finding, the fix is in the message",
|
|
70
74
|
);
|
|
71
|
-
}
|
|
75
|
+
});
|
|
72
76
|
|
|
73
77
|
// ── 2. STAYS SILENT on the fixed form. Without this half the rule is indistinguishable
|
|
74
78
|
// from one that screams at every `mkdtempSync`.
|
|
75
|
-
{
|
|
79
|
+
it("2. STAYS SILENT on the fixed form", async () => {
|
|
76
80
|
const m = await on(
|
|
77
81
|
`${HEAD}const TMP = realpathSync(mkdtempSync(join(tmpdir(), "probe-")));\n`,
|
|
78
82
|
);
|
|
@@ -82,14 +86,14 @@ const cases = [];
|
|
|
82
86
|
`the rule must stay silent on a resolved root, got: ${JSON.stringify(m)}`,
|
|
83
87
|
);
|
|
84
88
|
cases.push("realpathSync(mkdtempSync(join(tmpdir(), …))) → silence");
|
|
85
|
-
}
|
|
89
|
+
});
|
|
86
90
|
|
|
87
91
|
// ── 3. 🔴 STAYS SILENT ON A NESTED ROOT, and this is load-bearing, not a concession. The
|
|
88
92
|
// corpus has five of these (`mkdtempSync(join(TMP, "repo-"))`); they inherit their
|
|
89
93
|
// spelling from `TMP`, which is caught at ITS OWN spot. A rule that screamed here too
|
|
90
94
|
// would demand a double resolve — and for an `error`-level rule a false positive is
|
|
91
95
|
// worse than a miss: it gets turned off.
|
|
92
|
-
{
|
|
96
|
+
it("3. STAYS SILENT ON A NESTED ROOT", async () => {
|
|
93
97
|
const m = await on(
|
|
94
98
|
`${HEAD}const TMP = realpathSync(mkdtempSync(join(tmpdir(), "probe-")));\n` +
|
|
95
99
|
`const sub = mkdtempSync(join(TMP, "repo-"));\nvoid sub;\n`,
|
|
@@ -102,12 +106,12 @@ const cases = [];
|
|
|
102
106
|
cases.push(
|
|
103
107
|
"a nested mkdtempSync(join(TMP, …)) → silence (the parent is already resolved)",
|
|
104
108
|
);
|
|
105
|
-
}
|
|
109
|
+
});
|
|
106
110
|
|
|
107
111
|
// ── 4. A COMMENT AND A STRING ARE NOT A CALL. This is exactly why the rule parses the AST: a
|
|
108
112
|
// text-based guard looking for "mkdtempSync(join(tmpdir()" would find this very file and
|
|
109
113
|
// would have to exclude itself — the class of check string-based checks are banned for here.
|
|
110
|
-
{
|
|
114
|
+
it("4. A COMMENT AND A STRING ARE NOT A CALL", async () => {
|
|
111
115
|
const m = await on(
|
|
112
116
|
`${HEAD}// mkdtempSync(join(tmpdir(), "in-a-comment-"))\n` +
|
|
113
117
|
`const doc = 'mkdtempSync(join(tmpdir(), "in-a-string-"))';\nvoid doc;\n`,
|
|
@@ -118,11 +122,11 @@ const cases = [];
|
|
|
118
122
|
`text ABOUT a call is not a call; got: ${JSON.stringify(m)}`,
|
|
119
123
|
);
|
|
120
124
|
cases.push("the same sequence in a comment and a string → silence");
|
|
121
|
-
}
|
|
125
|
+
});
|
|
122
126
|
|
|
123
127
|
// ── 5. `fs.mkdtempSync` / `os.tmpdir()` through a namespace — the same thing under a
|
|
124
128
|
// different spelling.
|
|
125
|
-
{
|
|
129
|
+
it("5. `fs.mkdtempSync` / `os.tmpdir()` through a namespace", async () => {
|
|
126
130
|
const ns =
|
|
127
131
|
'import * as fs from "node:fs";\nimport * as os from "node:os";\nimport { join } from "node:path";\n';
|
|
128
132
|
const bad = await on(
|
|
@@ -144,12 +148,12 @@ const cases = [];
|
|
|
144
148
|
cases.push(
|
|
145
149
|
"fs.mkdtempSync(join(os.tmpdir(), …)) is caught, fs.realpathSync(…) exempts it",
|
|
146
150
|
);
|
|
147
|
-
}
|
|
151
|
+
});
|
|
148
152
|
|
|
149
153
|
// ── 5b. `realpathSync.native(…)` resolves too — as a bare import and through a namespace. A
|
|
150
154
|
// `.native(…)` on anything else is NOT a resolve: another object, a computed member, a call
|
|
151
155
|
// result, a bare `native` function. Each of those still gets its finding.
|
|
152
|
-
{
|
|
156
|
+
it("5b. `realpathSync.native(…)` resolves too — as a bare import and through a namespace", async () => {
|
|
153
157
|
const root = 'mkdtempSync(join(tmpdir(), "probe-"))';
|
|
154
158
|
const silent = await on(
|
|
155
159
|
`${HEAD}import * as fs from "node:fs";\n` +
|
|
@@ -177,11 +181,11 @@ const cases = [];
|
|
|
177
181
|
cases.push(
|
|
178
182
|
"realpathSync.native / fs.realpathSync.native exempt; keep, other.native, fs[name].native, pick().native, native do not",
|
|
179
183
|
);
|
|
180
|
-
}
|
|
184
|
+
});
|
|
181
185
|
|
|
182
186
|
// ── 5c. The walk over the arguments survives the shapes that are not plain nodes: an array hole
|
|
183
187
|
// (null) and a regex literal's `regex` object (no `type`). Neither is a `tmpdir()` call.
|
|
184
|
-
{
|
|
188
|
+
it("5c. The walk over the arguments survives the shapes that are not plain nodes", async () => {
|
|
185
189
|
const m = await on(
|
|
186
190
|
`${HEAD}const a = mkdtempSync([, /tmp/g]);\nconst b = mkdtempSync([, /x/, tmpdir()]);\n`,
|
|
187
191
|
);
|
|
@@ -193,13 +197,13 @@ const cases = [];
|
|
|
193
197
|
cases.push(
|
|
194
198
|
"an array hole and a regex literal in the arguments are walked, not mistaken",
|
|
195
199
|
);
|
|
196
|
-
}
|
|
200
|
+
});
|
|
197
201
|
|
|
198
202
|
// ── 6. 🔴 THE CORPUS ITSELF IS CLEAN. The "silent" half on a made-up string says nothing
|
|
199
203
|
// about the repository: the rule could also be silent because it was never handed a
|
|
200
204
|
// single file (the recorded class — `scripts/rules-see-files.mjs`). So this check runs
|
|
201
205
|
// THE RULE OVER THE REAL TREE and requires many files, zero findings.
|
|
202
|
-
{
|
|
206
|
+
it("6. THE CORPUS ITSELF IS CLEAN", async () => {
|
|
203
207
|
const corpus = new ESLint({ cwd: new URL("..", import.meta.url).pathname });
|
|
204
208
|
const results = await corpus.lintFiles(["."]);
|
|
205
209
|
const hits = results.flatMap((r) =>
|
|
@@ -218,8 +222,4 @@ const cases = [];
|
|
|
218
222
|
`the rule was only handed ${linted} .mjs files — zero findings on an empty input is NOT cleanliness`,
|
|
219
223
|
);
|
|
220
224
|
cases.push(`corpus: ${linted} .mjs files, zero unresolved roots`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
recordCheck(cases.length);
|
|
224
|
-
console.log(`local/temp-root-realpath: ${cases.length} cases:`);
|
|
225
|
-
for (const c of cases) console.log(` ok ${c}`);
|
|
225
|
+
});
|