@coywolf/emdash 0.0.0-stage → 0.35.13

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 (261) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -2
  3. package/package.json +70 -5
  4. package/src/admin/admin-css.ts +57 -0
  5. package/src/admin/ai.tsx +915 -0
  6. package/src/admin/backups.tsx +613 -0
  7. package/src/admin/breadcrumbs.tsx +542 -0
  8. package/src/admin/codeBlocks.tsx +204 -0
  9. package/src/admin/customBlocks.tsx +321 -0
  10. package/src/admin/dirty.ts +20 -0
  11. package/src/admin/discovery.tsx +463 -0
  12. package/src/admin/download.ts +28 -0
  13. package/src/admin/feature-switches.tsx +124 -0
  14. package/src/admin/features.tsx +142 -0
  15. package/src/admin/files.tsx +791 -0
  16. package/src/admin/formUploads.tsx +445 -0
  17. package/src/admin/guides.tsx +18 -0
  18. package/src/admin/headings.tsx +262 -0
  19. package/src/admin/images.tsx +825 -0
  20. package/src/admin/index.tsx +62 -0
  21. package/src/admin/links.tsx +980 -0
  22. package/src/admin/performance.tsx +330 -0
  23. package/src/admin/preview.tsx +63 -0
  24. package/src/admin/redirects-removed.tsx +266 -0
  25. package/src/admin/redirects.tsx +470 -0
  26. package/src/admin/reviews.tsx +232 -0
  27. package/src/admin/robots-bots.tsx +647 -0
  28. package/src/admin/robots-shared.tsx +109 -0
  29. package/src/admin/robots-wizard.tsx +748 -0
  30. package/src/admin/robots.tsx +911 -0
  31. package/src/admin/save-bar.tsx +134 -0
  32. package/src/admin/schema.tsx +1187 -0
  33. package/src/admin/search.tsx +355 -0
  34. package/src/admin/settings-ui.tsx +87 -0
  35. package/src/admin/trash-prompt-core.ts +135 -0
  36. package/src/admin/trash-prompt.tsx +156 -0
  37. package/src/admin/usage.tsx +301 -0
  38. package/src/admin/videos-display.tsx +248 -0
  39. package/src/admin/videos.tsx +1202 -0
  40. package/src/admin/wpImport.tsx +1516 -0
  41. package/src/ai/entities.ts +59 -0
  42. package/src/ai/export.ts +61 -0
  43. package/src/ai/logic.test.ts +187 -0
  44. package/src/ai/logic.ts +606 -0
  45. package/src/ai/pack.ts +121 -0
  46. package/src/ai/prompts.ts +87 -0
  47. package/src/ai/providers.ts +276 -0
  48. package/src/ai/queue.test.ts +97 -0
  49. package/src/ai/routes.ts +359 -0
  50. package/src/ai/store.ts +301 -0
  51. package/src/ai/wikidata.test.ts +184 -0
  52. package/src/ai/wikidata.ts +87 -0
  53. package/src/ai/worker.ts +530 -0
  54. package/src/astro/astro-modules.d.ts +6 -0
  55. package/src/astro/breadcrumbs/Breadcrumbs.astro +129 -0
  56. package/src/astro/breadcrumbs/BreadcrumbsBlock.astro +12 -0
  57. package/src/astro/codeBlocks/CodeBlock.astro +62 -0
  58. package/src/astro/codeBlocks/EmDashCode.astro +61 -0
  59. package/src/astro/customBlocks/CustomBlock.astro +64 -0
  60. package/src/astro/customBlocks/Details.astro +8 -0
  61. package/src/astro/customBlocks/Disclosure.astro +8 -0
  62. package/src/astro/customBlocks/Note.astro +8 -0
  63. package/src/astro/customBlocks/Podcast.astro +8 -0
  64. package/src/astro/customBlocks/Quote.astro +8 -0
  65. package/src/astro/customBlocks/Testimonial.astro +8 -0
  66. package/src/astro/files/FileCard.astro +103 -0
  67. package/src/astro/headings/HeadingBlock.astro +129 -0
  68. package/src/astro/headings/TableOfContents.astro +45 -0
  69. package/src/astro/headings/request.ts +19 -0
  70. package/src/astro/images/ResponsiveImage.astro +60 -0
  71. package/src/astro/index.ts +84 -0
  72. package/src/astro/reviews/CoywolfReview.astro +27 -0
  73. package/src/astro/reviews/Review.astro +49 -0
  74. package/src/astro/search/SearchBox.astro +61 -0
  75. package/src/astro/search/SearchBoxForm.astro +509 -0
  76. package/src/astro/tables/CaptionedTable.astro +72 -0
  77. package/src/astro/videos/CoywolfVideo.astro +448 -0
  78. package/src/backups/download.ts +112 -0
  79. package/src/backups/dump.test.mjs +287 -0
  80. package/src/backups/dump.ts +288 -0
  81. package/src/backups/module.ts +276 -0
  82. package/src/backups/pack.ts +33 -0
  83. package/src/backups/restore.test.mjs +103 -0
  84. package/src/backups/restore.ts +209 -0
  85. package/src/backups/store.ts +409 -0
  86. package/src/breadcrumbs/pack.ts +113 -0
  87. package/src/breadcrumbs/settings.ts +102 -0
  88. package/src/breadcrumbs/stamp.ts +40 -0
  89. package/src/breadcrumbs/trail.ts +123 -0
  90. package/src/codeBlocks/contrast.ts +179 -0
  91. package/src/codeBlocks/hljs.d.ts +5 -0
  92. package/src/codeBlocks/pack.ts +110 -0
  93. package/src/codeBlocks/render.test.ts +152 -0
  94. package/src/codeBlocks/render.ts +304 -0
  95. package/src/codeBlocks/settings.ts +18 -0
  96. package/src/codeBlocks/themes.generated.ts +304 -0
  97. package/src/codeBlocks/themes.ts +114 -0
  98. package/src/core/compose.ts +244 -0
  99. package/src/core/content-url.ts +888 -0
  100. package/src/core/csv.ts +119 -0
  101. package/src/core/d1-batch.ts +65 -0
  102. package/src/core/entry-docs.ts +175 -0
  103. package/src/core/features-module.ts +48 -0
  104. package/src/core/features.ts +392 -0
  105. package/src/core/generation.ts +88 -0
  106. package/src/core/guide-content.ts +166 -0
  107. package/src/core/module.ts +104 -0
  108. package/src/core/read-failures.ts +57 -0
  109. package/src/core/request-memo.ts +71 -0
  110. package/src/core/secrets.ts +83 -0
  111. package/src/core/settings-enhance.ts +74 -0
  112. package/src/core/site.ts +36 -0
  113. package/src/core/storage.ts +27 -0
  114. package/src/customBlocks/pack.ts +260 -0
  115. package/src/customBlocks/render.ts +424 -0
  116. package/src/customBlocks/rich.ts +313 -0
  117. package/src/customBlocks/settings.ts +46 -0
  118. package/src/discovery/build.ts +252 -0
  119. package/src/discovery/feed-build.ts +217 -0
  120. package/src/discovery/feed.ts +172 -0
  121. package/src/discovery/indexnow.ts +114 -0
  122. package/src/discovery/llms.ts +79 -0
  123. package/src/discovery/markdown.ts +294 -0
  124. package/src/discovery/memory-cache.ts +97 -0
  125. package/src/discovery/middleware.ts +186 -0
  126. package/src/discovery/module.ts +353 -0
  127. package/src/discovery/news.ts +99 -0
  128. package/src/discovery/pack.ts +58 -0
  129. package/src/discovery/settings.ts +91 -0
  130. package/src/discovery/urls.ts +35 -0
  131. package/src/env.d.ts +10 -0
  132. package/src/files/card.ts +231 -0
  133. package/src/files/counts.test.ts +114 -0
  134. package/src/files/counts.ts +60 -0
  135. package/src/files/export.ts +44 -0
  136. package/src/files/format.test.ts +93 -0
  137. package/src/files/format.ts +163 -0
  138. package/src/files/module.ts +596 -0
  139. package/src/files/pack.ts +92 -0
  140. package/src/files/r2-rules.test.ts +30 -0
  141. package/src/files/r2-rules.ts +41 -0
  142. package/src/files/range.ts +50 -0
  143. package/src/files/s3.ts +114 -0
  144. package/src/files/serve.ts +141 -0
  145. package/src/files/sigv4.test.ts +64 -0
  146. package/src/files/sigv4.ts +160 -0
  147. package/src/files/site.ts +137 -0
  148. package/src/files/walker.ts +58 -0
  149. package/src/formUploads/lib.ts +266 -0
  150. package/src/formUploads/pack.ts +55 -0
  151. package/src/formUploads/wrap.ts +592 -0
  152. package/src/forms.ts +16 -0
  153. package/src/headings/headings.test.ts +159 -0
  154. package/src/headings/pack.ts +154 -0
  155. package/src/headings/render.ts +139 -0
  156. package/src/headings/settings.ts +117 -0
  157. package/src/headings/slug.ts +68 -0
  158. package/src/headings/stamp.ts +142 -0
  159. package/src/headings/test-hooks.mjs +14 -0
  160. package/src/headings/toc.ts +48 -0
  161. package/src/images/cloudflare.ts +329 -0
  162. package/src/images/lib.ts +221 -0
  163. package/src/images/module.ts +372 -0
  164. package/src/images/pack.ts +804 -0
  165. package/src/images/pending.ts +37 -0
  166. package/src/images/settings.ts +48 -0
  167. package/src/images/setup.ts +192 -0
  168. package/src/images/variants-estimate.ts +162 -0
  169. package/src/images/variants-store.ts +475 -0
  170. package/src/images/variants.ts +311 -0
  171. package/src/index.ts +143 -0
  172. package/src/links/check.ts +101 -0
  173. package/src/links/classify.ts +270 -0
  174. package/src/links/export.ts +59 -0
  175. package/src/links/module.ts +652 -0
  176. package/src/links/pack.ts +43 -0
  177. package/src/links/pt.ts +325 -0
  178. package/src/links/store.ts +704 -0
  179. package/src/middleware.ts +287 -0
  180. package/src/modules.ts +53 -0
  181. package/src/options.ts +66 -0
  182. package/src/pageCache/lib.test.mjs +224 -0
  183. package/src/pageCache/lib.ts +274 -0
  184. package/src/pageCache/pack.ts +240 -0
  185. package/src/pageCache/usage-core.ts +152 -0
  186. package/src/pageCache/usage.ts +262 -0
  187. package/src/pageCache/warm.test.mjs +670 -0
  188. package/src/pageCache/warm.ts +722 -0
  189. package/src/redirects/middleware.ts +169 -0
  190. package/src/redirects/module.ts +124 -0
  191. package/src/redirects/pack.ts +89 -0
  192. package/src/redirects/removed-core.ts +151 -0
  193. package/src/redirects/removed.ts +293 -0
  194. package/src/redirects/rules.ts +355 -0
  195. package/src/redirects/slug-changes.ts +207 -0
  196. package/src/redirects/slug-core.test.ts +50 -0
  197. package/src/redirects/slug-core.ts +49 -0
  198. package/src/redirects/transfer.ts +92 -0
  199. package/src/reviews/lib.ts +624 -0
  200. package/src/reviews/pack.ts +135 -0
  201. package/src/reviews/schema.ts +128 -0
  202. package/src/reviews/settings.ts +26 -0
  203. package/src/robots/bots.ts +321 -0
  204. package/src/robots/data/bots.json +696 -0
  205. package/src/robots/data/verified.json +582 -0
  206. package/src/robots/directory.ts +26 -0
  207. package/src/robots/explain.ts +191 -0
  208. package/src/robots/guided.ts +300 -0
  209. package/src/robots/importer.ts +263 -0
  210. package/src/robots/middleware.ts +151 -0
  211. package/src/robots/module.ts +446 -0
  212. package/src/robots/pack.ts +69 -0
  213. package/src/robots/radar.ts +129 -0
  214. package/src/robots/rep.test.ts +335 -0
  215. package/src/robots/rep.ts +362 -0
  216. package/src/robots/rules.test.ts +251 -0
  217. package/src/robots/rules.ts +883 -0
  218. package/src/robots/transfer.ts +45 -0
  219. package/src/robots/validate.ts +524 -0
  220. package/src/schema/catalog.ts +146 -0
  221. package/src/schema/graph.test.mjs +522 -0
  222. package/src/schema/graph.ts +791 -0
  223. package/src/schema/module.ts +1138 -0
  224. package/src/schema/og-image.ts +100 -0
  225. package/src/schema/pack.ts +58 -0
  226. package/src/search/engine.ts +578 -0
  227. package/src/search/fallback.ts +80 -0
  228. package/src/search/live-cache.ts +116 -0
  229. package/src/search/live-client.ts +770 -0
  230. package/src/search/live-serve.ts +282 -0
  231. package/src/search/module.ts +261 -0
  232. package/src/search/pack.ts +57 -0
  233. package/src/search/query.ts +132 -0
  234. package/src/search/ratelimit-core.ts +118 -0
  235. package/src/search/ratelimit.ts +79 -0
  236. package/src/search/snippet.ts +135 -0
  237. package/src/search/title-index.ts +139 -0
  238. package/src/search/title-match.ts +192 -0
  239. package/src/shared.ts +71 -0
  240. package/src/version.ts +2 -0
  241. package/src/videos/date.ts +40 -0
  242. package/src/videos/engagement.ts +75 -0
  243. package/src/videos/lib.ts +679 -0
  244. package/src/videos/module.ts +1160 -0
  245. package/src/videos/pack.ts +187 -0
  246. package/src/videos/pause.ts +42 -0
  247. package/src/videos/poster.ts +324 -0
  248. package/src/videos/render.ts +336 -0
  249. package/src/videos/store.ts +551 -0
  250. package/src/videos/stream.ts +134 -0
  251. package/src/wpImport/convert.ts +702 -0
  252. package/src/wpImport/guests.ts +329 -0
  253. package/src/wpImport/gutenberg.ts +157 -0
  254. package/src/wpImport/markers.ts +66 -0
  255. package/src/wpImport/pack.ts +451 -0
  256. package/src/wpImport/parents.ts +202 -0
  257. package/src/wpImport/prepare.ts +592 -0
  258. package/src/wpImport/redirects.ts +358 -0
  259. package/src/wpImport/sources.ts +67 -0
  260. package/src/wpImport/stream.ts +160 -0
  261. package/src/wpImport/urls.ts +354 -0
@@ -0,0 +1,335 @@
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
+ });