@intentius/chant 0.124.90 → 0.124.91

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 (63) hide show
  1. package/dist/actor.d.ts +5 -3
  2. package/dist/actor.d.ts.map +1 -1
  3. package/dist/actor.js +7 -5
  4. package/dist/audit/core.d.ts.map +1 -1
  5. package/dist/audit/core.js +11 -1
  6. package/dist/ci-product.d.ts +9 -0
  7. package/dist/ci-product.d.ts.map +1 -1
  8. package/dist/ci-product.js +18 -9
  9. package/dist/cli/handlers/pr-comment.js +2 -2
  10. package/dist/cli/handlers/pr.d.ts +2 -2
  11. package/dist/cli/handlers/pr.d.ts.map +1 -1
  12. package/dist/cli/handlers/pr.js +28 -9
  13. package/dist/cli/parse-args.d.ts.map +1 -1
  14. package/dist/cli/parse-args.js +13 -0
  15. package/dist/cli/registry.d.ts +4 -0
  16. package/dist/cli/registry.d.ts.map +1 -1
  17. package/dist/components/pr-checks.d.ts +11 -0
  18. package/dist/components/pr-checks.d.ts.map +1 -1
  19. package/dist/components/pr-checks.js +15 -5
  20. package/dist/components/pr-pipeline.d.ts +9 -2
  21. package/dist/components/pr-pipeline.d.ts.map +1 -1
  22. package/dist/components/pr-pipeline.js +16 -5
  23. package/dist/components/product-pipeline.d.ts.map +1 -1
  24. package/dist/components/product-pipeline.js +6 -3
  25. package/dist/components/product-plan.d.ts +79 -1
  26. package/dist/components/product-plan.d.ts.map +1 -1
  27. package/dist/components/product-plan.js +140 -16
  28. package/dist/floor-table.data.d.ts.map +1 -1
  29. package/dist/floor-table.data.js +14 -9
  30. package/dist/lexicon-module.d.ts +2 -0
  31. package/dist/lexicon-module.d.ts.map +1 -1
  32. package/dist/lexicon-module.js +6 -2
  33. package/dist/planned-files.d.ts +16 -8
  34. package/dist/planned-files.d.ts.map +1 -1
  35. package/dist/planned-files.js +12 -8
  36. package/dist/pr-post.d.ts +6 -0
  37. package/dist/pr-post.d.ts.map +1 -1
  38. package/dist/pr-post.js +5 -4
  39. package/dist/release-floors.d.ts +7 -1
  40. package/dist/release-floors.d.ts.map +1 -1
  41. package/dist/release-floors.js +8 -2
  42. package/dist/wave-runtime.mjs +215 -215
  43. package/package.json +1 -1
  44. package/src/actor.test.ts +14 -1
  45. package/src/actor.ts +8 -6
  46. package/src/audit/core.ts +13 -1
  47. package/src/audit/first-load.test.ts +101 -0
  48. package/src/ci-product.ts +20 -9
  49. package/src/cli/handlers/pr-comment.ts +2 -2
  50. package/src/cli/handlers/pr.ts +23 -9
  51. package/src/cli/parse-args.ts +9 -0
  52. package/src/cli/registry.ts +4 -0
  53. package/src/components/pr-checks.ts +16 -5
  54. package/src/components/pr-pipeline.ts +17 -7
  55. package/src/components/product-pipeline.ts +6 -3
  56. package/src/components/product-plan-names.test.ts +135 -0
  57. package/src/components/product-plan.ts +210 -18
  58. package/src/floor-table.data.ts +14 -9
  59. package/src/lexicon-module.ts +6 -2
  60. package/src/planned-files.test.ts +33 -0
  61. package/src/planned-files.ts +26 -10
  62. package/src/pr-post.ts +11 -4
  63. package/src/release-floors.ts +11 -2
@@ -34,6 +34,39 @@ describe("planFile and writePlannedFiles", () => {
34
34
  expect(modeOf(script)).toBe(0o755);
35
35
  });
36
36
 
