@intentius/chant 0.49.0 → 0.51.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 (294) hide show
  1. package/dist/audit/catalog.d.ts +13 -3
  2. package/dist/audit/catalog.d.ts.map +1 -1
  3. package/dist/audit/core.d.ts +9 -0
  4. package/dist/audit/core.d.ts.map +1 -1
  5. package/dist/audit/discover.d.ts +6 -0
  6. package/dist/audit/discover.d.ts.map +1 -1
  7. package/dist/audit/fetch.d.ts.map +1 -1
  8. package/dist/audit/report-html.d.ts.map +1 -1
  9. package/dist/audit/report-model.d.ts +6 -0
  10. package/dist/audit/report-model.d.ts.map +1 -1
  11. package/dist/audit/report.d.ts.map +1 -1
  12. package/dist/audit/rules-doc.d.ts.map +1 -1
  13. package/dist/audit/secrets.d.ts +95 -0
  14. package/dist/audit/secrets.d.ts.map +1 -0
  15. package/dist/audit/wrangler.d.ts +33 -0
  16. package/dist/audit/wrangler.d.ts.map +1 -0
  17. package/dist/build.d.ts.map +1 -1
  18. package/dist/cli/commands/audit.d.ts +7 -0
  19. package/dist/cli/commands/audit.d.ts.map +1 -1
  20. package/dist/cli/commands/build.d.ts +23 -0
  21. package/dist/cli/commands/build.d.ts.map +1 -1
  22. package/dist/cli/handlers/build.d.ts.map +1 -1
  23. package/dist/cli/handlers/components.d.ts +31 -0
  24. package/dist/cli/handlers/components.d.ts.map +1 -1
  25. package/dist/cli/handlers/lifecycle.d.ts +11 -0
  26. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  27. package/dist/cli/handlers/op-progress.d.ts +57 -0
  28. package/dist/cli/handlers/op-progress.d.ts.map +1 -0
  29. package/dist/cli/handlers/operator.d.ts +32 -0
  30. package/dist/cli/handlers/operator.d.ts.map +1 -0
  31. package/dist/cli/handlers/run-client.d.ts +21 -1
  32. package/dist/cli/handlers/run-client.d.ts.map +1 -1
  33. package/dist/cli/handlers/run-report.d.ts.map +1 -1
  34. package/dist/cli/handlers/run.d.ts.map +1 -1
  35. package/dist/cli/handlers/scenario.d.ts +39 -0
  36. package/dist/cli/handlers/scenario.d.ts.map +1 -0
  37. package/dist/cli/handlers/search.d.ts +22 -0
  38. package/dist/cli/handlers/search.d.ts.map +1 -1
  39. package/dist/cli/main.d.ts.map +1 -1
  40. package/dist/cli/mcp/op-tools.d.ts.map +1 -1
  41. package/dist/cli/mcp/resource-handlers.d.ts.map +1 -1
  42. package/dist/cli/mcp/server.d.ts +35 -2
  43. package/dist/cli/mcp/server.d.ts.map +1 -1
  44. package/dist/cli/mcp/types.d.ts +29 -1
  45. package/dist/cli/mcp/types.d.ts.map +1 -1
  46. package/dist/cli/registry.d.ts +47 -3
  47. package/dist/cli/registry.d.ts.map +1 -1
  48. package/dist/codegen/docs-rule-scanning.d.ts.map +1 -1
  49. package/dist/components/capability.d.ts +17 -2
  50. package/dist/components/capability.d.ts.map +1 -1
  51. package/dist/components/cli-support.d.ts +7 -0
  52. package/dist/components/cli-support.d.ts.map +1 -1
  53. package/dist/components/component.d.ts +15 -0
  54. package/dist/components/component.d.ts.map +1 -1
  55. package/dist/components/driver.d.ts.map +1 -1
  56. package/dist/components/run-progress.d.ts +7 -5
  57. package/dist/components/run-progress.d.ts.map +1 -1
  58. package/dist/components/verbs/index.d.ts +6 -1
  59. package/dist/components/verbs/index.d.ts.map +1 -1
  60. package/dist/components/verbs/run-agent.d.ts +499 -0
  61. package/dist/components/verbs/run-agent.d.ts.map +1 -0
  62. package/dist/components/verbs/sign.d.ts +30 -0
  63. package/dist/components/verbs/sign.d.ts.map +1 -1
  64. package/dist/composite.d.ts +6 -1
  65. package/dist/composite.d.ts.map +1 -1
  66. package/dist/discovery/collect.d.ts.map +1 -1
  67. package/dist/discovery/fold-import.d.ts +15 -1
  68. package/dist/discovery/fold-import.d.ts.map +1 -1
  69. package/dist/discovery/fold-rank.d.ts +66 -0
  70. package/dist/discovery/fold-rank.d.ts.map +1 -0
  71. package/dist/discovery/index.d.ts +15 -0
  72. package/dist/discovery/index.d.ts.map +1 -1
  73. package/dist/discovery/param-deps.d.ts +17 -0
  74. package/dist/discovery/param-deps.d.ts.map +1 -0
  75. package/dist/fold/fold.d.ts +55 -2
  76. package/dist/fold/fold.d.ts.map +1 -1
  77. package/dist/fold/subset.d.ts +21 -14
  78. package/dist/fold/subset.d.ts.map +1 -1
  79. package/dist/lexicon-schema.d.ts +2 -0
  80. package/dist/lexicon-schema.d.ts.map +1 -1
  81. package/dist/lexicon.d.ts +134 -0
  82. package/dist/lexicon.d.ts.map +1 -1
  83. package/dist/lifecycle/assert-live.d.ts +77 -0
  84. package/dist/lifecycle/assert-live.d.ts.map +1 -0
  85. package/dist/lifecycle/change-set.d.ts +17 -0
  86. package/dist/lifecycle/change-set.d.ts.map +1 -1
  87. package/dist/lifecycle/converge-ledger.d.ts +90 -0
  88. package/dist/lifecycle/converge-ledger.d.ts.map +1 -0
  89. package/dist/lifecycle/deep-diff.d.ts +18 -0
  90. package/dist/lifecycle/deep-diff.d.ts.map +1 -1
  91. package/dist/lifecycle/deep-observe.d.ts +9 -1
  92. package/dist/lifecycle/deep-observe.d.ts.map +1 -1
  93. package/dist/lifecycle/disruption.d.ts +96 -0
  94. package/dist/lifecycle/disruption.d.ts.map +1 -0
  95. package/dist/lifecycle/gate-ledger.d.ts +33 -0
  96. package/dist/lifecycle/gate-ledger.d.ts.map +1 -0
  97. package/dist/lifecycle/git.d.ts +145 -21
  98. package/dist/lifecycle/git.d.ts.map +1 -1
  99. package/dist/lifecycle/index.d.ts +6 -0
  100. package/dist/lifecycle/index.d.ts.map +1 -1
  101. package/dist/lifecycle/lease.d.ts +113 -0
  102. package/dist/lifecycle/lease.d.ts.map +1 -0
  103. package/dist/lifecycle/replay.d.ts +2 -0
  104. package/dist/lifecycle/replay.d.ts.map +1 -1
  105. package/dist/lifecycle/scenario-eval.d.ts +42 -0
  106. package/dist/lifecycle/scenario-eval.d.ts.map +1 -0
  107. package/dist/lifecycle/scenario.d.ts +163 -0
  108. package/dist/lifecycle/scenario.d.ts.map +1 -0
  109. package/dist/lifecycle/symptoms.d.ts +63 -0
  110. package/dist/lifecycle/symptoms.d.ts.map +1 -0
  111. package/dist/lint/output-docs.d.ts +94 -0
  112. package/dist/lint/output-docs.d.ts.map +1 -0
  113. package/dist/lint/post-synth.d.ts +29 -0
  114. package/dist/lint/post-synth.d.ts.map +1 -1
  115. package/dist/lint/rules/__fixtures__/comp/comp003/pass/agent-turn.component.d.ts +11 -0
  116. package/dist/lint/rules/__fixtures__/comp/comp003/pass/agent-turn.component.d.ts.map +1 -0
  117. package/dist/lsp/lexicon-providers.d.ts +7 -0
  118. package/dist/lsp/lexicon-providers.d.ts.map +1 -1
  119. package/dist/op/activity-contract.d.ts +139 -0
  120. package/dist/op/activity-contract.d.ts.map +1 -0
  121. package/dist/op/builders.d.ts +42 -2
  122. package/dist/op/builders.d.ts.map +1 -1
  123. package/dist/op/converge-rule.d.ts +161 -0
  124. package/dist/op/converge-rule.d.ts.map +1 -0
  125. package/dist/op/generate-pipeline.d.ts +39 -0
  126. package/dist/op/generate-pipeline.d.ts.map +1 -0
  127. package/dist/op/index.d.ts +14 -0
  128. package/dist/op/index.d.ts.map +1 -1
  129. package/dist/op/local-executor.d.ts +7 -1
  130. package/dist/op/local-executor.d.ts.map +1 -1
  131. package/dist/op/op-verb-class.d.ts +42 -0
  132. package/dist/op/op-verb-class.d.ts.map +1 -0
  133. package/dist/op/operator.d.ts +128 -0
  134. package/dist/op/operator.d.ts.map +1 -0
  135. package/dist/op/step-output-ref.d.ts +187 -0
  136. package/dist/op/step-output-ref.d.ts.map +1 -0
  137. package/dist/op/types.d.ts +18 -1
  138. package/dist/op/types.d.ts.map +1 -1
  139. package/dist/provenance.d.ts +73 -3
  140. package/dist/provenance.d.ts.map +1 -1
  141. package/dist/runtime-adapter.d.ts +7 -1
  142. package/dist/runtime-adapter.d.ts.map +1 -1
  143. package/dist/serializer.d.ts +18 -0
  144. package/dist/serializer.d.ts.map +1 -1
  145. package/dist/testing.d.ts +23 -2
  146. package/dist/testing.d.ts.map +1 -1
  147. package/dist/toml.d.ts +40 -5
  148. package/dist/toml.d.ts.map +1 -1
  149. package/package.json +1 -1
  150. package/src/audit/catalog.test.ts +1 -1
  151. package/src/audit/catalog.ts +75 -3
  152. package/src/audit/core.ts +9 -0
  153. package/src/audit/discover.ts +29 -2
  154. package/src/audit/fetch.test.ts +216 -3
  155. package/src/audit/fetch.ts +270 -59
  156. package/src/audit/report-html.ts +5 -2
  157. package/src/audit/report-model.ts +9 -0
  158. package/src/audit/report.test.ts +22 -0
  159. package/src/audit/report.ts +3 -2
  160. package/src/audit/rules-doc.ts +2 -0
  161. package/src/audit/secrets.test.ts +303 -0
  162. package/src/audit/secrets.ts +406 -0
  163. package/src/audit/wrangler.test.ts +230 -0
  164. package/src/audit/wrangler.ts +290 -0
  165. package/src/build.ts +8 -3
  166. package/src/cli/command-group.ts +1 -1
  167. package/src/cli/commands/__fixtures__/schemas/sarif-2.1.0.schema.json +2882 -0
  168. package/src/cli/commands/audit.test.ts +215 -1
  169. package/src/cli/commands/audit.ts +86 -17
  170. package/src/cli/commands/build.test.ts +167 -2
  171. package/src/cli/commands/build.ts +114 -23
  172. package/src/cli/handlers/build.ts +2 -0
  173. package/src/cli/handlers/components.test.ts +199 -1
  174. package/src/cli/handlers/components.ts +160 -3
  175. package/src/cli/handlers/graph.test.ts +20 -0
  176. package/src/cli/handlers/graph.ts +10 -1
  177. package/src/cli/handlers/lifecycle.test.ts +90 -0
  178. package/src/cli/handlers/lifecycle.ts +30 -5
  179. package/src/cli/handlers/op-progress.test.ts +202 -0
  180. package/src/cli/handlers/op-progress.ts +192 -0
  181. package/src/cli/handlers/operator.test.ts +255 -0
  182. package/src/cli/handlers/operator.ts +240 -0
  183. package/src/cli/handlers/run-client.test.ts +82 -0
  184. package/src/cli/handlers/run-client.ts +85 -2
  185. package/src/cli/handlers/run-report.test.ts +62 -0
  186. package/src/cli/handlers/run-report.ts +20 -58
  187. package/src/cli/handlers/run.test.ts +144 -0
  188. package/src/cli/handlers/run.ts +40 -18
  189. package/src/cli/handlers/scenario.test.ts +456 -0
  190. package/src/cli/handlers/scenario.ts +330 -0
  191. package/src/cli/handlers/search-drift.test.ts +263 -0
  192. package/src/cli/handlers/search.ts +150 -1
  193. package/src/cli/main.test.ts +23 -0
  194. package/src/cli/main.ts +81 -1
  195. package/src/cli/mcp/op-tools.ts +17 -6
  196. package/src/cli/mcp/resource-handlers.ts +13 -5
  197. package/src/cli/mcp/server.test.ts +265 -2
  198. package/src/cli/mcp/server.ts +84 -7
  199. package/src/cli/mcp/types.ts +27 -1
  200. package/src/cli/registry.ts +47 -3
  201. package/src/codegen/docs-rule-scanning.test.ts +42 -0
  202. package/src/codegen/docs-rule-scanning.ts +25 -2
  203. package/src/components/README.md +7 -0
  204. package/src/components/capability.ts +17 -2
  205. package/src/components/cli-support.test.ts +17 -0
  206. package/src/components/cli-support.ts +13 -1
  207. package/src/components/component-schema.test.ts +32 -0
  208. package/src/components/component.schema.json +6 -0
  209. package/src/components/component.test.ts +21 -0
  210. package/src/components/component.ts +15 -0
  211. package/src/components/driver.ts +12 -4
  212. package/src/components/run-progress.ts +9 -5
  213. package/src/components/verbs/index.ts +6 -1
  214. package/src/components/verbs/run-agent.test.ts +683 -0
  215. package/src/components/verbs/run-agent.ts +786 -0
  216. package/src/components/verbs/sign.test.ts +19 -0
  217. package/src/components/verbs/sign.ts +34 -2
  218. package/src/composite.ts +31 -2
  219. package/src/discovery/collect.ts +11 -2
  220. package/src/discovery/fold-import.test.ts +54 -0
  221. package/src/discovery/fold-import.ts +178 -38
  222. package/src/discovery/fold-rank.test.ts +197 -0
  223. package/src/discovery/fold-rank.ts +346 -0
  224. package/src/discovery/index.ts +16 -1
  225. package/src/discovery/param-deps.test.ts +118 -0
  226. package/src/discovery/param-deps.ts +170 -0
  227. package/src/fold/fold.test.ts +6 -2
  228. package/src/fold/fold.ts +184 -3
  229. package/src/fold/subset.test.ts +82 -19
  230. package/src/fold/subset.ts +79 -41
  231. package/src/lexicon-schema.ts +3 -0
  232. package/src/lexicon.ts +154 -2
  233. package/src/lifecycle/assert-live.test.ts +125 -0
  234. package/src/lifecycle/assert-live.ts +154 -0
  235. package/src/lifecycle/change-set.ts +35 -3
  236. package/src/lifecycle/converge-ledger.test.ts +199 -0
  237. package/src/lifecycle/converge-ledger.ts +179 -0
  238. package/src/lifecycle/deep-diff.test.ts +79 -1
  239. package/src/lifecycle/deep-diff.ts +23 -0
  240. package/src/lifecycle/deep-observe.ts +13 -2
  241. package/src/lifecycle/disruption.test.ts +186 -0
  242. package/src/lifecycle/disruption.ts +224 -0
  243. package/src/lifecycle/gate-ledger.test.ts +103 -0
  244. package/src/lifecycle/gate-ledger.ts +140 -0
  245. package/src/lifecycle/git.test.ts +430 -0
  246. package/src/lifecycle/git.ts +446 -84
  247. package/src/lifecycle/index.ts +6 -0
  248. package/src/lifecycle/lease.test.ts +343 -0
  249. package/src/lifecycle/lease.ts +270 -0
  250. package/src/lifecycle/replay.test.ts +25 -0
  251. package/src/lifecycle/replay.ts +11 -3
  252. package/src/lifecycle/scenario-eval.test.ts +199 -0
  253. package/src/lifecycle/scenario-eval.ts +158 -0
  254. package/src/lifecycle/scenario.test.ts +195 -0
  255. package/src/lifecycle/scenario.ts +321 -0
  256. package/src/lifecycle/symptoms.test.ts +116 -0
  257. package/src/lifecycle/symptoms.ts +126 -0
  258. package/src/lint/output-docs.test.ts +220 -0
  259. package/src/lint/output-docs.ts +204 -0
  260. package/src/lint/post-synth.test.ts +97 -0
  261. package/src/lint/post-synth.ts +45 -0
  262. package/src/lint/rules/__fixtures__/comp/comp003/pass/agent-turn.component.ts +26 -0
  263. package/src/lint/rules/comp/comp.test.ts +49 -1
  264. package/src/lint/rules/evl001-non-literal-expression.test.ts +8 -3
  265. package/src/lint/rules/evl001-non-literal-expression.ts +6 -6
  266. package/src/lsp/lexicon-providers.test.ts +44 -0
  267. package/src/lsp/lexicon-providers.ts +11 -1
  268. package/src/op/activity-contract.test.ts +180 -0
  269. package/src/op/activity-contract.ts +278 -0
  270. package/src/op/builders-exports.test.ts +17 -1
  271. package/src/op/builders.ts +59 -5
  272. package/src/op/converge-rule.test.ts +179 -0
  273. package/src/op/converge-rule.ts +311 -0
  274. package/src/op/generate-pipeline.test.ts +53 -0
  275. package/src/op/generate-pipeline.ts +99 -0
  276. package/src/op/index.ts +30 -0
  277. package/src/op/local-executor.test.ts +92 -0
  278. package/src/op/local-executor.ts +52 -10
  279. package/src/op/local-output.ts +1 -1
  280. package/src/op/op-verb-class.test.ts +126 -0
  281. package/src/op/op-verb-class.ts +115 -0
  282. package/src/op/operator.test.ts +346 -0
  283. package/src/op/operator.ts +213 -0
  284. package/src/op/step-output-ref.test.ts +334 -0
  285. package/src/op/step-output-ref.ts +453 -0
  286. package/src/op/types.ts +18 -1
  287. package/src/provenance.test.ts +151 -4
  288. package/src/provenance.ts +118 -4
  289. package/src/runtime-adapter.ts +31 -10
  290. package/src/serializer.ts +18 -0
  291. package/src/testing.test.ts +89 -2
  292. package/src/testing.ts +63 -3
  293. package/src/toml.test.ts +157 -384
  294. package/src/toml.ts +371 -5
