@coywolf/emdash 0.35.13 → 0.35.14

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 (43) hide show
  1. package/README.md +2 -0
  2. package/docs/README.md +45 -0
  3. package/docs/ai.md +39 -0
  4. package/docs/backups.md +88 -0
  5. package/docs/breadcrumbs.md +59 -0
  6. package/docs/code-blocks.md +21 -0
  7. package/docs/content-urls.md +41 -0
  8. package/docs/custom-blocks.md +27 -0
  9. package/docs/discovery.md +32 -0
  10. package/docs/files.md +44 -0
  11. package/docs/form-uploads.md +59 -0
  12. package/docs/headings.md +37 -0
  13. package/docs/images.md +141 -0
  14. package/docs/internals.md +13 -0
  15. package/docs/links.md +34 -0
  16. package/docs/performance.md +72 -0
  17. package/docs/redirects.md +84 -0
  18. package/docs/releasing.md +21 -0
  19. package/docs/reviews.md +89 -0
  20. package/docs/robots.md +81 -0
  21. package/docs/schema.md +79 -0
  22. package/docs/search.md +114 -0
  23. package/docs/videos.md +48 -0
  24. package/docs/wordpress-import.md +198 -0
  25. package/package.json +11 -2
  26. package/src/version.ts +1 -1
  27. package/src/ai/logic.test.ts +0 -187
  28. package/src/ai/queue.test.ts +0 -97
  29. package/src/ai/wikidata.test.ts +0 -184
  30. package/src/backups/dump.test.mjs +0 -287
  31. package/src/backups/restore.test.mjs +0 -103
  32. package/src/codeBlocks/render.test.ts +0 -152
  33. package/src/files/counts.test.ts +0 -114
  34. package/src/files/format.test.ts +0 -93
  35. package/src/files/r2-rules.test.ts +0 -30
  36. package/src/files/sigv4.test.ts +0 -64
  37. package/src/headings/headings.test.ts +0 -159
  38. package/src/pageCache/lib.test.mjs +0 -224
  39. package/src/pageCache/warm.test.mjs +0 -670
  40. package/src/redirects/slug-core.test.ts +0 -50
  41. package/src/robots/rep.test.ts +0 -335
  42. package/src/robots/rules.test.ts +0 -251
  43. package/src/schema/graph.test.mjs +0 -522
