@intentius/chant 0.124.85 → 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
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The drift issue bundles small (#4790, ruling #3421).
3
+ *
4
+ * plywood, SQL Yodeler and terragucci keep their drift issue from a bundled
5
+ * file beside the forge clients, so `@intentius/chant/drift-issue` imports
6
+ * types only from the clients and the drift record. This bundles it alone,
7
+ * the way a product would, and reads esbuild's list of what went in.
8
+ */
9
+
10
+ import { join } from "node:path";
11
+ import { build } from "esbuild";
12
+ import { describe, expect, test } from "vitest";
13
+ import { REPO } from "./workspace/__fixtures__/contract-repo";
14
+
15
+ describe("the drift-issue bundle", () => {
16
+ test("holds the drift issue and nothing else", async () => {
17
+ const result = await build({
18
+ entryPoints: [join(REPO, "packages", "core", "src", "drift-issue.ts")],
19
+ bundle: true,
20
+ platform: "node",
21
+ format: "esm",
22
+ write: false,
23
+ metafile: true,
24
+ outdir: "out",
25
+ logLevel: "silent",
26
+ });
27
+ expect(Object.keys(result.metafile.inputs).map((i) => i.replace(/^.*?packages\//, "packages/"))).toEqual(["packages/core/src/drift-issue.ts"]);
28
+ // About 5.5 KB today.
29
+ expect(result.outputFiles.reduce((n, f) => n + f.contents.byteLength, 0)).toBeLessThan(12 * 1024);
30
+ });
31
+ });
@@ -0,0 +1,206 @@
1
+ /**
2
+ * One drift issue per environment (#4790), over each forge's real client and
3
+ * a fake forge that keeps its issues in memory.
4
+ */
5
+
6
+ import { describe, expect, test } from "vitest";
7
+ import { driftIssueBody, driftIssueFingerprint, driftIssueMarker, keepDriftIssue, type DriftIssueInput, type DriftIssueRecord, type DriftIssueWords } from "./drift-issue";
8
+ import { forgejoForge, githubForge, gitlabForge, type ForgeFetch, type PrForge } from "./pr-forge";
9
+
10
+ interface FakeIssue {
11
+ n: number;
12
+ title: string;
13
+ body: string;
14
+ open: boolean;
15
+ comments: string[];
16
+ }
17
+
18
+ /** A forge with issues in memory, answering the GitHub and Forgejo shape, or GitLab's. */
19
+ function fakeForge(kind: "github" | "forgejo" | "gitlab"): { forge: PrForge; issues: FakeIssue[]; writes: string[] } {
20
+ const issues: FakeIssue[] = [];
21
+ const writes: string[] = [];
22
+ const gl = kind === "gitlab";
23
+ const base = gl ? "/api/v4/projects/group%2Fapp/issues" : kind === "forgejo" ? "/api/v1/repos/acme/infra/issues" : "/repos/acme/infra/issues";
24
+ const shape = (i: FakeIssue) => (gl ? { iid: i.n, title: i.title, description: i.body, web_url: `https://forge/i/${i.n}` } : { number: i.n, title: i.title, body: i.body, html_url: `https://forge/i/${i.n}` });
25
+ const fetch: ForgeFetch = async (url, init) => {
26
+ const u = new URL(url);
27
+ const body = init.body ? (JSON.parse(init.body) as Record<string, string>) : {};
28
+ const ok = (v: unknown) => ({ ok: true, status: 200, text: async () => JSON.stringify(v) });
29
+ if (init.method !== "GET") writes.push(`${init.method} ${u.pathname.slice(base.length) || "/"}`);
30
+ if (u.pathname === base && init.method === "GET") return ok(u.searchParams.get("page") && u.searchParams.get("page") !== "1" ? [] : issues.filter((i) => i.open).map(shape));
31
+ if (u.pathname === base && init.method === "POST") {
32
+ const i = { n: issues.length + 1, title: body.title!, body: (gl ? body.description : body.body)!, open: true, comments: [] };
33
+ issues.push(i);
34
+ return ok(shape(i));
35
+ }
36
+ const m = /^\/(\d+)(\/comments|\/notes)?$/.exec(u.pathname.slice(base.length));
37
+ const i = m ? issues.find((x) => x.n === Number(m[1])) : undefined;
38
+ if (!m || !i) return { ok: false, status: 404, text: async () => '{"message":"Not Found"}' };
39
+ if (m[2]) {
40
+ i.comments.push(body.body!);
41
+ return ok({ id: 1 });
42
+ }
43
+ if (body.state === "closed" || body.state_event === "close") i.open = false;
44
+ if (body.title !== undefined) i.title = body.title;
45
+ const text = gl ? body.description : body.body;
46
+ if (text !== undefined) i.body = text;
47
+ return ok(shape(i));
48
+ };
49
+ const forge =
50
+ kind === "github"
51
+ ? githubForge({ apiBase: "https://api.github.com", repo: "acme/infra", token: "t", fetch })
52
+ : kind === "forgejo"
53
+ ? forgejoForge({ apiBase: "https://codeberg.org/api/v1", repo: "acme/infra", token: "t", host: "codeberg.org", fetch })
54
+ : gitlabForge({ apiBase: "https://gitlab.example.com/api/v4", project: "group/app", token: "t", fetch });
55
+ return { forge, issues, writes };
56
+ }
57
+
58
+ const words: DriftIssueWords = {
59
+ product: "plywood",
60
+ title: (f) => `plywood: ${f.environment} has drifted`,
61
+ address: "URN",
62
+ advice: (f) => `To put the cloud back to the program, merge a change to ${f.environment} or run \`plywood up\`.`,
63
+ cleared: (f) => `plywood's drift check at ${f.observedAt} found ${f.environment} matching its state, so this issue is closed.`,
64
+ };
65
+
66
+ const record = (address: string, status: DriftIssueRecord["status"], extra: Partial<DriftIssueRecord> = {}): DriftIssueRecord => ({
67
+ member: "infra/prod",
68
+ address,
69
+ status,
70
+ observedAt: "2026-11-09T06:00:00Z",
71
+ ...extra,
72
+ });
73
+
74
+ const bucket = record("urn:pulumi:prod::infra::aws:s3/bucket:Bucket::logs", "drifted", { attributes: [{ path: "tags.owner", before: "ops", after: "dev" }] });
75
+ const queue = record("urn:pulumi:prod::infra::aws:sqs/queue:Queue::jobs", "missing");
76
+ const role = record("urn:pulumi:prod::infra::aws:iam/role:Role::ci", "in-sync");
77
+
78
+ describe("keepDriftIssue (#4790)", () => {
79
+ for (const kind of ["github", "forgejo", "gitlab"] as const) {
80
+ test(`${kind}: opens, leaves an unchanged drift alone, updates a new one, closes when it clears`, async () => {
81
+ const { forge, issues, writes } = fakeForge(kind);
82
+ const input: DriftIssueInput = { words, environment: "infra/prod", records: [bucket, role, queue], runUrl: "https://ci/run/1" };
83
+
84
+ const opened = await keepDriftIssue(forge, input);
85
+ expect(opened).toMatchObject({ action: "opened", number: 1, marker: "<!-- plywood:drift infra/prod -->", fingerprint: driftIssueFingerprint([bucket, queue]) });
86
+ expect(issues[0]!.title).toBe("plywood: infra/prod has drifted");
87
+ expect(issues[0]!.body.split("\n")[0]).toBe("<!-- plywood:drift infra/prod -->");
88
+
89
+ // The next run names another run and finds the same drift: no write.
90
+ const before = writes.length;
91
+ expect((await keepDriftIssue(forge, { ...input, runUrl: "https://ci/run/2", records: [queue, role, bucket] })).action).toBe("unchanged");
92
+ expect(writes.length).toBe(before);
93
+
94
+ // The drift moved: the one issue is edited, not a second one opened.
95
+ const moved = record(bucket.address, "drifted", { attributes: [{ path: "tags.owner", before: "ops", after: "qa" }] });
96
+ expect(await keepDriftIssue(forge, { ...input, records: [moved, queue] })).toMatchObject({ action: "updated", number: 1 });
97
+ expect(issues).toHaveLength(1);
98
+ expect(issues[0]!.body).toContain(driftIssueFingerprint([moved, queue]));
99
+
100
+ // Another environment keeps its own issue.
101
+ expect((await keepDriftIssue(forge, { ...input, environment: "infra/dev" })).action).toBe("opened");
102
+ expect(issues).toHaveLength(2);
103
+
104
+ // Clean: closed, with the product's comment.
105
+ const closed = await keepDriftIssue(forge, { ...input, records: [record(bucket.address, "in-sync"), role] });
106
+ expect(closed).toMatchObject({ action: "closed", number: 1 });
107
+ expect(issues[0]).toMatchObject({ open: false, comments: ["plywood's drift check at 2026-11-09T06:00:00Z found infra/prod matching its state, so this issue is closed."] });
108
+ expect(issues[1]!.open).toBe(true);
109
+
110
+ // Clean again: nothing open, nothing written.
111
+ const after = writes.length;
112
+ expect((await keepDriftIssue(forge, { ...input, records: [role] })).action).toBe("none");
113
+ expect(writes.length).toBe(after);
114
+
115
+ // Drift found after a close opens a fresh issue: a closed one is never reopened.
116
+ expect(await keepDriftIssue(forge, input)).toMatchObject({ action: "opened", number: 3 });
117
+ });
118
+ }
119
+
120
+ test("a read that proves nothing leaves the open issue as it is", async () => {
121
+ const { forge, issues, writes } = fakeForge("github");
122
+ const input: DriftIssueInput = { words, environment: "infra/prod", records: [bucket] };
123
+ await keepDriftIssue(forge, input);
124
+ const before = writes.length;
125
+ const unread = record(bucket.address, "not-observed", { unobserved: { reason: "no-credentials" } });
126
+ expect(await keepDriftIssue(forge, { ...input, records: [unread, role] })).toMatchObject({
127
+ action: "left",
128
+ number: 1,
129
+ why: "1 resource could not be read, so whether infra/prod drifted is unknown",
130
+ });
131
+ expect(await keepDriftIssue(forge, { ...input, records: [], unknown: "the drift could not be read (exit 1)" })).toMatchObject({ action: "left", why: "the drift could not be read (exit 1)" });
132
+ expect(writes.length).toBe(before);
133
+ expect(issues[0]!.open).toBe(true);
134
+ });
135
+
136
+ test("a product's own marker keeps its open issues", async () => {
137
+ const { forge, issues } = fakeForge("gitlab");
138
+ const marker = "<!-- yodel:drift project=. env=prod -->";
139
+ await keepDriftIssue(forge, { words: { product: "yodel", title: () => "Drift in prod" }, environment: "prod", records: [queue], marker });
140
+ expect(issues[0]!.body.startsWith(`${marker}\n`)).toBe(true);
141
+ expect(await keepDriftIssue(forge, { words: { product: "yodel", title: () => "Drift in prod" }, environment: "prod", records: [queue], marker })).toMatchObject({ action: "unchanged", marker });
142
+ });
143
+ });
144
+
145
+ describe("the drift issue's parts (#4790)", () => {
146
+ test("the fingerprint is the drift's: order, time, run and unread or in-sync records leave it as it is", () => {
147
+ const later = { ...bucket, observedAt: "2026-11-10T00:00:00Z" };
148
+ const unread = record("urn:x", "not-observed", { unobserved: { reason: "no-credentials" } });
149
+ expect(driftIssueFingerprint([bucket, queue])).toBe(driftIssueFingerprint([queue, role, later, unread]));
150
+ expect(driftIssueFingerprint([bucket, queue])).toMatch(/^[0-9a-f]{16}$/);
151
+ expect(driftIssueFingerprint([bucket])).not.toBe(driftIssueFingerprint([bucket, queue]));
152
+ expect(driftIssueFingerprint([bucket])).not.toBe(driftIssueFingerprint([{ ...bucket, attributes: [{ path: "tags.owner", before: "ops", after: "qa" }] }]));
153
+ });
154
+
155
+ test("the body: marker, intro, table, unread records, notes, advice, run and fingerprint", () => {
156
+ const unread = record("urn:pulumi:prod::infra::aws:s3/bucket:Bucket::audit", "not-observed", { unobserved: { reason: "no-credentials", detail: "AccessDenied" } });
157
+ const body = driftIssueBody({ words, environment: "infra/prod", records: [queue, bucket, role, unread], runUrl: "https://ci/run/1", notes: ["Who changed each attribute:", "- tags.owner: alice"] }, "f00");
158
+ expect(body).toBe(
159
+ [
160
+ "<!-- plywood:drift infra/prod -->",
161
+ "plywood's drift check read infra/prod at 2026-11-09T06:00:00Z and found 2 resources that differ.",
162
+ "",
163
+ "| URN | Status | Attributes |",
164
+ "|---|---|---|",
165
+ "| `urn:pulumi:prod::infra::aws:s3/bucket:Bucket::logs` | drifted | `tags.owner` |",
166
+ "| `urn:pulumi:prod::infra::aws:sqs/queue:Queue::jobs` | missing | |",
167
+ "",
168
+ "Could not be read, so their state is unknown:",
169
+ "",
170
+ "- `urn:pulumi:prod::infra::aws:s3/bucket:Bucket::audit`: no-credentials (AccessDenied)",
171
+ "",
172
+ "Who changed each attribute:",
173
+ "- tags.owner: alice",
174
+ "",
175
+ "To put the cloud back to the program, merge a change to infra/prod or run `plywood up`.",
176
+ "",
177
+ "Found by https://ci/run/1.",
178
+ "",
179
+ "<!-- plywood:drift-fingerprint f00 -->",
180
+ ].join("\n"),
181
+ );
182
+ });
183
+
184
+ test("values in the product's words, a member column when several drifted, and a cell that keeps the table", () => {
185
+ const yodel: DriftIssueWords = { product: "yodel", title: () => "t", values: { before: "declared", after: "live" } };
186
+ const secret = record("app.users", "drifted", { member: "db", attributes: [{ path: "password", sensitive: true }, { path: "columns[1]", before: "int", after: "bigint" }] });
187
+ const piped = record("a|b", "missing", { member: "other" });
188
+ const body = driftIssueBody({ words: yodel, environment: "prod", records: [secret, piped] }, "f");
189
+ expect(body).toContain("| Member | Address | Status | Attributes |");
190
+ expect(body).toContain("| `db` | `app.users` | drifted | `columns[1]`: declared `int`, live `bigint`, `password` (sensitive) |");
191
+ expect(body).toContain("| `other` | `a\\|b` | missing | |");
192
+ });
193
+
194
+ test("statuses names what is drift, for a read with no snapshot", async () => {
195
+ const gone = record("app.events", "pending", { member: "." });
196
+ expect(driftIssueFingerprint([gone])).toBe(driftIssueFingerprint([]));
197
+ const { forge } = fakeForge("github");
198
+ const yodel: DriftIssueWords = { product: "yodel", title: () => "Drift in prod" };
199
+ expect((await keepDriftIssue(forge, { words: yodel, environment: "prod", records: [gone] })).action).toBe("none");
200
+ expect((await keepDriftIssue(forge, { words: yodel, environment: "prod", records: [gone], statuses: ["drifted", "missing", "pending"] })).action).toBe("opened");
201
+ });
202
+
203
+ test("the default marker cannot end its comment", () => {
204
+ expect(driftIssueMarker("plywood", "a b-->c")).toBe("<!-- plywood:drift a_bc -->");
205
+ });
206
+ });
@@ -0,0 +1,274 @@
1
+ /**
2
+ * One drift issue per environment (#4790).
3
+ *
4
+ * plywood, SQL Yodeler and terragucci each kept a tracking issue for an
5
+ * environment's drift through the forge client's `trackIssue` (#3759), and
6
+ * each wrote the rest itself: the hidden marker that finds the issue again,
7
+ * a fingerprint of the drift so a run that finds the same drift does not
8
+ * edit the issue, the body, and the comment that closes the issue when the
9
+ * drift clears. {@link keepDriftIssue} is that, once. A product passes its
10
+ * words and the run's drift records, and the call decides:
11
+ *
12
+ * - drift found (a record `drifted` or `missing`): open the issue, or update
13
+ * the open one when the fingerprint or the title changed. An issue that
14
+ * already carries the fingerprint is left as it is, so a body that names
15
+ * the run or the time does not edit it on every scheduled run;
16
+ * - no drift, and every record was read: close the open issue with the
17
+ * product's comment;
18
+ * - no drift, and a record is `not-observed`, or the caller says the read
19
+ * failed (`unknown`): leave the open issue as it is. A read that proves
20
+ * nothing neither closes nor opens one.
21
+ *
22
+ * Only open issues are read, so an issue closed by hand stays closed and the
23
+ * next drift opens a new one. It runs on GitHub, GitLab and Forgejo through
24
+ * any client with `trackIssue` (`@intentius/chant/pr-forge`), and needs no
25
+ * read of its own.
26
+ *
27
+ * ```ts
28
+ * import { forgeClient, forgeTargetFromEnv } from "@intentius/chant/pr-forge";
29
+ * import { keepDriftIssue } from "@intentius/chant/drift-issue";
30
+ *
31
+ * const forge = forgeClient(forgeTargetFromEnv(process.env, { kind: "github" }));
32
+ * const r = await keepDriftIssue(forge, { words, environment: "acme/prod", records });
33
+ * ```
34
+ *
35
+ * The module imports types only, apart from `node:crypto`, so a product's
36
+ * bundle gains this file and nothing else (`drift-issue-bundle.test.ts`).
37
+ */
38
+
39
+ import { createHash } from "node:crypto";
40
+ import type { DriftAttribute, DriftRecord, DriftStatus } from "./drift-record";
41
+ import type { IssueResult, MarkerMatch, PrForge } from "./pr-forge";
42
+
43
+ /** The statuses that are drift for the issue: present and different, or gone. */
44
+ export const DRIFT_ISSUE_STATUSES: readonly DriftStatus[] = ["drifted", "missing"];
45
+
46
+ /** What the issue reads of a record. Any {@link DriftRecord} is one. */
47
+ export type DriftIssueRecord = Pick<DriftRecord, "member" | "address" | "status"> & Partial<Pick<DriftRecord, "resourceType" | "attributes" | "unobserved" | "observedAt">>;
48
+
49
+ /** What the issue says about the environment, for {@link DriftIssueWords}. */
50
+ export interface DriftIssueFacts {
51
+ environment: string;
52
+ /** The records that are drift, sorted by member and address. */
53
+ drifted: readonly DriftIssueRecord[];
54
+ /** The latest `observedAt` among the records, else the caller's, else now. */
55
+ observedAt: string;
56
+ }
57
+
58
+ /** A product's words for its drift issue. Only `product` and `title` are required. */
59
+ export interface DriftIssueWords {
60
+ /** The marker's and fingerprint's namespace, and the name in chant's default sentences: `plywood`, `yodel`, `terragucci`. */
61
+ product: string;
62
+ /** The issue's title. It may name what drifted; a new title updates the issue. */
63
+ title: (facts: DriftIssueFacts) => string;
64
+ /** The paragraph above the table. Default: `<product>'s drift check read <env> at <time> and found N resources that differ.` */
65
+ intro?: (facts: DriftIssueFacts) => string;
66
+ /** The table's first column. Default `Address`; plywood's is `URN`. */
67
+ address?: string;
68
+ /**
69
+ * The words for an attribute's two values, as `declared` and `live`. With
70
+ * them each attribute shows its values, `` `path`: declared `a`, live `b` ``;
71
+ * without them only its path. A sensitive attribute never shows a value.
72
+ */
73
+ values?: { before: string; after: string };
74
+ /** The heading over the records that could not be read. Default `Could not be read, so their state is unknown:`. */
75
+ unobserved?: string;
76
+ /** The paragraph below the table: how to correct the drift. */
77
+ advice?: (facts: DriftIssueFacts) => string;
78
+ /** The line that names the run. Default `Found by <url>.` */
79
+ foundBy?: (runUrl: string) => string;
80
+ /** The comment posted when the drift clears and the issue is closed. Default: `<product>'s drift check at <time> found <env> matching, so this issue is closed.` */
81
+ cleared?: (facts: DriftIssueFacts) => string;
82
+ }
83
+
84
+ export interface DriftIssueInput {
85
+ words: DriftIssueWords;
86
+ /** The environment the issue is for: a stack, an environment name, a project and environment. Keys the default marker. */
87
+ environment: string;
88
+ /** The run's drift records for the environment. */
89
+ records: readonly DriftIssueRecord[];
90
+ /**
91
+ * The read failed, and why: the open issue is left as it is, whatever
92
+ * `records` holds.
93
+ */
94
+ unknown?: string;
95
+ /**
96
+ * The issue's marker, when the product's open issues already carry one of
97
+ * their own (`<!-- yodel:drift project=. env=prod -->`). Default
98
+ * {@link driftIssueMarker}`(product, environment)`.
99
+ */
100
+ marker?: string;
101
+ /** The run's URL, for the line that names it. */
102
+ runUrl?: string;
103
+ /** Lines of the product's own below the table, such as who changed each attribute. */
104
+ notes?: readonly string[];
105
+ /** When the drift was read, when the records carry no `observedAt`. */
106
+ observedAt?: string;
107
+ /** How the marker is found, and whose issues count (`trackIssue`'s {@link MarkerMatch}). */
108
+ match?: MarkerMatch;
109
+ /**
110
+ * The statuses that are drift. Default {@link DRIFT_ISSUE_STATUSES}. A
111
+ * read with no snapshot, such as the sql lexicon's, gives a declared
112
+ * object the server lacks as `pending`, which SQL Yodeler reports as gone:
113
+ * it passes `["drifted", "missing", "pending"]`.
114
+ */
115
+ statuses?: readonly DriftStatus[];
116
+ }
117
+
118
+ /** What {@link keepDriftIssue} did. */
119
+ export interface DriftIssueResult {
120
+ /**
121
+ * `opened`, `updated` or `unchanged` for drift; `closed` or `none` (no open
122
+ * issue) when it cleared; `left` when the read proves nothing and an issue
123
+ * is open, which stays as it is.
124
+ */
125
+ action: IssueResult["action"];
126
+ number?: number;
127
+ url?: string;
128
+ created?: string;
129
+ marker: string;
130
+ /** The drift's fingerprint, when the run found drift. */
131
+ fingerprint?: string;
132
+ /** Why the issue was left as it is (`left`, or `none` with nothing open). */
133
+ why?: string;
134
+ }
135
+
136
+ /** The hidden first line that finds the environment's drift issue again: `<!-- <product>:drift <environment> -->`. */
137
+ export function driftIssueMarker(product: string, environment: string): string {
138
+ return `<!-- ${clean(product)}:drift ${clean(environment)} -->`;
139
+ }
140
+
141
+ /** The hidden line that carries the fingerprint, which an unchanged drift's issue already holds. */
142
+ export function driftFingerprintLine(product: string, fingerprint: string): string {
143
+ return `<!-- ${clean(product)}:drift-fingerprint ${fingerprint} -->`;
144
+ }
145
+
146
+ /** The records that are drift, sorted by member and address. */
147
+ export function driftIssueRecords(records: readonly DriftIssueRecord[], statuses: readonly DriftStatus[] = DRIFT_ISSUE_STATUSES): DriftIssueRecord[] {
148
+ return records.filter((r) => statuses.includes(r.status)).sort(byPlace);
149
+ }
150
+
151
+ /**
152
+ * The drift's fingerprint: the same drift gives the same one, whenever and
153
+ * in whatever order it is read. It covers each drifted or missing record's
154
+ * member, address and status, and each attribute's path and, when the
155
+ * record carries them, its two values. The time, the run, the records that
156
+ * could not be read and those in sync are left out. 16 hex digits of a
157
+ * SHA-256.
158
+ */
159
+ export function driftIssueFingerprint(records: readonly DriftIssueRecord[], statuses: readonly DriftStatus[] = DRIFT_ISSUE_STATUSES): string {
160
+ const text = driftIssueRecords(records, statuses)
161
+ .map((r) => [r.member, r.address, r.status, ...attributesOf(r).map(attributeKey).sort()].join("\t"))
162
+ .join("\n");
163
+ return createHash("sha256").update(text, "utf8").digest("hex").slice(0, 16);
164
+ }
165
+
166
+ /** The issue's body: the marker, the product's intro, the table, what could not be read, the notes, the advice, the run, the fingerprint. */
167
+ export function driftIssueBody(input: DriftIssueInput, fingerprint = driftIssueFingerprint(input.records, input.statuses)): string {
168
+ const { words } = input;
169
+ const facts = factsOf(input);
170
+ const marker = input.marker ?? driftIssueMarker(words.product, input.environment);
171
+ const members = new Set(facts.drifted.map((r) => r.member));
172
+ const withMember = members.size > 1;
173
+ const lines = [marker, words.intro ? words.intro(facts) : defaultIntro(words.product, facts), ""];
174
+ lines.push(
175
+ `| ${withMember ? "Member | " : ""}${words.address ?? "Address"} | Status | Attributes |`,
176
+ `|${withMember ? "---|" : ""}---|---|---|`,
177
+ ...facts.drifted.map((r) => `| ${withMember ? `${code(r.member)} | ` : ""}${code(r.address)} | ${r.status} | ${attributesOf(r).map((a) => attributeCell(a, words.values)).join(", ")} |`),
178
+ "",
179
+ );
180
+ const unread = input.records.filter((r) => r.status === "not-observed").sort(byPlace);
181
+ if (unread.length > 0) {
182
+ lines.push(words.unobserved ?? "Could not be read, so their state is unknown:", "");
183
+ for (const r of unread) lines.push(`- ${code(r.address)}${r.unobserved ? `: ${r.unobserved.reason}${r.unobserved.detail ? ` (${oneLine(r.unobserved.detail)})` : ""}` : ""}`);
184
+ lines.push("");
185
+ }
186
+ if (input.notes?.length) lines.push(...input.notes, "");
187
+ if (words.advice) lines.push(words.advice(facts), "");
188
+ if (input.runUrl) lines.push(words.foundBy ? words.foundBy(input.runUrl) : `Found by ${input.runUrl}.`, "");
189
+ lines.push(driftFingerprintLine(words.product, fingerprint));
190
+ return lines.join("\n");
191
+ }
192
+
193
+ /**
194
+ * Bring the environment's one drift issue in line with the run; see the
195
+ * module comment for the three cases. Throws what the forge throws.
196
+ */
197
+ export async function keepDriftIssue(forge: Pick<PrForge, "trackIssue">, input: DriftIssueInput): Promise<DriftIssueResult> {
198
+ const { words } = input;
199
+ const marker = input.marker ?? driftIssueMarker(words.product, input.environment);
200
+ const match = input.match ?? {};
201
+ const drifted = driftIssueRecords(input.records, input.statuses);
202
+ const kept = (r: IssueResult, extra: Partial<DriftIssueResult> = {}): DriftIssueResult => ({
203
+ action: r.action,
204
+ ...(r.number !== undefined ? { number: r.number } : {}),
205
+ ...(r.url ? { url: r.url } : {}),
206
+ ...(r.created ? { created: r.created } : {}),
207
+ marker,
208
+ ...extra,
209
+ });
210
+ const unread = input.records.filter((r) => r.status === "not-observed").length;
211
+ const why = input.unknown ?? (drifted.length === 0 && unread > 0 ? `${unread} resource${unread === 1 ? "" : "s"} could not be read, so whether ${input.environment} drifted is unknown` : undefined);
212
+ if (why !== undefined) return kept(await forge.trackIssue(marker, null, match), { why });
213
+ if (drifted.length > 0) {
214
+ const fingerprint = driftIssueFingerprint(input.records, input.statuses);
215
+ const body = driftIssueBody({ ...input, marker }, fingerprint);
216
+ const r = await forge.trackIssue(marker, { title: words.title(factsOf(input)), body }, { ...match, sameWhen: driftFingerprintLine(words.product, fingerprint) });
217
+ return kept(r, { fingerprint });
218
+ }
219
+ const facts = factsOf(input);
220
+ const clearComment = words.cleared ? words.cleared(facts) : `${words.product}'s drift check at ${facts.observedAt} found ${input.environment} matching, so this issue is closed.`;
221
+ return kept(await forge.trackIssue(marker, null, { ...match, closeOnClear: true, clearComment }));
222
+ }
223
+
224
+ function factsOf(input: DriftIssueInput): DriftIssueFacts {
225
+ const times = input.records.map((r) => r.observedAt).filter((t): t is string => typeof t === "string").sort();
226
+ return { environment: input.environment, drifted: driftIssueRecords(input.records, input.statuses), observedAt: times[times.length - 1] ?? input.observedAt ?? new Date().toISOString() };
227
+ }
228
+
229
+ function defaultIntro(product: string, facts: DriftIssueFacts): string {
230
+ const n = facts.drifted.length;
231
+ return `${product}'s drift check read ${facts.environment} at ${facts.observedAt} and found ${n} resource${n === 1 ? "" : "s"} that differ.`;
232
+ }
233
+
234
+ function attributesOf(r: DriftIssueRecord): readonly DriftAttribute[] {
235
+ return [...(r.attributes ?? [])].sort((a, b) => compare(a.path, b.path));
236
+ }
237
+
238
+ function attributeKey(a: DriftAttribute): string {
239
+ if (a.sensitive) return `${a.path}=sensitive`;
240
+ return "before" in a || "after" in a ? `${a.path}=${JSON.stringify([a.before ?? null, a.after ?? null])}` : a.path;
241
+ }
242
+
243
+ function attributeCell(a: DriftAttribute, values: DriftIssueWords["values"]): string {
244
+ if (!values) return code(a.path);
245
+ if (a.sensitive) return `${code(a.path)} (sensitive)`;
246
+ if (!("before" in a) && !("after" in a)) return code(a.path);
247
+ return `${code(a.path)}: ${values.before} ${code(show(a.before))}, ${values.after} ${code(show(a.after))}`;
248
+ }
249
+
250
+ function show(v: unknown): string {
251
+ return v === undefined ? "absent" : typeof v === "string" ? v : JSON.stringify(v);
252
+ }
253
+
254
+ /** Inline code that keeps a table cell's shape. */
255
+ function code(s: string): string {
256
+ return `\`${oneLine(s).replace(/`/g, "'").replace(/\|/g, "\\|")}\``;
257
+ }
258
+
259
+ function oneLine(s: string): string {
260
+ return s.replace(/\r?\n/g, " ");
261
+ }
262
+
263
+ /** A marker part that cannot end the comment or break the line. */
264
+ function clean(s: string): string {
265
+ return s.replace(/-->/g, "").replace(/\s+/g, "_");
266
+ }
267
+
268
+ function byPlace(a: DriftIssueRecord, b: DriftIssueRecord): number {
269
+ return compare(a.member, b.member) || compare(a.address, b.address);
270
+ }
271
+
272
+ function compare(a: string, b: string): number {
273
+ return a < b ? -1 : a > b ? 1 : 0;
274
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * #4800 — the note size limit products call: `noteLimit` by forge and
3
+ * `fitNote`, the cut SQL Yodeler's `COMMENT_LIMIT` and terragucci's
4
+ * `MAX_NOTE` each made.
5
+ */
6
+
7
+ import { describe, expect, test } from "vitest";
8
+ import { fitNote, GITHUB_COMMENT_LIMIT, GITLAB_NOTE_LIMIT, NOTE_CUT_LINE, noteLimit } from "./plan-summary";
9
+
10
+ describe("noteLimit", () => {
11
+ test("GitLab's on GitLab, GitHub's on GitHub, Forgejo and an unknown forge", () => {
12
+ expect(noteLimit("gitlab")).toBe(GITLAB_NOTE_LIMIT);
13
+ expect(noteLimit("github")).toBe(GITHUB_COMMENT_LIMIT);
14
+ expect(noteLimit("forgejo")).toBe(GITHUB_COMMENT_LIMIT);
15
+ expect(noteLimit()).toBe(GITHUB_COMMENT_LIMIT);
16
+ });
17
+ });
18
+
19
+ describe("fitNote", () => {
20
+ test("a body that fits is returned as it is", () => {
21
+ expect(fitNote("x".repeat(100), { limit: 100 })).toBe("x".repeat(100));
22
+ });
23
+
24
+ test("a longer one is cut, with the closing line, to exactly the limit", () => {
25
+ const out = fitNote("x".repeat(GITHUB_COMMENT_LIMIT + 10));
26
+ expect(out.length).toBeLessThanOrEqual(GITHUB_COMMENT_LIMIT);
27
+ const cut = GITHUB_COMMENT_LIMIT - NOTE_CUT_LINE.replace("{cut}", String(GITHUB_COMMENT_LIMIT)).length;
28
+ expect(out).toBe("x".repeat(cut) + NOTE_CUT_LINE.replace("{cut}", String(cut)));
29
+ });
30
+
31
+ test("the product's own closing line, with the characters kept", () => {
32
+ expect(fitNote("abcdefghijklmnopqrstuvwxyz", { limit: 20, tail: "\n(cut at {cut})" })).toBe("abcdefgh\n(cut at 8)");
33
+ });
34
+
35
+ test("never splits a surrogate pair", () => {
36
+ const out = fitNote("ab" + "😀".repeat(20), { limit: 12, tail: "|" });
37
+ expect(out).toBe("ab" + "😀".repeat(4) + "|");
38
+ expect(out.length).toBeLessThanOrEqual(12);
39
+ });
40
+
41
+ test("a closing line longer than the limit still keeps to it", () => {
42
+ expect(fitNote("x".repeat(50), { limit: 5, tail: "a closing line that is long" }).length).toBe(5);
43
+ });
44
+ });