@intentius/chant 0.124.97 → 0.124.98

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 (223) hide show
  1. package/dist/audit/core.d.ts +29 -0
  2. package/dist/audit/core.d.ts.map +1 -1
  3. package/dist/audit/core.js +48 -11
  4. package/dist/audit/identity.d.ts +27 -0
  5. package/dist/audit/identity.d.ts.map +1 -0
  6. package/dist/audit/identity.js +36 -0
  7. package/dist/audit/report-html.d.ts +3 -1
  8. package/dist/audit/report-html.d.ts.map +1 -1
  9. package/dist/audit/report-html.js +1 -1
  10. package/dist/audit/report-model.d.ts +16 -0
  11. package/dist/audit/report-model.d.ts.map +1 -1
  12. package/dist/audit/report-model.js +5 -1
  13. package/dist/ci-agent.d.ts +17 -0
  14. package/dist/ci-agent.d.ts.map +1 -1
  15. package/dist/ci-agent.js +32 -0
  16. package/dist/ci-comment-allow.d.ts +88 -0
  17. package/dist/ci-comment-allow.d.ts.map +1 -0
  18. package/dist/ci-comment-allow.js +178 -0
  19. package/dist/ci-comment-commands.d.ts +12 -0
  20. package/dist/ci-comment-commands.d.ts.map +1 -1
  21. package/dist/ci-comment-commands.js +22 -0
  22. package/dist/ci-control.d.ts +6 -1
  23. package/dist/ci-control.d.ts.map +1 -1
  24. package/dist/ci-control.js +6 -1
  25. package/dist/ci-product.d.ts +3 -0
  26. package/dist/ci-product.d.ts.map +1 -1
  27. package/dist/ci-product.js +3 -0
  28. package/dist/cli/commands/audit.d.ts +3 -1
  29. package/dist/cli/commands/audit.d.ts.map +1 -1
  30. package/dist/cli/commands/audit.js +23 -6
  31. package/dist/cli/commands/import.d.ts +8 -1
  32. package/dist/cli/commands/import.d.ts.map +1 -1
  33. package/dist/cli/commands/import.js +31 -6
  34. package/dist/cli/handlers/agent.d.ts.map +1 -1
  35. package/dist/cli/handlers/agent.js +12 -2
  36. package/dist/cli/handlers/pr-comment.d.ts +6 -0
  37. package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
  38. package/dist/cli/handlers/pr-comment.js +12 -0
  39. package/dist/cli/handlers/promote.d.ts.map +1 -1
  40. package/dist/cli/handlers/promote.js +53 -6
  41. package/dist/cli/main.d.ts.map +1 -1
  42. package/dist/cli/main.js +29 -6
  43. package/dist/cli/parse-args.d.ts.map +1 -1
  44. package/dist/cli/parse-args.js +23 -0
  45. package/dist/cli/registry.d.ts +8 -0
  46. package/dist/cli/registry.d.ts.map +1 -1
  47. package/dist/cloud-lister/mask.d.ts +30 -1
  48. package/dist/cloud-lister/mask.d.ts.map +1 -1
  49. package/dist/cloud-lister/mask.js +66 -3
  50. package/dist/components/driver.d.ts +8 -1
  51. package/dist/components/driver.d.ts.map +1 -1
  52. package/dist/components/driver.js +1 -0
  53. package/dist/components/product-pipeline.d.ts +23 -1
  54. package/dist/components/product-pipeline.d.ts.map +1 -1
  55. package/dist/components/product-pipeline.js +40 -7
  56. package/dist/components/product-plan.d.ts +20 -0
  57. package/dist/components/product-plan.d.ts.map +1 -1
  58. package/dist/components/product-plan.js +11 -1
  59. package/dist/control/applied.d.ts +8 -1
  60. package/dist/control/applied.d.ts.map +1 -1
  61. package/dist/control/applied.js +18 -2
  62. package/dist/control/dispatch.d.ts +52 -0
  63. package/dist/control/dispatch.d.ts.map +1 -1
  64. package/dist/control/dispatch.js +140 -4
  65. package/dist/control/train.d.ts +198 -0
  66. package/dist/control/train.d.ts.map +1 -0
  67. package/dist/control/train.js +294 -0
  68. package/dist/deep-observation.js +2 -2
  69. package/dist/floor-table.data.d.ts.map +1 -1
  70. package/dist/floor-table.data.js +11 -0
  71. package/dist/graph-detail.d.ts +9 -0
  72. package/dist/graph-detail.d.ts.map +1 -1
  73. package/dist/graph-detail.js +38 -13
  74. package/dist/graph-refs.d.ts +233 -3
  75. package/dist/graph-refs.d.ts.map +1 -1
  76. package/dist/graph-refs.js +106 -15
  77. package/dist/lint/post-synth.d.ts +22 -0
  78. package/dist/lint/post-synth.d.ts.map +1 -1
  79. package/dist/lint/rules/declarable-naming-convention.d.ts +12 -0
  80. package/dist/lint/rules/declarable-naming-convention.d.ts.map +1 -1
  81. package/dist/lint/rules/declarable-naming-convention.js +38 -8
  82. package/dist/lint/rules/imported-source.d.ts +20 -0
  83. package/dist/lint/rules/imported-source.d.ts.map +1 -0
  84. package/dist/lint/rules/imported-source.js +27 -0
  85. package/dist/lint/rules/no-unused-declarable.d.ts.map +1 -1
  86. package/dist/lint/rules/no-unused-declarable.js +3 -0
  87. package/dist/op/gate.d.ts +2 -0
  88. package/dist/op/gate.d.ts.map +1 -1
  89. package/dist/op/gate.js +8 -1
  90. package/dist/pr-forge-reads.d.ts +17 -0
  91. package/dist/pr-forge-reads.d.ts.map +1 -1
  92. package/dist/pr-forge-reads.js +55 -0
  93. package/dist/release-floors.d.ts +9 -1
  94. package/dist/release-floors.d.ts.map +1 -1
  95. package/dist/release-floors.js +9 -1
  96. package/dist/repo-path.d.ts +29 -0
  97. package/dist/repo-path.d.ts.map +1 -0
  98. package/dist/repo-path.js +81 -0
  99. package/dist/sensitive-key.d.ts +23 -0
  100. package/dist/sensitive-key.d.ts.map +1 -1
  101. package/dist/sensitive-key.js +37 -0
  102. package/dist/terraform/hcl2json.d.ts +7 -0
  103. package/dist/terraform/hcl2json.d.ts.map +1 -1
  104. package/dist/terraform/hcl2json.js +7 -0
  105. package/dist/wave-runtime.mjs +352 -345
  106. package/dist/workspace/catalog-edges.d.ts +147 -0
  107. package/dist/workspace/catalog-edges.d.ts.map +1 -0
  108. package/dist/workspace/catalog-edges.js +461 -0
  109. package/dist/workspace/compose-graph.d.ts +73 -3
  110. package/dist/workspace/compose-graph.d.ts.map +1 -1
  111. package/dist/workspace/declaration.d.ts +2 -0
  112. package/dist/workspace/declaration.d.ts.map +1 -1
  113. package/dist/workspace/declaration.js +1 -0
  114. package/dist/workspace/declaration.schema.json +6 -0
  115. package/dist/workspace/discover.d.ts +134 -0
  116. package/dist/workspace/discover.d.ts.map +1 -0
  117. package/dist/workspace/discover.js +372 -0
  118. package/dist/workspace/graph-cli.d.ts +20 -0
  119. package/dist/workspace/graph-cli.d.ts.map +1 -1
  120. package/dist/workspace/graph-cli.js +178 -20
  121. package/dist/workspace/graph.schema.json +195 -2
  122. package/dist/workspace/release-train.d.ts +214 -3
  123. package/dist/workspace/release-train.d.ts.map +1 -1
  124. package/dist/workspace/release-train.js +552 -16
  125. package/dist/workspace/repo-ref.d.ts +14 -0
  126. package/dist/workspace/repo-ref.d.ts.map +1 -1
  127. package/dist/workspace/repo-ref.js +26 -1
  128. package/dist/workspace/workspace-gates.d.ts +24 -0
  129. package/dist/workspace/workspace-gates.d.ts.map +1 -1
  130. package/dist/workspace/workspace-gates.js +29 -5
  131. package/dist/workspace/workspace-ledger.d.ts +31 -5
  132. package/dist/workspace/workspace-ledger.d.ts.map +1 -1
  133. package/dist/workspace/workspace-ledger.js +2 -1
  134. package/dist/workspace/workspace-run.d.ts +14 -0
  135. package/dist/workspace/workspace-run.d.ts.map +1 -1
  136. package/dist/workspace/workspace-run.js +2 -2
  137. package/dist/yaml.d.ts.map +1 -1
  138. package/dist/yaml.js +33 -8
  139. package/package.json +1 -1
  140. package/src/audit/core.test.ts +64 -1
  141. package/src/audit/core.ts +75 -10
  142. package/src/audit/identity.test.ts +31 -0
  143. package/src/audit/identity.ts +43 -0
  144. package/src/audit/report-html.ts +4 -2
  145. package/src/audit/report-model.ts +21 -1
  146. package/src/ci-agent.test.ts +32 -0
  147. package/src/ci-agent.ts +42 -0
  148. package/src/ci-comment-allow.test.ts +380 -0
  149. package/src/ci-comment-allow.ts +184 -0
  150. package/src/ci-comment-commands.ts +25 -0
  151. package/src/ci-control.ts +42 -0
  152. package/src/ci-product.ts +3 -0
  153. package/src/cli/commands/audit-parser-notice.test.ts +74 -0
  154. package/src/cli/commands/audit.test.ts +12 -0
  155. package/src/cli/commands/audit.ts +25 -7
  156. package/src/cli/commands/import-layout.test.ts +2 -1
  157. package/src/cli/commands/import.ts +29 -6
  158. package/src/cli/handlers/agent.ts +13 -2
  159. package/src/cli/handlers/pr-comment.ts +12 -0
  160. package/src/cli/handlers/promote.test.ts +68 -0
  161. package/src/cli/handlers/promote.ts +52 -6
  162. package/src/cli/main.test.ts +5 -0
  163. package/src/cli/main.ts +29 -6
  164. package/src/cli/parse-args.ts +18 -0
  165. package/src/cli/registry.ts +8 -0
  166. package/src/cloud-lister/kubernetes.k3d.e2e.test.ts +104 -0
  167. package/src/cloud-lister/mask-references.test.ts +132 -0
  168. package/src/cloud-lister/mask.ts +68 -3
  169. package/src/components/driver.ts +9 -1
  170. package/src/components/product-pipeline.ts +57 -7
  171. package/src/components/product-plan.ts +27 -2
  172. package/src/control/applied.ts +33 -3
  173. package/src/control/dispatch.ts +156 -5
  174. package/src/control/train.test.ts +215 -0
  175. package/src/control/train.ts +413 -0
  176. package/src/deep-observation.ts +2 -2
  177. package/src/floor-table.data.ts +6 -0
  178. package/src/graph-detail.ts +37 -12
  179. package/src/graph-refs.test.ts +45 -1
  180. package/src/graph-refs.ts +321 -14
  181. package/src/lint/post-synth.ts +20 -0
  182. package/src/lint/rules/declarable-naming-convention.test.ts +35 -1
  183. package/src/lint/rules/declarable-naming-convention.ts +35 -8
  184. package/src/lint/rules/imported-source.test.ts +22 -0
  185. package/src/lint/rules/imported-source.ts +31 -0
  186. package/src/lint/rules/no-unused-declarable.test.ts +16 -0
  187. package/src/lint/rules/no-unused-declarable.ts +7 -0
  188. package/src/op/gate.ts +10 -2
  189. package/src/pr-forge-reads.ts +62 -0
  190. package/src/release-floors.ts +13 -1
  191. package/src/repo-path.test.ts +72 -0
  192. package/src/repo-path.ts +103 -0
  193. package/src/sensitive-key.ts +38 -0
  194. package/src/terraform/hcl2json.ts +8 -0
  195. package/src/workspace/application-set.e2e.test.ts +405 -0
  196. package/src/workspace/catalog-edges.ts +507 -0
  197. package/src/workspace/ci-green-workflow.test.ts +2 -2
  198. package/src/workspace/cluster-join.e2e.test.ts +150 -0
  199. package/src/workspace/compose-graph.ts +74 -5
  200. package/src/workspace/declaration.schema.json +6 -0
  201. package/src/workspace/declaration.ts +3 -0
  202. package/src/workspace/discover.e2e.test.ts +122 -0
  203. package/src/workspace/discover.test.ts +225 -0
  204. package/src/workspace/discover.ts +406 -0
  205. package/src/workspace/external-secret-catalog.e2e.test.ts +98 -0
  206. package/src/workspace/external-secret-catalog.test.ts +142 -0
  207. package/src/workspace/graph-cli.ts +207 -21
  208. package/src/workspace/graph-contract.test.ts +92 -0
  209. package/src/workspace/graph.schema.json +195 -2
  210. package/src/workspace/helm-references.e2e.test.ts +135 -0
  211. package/src/workspace/identity-annotation-catalog.e2e.test.ts +91 -0
  212. package/src/workspace/identity-annotation-catalog.test.ts +139 -0
  213. package/src/workspace/release-train-repos.test.ts +304 -0
  214. package/src/workspace/release-train.test.ts +296 -0
  215. package/src/workspace/release-train.ts +631 -16
  216. package/src/workspace/repo-ref.ts +26 -1
  217. package/src/workspace/runs-on.test.ts +45 -0
  218. package/src/workspace/workspace-gates.ts +48 -5
  219. package/src/workspace/workspace-ledger.ts +28 -5
  220. package/src/workspace/workspace-run.test.ts +1 -1
  221. package/src/workspace/workspace-run.ts +2 -2
  222. package/src/yaml.test.ts +96 -8
  223. package/src/yaml.ts +36 -8