@@ -1,50 +0,0 @@
1
- /**
2
- * Run: node --test src/redirects/slug-core.test.ts
3
- */
4
- import assert from "node:assert/strict";
5
- import { test } from "node:test";
6
-
7
- // @ts-expect-error -- Node's type stripping needs the real .ts extension.
8
- import { SLUG_NOTE_PREFIX, planSlugChange } from "./slug-core.ts";
9
-
10
- const ours = (id: string, source: string, target: string) => ({ id, source, target, note: `${SLUG_NOTE_PREFIX} Post` });
11
- const manual = (id: string, source: string, target: string) => ({ id, source, target, note: null });
12
-
13
- test("a new slug: one rule from the old URL to the new one", () => {
14
- assert.deepEqual(planSlugChange("/news/seo/old/", "/news/seo/new/", []), { kind: "apply", deleteIds: [], retargetIds: [], upsert: {} });
15
- });
16
-
17
- test("unchanged or unknown URLs do nothing", () => {
18
- assert.equal(planSlugChange("/a/", "/a", []).kind, "none");
19
- assert.equal(planSlugChange(null, "/a/", []).kind, "none");
20
- assert.equal(planSlugChange("/a/", null, []).kind, "none");
21
- });
22
-
23
- test("a second rename points the first rule at the new URL (no chain)", () => {
24
- const plan = planSlugChange("/b/", "/c/", [ours("r1", "/a", "/b/")]);
25
- assert.deepEqual(plan, { kind: "apply", deleteIds: [], retargetIds: ["r1"], upsert: {} });
26
- });
27
-
28
- test("renaming back deletes the rule that would shadow the live URL", () => {
29
- const plan = planSlugChange("/b/", "/a/", [ours("r1", "/a", "/b/")]);
30
- assert.equal(plan.kind, "apply");
31
- if (plan.kind !== "apply") return;
32
- assert.deepEqual(plan.deleteIds, ["r1"]);
33
- assert.deepEqual(plan.retargetIds, [], "the deleted rule isn't retargeted too");
34
- assert.deepEqual(plan.upsert, {});
35
- });
36
-
37
- test("our existing rule for the old URL is updated, not duplicated", () => {
38
- const plan = planSlugChange("/b/", "/c/", [ours("r2", "/b", "/somewhere/")]);
39
- assert.equal(plan.kind, "apply");
40
- if (plan.kind === "apply") assert.deepEqual(plan.upsert, { id: "r2" });
41
- });
42
-
43
- test("a hand-made rule for the old URL is left alone, and hand-made rules are never edited", () => {
44
- const plan = planSlugChange("/b/", "/c/", [manual("m1", "/b", "/elsewhere/"), manual("m2", "/x", "/b/"), manual("m3", "/c", "/b/")]);
45
- assert.equal(plan.kind, "apply");
46
- if (plan.kind !== "apply") return;
47
- assert.equal(plan.keptManual?.id, "m1");
48
- assert.deepEqual(plan.deleteIds, []);
49
- assert.deepEqual(plan.retargetIds, []);
50
- });
@@ -1,335 +0,0 @@
1
- /**
2
- * REP conformance tests, ported from Google's robots_test.cc
3
- * (https://github.com/google/robotstxt) via Coywolf SEO's PHP suite, plus
4
- * the RFC 9309 examples. Run: node --test src/robots/*.test.ts
5
- */
6
- import assert from "node:assert/strict";
7
- import { test } from "node:test";
8
-
9
- // @ts-expect-error -- Node's type stripping needs the real .ts extension.
10
- import * as REP from "./rep.ts";
11
-
12
- const rep = REP as typeof import("./rep.js");
13
- const al = (robots: string, agent: string, url: string) => rep.oneAgentAllowed(robots, agent, url);
14
-
15
- test("GoogleOnly_SystemTest", () => {
16
- const r1 = "user-agent: FooBot\ndisallow: /\n";
17
- assert.equal(al("", "FooBot", ""), true);
18
- assert.equal(al(r1, "", ""), true);
19
- assert.equal(al(r1, "FooBot", ""), false);
20
- assert.equal(al("", "", ""), true);
21
- });
22
-
23
- test("ID_LineSyntax_Line (missing colon)", () => {
24
- const u = "http://foo.bar/x/y";
25
- assert.equal(al("user-agent: FooBot\ndisallow: /\n", "FooBot", u), false);
26
- assert.equal(al("foo: FooBot\nbar: /\n", "FooBot", u), true);
27
- assert.equal(al("user-agent FooBot\ndisallow /\n", "FooBot", u), false);
28
- });
29
-
30
- test("ID_LineSyntax_Groups (group merging)", () => {
31
- const g =
32
- "allow: /foo/bar/\n\nuser-agent: FooBot\ndisallow: /\nallow: /x/\nuser-agent: BarBot\ndisallow: /\nallow: /y/\n\n\nallow: /w/\nuser-agent: BazBot\n\nuser-agent: FooBot\nallow: /z/\ndisallow: /\n";
33
- assert.equal(al(g, "FooBot", "http://foo.bar/x/b"), true);
34
- assert.equal(al(g, "FooBot", "http://foo.bar/z/d"), true);
35
- assert.equal(al(g, "FooBot", "http://foo.bar/y/c"), false);
36
- assert.equal(al(g, "BarBot", "http://foo.bar/y/c"), true);
37
- assert.equal(al(g, "BarBot", "http://foo.bar/w/a"), true);
38
- assert.equal(al(g, "BarBot", "http://foo.bar/z/d"), false);
39
- assert.equal(al(g, "BazBot", "http://foo.bar/z/d"), true);
40
- assert.equal(al(g, "FooBot", "http://foo.bar/foo/bar/"), false);
41
- assert.equal(al(g, "BarBot", "http://foo.bar/foo/bar/"), false);
42
- assert.equal(al(g, "BazBot", "http://foo.bar/foo/bar/"), false);
43
- });
44
-
45
- test("ID_LineSyntax_Groups_OtherRules", () => {
46
- const o1 = "User-agent: BarBot\nSitemap: https://foo.bar/sitemap\nUser-agent: *\nDisallow: /\n";
47
- assert.equal(al(o1, "FooBot", "http://foo.bar/"), false);
48
- assert.equal(al(o1, "BarBot", "http://foo.bar/"), false);
49
- const o2 = "User-agent: FooBot\nInvalid-Unknown-Line: unknown\nUser-agent: *\nDisallow: /\n";
50
- assert.equal(al(o2, "FooBot", "http://foo.bar/"), false);
51
- assert.equal(al(o2, "BarBot", "http://foo.bar/"), false);
52
- });
53
-
54
- test("ID_REPLineNamesCaseInsensitive", () => {
55
- for (const r of [
56
- "USER-AGENT: FooBot\nALLOW: /x/\nDISALLOW: /\n",
57
- "user-agent: FooBot\nallow: /x/\ndisallow: /\n",
58
- "uSeR-aGeNt: FooBot\nAlLoW: /x/\ndIsAlLoW: /\n",
59
- ]) {
60
- assert.equal(al(r, "FooBot", "http://foo.bar/x/y"), true);
61
- assert.equal(al(r, "FooBot", "http://foo.bar/a/b"), false);
62
- }
63
- });
64
-
65
- test("ID_VerifyValidUserAgentsToObey", () => {
66
- assert.equal(rep.isValidUserAgentToObey("Foobot"), true);
67
- assert.equal(rep.isValidUserAgentToObey("Foobot-Bar"), true);
68
- assert.equal(rep.isValidUserAgentToObey("Foo_Bar"), true);
69
- for (const bad of ["", "ツ", "Foobot*", " Foobot ", "Foobot/2.1", "Foobot Bar"]) {
70
- assert.equal(rep.isValidUserAgentToObey(bad), false, bad);
71
- }
72
- });
73
-
74
- test("ID_UserAgentValueCaseInsensitive", () => {
75
- for (const name of ["FOO BAR", "foo bar", "FoO bAr"]) {
76
- const r = `User-Agent: ${name}\nAllow: /x/\nDisallow: /\n`;
77
- for (const agent of ["Foo", "foo"]) {
78
- assert.equal(al(r, agent, "http://foo.bar/x/y"), true);
79
- assert.equal(al(r, agent, "http://foo.bar/a/b"), false);
80
- }
81
- }
82
- });
83
-
84
- test("GoogleOnly_AcceptUserAgentUpToFirstSpace", () => {
85
- const sp = "User-Agent: *\nDisallow: /\nUser-Agent: Foo Bar\nAllow: /x/\nDisallow: /\n";
86
- assert.equal(al(sp, "Foo", "http://foo.bar/x/y"), true);
87
- assert.equal(al(sp, "Foo Bar", "http://foo.bar/x/y"), false);
88
- });
89
-
90
- test("ID_GlobalGroups_Secondary", () => {
91
- const global = "user-agent: *\nallow: /\nuser-agent: FooBot\ndisallow: /\n";
92
- const only = "user-agent: FooBot\nallow: /\nuser-agent: BarBot\ndisallow: /\nuser-agent: BazBot\ndisallow: /\n";
93
- const u = "http://foo.bar/x/y";
94
- assert.equal(al("", "FooBot", u), true);
95
- assert.equal(al(global, "FooBot", u), false);
96
- assert.equal(al(global, "BarBot", u), true);
97
- assert.equal(al(only, "QuxBot", u), true);
98
- });
99
-
100
- test("ID_AllowDisallow_Value_CaseSensitive", () => {
101
- assert.equal(al("user-agent: FooBot\ndisallow: /x/\n", "FooBot", "http://foo.bar/x/y"), false);
102
- assert.equal(al("user-agent: FooBot\ndisallow: /X/\n", "FooBot", "http://foo.bar/x/y"), true);
103
- });
104
-
105
- test("ID_LongestMatch", () => {
106
- const ux = "http://foo.bar/x/page.html";
107
- assert.equal(al("user-agent: FooBot\ndisallow: /x/page.html\nallow: /x/\n", "FooBot", ux), false);
108
- assert.equal(al("user-agent: FooBot\nallow: /x/page.html\ndisallow: /x/\n", "FooBot", ux), true);
109
- assert.equal(al("user-agent: FooBot\nallow: /x/page.html\ndisallow: /x/\n", "FooBot", "http://foo.bar/x/"), false);
110
- assert.equal(al("user-agent: FooBot\ndisallow: \nallow: \n", "FooBot", ux), true);
111
- assert.equal(al("user-agent: FooBot\ndisallow: /\nallow: /\n", "FooBot", ux), true);
112
- assert.equal(al("user-agent: FooBot\ndisallow: /x\nallow: /x/\n", "FooBot", "http://foo.bar/x"), false);
113
- assert.equal(al("user-agent: FooBot\ndisallow: /x\nallow: /x/\n", "FooBot", "http://foo.bar/x/"), true);
114
- assert.equal(al("user-agent: FooBot\ndisallow: /x/page.html\nallow: /x/page.html\n", "FooBot", ux), true);
115
- assert.equal(al("user-agent: FooBot\nallow: /page\ndisallow: /*.html\n", "FooBot", "http://foo.bar/page.html"), false);
116
- assert.equal(al("user-agent: FooBot\nallow: /page\ndisallow: /*.html\n", "FooBot", "http://foo.bar/page"), true);
117
- assert.equal(al("user-agent: FooBot\nallow: /x/page.\ndisallow: /*.html\n", "FooBot", ux), true);
118
- assert.equal(al("user-agent: FooBot\nallow: /x/page.\ndisallow: /*.html\n", "FooBot", "http://foo.bar/x/y.html"), false);
119
- const grp = "User-agent: *\nDisallow: /x/\nUser-agent: FooBot\nDisallow: /y/\n";
120
- assert.equal(al(grp, "FooBot", "http://foo.bar/x/page"), true);
121
- assert.equal(al(grp, "FooBot", "http://foo.bar/y/page"), false);
122
- });
123
-
124
- test("ID_Encoding", () => {
125
- assert.equal(
126
- al(
127
- "User-agent: FooBot\nDisallow: /\nAllow: /foo/bar?qux=taz&baz=http://foo.bar?tar&par\n",
128
- "FooBot",
129
- "http://foo.bar/foo/bar?qux=taz&baz=http://foo.bar?tar&par",
130
- ),
131
- true,
132
- );
133
- const utf = "User-agent: FooBot\nDisallow: /\nAllow: /foo/bar/ツ\n";
134
- assert.equal(al(utf, "FooBot", "http://foo.bar/foo/bar/%E3%83%84"), true);
135
- assert.equal(al(utf, "FooBot", "http://foo.bar/foo/bar/ツ"), false);
136
- const enc = "User-agent: FooBot\nDisallow: /\nAllow: /foo/bar/%E3%83%84\n";
137
- assert.equal(al(enc, "FooBot", "http://foo.bar/foo/bar/%E3%83%84"), true);
138
- assert.equal(al(enc, "FooBot", "http://foo.bar/foo/bar/ツ"), false);
139
- const baz = "User-agent: FooBot\nDisallow: /\nAllow: /foo/bar/%62%61%7A\n";
140
- assert.equal(al(baz, "FooBot", "http://foo.bar/foo/bar/baz"), false);
141
- assert.equal(al(baz, "FooBot", "http://foo.bar/foo/bar/%62%61%7A"), true);
142
- });
143
-
144
- test("ID_SpecialCharacters", () => {
145
- const s1 = "User-agent: FooBot\nDisallow: /foo/bar/quz\nAllow: /foo/*/qux\n";
146
- assert.equal(al(s1, "FooBot", "http://foo.bar/foo/bar/quz"), false);
147
- assert.equal(al(s1, "FooBot", "http://foo.bar/foo/quz"), true);
148
- assert.equal(al(s1, "FooBot", "http://foo.bar/foo//quz"), true);
149
- assert.equal(al(s1, "FooBot", "http://foo.bar/foo/bax/quz"), true);
150
- const s2 = "User-agent: FooBot\nDisallow: /foo/bar$\nAllow: /foo/bar/qux\n";
151
- assert.equal(al(s2, "FooBot", "http://foo.bar/foo/bar"), false);
152
- assert.equal(al(s2, "FooBot", "http://foo.bar/foo/bar/qux"), true);
153
- assert.equal(al(s2, "FooBot", "http://foo.bar/foo/bar/"), true);
154
- assert.equal(al(s2, "FooBot", "http://foo.bar/foo/bar/baz"), true);
155
- const s3 = "User-agent: FooBot\n# Disallow: /\nDisallow: /foo/quz#qux\nAllow: /\n";
156
- assert.equal(al(s3, "FooBot", "http://foo.bar/foo/bar"), true);
157
- assert.equal(al(s3, "FooBot", "http://foo.bar/foo/quz"), false);
158
- });
159
-
160
- test("GoogleOnly_IndexHTMLisDirectory", () => {
161
- const idx = "User-Agent: *\nAllow: /allowed-slash/index.html\nDisallow: /\n";
162
- assert.equal(al(idx, "foobot", "http://foo.com/allowed-slash/"), true);
163
- assert.equal(al(idx, "foobot", "http://foo.com/allowed-slash/index.htm"), false);
164
- assert.equal(al(idx, "foobot", "http://foo.com/allowed-slash/index.html"), true);
165
- assert.equal(al(idx, "foobot", "http://foo.com/anyother-url"), false);
166
- });
167
-
168
- test("GoogleOnly_LineTooLong", () => {
169
- const maxLine = 2083 * 8;
170
- const maxLen = maxLine - "/x/".length - "disallow: ".length + 1;
171
- const longline = "/x/" + "a".repeat(Math.max(0, maxLen - 3));
172
- const rt = `user-agent: FooBot\ndisallow: ${longline}/qux\n`;
173
- assert.equal(al(rt, "FooBot", "http://foo.bar/fux"), true);
174
- assert.equal(al(rt, "FooBot", `http://foo.bar${longline}/fux`), false);
175
-
176
- const maxLen2 = maxLine - "/x/".length - "allow: ".length + 1;
177
- let la = "/x/";
178
- let lb = "/x/";
179
- while (la.length < maxLen2) {
180
- la += "a";
181
- lb += "b";
182
- }
183
- const rt2 = `user-agent: FooBot\ndisallow: /\nallow: ${la}/qux\nallow: ${lb}/qux\n`;
184
- assert.equal(al(rt2, "FooBot", "http://foo.bar/"), false);
185
- assert.equal(al(rt2, "FooBot", `http://foo.bar${la}/qux`), true);
186
- assert.equal(al(rt2, "FooBot", `http://foo.bar${lb}/fux`), true);
187
- });
188
-
189
- test("GoogleOnly_DocumentationChecks", () => {
190
- const base = "http://foo.bar";
191
- const check = (robots: string, cases: Record<string, boolean>) => {
192
- for (const [p, want] of Object.entries(cases)) assert.equal(al(robots, "FooBot", base + p), want, `${robots.split("\n")[2]} ${p}`);
193
- };
194
- check("user-agent: FooBot\ndisallow: /\nallow: /fish\n", {
195
- "/bar": false, "/fish": true, "/fish.html": true, "/fish/salmon.html": true, "/fishheads": true,
196
- "/fishheads/yummy.html": true, "/fish.html?id=anything": true, "/Fish.asp": false, "/catfish": false, "/?id=fish": false,
197
- });
198
- check("user-agent: FooBot\ndisallow: /\nallow: /fish*\n", {
199
- "/bar": false, "/fish": true, "/fish.html": true, "/fish/salmon.html": true, "/fishheads": true,
200
- "/fishheads/yummy.html": true, "/fish.html?id=anything": true, "/Fish.bar": false, "/catfish": false, "/?id=fish": false,
201
- });
202
- check("user-agent: FooBot\ndisallow: /\nallow: /fish/\n", {
203
- "/fish/": true, "/fish/salmon": true, "/fish/?salmon": true, "/fish/salmon.html": true,
204
- "/fish/?id=anything": true, "/fish": false, "/fish.html": false, "/Fish/Salmon.html": false,
205
- });
206
- check("user-agent: FooBot\ndisallow: /\nallow: /*.php\n", {
207
- "/bar": false, "/filename.php": true, "/folder/filename.php": true, "/folder/filename.php?parameters": true,
208
- "//folder/any.php.file.html": true, "/filename.php/": true, "/index?f=filename.php/": true, "/php/": false,
209
- "/index?php": false, "/windows.PHP": false,
210
- });
211
- check("user-agent: FooBot\ndisallow: /\nallow: /*.php$\n", {
212
- "/bar": false, "/filename.php": true, "/folder/filename.php": true, "/filename.php?parameters": false,
213
- "/filename.php/": false, "/filename.php5": false, "/php/": false, "/filename?php": false, "/aaaphpaaa": false,
214
- "//windows.PHP": false,
215
- });
216
- check("user-agent: FooBot\ndisallow: /\nallow: /fish*.php\n", {
217
- "/fish.php": true, "/fishheads/catfish.php?parameters": true, "/Fish.PHP": false,
218
- });
219
- const ex = "http://example.com";
220
- assert.equal(al("user-agent: FooBot\nallow: /p\ndisallow: /\n", "FooBot", `${ex}/page`), true);
221
- assert.equal(al("user-agent: FooBot\nallow: /folder\ndisallow: /folder\n", "FooBot", `${ex}/folder/page`), true);
222
- assert.equal(al("user-agent: FooBot\nallow: /page\ndisallow: /*.htm\n", "FooBot", `${ex}/page.htm`), false);
223
- assert.equal(al("user-agent: FooBot\nallow: /$\ndisallow: /\n", "FooBot", `${ex}/`), true);
224
- assert.equal(al("user-agent: FooBot\nallow: /$\ndisallow: /\n", "FooBot", `${ex}/page.html`), false);
225
- });
226
-
227
- test("TestGetPathParamsQuery", () => {
228
- const cases: [string, string][] = [
229
- ["", "/"], ["http://www.example.com", "/"], ["http://www.example.com/", "/"], ["http://www.example.com/a", "/a"],
230
- ["http://www.example.com/a/", "/a/"], ["http://www.example.com/a/b?c=http://d.e/", "/a/b?c=http://d.e/"],
231
- ["http://www.example.com/a/b?c=d&e=f#fragment", "/a/b?c=d&e=f"], ["example.com", "/"], ["example.com/", "/"],
232
- ["example.com/a", "/a"], ["example.com/a/", "/a/"], ["example.com/a/b?c=d&e=f#fragment", "/a/b?c=d&e=f"],
233
- ["a", "/"], ["a/", "/"], ["/a", "/a"], ["a/b", "/b"], ["example.com?a", "/?a"], ["example.com/a;b#c", "/a;b"],
234
- ["//a/b/c", "/b/c"],
235
- ];
236
- for (const [input, want] of cases) assert.equal(rep.pathParamsQuery(input), want, input);
237
- });
238
-
239
- test("TestMaybeEscapePattern", () => {
240
- assert.equal(rep.escapePattern("http://www.example.com"), "http://www.example.com");
241
- assert.equal(rep.escapePattern("/a/b/c"), "/a/b/c");
242
- assert.equal(rep.escapePattern(rep.toBytes("á")), "%C3%A1");
243
- assert.equal(rep.escapePattern("%aa"), "%AA");
244
- });
245
-
246
- test("parser: line endings, BOM, sitemap", () => {
247
- const counts = (body: string) => {
248
- const { directives } = rep.parse(body);
249
- const valid = directives.filter((d: { type: string }) => d.type !== "unknown").length;
250
- return { valid, unknown: directives.length - valid, last: directives.at(-1)?.line ?? 0 };
251
- };
252
- for (const body of [
253
- "User-Agent: foo\nAllow: /some/path\nUser-Agent: bar\n\n\nDisallow: /\n",
254
- "User-Agent: foo\r\nAllow: /some/path\r\nUser-Agent: bar\r\n\r\n\r\nDisallow: /\r\n",
255
- "User-Agent: foo\rAllow: /some/path\rUser-Agent: bar\r\r\rDisallow: /\r",
256
- "User-Agent: foo\nAllow: /some/path\nUser-Agent: bar\n\n\nDisallow: /",
257
- "User-Agent: foo\nAllow: /some/path\r\nUser-Agent: bar\n\r\n\nDisallow: /",
258
- ]) {
259
- const c = counts(body);
260
- assert.equal(c.valid, 4);
261
- assert.equal(c.last, 6);
262
- }
263
- assert.deepEqual(counts("User-Agent: foo\nAllow: /AnyValue\n").unknown, 0);
264
- assert.deepEqual(counts("User-Agent: foo\nAllow: /AnyValue\n").valid, 2);
265
- // (Google's partial-BOM cases are about raw byte streams; robots.txt arrives here as decoded text.)
266
- const mid = counts("User-Agent: foo\nAllow: /AnyValue\n");
267
- assert.equal(mid.valid, 1);
268
- assert.equal(mid.unknown, 1);
269
- const sitemap = (body: string) => rep.parse(body).directives.find((d: { type: string }) => d.type === "sitemap")?.value;
270
- assert.equal(sitemap("User-Agent: foo\nAllow: /some/path\nUser-Agent: bar\n\n\nSitemap: http://foo.bar/sitemap.xml\n"), "http://foo.bar/sitemap.xml");
271
- assert.equal(sitemap("Sitemap: http://foo.bar/sitemap.xml\nUser-Agent: foo\nAllow: /some/path\nUser-Agent: bar\n\n\n"), "http://foo.bar/sitemap.xml");
272
- });
273
-
274
- test("RFC 9309 §2.2.1: groups naming the same agent are merged", () => {
275
- const r = "User-agent: ExampleBot\nDisallow: /foo\n\nUser-agent: *\nDisallow: /\n\nUser-agent: ExampleBot\nDisallow: /bar\n";
276
- assert.equal(al(r, "ExampleBot", "https://example.com/foo/x"), false);
277
- assert.equal(al(r, "ExampleBot", "https://example.com/bar/x"), false);
278
- assert.equal(al(r, "ExampleBot", "https://example.com/baz"), true);
279
- assert.equal(al(r, "OtherBot", "https://example.com/baz"), false);
280
- // One group with several user-agent lines.
281
- const multi = "User-agent: a\nUser-agent: b\nDisallow: /x\n";
282
- assert.equal(al(multi, "a", "/x"), false);
283
- assert.equal(al(multi, "b", "/x"), false);
284
- assert.equal(al(multi, "c", "/x"), true);
285
- });
286
-
287
- test("RFC 9309 §2.2.2 / §5.2 examples: longest match, Allow on ties, * and $", () => {
288
- const r = "User-Agent: *\nDisallow: *.gif$\nDisallow: /example/\nAllow: /publications/\n\nUser-Agent: foobot\nDisallow:/\nAllow:/example/page.html\nAllow:/example/allowed.gif\n";
289
- assert.equal(al(r, "foobot", "/example/page.html"), true);
290
- assert.equal(al(r, "foobot", "/example/allowed.gif"), true);
291
- assert.equal(al(r, "foobot", "/example/other.html"), false);
292
- assert.equal(al(r, "barbot", "/x/y.gif"), false);
293
- assert.equal(al(r, "barbot", "/x/y.gif?q"), true);
294
- assert.equal(al(r, "barbot", "/example/z"), false);
295
- assert.equal(al(r, "barbot", "/publications/a"), true);
296
- // /robots.txt itself is always fetchable in practice; the matcher just reports rules.
297
- assert.equal(al("User-agent: *\nAllow: /a\nDisallow: /a\n", "x", "/a"), true);
298
- });
299
-
300
- test("evaluate() reports the deciding line", () => {
301
- const v = rep.evaluate("User-agent: *\nDisallow: /private/\nAllow: /private/ok\n", ["GPTBot"], "https://x.test/private/secret");
302
- assert.equal(v.allowed, false);
303
- assert.equal(v.matchedDirective, "disallow");
304
- assert.equal(v.matchedValue, "/private/");
305
- assert.equal(v.matchedLine, 2);
306
- assert.equal(v.scope, "global");
307
- });
308
-
309
- test("matches() normalizes both sides (rule tester)", () => {
310
- const cases: [string, string, boolean][] = [
311
- ["/fish", "/fish", true], ["/fish", "/fish.html", true], ["/fish", "/Fish.asp", false], ["/fish", "/catfish", false],
312
- ["/fish/", "/fish", false], ["/*.php", "/x.php?p", true], ["/*.php$", "/x.php?p", false], ["/fish*.php", "/Fish.PHP", false],
313
- ];
314
- for (const [p, path, want] of cases) assert.equal(rep.matches(p, path), want, `${p} ${path}`);
315
- assert.equal(rep.matches("/caf%c3%a9", "/café"), true);
316
- });
317
-
318
- test("tokens with digits and dots match their own groups (MJ12bot, archive.org_bot)", () => {
319
- const r = "User-agent: MJ12bot\nDisallow: /\n\nUser-agent: archive.org_bot\nDisallow: /private/\n\nUser-agent: MJ\nAllow: /\n";
320
- assert.equal(al(r, "MJ12bot", "/page"), false);
321
- assert.equal(al(r, "archive.org_bot", "/private/x"), false);
322
- assert.equal(al(r, "archive.org_bot", "/public"), true);
323
- assert.equal(al(r, "MJ", "/page"), true);
324
- assert.equal(rep.extractProductToken("MJ12bot/1.4"), "MJ12bot");
325
- });
326
-
327
- test("tester path encoding: a typed /café matches /caf%C3%A9 rules", () => {
328
- const r = "User-agent: *\nDisallow: /café\n";
329
- assert.equal(rep.evaluate(r, ["x"], "/café", { encodePath: true }).allowed, false);
330
- assert.equal(rep.evaluate(r, ["x"], "https://example.com/caf%c3%a9", { encodePath: true }).allowed, false);
331
- assert.equal(rep.evaluate(r, ["x"], "/cafe", { encodePath: true }).allowed, true);
332
- assert.equal(rep.evaluate("User-agent: *\nDisallow: /a%20b\n", ["x"], "/a b", { encodePath: true }).allowed, false);
333
- // Google's contract (no encoding) is unchanged.
334
- assert.equal(rep.evaluate(r, ["x"], "/café").allowed, true);
335
- });
@@ -1,251 +0,0 @@
1
- /**
2
- * Generation, rule rendering, the bundled directory and the Radar merge.
3
- * Run: node --test src/robots/*.test.ts
4
- */
5
- import assert from "node:assert/strict";
6
- import { readFileSync } from "node:fs";
7
- import { test } from "node:test";
8
-
9
- // @ts-expect-error -- Node's type stripping needs the real .ts extension.
10
- import * as BOTS from "./bots.ts";
11
- // @ts-expect-error -- Node's type stripping needs the real .ts extension.
12
- import * as REP from "./rep.ts";
13
- // @ts-expect-error -- Node's type stripping needs the real .ts extension.
14
- import * as RULES from "./rules.ts";
15
-
16
- const rules = RULES as typeof import("./rules.js");
17
- const rep = REP as typeof import("./rep.js");
18
- const bots = BOTS as typeof import("./bots.js");
19
- type RobotsRule = import("./rules.js").RobotsRule;
20
- type BotEntry = import("./bots.js").BotEntry;
21
-
22
- const site = { siteUrl: "https://example.com" };
23
- let nextId = 0;
24
- const rule = (r: Partial<RobotsRule>): RobotsRule => ({
25
- id: `r${++nextId}`,
26
- name: "Rule",
27
- enabled: true,
28
- agents: ["*"],
29
- directive: "disallow",
30
- kind: "entire_site",
31
- ...r,
32
- });
33
- const config = (r: RobotsRule[], extra: Partial<import("./rules.js").RobotsConfig> = {}) => ({ ...rules.DEFAULT_CONFIG, rules: r, ...extra });
34
-
35
- test("rule kinds render like Coywolf SEO", () => {
36
- const d = (r: Partial<RobotsRule>) => rules.directives(rule(r)).map((l) => `${l.directive}: ${l.value}`);
37
- assert.deepEqual(d({ kind: "entire_site" }), ["Disallow: /"]);
38
- assert.deepEqual(d({ kind: "folder", path: "private" }), ["Disallow: /private/"]);
39
- assert.deepEqual(d({ kind: "prefix", path: "/draft" }), ["Disallow: /draft"]);
40
- assert.deepEqual(d({ kind: "single_page", path: "/a.html", strict: true }), ["Disallow: /a.html$"]);
41
- assert.deepEqual(d({ kind: "exact_url", path: "/search" }), ["Disallow: /search$"]);
42
- assert.deepEqual(d({ kind: "filetype", ext: ".pdf" }), ["Disallow: /*.pdf$"]);
43
- assert.deepEqual(d({ kind: "filetype_in_folder", path: "/dl", ext: "zip" }), ["Disallow: /dl/*.zip$"]);
44
- assert.deepEqual(d({ kind: "contains", path: "/preview=" }), ["Disallow: /*preview="]);
45
- assert.deepEqual(d({ kind: "any_depth", path: "/print/" }), ["Disallow: /*/print/"]);
46
- assert.deepEqual(d({ kind: "query_any" }), ["Disallow: /*?"]);
47
- assert.deepEqual(d({ kind: "query_param", path: "?utm_source" }), ["Disallow: /*?utm_source=", "Disallow: /*&utm_source="]);
48
- assert.deepEqual(d({ kind: "wildcard_prefix", path: "/pa_" }), ["Disallow: /pa_*"]);
49
- assert.deepEqual(d({ kind: "allow_exception", path: "/members", allow: "/members/hi" }), ["Disallow: /members/", "Allow: /members/hi"]);
50
- assert.deepEqual(d({ kind: "folder", path: "/x/", directive: "allow" }), ["Allow: /x/"]);
51
- assert.deepEqual(d({ kind: "custom", path: "/a b#c" }), ["Disallow: /abc"]);
52
- });
53
-
54
- test("validation", () => {
55
- assert.throws(() => rules.validateRule(rule({ name: " " })), /name/);
56
- assert.throws(() => rules.validateRule(rule({ agents: ["Bad Bot"] })), /token/);
57
- assert.throws(() => rules.validateRule(rule({ kind: "folder", path: "" })), /path/);
58
- assert.throws(() => rules.validateRule(rule({ kind: "custom", path: "x" })), /start with/);
59
- assert.throws(() => rules.validateRule(rule({ kind: "filetype", ext: "p.d" })), /extension/);
60
- rules.validateRule(rule({ agents: ["GPTBot", "archive.org_bot", "*"] }));
61
- });
62
-
63
- test("no rules: EmDash's defaults (admin blocked, media and sitemap kept)", () => {
64
- const txt = rules.generate(config([]), site);
65
- assert.match(txt, /User-agent: \*\nAllow: \/_emdash\/api\/media\/\nDisallow: \/_emdash\//);
66
- assert.match(txt, /Sitemap: https:\/\/example\.com\/sitemap\.xml\n$/);
67
- assert.equal(rep.oneAgentAllowed(txt, "Googlebot", "/_emdash/admin"), false);
68
- assert.equal(rep.oneAgentAllowed(txt, "Googlebot", "/_emdash/api/media/file/a.jpg"), true);
69
- assert.equal(rep.oneAgentAllowed(txt, "Googlebot", "/a-post/"), true);
70
- });
71
-
72
- test("bots named in rules still get EmDash's admin block; fully blocked bots don't get the media Allow", () => {
73
- const txt = rules.generate(
74
- config([
75
- rule({ name: "Block AI training crawlers", agents: ["GPTBot", "CCBot"] }),
76
- rule({ name: "Allow search engines", agents: ["Googlebot"], directive: "allow" }),
77
- rule({ name: "No drafts for Bing", agents: ["bingbot"], kind: "folder", path: "/drafts/" }),
78
- ]),
79
- site,
80
- );
81
- for (const bot of ["GPTBot", "CCBot"]) {
82
- assert.equal(rep.oneAgentAllowed(txt, bot, "/"), false, bot);
83
- assert.equal(rep.oneAgentAllowed(txt, bot, "/_emdash/api/media/file/a.jpg"), false, `${bot} media`);
84
- }
85
- assert.equal(rep.oneAgentAllowed(txt, "Googlebot", "/post/"), true);
86
- assert.equal(rep.oneAgentAllowed(txt, "Googlebot", "/_emdash/admin"), false);
87
- assert.equal(rep.oneAgentAllowed(txt, "Googlebot", "/_emdash/api/media/file/a.jpg"), true);
88
- assert.equal(rep.oneAgentAllowed(txt, "bingbot", "/drafts/x"), false);
89
- assert.equal(rep.oneAgentAllowed(txt, "bingbot", "/_emdash/api/content"), false);
90
- assert.equal(rep.oneAgentAllowed(txt, "SomeOtherBot", "/drafts/x"), true);
91
- assert.equal(rep.oneAgentAllowed(txt, "SomeOtherBot", "/_emdash/"), false);
92
- assert.match(txt, /# Block AI training crawlers; discovery files stay readable\nUser-agent: GPTBot\nUser-agent: CCBot\nAllow: \/\.well-known\/\nDisallow: \/\n/);
93
- const gpt = txt.slice(txt.indexOf("User-agent: GPTBot"), txt.indexOf("\n\n", txt.indexOf("User-agent: GPTBot")));
94
- assert.ok(!gpt.includes("/_emdash/"));
95
- for (const bot of ["Googlebot", "bingbot"]) {
96
- const g = txt.slice(txt.indexOf(`User-agent: ${bot}`));
97
- assert.ok(g.slice(0, g.indexOf("\n\n")).includes("Disallow: /_emdash/"), bot);
98
- }
99
- });
100
-
101
- test("blocking everyone keeps media closed too", () => {
102
- const txt = rules.generate(config([rule({ name: "Closed", agents: ["*"] })]), site);
103
- assert.equal(rep.oneAgentAllowed(txt, "AnyBot", "/_emdash/api/media/file/a.jpg"), false);
104
- assert.equal(rep.oneAgentAllowed(txt, "AnyBot", "/"), false);
105
- assert.ok(!txt.includes("Allow: /_emdash/api/media/"));
106
- });
107
-
108
- test("disabled rules, comments off, sitemaps and extra lines", () => {
109
- const txt = rules.generate(
110
- config([rule({ name: "Off", enabled: false, agents: ["GPTBot"] })], {
111
- comments: false,
112
- includeSitemap: false,
113
- allowMedia: false,
114
- sitemaps: ["/news-sitemap.xml", "https://cdn.example.com/s.xml", ""],
115
- extra: "Content-Signal: search=yes, ai-train=no",
116
- }),
117
- site,
118
- );
119
- assert.ok(!txt.includes("GPTBot"));
120
- assert.ok(!txt.includes("#"));
121
- assert.ok(!txt.includes("/sitemap.xml\n"));
122
- assert.ok(!txt.includes("Allow:"));
123
- assert.match(txt, /Content-Signal: search=yes, ai-train=no\n\nSitemap: https:\/\/example\.com\/news-sitemap\.xml\nSitemap: https:\/\/cdn\.example\.com\/s\.xml\n$/);
124
- });
125
-
126
- test("presets only use verified tokens from the bundled directory", () => {
127
- const data = JSON.parse(readFileSync(new URL("./data/bots.json", import.meta.url), "utf8")) as { bots: BotEntry[] };
128
- const verified = new Set(data.bots.filter((b) => b.status === "verified").map((b) => b.token));
129
- for (const preset of rules.PRESETS) for (const agent of preset.agents) assert.ok(verified.has(agent), `${preset.name}: ${agent}`);
130
- });
131
-
132
- test("bundled directory: valid tokens, sources on verified entries, key crawlers verified", () => {
133
- const data = JSON.parse(readFileSync(new URL("./data/bots.json", import.meta.url), "utf8")) as { bots: BotEntry[] };
134
- assert.ok(data.bots.length > 650);
135
- const slugs = new Set<string>();
136
- const tokens = new Set<string>();
137
- for (const b of data.bots) {
138
- assert.ok(!tokens.has(b.token.toLowerCase()), `duplicate token ${b.token}`);
139
- tokens.add(b.token.toLowerCase());
140
- }
141
- for (const b of data.bots) {
142
- assert.ok(!slugs.has(b.slug), `duplicate ${b.slug}`);
143
- slugs.add(b.slug);
144
- assert.match(b.token, /^[A-Za-z0-9._-]+$/, b.slug);
145
- assert.match(b.token, /[A-Za-z]/, b.slug);
146
- if (b.evidence === "operator-docs") assert.doesNotMatch(b.sourceUrl ?? "", /^https?:\/\/[^/]+\/?$/, `${b.slug}: homepage isn't documentation`);
147
- if (b.status === "verified") assert.ok(b.verifiedAt, `${b.slug} verifiedAt`);
148
- if (b.evidence === "operator-docs") assert.match(b.sourceUrl ?? "", /^https?:\/\//, `${b.slug} source`);
149
- }
150
- const byToken = (t: string) => data.bots.find((b) => b.token === t && b.status === "verified") ?? data.bots.find((b) => b.token === t);
151
- for (const t of [
152
- "GPTBot", "OAI-SearchBot", "ChatGPT-User", "ClaudeBot", "Claude-User", "Claude-SearchBot", "Google-Extended", "Googlebot",
153
- "bingbot", "Applebot", "Applebot-Extended", "PerplexityBot", "Perplexity-User", "CCBot", "Bytespider", "Amazonbot",
154
- "meta-externalagent", "DuckAssistBot", "YandexBot", "Baiduspider",
155
- ]) {
156
- assert.equal(byToken(t)?.status, "verified", t);
157
- }
158
- for (const t of ["anthropic-ai", "cohere-ai", "FacebookBot"]) assert.equal(byToken(t)?.status, "unverified", t);
159
- });
160
-
161
- test("deriveToken from Radar patterns", () => {
162
- assert.equal(bots.deriveToken(["Barkrowler/"], "Barkrowler"), "Barkrowler");
163
- assert.equal(bots.deriveToken(["meta-externaltest/1\\.1"], "Meta-ExternalTest"), "meta-externaltest");
164
- assert.equal(bots.deriveToken(["Advailo Kuma"], "Advailo Kuma"), null);
165
- assert.equal(bots.deriveToken([], "AccessSparkBot"), "AccessSparkBot");
166
- assert.equal(bots.deriveToken(["http://yandex.com/bots"], "Yandex Bot"), null);
167
- });
168
-
169
- test("mergeRadar stores only differences and adds new bots unverified", () => {
170
- const base: BotEntry[] = [
171
- { slug: "gptbot", name: "GPTBot", operator: "OpenAI", category: "AI_CRAWLER", description: "d", token: "GPTBot", status: "verified", evidence: "operator-docs", origin: "radar" },
172
- { slug: "gone", name: "Gone", operator: "X", category: "OTHER", description: "", token: "GoneBot", status: "verified", evidence: "user-agent", origin: "radar" },
173
- { slug: "ccbot", name: "CCBot", operator: "Common Crawl", category: "AI_CRAWLER", description: "", token: "CCBot", status: "verified", evidence: "operator-docs", origin: "curated" },
174
- ];
175
- const radar = [
176
- { slug: "gptbot", name: "GPTBot", operator: "OpenAI", category: "AI_CRAWLER", description: "d", userAgentPatterns: ["GPTBot"] },
177
- { slug: "newbot", name: "New Bot", operator: "N", category: "AI_SEARCH", description: "new", userAgentPatterns: ["NewBot/"] },
178
- ];
179
- const first = bots.mergeRadar(base, [], radar, "2026-10-03");
180
- assert.equal(first.added, 1);
181
- assert.equal(first.delisted, 1); // "gone" left Radar; the curated CCBot is not Radar's to delist.
182
- assert.deepEqual(first.writes.map((w) => w.slug).sort(), ["gone", "newbot"]);
183
- const merged = bots.mergeDirectory(base, first.writes);
184
- const nb = merged.find((b) => b.slug === "newbot");
185
- assert.equal(nb?.token, "NewBot");
186
- assert.equal(nb?.status, "unverified");
187
- assert.equal(merged.find((b) => b.slug === "gone")?.delisted, true);
188
-
189
- // Same data next week: nothing to write.
190
- const second = bots.mergeRadar(base, first.writes, radar, "2026-10-10");
191
- assert.equal(second.writes.length, 0);
192
-
193
- // Radar recategorizes GPTBot: one overlay write, token untouched.
194
- const third = bots.mergeRadar(base, first.writes, [{ ...radar[0], category: "AI_SEARCH" }, radar[1]], "2026-10-17");
195
- assert.equal(third.updated, 1);
196
- const after = bots.mergeDirectory(base, [...first.writes, ...third.writes]);
197
- const g = after.find((b) => b.slug === "gptbot");
198
- assert.equal(g?.category, "AI_SEARCH");
199
- assert.equal(g?.token, "GPTBot");
200
- assert.equal(g?.status, "verified");
201
- });
202
-
203
- test("whole-site blocks in any spelling drop the media Allow; /$ doesn't", () => {
204
- for (const v of ["/", "/*", "*", "/**", "/*$"]) assert.equal(rules.blocksWholeSite(v), true, v);
205
- assert.equal(rules.blocksWholeSite("/$"), false);
206
- assert.equal(rules.blocksWholeSite("/private/"), false);
207
- for (const v of ["/*", "*"]) {
208
- const txt = rules.generate(config([rule({ name: "Block", agents: ["GPTBot"], kind: "custom", path: v })]), site);
209
- assert.equal(rep.oneAgentAllowed(txt, "GPTBot", "/_emdash/api/media/file/a.jpg"), false, v);
210
- const g = txt.slice(txt.indexOf("User-agent: GPTBot"));
211
- assert.ok(!g.slice(0, g.indexOf("\n\n")).includes("/_emdash/"), v);
212
- }
213
- const home = rules.generate(config([rule({ name: "Home", agents: ["GPTBot"], kind: "custom", path: "/$" })]), site);
214
- assert.equal(rep.oneAgentAllowed(home, "GPTBot", "/_emdash/api/media/file/a.jpg"), true);
215
- assert.equal(rep.oneAgentAllowed(home, "GPTBot", "/_emdash/admin"), false);
216
- });
217
-
218
- test("line breaks can't inject directives", () => {
219
- const txt = rules.generate(
220
- config(
221
- [
222
- rule({
223
- name: "Evil\nUser-agent: *\nDisallow: /",
224
- description: "x\r\nAllow: /",
225
- agents: ["GPTBot\nDisallow: /", "Good"],
226
- kind: "folder",
227
- path: "/a\nAllow: /b",
228
- }),
229
- ],
230
- { sitemaps: ["/s.xml\nUser-agent: *\nDisallow: /", "https://x.test/a.xml\r\nDisallow: /"] },
231
- ),
232
- { siteUrl: "https://example.com\nDisallow: /" },
233
- );
234
- for (const line of txt.split("\n")) {
235
- assert.ok(!/^Disallow: \/$/.test(line), `injected: ${line}`);
236
- assert.ok(!/^User-agent: \*$/.test(line) || txt.includes("# EmDash admin"), line);
237
- }
238
- assert.ok(!txt.includes("\r"));
239
- assert.equal(rep.oneAgentAllowed(txt, "Bingbot", "/post"), true);
240
- assert.match(txt, /Sitemap: https:\/\/example\.comDisallow:\/s\.xmlUser-agent:\*Disallow:\//);
241
- });
242
-
243
- test("Radar entries merged by token count as their primary entry", () => {
244
- const base: BotEntry[] = [
245
- { slug: "a", name: "A", operator: "", category: "OTHER", description: "", token: "ABot", status: "verified", evidence: "user-agent", origin: "radar", mergedSlugs: ["a-2"] },
246
- ];
247
- const r = bots.mergeRadar(base, [], [{ slug: "a-2", name: "A two", userAgentPatterns: ["ABot"] }], "2026-10-03");
248
- assert.equal(r.writes.length, 0);
249
- assert.equal(r.added, 0);
250
- assert.equal(r.delisted, 0);
251
- });