@intentius/chant 0.124.84 → 0.124.86

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 (254) hide show
  1. package/dist/bundle-check.d.ts +102 -0
  2. package/dist/bundle-check.d.ts.map +1 -0
  3. package/dist/bundle-check.js +310 -0
  4. package/dist/chant-install.d.ts +100 -0
  5. package/dist/chant-install.d.ts.map +1 -0
  6. package/dist/chant-install.js +158 -0
  7. package/dist/ci-commit.d.ts +19 -6
  8. package/dist/ci-commit.d.ts.map +1 -1
  9. package/dist/ci-commit.js +23 -4
  10. package/dist/ci-evidence-jobs.d.ts +54 -0
  11. package/dist/ci-evidence-jobs.d.ts.map +1 -0
  12. package/dist/ci-evidence-jobs.js +55 -0
  13. package/dist/ci-image.d.ts +274 -0
  14. package/dist/ci-image.d.ts.map +1 -0
  15. package/dist/ci-image.js +635 -0
  16. package/dist/ci-login.d.ts +150 -0
  17. package/dist/ci-login.d.ts.map +1 -0
  18. package/dist/ci-login.js +240 -0
  19. package/dist/ci-product.d.ts +16 -0
  20. package/dist/ci-product.d.ts.map +1 -1
  21. package/dist/ci-product.js +17 -0
  22. package/dist/cli/commands/import-index.js +2 -2
  23. package/dist/cli/handlers/build.d.ts +8 -0
  24. package/dist/cli/handlers/build.d.ts.map +1 -1
  25. package/dist/cli/handlers/build.js +22 -4
  26. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  27. package/dist/cli/handlers/ci-check.js +57 -2
  28. package/dist/cli/handlers/ci-evidence.d.ts +3 -0
  29. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
  30. package/dist/cli/handlers/ci-evidence.js +171 -0
  31. package/dist/cli/handlers/components.js +3 -3
  32. package/dist/cli/handlers/dead-guards.d.ts +3 -0
  33. package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
  34. package/dist/cli/handlers/dead-guards.js +35 -0
  35. package/dist/cli/handlers/graph.js +4 -4
  36. package/dist/cli/handlers/lifecycle.d.ts +2 -1
  37. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  38. package/dist/cli/handlers/lifecycle.js +5 -4
  39. package/dist/cli/handlers/local-chant.d.ts +16 -0
  40. package/dist/cli/handlers/local-chant.d.ts.map +1 -0
  41. package/dist/cli/handlers/local-chant.js +109 -0
  42. package/dist/cli/handlers/operator.js +2 -2
  43. package/dist/cli/handlers/search.js +5 -5
  44. package/dist/cli/main.d.ts.map +1 -1
  45. package/dist/cli/main.js +38 -0
  46. package/dist/cli/parse-args.d.ts.map +1 -1
  47. package/dist/cli/parse-args.js +28 -0
  48. package/dist/cli/registry.d.ts +16 -0
  49. package/dist/cli/registry.d.ts.map +1 -1
  50. package/dist/components/check-hooks.d.ts +49 -0
  51. package/dist/components/check-hooks.d.ts.map +1 -1
  52. package/dist/components/check-hooks.js +64 -4
  53. package/dist/components/check-steps.d.ts +17 -0
  54. package/dist/components/check-steps.d.ts.map +1 -1
  55. package/dist/components/check-steps.js +37 -5
  56. package/dist/components/product-pipeline.d.ts +23 -0
  57. package/dist/components/product-pipeline.d.ts.map +1 -1
  58. package/dist/components/product-pipeline.js +6 -2
  59. package/dist/components/product-plan.d.ts +137 -0
  60. package/dist/components/product-plan.d.ts.map +1 -0
  61. package/dist/components/product-plan.js +143 -0
  62. package/dist/components/release-compile.d.ts.map +1 -1
  63. package/dist/components/release-compile.js +2 -2
  64. package/dist/config.d.ts +39 -1
  65. package/dist/config.d.ts.map +1 -1
  66. package/dist/config.js +35 -3
  67. package/dist/dead-guards.d.ts +82 -0
  68. package/dist/dead-guards.d.ts.map +1 -0
  69. package/dist/dead-guards.js +436 -0
  70. package/dist/discovery/files.d.ts +3 -1
  71. package/dist/discovery/files.d.ts.map +1 -1
  72. package/dist/discovery/files.js +5 -3
  73. package/dist/drift-issue.d.ts +152 -0
  74. package/dist/drift-issue.d.ts.map +1 -0
  75. package/dist/drift-issue.js +167 -0
  76. package/dist/floor-table.d.ts +30 -0
  77. package/dist/floor-table.d.ts.map +1 -0
  78. package/dist/floor-table.data.d.ts +3 -0
  79. package/dist/floor-table.data.d.ts.map +1 -0
  80. package/dist/floor-table.data.js +178 -0
  81. package/dist/floor-table.js +56 -0
  82. package/dist/forge-flags.d.ts +90 -0
  83. package/dist/forge-flags.d.ts.map +1 -0
  84. package/dist/forge-flags.js +184 -0
  85. package/dist/lexicon.d.ts +69 -0
  86. package/dist/lexicon.d.ts.map +1 -1
  87. package/dist/lifecycle/gated-op.d.ts +7 -1
  88. package/dist/lifecycle/gated-op.d.ts.map +1 -1
  89. package/dist/lifecycle/gated-op.js +7 -4
  90. package/dist/local-chant.d.ts +98 -0
  91. package/dist/local-chant.d.ts.map +1 -0
  92. package/dist/local-chant.js +307 -0
  93. package/dist/op/activities/predict-behaviour.js +2 -2
  94. package/dist/op/op-waves-evidence-spec.d.ts +13 -0
  95. package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
  96. package/dist/op/op-waves-evidence-spec.js +21 -0
  97. package/dist/op/op-waves-evidence.d.ts +38 -0
  98. package/dist/op/op-waves-evidence.d.ts.map +1 -0
  99. package/dist/op/op-waves-evidence.js +57 -0
  100. package/dist/op/op-waves-run.d.ts +4 -0
  101. package/dist/op/op-waves-run.d.ts.map +1 -1
  102. package/dist/op/op-waves-run.js +24 -1
  103. package/dist/op/op-waves.d.ts +17 -1
  104. package/dist/op/op-waves.d.ts.map +1 -1
  105. package/dist/op/op-waves.js +23 -0
  106. package/dist/op/schedule-overdue.d.ts +41 -9
  107. package/dist/op/schedule-overdue.d.ts.map +1 -1
  108. package/dist/op/schedule-overdue.js +154 -25
  109. package/dist/plan-summary.d.ts +25 -0
  110. package/dist/plan-summary.d.ts.map +1 -1
  111. package/dist/plan-summary.js +31 -0
  112. package/dist/pr-plan-note.d.ts +35 -0
  113. package/dist/pr-plan-note.d.ts.map +1 -1
  114. package/dist/pr-plan-note.js +10 -0
  115. package/dist/pr-post.d.ts +23 -0
  116. package/dist/pr-post.d.ts.map +1 -1
  117. package/dist/pr-post.js +125 -3
  118. package/dist/release-floors.d.ts +31 -1
  119. package/dist/release-floors.d.ts.map +1 -1
  120. package/dist/release-floors.js +31 -1
  121. package/dist/state-migration.d.ts +24 -0
  122. package/dist/state-migration.d.ts.map +1 -1
  123. package/dist/state-migration.js +100 -5
  124. package/dist/wave-runtime.mjs +305 -298
  125. package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
  126. package/dist/workspace/lexicon-outputs.js +21 -7
  127. package/dist/workspace/reason-codes.d.ts +3 -0
  128. package/dist/workspace/reason-codes.d.ts.map +1 -1
  129. package/dist/workspace/reason-codes.js +4 -0
  130. package/dist/workspace/ref-gate.schema.json +85 -0
  131. package/dist/workspace/search-contract.d.ts +1 -1
  132. package/dist/workspace/search-contract.d.ts.map +1 -1
  133. package/dist/workspace/trust/check-evidence-report.d.ts +51 -0
  134. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
  135. package/dist/workspace/trust/check-evidence-report.js +102 -0
  136. package/dist/workspace/trust/check-evidence.d.ts +126 -0
  137. package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
  138. package/dist/workspace/trust/check-evidence.js +237 -0
  139. package/dist/workspace/trust/local-evidence.d.ts +120 -0
  140. package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
  141. package/dist/workspace/trust/local-evidence.js +259 -0
  142. package/dist/workspace/trust/policy.d.ts +84 -0
  143. package/dist/workspace/trust/policy.d.ts.map +1 -1
  144. package/dist/workspace/trust/policy.js +94 -1
  145. package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
  146. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
  147. package/dist/workspace/trust/ref-gate-cli.js +234 -0
  148. package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
  149. package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
  150. package/dist/workspace/trust/ref-gate-fixture.js +97 -0
  151. package/dist/workspace/trust/ref-gate.d.ts +187 -0
  152. package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
  153. package/dist/workspace/trust/ref-gate.js +430 -0
  154. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  155. package/dist/workspace/trust/trust-files.js +18 -1
  156. package/package.json +1 -1
  157. package/src/bundle-check.test.ts +140 -0
  158. package/src/bundle-check.ts +352 -0
  159. package/src/chant-install.test.ts +112 -0
  160. package/src/chant-install.ts +179 -0
  161. package/src/ci-commit.test.ts +45 -0
  162. package/src/ci-commit.ts +38 -4
  163. package/src/ci-evidence-jobs.ts +67 -0
  164. package/src/ci-image.test.ts +506 -0
  165. package/src/ci-image.ts +822 -0
  166. package/src/ci-login.test.ts +235 -0
  167. package/src/ci-login.ts +307 -0
  168. package/src/ci-product.ts +18 -0
  169. package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
  170. package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
  171. package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
  172. package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
  173. package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
  174. package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
  175. package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
  176. package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
  177. package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
  178. package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
  179. package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
  180. package/src/cli/commands/import-index.ts +2 -2
  181. package/src/cli/handlers/build-source-dir.test.ts +64 -0
  182. package/src/cli/handlers/build.ts +21 -4
  183. package/src/cli/handlers/ci-check.ts +56 -3
  184. package/src/cli/handlers/ci-evidence.ts +162 -0
  185. package/src/cli/handlers/components.ts +3 -3
  186. package/src/cli/handlers/dead-guards.ts +37 -0
  187. package/src/cli/handlers/graph.ts +4 -4
  188. package/src/cli/handlers/lifecycle.ts +5 -4
  189. package/src/cli/handlers/local-chant.ts +106 -0
  190. package/src/cli/handlers/operator.ts +2 -2
  191. package/src/cli/handlers/search.ts +5 -5
  192. package/src/cli/main.test.ts +7 -0
  193. package/src/cli/main.ts +38 -0
  194. package/src/cli/parse-args.ts +21 -0
  195. package/src/cli/registry.ts +16 -0
  196. package/src/components/check-evidence-stage.test.ts +80 -0
  197. package/src/components/check-hooks.ts +84 -4
  198. package/src/components/check-local-evidence-stage.test.ts +141 -0
  199. package/src/components/check-steps.ts +56 -6
  200. package/src/components/product-pipeline.ts +28 -3
  201. package/src/components/product-plan.test.ts +87 -0
  202. package/src/components/product-plan.ts +226 -0
  203. package/src/components/release-compile.ts +2 -2
  204. package/src/config.ts +44 -3
  205. package/src/dead-guards.test.ts +206 -0
  206. package/src/dead-guards.ts +446 -0
  207. package/src/discovery/files.ts +5 -3
  208. package/src/drift-issue-bundle.test.ts +31 -0
  209. package/src/drift-issue.test.ts +206 -0
  210. package/src/drift-issue.ts +274 -0
  211. package/src/fit-note.test.ts +44 -0
  212. package/src/floor-table.data.ts +180 -0
  213. package/src/floor-table.ts +77 -0
  214. package/src/forge-flags.test.ts +110 -0
  215. package/src/forge-flags.ts +208 -0
  216. package/src/gate-decision-bundle.test.ts +1 -0
  217. package/src/lexicon.ts +68 -0
  218. package/src/lifecycle/gated-op.ts +10 -5
  219. package/src/local-chant.e2e.test.ts +94 -0
  220. package/src/local-chant.test.ts +162 -0
  221. package/src/local-chant.ts +341 -0
  222. package/src/op/activities/predict-behaviour.ts +2 -2
  223. package/src/op/op-waves-evidence-spec.ts +24 -0
  224. package/src/op/op-waves-evidence.test.ts +130 -0
  225. package/src/op/op-waves-evidence.ts +57 -0
  226. package/src/op/op-waves-run.ts +25 -1
  227. package/src/op/op-waves.ts +31 -1
  228. package/src/op/schedule-overdue.test.ts +85 -0
  229. package/src/op/schedule-overdue.ts +162 -26
  230. package/src/plan-summary.ts +40 -0
  231. package/src/pr-plan-note.ts +34 -0
  232. package/src/pr-post-plan-note.test.ts +146 -0
  233. package/src/pr-post.ts +127 -3
  234. package/src/release-floors.ts +44 -1
  235. package/src/stage-hooks-bundle.test.ts +1 -0
  236. package/src/state-migration.test.ts +52 -1
  237. package/src/state-migration.ts +107 -5
  238. package/src/workspace/lexicon-outputs.ts +23 -6
  239. package/src/workspace/reason-codes.test.ts +3 -0
  240. package/src/workspace/reason-codes.ts +4 -0
  241. package/src/workspace/ref-gate.schema.json +85 -0
  242. package/src/workspace/trust/check-evidence-report.ts +106 -0
  243. package/src/workspace/trust/check-evidence.test.ts +133 -0
  244. package/src/workspace/trust/check-evidence.ts +257 -0
  245. package/src/workspace/trust/local-evidence.test.ts +127 -0
  246. package/src/workspace/trust/local-evidence.ts +266 -0
  247. package/src/workspace/trust/policy.ts +134 -1
  248. package/src/workspace/trust/ref-gate-cli.ts +244 -0
  249. package/src/workspace/trust/ref-gate-fixture.ts +125 -0
  250. package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
  251. package/src/workspace/trust/ref-gate.test.ts +247 -0
  252. package/src/workspace/trust/ref-gate.ts +538 -0
  253. package/src/workspace/trust/trust-files.test.ts +16 -0
  254. package/src/workspace/trust/trust-files.ts +41 -1
