paperlint 18.3.1 → 18.4.0
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/dist/adapters/memory/index.d.ts +6 -0
- package/dist/adapters/memory/index.d.ts.map +1 -1
- package/dist/adapters/memory/index.js +11 -0
- package/dist/adapters/memory/index.js.map +1 -1
- package/dist/adapters/node/index.d.ts +1 -0
- package/dist/adapters/node/index.d.ts.map +1 -1
- package/dist/adapters/node/index.js +1 -0
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/adapters/node/list-tree.io.d.ts +3 -0
- package/dist/adapters/node/list-tree.io.d.ts.map +1 -0
- package/dist/adapters/node/list-tree.io.js +23 -0
- package/dist/adapters/node/list-tree.io.js.map +1 -0
- package/dist/adapters/study-registry/index.d.ts +2 -2
- package/dist/artifact-rules.d.ts +26 -0
- package/dist/artifact-rules.d.ts.map +1 -0
- package/dist/artifact-rules.js +117 -0
- package/dist/artifact-rules.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +7 -1
- package/dist/cli.js.map +1 -1
- package/dist/domain/artifact.d.ts +36 -0
- package/dist/domain/artifact.d.ts.map +1 -0
- package/dist/domain/artifact.js +116 -0
- package/dist/domain/artifact.js.map +1 -0
- package/dist/lib/paper-config.d.ts.map +1 -1
- package/dist/lib/paper-config.js +2 -0
- package/dist/lib/paper-config.js.map +1 -1
- package/dist/paper-settings.d.ts +3 -0
- package/dist/paper-settings.d.ts.map +1 -1
- package/dist/paper-settings.js +19 -16
- package/dist/paper-settings.js.map +1 -1
- package/dist/ports/list-tree.d.ts +11 -0
- package/dist/ports/list-tree.d.ts.map +1 -0
- package/dist/ports/list-tree.js +2 -0
- package/dist/ports/list-tree.js.map +1 -0
- package/docs/configuration.md +2 -1
- package/docs/rules/artifact/promised.md +64 -0
- package/docs/rules/artifact/required-files.md +65 -0
- package/docs/rules.md +2 -0
- package/lib/paper-config.ts +3 -0
- package/package.json +1 -1
- package/presets/agent-2027.jsonc +33 -0
- package/src/adapters/memory/index.test.ts +9 -0
- package/src/adapters/memory/index.ts +15 -0
- package/src/adapters/node/index.ts +1 -0
- package/src/adapters/node/list-tree.io.ts +27 -0
- package/src/adapters/node/list-tree.test.ts +38 -0
- package/src/artifact-rules.test.ts +50 -0
- package/src/artifact-rules.ts +188 -0
- package/src/cli.ts +7 -0
- package/src/domain/artifact.test.ts +154 -0
- package/src/domain/artifact.ts +171 -0
- package/src/new-paper.test.ts +1 -1
- package/src/paper-settings.test.ts +19 -0
- package/src/paper-settings.ts +21 -16
- package/src/ports/list-tree.ts +11 -0
- package/src/presets.test.ts +23 -0
- package/src/rule-cases.test.ts +134 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE ARTIFACT RULES — the artifact holds what the paper's own `paperlint.json` says it must
|
|
3
|
+
* (`src/domain/artifact.ts`): `artifact/required-files` (each `artifact.required` name at its top
|
|
4
|
+
* level) and `artifact/promised` (each `artifact.promises` glob matches a path). The paths are every
|
|
5
|
+
* file under `artifact.dir` (the `ListTree` port) or the lines of the committed list `artifact.files`.
|
|
6
|
+
*
|
|
7
|
+
* On by default and silent for a paper that declares nothing they read, as the talk rules are for a
|
|
8
|
+
* paper without `talk`; silent on a `paperlint.json` that does not parse (`pdf/profile` says why). A
|
|
9
|
+
* missing folder, or a list missing or empty: each rule says so, naming what it could not check.
|
|
10
|
+
*/
|
|
11
|
+
import { basename, dirname, resolve } from "node:path";
|
|
12
|
+
import { callerPath } from "./caller-path.ts";
|
|
13
|
+
import {
|
|
14
|
+
brokenPromises,
|
|
15
|
+
listedPaths,
|
|
16
|
+
missingRequired,
|
|
17
|
+
type PaperArtifact,
|
|
18
|
+
} from "./domain/artifact.ts";
|
|
19
|
+
import type { Files } from "./ports/files.ts";
|
|
20
|
+
import type { ListTree } from "./ports/list-tree.ts";
|
|
21
|
+
import type {
|
|
22
|
+
FolderRuleContext,
|
|
23
|
+
FolderRuleModule,
|
|
24
|
+
} from "./folder-venue-rule.ts";
|
|
25
|
+
import { readPaperSettings } from "./paper-settings.ts";
|
|
26
|
+
import { rulePageUrl, type Finding } from "./venue-rules.ts";
|
|
27
|
+
|
|
28
|
+
/** The file the rules report on: one per paper folder, whatever the paper's source format. */
|
|
29
|
+
const STATUS_FILE = "PIPELINE-STATUS.md";
|
|
30
|
+
|
|
31
|
+
export interface ArtifactRuleDeps {
|
|
32
|
+
readonly files: Files;
|
|
33
|
+
readonly listTree: ListTree;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ArtifactRuleName = "required-files" | "promised";
|
|
37
|
+
|
|
38
|
+
/** A rule of this file: a folder rule that reports a problem, not a suggestion. */
|
|
39
|
+
interface ArtifactRuleModule {
|
|
40
|
+
readonly meta: Omit<FolderRuleModule["meta"], "type"> & {
|
|
41
|
+
readonly type: "problem";
|
|
42
|
+
};
|
|
43
|
+
create(context: FolderRuleContext): { root?: () => void };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The artifact's paths, relative to its root, or why there are none to judge. */
|
|
47
|
+
type Listing =
|
|
48
|
+
| { readonly kind: "paths"; readonly paths: readonly string[] }
|
|
49
|
+
| { readonly kind: "noDir" | "noList" | "emptyList"; readonly path: string };
|
|
50
|
+
|
|
51
|
+
/** The paths of the artifact `a` declares, read through `deps`; `paperDir` is what its paths are relative to. */
|
|
52
|
+
function listing(
|
|
53
|
+
paperDir: string,
|
|
54
|
+
a: PaperArtifact,
|
|
55
|
+
deps: ArtifactRuleDeps,
|
|
56
|
+
): Listing {
|
|
57
|
+
const at = callerPath(resolve(paperDir, a.source.path));
|
|
58
|
+
const { path } = a.source;
|
|
59
|
+
if (a.source.kind === "dir") {
|
|
60
|
+
const paths = deps.listTree(at);
|
|
61
|
+
return paths === null ? { kind: "noDir", path } : { kind: "paths", paths };
|
|
62
|
+
}
|
|
63
|
+
const bytes = deps.files.readBytes(at);
|
|
64
|
+
if (bytes === null) return { kind: "noList", path };
|
|
65
|
+
const paths = listedPaths(new TextDecoder().decode(bytes));
|
|
66
|
+
return paths.length === 0
|
|
67
|
+
? { kind: "emptyList", path }
|
|
68
|
+
: { kind: "paths", paths };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The three messages about where the paths come from, naming what `what` could not be checked. */
|
|
72
|
+
const sourceMessages = (what: string): Readonly<Record<string, string>> => ({
|
|
73
|
+
noDir: `the artifact folder {{path}} ("artifact.dir" in paperlint.json, relative to the paper) does not exist or is not a folder, so ${what} cannot be checked`,
|
|
74
|
+
noList: `the artifact's list of paths {{path}} ("artifact.files" in paperlint.json, relative to the paper) does not exist, so ${what} cannot be checked`,
|
|
75
|
+
emptyList: `the artifact's list of paths {{path}} names no file, so ${what} cannot be checked — write one path per line, relative to the artifact's root, as \`zipinfo -1\` or \`find . -type f\` print them`,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/** Each rule: its page's line, its messages, whether the paper declared what it reads, and its judgement over the paths. */
|
|
79
|
+
const RULES: Readonly<
|
|
80
|
+
Record<
|
|
81
|
+
ArtifactRuleName,
|
|
82
|
+
{
|
|
83
|
+
readonly description: string;
|
|
84
|
+
readonly messages: Readonly<Record<string, string>>;
|
|
85
|
+
readonly declared: (a: PaperArtifact) => boolean;
|
|
86
|
+
readonly judge: (
|
|
87
|
+
a: PaperArtifact,
|
|
88
|
+
paths: readonly string[],
|
|
89
|
+
) => readonly Finding[];
|
|
90
|
+
}
|
|
91
|
+
>
|
|
92
|
+
> = {
|
|
93
|
+
"required-files": {
|
|
94
|
+
description:
|
|
95
|
+
"each name the paper's artifact.required lists is at the top level of the artifact, with any extension",
|
|
96
|
+
messages: {
|
|
97
|
+
...sourceMessages("its required names"),
|
|
98
|
+
missing:
|
|
99
|
+
'the artifact ({{where}}) has no top-level {{name}} — any extension counts ({{name}}.md, {{name}}.txt, {{name}}); "artifact.required" in paperlint.json asks for one',
|
|
100
|
+
},
|
|
101
|
+
declared: (a) => a.required.length > 0,
|
|
102
|
+
judge: (a, paths) =>
|
|
103
|
+
missingRequired(a.required, paths).map((name) => ({
|
|
104
|
+
messageId: "missing",
|
|
105
|
+
data: { name, where: a.source.path },
|
|
106
|
+
})),
|
|
107
|
+
},
|
|
108
|
+
promised: {
|
|
109
|
+
description:
|
|
110
|
+
"each glob the paper's artifact.promises lists matches a path of the artifact",
|
|
111
|
+
messages: {
|
|
112
|
+
...sourceMessages("its promises"),
|
|
113
|
+
broken:
|
|
114
|
+
'the artifact promise "{{label}}" ({{glob}}) matches no path of the artifact ({{where}}): the paper says the artifact holds it — add the files, or correct the glob in "artifact.promises"',
|
|
115
|
+
},
|
|
116
|
+
declared: (a) => Object.keys(a.promises).length > 0,
|
|
117
|
+
judge: (a, paths) =>
|
|
118
|
+
brokenPromises(a.promises, paths).map(([label, glob]) => ({
|
|
119
|
+
messageId: "broken",
|
|
120
|
+
data: { label, glob, where: a.source.path },
|
|
121
|
+
})),
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/** The findings of rule `name` for the paper folder `dir`. Reads through `deps`; never throws. */
|
|
126
|
+
export function artifactFindings(
|
|
127
|
+
name: ArtifactRuleName,
|
|
128
|
+
dir: string,
|
|
129
|
+
deps: ArtifactRuleDeps,
|
|
130
|
+
): readonly Finding[] {
|
|
131
|
+
const settings = readPaperSettings(deps.files, dir);
|
|
132
|
+
const a = settings.ok ? (settings.value?.artifact ?? null) : null;
|
|
133
|
+
const { declared, judge } = RULES[name];
|
|
134
|
+
if (a === null || !declared(a)) return [];
|
|
135
|
+
const l = listing(dir, a, deps);
|
|
136
|
+
return l.kind === "paths"
|
|
137
|
+
? judge(a, l.paths)
|
|
138
|
+
: [{ messageId: l.kind, data: { path: l.path } }];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function rule(
|
|
142
|
+
name: ArtifactRuleName,
|
|
143
|
+
deps: ArtifactRuleDeps,
|
|
144
|
+
): ArtifactRuleModule {
|
|
145
|
+
const meta = RULES[name];
|
|
146
|
+
return {
|
|
147
|
+
meta: {
|
|
148
|
+
type: "problem",
|
|
149
|
+
docs: {
|
|
150
|
+
description: meta.description,
|
|
151
|
+
url: rulePageUrl(`artifact/${name}`),
|
|
152
|
+
},
|
|
153
|
+
schema: [],
|
|
154
|
+
messages: meta.messages,
|
|
155
|
+
},
|
|
156
|
+
create(context) {
|
|
157
|
+
if (basename(context.filename) !== STATUS_FILE) return {};
|
|
158
|
+
return {
|
|
159
|
+
root() {
|
|
160
|
+
const at = context.sourceCode.getLocFromIndex(0);
|
|
161
|
+
artifactFindings(name, dirname(context.filename), deps).forEach(
|
|
162
|
+
(f) => {
|
|
163
|
+
context.report({ loc: { start: at, end: at }, ...f });
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The artifact rules, as the rules of the `artifact` plugin. */
|
|
173
|
+
export function artifactRules(
|
|
174
|
+
deps: ArtifactRuleDeps,
|
|
175
|
+
): Readonly<Record<ArtifactRuleName, ArtifactRuleModule>> {
|
|
176
|
+
return {
|
|
177
|
+
"required-files": rule("required-files", deps),
|
|
178
|
+
promised: rule("promised", deps),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** The level each artifact rule is on at, for every paper's `PIPELINE-STATUS.md`. Silent for a paper without `artifact`. */
|
|
183
|
+
export const ARTIFACT_RULE_LEVELS: Readonly<
|
|
184
|
+
Record<`artifact/${ArtifactRuleName}`, "error">
|
|
185
|
+
> = {
|
|
186
|
+
"artifact/required-files": "error",
|
|
187
|
+
"artifact/promised": "error",
|
|
188
|
+
};
|
package/src/cli.ts
CHANGED
|
@@ -63,6 +63,7 @@ import {
|
|
|
63
63
|
nodeAdapters,
|
|
64
64
|
nodeFiles,
|
|
65
65
|
nodeListDir,
|
|
66
|
+
nodeListTree,
|
|
66
67
|
nodeCopyFile,
|
|
67
68
|
nodeMoveFile,
|
|
68
69
|
} from "./adapters/node/index.ts";
|
|
@@ -187,6 +188,7 @@ import paperStages from "#eslint-rules/paper-stages";
|
|
|
187
188
|
import preregCoverage from "#eslint-rules/prereg-coverage";
|
|
188
189
|
import { CYCLE_RULE_LEVELS, cycleRules } from "./cycle-rules.ts";
|
|
189
190
|
import { EDITION_RULE_LEVELS, editionRules } from "./edition-rule.ts";
|
|
191
|
+
import { ARTIFACT_RULE_LEVELS, artifactRules } from "./artifact-rules.ts";
|
|
190
192
|
import { changesRules } from "./changes-rule.ts";
|
|
191
193
|
import { latexDiff, withTexBin } from "./adapters/latexdiff/index.ts";
|
|
192
194
|
import { runVersions } from "./versions-command.ts";
|
|
@@ -630,6 +632,10 @@ export function buildConfig(
|
|
|
630
632
|
},
|
|
631
633
|
},
|
|
632
634
|
repro: { rules: REPRO_RULES },
|
|
635
|
+
// On for every paper, silent for one whose paperlint.json declares no `artifact`.
|
|
636
|
+
artifact: {
|
|
637
|
+
rules: artifactRules({ files: nodeFiles, listTree: nodeListTree }),
|
|
638
|
+
},
|
|
633
639
|
// Registered, on for no paper: `"study/declare-sample": "error"` in paperlint.json turns it on.
|
|
634
640
|
study: { rules: preregCoverage.rules },
|
|
635
641
|
cycle: { rules: CYCLE_STATUS_RULES },
|
|
@@ -641,6 +647,7 @@ export function buildConfig(
|
|
|
641
647
|
"paper/source": "error",
|
|
642
648
|
...FOLDER_VENUE_RULE_LEVELS,
|
|
643
649
|
...EDITION_RULE_LEVELS,
|
|
650
|
+
...ARTIFACT_RULE_LEVELS,
|
|
644
651
|
...FOLDER_LAYOUT_RULE_LEVELS,
|
|
645
652
|
...REPRO_RULE_LEVELS,
|
|
646
653
|
...STATUS_CYCLE_RULE_LEVELS,
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/** A paper's `artifact` key, parsed, and the two judgements over the artifact's paths. */
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
answers,
|
|
5
|
+
brokenPromises,
|
|
6
|
+
listedPaths,
|
|
7
|
+
missingRequired,
|
|
8
|
+
parsePaperArtifact,
|
|
9
|
+
} from "./artifact.ts";
|
|
10
|
+
|
|
11
|
+
/** A bad shape, and the one line that refuses it. */
|
|
12
|
+
const REFUSED: readonly (readonly [string, unknown, string])[] = [
|
|
13
|
+
[
|
|
14
|
+
"not an object",
|
|
15
|
+
"artifact",
|
|
16
|
+
`"artifact" must be an object with a "dir" or a "files"`,
|
|
17
|
+
],
|
|
18
|
+
[
|
|
19
|
+
"an unknown key",
|
|
20
|
+
{ dir: "a", include: ["x"] },
|
|
21
|
+
`"artifact" has an unknown key "include" — known: dir, files, required, promises`,
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"neither dir nor files",
|
|
25
|
+
{ promises: {} },
|
|
26
|
+
`"artifact" needs exactly one of "dir" (the artifact's folder) or "files" (a committed list of its paths), got neither`,
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
"both dir and files",
|
|
30
|
+
{ dir: "a", files: "a.txt" },
|
|
31
|
+
`"artifact" needs exactly one of "dir" (the artifact's folder) or "files" (a committed list of its paths), got both`,
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
"an absolute dir",
|
|
35
|
+
{ dir: "/srv/artifact" },
|
|
36
|
+
`"artifact.dir" must be a path relative to the paper, got "/srv/artifact"`,
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
"a required name with a folder",
|
|
40
|
+
{ dir: "a", required: ["docs/README"] },
|
|
41
|
+
`"artifact.required" must be a list of top-level names without an extension ("README", "LICENSE"), got ["docs/README"]`,
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
"promises as a list",
|
|
45
|
+
{ dir: "a", promises: ["**/*.md"] },
|
|
46
|
+
`"artifact.promises" must be an object of label → glob`,
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
"an empty glob",
|
|
50
|
+
{ dir: "a", promises: { prompts: "" } },
|
|
51
|
+
`"artifact.promises" entry "prompts" must be a non-empty glob relative to the artifact's root, got ""`,
|
|
52
|
+
],
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
describe("parsePaperArtifact", () => {
|
|
56
|
+
it("is null when the paper declares no artifact", () => {
|
|
57
|
+
expect(parsePaperArtifact(undefined)).toEqual({ ok: true, value: null });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("takes a folder, the required names and the promises", () => {
|
|
61
|
+
expect(
|
|
62
|
+
parsePaperArtifact({
|
|
63
|
+
dir: "../artifact",
|
|
64
|
+
required: ["README", "LICENSE"],
|
|
65
|
+
promises: { prompts: "**/prompts/*.md" },
|
|
66
|
+
}),
|
|
67
|
+
).toEqual({
|
|
68
|
+
ok: true,
|
|
69
|
+
value: {
|
|
70
|
+
source: { kind: "dir", path: "../artifact" },
|
|
71
|
+
required: ["README", "LICENSE"],
|
|
72
|
+
promises: { prompts: "**/prompts/*.md" },
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("takes a committed list instead of a folder; required and promises are optional", () => {
|
|
78
|
+
expect(parsePaperArtifact({ files: "artifact-files.txt" })).toEqual({
|
|
79
|
+
ok: true,
|
|
80
|
+
value: {
|
|
81
|
+
source: { kind: "files", path: "artifact-files.txt" },
|
|
82
|
+
required: [],
|
|
83
|
+
promises: {},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it.each(REFUSED)("refuses %s", (_, v, why) => {
|
|
89
|
+
// Guards: each bad shape is refused with the one line naming the key and what it must be.
|
|
90
|
+
expect(parsePaperArtifact(v)).toEqual({ ok: false, error: why });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("answers — a top-level name answers a required name by its name before any extension, case ignored", () => {
|
|
95
|
+
it.each<[string, boolean]>([
|
|
96
|
+
["README.md", true],
|
|
97
|
+
["readme.txt", true],
|
|
98
|
+
["README", true],
|
|
99
|
+
["READMEFIRST.md", false],
|
|
100
|
+
])("%s → %s", (name, yes) => {
|
|
101
|
+
expect(answers(name, "README")).toBe(yes);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("brokenPromises — a promise matching no path", () => {
|
|
106
|
+
it("names the label and the glob of each promise that matches nothing", () => {
|
|
107
|
+
expect(
|
|
108
|
+
brokenPromises({ prompts: "**/prompts/*.md", runs: "runs/*.jsonl" }, [
|
|
109
|
+
"prompts/a.md",
|
|
110
|
+
"README.md",
|
|
111
|
+
]),
|
|
112
|
+
).toEqual([["runs", "runs/*.jsonl"]]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("one wrapper folder around every path (GitHub's Download ZIP, Zenodo, OSF) is looked through", () => {
|
|
117
|
+
const REQ = ["README", "LICENSE"];
|
|
118
|
+
|
|
119
|
+
it("🔴 a wrapped artifact holding README and LICENSE: nothing missing", () => {
|
|
120
|
+
expect(
|
|
121
|
+
missingRequired(REQ, ["repo-main/README.md", "repo-main/LICENSE"]),
|
|
122
|
+
).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("a wrapped artifact without a README: README missing", () => {
|
|
126
|
+
expect(
|
|
127
|
+
missingRequired(REQ, ["repo-main/LICENSE", "repo-main/docs/README.md"]),
|
|
128
|
+
).toEqual(["README"]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("two top folders are not unwrapped", () => {
|
|
132
|
+
expect(missingRequired(REQ, ["a/README.md", "b/LICENSE"])).toEqual(REQ);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("a top-level file beside one folder is not unwrapped", () => {
|
|
136
|
+
expect(
|
|
137
|
+
missingRequired(REQ, ["notes.txt", "a/README.md", "a/LICENSE"]),
|
|
138
|
+
).toEqual(REQ);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("🔴 a promise's glob matches inside the wrapper", () => {
|
|
142
|
+
expect(
|
|
143
|
+
brokenPromises({ data: "data/*.csv" }, ["artifact/data/x.csv"]),
|
|
144
|
+
).toEqual([]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("listedPaths — a committed list as zipinfo -1 or find writes it", () => {
|
|
149
|
+
it("drops blank lines, folder entries and a leading ./", () => {
|
|
150
|
+
expect(
|
|
151
|
+
listedPaths(".\n./README.md\nprompts/\nprompts/a.md\r\n\n LICENSE \n"),
|
|
152
|
+
).toEqual(["README.md", "prompts/a.md", "LICENSE"]);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A paper's reproduction artifact, as the paper declares it in its `paperlint.json`:
|
|
3
|
+
*
|
|
4
|
+
* "artifact": {
|
|
5
|
+
* "dir": "<folder, relative to the paper>" ┐ exactly one: where the artifact is, or
|
|
6
|
+
* "files": "<text file, relative to the paper>", ┘ a committed list of its paths, one per line
|
|
7
|
+
* "required": ["README", "LICENSE"], names its top level must hold
|
|
8
|
+
* "promises": { "<label>": "<glob>" } what the paper says it holds
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* `files` is for a bundle that is not committed (a gitignored zip): its paths as `zipinfo -1` or
|
|
12
|
+
* `find` writes them, relative to the artifact's root. A required name is matched without its
|
|
13
|
+
* extension and case (`README` is answered by README.md, readme.txt, README), and a promise's glob
|
|
14
|
+
* by `path.matchesGlob`, the same way whichever form lists the paths; one folder wrapped around
|
|
15
|
+
* every path is looked through (`unwrapSingleRoot`). `artifact/required-files` and
|
|
16
|
+
* `artifact/promised` judge them. The keys #205 plans for assembling a bundle (`include`, `exclude`,
|
|
17
|
+
* `scrub`) are left free.
|
|
18
|
+
*/
|
|
19
|
+
import { isAbsolute, matchesGlob } from "node:path";
|
|
20
|
+
import { err, ok, type Result } from "./result.ts";
|
|
21
|
+
import { isRecord } from "./record.ts";
|
|
22
|
+
|
|
23
|
+
/** Where the artifact's paths come from: its folder, or a committed list of them. */
|
|
24
|
+
export interface ArtifactSource {
|
|
25
|
+
readonly kind: "dir" | "files";
|
|
26
|
+
readonly path: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What a paper says its artifact is. */
|
|
30
|
+
export interface PaperArtifact {
|
|
31
|
+
/** The folder or the list, its path relative to the paper folder. */
|
|
32
|
+
readonly source: ArtifactSource;
|
|
33
|
+
/** Names the artifact's top level must hold, each matched without its extension; empty when none. */
|
|
34
|
+
readonly required: readonly string[];
|
|
35
|
+
/** A label the author chose → a glob, relative to the artifact's root, that must match a path. */
|
|
36
|
+
readonly promises: Readonly<Record<string, string>>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const KEYS = ["dir", "files", "required", "promises"];
|
|
40
|
+
|
|
41
|
+
/** The text of a name before its first dot, case folded: what a required name is matched by. Pure. */
|
|
42
|
+
const stemOf = (name: string): string =>
|
|
43
|
+
name.split(".", 1).join("").toLowerCase();
|
|
44
|
+
|
|
45
|
+
/** Whether a top-level name answers the required name `want` (any extension, any case). Pure. */
|
|
46
|
+
export const answers = (name: string, want: string): boolean =>
|
|
47
|
+
stemOf(name) === want.toLowerCase();
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `paths` without the one folder every one of them sits in, when they all do and no file stands
|
|
51
|
+
* beside it (`repo-main/…` of GitHub's Download ZIP, Zenodo's and OSF's archives); else as they are.
|
|
52
|
+
* Pure.
|
|
53
|
+
*/
|
|
54
|
+
export const unwrapSingleRoot = (
|
|
55
|
+
paths: readonly string[],
|
|
56
|
+
): readonly string[] => {
|
|
57
|
+
const firsts = [...new Set(paths.map((p) => p.split("/", 1).join("")))];
|
|
58
|
+
// With exactly one first segment, joining the list gives it.
|
|
59
|
+
const root = firsts.join("");
|
|
60
|
+
const wrapped =
|
|
61
|
+
firsts.length === 1 && paths.every((p) => p.startsWith(`${root}/`));
|
|
62
|
+
return wrapped ? paths.map((p) => p.slice(root.length + 1)) : paths;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** The required names `paths` (relative to the artifact's root) do not hold at its top level. Pure. */
|
|
66
|
+
export const missingRequired = (
|
|
67
|
+
required: readonly string[],
|
|
68
|
+
paths: readonly string[],
|
|
69
|
+
): readonly string[] => {
|
|
70
|
+
const top = unwrapSingleRoot(paths).filter((p) => !p.includes("/"));
|
|
71
|
+
return required.filter((want) => !top.some((name) => answers(name, want)));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** The promises whose glob matches none of `paths`, as [label, glob]. Pure. */
|
|
75
|
+
export const brokenPromises = (
|
|
76
|
+
promises: Readonly<Record<string, string>>,
|
|
77
|
+
paths: readonly string[],
|
|
78
|
+
): readonly (readonly [string, string])[] => {
|
|
79
|
+
const under = unwrapSingleRoot(paths);
|
|
80
|
+
return Object.entries(promises).filter(
|
|
81
|
+
([, glob]) => !under.some((p) => matchesGlob(p, glob)),
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A committed list of paths → the files it names, relative to the artifact's root: one per line,
|
|
87
|
+
* blank lines and folder entries (`dir/`, as `zipinfo -1` writes them) dropped, a leading `./` (as
|
|
88
|
+
* `find .` writes it) removed. Pure.
|
|
89
|
+
*/
|
|
90
|
+
export const listedPaths = (text: string): readonly string[] =>
|
|
91
|
+
text
|
|
92
|
+
.split(/\r?\n/u)
|
|
93
|
+
.map((l) => l.trim().replace(/^(?:\.\/)+/u, ""))
|
|
94
|
+
.filter((l) => l !== "" && l !== "." && !l.endsWith("/"));
|
|
95
|
+
|
|
96
|
+
/** A path relative to the paper: a non-empty string, not absolute. */
|
|
97
|
+
const relativePath = (v: unknown): v is string =>
|
|
98
|
+
typeof v === "string" && v !== "" && !isAbsolute(v);
|
|
99
|
+
|
|
100
|
+
/** `dir` or `files`, exactly one, each relative to the paper. Pure. */
|
|
101
|
+
function sourceOf(
|
|
102
|
+
v: Readonly<Record<string, unknown>>,
|
|
103
|
+
): Result<ArtifactSource, string> {
|
|
104
|
+
const given = (["dir", "files"] as const).filter((k) => k in v);
|
|
105
|
+
const [kind] = given;
|
|
106
|
+
if (given.length !== 1 || kind === undefined)
|
|
107
|
+
return err(
|
|
108
|
+
`"artifact" needs exactly one of "dir" (the artifact's folder) or "files" (a committed list of its paths), got ${given.length === 0 ? "neither" : "both"}`,
|
|
109
|
+
);
|
|
110
|
+
const path = v[kind];
|
|
111
|
+
return relativePath(path)
|
|
112
|
+
? ok({ kind, path })
|
|
113
|
+
: err(
|
|
114
|
+
`"artifact.${kind}" must be a path relative to the paper, got ${JSON.stringify(path)}`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** `required`: absent is none; otherwise names without a folder in them. Pure. */
|
|
119
|
+
function requiredOf(v: unknown): Result<readonly string[], string> {
|
|
120
|
+
if (v === undefined) return ok([]);
|
|
121
|
+
return Array.isArray(v) &&
|
|
122
|
+
v.every((x) => typeof x === "string" && /^[^/\\.\s]+$/u.test(x))
|
|
123
|
+
? ok(v.filter((x): x is string => typeof x === "string"))
|
|
124
|
+
: err(
|
|
125
|
+
`"artifact.required" must be a list of top-level names without an extension ("README", "LICENSE"), got ${JSON.stringify(v)}`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** `promises`: absent is none; otherwise each label and glob a non-empty string. Pure. */
|
|
130
|
+
function promisesOf(
|
|
131
|
+
v: unknown,
|
|
132
|
+
): Result<Readonly<Record<string, string>>, string> {
|
|
133
|
+
if (v === undefined) return ok({});
|
|
134
|
+
if (!isRecord(v))
|
|
135
|
+
return err(`"artifact.promises" must be an object of label → glob`);
|
|
136
|
+
const entries = Object.entries(v);
|
|
137
|
+
const bad = entries.find(
|
|
138
|
+
([label, glob]) => label === "" || typeof glob !== "string" || glob === "",
|
|
139
|
+
);
|
|
140
|
+
return bad === undefined
|
|
141
|
+
? ok(Object.fromEntries(entries.map(([l, g]) => [l, String(g)])))
|
|
142
|
+
: err(
|
|
143
|
+
`"artifact.promises" entry ${JSON.stringify(bad[0])} must be a non-empty glob relative to the artifact's root, got ${JSON.stringify(bad[1])}`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A paper's `artifact` → the value, null when absent, or one line saying what is wrong. Pure. */
|
|
148
|
+
export function parsePaperArtifact(
|
|
149
|
+
v: unknown,
|
|
150
|
+
): Result<PaperArtifact | null, string> {
|
|
151
|
+
if (v === undefined) return ok(null);
|
|
152
|
+
if (!isRecord(v))
|
|
153
|
+
return err(`"artifact" must be an object with a "dir" or a "files"`);
|
|
154
|
+
const unknown = Object.keys(v).find((k) => !KEYS.includes(k));
|
|
155
|
+
if (unknown !== undefined)
|
|
156
|
+
return err(
|
|
157
|
+
`"artifact" has an unknown key "${unknown}" — known: ${KEYS.join(", ")}`,
|
|
158
|
+
);
|
|
159
|
+
const source = sourceOf(v);
|
|
160
|
+
if (!source.ok) return source;
|
|
161
|
+
const required = requiredOf(v["required"]);
|
|
162
|
+
if (!required.ok) return required;
|
|
163
|
+
const promises = promisesOf(v["promises"]);
|
|
164
|
+
return promises.ok
|
|
165
|
+
? ok({
|
|
166
|
+
source: source.value,
|
|
167
|
+
required: required.value,
|
|
168
|
+
promises: promises.value,
|
|
169
|
+
})
|
|
170
|
+
: promises;
|
|
171
|
+
}
|
package/src/new-paper.test.ts
CHANGED
|
@@ -73,7 +73,6 @@ describe("paperlint new — paperlint.json", () => {
|
|
|
73
73
|
from: "package",
|
|
74
74
|
});
|
|
75
75
|
const s = settingsOf(join(papers, "demo"));
|
|
76
|
-
expect(s["extends"]).toBeNull();
|
|
77
76
|
expect(String(s["$comment"])).toMatch(/paperlint:agenticdev-2026/);
|
|
78
77
|
expect(parsePaperSettings(s)).toEqual({
|
|
79
78
|
ok: true,
|
|
@@ -88,6 +87,7 @@ describe("paperlint new — paperlint.json", () => {
|
|
|
88
87
|
authors: null,
|
|
89
88
|
fields: null,
|
|
90
89
|
cycles: null,
|
|
90
|
+
artifact: null,
|
|
91
91
|
},
|
|
92
92
|
});
|
|
93
93
|
});
|
|
@@ -36,6 +36,7 @@ describe("parsePaperSettings", () => {
|
|
|
36
36
|
authors: null,
|
|
37
37
|
fields: null,
|
|
38
38
|
cycles: null,
|
|
39
|
+
artifact: null,
|
|
39
40
|
},
|
|
40
41
|
});
|
|
41
42
|
expect(parsePaperSettings({})).toEqual({
|
|
@@ -51,6 +52,7 @@ describe("parsePaperSettings", () => {
|
|
|
51
52
|
authors: null,
|
|
52
53
|
fields: null,
|
|
53
54
|
cycles: null,
|
|
55
|
+
artifact: null,
|
|
54
56
|
},
|
|
55
57
|
});
|
|
56
58
|
});
|
|
@@ -69,6 +71,7 @@ describe("parsePaperSettings", () => {
|
|
|
69
71
|
authors: null,
|
|
70
72
|
fields: null,
|
|
71
73
|
cycles: null,
|
|
74
|
+
artifact: null,
|
|
72
75
|
},
|
|
73
76
|
});
|
|
74
77
|
});
|
|
@@ -191,6 +194,7 @@ const UNSET = {
|
|
|
191
194
|
authors: null,
|
|
192
195
|
fields: null,
|
|
193
196
|
cycles: null,
|
|
197
|
+
artifact: null,
|
|
194
198
|
};
|
|
195
199
|
|
|
196
200
|
describe("readPaperSettings — the root paperlint.json's defaults, the paper's file over them", () => {
|
|
@@ -252,6 +256,7 @@ describe("readPaperSettings — the root paperlint.json's defaults, the paper's
|
|
|
252
256
|
authors: null,
|
|
253
257
|
fields: null,
|
|
254
258
|
cycles: null,
|
|
259
|
+
artifact: null,
|
|
255
260
|
});
|
|
256
261
|
});
|
|
257
262
|
});
|
|
@@ -304,6 +309,7 @@ describe("paperRules — `rules` in paperlint.json", () => {
|
|
|
304
309
|
authors: null,
|
|
305
310
|
fields: null,
|
|
306
311
|
cycles: null,
|
|
312
|
+
artifact: null,
|
|
307
313
|
});
|
|
308
314
|
|
|
309
315
|
it("no rules: none", () => {
|
|
@@ -393,6 +399,19 @@ describe("talk in a paper's paperlint.json", () => {
|
|
|
393
399
|
});
|
|
394
400
|
});
|
|
395
401
|
|
|
402
|
+
it("🔴 artifact: parsed into the paper's settings, or refused naming the key", () => {
|
|
403
|
+
const r = parsePaperSettings({ artifact: { files: "a.txt" } });
|
|
404
|
+
expect(r.ok && r.value.artifact).toEqual({
|
|
405
|
+
source: { kind: "files", path: "a.txt" },
|
|
406
|
+
required: [],
|
|
407
|
+
promises: {},
|
|
408
|
+
});
|
|
409
|
+
expect(parsePaperSettings({ artifact: { dir: "/abs" } })).toEqual({
|
|
410
|
+
ok: false,
|
|
411
|
+
error: `"artifact.dir" must be a path relative to the paper, got "/abs"`,
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
396
415
|
describe("parsePaperSettings — `cycles`: the current attempt supplies extends, kind and submission", () => {
|
|
397
416
|
const closed = {
|
|
398
417
|
id: "alpha-2026",
|