@intentius/chant 0.124.96 → 0.124.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit/core.d.ts +29 -0
- package/dist/audit/core.d.ts.map +1 -1
- package/dist/audit/core.js +48 -11
- package/dist/audit/identity.d.ts +27 -0
- package/dist/audit/identity.d.ts.map +1 -0
- package/dist/audit/identity.js +36 -0
- package/dist/audit/report-html.d.ts +3 -1
- package/dist/audit/report-html.d.ts.map +1 -1
- package/dist/audit/report-html.js +1 -1
- package/dist/audit/report-model.d.ts +16 -0
- package/dist/audit/report-model.d.ts.map +1 -1
- package/dist/audit/report-model.js +5 -1
- package/dist/change-set-graph.d.ts +3 -1
- package/dist/change-set-graph.d.ts.map +1 -1
- package/dist/change-set-graph.js +7 -1
- package/dist/change-set.d.ts +5 -2
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -3
- package/dist/ci-agent.d.ts +17 -0
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +32 -0
- package/dist/ci-comment-allow.d.ts +88 -0
- package/dist/ci-comment-allow.d.ts.map +1 -0
- package/dist/ci-comment-allow.js +178 -0
- package/dist/ci-comment-commands.d.ts +12 -0
- package/dist/ci-comment-commands.d.ts.map +1 -1
- package/dist/ci-comment-commands.js +22 -0
- package/dist/ci-control.d.ts +6 -1
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +6 -1
- package/dist/ci-product.d.ts +3 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +3 -0
- package/dist/cli/commands/audit.d.ts +3 -1
- package/dist/cli/commands/audit.d.ts.map +1 -1
- package/dist/cli/commands/audit.js +23 -6
- package/dist/cli/commands/import.d.ts +8 -1
- package/dist/cli/commands/import.d.ts.map +1 -1
- package/dist/cli/commands/import.js +31 -6
- package/dist/cli/handlers/agent.d.ts.map +1 -1
- package/dist/cli/handlers/agent.js +12 -2
- package/dist/cli/handlers/pr-comment.d.ts +6 -0
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
- package/dist/cli/handlers/pr-comment.js +12 -0
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +53 -6
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +29 -6
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +23 -0
- package/dist/cli/registry.d.ts +8 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/cloud-lister/mask.d.ts +30 -1
- package/dist/cloud-lister/mask.d.ts.map +1 -1
- package/dist/cloud-lister/mask.js +66 -3
- package/dist/components/driver.d.ts +8 -1
- package/dist/components/driver.d.ts.map +1 -1
- package/dist/components/driver.js +1 -0
- package/dist/components/product-pipeline.d.ts +23 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +40 -7
- package/dist/components/product-plan.d.ts +20 -0
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +11 -1
- package/dist/control/applied.d.ts +8 -1
- package/dist/control/applied.d.ts.map +1 -1
- package/dist/control/applied.js +18 -2
- package/dist/control/dispatch.d.ts +52 -0
- package/dist/control/dispatch.d.ts.map +1 -1
- package/dist/control/dispatch.js +140 -4
- package/dist/control/train.d.ts +198 -0
- package/dist/control/train.d.ts.map +1 -0
- package/dist/control/train.js +294 -0
- package/dist/deep-observation.js +2 -2
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +7 -1
- package/dist/graph-detail.d.ts +9 -0
- package/dist/graph-detail.d.ts.map +1 -1
- package/dist/graph-detail.js +38 -13
- package/dist/graph-refs.d.ts +233 -3
- package/dist/graph-refs.d.ts.map +1 -1
- package/dist/graph-refs.js +106 -15
- package/dist/lint/post-synth.d.ts +22 -0
- package/dist/lint/post-synth.d.ts.map +1 -1
- package/dist/lint/rules/declarable-naming-convention.d.ts +12 -0
- package/dist/lint/rules/declarable-naming-convention.d.ts.map +1 -1
- package/dist/lint/rules/declarable-naming-convention.js +38 -8
- package/dist/lint/rules/imported-source.d.ts +20 -0
- package/dist/lint/rules/imported-source.d.ts.map +1 -0
- package/dist/lint/rules/imported-source.js +27 -0
- package/dist/lint/rules/no-unused-declarable.d.ts.map +1 -1
- package/dist/lint/rules/no-unused-declarable.js +3 -0
- package/dist/op/gate.d.ts +2 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +8 -1
- package/dist/pr-forge-reads.d.ts +17 -0
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +55 -0
- package/dist/reconcile.d.ts +9 -0
- package/dist/reconcile.d.ts.map +1 -1
- package/dist/release-floors.d.ts +9 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +10 -2
- package/dist/repo-path.d.ts +29 -0
- package/dist/repo-path.d.ts.map +1 -0
- package/dist/repo-path.js +81 -0
- package/dist/sensitive-key.d.ts +23 -0
- package/dist/sensitive-key.d.ts.map +1 -1
- package/dist/sensitive-key.js +37 -0
- package/dist/terraform/hcl2json.d.ts +7 -0
- package/dist/terraform/hcl2json.d.ts.map +1 -1
- package/dist/terraform/hcl2json.js +7 -0
- package/dist/wave-runtime.mjs +352 -345
- package/dist/workspace/catalog-edges.d.ts +147 -0
- package/dist/workspace/catalog-edges.d.ts.map +1 -0
- package/dist/workspace/catalog-edges.js +461 -0
- package/dist/workspace/compose-graph.d.ts +73 -3
- package/dist/workspace/compose-graph.d.ts.map +1 -1
- package/dist/workspace/declaration.d.ts +2 -0
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +1 -0
- package/dist/workspace/declaration.schema.json +6 -0
- package/dist/workspace/discover.d.ts +134 -0
- package/dist/workspace/discover.d.ts.map +1 -0
- package/dist/workspace/discover.js +372 -0
- package/dist/workspace/graph-cli.d.ts +20 -0
- package/dist/workspace/graph-cli.d.ts.map +1 -1
- package/dist/workspace/graph-cli.js +178 -20
- package/dist/workspace/graph.schema.json +195 -2
- package/dist/workspace/release-train.d.ts +214 -3
- package/dist/workspace/release-train.d.ts.map +1 -1
- package/dist/workspace/release-train.js +552 -16
- package/dist/workspace/repo-ref.d.ts +14 -0
- package/dist/workspace/repo-ref.d.ts.map +1 -1
- package/dist/workspace/repo-ref.js +26 -1
- package/dist/workspace/workspace-gates.d.ts +24 -0
- package/dist/workspace/workspace-gates.d.ts.map +1 -1
- package/dist/workspace/workspace-gates.js +29 -5
- package/dist/workspace/workspace-ledger.d.ts +31 -5
- package/dist/workspace/workspace-ledger.d.ts.map +1 -1
- package/dist/workspace/workspace-ledger.js +2 -1
- package/dist/workspace/workspace-run.d.ts +14 -0
- package/dist/workspace/workspace-run.d.ts.map +1 -1
- package/dist/workspace/workspace-run.js +2 -2
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +33 -8
- package/package.json +1 -1
- package/src/audit/core.test.ts +64 -1
- package/src/audit/core.ts +75 -10
- package/src/audit/identity.test.ts +31 -0
- package/src/audit/identity.ts +43 -0
- package/src/audit/report-html.ts +4 -2
- package/src/audit/report-model.ts +21 -1
- package/src/change-set-graph.test.ts +33 -1
- package/src/change-set-graph.ts +7 -1
- package/src/change-set.ts +6 -3
- package/src/ci-agent.test.ts +32 -0
- package/src/ci-agent.ts +42 -0
- package/src/ci-comment-allow.test.ts +380 -0
- package/src/ci-comment-allow.ts +184 -0
- package/src/ci-comment-commands.ts +25 -0
- package/src/ci-control.ts +42 -0
- package/src/ci-product.ts +3 -0
- package/src/cli/commands/audit-parser-notice.test.ts +74 -0
- package/src/cli/commands/audit.test.ts +12 -0
- package/src/cli/commands/audit.ts +25 -7
- package/src/cli/commands/import-layout.test.ts +2 -1
- package/src/cli/commands/import.ts +29 -6
- package/src/cli/handlers/agent.ts +13 -2
- package/src/cli/handlers/pr-before-merge.test.ts +18 -0
- package/src/cli/handlers/pr-comment.ts +12 -0
- package/src/cli/handlers/promote.test.ts +68 -0
- package/src/cli/handlers/promote.ts +52 -6
- package/src/cli/main.test.ts +5 -0
- package/src/cli/main.ts +29 -6
- package/src/cli/parse-args.ts +18 -0
- package/src/cli/registry.ts +8 -0
- package/src/cloud-lister/kubernetes.k3d.e2e.test.ts +104 -0
- package/src/cloud-lister/mask-references.test.ts +132 -0
- package/src/cloud-lister/mask.ts +68 -3
- package/src/components/driver.ts +9 -1
- package/src/components/product-pipeline.ts +57 -7
- package/src/components/product-plan.ts +27 -2
- package/src/control/applied.ts +33 -3
- package/src/control/dispatch.ts +156 -5
- package/src/control/train.test.ts +215 -0
- package/src/control/train.ts +413 -0
- package/src/deep-observation.ts +2 -2
- package/src/floor-table.data.ts +7 -1
- package/src/graph-detail.ts +37 -12
- package/src/graph-refs.test.ts +45 -1
- package/src/graph-refs.ts +321 -14
- package/src/lint/post-synth.ts +20 -0
- package/src/lint/rules/declarable-naming-convention.test.ts +35 -1
- package/src/lint/rules/declarable-naming-convention.ts +35 -8
- package/src/lint/rules/imported-source.test.ts +22 -0
- package/src/lint/rules/imported-source.ts +31 -0
- package/src/lint/rules/no-unused-declarable.test.ts +16 -0
- package/src/lint/rules/no-unused-declarable.ts +7 -0
- package/src/op/gate.ts +10 -2
- package/src/pr-forge-reads.ts +62 -0
- package/src/reconcile.ts +9 -0
- package/src/release-floors.ts +14 -2
- package/src/repo-path.test.ts +72 -0
- package/src/repo-path.ts +103 -0
- package/src/sensitive-key.ts +38 -0
- package/src/terraform/hcl2json.ts +8 -0
- package/src/workspace/application-set.e2e.test.ts +405 -0
- package/src/workspace/catalog-edges.ts +507 -0
- package/src/workspace/ci-green-workflow.test.ts +2 -2
- package/src/workspace/cluster-join.e2e.test.ts +150 -0
- package/src/workspace/compose-graph.ts +74 -5
- package/src/workspace/declaration.schema.json +6 -0
- package/src/workspace/declaration.ts +3 -0
- package/src/workspace/discover.e2e.test.ts +122 -0
- package/src/workspace/discover.test.ts +225 -0
- package/src/workspace/discover.ts +406 -0
- package/src/workspace/drift-reader.test.ts +3 -3
- package/src/workspace/external-secret-catalog.e2e.test.ts +98 -0
- package/src/workspace/external-secret-catalog.test.ts +142 -0
- package/src/workspace/graph-cli.ts +207 -21
- package/src/workspace/graph-contract.test.ts +92 -0
- package/src/workspace/graph.schema.json +195 -2
- package/src/workspace/helm-references.e2e.test.ts +135 -0
- package/src/workspace/identity-annotation-catalog.e2e.test.ts +91 -0
- package/src/workspace/identity-annotation-catalog.test.ts +139 -0
- package/src/workspace/release-train-repos.test.ts +304 -0
- package/src/workspace/release-train.test.ts +296 -0
- package/src/workspace/release-train.ts +631 -16
- package/src/workspace/repo-ref.ts +26 -1
- package/src/workspace/runs-on.test.ts +45 -0
- package/src/workspace/workspace-gates.ts +48 -5
- package/src/workspace/workspace-ledger.ts +28 -5
- package/src/workspace/workspace-run.test.ts +1 -1
- package/src/workspace/workspace-run.ts +2 -2
- package/src/yaml.test.ts +96 -8
- package/src/yaml.ts +36 -8
|
@@ -70,6 +70,11 @@ export type RepoFetch = { ok: true; dir: string; worktree: string } | { ok: fals
|
|
|
70
70
|
|
|
71
71
|
const GIT_ENV = { ...process.env, GIT_TERMINAL_PROMPT: "0" };
|
|
72
72
|
|
|
73
|
+
/** The cache clone of one URL, as git is handed it. */
|
|
74
|
+
function cloneDirOf(url: string, env: NodeJS.ProcessEnv): string {
|
|
75
|
+
return join(repoCacheDir(env), createHash("sha256").update(url).digest("hex").slice(0, 24));
|
|
76
|
+
}
|
|
77
|
+
|
|
73
78
|
function git(args: string[], cwd?: string): { ok: boolean; out: string } {
|
|
74
79
|
try {
|
|
75
80
|
const out = execFileSync("git", args, { cwd, encoding: "utf-8", env: GIT_ENV, stdio: ["ignore", "pipe", "pipe"], timeout: 120_000 });
|
|
@@ -88,7 +93,7 @@ function git(args: string[], cwd?: string): { ok: boolean; out: string } {
|
|
|
88
93
|
export function fetchRepoAt(ref: RepoRef, workspaceRoot: string, env: NodeJS.ProcessEnv = process.env): RepoFetch {
|
|
89
94
|
if (urlCredential(ref.url)) return { ok: false, message: `the repo url carries a credential, which chant refuses to use (WSP016)` };
|
|
90
95
|
const url = fetchUrl(ref.url, workspaceRoot);
|
|
91
|
-
const clone =
|
|
96
|
+
const clone = cloneDirOf(url, env);
|
|
92
97
|
const worktree = join(clone, "at", ref.rev);
|
|
93
98
|
const dir = ref.workspace === "." ? worktree : join(worktree, ...ref.workspace.split("/"));
|
|
94
99
|
if (existsSync(join(worktree, ".git"))) return { ok: true, dir, worktree };
|
|
@@ -111,3 +116,23 @@ export function fetchRepoAt(ref: RepoRef, workspaceRoot: string, env: NodeJS.Pro
|
|
|
111
116
|
if (!add.ok && !existsSync(join(worktree, ".git"))) return { ok: false, message: `could not check out ${ref.rev} in the cache: ${add.out}` };
|
|
112
117
|
return { ok: true, dir, worktree };
|
|
113
118
|
}
|
|
119
|
+
|
|
120
|
+
/** The ledger branch a repository's releases are read from. */
|
|
121
|
+
const LIFECYCLE_BRANCH = "refs/heads/chant/lifecycle";
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Bring the repository's `chant/lifecycle` into the cache clone (#5119), so
|
|
125
|
+
* `chant release list` in a revision's worktree there reads that
|
|
126
|
+
* repository's releases. The ledger moves on its own, apart from the pinned
|
|
127
|
+
* revision, so it is fetched again on every call, forced, and only that
|
|
128
|
+
* branch. Run after {@link fetchRepoAt}, which makes the clone. Never
|
|
129
|
+
* throws; a failure says why.
|
|
130
|
+
*/
|
|
131
|
+
export function fetchRepoLifecycle(ref: RepoRef, workspaceRoot: string, env: NodeJS.ProcessEnv = process.env): { ok: true } | { ok: false; message: string } {
|
|
132
|
+
if (urlCredential(ref.url)) return { ok: false, message: `the repo url carries a credential, which chant refuses to use (WSP016)` };
|
|
133
|
+
const clone = cloneDirOf(fetchUrl(ref.url, workspaceRoot), env);
|
|
134
|
+
if (!existsSync(join(clone, ".git"))) return { ok: false, message: `${redactUrl(ref.url)} has no cache clone yet` };
|
|
135
|
+
const got = git(["-C", clone, "fetch", "-q", "--no-tags", "origin", `+${LIFECYCLE_BRANCH}:${LIFECYCLE_BRANCH}`]);
|
|
136
|
+
if (!got.ok) return { ok: false, message: `could not fetch chant/lifecycle from ${redactUrl(ref.url)}: ${got.out}` };
|
|
137
|
+
return { ok: true };
|
|
138
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `runsOn` on a member entry (#5101): the cluster resource the member runs
|
|
3
|
+
* on, read from the declaration, with `--runs-on` setting it for a discovered
|
|
4
|
+
* read.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, test } from "vitest";
|
|
7
|
+
import { parseArgs } from "../cli/parse-args";
|
|
8
|
+
import { parseDeclaration, WorkspaceReadError } from "./declaration";
|
|
9
|
+
|
|
10
|
+
const parse = (doc: unknown) => parseDeclaration(JSON.stringify(doc, null, 2), "chant.workspace.json");
|
|
11
|
+
|
|
12
|
+
describe("a member's runsOn", () => {
|
|
13
|
+
test("reads as the entry wrote it, and is null when the entry names none", () => {
|
|
14
|
+
const d = parse({
|
|
15
|
+
name: "acme",
|
|
16
|
+
schema: 1,
|
|
17
|
+
members: [
|
|
18
|
+
{ name: "argo", dir: "argo", kind: "other", because: "x", runsOn: "infra/google_container_cluster.prod" },
|
|
19
|
+
{ name: "infra", dir: "infra", kind: "other", because: "x" },
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
expect(d.members.map((m) => m.runsOn)).toEqual(["infra/google_container_cluster.prod", null]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("is refused without a member and an address, or with a space", () => {
|
|
26
|
+
for (const runsOn of ["google_container_cluster.prod", "infra/", "/x", "infra/a b", ""]) {
|
|
27
|
+
expect(() => parse({ name: "acme", schema: 1, members: [{ name: "argo", dir: "argo", kind: "other", because: "x", runsOn }] }), runsOn).toThrow(WorkspaceReadError);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("--runs-on", () => {
|
|
33
|
+
test("is repeatable and splits at the first =", () => {
|
|
34
|
+
expect(parseArgs(["workspace", "graph", "--discover", "--runs-on", "argo=infra/google_container_cluster.prod", "--runs-on", "web=infra/aws_eks_cluster.a"]).runsOn).toEqual({
|
|
35
|
+
argo: "infra/google_container_cluster.prod",
|
|
36
|
+
web: "infra/aws_eks_cluster.a",
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("needs a member and a target", () => {
|
|
41
|
+
for (const value of ["argo", "=infra/x.y", "argo="]) {
|
|
42
|
+
expect(() => parseArgs(["workspace", "graph", "--discover", "--runs-on", value]), value).toThrow(/--runs-on needs/);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
* `acceptWorkspaceGates: true`. A declaration read only from the working
|
|
20
20
|
* tree never opts a member in.
|
|
21
21
|
*
|
|
22
|
+
* A release train's promote (`chant workspace train promote --gate`, #4037)
|
|
23
|
+
* gathers each member's release gates before any member deploys: a cover
|
|
24
|
+
* then also names the member's `releaseDigest`, and its `planDigest` is the
|
|
25
|
+
* member's change set for the environment. The member's promote, started
|
|
26
|
+
* under the gate, asks the same rule from the release gate.
|
|
27
|
+
*
|
|
22
28
|
* A member run started under the gate (`CHANT_WORKSPACE_GATE`) asks this
|
|
23
29
|
* module through `GateCheckInput.workspace` after its own approvals have
|
|
24
30
|
* not passed the gate. Nothing is written to the member's gate ledger: the
|
|
@@ -38,6 +44,19 @@ export interface WorkspaceGateCover {
|
|
|
38
44
|
planDigest: string;
|
|
39
45
|
/** The member gate's environment, when it is bound to one. */
|
|
40
46
|
environment?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The release a member's release gate binds (#4037): set on the covers a
|
|
49
|
+
* release train's promote gathers, whose `planDigest` is that member's
|
|
50
|
+
* change set for the environment. A cover with it stands in only for a
|
|
51
|
+
* gate bound to the same release.
|
|
52
|
+
*/
|
|
53
|
+
releaseDigest?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The release train a workspace gate's fact was gathered for (#4037). */
|
|
57
|
+
export interface WorkspaceGateTrain {
|
|
58
|
+
id: string;
|
|
59
|
+
digest: string;
|
|
41
60
|
}
|
|
42
61
|
|
|
43
62
|
export interface WorkspaceGatePending {
|
|
@@ -49,6 +68,8 @@ export interface WorkspaceGatePending {
|
|
|
49
68
|
timestamp: string;
|
|
50
69
|
digest: string;
|
|
51
70
|
covers: WorkspaceGateCover[];
|
|
71
|
+
/** The train `chant workspace train promote --gate` gathered the covers for, or absent. */
|
|
72
|
+
train?: WorkspaceGateTrain;
|
|
52
73
|
}
|
|
53
74
|
|
|
54
75
|
export interface WorkspaceGateApproval {
|
|
@@ -60,15 +81,24 @@ export interface WorkspaceGateApproval {
|
|
|
60
81
|
approvedBy: string;
|
|
61
82
|
timestamp: string;
|
|
62
83
|
note?: string;
|
|
84
|
+
/** Copied from the pending fact it approves. */
|
|
85
|
+
train?: WorkspaceGateTrain;
|
|
63
86
|
}
|
|
64
87
|
|
|
65
88
|
export type WorkspaceGateLine = WorkspaceGatePending | WorkspaceGateApproval;
|
|
66
89
|
|
|
67
90
|
/** Covers in one order, so the same set always has the same digest. */
|
|
68
91
|
export function sortCovers(covers: readonly WorkspaceGateCover[]): WorkspaceGateCover[] {
|
|
69
|
-
const key = (c: WorkspaceGateCover) => `${c.member}\u0000${c.op}\u0000${c.gate}\u0000${c.environment ?? ""}\u0000${c.planDigest}`;
|
|
92
|
+
const key = (c: WorkspaceGateCover) => `${c.member}\u0000${c.op}\u0000${c.gate}\u0000${c.environment ?? ""}\u0000${c.planDigest}\u0000${c.releaseDigest ?? ""}`;
|
|
70
93
|
return [...covers]
|
|
71
|
-
.map((c) => ({
|
|
94
|
+
.map((c) => ({
|
|
95
|
+
member: c.member,
|
|
96
|
+
op: c.op,
|
|
97
|
+
gate: c.gate,
|
|
98
|
+
planDigest: c.planDigest,
|
|
99
|
+
...(c.environment !== undefined ? { environment: c.environment } : {}),
|
|
100
|
+
...(c.releaseDigest !== undefined ? { releaseDigest: c.releaseDigest } : {}),
|
|
101
|
+
}))
|
|
72
102
|
.sort((a, b) => (key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0));
|
|
73
103
|
}
|
|
74
104
|
|
|
@@ -83,6 +113,8 @@ export interface MemberGateQuery {
|
|
|
83
113
|
gate: string;
|
|
84
114
|
planDigest: string;
|
|
85
115
|
environment?: string;
|
|
116
|
+
/** Set on a release gate (#4037). */
|
|
117
|
+
releaseDigest?: string;
|
|
86
118
|
}
|
|
87
119
|
|
|
88
120
|
/**
|
|
@@ -102,7 +134,8 @@ export function workspaceGateStandsIn(
|
|
|
102
134
|
(c) =>
|
|
103
135
|
c.member === ctx.member && c.op === q.op && c.gate === q.gate &&
|
|
104
136
|
samePlanDigest(c.planDigest, q.planDigest) &&
|
|
105
|
-
(c.environment ?? null) === (q.environment ?? null)
|
|
137
|
+
(c.environment ?? null) === (q.environment ?? null) &&
|
|
138
|
+
(c.releaseDigest ?? null) === (q.releaseDigest ?? null),
|
|
106
139
|
),
|
|
107
140
|
);
|
|
108
141
|
return covering.sort((a, b) => (a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0)).at(-1) ?? null;
|
|
@@ -136,7 +169,16 @@ export async function readWorkspaceGate(cwd: string, gate: string): Promise<{ pe
|
|
|
136
169
|
|
|
137
170
|
export async function appendWorkspaceGatePending(cwd: string, input: Omit<WorkspaceGatePending, "version" | "kind" | "digest" | "covers"> & { covers: readonly WorkspaceGateCover[] }): Promise<WorkspaceGatePending> {
|
|
138
171
|
const covers = sortCovers(input.covers);
|
|
139
|
-
const record: WorkspaceGatePending = {
|
|
172
|
+
const record: WorkspaceGatePending = {
|
|
173
|
+
version: 1,
|
|
174
|
+
kind: "pending",
|
|
175
|
+
gate: input.gate,
|
|
176
|
+
run: input.run,
|
|
177
|
+
timestamp: input.timestamp,
|
|
178
|
+
digest: workspaceGateDigest(covers),
|
|
179
|
+
covers,
|
|
180
|
+
...(input.train ? { train: input.train } : {}),
|
|
181
|
+
};
|
|
140
182
|
await appendWorkspaceLine(cwd, WORKSPACE_GATES_DIR, fileFor(input.gate), record, `Workspace gate pending: ${input.gate}`);
|
|
141
183
|
return record;
|
|
142
184
|
}
|
|
@@ -156,7 +198,7 @@ export async function approveWorkspaceGate(
|
|
|
156
198
|
if (!fact) {
|
|
157
199
|
throw new Error(
|
|
158
200
|
input.digest === undefined
|
|
159
|
-
? `workspace gate "${input.gate}" has no pending fact to approve; a chant workspace run --gate ${input.gate} whose members stop at their gates records one`
|
|
201
|
+
? `workspace gate "${input.gate}" has no pending fact to approve; a chant workspace run --gate ${input.gate} whose members stop at their gates records one, as does a chant workspace train promote --gate ${input.gate}`
|
|
160
202
|
: `workspace gate "${input.gate}" has no pending fact with digest ${input.digest}`,
|
|
161
203
|
);
|
|
162
204
|
}
|
|
@@ -169,6 +211,7 @@ export async function approveWorkspaceGate(
|
|
|
169
211
|
approvedBy: input.approvedBy,
|
|
170
212
|
timestamp: input.timestamp,
|
|
171
213
|
...(input.note ? { note: input.note } : {}),
|
|
214
|
+
...(fact.train ? { train: fact.train } : {}),
|
|
172
215
|
};
|
|
173
216
|
await appendWorkspaceLine(cwd, WORKSPACE_GATES_DIR, fileFor(input.gate), record, `Workspace gate approval: ${input.gate}`);
|
|
174
217
|
return record;
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* Each names the member plans it covers and their digest
|
|
14
14
|
* (`./workspace-gates.ts`).
|
|
15
15
|
* - `<env>/trains.jsonl`: release trains, each pinning one release of every
|
|
16
|
-
* `chant` member (`./release-train.ts`).
|
|
16
|
+
* `chant` member, with a digest over those releases (`./release-train.ts`).
|
|
17
|
+
* A train's promote is a run in `<env>/runs.jsonl` that names the train.
|
|
17
18
|
*
|
|
18
19
|
* A malformed line is skipped and counted, never thrown on.
|
|
19
20
|
*/
|
|
@@ -81,8 +82,12 @@ export function canonicalDigest(value: unknown): string {
|
|
|
81
82
|
|
|
82
83
|
// ── Runs ─────────────────────────────────────────────────────────────────────
|
|
83
84
|
|
|
84
|
-
/**
|
|
85
|
-
|
|
85
|
+
/**
|
|
86
|
+
* How one `<member>/<op>` step of a workspace run ended. `dispatched` is a
|
|
87
|
+
* step of a train's promote across repositories (#5119) whose member
|
|
88
|
+
* repository was dispatched and has not answered yet.
|
|
89
|
+
*/
|
|
90
|
+
export type WorkspaceStepStatus = "ok" | "fail" | "gated" | "not-run" | "dispatched";
|
|
86
91
|
|
|
87
92
|
export interface WorkspaceRunStep {
|
|
88
93
|
/** `<member>/<op>`. */
|
|
@@ -96,6 +101,12 @@ export interface WorkspaceRunStep {
|
|
|
96
101
|
memberRun: string | null;
|
|
97
102
|
/** For a gated step: the member gate it stopped at and the plan it waits on. */
|
|
98
103
|
gate?: { op: string; name: string; planDigest: string | null; environment: string | null };
|
|
104
|
+
/** For a step run in another repository (#5119): that repository's URL. */
|
|
105
|
+
repo?: string;
|
|
106
|
+
/** For a step run in another repository: what its applied dispatch said, once it answered. */
|
|
107
|
+
outcome?: string;
|
|
108
|
+
/** For a step run in another repository: a step that did not pass, in a sentence. */
|
|
109
|
+
reason?: string;
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
export interface WorkspaceRunRecord {
|
|
@@ -103,8 +114,14 @@ export interface WorkspaceRunRecord {
|
|
|
103
114
|
id: string;
|
|
104
115
|
started: string;
|
|
105
116
|
ended: string;
|
|
106
|
-
/**
|
|
107
|
-
|
|
117
|
+
/**
|
|
118
|
+
* `gated` when a step stopped at a gate; `fail` when a step failed. A run
|
|
119
|
+
* stops at the first step that does not pass. `dispatched` is a train's
|
|
120
|
+
* promote across repositories (#5119) waiting on a member repository's
|
|
121
|
+
* answer: it is appended again, under the same id, as each member answers,
|
|
122
|
+
* and the newest line of an id is the run.
|
|
123
|
+
*/
|
|
124
|
+
status: "ok" | "fail" | "gated" | "dispatched";
|
|
108
125
|
/** `--env`, or null. */
|
|
109
126
|
env: string | null;
|
|
110
127
|
/** The workspace gate the run was started under (`--gate`), or null. */
|
|
@@ -112,6 +129,12 @@ export interface WorkspaceRunRecord {
|
|
|
112
129
|
/** `--dependents-of`, the member whose dependents the run ran, or null. */
|
|
113
130
|
dependentsOf: string | null;
|
|
114
131
|
steps: WorkspaceRunStep[];
|
|
132
|
+
/**
|
|
133
|
+
* The release train the run promoted (#4037), by id and digest: a run of
|
|
134
|
+
* `chant workspace train promote`, whose steps are each member's
|
|
135
|
+
* `components promote` of its release in the train. Absent on every other run.
|
|
136
|
+
*/
|
|
137
|
+
train?: { id: string; digest: string };
|
|
115
138
|
}
|
|
116
139
|
|
|
117
140
|
const RUNS_FILE = "runs.jsonl";
|
|
@@ -298,7 +298,7 @@ describe("release trains", () => {
|
|
|
298
298
|
|
|
299
299
|
test("refuses when any member has no release, so a train never leaves one out", () => {
|
|
300
300
|
const picked = pickTrain([{ member: "api", releases: [rel("api", "sha256:2", "v2")] }, { member: "web", releases: [] }], new Map([["ghost", "v1"]]));
|
|
301
|
-
expect(picked).toEqual({ problems: ["--pin ghost: not a chant member of the workspace", "member web has no release; cut one with chant release cut in its directory"] });
|
|
301
|
+
expect(picked).toEqual({ problems: ["--pin ghost: not a chant or repo member of the workspace", "member web has no release; cut one with chant release cut in its directory"] });
|
|
302
302
|
});
|
|
303
303
|
});
|
|
304
304
|
|
|
@@ -202,7 +202,7 @@ export type WorkspaceRunOutcome =
|
|
|
202
202
|
| { kind: "planned"; id: string; targets: string[]; skipped: WorkspaceRunSkip[] }
|
|
203
203
|
| { kind: "ran"; record: WorkspaceRunRecord; skipped: WorkspaceRunSkip[]; pending: WorkspaceGatePending | null; ledgerError: string | null };
|
|
204
204
|
|
|
205
|
-
async function defaultReadGraph(cwd: string): Promise<{ graph: WorkspaceGraph; failed: boolean } | { error: string }> {
|
|
205
|
+
export async function defaultReadGraph(cwd: string): Promise<{ graph: WorkspaceGraph; failed: boolean } | { error: string }> {
|
|
206
206
|
const { workspaceGraph } = await import("./graph-cli");
|
|
207
207
|
const { doc, failed } = await workspaceGraph({ cwd, onStderr: (t) => process.stderr.write(t) });
|
|
208
208
|
if ("error" in doc) return { error: `${doc.error.code}: ${doc.error.message}` };
|
|
@@ -213,7 +213,7 @@ async function defaultReadGraph(cwd: string): Promise<{ graph: WorkspaceGraph; f
|
|
|
213
213
|
* Run one member's `chant run`, under the member's own toolchain (the one
|
|
214
214
|
* `chant workspace graph` reads it with), from inside its directory.
|
|
215
215
|
*/
|
|
216
|
-
async function defaultRunMember(cwd: string, member: { name: string; dir: string }, argv: string[], env: Record<string, string>): Promise<MemberOpResult> {
|
|
216
|
+
export async function defaultRunMember(cwd: string, member: { name: string; dir: string }, argv: string[], env: Record<string, string>): Promise<MemberOpResult> {
|
|
217
217
|
const located = locateWorkspace(cwd);
|
|
218
218
|
const declaration = readDeclaration(located.tree, "", { rootChant: true });
|
|
219
219
|
const { registry: kinds } = loadKindRegistry(declaration.pins, located.rootOnDisk);
|
package/src/yaml.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
2
3
|
import { load as jsYamlLoad } from "js-yaml";
|
|
3
4
|
import { emitYAML, emitYAMLEntry, parseYAML, parseYAMLDocument, parseScalar, splitYAMLDocuments, YAMLParseError } from "./yaml";
|
|
4
5
|
|
|
@@ -112,27 +113,114 @@ describe("emitYAML", () => {
|
|
|
112
113
|
});
|
|
113
114
|
|
|
114
115
|
test("multiline string emits as | block scalar", () => {
|
|
115
|
-
const result = emitYAML("line1\nline2\nline3", 0);
|
|
116
|
+
const result = emitYAML("line1\nline2\nline3\n", 0);
|
|
116
117
|
expect(result).toBe("|\nline1\nline2\nline3");
|
|
117
118
|
});
|
|
118
119
|
|
|
119
|
-
test("
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
test("a string with exactly one final newline is a clipped block (#5073)", () => {
|
|
121
|
+
expect(emitYAML("line1\nline2\n", 0)).toBe("|\nline1\nline2");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("a string with no final newline is a stripped block (#5073)", () => {
|
|
125
|
+
expect(emitYAML("line1\nline2", 0)).toBe("|-\nline1\nline2");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("a string with several final newlines is a kept block (#5073)", () => {
|
|
129
|
+
expect(emitYAML({ k: "a\n\n\n" }, 0)).toBe("\nk: |+\n a\n \n ");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("a first line that starts with a space gets an indentation indicator (#5073)", () => {
|
|
133
|
+
expect(emitYAML({ k: " indented\nnext" }, 0)).toBe("\nk: |2-\n indented\n next");
|
|
123
134
|
});
|
|
124
135
|
|
|
125
136
|
test("multiline string inside object value is properly indented", () => {
|
|
126
|
-
const result = emitYAML({ config: "line1\nline2\nline3" }, 0);
|
|
137
|
+
const result = emitYAML({ config: "line1\nline2\nline3\n" }, 0);
|
|
127
138
|
expect(result).toContain("config: |\n line1\n line2\n line3");
|
|
128
139
|
});
|
|
129
140
|
|
|
130
141
|
test("multiline string inside array item is properly indented", () => {
|
|
131
|
-
const result = emitYAML([{ data: "a\nb" }], 0);
|
|
142
|
+
const result = emitYAML([{ data: "a\nb\n" }], 0);
|
|
132
143
|
expect(result).toContain("data: |\n a\n b");
|
|
133
144
|
});
|
|
134
145
|
});
|
|
135
146
|
|
|
147
|
+
describe("emitYAML multi-line strings read back unchanged (#5073)", () => {
|
|
148
|
+
const values = [
|
|
149
|
+
"a\nb",
|
|
150
|
+
"a\nb\n",
|
|
151
|
+
"a\nb\n\n",
|
|
152
|
+
"a\nb\n\n\n",
|
|
153
|
+
"a\n\nb",
|
|
154
|
+
"\na\nb",
|
|
155
|
+
"\n\na\n",
|
|
156
|
+
" lead\nb",
|
|
157
|
+
"\n lead\nb\n",
|
|
158
|
+
"a \nb ",
|
|
159
|
+
"a\n b\n",
|
|
160
|
+
"tab\there\nx",
|
|
161
|
+
"\n",
|
|
162
|
+
"\n\n",
|
|
163
|
+
"a\r\nb",
|
|
164
|
+
"a\u2028b\nc",
|
|
165
|
+
"key: value\n# not a comment\n- not a list",
|
|
166
|
+
];
|
|
167
|
+
for (const v of values) {
|
|
168
|
+
test(`${JSON.stringify(v)} through an object, an array item and the top level`, () => {
|
|
169
|
+
expect(jsYamlLoad(`k:${emitYAML({ k: v }, 0).slice(3)}\n`)).toEqual({ k: v });
|
|
170
|
+
expect(jsYamlLoad(emitYAML({ k: v }, 0).trimStart() + "\nz: 1\n")).toEqual({ k: v, z: 1 });
|
|
171
|
+
expect(jsYamlLoad(emitYAML([{ k: v, z: 1 }], 0).trimStart() + "\n")).toEqual([{ k: v, z: 1 }]);
|
|
172
|
+
expect(jsYamlLoad(emitYAML([v, "after"], 0).trimStart() + "\n")).toEqual([v, "after"]);
|
|
173
|
+
expect(parseYAML(emitYAML({ k: v, z: 1 }, 0).trimStart() + "\n")).toEqual({ k: v, z: 1 });
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Strings a YAML 1.1 parser reads as something else (#5074). A 1.2 parser (js-yaml)
|
|
179
|
+
// and a 1.1 parser (PyYAML, when python3 has it) must both give the string back.
|
|
180
|
+
const YAML_11_STRINGS = [
|
|
181
|
+
"=", "<<", "~", "y", "Y", "n", "N", "yes", "Yes", "YES", "no", "No", "NO",
|
|
182
|
+
"on", "On", "ON", "off", "Off", "OFF", "true", "True", "false", "False", "null", "Null",
|
|
183
|
+
"0755", "0o755", "0x1F", "0b101", "1:30", "190:20:30", "-1:30", "+1:30", "1_000", "1e3", "12", "1.5", ".5", "-.5",
|
|
184
|
+
".inf", "-.INF", ".nan", "2001-12-14", "2001-12-14 21:59:43.10 -5", "-", "?", ":", "- a", "? a", ": a",
|
|
185
|
+
"a: b", "a #b", "yes please", "on call", "=x", "<<x", "ok", "maybe", "nope", "o", "",
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
describe("emitYAML quotes the YAML 1.1 special scalars (#5074)", () => {
|
|
189
|
+
for (const v of YAML_11_STRINGS) {
|
|
190
|
+
test(`${JSON.stringify(v)} reads back as the same string under a 1.2 parser, in a mapping, a list and at the top`, () => {
|
|
191
|
+
expect(jsYamlLoad(`k: ${emitYAML(v, 0)}\n`)).toEqual({ k: v });
|
|
192
|
+
expect(jsYamlLoad(emitYAML([v], 0).trimStart() + "\n")).toEqual([v]);
|
|
193
|
+
expect(jsYamlLoad(emitYAML({ a: [{ k: v }] }, 0).trimStart() + "\n")).toEqual({ a: [{ k: v }] });
|
|
194
|
+
expect(parseYAML(`k: ${emitYAML(v, 0)}\n`).k).toBe(v);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
for (const v of ["=", "<<", "y", "n", "yes", "no", "on", "off", "0755", "1:30", "~"]) {
|
|
199
|
+
test(`${JSON.stringify(v)} is quoted`, () => {
|
|
200
|
+
expect(emitYAML(v, 0)).toBe(`'${v}'`);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
test("plain words that only look close stay plain", () => {
|
|
205
|
+
for (const v of ["ok", "yesterday", "online", "none", "o", "ny", "a=b", "x<<y"]) expect(emitYAML(v, 0)).toBe(v);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const py = spawnSync("python3", ["-I", "-c", "import yaml"], { encoding: "utf8" });
|
|
209
|
+
test.skipIf(py.status !== 0)("a YAML 1.1 parser (PyYAML) reads every one of them back unchanged", () => {
|
|
210
|
+
const doc = emitYAML(
|
|
211
|
+
Object.fromEntries(YAML_11_STRINGS.map((v, i) => [`k${i}`, v])) as Record<string, unknown>,
|
|
212
|
+
0,
|
|
213
|
+
).trimStart();
|
|
214
|
+
const out = spawnSync(
|
|
215
|
+
"python3",
|
|
216
|
+
["-I", "-c", "import sys, json, yaml; print(json.dumps(yaml.safe_load(sys.stdin.read())))"],
|
|
217
|
+
{ input: doc + "\n", encoding: "utf8" },
|
|
218
|
+
);
|
|
219
|
+
expect(out.stderr).toBe("");
|
|
220
|
+
expect(Object.values(JSON.parse(out.stdout))).toEqual(YAML_11_STRINGS);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
136
224
|
// ---------------------------------------------------------------------------
|
|
137
225
|
// parseYAML
|
|
138
226
|
// ---------------------------------------------------------------------------
|
|
@@ -894,6 +982,6 @@ describe("emitYAML quotes strings a parser would read as something else (#3006)"
|
|
|
894
982
|
}
|
|
895
983
|
|
|
896
984
|
test("strings that were safe stay plain", () => {
|
|
897
|
-
for (const v of ["--flag", "-x", "a:b", "http://a/b"
|
|
985
|
+
for (const v of ["--flag", "-x", "a:b", "http://a/b"]) expect(emitYAML(v, 0)).toBe(v);
|
|
898
986
|
});
|
|
899
987
|
});
|
package/src/yaml.ts
CHANGED
|
@@ -43,6 +43,14 @@ function definedEntries(obj: Record<string, unknown>): [string, unknown][] {
|
|
|
43
43
|
return Object.entries(obj).filter(([, val]) => val !== undefined);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/** A double-quoted scalar. JSON escapes are YAML escapes; the characters JSON leaves raw are escaped too. */
|
|
47
|
+
function doubleQuote(value: string): string {
|
|
48
|
+
return JSON.stringify(value).replace(
|
|
49
|
+
/[\x7f\x85\u2028\u2029\ufeff]/g,
|
|
50
|
+
(c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
export function emitYAML(value: unknown, indent: number): string {
|
|
47
55
|
const prefix = " ".repeat(indent);
|
|
48
56
|
|
|
@@ -64,12 +72,26 @@ export function emitYAML(value: unknown, indent: number): string {
|
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
if (typeof value === "string") {
|
|
67
|
-
// Multiline strings use YAML literal block scalar
|
|
75
|
+
// Multiline strings use a YAML literal block scalar. The chomping
|
|
76
|
+
// indicator carries the string's own ending (#5073): `|-` when it has no
|
|
77
|
+
// final newline, `|` for exactly one, `|+` for more.
|
|
68
78
|
if (value.includes("\n")) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
const body = value.replace(/\n+$/, "");
|
|
80
|
+
const finalNewlines = value.length - body.length;
|
|
81
|
+
// Text a literal block cannot carry faithfully (a string of only
|
|
82
|
+
// newlines, carriage returns, control characters, the Unicode line
|
|
83
|
+
// separators) is written double-quoted instead.
|
|
84
|
+
if (body.trim() === "" || /[\r\x00-\x08\x0b\x0c\x0e-\x1f\x7f\x85\u2028\u2029\ufeff]/.test(value)) {
|
|
85
|
+
return doubleQuote(value);
|
|
86
|
+
}
|
|
87
|
+
const chomp = finalNewlines === 0 ? "-" : finalNewlines === 1 ? "" : "+";
|
|
88
|
+
// A first line that starts with a space needs an explicit indentation
|
|
89
|
+
// indicator, relative to the parent node, which is always two columns.
|
|
90
|
+
const firstText = body.split("\n").find((l) => l !== "");
|
|
91
|
+
const indicator = firstText !== undefined && firstText.startsWith(" ") ? "2" : "";
|
|
92
|
+
const lines = body.split("\n");
|
|
93
|
+
for (let i = 1; i < finalNewlines; i++) lines.push("");
|
|
94
|
+
return `|${indicator}${chomp}\n` + lines.map((l) => `${prefix}${l}`).join("\n");
|
|
73
95
|
}
|
|
74
96
|
// Quote strings that could be misinterpreted
|
|
75
97
|
if (
|
|
@@ -77,8 +99,6 @@ export function emitYAML(value: unknown, indent: number): string {
|
|
|
77
99
|
value === "true" ||
|
|
78
100
|
value === "false" ||
|
|
79
101
|
value === "null" ||
|
|
80
|
-
value === "yes" ||
|
|
81
|
-
value === "no" ||
|
|
82
102
|
value.includes(": ") ||
|
|
83
103
|
value.includes("#") ||
|
|
84
104
|
value.startsWith("*") ||
|
|
@@ -95,7 +115,15 @@ export function emitYAML(value: unknown, indent: number): string {
|
|
|
95
115
|
// whitespace, a signed or dotted number, and the other spellings of
|
|
96
116
|
// booleans, null and the float constants (#3006).
|
|
97
117
|
/^[-?:](?:\s|$)|^[,\]}|>%@`]|:$|^\s|\s$|^[-+.]\d/.test(value) ||
|
|
98
|
-
/^(?:true|false|null|~|
|
|
118
|
+
/^(?:true|false|null|~|[-+]?\.(?:inf|nan))$/i.test(value) ||
|
|
119
|
+
// YAML 1.1 reads these as other types: its booleans `y`, `n`, `yes`,
|
|
120
|
+
// `no`, `on` and `off` in any case, the value indicator `=` (which a 1.1
|
|
121
|
+
// parser refuses outright), and the merge key `<<` (#5074). Octal-looking
|
|
122
|
+
// and sexagesimal numbers (`0755`, `1:30`) start with a digit and are
|
|
123
|
+
// quoted above.
|
|
124
|
+
/^(?:y|n|yes|no|on|off)$/i.test(value) ||
|
|
125
|
+
value === "=" ||
|
|
126
|
+
value === "<<"
|
|
99
127
|
) {
|
|
100
128
|
// Use single quotes, escaping internal single quotes
|
|
101
129
|
return `'${value.replace(/'/g, "''")}'`;
|