@intentius/chant 0.124.85 → 0.124.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle-check.d.ts +102 -0
- package/dist/bundle-check.d.ts.map +1 -0
- package/dist/bundle-check.js +310 -0
- package/dist/chant-install.d.ts +100 -0
- package/dist/chant-install.d.ts.map +1 -0
- package/dist/chant-install.js +158 -0
- package/dist/ci-commit.d.ts +19 -6
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +23 -4
- package/dist/ci-evidence-jobs.d.ts +54 -0
- package/dist/ci-evidence-jobs.d.ts.map +1 -0
- package/dist/ci-evidence-jobs.js +55 -0
- package/dist/ci-image.d.ts +274 -0
- package/dist/ci-image.d.ts.map +1 -0
- package/dist/ci-image.js +635 -0
- package/dist/ci-login.d.ts +150 -0
- package/dist/ci-login.d.ts.map +1 -0
- package/dist/ci-login.js +240 -0
- package/dist/ci-product.d.ts +16 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +17 -0
- package/dist/cli/commands/import-index.js +2 -2
- package/dist/cli/handlers/build.d.ts +8 -0
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -4
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +57 -2
- package/dist/cli/handlers/ci-evidence.d.ts +3 -0
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
- package/dist/cli/handlers/ci-evidence.js +171 -0
- package/dist/cli/handlers/components.js +3 -3
- package/dist/cli/handlers/dead-guards.d.ts +3 -0
- package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
- package/dist/cli/handlers/dead-guards.js +35 -0
- package/dist/cli/handlers/graph.js +4 -4
- package/dist/cli/handlers/lifecycle.d.ts +2 -1
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +5 -4
- package/dist/cli/handlers/local-chant.d.ts +16 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -0
- package/dist/cli/handlers/local-chant.js +109 -0
- package/dist/cli/handlers/operator.js +2 -2
- package/dist/cli/handlers/search.js +5 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +28 -0
- package/dist/cli/registry.d.ts +16 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +49 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +64 -4
- package/dist/components/check-steps.d.ts +17 -0
- package/dist/components/check-steps.d.ts.map +1 -1
- package/dist/components/check-steps.js +37 -5
- package/dist/components/product-pipeline.d.ts +23 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +6 -2
- package/dist/components/product-plan.d.ts +137 -0
- package/dist/components/product-plan.d.ts.map +1 -0
- package/dist/components/product-plan.js +143 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +2 -2
- package/dist/config.d.ts +39 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -3
- package/dist/dead-guards.d.ts +82 -0
- package/dist/dead-guards.d.ts.map +1 -0
- package/dist/dead-guards.js +436 -0
- package/dist/discovery/files.d.ts +3 -1
- package/dist/discovery/files.d.ts.map +1 -1
- package/dist/discovery/files.js +5 -3
- package/dist/drift-issue.d.ts +152 -0
- package/dist/drift-issue.d.ts.map +1 -0
- package/dist/drift-issue.js +167 -0
- package/dist/floor-table.d.ts +30 -0
- package/dist/floor-table.d.ts.map +1 -0
- package/dist/floor-table.data.d.ts +3 -0
- package/dist/floor-table.data.d.ts.map +1 -0
- package/dist/floor-table.data.js +178 -0
- package/dist/floor-table.js +56 -0
- package/dist/forge-flags.d.ts +90 -0
- package/dist/forge-flags.d.ts.map +1 -0
- package/dist/forge-flags.js +184 -0
- package/dist/lexicon.d.ts +69 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.d.ts +7 -1
- package/dist/lifecycle/gated-op.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.js +7 -4
- package/dist/local-chant.d.ts +98 -0
- package/dist/local-chant.d.ts.map +1 -0
- package/dist/local-chant.js +307 -0
- package/dist/op/activities/predict-behaviour.js +2 -2
- package/dist/op/op-waves-evidence-spec.d.ts +13 -0
- package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-spec.js +21 -0
- package/dist/op/op-waves-evidence.d.ts +38 -0
- package/dist/op/op-waves-evidence.d.ts.map +1 -0
- package/dist/op/op-waves-evidence.js +57 -0
- package/dist/op/op-waves-run.d.ts +4 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +24 -1
- package/dist/op/op-waves.d.ts +17 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +23 -0
- package/dist/op/schedule-overdue.d.ts +41 -9
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +154 -25
- package/dist/plan-summary.d.ts +25 -0
- package/dist/plan-summary.d.ts.map +1 -1
- package/dist/plan-summary.js +31 -0
- package/dist/pr-plan-note.d.ts +35 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +10 -0
- package/dist/pr-post.d.ts +23 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +125 -3
- package/dist/release-floors.d.ts +31 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +31 -1
- package/dist/state-migration.d.ts +24 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +100 -5
- package/dist/wave-runtime.mjs +305 -298
- package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
- package/dist/workspace/lexicon-outputs.js +21 -7
- package/dist/workspace/reason-codes.d.ts +3 -0
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/reason-codes.js +4 -0
- package/dist/workspace/ref-gate.schema.json +85 -0
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/search-contract.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.d.ts +51 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence-report.js +102 -0
- package/dist/workspace/trust/check-evidence.d.ts +126 -0
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence.js +237 -0
- package/dist/workspace/trust/local-evidence.d.ts +120 -0
- package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/local-evidence.js +259 -0
- package/dist/workspace/trust/policy.d.ts +84 -0
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +94 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-cli.js +234 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-fixture.js +97 -0
- package/dist/workspace/trust/ref-gate.d.ts +187 -0
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate.js +430 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +18 -1
- package/package.json +1 -1
- package/src/bundle-check.test.ts +140 -0
- package/src/bundle-check.ts +352 -0
- package/src/chant-install.test.ts +112 -0
- package/src/chant-install.ts +179 -0
- package/src/ci-commit.test.ts +45 -0
- package/src/ci-commit.ts +38 -4
- package/src/ci-evidence-jobs.ts +67 -0
- package/src/ci-image.test.ts +506 -0
- package/src/ci-image.ts +822 -0
- package/src/ci-login.test.ts +235 -0
- package/src/ci-login.ts +307 -0
- package/src/ci-product.ts +18 -0
- package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/import-index.ts +2 -2
- package/src/cli/handlers/build-source-dir.test.ts +64 -0
- package/src/cli/handlers/build.ts +21 -4
- package/src/cli/handlers/ci-check.ts +56 -3
- package/src/cli/handlers/ci-evidence.ts +162 -0
- package/src/cli/handlers/components.ts +3 -3
- package/src/cli/handlers/dead-guards.ts +37 -0
- package/src/cli/handlers/graph.ts +4 -4
- package/src/cli/handlers/lifecycle.ts +5 -4
- package/src/cli/handlers/local-chant.ts +106 -0
- package/src/cli/handlers/operator.ts +2 -2
- package/src/cli/handlers/search.ts +5 -5
- package/src/cli/main.test.ts +7 -0
- package/src/cli/main.ts +38 -0
- package/src/cli/parse-args.ts +21 -0
- package/src/cli/registry.ts +16 -0
- package/src/components/check-evidence-stage.test.ts +80 -0
- package/src/components/check-hooks.ts +84 -4
- package/src/components/check-local-evidence-stage.test.ts +141 -0
- package/src/components/check-steps.ts +56 -6
- package/src/components/product-pipeline.ts +28 -3
- package/src/components/product-plan.test.ts +87 -0
- package/src/components/product-plan.ts +226 -0
- package/src/components/release-compile.ts +2 -2
- package/src/config.ts +44 -3
- package/src/dead-guards.test.ts +206 -0
- package/src/dead-guards.ts +446 -0
- package/src/discovery/files.ts +5 -3
- package/src/drift-issue-bundle.test.ts +31 -0
- package/src/drift-issue.test.ts +206 -0
- package/src/drift-issue.ts +274 -0
- package/src/fit-note.test.ts +44 -0
- package/src/floor-table.data.ts +180 -0
- package/src/floor-table.ts +77 -0
- package/src/forge-flags.test.ts +110 -0
- package/src/forge-flags.ts +208 -0
- package/src/gate-decision-bundle.test.ts +1 -0
- package/src/lexicon.ts +68 -0
- package/src/lifecycle/gated-op.ts +10 -5
- package/src/local-chant.e2e.test.ts +94 -0
- package/src/local-chant.test.ts +162 -0
- package/src/local-chant.ts +341 -0
- package/src/op/activities/predict-behaviour.ts +2 -2
- package/src/op/op-waves-evidence-spec.ts +24 -0
- package/src/op/op-waves-evidence.test.ts +130 -0
- package/src/op/op-waves-evidence.ts +57 -0
- package/src/op/op-waves-run.ts +25 -1
- package/src/op/op-waves.ts +31 -1
- package/src/op/schedule-overdue.test.ts +85 -0
- package/src/op/schedule-overdue.ts +162 -26
- package/src/plan-summary.ts +40 -0
- package/src/pr-plan-note.ts +34 -0
- package/src/pr-post-plan-note.test.ts +146 -0
- package/src/pr-post.ts +127 -3
- package/src/release-floors.ts +44 -1
- package/src/stage-hooks-bundle.test.ts +1 -0
- package/src/state-migration.test.ts +52 -1
- package/src/state-migration.ts +107 -5
- package/src/workspace/lexicon-outputs.ts +23 -6
- package/src/workspace/reason-codes.test.ts +3 -0
- package/src/workspace/reason-codes.ts +4 -0
- package/src/workspace/ref-gate.schema.json +85 -0
- package/src/workspace/trust/check-evidence-report.ts +106 -0
- package/src/workspace/trust/check-evidence.test.ts +133 -0
- package/src/workspace/trust/check-evidence.ts +257 -0
- package/src/workspace/trust/local-evidence.test.ts +127 -0
- package/src/workspace/trust/local-evidence.ts +266 -0
- package/src/workspace/trust/policy.ts +134 -1
- package/src/workspace/trust/ref-gate-cli.ts +244 -0
- package/src/workspace/trust/ref-gate-fixture.ts +125 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
- package/src/workspace/trust/ref-gate.test.ts +247 -0
- package/src/workspace/trust/ref-gate.ts +538 -0
- package/src/workspace/trust/trust-files.test.ts +16 -0
- package/src/workspace/trust/trust-files.ts +41 -1
|
@@ -133,14 +133,14 @@ async function projectEntities(
|
|
|
133
133
|
): Promise<{ entities: Map<string, DeclaredEntity[]>; warning?: string }> {
|
|
134
134
|
const entities = new Map<string, DeclaredEntity[]>();
|
|
135
135
|
try {
|
|
136
|
-
const { loadChantConfigUpward } = await import("../../config");
|
|
136
|
+
const { loadChantConfigUpward, resolveSourceDir } = await import("../../config");
|
|
137
137
|
const { config, configPath } = await loadChantConfigUpward(projectDir);
|
|
138
138
|
if (!configPath) return { entities };
|
|
139
139
|
const projectPlugins = plugins.filter((p) => p.serializer);
|
|
140
140
|
if (projectPlugins.length === 0) return { entities };
|
|
141
141
|
const { build } = await import("../../build");
|
|
142
142
|
const { isObservableDeclarable } = await import("../../declarable");
|
|
143
|
-
const root = src ? resolve(src) :
|
|
143
|
+
const root = resolveSourceDir(dirname(configPath), config, src ? resolve(src) : undefined);
|
|
144
144
|
const result = await build(root, projectPlugins.map((p) => p.serializer), undefined, { config: config as unknown as Record<string, unknown> });
|
|
145
145
|
if (result.errors.length > 0) {
|
|
146
146
|
return { entities, warning: `the project at ${root} does not build, so no indexed resource was checked against its declarations` };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4794: one source-dir rule. `chant build` with no path builds the config's
|
|
3
|
+
* `sourceDir`, else the project root, as `resolveSourceDir` says for every
|
|
4
|
+
* command; and a root build leaves a top-level `scripts/` out unless
|
|
5
|
+
* `include` brings it back. Test files stay out of every build.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, test, expect } from "vitest";
|
|
8
|
+
import { join, relative, resolve } from "node:path";
|
|
9
|
+
import { buildPathOf } from "./build";
|
|
10
|
+
import { discover } from "../../discovery/index";
|
|
11
|
+
import { findInfraFiles } from "../../discovery/files";
|
|
12
|
+
import { configuredSourceDir, resolveSourceDir } from "../../config";
|
|
13
|
+
|
|
14
|
+
const fixtures = resolve(import.meta.dirname, "../commands/__fixtures__");
|
|
15
|
+
const root = join(fixtures, "source-dir-root");
|
|
16
|
+
const scoped = join(fixtures, "source-dir-scoped");
|
|
17
|
+
const include = join(fixtures, "source-dir-include");
|
|
18
|
+
|
|
19
|
+
const loaded = async (path: string, from: string): Promise<string[]> => {
|
|
20
|
+
const result = await discover(path);
|
|
21
|
+
expect(result.errors.map((e) => String(e))).toEqual([]);
|
|
22
|
+
return result.sourceFiles.map((f) => relative(from, f).split("\\").join("/")).sort();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe("resolveSourceDir (#4794)", () => {
|
|
26
|
+
test("an explicit path wins, then sourceDir, then the project root", () => {
|
|
27
|
+
expect(resolveSourceDir("/p", { sourceDir: "ci" }, "other")).toBe(resolve("/p/other"));
|
|
28
|
+
expect(resolveSourceDir("/p", { sourceDir: "ci" })).toBe(resolve("/p/ci"));
|
|
29
|
+
expect(resolveSourceDir("/p", {})).toBe(resolve("/p"));
|
|
30
|
+
expect(resolveSourceDir("/p", undefined)).toBe(resolve("/p"));
|
|
31
|
+
expect(configuredSourceDir({})).toBe(".");
|
|
32
|
+
expect(configuredSourceDir({ sourceDir: "src" })).toBe("src");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("a root build (#4794)", () => {
|
|
37
|
+
test("a project with scripts/ and no sourceDir builds without loading it, nor its test files", async () => {
|
|
38
|
+
expect(await loaded(root, root)).toEqual(["infra.ts"]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("include brings scripts/ back", async () => {
|
|
42
|
+
expect((await findInfraFiles(include)).map((f) => relative(include, f).split("\\").join("/")).sort()).toEqual(["infra.ts", "scripts/run-on-load.ts"]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("an explicit path below the root is not a root build", async () => {
|
|
46
|
+
expect((await findInfraFiles(join(root, "scripts"))).map((f) => relative(root, f))).toEqual([join("scripts", "run-on-load.ts")]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("chant build's path (#4794)", () => {
|
|
51
|
+
test("with no path, at a project that sets sourceDir, it builds only that directory", async () => {
|
|
52
|
+
const path = await buildPathOf({ path: scoped, pathGiven: false });
|
|
53
|
+
expect(path).toBe(join(scoped, "infra"));
|
|
54
|
+
expect(await loaded(path, scoped)).toEqual(["infra/net.ts"]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("a path argument wins over sourceDir", async () => {
|
|
58
|
+
expect(await buildPathOf({ path: scoped, pathGiven: true })).toBe(scoped);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("with no sourceDir it is the path it was given, as before", async () => {
|
|
62
|
+
expect(await buildPathOf({ path: root, pathGiven: false })).toBe(root);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { writeFileSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
2
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
3
3
|
import { buildCommand, buildCommandWatch, printErrors, printWarnings, resolveBuildFormat } from "../commands/build";
|
|
4
4
|
import { formatError, formatInfo, formatSuccess, formatBold } from "../format";
|
|
5
5
|
import { reportUninstalledDependencies } from "../dependencies";
|
|
6
6
|
import type { CommandContext } from "../registry";
|
|
7
7
|
import { generateComponentsPipeline } from "../../components/cli-support";
|
|
8
|
-
import { loadChantConfigUpward, type ChantConfig } from "../../config";
|
|
8
|
+
import { loadChantConfigUpward, resolveSourceDir, type ChantConfig } from "../../config";
|
|
9
9
|
import { resolveCliBuildParams, parseParamFlags } from "../build-params-cli";
|
|
10
10
|
import { findWorkspaceRoot } from "../../project-root";
|
|
11
11
|
import { resolvePromotionSource } from "../../components/promote-order";
|
|
@@ -456,16 +456,33 @@ async function runGenerateComponents(ctx: CommandContext): Promise<number> {
|
|
|
456
456
|
return 0;
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
+
/**
|
|
460
|
+
* The directory `chant build` builds (#4794). A path argument wins. With
|
|
461
|
+
* none, at the root of a project, it is the one source-dir rule's
|
|
462
|
+
* (`resolveSourceDir`): the config's `sourceDir`, else the root. Below the
|
|
463
|
+
* root it is the directory the command runs in, as it always was. Kept
|
|
464
|
+
* relative, so the paths the build prints read as before.
|
|
465
|
+
*/
|
|
466
|
+
export async function buildPathOf(args: Pick<CommandContext["args"], "path" | "pathGiven">): Promise<string> {
|
|
467
|
+
if (args.pathGiven) return args.path;
|
|
468
|
+
const here = resolve(args.path);
|
|
469
|
+
const loaded = await loadChantConfigUpward(here).catch(() => undefined);
|
|
470
|
+
if (!loaded?.configPath || resolve(dirname(loaded.configPath)) !== here || loaded.config.sourceDir === undefined) return args.path;
|
|
471
|
+
return join(args.path, relative(here, resolveSourceDir(here, loaded.config)));
|
|
472
|
+
}
|
|
473
|
+
|
|
459
474
|
export async function runBuild(ctx: CommandContext): Promise<number> {
|
|
460
|
-
const {
|
|
475
|
+
const { plugins } = ctx;
|
|
461
476
|
let { serializers } = ctx;
|
|
462
477
|
|
|
463
478
|
// Generate mode (#563): synthesize CI YAML from components instead of
|
|
464
479
|
// running a normal lexicon build. Checked first since it does not need
|
|
465
480
|
// `serializers`/lexicon resources at all.
|
|
466
|
-
if (args.components && args.generate) {
|
|
481
|
+
if (ctx.args.components && ctx.args.generate) {
|
|
467
482
|
return runGenerateComponents(ctx);
|
|
468
483
|
}
|
|
484
|
+
// #4794: the lexicon build reads the config's sourceDir when no path is given.
|
|
485
|
+
const args = { ...ctx.args, path: await buildPathOf(ctx.args) };
|
|
469
486
|
|
|
470
487
|
// Filter to a single lexicon when --lexicon is specified
|
|
471
488
|
if (args.lexicon) {
|
|
@@ -9,9 +9,19 @@
|
|
|
9
9
|
* when every hook and step passed or there were none, 1 (`failed`) when one
|
|
10
10
|
* failed. See `../../components/check-hooks.ts` and
|
|
11
11
|
* `../../components/check-steps.ts`.
|
|
12
|
+
*
|
|
13
|
+
* With a runner key in `CHANT_RUNNER_KEY` (#4870), each hook that passed is
|
|
14
|
+
* signed as a named check over `HEAD` and attached under `refs/notes/chant/evidence`, which
|
|
15
|
+
* is pushed unless `--no-push`; the key never reaches a hook.
|
|
16
|
+
*
|
|
17
|
+
* #4868: with a local key in `CHANT_LOCAL_EVIDENCE_KEY` (a developer's or an
|
|
18
|
+
* agent session's, listed under `local.keys` at base) each hook that passed
|
|
19
|
+
* is signed as local evidence instead, under `refs/notes/chant/local-evidence`.
|
|
20
|
+
* Without one, a hook whose check `local.checks` at base names is skipped
|
|
21
|
+
* when current local evidence for the tree stands in for it; the rest run.
|
|
12
22
|
*/
|
|
13
23
|
import { resolve } from "node:path";
|
|
14
|
-
import type { CheckStepsAdapter } from "../../components/check-steps";
|
|
24
|
+
import type { CheckStageEvidence, CheckStepsAdapter } from "../../components/check-steps";
|
|
15
25
|
import { CHANT_EXIT } from "../../exit-codes";
|
|
16
26
|
import { formatError } from "../format";
|
|
17
27
|
import type { CommandContext } from "../registry";
|
|
@@ -34,7 +44,44 @@ async function lexiconCheckSteps(ctx: CommandContext, cwd: string): Promise<Chec
|
|
|
34
44
|
return plugins.map((p) => p.checkSteps?.()).filter((a): a is CheckStepsAdapter => a !== undefined);
|
|
35
45
|
}
|
|
36
46
|
|
|
37
|
-
const USAGE = "chant ci check --base <rev> [<target>...] [--output <dir>] [--json]";
|
|
47
|
+
const USAGE = "chant ci check --base <rev> [<target>...] [--output <dir>] [--no-push] [--json]";
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The check stage's signer (#4870), when the job holds a runner key in
|
|
51
|
+
* `CHANT_RUNNER_KEY`: the runner `.chant/trust.json` at `base` lists for it.
|
|
52
|
+
* Throws when the key is there and the policy at base does not list it, so
|
|
53
|
+
* a job asked to sign never passes while signing nothing.
|
|
54
|
+
*/
|
|
55
|
+
async function checkEvidenceSigner(base: string, noPush: boolean): Promise<CheckStageEvidence | undefined> {
|
|
56
|
+
const { CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV } = await import("../../workspace/trust/check-evidence-report");
|
|
57
|
+
const pem = process.env[CHECK_EVIDENCE_KEY_ENV];
|
|
58
|
+
const localPem = process.env[LOCAL_EVIDENCE_KEY_ENV];
|
|
59
|
+
if (!pem && !localPem) return undefined;
|
|
60
|
+
if (pem && localPem) throw new Error(`${CHECK_EVIDENCE_KEY_ENV} and ${LOCAL_EVIDENCE_KEY_ENV} are both set; a job signs as a runner or as a person or agent, never both`);
|
|
61
|
+
const { top, commit } = await baseCommit(base);
|
|
62
|
+
if (localPem) {
|
|
63
|
+
const { localKeyEvidenceSigner } = await import("../../workspace/trust/local-evidence");
|
|
64
|
+
return { signer: localKeyEvidenceSigner(top, commit, localPem), ...(noPush ? { push: false } : {}) };
|
|
65
|
+
}
|
|
66
|
+
const { runnerKeyEvidenceSigner } = await import("../../workspace/trust/check-evidence");
|
|
67
|
+
return { signer: runnerKeyEvidenceSigner(top, commit, pem!), ...(noPush ? { push: false } : {}) };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function baseCommit(base: string): Promise<{ top: string; commit: string }> {
|
|
71
|
+
const { execFileSync } = await import("node:child_process");
|
|
72
|
+
const top = execFileSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
73
|
+
const commit = execFileSync("git", ["rev-parse", "--verify", `${base}^{commit}`], { cwd: top, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
74
|
+
return { top, commit };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Skipping on local evidence (#4868), judged by the policy at `base`; undefined outside a git repository. */
|
|
78
|
+
async function localEvidenceAt(base: string): Promise<{ base: string } | undefined> {
|
|
79
|
+
try {
|
|
80
|
+
return { base: (await baseCommit(base)).commit };
|
|
81
|
+
} catch {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
38
85
|
|
|
39
86
|
export async function runCiCheck(ctx: CommandContext): Promise<number> {
|
|
40
87
|
const { args } = ctx;
|
|
@@ -47,7 +94,10 @@ export async function runCiCheck(ctx: CommandContext): Promise<number> {
|
|
|
47
94
|
let report;
|
|
48
95
|
try {
|
|
49
96
|
const adapters = await lexiconCheckSteps(ctx, process.cwd());
|
|
50
|
-
|
|
97
|
+
const evidence = await checkEvidenceSigner(args.base, args.noPush === true);
|
|
98
|
+
// #4868: a job that signs local evidence runs every hook; any other may skip one on local evidence.
|
|
99
|
+
const local = evidence && "class" in evidence.signer ? undefined : await localEvidenceAt(args.base);
|
|
100
|
+
report = await runCheckStage({ base: args.base, targets, adapters, ...(args.output ? { dir: args.output } : {}), ...(evidence ? { evidence } : {}), ...(local ? { localEvidence: local } : {}) });
|
|
51
101
|
} catch (err) {
|
|
52
102
|
console.error(formatError({ message: err instanceof Error ? err.message : String(err), hint: USAGE }));
|
|
53
103
|
return CHANT_EXIT.failed;
|
|
@@ -58,6 +108,9 @@ export async function runCiCheck(ctx: CommandContext): Promise<number> {
|
|
|
58
108
|
const all = [...report.hooks, ...(report.steps ?? [])];
|
|
59
109
|
console.error(`ci check: ${all.filter((h) => h.outcome === "passed").length} passed, ${all.filter((h) => h.outcome === "failed").length} failed, ${all.filter((h) => h.outcome === "skipped").length} skipped`);
|
|
60
110
|
if (report.failed) console.error(`ci check: ${report.failed}`);
|
|
111
|
+
if (report.evidence) console.error(`ci check: signed ${report.evidence.signed.join(", ")} as ${report.evidence.runner}`);
|
|
112
|
+
const onLocal = report.hooks.filter((h) => h.localEvidence);
|
|
113
|
+
if (onLocal.length > 0) console.error(`ci check: skipped on local evidence: ${onLocal.map((h) => `${h.name} (${h.localEvidence!.class} ${h.localEvidence!.signer})`).join(", ")}`);
|
|
61
114
|
}
|
|
62
115
|
return report.status === "failed" ? CHANT_EXIT.failed : CHANT_EXIT.done;
|
|
63
116
|
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant ci evidence sign|verify` (#4870): evidence for the named checks a
|
|
3
|
+
* generated pipeline runs, attached to the commit under
|
|
4
|
+
* `refs/notes/chant/evidence`, where #4867's ref gate reads them
|
|
5
|
+
* (../../workspace/trust/check-evidence.ts).
|
|
6
|
+
*
|
|
7
|
+
* - `sign --check-id <id>[,<id>...]` signs that each check passed at `--at`
|
|
8
|
+
* (default `HEAD`), with the runner key in `--key <file>` or
|
|
9
|
+
* `CHANT_RUNNER_KEY`, and pushes the notes unless `--no-push`.
|
|
10
|
+
* - `sign --from-report <dir> --result <result>` is the plan note job's
|
|
11
|
+
* form: it signs `plan` when the plan job succeeded and left a report in
|
|
12
|
+
* `<dir>`, and `policy` when the policy evaluated inside that plan did not
|
|
13
|
+
* deny it (a `pr-plan.json`'s `policy`, a plan note hand-off's overrides).
|
|
14
|
+
* It writes `evidence.json` in `<dir>`, which `pr-post` reads to say in the
|
|
15
|
+
* note which checks were signed.
|
|
16
|
+
* - `verify --check-id <id>[,<id>...]` reads the evidence for `--at`'s tree
|
|
17
|
+
* and verifies it against the runner keys at `--base`; exits 1 when one
|
|
18
|
+
* is not current.
|
|
19
|
+
*
|
|
20
|
+
* Without a runner key, `sign` signs nothing and says so: a project that
|
|
21
|
+
* declares no runner identity gets the same job it had.
|
|
22
|
+
*
|
|
23
|
+
* `--local` (#4868) is the developer's or agent session's form: `sign
|
|
24
|
+
* --local` signs with the key in `--key` or `CHANT_LOCAL_EVIDENCE_KEY`, which
|
|
25
|
+
* `local.keys` at base lists, and pushes `refs/notes/chant/local-evidence`;
|
|
26
|
+
* `verify --local` says whether CI would skip each check on that evidence.
|
|
27
|
+
*/
|
|
28
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { CHANT_EXIT } from "../../exit-codes";
|
|
31
|
+
import { formatError } from "../format";
|
|
32
|
+
import type { CommandContext } from "../registry";
|
|
33
|
+
import { gitRoot } from "../../workspace/record-source";
|
|
34
|
+
import { resolveBase } from "../../workspace/trust/provenance";
|
|
35
|
+
import {
|
|
36
|
+
CHECK_EVIDENCE_KEY_ENV,
|
|
37
|
+
readCheckEvidence,
|
|
38
|
+
recordChecks,
|
|
39
|
+
runnerKeyEvidenceSigner,
|
|
40
|
+
signChecks,
|
|
41
|
+
type EvidenceSigner,
|
|
42
|
+
} from "../../workspace/trust/check-evidence";
|
|
43
|
+
import { CHECK_EVIDENCE_FILE, LOCAL_EVIDENCE_KEY_ENV, planReportChecks, type CheckEvidenceNote } from "../../workspace/trust/check-evidence-report";
|
|
44
|
+
|
|
45
|
+
const USAGE =
|
|
46
|
+
"chant ci evidence sign (--check-id <id>[,<id>...] | --from-report <dir> --result <result>) [--at <rev>] [--base <rev>] [--key <file>] [--claim <file>] [--no-push] [--json]\n" +
|
|
47
|
+
" chant ci evidence sign --local --check-id <id>[,<id>...] [--at <rev>] [--base <rev>] [--key <file>] [--claim <file>] [--no-push] [--json]\n" +
|
|
48
|
+
" chant ci evidence verify [--local] --check-id <id>[,<id>...] [--at <rev>] [--base <rev>] [--json]";
|
|
49
|
+
|
|
50
|
+
function usage(message: string): number {
|
|
51
|
+
console.error(formatError({ message, hint: USAGE }));
|
|
52
|
+
return CHANT_EXIT.failed;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function idsOf(value: string | undefined): string[] {
|
|
56
|
+
return (value ?? "").split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function runCiEvidence(ctx: CommandContext): Promise<number> {
|
|
60
|
+
const { args } = ctx;
|
|
61
|
+
const sub = args.extraPositional;
|
|
62
|
+
if (sub !== "sign" && sub !== "verify") return usage(sub ? `Unknown evidence subcommand: ${sub}` : "chant ci evidence needs sign or verify");
|
|
63
|
+
const repo = gitRoot(process.cwd());
|
|
64
|
+
if (!repo) return usage("check evidence is bound to git commits, and this directory is not in a git repository");
|
|
65
|
+
const base = resolveBase(repo, args.base);
|
|
66
|
+
if (!base.commit) return usage(base.problem ?? "no base: pass --base <rev>, the commit whose .chant/trust.json lists the runner keys");
|
|
67
|
+
const at = args.at ?? "HEAD";
|
|
68
|
+
if (args.local) return sub === "sign" ? signLocal(ctx, repo, base.commit, at) : verifyLocal(ctx, repo, base.commit, at);
|
|
69
|
+
return sub === "sign" ? sign(ctx, repo, base.commit, at) : verify(ctx, repo, base.commit, at);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** `sign --local` (#4868): local evidence for each named check, signed by a person's or an agent's key. */
|
|
73
|
+
async function signLocal(ctx: CommandContext, repo: string, base: string, at: string): Promise<number> {
|
|
74
|
+
const { args } = ctx;
|
|
75
|
+
const checks = idsOf(args.checkId);
|
|
76
|
+
if (checks.length === 0) return usage("sign --local needs --check-id <id>");
|
|
77
|
+
if (args.fromReport) return usage("--from-report is the plan note job's; plan and policy never take local evidence");
|
|
78
|
+
const pem = args.key ? readFileSync(args.key, "utf-8") : process.env[LOCAL_EVIDENCE_KEY_ENV];
|
|
79
|
+
if (!pem) return usage(`sign --local needs a local evidence key: --key <file> or ${LOCAL_EVIDENCE_KEY_ENV}`);
|
|
80
|
+
const { localKeyEvidenceSigner, recordLocalChecks, signLocalChecks } = await import("../../workspace/trust/local-evidence");
|
|
81
|
+
let signer;
|
|
82
|
+
try {
|
|
83
|
+
signer = localKeyEvidenceSigner(repo, base, pem);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(formatError({ message: err instanceof Error ? err.message : String(err), hint: USAGE }));
|
|
86
|
+
return CHANT_EXIT.failed;
|
|
87
|
+
}
|
|
88
|
+
const claim = args.claim ? readFileSync(args.claim) : undefined;
|
|
89
|
+
const signed = signLocalChecks(repo, at, checks.map((check) => ({ check, ...(claim ? { claim } : {}) })), signer);
|
|
90
|
+
const pushed = await recordLocalChecks(repo, signed, { push: !args.noPush });
|
|
91
|
+
for (const s of signed) console.error(`ci evidence: signed local evidence for ${s.check} at ${s.commit.slice(0, 12)} as ${signer.class} ${s.runner}`);
|
|
92
|
+
if (!args.noPush && !pushed.pushed && pushed.pushWarning) console.error(`ci evidence: the evidence is attached here, and the push did not land: ${pushed.pushWarning}`);
|
|
93
|
+
if (args.json) console.log(JSON.stringify({ signed: signed.map((s) => ({ check: s.check, signer: s.runner, class: signer.class, commit: s.commit, tree: s.tree })) }, null, 2));
|
|
94
|
+
return CHANT_EXIT.done;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** `verify --local` (#4868): whether CI would skip each check on local evidence; exits 1 when one would run. */
|
|
98
|
+
async function verifyLocal(ctx: CommandContext, repo: string, base: string, at: string): Promise<number> {
|
|
99
|
+
const { args } = ctx;
|
|
100
|
+
const checks = idsOf(args.checkId);
|
|
101
|
+
if (checks.length === 0) return usage("verify --local needs --check-id <id>");
|
|
102
|
+
const { acceptedLocalEvidence } = await import("../../workspace/trust/local-evidence");
|
|
103
|
+
const verdicts = acceptedLocalEvidence(repo, at, base, checks);
|
|
104
|
+
if (args.json) console.log(JSON.stringify({ at, base, local: true, checks: verdicts }, null, 2));
|
|
105
|
+
else for (const v of verdicts) console.error(v.status === "accepted" ? ` accepted ${v.check} (${v.class} ${v.signer} at ${v.commit.slice(0, 12)})` : ` ${v.status.padEnd(12)} ${v.check}: ${v.reason}`);
|
|
106
|
+
return verdicts.every((v) => v.status === "accepted") ? CHANT_EXIT.done : CHANT_EXIT.failed;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function sign(ctx: CommandContext, repo: string, base: string, at: string): Promise<number> {
|
|
110
|
+
const { args } = ctx;
|
|
111
|
+
const fromReport = args.fromReport;
|
|
112
|
+
if (!fromReport && idsOf(args.checkId).length === 0) return usage("sign needs --check-id <id>, or --from-report <dir> in a plan note job");
|
|
113
|
+
const pem = args.key ? readFileSync(args.key, "utf-8") : process.env[CHECK_EVIDENCE_KEY_ENV];
|
|
114
|
+
const note: CheckEvidenceNote = { signed: [], skipped: [] };
|
|
115
|
+
let wanted: Array<{ check: string; claim?: Buffer | string }>;
|
|
116
|
+
if (fromReport) {
|
|
117
|
+
const decided = planReportChecks(fromReport, args.planResult);
|
|
118
|
+
wanted = decided.sign;
|
|
119
|
+
note.skipped.push(...decided.skipped);
|
|
120
|
+
} else {
|
|
121
|
+
const claim = args.claim ? readFileSync(args.claim) : undefined;
|
|
122
|
+
wanted = idsOf(args.checkId).map((check) => ({ check, ...(claim ? { claim } : {}) }));
|
|
123
|
+
}
|
|
124
|
+
const finish = (code: number): number => {
|
|
125
|
+
if (fromReport) writeFileSync(join(fromReport, CHECK_EVIDENCE_FILE), JSON.stringify(note, null, 2) + "\n");
|
|
126
|
+
if (args.json) console.log(JSON.stringify(note, null, 2));
|
|
127
|
+
return code;
|
|
128
|
+
};
|
|
129
|
+
if (!pem) {
|
|
130
|
+
note.skipped.push(...wanted.map((w) => ({ check: w.check, reason: `no runner key: ${CHECK_EVIDENCE_KEY_ENV} is not set` })));
|
|
131
|
+
console.error(`ci evidence: no runner key in ${CHECK_EVIDENCE_KEY_ENV}, so no check was signed`);
|
|
132
|
+
return finish(CHANT_EXIT.done);
|
|
133
|
+
}
|
|
134
|
+
let signer: EvidenceSigner;
|
|
135
|
+
try {
|
|
136
|
+
signer = runnerKeyEvidenceSigner(repo, base, pem);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
console.error(formatError({ message: err instanceof Error ? err.message : String(err), hint: USAGE }));
|
|
139
|
+
return finish(CHANT_EXIT.failed);
|
|
140
|
+
}
|
|
141
|
+
for (const s of note.skipped) console.error(`ci evidence: ${s.check} not signed: ${s.reason}`);
|
|
142
|
+
if (wanted.length === 0) return finish(CHANT_EXIT.done);
|
|
143
|
+
const signed = signChecks(repo, at, wanted, signer);
|
|
144
|
+
const pushed = await recordChecks(repo, signed, { push: !args.noPush });
|
|
145
|
+
for (const s of signed) {
|
|
146
|
+
note.signed.push({ check: s.check, runner: s.runner, commit: s.commit, tree: s.tree });
|
|
147
|
+
console.error(`ci evidence: signed ${s.check} at ${s.commit.slice(0, 12)} as ${s.runner}`);
|
|
148
|
+
}
|
|
149
|
+
if (!args.noPush && !pushed.pushed && pushed.pushWarning) console.error(`ci evidence: the evidence is attached here, and the push did not land: ${pushed.pushWarning}`);
|
|
150
|
+
return finish(CHANT_EXIT.done);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function verify(ctx: CommandContext, repo: string, base: string, at: string): Promise<number> {
|
|
154
|
+
const { args } = ctx;
|
|
155
|
+
const checks = idsOf(args.checkId);
|
|
156
|
+
if (checks.length === 0) return usage("verify needs --check-id <id>");
|
|
157
|
+
const verdicts = await readCheckEvidence(repo, at, base, checks);
|
|
158
|
+
if (args.json) console.log(JSON.stringify({ at, base, checks: verdicts }, null, 2));
|
|
159
|
+
else for (const v of verdicts) console.error(v.status === "current" ? ` current ${v.check} (signed by ${v.runner} at ${v.commit.slice(0, 12)})` : ` ${v.status.padEnd(7)} ${v.check}: ${v.reason}`);
|
|
160
|
+
return verdicts.every((v) => v.status === "current") ? CHANT_EXIT.done : CHANT_EXIT.failed;
|
|
161
|
+
}
|
|
162
|
+
|
|
@@ -47,7 +47,7 @@ import { buildLedgerEntries, componentBomSummary, type BuildLedgerEntry } from "
|
|
|
47
47
|
import { findBuildManifestByArtifactDigest, readBuildManifest } from "../../lifecycle/build-ledger-store";
|
|
48
48
|
import type { ComponentBomSummary } from "../../lifecycle/build-ledger";
|
|
49
49
|
import type { BuildArchiveManifest } from "../../components/verbs/build-archive";
|
|
50
|
-
import { loadChantConfig } from "../../config";
|
|
50
|
+
import { loadChantConfig, resolveSourceDir } from "../../config";
|
|
51
51
|
import { applyLiveEndpoint } from "../../live-endpoint";
|
|
52
52
|
import { isObservableDeclarable } from "../../declarable";
|
|
53
53
|
import { build } from "../../build";
|
|
@@ -575,7 +575,7 @@ export async function runComponentsStatus(ctx: CommandContext): Promise<number>
|
|
|
575
575
|
// Discover components (best-effort) so a live/owned-but-never-recorded
|
|
576
576
|
// component still gets a row, not just those that appear in the ledger.
|
|
577
577
|
const { config } = await loadChantConfig(resolve("."));
|
|
578
|
-
const discovery = await discoverComponents(resolve(
|
|
578
|
+
const discovery = await discoverComponents(resolveSourceDir(resolve("."), config, args.src), {
|
|
579
579
|
sandbox: args.sandbox,
|
|
580
580
|
});
|
|
581
581
|
const allComponents = [...discovery.components.keys()];
|
|
@@ -620,7 +620,7 @@ export async function runComponentsStatus(ctx: CommandContext): Promise<number>
|
|
|
620
620
|
// absent.
|
|
621
621
|
const statusParams = await commandBuildParams(config.buildParams, args);
|
|
622
622
|
if (!statusParams) return 1;
|
|
623
|
-
const buildResult = await build(resolve(
|
|
623
|
+
const buildResult = await build(resolveSourceDir(resolve("."), config, args.src), targetSerializers, undefined, {
|
|
624
624
|
buildParams: statusParams,
|
|
625
625
|
config: config as unknown as Record<string, unknown>,
|
|
626
626
|
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant dev dead-guards [<product-dir>]` (#4792): each feature-detect in a
|
|
3
|
+
* product whose chant floor the product's pin already meets, so the product
|
|
4
|
+
* deletes it. Exit 1 when there is one, 2 for a usage error.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, statSync } from "node:fs";
|
|
7
|
+
import { resolve } from "node:path";
|
|
8
|
+
import { deadGuardLine, findDeadGuards } from "../../dead-guards";
|
|
9
|
+
import { formatError } from "../format";
|
|
10
|
+
import type { CommandContext } from "../registry";
|
|
11
|
+
|
|
12
|
+
const USAGE = "chant dev dead-guards [<product-dir>] [--chant-version <version>] [--json]";
|
|
13
|
+
|
|
14
|
+
export async function runDevDeadGuards(ctx: CommandContext): Promise<number> {
|
|
15
|
+
const dir = resolve(ctx.args.extraPositional ?? process.cwd());
|
|
16
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory()) {
|
|
17
|
+
console.error(formatError({ message: `${dir} is not a directory`, hint: USAGE }));
|
|
18
|
+
return 2;
|
|
19
|
+
}
|
|
20
|
+
const r = findDeadGuards({ productDir: dir, ...(ctx.args.chantVersion ? { chant: ctx.args.chantVersion } : {}) });
|
|
21
|
+
if (!ctx.args.chantVersion && r.pins.length === 0) {
|
|
22
|
+
console.error(formatError({ message: `no package.json under ${dir} pins @intentius/chant at a version`, hint: USAGE }));
|
|
23
|
+
return 2;
|
|
24
|
+
}
|
|
25
|
+
if (ctx.args.json) {
|
|
26
|
+
console.log(JSON.stringify(r, null, 2));
|
|
27
|
+
return r.ok ? 0 : 1;
|
|
28
|
+
}
|
|
29
|
+
const against = ctx.args.chantVersion ? `chant ${ctx.args.chantVersion}` : r.pins.map((p) => `${p.file} ${p.pin}`).join(", ");
|
|
30
|
+
if (r.ok) {
|
|
31
|
+
console.error(`dead-guards: ${r.files} files, no feature-detect the pin meets (${r.live.length} still needed; against ${against})`);
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
console.error(`dead-guards: ${r.dead.length} feature-detect(s) the pin already meets; delete each check and its fallback (against ${against})`);
|
|
35
|
+
for (const g of r.dead) console.error(` ${deadGuardLine(g)}`);
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
@@ -13,7 +13,7 @@ import { carryAnnotations, observeResources } from "../../lifecycle/observe";
|
|
|
13
13
|
import type { RootRead } from "../../observation";
|
|
14
14
|
import { withLiveReadSession } from "../../live-read-session";
|
|
15
15
|
import { replaySnapshots, hasSnapshot } from "../../lifecycle/replay";
|
|
16
|
-
import { loadChantConfig, environmentNames, matchesDeclaredEnvironment, loadChantConfigUpward, type ChantConfig } from "../../config";
|
|
16
|
+
import { loadChantConfig, environmentNames, matchesDeclaredEnvironment, loadChantConfigUpward, resolveSourceDir, type ChantConfig } from "../../config";
|
|
17
17
|
import { applyLiveEndpoint } from "../../live-endpoint";
|
|
18
18
|
import { applyDetail, detailInertNotice, type DetailLevel } from "../../graph-detail";
|
|
19
19
|
import { applyLens, parseLens } from "../../graph-lens";
|
|
@@ -234,7 +234,7 @@ async function runGraphLive(
|
|
|
234
234
|
// build here didn't, and the overlay called every one of them foreign.
|
|
235
235
|
const buildRoots = collectBuildRootContributors(plugins, config as unknown as Record<string, unknown>, projectPath);
|
|
236
236
|
const buildResult = await build(
|
|
237
|
-
resolve(
|
|
237
|
+
resolveSourceDir(resolve("."), config, args.src),
|
|
238
238
|
plugins.map((p) => p.serializer),
|
|
239
239
|
undefined,
|
|
240
240
|
// #4252: the serializers read lexicon settings from config (gcp.project
|
|
@@ -263,7 +263,7 @@ async function runGraphLive(
|
|
|
263
263
|
// no components (or whose discovery errors) yields no stacks, so
|
|
264
264
|
// `observeResources` falls back to its original single-stack call —
|
|
265
265
|
// unchanged.
|
|
266
|
-
const componentsDiscovery = await discoverComponents(resolve(
|
|
266
|
+
const componentsDiscovery = await discoverComponents(resolveSourceDir(resolve("."), config, args.src), {
|
|
267
267
|
sandbox: args.sandbox,
|
|
268
268
|
});
|
|
269
269
|
const stacks: Array<{ name: string; region?: string; src?: string }> = [];
|
|
@@ -421,7 +421,7 @@ async function runGraphLive(
|
|
|
421
421
|
: sourceOverlayGraphs(declaredIr, ir, overlayOpts);
|
|
422
422
|
} else {
|
|
423
423
|
const declaredParams = await graphBuildParams(ctx, projectPath);
|
|
424
|
-
const declared = await discover(resolve(
|
|
424
|
+
const declared = await discover(resolveSourceDir(resolve("."), config, args.src), {
|
|
425
425
|
...(declaredParams ? { buildParams: declaredParams } : {}),
|
|
426
426
|
});
|
|
427
427
|
// #1626 — the declared canvas must include what the build declares, and
|
|
@@ -41,7 +41,7 @@ import { changedFilesBetween, lexiconChangedUnits } from "../../components/chang
|
|
|
41
41
|
import { cfnDeployStacks } from "./components";
|
|
42
42
|
import { affectedStacks } from "../../lifecycle/affected";
|
|
43
43
|
import { rollbackToRevision } from "../../lifecycle/rollback";
|
|
44
|
-
import { loadChantConfig, environmentNames, matchesDeclaredEnvironment, resolveOwnershipStack } from "../../config";
|
|
44
|
+
import { loadChantConfig, environmentNames, matchesDeclaredEnvironment, resolveOwnershipStack, resolveSourceDir, configuredSourceDir } from "../../config";
|
|
45
45
|
import { unknownEnvError, isProdLikeEnvironment } from "../../env";
|
|
46
46
|
import { planTeardown, executeTeardown, type TeardownPlan, type TeardownReport } from "../../lifecycle/teardown";
|
|
47
47
|
import { collectBuildRootContributors } from "../plugins";
|
|
@@ -66,10 +66,11 @@ type LoadedChantConfigLike = { observationBaseline?: unknown; snapshots?: unknow
|
|
|
66
66
|
* subdirectory so a mixed-layout project — chant `src/` next to app code with
|
|
67
67
|
* import side effects — only synthesizes its infra. Precedence: `--src` flag,
|
|
68
68
|
* then `config.sourceDir`, then "." (the root). Snapshot/diff/plan all use this
|
|
69
|
-
* so their build digests stay consistent.
|
|
69
|
+
* so their build digests stay consistent. The rule is `resolveSourceDir`'s,
|
|
70
|
+
* which every command that picks a source directory shares (#4794).
|
|
70
71
|
*/
|
|
71
72
|
export function resolveBuildRoot(args: ParsedArgs, config: ChantConfig): string {
|
|
72
|
-
return resolve(
|
|
73
|
+
return resolveSourceDir(resolve("."), config, args.src);
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/** One stack a lifecycle command operates on: its build root and, for a
|
|
@@ -302,7 +303,7 @@ export async function runLifecycleRollback(ctx: CommandContext): Promise<number>
|
|
|
302
303
|
return 1;
|
|
303
304
|
}
|
|
304
305
|
const { config } = await loadChantConfig(resolve("."));
|
|
305
|
-
const sourceDir = config
|
|
306
|
+
const sourceDir = configuredSourceDir(config);
|
|
306
307
|
try {
|
|
307
308
|
const result = await rollbackToRevision({ ref, env: environment, sourceDir, cwd: resolve("."), dryRun: args.dryRun });
|
|
308
309
|
if (result.noop) {
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant dev local` and `chant dev bundle-check` (#4787): build a product
|
|
3
|
+
* against a chant checkout, and check the product's bundle. Both modules are
|
|
4
|
+
* imported here, before the install, so the command keeps running the chant
|
|
5
|
+
* it started with while npm replaces the installed one.
|
|
6
|
+
*/
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { join, resolve } from "node:path";
|
|
9
|
+
import { checkBundle, readBundleCheckConfig, type BundleCheckResult } from "../../bundle-check";
|
|
10
|
+
import { installLocalChant, LocalChantError, productManifests, resetLocalChant, type LocalChantResult } from "../../local-chant";
|
|
11
|
+
import { formatError } from "../format";
|
|
12
|
+
import type { CommandContext } from "../registry";
|
|
13
|
+
|
|
14
|
+
const LOCAL_USAGE = "chant dev local <chant-dir> [--with <package>]... [--build '<command>'] [--json] | chant dev local --reset [--build '<command>']";
|
|
15
|
+
const CHECK_USAGE = "chant dev bundle-check [<package-dir>] [--json]";
|
|
16
|
+
|
|
17
|
+
/** The product packages that declare `chantBundleCheck`, as directories. */
|
|
18
|
+
function checkedPackages(productDir: string): string[] {
|
|
19
|
+
return productManifests(productDir)
|
|
20
|
+
.map((f) => join(productDir, f.replace(/\/?package\.json$/, "")))
|
|
21
|
+
.filter((d) => readBundleCheckConfig(d) !== undefined);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Run each package's bundle check and print the result; true when every one passes. */
|
|
25
|
+
function runChecks(dirs: string[], json: boolean): { ok: boolean; results: (BundleCheckResult & { dir: string })[] } {
|
|
26
|
+
const results = dirs.map((dir) => ({ dir, ...checkBundle(dir, readBundleCheckConfig(dir)!) }));
|
|
27
|
+
if (!json) {
|
|
28
|
+
for (const r of results) {
|
|
29
|
+
if (r.ok) console.error(` bundle-check: ${r.summary}`);
|
|
30
|
+
else console.error(`bundle-check: ${r.dir}\n ${r.problems.join("\n ")}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { ok: results.every((r) => r.ok), results };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The product's build, as one shell command in its root. */
|
|
37
|
+
function runBuild(command: string, cwd: string): boolean {
|
|
38
|
+
console.error(`chant dev local: ${command}`);
|
|
39
|
+
const r = spawnSync("sh", ["-c", command], { cwd, stdio: "inherit" });
|
|
40
|
+
return r.status === 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `chant dev local <chant-dir>`: pack the checkout and install it into the
|
|
45
|
+
* product in the current directory (`installLocalChant`), run `--build`, then
|
|
46
|
+
* the bundle check of every package that declares `chantBundleCheck`.
|
|
47
|
+
* `--reset` goes back to the lock's pins the same way. Exit 1 when a step
|
|
48
|
+
* fails, 2 for a usage error.
|
|
49
|
+
*/
|
|
50
|
+
export async function runDevLocal(ctx: CommandContext): Promise<number> {
|
|
51
|
+
const productDir = process.cwd();
|
|
52
|
+
const reset = ctx.args.reset === true;
|
|
53
|
+
const chantDir = ctx.args.extraPositional;
|
|
54
|
+
if (reset === (chantDir !== undefined)) {
|
|
55
|
+
console.error(formatError({ message: reset ? "--reset takes no chant directory" : "chant dev local needs a chant checkout", hint: LOCAL_USAGE }));
|
|
56
|
+
return 2;
|
|
57
|
+
}
|
|
58
|
+
let installed: LocalChantResult | undefined;
|
|
59
|
+
try {
|
|
60
|
+
if (reset) resetLocalChant({ productDir });
|
|
61
|
+
else installed = installLocalChant({ productDir, chantDir: resolve(chantDir!), with: ctx.args.withPackages });
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (!(err instanceof LocalChantError)) throw err;
|
|
64
|
+
console.error(formatError({ message: err.message }));
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
if (ctx.args.buildCommand && !runBuild(ctx.args.buildCommand, productDir)) {
|
|
68
|
+
console.error(formatError({ message: `the build failed: ${ctx.args.buildCommand}` }));
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
const dirs = checkedPackages(productDir);
|
|
72
|
+
if (!dirs.length) console.error("chant dev local: no package declares chantBundleCheck, so no bundle was checked");
|
|
73
|
+
const { ok, results } = runChecks(dirs, ctx.args.json === true);
|
|
74
|
+
if (ctx.args.json) {
|
|
75
|
+
console.log(JSON.stringify({ reset, local: installed ? { commit: installed.mark.commit, dir: installed.mark.dir, packed: installed.packed.map((p) => ({ name: p.name, version: p.version })), marked: installed.marked } : undefined, checks: results }, null, 2));
|
|
76
|
+
} else if (installed) {
|
|
77
|
+
console.log(`chant commit: ${installed.mark.commit}`);
|
|
78
|
+
}
|
|
79
|
+
return ok ? 0 : 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* `chant dev bundle-check [<package-dir>]`: check one package's bundle against
|
|
84
|
+
* its `chantBundleCheck`, or, with no directory, every package of the product
|
|
85
|
+
* in the current directory that declares one.
|
|
86
|
+
*/
|
|
87
|
+
export async function runDevBundleCheck(ctx: CommandContext): Promise<number> {
|
|
88
|
+
const dir = ctx.args.extraPositional;
|
|
89
|
+
let dirs: string[];
|
|
90
|
+
if (dir !== undefined) {
|
|
91
|
+
if (readBundleCheckConfig(resolve(dir)) === undefined) {
|
|
92
|
+
console.error(formatError({ message: `${join(dir, "package.json")} has no chantBundleCheck`, hint: CHECK_USAGE }));
|
|
93
|
+
return 2;
|
|
94
|
+
}
|
|
95
|
+
dirs = [resolve(dir)];
|
|
96
|
+
} else {
|
|
97
|
+
dirs = checkedPackages(process.cwd());
|
|
98
|
+
if (!dirs.length) {
|
|
99
|
+
console.error(formatError({ message: "no package here declares chantBundleCheck", hint: CHECK_USAGE }));
|
|
100
|
+
return 2;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const { ok, results } = runChecks(dirs, ctx.args.json === true);
|
|
104
|
+
if (ctx.args.json) console.log(JSON.stringify(results, null, 2));
|
|
105
|
+
return ok ? 0 : 1;
|
|
106
|
+
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* `loadProfiles` from the project's configured lexicons).
|
|
8
8
|
*/
|
|
9
9
|
import { lexiconNames } from "../../lexicon-module";
|
|
10
|
-
import { loadChantConfig } from "../../config";
|
|
10
|
+
import { loadChantConfig, resolveSourceDir } from "../../config";
|
|
11
11
|
import { build } from "../../build";
|
|
12
12
|
import { isObservableDeclarable } from "../../declarable";
|
|
13
13
|
import { collectBuildRootContributors, collectChangeSubscribers } from "../plugins";
|
|
@@ -88,7 +88,7 @@ async function collectOperatorSubscribers(
|
|
|
88
88
|
config as unknown as Record<string, unknown>,
|
|
89
89
|
cwd,
|
|
90
90
|
);
|
|
91
|
-
const buildResult = await build(config
|
|
91
|
+
const buildResult = await build(resolveSourceDir(cwd, config), ctx.serializers, undefined, { buildRoots });
|
|
92
92
|
if (buildResult.errors.length > 0) {
|
|
93
93
|
console.error(formatWarning({
|
|
94
94
|
message: "build failed while scoping the change signal, so this runs on the timer alone",
|