package/dist/toml.d.ts CHANGED
@@ -1,9 +1,44 @@
1
1
  /**
2
- * TOML emitter and parser — re-exports from split modules.
2
+ * Lightweight TOML parser (#446).
3
3
  *
4
- * Import from here for the public API:
5
- * import { emitTOML, parseTOML } from "@intentius/chant/toml";
4
+ * Written for the audit engine's spike: is there a pure, dependency-free way
5
+ * to parse a config format the engine can't read today? TOML fits — it is a
6
+ * fully-specified, static (no macros/interpolation/imports) grammar, so a
7
+ * hand-rolled tokenizer + recursive-descent parser covers it without any
8
+ * runtime surface a Workers sandbox would reject (no `eval`, no native
9
+ * modules, no filesystem/network).
10
+ *
11
+ * Covers the subset of TOML v1.0 that real-world deploy configs
12
+ * (`wrangler.toml`, `Cargo.toml`, `pyproject.toml`, `netlify.toml`) actually
13
+ * use: basic/literal strings (single-line), integers, floats, booleans,
14
+ * arrays (including multi-line), inline tables, dotted keys, standard tables
15
+ * (`[a.b]`), and arrays of tables (`[[a.b]]`).
16
+ *
17
+ * Deliberately NOT a full spec implementation:
18
+ * - Multi-line strings (`"""..."""`, `'''...'''`) are read as a single
19
+ * opaque string body (no line-ending backslash trimming); good enough to
20
+ * not crash, not spec-perfect for continuation whitespace.
21
+ * - Dates/times are returned as their raw source text (a string), not a
22
+ * `Date` — none of the checks built on this parser need calendar math.
23
+ * - A dotted-key path element must be a bare word or a plain quoted string;
24
+ * mixing exotic key shapes mid-path is not supported.
25
+ * These gaps only matter for exotic TOML; they don't affect the shapes the
26
+ * audit checks read (`[vars]`, `[[kv_namespaces]]`, `[env.NAME]`, …).
27
+ */
28
+ export declare class TomlParseError extends Error {
29
+ }
30
+ type TomlValue = string | number | boolean | TomlValue[] | {
31
+ [k: string]: TomlValue;
32
+ };
33
+ type TomlTable = {
34
+ [k: string]: TomlValue;
35
+ };
36
+ /**
37
+ * Parse a TOML document into a plain nested object. Throws {@link TomlParseError}
38
+ * on malformed input — callers that scan arbitrary repo files should wrap the
39
+ * call in a try/catch (matching the rest of the audit engine's tolerance for
40
+ * unparseable content).
6
41
  */
