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.
Files changed (104) hide show
  1. package/CLAUDE.md +5 -1
  2. package/dist/adapters/latex/abstract.d.ts +11 -0
  3. package/dist/adapters/latex/abstract.d.ts.map +1 -1
  4. package/dist/adapters/latex/abstract.js +1 -1
  5. package/dist/adapters/latex/abstract.js.map +1 -1
  6. package/dist/adapters/latex/index.d.ts.map +1 -1
  7. package/dist/adapters/latex/index.js +3 -0
  8. package/dist/adapters/latex/index.js.map +1 -1
  9. package/dist/adapters/latex/macros.d.ts +6 -0
  10. package/dist/adapters/latex/macros.d.ts.map +1 -0
  11. package/dist/adapters/latex/macros.js +27 -0
  12. package/dist/adapters/latex/macros.js.map +1 -0
  13. package/dist/adapters/osf/host.io.d.ts +12 -0
  14. package/dist/adapters/osf/host.io.d.ts.map +1 -0
  15. package/dist/adapters/osf/host.io.js +119 -0
  16. package/dist/adapters/osf/host.io.js.map +1 -0
  17. package/dist/adapters/osf/index.d.ts +10 -0
  18. package/dist/adapters/osf/index.d.ts.map +1 -0
  19. package/dist/adapters/osf/index.js +10 -0
  20. package/dist/adapters/osf/index.js.map +1 -0
  21. package/dist/adapters/osf/response.d.ts +11 -0
  22. package/dist/adapters/osf/response.d.ts.map +1 -0
  23. package/dist/adapters/osf/response.js +87 -0
  24. package/dist/adapters/osf/response.js.map +1 -0
  25. package/dist/artifact-upload-rule.d.ts +66 -0
  26. package/dist/artifact-upload-rule.d.ts.map +1 -0
  27. package/dist/artifact-upload-rule.js +151 -0
  28. package/dist/artifact-upload-rule.js.map +1 -0
  29. package/dist/artifact.d.ts +35 -0
  30. package/dist/artifact.d.ts.map +1 -0
  31. package/dist/artifact.js +251 -0
  32. package/dist/artifact.js.map +1 -0
  33. package/dist/cli.d.ts +9 -1
  34. package/dist/cli.d.ts.map +1 -1
  35. package/dist/cli.js +136 -23
  36. package/dist/cli.js.map +1 -1
  37. package/dist/domain/artifact-upload.d.ts +44 -0
  38. package/dist/domain/artifact-upload.d.ts.map +1 -0
  39. package/dist/domain/artifact-upload.js +80 -0
  40. package/dist/domain/artifact-upload.js.map +1 -0
  41. package/dist/domain/paper-dirs.d.ts +16 -0
  42. package/dist/domain/paper-dirs.d.ts.map +1 -0
  43. package/dist/domain/paper-dirs.js +42 -0
  44. package/dist/domain/paper-dirs.js.map +1 -0
  45. package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
  46. package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
  47. package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
  48. package/dist/paper-files.d.ts +25 -42
  49. package/dist/paper-files.d.ts.map +1 -1
  50. package/dist/paper-files.js +101 -9
  51. package/dist/paper-files.js.map +1 -1
  52. package/dist/ports/artifact-host.d.ts +54 -0
  53. package/dist/ports/artifact-host.d.ts.map +1 -0
  54. package/dist/ports/artifact-host.js +2 -0
  55. package/dist/ports/artifact-host.js.map +1 -0
  56. package/dist/ports/latex.d.ts +9 -0
  57. package/dist/ports/latex.d.ts.map +1 -1
  58. package/dist/submission-confirm-hook.d.ts +11 -1
  59. package/dist/submission-confirm-hook.d.ts.map +1 -1
  60. package/dist/submission-confirm-hook.js +83 -21
  61. package/dist/submission-confirm-hook.js.map +1 -1
  62. package/dist/types.d.ts +6 -0
  63. package/dist/types.d.ts.map +1 -1
  64. package/docs/artifact-upload.md +124 -0
  65. package/docs/optional-rules.md +1 -0
  66. package/docs/osf-artifact.md +4 -1
  67. package/docs/rules/artifact/upload-current.md +85 -0
  68. package/docs/rules.md +1 -0
  69. package/eslint-rules/CLAUDE.md +5 -1
  70. package/eslint-rules/CLAUDE.md.spec.ts +3 -0
  71. package/package.json +1 -1
  72. package/src/adapters/latex/abstract.ts +3 -1
  73. package/src/adapters/latex/index.ts +3 -0
  74. package/src/adapters/latex/macros.test.ts +31 -0
  75. package/src/adapters/latex/macros.ts +43 -0
  76. package/src/adapters/osf/cassette/README.md +20 -0
  77. package/src/adapters/osf/cassette/get-file.json +108 -0
  78. package/src/adapters/osf/cassette/get-listing.json +111 -0
  79. package/src/adapters/osf/cassette/get-missing.json +1 -0
  80. package/src/adapters/osf/cassette/put-new.json +31 -0
  81. package/src/adapters/osf/host.io.ts +156 -0
  82. package/src/adapters/osf/host.test.ts +274 -0
  83. package/src/adapters/osf/index.ts +14 -0
  84. package/src/adapters/osf/response.ts +105 -0
  85. package/src/artifact-upload-rule.test.ts +213 -0
  86. package/src/artifact-upload-rule.ts +213 -0
  87. package/src/artifact.test.ts +504 -0
  88. package/src/artifact.ts +402 -0
  89. package/src/cli.test.ts +271 -1
  90. package/src/cli.ts +168 -23
  91. package/src/domain/artifact-upload.test.ts +80 -0
  92. package/src/domain/artifact-upload.ts +111 -0
  93. package/src/domain/paper-dirs.test.ts +91 -0
  94. package/src/domain/paper-dirs.ts +62 -0
  95. package/src/new-paper.test.ts +8 -2
  96. package/src/paper-files.test.ts +88 -0
  97. package/src/paper-files.ts +98 -9
  98. package/src/paper-settings-commands.test.ts +18 -0
  99. package/src/ports/artifact-host.ts +65 -0
  100. package/src/ports/latex.ts +10 -0
  101. package/src/rule-cases.test.ts +44 -0
  102. package/src/submission-confirm-hook.test.ts +113 -1
  103. package/src/submission-confirm-hook.ts +120 -27
  104. package/src/types.ts +6 -0
