paperlint 18.4.0 → 18.5.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/CLAUDE.md +5 -1
- package/dist/adapters/latex/abstract.d.ts +11 -0
- package/dist/adapters/latex/abstract.d.ts.map +1 -1
- package/dist/adapters/latex/abstract.js +1 -1
- package/dist/adapters/latex/abstract.js.map +1 -1
- package/dist/adapters/latex/index.d.ts.map +1 -1
- package/dist/adapters/latex/index.js +3 -0
- package/dist/adapters/latex/index.js.map +1 -1
- package/dist/adapters/latex/macros.d.ts +6 -0
- package/dist/adapters/latex/macros.d.ts.map +1 -0
- package/dist/adapters/latex/macros.js +27 -0
- package/dist/adapters/latex/macros.js.map +1 -0
- package/dist/adapters/osf/host.io.d.ts +12 -0
- package/dist/adapters/osf/host.io.d.ts.map +1 -0
- package/dist/adapters/osf/host.io.js +119 -0
- package/dist/adapters/osf/host.io.js.map +1 -0
- package/dist/adapters/osf/index.d.ts +10 -0
- package/dist/adapters/osf/index.d.ts.map +1 -0
- package/dist/adapters/osf/index.js +10 -0
- package/dist/adapters/osf/index.js.map +1 -0
- package/dist/adapters/osf/response.d.ts +11 -0
- package/dist/adapters/osf/response.d.ts.map +1 -0
- package/dist/adapters/osf/response.js +87 -0
- package/dist/adapters/osf/response.js.map +1 -0
- package/dist/artifact-upload-rule.d.ts +66 -0
- package/dist/artifact-upload-rule.d.ts.map +1 -0
- package/dist/artifact-upload-rule.js +151 -0
- package/dist/artifact-upload-rule.js.map +1 -0
- package/dist/artifact.d.ts +35 -0
- package/dist/artifact.d.ts.map +1 -0
- package/dist/artifact.js +251 -0
- package/dist/artifact.js.map +1 -0
- package/dist/cli.d.ts +9 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +136 -23
- package/dist/cli.js.map +1 -1
- package/dist/domain/artifact-upload.d.ts +44 -0
- package/dist/domain/artifact-upload.d.ts.map +1 -0
- package/dist/domain/artifact-upload.js +80 -0
- package/dist/domain/artifact-upload.js.map +1 -0
- package/dist/domain/paper-dirs.d.ts +16 -0
- package/dist/domain/paper-dirs.d.ts.map +1 -0
- package/dist/domain/paper-dirs.js +42 -0
- package/dist/domain/paper-dirs.js.map +1 -0
- package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
- package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
- package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
- package/dist/paper-files.d.ts +25 -42
- package/dist/paper-files.d.ts.map +1 -1
- package/dist/paper-files.js +101 -9
- package/dist/paper-files.js.map +1 -1
- package/dist/ports/artifact-host.d.ts +54 -0
- package/dist/ports/artifact-host.d.ts.map +1 -0
- package/dist/ports/artifact-host.js +2 -0
- package/dist/ports/artifact-host.js.map +1 -0
- package/dist/ports/latex.d.ts +9 -0
- package/dist/ports/latex.d.ts.map +1 -1
- package/dist/submission-confirm-hook.d.ts +11 -1
- package/dist/submission-confirm-hook.d.ts.map +1 -1
- package/dist/submission-confirm-hook.js +83 -21
- package/dist/submission-confirm-hook.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/artifact-upload.md +124 -0
- package/docs/optional-rules.md +1 -0
- package/docs/osf-artifact.md +4 -1
- package/docs/rules/artifact/upload-current.md +85 -0
- package/docs/rules.md +1 -0
- package/eslint-rules/CLAUDE.md +5 -1
- package/eslint-rules/CLAUDE.md.spec.ts +3 -0
- package/package.json +1 -1
- package/src/adapters/latex/abstract.ts +3 -1
- package/src/adapters/latex/index.ts +3 -0
- package/src/adapters/latex/macros.test.ts +31 -0
- package/src/adapters/latex/macros.ts +43 -0
- package/src/adapters/osf/cassette/README.md +20 -0
- package/src/adapters/osf/cassette/get-file.json +108 -0
- package/src/adapters/osf/cassette/get-listing.json +111 -0
- package/src/adapters/osf/cassette/get-missing.json +1 -0
- package/src/adapters/osf/cassette/put-new.json +31 -0
- package/src/adapters/osf/host.io.ts +156 -0
- package/src/adapters/osf/host.test.ts +274 -0
- package/src/adapters/osf/index.ts +14 -0
- package/src/adapters/osf/response.ts +105 -0
- package/src/artifact-upload-rule.test.ts +213 -0
- package/src/artifact-upload-rule.ts +213 -0
- package/src/artifact.test.ts +504 -0
- package/src/artifact.ts +402 -0
- package/src/cli.test.ts +271 -1
- package/src/cli.ts +168 -23
- package/src/domain/artifact-upload.test.ts +80 -0
- package/src/domain/artifact-upload.ts +111 -0
- package/src/domain/paper-dirs.test.ts +91 -0
- package/src/domain/paper-dirs.ts +62 -0
- package/src/new-paper.test.ts +8 -2
- package/src/paper-files.test.ts +88 -0
- package/src/paper-files.ts +98 -9
- package/src/paper-settings-commands.test.ts +18 -0
- package/src/ports/artifact-host.ts +65 -0
- package/src/ports/latex.ts +10 -0
- package/src/rule-cases.test.ts +44 -0
- package/src/submission-confirm-hook.test.ts +113 -1
- package/src/submission-confirm-hook.ts +120 -27
- package/src/types.ts +6 -0
package/src/cli.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* replaced it: silently breaking someone else's workflow is worse than asking them to fix a line.
|
|
25
25
|
*/
|
|
26
26
|
import { ESLint, type Linter } from "eslint";
|
|
27
|
-
import { readFileSync, existsSync, statSync } from "node:fs";
|
|
27
|
+
import { readFileSync, readdirSync, existsSync, statSync } from "node:fs";
|
|
28
28
|
import { createRequire } from "node:module";
|
|
29
29
|
import { stripVTControlCharacters } from "node:util";
|
|
30
30
|
import { spawnSync } from "node:child_process";
|
|
@@ -119,11 +119,15 @@ import type { PortalKind, SupportedPortal } from "./domain/submission.ts";
|
|
|
119
119
|
import type { PortalSite } from "./ports/submission-portal.ts";
|
|
120
120
|
import type { CheckReferences } from "./ports/check-references.ts";
|
|
121
121
|
import {
|
|
122
|
+
ANY_PAPER,
|
|
122
123
|
narrowToOwners,
|
|
123
124
|
ownedPatterns,
|
|
125
|
+
paperFiles,
|
|
126
|
+
papersScope,
|
|
124
127
|
ruleOwners,
|
|
125
128
|
scopeToOwned,
|
|
126
129
|
} from "./paper-files.ts";
|
|
130
|
+
import type { PaperScope } from "./paper-files.ts";
|
|
127
131
|
import {
|
|
128
132
|
paperPreset,
|
|
129
133
|
settingsProblemLine,
|
|
@@ -189,6 +193,10 @@ import preregCoverage from "#eslint-rules/prereg-coverage";
|
|
|
189
193
|
import { CYCLE_RULE_LEVELS, cycleRules } from "./cycle-rules.ts";
|
|
190
194
|
import { EDITION_RULE_LEVELS, editionRules } from "./edition-rule.ts";
|
|
191
195
|
import { ARTIFACT_RULE_LEVELS, artifactRules } from "./artifact-rules.ts";
|
|
196
|
+
import { artifactUploadRules } from "./artifact-upload-rule.ts";
|
|
197
|
+
import { runArtifact } from "./artifact.ts";
|
|
198
|
+
import { osfHost } from "./adapters/osf/index.ts";
|
|
199
|
+
import type { ArtifactHost } from "./ports/artifact-host.ts";
|
|
192
200
|
import { changesRules } from "./changes-rule.ts";
|
|
193
201
|
import { latexDiff, withTexBin } from "./adapters/latexdiff/index.ts";
|
|
194
202
|
import { runVersions } from "./versions-command.ts";
|
|
@@ -214,6 +222,7 @@ import {
|
|
|
214
222
|
} from "./folder-layout-rule.ts";
|
|
215
223
|
import { folderLayoutHook } from "./folder-layout-hook.ts";
|
|
216
224
|
import { paperFolderOf, writtenPath } from "./domain/paper-folder.ts";
|
|
225
|
+
import { papersReached, type PaperTree } from "./domain/paper-dirs.ts";
|
|
217
226
|
import {
|
|
218
227
|
NOTICE_HOOKS,
|
|
219
228
|
collector,
|
|
@@ -233,6 +242,7 @@ import {
|
|
|
233
242
|
import {
|
|
234
243
|
submissionConfirm,
|
|
235
244
|
UNREADABLE_INPUT,
|
|
245
|
+
type Upload,
|
|
236
246
|
} from "./submission-confirm-hook.ts";
|
|
237
247
|
import { leafCommandsNormalized } from "vigiles/hook";
|
|
238
248
|
import {
|
|
@@ -308,6 +318,15 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
|
|
|
308
318
|
npx paperlint submission topics [paper]
|
|
309
319
|
the topics the venue's portal offers, against the ones its
|
|
310
320
|
preset records; exit 1 when they differ
|
|
321
|
+
npx paperlint artifact record <zip> --url <url> [--host <name>] [--numbers <file>] [paper]
|
|
322
|
+
write the upload record (submission/artifact-upload.json): the
|
|
323
|
+
zip's sha256 and md5, and the numbers the paper prints now. Any
|
|
324
|
+
host, no network; artifact/upload-current reads it
|
|
325
|
+
npx paperlint artifact upload --to osf <zip> [--node <id>] [paper] [--save]
|
|
326
|
+
upload the zip and write the same record with the host's own
|
|
327
|
+
hashes. A DRY RUN unless --save. Token: OSF_TOKEN_OSF_IO
|
|
328
|
+
npx paperlint artifact show [paper] the record, and match yes/no against the hashes the host holds
|
|
329
|
+
now, where its adapter reads them (osf)
|
|
311
330
|
npx paperlint versions [show|lock|migrate|approve|diff] [paper]
|
|
312
331
|
the paper's frozen versions, one folder per attempt:
|
|
313
332
|
versions/<cycle>/<stage>.{pdf,tex}. show (the default): each
|
|
@@ -561,6 +580,22 @@ const today = (now = new Date()): string =>
|
|
|
561
580
|
String(now.getDate()).padStart(2, "0"),
|
|
562
581
|
].join("-");
|
|
563
582
|
|
|
583
|
+
/** What `artifact/upload-current` and `paperlint artifact record` read with. */
|
|
584
|
+
const UPLOAD_RULE_DEPS = {
|
|
585
|
+
files: nodeFiles,
|
|
586
|
+
codec: sourcesCodec,
|
|
587
|
+
latex: latexReader,
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* The `artifact` plugin: required-files and promised on for every paper, silent for one whose
|
|
592
|
+
* paperlint.json declares no `artifact`; upload-current on for no paper until its options turn it on.
|
|
593
|
+
*/
|
|
594
|
+
const ARTIFACT_PLUGIN_RULES = {
|
|
595
|
+
...artifactRules({ files: nodeFiles, listTree: nodeListTree }),
|
|
596
|
+
...artifactUploadRules(UPLOAD_RULE_DEPS),
|
|
597
|
+
};
|
|
598
|
+
|
|
564
599
|
/** What the talk rules read with: the disk, the shipped presets, and the three media readers. */
|
|
565
600
|
const TALK_RULE_DEPS = {
|
|
566
601
|
files: nodeFiles,
|
|
@@ -573,7 +608,11 @@ const TALK_RULE_DEPS = {
|
|
|
573
608
|
export function buildConfig(
|
|
574
609
|
opts: PaperlintConfig = {},
|
|
575
610
|
texLanguage: unknown,
|
|
611
|
+
// The papers whose own files the blocks claim (`PaperScope`): any folder for the config's shape,
|
|
612
|
+
// the real papers for `paperlint lint`, so a copy kept inside one is claimed by no block (#582).
|
|
613
|
+
papers: PaperScope = ANY_PAPER,
|
|
576
614
|
): ConfigBlock[] {
|
|
615
|
+
const own = (glob: string): readonly string[] => paperFiles(papers, glob);
|
|
577
616
|
const paperRules = { ...typography.rules };
|
|
578
617
|
// The reference rules judge `_build/references.json`, and only on `paper.tex`.
|
|
579
618
|
const texPaperRules = {
|
|
@@ -614,7 +653,7 @@ export function buildConfig(
|
|
|
614
653
|
},
|
|
615
654
|
},
|
|
616
655
|
{
|
|
617
|
-
files:
|
|
656
|
+
files: own("PIPELINE-STATUS.md"),
|
|
618
657
|
// Every paper folder has one: the rules about the folder itself (its stages, its frozen
|
|
619
658
|
// sources, its name) are judged here, once per paper.
|
|
620
659
|
plugins: {
|
|
@@ -632,10 +671,7 @@ export function buildConfig(
|
|
|
632
671
|
},
|
|
633
672
|
},
|
|
634
673
|
repro: { rules: REPRO_RULES },
|
|
635
|
-
|
|
636
|
-
artifact: {
|
|
637
|
-
rules: artifactRules({ files: nodeFiles, listTree: nodeListTree }),
|
|
638
|
-
},
|
|
674
|
+
artifact: { rules: ARTIFACT_PLUGIN_RULES },
|
|
639
675
|
// Registered, on for no paper: `"study/declare-sample": "error"` in paperlint.json turns it on.
|
|
640
676
|
study: { rules: preregCoverage.rules },
|
|
641
677
|
cycle: { rules: CYCLE_STATUS_RULES },
|
|
@@ -654,7 +690,7 @@ export function buildConfig(
|
|
|
654
690
|
},
|
|
655
691
|
},
|
|
656
692
|
{
|
|
657
|
-
files:
|
|
693
|
+
files: own("reviews/*.md"),
|
|
658
694
|
plugins: { markdown, review: reviewFrontmatter },
|
|
659
695
|
...md,
|
|
660
696
|
// A review's frontmatter is a record, validated by paperlint's JSON Schema
|
|
@@ -664,7 +700,7 @@ export function buildConfig(
|
|
|
664
700
|
{
|
|
665
701
|
// A sibling card says how much of the competing paper was read (`read:`). The cards are
|
|
666
702
|
// written by this package's analyze-sibling-paper skill; its README is an index, not a card.
|
|
667
|
-
files:
|
|
703
|
+
files: own("siblings/*.md"),
|
|
668
704
|
ignores: ["**/siblings/README.md"],
|
|
669
705
|
plugins: { markdown, sibling: siblingFrontmatter },
|
|
670
706
|
...md,
|
|
@@ -676,7 +712,7 @@ export function buildConfig(
|
|
|
676
712
|
// corpus without a single `.tex` would be refusing to work where work is possible.
|
|
677
713
|
if (texLanguage)
|
|
678
714
|
cfg.push({
|
|
679
|
-
files:
|
|
715
|
+
files: own("paper.tex"),
|
|
680
716
|
plugins: {
|
|
681
717
|
tex: {
|
|
682
718
|
languages: { latex: texLanguage },
|
|
@@ -760,9 +796,11 @@ export function buildConfig(
|
|
|
760
796
|
// PIPELINE-STATUS.md than beside paper.tex, and ESLint throws on a rule its plugin lacks.
|
|
761
797
|
cfg.push(
|
|
762
798
|
...fragments,
|
|
763
|
-
...(opts.rules ?? []).flatMap((b) => narrowToOwners(b, owners)),
|
|
799
|
+
...(opts.rules ?? []).flatMap((b) => narrowToOwners(b, owners, papers)),
|
|
764
800
|
);
|
|
765
|
-
|
|
801
|
+
// With no paper to claim, an own block's `files` is empty, and ESLint refuses an empty `files`: the
|
|
802
|
+
// block goes, and nothing is linted, which the run then says (#582).
|
|
803
|
+
return cfg.filter((b) => b.files === undefined || b.files.length > 0);
|
|
766
804
|
}
|
|
767
805
|
|
|
768
806
|
/**
|
|
@@ -928,16 +966,34 @@ export async function silentOptionalRules(
|
|
|
928
966
|
return [...turnedOn].filter((id) => !reached.has(id));
|
|
929
967
|
}
|
|
930
968
|
|
|
931
|
-
/**
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
969
|
+
/** The disk as the paper-reach rule sees it (`src/domain/paper-dirs.ts`). */
|
|
970
|
+
const PAPER_TREE: PaperTree = {
|
|
971
|
+
...nodeFiles,
|
|
972
|
+
subfolders: (dir) => {
|
|
973
|
+
try {
|
|
974
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
975
|
+
.filter(
|
|
976
|
+
(e) =>
|
|
977
|
+
e.isDirectory() &&
|
|
978
|
+
!e.name.startsWith(".") &&
|
|
979
|
+
e.name !== "node_modules" &&
|
|
980
|
+
e.name !== ESCAPE_HATCH,
|
|
981
|
+
)
|
|
982
|
+
.map((e) => join(dir, e.name));
|
|
983
|
+
} catch {
|
|
984
|
+
return [];
|
|
985
|
+
}
|
|
986
|
+
},
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
/** The papers `paths` reach: a file counts as the folder it sits in (#582). */
|
|
990
|
+
const paperDirs = (paths: readonly string[]): readonly string[] =>
|
|
991
|
+
papersReached(
|
|
992
|
+
paths.map((p) =>
|
|
993
|
+
resolve(existsSync(p) && statSync(p).isFile() ? dirname(p) : p),
|
|
994
|
+
),
|
|
995
|
+
PAPER_TREE,
|
|
938
996
|
);
|
|
939
|
-
return [...new Set(dirs.flatMap((p) => [p, ...papersIn(p)]))];
|
|
940
|
-
}
|
|
941
997
|
|
|
942
998
|
/**
|
|
943
999
|
* Every linted paper's rules, as ESLint blocks scoped to that paper, in two groups: what its venue
|
|
@@ -1135,6 +1191,11 @@ export function parseArgs(argv: readonly string[]): Args {
|
|
|
1135
1191
|
abstract: null,
|
|
1136
1192
|
submit: false,
|
|
1137
1193
|
save: false,
|
|
1194
|
+
url: null,
|
|
1195
|
+
host: null,
|
|
1196
|
+
to: null,
|
|
1197
|
+
node: null,
|
|
1198
|
+
numbers: null,
|
|
1138
1199
|
hooksMode: null,
|
|
1139
1200
|
// -1 = warnings NEVER fail the run. In this set most findings are advisory by design, and a
|
|
1140
1201
|
// gate that fails on advice gets muted entirely.
|
|
@@ -1227,13 +1288,27 @@ const SWITCHES: ReadonlyMap<
|
|
|
1227
1288
|
/** The flags whose value is one string field of `Args`. */
|
|
1228
1289
|
const STRING_FLAGS: ReadonlyMap<
|
|
1229
1290
|
string,
|
|
1230
|
-
|
|
1291
|
+
| "paper"
|
|
1292
|
+
| "venue"
|
|
1293
|
+
| "kind"
|
|
1294
|
+
| "pdf"
|
|
1295
|
+
| "abstract"
|
|
1296
|
+
| "url"
|
|
1297
|
+
| "host"
|
|
1298
|
+
| "to"
|
|
1299
|
+
| "node"
|
|
1300
|
+
| "numbers"
|
|
1231
1301
|
> = new Map([
|
|
1232
1302
|
["--paper", "paper"],
|
|
1233
1303
|
["--venue", "venue"],
|
|
1234
1304
|
["--kind", "kind"],
|
|
1235
1305
|
["--pdf", "pdf"],
|
|
1236
1306
|
["--abstract", "abstract"],
|
|
1307
|
+
["--url", "url"],
|
|
1308
|
+
["--host", "host"],
|
|
1309
|
+
["--to", "to"],
|
|
1310
|
+
["--node", "node"],
|
|
1311
|
+
["--numbers", "numbers"],
|
|
1237
1312
|
]);
|
|
1238
1313
|
|
|
1239
1314
|
/** The flags that take a value, in either spelling: `--flag value` or `--flag=value`. */
|
|
@@ -1374,6 +1449,7 @@ const IN_PROCESS_HOOKS: Readonly<
|
|
|
1374
1449
|
portalHosts,
|
|
1375
1450
|
shellLeaves: leafCommandsNormalized,
|
|
1376
1451
|
readSend: submissionSend,
|
|
1452
|
+
readUpload: uploadSend,
|
|
1377
1453
|
});
|
|
1378
1454
|
} catch {
|
|
1379
1455
|
return UNREADABLE_INPUT;
|
|
@@ -1401,6 +1477,24 @@ export function submissionSend(
|
|
|
1401
1477
|
return clean ? { paper: a.paths[1] ?? null, pdf: a.pdf } : null;
|
|
1402
1478
|
}
|
|
1403
1479
|
|
|
1480
|
+
/**
|
|
1481
|
+
* The words after `artifact`, read by this CLI's own parser, for an upload: the file it uploads, the
|
|
1482
|
+
* paper (null for the current folder), and the host and project it goes to — or null when they would
|
|
1483
|
+
* not run cleanly. `--save` uploads only to a project named on the command line (`artifact.ts`).
|
|
1484
|
+
*/
|
|
1485
|
+
export function uploadSend(words: readonly string[]): Upload | null {
|
|
1486
|
+
const a = parseArgs(["artifact", ...words]);
|
|
1487
|
+
const [sub, file, paper, ...rest] = a.paths;
|
|
1488
|
+
const clean =
|
|
1489
|
+
a.missingValue === undefined &&
|
|
1490
|
+
a.unknownFlag === undefined &&
|
|
1491
|
+
sub === "upload" &&
|
|
1492
|
+
rest.length === 0;
|
|
1493
|
+
return clean && file !== undefined && a.to !== null && a.node !== null
|
|
1494
|
+
? { paper: paper ?? null, artifact: file, host: a.to, project: a.node }
|
|
1495
|
+
: null;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1404
1498
|
/**
|
|
1405
1499
|
* `paperlint hook <name>` — run an editor hook. It exists for ONE thing: so that the wiring does not
|
|
1406
1500
|
* address the runtime from the project root.
|
|
@@ -2148,6 +2242,20 @@ const SIMPLE: Readonly<
|
|
|
2148
2242
|
log,
|
|
2149
2243
|
err,
|
|
2150
2244
|
}),
|
|
2245
|
+
artifact: (a, { log, err, cwd }) =>
|
|
2246
|
+
runArtifact(
|
|
2247
|
+
{ ...a, sub: a.paths[0], operands: a.paths.slice(1) },
|
|
2248
|
+
{
|
|
2249
|
+
...UPLOAD_RULE_DEPS,
|
|
2250
|
+
ruleEntry: uploadRuleEntry,
|
|
2251
|
+
hosts: ARTIFACT_HOSTS,
|
|
2252
|
+
env: (name) => process.env[name],
|
|
2253
|
+
now: isoNow,
|
|
2254
|
+
cwd,
|
|
2255
|
+
log,
|
|
2256
|
+
err,
|
|
2257
|
+
},
|
|
2258
|
+
),
|
|
2151
2259
|
submission: (a, { log, err, cwd }) =>
|
|
2152
2260
|
runSubmission(
|
|
2153
2261
|
{
|
|
@@ -2176,6 +2284,38 @@ const SIMPLE: Readonly<
|
|
|
2176
2284
|
),
|
|
2177
2285
|
};
|
|
2178
2286
|
|
|
2287
|
+
/**
|
|
2288
|
+
* `artifact/upload-current`'s entry for the paper in `dir`, as ESLint computes it for the paper's
|
|
2289
|
+
* `PIPELINE-STATUS.md`, where the rule runs, under the config `paperlint lint` run there would use: one answer for the rule and the commands,
|
|
2290
|
+
* whichever shape the settings take (a `rules` object, a list of blocks, the project's or the
|
|
2291
|
+
* paper's). Undefined when the rule is not on there or the config does not read; lint says why.
|
|
2292
|
+
*/
|
|
2293
|
+
async function uploadRuleEntry(dir: string): Promise<unknown> {
|
|
2294
|
+
// Quiet: a config that does not read is lint's to report, not this command's.
|
|
2295
|
+
const quiet = (): void => {};
|
|
2296
|
+
const cfg = readConfig(parseArgs(["lint"]), {
|
|
2297
|
+
log: quiet,
|
|
2298
|
+
err: quiet,
|
|
2299
|
+
cwd: dir,
|
|
2300
|
+
});
|
|
2301
|
+
if (cfg.code !== undefined) return undefined;
|
|
2302
|
+
const engine = await paperEslint(cfg, [dir], {
|
|
2303
|
+
loadTexLanguage: loadLatexLanguage,
|
|
2304
|
+
fix: false,
|
|
2305
|
+
stats: false,
|
|
2306
|
+
});
|
|
2307
|
+
if (!engine.ok) return undefined;
|
|
2308
|
+
const computed = ComputedConfig.parse(
|
|
2309
|
+
await engine.value.eslint.calculateConfigForFile(join(dir, STATUS_FILE)),
|
|
2310
|
+
);
|
|
2311
|
+
return computed?.rules?.["artifact/upload-current"];
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/** Every artifact host paperlint has an adapter for: a new host is its folder and one line here. */
|
|
2315
|
+
const ARTIFACT_HOSTS: Readonly<Record<string, ArtifactHost>> = {
|
|
2316
|
+
osf: osfHost(),
|
|
2317
|
+
};
|
|
2318
|
+
|
|
2179
2319
|
/** The adapter of each portal kind — one per kind, chosen here at the root. */
|
|
2180
2320
|
const PORTALS: Readonly<Record<PortalKind, (url: string) => PortalSite>> = {
|
|
2181
2321
|
hotcrp: hotcrpSite,
|
|
@@ -2515,11 +2655,16 @@ async function paperEslint(
|
|
|
2515
2655
|
? paperBodies(paperDirs([...paths, ...papersRoots(cfg)]), RECORD_DEPS)
|
|
2516
2656
|
: [];
|
|
2517
2657
|
|
|
2658
|
+
const cwd = lintRoot(cfg.root, paths);
|
|
2659
|
+
// The papers whose own files the config names: the ones `paths` reach and the project's. A copy of
|
|
2660
|
+
// a paper kept inside it (a review snapshot, a build copy) is in no such list, so no block claims
|
|
2661
|
+
// it (#582).
|
|
2662
|
+
const claimed = papersScope(paperDirs([...paths, ...papersRoots(cfg)]), cwd);
|
|
2518
2663
|
const eslint = new ESLint({
|
|
2519
|
-
cwd
|
|
2664
|
+
cwd,
|
|
2520
2665
|
overrideConfigFile: true,
|
|
2521
2666
|
overrideConfig: eslintConfig([
|
|
2522
|
-
...buildConfig(opts, texLanguage),
|
|
2667
|
+
...buildConfig(opts, texLanguage, claimed),
|
|
2523
2668
|
...includeBlocks(bodies),
|
|
2524
2669
|
]),
|
|
2525
2670
|
fix,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { omit } from "remeda";
|
|
2
|
+
import { expect, test } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
drift,
|
|
5
|
+
md5Hex,
|
|
6
|
+
parseUploadRecord,
|
|
7
|
+
uploadRecordText,
|
|
8
|
+
type UploadRecord,
|
|
9
|
+
} from "./artifact-upload.ts";
|
|
10
|
+
|
|
11
|
+
const RECORD: UploadRecord = {
|
|
12
|
+
version: 1,
|
|
13
|
+
host: "osf",
|
|
14
|
+
url: "https://osf.io/abcde/",
|
|
15
|
+
file: "artifact.zip",
|
|
16
|
+
id: "0123456789abcdef01234567",
|
|
17
|
+
sha256: "a".repeat(64),
|
|
18
|
+
md5: "b".repeat(32),
|
|
19
|
+
uploadedAt: "2026-11-01T10:00:00Z",
|
|
20
|
+
numbers: { nRepos: "63", pctPass: "41.2\\%" },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
test("a record survives its own text: written, then read back whole", () => {
|
|
24
|
+
// Guards: the writer and the reader agree on every field.
|
|
25
|
+
expect(parseUploadRecord(uploadRecordText(RECORD))).toEqual({
|
|
26
|
+
ok: true,
|
|
27
|
+
value: RECORD,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("a hand-written record without the optional fields is a record", () => {
|
|
32
|
+
const bare = omit(RECORD, ["id", "sha256", "md5"]);
|
|
33
|
+
// Guards: id and the hashes are optional; a host that gives none still has a record.
|
|
34
|
+
expect(parseUploadRecord(JSON.stringify(bare))).toEqual({
|
|
35
|
+
ok: true,
|
|
36
|
+
value: bare,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("what is not a record is refused, saying which field and why", () => {
|
|
41
|
+
// Guards: text that is not JSON is named as such.
|
|
42
|
+
expect(parseUploadRecord("{")).toEqual({
|
|
43
|
+
ok: false,
|
|
44
|
+
error: "it is not JSON",
|
|
45
|
+
});
|
|
46
|
+
// Guards: an unknown version, an unknown key and a bad hash each name their path.
|
|
47
|
+
expect(
|
|
48
|
+
parseUploadRecord(
|
|
49
|
+
JSON.stringify({ ...RECORD, version: 2, sha256: "x", extra: 1 }),
|
|
50
|
+
),
|
|
51
|
+
).toEqual({
|
|
52
|
+
ok: false,
|
|
53
|
+
error:
|
|
54
|
+
'version: Invalid input: expected 1; sha256: Invalid string: must match pattern /^[0-9a-f]{64}$/; the record: Unrecognized key: "extra"',
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("md5 as hosts print it", () => {
|
|
59
|
+
// Guards: the digest of the empty input, the one every md5 implementation agrees on.
|
|
60
|
+
expect(md5Hex(new Uint8Array())).toBe("d41d8cd98f00b204e9800998ecf8427e");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("drift: keys the paper prints that the upload lacked or held with another value, used keys only", () => {
|
|
64
|
+
const current = new Map([
|
|
65
|
+
["nRepos", "64"],
|
|
66
|
+
["pctPass", "41.2\\%"],
|
|
67
|
+
["nNew", "7"],
|
|
68
|
+
["nUnused", "9"],
|
|
69
|
+
]);
|
|
70
|
+
const used = new Set(["nRepos", "pctPass", "nNew"]);
|
|
71
|
+
// Guards: a changed value, a new key, and an unused new key that does not count.
|
|
72
|
+
expect(drift(RECORD.numbers, current, used)).toEqual({
|
|
73
|
+
added: ["nNew"],
|
|
74
|
+
changed: ["nRepos"],
|
|
75
|
+
});
|
|
76
|
+
// Guards: the paper as uploaded drifts nowhere.
|
|
77
|
+
expect(
|
|
78
|
+
drift(RECORD.numbers, new Map(Object.entries(RECORD.numbers)), used),
|
|
79
|
+
).toEqual({ added: [], changed: [] });
|
|
80
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE UPLOAD RECORD — what an artifact host holds, written down once at upload time, so a lint rule
|
|
3
|
+
* can say later whether the paper still prints what that upload was built for. Pure.
|
|
4
|
+
*
|
|
5
|
+
* The record is a JSON file (default `<paper>/submission/artifact-upload.json`, docs/artifact-upload.md)
|
|
6
|
+
* that anyone may write: `paperlint artifact record`, `paperlint artifact upload --save`, the author's
|
|
7
|
+
* own script, or a hand. It is parsed here, once, into `UploadRecord`; nothing after reads the raw
|
|
8
|
+
* JSON. `numbers` is the paper's printed key → value map at upload time: every argument-less macro
|
|
9
|
+
* of the paper's numbers file, as written in its definition.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { err, ok, type Result } from "./result.ts";
|
|
14
|
+
|
|
15
|
+
/** The record's version: a reader refuses one it does not know rather than misread it. */
|
|
16
|
+
export const RECORD_VERSION = 1;
|
|
17
|
+
|
|
18
|
+
/** Where the record is, relative to the paper, unless the rule's `record` option names another. */
|
|
19
|
+
export const DEFAULT_RECORD = "submission/artifact-upload.json";
|
|
20
|
+
|
|
21
|
+
const Hex = (n: number) =>
|
|
22
|
+
z.string().regex(new RegExp(`^[0-9a-f]{${String(n)}}$`));
|
|
23
|
+
|
|
24
|
+
const Record = z.strictObject({
|
|
25
|
+
version: z.literal(RECORD_VERSION),
|
|
26
|
+
/** The host's name: `osf`, `zenodo`, `other`, … — a host paperlint has no adapter for is fine. */
|
|
27
|
+
host: z.string().min(1),
|
|
28
|
+
url: z.url(),
|
|
29
|
+
/** The uploaded file's name. */
|
|
30
|
+
file: z.string().min(1),
|
|
31
|
+
/** The host's own id of the file, when it has one (OSF: the file's id); lets `show` find it. */
|
|
32
|
+
id: z.string().min(1).optional(),
|
|
33
|
+
sha256: Hex(64).optional(),
|
|
34
|
+
md5: Hex(32).optional(),
|
|
35
|
+
uploadedAt: z.iso.datetime({ offset: true }),
|
|
36
|
+
numbers: z.record(z.string(), z.string()),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export type UploadRecord = Readonly<z.infer<typeof Record>>;
|
|
40
|
+
|
|
41
|
+
/** `json` as a record, or why it is not one, in words: which field and what is wrong with it. */
|
|
42
|
+
export function recordOf(json: unknown): Result<UploadRecord, string> {
|
|
43
|
+
const r = Record.safeParse(json);
|
|
44
|
+
return r.success
|
|
45
|
+
? ok(r.data)
|
|
46
|
+
: err(
|
|
47
|
+
r.error.issues
|
|
48
|
+
.map((i) => `${i.path.join(".") || "the record"}: ${i.message}`)
|
|
49
|
+
.join("; "),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The record in `text`, or why it is not one, in words. */
|
|
54
|
+
export function parseUploadRecord(text: string): Result<UploadRecord, string> {
|
|
55
|
+
try {
|
|
56
|
+
return recordOf(JSON.parse(text));
|
|
57
|
+
} catch {
|
|
58
|
+
return err("it is not JSON");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The record as its file holds it: two-space JSON, keys in the order given, a final newline. */
|
|
63
|
+
export const uploadRecordText = (r: UploadRecord): string =>
|
|
64
|
+
`${JSON.stringify(r, null, 2)}\n`;
|
|
65
|
+
|
|
66
|
+
/** The md5 of `bytes`, as hosts print it: 32 lowercase hex digits. */
|
|
67
|
+
export const md5Hex = (bytes: Uint8Array): string =>
|
|
68
|
+
createHash("md5").update(bytes).digest("hex");
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* `used`, plus every macro of `values` that a used macro's definition names, at any depth
|
|
72
|
+
* (`repoCount` defined as `\nRepos` prints `nRepos` too). `usesIn` reads the names a definition
|
|
73
|
+
* uses. The set only grows and is bounded by `values`, so a cycle of definitions ends.
|
|
74
|
+
*/
|
|
75
|
+
export const printedThrough = (
|
|
76
|
+
values: ReadonlyMap<string, string>,
|
|
77
|
+
used: ReadonlySet<string>,
|
|
78
|
+
usesIn: (definition: string) => readonly string[],
|
|
79
|
+
): ReadonlySet<string> => {
|
|
80
|
+
const next = new Set([
|
|
81
|
+
...used,
|
|
82
|
+
...[...used].flatMap((k) =>
|
|
83
|
+
usesIn(values.get(k) ?? "").filter((u) => values.has(u)),
|
|
84
|
+
),
|
|
85
|
+
]);
|
|
86
|
+
return next.size === used.size ? used : printedThrough(values, next, usesIn);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** What the paper prints now that the upload was not built for: keys it lacked, keys with another value. */
|
|
90
|
+
export interface Drift {
|
|
91
|
+
readonly added: readonly string[];
|
|
92
|
+
readonly changed: readonly string[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The drift between the numbers recorded at upload and the paper's `current` ones, counting only the
|
|
97
|
+
* keys the paper uses: a macro defined and never printed never fires. Keys in source order.
|
|
98
|
+
*/
|
|
99
|
+
export const drift = (
|
|
100
|
+
recorded: Readonly<Record<string, string>>,
|
|
101
|
+
current: ReadonlyMap<string, string>,
|
|
102
|
+
used: ReadonlySet<string>,
|
|
103
|
+
): Drift => {
|
|
104
|
+
const printed = [...current].filter(([k]) => used.has(k));
|
|
105
|
+
return {
|
|
106
|
+
added: printed.filter(([k]) => !Object.hasOwn(recorded, k)).map(([k]) => k),
|
|
107
|
+
changed: printed
|
|
108
|
+
.filter(([k, v]) => Object.hasOwn(recorded, k) && recorded[k] !== v)
|
|
109
|
+
.map(([k]) => k),
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { papersReached, type PaperTree } from "./paper-dirs.ts";
|
|
4
|
+
|
|
5
|
+
/** A disk holding exactly `files`, its folders the ones those files imply. */
|
|
6
|
+
const treeOf = (files: readonly string[]): PaperTree => {
|
|
7
|
+
const dirs = new Set(
|
|
8
|
+
files.flatMap((f) => {
|
|
9
|
+
const up = (d: string): readonly string[] =>
|
|
10
|
+
d === "/" ? [] : [d, ...up(dirname(d))];
|
|
11
|
+
return up(dirname(f));
|
|
12
|
+
}),
|
|
13
|
+
);
|
|
14
|
+
return {
|
|
15
|
+
isFile: (p) => files.includes(p),
|
|
16
|
+
subfolders: (dir) =>
|
|
17
|
+
[...dirs]
|
|
18
|
+
.filter((d) => dirname(d) === dir && !d.endsWith("/extra"))
|
|
19
|
+
.sort(),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** The project every row reads: three papers, a source-only one, a copy in each place one is kept. */
|
|
24
|
+
const PROJECT = treeOf([
|
|
25
|
+
"/w/paperlint.json",
|
|
26
|
+
"/w/papers/p/paper.tex",
|
|
27
|
+
"/w/papers/p/PIPELINE-STATUS.md",
|
|
28
|
+
"/w/papers/p/reviews/r.md",
|
|
29
|
+
"/w/papers/p/reviews/snapshot/paper.tex",
|
|
30
|
+
"/w/papers/p/reviews/snapshot/PIPELINE-STATUS.md",
|
|
31
|
+
"/w/papers/p/old/paper.tex",
|
|
32
|
+
"/w/papers/p/_build/paper.tex",
|
|
33
|
+
"/w/papers/p/extra/2025/paper.tex",
|
|
34
|
+
"/w/papers/q/PIPELINE-STATUS.md",
|
|
35
|
+
"/w/archive/2025/s/paper.tex",
|
|
36
|
+
"/w/archive/2025/s/reviews/r.md",
|
|
37
|
+
"/w/archive/2025/s/reviews/snapshot/PIPELINE-STATUS.md",
|
|
38
|
+
"/w/archive/notes/todo.md",
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
describe("the papers a path reaches (#582)", () => {
|
|
42
|
+
test.each([
|
|
43
|
+
[
|
|
44
|
+
"the project root: every paper below it, none inside one",
|
|
45
|
+
["/w"],
|
|
46
|
+
["/w/archive/2025/s", "/w/papers/p", "/w/papers/q"],
|
|
47
|
+
],
|
|
48
|
+
["a papers directory", ["/w/papers"], ["/w/papers/p", "/w/papers/q"]],
|
|
49
|
+
[
|
|
50
|
+
"a folder two levels above a paper",
|
|
51
|
+
["/w/archive"],
|
|
52
|
+
["/w/archive/2025/s"],
|
|
53
|
+
],
|
|
54
|
+
["a paper with both markers", ["/w/papers/p"], ["/w/papers/p"]],
|
|
55
|
+
["a paper with only its scorecard", ["/w/papers/q"], ["/w/papers/q"]],
|
|
56
|
+
[
|
|
57
|
+
"a paper with only its source",
|
|
58
|
+
["/w/archive/2025/s"],
|
|
59
|
+
["/w/archive/2025/s"],
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
"a review card's folder, a snapshot beside it",
|
|
63
|
+
["/w/papers/p/reviews"],
|
|
64
|
+
["/w/papers/p"],
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
"the same, in a source-only paper",
|
|
68
|
+
["/w/archive/2025/s/reviews"],
|
|
69
|
+
["/w/archive/2025/s"],
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
"a build copy named itself",
|
|
73
|
+
["/w/papers/p/_build"],
|
|
74
|
+
["/w/papers/p/_build"],
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
"a snapshot named itself",
|
|
78
|
+
["/w/papers/p/reviews/snapshot"],
|
|
79
|
+
["/w/papers/p/reviews/snapshot"],
|
|
80
|
+
],
|
|
81
|
+
["a folder with no paper at or below it", ["/w/archive/notes"], []],
|
|
82
|
+
["a paper kept under extra/", ["/w/papers/p/extra/2025"], ["/w/papers/p"]],
|
|
83
|
+
[
|
|
84
|
+
"two paths reaching one paper",
|
|
85
|
+
["/w/papers/p", "/w/papers/p/reviews"],
|
|
86
|
+
["/w/papers/p"],
|
|
87
|
+
],
|
|
88
|
+
] as const)("%s", (_, dirs, papers) => {
|
|
89
|
+
expect(papersReached(dirs, PROJECT)).toEqual(papers);
|
|
90
|
+
});
|
|
91
|
+
});
|