7
- export { emitTOML, type EmitTOMLOptions } from "./toml-emit.js";
8
- export { parseTOML } from "./toml-parse.js";
42
+ export declare function parseTOML(input: string): TomlTable;
43
+ export {};
9
44
  //# sourceMappingURL=toml.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toml.d.ts","sourceRoot":"","sources":["../src/toml.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"toml.d.ts","sourceRoot":"","sources":["../src/toml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,qBAAa,cAAe,SAAQ,KAAK;CAAG;AAqK5C,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AACtF,KAAK,SAAS,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAgJ5C;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CA8BlD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.49.0",
3
+ "version": "0.51.0",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -91,7 +91,7 @@ describe("RULE_CATALOG (aggregated: core static + lexicon-contributed, #687)", (
91
91
  expect(m.remediation.length, `${id} has remediation`).toBeGreaterThan(0);
92
92
  expect(["merge-worthy", "report-only"]).toContain(m.tier);
93
93
  expect(["deterministic", "guidance"]).toContain(m.fixKind);
94
- expect(["security", "correctness", "best-practice"], `${id} has a valid category`).toContain(m.category);
94
+ expect(["security", "correctness", "best-practice", "efficiency"], `${id} has a valid category`).toContain(m.category);
95
95
  }
96
96
  });
