@intentius/chant 0.124.62 → 0.124.64
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/cli/handlers/approve.d.ts +26 -0
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +167 -18
- package/dist/cli/handlers/plan.d.ts +10 -0
- package/dist/cli/handlers/plan.d.ts.map +1 -0
- package/dist/cli/handlers/plan.js +71 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +2 -1
- package/dist/cli/handlers/release.d.ts +11 -7
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +93 -20
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +48 -7
- package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
- package/dist/cli/mcp/workspace-tools.js +2 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +43 -0
- package/dist/cli/registry.d.ts +18 -2
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/config.d.ts +50 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/gate-decision.d.ts +1 -1
- package/dist/gate-decision.d.ts.map +1 -1
- package/dist/gate-decision.js +4 -2
- package/dist/gate-statement.schema.json +46 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
- package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
- package/dist/lifecycle/gate-ledger.d.ts +28 -5
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.js +6 -0
- package/dist/lifecycle/gate-seal.d.ts +59 -7
- package/dist/lifecycle/gate-seal.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.js +68 -15
- package/dist/lifecycle/gate-statement.d.ts +95 -0
- package/dist/lifecycle/gate-statement.d.ts.map +1 -0
- package/dist/lifecycle/gate-statement.js +110 -0
- package/dist/lifecycle/gate-webauthn.d.ts +79 -0
- package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
- package/dist/lifecycle/gate-webauthn.js +105 -0
- package/dist/lifecycle/git.d.ts +1 -1
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +24 -19
- package/dist/lifecycle/ledger-remote.d.ts +37 -0
- package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
- package/dist/lifecycle/ledger-remote.js +42 -0
- package/dist/lifecycle/plan-stale.d.ts +76 -0
- package/dist/lifecycle/plan-stale.d.ts.map +1 -0
- package/dist/lifecycle/plan-stale.js +120 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
- package/dist/lifecycle/publish-credentials.js +2 -0
- package/dist/lifecycle/publish-declaration.d.ts +107 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +110 -1
- package/dist/lifecycle/publish-forge.d.ts +5 -1
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +13 -4
- package/dist/lifecycle/publish-git-ssh.d.ts +82 -0
- package/dist/lifecycle/publish-git-ssh.d.ts.map +1 -0
- package/dist/lifecycle/publish-git-ssh.js +180 -0
- package/dist/lifecycle/publish-github.d.ts +69 -0
- package/dist/lifecycle/publish-github.d.ts.map +1 -0
- package/dist/lifecycle/publish-github.js +153 -0
- package/dist/lifecycle/publish-homebrew.d.ts +77 -0
- package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
- package/dist/lifecycle/publish-homebrew.js +265 -0
- package/dist/lifecycle/publish-marketplace.d.ts +85 -0
- package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
- package/dist/lifecycle/publish-marketplace.js +398 -0
- package/dist/lifecycle/publish-targets.d.ts +6 -0
- package/dist/lifecycle/publish-targets.d.ts.map +1 -1
- package/dist/lifecycle/publish-targets.js +15 -0
- package/dist/lifecycle/publish-tauri.d.ts +61 -0
- package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
- package/dist/lifecycle/publish-tauri.js +181 -0
- package/dist/lifecycle/release-cut.d.ts +51 -5
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +165 -16
- package/dist/lifecycle/release-publish.d.ts +18 -2
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/lifecycle/release-publish.js +5 -0
- package/dist/lifecycle/release-revocation.d.ts +4 -3
- package/dist/lifecycle/release-revocation.d.ts.map +1 -1
- package/dist/lifecycle/release-revocation.js +5 -4
- package/dist/lifecycle/release-store.d.ts +32 -0
- package/dist/lifecycle/release-store.d.ts.map +1 -1
- package/dist/lifecycle/release-store.js +11 -0
- package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
- package/dist/lifecycle/snapshot-store.js +17 -9
- package/dist/lifecycle/test-passkey.d.ts +25 -0
- package/dist/lifecycle/test-passkey.d.ts.map +1 -0
- package/dist/lifecycle/test-passkey.js +39 -0
- package/dist/notify.d.ts +23 -3
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +8 -2
- package/dist/notify.schema.json +12 -3
- package/dist/op/gate.d.ts +1 -1
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +2 -1
- package/dist/pr-forge.d.ts +20 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +87 -8
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +333 -331
- package/dist/workspace/ci-builds.d.ts +21 -0
- package/dist/workspace/ci-builds.d.ts.map +1 -1
- package/dist/workspace/ci-builds.js +14 -0
- package/dist/workspace/ci-green.d.ts +45 -2
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +123 -5
- package/dist/workspace/ci-quarantine-report.d.ts +80 -0
- package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
- package/dist/workspace/ci-quarantine-report.js +204 -0
- package/dist/workspace/ci-quarantine.d.ts +73 -0
- package/dist/workspace/ci-quarantine.d.ts.map +1 -0
- package/dist/workspace/ci-quarantine.js +170 -0
- package/dist/workspace/ci-serve.d.ts.map +1 -1
- package/dist/workspace/ci-serve.js +7 -4
- package/dist/workspace/class-data.d.ts +3 -1
- package/dist/workspace/class-data.d.ts.map +1 -1
- package/dist/workspace/class-data.js +4 -1
- package/dist/workspace/declaration.d.ts +45 -2
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +45 -2
- package/dist/workspace/declaration.schema.json +51 -3
- package/dist/workspace/forge-work.d.ts +76 -0
- package/dist/workspace/forge-work.d.ts.map +1 -0
- package/dist/workspace/forge-work.js +160 -0
- package/dist/workspace/identity-gate-rule.d.ts +3 -2
- package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
- package/dist/workspace/identity-gate-rule.js +5 -7
- package/dist/workspace/identity.d.ts +3 -2
- package/dist/workspace/identity.d.ts.map +1 -1
- package/dist/workspace/identity.js +6 -3
- package/dist/workspace/intent-cli.d.ts +3 -2
- package/dist/workspace/intent-cli.d.ts.map +1 -1
- package/dist/workspace/intent-cli.js +26 -5
- package/dist/workspace/intent-record.d.ts +3 -0
- package/dist/workspace/intent-record.d.ts.map +1 -1
- package/dist/workspace/intent-record.schema.json +32 -0
- package/dist/workspace/intent.d.ts +9 -0
- package/dist/workspace/intent.d.ts.map +1 -1
- package/dist/workspace/intent.js +2 -0
- package/dist/workspace/intent.schema.json +32 -0
- package/dist/workspace/kind-readers.d.ts.map +1 -1
- package/dist/workspace/kind-readers.js +2 -1
- package/dist/workspace/kinds.d.ts +6 -1
- package/dist/workspace/kinds.d.ts.map +1 -1
- package/dist/workspace/kinds.js +8 -3
- package/dist/workspace/plan-stale.schema.json +286 -0
- package/dist/workspace/release-candidates.d.ts +42 -7
- package/dist/workspace/release-candidates.d.ts.map +1 -1
- package/dist/workspace/release-candidates.js +64 -23
- package/dist/workspace/release-candidates.schema.json +55 -2
- package/dist/workspace/releases.schema.json +47 -0
- package/dist/workspace/trust/policy.d.ts +10 -0
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +19 -1
- package/dist/workspace/trust/run-commits.d.ts.map +1 -1
- package/dist/workspace/trust/run-commits.js +2 -1
- package/dist/workspace/trust/seal.d.ts.map +1 -1
- package/dist/workspace/trust/seal.js +34 -3
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +6 -1
- package/package.json +2 -1
- package/src/cli/handlers/approve-external-signature.test.ts +328 -0
- package/src/cli/handlers/approve.ts +206 -18
- package/src/cli/handlers/plan.ts +74 -0
- package/src/cli/handlers/pr.ts +2 -1
- package/src/cli/handlers/release.ts +84 -20
- package/src/cli/main.ts +48 -7
- package/src/cli/mcp/workspace-tools.ts +2 -1
- package/src/cli/parse-args.ts +33 -0
- package/src/cli/registry.ts +18 -2
- package/src/config.ts +8 -0
- package/src/gate-decision-bundle.test.ts +4 -2
- package/src/gate-decision.ts +11 -2
- package/src/gate-statement.schema.json +46 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
- package/src/lifecycle/gate-ledger.ts +34 -5
- package/src/lifecycle/gate-seal.ts +86 -15
- package/src/lifecycle/gate-statement.ts +144 -0
- package/src/lifecycle/gate-webauthn.test.ts +77 -0
- package/src/lifecycle/gate-webauthn.ts +133 -0
- package/src/lifecycle/git.ts +23 -19
- package/src/lifecycle/ledger-remote.test.ts +183 -0
- package/src/lifecycle/ledger-remote.ts +46 -0
- package/src/lifecycle/plan-stale.test.ts +149 -0
- package/src/lifecycle/plan-stale.ts +172 -0
- package/src/lifecycle/publish-credentials.ts +2 -0
- package/src/lifecycle/publish-declaration.ts +116 -1
- package/src/lifecycle/publish-forge.ts +14 -4
- package/src/lifecycle/publish-git-ssh.ts +202 -0
- package/src/lifecycle/publish-github.ts +174 -0
- package/src/lifecycle/publish-homebrew.test.ts +358 -0
- package/src/lifecycle/publish-homebrew.ts +283 -0
- package/src/lifecycle/publish-marketplace.test.ts +406 -0
- package/src/lifecycle/publish-marketplace.ts +421 -0
- package/src/lifecycle/publish-resume.test.ts +40 -0
- package/src/lifecycle/publish-target-context.test.ts +2 -2
- package/src/lifecycle/publish-targets.test.ts +23 -0
- package/src/lifecycle/publish-targets.ts +15 -0
- package/src/lifecycle/publish-tauri.test.ts +163 -0
- package/src/lifecycle/publish-tauri.ts +198 -0
- package/src/lifecycle/release-cut-lane.test.ts +177 -0
- package/src/lifecycle/release-cut-override.test.ts +213 -0
- package/src/lifecycle/release-cut.ts +198 -17
- package/src/lifecycle/release-publish.ts +23 -3
- package/src/lifecycle/release-revocation.ts +5 -4
- package/src/lifecycle/release-store.ts +44 -0
- package/src/lifecycle/snapshot-store.ts +16 -9
- package/src/lifecycle/test-passkey.ts +55 -0
- package/src/notify-bundle.test.ts +3 -1
- package/src/notify.schema.json +12 -3
- package/src/notify.ts +20 -3
- package/src/op/gate.ts +2 -1
- package/src/override-gate-bundle.test.ts +2 -0
- package/src/pr-forge-bundle.test.ts +2 -2
- package/src/pr-forge.test.ts +38 -0
- package/src/pr-forge.ts +93 -11
- package/src/pr-requires.test.ts +9 -0
- package/src/release-floors.ts +1 -1
- package/src/stage-hooks-bundle.test.ts +2 -0
- package/src/wave-runtime-bundle.test.ts +3 -2
- package/src/workspace/ci-builds.ts +27 -0
- package/src/workspace/ci-green-stale.test.ts +193 -0
- package/src/workspace/ci-green.ts +137 -6
- package/src/workspace/ci-quarantine-report.test.ts +145 -0
- package/src/workspace/ci-quarantine-report.ts +234 -0
- package/src/workspace/ci-quarantine.test.ts +160 -0
- package/src/workspace/ci-quarantine.ts +188 -0
- package/src/workspace/ci-serve.ts +7 -4
- package/src/workspace/class-data.ts +5 -1
- package/src/workspace/declaration.schema.json +51 -3
- package/src/workspace/declaration.test.ts +1 -0
- package/src/workspace/declaration.ts +88 -5
- package/src/workspace/forge-work.test.ts +143 -0
- package/src/workspace/forge-work.ts +195 -0
- package/src/workspace/identity-gate-rule.ts +6 -8
- package/src/workspace/identity.ts +6 -3
- package/src/workspace/intent-cli.ts +24 -5
- package/src/workspace/intent-record.schema.json +32 -0
- package/src/workspace/intent-record.ts +3 -0
- package/src/workspace/intent.schema.json +32 -0
- package/src/workspace/intent.ts +9 -0
- package/src/workspace/kind-readers.ts +2 -1
- package/src/workspace/kinds.test.ts +13 -0
- package/src/workspace/kinds.ts +12 -3
- package/src/workspace/plan-stale.schema.json +286 -0
- package/src/workspace/release-candidates.schema.json +55 -2
- package/src/workspace/release-candidates.test.ts +77 -4
- package/src/workspace/release-candidates.ts +80 -23
- package/src/workspace/releases.schema.json +47 -0
- package/src/workspace/trust/gate-seal.test.ts +44 -0
- package/src/workspace/trust/policy.ts +24 -1
- package/src/workspace/trust/run-commits.ts +2 -1
- package/src/workspace/trust/seal.ts +35 -3
- package/src/workspace/trust/trust-files.test.ts +5 -0
- package/src/workspace/trust/trust-files.ts +15 -1
|
@@ -333,7 +333,7 @@
|
|
|
333
333
|
"properties": {
|
|
334
334
|
"template": {
|
|
335
335
|
"type": "string",
|
|
336
|
-
"pattern": "^[a-z0-9][a-z0-9-]
|
|
336
|
+
"pattern": "^[a-z0-9][a-z0-9-]*(/[a-z0-9][a-z0-9-]*)?$",
|
|
337
337
|
"description": "The declared environment a pull request's environment is derived from: pr-<number> takes its endpoint unless a pr-* entry declares one."
|
|
338
338
|
},
|
|
339
339
|
"ttl": {
|
|
@@ -1907,13 +1907,61 @@
|
|
|
1907
1907
|
},
|
|
1908
1908
|
"notify": {
|
|
1909
1909
|
"type": "object",
|
|
1910
|
-
"description": "Who chant ci tick tells (#4645), as an Op waves spec's notify: each value names an environment variable, never a URL or a key. webhook and key: a signed chant.notify/v1 webhook; slack and teams: incoming webhooks; events: which to send, of ci.red, ci.culprit and ci.
|
|
1910
|
+
"description": "Who chant ci tick tells (#4645), as an Op waves spec's notify: each value names an environment variable, never a URL or a key. webhook and key: a signed chant.notify/v1 webhook; slack and teams: incoming webhooks; events: which to send, of ci.red, ci.culprit, ci.green and ci.quarantine-passed (all of them by default). ci.red: the branch's newest decided commit is red after its one retry. ci.culprit: a bisect named the first red commit. ci.green: the branch is green again after a ci.red. ci.quarantine-passed (#4677), from chant ci quarantine report rather than the tick: a quarantined test passed in the scheduled run, sent on every such run until its entry goes. The tick's events are each sent once: the tick marks it in the commit's _ci record, so it needs chant/lifecycle, and it sends nothing when it can't write the records. Read by chant 0.124.61 and newer, so a declaration that sets it sets minReader to 0.124.61 or newer. staleAfter adds ci.stale (#4678).",
|
|
1911
1911
|
"properties": {
|
|
1912
1912
|
"webhook": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
|
|
1913
1913
|
"key": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
|
|
1914
1914
|
"slack": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
|
|
1915
1915
|
"teams": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
|
|
1916
|
-
"events": { "type": "array", "uniqueItems": true, "items": { "enum": ["ci.red", "ci.culprit", "ci.green"] } }
|
|
1916
|
+
"events": { "type": "array", "uniqueItems": true, "items": { "enum": ["ci.red", "ci.culprit", "ci.green", "ci.quarantine-passed", "ci.stale"] } },
|
|
1917
|
+
"staleAfter": {
|
|
1918
|
+
"type": "number",
|
|
1919
|
+
"exclusiveMinimum": 0,
|
|
1920
|
+
"description": "Added by #4678. Hours the branch may go without a green commit before the tick sends ci.stale: when the oldest first-parent commit above the newest green one (ci/green, not revoked; lanes don't count) was committed this long ago. It names the tip, that commit (since), the green commit (lastGreen) and the whole hours. It is sent once per red stretch, marked in _ci/branch/<branch>.json on chant/lifecycle, and the stretch ends when a newer commit is green: the tick then sends ci.green naming since, or adds since to the ci.green it sends anyway. The generated chant-ci-green.yml ticks every 15 minutes on a schedule, so this fires when nothing else runs the tick. Unset, no ci.stale. Read by chant 0.124.63 and newer, so a declaration that sets staleAfter sets minReader to 0.124.63 or newer."
|
|
1921
|
+
}
|
|
1922
|
+
},
|
|
1923
|
+
"additionalProperties": false
|
|
1924
|
+
},
|
|
1925
|
+
"quarantine": {
|
|
1926
|
+
"type": "object",
|
|
1927
|
+
"required": ["phases"],
|
|
1928
|
+
"description": "Known-flaky tests the phases' runners leave out until they are fixed (#4677). Each entry names the test, the issue that tracks the fix, the last day it stays out (until) and why. Each phase's runner gets its filter from chant ci quarantine filter --phase <name> --runner nextest|playwright|list, and chant ci quarantine check fails, as filter does, when an entry is past its until or the until is more than maxDays from today. A scheduled run of the quarantined tests alone, which no phase's patterns match, tells whether one is fixed. Read by chant 0.124.63 and newer, so a declaration that sets it sets minReader to 0.124.63 or newer.",
|
|
1929
|
+
"properties": {
|
|
1930
|
+
"maxDays": {
|
|
1931
|
+
"type": "integer",
|
|
1932
|
+
"minimum": 1,
|
|
1933
|
+
"description": "How many days from today an entry's until may be, at most. 14 when absent."
|
|
1934
|
+
},
|
|
1935
|
+
"phases": {
|
|
1936
|
+
"type": "object",
|
|
1937
|
+
"minProperties": 1,
|
|
1938
|
+
"description": "The quarantined tests by phase. Each phase must be a declared phase.",
|
|
1939
|
+
"propertyNames": {
|
|
1940
|
+
"$ref": "#/$defs/ciPhaseName"
|
|
1941
|
+
},
|
|
1942
|
+
"additionalProperties": {
|
|
1943
|
+
"type": "array",
|
|
1944
|
+
"minItems": 1,
|
|
1945
|
+
"items": {
|
|
1946
|
+
"type": "object",
|
|
1947
|
+
"required": ["test", "issue", "until", "why"],
|
|
1948
|
+
"properties": {
|
|
1949
|
+
"test": { "type": "string", "minLength": 1, "description": "The test, as its runner names it. nextest: the binary id, a space and the test's name, as nextest prints them, or the test's name alone for any binary. Playwright: the test's title, with file set." },
|
|
1950
|
+
"file": { "type": "string", "minLength": 1, "description": "The file the test is in, from the runner's test directory: for Playwright the spec's path from testDir, as Playwright prints it." },
|
|
1951
|
+
"issue": { "type": "string", "pattern": "^(#?[0-9]+|https?://\\S+)$", "description": "The issue that tracks the fix: a number or a URL." },
|
|
1952
|
+
"until": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$", "description": "The last day the test stays out, YYYY-MM-DD, UTC." },
|
|
1953
|
+
"why": { "type": "string", "minLength": 1, "description": "One line: how it fails." }
|
|
1954
|
+
},
|
|
1955
|
+
"patternProperties": {
|
|
1956
|
+
"^x-": true
|
|
1957
|
+
},
|
|
1958
|
+
"additionalProperties": false
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
},
|
|
1963
|
+
"patternProperties": {
|
|
1964
|
+
"^x-": true
|
|
1917
1965
|
},
|
|
1918
1966
|
"additionalProperties": false
|
|
1919
1967
|
},
|
|
@@ -556,6 +556,7 @@ describe("ci.prEnvironment (#4298)", () => {
|
|
|
556
556
|
const members = [{ name: "api", dir: "api", kind: "chant" }];
|
|
557
557
|
|
|
558
558
|
test("is read with its template and a 72h TTL by default", () => {
|
|
559
|
+
expect(parse(base(members, { ci: { prEnvironment: { template: "shop/dev" } } })).ci?.prEnvironment?.template).toBe("shop/dev"); // a lexicon's own stack (plywood#64)
|
|
559
560
|
expect(parse(base(members, { ci: { prEnvironment: { template: "staging" } } })).ci?.prEnvironment).toEqual({ template: "staging", ttl: "72h" });
|
|
560
561
|
expect(parse(base(members, { ci: { prEnvironment: { template: "staging", ttl: "7d" } } })).ci?.prEnvironment).toEqual({ template: "staging", ttl: "7d" });
|
|
561
562
|
});
|
|
@@ -233,6 +233,9 @@ export function greenBranches(green: Pick<CiGreen, "branch" | "branches">): stri
|
|
|
233
233
|
return green.branches ?? [green.branch];
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
/** `ci.green.notify`: notify's settings, and the hours the branch may go without a green commit before `ci.stale` (#4678). */
|
|
237
|
+
export type CiNotify = NotifyConfig & { staleAfter?: number };
|
|
238
|
+
|
|
236
239
|
/** The default `ci.green.window`. */
|
|
237
240
|
export const DEFAULT_CI_WINDOW = "24h";
|
|
238
241
|
|
|
@@ -283,9 +286,11 @@ export interface CiGreen {
|
|
|
283
286
|
lanes?: CiLane[];
|
|
284
287
|
/**
|
|
285
288
|
* Who the tick tells (#4645): `ci.red`, `ci.culprit` and `ci.green`, sent
|
|
286
|
-
* through notify as Op waves send theirs
|
|
289
|
+
* through notify as Op waves send theirs; and who `ci quarantine report`
|
|
290
|
+
* tells `ci.quarantine-passed` (#4677). The tick also sends `ci.stale` after
|
|
291
|
+
* `staleAfter` hours without a green commit (#4678). Absent when the declaration sets none.
|
|
287
292
|
*/
|
|
288
|
-
notify?:
|
|
293
|
+
notify?: CiNotify;
|
|
289
294
|
/**
|
|
290
295
|
* The branch takes changes through GitHub's merge queue (#4644): `ci
|
|
291
296
|
* workflow` adds the `merge_group` trigger to the workflows holding a
|
|
@@ -293,7 +298,45 @@ export interface CiGreen {
|
|
|
293
298
|
* `chant-verdict` job the queue's ruleset requires. Absent when unset.
|
|
294
299
|
*/
|
|
295
300
|
mergeQueue?: true;
|
|
301
|
+
/**
|
|
302
|
+
* Known-flaky tests the phases' runners leave out (#4677), each with the
|
|
303
|
+
* issue tracking its fix and the day it comes back. Absent when the
|
|
304
|
+
* declaration names none.
|
|
305
|
+
*/
|
|
306
|
+
quarantine?: CiQuarantine;
|
|
307
|
+
pointer: string;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** The default `ci.green.quarantine.maxDays` (#4677): how far out an entry's `until` may be. */
|
|
311
|
+
export const DEFAULT_QUARANTINE_MAX_DAYS = 14;
|
|
312
|
+
|
|
313
|
+
/** `ci.green.quarantine` (#4677). */
|
|
314
|
+
export interface CiQuarantine {
|
|
315
|
+
/** How many days from today an entry's `until` may be, at most. */
|
|
316
|
+
maxDays: number;
|
|
317
|
+
/** Every entry, phase by phase, in file order. */
|
|
318
|
+
entries: CiQuarantineEntry[];
|
|
319
|
+
pointer: string;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* One quarantined test (#4677). `test` is the name the phase's runner gives
|
|
324
|
+
* it: for nextest the binary id, a space and the test's name, as nextest
|
|
325
|
+
* prints them; for Playwright the test's title, with `file` its spec's path
|
|
326
|
+
* from the project's testDir.
|
|
327
|
+
*/
|
|
328
|
+
export interface CiQuarantineEntry {
|
|
329
|
+
phase: string;
|
|
330
|
+
test: string;
|
|
331
|
+
file?: string;
|
|
332
|
+
/** The issue that tracks the fix: a number or a URL. */
|
|
333
|
+
issue: string;
|
|
334
|
+
/** The last day the test stays out, YYYY-MM-DD (UTC). */
|
|
335
|
+
until: string;
|
|
336
|
+
why: string;
|
|
296
337
|
pointer: string;
|
|
338
|
+
/** Where the entry is in the declaration's file, for messages about it. */
|
|
339
|
+
location: ErrorLocation;
|
|
297
340
|
}
|
|
298
341
|
|
|
299
342
|
/**
|
|
@@ -1412,7 +1455,7 @@ function cloudIdentityOf(raw: CloudIdentityDeclaration, at: (pointer: string, ke
|
|
|
1412
1455
|
|
|
1413
1456
|
function ciOf(raw: unknown, at: (pointer: string, key?: boolean) => ErrorLocation): CiDeclaration | null {
|
|
1414
1457
|
if (raw === undefined) return null;
|
|
1415
|
-
const block = raw as { reportUrl?: string; workflow?: CiWorkflow; hooks?: unknown; identity?: { cloud?: CloudIdentityDeclaration }; branches?: Record<string, string[]>; labels?: Record<string, string[]>; locks?: CiLocks; lockGrain?: CiLockGrain; policy?: unknown; prEnvironment?: { template: string; ttl?: string; teardown?: { name?: string; command: string[]; lexicons?: string[] } }; green?: { branch: string | string[]; window?: string; phases: Record<string, string[] | { runs: string[]; skipped?: CiSkipped; build?: CiBuild }>; require: string[]; preMerge?: string[]; signedSince?: string; source?: CiSource; lanes?: Record<string, { require: string[] }>; notify?:
|
|
1458
|
+
const block = raw as { reportUrl?: string; workflow?: CiWorkflow; hooks?: unknown; identity?: { cloud?: CloudIdentityDeclaration }; branches?: Record<string, string[]>; labels?: Record<string, string[]>; locks?: CiLocks; lockGrain?: CiLockGrain; policy?: unknown; prEnvironment?: { template: string; ttl?: string; teardown?: { name?: string; command: string[]; lexicons?: string[] } }; green?: { branch: string | string[]; window?: string; phases: Record<string, string[] | { runs: string[]; skipped?: CiSkipped; build?: CiBuild }>; require: string[]; preMerge?: string[]; signedSince?: string; source?: CiSource; lanes?: Record<string, { require: string[] }>; notify?: CiNotify; mergeQueue?: boolean; quarantine?: { maxDays?: number; phases: Record<string, { test: string; file?: string; issue: string; until: string; why: string }[]> } } };
|
|
1416
1459
|
const hooks = ciHooksOf(block.hooks, "/ci/hooks", at);
|
|
1417
1460
|
const policy = ciPolicyOf(block.policy, at);
|
|
1418
1461
|
const workflow = {
|
|
@@ -1487,11 +1530,51 @@ function ciOf(raw: unknown, at: (pointer: string, key?: boolean) => ErrorLocatio
|
|
|
1487
1530
|
return { name, require: [...l.require], pointer };
|
|
1488
1531
|
});
|
|
1489
1532
|
if (g.notify !== undefined) {
|
|
1490
|
-
|
|
1533
|
+
// staleAfter is the tick's own (#4678); the rest is notify's.
|
|
1534
|
+
const object = typeof g.notify === "object" && g.notify !== null && !Array.isArray(g.notify);
|
|
1535
|
+
const { staleAfter, ...config }: CiNotify = object ? g.notify : {};
|
|
1536
|
+
const problem = notifyConfigProblem(object ? config : g.notify, "ci.green.notify");
|
|
1491
1537
|
if (problem) throw new WorkspaceReadError("declaration-invalid", problem, at("/ci/green/notify"));
|
|
1538
|
+
if (staleAfter !== undefined && !(typeof staleAfter === "number" && Number.isFinite(staleAfter) && staleAfter > 0)) {
|
|
1539
|
+
throw new WorkspaceReadError("declaration-invalid", "ci.green.notify.staleAfter: a number of hours greater than 0", at("/ci/green/notify/staleAfter"));
|
|
1540
|
+
}
|
|
1492
1541
|
}
|
|
1542
|
+
const quarantine = g.quarantine !== undefined ? quarantineOf(g.quarantine, phases, at) : undefined;
|
|
1493
1543
|
const judged = Array.isArray(g.branch) ? g.branch : [g.branch];
|
|
1494
|
-
return { green: { branch: judged[0]!, ...(judged.length > 1 ? { branches: [...judged] } : {}), window: g.window ?? DEFAULT_CI_WINDOW, phases, require: [...g.require], ...(g.preMerge !== undefined ? { preMerge: [...g.preMerge] } : {}), signedSince: g.signedSince ?? null, source: g.source ?? "checks", ...(lanes.length > 0 ? { lanes } : {}), ...(g.notify !== undefined ? { notify: { ...g.notify, ...(g.notify.events ? { events: [...g.notify.events] } : {}) } } : {}), ...(g.mergeQueue === true ? { mergeQueue: true as const } : {}), pointer: "/ci/green" }, ...workflow, reportUrl };
|
|
1544
|
+
return { green: { branch: judged[0]!, ...(judged.length > 1 ? { branches: [...judged] } : {}), window: g.window ?? DEFAULT_CI_WINDOW, phases, require: [...g.require], ...(g.preMerge !== undefined ? { preMerge: [...g.preMerge] } : {}), signedSince: g.signedSince ?? null, source: g.source ?? "checks", ...(lanes.length > 0 ? { lanes } : {}), ...(g.notify !== undefined ? { notify: { ...g.notify, ...(g.notify.events ? { events: [...g.notify.events] } : {}) } } : {}), ...(g.mergeQueue === true ? { mergeQueue: true as const } : {}), ...(quarantine ? { quarantine } : {}), pointer: "/ci/green" }, ...workflow, reportUrl };
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
/** A YYYY-MM-DD that names a real day, as days since 1970-01-01 UTC, or null. */
|
|
1548
|
+
export function quarantineDay(s: string): number | null {
|
|
1549
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(s)) return null;
|
|
1550
|
+
const t = Date.parse(`${s}T00:00:00Z`);
|
|
1551
|
+
return Number.isNaN(t) || new Date(t).toISOString().slice(0, 10) !== s ? null : t / 86_400_000;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* `ci.green.quarantine` (#4677), checked for what holds on any day: each
|
|
1556
|
+
* phase is declared, each `until` is a real day, and no test is listed twice
|
|
1557
|
+
* in a phase. Whether an entry has expired depends on the day it is read,
|
|
1558
|
+
* so `chant ci quarantine check` and `filter` judge that, not the reader.
|
|
1559
|
+
*/
|
|
1560
|
+
function quarantineOf(raw: { maxDays?: number; phases: Record<string, { test: string; file?: string; issue: string; until: string; why: string }[]> }, phases: CiPhase[], at: (pointer: string, key?: boolean) => ErrorLocation): CiQuarantine {
|
|
1561
|
+
const entries: CiQuarantineEntry[] = [];
|
|
1562
|
+
for (const [phase, list] of Object.entries(raw.phases)) {
|
|
1563
|
+
const base = `/ci/green/quarantine/phases/${pointerToken(phase)}`;
|
|
1564
|
+
if (!phases.some((p) => p.name === phase)) {
|
|
1565
|
+
throw new WorkspaceReadError("declaration-invalid", `ci.green.quarantine.phases names the phase ${JSON.stringify(phase)}, which ci.green.phases does not declare; declared phases: ${phases.map((p) => p.name).join(", ")}`, at(base, true));
|
|
1566
|
+
}
|
|
1567
|
+
const seen = new Set<string>();
|
|
1568
|
+
for (const [i, e] of list.entries()) {
|
|
1569
|
+
const pointer = `${base}/${i}`;
|
|
1570
|
+
if (quarantineDay(e.until) === null) throw new WorkspaceReadError("declaration-invalid", `ci.green.quarantine.phases.${phase}[${i}].until is not a day: ${JSON.stringify(e.until)} (YYYY-MM-DD)`, at(`${pointer}/until`));
|
|
1571
|
+
const key = JSON.stringify([e.file ?? null, e.test]);
|
|
1572
|
+
if (seen.has(key)) throw new WorkspaceReadError("declaration-invalid", `ci.green.quarantine.phases.${phase} lists ${e.file !== undefined ? `${e.file} ` : ""}${JSON.stringify(e.test)} twice`, at(pointer));
|
|
1573
|
+
seen.add(key);
|
|
1574
|
+
entries.push({ phase, test: e.test, ...(e.file !== undefined ? { file: e.file } : {}), issue: e.issue, until: e.until, why: e.why, pointer, location: at(pointer) });
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
return { maxDays: raw.maxDays ?? DEFAULT_QUARANTINE_MAX_DAYS, entries, pointer: "/ci/green/quarantine" };
|
|
1495
1578
|
}
|
|
1496
1579
|
|
|
1497
1580
|
function agentsOf(raw: unknown, members: Member[], at: (pointer: string, key?: boolean) => ErrorLocation): AgentDeclaration[] {
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work items from the forge (#4649): which forge and token a read finds, one
|
|
3
|
+
* call per pull request, and an answer without the forge when it can't be
|
|
4
|
+
* read. Driven through a recording `fetch`; nothing here reaches a network.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
import type { ForgeFetch } from "../pr-forge";
|
|
9
|
+
import { forgeApiBase, forgeKindOfHost, forgeWorkReader, setCommitCloses } from "./forge-work";
|
|
10
|
+
|
|
11
|
+
/** A GitHub GraphQL endpoint that says pull request `n` closes `closes[n]`; any other is not found. */
|
|
12
|
+
function github(closes: Record<number, number[]>): { fetch: ForgeFetch; calls: { url: string; pr: number; auth: string | undefined }[] } {
|
|
13
|
+
const calls: { url: string; pr: number; auth: string | undefined }[] = [];
|
|
14
|
+
const fetch: ForgeFetch = async (url, init) => {
|
|
15
|
+
const pr = (JSON.parse(init.body ?? "{}") as { variables: { pr: number } }).variables.pr;
|
|
16
|
+
calls.push({ url, pr, auth: init.headers.Authorization });
|
|
17
|
+
const issues = closes[pr];
|
|
18
|
+
const body = issues
|
|
19
|
+
? { data: { repository: { pullRequest: { closingIssuesReferences: { nodes: issues.map((number) => ({ number, repository: { nameWithOwner: "acme/app" } })) } } } } }
|
|
20
|
+
: { data: { repository: { pullRequest: null } }, errors: [{ message: `Could not resolve to a PullRequest with the number of ${pr}.` }] };
|
|
21
|
+
return { ok: true, status: 200, text: async () => JSON.stringify(body) };
|
|
22
|
+
};
|
|
23
|
+
return { fetch, calls };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const top = "/nowhere";
|
|
27
|
+
const remoteUrl = "git@github.com:acme/app.git";
|
|
28
|
+
|
|
29
|
+
describe("forgeWorkReader", () => {
|
|
30
|
+
test("asks GitHub once per pull request, with the token the environment names", async () => {
|
|
31
|
+
const { fetch, calls } = github({ 12: [70, 71], 13: [] });
|
|
32
|
+
const reader = forgeWorkReader(top, { env: { GH_TOKEN: "t0k" }, remoteUrl, fetch });
|
|
33
|
+
expect(reader.source).toEqual({ kind: "github", host: "github.com", repo: "acme/app" });
|
|
34
|
+
const all = await reader.closesAll([12, 13, 12]);
|
|
35
|
+
expect(all.get(12)).toEqual({ resolved: true, issues: [70, 71], reason: null });
|
|
36
|
+
expect(all.get(13)).toEqual({ resolved: true, issues: [], reason: null });
|
|
37
|
+
expect(await reader.closes(12)).toEqual({ resolved: true, issues: [70, 71], reason: null });
|
|
38
|
+
expect(calls.map((c) => c.pr).sort()).toEqual([12, 13]);
|
|
39
|
+
expect(calls[0]).toMatchObject({ url: "https://api.github.com/graphql", auth: "Bearer t0k" });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("without a token every pull request is unresolved and the forge is never called", async () => {
|
|
43
|
+
const { fetch, calls } = github({ 12: [70] });
|
|
44
|
+
const reader = forgeWorkReader(top, { env: {}, remoteUrl, fetch, ghToken: () => undefined });
|
|
45
|
+
const got = await reader.closes(12);
|
|
46
|
+
expect(got).toMatchObject({ resolved: false, issues: [] });
|
|
47
|
+
expect(got.reason).toMatch(/^no token for github\.com: set CHANT_FORGE_TOKEN, CHANT_GITHUB_TOKEN, GH_TOKEN, GITHUB_TOKEN, or log in with gh auth login$/);
|
|
48
|
+
expect(calls).toEqual([]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("falls back to the token gh holds for the host", async () => {
|
|
52
|
+
const { fetch, calls } = github({ 12: [70] });
|
|
53
|
+
const hosts: string[] = [];
|
|
54
|
+
const reader = forgeWorkReader(top, { env: {}, remoteUrl: "https://ghe.github.acme.io/acme/app.git", fetch, ghToken: (h) => (hosts.push(h), "from-gh") });
|
|
55
|
+
expect(await reader.closes(12)).toMatchObject({ resolved: true, issues: [70] });
|
|
56
|
+
expect(hosts).toEqual(["ghe.github.acme.io"]);
|
|
57
|
+
expect(calls[0]).toMatchObject({ url: "https://ghe.github.acme.io/api/graphql", auth: "Bearer from-gh" });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("a pull request the forge doesn't know is unresolved, and the next is still asked", async () => {
|
|
61
|
+
const { fetch, calls } = github({ 13: [5] });
|
|
62
|
+
const reader = forgeWorkReader(top, { env: { GITHUB_TOKEN: "t" }, remoteUrl, fetch });
|
|
63
|
+
expect((await reader.closes(12)).reason).toMatch(/Could not resolve to a PullRequest/);
|
|
64
|
+
expect(await reader.closes(13)).toMatchObject({ resolved: true, issues: [5] });
|
|
65
|
+
expect(calls).toHaveLength(2);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("offline, the first failure answers the rest without another call", async () => {
|
|
69
|
+
let calls = 0;
|
|
70
|
+
const fetch: ForgeFetch = async () => {
|
|
71
|
+
calls++;
|
|
72
|
+
throw new TypeError("fetch failed");
|
|
73
|
+
};
|
|
74
|
+
const reader = forgeWorkReader(top, { env: { GITHUB_TOKEN: "t" }, remoteUrl, fetch });
|
|
75
|
+
const first = await reader.closes(12);
|
|
76
|
+
expect(first).toEqual({ resolved: false, issues: [], reason: "github.com could not be read: fetch failed" });
|
|
77
|
+
expect(await reader.closes(13)).toEqual(first);
|
|
78
|
+
expect(calls).toBe(1);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("a 401 stops the rest too", async () => {
|
|
82
|
+
let calls = 0;
|
|
83
|
+
const fetch: ForgeFetch = async () => (calls++, { ok: false, status: 401, text: async () => "Bad credentials" });
|
|
84
|
+
const reader = forgeWorkReader(top, { env: { GITHUB_TOKEN: "t" }, remoteUrl, fetch });
|
|
85
|
+
expect((await reader.closes(12)).reason).toMatch(/answered 401/);
|
|
86
|
+
expect((await reader.closes(13)).reason).toMatch(/answered 401/);
|
|
87
|
+
expect(calls).toBe(1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("a call that never answers times out", async () => {
|
|
91
|
+
const fetch: ForgeFetch = () => new Promise(() => {});
|
|
92
|
+
const reader = forgeWorkReader(top, { env: { GITHUB_TOKEN: "t" }, remoteUrl, fetch, timeoutMs: 20 });
|
|
93
|
+
expect(await reader.closes(12)).toMatchObject({ resolved: false, reason: "github.com could not be read: no answer in 0.02s" });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("an origin on no forge it knows, or none, is unresolved with why", async () => {
|
|
97
|
+
expect((await forgeWorkReader(top, { env: { GITHUB_TOKEN: "t" }, remoteUrl: "https://git.example.org/a/b.git" }).closes(1)).reason).toBe(
|
|
98
|
+
"origin (https://git.example.org/a/b.git) is not on a forge chant reads issues from: GitHub, GitLab or Forgejo",
|
|
99
|
+
);
|
|
100
|
+
const none = forgeWorkReader(top, { env: {}, remoteUrl: null });
|
|
101
|
+
expect(none.source).toBeNull();
|
|
102
|
+
expect((await none.closes(1)).reason).toBe("there is no origin remote to name the forge");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("in a CI job it reads the job's forge and repository", async () => {
|
|
106
|
+
const { fetch, calls } = github({ 3: [1] });
|
|
107
|
+
const reader = forgeWorkReader(top, { env: { GITHUB_ACTIONS: "true", GITHUB_REPOSITORY: "acme/app", GITHUB_TOKEN: "job" }, remoteUrl: "https://example.org/x/y", fetch });
|
|
108
|
+
expect(reader.source).toEqual({ kind: "github", host: "github.com", repo: "acme/app" });
|
|
109
|
+
expect(await reader.closes(3)).toMatchObject({ resolved: true, issues: [1] });
|
|
110
|
+
expect(calls[0].auth).toBe("Bearer job");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("GitLab and Forgejo origins get their own REST base and token order", async () => {
|
|
114
|
+
const urls: string[] = [];
|
|
115
|
+
const fetch: ForgeFetch = async (url) => (urls.push(url), { ok: true, status: 200, text: async () => (url.includes("gitlab") ? "[]" : '{"body":"fixes #4"}') });
|
|
116
|
+
expect(await forgeWorkReader(top, { env: { GITLAB_TOKEN: "g" }, remoteUrl: "git@gitlab.com:grp/sub/app.git", fetch }).closes(5)).toMatchObject({ resolved: true, issues: [] });
|
|
117
|
+
expect(await forgeWorkReader(top, { env: { FORGEJO_TOKEN: "f" }, remoteUrl: "https://codeberg.org/acme/app", fetch }).closes(6)).toMatchObject({ resolved: true, issues: [4] });
|
|
118
|
+
expect(urls).toEqual([
|
|
119
|
+
"https://gitlab.com/api/v4/projects/grp%2Fsub%2Fapp/merge_requests/5/closes_issues?per_page=100&page=1",
|
|
120
|
+
"https://codeberg.org/api/v1/repos/acme/app/pulls/6",
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("setCommitCloses", () => {
|
|
126
|
+
test("sets closes on each commit with a pull request, asking once per pull request, and null on the rest", async () => {
|
|
127
|
+
const { fetch, calls } = github({ 4: [9] });
|
|
128
|
+
const commits: { pullRequest: number | null; closes?: unknown }[] = [{ pullRequest: 4 }, { pullRequest: null }, { pullRequest: 4 }];
|
|
129
|
+
await setCommitCloses(commits as { pullRequest: number | null }[], forgeWorkReader(top, { env: { GH_TOKEN: "t" }, remoteUrl, fetch }));
|
|
130
|
+
expect(commits.map((c) => c.closes)).toEqual([{ resolved: true, issues: [9], reason: null }, null, { resolved: true, issues: [9], reason: null }]);
|
|
131
|
+
expect(calls).toHaveLength(1);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("forgeKindOfHost and forgeApiBase", () => {
|
|
136
|
+
test("name a host's forge and its REST base", () => {
|
|
137
|
+
expect(["github.com", "github.acme.io", "gitlab.com", "gitlab.acme.io", "codeberg.org", "forgejo.acme.io", "git.acme.io"].map(forgeKindOfHost)).toEqual(["github", "github", "gitlab", "gitlab", "forgejo", "forgejo", null]);
|
|
138
|
+
expect(forgeApiBase("github", "github.com")).toBe("https://api.github.com");
|
|
139
|
+
expect(forgeApiBase("github", "ghe.acme.io")).toBe("https://ghe.acme.io/api/v3");
|
|
140
|
+
expect(forgeApiBase("gitlab", "gitlab.acme.io")).toBe("https://gitlab.acme.io/api/v4");
|
|
141
|
+
expect(forgeApiBase("forgejo", "codeberg.org")).toBe("https://codeberg.org/api/v1");
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work items from the forge (#4649): the issues a squash-merged pull request
|
|
3
|
+
* closes.
|
|
4
|
+
*
|
|
5
|
+
* A project that squash-merges pull requests and tracks its work in forge
|
|
6
|
+
* issues writes no `Chant-Record` trailer. Its commit subjects end in
|
|
7
|
+
* `(#<n>)`, the pull request, and the pull request closes issues. Asked to
|
|
8
|
+
* (`--forge-issues`), `release candidates` and `workspace graph --intent` ask
|
|
9
|
+
* the forge which issues each pull request closes, through the forge clients
|
|
10
|
+
* of `../pr-forge.ts` ({@link PrForge.closingIssues}): one call per pull
|
|
11
|
+
* request, each answer kept for the rest of the read.
|
|
12
|
+
*
|
|
13
|
+
* The forge is the CI job's when the read runs in one ({@link detectForge}),
|
|
14
|
+
* else the one `origin` points at: github.com and hosts named for GitHub,
|
|
15
|
+
* hosts named for GitLab, and codeberg.org and hosts named for Forgejo or
|
|
16
|
+
* Gitea. The token is read in {@link FORGE_TOKEN_ORDER}, with
|
|
17
|
+
* `CHANT_FORGE_TOKEN` first, and on GitHub `gh auth token` for the host last.
|
|
18
|
+
*
|
|
19
|
+
* Nothing here fails a read. Without a forge or a token, offline, or when the
|
|
20
|
+
* forge answers an error, a pull request is `resolved: false` with the
|
|
21
|
+
* reason, and its number still stands. After a network failure, a 401 or a
|
|
22
|
+
* 403, the rest are answered with the same reason without another call.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { execFileSync } from "node:child_process";
|
|
26
|
+
import { remoteRepoPath } from "../op/activities/forge-pull-request";
|
|
27
|
+
import { remoteHost } from "../op/activities/gh-host";
|
|
28
|
+
import { detectForge, FORGE_TOKEN_ORDER, ForgeApiError, forgeClient, forgeTargetFromEnv, type ForgeFetch, type ForgeKind, type ForgeTarget, type PrForge } from "../pr-forge";
|
|
29
|
+
|
|
30
|
+
/** What the forge says one pull request closes. */
|
|
31
|
+
export interface PullRequestCloses {
|
|
32
|
+
/** Whether the forge answered. When false, `issues` is empty and `reason` says why. */
|
|
33
|
+
resolved: boolean;
|
|
34
|
+
/** The issues of the repository the pull request closes, ascending. */
|
|
35
|
+
issues: number[];
|
|
36
|
+
/** Why the forge was not read, or null when it was. */
|
|
37
|
+
reason: string | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The forge a {@link ForgeWorkReader} reads, as the read found it. */
|
|
41
|
+
export interface ForgeWorkSource {
|
|
42
|
+
kind: ForgeKind;
|
|
43
|
+
host: string;
|
|
44
|
+
/** `owner/name`, or the GitLab project path. */
|
|
45
|
+
repo: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ForgeWorkReader {
|
|
49
|
+
/** The forge read, or null when none could be worked out. */
|
|
50
|
+
source: ForgeWorkSource | null;
|
|
51
|
+
/** What pull request `pr` closes. Asked twice, the forge is called once. */
|
|
52
|
+
closes(pr: number): Promise<PullRequestCloses>;
|
|
53
|
+
/** {@link closes} for each of `prs`, a few at a time. */
|
|
54
|
+
closesAll(prs: Iterable<number>): Promise<Map<number, PullRequestCloses>>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ForgeWorkOptions {
|
|
58
|
+
/** Default `process.env`. */
|
|
59
|
+
env?: Record<string, string | undefined>;
|
|
60
|
+
fetch?: ForgeFetch;
|
|
61
|
+
/** `origin`'s URL. Default `git remote get-url origin` in `top`; null for none. */
|
|
62
|
+
remoteUrl?: string | null;
|
|
63
|
+
/** The token `gh` holds for a GitHub host, or undefined. Default `gh auth token --hostname <host>`. */
|
|
64
|
+
ghToken?: (host: string) => string | undefined;
|
|
65
|
+
/** How long one call may take. Default 15 seconds. */
|
|
66
|
+
timeoutMs?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** How many pull requests are asked about at once. */
|
|
70
|
+
const CONCURRENCY = 4;
|
|
71
|
+
|
|
72
|
+
function gitRemote(top: string): string | null {
|
|
73
|
+
try {
|
|
74
|
+
return execFileSync("git", ["remote", "get-url", "origin"], { cwd: top, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim() || null;
|
|
75
|
+
} catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function ghAuthToken(host: string): string | undefined {
|
|
81
|
+
try {
|
|
82
|
+
return execFileSync("gh", ["auth", "token", "--hostname", host], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 5_000 }).trim() || undefined;
|
|
83
|
+
} catch {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The forge kind a remote host is: github.com and hosts named for GitHub, GitLab, or Forgejo and Gitea (codeberg.org too). Null for any other. */
|
|
89
|
+
export function forgeKindOfHost(host: string): ForgeKind | null {
|
|
90
|
+
const h = host.toLowerCase().replace(/:\d+$/, "");
|
|
91
|
+
if (h === "github.com" || /(^|[.-])github([.-]|$)/.test(h)) return "github";
|
|
92
|
+
if (h === "gitlab.com" || /(^|[.-])gitlab([.-]|$)/.test(h)) return "gitlab";
|
|
93
|
+
if (h === "codeberg.org" || /(^|[.-])(forgejo|gitea)([.-]|$)/.test(h)) return "forgejo";
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The REST base of a forge at `host`, as the clients take it. */
|
|
98
|
+
export function forgeApiBase(kind: ForgeKind, host: string): string {
|
|
99
|
+
if (kind === "github") return host === "github.com" ? "https://api.github.com" : `https://${host}/api/v3`;
|
|
100
|
+
return kind === "gitlab" ? `https://${host}/api/v4` : `https://${host}/api/v1`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Where the issues are read from, or why they can't be. */
|
|
104
|
+
function locate(top: string, opts: ForgeWorkOptions): { target: ForgeTarget } | { source: ForgeWorkSource | null; reason: string } {
|
|
105
|
+
const env = opts.env ?? process.env;
|
|
106
|
+
const job = detectForge(env);
|
|
107
|
+
if (job) {
|
|
108
|
+
try {
|
|
109
|
+
return { target: forgeTargetFromEnv(env, { kind: job }) };
|
|
110
|
+
} catch (err) {
|
|
111
|
+
return { source: null, reason: err instanceof Error ? err.message : String(err) };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const url = opts.remoteUrl !== undefined ? opts.remoteUrl : gitRemote(top);
|
|
115
|
+
if (!url) return { source: null, reason: "there is no origin remote to name the forge" };
|
|
116
|
+
const host = remoteHost(url);
|
|
117
|
+
const repo = remoteRepoPath(url);
|
|
118
|
+
const kind = host ? forgeKindOfHost(host) : null;
|
|
119
|
+
if (!host || !repo || !kind) return { source: null, reason: `origin (${url}) is not on a forge chant reads issues from: GitHub, GitLab or Forgejo` };
|
|
120
|
+
const source = { kind, host, repo };
|
|
121
|
+
const names = ["CHANT_FORGE_TOKEN", ...FORGE_TOKEN_ORDER[kind]];
|
|
122
|
+
const tokenSource = names.find((n) => env[n]?.trim());
|
|
123
|
+
const token = tokenSource ? env[tokenSource]!.trim() : kind === "github" ? (opts.ghToken ?? ghAuthToken)(host) : undefined;
|
|
124
|
+
if (!token) return { source, reason: `no token for ${host}: set ${names.join(", ")}${kind === "github" ? ", or log in with gh auth login" : ""}` };
|
|
125
|
+
return { target: { kind, apiBase: forgeApiBase(kind, host), repo, host, token, tokenSource: tokenSource ?? "gh auth token" } };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Why a failed call stops the rest: the forge can't be reached, or won't let this token read. */
|
|
129
|
+
function stopsTheRest(err: unknown): boolean {
|
|
130
|
+
return !(err instanceof ForgeApiError) || err.status === 401 || err.status === 403;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A reader of what pull requests close, for the repository at `top`. */
|
|
134
|
+
export function forgeWorkReader(top: string, opts: ForgeWorkOptions = {}): ForgeWorkReader {
|
|
135
|
+
const where = locate(top, opts);
|
|
136
|
+
const cache = new Map<number, Promise<PullRequestCloses>>();
|
|
137
|
+
let stopped: string | null = "reason" in where ? where.reason : null;
|
|
138
|
+
const client: PrForge | null = "target" in where ? forgeClient(where.target, opts.fetch) : null;
|
|
139
|
+
const source: ForgeWorkSource | null = "target" in where ? { kind: where.target.kind, host: where.target.host, repo: where.target.repo } : where.source;
|
|
140
|
+
const timeoutMs = opts.timeoutMs ?? 15_000;
|
|
141
|
+
const unresolved = (reason: string): PullRequestCloses => ({ resolved: false, issues: [], reason });
|
|
142
|
+
|
|
143
|
+
const ask = async (pr: number): Promise<PullRequestCloses> => {
|
|
144
|
+
if (stopped !== null) return unresolved(stopped);
|
|
145
|
+
if (!client?.closingIssues) return unresolved(`the ${source?.kind ?? "forge"} client can't list the issues a pull request closes`);
|
|
146
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
147
|
+
try {
|
|
148
|
+
const timeout = new Promise<never>((_, reject) => {
|
|
149
|
+
timer = setTimeout(() => reject(new Error(`no answer in ${timeoutMs / 1000}s`)), timeoutMs);
|
|
150
|
+
});
|
|
151
|
+
const issues = await Promise.race([client.closingIssues(pr), timeout]);
|
|
152
|
+
return { resolved: true, issues, reason: null };
|
|
153
|
+
} catch (err) {
|
|
154
|
+
const message = `${source?.host ?? "the forge"} could not be read: ${err instanceof Error ? err.message : String(err)}`;
|
|
155
|
+
if (stopsTheRest(err)) stopped = message;
|
|
156
|
+
return unresolved(message);
|
|
157
|
+
} finally {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const closes = (pr: number): Promise<PullRequestCloses> => {
|
|
163
|
+
let hit = cache.get(pr);
|
|
164
|
+
if (!hit) {
|
|
165
|
+
hit = ask(pr);
|
|
166
|
+
cache.set(pr, hit);
|
|
167
|
+
}
|
|
168
|
+
return hit;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
source,
|
|
173
|
+
closes,
|
|
174
|
+
async closesAll(prs) {
|
|
175
|
+
const queue = [...new Set(prs)];
|
|
176
|
+
const out = new Map<number, PullRequestCloses>();
|
|
177
|
+
const worker = async (): Promise<void> => {
|
|
178
|
+
for (let pr = queue.shift(); pr !== undefined; pr = queue.shift()) out.set(pr, await closes(pr));
|
|
179
|
+
};
|
|
180
|
+
await Promise.all(Array.from({ length: Math.min(CONCURRENCY, queue.length) }, worker));
|
|
181
|
+
return out;
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Set `closes` on each commit from what its `pullRequest` closes, asking the
|
|
188
|
+
* forge once per pull request; null for a commit with none. For
|
|
189
|
+
* `workspace graph --intent --forge-issues`, over the graph's commit nodes or
|
|
190
|
+
* a record walk's commits.
|
|
191
|
+
*/
|
|
192
|
+
export async function setCommitCloses(commits: { pullRequest: number | null; closes?: PullRequestCloses | null }[], reader: ForgeWorkReader): Promise<void> {
|
|
193
|
+
const closed = await reader.closesAll(commits.map((c) => c.pullRequest).filter((n): n is number => n !== null));
|
|
194
|
+
for (const c of commits) c.closes = c.pullRequest !== null ? (closed.get(c.pullRequest) ?? null) : null;
|
|
195
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* else: no zod, no ajv, no package loading, so it bundles small.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { checkGateSignature, gateSealPayload, namespaceAllowed, sshKeyFingerprint, sshSignatureKey, unlistedWhat, unlistedWhere, verifySshSignatureWith, type PasskeySigner, type SealedGateApproval } from "../lifecycle/gate-seal";
|
|
18
18
|
import type { Signer } from "./trust/trust-files";
|
|
19
19
|
|
|
20
20
|
/** The core classes, in the order a principal's roles are tried; `human` holds no role and is the rest. */
|
|
@@ -46,8 +46,8 @@ export interface GateAdmissionRule {
|
|
|
46
46
|
gate: string;
|
|
47
47
|
/** The class the approver must be in, or null for any signer. */
|
|
48
48
|
class: string | null;
|
|
49
|
-
/** The signers file at base: its path, whether it exists, and its signers. */
|
|
50
|
-
signers: { signersPath: string; active: boolean; signers: readonly Signer[] };
|
|
49
|
+
/** The signers file at base: its path, whether it exists, and its signers, with the passkeys `.chant/trust.json` lists (#4646). */
|
|
50
|
+
signers: { signersPath: string; active: boolean; signers: readonly Signer[]; passkeys?: readonly PasskeySigner[] };
|
|
51
51
|
/** The role grants at base (`.chant/trust.json` `roles`). */
|
|
52
52
|
roles: Readonly<Record<string, readonly string[]>>;
|
|
53
53
|
/** Every class the rule knows, core first, then domain classes in pin order. */
|
|
@@ -185,9 +185,7 @@ function sealRefusal(gate: string, signers: GateAdmissionRule["signers"], a: Sea
|
|
|
185
185
|
}
|
|
186
186
|
if (normalise(seal.signer) !== normalise(a.resolvedBy)) return `the seal on ${what} is by ${seal.signer}, and its approver is ${a.resolvedBy || "empty"}`;
|
|
187
187
|
const where = `${signers.signersPath} at base`;
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
const r = verifySshSignatureWith(seal.signature, gateSealPayload(a), GATE_SEAL_NAMESPACE, keys);
|
|
192
|
-
return r.ok ? null : `the seal does not verify for ${a.resolvedBy} against ${where}: ${r.reason}`;
|
|
188
|
+
const r = checkGateSignature(signers, a.resolvedBy, seal as { signature: string }, gateSealPayload(a));
|
|
189
|
+
if (r.ok) return null;
|
|
190
|
+
return r.unlisted ? `${a.resolvedBy} has no ${unlistedWhat(seal)} in ${unlistedWhere(seal, where)}, so the seal can't count` : `the seal does not verify for ${a.resolvedBy} against ${where}: ${r.reason}`;
|
|
193
191
|
}
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* it to chant's write commands (`--by`, `--actor`). chant records what it is
|
|
7
7
|
* given and says which form it is:
|
|
8
8
|
*
|
|
9
|
-
* - `signer`: a principal `.chant/allowed_signers` lists at base
|
|
10
|
-
*
|
|
9
|
+
* - `signer`: a principal `.chant/allowed_signers` lists at base, or one with
|
|
10
|
+
* a passkey in `.chant/trust.json` (#4646). A seal made with that
|
|
11
|
+
* principal's key (`--sign`) or passkey (`--signature`) attests it.
|
|
11
12
|
* - `forge`: a forge identity, `github:<login>`, `gitlab:<login>`, or
|
|
12
13
|
* `<forge>@<host>:<login>` (forgejo, gitea, or a self-hosted github or
|
|
13
14
|
* gitlab). The surface that signed the person in vouches for it; nothing
|
|
@@ -90,7 +91,9 @@ const NON_PERSON_CLASSES = new Set(["agent", "runner", "service"]);
|
|
|
90
91
|
export function identify(principal: string, policy: TrustPolicy, declaration: Declaration | null = null): Identified {
|
|
91
92
|
const name = normalisePrincipal(principal);
|
|
92
93
|
const forge = parseForgeIdentity(principal);
|
|
93
|
-
|
|
94
|
+
// #4646: a principal with a passkey at base signs like one with a key.
|
|
95
|
+
const listed = (s: { principal: string }) => normalisePrincipal(s.principal) === name;
|
|
96
|
+
if (policy.active && (policy.signers.some(listed) || (policy.passkeys ?? []).some(listed))) return { principal, form: "signer", forge };
|
|
94
97
|
if (forge) return { principal, form: "forge", forge };
|
|
95
98
|
const session = (declaration?.agents ?? []).some((a) => a.principals.some((p) => normalisePrincipal(p) === name));
|
|
96
99
|
if (session || classesOf(coreClassRegistry(), policy, principal).some((c) => NON_PERSON_CLASSES.has(c))) return { principal, form: "role", forge: null };
|