@@ -71,6 +71,16 @@ export interface PostSynthContext {
71
71
  * where a check that reads the disk stays silent.
72
72
  */
73
73
  readonly projectDir?: string;
74
+ /**
75
+ * Set when the checks run under `chant audit` (#5109), which reads a tree
76
+ * rather than building a project. `root` is the directory the audit walked,
77
+ * and is absent when the tree is a remote fetch with nothing on disk. A
78
+ * check that reads the disk looks there, never in the working directory the
79
+ * command happened to start from, and stays silent when there is no `root`.
80
+ * Absent from `chant build` and `chant lint` (which set `projectDir`) and
81
+ * from a hand-built context.
82
+ */
83
+ readonly audit?: { root?: string };
74
84
  /**
75
85
  * The project config the build loaded (#3751), as source lint rules get it
76
86
  * in `LintContext.projectConfig`. A check that renders output again, as the
@@ -192,6 +202,16 @@ export interface PostSynthDiagnostic {
192
202
  /** Where it is missing from (e.g. a root module name). */
193
203
  scope: string;
194
204
  };
205
+ /**
206
+ * Where in the entity the finding sits, as a path that does not depend on
207
+ * any display name: `Deployment/containers[1]`, `resource.rules[0]`. The
208
+ * audit builds a finding's `identity` from the check id, the file, `entity`
209
+ * and this locator, never from `message`. A check that reports several
210
+ * findings against one entity, and whose message names a part of it (a
211
+ * container, a port), sets this so renaming that part, or fixing an earlier
212
+ * one, leaves the identity of the rest alone. Optional.
213
+ */
214
+ locator?: string;
195
215
  /**
196
216
  * The build root the finding is about, set by a {@link CrossRootCheck}
197
217
  * (chant #1939). Absent from a per-build finding.
@@ -1,6 +1,7 @@
1
1
  import { describe, test, expect } from "vitest";
2
2
  import * as ts from "typescript";
3
- import { declarableNamingConventionRule } from "./declarable-naming-convention";
3
+ import { declarableNamingConventionRule, toCamelCase } from "./declarable-naming-convention";
4
+ import { IMPORTED_SOURCE_HEADER, IMPORTED_SOURCE_MARKER } from "./imported-source";
4
5
  import type { LintContext } from "../rule";
5
6
 
6
7
  function createContext(code: string, filePath = "test.ts"): LintContext {
@@ -66,4 +67,37 @@ describe("COR005: declarable-naming-convention", () => {
66
67
  expect(diags[0].line).toBe(1);
67
68
  expect(diags[0].column).toBeGreaterThan(0);
68
69
  });
70
+
71
+ test.each([
72
+ ["TFStateBucket", "tfStateBucket"],
73
+ ["OBSAdminUser", "obsAdminUser"],
74
+ ["HTTPServer", "httpServer"],
75
+ ["S3Bucket", "s3Bucket"],
76
+ ["TF2State", "tf2State"],
77
+ ["URL", "url"],
78
+ ["DataBucket", "dataBucket"],
79
+ ["DATA_BUCKET", "dataBucket"],
80
+ ["MAX_RETRY_COUNT", "maxRetryCount"],
81
+ ["Data_Bucket", "dataBucket"],
82
+ ])("suggests %s as %s", (name, expected) => {
83
+ expect(toCamelCase(name)).toBe(expected);
84
+ const diags = declarableNamingConventionRule.check(createContext(`export const ${name} = new Bucket({});`));
85
+ expect(diags).toHaveLength(1);
86
+ expect(diags[0].message).toContain(`rename to '${expected}'`);
87
+ });
88
+
89
+ test("skips a file that opens with the import marker", () => {
90
+ const code = `${IMPORTED_SOURCE_HEADER}import { Bucket } from "@intentius/chant-lexicon-aws";\nexport const TFStateBucket = new Bucket({});`;
91
+ expect(declarableNamingConventionRule.check(createContext(code))).toHaveLength(0);
92
+ });
93
+
94
+ test("still flags when the marker sits below code, not in the opening comments", () => {
95
+ const code = `export const TFStateBucket = new Bucket({});\n${IMPORTED_SOURCE_MARKER}\n`;
96
+ expect(declarableNamingConventionRule.check(createContext(code))).toHaveLength(1);
97
+ });
98
+
99
+ test("still flags a file whose opening comment is not the marker", () => {
100
+ const code = `// hand written\nexport const TFStateBucket = new Bucket({});`;
101
+ expect(declarableNamingConventionRule.check(createContext(code))).toHaveLength(1);
102
+ });
69
103
  });
@@ -1,5 +1,6 @@
1
1
  import * as ts from "typescript";
2
2
  import type { LintRule, LintContext, LintDiagnostic } from "../rule";
3
+ import { isImportedSource } from "./imported-source";
3
4
 
4
5
  /**
5
6
  * COR005: declarable-naming-convention
@@ -12,6 +13,7 @@ import type { LintRule, LintContext, LintDiagnostic } from "../rule";
12
13
  * OK: export const dataBucket = new Bucket({ ... })
13
14
  * OK: export const DataBucket = createBucket({ ... }) (not a new expression)
14
15
  * OK: const DataBucket = new Bucket({ ... }) (not exported)
16
+ * OK: any name in a file written by `chant import` (see imported-source.ts)
15
17
  */