97
97
 
@@ -26,10 +26,13 @@ export type FixKind = "deterministic" | "guidance";
26
26
  * What kind of finding this is — orthogonal to `tier` (fix confidence). Lets the
27
27
  * report say "N security, M best-practice, K correctness" instead of branding
28
28
  * everything "security." `security` = exposure/vuln/supply-chain; `correctness`
29
- * = a structural bug (broken reference, invalid schema, never-runs); everything
30
- * else is `best-practice` (hygiene/style/deprecation/reliability).
29
+ * = a structural bug (broken reference, invalid schema, never-runs); `efficiency`
30
+ * (#444) = waste — redundant work, an oversized execution environment,
31
+ * unintended fan-out, unbounded retention — never a safety/correctness issue,
32
+ * so it is excluded from the security and correctness tallies; everything else
33
+ * is `best-practice` (hygiene/style/deprecation/reliability).
31
34
  */
32
- export type Category = "security" | "correctness" | "best-practice";
35
+ export type Category = "security" | "correctness" | "best-practice" | "efficiency";
33
36
 
34
37
  export interface Authority {
35
38
  name: string;
@@ -96,6 +99,34 @@ export const K8S_SECRETS: Authority = {
96
99
  name: "Kubernetes — Good practices for Secrets",
97
100
  url: "https://kubernetes.io/docs/concepts/security/secrets-good-practices/",
98
101
  };
102
+ export const GH_SECRET_SCANNING: Authority = {
103
+ name: "GitHub — About secret scanning",
104
+ url: "https://docs.github.com/en/code-security/secret-scanning/introduction/about-secret-scanning",
105
+ };
106
+ export const SCORECARD_VULN: Authority = {
107
+ name: "OSSF Scorecard — Vulnerabilities",
108
+ url: "https://github.com/ossf/scorecard/blob/main/docs/checks.md#vulnerabilities",
109
+ };
110
+ export const CF_WORKERS_DEV: Authority = {
111
+ name: "Cloudflare Workers — workers.dev",
112
+ url: "https://developers.cloudflare.com/workers/configuration/routing/workers-dev/",
113
+ };
114
+ export const CF_SECRETS: Authority = {
115
+ name: "Cloudflare Workers — Secrets",
116
+ url: "https://developers.cloudflare.com/workers/configuration/secrets/",
117
+ };
118
+ export const CF_ROUTES: Authority = {
119
+ name: "Cloudflare Workers — Routes",
120
+ url: "https://developers.cloudflare.com/workers/configuration/routing/routes/",
121
+ };
122
+ export const CF_ENVIRONMENTS: Authority = {
123
+ name: "Cloudflare Workers — Wrangler environments",
124
+ url: "https://developers.cloudflare.com/workers/wrangler/configuration/#environments",
125
+ };
126
+ export const CF_STATIC_ASSETS: Authority = {
127
+ name: "Cloudflare Workers — Static assets",
128
+ url: "https://developers.cloudflare.com/workers/static-assets/",
129
+ };
99
130
 
100
131
  function meta(
101
132
  id: string,
@@ -127,6 +158,22 @@ const G = "guidance" as const;
127
158
  export const RULE_CATEGORY: Record<string, Category> = {
128
159
  COR020: "correctness",
129
160
  EXT001: "correctness",
161
+ SEC001: "security",
162
+ SEC002: "security",
163
+ SEC003: "security",
164
+ SEC004: "security",
165
+ SEC005: "security",
166
+ SEC006: "security",
167
+ SEC007: "security",
168
+ SEC008: "security",
169
+ SEC009: "security",
170
+ SEC010: "security",
171
+ WRG001: "security",
172
+ WRG002: "security",
173
+ WRG003: "best-practice",
174
+ WRG004: "security",
175
+ WRG005: "security",
176
+ WRG006: "security",
130
177
  };
131
178
 
132
179
  /**
@@ -139,6 +186,31 @@ export const RULE_CATEGORY: Record<string, Category> = {
139
186
  export const RULE_CATALOG: Record<string, RuleMeta> = {
140
187
  COR020: meta("COR020", M, G, "Circular resource dependency", "Break the dependency cycle between resources."),
141
188
  EXT001: meta("EXT001", M, G, "Extension constraint violation", "Fix the cross-property constraint flagged by the cfn-lint extension schema."),
189
+
190
+ // Secrets & credentials (#443) — lexicon-independent: `secrets.ts` scans the
191
+ // raw text of every candidate file, so these ids apply regardless of which
192
+ // (if any) audit lexicons are installed. `fixKind` is `guidance`: removing
193
+ // a hardcoded credential and rotating it needs a human, never an auto-fix.
194
+ SEC001: meta("SEC001", M, G, "AWS access key ID found", "Remove the key from source, rotate it in IAM, and load it from a secret store or environment variable instead.", [GH_SECRET_SCANNING]),
195
+ SEC002: meta("SEC002", M, G, "AWS secret access key found", "Remove the key from source, rotate it in IAM, and load it from a secret store or environment variable instead.", [GH_SECRET_SCANNING]),
196
+ SEC003: meta("SEC003", M, G, "GitHub token found", "Remove the token from source and revoke it at github.com/settings/tokens; use a GitHub Actions secret instead.", [GH_SECRET_SCANNING]),
197
+ SEC004: meta("SEC004", M, G, "Slack token found", "Remove the token from source and revoke it in the Slack app's OAuth settings.", [GH_SECRET_SCANNING]),
198
+ SEC005: meta("SEC005", M, G, "Google API key found", "Remove the key from source and regenerate it in the Google Cloud Console credentials page.", [GH_SECRET_SCANNING]),
199
+ SEC006: meta("SEC006", M, G, "Stripe live secret key found", "Remove the key from source and roll it in the Stripe dashboard immediately — this is a live-mode key.", [GH_SECRET_SCANNING]),
200
+ SEC007: meta("SEC007", M, G, "Private key block found", "Remove the private key from source, rotate the keypair, and load the key from a secret store instead.", [GH_SECRET_SCANNING]),
201
+ SEC008: meta("SEC008", M, G, "Bearer/authorization token found", "Remove the token from source; if it's long-lived, revoke and reissue it via the issuing service.", [GH_SECRET_SCANNING]),
202
+ SEC009: meta("SEC009", M, G, "Credentials embedded in a connection string", "Move the username/password out of the URI into a secret store, and rotate the credential.", [GH_SECRET_SCANNING]),
203
+ SEC010: meta("SEC010", M, G, "High-entropy string — possible secret", "Confirm whether this is a live credential; if so, remove it from source and rotate it. If it's a false positive, suppress with a `chant-audit-ignore` comment or an allowlist entry.", [GH_SECRET_SCANNING]),
204
+
205
+ // Wrangler config audit (#446) — lexicon-independent, same shape as the SEC
206
+ // family above: `wrangler.ts` scans every `wrangler.toml` it finds
207
+ // regardless of which (if any) audit lexicons are installed.
208
+ WRG001: meta("WRG001", M, G, "Production environment exposed on *.workers.dev", "Remove workers_dev (or set it to false) for this environment and rely on its custom domain/route instead of the shared public subdomain.", [CF_WORKERS_DEV]),
209
+ WRG002: meta("WRG002", M, G, "Credential-shaped key stored in [vars]", "Move the value out of [vars] and into `wrangler secret put <name>` so it isn't committed to source or visible in `wrangler dev`/the dashboard.", [CF_SECRETS]),
210
+ WRG003: meta("WRG003", R, G, "Observability explicitly disabled", "Set observability.enabled = true (or remove the override) so Workers Logs are recorded for this deployment."),
211
+ WRG004: meta("WRG004", M, G, "Unscoped wildcard route", "Scope the route pattern to the intended zone (e.g. \"example.com/*\") instead of a bare \"*\" or \"*/*\" that matches every zone on the account.", [CF_ROUTES]),
212
+ WRG005: meta("WRG005", M, G, "Non-production environment shares a data store with production", "Give the non-production environment its own KV namespace/R2 bucket/D1 database id instead of reusing production's.", [CF_ENVIRONMENTS]),
213
+ WRG006: meta("WRG006", M, G, "Static assets served from the project root", "Point [site].bucket / [assets].directory at a dedicated public output folder, not the project root, so non-public files (config, source maps, .git) aren't served.", [CF_STATIC_ASSETS]),
142
214
  };
143
215
 
144
216
  /**
package/src/audit/core.ts CHANGED
@@ -73,6 +73,15 @@ export interface AuditFinding {
73
73
  lexicon: string;
74
74
  /** Optional entity (e.g. job name) the check attached. */
75
75
  entity?: string;
76
+ /** 1-based line number within `file`, when the check can pin one (e.g. secrets detection, #443). */
77
+ line?: number;
78
+ /**
79
+ * A redaction-safe fingerprint of the flagged value (see
80
+ * `secrets.ts`'s `fingerprintSecret`), so a finding can be referenced —
81
+ * for an allowlist entry, for dedup — without ever carrying the value
82
+ * itself.
83
+ */
84
+ fingerprint?: string;
76
85
  }
