@intentius/chant 0.124.76 → 0.124.78

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 (212) hide show
  1. package/dist/__fixtures__/agent-guard/plywood.d.ts +8 -0
  2. package/dist/__fixtures__/agent-guard/plywood.d.ts.map +1 -0
  3. package/dist/__fixtures__/agent-guard/plywood.js +19 -0
  4. package/dist/__fixtures__/agent-guard/terragucci.d.ts +8 -0
  5. package/dist/__fixtures__/agent-guard/terragucci.d.ts.map +1 -0
  6. package/dist/__fixtures__/agent-guard/terragucci.js +30 -0
  7. package/dist/__fixtures__/gated-ledger.d.ts +10 -0
  8. package/dist/__fixtures__/gated-ledger.d.ts.map +1 -0
  9. package/dist/__fixtures__/gated-ledger.js +51 -0
  10. package/dist/__fixtures__/notify-messages/events.d.ts +9 -0
  11. package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
  12. package/dist/__fixtures__/notify-messages/events.js +21 -0
  13. package/dist/__fixtures__/product-words.d.ts +14 -0
  14. package/dist/__fixtures__/product-words.d.ts.map +1 -1
  15. package/dist/__fixtures__/product-words.js +11 -0
  16. package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
  17. package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
  18. package/dist/__fixtures__/terragucci-notify.js +133 -0
  19. package/dist/action-pins.d.ts +8 -0
  20. package/dist/action-pins.d.ts.map +1 -1
  21. package/dist/action-pins.js +9 -0
  22. package/dist/agent-guard.d.ts +143 -0
  23. package/dist/agent-guard.d.ts.map +1 -0
  24. package/dist/agent-guard.js +455 -0
  25. package/dist/ci-commit.d.ts +120 -5
  26. package/dist/ci-commit.d.ts.map +1 -1
  27. package/dist/ci-commit.js +214 -23
  28. package/dist/ci-own-jobs.d.ts +81 -0
  29. package/dist/ci-own-jobs.d.ts.map +1 -0
  30. package/dist/ci-own-jobs.js +233 -0
  31. package/dist/ci-product-words.d.ts +18 -4
  32. package/dist/ci-product-words.d.ts.map +1 -1
  33. package/dist/ci-product-words.js +26 -6
  34. package/dist/ci-product.d.ts +40 -1
  35. package/dist/ci-product.d.ts.map +1 -1
  36. package/dist/ci-product.js +40 -1
  37. package/dist/cli/handlers/approve.d.ts +5 -1
  38. package/dist/cli/handlers/approve.d.ts.map +1 -1
  39. package/dist/cli/handlers/approve.js +17 -11
  40. package/dist/cli/handlers/build.d.ts +1 -1
  41. package/dist/cli/handlers/build.d.ts.map +1 -1
  42. package/dist/cli/handlers/build.js +88 -2
  43. package/dist/cli/handlers/commit.d.ts.map +1 -1
  44. package/dist/cli/handlers/commit.js +3 -1
  45. package/dist/cli/handlers/notify-relay.d.ts +18 -1
  46. package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
  47. package/dist/cli/handlers/notify-relay.js +90 -14
  48. package/dist/cli/handlers/pr.d.ts.map +1 -1
  49. package/dist/cli/handlers/pr.js +3 -1
  50. package/dist/cli/handlers/release.d.ts +5 -1
  51. package/dist/cli/handlers/release.d.ts.map +1 -1
  52. package/dist/cli/handlers/release.js +21 -9
  53. package/dist/cli/handlers/run-generate.d.ts.map +1 -1
  54. package/dist/cli/handlers/run-generate.js +2 -1
  55. package/dist/cli/main.d.ts.map +1 -1
  56. package/dist/cli/main.js +21 -1
  57. package/dist/cli/parse-args.d.ts.map +1 -1
  58. package/dist/cli/parse-args.js +60 -4
  59. package/dist/cli/registry.d.ts +16 -0
  60. package/dist/cli/registry.d.ts.map +1 -1
  61. package/dist/components/pr-env-components.d.ts +65 -0
  62. package/dist/components/pr-env-components.d.ts.map +1 -0
  63. package/dist/components/pr-env-components.js +162 -0
  64. package/dist/components/pr-policy.d.ts +15 -0
  65. package/dist/components/pr-policy.d.ts.map +1 -1
  66. package/dist/components/pr-policy.js +24 -1
  67. package/dist/components/release-compile.d.ts +15 -3
  68. package/dist/components/release-compile.d.ts.map +1 -1
  69. package/dist/components/release-compile.js +66 -15
  70. package/dist/config.d.ts +14 -8
  71. package/dist/config.d.ts.map +1 -1
  72. package/dist/config.js +16 -1
  73. package/dist/gate-policy.d.ts +14 -1
  74. package/dist/gate-policy.d.ts.map +1 -1
  75. package/dist/gate-policy.js +16 -6
  76. package/dist/lexicon.d.ts +25 -1
  77. package/dist/lexicon.d.ts.map +1 -1
  78. package/dist/lexicon.js +10 -0
  79. package/dist/lifecycle/gated-op.d.ts +95 -0
  80. package/dist/lifecycle/gated-op.d.ts.map +1 -0
  81. package/dist/lifecycle/gated-op.js +96 -0
  82. package/dist/lifecycle/git.d.ts.map +1 -1
  83. package/dist/lifecycle/git.js +83 -2
  84. package/dist/lifecycle/release-images.d.ts +77 -3
  85. package/dist/lifecycle/release-images.d.ts.map +1 -1
  86. package/dist/lifecycle/release-images.js +132 -6
  87. package/dist/notify-product.d.ts +11 -2
  88. package/dist/notify-product.d.ts.map +1 -1
  89. package/dist/notify-product.js +16 -4
  90. package/dist/notify-relay-repo.d.ts +131 -0
  91. package/dist/notify-relay-repo.d.ts.map +1 -0
  92. package/dist/notify-relay-repo.js +202 -0
  93. package/dist/notify-relay.d.ts +25 -1
  94. package/dist/notify-relay.d.ts.map +1 -1
  95. package/dist/notify-relay.js +27 -2
  96. package/dist/notify.d.ts +36 -4
  97. package/dist/notify.d.ts.map +1 -1
  98. package/dist/notify.js +31 -21
  99. package/dist/notify.schema.json +1 -0
  100. package/dist/op/activities/review-product.d.ts +111 -0
  101. package/dist/op/activities/review-product.d.ts.map +1 -0
  102. package/dist/op/activities/review-product.js +116 -0
  103. package/dist/op/op-waves-capability.js +2 -2
  104. package/dist/policy-engine.d.ts +95 -0
  105. package/dist/policy-engine.d.ts.map +1 -0
  106. package/dist/policy-engine.js +157 -0
  107. package/dist/pr-forge-reads.d.ts +124 -0
  108. package/dist/pr-forge-reads.d.ts.map +1 -0
  109. package/dist/pr-forge-reads.js +322 -0
  110. package/dist/pr-forge.d.ts +14 -0
  111. package/dist/pr-forge.d.ts.map +1 -1
  112. package/dist/pr-forge.js +21 -13
  113. package/dist/pr-plan-note.d.ts +293 -0
  114. package/dist/pr-plan-note.d.ts.map +1 -0
  115. package/dist/pr-plan-note.js +362 -0
  116. package/dist/release-floors.d.ts +9 -1
  117. package/dist/release-floors.d.ts.map +1 -1
  118. package/dist/release-floors.js +9 -1
  119. package/dist/state-export.d.ts +126 -0
  120. package/dist/state-export.d.ts.map +1 -0
  121. package/dist/state-export.js +156 -0
  122. package/dist/state-migration.d.ts +148 -0
  123. package/dist/state-migration.d.ts.map +1 -0
  124. package/dist/state-migration.js +146 -0
  125. package/dist/state-unlock.d.ts +167 -0
  126. package/dist/state-unlock.d.ts.map +1 -0
  127. package/dist/state-unlock.js +196 -0
  128. package/dist/wave-runtime.mjs +332 -332
  129. package/dist/workspace/declaration.schema.json +1 -1
  130. package/dist/workspace/release-workflow.d.ts +10 -0
  131. package/dist/workspace/release-workflow.d.ts.map +1 -1
  132. package/dist/workspace/release-workflow.js +10 -4
  133. package/package.json +1 -1
  134. package/src/__fixtures__/agent-guard/plywood.ts +27 -0
  135. package/src/__fixtures__/agent-guard/terragucci.ts +39 -0
  136. package/src/__fixtures__/gated-ledger.ts +58 -0
  137. package/src/__fixtures__/notify-messages/events.ts +23 -0
  138. package/src/__fixtures__/notify-messages/messages.json +50 -0
  139. package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
  140. package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
  141. package/src/__fixtures__/product-words.ts +12 -0
  142. package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
  143. package/src/__fixtures__/terragucci-notify.ts +170 -0
  144. package/src/action-pins.test.ts +12 -1
  145. package/src/action-pins.ts +11 -0
  146. package/src/agent-guard.test.ts +319 -0
  147. package/src/agent-guard.ts +547 -0
  148. package/src/ci-commit.test.ts +213 -2
  149. package/src/ci-commit.ts +258 -27
  150. package/src/ci-own-jobs.test.ts +108 -0
  151. package/src/ci-own-jobs.ts +252 -0
  152. package/src/ci-product-words.ts +35 -7
  153. package/src/ci-product.ts +81 -1
  154. package/src/cli/handlers/approve-cwd.test.ts +112 -0
  155. package/src/cli/handlers/approve.ts +22 -11
  156. package/src/cli/handlers/build-own-jobs.test.ts +80 -0
  157. package/src/cli/handlers/build-pr-loop-control.test.ts +87 -0
  158. package/src/cli/handlers/build-run-group.test.ts +59 -0
  159. package/src/cli/handlers/build.ts +83 -3
  160. package/src/cli/handlers/commit.ts +3 -0
  161. package/src/cli/handlers/notify-relay.ts +99 -17
  162. package/src/cli/handlers/pr.ts +3 -1
  163. package/src/cli/handlers/release.ts +20 -10
  164. package/src/cli/handlers/run-generate.ts +2 -1
  165. package/src/cli/main.ts +21 -1
  166. package/src/cli/parse-args.ts +45 -3
  167. package/src/cli/registry.ts +16 -0
  168. package/src/components/pr-env-components.test.ts +137 -0
  169. package/src/components/pr-env-components.ts +213 -0
  170. package/src/components/pr-policy.test.ts +41 -1
  171. package/src/components/pr-policy.ts +25 -1
  172. package/src/components/release-compile.test.ts +47 -0
  173. package/src/components/release-compile.ts +70 -13
  174. package/src/config.ts +23 -3
  175. package/src/gate-policy-bundle.test.ts +14 -0
  176. package/src/gate-policy.test.ts +7 -0
  177. package/src/gate-policy.ts +22 -7
  178. package/src/lexicon.ts +28 -1
  179. package/src/lifecycle/gated-op.ts +158 -0
  180. package/src/lifecycle/git.test.ts +92 -0
  181. package/src/lifecycle/git.ts +71 -2
  182. package/src/lifecycle/release-images-dockerfile.test.ts +221 -0
  183. package/src/lifecycle/release-images.ts +167 -8
  184. package/src/notify-message-words.test.ts +186 -0
  185. package/src/notify-product.ts +17 -4
  186. package/src/notify-relay-repo.test.ts +284 -0
  187. package/src/notify-relay-repo.ts +234 -0
  188. package/src/notify-relay.test.ts +12 -0
  189. package/src/notify-relay.ts +29 -3
  190. package/src/notify.schema.json +1 -0
  191. package/src/notify.ts +59 -19
  192. package/src/op/activities/review-product.test.ts +116 -0
  193. package/src/op/activities/review-product.ts +200 -0
  194. package/src/op/op-waves-capability.ts +2 -2
  195. package/src/op/schedule-overdue.test.ts +26 -0
  196. package/src/policy-engine.test.ts +162 -0
  197. package/src/policy-engine.ts +200 -0
  198. package/src/pr-forge-reads.test.ts +285 -0
  199. package/src/pr-forge-reads.ts +424 -0
  200. package/src/pr-forge.ts +30 -16
  201. package/src/pr-plan-note.test.ts +105 -0
  202. package/src/pr-plan-note.ts +521 -0
  203. package/src/release-floors.ts +13 -1
  204. package/src/state-export.test.ts +124 -0
  205. package/src/state-export.ts +227 -0
  206. package/src/state-migration.test.ts +133 -0
  207. package/src/state-migration.ts +236 -0
  208. package/src/state-unlock.test.ts +165 -0
  209. package/src/state-unlock.ts +293 -0
  210. package/src/workspace/declaration.schema.json +1 -1
  211. package/src/workspace/release-workflow.test.ts +34 -0
  212. package/src/workspace/release-workflow.ts +19 -4
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The policy engine's binary (#4774): conftest or OPA at a pinned release,
3
+ * fetched once, checked against the sha256 chant records for it, and kept in
4
+ * a cache directory.
5
+ *
6
+ * `ci.policy.install: true` makes the pull-request jobs and Op waves use it
7
+ * (`./components/pr-policy.ts`). A product that runs the engine itself calls
8
+ * {@link policyEngineBinary} with its own `download`, `cache` and `exec`, so
9
+ * it keeps no download code. Tests pass `download`, so nothing reaches the
10
+ * network.
11
+ *
12
+ * The digests are the release's own: conftest's `checksums.txt` and OPA's
13
+ * `.sha256` files, checked against the archives themselves when the pins
14
+ * were set. A download that does not match its pin is never written to the
15
+ * cache. A caller pinning another release passes its `version` and the
16
+ * sha256 for the platform; chant fetches nothing without a pin.
17
+ *
18
+ * Like `./gate-policy.ts` this module imports only node built-ins (and the
19
+ * release-floor constant), so a product can bundle it.
20
+ */
21
+ /** The first chant with `ci.policy.install` and `@intentius/chant/policy-engine` (#4774). Products feature-detect on it. */
22
+ export declare const POLICY_ENGINE_INSTALL_FLOOR = "0.124.77";
23
+ export type PolicyEngineName = "conftest" | "opa";
24
+ /** The platforms chant has pins for. */
25
+ export type PolicyEnginePlatform = "linux-x64" | "linux-arm64" | "darwin-x64" | "darwin-arm64";
26
+ export declare const POLICY_ENGINE_PLATFORMS: readonly PolicyEnginePlatform[];
27
+ /** The conftest release chant installs. */
28
+ export declare const CONFTEST_VERSION = "0.71.1";
29
+ /** The OPA release chant installs. */
30
+ export declare const OPA_VERSION = "1.21.4";
31
+ /**
32
+ * The sha256 of each pinned release file, as `<engine>-<version>-<platform>`,
33
+ * copied from the release's checksums (conftest's `checksums.txt`, OPA's
34
+ * `<asset>.sha256`) and checked against the files. The files are conftest's
35
+ * `conftest_<v>_<OS>_<arch>.tar.gz` and OPA's static builds, except on
36
+ * darwin-x64, where OPA builds none and the file is `opa_darwin_amd64`. Add
37
+ * a release's lines when moving a default version.
38
+ */
39
+ export declare const POLICY_ENGINE_SHA256: Readonly<Record<string, string>>;
40
+ /** One release file of one engine for one platform. */
41
+ export interface PolicyEngineRelease {
42
+ engine: PolicyEngineName;
43
+ version: string;
44
+ platform: PolicyEnginePlatform;
45
+ /** The release file's name. OPA ships a bare binary, conftest a `.tar.gz` holding `conftest`. */
46
+ asset: string;
47
+ url: string;
48
+ /** Whether the file is a `.tar.gz` to unpack. */
49
+ archive: boolean;
50
+ }
51
+ /** The release file of `engine` at `version` for `platform`. A version is a plain semver. */
52
+ export declare function policyEngineRelease(engine: PolicyEngineName, platform: PolicyEnginePlatform, version?: string): PolicyEngineRelease;
53
+ /** The sha256 chant records for a release file, or undefined when it records none. */
54
+ export declare function pinnedPolicyEngineSha256(release: PolicyEngineRelease): string | undefined;
55
+ /** This process's platform as chant pins it. Throws on one with no pin. */
56
+ export declare function policyEnginePlatform(platform?: string, arch?: string): PolicyEnginePlatform;
57
+ /** Where installed engines are kept by default: `CHANT_TOOL_CACHE`, else `chant-tools` in the temp directory. */
58
+ export declare function defaultPolicyEngineCache(): string;
59
+ export interface InstallPolicyEngineOptions {
60
+ /** Fetches a release file. Default: Node's fetch. Tests pass their own. */
61
+ download?: (url: string) => Promise<Uint8Array>;
62
+ /** Where installed engines are kept. Default {@link defaultPolicyEngineCache}. */
63
+ cache?: string;
64
+ /** The platform to fetch for. Default this process's ({@link policyEnginePlatform}). */
65
+ platform?: PolicyEnginePlatform;
66
+ /** Another release than chant's default. Needs `sha256` for the platform. */
67
+ version?: string;
68
+ /** The release file's sha256 by platform, in place of {@link POLICY_ENGINE_SHA256}. */
69
+ sha256?: Partial<Record<PolicyEnginePlatform, string>>;
70
+ }
71
+ /** The bytes of the regular file `name` (at the top, or under `./`) in a tar stream. Undefined when it holds none. */
72
+ export declare function tarEntry(tar: Uint8Array, name: string): Uint8Array | undefined;
73
+ /**
74
+ * Install `engine` into the cache and return the binary's path. A binary
75
+ * already installed there for that release and platform is returned without
76
+ * a download. Throws when the platform has no pin, the download fails, or
77
+ * the file does not match its pin.
78
+ */
79
+ export declare function installPolicyEngine(engine: PolicyEngineName, options?: InstallPolicyEngineOptions): Promise<string>;
80
+ /** Whether the engine on PATH answers. Default: runs `conftest --version` or `opa version`. */
81
+ export type PolicyEngineProbe = (engine: PolicyEngineName) => boolean;
82
+ export declare const defaultPolicyEngineProbe: PolicyEngineProbe;
83
+ export interface PolicyEngineBinaryOptions extends InstallPolicyEngineOptions {
84
+ /** Checks the engine on PATH. Default {@link defaultPolicyEngineProbe}. */
85
+ probe?: PolicyEngineProbe;
86
+ /** Skip the PATH and always use the pinned release. Default false. */
87
+ pinnedOnly?: boolean;
88
+ }
89
+ /**
90
+ * The engine's executable: its name when the one on PATH answers (an image
91
+ * that carries the engine pays nothing), else the pinned release installed
92
+ * by {@link installPolicyEngine}.
93
+ */
94
+ export declare function policyEngineBinary(engine: PolicyEngineName, options?: PolicyEngineBinaryOptions): Promise<string>;
95
+ //# sourceMappingURL=policy-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-engine.d.ts","sourceRoot":"","sources":["../src/policy-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AASH,4HAA4H;AAC5H,eAAO,MAAM,2BAA2B,aAAa,CAAC;AAEtD,MAAM,MAAM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AE,MAAM,CAAC;IACf,wFAAwF;IACxF,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC,CAAC;CACxD;AAQD,sHAAsH;AACtH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAkB9E;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CAAC,MAAM,CAAC,CAqB7H;AAED,+FAA+F;AAC/F,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC;AAEtE,eAAO,MAAM,wBAAwB,EAAE,iBAGtC,CAAC;AAEF,MAAM,WAAW,yBAA0B,SAAQ,0BAA0B;IAC3E,2EAA2E;IAC3E,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,sEAAsE;IACtE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAE,yBAA8B,GAAG,OAAO,CAAC,MAAM,CAAC,CAG3H"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The policy engine's binary (#4774): conftest or OPA at a pinned release,
3
+ * fetched once, checked against the sha256 chant records for it, and kept in
4
+ * a cache directory.
5
+ *
6
+ * `ci.policy.install: true` makes the pull-request jobs and Op waves use it
7
+ * (`./components/pr-policy.ts`). A product that runs the engine itself calls
8
+ * {@link policyEngineBinary} with its own `download`, `cache` and `exec`, so
9
+ * it keeps no download code. Tests pass `download`, so nothing reaches the
10
+ * network.
11
+ *
12
+ * The digests are the release's own: conftest's `checksums.txt` and OPA's
13
+ * `.sha256` files, checked against the archives themselves when the pins
14
+ * were set. A download that does not match its pin is never written to the
15
+ * cache. A caller pinning another release passes its `version` and the
16
+ * sha256 for the platform; chant fetches nothing without a pin.
17
+ *
18
+ * Like `./gate-policy.ts` this module imports only node built-ins (and the
19
+ * release-floor constant), so a product can bundle it.
20
+ */
21
+ import { spawnSync } from "node:child_process";
22
+ import { createHash, randomBytes } from "node:crypto";
23
+ import { chmodSync, existsSync, mkdirSync, renameSync, writeFileSync } from "node:fs";
24
+ import { tmpdir } from "node:os";
25
+ import { join } from "node:path";
26
+ import { gunzipSync } from "node:zlib";
27
+ /** The first chant with `ci.policy.install` and `@intentius/chant/policy-engine` (#4774). Products feature-detect on it. */
28
+ export const POLICY_ENGINE_INSTALL_FLOOR = "0.124.77";
29
+ export const POLICY_ENGINE_PLATFORMS = ["linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64"];
30
+ /** The conftest release chant installs. */
31
+ export const CONFTEST_VERSION = "0.71.1";
32
+ /** The OPA release chant installs. */
33
+ export const OPA_VERSION = "1.21.4";
34
+ /**
35
+ * The sha256 of each pinned release file, as `<engine>-<version>-<platform>`,
36
+ * copied from the release's checksums (conftest's `checksums.txt`, OPA's
37
+ * `<asset>.sha256`) and checked against the files. The files are conftest's
38
+ * `conftest_<v>_<OS>_<arch>.tar.gz` and OPA's static builds, except on
39
+ * darwin-x64, where OPA builds none and the file is `opa_darwin_amd64`. Add
40
+ * a release's lines when moving a default version.
41
+ */
42
+ export const POLICY_ENGINE_SHA256 = {
43
+ "conftest-0.71.1-linux-x64": "c3f6b2a753bd56e377a1e51a95ae3e057f926f2e9139f7d5b5dfbbaf810f7985",
44
+ "conftest-0.71.1-linux-arm64": "218c682e110ae7e826dc14a746a6f9b43eb782643dbe730b771fd305634e3f47",
45
+ "conftest-0.71.1-darwin-x64": "a309853b5763c18486768157442d440248ee683b20a2aa1f6b28214e818bd780",
46
+ "conftest-0.71.1-darwin-arm64": "e1cc50d2590b6c5e3da6912666a71264bae82d60bdd62d7ae2b99971ccc8eedd",
47
+ "opa-1.21.4-linux-x64": "2ab571f367f293bb19523b76f92f1945bbf245003392c7f392903f95c2b9b630",
48
+ "opa-1.21.4-linux-arm64": "810aa96e44f1f852d044888cf830324e44eafd0f510345339011347ab4deaab1",
49
+ "opa-1.21.4-darwin-x64": "8802bd39bc14b58a705e6b3d4f4dd14f7f24ee657f0362c737338be243190c7e",
50
+ "opa-1.21.4-darwin-arm64": "4c105208a9282f590385bccbe600875c011f0894ccf9431782dfe855e1f99aa6",
51
+ };
52
+ const VERSION = /^\d+\.\d+\.\d+$/;
53
+ const SHA256 = /^[0-9a-f]{64}$/;
54
+ /** The release file of `engine` at `version` for `platform`. A version is a plain semver. */
55
+ export function policyEngineRelease(engine, platform, version = engine === "opa" ? OPA_VERSION : CONFTEST_VERSION) {
56
+ if (!VERSION.test(version))
57
+ throw new Error(`${engine} version ${JSON.stringify(version)} is not a release version such as ${engine === "opa" ? OPA_VERSION : CONFTEST_VERSION}`);
58
+ const [os, cpu] = platform.split("-");
59
+ if (engine === "conftest") {
60
+ const asset = `conftest_${version}_${os === "linux" ? "Linux" : "Darwin"}_${cpu === "x64" ? "x86_64" : "arm64"}.tar.gz`;
61
+ return { engine, version, platform, asset, url: `https://github.com/open-policy-agent/conftest/releases/download/v${version}/${asset}`, archive: true };
62
+ }
63
+ // OPA builds no static binary for darwin on amd64.
64
+ const asset = `opa_${os}_${cpu === "x64" ? "amd64" : "arm64"}${platform === "darwin-x64" ? "" : "_static"}`;
65
+ return { engine, version, platform, asset, url: `https://github.com/open-policy-agent/opa/releases/download/v${version}/${asset}`, archive: false };
66
+ }
67
+ /** The sha256 chant records for a release file, or undefined when it records none. */
68
+ export function pinnedPolicyEngineSha256(release) {
69
+ return POLICY_ENGINE_SHA256[`${release.engine}-${release.version}-${release.platform}`];
70
+ }
71
+ /** This process's platform as chant pins it. Throws on one with no pin. */
72
+ export function policyEnginePlatform(platform = process.platform, arch = process.arch) {
73
+ const os = platform === "linux" || platform === "darwin" ? platform : undefined;
74
+ const cpu = arch === "x64" || arch === "x86_64" || arch === "amd64" ? "x64" : arch === "arm64" || arch === "aarch64" ? "arm64" : undefined;
75
+ if (!os || !cpu)
76
+ throw new Error(`chant pins conftest and OPA for ${POLICY_ENGINE_PLATFORMS.join(", ")}, not ${platform}-${arch}; put the engine on PATH instead`);
77
+ return `${os}-${cpu}`;
78
+ }
79
+ /** Where installed engines are kept by default: `CHANT_TOOL_CACHE`, else `chant-tools` in the temp directory. */
80
+ export function defaultPolicyEngineCache() {
81
+ return process.env.CHANT_TOOL_CACHE || join(tmpdir(), "chant-tools");
82
+ }
83
+ async function fetchBytes(url) {
84
+ const res = await fetch(url);
85
+ if (!res.ok)
86
+ throw new Error(`${url}: HTTP ${res.status}`);
87
+ return new Uint8Array(await res.arrayBuffer());
88
+ }
89
+ /** The bytes of the regular file `name` (at the top, or under `./`) in a tar stream. Undefined when it holds none. */
90
+ export function tarEntry(tar, name) {
91
+ const text = (from, len) => {
92
+ const raw = Buffer.from(tar.subarray(from, from + len)).toString("utf-8");
93
+ const nul = raw.indexOf("\0");
94
+ return nul < 0 ? raw : raw.slice(0, nul);
95
+ };
96
+ let at = 0;
97
+ while (at + 512 <= tar.length) {
98
+ if (tar.subarray(at, at + 512).every((b) => b === 0))
99
+ return undefined;
100
+ const prefix = text(at + 345, 155);
101
+ const entry = (prefix ? `${prefix}/` : "") + text(at, 100);
102
+ const size = parseInt(text(at + 124, 12).trim() || "0", 8);
103
+ const type = text(at + 156, 1);
104
+ const body = at + 512;
105
+ if ((type === "" || type === "0") && entry.replace(/^\.\//, "") === name)
106
+ return tar.subarray(body, body + size);
107
+ at = body + Math.ceil(size / 512) * 512;
108
+ }
109
+ return undefined;
110
+ }
111
+ /**
112
+ * Install `engine` into the cache and return the binary's path. A binary
113
+ * already installed there for that release and platform is returned without
114
+ * a download. Throws when the platform has no pin, the download fails, or
115
+ * the file does not match its pin.
116
+ */
117
+ export async function installPolicyEngine(engine, options = {}) {
118
+ const platform = options.platform ?? policyEnginePlatform();
119
+ const release = policyEngineRelease(engine, platform, options.version);
120
+ const want = options.sha256 ? options.sha256[platform] : pinnedPolicyEngineSha256(release);
121
+ if (want === undefined)
122
+ throw new Error(`chant records no sha256 for ${engine} ${release.version} on ${platform} (${release.asset}); pass sha256 for it, or use ${engine === "opa" ? OPA_VERSION : CONFTEST_VERSION}`);
123
+ if (!SHA256.test(want))
124
+ throw new Error(`the sha256 for ${release.asset} is not 64 hex digits`);
125
+ const dir = join(options.cache ?? defaultPolicyEngineCache(), `${engine}-${release.version}-${platform}`);
126
+ const bin = join(dir, engine);
127
+ if (existsSync(bin))
128
+ return bin;
129
+ const body = await (options.download ?? fetchBytes)(release.url);
130
+ const sum = createHash("sha256").update(body).digest("hex");
131
+ if (sum !== want)
132
+ throw new Error(`${engine} ${release.version} from ${release.url} does not match its pinned sha256 (want ${want}, got ${sum}); not running it`);
133
+ const binary = release.archive ? tarEntry(gunzipSync(body), engine) : body;
134
+ if (!binary)
135
+ throw new Error(`${release.asset} holds no ${engine} binary`);
136
+ mkdirSync(dir, { recursive: true });
137
+ // Written beside its final name and renamed, so a job that stops halfway leaves no binary behind.
138
+ const part = join(dir, `.${engine}.${randomBytes(6).toString("hex")}`);
139
+ writeFileSync(part, binary);
140
+ chmodSync(part, 0o755);
141
+ renameSync(part, bin);
142
+ return bin;
143
+ }
144
+ export const defaultPolicyEngineProbe = (engine) => {
145
+ const r = spawnSync(engine, engine === "opa" ? ["version"] : ["--version"], { stdio: "ignore" });
146
+ return !r.error && r.status === 0;
147
+ };
148
+ /**
149
+ * The engine's executable: its name when the one on PATH answers (an image
150
+ * that carries the engine pays nothing), else the pinned release installed
151
+ * by {@link installPolicyEngine}.
152
+ */
153
+ export async function policyEngineBinary(engine, options = {}) {
154
+ if (!options.pinnedOnly && (options.probe ?? defaultPolicyEngineProbe)(engine))
155
+ return engine;
156
+ return installPolicyEngine(engine, options);
157
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Reads a product asks of a forge beside the ones `./pr-forge.ts` makes
3
+ * (#4809): the user the token acts as, a pull request with its author, URL,
4
+ * state and merge commit, the pull requests from a branch (or a branch
5
+ * prefix) in any state, every note on a pull request, GitHub's check runs on
6
+ * a commit, a pull request's commits, a collaborator's permission level, and
7
+ * every open pull request in the repository.
8
+ *
9
+ * They take the same options as the clients in `./pr-forge.ts` and live in
10
+ * their own module, imported only by the products that call them, so the
11
+ * pull-request loop's and the review agent's bundles do not grow for them
12
+ * (`./pr-forge-bundle.test.ts`, `./pr-loop-bundle.test.ts`,
13
+ * `./review-agent-bundle.test.ts`).
14
+ */
15
+ import { type ForgeFetch, type ForgeKind, type ForgeTarget, type GithubForgeOptions, type GitlabForgeOptions, type OpenPullRequest } from "./pr-forge.js";
16
+ /** The user a token acts as: GitHub's and Forgejo's `login`, GitLab's `username`, and the forge's numeric id. */
17
+ export interface ForgeUser {
18
+ login: string;
19
+ id?: number;
20
+ }
21
+ /** A pull request (merge request) as {@link ForgeReads.pullRequest} reads it. */
22
+ export interface PullRequestDetail {
23
+ /** The pull request's number, or the merge request's iid. */
24
+ number: number;
25
+ url?: string;
26
+ title: string;
27
+ body: string;
28
+ state: "open" | "closed" | "merged";
29
+ /** Its head (source) branch. */
30
+ head: string;
31
+ /** The commit its head points at. */
32
+ headSha?: string;
33
+ /** Its base (target) branch. */
34
+ base?: string;
35
+ /** Who opened it. */
36
+ author?: string;
37
+ /** Its head branch lives in this repository, not a fork. */
38
+ sameRepo: boolean;
39
+ /**
40
+ * Once merged, the commit the merge made on the base branch: the merge or
41
+ * squash commit, or on GitLab the head itself after a fast-forward merge.
42
+ */
43
+ mergeCommit?: string;
44
+ /** When it last changed (ISO 8601). */
45
+ updated?: string;
46
+ }
47
+ /** A comment (note) on a pull request, as {@link ForgeReads.pullRequestNotes} reads it. */
48
+ export interface PullRequestNote {
49
+ id: number;
50
+ body: string;
51
+ author?: string;
52
+ /** The author's numeric id. */
53
+ authorId?: number;
54
+ /** GitLab's own note ("approved this merge request", "added 1 commit"). Always false on GitHub and Forgejo. */
55
+ system: boolean;
56
+ created?: string;
57
+ }
58
+ /** A GitHub check run on a commit. */
59
+ export interface CheckRun {
60
+ id: number;
61
+ name: string;
62
+ /** `queued`, `in_progress` or `completed`, and GitHub's other words for a run not done. */
63
+ status: string;
64
+ /** Once completed: `success`, `failure`, `neutral`, `cancelled`, `skipped`, `timed_out`, `action_required` or `stale`. */
65
+ conclusion?: string;
66
+ }
67
+ /** A person on a commit, as the forge records it. `login` only when the forge ties the address to an account (GitHub, Forgejo). */
68
+ export interface CommitPerson {
69
+ name?: string;
70
+ email?: string;
71
+ login?: string;
72
+ }
73
+ /** One of a pull request's commits. */
74
+ export interface PullRequestCommit {
75
+ sha: string;
76
+ message: string;
77
+ author: CommitPerson;
78
+ committer: CommitPerson;
79
+ }
80
+ /** What {@link ForgeReads.pullRequestsFrom} reads. */
81
+ export interface PullRequestsFromOptions {
82
+ /** Take every head branch that starts with the branch given, not only that branch. */
83
+ prefix?: boolean;
84
+ /** At most this many pull requests are read, newest update first. Default 500. */
85
+ limit?: number;
86
+ }
87
+ /** The reads, for GitHub, Forgejo and GitLab alike. */
88
+ export interface ForgeReads {
89
+ kind: ForgeKind;
90
+ /** The user the client's token acts as (`GET /user`). Undefined when the forge names none. */
91
+ tokenUser(): Promise<ForgeUser | undefined>;
92
+ /** A pull request in any state, or undefined when the forge has none by that number. */
93
+ pullRequest(pr: number): Promise<PullRequestDetail | undefined>;
94
+ /**
95
+ * The pull requests in any state whose head is `branch` (with `prefix`,
96
+ * whose head starts with it), from this repository, newest first by number.
97
+ */
98
+ pullRequestsFrom(branch: string, opts?: PullRequestsFromOptions): Promise<PullRequestDetail[]>;
99
+ /** Every comment on a pull request, GitLab's system notes among them, oldest first. */
100
+ pullRequestNotes(pr: number): Promise<PullRequestNote[]>;
101
+ /** GitHub's check runs on `sha`, the newest per name. Forgejo and GitLab have none and answer `[]`. */
102
+ checkRuns(sha: string): Promise<CheckRun[]>;
103
+ /** A pull request's commits, in the order the forge lists them. */
104
+ pullRequestCommits(pr: number): Promise<PullRequestCommit[]>;
105
+ /**
106
+ * The permission `login` holds on the repository: GitHub's `admin`,
107
+ * `maintain`, `write`, `triage`, `read` or `none`; Forgejo's `owner`,
108
+ * `admin`, `write`, `read` or `none`; GitLab's `guest`, `reporter`,
109
+ * `developer`, `maintainer` or `owner` (project or inherited). Undefined
110
+ * when the forge knows no such user or member.
111
+ */
112
+ permission(login: string): Promise<string | undefined>;
113
+ /** Every open pull request in the repository, into any base, ascending by number. */
114
+ openPullRequests(): Promise<OpenPullRequest[]>;
115
+ }
116
+ /** The reads for a GitHub client's options. */
117
+ export declare function githubReads(opts: GithubForgeOptions): ForgeReads;
118
+ /** The reads for a Forgejo (or Gitea) client's options. */
119
+ export declare function forgejoReads(opts: GithubForgeOptions): ForgeReads;
120
+ /** The reads for a GitLab client's options. */
121
+ export declare function gitlabReads(opts: GitlabForgeOptions): ForgeReads;
122
+ /** The reads for a {@link ForgeTarget}, the way `forgeClient` builds its client. */
123
+ export declare function forgeReadsFor(target: ForgeTarget, fetchImpl?: ForgeFetch): ForgeReads;
124
+ //# sourceMappingURL=pr-forge-reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pr-forge-reads.d.ts","sourceRoot":"","sources":["../src/pr-forge-reads.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,YAAY,CAAC;AAEpB,iHAAiH;AACjH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,iFAAiF;AACjF,MAAM,WAAW,iBAAiB;IAChC,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC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