16
18
 
17
19
  function checkNode(node: ts.Node, context: LintContext, diagnostics: LintDiagnostic[]): void {
@@ -48,14 +50,38 @@ function checkNode(node: ts.Node, context: LintContext, diagnostics: LintDiagnos
48
50
  ts.forEachChild(node, child => checkNode(child, context, diagnostics));
49
51
  }
50
52
 
51
- /** Suggest a camelCase version of a PascalCase or UPPER_SNAKE_CASE name */
52
- function toCamelCase(name: string): string {
53
- // PascalCase -> camelCase: lowercase first char
54
- if (/^[A-Z][a-z]/.test(name)) {
55
- return name[0].toLowerCase() + name.slice(1);
56
- }
57
- // UPPER_SNAKE -> camelCase
58
- return name.toLowerCase().replace(/_([a-z])/g, (_, c) => c.toUpperCase());
53
+ /**
54
+ * Suggest a camelCase version of a PascalCase or UPPER_SNAKE_CASE name.
55
+ *
56
+ * The name is cut at every character an identifier cannot start a word with
57
+ * (`_`, `$`), the same non-alphanumeric cut the Kubernetes importer makes in
58
+ * `toLogicalId`. A leading run of capitals is an acronym: it is lowercased up
59
+ * to the capital that begins the next word, so `TFStateBucket` gives
60
+ * `tfStateBucket` and `OBSAdminUser` gives `obsAdminUser`. That boundary is
61
+ * a case boundary inside one identifier, which `toLogicalId` (names joined
62
+ * from DNS-style segments) never has to find, so the two stay separate.
63
+ */
64
+ export function toCamelCase(name: string): string {
65
+ const words = name.split(/[^A-Za-z0-9]+/).filter((w) => w.length > 0);
66
+ if (words.length === 0) return name;
67
+ return words
68
+ .map((word, i) => {
69
+ // A word written entirely in capitals ("BUCKET", "S3") is one word.
70
+ const allCaps = word === word.toUpperCase() && /[A-Z]/.test(word);
71
+ if (i === 0) return lowerLeadingCapitals(word, allCaps);
72
+ return word[0].toUpperCase() + (allCaps ? word.slice(1).toLowerCase() : word.slice(1));
73
+ })
74
+ .join("");
75
+ }
76
+
77
+ /** Lowercase the leading capitals of a word, keeping the capital that starts its next word. */
78
+ function lowerLeadingCapitals(word: string, allCaps: boolean): string {
79
+ if (allCaps) return word.toLowerCase();
80
+ const run = /^[A-Z]+/.exec(word)?.[0] ?? "";
81
+ // "TFState": the run is "TFS", and its last capital starts "State".
82
+ const startsNextWord = run.length > 1 && /[a-z]/.test(word[run.length] ?? "");
83
+ const keep = startsNextWord ? run.length - 1 : Math.max(run.length, 1);
84
+ return word.slice(0, keep).toLowerCase() + word.slice(keep);
59
85
  }
60
86
 
61
87
  export const declarableNamingConventionRule: LintRule = {
@@ -65,6 +91,7 @@ export const declarableNamingConventionRule: LintRule = {
65
91
  description: "Exported declarable instances must use camelCase naming",
66
92
  check(context: LintContext): LintDiagnostic[] {
67
93
  const diagnostics: LintDiagnostic[] = [];
94
+ if (isImportedSource(context.sourceFile)) return diagnostics;
68
95
  checkNode(context.sourceFile, context, diagnostics);
69
96
  return diagnostics;
70
97
  },
@@ -0,0 +1,22 @@
1
+ import { describe, test, expect } from "vitest";
2
+ import * as ts from "typescript";
3
+ import { IMPORTED_SOURCE_HEADER, isImportedSource, markImportedSource } from "./imported-source";
4
+
5
+ const parse = (code: string) => ts.createSourceFile("x.ts", code, ts.ScriptTarget.Latest, true);
6
+
7
+ describe("imported source marker", () => {
8
+ test("marks a TypeScript file once", () => {
9
+ const once = markImportedSource("main.ts", "export const a = 1;\n");
10
+ expect(once.startsWith(IMPORTED_SOURCE_HEADER)).toBe(true);
11
+ expect(markImportedSource("main.ts", once)).toBe(once);
12
+ expect(isImportedSource(parse(once))).toBe(true);
13
+ });
14
+
15
+ test("leaves other file types alone", () => {
16
+ expect(markImportedSource("package.json", "{}")).toBe("{}");
17
+ });
18
+
19
+ test("an unmarked file is not imported", () => {
20
+ expect(isImportedSource(parse("export const a = 1;\n"))).toBe(false);
21
+ });
22
+ });
@@ -0,0 +1,31 @@
1
+ import * as ts from "typescript";
2
+
3
+ /**
4
+ * The first comment line of a file written by `chant import`.
5
+ *
6
+ * An imported declaration keeps the name the source template gave it, and the
7
+ * name is part of what the template deploys, so a naming or an
8
+ * unreferenced-declaration finding on it asks for a change that alters the
9
+ * deployed resources. COR004 and COR005 read this line and skip the file.
10
+ */
11
+ export const IMPORTED_SOURCE_MARKER = "// chant:imported";
12
+
13
+ /** The header `chant import` puts on a generated TypeScript file. */
14
+ export const IMPORTED_SOURCE_HEADER =
15
+ `${IMPORTED_SOURCE_MARKER} - declarations keep the names of the source template; COR004 and COR005 skip this file.\n`;
16
+
17
+ /** Prefix the marker onto generated content once; other file types are returned as they are. */
18
+ export function markImportedSource(path: string, content: string): string {
19
+ if (!path.endsWith(".ts") || content.startsWith(IMPORTED_SOURCE_MARKER)) return content;
20
+ return IMPORTED_SOURCE_HEADER + content;
21
+ }
22
+
23
+ /**
24
+ * True when the marker is one of the comments that open the file. A marker
25
+ * further down, after code, does not count.
26
+ */
27
+ export function isImportedSource(sourceFile: ts.SourceFile): boolean {
28
+ const text = sourceFile.text;
29
+ const ranges = ts.getLeadingCommentRanges(text, 0) ?? [];
30
+ return ranges.some((r) => text.startsWith(IMPORTED_SOURCE_MARKER, r.pos));
31
+ }
@@ -2,6 +2,7 @@ import { describe, test, expect } from "vitest";
2
2
  import * as ts from "typescript";
3
3
  import { noUnusedDeclarableRule } from "./no-unused-declarable";
4
4
  import type { LintContext } from "../rule";
5
+ import { IMPORTED_SOURCE_HEADER, IMPORTED_SOURCE_MARKER } from "./imported-source";
5
6
 
6
7
  function createContext(code: string, filePath = "test.ts"): LintContext {
7
8
  const sourceFile = ts.createSourceFile(filePath, code, ts.ScriptTarget.Latest, true);
@@ -139,4 +140,19 @@ describe("COR004: no-unused-declarable", () => {
139
140
  const diags = noUnusedDeclarableRule.check(ctx);
140
141
  expect(diags).toHaveLength(0);
141
142
  });
143
+
144
+ test("skips a file that opens with the import marker", () => {
145
+ const code = `${IMPORTED_SOURCE_HEADER}export const ManagedPolicy1 = new ManagedPolicy({});`;
146
+ expect(noUnusedDeclarableRule.check(createContext(code))).toHaveLength(0);
147
+ });
148
+
149
+ test("still flags when the marker sits below code, not in the opening comments", () => {
150
+ const code = `export const bucket = new Bucket({});\n${IMPORTED_SOURCE_MARKER}\n`;
151
+ expect(noUnusedDeclarableRule.check(createContext(code))).toHaveLength(1);
152
+ });
153
+
154
+ test("still flags an unreferenced declarable in a hand-written file with a header comment", () => {
155
+ const code = `// hand written\nexport const bucket = new Bucket({});`;
156
+ expect(noUnusedDeclarableRule.check(createContext(code))).toHaveLength(1);
157
+ });
142
158
  });
@@ -1,6 +1,7 @@
1
1
  import * as ts from "typescript";
2
2
  import type { LintRule, LintContext, LintDiagnostic } from "../rule";
3
3
  import { isPropertyKindNew } from "./property-kind";
4
+ import { isImportedSource } from "./imported-source";
4
5
 
5
6
  /**
6
7
  * COR004: no-unused-declarable
@@ -18,6 +19,11 @@ import { isPropertyKindNew } from "./property-kind";
18
19
  * resource from another file. A resource that holds one, inline or through
19
20
  * a const declared in this file, is the root that emits it, so it is not
20
21
  * flagged either: nothing ever references a dashboard, and that is fine.
22
+ *
23
+ * A file written by `chant import` is skipped (imported-source.ts). Its
24
+ * declarations are the template's resources, and CloudFormation attaches
25
+ * some of them, a ManagedPolicy for one, through their own properties
26
+ * rather than through a reference in the file.
21
27
  */
22
28
 
23
29
  interface DeclarableInfo {
@@ -155,6 +161,7 @@ export const noUnusedDeclarableRule: LintRule = {
155
161
  description: "Detects exported declarables that are never referenced in the same file",
156
162
  check(context: LintContext): LintDiagnostic[] {
157
163
  const diagnostics: LintDiagnostic[] = [];
164
+ if (isImportedSource(context.sourceFile)) return diagnostics;
158
165
  const declarables = collectExportedDeclarables(context);
159
166
 
160
167
  for (const decl of declarables) {
package/src/op/gate.ts CHANGED
@@ -524,7 +524,8 @@ export interface WorkspaceGateStood {
524
524
 
525
525
  /** See {@link GateCheckInput.workspace}. */
526
526
  export interface WorkspaceGateStandIn {
527
- standIn(q: { op: string; gate: string; planDigest: string; environment?: string }): Promise<WorkspaceGateStood | null>;
527
+ /** `releaseDigest` is set on a release gate (#4037): the approval must cover that release too. */
528
+ standIn(q: { op: string; gate: string; planDigest: string; environment?: string; releaseDigest?: string }): Promise<WorkspaceGateStood | null>;
528
529
  }
529
530
 
530
531
  /**
@@ -1045,7 +1046,13 @@ export async function evaluateGate(port: GateLedgerPort, input: GateCheckInput):
1045
1046
  // #2554, ws-039: a workspace gate stands in only when the member opted in
1046
1047
  // at base and the workspace approval's digest covers this plan.
1047
1048
  if (input.workspace && input.planDigest !== undefined) {
1048
- const stood = await input.workspace.standIn({ op: input.op, gate: input.gate, planDigest: input.planDigest, ...(env !== undefined ? { environment: env } : {}) });
1049
+ const stood = await input.workspace.standIn({
1050
+ op: input.op,
1051
+ gate: input.gate,
1052
+ planDigest: input.planDigest,
1053
+ ...(env !== undefined ? { environment: env } : {}),
1054
+ ...(input.releaseDigest !== undefined ? { releaseDigest: input.releaseDigest } : {}),
1055
+ });
1049
1056
  if (stood) {
1050
1057
  return {
1051
1058
  satisfied: true,
@@ -1059,6 +1066,7 @@ export async function evaluateGate(port: GateLedgerPort, input: GateCheckInput):
1059
1066
  timestamp: stood.timestamp,
1060
1067
  planDigest: input.planDigest,
1061
1068
  ...(env !== undefined ? { environment: env } : {}),
1069
+ ...(input.releaseDigest !== undefined ? { releaseDigest: input.releaseDigest } : {}),
1062
1070
  workspaceGate: { gate: stood.gate, digest: stood.digest },
1063
1071
  },
1064
1072
  };
@@ -19,6 +19,7 @@
19
19
  * `./review-agent-bundle.test.ts`).
20
20
  */
21
21
 
22
+ import { TeamReadError } from "./ci-comment-allow";
22
23
  import {
23
24
  ForgeApiError,
24
25
  type ForgeFetch,
@@ -29,6 +30,8 @@ import {
29
30
  type OpenPullRequest,
30
31
  } from "./pr-forge";
31
32
 
33
+ export { TeamReadError };
34
+
32
35
  /** The user a token acts as: GitHub's and Forgejo's `login`, GitLab's `username`, and the forge's numeric id. */
33
36
  export interface ForgeUser {
34
37
  login: string;
@@ -270,6 +273,21 @@ export interface ForgeReads {
270
273
  * when the forge knows no such user or member.
271
274
  */
272
275
  permission(login: string): Promise<string | undefined>;
276
+ /**
277
+ * Whether `login` is an active member of `team`, written `<org>/<team>` (a
278
+ * team's slug on GitHub, its name on Forgejo), for `comment_allow` lists
279
+ * (INTENTIUS/terragucci#1461). GitHub and Forgejo only: GitLab's reads leave it out. The team is
280
+ * looked up first, since GitHub answers 404 both for a team the token cannot
281
+ * see and for one that does not exist; if that lookup fails the read throws
282
+ * {@link TeamReadError}, and a 404 on the membership afterwards means the
283
+ * login is not in the team. A pending invitation is not membership.
284
+ *
285
+ * GitHub needs a token that can read the organization's members: a classic
286
+ * token with `read:org`, or a fine-grained token or app with the
287
+ * organization permission Members: read. The workflow's own token cannot.
288
+ * Forgejo needs `read:organization`.
289
+ */
290
+ teamMember?(team: string, login: string): Promise<boolean>;
273
291
  /** Every open pull request in the repository, into any base, ascending by number. */
274
292
  openPullRequests(): Promise<OpenPullRequest[]>;
275
293
  /** The workflow runs (GitLab's pipelines) on commit `sha`, newest first (#4846). */
@@ -552,6 +570,50 @@ function githubShapedReads(kind: "github" | "forgejo", opts: GithubForgeOptions)
552
570
  }
553
571
  return isObject(got) ? str(got.permission) : undefined;
554
572
  },
573
+ async teamMember(team, login) {
574
+ const cut = team.lastIndexOf("/");
575
+ if (cut < 1 || cut === team.length - 1) throw new TeamReadError(`${JSON.stringify(team)} is not a team: write <org>/<team>`);
576
+ const rawOrg = team.slice(0, cut);
577
+ const org = encodeURIComponent(rawOrg);
578
+ const name = team.slice(cut + 1);
579
+ const unreadable = (what: string, err: unknown): Error => {
580
+ if (!(err instanceof ForgeApiError)) return err instanceof Error ? err : new Error(String(err));
581
+ return new TeamReadError(`${what} answered ${err.status}${err.status === 404 ? ": the team does not exist, or the token cannot see it" : ""}`);
582
+ };
583
+ if (kind === "forgejo") {
584
+ let found: unknown;
585
+ try {
586
+ found = await get(`/orgs/${org}/teams/search?q=${encodeURIComponent(name)}&limit=50`);
587
+ } catch (err) {
588
+ throw unreadable(`searching ${rawOrg}'s teams`, err);
589
+ }
590
+ const rows = isObject(found) && Array.isArray(found.data) ? found.data.filter(isObject) : [];
591
+ const hit = rows.find((t) => String(t.name).toLowerCase() === name.toLowerCase());
592
+ const id = hit ? num(hit.id) : undefined;
593
+ if (id === undefined) throw new TeamReadError(`${rawOrg} has no team named ${name}, or the token cannot see it`);
594
+ try {
595
+ await get(`/teams/${id}/members/${encodeURIComponent(login)}`);
596
+ return true;
597
+ } catch (err) {
598
+ if (notFound(err)) return false;
599
+ throw unreadable(`team ${team}'s member list`, err);
600
+ }
601
+ }
602
+ try {
603
+ await get(`/orgs/${org}/teams/${encodeURIComponent(name)}`);
604
+ } catch (err) {
605
+ throw unreadable(`GitHub team ${team}`, err);
606
+ }
607
+ let got: unknown;
608
+ try {
609
+ got = await get(`/orgs/${org}/teams/${encodeURIComponent(name)}/memberships/${encodeURIComponent(login)}`);
610
+ } catch (err) {
611
+ if (notFound(err)) return false;
612
+ throw unreadable(`team ${team}'s membership of ${login}`, err);
613
+ }
614
+ // A pending invitation is not membership.
615
+ return isObject(got) && got.state === "active";
616
+ },
555
617
  async openPullRequests() {
556
618
  const out: OpenPullRequest[] = [];
557
619
  for (const v of await pulls("state=open")) {
@@ -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.97";
22
+ export const NEXT_RELEASE = "0.124.98";
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";
@@ -255,8 +255,20 @@ export const WAVES_BEFORE_MERGE_LOCKS_FLOOR = "0.124.95";
255
255
  /** The first chant whose kinds file takes `drift: { reader, config }` beside `graph` and whose `chant workspace drift --member` reads a member of such a kind with that module, `(input: { dir, config, member, observedAt, read?, resource?, stack? }) => DriftReaderOutput` from `@intentius/chant/workspace/drift-reader`, checked against `drift-reader.schema.json` (#5068). */
256
256
  export const KIND_DRIFT_READER_FLOOR = "0.124.96";
257
257
 
258
+ /** The first chant whose `chant workspace graph` runs each lexicon's reference catalog over the composed declared graph, across members, on full attributes at every `--detail` (#5097): derived edges in `edges` with `origin: "derived"`, `rule` and `relation`, references to no node in `dangling` with their `rule` and `targetKind`, references to several nodes in `ambiguous` with every candidate, and `catalog` naming the lexicons and members read, each rule named, and per node the arguments not read because not literal; a catalog path takes a quoted key, `metadata.annotations["iam.gke.io/gcp-service-account"]`; and a catalog takes `scopes` and `declaredNode`. */
259
+ export const WORKSPACE_GRAPH_CATALOG_FLOOR = NEXT_RELEASE;
260
+
261
+ /** The first chant whose reference catalogs join an Argo CD cluster Secret to the cluster resource (#5101): an Application's `spec.destination.name` and `spec.destination.server` to the Secret whose `name` and `server` match, and the Secret's `name` (base64 `data` decoded) to a `google_container_cluster`, `aws_eks_cluster` or `azurerm_kubernetes_cluster` of that literal name, with a reference no rule of its id matched listed once in `dangling`; a member of kind `argo-app` or `manifests` reads a cluster Secret cut down to its `name` and `server`; and a workspace member entry takes `runsOn`, `<member>/<address>`, with `chant workspace graph --discover --runs-on <member>=<member>/<address>`, which draws a declared edge from each of the member's cluster Secrets to that node. */
262
+ export const WORKSPACE_GRAPH_CLUSTER_JOIN_FLOOR = NEXT_RELEASE;
263
+
264
+ /** The first chant whose `chant workspace graph` expands an Argo CD ApplicationSet's `list` and `clusters` generators (#5102): one node per generated Application, with `generatedBy` naming the ApplicationSet, the rule, the generator, the parameters and the cluster Secret it was made for, a derived edge from the ApplicationSet to it under `k8s:K8s::Argo::ApplicationSet:spec.generators` and from it to the cluster Secret a clusters generator selected under `k8s:K8s::Argo::ApplicationSet:generators[].clusters`, and `expansion` on the ApplicationSet with the count and what was not expanded; and whose catalogs read an Application's `spec.source.path`, `spec.sources[].path` and `helm.valueFiles`, listing a path the workspace's own repository does not have in `dangling`, with `through` and `cluster` on a generated one. */
265
+ export const WORKSPACE_GRAPH_APPLICATION_SET_FLOOR = NEXT_RELEASE;
266
+
258
267
  /** 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). */
259
268
  export const GITLAB_WAVE_EVIDENCE_RETRY_FLOOR = "0.124.89";
260
269
 
261
270
  /** 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). */
262
271
  export const TERRAFORM_COMMAND_TRACE_FLOOR = "0.124.91";
272
+
273
+ /** The first chant whose product pipeline limits comment commands to logins and teams on GitHub and Forgejo (INTENTIUS/terragucci#1461): `commentAllow: { allow, tokenSecret? }` in `productPipelineJobs`, where `allow` maps `plan`, `apply`, `lock`, `unlock`, `agent` and `default` to logins and `team:<org>/<team>` entries. The map is written as `CHANT_COMMENT_ALLOW` into the comment job, the product plan's re-plan decision and the agent's jobs (a spec's `agent.commentAllow`), so it is read from the workflow on the default branch. `answerProductComment` takes `allow` and replies to a commenter the list leaves out, `ForgeReads.teamMember` reads a team on GitHub and Forgejo, `CHANT_COMMENT_ALLOW_TOKEN` (`tokenSecret`) carries a token that can read teams, and a team the forge cannot answer for fails closed with a message. */
274
+ export const COMMENT_ALLOW_FLOOR = NEXT_RELEASE;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * #5109: a path a manifest names resolves against the checkout the audited
3
+ * tree is in, and only when that checkout is the repository the manifest names.
4
+ */
5
+ import { execFileSync } from "node:child_process";
6
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
7
+ import { tmpdir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { describe, expect, test } from "vitest";
10
+ import { repoTreeOf, resolveRepoPath, sameRepository } from "./repo-path";
11
+
12
+ function checkout(origin?: string): string {
13
+ const dir = mkdtempSync(join(tmpdir(), "chant-repo-path-"));
14
+ execFileSync("git", ["init", "-q"], { cwd: dir });
15
+ if (origin) execFileSync("git", ["remote", "add", "origin", origin], { cwd: dir });
16
+ mkdirSync(join(dir, "kubernetes/app"), { recursive: true });
17
+ writeFileSync(join(dir, "kubernetes/app/cm.yaml"), "kind: ConfigMap\n");
18
+ return dir;
19
+ }
20
+
21
+ describe("sameRepository", () => {
22
+ test("ignores scheme, user, case and a .git suffix", () => {
23
+ expect(sameRepository("git@github.com:Acme/Infra.git", "https://github.com/acme/infra")).toBe(true);
24
+ expect(sameRepository("https://github.com/acme/infra.git", "ssh://git@github.com/acme/infra")).toBe(true);
25
+ });
26
+ test("a different host, a different path, or no path is another repository", () => {
27
+ expect(sameRepository("https://github.com/acme/infra", "https://gitlab.com/acme/infra")).toBe(false);
28
+ expect(sameRepository("https://github.com/acme/infra", "https://github.com/acme/other")).toBe(false);
29
+ expect(sameRepository("https://github.com/acme/infra", "x")).toBe(false);
30
+ });
31
+ });
32
+
33
+ describe("resolveRepoPath", () => {
34
+ test("finds a directory from the checkout root when origin is the repository", () => {
35
+ const dir = checkout("https://github.com/acme/infra.git");
36
+ expect(resolveRepoPath(dir, "https://github.com/acme/infra", "kubernetes/app")).toEqual({ status: "found", path: "kubernetes/app" });
37
+ expect(resolveRepoPath(dir, "https://github.com/acme/infra", "./kubernetes/../kubernetes/app/")).toEqual({ status: "found", path: "kubernetes/app" });
38
+ expect(resolveRepoPath(dir, "https://github.com/acme/infra", "/kubernetes/app").status).toBe("found");
39
+ });
40
+
41
+ test("resolves from the checkout root when the audited directory is below it", () => {
42
+ const dir = checkout("https://github.com/acme/infra.git");
43
+ expect(resolveRepoPath(join(dir, "kubernetes"), "https://github.com/acme/infra", "kubernetes/app").status).toBe("found");
44
+ });
45
+
46
+ test("a missing path, a file, and a path out of the checkout are missing", () => {
47
+ const dir = checkout("https://github.com/acme/infra.git");
48
+ const url = "https://github.com/acme/infra";
49
+ expect(resolveRepoPath(dir, url, "kubernetes/gone").status).toBe("missing");
50
+ expect(resolveRepoPath(dir, url, "kubernetes/app/cm.yaml").status).toBe("missing");
51
+ expect(resolveRepoPath(dir, url, "kubernetes/app/cm.yaml", { type: "file" }).status).toBe("found");
52
+ expect(resolveRepoPath(dir, url, "../../etc").status).toBe("missing");
53
+ });
54
+
55
+ test("a repository the origin does not name is elsewhere, and says nothing about the path", () => {
56
+ const dir = checkout("https://github.com/acme/infra.git");
57
+ expect(resolveRepoPath(dir, "https://github.com/acme/other", "kubernetes/gone").status).toBe("elsewhere");
58
+ expect(resolveRepoPath(dir, "x", "kubernetes/app").status).toBe("elsewhere");
59
+ });
60
+
61
+ test("a tree with no origin resolves against the directory, unless an origin is required", () => {
62
+ const git = checkout();
63
+ expect(repoTreeOf(git).origin).toBeUndefined();
64
+ expect(resolveRepoPath(git, "https://github.com/acme/infra", "kubernetes/app").status).toBe("found");
65
+ expect(resolveRepoPath(git, "https://github.com/acme/infra", "kubernetes/app", { requireOrigin: true }).status).toBe("elsewhere");
66
+
67
+ const plain = mkdtempSync(join(tmpdir(), "chant-repo-path-plain-"));
68
+ mkdirSync(join(plain, "kubernetes/app"), { recursive: true });
69
+ expect(resolveRepoPath(plain, "https://github.com/acme/infra", "kubernetes/app").status).toBe("found");
70
+ expect(resolveRepoPath(plain, "https://github.com/acme/infra", "kubernetes/gone").status).toBe("missing");
71
+ });
72
+ });
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Where a path a manifest names lives (#5109): an Argo CD Application's
3
+ * `spec.source.path` is a path inside the repository its `repoURL` names, not
4
+ * inside whatever directory a command was started from.
5
+ *
6
+ * Given the directory of a tree that is being read (the root `chant audit`
7
+ * walks), {@link resolveRepoPath} finds the checkout the tree is in and
8
+ * answers one of three things:
9
+ *
10
+ * - `found` or `missing`: the repository is this one, or no `origin` remote
11
+ * says otherwise, and the path is (or is not) a directory or file below the
12
+ * checkout's root.
13
+ * - `elsewhere`: the checkout's `origin` remote names a different repository
14
+ * than `repoURL`, so the path is in a tree that is not on disk and nothing
15
+ * can be said about it.
16
+ *
17
+ * A tree outside any checkout (an extracted archive) has no remote to compare,
18
+ * and resolves against the directory itself. `requireOrigin` turns that case
19
+ * into `elsewhere`, for a caller that wants a path read only when a remote
20
+ * says the repository is the workspace's own.
21
+ *
22
+ * Reading the remote runs `git`, once per directory.
23
+ */
24
+ import { execFileSync } from "node:child_process";
25
+ import { statSync } from "node:fs";
26
+ import { isAbsolute, relative, resolve, sep } from "node:path";
27
+ import { remoteHost, remoteRepoPath } from "./forge-remote";
28
+
29
+ /** The checkout a directory is in. */
30
+ export interface RepoTree {
31
+ /** The checkout's root, or the directory itself when it is in none. */
32
+ root: string;
33
+ /** The `origin` remote's URL, when the directory is in a checkout that has one. */
34
+ origin?: string;
35
+ }
36
+
37
+ const trees = new Map<string, RepoTree>();
38
+
39
+ function git(cwd: string, args: string[]): string | undefined {
40
+ try {
41
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim() || undefined;
42
+ } catch {
43
+ return undefined;
44
+ }
45
+ }
46
+
47
+ /** The checkout `dir` is in, read once per directory. */
48
+ export function repoTreeOf(dir: string): RepoTree {
49
+ const abs = resolve(dir);
50
+ const known = trees.get(abs);
51
+ if (known) return known;
52
+ const top = git(abs, ["rev-parse", "--show-toplevel"]);
53
+ const tree: RepoTree = top ? { root: top, origin: git(abs, ["remote", "get-url", "origin"]) } : { root: abs };
54
+ if (tree.origin === undefined) delete tree.origin;
55
+ trees.set(abs, tree);
56
+ return tree;
57
+ }
58
+
59
+ /** Whether two repository URLs name the same repository: the same host and path, whatever the scheme, user, case or `.git` suffix. */
60
+ export function sameRepository(a: string | undefined, b: string | undefined): boolean {
61
+ const pa = remoteRepoPath(a);
62
+ const pb = remoteRepoPath(b);
63
+ if (!pa || !pb) return false;
64
+ return pa.toLowerCase() === pb.toLowerCase() && remoteHost(a) === remoteHost(b);
65
+ }
66
+
67
+ export type RepoPathStatus = "found" | "missing" | "elsewhere";
68
+
69
+ export interface RepoPathResolution {
70
+ status: RepoPathStatus;
71
+ /** The path from the checkout's root, with `.` and `..` folded, or the path as given when it leaves the checkout. */
72
+ path: string;
73
+ }
74
+
75
+ export interface ResolveRepoPathOptions {
76
+ /** Whether the path names a directory (the default) or a file. */
77
+ type?: "dir" | "file";
78
+ /** Treat a tree with no `origin` remote as another repository. Default false. */
79
+ requireOrigin?: boolean;
80
+ }
81
+
82
+ /**
83
+ * Resolve `path`, which a manifest in the tree at `dir` names inside the
84
+ * repository `repoURL`. See the module comment for the three answers.
85
+ */
86
+ export function resolveRepoPath(dir: string, repoURL: string | undefined, path: string, opts: ResolveRepoPathOptions = {}): RepoPathResolution {
87
+ const tree = repoTreeOf(dir);
88
+ if (tree.origin === undefined ? opts.requireOrigin : repoURL !== undefined && repoURL !== "" && !sameRepository(tree.origin, repoURL)) {
89
+ return { status: "elsewhere", path };
90
+ }
91
+ // A path in a repository is relative to its root, with or without a leading slash.
92
+ const full = resolve(tree.root, path.replace(/^\/+/, ""));
93
+ const rel = relative(tree.root, full);
94
+ if (isAbsolute(rel) || rel === ".." || rel.startsWith(`..${sep}`)) return { status: "missing", path };
95
+ const shown = rel === "" ? "." : rel.split(sep).join("/");
96
+ try {
97
+ const stat = statSync(full);
98
+ const ok = (opts.type ?? "dir") === "dir" ? stat.isDirectory() : stat.isFile();
99
+ return { status: ok ? "found" : "missing", path: shown };
100
+ } catch {
101
+ return { status: "missing", path: shown };
102
+ }
103
+ }
@@ -32,3 +32,41 @@ export function isSensitiveKey(key: string): boolean {
32
32
  return SENSITIVE_KEY_PATTERNS.some((p) => p.test(key));
33
33
  }
34
34
 
35
+
36
+ /**
37
+ * Reference fields: keys that match {@link SENSITIVE_KEY_PATTERNS} only because
38
+ * the word "secret" is in the name, and whose value names another object
39
+ * instead of holding a secret. `spec.secretStoreRef` on an ExternalSecret is
40
+ * `{ name, kind }`, the pointer to a SecretStore; a joined graph needs it.
41
+ *
42
+ * This is an exact-key allowlist, and the value must also have the shape of a
43
+ * pointer (see {@link isReferenceField}). A key outside the list stays masked
44
+ * by the patterns, so a new field is masked until someone adds it here.
45
+ * `secretKeyRef` is not on the list: its `key` names an entry inside a Secret
46
+ * and the paths that read a masked value (chant import) treat it as one.
47
+ */
48
+ export const REFERENCE_KEYS: ReadonlySet<string> = new Set(["secretStoreRef", "secretRef", "imagePullSecrets"]);
49
+
50
+ /** The only fields a pointer may carry. `key`, `value`, `data` and the like are not here. */
51
+ const REFERENCE_FIELDS: ReadonlySet<string> = new Set(["name", "namespace", "kind", "apiVersion"]);
52
+
53
+ function isPointer(value: unknown): boolean {
54
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
55
+ const entries = Object.entries(value as Record<string, unknown>);
56
+ return entries.every(([k, v]) => REFERENCE_FIELDS.has(k) && typeof v === "string");
57
+ }
58
+
59
+ /**
60
+ * True when `key` is a reference key and `value` is a pointer to an object:
61
+ * a plain object whose every field is a string named `name`, `namespace`,
62
+ * `kind` or `apiVersion` (or a list of such objects, for `imagePullSecrets`).
63
+ * Anything else under the same key, a string, a number, an object with a
64
+ * `key` or `value` field, a nested object, is not a pointer and stays masked.
65
+ * The value is not a secret, but the check is on shape so that a value that
66
+ * could be one never passes on the strength of its key.
67
+ */
68
+ export function isReferenceField(key: string, value: unknown): boolean {
69
+ if (!REFERENCE_KEYS.has(key)) return false;
70
+ if (Array.isArray(value)) return value.length > 0 && value.every(isPointer);
71
+ return isPointer(value);
72
+ }