@intentius/chant 0.44.14 → 0.45.0
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/discover.d.ts +26 -2
- package/dist/audit/discover.d.ts.map +1 -1
- package/dist/audit/report-model.d.ts +10 -0
- package/dist/audit/report-model.d.ts.map +1 -1
- package/dist/audit/rules-doc.d.ts.map +1 -1
- package/dist/cli/build-params-cli.d.ts +16 -7
- package/dist/cli/build-params-cli.d.ts.map +1 -1
- package/dist/cli/commands/audit.d.ts +20 -0
- package/dist/cli/commands/audit.d.ts.map +1 -1
- package/dist/cli/commands/build.d.ts +9 -0
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/check-lexicon-docs.d.ts +13 -0
- package/dist/cli/commands/check-lexicon-docs.d.ts.map +1 -1
- package/dist/cli/commands/check-lexicon-examples.d.ts +24 -14
- package/dist/cli/commands/check-lexicon-examples.d.ts.map +1 -1
- package/dist/cli/commands/check-lexicon.d.ts.map +1 -1
- package/dist/cli/commands/init-lexicon/templates/codegen.d.ts.map +1 -1
- package/dist/cli/commands/init-lexicon/templates/docs.d.ts +5 -0
- package/dist/cli/commands/init-lexicon/templates/docs.d.ts.map +1 -1
- package/dist/cli/commands/init-lexicon.d.ts.map +1 -1
- package/dist/cli/commands/onboard.d.ts +28 -0
- package/dist/cli/commands/onboard.d.ts.map +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/graph.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/search.d.ts +27 -0
- package/dist/cli/handlers/search.d.ts.map +1 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/codegen/docs-pages.d.ts +39 -0
- package/dist/codegen/docs-pages.d.ts.map +1 -0
- package/dist/codegen/docs-sections.d.ts.map +1 -1
- package/dist/codegen/docs-sidebar.d.ts +13 -2
- package/dist/codegen/docs-sidebar.d.ts.map +1 -1
- package/dist/codegen/docs-types.d.ts +30 -10
- package/dist/codegen/docs-types.d.ts.map +1 -1
- package/dist/codegen/docs.d.ts +14 -2
- package/dist/codegen/docs.d.ts.map +1 -1
- package/dist/codegen/surface-snapshot.d.ts +27 -3
- package/dist/codegen/surface-snapshot.d.ts.map +1 -1
- package/dist/codegen/validate.d.ts +11 -3
- package/dist/codegen/validate.d.ts.map +1 -1
- package/dist/components/capability-plugin.d.ts +13 -2
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/components/driver.d.ts +38 -0
- package/dist/components/driver.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/starter-plugin.d.ts.map +1 -1
- package/dist/config.d.ts +57 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/discovery/fold-import.d.ts.map +1 -1
- package/dist/fold/fold.d.ts +100 -1
- package/dist/fold/fold.d.ts.map +1 -1
- package/dist/graph-ir.d.ts +12 -0
- package/dist/graph-ir.d.ts.map +1 -1
- package/dist/graph-ops.d.ts +17 -0
- package/dist/graph-ops.d.ts.map +1 -0
- package/dist/lifecycle/change-set.d.ts +23 -2
- package/dist/lifecycle/change-set.d.ts.map +1 -1
- package/dist/lifecycle/deep-observe.d.ts.map +1 -1
- package/dist/lifecycle/observe.d.ts +8 -0
- package/dist/lifecycle/observe.d.ts.map +1 -1
- package/dist/lifecycle/replay.d.ts.map +1 -1
- package/dist/lifecycle/snapshot.d.ts.map +1 -1
- package/dist/lifecycle/types.d.ts +7 -0
- package/dist/lifecycle/types.d.ts.map +1 -1
- package/dist/lint/policy.d.ts.map +1 -1
- package/dist/managed-fields.d.ts +33 -21
- package/dist/managed-fields.d.ts.map +1 -1
- package/dist/observation.d.ts +23 -1
- package/dist/observation.d.ts.map +1 -1
- package/dist/yaml.d.ts +0 -8
- package/dist/yaml.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__snapshots__/okf.test.ts.snap +20 -0
- package/src/audit/discover.test.ts +55 -1
- package/src/audit/discover.ts +70 -2
- package/src/audit/edge-init-safety.test.ts +149 -18
- package/src/audit/report-model.ts +12 -1
- package/src/audit/rules-doc.ts +1 -0
- package/src/build-params.test.ts +52 -0
- package/src/cli/build-params-cli.test.ts +25 -8
- package/src/cli/build-params-cli.ts +37 -23
- package/src/cli/commands/__fixtures__/audit-coverage/.github/workflows/ci.yml +5 -0
- package/src/cli/commands/__fixtures__/audit-coverage/Dockerfile +2 -0
- package/src/cli/commands/__fixtures__/audit-coverage/infra/main.tf +3 -0
- package/src/cli/commands/__fixtures__/audit-coverage/infra/stack.json +6 -0
- package/src/cli/commands/__fixtures__/audit-coverage/k8s/deploy.yaml +12 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/pages/getting-started.mdx +16 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/src/content.config.ts +10 -2
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/generate-cli.ts +3 -1
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/generate.ts +2 -1
- package/src/cli/commands/__snapshots__/init-lexicon.test.ts.snap +2 -1
- package/src/cli/commands/audit.test.ts +83 -1
- package/src/cli/commands/audit.ts +121 -28
- package/src/cli/commands/build.test.ts +144 -5
- package/src/cli/commands/build.ts +66 -14
- package/src/cli/commands/check-lexicon-docs.ts +30 -0
- package/src/cli/commands/check-lexicon-examples.test.ts +73 -7
- package/src/cli/commands/check-lexicon-examples.ts +66 -17
- package/src/cli/commands/check-lexicon.test.ts +1 -1
- package/src/cli/commands/check-lexicon.ts +19 -4
- package/src/cli/commands/init-lexicon/templates/codegen.ts +5 -2
- package/src/cli/commands/init-lexicon/templates/docs.ts +35 -2
- package/src/cli/commands/init-lexicon.test.ts +42 -1
- package/src/cli/commands/init-lexicon.ts +3 -1
- package/src/cli/commands/lexicon-rolling-upgrade.ts +1 -1
- package/src/cli/commands/lexicon-surface-diff.test.ts +1 -1
- package/src/cli/commands/lexicon-surface-diff.ts +1 -1
- package/src/cli/commands/onboard.test.ts +319 -225
- package/src/cli/commands/onboard.ts +144 -58
- package/src/cli/handlers/build.test.ts +3 -3
- package/src/cli/handlers/build.ts +2 -0
- package/src/cli/handlers/components.ts +2 -2
- package/src/cli/handlers/graph.test.ts +44 -0
- package/src/cli/handlers/graph.ts +22 -2
- package/src/cli/handlers/lifecycle.test.ts +117 -0
- package/src/cli/handlers/lifecycle.ts +16 -0
- package/src/cli/handlers/run.test.ts +5 -5
- package/src/cli/handlers/run.ts +1 -0
- package/src/cli/handlers/search-live.test.ts +217 -0
- package/src/cli/handlers/search.test.ts +41 -1
- package/src/cli/handlers/search.ts +55 -6
- package/src/cli/main.ts +5 -3
- package/src/cli/security-boundary.test.ts +2 -1
- package/src/codegen/docs-pages.test.ts +194 -0
- package/src/codegen/docs-pages.ts +138 -0
- package/src/codegen/docs-sections.ts +0 -8
- package/src/codegen/docs-sidebar.ts +50 -37
- package/src/codegen/docs-types.ts +32 -4
- package/src/codegen/docs.ts +78 -40
- package/src/codegen/lexicon-regen.ts +3 -1
- package/src/codegen/rolling-upgrade.test.ts +1 -1
- package/src/codegen/rolling-upgrade.ts +1 -1
- package/src/codegen/surface-snapshot.test.ts +139 -0
- package/src/codegen/surface-snapshot.ts +297 -122
- package/src/codegen/validate.test.ts +16 -3
- package/src/codegen/validate.ts +17 -7
- package/src/components/auto-release.ts +1 -1
- package/src/components/capability-plugin.ts +23 -2
- package/src/components/driver.test.ts +45 -0
- package/src/components/driver.ts +64 -27
- package/src/components/index.ts +2 -0
- package/src/components/starter-plugin.ts +5 -2
- package/src/config.ts +101 -7
- package/src/discovery/fold-import.test.ts +427 -2
- package/src/discovery/fold-import.ts +163 -7
- package/src/discovery/sandbox/driver.test.ts +11 -0
- package/src/fold/fold.test.ts +41 -0
- package/src/fold/fold.ts +372 -2
- package/src/graph-ir-live.test.ts +42 -0
- package/src/graph-ir.ts +42 -2
- package/src/graph-ops.test.ts +69 -0
- package/src/graph-ops.ts +42 -0
- package/src/lifecycle/change-set.test.ts +41 -0
- package/src/lifecycle/change-set.ts +30 -2
- package/src/lifecycle/deep-observe.ts +4 -0
- package/src/lifecycle/observe.ts +29 -2
- package/src/lifecycle/replay.ts +3 -0
- package/src/lifecycle/snapshot.ts +3 -0
- package/src/lifecycle/types.ts +7 -0
- package/src/lint/policy.ts +14 -3
- package/src/managed-fields.test.ts +15 -42
- package/src/managed-fields.ts +43 -26
- package/src/observation.test.ts +24 -8
- package/src/observation.ts +48 -4
- package/src/ownership.test.ts +63 -1
- package/src/yaml.test.ts +15 -0
- package/src/yaml.ts +19 -2
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
DriverGateUnsupportedError,
|
|
19
19
|
DriverRunFailure,
|
|
20
20
|
UnknownDependencyError,
|
|
21
|
+
accumulateComponentOutputs,
|
|
22
|
+
collectComponentOutputs,
|
|
21
23
|
resolveComponentGraph,
|
|
22
24
|
resolveWiring,
|
|
23
25
|
runComponentDeploy,
|
|
@@ -411,6 +413,49 @@ describe("runComponentDeploy — output wiring", () => {
|
|
|
411
413
|
});
|
|
412
414
|
});
|
|
413
415
|
|
|
416
|
+
describe("collectComponentOutputs / accumulateComponentOutputs — the shared accumulator (#700)", () => {
|
|
417
|
+
// Exported so the durable path's `accumulateComponentOutputs` activity
|
|
418
|
+
// (lexicons/temporal/src/component-op/activities.ts) captures outputs via
|
|
419
|
+
// the same function `runComponentDeploy` does — the accumulation twin of
|
|
420
|
+
// the already-shared `resolveStepInput`.
|
|
421
|
+
const phaseOutputs = {
|
|
422
|
+
Apply: { stackStatus: "CREATE_COMPLETE", outputs: { ClusterArn: "arn:cluster", ApiRepoUri: "repo" } },
|
|
423
|
+
Publish: { uri: "repo@sha256:abc", digest: "sha256:abc" },
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
it("namespaces publish outputs under `publish` and merges stack outputs at the top level", () => {
|
|
427
|
+
expect(collectComponentOutputs(phaseOutputs)).toEqual({
|
|
428
|
+
ClusterArn: "arn:cluster",
|
|
429
|
+
ApiRepoUri: "repo",
|
|
430
|
+
publish: { uri: "repo@sha256:abc", digest: "sha256:abc" },
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it("returns undefined when no phase output looks like a publish or stack result", () => {
|
|
435
|
+
expect(collectComponentOutputs({ Verify: { ok: true } })).toBeUndefined();
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("records under the component name, merging over a seeded entry, and returns the map", () => {
|
|
439
|
+
const seeded = { "shared-alb": { Seeded: "keep" }, other: { x: 1 } };
|
|
440
|
+
const out = accumulateComponentOutputs(seeded, "shared-alb", phaseOutputs);
|
|
441
|
+
expect(out).toBe(seeded);
|
|
442
|
+
expect(out["shared-alb"]).toEqual({
|
|
443
|
+
Seeded: "keep",
|
|
444
|
+
ClusterArn: "arn:cluster",
|
|
445
|
+
ApiRepoUri: "repo",
|
|
446
|
+
publish: { uri: "repo@sha256:abc", digest: "sha256:abc" },
|
|
447
|
+
});
|
|
448
|
+
expect(out.other).toEqual({ x: 1 });
|
|
449
|
+
// Plain data throughout — survives the Temporal activity JSON boundary unchanged.
|
|
450
|
+
expect(JSON.parse(JSON.stringify(out))).toEqual(out);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it("is a no-op when the component exposed nothing", () => {
|
|
454
|
+
const map = { other: { x: 1 } };
|
|
455
|
+
expect(accumulateComponentOutputs(map, "svc", { Verify: { ok: true } })).toEqual({ other: { x: 1 } });
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
|
|
414
459
|
describe("runInterpretDriver — end to end", () => {
|
|
415
460
|
it("runs a producer before its consumer and threads env/vars into every capability call", async () => {
|
|
416
461
|
const registry = new CapabilityRegistry();
|
package/src/components/driver.ts
CHANGED
|
@@ -603,37 +603,77 @@ export async function runComponentDeploy(
|
|
|
603
603
|
return { component: component.name, ok: false, records };
|
|
604
604
|
}
|
|
605
605
|
|
|
606
|
-
// Publish-family outputs
|
|
607
|
-
//
|
|
608
|
-
//
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}
|
|
606
|
+
// Publish-family and stack outputs become this component's entry in
|
|
607
|
+
// `componentOutputs` — through the same exported accumulator the durable
|
|
608
|
+
// path's `accumulateComponentOutputs` activity calls (#700), so local and
|
|
609
|
+
// Temporal runs can never diverge on what downstream references see.
|
|
610
|
+
accumulateComponentOutputs(componentOutputs, component.name, phaseOutputs);
|
|
611
|
+
|
|
612
|
+
return { component: component.name, ok: true, records };
|
|
613
|
+
}
|
|
613
614
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
615
|
+
/**
|
|
616
|
+
* Collect the cross-component outputs one finished component exposes to its
|
|
617
|
+
* downstream consumers, from every phase output it produced:
|
|
618
|
+
*
|
|
619
|
+
* - publish-family outputs (publish-image / publish-artifact /
|
|
620
|
+
* load-image-on-host all return at least one of uri/digest/key — see
|
|
621
|
+
* ./verbs/publish.ts) are namespaced under `publish`, so downstream
|
|
622
|
+
* `@<name>.publish.*` references resolve;
|
|
623
|
+
* - stack outputs from an apply step (cfn-deploy returns
|
|
624
|
+
* `CfnDeployOutput.outputs`) are merged at the top level, peer to
|
|
625
|
+
* `publish`, so `resolveWiring`'s stackOutput branch —
|
|
626
|
+
* `resolvePath(componentOutputs[stack], name)` — finds each output by
|
|
627
|
+
* name (the cross-stack apply-order integration deferred in #556, closed
|
|
628
|
+
* in #699). The entry is keyed by the component's own name, which by
|
|
629
|
+
* convention is the stack name a `stackOutput` reference targets (see the
|
|
630
|
+
* pilots and composition-and-wiring.mdx).
|
|
631
|
+
*
|
|
632
|
+
* Both halves are generic by output *shape*, not by capability `kind`, keeping
|
|
633
|
+
* the driver free of per-capability branching. Returns `undefined` when the
|
|
634
|
+
* component exposed nothing.
|
|
635
|
+
*
|
|
636
|
+
* Exported, like `resolveStepInput`, so the durable Temporal path
|
|
637
|
+
* (lexicons/temporal/src/component-op/activities.ts) accumulates outputs via
|
|
638
|
+
* this exact function rather than re-deriving it (#700). The resolver and the
|
|
639
|
+
* accumulator are the two halves of one contract; sharing only the resolver
|
|
640
|
+
* is how the cross-stack gap #699 closed locally could reopen durably.
|
|
641
|
+
*/
|
|
642
|
+
export function collectComponentOutputs(
|
|
643
|
+
phaseOutputs: Record<string, Record<string, unknown>>,
|
|
644
|
+
): Record<string, unknown> | undefined {
|
|
645
|
+
const publishOutput = findPublishOutput(phaseOutputs);
|
|
622
646
|
const stackOutputs = findStackOutputs(phaseOutputs);
|
|
623
|
-
if (stackOutputs)
|
|
624
|
-
|
|
625
|
-
|
|
647
|
+
if (!publishOutput && !stackOutputs) return undefined;
|
|
648
|
+
return { ...(stackOutputs ?? {}), ...(publishOutput ? { publish: publishOutput } : {}) };
|
|
649
|
+
}
|
|
626
650
|
|
|
627
|
-
|
|
651
|
+
/**
|
|
652
|
+
* Record a finished component's outputs (`collectComponentOutputs`) into the
|
|
653
|
+
* shared `componentOutputs` map under the component's own name, merging over
|
|
654
|
+
* any seeded entry (`--seed-outputs`, or a durable parent workflow's
|
|
655
|
+
* thread-through). Mutates and returns `componentOutputs`, so a Temporal
|
|
656
|
+
* activity can hand the updated map back to its workflow over the JSON
|
|
657
|
+
* boundary — every value in it is plain activity-result data, so the map is
|
|
658
|
+
* serializable by construction. A no-op when the component exposed nothing.
|
|
659
|
+
*/
|
|
660
|
+
export function accumulateComponentOutputs(
|
|
661
|
+
componentOutputs: Record<string, Record<string, unknown>>,
|
|
662
|
+
componentName: string,
|
|
663
|
+
phaseOutputs: Record<string, Record<string, unknown>>,
|
|
664
|
+
): Record<string, Record<string, unknown>> {
|
|
665
|
+
const collected = collectComponentOutputs(phaseOutputs);
|
|
666
|
+
if (collected) {
|
|
667
|
+
componentOutputs[componentName] = { ...componentOutputs[componentName], ...collected };
|
|
668
|
+
}
|
|
669
|
+
return componentOutputs;
|
|
628
670
|
}
|
|
629
671
|
|
|
630
672
|
/**
|
|
631
673
|
* Find the output of the last step that looks like a publish result (carries
|
|
632
|
-
* `uri`, `digest`, or `key`) across every phase this component ran, so
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
* carries one of these fields is eligible, keeping the driver free of
|
|
636
|
-
* per-capability branching.
|
|
674
|
+
* `uri`, `digest`, or `key`) across every phase this component ran, so
|
|
675
|
+
* `collectComponentOutputs` can populate `@<component>.publish.*` for a
|
|
676
|
+
* downstream consumer.
|
|
637
677
|
*/
|
|
638
678
|
function findPublishOutput(
|
|
639
679
|
phaseOutputs: Record<string, Record<string, unknown>>,
|
|
@@ -651,9 +691,6 @@ function findPublishOutput(
|
|
|
651
691
|
* Find the stack `outputs` map produced by an apply-style step (cfn-deploy
|
|
652
692
|
* returns `CfnDeployOutput.outputs`) across every phase this component ran, so
|
|
653
693
|
* a deployed stack's outputs can seed downstream `stackOutput()` resolution.
|
|
654
|
-
* Generic by shape — any output carrying an `outputs` record is eligible —
|
|
655
|
-
* keeping the driver free of per-capability branching, the same way
|
|
656
|
-
* `findPublishOutput` is.
|
|
657
694
|
*/
|
|
658
695
|
function findStackOutputs(
|
|
659
696
|
phaseOutputs: Record<string, Record<string, unknown>>,
|
package/src/components/index.ts
CHANGED
|
@@ -100,8 +100,11 @@ function starterCapabilities(): Array<Capability<never, unknown>> {
|
|
|
100
100
|
export const starterCapabilityPlugin: CapabilityPlugin = {
|
|
101
101
|
name: "starter",
|
|
102
102
|
// The core package's own version (#1505) — lockstep releases bump it, so a
|
|
103
|
-
// literal here would go stale every `just release`.
|
|
104
|
-
|
|
103
|
+
// literal here would go stale every `just release`. A getter, so the
|
|
104
|
+
// package.json read happens on first access rather than at import time.
|
|
105
|
+
get version(): string {
|
|
106
|
+
return ownPackageVersion(import.meta.url);
|
|
107
|
+
},
|
|
105
108
|
capabilities: starterCapabilities,
|
|
106
109
|
families: () => STARTER_VERB_FAMILIES,
|
|
107
110
|
};
|
package/src/config.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { DEFAULT_SBOM_FORMAT, type SbomFormat } from "./components/verbs/sbom-ge
|
|
|
7
7
|
import type { Severity } from "./components/verbs/vuln-scan";
|
|
8
8
|
import type { VulnPolicy } from "./components/verbs/vuln-gate";
|
|
9
9
|
import type { BuildParamsConfig } from "./build-params";
|
|
10
|
+
import type { BuildParamProvenance } from "./provenance";
|
|
10
11
|
import { findProjectConfig } from "./project-root";
|
|
11
12
|
import { evaluateProjectConfig } from "./config-sandbox";
|
|
12
13
|
|
|
@@ -22,6 +23,12 @@ import { evaluateProjectConfig } from "./config-sandbox";
|
|
|
22
23
|
*/
|
|
23
24
|
export type EnvironmentDeclaration = string | { name: string; endpoint?: string };
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* `ownership.env`: a literal environment identity, or a reference to a
|
|
28
|
+
* declared build parameter whose resolved value becomes the identity (#1396).
|
|
29
|
+
*/
|
|
30
|
+
export type OwnershipEnv = string | { param: string };
|
|
31
|
+
|
|
25
32
|
/** The declared name of one `environments` entry, whichever form it takes. */
|
|
26
33
|
export function environmentName(entry: EnvironmentDeclaration): string {
|
|
27
34
|
return typeof entry === "string" ? entry : entry.name;
|
|
@@ -69,7 +76,7 @@ export const ChantConfigSchema = z.object({
|
|
|
69
76
|
lint: z.record(z.string(), z.unknown()).optional(),
|
|
70
77
|
ownership: z.object({
|
|
71
78
|
stack: z.string().min(1).optional(),
|
|
72
|
-
env: z.string().min(1).optional(),
|
|
79
|
+
env: z.union([z.string().min(1), z.object({ param: z.string().min(1) })]).optional(),
|
|
73
80
|
enabled: z.boolean().optional(),
|
|
74
81
|
}).optional(),
|
|
75
82
|
build: z.object({
|
|
@@ -193,8 +200,17 @@ export interface ChantConfig {
|
|
|
193
200
|
ownership?: {
|
|
194
201
|
/** Stack identity stamped onto resources (required to enable stamping). */
|
|
195
202
|
stack?: string;
|
|
196
|
-
/**
|
|
197
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Optional environment identity. Either a literal, or a reference to one
|
|
205
|
+
* of this project's declared `buildParams` (`{ param: "env" }`), in which
|
|
206
|
+
* case the marker takes whatever value that parameter resolves to for the
|
|
207
|
+
* build — the same value `params.env` reads in source (#1396). A
|
|
208
|
+
* reference is the only way to make the marker follow `--param env=prod`:
|
|
209
|
+
* the config is evaluated before build parameters exist, so a literal
|
|
210
|
+
* computed from `process.env` here and a parameter mapped to the same
|
|
211
|
+
* variable are two sources of truth that nothing keeps in step.
|
|
212
|
+
*/
|
|
213
|
+
env?: OwnershipEnv;
|
|
198
214
|
/** Set false to disable stamping even when `stack` is present. */
|
|
199
215
|
enabled?: boolean;
|
|
200
216
|
};
|
|
@@ -490,14 +506,92 @@ function warnIfFragmentShadowsProjectConfig(configPath: string): void {
|
|
|
490
506
|
/** Top-level keys that make a config a *project* config rather than a lint fragment. */
|
|
491
507
|
const PROJECT_CONFIG_KEYS = new Set(Object.keys(ChantConfigSchema.shape).filter((k) => k !== "lint"));
|
|
492
508
|
|
|
509
|
+
/** Whether an `ownership.env` entry is a build-parameter reference rather than a literal. */
|
|
510
|
+
export function isOwnershipParamRef(env: OwnershipEnv | undefined): env is { param: string } {
|
|
511
|
+
return typeof env === "object" && env !== null && typeof env.param === "string";
|
|
512
|
+
}
|
|
513
|
+
|
|
493
514
|
/**
|
|
494
|
-
*
|
|
495
|
-
*
|
|
515
|
+
* The ownership stack identity alone — `ownership.stack` when marking is on
|
|
516
|
+
* (no `stack`, or `enabled: false`, means off). For callers that need the
|
|
517
|
+
* stack and nothing else (a field manager, a prune selector) and so have no
|
|
518
|
+
* build parameters to resolve `env` against.
|
|
496
519
|
*/
|
|
497
|
-
export function
|
|
520
|
+
export function resolveOwnershipStack(config: ChantConfig): string | undefined {
|
|
498
521
|
const o = config.ownership;
|
|
499
522
|
if (!o || !o.stack || o.enabled === false) return undefined;
|
|
500
|
-
return
|
|
523
|
+
return o.stack;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Resolve the `env` half of the ownership marker (#1396). A literal is
|
|
528
|
+
* returned as-is. A `{ param }` reference is looked up in this build's resolved
|
|
529
|
+
* build parameters and must find one: a reference to a parameter that was
|
|
530
|
+
* never declared, or that resolved to no value, throws rather than quietly
|
|
531
|
+
* stamping a marker without an env — an env-less marker is exactly what lets
|
|
532
|
+
* a prod deployment go unseen by `--owned` filtering scoped to prod.
|
|
533
|
+
*/
|
|
534
|
+
export function resolveOwnershipEnv(
|
|
535
|
+
config: ChantConfig,
|
|
536
|
+
buildParams: readonly BuildParamProvenance[] | undefined,
|
|
537
|
+
): string | undefined {
|
|
538
|
+
const env = config.ownership?.env;
|
|
539
|
+
if (!isOwnershipParamRef(env)) return env;
|
|
540
|
+
const name = env.param;
|
|
541
|
+
const declared = config.buildParams?.[name];
|
|
542
|
+
if (!declared) {
|
|
543
|
+
throw new Error(
|
|
544
|
+
`ownership.env references build parameter "${name}", which chant.config.ts's buildParams does not declare`,
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
const resolved = buildParams?.find((p) => p.name === name);
|
|
548
|
+
if (!resolved) {
|
|
549
|
+
throw new Error(
|
|
550
|
+
`ownership.env references build parameter "${name}", which resolved to no value for this build — pass --param ${name}=<value>${declared.env ? `, set ${declared.env}` : ""}, or give it a default`,
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
return String(resolved.value);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Resolve the ownership marker to stamp from project config, or undefined when
|
|
558
|
+
* ownership marking is off (no `stack`, or `enabled: false`). `buildParams` is
|
|
559
|
+
* this build's resolved parameters (`resolveBuildParams`'s provenance), which
|
|
560
|
+
* an `ownership.env: { param }` reference resolves against — see {@link
|
|
561
|
+
* resolveOwnershipEnv}; it throws when the reference cannot be satisfied.
|
|
562
|
+
*/
|
|
563
|
+
export function resolveOwnershipMarker(
|
|
564
|
+
config: ChantConfig,
|
|
565
|
+
buildParams?: readonly BuildParamProvenance[],
|
|
566
|
+
): OwnershipMarker | undefined {
|
|
567
|
+
const stack = resolveOwnershipStack(config);
|
|
568
|
+
if (stack === undefined) return undefined;
|
|
569
|
+
return { stack, env: resolveOwnershipEnv(config, buildParams) };
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* The divergence #1396 is about, made loud when it cannot be removed: a
|
|
574
|
+
* project whose `ownership.env` is a literal while it also declares a build
|
|
575
|
+
* parameter named `env` has two answers to "which environment is this", and
|
|
576
|
+
* the manifest carries both (the ownership marker from config, the labels
|
|
577
|
+
* from the parameter). Returns a warning naming both values when they differ;
|
|
578
|
+
* undefined when there is nothing to say (no literal, no `env` parameter, or
|
|
579
|
+
* the two agree). The fix is the `{ param: "env" }` reference.
|
|
580
|
+
*/
|
|
581
|
+
export function ownershipEnvDisagreement(
|
|
582
|
+
config: ChantConfig,
|
|
583
|
+
buildParams: readonly BuildParamProvenance[] | undefined,
|
|
584
|
+
): string | undefined {
|
|
585
|
+
const literal = config.ownership?.env;
|
|
586
|
+
if (typeof literal !== "string") return undefined;
|
|
587
|
+
if (resolveOwnershipStack(config) === undefined) return undefined;
|
|
588
|
+
const param = buildParams?.find((p) => p.name === "env");
|
|
589
|
+
if (!param || String(param.value) === literal) return undefined;
|
|
590
|
+
return (
|
|
591
|
+
`ownership.env is "${literal}" but the env build parameter resolved to ${JSON.stringify(param.value)} (${param.source}) — ` +
|
|
592
|
+
`the ownership marker and params.env disagree about which environment this build is for. ` +
|
|
593
|
+
`Use ownership: { env: { param: "env" } } so the marker follows the parameter.`
|
|
594
|
+
);
|
|
501
595
|
}
|
|
502
596
|
|
|
503
597
|
/**
|