@intentius/chant 0.124.61 → 0.124.63
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 +18 -0
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +142 -16
- 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/release.d.ts +6 -4
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +13 -7
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +34 -5
- 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 +31 -0
- package/dist/cli/registry.d.ts +13 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/config.d.ts +32 -0
- package/dist/config.d.ts.map +1 -1
- 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 +44 -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 +17 -3
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.d.ts +39 -3
- package/dist/lifecycle/gate-seal.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.js +50 -10
- package/dist/lifecycle/gate-statement.d.ts +70 -0
- package/dist/lifecycle/gate-statement.d.ts.map +1 -0
- package/dist/lifecycle/gate-statement.js +74 -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 +121 -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 +87 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +87 -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 +14 -4
- 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 +66 -0
- package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
- package/dist/lifecycle/publish-homebrew.js +173 -0
- package/dist/lifecycle/publish-marketplace.d.ts +51 -0
- package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
- package/dist/lifecycle/publish-marketplace.js +254 -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 +182 -0
- package/dist/lifecycle/release-publish.d.ts +5 -2
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- 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/activities/activity-contracts.d.ts +4 -4
- package/dist/pr-forge.d.ts +20 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +61 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +331 -330
- 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-workflow.d.ts +2 -0
- package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
- package/dist/workspace/ci-green-workflow.js +9 -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 +127 -9
- 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 +205 -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 +171 -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 +3 -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 +33 -6
- package/dist/workspace/release-candidates.d.ts.map +1 -1
- package/dist/workspace/release-candidates.js +49 -20
- package/dist/workspace/release-candidates.schema.json +48 -2
- 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 +226 -0
- package/src/cli/handlers/approve.ts +174 -16
- package/src/cli/handlers/plan.ts +74 -0
- package/src/cli/handlers/release.ts +12 -7
- package/src/cli/main.ts +34 -5
- package/src/cli/mcp/workspace-tools.ts +2 -1
- package/src/cli/parse-args.ts +24 -0
- package/src/cli/registry.ts +13 -1
- package/src/gate-decision-bundle.test.ts +4 -2
- package/src/gate-decision.ts +11 -2
- package/src/gate-statement.schema.json +44 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
- package/src/lifecycle/gate-ledger.ts +17 -3
- package/src/lifecycle/gate-seal.ts +62 -9
- package/src/lifecycle/gate-statement.ts +107 -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 +150 -0
- package/src/lifecycle/plan-stale.ts +173 -0
- package/src/lifecycle/publish-credentials.ts +2 -0
- package/src/lifecycle/publish-declaration.ts +93 -1
- package/src/lifecycle/publish-forge.ts +15 -4
- package/src/lifecycle/publish-github.ts +174 -0
- package/src/lifecycle/publish-homebrew.test.ts +179 -0
- package/src/lifecycle/publish-homebrew.ts +187 -0
- package/src/lifecycle/publish-marketplace.test.ts +254 -0
- package/src/lifecycle/publish-marketplace.ts +259 -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 +199 -0
- package/src/lifecycle/release-publish.ts +5 -3
- 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/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 +68 -5
- 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-workflow.test.ts +9 -0
- package/src/workspace/ci-green-workflow.ts +9 -0
- package/src/workspace/ci-green.ts +141 -10
- package/src/workspace/ci-quarantine-report.test.ts +146 -0
- package/src/workspace/ci-quarantine-report.ts +235 -0
- package/src/workspace/ci-quarantine.test.ts +161 -0
- package/src/workspace/ci-quarantine.ts +189 -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 +10 -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 +48 -2
- package/src/workspace/release-candidates.test.ts +77 -4
- package/src/workspace/release-candidates.ts +62 -20
- 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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The quarantine (#4677): known-flaky tests a phase's runner leaves out
|
|
3
|
+
* until they are fixed, declared in `ci.green.quarantine`.
|
|
4
|
+
*
|
|
5
|
+
* ci quarantine check every entry is current: none is past its
|
|
6
|
+
* `until`, and none is more than maxDays out
|
|
7
|
+
* ci quarantine filter --phase <name> --runner nextest|playwright|list [--only] [--json]
|
|
8
|
+
* what the phase's runner leaves out, or with
|
|
9
|
+
* --only what the scheduled run runs
|
|
10
|
+
* ci quarantine report --phase <name> --junit <file>... [--commit <sha>] [--dry-run] [--json]
|
|
11
|
+
* what became of each quarantined test in the
|
|
12
|
+
* scheduled run, and ci.quarantine-passed for
|
|
13
|
+
* each that passed (./ci-quarantine-report.ts)
|
|
14
|
+
*
|
|
15
|
+
* The tick judges a phase by its check runs, whole, so a quarantined test is
|
|
16
|
+
* kept out of the verdict by its runner never running it there: nextest gets
|
|
17
|
+
* a filterset (`-E`), Playwright a `--grep-invert` pattern, and any other
|
|
18
|
+
* runner a list. A scheduled run of the quarantined tests alone, under a job
|
|
19
|
+
* no phase's patterns match, tells whether one is fixed.
|
|
20
|
+
*
|
|
21
|
+
* Whether an entry has expired depends on the day, so the declaration's
|
|
22
|
+
* reader doesn't judge it: an expired quarantine would otherwise stop every
|
|
23
|
+
* chant command, the tick among them. `check` and `filter` do, and fail
|
|
24
|
+
* with `declaration-invalid` at the entry, so the phase whose job asks for
|
|
25
|
+
* its filter goes red until someone fixes the test or the entry. `filter
|
|
26
|
+
* --only` doesn't refuse, so the scheduled run still says whether an expired
|
|
27
|
+
* test passes.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { formatError } from "../cli/format";
|
|
31
|
+
import type { CommandContext } from "../cli/registry";
|
|
32
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
33
|
+
import { locateWorkspace } from "./which-chant";
|
|
34
|
+
import { quarantineDay, readDeclaration, WorkspaceReadError, type CiGreen, type CiQuarantineEntry } from "./declaration";
|
|
35
|
+
|
|
36
|
+
/** The first chant that reads `ci.green.quarantine` and runs `chant ci quarantine` (#4677). */
|
|
37
|
+
export const CI_QUARANTINE_FLOOR = NEXT_RELEASE;
|
|
38
|
+
|
|
39
|
+
export const QUARANTINE_RUNNERS = ["nextest", "playwright", "list"] as const;
|
|
40
|
+
export type QuarantineRunner = (typeof QUARANTINE_RUNNERS)[number];
|
|
41
|
+
|
|
42
|
+
const USAGE = "chant ci quarantine check | ci quarantine filter --phase <name> --runner nextest|playwright|list [--only] [--json] | ci quarantine report --phase <name> --junit <file>... [--commit <sha>] [--dry-run] [--json]";
|
|
43
|
+
|
|
44
|
+
/** Today, YYYY-MM-DD in UTC. */
|
|
45
|
+
export const utcToday = (now: Date = new Date()): string => now.toISOString().slice(0, 10);
|
|
46
|
+
|
|
47
|
+
/** An entry as a person reads it: `file › test`, or the test. */
|
|
48
|
+
export const quarantineName = (e: Pick<CiQuarantineEntry, "test" | "file">): string => (e.file !== undefined ? `${e.file} › ${e.test}` : e.test);
|
|
49
|
+
|
|
50
|
+
/** What is wrong with an entry on `today`: past its `until`, or `until` further out than `maxDays`. */
|
|
51
|
+
export interface QuarantineProblem {
|
|
52
|
+
entry: CiQuarantineEntry;
|
|
53
|
+
message: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The quarantine's entries that are expired or too far out on `today`, of `phase` when given. */
|
|
57
|
+
export function quarantineProblems(green: CiGreen, today: string, phase?: string): QuarantineProblem[] {
|
|
58
|
+
const q = green.quarantine;
|
|
59
|
+
if (!q) return [];
|
|
60
|
+
const now = quarantineDay(today);
|
|
61
|
+
if (now === null) throw new Error(`today isn't a day: ${today}`);
|
|
62
|
+
const out: QuarantineProblem[] = [];
|
|
63
|
+
for (const e of q.entries) {
|
|
64
|
+
if (phase !== undefined && e.phase !== phase) continue;
|
|
65
|
+
const until = quarantineDay(e.until)!;
|
|
66
|
+
const what = `ci.green.quarantine: ${e.phase}: ${quarantineName(e)} (${e.issue})`;
|
|
67
|
+
if (until < now) out.push({ entry: e, message: `${what} expired on ${e.until}: fix the test and delete the entry, or delete the test` });
|
|
68
|
+
else if (until - now > q.maxDays) out.push({ entry: e, message: `${what} stays out until ${e.until}, more than ${q.maxDays} days from ${today} (ci.green.quarantine.maxDays)` });
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A problem as the reader's own `declaration-invalid` error, located at its entry. */
|
|
74
|
+
function problemError(p: QuarantineProblem): WorkspaceReadError {
|
|
75
|
+
return new WorkspaceReadError("declaration-invalid", p.message, p.entry.location);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
79
|
+
|
|
80
|
+
// A Rust binary id and test name use none of the characters nextest's
|
|
81
|
+
// matchers would need escaped, so a name that does is refused, not escaped.
|
|
82
|
+
const NEXTEST_PART = /^[A-Za-z0-9_:/.-]+$/;
|
|
83
|
+
|
|
84
|
+
/** One entry as a nextest filterset: `binary_id(=B) & test(=T)`, or `test(=T)` for a name alone. */
|
|
85
|
+
function nextestSet(e: CiQuarantineEntry): string {
|
|
86
|
+
const parts = e.test.split(" ");
|
|
87
|
+
if (parts.length > 2 || !parts.every((p) => NEXTEST_PART.test(p))) {
|
|
88
|
+
throw new WorkspaceReadError("declaration-invalid", `ci.green.quarantine: ${e.phase}: ${JSON.stringify(e.test)} isn't a nextest test: give the binary id and the test's name as nextest prints them ("my-crate::integration module::test_name"), or the name alone`, e.location);
|
|
89
|
+
}
|
|
90
|
+
return parts.length === 2 ? `(binary_id(=${parts[0]}) & test(=${parts[1]}))` : `test(=${parts[0]})`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* One entry as a pattern for Playwright's `grep`, which it matches against
|
|
95
|
+
* a test's title path joined by spaces (project, spec file from testDir,
|
|
96
|
+
* describe titles, title) with its tags after: the file, then the title at
|
|
97
|
+
* the end, any describe titles between.
|
|
98
|
+
*/
|
|
99
|
+
function playwrightPattern(e: CiQuarantineEntry): string {
|
|
100
|
+
return `(?:^| )${escapeRegExp(e.file!)} (?:.* )?${escapeRegExp(e.test)}(?: @\\S+)*$`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A regex that matches nothing, for a `--grep-invert` that leaves nothing out. */
|
|
104
|
+
export const PLAYWRIGHT_NOTHING = "(?!)";
|
|
105
|
+
|
|
106
|
+
export interface QuarantineFilter {
|
|
107
|
+
phase: string;
|
|
108
|
+
runner: QuarantineRunner;
|
|
109
|
+
only: boolean;
|
|
110
|
+
/** What the runner takes: a filterset, a pattern, or lines. */
|
|
111
|
+
filter: string;
|
|
112
|
+
/** The entries it covers. */
|
|
113
|
+
entries: CiQuarantineEntry[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* What `phase`'s runner takes (#4677). nextest covers the entries that
|
|
118
|
+
* name no file, and Playwright the ones that do; `list` covers every one, a
|
|
119
|
+
* line each, `file<TAB>test` for an entry with a file. Without `only` it
|
|
120
|
+
* leaves the quarantined tests out, as a phase's run does, and refuses when
|
|
121
|
+
* an entry of the phase is expired or too far out on `today`; with `only` it
|
|
122
|
+
* selects them, for the scheduled run.
|
|
123
|
+
*/
|
|
124
|
+
export function quarantineFilter(green: CiGreen, req: { phase: string; runner: QuarantineRunner; only?: boolean; today: string }): QuarantineFilter {
|
|
125
|
+
if (!green.phases.some((p) => p.name === req.phase)) {
|
|
126
|
+
throw new WorkspaceReadError("declaration-invalid", `ci.green declares no phase ${JSON.stringify(req.phase)}; it declares ${green.phases.map((p) => p.name).join(", ")}`);
|
|
127
|
+
}
|
|
128
|
+
const only = req.only === true;
|
|
129
|
+
if (!only) {
|
|
130
|
+
const [problem] = quarantineProblems(green, req.today, req.phase);
|
|
131
|
+
if (problem) throw problemError(problem);
|
|
132
|
+
}
|
|
133
|
+
const all = (green.quarantine?.entries ?? []).filter((e) => e.phase === req.phase);
|
|
134
|
+
const entries = req.runner === "nextest" ? all.filter((e) => e.file === undefined) : req.runner === "playwright" ? all.filter((e) => e.file !== undefined) : all;
|
|
135
|
+
let filter: string;
|
|
136
|
+
if (req.runner === "nextest") {
|
|
137
|
+
const set = entries.map(nextestSet).join(" | ");
|
|
138
|
+
filter = only ? set || "none()" : set ? `not (${set})` : "all()";
|
|
139
|
+
} else if (req.runner === "playwright") {
|
|
140
|
+
filter = entries.map(playwrightPattern).join("|") || PLAYWRIGHT_NOTHING;
|
|
141
|
+
} else {
|
|
142
|
+
filter = entries.map((e) => (e.file !== undefined ? `${e.file}\t${e.test}` : e.test)).join("\n");
|
|
143
|
+
}
|
|
144
|
+
return { phase: req.phase, runner: req.runner, only, filter, entries };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function readGreenOnly(cwd: string): CiGreen {
|
|
148
|
+
const declaration = readDeclaration(locateWorkspace(cwd).tree);
|
|
149
|
+
const green = declaration.ci?.green;
|
|
150
|
+
if (!green) throw new WorkspaceReadError("declaration-invalid", `${declaration.file} declares no ci.green, so it has no phases to quarantine tests of`);
|
|
151
|
+
return green;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const describe = (err: unknown) => (err instanceof WorkspaceReadError ? err.describe() : err instanceof Error ? err.message : String(err));
|
|
155
|
+
|
|
156
|
+
/** `chant ci quarantine check|filter` (#4677). */
|
|
157
|
+
export async function runCiQuarantine(ctx: CommandContext): Promise<number> {
|
|
158
|
+
const { args } = ctx;
|
|
159
|
+
const action = args.extraPositional;
|
|
160
|
+
try {
|
|
161
|
+
const today = utcToday();
|
|
162
|
+
if (action === "check") {
|
|
163
|
+
const green = readGreenOnly(process.cwd());
|
|
164
|
+
const problems = quarantineProblems(green, today);
|
|
165
|
+
for (const p of problems) console.error(problemError(p).describe());
|
|
166
|
+
if (problems.length > 0) return 1;
|
|
167
|
+
const n = green.quarantine?.entries.length ?? 0;
|
|
168
|
+
console.log(`${n} test${n === 1 ? "" : "s"} quarantined, every one current on ${today}`);
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
if (action === "filter") {
|
|
172
|
+
if (!args.phase) throw new Error("--phase names the ci.green phase whose runner takes the filter");
|
|
173
|
+
const runner = args.quarantineRunner;
|
|
174
|
+
if (!runner || !(QUARANTINE_RUNNERS as readonly string[]).includes(runner)) throw new Error(`--runner takes ${QUARANTINE_RUNNERS.join(", ")}${runner ? `, not ${JSON.stringify(runner)}` : ""}`);
|
|
175
|
+
const out = quarantineFilter(readGreenOnly(process.cwd()), { phase: args.phase, runner: runner as QuarantineRunner, only: args.quarantineOnly === true, today });
|
|
176
|
+
if (args.json) {
|
|
177
|
+
const { entries, ...rest } = out;
|
|
178
|
+
console.log(JSON.stringify({ ...rest, entries: entries.map(({ pointer: _p, location: _l, ...e }) => e) }, null, 2));
|
|
179
|
+
} else if (out.filter !== "") console.log(out.filter);
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
if (action === "report") return (await import("./ci-quarantine-report")).runCiQuarantineReport(ctx);
|
|
183
|
+
console.error(formatError({ message: action ? `chant ci quarantine: no ${action}` : "chant ci quarantine needs check, filter or report", hint: USAGE }));
|
|
184
|
+
return 1;
|
|
185
|
+
} catch (err) {
|
|
186
|
+
console.error(formatError({ message: `chant ci quarantine: ${describe(err)}`, hint: USAGE }));
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -103,6 +103,7 @@ import { forgeFromEnv, type OpenPullRequest } from "../pr-forge";
|
|
|
103
103
|
import type { CommandContext } from "../cli/registry";
|
|
104
104
|
import { formatError, formatWarning } from "../cli/format";
|
|
105
105
|
import { acquireLease, currentHolderId, releaseLease, DEFAULT_LEASE_TTL_MS, type LeaseRecord } from "../lifecycle/lease";
|
|
106
|
+
import { lifecycleRemoteOverride } from "../lifecycle/ledger-remote";
|
|
106
107
|
import { parseDuration } from "../op/duration";
|
|
107
108
|
import { reportUrlOf } from "./ci-report-url";
|
|
108
109
|
import { CI_JOB_OPS, ciJobPlace, ciLoopOptions, ciSecretsOf, ciRun, ciStatusFromEnv, CiRunError, type CiJobName, type CiRunRequest, type CiRunResult } from "./ci-run";
|
|
@@ -332,11 +333,13 @@ function gitStatus(cwd: string, args: string[]): { code: number; out: string } {
|
|
|
332
333
|
* fetch says why.
|
|
333
334
|
*/
|
|
334
335
|
export function reconcileCiServeLedger(top: string): CiServeEvent | undefined {
|
|
336
|
+
// #4647: the remote the apply jobs push the ledger to.
|
|
337
|
+
const remote = lifecycleRemoteOverride() ?? "origin";
|
|
335
338
|
const local = tryGit(top, ["rev-parse", "--verify", "--quiet", `refs/heads/${LEDGER}^{commit}`]);
|
|
336
|
-
const listed = gitStatus(top, ["ls-remote", "--exit-code",
|
|
339
|
+
const listed = gitStatus(top, ["ls-remote", "--exit-code", remote, `refs/heads/${LEDGER}`]);
|
|
337
340
|
if (listed.code === 2) {
|
|
338
341
|
// A remote-tracking ref left from a deleted branch would be the next push's lease, and refuse it.
|
|
339
|
-
tryGit(top, ["update-ref", "-d", `refs/remotes
|
|
342
|
+
tryGit(top, ["update-ref", "-d", `refs/remotes/${remote}/${LEDGER}`]);
|
|
340
343
|
if (!local) return undefined;
|
|
341
344
|
tryGit(top, ["update-ref", "-d", `refs/heads/${LEDGER}`, local]);
|
|
342
345
|
return { type: "ledger", action: "deleted", local };
|
|
@@ -344,13 +347,13 @@ export function reconcileCiServeLedger(top: string): CiServeEvent | undefined {
|
|
|
344
347
|
if (listed.code !== 0 || !local) return undefined;
|
|
345
348
|
const forge = listed.out.split(/\s+/)[0];
|
|
346
349
|
if (!forge || forge === local) return undefined;
|
|
347
|
-
if (gitStatus(top, ["fetch", "--quiet", "--no-tags",
|
|
350
|
+
if (gitStatus(top, ["fetch", "--quiet", "--no-tags", remote, `+refs/heads/${LEDGER}:${FORGE_LEDGER}`]).code !== 0) return undefined;
|
|
348
351
|
try {
|
|
349
352
|
const ahead = gitStatus(top, ["merge-base", "--is-ancestor", forge, local]).code === 0;
|
|
350
353
|
const behind = gitStatus(top, ["merge-base", "--is-ancestor", local, forge]).code === 0;
|
|
351
354
|
if (ahead || behind) return undefined;
|
|
352
355
|
tryGit(top, ["update-ref", `refs/heads/${LEDGER}`, forge, local]);
|
|
353
|
-
tryGit(top, ["update-ref", `refs/remotes
|
|
356
|
+
tryGit(top, ["update-ref", `refs/remotes/${remote}/${LEDGER}`, forge]);
|
|
354
357
|
return { type: "ledger", action: "reset", local, forge };
|
|
355
358
|
} finally {
|
|
356
359
|
tryGit(top, ["update-ref", "-d", FORGE_LEDGER]);
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
* several pins merge. {@link classDataShapeProblems} is the schema written
|
|
12
12
|
* out by hand for the bundle; `class-data.test.ts` holds it to ajv's answer.
|
|
13
13
|
*
|
|
14
|
-
* The module imports node:fs and node:
|
|
14
|
+
* The module imports node:fs, node:path and node:url and nothing else.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
18
18
|
import { dirname, join, posix, resolve } from "node:path";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
19
20
|
import { CORE_CLASSES, CORE_PRINCIPAL_CLASSES, type PrincipalClass } from "./identity-gate-rule";
|
|
20
21
|
|
|
21
22
|
/** The subpath a package publishes its principal classes at. */
|
|
@@ -41,6 +42,9 @@ export function diskFiles(dir: string): PackageFiles {
|
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
/** This chant's own install: a pinned package a checkout does not hold is looked up from here too (plywood#54). */
|
|
46
|
+
export const CHANT_INSTALL = dirname(fileURLToPath(import.meta.url));
|
|
47
|
+
|
|
44
48
|
/**
|
|
45
49
|
* The directory of an installed package `name`, found the way Node finds a
|
|
46
50
|
* bare import: `node_modules/<name>` in `fromDir` and each directory above it.
|
|
@@ -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
|
+
});
|