@@ -17,7 +17,7 @@ import type { LexiconPlugin, ResourceMetadata } from "../../lexicon";
17
17
  import type { ObservationDepth } from "../../lifecycle/types";
18
18
  import { formatUnobserved, type RootRead } from "../../observation";
19
19
  import { readChantPackageVersion } from "../../package-version";
20
- import { loadChantConfig, matchesDeclaredEnvironment } from "../../config";
20
+ import { loadChantConfig, matchesDeclaredEnvironment, resolveSourceDir } from "../../config";
21
21
  import { collectBuildRootContributors, loadPlugins, resolveProjectLexicons } from "../plugins";
22
22
  import { declaredBuildRootContributors, mergeDeclaredBuildRoots, withLexiconEdges } from "./declared-graph";
23
23
  import { parseCountBy, countGroups, countsJson, formatCounts, groupMembers, hasManyTerraformRoots, type CountBy } from "./search-count";
@@ -135,7 +135,7 @@ export async function runSearch(ctx: CommandContext): Promise<number> {
135
135
  // Why --check-snapshot had nothing to check against, for --json (#4367).
136
136
  let driftUnavailable: string | undefined;
137
137
  if (args.index !== undefined) {
138
- const answered = await indexAnswer(ctx, String(args.index), projectPath, resolve(args.src ?? config.sourceDir ?? "."), config);
138
+ const answered = await indexAnswer(ctx, String(args.index), projectPath, resolveSourceDir(resolve("."), config, args.src), config);
139
139
  if ("error" in answered) return refuse(answered.error);
140
140
  ir = answered.ir;
141
141
  source = answered.source;
@@ -155,7 +155,7 @@ export async function runSearch(ctx: CommandContext): Promise<number> {
155
155
  // root's blocks are entities only once its root is rendered, and an
156
156
  // entity the build never produced is never observed.
157
157
  const buildRoots = collectBuildRootContributors(plugins, config as unknown as Record<string, unknown>, projectPath);
158
- const buildResult = await build(resolve(args.src ?? config.sourceDir ?? "."), plugins.map((p) => p.serializer), undefined, {
158
+ const buildResult = await build(resolveSourceDir(resolve("."), config, args.src), plugins.map((p) => p.serializer), undefined, {
159
159
  buildRoots,
160
160
  config: config as unknown as Record<string, unknown>,
161
161
  });
@@ -305,7 +305,7 @@ export async function runSearch(ctx: CommandContext): Promise<number> {
305
305
  const declared =
306
306
  stacks.length > 0
307
307
  ? await buildDeclaredPerStack(stacks, projectPath, (g, entities) => withLexiconEdges(g, plugins, entities))
308
- : await declaredGraph(ctx, projectPath, resolve(args.src ?? config.sourceDir ?? "."), plugins);
308
+ : await declaredGraph(ctx, projectPath, resolveSourceDir(resolve("."), config, args.src), plugins);
309
309
  if (!declared) return refuse(BUILD_ROOT_FAILED);
310
310
  declaredForDrift = declared;
311
311
  // Carry the NOT-OBSERVED half of the tri-state (#1089) onto the rows, so a
@@ -352,7 +352,7 @@ export async function runSearch(ctx: CommandContext): Promise<number> {
352
352
  // stays pending: only its attributes change.
353
353
  ir = { ...ir, nodes: carryAnnotations(ir.nodes, annotations) };
354
354
  } else {
355
- const declared = await declaredGraph(ctx, projectPath, resolve(args.src ?? config.sourceDir ?? "."));
355
+ const declared = await declaredGraph(ctx, projectPath, resolveSourceDir(resolve("."), config, args.src));
356
356
  if (!declared) return refuse(BUILD_ROOT_FAILED);
357
357
  ir = declared;
358
358
  }
@@ -388,6 +388,12 @@ describe("parseArgs", () => {
388
388
  expect(result.url).toBe("https://github.com/org/repo/pull/1");
389
389
  });
390
390
 
391
+ test("parses the ref gate's --ref, --hook, --git-dir and --ledger (#4867)", () => {
392
+ const result = parseArgs(["workspace", "ref-gate", "install", "--hook", "pre-receive", "--git-dir", "/srv/x.git", "--ref", "refs/heads/main", "--ledger", "l.jsonl"]);
393
+ expect(result).toMatchObject({ hook: "pre-receive", gitDir: "/srv/x.git", ref: "refs/heads/main", ledger: "l.jsonl" });
394
+ expect(() => parseArgs(["workspace", "ref-gate", "check", "--ref"])).toThrow(/--ref needs a value/);
395
+ });
396
+
391
397
  test("parses --rule (repeated) and --reason for an override (#3760)", () => {
392
398
  const result = parseArgs(["approve", "policy-override", "prod", "--rule", "no-drop", "--rule", "no-lock", "--reason", "the table is empty"]);
393
399
  expect(result.rules).toEqual(["no-drop", "no-lock"]);
@@ -878,6 +884,7 @@ describe("workspace init and ls (#2534)", () => {
878
884
  "workspace points",
879
885
  "workspace promote",
880
886
  "workspace records",
887
+ "workspace ref-gate",
881
888
  "workspace run",
882
889
  "workspace runs",
883
890
  "workspace search",
package/src/cli/main.ts CHANGED
@@ -273,6 +273,15 @@ CI:
273
273
  perRun, with no forge token or cloud credentials in
274
274
  their environment. Writes check-hooks.json under
275
275
  --output (default .chant/check); exits 1 when one failed.
276
+ ci evidence sign --check-id <id>[,<id>...] [--at <rev>] [--base <rev>] [--no-push]
277
+ Sign that each named check passed at --at, with the
278
+ runner key in CHANT_RUNNER_KEY or --key, and keep it on
279
+ chant/lifecycle by the commit's tree. With --from-report
280
+ <dir> --result <result>, sign plan and policy from the
281
+ plan job's report, as a generated plan note job does.
282
+ ci evidence verify --check-id <id>[,<id>...] [--at <rev>] [--base <rev>] [--json]
283
+ Verify the kept evidence for --at's tree against the
284
+ runner keys at --base; exits 1 when one is not current.
276
285
  ci check-job The apply-job guard: compare the forge environment,
277
286
  ref and runner the forge gives this job with the
278
287
  expectation in CHANT_JOB_GUARD, which a generated
@@ -1045,6 +1054,13 @@ Workspace (level 1, #2524):
1045
1054
  workspace evidence verify --envelope <file> [--at <rev>] [--json]
1046
1055
  Verify runner evidence offline, and whether the
1047
1056
  records it covers are unchanged
1057
+ workspace ref-gate check|status --ref <ref> [--at <rev>] [--base <rev>] [--json]
1058
+ Decide a ref update against the checks .chant/trust.json
1059
+ at base requires for the ref; status sets the commit
1060
+ status a forge requires
1061
+ workspace ref-gate install --hook pre-receive|pre-push [--git-dir <dir>]
1062
+ Write the git hook that refuses an update whose commit
1063
+ lacks current evidence for a blocking check
1048
1064
  workspace lineage [--json]
1049
1065
  Show each scope in .chant/workspace.lock.json: its
1050
1066
  template and pin, locally edited files and open
@@ -1451,6 +1467,20 @@ Lexicon development:
1451
1467
  dev rolling-upgrade <dir> Report rolling-spec drift (aws, azure, github): regen from
1452
1468
  latest, diff surface vs committed baseline, print delta + PR
1453
1469
  label (dry run; --force bypasses the spec cache, --format json)
1470
+ dev local <chant-dir> In a product: npm pack the chant packages its package.json
1471
+ files name (--with <package> adds one) from the checkout,
1472
+ install them with npm install --no-save and put the manifests
1473
+ and lock back, mark each copy chantLocal, run --build '<command>',
1474
+ then dev bundle-check. --reset runs npm ci and checks the pins
1475
+ dev bundle-check [<package-dir>]
1476
+ Check a bundle against its package.json chantBundleCheck: imports
1477
+ only Node, its dependencies and chant served as compiled JS, the
1478
+ dependencies on the root's chant pin, size ceilings, denied inputs
1479
+ dev dead-guards [<product-dir>]
1480
+ Fail naming each feature-detect on a chant floor (a floor read off
1481
+ a lazily loaded module, a subpath loaded behind a catch, the
1482
+ product's own CHANT_*_FLOOR) that the product's chant pin meets;
1483
+ --chant-version <v> checks against v, --json
1454
1484
 
1455
1485
  Local:
1456
1486
  emulator <up|down|status> Boot/stop/inspect configured lexicons' local
@@ -1902,6 +1932,7 @@ export const commandRegistry: CommandDef[] = [
1902
1932
  { name: "ci init", runsNoConfig: true, handler: async (ctx) => (await import("../workspace/ci-init")).runCiInit(ctx) },
1903
1933
  // #4556: the ci.hooks.check hooks at base, for a product's check job.
1904
1934
  { name: "ci check", runsNoConfig: true, handler: async (ctx) => (await import("./handlers/ci-check")).runCiCheck(ctx) },
1935
+ { name: "ci evidence", runsNoConfig: true, handler: async (ctx) => (await import("./handlers/ci-evidence")).runCiEvidence(ctx) },
1905
1936
  // #4608: the live forge, cloud trust policies and Pulumi Cloud's OIDC policies against ci.identity.cloud. Read-only.
1906
1937
  // #4624: the apply-job guard, from the expectation the job carries.
1907
1938
  { name: "ci check-job", runsNoConfig: true, handler: async (ctx) => (await import("./handlers/ci-check-job")).runCiCheckJob(ctx) },
@@ -1950,6 +1981,11 @@ export const commandRegistry: CommandDef[] = [
1950
1981
  { name: "dev surface-diff", handler: runDevSurfaceDiff },
1951
1982
  { name: "dev pinned-upgrade", handler: runDevPinnedUpgrade },
1952
1983
  { name: "dev rolling-upgrade", handler: runDevRollingUpgrade },
1984
+ // #4787: build a product against a chant checkout, and check its bundle. Imported on first use.
1985
+ { name: "dev local", runsNoConfig: true, handler: async (ctx) => (await import("./handlers/local-chant")).runDevLocal(ctx) },
1986
+ { name: "dev bundle-check", runsNoConfig: true, handler: async (ctx) => (await import("./handlers/local-chant")).runDevBundleCheck(ctx) },
1987
+ // #4792: the feature-detects on a chant floor the product's pin already meets.
1988
+ { name: "dev dead-guards", runsNoConfig: true, handler: async (ctx) => (await import("./handlers/dead-guards")).runDevDeadGuards(ctx) },
1953
1989
 
1954
1990
  // Op / run subcommands
1955
1991
  { name: "run list", handler: runOpList },
@@ -2050,6 +2086,8 @@ export const commandRegistry: CommandDef[] = [
2050
2086
  { name: "workspace trust", runsNoConfig: true, handler: async (ctx) => (await import("../workspace/trust/trust-write")).runWorkspaceTrust(ctx) },
2051
2087
  { name: "workspace signers", handler: async (ctx) => (await import("../workspace/trust/signers-cli")).runWorkspaceSigners(ctx) },
2052
2088
  { name: "workspace evidence", handler: async (ctx) => (await import("../workspace/trust/evidence-cli")).runWorkspaceEvidence(ctx) },
2089
+ // #4867 — refuse a ref update that lacks the evidence the policy at base requires. Runs in a bare repository's hook, so no config.
2090
+ { name: "workspace ref-gate", runsNoConfig: true, handler: async (ctx) => (await import("../workspace/trust/ref-gate-cli")).runWorkspaceRefGate(ctx) },
2053
2091
 
2054
2092
  // State subcommands
2055
2093
  { name: "lifecycle snapshot", requiresPlugins: true, handler: runLifecycleSnapshot },
@@ -109,6 +109,7 @@ const BOOLEAN_FLAGS = new Set([
109
109
  "--artifacts",
110
110
  "--push",
111
111
  "--only",
112
+ "--reset",
112
113
  ]);
113
114
 
114
115
  /**
@@ -185,6 +186,7 @@ export function parseArgs(args: string[]): ParsedArgs {
185
186
  result.command = arg;
186
187
  } else if (result.path === ".") {
187
188
  result.path = arg;
189
+ result.pathGiven = true;
188
190
  } else if (!result.extraPositional) {
189
191
  result.extraPositional = arg;
190
192
  } else {
@@ -253,6 +255,19 @@ export function parseArgs(args: string[]): ParsedArgs {
253
255
  const v = args[++i];
254
256
  if (v === undefined || v === "--" || v.startsWith("--")) throw new Error("--scan needs a directory: --scan <dir>");
255
257
  (result.scanDirs ??= []).push(v);
258
+ } else if (arg === "--reset") {
259
+ // `chant dev local --reset` (#4787)
260
+ result.reset = true;
261
+ } else if (arg === "--chant-version") {
262
+ // `chant dev dead-guards --chant-version <version>` (#4792)
263
+ const v = args[++i];
264
+ if (!v || !/^\d+\.\d+\.\d+$/.test(v)) throw new Error("--chant-version needs a chant version: --chant-version 0.124.84");
265
+ result.chantVersion = v;
266
+ } else if (arg === "--with") {
267
+ // `chant dev local <chant-dir> --with <package>` (#4787), repeatable.
268
+ const v = args[++i];
269
+ if (!v || v.startsWith("-")) throw new Error("--with needs a chant package name: --with @intentius/chant-lexicon-<name>");
270
+ (result.withPackages ??= []).push(v);
256
271
  } else if (arg === "--from") {
257
272
  // Shared by `migrate --from <lexicon>`, `import --from <env>`,
258
273
  // `components promote --from <env>`, `init --from <repo>@<ref>` and
@@ -974,6 +989,12 @@ export function parseArgs(args: string[]): ParsedArgs {
974
989
  if (value === undefined || value.startsWith("-")) throw new Error(`${arg} needs a value`);
975
990
  const field = ({ "--key": "key", "--check-id": "checkId", "--claim": "claim", "--environment": "environment", "--envelope": "envelope", "--threshold": "threshold" } as const)[arg];
976
991
  result[field] = value;
992
+ } else if (arg === "--ref" || arg === "--hook" || arg === "--git-dir" || arg === "--ledger") {
993
+ // `chant workspace ref-gate check|status --ref <ref>`, `install --hook <pre-receive|pre-push> --git-dir <dir>`, `--ledger <file>` (#4867)
994
+ const value = args[++i];
995
+ if (value === undefined || value.startsWith("-")) throw new Error(`${arg} needs a value`);
996
+ const field = ({ "--ref": "ref", "--hook": "hook", "--git-dir": "gitDir", "--ledger": "ledger" } as const)[arg];
997
+ result[field] = value;
977
998
  } else if (arg === "--require") {
978
999
  // `chant workspace records|verify --require attested` (#2547)
979
1000
  result.require = args[++i];
@@ -7,6 +7,8 @@ import type { Serializer } from "../serializer";
7
7
  export interface ParsedArgs {
8
8
  command: string;
9
9
  path: string;
10
+ /** True when a positional set `path` (#4794): `chant build` with none builds from the config's `sourceDir`. */
11
+ pathGiven?: boolean;
10
12
  extraPositional?: string;
11
13
  extraPositional2?: string;
12
14
  /** Every positional after the command word, in order (#3308): for a command with more than three, such as `workspace box listing set <member>`. */
@@ -91,6 +93,12 @@ export interface ParsedArgs {
91
93
  parserOption?: string[];
92
94
  /** `chant e2e safe-run --scan <dir>`, repeatable (chant#4587): a directory to scan for a real cloud answering, beside the command's output */
93
95
  scanDirs?: string[];
96
+ /** `chant dev local --reset` (#4787): go back to the lock's pins. */
97
+ reset?: boolean;
98
+ /** `chant dev local --with <package>`, repeatable (#4787): a chant package to pack besides the ones the product names. */
99
+ withPackages?: string[];
100
+ /** `chant dev dead-guards --chant-version <v>` (#4792): check the product against this chant in place of its pins. */
101
+ chantVersion?: string;
94
102
  /** `chant carve advise --state <path>` — opt-in .tfstate for accurate instance counts */
95
103
  statePath?: string;
96
104
  /** Every `--state` value in order (#4461): `chant workspace promote --all --state <member>=<path>`, repeatable. */
@@ -765,6 +773,14 @@ export interface ParsedArgs {
765
773
  signer?: string;
766
774
  /** `chant workspace evidence verify --envelope <file>` (#2553). */
767
775
  envelope?: string;
776
+ /** `chant workspace ref-gate check|status --ref <ref>` (#4867): the ref the update is to. */
777
+ ref?: string;
778
+ /** `chant workspace ref-gate install --hook <pre-receive|pre-push>` (#4867). */
779
+ hook?: string;
780
+ /** `chant workspace ref-gate install --git-dir <dir>` (#4867): the repository whose hooks directory gets the hook. */
781
+ gitDir?: string;
782
+ /** `chant workspace ref-gate --ledger <file>` (#4867): the ledger file decisions are appended to. */
783
+ ledger?: string;
768
784
  /** `chant workspace signers rotate --threshold <n>` (#2553). */
769
785
  threshold?: string;
770
786
  /**
@@ -0,0 +1,80 @@
1
+ /**
2
+ * #4870: `ci.hooks.check`'s runner signs each hook whose every run passed as
3
+ * a named check by the hook's name, attached where the ref gate (#4867)
4
+ * reads it, and the key never reaches a hook. Without a signer the report is
5
+ * as before.
6
+ */
7
+
8
+ import { execFileSync } from "node:child_process";
9
+ import { generateKeyPairSync } from "node:crypto";
10
+ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { describe, expect, test } from "vitest";
14
+ import { checkHookEnv } from "./check-hooks";
15
+ import { runCheckStage } from "./check-steps";
16
+ import { loadRunnerKey } from "../workspace/trust/dsse";
17
+ import { readCheckEvidence, runnerKeyEvidenceSigner } from "../workspace/trust/check-evidence";
18
+ import { decideRefUpdate } from "../workspace/trust/ref-gate";
19
+
20
+ function git(cwd: string, ...args: string[]): string {
21
+ return execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.invalid", "-c", "init.defaultBranch=main", ...args], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
22
+ }
23
+
24
+ function repo(): { cwd: string; head: string; pem: string } {
25
+ const cwd = mkdtempSync(join(tmpdir(), "chant-4870-check-"));
26
+ const { privateKey } = generateKeyPairSync("ed25519");
27
+ const pem = privateKey.export({ format: "pem", type: "pkcs8" }).toString();
28
+ git(cwd, "init", "--quiet");
29
+ mkdirSync(join(cwd, ".chant"));
30
+ writeFileSync(join(cwd, ".chant/trust.json"), JSON.stringify({ schema: 1, runners: [{ principal: "ci", class: "runner", key: loadRunnerKey(pem).publicKey }] }));
31
+ git(cwd, "add", ".");
32
+ git(cwd, "commit", "--quiet", "-m", "base");
33
+ return { cwd, head: git(cwd, "rev-parse", "HEAD"), pem };
34
+ }
35
+
36
+ const hooks = [
37
+ { name: "fmt", command: ["fmt"] },
38
+ { name: "tflint", command: ["tflint", "{target}"], perRun: true },
39
+ { name: "checkov", command: ["checkov"] },
40
+ ];
41
+
42
+ describe("the check runner signs per hook (#4870)", () => {
43
+ test("each hook that passed is signed, and one that failed is not", async () => {
44
+ const { cwd, head, pem } = repo();
45
+ const logs: string[] = [];
46
+ const report = await runCheckStage({
47
+ base: head,
48
+ targets: ["roots/a", "roots/b"],
49
+ cwd,
50
+ adapters: [],
51
+ read: { base: head, hooks },
52
+ exec: (argv) => (argv[0] === "checkov" ? 1 : 0),
53
+ log: (l) => logs.push(l),
54
+ evidence: { signer: runnerKeyEvidenceSigner(cwd, head, pem), push: false },
55
+ });
56
+ expect(report.status).toBe("failed");
57
+ expect(report.evidence).toEqual({ signed: ["fmt", "tflint"], runner: "ci", commit: head });
58
+ expect(logs).toContain(`ci check: signed evidence for tflint at ${head.slice(0, 12)} as ci`);
59
+ expect((await readCheckEvidence(cwd, head, head, ["fmt", "tflint", "checkov"])).map((v) => v.status)).toEqual(["current", "current", "missing"]);
60
+ expect(JSON.parse(readFileSync(join(cwd, ".chant/check/check-hooks.json"), "utf8")).evidence.signed).toEqual(["fmt", "tflint"]);
61
+ // The ref gate reads the same notes: a rule at base naming fmt and tflint admits the commit.
62
+ const policy = JSON.parse(readFileSync(join(cwd, ".chant/trust.json"), "utf8"));
63
+ writeFileSync(join(cwd, ".chant/trust.json"), JSON.stringify({ ...policy, refs: [{ ref: "refs/heads/main", checks: [{ check: "fmt", command: "chant ci check" }, { check: "tflint", command: "chant ci check" }, { check: "checkov", command: "chant ci check" }] }] }));
64
+ git(cwd, "commit", "--quiet", "-am", "require the checks");
65
+ const ruled = git(cwd, "rev-parse", "HEAD");
66
+ const decided = decideRefUpdate({ repo: cwd, base: ruled, update: { ref: "refs/heads/main", old: ruled, new: head } });
67
+ expect(decided.checks.map((c) => [c.check, c.status])).toEqual([["fmt", "current"], ["tflint", "current"], ["checkov", "missing"]]);
68
+ });
69
+
70
+ test("without a signer nothing is signed and the report has no evidence", async () => {
71
+ const { cwd, head } = repo();
72
+ const report = await runCheckStage({ base: head, cwd, adapters: [], read: { base: head, hooks: [hooks[0]!] }, exec: () => 0, log: () => {} });
73
+ expect(report).not.toHaveProperty("evidence");
74
+ expect(JSON.parse(readFileSync(join(cwd, ".chant/check/check-hooks.json"), "utf8"))).not.toHaveProperty("evidence");
75
+ });
76
+
77
+ test("a hook never sees the runner key", () => {
78
+ expect(checkHookEnv({ PATH: "/bin", CHANT_RUNNER_KEY: "-----BEGIN PRIVATE KEY-----" })).toEqual({ PATH: "/bin" });
79
+ });
80
+ });
@@ -18,7 +18,7 @@
18
18
  * `ci.hooks`, keeping the declaration's formatting.
19
19
  */
20
20
 
21
- import { spawnSync } from "node:child_process";
21
+ import { execFileSync, spawnSync } from "node:child_process";
22
22
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
23
23
  import { join, relative, resolve } from "node:path";
24
24
  import { CHECK_HOOK_MOMENT, assertCheckHooks, type CiHooks, type OpWaveHook } from "../op/op-waves";
@@ -31,6 +31,8 @@ import { parseJsonText } from "../workspace/jsonc";
31
31
  import { memberAtCwd } from "../workspace/security";
32
32
  import { locateWorkspace } from "../workspace/which-chant";
33
33
  import type { CheckStepOutcome } from "./check-steps";
34
+ import { CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV } from "../workspace/trust/check-evidence-report";
35
+ import { acceptedLocalEvidence, acceptsLocalEvidence, fetchLocalEvidence } from "../workspace/trust/local-evidence";
34
36
 
35
37
  export { CI_CHECK_HOOK_FLOOR } from "../op/op-waves";
36
38
 
@@ -99,7 +101,8 @@ const CLOUD_CREDENTIAL_VARS = [
99
101
  * else.
100
102
  */
101
103
  export function checkHookEnv(env: NodeJS.ProcessEnv = process.env): Record<string, string> {
102
- const drop = new Set<string>([...FORGE_TOKEN_VARS, ...OIDC_REQUEST_VARS, ...Object.values(TRADED_VARS).flat(), ...CLOUD_CREDENTIAL_VARS]);
104
+ // #4870, #4868: the runner key and the local evidence key the check runner signs each hook's evidence with never reach a hook.
105
+ const drop = new Set<string>([...FORGE_TOKEN_VARS, ...OIDC_REQUEST_VARS, ...Object.values(TRADED_VARS).flat(), ...CLOUD_CREDENTIAL_VARS, CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV]);
103
106
  const out: Record<string, string> = {};
104
107
  for (const [name, value] of Object.entries(env)) {
105
108
  if (value === undefined || drop.has(name) || name.startsWith("TF_TOKEN_")) continue;
@@ -123,6 +126,8 @@ export interface CheckHookOutcome {
123
126
  exit: number;
124
127
  outcome: "passed" | "failed" | "skipped";
125
128
  reason?: string;
129
+ /** Set when the hook was skipped because current local evidence stands in for it (#4868): who signed it, at which commit. */
130
+ localEvidence?: { signer: string; class: "person" | "agent"; commit: string };
126
131
  }
127
132
 
128
133
  /** What the check hooks came to, for the product's check report. */
@@ -137,11 +142,25 @@ export interface CheckHooksReport {
137
142
  hooks: CheckHookOutcome[];
138
143
  /** The lexicons' check steps (#4633, `./check-steps.ts`), when any ran. */
139
144
  steps?: CheckStepOutcome[];
145
+ /** The checks whose evidence was signed (#4870), when the job has a runner identity. */
146
+ evidence?: { signed: string[]; runner: string; commit: string; pushWarning?: string };
140
147
  /** The first hook that failed, and why; the hooks after it did not run. Or the check steps that failed. */
141
148
  failed?: string;
142
149
  note?: string;
143
150
  }
144
151
 
152
+ /**
153
+ * The named checks the hooks' runs are signed as (#4870): each hook by its
154
+ * name, once every run of it passed, so a `perRun` hook is one check over
155
+ * all its targets. The name is the one `refs` in `.chant/trust.json` and an
156
+ * Op waves spec's `evidence.requires` name.
157
+ */
158
+ export function passedCheckHooks(outcomes: readonly CheckHookOutcome[]): Array<{ check: string; runs: CheckHookOutcome[] }> {
159
+ const byName = new Map<string, CheckHookOutcome[]>();
160
+ for (const o of outcomes) byName.set(o.name, [...(byName.get(o.name) ?? []), o]);
161
+ return [...byName].filter(([, runs]) => runs.every((r) => r.outcome === "passed")).map(([check, runs]) => ({ check, runs }));
162
+ }
163
+
145
164
  /** Where {@link runCheckHooks} writes its runs file and report unless told: `.chant/check`. */
146
165
  export const CHECK_HOOKS_DIR = ".chant/check";
147
166
 
@@ -164,6 +183,54 @@ export interface RunCheckHooksOptions {
164
183
  /** Default {@link checkHookExec}. */
165
184
  exec?: OpWaveExec;
166
185
  log?: (line: string) => void;
186
+ /**
187
+ * Hooks not to run, by name, because current local evidence the policy at
188
+ * base accepts stands in for them (#4868). Each is reported `skipped` with
189
+ * the evidence, the rest run, and the report passes when they do.
190
+ */
191
+ skip?: ReadonlyMap<string, { signer: string; class: "person" | "agent"; commit: string }>;
192
+ /** Skip each hook whose current local evidence the policy at `localEvidence.base` accepts (#4868), added to `skip`. */
193
+ localEvidence?: CheckHooksLocalEvidence;
194
+ }
195
+
196
+ /**
197
+ * Skipping hooks on local evidence (#4868): `base` is the full commit whose
198
+ * `.chant/trust.json` says which checks take local evidence and whose keys
199
+ * sign it. Absent, every hook runs.
200
+ */
201
+ export interface CheckHooksLocalEvidence {
202
+ base: string;
203
+ /** The commit the checks run at. Default `HEAD`. */
204
+ at?: string;
205
+ /** Fetch `refs/notes/chant/local-evidence` from `origin` first, as a CI job does. Default true. */
206
+ fetch?: boolean;
207
+ }
208
+
209
+ /**
210
+ * `options.skip` plus the hooks whose current local evidence the
211
+ * policy at base accepts (#4868). Each hook is judged on its own, so a job
212
+ * that runs several hooks runs the rest. Nothing is fetched or read when the
213
+ * policy names no check, so a project that never opted in has the job it had.
214
+ */
215
+ function localSkips(options: RunCheckHooksOptions, read: CheckHooksRead, cwd: string, log: (line: string) => void): RunCheckHooksOptions["skip"] {
216
+ const local = options.localEvidence;
217
+ if (!local || read.hooks.length === 0) return options.skip;
218
+ const repo = execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
219
+ if (!acceptsLocalEvidence(repo, local.base)) return options.skip;
220
+ if (local.fetch !== false && !fetchLocalEvidence(repo)) log("check hooks: refs/notes/chant/local-evidence could not be fetched from origin; using the local evidence this checkout has");
221
+ const names = [...new Set(read.hooks.map(checkHookName))];
222
+ const skip = new Map(options.skip ?? []);
223
+ for (const v of acceptedLocalEvidence(repo, local.at ?? "HEAD", local.base, names)) {
224
+ if (v.status === "accepted") skip.set(v.check, { signer: v.signer, class: v.class, commit: v.commit });
225
+ else if (v.status === "untrusted") log(`check hook ${v.check} runs: ${v.reason}`);
226
+ }
227
+ return skip;
228
+ }
229
+
230
+ /** A hook's name as the runner reports it. */
231
+ export function checkHookName(hook: OpWaveHook): string {
232
+ const command = hook.command.join(" ");
233
+ return hook.name ?? (command.length > 60 ? `${command.slice(0, 57)}...` : command);
167
234
  }
168
235
 
169
236
  /**
@@ -191,7 +258,13 @@ export function runCheckHooks(options: RunCheckHooksOptions): CheckHooksReport {
191
258
  const runs: OpWaveHookRun[] = targets.map((target) => ({ target, op }));
192
259
  const runsFile = join(dir, "runs.json");
193
260
  writeFileSync(join(cwd, runsFile), JSON.stringify({ version: 1, op, stage: "check", base: read.base, hook: CHECK_HOOK_MOMENT, runs }, null, 2) + "\n");
194
- const ran = runStageHooks(CHECK_HOOK_MOMENT, read.hooks, {
261
+ const skip = localSkips(options, read, cwd, log) ?? new Map();
262
+ const toRun = read.hooks.filter((h) => !skip.has(checkHookName(h)));
263
+ for (const h of read.hooks) {
264
+ const by = skip.get(checkHookName(h));
265
+ if (by) log(`check hook ${checkHookName(h)}: skipped, current local evidence from ${by.class} ${by.signer} (signed at ${by.commit.slice(0, 12)}) stands in for it`);
266
+ }
267
+ const ran = runStageHooks(CHECK_HOOK_MOMENT, toRun, {
195
268
  name: op,
196
269
  op,
197
270
  wave: op,
@@ -203,13 +276,20 @@ export function runCheckHooks(options: RunCheckHooksOptions): CheckHooksReport {
203
276
  exec: options.exec ?? checkHookExec,
204
277
  log,
205
278
  });
206
- const hooks = ran.outcomes.map((o): CheckHookOutcome => ({
279
+ const outcomes = ran.outcomes.map((o): CheckHookOutcome => ({
207
280
  name: o.name,
208
281
  ...(o.target ? { target: o.target } : {}),
209
282
  exit: o.exit,
210
283
  outcome: o.outcome === "skipped" ? "skipped" : o.outcome === "passed" ? "passed" : "failed",
211
284
  ...(o.reason ? { reason: o.reason } : {}),
212
285
  }));
286
+ // In the declaration's order: a skipped hook where it would have run.
287
+ const hooks = read.hooks.flatMap((h): CheckHookOutcome[] => {
288
+ const name = checkHookName(h);
289
+ const by = skip.get(name);
290
+ if (by) return [{ name, exit: 0, outcome: "skipped", reason: `current local evidence from ${by.class} ${by.signer}`, localEvidence: by }];
291
+ return outcomes.filter((o) => o.name === name);
292
+ });
213
293
  const failed = ran.failed ?? (hooks.some((h) => h.outcome === "failed") ? `a check hook failed: ${hooks.filter((h) => h.outcome === "failed").map((h) => h.name).join(", ")}` : undefined);
214
294
  return report({ status: failed ? "failed" : "passed", hooks, ...(failed ? { failed } : {}) });
215
295
  }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * #4868: the check runner skips a hook whose current local evidence the
3
+ * policy at base accepts, per hook, so a job that runs several hooks runs
4
+ * the rest and still passes; and runs it for a tree without such evidence.
5
+ */
6
+
7
+ import { execFileSync } from "node:child_process";
8
+ import { generateKeyPairSync } from "node:crypto";
9
+ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
10
+ import { tmpdir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { describe, expect, test } from "vitest";
13
+ import { checkHookEnv, runCheckHooks } from "./check-hooks";
14
+ import { runCheckStage } from "./check-steps";
15
+ import { loadRunnerKey } from "../workspace/trust/dsse";
16
+ import { localKeyEvidenceSigner, recordLocalChecks, signLocalChecks } from "../workspace/trust/local-evidence";
17
+
18
+ function git(cwd: string, ...args: string[]): string {
19
+ return execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.invalid", "-c", "init.defaultBranch=main", ...args], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
20
+ }
21
+
22
+ function pemKey(): string {
23
+ return generateKeyPairSync("ed25519").privateKey.export({ format: "pem", type: "pkcs8" }).toString();
24
+ }
25
+
26
+ /** A repository whose policy at its first commit lists alice's local key and takes local evidence for fmt and tflint. */
27
+ function repo(): { cwd: string; base: string; alice: string } {
28
+ const cwd = mkdtempSync(join(tmpdir(), "chant-4868-stage-"));
29
+ const alice = pemKey();
30
+ git(cwd, "init", "--quiet");
31
+ mkdirSync(join(cwd, ".chant"));
32
+ writeFileSync(
33
+ join(cwd, ".chant/trust.json"),
34
+ JSON.stringify({ schema: 1, local: { keys: [{ principal: "alice", class: "person", key: loadRunnerKey(alice).publicKey }], checks: [{ check: "fmt" }, { check: "tflint" }] } }),
35
+ );
36
+ writeFileSync(join(cwd, "main.tf"), "# a\n");
37
+ git(cwd, "add", ".");
38
+ git(cwd, "commit", "--quiet", "-m", "base");
39
+ return { cwd, base: git(cwd, "rev-parse", "HEAD"), alice };
40
+ }
41
+
42
+ const hooks = [
43
+ { name: "fmt", command: ["fmt"] },
44
+ { name: "tflint", command: ["tflint", "{target}"], perRun: true },
45
+ { name: "checkov", command: ["checkov"] },
46
+ ];
47
+
48
+ async function signLocally(cwd: string, base: string, pem: string, checks: string[]): Promise<void> {
49
+ const signer = localKeyEvidenceSigner(cwd, base, pem);
50
+ await recordLocalChecks(cwd, signLocalChecks(cwd, "HEAD", checks.map((check) => ({ check })), signer), { push: false });
51
+ }
52
+
53
+ async function stage(cwd: string, base: string) {
54
+ const ran: string[] = [];
55
+ const logs: string[] = [];
56
+ const report = await runCheckStage({
57
+ base,
58
+ targets: ["roots/a", "roots/b"],
59
+ cwd,
60
+ adapters: [],
61
+ read: { base, hooks },
62
+ exec: (argv) => {
63
+ ran.push(argv.join(" "));
64
+ return 0;
65
+ },
66
+ log: (l) => logs.push(l),
67
+ localEvidence: { base, fetch: false },
68
+ });
69
+ return { report, ran, logs };
70
+ }
71
+
72
+ describe("the check runner skips a hook on local evidence (#4868)", () => {
73
+ test("a hook with current, accepted local evidence is skipped; the others run and the job passes", async () => {
74
+ const { cwd, base, alice } = repo();
75
+ await signLocally(cwd, base, alice, ["fmt", "checkov"]);
76
+ const { report, ran, logs } = await stage(cwd, base);
77
+ expect(report.status).toBe("passed");
78
+ // checkov has local evidence too, and the policy does not take it for checkov.
79
+ expect(ran).toEqual(["tflint roots/a", "tflint roots/b", "checkov"]);
80
+ expect(report.hooks.map((h) => [h.name, h.outcome])).toEqual([["fmt", "skipped"], ["tflint", "passed"], ["tflint", "passed"], ["checkov", "passed"]]);
81
+ expect(report.hooks[0]!.localEvidence).toEqual({ signer: "alice", class: "person", commit: base });
82
+ expect(logs.some((l) => l.includes("check hook fmt: skipped, current local evidence from person alice"))).toBe(true);
83
+ expect(JSON.parse(readFileSync(join(cwd, ".chant/check/check-hooks.json"), "utf8")).hooks[0].outcome).toBe("skipped");
84
+ });
85
+
86
+ test("every hook skipped still passes, so a job other jobs need succeeds", async () => {
87
+ const { cwd, base, alice } = repo();
88
+ await signLocally(cwd, base, alice, ["fmt", "tflint"]);
89
+ const { report, ran } = await stage(cwd, base);
90
+ expect(ran).toEqual(["checkov"]);
91
+ expect(report.status).toBe("passed");
92
+ });
93
+
94
+ test("a tree changed after signing runs the hook", async () => {
95
+ const { cwd, base, alice } = repo();
96
+ await signLocally(cwd, base, alice, ["fmt"]);
97
+ writeFileSync(join(cwd, "main.tf"), "# b\n");
98
+ git(cwd, "commit", "--quiet", "-am", "change the tree");
99
+ const { ran } = await stage(cwd, base);
100
+ expect(ran[0]).toBe("fmt");
101
+ });
102
+
103
+ test("an amend that keeps the tree keeps the evidence current", async () => {
104
+ const { cwd, base, alice } = repo();
105
+ writeFileSync(join(cwd, "main.tf"), "# b\n");
106
+ git(cwd, "commit", "--quiet", "-am", "work");
107
+ await signLocally(cwd, base, alice, ["fmt"]);
108
+ git(cwd, "commit", "--quiet", "--amend", "-m", "work, reworded");
109
+ const { ran } = await stage(cwd, base);
110
+ expect(ran).not.toContain("fmt");
111
+ });
112
+
113
+ test("without localEvidence every hook runs", async () => {
114
+ const { cwd, base, alice } = repo();
115
+ await signLocally(cwd, base, alice, ["fmt"]);
116
+ const ran: string[] = [];
117
+ await runCheckStage({ base, cwd, adapters: [], read: { base, hooks: [hooks[0]!] }, exec: (argv) => (ran.push(argv[0]!), 0), log: () => {} });
118
+ expect(ran).toEqual(["fmt"]);
119
+ });
120
+
121
+ test("a local signer signs each passed hook as local evidence, and CI then skips it", async () => {
122
+ const { cwd, base, alice } = repo();
123
+ const signed = await runCheckStage({ base, cwd, adapters: [], read: { base, hooks: [hooks[0]!] }, exec: () => 0, log: () => {}, evidence: { signer: localKeyEvidenceSigner(cwd, base, alice), push: false } });
124
+ expect(signed.evidence?.signed).toEqual(["fmt"]);
125
+ const { ran } = await stage(cwd, base);
126
+ expect(ran).not.toContain("fmt");
127
+ });
128
+
129
+ test("runCheckHooks, which a product's own check job calls, skips the same way", async () => {
130
+ const { cwd, base, alice } = repo();
131
+ await signLocally(cwd, base, alice, ["fmt"]);
132
+ const ran: string[] = [];
133
+ const report = runCheckHooks({ base, cwd, read: { base, hooks: [hooks[0]!, hooks[2]!] }, exec: (argv) => (ran.push(argv[0]!), 0), log: () => {}, localEvidence: { base, fetch: false } });
134
+ expect(ran).toEqual(["checkov"]);
135
+ expect(report.hooks.map((h) => h.outcome)).toEqual(["skipped", "passed"]);
136
+ });
137
+
138
+ test("a hook never sees the local evidence key", () => {
139
+ expect(checkHookEnv({ PATH: "/bin", CHANT_LOCAL_EVIDENCE_KEY: "-----BEGIN PRIVATE KEY-----" })).toEqual({ PATH: "/bin" });
140
+ });
141
+ });