@intentius/chant 0.124.77 → 0.124.79
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/__fixtures__/notify-messages/events.d.ts +9 -0
- package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
- package/dist/__fixtures__/notify-messages/events.js +21 -0
- package/dist/__fixtures__/product-words.d.ts +14 -0
- package/dist/__fixtures__/product-words.d.ts.map +1 -1
- package/dist/__fixtures__/product-words.js +11 -0
- package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
- package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
- package/dist/__fixtures__/terragucci-notify.js +133 -0
- package/dist/action-pins.d.ts +8 -0
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +8 -0
- package/dist/agent-guard.d.ts.map +1 -1
- package/dist/agent-guard.js +1 -2
- package/dist/change-set.d.ts +10 -1
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +4 -1
- package/dist/ci-agent.d.ts +16 -2
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +6 -1
- package/dist/ci-commit.d.ts +66 -2
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +147 -19
- package/dist/ci-own-jobs.d.ts.map +1 -1
- package/dist/ci-own-jobs.js +1 -2
- package/dist/ci-product-words.d.ts +18 -4
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +26 -6
- package/dist/ci-product.d.ts +7 -3
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +8 -5
- package/dist/cli/handlers/release.d.ts +8 -0
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +68 -6
- package/dist/cli/handlers/run-wave.js +1 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +7 -0
- package/dist/cli/mcp/product-tools.d.ts +6 -0
- package/dist/cli/mcp/product-tools.d.ts.map +1 -1
- package/dist/cli/mcp/product-tools.js +7 -0
- package/dist/cli/mcp/read-only.d.ts +12 -0
- package/dist/cli/mcp/read-only.d.ts.map +1 -1
- package/dist/cli/mcp/read-only.js +16 -0
- package/dist/cli/mcp/server.d.ts +11 -0
- package/dist/cli/mcp/server.d.ts.map +1 -1
- package/dist/cli/mcp/server.js +26 -5
- package/dist/cli/mcp/types.d.ts +5 -1
- package/dist/cli/mcp/types.d.ts.map +1 -1
- package/dist/components/capability.d.ts +42 -0
- package/dist/components/capability.d.ts.map +1 -1
- package/dist/components/group-digest.d.ts +17 -0
- package/dist/components/group-digest.d.ts.map +1 -0
- package/dist/components/group-digest.js +18 -0
- package/dist/components/groups.d.ts +2 -11
- package/dist/components/groups.d.ts.map +1 -1
- package/dist/components/groups.js +2 -12
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/pr-env-components.d.ts.map +1 -1
- package/dist/components/pr-env-components.js +1 -2
- package/dist/config.d.ts +28 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +21 -1
- package/dist/lexicon.d.ts +8 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +8 -0
- package/dist/lifecycle/release-cut.d.ts +7 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +1 -0
- package/dist/lifecycle/release-images.d.ts +86 -3
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +131 -6
- package/dist/lifecycle/release-publish.d.ts +8 -1
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/lifecycle/release-publish.js +30 -3
- package/dist/lifecycle/release-version.d.ts +86 -0
- package/dist/lifecycle/release-version.d.ts.map +1 -0
- package/dist/lifecycle/release-version.js +209 -0
- package/dist/mcp/types.d.ts +26 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/notify-product.d.ts +11 -2
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +15 -4
- package/dist/notify-relay.d.ts.map +1 -1
- package/dist/notify-relay.js +1 -2
- package/dist/notify.d.ts +36 -4
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +31 -21
- package/dist/notify.schema.json +1 -0
- package/dist/op/activities/review-product.d.ts +111 -0
- package/dist/op/activities/review-product.d.ts.map +1 -0
- package/dist/op/activities/review-product.js +115 -0
- package/dist/op/gate.d.ts +17 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +36 -0
- package/dist/op/index.d.ts +8 -6
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +5 -4
- package/dist/op/op-waves-after-plan.d.ts +76 -1
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-after-plan.js +142 -3
- package/dist/op/op-waves-capability-spec.js +1 -2
- package/dist/op/op-waves-capability.d.ts +89 -2
- package/dist/op/op-waves-capability.d.ts.map +1 -1
- package/dist/op/op-waves-capability.js +215 -7
- package/dist/op/op-waves-run-hooks.d.ts +104 -0
- package/dist/op/op-waves-run-hooks.d.ts.map +1 -0
- package/dist/op/op-waves-run-hooks.js +146 -0
- package/dist/op/op-waves-run.d.ts +21 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +233 -13
- package/dist/op/op-waves.d.ts +11 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +7 -1
- package/dist/op/runtime.d.ts +2 -0
- package/dist/op/runtime.d.ts.map +1 -1
- package/dist/policy-engine.d.ts.map +1 -1
- package/dist/policy-engine.js +1 -2
- package/dist/pr-forge-reads.d.ts +124 -0
- package/dist/pr-forge-reads.d.ts.map +1 -0
- package/dist/pr-forge-reads.js +322 -0
- package/dist/pr-forge.d.ts +14 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +21 -13
- package/dist/pr-plan-note.d.ts +293 -0
- package/dist/pr-plan-note.d.ts.map +1 -0
- package/dist/pr-plan-note.js +361 -0
- package/dist/release-floors.d.ts +13 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +13 -1
- package/dist/state-export.d.ts.map +1 -1
- package/dist/state-export.js +1 -2
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +1 -2
- package/dist/state-unlock.d.ts.map +1 -1
- package/dist/state-unlock.js +1 -2
- package/dist/wave-runtime.mjs +314 -314
- package/dist/workspace/change-set.schema.json +7 -0
- package/dist/workspace/release-workflow.d.ts +7 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +13 -2
- package/package.json +1 -1
- package/src/__fixtures__/notify-messages/events.ts +23 -0
- package/src/__fixtures__/notify-messages/messages.json +50 -0
- package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
- package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
- package/src/__fixtures__/product-words.ts +12 -0
- package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
- package/src/__fixtures__/terragucci-notify.ts +170 -0
- package/src/action-pins.test.ts +11 -1
- package/src/action-pins.ts +9 -0
- package/src/agent-guard.test.ts +1 -2
- package/src/agent-guard.ts +1 -2
- package/src/change-set.test.ts +20 -0
- package/src/change-set.ts +11 -1
- package/src/ci-agent.test.ts +9 -0
- package/src/ci-agent.ts +15 -2
- package/src/ci-commit.test.ts +162 -0
- package/src/ci-commit.ts +167 -21
- package/src/ci-own-jobs.test.ts +1 -2
- package/src/ci-own-jobs.ts +1 -2
- package/src/ci-product-words.ts +35 -7
- package/src/ci-product.ts +9 -6
- package/src/cli/handlers/build-pr-loop-control.test.ts +1 -2
- package/src/cli/handlers/build-run-group.test.ts +1 -2
- package/src/cli/handlers/release.ts +60 -7
- package/src/cli/handlers/run-wave.ts +1 -0
- package/src/cli/main.ts +7 -0
- package/src/cli/mcp/product-tools.test.ts +50 -0
- package/src/cli/mcp/product-tools.ts +8 -0
- package/src/cli/mcp/read-only.ts +19 -0
- package/src/cli/mcp/server.test.ts +30 -0
- package/src/cli/mcp/server.ts +28 -5
- package/src/cli/mcp/types.ts +6 -1
- package/src/components/capability.ts +41 -0
- package/src/components/group-digest.ts +20 -0
- package/src/components/groups.ts +3 -13
- package/src/components/index.ts +2 -0
- package/src/components/pr-env-components.test.ts +1 -2
- package/src/components/pr-env-components.ts +1 -2
- package/src/config.ts +38 -3
- package/src/gate-policy-bundle.test.ts +1 -1
- package/src/lexicon.ts +9 -0
- package/src/lifecycle/release-cut.ts +11 -0
- package/src/lifecycle/release-images-dockerfile.test.ts +229 -0
- package/src/lifecycle/release-images.ts +171 -8
- package/src/lifecycle/release-publish.ts +34 -3
- package/src/lifecycle/release-version.test.ts +155 -0
- package/src/lifecycle/release-version.ts +227 -0
- package/src/mcp/types.ts +27 -0
- package/src/notify-message-words.test.ts +185 -0
- package/src/notify-product.ts +16 -4
- package/src/notify-relay.ts +1 -2
- package/src/notify.schema.json +1 -0
- package/src/notify.ts +59 -19
- package/src/op/activities/review-product.test.ts +116 -0
- package/src/op/activities/review-product.ts +199 -0
- package/src/op/gate.ts +46 -0
- package/src/op/index.ts +10 -4
- package/src/op/op-waves-after-plan-wave.test.ts +226 -0
- package/src/op/op-waves-after-plan.ts +170 -5
- package/src/op/op-waves-capability-spec.ts +1 -1
- package/src/op/op-waves-capability.test.ts +6 -0
- package/src/op/op-waves-capability.ts +243 -10
- package/src/op/op-waves-run-hooks.test.ts +184 -0
- package/src/op/op-waves-run-hooks.ts +195 -0
- package/src/op/op-waves-run.ts +240 -16
- package/src/op/op-waves-step-wave.test.ts +277 -0
- package/src/op/op-waves.ts +15 -2
- package/src/op/runtime.ts +2 -0
- package/src/op/schedule-overdue.test.ts +26 -0
- package/src/policy-engine.test.ts +1 -2
- package/src/policy-engine.ts +1 -2
- package/src/pr-forge-reads.test.ts +285 -0
- package/src/pr-forge-reads.ts +424 -0
- package/src/pr-forge.ts +30 -16
- package/src/pr-plan-note.test.ts +105 -0
- package/src/pr-plan-note.ts +520 -0
- package/src/release-floors.ts +19 -1
- package/src/state-export.test.ts +1 -2
- package/src/state-export.ts +1 -2
- package/src/state-migration.test.ts +1 -2
- package/src/state-migration.ts +1 -2
- package/src/state-unlock.test.ts +1 -2
- package/src/state-unlock.ts +1 -2
- package/src/workspace/change-set.schema.json +7 -0
- package/src/workspace/release-workflow.test.ts +18 -0
- package/src/workspace/release-workflow.ts +23 -2
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
|
|
42
42
|
import { execFileSync } from "node:child_process";
|
|
43
43
|
import type { Release } from "./release-store";
|
|
44
|
+
import { stampedChanges, type ReleaseVersionConfig } from "./release-version";
|
|
44
45
|
import { createRedactor, type Redactor } from "./publish-credentials";
|
|
45
46
|
|
|
46
47
|
/** Whether this run can sign provenance with an OIDC token, and why not when it can't. */
|
|
@@ -421,7 +422,10 @@ export async function preparePublish(req: {
|
|
|
421
422
|
}
|
|
422
423
|
// A target publishes files from this checkout, so they must be the release commit's (#4047).
|
|
423
424
|
if (targets.length > 0) {
|
|
424
|
-
|
|
425
|
+
// #4840: the files release.version names may carry the label, as the publish job's `chant release stamp` writes them.
|
|
426
|
+
const { loadChantConfig } = await import("../config");
|
|
427
|
+
const version = (await loadChantConfig(cwd)).config.release?.version;
|
|
428
|
+
const refused = checkCheckoutIsRelease(cwd, release.commit, name, version ? { version, label } : {});
|
|
425
429
|
if (refused) return { refusal: refused };
|
|
426
430
|
}
|
|
427
431
|
|
|
@@ -455,8 +459,16 @@ export async function preparePublish(req: {
|
|
|
455
459
|
* checkout is the release's commit with nothing changed, so a publish refuses
|
|
456
460
|
* a `HEAD` that is another commit and a tree with changes git sees. A publish
|
|
457
461
|
* with no target reads nothing and checks neither.
|
|
462
|
+
*
|
|
463
|
+
* Under `release.version` (#4840), a file it names that is exactly the
|
|
464
|
+
* commit's stamped with the release's label is the commit's too.
|
|
458
465
|
*/
|
|
459
|
-
export function checkCheckoutIsRelease(
|
|
466
|
+
export function checkCheckoutIsRelease(
|
|
467
|
+
cwd: string,
|
|
468
|
+
commit: string,
|
|
469
|
+
name: string,
|
|
470
|
+
o: { version?: ReleaseVersionConfig; label?: string | null } = {},
|
|
471
|
+
): PublishRefusal | null {
|
|
460
472
|
const head = tryGit(cwd, ["rev-parse", "HEAD"]);
|
|
461
473
|
if (head !== commit) {
|
|
462
474
|
return {
|
|
@@ -465,7 +477,8 @@ export function checkCheckoutIsRelease(cwd: string, commit: string, name: string
|
|
|
465
477
|
fix: `Check out the release's commit, as a CI job on its tag does: git checkout ${commit}`,
|
|
466
478
|
};
|
|
467
479
|
}
|
|
468
|
-
|
|
480
|
+
let status = tryGit(cwd, ["status", "--porcelain", "--untracked-files=normal"]);
|
|
481
|
+
if (status && o.version) status = withoutStamps(cwd, commit, o.version, o.label ?? null, status);
|
|
469
482
|
if (status) {
|
|
470
483
|
const n = status.split("\n").length;
|
|
471
484
|
return {
|
|
@@ -477,6 +490,24 @@ export function checkCheckoutIsRelease(cwd: string, commit: string, name: string
|
|
|
477
490
|
return null;
|
|
478
491
|
}
|
|
479
492
|
|
|
493
|
+
/** The porcelain status without the files {@link stampedChanges} takes as the commit's stamped with the label. */
|
|
494
|
+
function withoutStamps(cwd: string, commit: string, version: ReleaseVersionConfig, label: string | null, status: string): string {
|
|
495
|
+
let raw: string;
|
|
496
|
+
let top: string;
|
|
497
|
+
try {
|
|
498
|
+
raw = execFileSync("git", ["status", "--porcelain", "--untracked-files=normal"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
|
|
499
|
+
top = execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
500
|
+
} catch {
|
|
501
|
+
return status;
|
|
502
|
+
}
|
|
503
|
+
const stamped = stampedChanges({ cwd, top, commit, config: version, label, status: raw });
|
|
504
|
+
return raw
|
|
505
|
+
.split("\n")
|
|
506
|
+
.filter((l) => l.length > 0 && !stamped.has(l.slice(3)))
|
|
507
|
+
.join("\n")
|
|
508
|
+
.trim();
|
|
509
|
+
}
|
|
510
|
+
|
|
480
511
|
function tryGit(cwd: string, args: string[]): string | null {
|
|
481
512
|
try {
|
|
482
513
|
return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4840: `release.version` stamps the release's label into package.json at
|
|
3
|
+
* the cut and the publish, so a product needs no version-bump commit.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { afterAll, describe, expect, test } from "vitest";
|
|
7
|
+
import { readFileSync, rmSync } from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { cutRelease, ReleaseCutError } from "./release-cut";
|
|
10
|
+
import { checkCheckoutIsRelease } from "./release-publish";
|
|
11
|
+
import { checkVersionLabel, releaseVersionFiles, ReleaseVersionError, stampedChanges, stampReleaseVersion, stampText, type ReleaseVersionConfig } from "./release-version";
|
|
12
|
+
import type { CompiledTarget, TargetCompiler } from "../components/release-compile";
|
|
13
|
+
import { TestRepo } from "../workspace/trust/test-repo";
|
|
14
|
+
import { ChantConfigSchema } from "../config";
|
|
15
|
+
|
|
16
|
+
const repos: TestRepo[] = [];
|
|
17
|
+
afterAll(() => {
|
|
18
|
+
for (const r of repos) rmSync(dirname(r.dir), { recursive: true, force: true });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const PKG = `{\n "name": "@acme/cli",\n "version": "0.4.52",\n "dependencies": {\n "@intentius/chant": "0.124.77"\n }\n}\n`;
|
|
22
|
+
const ROOT = `{\n "name": "acme",\n "private": true,\n "workspaces": ["packages/*"]\n}\n`;
|
|
23
|
+
const LOCK = `{\n "name": "acme",\n "lockfileVersion": 3,\n "requires": true,\n "packages": {\n "": {\n "name": "acme",\n "workspaces": [\n "packages/*"\n ]\n },\n "packages/cli": {\n "name": "@acme/cli",\n "version": "0.4.52"\n },\n "node_modules/@acme/cli": {\n "resolved": "packages/cli",\n "link": true\n }\n }\n}\n`;
|
|
24
|
+
|
|
25
|
+
/** A workspace with one package, as terragucci's is, committed and green. */
|
|
26
|
+
function workspace(label: string): { r: TestRepo; head: string } {
|
|
27
|
+
const r = new TestRepo(label);
|
|
28
|
+
repos.push(r);
|
|
29
|
+
r.write("chant.config.ts", `export default { environments: ["dev"] };\n`);
|
|
30
|
+
r.write("package.json", ROOT);
|
|
31
|
+
r.write("package-lock.json", LOCK);
|
|
32
|
+
r.write("packages/cli/package.json", PKG);
|
|
33
|
+
const head = r.commit("init");
|
|
34
|
+
r.git(["tag", `ci/green/${head}`]);
|
|
35
|
+
return { r, head };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const CONFIG: ReleaseVersionConfig = { packages: ["packages/cli"] };
|
|
39
|
+
|
|
40
|
+
describe("stamping the label (#4840)", () => {
|
|
41
|
+
test("a package.json changes in its version alone, and a lockfile in the package's entry", () => {
|
|
42
|
+
expect(stampText(PKG, "0.4.53", "package")).toBe(PKG.replace(`"version": "0.4.52"`, `"version": "0.4.53"`));
|
|
43
|
+
expect(stampText(LOCK, "0.4.53", "lockfile", ["packages/cli"])).toBe(LOCK.replace(`"version": "0.4.52"`, `"version": "0.4.53"`));
|
|
44
|
+
// The member's own package: the root entry and the lockfile's top-level version.
|
|
45
|
+
const rootLock = `{\n "name": "yodel",\n "version": "0.12.1",\n "lockfileVersion": 3,\n "packages": {\n "": {\n "name": "yodel",\n "version": "0.12.1"\n }\n }\n}\n`;
|
|
46
|
+
expect(stampText(rootLock, "0.13.0", "lockfile", ["."])).toBe(rootLock.replaceAll("0.12.1", "0.13.0"));
|
|
47
|
+
// A tab-indented file keeps its tabs.
|
|
48
|
+
expect(stampText(`{\n\t"name": "a",\n\t"version": "1.0.0"\n}\n`, "1.0.1", "package")).toBe(`{\n\t"name": "a",\n\t"version": "1.0.1"\n}\n`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("the files are each package's package.json and the lockfile when there is one", () => {
|
|
52
|
+
const { r } = workspace("release-version-files");
|
|
53
|
+
expect(releaseVersionFiles(r.dir, CONFIG)).toEqual(["packages/cli/package.json", "package-lock.json"]);
|
|
54
|
+
expect(releaseVersionFiles(r.dir, { packages: ["."], lockfile: false })).toEqual(["package.json"]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("stamp, then restore, puts every file back byte for byte", () => {
|
|
58
|
+
const { r } = workspace("release-version-restore");
|
|
59
|
+
const s = stampReleaseVersion({ cwd: r.dir, config: CONFIG, label: "0.4.53" });
|
|
60
|
+
expect(JSON.parse(readFileSync(join(r.dir, "packages/cli/package.json"), "utf-8")).version).toBe("0.4.53");
|
|
61
|
+
expect(JSON.parse(readFileSync(join(r.dir, "package-lock.json"), "utf-8")).packages["packages/cli"].version).toBe("0.4.53");
|
|
62
|
+
s.restore();
|
|
63
|
+
expect(readFileSync(join(r.dir, "packages/cli/package.json"), "utf-8")).toBe(PKG);
|
|
64
|
+
expect(readFileSync(join(r.dir, "package-lock.json"), "utf-8")).toBe(LOCK);
|
|
65
|
+
expect(r.git(["status", "--porcelain"])).toBe("");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("a label npm can't take as a version, no label, and a missing package are refused before anything is written", () => {
|
|
69
|
+
expect(() => checkVersionLabel(null)).toThrow(ReleaseVersionError);
|
|
70
|
+
expect(() => checkVersionLabel("v1.4.0")).toThrow(/"v1.4.0" is not a version npm takes/);
|
|
71
|
+
expect((() => { try { checkVersionLabel("v1.4.0"); } catch (e) { return (e as ReleaseVersionError).fix; } })()).toBe("Label the release MAJOR.MINOR.PATCH, such as 1.4.0, with no v.");
|
|
72
|
+
expect(() => checkVersionLabel("1.4")).toThrow(/not a version/);
|
|
73
|
+
expect(() => checkVersionLabel("1.4.0-rc.1")).not.toThrow();
|
|
74
|
+
const { r } = workspace("release-version-refuse");
|
|
75
|
+
expect(() => stampReleaseVersion({ cwd: r.dir, config: { packages: ["packages/cli", "packages/nope"] }, label: "0.4.53" })).toThrow(/packages\/nope\/package.json, which does not exist/);
|
|
76
|
+
expect(r.git(["status", "--porcelain"])).toBe("");
|
|
77
|
+
expect(() => stampReleaseVersion({ cwd: r.dir, config: { packages: ["../other"] }, label: "0.4.53" })).toThrow(/not a path inside the member/);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("chant.config.ts takes release.version, and refuses a misspelt key", () => {
|
|
81
|
+
expect(ChantConfigSchema.safeParse({ release: { version: { packages: ["packages/cli"], lockfile: false } } }).success).toBe(true);
|
|
82
|
+
expect(ChantConfigSchema.safeParse({ release: { version: { package: ["packages/cli"] } } }).success).toBe(false);
|
|
83
|
+
expect(ChantConfigSchema.safeParse({ release: { version: { packages: [] } } }).success).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("the publish takes a stamped tree as the commit's (#4840)", () => {
|
|
88
|
+
test("only the named files, stamped with this release's label, pass the checkout check", () => {
|
|
89
|
+
const { r, head } = workspace("release-version-publish");
|
|
90
|
+
// Today's check, with no release.version: a stamped tree is dirty.
|
|
91
|
+
stampReleaseVersion({ cwd: r.dir, config: CONFIG, label: "0.4.53" });
|
|
92
|
+
expect(checkCheckoutIsRelease(r.dir, head, "0.4.53")?.code).toBe("release-worktree-dirty");
|
|
93
|
+
expect(checkCheckoutIsRelease(r.dir, head, "0.4.53", { version: CONFIG, label: "0.4.53" })).toBeNull();
|
|
94
|
+
// Another release's label is not this one's.
|
|
95
|
+
expect(checkCheckoutIsRelease(r.dir, head, "0.4.54", { version: CONFIG, label: "0.4.54" })?.code).toBe("release-worktree-dirty");
|
|
96
|
+
// Any other change in a stamped file, or another file changed, is still dirty.
|
|
97
|
+
r.write("README.md", "changed\n");
|
|
98
|
+
expect(checkCheckoutIsRelease(r.dir, head, "0.4.53", { version: CONFIG, label: "0.4.53" })?.code).toBe("release-worktree-dirty");
|
|
99
|
+
r.git(["checkout", "--", "."]);
|
|
100
|
+
r.git(["clean", "-fdq"]);
|
|
101
|
+
r.write("packages/cli/package.json", PKG.replace("0.4.52", "0.4.53").replace("0.124.77", "0.124.78"));
|
|
102
|
+
expect(stampedChanges({ cwd: r.dir, top: r.dir, commit: head, config: CONFIG, label: "0.4.53", status: r.git(["status", "--porcelain"]) }).size).toBe(0);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("the cut stamps after its clean-tree check and before it builds (#4840)", () => {
|
|
107
|
+
test("the images and the compile read the label from package.json, and the tree is the commit's after", async () => {
|
|
108
|
+
const { r } = workspace("release-version-cut");
|
|
109
|
+
const seen: string[] = [];
|
|
110
|
+
const version = () => JSON.parse(readFileSync(join(r.dir, "packages/cli/package.json"), "utf-8")).version as string;
|
|
111
|
+
const compiler: TargetCompiler = {
|
|
112
|
+
async compile(env): Promise<CompiledTarget> {
|
|
113
|
+
seen.push(`compile ${version()}`);
|
|
114
|
+
return { env, params: [], components: [], buildSteps: {}, buildInputs: {}, componentFiles: {}, templates: [{ component: null, path: "dist/out.json", content: "{}\n" }] };
|
|
115
|
+
},
|
|
116
|
+
async buildArtifacts() {
|
|
117
|
+
return [];
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
let stamped: ReturnType<typeof stampReleaseVersion> | null = null;
|
|
121
|
+
try {
|
|
122
|
+
await cutRelease({
|
|
123
|
+
cwd: r.dir,
|
|
124
|
+
compiler,
|
|
125
|
+
label: "0.4.53",
|
|
126
|
+
actor: "alice",
|
|
127
|
+
env: {},
|
|
128
|
+
now: () => new Date("2026-11-08T10:00:00.000Z"),
|
|
129
|
+
stamp: () => {
|
|
130
|
+
seen.push(`stamp ${version()}`);
|
|
131
|
+
stamped = stampReleaseVersion({ cwd: r.dir, config: CONFIG, label: "0.4.53" });
|
|
132
|
+
},
|
|
133
|
+
buildImages: () => {
|
|
134
|
+
seen.push(`images ${version()}`);
|
|
135
|
+
return [];
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
} finally {
|
|
139
|
+
(stamped as ReturnType<typeof stampReleaseVersion> | null)?.restore();
|
|
140
|
+
}
|
|
141
|
+
expect(seen).toEqual(["stamp 0.4.52", "images 0.4.53", "compile 0.4.53"]);
|
|
142
|
+
expect(r.git(["status", "--porcelain"])).toBe("");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("a dirty tree is refused before anything is stamped", async () => {
|
|
146
|
+
const { r } = workspace("release-version-cut-dirty");
|
|
147
|
+
r.write("packages/cli/package.json", PKG.replace("0.4.52", "9.9.9"));
|
|
148
|
+
let called = false;
|
|
149
|
+
const compiler: TargetCompiler = { async compile(env) { return { env, params: [], components: [], buildSteps: {}, buildInputs: {}, componentFiles: {}, templates: [] }; }, async buildArtifacts() { return []; } };
|
|
150
|
+
const err = await cutRelease({ cwd: r.dir, compiler, label: "0.4.53", actor: "alice", env: {}, stamp: () => { called = true; } }).catch((e: unknown) => e);
|
|
151
|
+
expect(err).toBeInstanceOf(ReleaseCutError);
|
|
152
|
+
expect((err as ReleaseCutError).code).toBe("release-worktree-dirty");
|
|
153
|
+
expect(called).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The release's label as the package version (#4840).
|
|
3
|
+
*
|
|
4
|
+
* A product released with `chant release cut <label>` used to set its
|
|
5
|
+
* version with a commit first, because the npm target publishes the
|
|
6
|
+
* package directory's `package.json`, the bundle imports the version from
|
|
7
|
+
* it, and `releaseImagePins` refuses a label that is not the version.
|
|
8
|
+
* `release.version` in `chant.config.ts` names the package directories
|
|
9
|
+
* whose `package.json` the release stamps with the label instead, and the
|
|
10
|
+
* lockfile whose entries for them follow:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* release: { version: { packages: ["packages/terragucci"] } },
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The cut stamps them after its clean-tree check and before it builds the
|
|
17
|
+
* images and runs the build, and puts the files back when it is done. The
|
|
18
|
+
* publish job runs `chant release stamp <label>` before its build, and
|
|
19
|
+
* `chant release publish` accepts a tree whose only changes are those files
|
|
20
|
+
* as the commit's own stamped with the release's label
|
|
21
|
+
* ({@link stampedChanges}). Only `version` changes: dependency ranges and
|
|
22
|
+
* every other field are left as committed. scripts/release-pack.sh does the
|
|
23
|
+
* same for chant itself, and more (the `@intentius/` ranges, the floors, the
|
|
24
|
+
* packing in dependency layers), so chant's own release keeps it.
|
|
25
|
+
*
|
|
26
|
+
* This module reaches only Node's built-ins and git.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { execFileSync } from "node:child_process";
|
|
30
|
+
import { existsSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
31
|
+
import { isAbsolute, posix, relative, resolve } from "node:path";
|
|
32
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
33
|
+
|
|
34
|
+
/** The first chant with `release.version` and `chant release stamp` (#4840). Products feature-detect on it. */
|
|
35
|
+
export const RELEASE_VERSION_FLOOR = NEXT_RELEASE;
|
|
36
|
+
|
|
37
|
+
/** `release.version` in `chant.config.ts`. */
|
|
38
|
+
export interface ReleaseVersionConfig {
|
|
39
|
+
/** The package directories, relative to the member, whose `package.json` takes the label as its `version`: `"."` for the member's own. */
|
|
40
|
+
packages: string[];
|
|
41
|
+
/** The lockfile whose entries for those packages take it too. Default `package-lock.json` when the member has one; `false` for none. */
|
|
42
|
+
lockfile?: string | false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class ReleaseVersionError extends Error {
|
|
46
|
+
constructor(
|
|
47
|
+
readonly code: string,
|
|
48
|
+
message: string,
|
|
49
|
+
readonly fix?: string,
|
|
50
|
+
) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = "ReleaseVersionError";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A version npm takes: MAJOR.MINOR.PATCH with an optional prerelease and build. */
|
|
57
|
+
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
58
|
+
|
|
59
|
+
/** Refuse a label `package.json` can't carry as its version. */
|
|
60
|
+
export function checkVersionLabel(label: string | null): asserts label is string {
|
|
61
|
+
if (label === null) {
|
|
62
|
+
throw new ReleaseVersionError("release-version-no-label", "release.version stamps the release's label into package.json, and this release has no label", "Cut it with a label: chant release cut <version>.");
|
|
63
|
+
}
|
|
64
|
+
if (!SEMVER.test(label)) {
|
|
65
|
+
throw new ReleaseVersionError(
|
|
66
|
+
"release-version-label-invalid",
|
|
67
|
+
`release.version stamps the label into package.json, and "${label}" is not a version npm takes`,
|
|
68
|
+
`Label the release MAJOR.MINOR.PATCH, such as ${SEMVER.test(label.replace(/^v/, "")) ? label.replace(/^v/, "") : "1.4.0"}${/^v\d/.test(label) ? ", with no v" : ""}.`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const norm = (p: string): string => posix.normalize(p.split("\\").join("/")).replace(/\/$/, "") || ".";
|
|
74
|
+
|
|
75
|
+
const outside = (p: string): boolean => isAbsolute(p) || norm(p).split("/").includes("..");
|
|
76
|
+
|
|
77
|
+
/** Check the declaration's paths: at least one package, every path inside the member. */
|
|
78
|
+
export function checkReleaseVersion(config: ReleaseVersionConfig): void {
|
|
79
|
+
if (config.packages.length === 0) throw new ReleaseVersionError("release-version-invalid", "release.version.packages names no package directory");
|
|
80
|
+
for (const p of [...config.packages, ...(typeof config.lockfile === "string" ? [config.lockfile] : [])]) {
|
|
81
|
+
if (outside(p)) throw new ReleaseVersionError("release-version-invalid", `release.version: ${p} is not a path inside the member`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The lockfile the declaration names, relative to the member, or null. */
|
|
86
|
+
function lockfileOf(cwd: string, config: ReleaseVersionConfig): string | null {
|
|
87
|
+
if (config.lockfile === false) return null;
|
|
88
|
+
if (typeof config.lockfile === "string") return norm(config.lockfile);
|
|
89
|
+
return existsSync(resolve(cwd, "package-lock.json")) ? "package-lock.json" : null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The files the release stamps, relative to the member: each package's `package.json`, then the lockfile. */
|
|
93
|
+
export function releaseVersionFiles(cwd: string, config: ReleaseVersionConfig): string[] {
|
|
94
|
+
const files = config.packages.map((p) => (norm(p) === "." ? "package.json" : `${norm(p)}/package.json`));
|
|
95
|
+
const lock = lockfileOf(cwd, config);
|
|
96
|
+
return lock ? [...files, lock] : files;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The indent a JSON file was written with, so the stamped file differs from it in the version alone. */
|
|
100
|
+
function indentOf(text: string): string {
|
|
101
|
+
return /^\{\r?\n([ \t]+)"/.exec(text)?.[1] ?? " ";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function rewrite(text: string, edit: (doc: Record<string, unknown>) => void): string {
|
|
105
|
+
const doc = JSON.parse(text) as Record<string, unknown>;
|
|
106
|
+
edit(doc);
|
|
107
|
+
const out = JSON.stringify(doc, null, indentOf(text));
|
|
108
|
+
return text.endsWith("\n") ? `${out}\n` : out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* One file's text stamped with `label`: a `package.json`'s `version`, or a
|
|
113
|
+
* lockfile's entries for `packageDirs` (relative to the lockfile's
|
|
114
|
+
* directory), with the root entry's `version` beside it for `"."`. A
|
|
115
|
+
* lockfile entry that is not there is not added.
|
|
116
|
+
*/
|
|
117
|
+
export function stampText(text: string, label: string, kind: "package" | "lockfile", packageDirs: readonly string[] = []): string {
|
|
118
|
+
if (kind === "package") {
|
|
119
|
+
return rewrite(text, (doc) => {
|
|
120
|
+
if (typeof doc.version !== "string") throw new ReleaseVersionError("release-version-no-package", "package.json has no version to stamp");
|
|
121
|
+
doc.version = label;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return rewrite(text, (doc) => {
|
|
125
|
+
const packages = (doc.packages ?? {}) as Record<string, { version?: unknown }>;
|
|
126
|
+
for (const dir of packageDirs) {
|
|
127
|
+
const key = dir === "." ? "" : dir;
|
|
128
|
+
const entry = packages[key];
|
|
129
|
+
if (entry && typeof entry === "object" && typeof entry.version === "string") entry.version = label;
|
|
130
|
+
if (key === "" && typeof doc.version === "string") doc.version = label;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Each stamped file's text, given its committed text. */
|
|
136
|
+
function stamper(cwd: string, config: ReleaseVersionConfig, label: string): (file: string, text: string) => string {
|
|
137
|
+
const lock = lockfileOf(cwd, config);
|
|
138
|
+
const lockDir = lock ? posix.dirname(lock) : ".";
|
|
139
|
+
const dirs = config.packages.map((p) => norm(posix.relative(lockDir, norm(p))) || ".");
|
|
140
|
+
return (file, text) => (file === lock ? stampText(text, label, "lockfile", dirs) : stampText(text, label, "package"));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface Stamped {
|
|
144
|
+
/** The files stamped, relative to the member. */
|
|
145
|
+
files: string[];
|
|
146
|
+
/** Put every stamped file back as it was. */
|
|
147
|
+
restore(): void;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Stamp the label into each file {@link releaseVersionFiles} names, and
|
|
152
|
+
* return how to put them back. Refuses a label that is not a version and a
|
|
153
|
+
* package directory with no `package.json`, before anything is written.
|
|
154
|
+
*/
|
|
155
|
+
export function stampReleaseVersion(i: { cwd: string; config: ReleaseVersionConfig; label: string | null }): Stamped {
|
|
156
|
+
checkReleaseVersion(i.config);
|
|
157
|
+
checkVersionLabel(i.label);
|
|
158
|
+
const stamp = stamper(i.cwd, i.config, i.label);
|
|
159
|
+
const files = releaseVersionFiles(i.cwd, i.config);
|
|
160
|
+
const before = new Map<string, string>();
|
|
161
|
+
for (const f of files) {
|
|
162
|
+
const abs = resolve(i.cwd, f);
|
|
163
|
+
if (!existsSync(abs)) throw new ReleaseVersionError("release-version-no-package", `release.version names ${f}, which does not exist`, "Name the directory that holds the package.json, as the npm target does.");
|
|
164
|
+
before.set(f, readFileSync(abs, "utf-8"));
|
|
165
|
+
}
|
|
166
|
+
const after = new Map<string, string>();
|
|
167
|
+
for (const [f, text] of before) {
|
|
168
|
+
try {
|
|
169
|
+
after.set(f, stamp(f, text));
|
|
170
|
+
} catch (err) {
|
|
171
|
+
if (err instanceof ReleaseVersionError) throw new ReleaseVersionError(err.code, `${f}: ${err.message}`);
|
|
172
|
+
throw new ReleaseVersionError("release-version-invalid", `${f} is not JSON: ${(err as Error).message}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const [f, text] of after) writeFileSync(resolve(i.cwd, f), text);
|
|
176
|
+
let restored = false;
|
|
177
|
+
return {
|
|
178
|
+
files,
|
|
179
|
+
restore() {
|
|
180
|
+
if (restored) return;
|
|
181
|
+
restored = true;
|
|
182
|
+
for (const [f, text] of before) writeFileSync(resolve(i.cwd, f), text);
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function gitShow(cwd: string, commit: string, file: string): string | null {
|
|
188
|
+
try {
|
|
189
|
+
return execFileSync("git", ["show", `${commit}:./${file}`], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 256 * 1024 * 1024 });
|
|
190
|
+
} catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Of `git status --porcelain` lines, the paths (relative to the member)
|
|
197
|
+
* that are a stamped file whose text is exactly the commit's stamped with
|
|
198
|
+
* `label`. A publish takes those as the commit's (#4840); every other
|
|
199
|
+
* change still makes the tree dirty. `top` is the repository root the
|
|
200
|
+
* porcelain paths are relative to.
|
|
201
|
+
*/
|
|
202
|
+
export function stampedChanges(i: { cwd: string; top: string; commit: string; config: ReleaseVersionConfig; label: string | null; status: string }): Set<string> {
|
|
203
|
+
const out = new Set<string>();
|
|
204
|
+
if (i.label === null || !SEMVER.test(i.label)) return out;
|
|
205
|
+
const stamp = stamper(i.cwd, i.config, i.label);
|
|
206
|
+
const files = new Set(releaseVersionFiles(i.cwd, i.config));
|
|
207
|
+
// git prints the top as its real path (macOS's /private/var for /var).
|
|
208
|
+
const cwd = realpathSync(i.cwd);
|
|
209
|
+
const top = realpathSync(i.top);
|
|
210
|
+
for (const line of i.status.split("\n")) {
|
|
211
|
+
// Only a modified tracked file, " M" or "M ", can be a stamp.
|
|
212
|
+
if (!/^(?: M|M |MM) /.test(line)) continue;
|
|
213
|
+
const path = line.slice(3);
|
|
214
|
+
const rel = relative(cwd, resolve(top, path)).split("\\").join("/");
|
|
215
|
+
if (!files.has(rel)) continue;
|
|
216
|
+
const committed = gitShow(i.cwd, i.commit, rel);
|
|
217
|
+
if (committed === null) continue;
|
|
218
|
+
let expected: string;
|
|
219
|
+
try {
|
|
220
|
+
expected = stamp(rel, committed);
|
|
221
|
+
} catch {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (readFileSync(resolve(i.cwd, rel), "utf-8") === expected) out.add(path);
|
|
225
|
+
}
|
|
226
|
+
return out;
|
|
227
|
+
}
|
package/src/mcp/types.ts
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
* MCP contribution types for lexicon plugins.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* MCP's tool annotations (schema 2025-06-18 on), hints a client reads off
|
|
7
|
+
* `tools/list`. A client that gets none treats a tool as one that may change
|
|
8
|
+
* things and may destroy them.
|
|
9
|
+
*/
|
|
10
|
+
export interface ToolAnnotations {
|
|
11
|
+
/** A human-readable title. */
|
|
12
|
+
title?: string;
|
|
13
|
+
/** The tool changes nothing. */
|
|
14
|
+
readOnlyHint?: boolean;
|
|
15
|
+
/** The tool may destroy what it changes, when not read-only. MCP's default is true. */
|
|
16
|
+
destructiveHint?: boolean;
|
|
17
|
+
/** Calling the tool again with the same arguments changes nothing more. */
|
|
18
|
+
idempotentHint?: boolean;
|
|
19
|
+
/** The tool reaches entities outside a closed domain, such as the web. */
|
|
20
|
+
openWorldHint?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
export interface McpToolContribution {
|
|
6
24
|
name: string;
|
|
7
25
|
description: string;
|
|
@@ -27,6 +45,15 @@ export interface McpToolContribution {
|
|
|
27
45
|
* serves it as any other tool. Lexicon tools do not use it.
|
|
28
46
|
*/
|
|
29
47
|
forgeWrite?: true;
|
|
48
|
+
/**
|
|
49
|
+
* The tool's MCP annotations, listed in `tools/list` (chant#4823). chant
|
|
50
|
+
* sets `readOnlyHint` and `destructiveHint` from the declaration above,
|
|
51
|
+
* over what this says: `readOnly: true` lists `readOnlyHint: true,
|
|
52
|
+
* destructiveHint: false`, and `forgeWrite: true` lists `readOnlyHint:
|
|
53
|
+
* false, destructiveHint: false`. The other hints, and both on a tool that
|
|
54
|
+
* declares neither, are listed as given.
|
|
55
|
+
*/
|
|
56
|
+
annotations?: ToolAnnotations;
|
|
30
57
|
}
|
|
31
58
|
|
|
32
59
|
export interface McpResourceContribution {
|