77
86
 
78
87
  /**
@@ -104,6 +104,27 @@ function isDockerfileName(name: string): boolean {
104
104
  return name === "Dockerfile" || name.startsWith("Dockerfile.") || name.endsWith(".Dockerfile") || name.endsWith(".dockerfile");
105
105
  }
106
106
 
107
+ /**
108
+ * Filenames the secrets scan (#443) wants that no lexicon otherwise reads —
109
+ * dotenv files and key/cert material. Included in `isCandidatePath` so both
110
+ * the local walk and the remote fetch pick them up; `classifyFiles` doesn't
111
+ * claim them for any lexicon, they just ride along for `scanForSecrets`.
112
+ */
113
+ function isSecretBearingName(name: string): boolean {
114
+ if (/^\.env(\..+)?$/i.test(name)) return true;
115
+ return /\.(pem|key|crt|cer|pfx|p12)$/i.test(name);
116
+ }
117
+
118
+ /**
119
+ * `wrangler.toml` (#446) — Cloudflare Workers' declarative deploy config.
120
+ * Native TOML, so it rides along the same way secret-bearing filenames do:
121
+ * `wrangler.ts` reads it directly (no lexicon plugin, no authoring surface),
122
+ * so it only needs to be a candidate path, not a `detectTemplate` entry.
123
+ */
124
+ function isWranglerConfigName(name: string): boolean {
125
+ return name === "wrangler.toml";
126
+ }
127
+
107
128
  /** Split a possibly multi-document YAML string into per-doc parsed objects. */