@@ -0,0 +1,274 @@
1
+ /**
2
+ * The OSF adapter against a local HTTP server on 127.0.0.1 β€” no real OSF, no network. The server
3
+ * answers with the recorded answers in `cassette/` and records each request whole (method, path,
4
+ * query, the Authorization header, the body), so the tests assert what OSF would receive.
5
+ */
6
+ import { readFileSync } from "node:fs";
7
+ import { createServer, type IncomingMessage } from "node:http";
8
+ import type { AddressInfo } from "node:net";
9
+ import { afterAll, beforeAll, beforeEach, expect, test } from "vitest";
10
+ import type { ArtifactHost } from "../../ports/artifact-host.ts";
11
+ import { osfHost, parseFile, parseListing, parseUploaded } from "./index.ts";
12
+
13
+ const cassette = (name: string): string =>
14
+ readFileSync(new URL(`cassette/${name}`, import.meta.url), "utf8");
15
+
16
+ interface Seen {
17
+ readonly request: string;
18
+ readonly auth: string | null;
19
+ readonly body: string;
20
+ }
21
+ interface Reply {
22
+ readonly status: number;
23
+ readonly body: string;
24
+ }
25
+
26
+ const seen: Seen[] = [];
27
+ let routes: Readonly<Record<string, Reply>> = {};
28
+ const server = createServer((req: IncomingMessage, res) => {
29
+ const chunks: Buffer[] = [];
30
+ req.on("data", (c: Buffer) => chunks.push(c));
31
+ req.on("end", () => {
32
+ const request = `${req.method ?? ""} ${req.url ?? ""}`;
33
+ seen.push({
34
+ request,
35
+ auth: req.headers.authorization ?? null,
36
+ body: Buffer.concat(chunks).toString(),
37
+ });
38
+ const r = routes[request] ?? { status: 599, body: "{}" };
39
+ res.writeHead(r.status, { "content-type": "application/json" });
40
+ res.end(r.body);
41
+ });
42
+ });
43
+
44
+ let host: ArtifactHost;
45
+ let base = "";
46
+ beforeAll(async () => {
47
+ await new Promise<void>((done) => server.listen(0, "127.0.0.1", done));
48
+ const a: AddressInfo | string | null = server.address();
49
+ base = `http://127.0.0.1:${typeof a === "object" && a !== null ? String(a.port) : ""}`;
50
+ host = osfHost({
51
+ api: `${base}/v2`,
52
+ files: `${base}/v1`,
53
+ site: "https://osf.io",
54
+ });
55
+ });
56
+ afterAll(
57
+ () =>
58
+ new Promise<void>((done) => {
59
+ server.close(() => {
60
+ done();
61
+ });
62
+ }),
63
+ );
64
+ beforeEach(() => {
65
+ seen.length = 0;
66
+ });
67
+
68
+ const ID = "0123456789abcdef01234567";
69
+ const FILE = `/v2/files/${ID}/`;
70
+ const LISTING =
71
+ "/v2/nodes/abcde/files/osfstorage/?filter%5Bname%5D=artifact.zip";
72
+ const HOSTED = {
73
+ id: ID,
74
+ url: `https://osf.io/abcde/files/osfstorage/${ID}`,
75
+ sha256: "59bd16dfc39e768f82bb8ec74467e571e80ed284683b586f077dbf1aa2483ecd",
76
+ md5: "3f395fbbb68716f38f5ff7fa9d740e3b",
77
+ };
78
+ const EMPTY = JSON.stringify({ data: [] });
79
+ const ok200 = (name: string): Reply => ({ status: 200, body: cassette(name) });
80
+
81
+ test("read: by the record's file id, without a token on a public file", async () => {
82
+ routes = { [`GET ${FILE}`]: ok200("get-file.json") };
83
+ const r = await host.read(
84
+ { url: "https://osf.io/abcde/", file: "x", id: ID },
85
+ null,
86
+ );
87
+ // Guards: the file's hashes as OSF holds them, and no Authorization header without a token.
88
+ expect(r).toEqual({ ok: true, value: HOSTED });
89
+ expect(seen).toEqual([{ request: `GET ${FILE}`, auth: null, body: "" }]);
90
+ });
91
+
92
+ test("read: by name in the project the url names, with the token in its header only", async () => {
93
+ routes = { [`GET ${LISTING}`]: ok200("get-listing.json") };
94
+ const where = {
95
+ url: "https://osf.io/abcde/?view_only=0f",
96
+ file: "artifact.zip",
97
+ id: null,
98
+ };
99
+ // Guards: the listing filtered by the record's file name; the token travels as a bearer header.
100
+ expect(await host.read(where, "tok")).toEqual({ ok: true, value: HOSTED });
101
+ expect(seen).toEqual([
102
+ { request: `GET ${LISTING}`, auth: "Bearer tok", body: "" },
103
+ ]);
104
+ // Guards: a project without that file is not found, naming both.
105
+ routes = { [`GET ${LISTING}`]: { status: 200, body: EMPTY } };
106
+ expect(await host.read(where, null)).toEqual({
107
+ ok: false,
108
+ error: {
109
+ kind: "not-found",
110
+ detail: "the project abcde holds no file artifact.zip at its top level",
111
+ },
112
+ });
113
+ });
114
+
115
+ test("read: what OSF or the record cannot answer is a failure that says which", async () => {
116
+ routes = {
117
+ [`GET ${FILE}`]: { status: 404, body: cassette("get-missing.json") },
118
+ };
119
+ const where = { url: "https://example.org/a", file: "artifact.zip", id: ID };
120
+ // Guards: 404 β†’ not found.
121
+ expect(await host.read(where, null)).toEqual({
122
+ ok: false,
123
+ error: {
124
+ kind: "not-found",
125
+ detail: "HTTP 404: OSF has no such file or project",
126
+ },
127
+ });
128
+ // Guards: a url that is not OSF's, and no id β†’ not found, before any request.
129
+ expect(await host.read({ ...where, id: null }, null)).toEqual({
130
+ ok: false,
131
+ error: {
132
+ kind: "not-found",
133
+ detail:
134
+ "the record has no file id and its url names no https://osf.io project",
135
+ },
136
+ });
137
+ routes = { [`GET ${FILE}`]: { status: 401, body: "{}" } };
138
+ // Guards: 401 β†’ refused, with no token in the words.
139
+ expect(await host.read(where, "secret-token")).toEqual({
140
+ ok: false,
141
+ error: {
142
+ kind: "refused",
143
+ detail:
144
+ "HTTP 401: OSF refused the token, or the file is not public and no token was given",
145
+ },
146
+ });
147
+ routes = { [`GET ${FILE}`]: { status: 500, body: "<html>" } };
148
+ // Guards: an answer that is not JSON is malformed.
149
+ expect(await host.read(where, null)).toEqual({
150
+ ok: false,
151
+ error: { kind: "malformed", detail: "HTTP 500: the answer is not JSON" },
152
+ });
153
+ const gone = osfHost({
154
+ api: "http://127.0.0.1:1/v2",
155
+ files: "",
156
+ site: "https://osf.io",
157
+ });
158
+ const r = await gone.read(where, null);
159
+ // Guards: a host that does not answer is unreachable β€” for a read by id, by name, and an upload.
160
+ expect(r.ok ? null : r.error.kind).toBe("unreachable");
161
+ const byName = await gone.read(
162
+ { ...where, url: "https://osf.io/abcde/", id: null },
163
+ null,
164
+ );
165
+ expect(byName.ok ? null : byName.error.kind).toBe("unreachable");
166
+ const up = await gone.upload(
167
+ { target: "abcde", name: "a", bytes: new Uint8Array() },
168
+ "t",
169
+ );
170
+ expect(up.ok ? null : up.error.kind).toBe("unreachable");
171
+ });
172
+
173
+ test("upload: a new file, then its hashes read back from OSF", async () => {
174
+ const put =
175
+ "/v1/resources/abcde/providers/osfstorage/?kind=file&name=artifact.zip";
176
+ routes = {
177
+ [`GET ${LISTING}`]: { status: 200, body: EMPTY },
178
+ [`PUT ${put}`]: { status: 201, body: cassette("put-new.json") },
179
+ [`GET ${FILE}`]: ok200("get-file.json"),
180
+ };
181
+ const bytes = new TextEncoder().encode("artifact bytes\n");
182
+ const r = await host.upload(
183
+ { target: "abcde", name: "artifact.zip", bytes },
184
+ "tok",
185
+ );
186
+ // Guards: look for the name, PUT the bytes as a new file, read the hashes back β€” each with the token.
187
+ expect(r).toEqual({ ok: true, value: HOSTED });
188
+ expect(seen).toEqual([
189
+ { request: `GET ${LISTING}`, auth: "Bearer tok", body: "" },
190
+ { request: `PUT ${put}`, auth: "Bearer tok", body: "artifact bytes\n" },
191
+ { request: `GET ${FILE}`, auth: "Bearer tok", body: "" },
192
+ ]);
193
+ });
194
+
195
+ test("upload: a file of the same name gets a new version; a failing step stops it", async () => {
196
+ const put = `/v1/resources/abcde/providers/osfstorage/${ID}?kind=file`;
197
+ routes = {
198
+ [`GET ${LISTING}`]: ok200("get-listing.json"),
199
+ [`PUT ${put}`]: ok200("put-new.json"),
200
+ [`GET ${FILE}`]: ok200("get-file.json"),
201
+ };
202
+ const u = {
203
+ target: "abcde",
204
+ name: "artifact.zip",
205
+ bytes: new Uint8Array([1]),
206
+ };
207
+ // Guards: the version goes to the existing file's id.
208
+ expect(await host.upload(u, "tok")).toEqual({ ok: true, value: HOSTED });
209
+ expect(seen.map((s) => s.request)).toEqual([
210
+ `GET ${LISTING}`,
211
+ `PUT ${put}`,
212
+ `GET ${FILE}`,
213
+ ]);
214
+ routes = { [`GET ${LISTING}`]: { status: 403, body: "{}" } };
215
+ // Guards: a refused listing uploads nothing.
216
+ expect((await host.upload(u, "tok")).ok).toBe(false);
217
+ routes = {
218
+ [`GET ${LISTING}`]: ok200("get-listing.json"),
219
+ [`PUT ${put}`]: { status: 200, body: "{}" },
220
+ };
221
+ // Guards: an upload answer without the file's path is malformed.
222
+ expect(await host.upload(u, "tok")).toEqual({
223
+ ok: false,
224
+ error: {
225
+ kind: "malformed",
226
+ detail: "HTTP 200: the answer is not an uploaded file",
227
+ },
228
+ });
229
+ routes = {
230
+ [`GET ${LISTING}`]: ok200("get-listing.json"),
231
+ [`PUT ${put}`]: { status: 502, body: "<html>" },
232
+ };
233
+ // Guards: a PUT whose answer is not JSON stops before the read-back.
234
+ expect(await host.upload(u, "tok")).toEqual({
235
+ ok: false,
236
+ error: { kind: "malformed", detail: "HTTP 502: the answer is not JSON" },
237
+ });
238
+ expect(seen.at(-1)?.request).toBe(`PUT ${put}`);
239
+ });
240
+
241
+ test("the parsers: shapes that are not OSF's are malformed; a file without hashes has none", () => {
242
+ // Guards: each parser refuses a body of the wrong shape, by what it expected.
243
+ expect(parseFile(200, {})).toEqual({
244
+ ok: false,
245
+ error: { kind: "malformed", detail: "HTTP 200: the answer is not a file" },
246
+ });
247
+ expect(parseListing(200, {}, "a")).toEqual({
248
+ ok: false,
249
+ error: {
250
+ kind: "malformed",
251
+ detail: "HTTP 200: the answer is not a list of files",
252
+ },
253
+ });
254
+ expect(parseListing(404, {}, "a").ok).toBe(false);
255
+ expect(parseUploaded(500, {}).ok).toBe(false);
256
+ const bare = {
257
+ id: "i",
258
+ attributes: { name: "a", kind: "file", extra: {} },
259
+ links: { html: "h" },
260
+ };
261
+ // Guards: a file OSF gives no hashes for reads as none, not as an error.
262
+ expect(parseFile(200, { data: bare })).toEqual({
263
+ ok: true,
264
+ value: { id: "i", url: "h", sha256: null, md5: null },
265
+ });
266
+ });
267
+
268
+ test("targetOf: the project's guid in an osf.io url, else none", () => {
269
+ // Guards: a project url, with or without a view-only link; anything else is none.
270
+ expect(host.targetOf("https://osf.io/abcde/?view_only=1")).toBe("abcde");
271
+ expect(host.targetOf("https://osf.io/settings/")).toBe(null);
272
+ expect(host.targetOf("https://zenodo.org/records/1")).toBe(null);
273
+ expect(host.targetOf("not a url")).toBe(null);
274
+ });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * OSF (osf.io), as the `ArtifactHost` port: its API read and WaterButler written over `fetch`, its
3
+ * answers parsed here, its token variable and page. Everything that changes if OSF's API does lives
4
+ * in this folder; `cassette/README.md` says which answers are recorded and which are written from
5
+ * OSF's source. A contributor adding a host copies this folder's shape: `host.io.ts`, `response.ts`,
6
+ * a cassette and its test, and one line in `ARTIFACT_HOSTS` (src/cli.ts).
7
+ */
8
+ export { OSF, osfHost, type OsfUrls } from "./host.io.ts";
9
+ export {
10
+ parseFile,
11
+ parseListing,
12
+ parseUploaded,
13
+ statusFailure,
14
+ } from "./response.ts";
@@ -0,0 +1,105 @@
1
+ /**
2
+ * OSF's answers, parsed into what the `ArtifactHost` port returns. Pure. The shapes are OSF's own,
3
+ * checked against recorded answers in `cassette/` (README there).
4
+ *
5
+ * - `GET api.osf.io/v2/files/<id>/` and each entry of `GET api.osf.io/v2/nodes/<guid>/files/osfstorage/`:
6
+ * a file's `id`, `attributes.name`, `attributes.kind` and `attributes.extra.hashes` (`md5`,
7
+ * `sha256`), and `links.html`, its page.
8
+ * - `PUT files.osf.io/v1/…` (WaterButler): `{ "data": <file entity> }`, whose `attributes.path` is
9
+ * `/<id>` (`BaseOsfStorageItemMetadata.path` and the upload handler of
10
+ * CenterForOpenScience/waterbutler, read 2026-11-21).
11
+ */
12
+ import { z } from "zod";
13
+ import { err, ok, type Result } from "../../domain/result.ts";
14
+ import type { HostedFile, HostFailure } from "../../ports/artifact-host.ts";
15
+
16
+ const Hash = z.string().nullable().optional();
17
+
18
+ const FileEntry = z.object({
19
+ id: z.string(),
20
+ attributes: z.object({
21
+ name: z.string(),
22
+ kind: z.string(),
23
+ extra: z.object({
24
+ hashes: z.object({ md5: Hash, sha256: Hash }).optional(),
25
+ }),
26
+ }),
27
+ links: z.object({ html: z.string() }),
28
+ });
29
+ type FileEntry = z.infer<typeof FileEntry>;
30
+
31
+ const OneFile = z.object({ data: FileEntry });
32
+ const Listing = z.object({ data: z.array(FileEntry) });
33
+ const Uploaded = z.object({
34
+ data: z.object({ attributes: z.object({ path: z.string() }) }),
35
+ });
36
+
37
+ /** An answer whose shape is not the one parsed: what was expected, and the status it came with. */
38
+ const malformed = (status: number, what: string): HostFailure => ({
39
+ kind: "malformed",
40
+ detail: `HTTP ${String(status)}: the answer is not ${what}`,
41
+ });
42
+
43
+ /** A status that is no success, as a failure: 401 and 403 refused, 404 not found. */
44
+ export function statusFailure(status: number): HostFailure | null {
45
+ if (status === 401 || status === 403)
46
+ return {
47
+ kind: "refused",
48
+ detail: `HTTP ${String(status)}: OSF refused the token, or the file is not public and no token was given`,
49
+ };
50
+ if (status === 404)
51
+ return {
52
+ kind: "not-found",
53
+ detail: "HTTP 404: OSF has no such file or project",
54
+ };
55
+ return status >= 200 && status < 300
56
+ ? null
57
+ : { kind: "refused", detail: `HTTP ${String(status)}` };
58
+ }
59
+
60
+ const hosted = (f: Readonly<FileEntry>): HostedFile => ({
61
+ id: f.id,
62
+ url: f.links.html,
63
+ sha256: f.attributes.extra.hashes?.sha256 ?? null,
64
+ md5: f.attributes.extra.hashes?.md5 ?? null,
65
+ });
66
+
67
+ /** `GET /v2/files/<id>/` β†’ the file. */
68
+ export function parseFile(
69
+ status: number,
70
+ body: unknown,
71
+ ): Result<HostedFile, HostFailure> {
72
+ const bad = statusFailure(status);
73
+ if (bad !== null) return err(bad);
74
+ const f = OneFile.safeParse(body);
75
+ return f.success ? ok(hosted(f.data.data)) : err(malformed(status, "a file"));
76
+ }
77
+
78
+ /** A folder listing β†’ the file called `name` in it, or null when there is none. */
79
+ export function parseListing(
80
+ status: number,
81
+ body: unknown,
82
+ name: string,
83
+ ): Result<HostedFile | null, HostFailure> {
84
+ const bad = statusFailure(status);
85
+ if (bad !== null) return err(bad);
86
+ const l = Listing.safeParse(body);
87
+ if (!l.success) return err(malformed(status, "a list of files"));
88
+ const f = l.data.data.find(
89
+ (e) => e.attributes.kind === "file" && e.attributes.name === name,
90
+ );
91
+ return ok(f === undefined ? null : hosted(f));
92
+ }
93
+
94
+ /** WaterButler's answer to an upload β†’ the id of the file it holds now. */
95
+ export function parseUploaded(
96
+ status: number,
97
+ body: unknown,
98
+ ): Result<string, HostFailure> {
99
+ const bad = statusFailure(status);
100
+ if (bad !== null) return err(bad);
101
+ const u = Uploaded.safeParse(body);
102
+ return u.success
103
+ ? ok(u.data.data.attributes.path.replace(/^\//u, ""))
104
+ : err(malformed(status, "an uploaded file"));
105
+ }
@@ -0,0 +1,213 @@
1
+ /**
2
+ * `artifact/upload-current` (`src/artifact-upload-rule.ts`) over files in memory: every state it can
3
+ * be in, as the finding it makes. Through real ESLint and the CLI, in `src/rule-cases.test.ts`.
4
+ */
5
+ import { expect, test } from "vitest";
6
+ import { latexReader } from "./adapters/latex/index.ts";
7
+ import { memoryFiles } from "./adapters/memory/index.ts";
8
+ import { sourcesCodec } from "./adapters/sources-record/index.ts";
9
+ import {
10
+ artifactUploadRules,
11
+ uploadFindings,
12
+ uploadOptions,
13
+ } from "./artifact-upload-rule.ts";
14
+ import { uploadRecordText } from "./domain/artifact-upload.ts";
15
+ import { recordText } from "../test/recorded-fixture.ts";
16
+
17
+ const DIR = "/work/papers/p";
18
+ const NUMBERS =
19
+ "\\newcommand{\\nRepos}{64}\n\\newcommand{\\nRuns}{7}\n\\newcommand{\\pct}{41.2\\%}\n\\newcommand{\\nA}{1}\n\\newcommand{\\nB}{2}\n\\newcommand{\\nC}{3}\n\\newcommand{\\unused}{9}\n";
20
+ const PAPER =
21
+ "\\documentclass{article}\n\\input{numbersdef}\n\\begin{document}\n\\nRepos{} repos, \\nRuns{} runs, \\pct.\n\\input{sections/more}\n\\end{document}\n";
22
+ const MORE = "\\nA, \\nB, \\nC.\n";
23
+ const AT_UPLOAD = { nRepos: "63", nRuns: "7", pct: "41.2\\%" };
24
+
25
+ const record = (numbers: Readonly<Record<string, string>>): string =>
26
+ uploadRecordText({
27
+ version: 1,
28
+ host: "osf",
29
+ url: "https://osf.io/abcde/",
30
+ file: "artifact.zip",
31
+ uploadedAt: "2026-11-01T10:00:00Z",
32
+ numbers,
33
+ });
34
+
35
+ /** The paper's files under `DIR`, with the build's record of its body file. */
36
+ const tree = (
37
+ extra: Readonly<Record<string, string>>,
38
+ ): Record<string, string> => {
39
+ const own = {
40
+ "paper.tex": PAPER,
41
+ "numbersdef.tex": NUMBERS,
42
+ "sections/more.tex": MORE,
43
+ };
44
+ const built = recordText(own, {
45
+ inputs: [
46
+ ["paper.tex", "body"],
47
+ ["numbersdef.tex", "preamble"],
48
+ ["sections/more.tex", "body"],
49
+ ],
50
+ });
51
+ return Object.fromEntries(
52
+ Object.entries({ ...own, "_build/sources.json": built, ...extra }).map(
53
+ ([p, t]) => [`${DIR}/${p}`, t],
54
+ ),
55
+ );
56
+ };
57
+
58
+ const findings = (
59
+ files: Readonly<Record<string, string>>,
60
+ options: unknown = { numbers: "numbersdef.tex" },
61
+ ) =>
62
+ uploadFindings(DIR, uploadOptions(options), {
63
+ files: memoryFiles(files),
64
+ codec: sourcesCodec,
65
+ latex: latexReader,
66
+ });
67
+
68
+ const RECORD = "submission/artifact-upload.json";
69
+
70
+ test("πŸ”΄ stale: names the new and the changed keys the paper prints, a few of each", () => {
71
+ // Guards: nRepos changed, nA–nC new (from the body file the build record lists), \unused not counted.
72
+ expect(findings(tree({ [RECORD]: record(AT_UPLOAD) }))).toEqual([
73
+ {
74
+ messageId: "stale",
75
+ data: {
76
+ count: 4,
77
+ date: "2026-11-01",
78
+ url: "https://osf.io/abcde/",
79
+ detail: "3 new (nA, nB, nC), 1 changed (nRepos)",
80
+ },
81
+ },
82
+ ]);
83
+ });
84
+
85
+ test("more than three keys of a kind: the rest is counted, not listed", () => {
86
+ // Guards: five new keys show three and "2 more".
87
+ expect(findings(tree({ [RECORD]: record({ pct: "1" }) }))).toEqual([
88
+ {
89
+ messageId: "stale",
90
+ data: {
91
+ count: 6,
92
+ date: "2026-11-01",
93
+ url: "https://osf.io/abcde/",
94
+ detail: "5 new (nRepos, nRuns, nA, 2 more), 1 changed (pct)",
95
+ },
96
+ },
97
+ ]);
98
+ const four = tree({
99
+ "sections/more.tex": "\\nA, \\nB, \\nC, \\unused.\n",
100
+ [RECORD]: record({ pct: "1" }),
101
+ });
102
+ // Without a fresh build record the body file is not read: paper.tex alone counts.
103
+ // Guards: a stale build record narrows the uses to paper.tex.
104
+ expect(findings(four)).toEqual([
105
+ {
106
+ messageId: "stale",
107
+ data: {
108
+ count: 3,
109
+ date: "2026-11-01",
110
+ url: "https://osf.io/abcde/",
111
+ detail: "2 new (nRepos, nRuns), 1 changed (pct)",
112
+ },
113
+ },
114
+ ]);
115
+ });
116
+
117
+ test("a number the paper prints through another macro counts: a change under an alias is found, at any depth", () => {
118
+ const numbers =
119
+ "\\newcommand{\\nRepos}{64}\n\\newcommand{\\repoCount}{\\nRepos}\n\\newcommand{\\shown}{\\repoCount{} repos}\n\\newcommand{\\loopA}{\\loopB}\n\\newcommand{\\loopB}{\\loopA}\n";
120
+ const paper =
121
+ "\\documentclass{article}\n\\begin{document}\n\\shown, \\loopA.\n\\end{document}\n";
122
+ const atUpload = {
123
+ nRepos: "63",
124
+ repoCount: "\\nRepos",
125
+ shown: "\\repoCount{} repos",
126
+ loopA: "\\loopB",
127
+ loopB: "\\loopA",
128
+ };
129
+ const files = {
130
+ [`${DIR}/paper.tex`]: paper,
131
+ [`${DIR}/numbersdef.tex`]: numbers,
132
+ [`${DIR}/${RECORD}`]: record(atUpload),
133
+ };
134
+ // Guards: only \shown is printed; \nRepos, two definitions down, changed; a cycle ends.
135
+ expect(findings(files)).toEqual([
136
+ {
137
+ messageId: "stale",
138
+ data: {
139
+ count: 1,
140
+ date: "2026-11-01",
141
+ url: "https://osf.io/abcde/",
142
+ detail: "1 changed (nRepos)",
143
+ },
144
+ },
145
+ ]);
146
+ });
147
+
148
+ test("silent when the record holds every value the paper prints", () => {
149
+ const now = { ...AT_UPLOAD, nRepos: "64", nA: "1", nB: "2", nC: "3" };
150
+ // Guards: a current record makes no finding, whatever unused macros differ.
151
+ expect(findings(tree({ [RECORD]: record(now) }))).toEqual([]);
152
+ const elsewhere = "extra/upload.json";
153
+ // Guards: the `record` option is where the record is read.
154
+ expect(
155
+ findings(tree({ [elsewhere]: record(now) }), {
156
+ numbers: "numbersdef.tex",
157
+ record: elsewhere,
158
+ }),
159
+ ).toEqual([]);
160
+ });
161
+
162
+ test("turned on without what it needs: one finding, naming what answers it", () => {
163
+ // Guards: no record β†’ the command that writes one.
164
+ expect(findings(tree({}))).toEqual([
165
+ { messageId: "noRecord", data: { path: RECORD } },
166
+ ]);
167
+ // Guards: a record that is not one says why.
168
+ expect(findings(tree({ [RECORD]: "[]" }))).toEqual([
169
+ {
170
+ messageId: "badRecord",
171
+ data: {
172
+ path: RECORD,
173
+ why: "the record: Invalid input: expected object, received array",
174
+ },
175
+ },
176
+ ]);
177
+ // Guards: no numbers file, and one defining nothing, before the record is looked at.
178
+ expect(findings(tree({}), { numbers: "gone.tex" })).toEqual([
179
+ { messageId: "noNumbersFile", data: { path: "gone.tex" } },
180
+ ]);
181
+ expect(findings(tree({ "numbersdef.tex": "% nothing\n" }))).toEqual([
182
+ { messageId: "emptyNumbers", data: { path: "numbersdef.tex" } },
183
+ ]);
184
+ // Guards: turned on with no options at all.
185
+ expect(findings(tree({}), null)).toEqual([
186
+ { messageId: "noOption", data: {} },
187
+ ]);
188
+ });
189
+
190
+ test("reports on PIPELINE-STATUS.md's first line only", () => {
191
+ const rule = artifactUploadRules({
192
+ files: memoryFiles(tree({})),
193
+ codec: sourcesCodec,
194
+ latex: latexReader,
195
+ })["upload-current"];
196
+ const seen = (file: string): readonly string[] => {
197
+ const out: string[] = [];
198
+ rule
199
+ .create({
200
+ filename: `${DIR}/${file}`,
201
+ options: [{ numbers: "numbersdef.tex" }],
202
+ sourceCode: { getLocFromIndex: () => ({ line: 1, column: 0 }) },
203
+ report: (d) => {
204
+ out.push(`${String(d.loc.start.line)} ${d.messageId}`);
205
+ },
206
+ })
207
+ .root?.();
208
+ return out;
209
+ };
210
+ // Guards: one finding on the scorecard; nothing on any other file.
211
+ expect(seen("PIPELINE-STATUS.md")).toEqual(["1 noRecord"]);
212
+ expect(seen("paper.tex")).toEqual([]);
213
+ });