37
+ /** #5006: a product's byte files, such as terragucci's `registry edge` bundles, beside its text ones. */
38
+ test("bytes are written unchanged and compared with the file byte for byte", () => {
39
+ const root = dir();
40
+ const zip = join(root, "edge", "bundle.zip");
41
+ const bytes = new Uint8Array([0x50, 0x4b, 0x03, 0x04, 0xff, 0x00, 0xfe]);
42
+ const files: { path: string; content: string | Buffer }[] = [
43
+ { path: "worker.mjs", content: Buffer.from([0xef, 0xbb, 0xbf, 0x80]) },
44
+ { path: "wrangler.toml", content: "name = \"r\"\n" },
45
+ ];
46
+ const plan = [planFile(zip, bytes), ...files.map((f) => planFile(join(root, "edge", f.path), f.content))];
47
+ expect(plan.map((f) => f.status)).toEqual(["created", "created", "created"]);
48
+ expect(plan[0].content).toBe(bytes);
49
+ writePlannedFiles(plan);
50
+ expect([...readFileSync(zip)]).toEqual([...bytes]);
51
+ expect([...readFileSync(join(root, "edge", "worker.mjs"))]).toEqual([0xef, 0xbb, 0xbf, 0x80]);
52
+ expect(readFileSync(join(root, "edge", "wrangler.toml"), "utf-8")).toBe("name = \"r\"\n");
53
+ expect(planFile(zip, Buffer.from(bytes)).status).toBe("unchanged");
54
+ expect(planFile(join(root, "edge", "worker.mjs"), files[0].content).status).toBe("unchanged");
55
+ // A view into a larger buffer compares only its own bytes.
56
+ const wider = new Uint8Array([9, ...bytes, 9]);
57
+ expect(planFile(zip, wider.subarray(1, 1 + bytes.length)).status).toBe("unchanged");
58
+ // 0xff and 0xfe both read as U+FFFD in UTF-8 text, so only a byte compare tells them apart.
59
+ const odd = join(root, "odd.bin");
60
+ writeFileSync(odd, Buffer.from([0xff]));
61
+ expect(planFile(odd, "�").status).toBe("unchanged");
62
+ expect(planFile(odd, new Uint8Array([0xfe])).status).toBe("updated");
63
+ expect(planFile(odd, new Uint8Array([0xff, 0x00])).status).toBe("updated");
64
+ const binary = planFile(odd, new Uint8Array([0xfe]), { mode: 0o600 });
65
+ writePlannedFiles([binary]);
66
+ expect([...readFileSync(odd)]).toEqual([0xfe]);
67
+ expect(modeOf(odd)).toBe(0o600);
68
+ });
69
+
37
70
  test("a removal is planned only for a file that is there, and written by unlinking it", () => {
38
71
  const root = dir();
39
72
  const old = join(root, "old.yml");
@@ -12,6 +12,8 @@
12
12
  *
13
13
  * - {@link planFile} plans one file against what is on disk, its mode
14
14
  * included, and writes nothing, so a dry run prints the plan as it is.
15
+ * Its content is text, or bytes for a file such as terragucci's
16
+ * `registry edge` bundles, compared byte for byte (#5006).
15
17
  * - {@link planRemoval} plans the removal of a file an earlier run wrote.
16
18
  * - {@link writePlannedFiles} writes the plan: each directory made, each
17
19
  * file's mode set, each removed file unlinked, an unchanged one left as
@@ -28,14 +30,17 @@
28
30
  import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from "node:fs";
29
31
  import { dirname, join } from "node:path";
30
32
 
31
- /** One planned file. */
32
- export interface PlannedFile {
33
+ /** What a planned file holds: text, or bytes such as a bundle or a zip, written as they are (#5006). A `Buffer` is a `Uint8Array`. */
34
+ export type PlannedContent = string | Uint8Array;
35
+
36
+ /** One planned file. Its content is text unless the plan was made with bytes (#5006). */
37
+ export interface PlannedFile<C extends PlannedContent = string> {
33
38
  /** Where it is written. Absolute, or relative to the process's directory. */
34
39
  path: string;
35
40
  /** `removed`: a file an earlier run wrote that this one no longer asks for. */
36
41
  status: "created" | "updated" | "unchanged" | "removed";
37
- /** The text to write; empty for a removal. */
38
- content: string;
42
+ /** The text or bytes to write; empty text for a removal. */
43
+ content: C;
39
44
  /** The permission bits to set, such as `0o755` for a script. Unset, a new file gets the process's default and an existing one keeps its own. */
40
45
  mode?: number;
41
46
  /** In the git directory or otherwise never committed, such as a hook. */
@@ -51,15 +56,25 @@ function modeOf(path: string): number | undefined {
51
56
  }
52
57
  }
53
58
 
59
+ /** Whether the file at `path` holds `content`: text compared as UTF-8 text, bytes compared byte for byte (#5006). */
60
+ function holds(path: string, content: PlannedContent): boolean {
61
+ if (typeof content === "string") return readFileSync(path, "utf-8") === content;
62
+ return Buffer.from(content.buffer, content.byteOffset, content.byteLength).equals(readFileSync(path));
63
+ }
64
+
54
65
  /**
55
66
  * Plan `content` at `path`: `created` when there is no file, `unchanged`
56
67
  * when the file holds the content (and, with `mode`, has that mode),
57
- * `updated` otherwise. Writes nothing.
68
+ * `updated` otherwise. Writes nothing. Content given as bytes is compared
69
+ * with the file byte for byte, and the plan carries the bytes (#5006).
58
70
  */
59
- export function planFile(path: string, content: string, extra: Pick<PlannedFile, "mode" | "local"> = {}): PlannedFile {
71
+ export function planFile(path: string, content: string, extra?: Pick<PlannedFile, "mode" | "local">): PlannedFile;
72
+ export function planFile(path: string, content: Uint8Array, extra?: Pick<PlannedFile, "mode" | "local">): PlannedFile<Uint8Array>;
73
+ export function planFile(path: string, content: PlannedContent, extra?: Pick<PlannedFile, "mode" | "local">): PlannedFile<PlannedContent>;
74
+ export function planFile(path: string, content: PlannedContent, extra: Pick<PlannedFile, "mode" | "local"> = {}): PlannedFile<PlannedContent> {
60
75
  const own = { ...(extra.mode !== undefined ? { mode: extra.mode } : {}), ...(extra.local ? { local: true } : {}) };
61
76
  if (!existsSync(path)) return { path, status: "created", content, ...own };
62
- const same = readFileSync(path, "utf-8") === content && (extra.mode === undefined || modeOf(path) === extra.mode);
77
+ const same = holds(path, content) && (extra.mode === undefined || modeOf(path) === extra.mode);
63
78
  return { path, status: same ? "unchanged" : "updated", content, ...own };
64
79
  }
65
80
 
@@ -71,9 +86,10 @@ export function planRemoval(path: string): PlannedFile | undefined {
71
86
  /**
72
87
  * Write a plan: each created or updated file written, its directory made
73
88
  * and its mode set; each removed file unlinked; an unchanged file not
74
- * touched. A removed file that is already gone is not an error.
89
+ * touched. A removed file that is already gone is not an error. Bytes
90
+ * are written as they are (#5006).
75
91
  */
76
- export function writePlannedFiles(files: readonly Pick<PlannedFile, "path" | "status" | "content" | "mode">[]): void {
92
+ export function writePlannedFiles(files: readonly Pick<PlannedFile<PlannedContent>, "path" | "status" | "content" | "mode">[]): void {
77
93
  for (const f of files) {
78
94
  if (f.status === "unchanged") continue;
79
95
  if (f.status === "removed") {
@@ -131,4 +147,4 @@ export function staleGeneratedFiles(options: StaleGeneratedOptions): string[] {
131
147
  return out;
132
148
  }
133
149
 
134
- export { PLANNED_FILES_FLOOR } from "./release-floors";
150
+ export { PLANNED_BYTES_FLOOR, PLANNED_FILES_FLOOR } from "./release-floors";
package/src/pr-post.ts CHANGED
@@ -58,6 +58,8 @@ export interface PlanPostInput {
58
58
  head: string;
59
59
  env: string;
60
60
  member?: string;
61
+ /** The plan status's context (#5003, a product plan's `statusContext`), in place of {@link prStatusContext}'s. */
62
+ context?: string;
61
63
  /** The plan job's own result (`needs.plan.result`). `failure` fails the status. */
62
64
  result?: string;
63
65
  /**
@@ -302,7 +304,7 @@ export async function postPlanReport(input: PlanPostInput): Promise<PlanPostResu
302
304
  // #4799: a product's plan verb wrote its plan note hand-off in place of pr-plan's report.
303
305
  if (!existsSync(join(input.dir, PR_PLAN_REPORT_FILE)) && existsSync(join(input.dir, PR_PLAN_NOTE_FILE))) return postPlanNoteHandoff(input);
304
306
  const warnings: string[] = [];
305
- const context = prStatusContext("plan", input.member);
307
+ const context = input.context ?? prStatusContext("plan", input.member);
306
308
  const read = readPlanReport(input);
307
309
  const failedJob = input.result === "failure" || input.result === "cancelled";
308
310
  let state: PlanPostResult["state"];
@@ -538,7 +540,7 @@ export function planNoteHandoffNote(handoff: PrPlanNoteHandoff, forge: Pick<PrFo
538
540
  /** {@link postPlanReport} for a product's plan note hand-off (#4799). */
539
541
  async function postPlanNoteHandoff(input: PlanPostInput): Promise<PlanPostResult> {
540
542
  const warnings: string[] = [];
541
- const context = prStatusContext("plan", input.member);
543
+ const context = input.context ?? prStatusContext("plan", input.member);
542
544
  const read = readPlanNoteHandoff(input);
543
545
  const failedJob = input.result === "failure" || input.result === "cancelled";
544
546
  let state: PlanPostResult["state"];
@@ -613,6 +615,8 @@ export interface OpenPlanPostInput {
613
615
  artifactDir: string;
614
616
  env: string;
615
617
  member?: string;
618
+ /** The plan status's context (#5003), in place of {@link prStatusContext}'s. */
619
+ context?: string;
616
620
  overdue?: () => Promise<PrOverdue[]>;
617
621
  /** The description check, as {@link PlanPostInput.description}. */
618
622
  description?: (report: PrReport) => Promise<void>;
@@ -655,7 +659,7 @@ export async function postOpenPlanReports(input: OpenPlanPostInput): Promise<{ p
655
659
  if (!forge.mergeRequestJobs || !forge.jobArtifact || !forge.statusUrl) {
656
660
  throw new Error(`pr-post --open reads the plan jobs of open merge requests, which ${forge.kind} cannot say; it is for GitLab`);
657
661
  }
658
- const context = prStatusContext("plan", input.member);
662
+ const context = input.context ?? prStatusContext("plan", input.member);
659
663
  const warnings: string[] = [];
660
664
  let overdue: Promise<PrOverdue[]> | undefined;
661
665
  const overdueOnce = input.overdue ? () => (overdue ??= input.overdue!()) : undefined;
@@ -692,6 +696,7 @@ export async function postOpenPlanReports(input: OpenPlanPostInput): Promise<{ p
692
696
  head: job.head,
693
697
  env: input.env,
694
698
  ...(input.member ? { member: input.member } : {}),
699
+ ...(input.context ? { context: input.context } : {}),
695
700
  result: settled,
696
701
  ...(overdueOnce ? { overdue: overdueOnce } : {}),
697
702
  ...(input.description ? { description: input.description } : {}),
@@ -721,6 +726,8 @@ export interface StaleMarkInput {
721
726
  tip: string;
722
727
  env: string;
723
728
  member?: string;
729
+ /** The plan status's context (#5003), which goes back to pending, in place of {@link prStatusContext}'s. */
730
+ context?: string;
724
731
  /** The pipeline answers the plan comment (`--preview-comment`), so the stale line names it. */
725
732
  previewComment?: boolean;
726
733
  words?: CiProductWords;
@@ -750,7 +757,7 @@ export async function markStaleNotes(input: StaleMarkInput): Promise<{ marks: St
750
757
  if (!forge.openPullRequests) throw new Error(`marking notes stale lists the open pull requests into ${input.branch}, which this ${forge.kind} client cannot`);
751
758
  const words = input.words ?? activeProductWords();
752
759
  const marker = prNoteMarker(input.env, input.member);
753
- const context = prStatusContext("plan", input.member, words);
760
+ const context = input.context ?? prStatusContext("plan", input.member, words);
754
761
  const comment = input.previewComment ? commentLine(words, "plan") : undefined;
755
762
  const verb = words.verbs.plan[0];
756
763
  const again = comment ? `comment \`${comment}\` to ${verb} again` : `push a commit to ${verb} again`;
@@ -19,7 +19,7 @@
19
19
  * this constant to the next patch (#4501). The check fails while a floor
20
20
  * still names this constant after its version shipped.
21
21
  */
22
- export const NEXT_RELEASE = "0.124.90";
22
+ export const NEXT_RELEASE = "0.124.91";
23
23
 
24
24
  /** The first chant with `chant dev local` and `chant dev bundle-check`, `@intentius/chant/local-chant` and `@intentius/chant/bundle-check` (`chantRuntimeTarget`, `chantExternalPlugin`, `checkBundle`): a product built against a chant checkout, and its bundle checked, without its own scripts (#4787). */
25
25
  export const LOCAL_CHANT_FLOOR = "0.124.86";
@@ -202,7 +202,7 @@ export const MEMBER_SIGNED_CHECKS_FLOOR = "0.124.89";
202
202
  export const PRODUCT_CHECK_JOBS_FLOOR = "0.124.89";
203
203
 
204
204
  /** The first chant whose `checkJob` takes `artifacts: { paths, reports }` (`PrCheckArtifacts`), which GitLab's check job keeps beside its report as `artifacts:paths` and `artifacts:reports`, such as a lint hook's `codequality` report (#4988). */
205
- export const CHECK_JOB_ARTIFACTS_FLOOR = NEXT_RELEASE;
205
+ export const CHECK_JOB_ARTIFACTS_FLOOR = "0.124.90";
206
206
 
207
207
  /** The first chant whose GitLab Op waves pipeline with a runner key hands it to no wave job: each deciding wave's `<wave job>-evidence` job names the `chant-evidence` environment and signs `plan:<wave>` from the wave job (#4964). */
208
208
  export const GITLAB_WAVE_KEY_SCOPE_FLOOR = "0.124.89";
@@ -210,12 +210,18 @@ export const GITLAB_WAVE_KEY_SCOPE_FLOOR = "0.124.89";
210
210
  /** The first chant with `actorOf` and `actorOrder` in `@intentius/chant/actor`: the actor fallback with `GITHUB_TRIGGERING_ACTOR` ahead of the forge's actor and git's `user.name` before the login, each place switched on or off by the caller (#4966). */
211
211
  export const ACTOR_ORDER_FLOOR = "0.124.89";
212
212
 
213
+ /** The first chant whose `actorOf({ env, repo })` runs `git config` in `repo` with the `env` it is given rather than the process's, so a job's `GIT_CONFIG_GLOBAL` or `HOME` picks the `user.name` it reads (#5005). */
214
+ export const ACTOR_GIT_ENV_FLOOR = NEXT_RELEASE;
215
+
213
216
  /** The first chant with `@intentius/chant/ci-base` (`ciBaseRef`), the base a CI job measures a change from (the pull request's target branch, else the default branch for a push to another branch), and whose `chant ci check` defaults `--base` to it (#4966). */
214
217
  export const CI_BASE_REF_FLOOR = "0.124.89";
215
218
 
216
219
  /** The first chant with `@intentius/chant/planned-files` (`planFile`, `planRemoval`, `writePlannedFiles`, `staleGeneratedFiles`): an init's planned files with their modes, written or removed in one call, and the generated files a product no longer renders, found by their header (#4966). */
217
220
  export const PLANNED_FILES_FLOOR = "0.124.89";
218
221
 
222
+ /** The first chant whose `planFile` in `@intentius/chant/planned-files` takes bytes (`Uint8Array` or `Buffer`) as well as text: `writePlannedFiles` writes them unchanged and the plan compares them with the file byte for byte (#5006). */
223
+ export const PLANNED_BYTES_FLOOR = NEXT_RELEASE;
224
+
219
225
  /** The first chant whose `pipelineContract` takes `jobs`, the jobs a product builds from its own config, beside or in place of `pipelines`, so a product's forge check gets the required statuses and `refGateStatus` from chant (#4966). */
220
226
  export const FORGE_CHECK_OWN_JOBS_FLOOR = "0.124.89";
221
227
 
@@ -230,3 +236,6 @@ export const RUNTIME_WAVES_SPEC_FLOOR = "0.124.89";
230
236
 
231
237
  /** The first chant whose `chant run resume` (`resumeGateRun`) on GitLab retries a wave job's `<wave job>-evidence` with the wave job when the evidence job already ran, and whose `ci evidence sign --from-job` waits for a job it reads to finish, so a resumed wave's evidence job signs from the new try (#4978). */
232
238
  export const GITLAB_WAVE_EVIDENCE_RETRY_FLOOR = "0.124.89";
239
+
240
+ /** The first chant whose terraform lexicon's engine runs carry what a product's own command tracing read: `runBinary` and the engine runner's `exec` and `execSync` answer stderr apart (`Ran.stderr`) and a spawn failure's message (`Ran.error`), a hook's `after` gets a binary that could not be started as a null code with `error`, `commandTrace` ends that span with the message, and `composeCommandHooks` runs a product's own hook and `commandTrace` as one `onCommand` (#5007). */
241
+ export const TERRAFORM_COMMAND_TRACE_FLOOR = NEXT_RELEASE;