@intentius/chant 0.124.96 → 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.
- package/dist/audit/core.d.ts +29 -0
- package/dist/audit/core.d.ts.map +1 -1
- package/dist/audit/core.js +48 -11
- package/dist/audit/identity.d.ts +27 -0
- package/dist/audit/identity.d.ts.map +1 -0
- package/dist/audit/identity.js +36 -0
- package/dist/audit/report-html.d.ts +3 -1
- package/dist/audit/report-html.d.ts.map +1 -1
- package/dist/audit/report-html.js +1 -1
- package/dist/audit/report-model.d.ts +16 -0
- package/dist/audit/report-model.d.ts.map +1 -1
- package/dist/audit/report-model.js +5 -1
- package/dist/change-set-graph.d.ts +3 -1
- package/dist/change-set-graph.d.ts.map +1 -1
- package/dist/change-set-graph.js +7 -1
- package/dist/change-set.d.ts +5 -2
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -3
- package/dist/ci-agent.d.ts +17 -0
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +32 -0
- package/dist/ci-comment-allow.d.ts +88 -0
- package/dist/ci-comment-allow.d.ts.map +1 -0
- package/dist/ci-comment-allow.js +178 -0
- package/dist/ci-comment-commands.d.ts +12 -0
- package/dist/ci-comment-commands.d.ts.map +1 -1
- package/dist/ci-comment-commands.js +22 -0
- package/dist/ci-control.d.ts +6 -1
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +6 -1
- package/dist/ci-product.d.ts +3 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +3 -0
- package/dist/cli/commands/audit.d.ts +3 -1
- package/dist/cli/commands/audit.d.ts.map +1 -1
- package/dist/cli/commands/audit.js +23 -6
- package/dist/cli/commands/import.d.ts +8 -1
- package/dist/cli/commands/import.d.ts.map +1 -1
- package/dist/cli/commands/import.js +31 -6
- package/dist/cli/handlers/agent.d.ts.map +1 -1
- package/dist/cli/handlers/agent.js +12 -2
- package/dist/cli/handlers/pr-comment.d.ts +6 -0
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
- package/dist/cli/handlers/pr-comment.js +12 -0
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +53 -6
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +29 -6
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +23 -0
- package/dist/cli/registry.d.ts +8 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/cloud-lister/mask.d.ts +30 -1
- package/dist/cloud-lister/mask.d.ts.map +1 -1
- package/dist/cloud-lister/mask.js +66 -3
- package/dist/components/driver.d.ts +8 -1
- package/dist/components/driver.d.ts.map +1 -1
- package/dist/components/driver.js +1 -0
- package/dist/components/product-pipeline.d.ts +23 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +40 -7
- package/dist/components/product-plan.d.ts +20 -0
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +11 -1
- package/dist/control/applied.d.ts +8 -1
- package/dist/control/applied.d.ts.map +1 -1
- package/dist/control/applied.js +18 -2
- package/dist/control/dispatch.d.ts +52 -0
- package/dist/control/dispatch.d.ts.map +1 -1
- package/dist/control/dispatch.js +140 -4
- package/dist/control/train.d.ts +198 -0
- package/dist/control/train.d.ts.map +1 -0
- package/dist/control/train.js +294 -0
- package/dist/deep-observation.js +2 -2
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +7 -1
- package/dist/graph-detail.d.ts +9 -0
- package/dist/graph-detail.d.ts.map +1 -1
- package/dist/graph-detail.js +38 -13
- package/dist/graph-refs.d.ts +233 -3
- package/dist/graph-refs.d.ts.map +1 -1
- package/dist/graph-refs.js +106 -15
- package/dist/lint/post-synth.d.ts +22 -0
- package/dist/lint/post-synth.d.ts.map +1 -1
- package/dist/lint/rules/declarable-naming-convention.d.ts +12 -0
- package/dist/lint/rules/declarable-naming-convention.d.ts.map +1 -1
- package/dist/lint/rules/declarable-naming-convention.js +38 -8
- package/dist/lint/rules/imported-source.d.ts +20 -0
- package/dist/lint/rules/imported-source.d.ts.map +1 -0
- package/dist/lint/rules/imported-source.js +27 -0
- package/dist/lint/rules/no-unused-declarable.d.ts.map +1 -1
- package/dist/lint/rules/no-unused-declarable.js +3 -0
- package/dist/op/gate.d.ts +2 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +8 -1
- package/dist/pr-forge-reads.d.ts +17 -0
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +55 -0
- package/dist/reconcile.d.ts +9 -0
- package/dist/reconcile.d.ts.map +1 -1
- package/dist/release-floors.d.ts +9 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +10 -2
- package/dist/repo-path.d.ts +29 -0
- package/dist/repo-path.d.ts.map +1 -0
- package/dist/repo-path.js +81 -0
- package/dist/sensitive-key.d.ts +23 -0
- package/dist/sensitive-key.d.ts.map +1 -1
- package/dist/sensitive-key.js +37 -0
- package/dist/terraform/hcl2json.d.ts +7 -0
- package/dist/terraform/hcl2json.d.ts.map +1 -1
- package/dist/terraform/hcl2json.js +7 -0
- package/dist/wave-runtime.mjs +352 -345
- package/dist/workspace/catalog-edges.d.ts +147 -0
- package/dist/workspace/catalog-edges.d.ts.map +1 -0
- package/dist/workspace/catalog-edges.js +461 -0
- package/dist/workspace/compose-graph.d.ts +73 -3
- package/dist/workspace/compose-graph.d.ts.map +1 -1
- package/dist/workspace/declaration.d.ts +2 -0
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +1 -0
- package/dist/workspace/declaration.schema.json +6 -0
- package/dist/workspace/discover.d.ts +134 -0
- package/dist/workspace/discover.d.ts.map +1 -0
- package/dist/workspace/discover.js +372 -0
- package/dist/workspace/graph-cli.d.ts +20 -0
- package/dist/workspace/graph-cli.d.ts.map +1 -1
- package/dist/workspace/graph-cli.js +178 -20
- package/dist/workspace/graph.schema.json +195 -2
- package/dist/workspace/release-train.d.ts +214 -3
- package/dist/workspace/release-train.d.ts.map +1 -1
- package/dist/workspace/release-train.js +552 -16
- package/dist/workspace/repo-ref.d.ts +14 -0
- package/dist/workspace/repo-ref.d.ts.map +1 -1
- package/dist/workspace/repo-ref.js +26 -1
- package/dist/workspace/workspace-gates.d.ts +24 -0
- package/dist/workspace/workspace-gates.d.ts.map +1 -1
- package/dist/workspace/workspace-gates.js +29 -5
- package/dist/workspace/workspace-ledger.d.ts +31 -5
- package/dist/workspace/workspace-ledger.d.ts.map +1 -1
- package/dist/workspace/workspace-ledger.js +2 -1
- package/dist/workspace/workspace-run.d.ts +14 -0
- package/dist/workspace/workspace-run.d.ts.map +1 -1
- package/dist/workspace/workspace-run.js +2 -2
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +33 -8
- package/package.json +1 -1
- package/src/audit/core.test.ts +64 -1
- package/src/audit/core.ts +75 -10
- package/src/audit/identity.test.ts +31 -0
- package/src/audit/identity.ts +43 -0
- package/src/audit/report-html.ts +4 -2
- package/src/audit/report-model.ts +21 -1
- package/src/change-set-graph.test.ts +33 -1
- package/src/change-set-graph.ts +7 -1
- package/src/change-set.ts +6 -3
- package/src/ci-agent.test.ts +32 -0
- package/src/ci-agent.ts +42 -0
- package/src/ci-comment-allow.test.ts +380 -0
- package/src/ci-comment-allow.ts +184 -0
- package/src/ci-comment-commands.ts +25 -0
- package/src/ci-control.ts +42 -0
- package/src/ci-product.ts +3 -0
- package/src/cli/commands/audit-parser-notice.test.ts +74 -0
- package/src/cli/commands/audit.test.ts +12 -0
- package/src/cli/commands/audit.ts +25 -7
- package/src/cli/commands/import-layout.test.ts +2 -1
- package/src/cli/commands/import.ts +29 -6
- package/src/cli/handlers/agent.ts +13 -2
- package/src/cli/handlers/pr-before-merge.test.ts +18 -0
- package/src/cli/handlers/pr-comment.ts +12 -0
- package/src/cli/handlers/promote.test.ts +68 -0
- package/src/cli/handlers/promote.ts +52 -6
- package/src/cli/main.test.ts +5 -0
- package/src/cli/main.ts +29 -6
- package/src/cli/parse-args.ts +18 -0
- package/src/cli/registry.ts +8 -0
- package/src/cloud-lister/kubernetes.k3d.e2e.test.ts +104 -0
- package/src/cloud-lister/mask-references.test.ts +132 -0
- package/src/cloud-lister/mask.ts +68 -3
- package/src/components/driver.ts +9 -1
- package/src/components/product-pipeline.ts +57 -7
- package/src/components/product-plan.ts +27 -2
- package/src/control/applied.ts +33 -3
- package/src/control/dispatch.ts +156 -5
- package/src/control/train.test.ts +215 -0
- package/src/control/train.ts +413 -0
- package/src/deep-observation.ts +2 -2
- package/src/floor-table.data.ts +7 -1
- package/src/graph-detail.ts +37 -12
- package/src/graph-refs.test.ts +45 -1
- package/src/graph-refs.ts +321 -14
- package/src/lint/post-synth.ts +20 -0
- package/src/lint/rules/declarable-naming-convention.test.ts +35 -1
- package/src/lint/rules/declarable-naming-convention.ts +35 -8
- package/src/lint/rules/imported-source.test.ts +22 -0
- package/src/lint/rules/imported-source.ts +31 -0
- package/src/lint/rules/no-unused-declarable.test.ts +16 -0
- package/src/lint/rules/no-unused-declarable.ts +7 -0
- package/src/op/gate.ts +10 -2
- package/src/pr-forge-reads.ts +62 -0
- package/src/reconcile.ts +9 -0
- package/src/release-floors.ts +14 -2
- package/src/repo-path.test.ts +72 -0
- package/src/repo-path.ts +103 -0
- package/src/sensitive-key.ts +38 -0
- package/src/terraform/hcl2json.ts +8 -0
- package/src/workspace/application-set.e2e.test.ts +405 -0
- package/src/workspace/catalog-edges.ts +507 -0
- package/src/workspace/ci-green-workflow.test.ts +2 -2
- package/src/workspace/cluster-join.e2e.test.ts +150 -0
- package/src/workspace/compose-graph.ts +74 -5
- package/src/workspace/declaration.schema.json +6 -0
- package/src/workspace/declaration.ts +3 -0
- package/src/workspace/discover.e2e.test.ts +122 -0
- package/src/workspace/discover.test.ts +225 -0
- package/src/workspace/discover.ts +406 -0
- package/src/workspace/drift-reader.test.ts +3 -3
- package/src/workspace/external-secret-catalog.e2e.test.ts +98 -0
- package/src/workspace/external-secret-catalog.test.ts +142 -0
- package/src/workspace/graph-cli.ts +207 -21
- package/src/workspace/graph-contract.test.ts +92 -0
- package/src/workspace/graph.schema.json +195 -2
- package/src/workspace/helm-references.e2e.test.ts +135 -0
- package/src/workspace/identity-annotation-catalog.e2e.test.ts +91 -0
- package/src/workspace/identity-annotation-catalog.test.ts +139 -0
- package/src/workspace/release-train-repos.test.ts +304 -0
- package/src/workspace/release-train.test.ts +296 -0
- package/src/workspace/release-train.ts +631 -16
- package/src/workspace/repo-ref.ts +26 -1
- package/src/workspace/runs-on.test.ts +45 -0
- package/src/workspace/workspace-gates.ts +48 -5
- package/src/workspace/workspace-ledger.ts +28 -5
- package/src/workspace/workspace-run.test.ts +1 -1
- package/src/workspace/workspace-run.ts +2 -2
- package/src/yaml.test.ts +96 -8
- package/src/yaml.ts +36 -8
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reference catalog over a composed workspace graph (#5097, phase 3 of
|
|
3
|
+
* INTENTIUS/behold#1049).
|
|
4
|
+
*
|
|
5
|
+
* Each lexicon's `referenceCatalog` says how its resources name each other.
|
|
6
|
+
* It ran over a live read and over a cloud index (#4522), never over the
|
|
7
|
+
* declared graph `chant workspace graph` composes, so no edge went from one
|
|
8
|
+
* member to another except through links. {@link runCatalogPass} runs
|
|
9
|
+
* `reconstructIndexedEdges` (../graph-refs.ts) over every composed node, and
|
|
10
|
+
* {@link placeCatalogPass} writes what it found into the document:
|
|
11
|
+
*
|
|
12
|
+
* - each edge it draws goes in `edges` with `origin: "derived"`, the `rule`
|
|
13
|
+
* that drew it, its `relation` and `grain: "property"`, and the holder's
|
|
14
|
+
* `member`. A pair the declared graph already joins gets no second edge;
|
|
15
|
+
* - a reference that names no node goes in `dangling`, with its `rule` and
|
|
16
|
+
* the `targetKind` the rule looks for;
|
|
17
|
+
* - a reference that names more than one node draws no edge and goes in
|
|
18
|
+
* `ambiguous` with every candidate;
|
|
19
|
+
* - `catalog` names the lexicons whose catalog ran, the members read, each
|
|
20
|
+
* rule the document names, and per node the arguments it could not read.
|
|
21
|
+
*
|
|
22
|
+
* ## Scopes
|
|
23
|
+
*
|
|
24
|
+
* A Kubernetes name is unique inside its namespace, while a rule from a
|
|
25
|
+
* Kubernetes object to a cloud resource has to reach a node of another
|
|
26
|
+
* member. The pass keeps one scope per node and uses the index's two-level
|
|
27
|
+
* lookup for both: every node sits in the workspace, and a node of a kind its
|
|
28
|
+
* catalog lists in `scopes` also sits in the scope that kind names, its
|
|
29
|
+
* namespace. A holder in a namespace reaches the nodes of that namespace in
|
|
30
|
+
* any member, and every node that has no namespace. A holder with no
|
|
31
|
+
* namespace reaches only nodes with none. One of those kinds whose node names
|
|
32
|
+
* no namespace sits in a scope of its own member, since chant cannot tell
|
|
33
|
+
* where it will be applied, and the objects one member applies together go to
|
|
34
|
+
* one namespace far more often than not.
|
|
35
|
+
*
|
|
36
|
+
* ## Declared nodes the rules are not written against
|
|
37
|
+
*
|
|
38
|
+
* A catalog's `declaredNode` gives the node the rules read, for a lexicon
|
|
39
|
+
* whose declared nodes are not shaped like its rules: terraform's are all
|
|
40
|
+
* `Terraform::Resource`, with their arguments under `body`. An instance node
|
|
41
|
+
* is handed its block node too, since its attrs stay on the block (#5117).
|
|
42
|
+
* The view is read for this pass only; the document's nodes are unchanged.
|
|
43
|
+
*
|
|
44
|
+
* ## Generated nodes and repository paths (#5102)
|
|
45
|
+
*
|
|
46
|
+
* A catalog's `generates` rules make nodes from a node: an ApplicationSet's
|
|
47
|
+
* generators yield Applications. The pass reads each generated node with the
|
|
48
|
+
* others, so the rules join it as they join a declared node of its kind, and
|
|
49
|
+
* draws a derived edge from the holder to it. A node a generator made for a
|
|
50
|
+
* cluster registration it selected gets an edge to that registration under
|
|
51
|
+
* the rule's `cluster` id, and no other rule's edge for that pair. {@link placeCatalogPass} adds
|
|
52
|
+
* it to `nodes` with `generatedBy`, and marks the holder with `expansion`:
|
|
53
|
+
* how many it generated and what it did not expand.
|
|
54
|
+
*
|
|
55
|
+
* A generate rule's `files` reads the files a generated node names, when the
|
|
56
|
+
* caller hands the pass `readFile` (#5094): a generated Application's Helm
|
|
57
|
+
* values files become nodes, with the objects under their `extraObjects`,
|
|
58
|
+
* as they do for an Application written by hand. Each is `<holder
|
|
59
|
+
* id>/<key>`, in the holder's member, with `generatedBy` naming the
|
|
60
|
+
* generated node and `generator: "file"`, and the rules read it with the
|
|
61
|
+
* rest.
|
|
62
|
+
*
|
|
63
|
+
* A catalog's `pathRefs` rules read the paths in a repository a node names.
|
|
64
|
+
* The caller says, through `lookPath`, whether each is in the workspace's
|
|
65
|
+
* repository; one that is not there, or is a file where a directory is
|
|
66
|
+
* named, goes in `dangling`. A path in another repository is not read. On a
|
|
67
|
+
* generated node the entry names the holder as `through` and the cluster
|
|
68
|
+
* registration the node was made for as `cluster`.
|
|
69
|
+
*
|
|
70
|
+
* ## Detail tiers
|
|
71
|
+
*
|
|
72
|
+
* The pass reads every node with its full attributes, whatever `--detail` the
|
|
73
|
+
* document is printed at. At T1 and T0 an edge, a dangling holder and the
|
|
74
|
+
* candidates move to the node they are drawn as ({@link detailIdMap}), and an
|
|
75
|
+
* edge both of whose ends land on one node is dropped, as T1 drops an edge
|
|
76
|
+
* inside a composite.
|
|
77
|
+
*
|
|
78
|
+
* Pure.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
import {
|
|
82
|
+
containmentGroups,
|
|
83
|
+
memberRegion,
|
|
84
|
+
reconstructIndexedEdges,
|
|
85
|
+
readPath,
|
|
86
|
+
refRuleId,
|
|
87
|
+
type ContainmentPair,
|
|
88
|
+
type GenerateRule,
|
|
89
|
+
type RepoPathRef,
|
|
90
|
+
type IndexedNodeScope,
|
|
91
|
+
type NamedCatalog,
|
|
92
|
+
} from "../graph-refs";
|
|
93
|
+
import type { IREdge } from "../graph-ir";
|
|
94
|
+
import { nodeAttrsAt, type DetailLevel } from "../graph-detail";
|
|
95
|
+
import type {
|
|
96
|
+
CatalogRuleEntry,
|
|
97
|
+
CatalogSummary,
|
|
98
|
+
ComposedAmbiguous,
|
|
99
|
+
ComposedDangling,
|
|
100
|
+
ComposedEdge,
|
|
101
|
+
ComposedNode,
|
|
102
|
+
NodeExpansion,
|
|
103
|
+
WorkspaceGraph,
|
|
104
|
+
} from "./compose-graph";
|
|
105
|
+
import { composedId, danglingKey } from "./compose-graph";
|
|
106
|
+
|
|
107
|
+
/** The scope every node of a declared workspace graph sits in. */
|
|
108
|
+
export const WORKSPACE_SCOPE = "workspace";
|
|
109
|
+
|
|
110
|
+
/** What the catalog pass found, on the ids of the nodes it read. */
|
|
111
|
+
export interface CatalogPass {
|
|
112
|
+
edges: ComposedEdge[];
|
|
113
|
+
containment: ContainmentPair[];
|
|
114
|
+
dangling: ComposedDangling[];
|
|
115
|
+
ambiguous: ComposedAmbiguous[];
|
|
116
|
+
/** By node id: arguments left unread because they are not literal. */
|
|
117
|
+
nonLiteral: Record<string, number>;
|
|
118
|
+
/** Every rule of the catalogs, by rule id. */
|
|
119
|
+
rules: Record<string, CatalogRuleEntry>;
|
|
120
|
+
lexicons: string[];
|
|
121
|
+
members: string[];
|
|
122
|
+
/** Nodes a catalog's `sharedNodes` added (#5100), with their ids as the document gives them. */
|
|
123
|
+
shared: ComposedNode[];
|
|
124
|
+
/** The nodes the catalogs' `generates` rules made (#5102), as the pass read them, each with `generatedBy`. */
|
|
125
|
+
generated: ComposedNode[];
|
|
126
|
+
/** By holder id: what a `generates` rule made of it. */
|
|
127
|
+
expansions: Record<string, NodeExpansion>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The text of a workspace-relative file in the workspace's repository, or undefined when it is not there (#5094). */
|
|
131
|
+
export type ReadFile = (path: string) => string | undefined;
|
|
132
|
+
|
|
133
|
+
/** Whether a repository path is in the workspace's repository: what it is there, `missing`, or undefined when the path is in another repository and is not read. */
|
|
134
|
+
export type LookPath = (ref: RepoPathRef) => "dir" | "file" | "missing" | undefined;
|
|
135
|
+
|
|
136
|
+
const byString = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
|
|
137
|
+
|
|
138
|
+
/** Each rule of the catalogs by id. Rules that share an id (one per target kind) share an entry. */
|
|
139
|
+
export function catalogRules(catalogs: readonly NamedCatalog[]): Record<string, CatalogRuleEntry> {
|
|
140
|
+
const out: Record<string, CatalogRuleEntry> = {};
|
|
141
|
+
const add = (id: string, entry: Omit<CatalogRuleEntry, "targetKinds">, targetKind: string | undefined): void => {
|
|
142
|
+
const prev = out[id];
|
|
143
|
+
const kinds = new Set(prev?.targetKinds ?? []);
|
|
144
|
+
if (targetKind !== undefined) kinds.add(targetKind);
|
|
145
|
+
out[id] = { ...entry, ...(prev?.label !== undefined && entry.label === undefined ? { label: prev.label } : {}), targetKinds: [...kinds].sort(byString) };
|
|
146
|
+
};
|
|
147
|
+
for (const { lexicon, catalog } of catalogs) {
|
|
148
|
+
for (const r of catalog.refs) {
|
|
149
|
+
add(refRuleId(lexicon, r.from, r.path), { lexicon, from: r.from, path: r.path, relation: r.relation, ...(r.label ? { label: r.label } : {}) }, r.targetKind ?? r.indexedTargetKind);
|
|
150
|
+
}
|
|
151
|
+
for (const g of catalog.generates ?? []) {
|
|
152
|
+
add(refRuleId(lexicon, g.from, g.path), { lexicon, from: g.from, path: g.path, relation: "reference", ...(g.label ? { label: g.label } : {}) }, g.targetKind);
|
|
153
|
+
if (g.cluster) add(refRuleId(lexicon, g.from, g.cluster.path), { lexicon, from: g.from, path: g.cluster.path, relation: "reference", ...(g.cluster.label ? { label: g.cluster.label } : {}) }, g.cluster.targetKind);
|
|
154
|
+
}
|
|
155
|
+
for (const p of catalog.pathRefs ?? []) {
|
|
156
|
+
add(refRuleId(lexicon, p.from, p.path), { lexicon, from: p.from, path: p.path, relation: "reference", ...(p.label ? { label: p.label } : {}) }, undefined);
|
|
157
|
+
}
|
|
158
|
+
for (const t of catalog.tagRefs ?? []) {
|
|
159
|
+
const from = t.from ?? "*";
|
|
160
|
+
add(refRuleId(lexicon, from, `tag:${t.key}`), { lexicon, from, path: `tag:${t.key}`, relation: "reference", ...(t.label ? { label: t.label } : {}) }, t.targetKind);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Run the catalogs over composed nodes, each read with its full attributes.
|
|
168
|
+
* Rules apply to nodes of their own lexicon; targets can be any node.
|
|
169
|
+
* `members` names the members read, the nodes' own members by default.
|
|
170
|
+
* `lookPath` finds a path rule's paths in the repository; without it no path
|
|
171
|
+
* is read. `readFile` reads a file a generated node names (#5094); without
|
|
172
|
+
* it no such file is read.
|
|
173
|
+
*/
|
|
174
|
+
export function runCatalogPass(nodes: readonly ComposedNode[], catalogs: readonly NamedCatalog[], members?: readonly string[], lookPath?: LookPath, readFile?: ReadFile): CatalogPass {
|
|
175
|
+
const byLexicon = new Map(catalogs.map((c) => [c.lexicon, c.catalog]));
|
|
176
|
+
const nonLiteral: Record<string, number> = {};
|
|
177
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
178
|
+
const read: ComposedNode[] = nodes.map((n) => {
|
|
179
|
+
const view = byLexicon.get(n.lexicon)?.declaredNode?.(n, n.instanceOf !== undefined ? byId.get(n.instanceOf) : undefined);
|
|
180
|
+
if (!view) return n;
|
|
181
|
+
if (view.nonLiteral > 0) nonLiteral[n.id] = view.nonLiteral;
|
|
182
|
+
return { ...n, kind: view.kind, attrs: view.attrs };
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Generated nodes (#5102), made from the nodes as the rules read them.
|
|
186
|
+
const generated: ComposedNode[] = [];
|
|
187
|
+
const expansions: Record<string, NodeExpansion> = {};
|
|
188
|
+
const generatedEdges: ComposedEdge[] = [];
|
|
189
|
+
// A generated node's cluster registration, when its generator selected one: another rule's edge to it is left out.
|
|
190
|
+
const selectedFor = new Map<string, string>();
|
|
191
|
+
const withFiles: Array<{ rule: GenerateRule; ruleId: string; holder: ComposedNode; node: ComposedNode }> = [];
|
|
192
|
+
for (const holder of read) {
|
|
193
|
+
for (const rule of byLexicon.get(holder.lexicon)?.generates ?? []) {
|
|
194
|
+
if (rule.from !== holder.kind) continue;
|
|
195
|
+
const id = refRuleId(holder.lexicon, rule.from, rule.path);
|
|
196
|
+
const made = rule.generate(holder, read);
|
|
197
|
+
let count = 0;
|
|
198
|
+
for (const g of made.nodes) {
|
|
199
|
+
const nodeId = `${holder.id}/${g.key}`;
|
|
200
|
+
if (byId.has(nodeId) || generated.some((n) => n.id === nodeId)) continue;
|
|
201
|
+
count++;
|
|
202
|
+
const node: ComposedNode = {
|
|
203
|
+
id: nodeId,
|
|
204
|
+
kind: g.kind,
|
|
205
|
+
lexicon: holder.lexicon,
|
|
206
|
+
attrs: g.attrs,
|
|
207
|
+
member: holder.member,
|
|
208
|
+
...(holder.nested !== undefined ? { nested: holder.nested } : {}),
|
|
209
|
+
generatedBy: { node: holder.id, rule: id, generator: g.generator, params: g.params, ...(g.cluster ? { cluster: g.cluster.id } : {}) },
|
|
210
|
+
};
|
|
211
|
+
generated.push(node);
|
|
212
|
+
if (rule.files && readFile) withFiles.push({ rule, ruleId: id, holder, node });
|
|
213
|
+
generatedEdges.push({ from: holder.id, to: nodeId, kind: "ref", viaAttr: refViaAttr(rule.path), grain: "property", origin: "derived", rule: id, relation: "reference", member: holder.member });
|
|
214
|
+
if (g.cluster && rule.cluster) {
|
|
215
|
+
const clusterRule = refRuleId(holder.lexicon, rule.from, rule.cluster.path);
|
|
216
|
+
generatedEdges.push({ from: nodeId, to: g.cluster.id, kind: "ref", viaAttr: "generatedBy", grain: "property", origin: "derived", rule: clusterRule, relation: "reference", member: holder.member });
|
|
217
|
+
selectedFor.set(nodeId, g.cluster.id);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
expansions[holder.id] = { rule: id, generated: count, notExpanded: made.notExpanded };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
read.push(...generated);
|
|
224
|
+
|
|
225
|
+
// The files a generated node names (#5094): its values files and their objects, one node per file under the holder.
|
|
226
|
+
const fromFiles: ComposedNode[] = [];
|
|
227
|
+
const fileIds = new Set<string>();
|
|
228
|
+
for (const { rule, ruleId, holder, node } of withFiles) {
|
|
229
|
+
for (const f of rule.files!(node, readFile!, read)) {
|
|
230
|
+
const id = `${holder.id}/${f.key}`;
|
|
231
|
+
if (byId.has(id) || fileIds.has(id)) continue;
|
|
232
|
+
fileIds.add(id);
|
|
233
|
+
fromFiles.push({
|
|
234
|
+
id,
|
|
235
|
+
kind: f.kind,
|
|
236
|
+
lexicon: f.lexicon,
|
|
237
|
+
attrs: f.attrs,
|
|
238
|
+
member: holder.member,
|
|
239
|
+
...(holder.nested !== undefined ? { nested: holder.nested } : {}),
|
|
240
|
+
generatedBy: { node: node.id, rule: ruleId, generator: "file", params: {} },
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
generated.push(...fromFiles);
|
|
245
|
+
read.push(...fromFiles);
|
|
246
|
+
const member = new Map(read.map((n) => [n.id, n.member]));
|
|
247
|
+
|
|
248
|
+
// A kind a catalog scopes is looked up by its own kind alone: the lexicon that wrote the node is not the catalog's (a values file read by the k8s reader is a helm node).
|
|
249
|
+
const scopePath = new Map<string, string | null>();
|
|
250
|
+
for (const { catalog } of catalogs) for (const r of catalog.scopes ?? []) scopePath.set(r.kind, r.path ?? null);
|
|
251
|
+
const scopeOf = (n: ComposedNode): IndexedNodeScope => {
|
|
252
|
+
// Every holder also reaches the nodes its own member holds with no other scope (`member`).
|
|
253
|
+
if (!scopePath.has(n.kind)) return { account: WORKSPACE_SCOPE, member: n.member };
|
|
254
|
+
const path = scopePath.get(n.kind);
|
|
255
|
+
// A kind scoped with no path is held by its member alone, whichever lexicon the member's other nodes are of.
|
|
256
|
+
if (path === null) return { account: WORKSPACE_SCOPE, region: memberRegion(n.member), member: n.member };
|
|
257
|
+
const named = readPath(n.attrs, path!).find((v) => v !== "");
|
|
258
|
+
return { account: WORKSPACE_SCOPE, region: named !== undefined ? `${n.lexicon}:${named}` : `${n.lexicon}@${n.member}`, member: n.member };
|
|
259
|
+
};
|
|
260
|
+
const scopes = new Map(read.map((n) => [n.id, scopeOf(n)]));
|
|
261
|
+
|
|
262
|
+
// Nodes that no member owns (#5100): placed in the member of the first holder, with an edge to each from every holder.
|
|
263
|
+
const shared: ComposedNode[] = [];
|
|
264
|
+
const sharedEdges: ComposedEdge[] = [];
|
|
265
|
+
const sharedRules: Record<string, CatalogRuleEntry> = {};
|
|
266
|
+
const kindOf = new Map(read.map((n) => [n.id, n.kind]));
|
|
267
|
+
for (const { lexicon, catalog } of catalogs) {
|
|
268
|
+
for (const s of catalog.sharedNodes?.(read) ?? []) {
|
|
269
|
+
const holders = [...s.holders].sort((a, b) => byString(a.from, b.from));
|
|
270
|
+
if (holders.length === 0) continue;
|
|
271
|
+
const owner = member.get(holders[0].from);
|
|
272
|
+
if (owner === undefined) continue;
|
|
273
|
+
const id = composedId(owner, s.id);
|
|
274
|
+
shared.push({ id, kind: s.kind, lexicon, attrs: s.attrs, member: owner });
|
|
275
|
+
member.set(id, owner);
|
|
276
|
+
for (const h of holders) {
|
|
277
|
+
const from = kindOf.get(h.from);
|
|
278
|
+
if (from === undefined || h.from === id) continue;
|
|
279
|
+
const rule = refRuleId(lexicon, from, h.via);
|
|
280
|
+
const prev = sharedRules[rule];
|
|
281
|
+
const label = h.label ?? prev?.label;
|
|
282
|
+
sharedRules[rule] = {
|
|
283
|
+
lexicon,
|
|
284
|
+
from,
|
|
285
|
+
path: h.via,
|
|
286
|
+
relation: "reference",
|
|
287
|
+
targetKinds: [...new Set([...(prev?.targetKinds ?? []), s.kind])].sort(byString),
|
|
288
|
+
...(label ? { label } : {}),
|
|
289
|
+
};
|
|
290
|
+
sharedEdges.push({ from: h.from, to: id, kind: "ref", viaAttr: h.via, grain: "property", origin: "derived", rule, relation: "reference", member: member.get(h.from)! });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const found = reconstructIndexedEdges([...read, ...shared], catalogs, (n) => scopes.get(n.id) ?? { account: WORKSPACE_SCOPE, member: member.get(n.id) });
|
|
296
|
+
const memberOf = (id: string) => member.get(id)!;
|
|
297
|
+
return {
|
|
298
|
+
shared,
|
|
299
|
+
edges: [...generatedEdges, ...found.edges.filter((e) => selectedFor.get(e.from) !== e.to).map((e) => ({ ...e, member: memberOf(e.from) })), ...sharedEdges],
|
|
300
|
+
containment: found.containment,
|
|
301
|
+
dangling: [...pathDangling(read, byLexicon, lookPath), ...found.dangling.map((d) => ({
|
|
302
|
+
from: d.from,
|
|
303
|
+
kind: "ref" as const,
|
|
304
|
+
path: d.path,
|
|
305
|
+
value: d.value,
|
|
306
|
+
member: memberOf(d.from),
|
|
307
|
+
rule: d.rule,
|
|
308
|
+
...(d.targetKind ? { targetKind: d.targetKind } : {}),
|
|
309
|
+
...(d.through ? { through: d.through } : {}),
|
|
310
|
+
}))],
|
|
311
|
+
ambiguous: found.ambiguous.map((a) => ({ from: a.from, member: memberOf(a.from), rule: a.rule, path: a.path, value: a.value, candidates: a.candidates })),
|
|
312
|
+
nonLiteral,
|
|
313
|
+
rules: { ...catalogRules(catalogs), ...sharedRules },
|
|
314
|
+
lexicons: catalogs.map((c) => c.lexicon).sort(byString),
|
|
315
|
+
members: [...new Set(members ?? read.map((n) => n.member))].sort(byString),
|
|
316
|
+
generated,
|
|
317
|
+
expansions,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** A rule path's first step, the `viaAttr` an edge it draws carries, as the pass's own rules do. */
|
|
322
|
+
const refViaAttr = (path: string): string => path.split(/[.[]/)[0] || path;
|
|
323
|
+
|
|
324
|
+
/** The repository paths the nodes name that `lookPath` does not find (#5102). */
|
|
325
|
+
function pathDangling(nodes: readonly ComposedNode[], byLexicon: ReadonlyMap<string, NamedCatalog["catalog"]>, lookPath: LookPath | undefined): ComposedDangling[] {
|
|
326
|
+
if (!lookPath) return [];
|
|
327
|
+
const out = new Map<string, ComposedDangling>();
|
|
328
|
+
for (const node of nodes) {
|
|
329
|
+
for (const rule of byLexicon.get(node.lexicon)?.pathRefs ?? []) {
|
|
330
|
+
if (rule.from !== node.kind) continue;
|
|
331
|
+
const id = refRuleId(node.lexicon, rule.from, rule.path);
|
|
332
|
+
for (const ref of rule.read(node)) {
|
|
333
|
+
const there = lookPath(ref);
|
|
334
|
+
if (there === undefined || there === ref.type) continue;
|
|
335
|
+
const by = node.generatedBy;
|
|
336
|
+
out.set(`${node.id}\u0000${id}\u0000${ref.value}`, {
|
|
337
|
+
from: node.id,
|
|
338
|
+
kind: "ref",
|
|
339
|
+
path: rule.path,
|
|
340
|
+
value: ref.value,
|
|
341
|
+
member: node.member,
|
|
342
|
+
rule: id,
|
|
343
|
+
...(by ? { through: by.node, ...(by.cluster ? { cluster: by.cluster } : {}) } : {}),
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return [...out.values()];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Write a pass into the document. `placed` maps an id the pass read to the
|
|
353
|
+
* id of the node the document draws it as at its detail tier; an id it does
|
|
354
|
+
* not hold is kept as it is, except a generated node's, which is drawn where
|
|
355
|
+
* its holder is (a node read from a generated node's file, where that node is). A generated node goes in `nodes` when its holder is drawn
|
|
356
|
+
* as itself, with its attrs as `level` prints them.
|
|
357
|
+
*/
|
|
358
|
+
export function placeCatalogPass(graph: WorkspaceGraph, pass: CatalogPass, placed: ReadonlyMap<string, string> = new Map(), level: DetailLevel = 3): void {
|
|
359
|
+
const holderOf = new Map(pass.generated.map((n) => [n.id, n.generatedBy!.node]));
|
|
360
|
+
// A node read from a generated node's file (#5094) has that node as its holder, so the walk goes up to a node the document holds.
|
|
361
|
+
const at = (id: string, depth = 0): string => {
|
|
362
|
+
const holder = holderOf.get(id);
|
|
363
|
+
if (holder === undefined || depth > 4) return placed.get(id) ?? id;
|
|
364
|
+
const drawn = at(holder, depth + 1);
|
|
365
|
+
return drawn === holder ? id : drawn;
|
|
366
|
+
};
|
|
367
|
+
addGenerated(graph, pass, at, level);
|
|
368
|
+
if (pass.shared.length > 0) {
|
|
369
|
+
const have = new Set(graph.nodes.map((n) => n.id));
|
|
370
|
+
const added = pass.shared.filter((n) => !have.has(n.id));
|
|
371
|
+
graph.nodes = [...graph.nodes, ...added].sort((a, b) => byString(a.id, b.id));
|
|
372
|
+
for (const n of added) {
|
|
373
|
+
const m = (graph.groups.byMember[n.member] ??= []);
|
|
374
|
+
m.push(n.id);
|
|
375
|
+
m.sort(byString);
|
|
376
|
+
const l = ((graph.groups.byLexicon ??= {})[n.lexicon] ??= []);
|
|
377
|
+
l.push(n.id);
|
|
378
|
+
l.sort(byString);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const joined = new Set(graph.edges.map((e) => `${e.from}\u0000${e.to}`));
|
|
382
|
+
const named = new Set<string>();
|
|
383
|
+
|
|
384
|
+
const edges = new Map<string, ComposedEdge>();
|
|
385
|
+
for (const e of pass.edges) {
|
|
386
|
+
const from = at(e.from);
|
|
387
|
+
const to = at(e.to);
|
|
388
|
+
if (from === to || joined.has(`${from}\u0000${to}`)) continue;
|
|
389
|
+
const key = `${from}\u0000${to}\u0000${e.viaAttr ?? ""}\u0000${e.relation ?? ""}`;
|
|
390
|
+
const prev = edges.get(key);
|
|
391
|
+
if (!prev || byString(e.rule!, prev.rule!) < 0) edges.set(key, { ...e, from, to });
|
|
392
|
+
}
|
|
393
|
+
for (const e of edges.values()) named.add(e.rule!);
|
|
394
|
+
const edgeKey = (e: IREdge) => `${e.from}\u0000${e.to}\u0000${e.viaAttr ?? ""}`;
|
|
395
|
+
graph.edges = [...graph.edges, ...edges.values()].sort((a, b) => edgeKey(a).localeCompare(edgeKey(b)));
|
|
396
|
+
|
|
397
|
+
const dangling = new Map<string, ComposedDangling>();
|
|
398
|
+
for (const d of graph.dangling ?? []) dangling.set(`${danglingKey(d)}\u0000${d.rule ?? ""}\u0000${d.through ?? ""}`, d);
|
|
399
|
+
for (const d of pass.dangling) {
|
|
400
|
+
const moved = { ...d, from: at(d.from), ...(d.through ? { through: at(d.through) } : {}), ...(d.cluster ? { cluster: at(d.cluster) } : {}) };
|
|
401
|
+
dangling.set(`${danglingKey(moved)}\u0000${moved.rule ?? ""}\u0000${moved.through ?? ""}`, moved);
|
|
402
|
+
named.add(d.rule!);
|
|
403
|
+
}
|
|
404
|
+
if (dangling.size > 0) graph.dangling = [...dangling.values()].sort((a, b) => danglingKey(a).localeCompare(danglingKey(b)) || byString(a.rule ?? "", b.rule ?? "") || byString(a.through ?? "", b.through ?? ""));
|
|
405
|
+
|
|
406
|
+
const ambiguous = new Map<string, ComposedAmbiguous>();
|
|
407
|
+
for (const a of pass.ambiguous) {
|
|
408
|
+
const moved = { ...a, from: at(a.from), candidates: [...new Set(a.candidates.map(at))].sort(byString) };
|
|
409
|
+
ambiguous.set(`${moved.from}\u0000${moved.rule}\u0000${moved.value}`, moved);
|
|
410
|
+
named.add(a.rule);
|
|
411
|
+
}
|
|
412
|
+
const ambiguousKey = (a: ComposedAmbiguous) => `${a.from}\u0000${a.rule}\u0000${a.value}`;
|
|
413
|
+
if (ambiguous.size > 0) graph.ambiguous = [...ambiguous.values()].sort((a, b) => byString(ambiguousKey(a), ambiguousKey(b)));
|
|
414
|
+
|
|
415
|
+
// Containment fills the boundary boxes, on the nodes the document draws.
|
|
416
|
+
const pairs = pass.containment
|
|
417
|
+
.map((p) => ({ ...p, child: at(p.child), parent: at(p.parent) }))
|
|
418
|
+
.filter((p) => p.child !== p.parent);
|
|
419
|
+
const byContainer = containmentGroups(pairs);
|
|
420
|
+
if (Object.keys(byContainer).length > 0) {
|
|
421
|
+
const merged: Record<string, string[]> = { ...(graph.groups.byContainer ?? {}) };
|
|
422
|
+
for (const [k, v] of Object.entries(byContainer)) merged[k] = [...new Set([...(merged[k] ?? []), ...v])].sort(byString);
|
|
423
|
+
graph.groups.byContainer = Object.fromEntries(Object.keys(merged).sort(byString).map((k) => [k, merged[k]]));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const nonLiteral: Record<string, number> = {};
|
|
427
|
+
for (const [id, n] of Object.entries(pass.nonLiteral)) nonLiteral[at(id)] = (nonLiteral[at(id)] ?? 0) + n;
|
|
428
|
+
const summary: CatalogSummary = {
|
|
429
|
+
lexicons: pass.lexicons,
|
|
430
|
+
members: pass.members,
|
|
431
|
+
rules: Object.fromEntries([...named].filter((id) => pass.rules[id]).sort(byString).map((id) => [id, pass.rules[id]])),
|
|
432
|
+
};
|
|
433
|
+
if (Object.keys(nonLiteral).length > 0) summary.nonLiteral = Object.fromEntries(Object.keys(nonLiteral).sort(byString).map((k) => [k, nonLiteral[k]]));
|
|
434
|
+
graph.catalog = summary;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** The generated nodes whose holder the document draws as itself, and each holder's `expansion` (#5102). */
|
|
438
|
+
function addGenerated(graph: WorkspaceGraph, pass: CatalogPass, at: (id: string) => string, level: DetailLevel): void {
|
|
439
|
+
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
440
|
+
for (const [holder, expansion] of Object.entries(pass.expansions)) {
|
|
441
|
+
const node = at(holder) === holder ? byId.get(holder) : undefined;
|
|
442
|
+
if (node) node.expansion = expansion;
|
|
443
|
+
}
|
|
444
|
+
const added: ComposedNode[] = [];
|
|
445
|
+
for (const n of pass.generated) {
|
|
446
|
+
if (at(n.id) !== n.id || byId.has(n.id)) continue;
|
|
447
|
+
const by = n.generatedBy!;
|
|
448
|
+
added.push({ ...n, attrs: nodeAttrsAt(n.attrs, level), generatedBy: { ...by, ...(by.cluster ? { cluster: at(by.cluster) } : {}) } });
|
|
449
|
+
}
|
|
450
|
+
if (added.length === 0) return;
|
|
451
|
+
graph.nodes = [...graph.nodes, ...added].sort((a, b) => a.id.localeCompare(b.id));
|
|
452
|
+
const into = (group: Record<string, string[]>, key: string, id: string) => (group[key] = [...(group[key] ?? []), id].sort());
|
|
453
|
+
for (const n of added) {
|
|
454
|
+
into(graph.groups.byMember, n.member, n.id);
|
|
455
|
+
if (graph.groups.byLexicon) into(graph.groups.byLexicon, n.lexicon, n.id);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** What a member's declared `runsOn` drew (#5101). */
|
|
460
|
+
export interface RunsOnEdges {
|
|
461
|
+
/** One declared edge from each cluster registration of the member to the node `runsOn` names. */
|
|
462
|
+
edges: ComposedEdge[];
|
|
463
|
+
/** The registrations an edge was drawn from, so their unmatched references are not reported. */
|
|
464
|
+
joined: Set<string>;
|
|
465
|
+
/** A `runsOn` that drew nothing, and why. */
|
|
466
|
+
problems: string[];
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* The declared mapping from a cluster's registration to the cluster resource
|
|
471
|
+
* (#5101), for a repo whose names do not match: a member's `runsOn`,
|
|
472
|
+
* `<member>/<address>`, names the node the member runs on, by the member that
|
|
473
|
+
* holds it and its address (the node's id without the member, or an
|
|
474
|
+
* `attrs.address`). Each node of the member that its lexicon's
|
|
475
|
+
* `registersCluster` accepts draws one `declared` edge to it. A target that
|
|
476
|
+
* matches no node or several, a member with nothing that registers a cluster,
|
|
477
|
+
* and a target in the member itself are problems that draw no edge.
|
|
478
|
+
*/
|
|
479
|
+
export function runsOnEdges(nodes: readonly ComposedNode[], runsOn: ReadonlyMap<string, string>, catalogs: readonly NamedCatalog[]): RunsOnEdges {
|
|
480
|
+
const out: RunsOnEdges = { edges: [], joined: new Set(), problems: [] };
|
|
481
|
+
const registers = new Map(catalogs.map((c) => [c.lexicon, c.catalog.registersCluster]));
|
|
482
|
+
for (const [member, target] of [...runsOn].sort((a, b) => byString(a[0], b[0]))) {
|
|
483
|
+
const slash = target.indexOf("/");
|
|
484
|
+
const targetMember = target.slice(0, slash);
|
|
485
|
+
const address = target.slice(slash + 1);
|
|
486
|
+
const matches = nodes.filter((n) => n.member === targetMember && (n.id === `${targetMember}/${address}` || n.id.endsWith(`/${address}`) || n.attrs?.address === address));
|
|
487
|
+
if (matches.length !== 1) {
|
|
488
|
+
out.problems.push(
|
|
489
|
+
matches.length === 0
|
|
490
|
+
? `member ${member} runs on ${target}, which matches no node of ${targetMember}; no edge is drawn`
|
|
491
|
+
: `member ${member} runs on ${target}, which matches ${matches.length} nodes (${matches.map((n) => n.id).join(", ")}); no edge is drawn`,
|
|
492
|
+
);
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
const registrations = nodes.filter((n) => n.member === member && registers.get(n.lexicon)?.(n) === true);
|
|
496
|
+
if (registrations.length === 0) {
|
|
497
|
+
out.problems.push(`member ${member} runs on ${target}, and holds no cluster registration to join to it; no edge is drawn`);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
for (const r of registrations) {
|
|
501
|
+
if (r.id === matches[0].id) continue;
|
|
502
|
+
out.joined.add(r.id);
|
|
503
|
+
out.edges.push({ from: r.id, to: matches[0].id, kind: "ref", viaAttr: "runsOn", origin: "declared", member });
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return out;
|
|
507
|
+
}
|
|
@@ -454,8 +454,8 @@ describe("the triggers of a phase that sets build (#4169)", () => {
|
|
|
454
454
|
});
|
|
455
455
|
|
|
456
456
|
test("writeTopLevel replaces a block up to the next top-level line, or adds one before jobs", () => {
|
|
457
|
-
expect(writeTopLevel("a: 1\nconcurrency:\n group: x\n\njobs: {}\n", "concurrency", { group: "
|
|
458
|
-
expect(writeTopLevel("a: 1\njobs: {}\n", "concurrency", { group: "
|
|
457
|
+
expect(writeTopLevel("a: 1\nconcurrency:\n group: x\n\njobs: {}\n", "concurrency", { group: "z" })).toBe(`a: 1\n${BUILD_BLOCK_MARKER}\nconcurrency:\n group: z\n\njobs: {}\n`);
|
|
458
|
+
expect(writeTopLevel("a: 1\njobs: {}\n", "concurrency", { group: "z" })).toBe(`a: 1\n${BUILD_BLOCK_MARKER}\nconcurrency:\n group: z\n\njobs: {}\n`);
|
|
459
459
|
});
|
|
460
460
|
|
|
461
461
|
test("the tick may re-run jobs and start workflows, and ticks on a build tag's runs, only when a phase sets build", () => {
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cluster join end to end (#5101): `chant workspace graph --discover`
|
|
3
|
+
* over a directory with Argo CD manifests and Terraform, read through the
|
|
4
|
+
* terraform and k8s lexicons installed in this checkout. Each fixture is a
|
|
5
|
+
* plain directory in a scratch location, so nothing writes into this
|
|
6
|
+
* repository's git directory.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { readFileSync, symlinkSync } from "node:fs";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { afterAll, beforeAll, describe, expect, test } from "vitest";
|
|
12
|
+
import { cleanScratch, contract, REPO, scratchDir, writeFiles } from "./__fixtures__/contract-repo";
|
|
13
|
+
import { CACHE_DIR_ENV } from "./graph-cache";
|
|
14
|
+
import { workspaceGraph, type GraphDocument } from "./graph-cli";
|
|
15
|
+
import schema from "./graph.schema.json";
|
|
16
|
+
|
|
17
|
+
const TIMEOUT = 240_000;
|
|
18
|
+
const { expectValid } = contract(schema);
|
|
19
|
+
|
|
20
|
+
let cacheBefore: string | undefined;
|
|
21
|
+
beforeAll(() => {
|
|
22
|
+
cacheBefore = process.env[CACHE_DIR_ENV];
|
|
23
|
+
process.env[CACHE_DIR_ENV] = scratchDir("chant-cluster-join-cache-");
|
|
24
|
+
});
|
|
25
|
+
afterAll(() => {
|
|
26
|
+
if (cacheBefore === undefined) delete process.env[CACHE_DIR_ENV];
|
|
27
|
+
else process.env[CACHE_DIR_ENV] = cacheBefore;
|
|
28
|
+
cleanScratch();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const CLUSTERS = `apiVersion: v1
|
|
32
|
+
kind: Secret
|
|
33
|
+
metadata:
|
|
34
|
+
name: cluster-prod
|
|
35
|
+
namespace: argocd
|
|
36
|
+
labels:
|
|
37
|
+
argocd.argoproj.io/secret-type: cluster
|
|
38
|
+
stringData:
|
|
39
|
+
name: prod
|
|
40
|
+
server: https://10.0.0.1
|
|
41
|
+
`;
|
|
42
|
+
const APP = `apiVersion: argoproj.io/v1alpha1
|
|
43
|
+
kind: Application
|
|
44
|
+
metadata:
|
|
45
|
+
name: web
|
|
46
|
+
namespace: argocd
|
|
47
|
+
spec:
|
|
48
|
+
project: default
|
|
49
|
+
source:
|
|
50
|
+
repoURL: https://example.com/repo.git
|
|
51
|
+
path: web
|
|
52
|
+
destination:
|
|
53
|
+
name: prod
|
|
54
|
+
namespace: web
|
|
55
|
+
`;
|
|
56
|
+
const cluster = (name: string) => `resource "google_container_cluster" "main" {\n name = "${name}"\n location = "us-central1"\n}\n`;
|
|
57
|
+
|
|
58
|
+
const SECRET = "argo/argo/secretClusterProd";
|
|
59
|
+
const APPLICATION = "argo/argo/applicationWeb";
|
|
60
|
+
const REGISTERS = "k8s:K8s::Core::Secret:argoCluster.name";
|
|
61
|
+
const DESTINATION = "k8s:K8s::Argo::Application:spec.destination.name";
|
|
62
|
+
|
|
63
|
+
function result(doc: GraphDocument): Extract<GraphDocument, { nodes: unknown }> {
|
|
64
|
+
if ("error" in doc) throw new Error(`${doc.error.code}: ${doc.error.message}`);
|
|
65
|
+
return doc;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function read(files: Record<string, string>, runsOn?: Record<string, string>) {
|
|
69
|
+
const root = scratchDir("chant-cluster-join-fx-");
|
|
70
|
+
writeFiles(root, files);
|
|
71
|
+
const g = result((await workspaceGraph({ cwd: root, discover: true, noCache: false, catalog: true, ...(runsOn ? { runsOn } : {}) })).doc);
|
|
72
|
+
expectValid(g);
|
|
73
|
+
const registers = (x: { rule?: string }) => x.rule === REGISTERS;
|
|
74
|
+
return {
|
|
75
|
+
edges: g.edges.map((e) => `${e.from} > ${e.to} ${e.origin}${e.rule ? ` ${e.rule}` : ""}`),
|
|
76
|
+
registerDangling: (g.dangling ?? []).filter(registers).map((d) => d.value),
|
|
77
|
+
registerAmbiguous: (g.ambiguous ?? []).filter(registers),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
describe("the cluster join (#5101)", () => {
|
|
82
|
+
test(
|
|
83
|
+
"an Application joins its Secret, and the Secret joins a cluster of its name",
|
|
84
|
+
async () => {
|
|
85
|
+
const { edges, registerDangling } = await read({ "argo/clusters.yaml": CLUSTERS, "argo/app.yaml": APP, "tf/main.tf": cluster("prod") });
|
|
86
|
+
expect(edges).toEqual([`${APPLICATION} > ${SECRET} derived ${DESTINATION}`, `${SECRET} > tf/tf/google_container_cluster.main derived ${REGISTERS}`]);
|
|
87
|
+
expect(registerDangling).toEqual([]);
|
|
88
|
+
},
|
|
89
|
+
TIMEOUT,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
test(
|
|
93
|
+
"a renamed cluster draws no edge, and the Secret's name is dangling",
|
|
94
|
+
async () => {
|
|
95
|
+
const { edges, registerDangling } = await read({ "argo/clusters.yaml": CLUSTERS, "argo/app.yaml": APP, "tf/main.tf": cluster("prod-gke") });
|
|
96
|
+
expect(edges).toEqual([`${APPLICATION} > ${SECRET} derived ${DESTINATION}`]);
|
|
97
|
+
expect(registerDangling).toEqual(["prod"]);
|
|
98
|
+
},
|
|
99
|
+
TIMEOUT,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
test(
|
|
103
|
+
"--runs-on draws a declared edge from the Secret to the cluster, and the Secret is no longer dangling",
|
|
104
|
+
async () => {
|
|
105
|
+
const { edges, registerDangling } = await read({ "argo/clusters.yaml": CLUSTERS, "argo/app.yaml": APP, "tf/main.tf": cluster("prod-gke") }, { argo: "tf/google_container_cluster.main" });
|
|
106
|
+
expect(edges).toEqual([`${APPLICATION} > ${SECRET} derived ${DESTINATION}`, `${SECRET} > tf/tf/google_container_cluster.main declared`]);
|
|
107
|
+
expect(registerDangling).toEqual([]);
|
|
108
|
+
},
|
|
109
|
+
TIMEOUT,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
test(
|
|
113
|
+
"two clusters of one name in two roots draw no edge, and are recorded as ambiguous",
|
|
114
|
+
async () => {
|
|
115
|
+
const { edges, registerAmbiguous, registerDangling } = await read({ "argo/clusters.yaml": CLUSTERS, "argo/app.yaml": APP, "a/main.tf": cluster("prod"), "b/main.tf": cluster("prod") });
|
|
116
|
+
expect(edges).toEqual([`${APPLICATION} > ${SECRET} derived ${DESTINATION}`]);
|
|
117
|
+
expect(registerAmbiguous).toEqual([expect.objectContaining({ from: SECRET, value: "prod", candidates: ["a/a/google_container_cluster.main", "b/b/google_container_cluster.main"] })]);
|
|
118
|
+
expect(registerDangling).toEqual([]);
|
|
119
|
+
},
|
|
120
|
+
TIMEOUT,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
test(
|
|
124
|
+
"a declaration's runsOn does the same, and the document carries no credential",
|
|
125
|
+
async () => {
|
|
126
|
+
const root = scratchDir("chant-cluster-join-decl-");
|
|
127
|
+
// A declared member kind comes from a pinned package; the checkout's own lexicons and chant serve here.
|
|
128
|
+
const pin = (lexicon: string) => ({ package: `@intentius/chant-lexicon-${lexicon}`, version: JSON.parse(readFileSync(join(REPO, "lexicons", lexicon, "package.json"), "utf-8")).version as string });
|
|
129
|
+
writeFiles(root, {
|
|
130
|
+
"chant.workspace.json": JSON.stringify({
|
|
131
|
+
name: "fx",
|
|
132
|
+
schema: 1,
|
|
133
|
+
pins: [pin("k8s"), pin("terraform")],
|
|
134
|
+
members: [
|
|
135
|
+
{ name: "argo", dir: "argo", kind: "argo-app", runsOn: "tf/google_container_cluster.main" },
|
|
136
|
+
{ name: "tf", dir: "tf", kind: "terraform" },
|
|
137
|
+
],
|
|
138
|
+
}),
|
|
139
|
+
"argo/clusters.yaml": `${CLUSTERS} config: '{"bearerToken": "not-a-real-token"}'\n`,
|
|
140
|
+
"argo/app.yaml": APP,
|
|
141
|
+
"tf/main.tf": cluster("prod-gke"),
|
|
142
|
+
});
|
|
143
|
+
symlinkSync(join(REPO, "node_modules"), join(root, "node_modules"));
|
|
144
|
+
const g = result((await workspaceGraph({ cwd: root, noCache: false, catalog: true, args: { detail: 3 } as never })).doc);
|
|
145
|
+
expect(g.edges.filter((e) => e.origin === "declared").map((e) => `${e.from} > ${e.to}`)).toEqual([`${SECRET} > tf/tf/google_container_cluster.main`]);
|
|
146
|
+
expect(JSON.stringify(g)).not.toContain("not-a-real-token");
|
|
147
|
+
},
|
|
148
|
+
TIMEOUT,
|
|
149
|
+
);
|
|
150
|
+
});
|