108
129
  function parseDocs(content: string): Record<string, unknown>[] {
109
130
  const docs: Record<string, unknown>[] = [];
@@ -231,8 +252,12 @@ export interface DetectPlugin {
231
252
  detectTemplate?: (data: unknown) => boolean;
232
253
  }
233
254
 
234
- /** Which CI lexicon a path belongs to (by location — content can't disambiguate github vs forgejo). */
235
- function ciLexiconForPath(path: string): AuditLexicon | undefined {
255
+ /**
256
+ * Which CI lexicon a path belongs to (by location — content can't disambiguate
257
+ * github vs forgejo). Exported for the fetch module: known-path lexicons stay a
258
+ * direct path match even in search-first (large-repo) discovery (#520).
259
+ */
260
+ export function ciLexiconForPath(path: string): AuditLexicon | undefined {
236
261
  if (/^\.github\/workflows\/[^/]+\.ya?ml$/.test(path)) return "github";
237
262
  if (/^\.forgejo\/workflows\/[^/]+\.ya?ml$/.test(path)) return "forgejo";
238
263
  if (path === ".gitlab-ci.yml") return "gitlab";
@@ -248,6 +273,8 @@ export function isCandidatePath(path: string): boolean {
248
273
  if (ciLexiconForPath(path)) return true;
249
274
  if (isDockerfileName(name)) return true;
250
275
  if (name === "Chart.yaml") return true;
276
+ if (isSecretBearingName(name)) return true;
277
+ if (isWranglerConfigName(name)) return true;
251
278
  return /\.(ya?ml|json|template)$/i.test(name);
252
279
  }
253
280
 
@@ -54,15 +54,28 @@ function gitTreeMock(files: Record<string, string>, sizes: Record<string, number
54
54
  return { impl, calls };
55
55
  }
56
56
 
57
+ /** A full root-level tree page (>=100 entries) — the "large repo" signal `listTreeGitLab` probes for. */
58
+ const LARGE_ROOT_PAGE = Array.from({ length: 100 }, (_, i) => ({ path: `dir${i}`, type: "tree" }));
59
+ /** A small root-level tree page (<100 entries) — the "small repo" signal, keeps the walk. */
60
+ const SMALL_ROOT_PAGE: Array<{ path: string; type: string }> = [];
61
+
57
62
  /**
58
63
  * GitLab mock for authenticated search-based discovery. `searchMap` maps search
59
64
  * term → array of blob paths the search API returns. `files` maps path → content.
60
- * Pass `token` to fetchRepoFiles when using this mock so the code takes the
61
- * search path (unauthenticated calls fall back to BFS).
65
+ * The root tree probe reports a large repo by default (`rootPage`
66
+ * overridable) so these mocks exercise the search path; pass `token` to
67
+ * `fetchRepoFiles` too, since search additionally requires authentication.
62
68
  */
63
- function gitlabMock(searchMap: Record<string, string[]>, files: Record<string, string>) {
69
+ function gitlabMock(searchMap: Record<string, string[]>, files: Record<string, string>, rootPage: Array<{ path: string; type: string }> = LARGE_ROOT_PAGE) {
64
70
  const impl = (async (url: string | URL | Request) => {
65
71
  const u = String(url);
72
+ if (u.includes("/repository/tree")) {
73
+ const params = new URL(u).searchParams;
74
+ const path = params.get("path") ?? "";
75
+ const page = Number(params.get("page") ?? "1");
76
+ const entries = path === "" && page === 1 ? rootPage : [];
77
+ return new Response(JSON.stringify(entries), { status: 200 });
78
+ }
66
79
  if (u.includes("/search")) {
67
80
  const params = new URL(u).searchParams;
68
81
  const term = params.get("search") ?? "";
@@ -112,6 +125,85 @@ function gitlabBfsMock(
112
125
  return { impl };
113
126
  }
114
127
 
128
+ /**
129
+ * A GitHub-shaped mock for large-repo (search-first) discovery: `fillerCount`
130
+ * inflates the recursive tree past `LARGE_REPO_TREE_ENTRIES` so `listTree`
131
+ * switches strategies; `searchMap` maps a bare search term (no `repo:` qualifier)
132
+ * to the paths GitHub's code search returns for it, paginated 100/page.
133
+ */
134
+ function githubCodeSearchMock(fillerCount: number, files: Record<string, string>, searchMap: Record<string, string[]>) {
135
+ const calls: Array<{ url: string }> = [];
136
+ const impl = (async (url: string | URL | Request) => {
137
+ const u = String(url);
138
+ calls.push({ url: u });
139
+ if (u.includes("/git/trees/")) {
140
+ const filler = Array.from({ length: fillerCount }, (_, i) => ({ path: `filler/file${i}.md`, type: "blob", size: 10 }));
141
+ const real = Object.keys(files).map((path) => ({ path, type: "blob", size: files[path].length }));
142
+ return new Response(JSON.stringify({ tree: [...filler, ...real] }), { status: 200 });
143
+ }
144
+ if (u.includes("/search/code")) {
145
+ const params = new URL(u).searchParams;
146
+ const term = (params.get("q") ?? "").replace(/\s*repo:.*/, "");
147
+ const page = Number(params.get("page") ?? "1");
148
+ const all = searchMap[term] ?? [];
149
+ const start = (page - 1) * 100;
150
+ const items = all.slice(start, start + 100).map((path) => ({ path }));
151
+ return new Response(JSON.stringify({ items, total_count: all.length }), { status: 200 });
152
+ }
153
+ const rawm = u.match(/raw\.githubusercontent\.com\/[^/]+\/[^/]+\/[^/]+\/(.+)$/);
154
+ if (rawm) {
155
+ const path = decodeURIComponent(rawm[1]);
156
+ if (files[path] === undefined) return new Response("not found", { status: 404 });
157
+ return new Response(files[path], { status: 200 });
158
+ }
159
+ const cm = u.match(/\/contents\/(.+?)\?/);
160
+ if (cm) {
161
+ const path = decodeURIComponent(cm[1]);
162
+ if (files[path] === undefined) return new Response("not found", { status: 404 });
163
+ return new Response(JSON.stringify({ path, type: "file", content: b64(files[path]), encoding: "base64" }), { status: 200 });
164
+ }
165
+ if (/\/repos\/[^/]+\/[^/]+(\?|$)/.test(u)) return new Response(JSON.stringify({ default_branch: "main" }), { status: 200 });
166
+ return new Response("not found", { status: 404 });
167
+ }) as unknown as typeof fetch;
168
+ return { impl, calls };
169
+ }
170
+
171
+ /**
172
+ * A Forgejo/Gitea-shaped mock for large-repo discovery. `searchMap` maps a bare
173
+ * search term to the paths its (best-effort, `{ok, data}`-enveloped) search
174
+ * endpoint returns, paginated 100/page.
175
+ */
176
+ function forgejoCodeSearchMock(fillerCount: number, files: Record<string, string>, searchMap: Record<string, string[]>) {
177
+ const calls: Array<{ url: string }> = [];
178
+ const impl = (async (url: string | URL | Request) => {
179
+ const u = String(url);
180
+ calls.push({ url: u });
181
+ if (u.includes("/git/trees/")) {
182
+ const filler = Array.from({ length: fillerCount }, (_, i) => ({ path: `filler/file${i}.md`, type: "blob", size: 10 }));
183
+ const real = Object.keys(files).map((path) => ({ path, type: "blob", size: files[path].length }));
184
+ return new Response(JSON.stringify({ tree: [...filler, ...real] }), { status: 200 });
185
+ }
186
+ if (u.includes("/search")) {
187
+ const params = new URL(u).searchParams;
188
+ const term = params.get("q") ?? "";
189
+ const page = Number(params.get("page") ?? "1");
190
+ const all = searchMap[term] ?? [];
191
+ const start = (page - 1) * 100;
192
+ const data = all.slice(start, start + 100).map((path) => ({ path }));
193
+ return new Response(JSON.stringify({ ok: true, data }), { status: 200 });
194
+ }
195
+ const cm = u.match(/\/contents\/(.+?)\?/);
196
+ if (cm) {
197
+ const path = decodeURIComponent(cm[1]);
198
+ if (files[path] === undefined) return new Response("not found", { status: 404 });
199
+ return new Response(JSON.stringify({ path, type: "file", content: b64(files[path]), encoding: "base64" }), { status: 200 });
200
+ }
201
+ if (/\/repos\/[^/]+\/[^/]+(\?|$)/.test(u)) return new Response(JSON.stringify({ default_branch: "main" }), { status: 200 });
202
+ return new Response("not found", { status: 404 });
203
+ }) as unknown as typeof fetch;
204
+ return { impl, calls };
205
+ }
206
+
115
207
  describe("parseRepoUrl", () => {
116
208
  test("rejects non-https", () => {
117
209
  expect(() => parseRepoUrl("http://github.com/o/r")).toThrow(FetchError);
@@ -285,12 +377,133 @@ describe("fetchRepoFiles", () => {
285
377
  expect(files.map((f) => f.path)).toContain(".gitlab-ci.yml");
286
378
  });
287
379
 
380
+ // ── Strategy selection: small repo → walk, large repo → search (#520) ────
381
+
382
+ test("gitlab: a small repo uses the walk even when a token is present (no search call)", async () => {
383
+ // The root page has one blob and no filler dirs — well under the large-repo
384
+ // threshold — so the walk is used regardless of the token, and the search
385
+ // API is never called.
386
+ const rootPage = [{ path: ".gitlab-ci.yml", type: "blob" }];
387
+ const { impl } = gitlabMock({ "stages:": [".gitlab-ci.yml"] }, { ".gitlab-ci.yml": "stages:\n - build\n" }, rootPage);
388
+ const calls: string[] = [];
389
+ const spy = (async (url: string | URL | Request, init?: RequestInit) => {
390
+ calls.push(String(url));
391
+ return impl(url, init);
392
+ }) as unknown as typeof fetch;
393
+ const files = await fetchRepoFiles("https://gitlab.com/acme/widgets", { fetchImpl: spy, token: "tok" });
394
+ expect(files.map((f) => f.path)).toEqual([".gitlab-ci.yml"]);
395
+ expect(calls.some((c) => c.includes("/search"))).toBe(false);
396
+ });
397
+
398
+ test("gitlab: a large repo without a token falls back to the BFS walk (search needs auth)", async () => {
399
+ const dirEntries = {
400
+ "": [{ path: ".gitlab-ci.yml", type: "blob" as const }, ...Array.from({ length: 99 }, (_, i) => ({ path: `dir${i}`, type: "tree" as const }))],
401
+ };
402
+ const { impl } = gitlabBfsMock(dirEntries, { ".gitlab-ci.yml": "stages:\n - build\n" });
403
+ const files = await fetchRepoFiles("https://gitlab.com/acme/widgets", { fetchImpl: impl }); // no token
404
+ expect(files.map((f) => f.path)).toContain(".gitlab-ci.yml");
405
+ });
406
+
407
+ test("gitlab: search failure on a large repo falls back to the BFS walk (#520)", async () => {
408
+ const dirEntries = {
409
+ "": [{ path: ".gitlab-ci.yml", type: "blob" as const }, ...Array.from({ length: 99 }, (_, i) => ({ path: `dir${i}`, type: "tree" as const }))],
410
+ };
411
+ const { impl: bfsImpl } = gitlabBfsMock(dirEntries, { ".gitlab-ci.yml": "stages:\n - build\n" });
412
+ const impl = (async (url: string | URL | Request, init?: RequestInit) => {
413
+ if (String(url).includes("/search")) return new Response("rate limited", { status: 429 });
414
+ return bfsImpl(url, init);
415
+ }) as unknown as typeof fetch;
416
+ const files = await fetchRepoFiles("https://gitlab.com/acme/widgets", { fetchImpl: impl, token: "tok" });
417
+ expect(files.map((f) => f.path)).toContain(".gitlab-ci.yml");
418
+ });
419
+
420
+ test("github: a small repo never calls the code search API", async () => {
421
+ const { impl, calls } = gitTreeMock({ ".github/workflows/ci.yml": CI_YAML, "k8s/deploy.yaml": "apiVersion: apps/v1\nkind: Deployment\n" });
422
+ await fetchRepoFiles("https://github.com/acme/widgets", { fetchImpl: impl });
423
+ expect(calls.some((c) => c.url.includes("/search/code"))).toBe(false);
424
+ });
425
+
426
+ test("github: a large repo switches to per-lexicon search; known-path CI bypasses search entirely", async () => {
427
+ const files = { ".github/workflows/ci.yml": CI_YAML, "infra/eks.yaml": "apiVersion: v1\nkind: ConfigMap\n" };
428
+ const { impl, calls } = githubCodeSearchMock(600, files, { apiVersion: ["infra/eks.yaml"] });
429
+ const found = await fetchRepoFiles("https://github.com/acme/monorepo", { fetchImpl: impl, maxFiles: 100 });
430
+ const paths = found.map((f) => f.path);
431
+ expect(paths).toContain(".github/workflows/ci.yml");
432
+ expect(paths).toContain("infra/eks.yaml");
433
+ // The workflow came straight from the tree already in hand — no search
434
+ // query was needed (or issued) to find it.
435
+ expect(calls.some((c) => c.url.includes("/search/code") && c.url.includes("workflows"))).toBe(false);
436
+ });
437
+
438
+ test("github: search results paginate past 100 until a short page", async () => {
439
+ const manyPaths = Array.from({ length: 150 }, (_, i) => `k8s/deploy${i}.yaml`);
440
+ const files: Record<string, string> = {};
441
+ for (const p of manyPaths) files[p] = "apiVersion: apps/v1\nkind: Deployment\n";
442
+ const { impl, calls } = githubCodeSearchMock(600, files, { apiVersion: manyPaths });
443
+ const found = await fetchRepoFiles("https://github.com/acme/monorepo", { fetchImpl: impl, maxFiles: 1000 });
444
+ expect(found.length).toBe(150);
445
+ const searchCalls = calls.filter((c) => c.url.includes("/search/code") && c.url.includes("q=apiVersion"));
446
+ expect(searchCalls.some((c) => c.url.includes("page=1"))).toBe(true);
447
+ expect(searchCalls.some((c) => c.url.includes("page=2"))).toBe(true);
448
+ });
449
+
450
+ test("github: search failure (rate limit) on a large repo falls back to the full tree", async () => {
451
+ const files = { ".github/workflows/ci.yml": CI_YAML, "infra/eks.yaml": "apiVersion: v1\nkind: ConfigMap\n" };
452
+ const { impl: base } = githubCodeSearchMock(600, files, {});
453
+ const impl = (async (url: string | URL | Request, init?: RequestInit) => {
454
+ if (String(url).includes("/search/code")) return new Response("rate limited", { status: 403 });
455
+ return base(url, init);
456
+ }) as unknown as typeof fetch;
457
+ const found = await fetchRepoFiles("https://github.com/acme/monorepo", { fetchImpl: impl, maxFiles: 1000 });
458
+ const paths = found.map((f) => f.path);
459
+ expect(paths).toContain(".github/workflows/ci.yml");
460
+ expect(paths).toContain("infra/eks.yaml");
461
+ });
462
+
288
463
  test("forgejo (codeberg): gitea tree + contents", async () => {
289
464
  const { impl } = gitTreeMock({ ".forgejo/workflows/ci.yml": CI_YAML });
290
465
  const files = await fetchRepoFiles("https://codeberg.org/acme/widgets", { fetchImpl: impl });
291
466
  expect(files.map((f) => f.path)).toEqual([".forgejo/workflows/ci.yml"]);
292
467
  });
293
468
 
469
+ test("forgejo: a large repo switches to search; known-path CI bypasses search entirely", async () => {
470
+ const files = { ".forgejo/workflows/ci.yml": CI_YAML, "charts/app/Chart.yaml": "apiVersion: v2\nname: app\nversion: 1.0.0\n" };
471
+ const { impl, calls } = forgejoCodeSearchMock(600, files, { "apiVersion: v2": ["charts/app/Chart.yaml"] });
472
+ const found = await fetchRepoFiles("https://codeberg.org/acme/monorepo", { fetchImpl: impl, maxFiles: 100 });
473
+ const paths = found.map((f) => f.path);
474
+ expect(paths).toContain(".forgejo/workflows/ci.yml");
475
+ expect(paths).toContain("charts/app/Chart.yaml");
476
+ expect(calls.some((c) => c.url.includes("/search") && c.url.includes("workflows"))).toBe(false);
477
+ });
478
+
479
+ test("forgejo: search paginates past 100 until a short page", async () => {
480
+ const manyPaths = Array.from({ length: 120 }, (_, i) => `k8s/deploy${i}.yaml`);
481
+ const files: Record<string, string> = {};
482
+ for (const p of manyPaths) files[p] = "apiVersion: apps/v1\nkind: Deployment\n";
483
+ const { impl, calls } = forgejoCodeSearchMock(600, files, { apiVersion: manyPaths });
484
+ const found = await fetchRepoFiles("https://codeberg.org/acme/monorepo", { fetchImpl: impl, maxFiles: 1000 });
485
+ expect(found.length).toBe(120);
486
+ const searchCalls = calls.filter((c) => c.url.includes("/search") && c.url.includes("q=apiVersion"));
487
+ expect(searchCalls.some((c) => c.url.includes("page=1"))).toBe(true);
488
+ expect(searchCalls.some((c) => c.url.includes("page=2"))).toBe(true);
489
+ });
490
+
491
+ test("forgejo: an instance with no code search (404) falls back to the full tree", async () => {
492
+ // Forgejo's code-search availability/shape is undocumented (#520) — an
493
+ // instance without a code indexer, or with a different API shape, must
494
+ // still produce a full audit via the fallback, not an empty/failed one.
495
+ const files = { ".forgejo/workflows/ci.yml": CI_YAML, "charts/app/Chart.yaml": "apiVersion: v2\nname: app\nversion: 1.0.0\n" };
496
+ const { impl: base } = forgejoCodeSearchMock(600, files, {});
497
+ const impl = (async (url: string | URL | Request, init?: RequestInit) => {
498
+ if (String(url).includes("/search")) return new Response("not found", { status: 404 });
499
+ return base(url, init);
500
+ }) as unknown as typeof fetch;
501
+ const found = await fetchRepoFiles("https://codeberg.org/acme/monorepo", { fetchImpl: impl, maxFiles: 1000 });
502
+ const paths = found.map((f) => f.path);
503
+ expect(paths).toContain(".forgejo/workflows/ci.yml");
504
+ expect(paths).toContain("charts/app/Chart.yaml");
505
+ });
506
+
294
507
  test("an empty repo returns []", async () => {
295
508
  const { impl } = gitTreeMock({});
296
509
  const files = await fetchRepoFiles("https://github.com/acme/empty", { fetchImpl: impl });