@intentius/chant 0.124.62 → 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.d.ts +45 -2
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +124 -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 +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.ts +138 -6
- 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,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The quarantine's scheduled run (#4677): what became of each quarantined
|
|
3
|
+
* test, read from the run's JUnit XML, and `ci.quarantine-passed` through
|
|
4
|
+
* `ci.green.notify` for each one that passed, so someone can take it out.
|
|
5
|
+
*
|
|
6
|
+
* ci quarantine report --phase <name> --junit <file>... [--commit <sha>] [--dry-run] [--json]
|
|
7
|
+
*
|
|
8
|
+
* nextest (`[profile.<p>.junit]`), Playwright (`--reporter=junit`) and most
|
|
9
|
+
* other runners write JUnit XML. A test counts as passed only when every
|
|
10
|
+
* case of it passed on its first try: one nextest marks flaky (it failed,
|
|
11
|
+
* then passed on a retry) is still flaky. The report gates nothing: it exits
|
|
12
|
+
* 0 whatever the tests did, and 1 only when it can't read what it was given.
|
|
13
|
+
*
|
|
14
|
+
* The event is sent on every scheduled run the test passes in, with an id
|
|
15
|
+
* made from the test and the commit, so a re-run of the same commit sends
|
|
16
|
+
* the same id and a receiver can drop it.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { createHash } from "node:crypto";
|
|
20
|
+
import { execFileSync } from "node:child_process";
|
|
21
|
+
import { readFileSync } from "node:fs";
|
|
22
|
+
import { resolve } from "node:path";
|
|
23
|
+
import { formatError } from "../cli/format";
|
|
24
|
+
import type { CommandContext } from "../cli/registry";
|
|
25
|
+
import { makeNotifyEvent, sendNotify as realSendNotify, type NotifyDelivery, type NotifyEvent } from "../notify";
|
|
26
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
27
|
+
import { quarantineName } from "./ci-quarantine";
|
|
28
|
+
import { locateWorkspace } from "./which-chant";
|
|
29
|
+
import { readDeclaration, WorkspaceReadError, type CiGreen, type CiQuarantineEntry } from "./declaration";
|
|
30
|
+
|
|
31
|
+
/** The first chant that sends `ci.quarantine-passed` (#4677). */
|
|
32
|
+
export const CI_QUARANTINE_NOTIFY_FLOOR = NEXT_RELEASE;
|
|
33
|
+
|
|
34
|
+
/** One `<testcase>`: its suite's name, its classname and name, and how it ended. */
|
|
35
|
+
export interface JUnitCase {
|
|
36
|
+
suite: string;
|
|
37
|
+
classname: string;
|
|
38
|
+
name: string;
|
|
39
|
+
outcome: "passed" | "flaky" | "failed" | "skipped";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ENTITY: Record<string, string> = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
|
|
43
|
+
const decode = (s: string) => s.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-z]+);/g, (all, e: string) => (e[0] === "#" ? String.fromCodePoint(e[1] === "x" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10)) : (ENTITY[e] ?? all)));
|
|
44
|
+
|
|
45
|
+
function attributes(text: string): Record<string, string> {
|
|
46
|
+
const out: Record<string, string> = {};
|
|
47
|
+
for (const m of text.matchAll(/([^\s=]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) out[m[1]!] = decode(m[2] ?? m[3] ?? "");
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The test cases of a JUnit XML document. Only the elements a test's
|
|
53
|
+
* outcome needs are read: `testsuite`, `testcase` and its `failure`,
|
|
54
|
+
* `error`, `skipped`, and nextest's `flakyFailure` and `flakyError`.
|
|
55
|
+
*/
|
|
56
|
+
export function parseJUnit(xml: string): JUnitCase[] {
|
|
57
|
+
// CDATA, comments and declarations can hold anything, `<` included.
|
|
58
|
+
const text = xml.replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, "").replace(/<!--[\s\S]*?-->/g, "").replace(/<[?!][\s\S]*?>/g, "");
|
|
59
|
+
if (!/<testsuites?[\s>/]/.test(text)) throw new Error("not JUnit XML: no <testsuites> or <testsuite>");
|
|
60
|
+
const out: JUnitCase[] = [];
|
|
61
|
+
const suites: string[] = [];
|
|
62
|
+
let open: (JUnitCase & { marks: Set<string> }) | null = null;
|
|
63
|
+
const close = () => {
|
|
64
|
+
if (!open) return;
|
|
65
|
+
const m = open.marks;
|
|
66
|
+
open.outcome = m.has("failure") || m.has("error") ? "failed" : m.has("flakyFailure") || m.has("flakyError") ? "flaky" : m.has("skipped") ? "skipped" : "passed";
|
|
67
|
+
const { marks: _m, ...c } = open;
|
|
68
|
+
out.push(c);
|
|
69
|
+
open = null;
|
|
70
|
+
};
|
|
71
|
+
for (const m of text.matchAll(/<(\/?)([A-Za-z][\w:.-]*)((?:\s+[^\s=>/]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*(\/?)>/g)) {
|
|
72
|
+
const [, end, tag, attrs, selfClosing] = m;
|
|
73
|
+
if (tag === "testsuite") {
|
|
74
|
+
if (end) suites.pop();
|
|
75
|
+
else if (!selfClosing) suites.push(attributes(attrs!).name ?? "");
|
|
76
|
+
} else if (tag === "testcase") {
|
|
77
|
+
if (end) close();
|
|
78
|
+
else {
|
|
79
|
+
close();
|
|
80
|
+
const a = attributes(attrs!);
|
|
81
|
+
open = { suite: suites.at(-1) ?? "", classname: a.classname ?? "", name: a.name ?? "", outcome: "passed", marks: new Set() };
|
|
82
|
+
if (selfClosing) close();
|
|
83
|
+
}
|
|
84
|
+
} else if (open && !end) open.marks.add(tag!);
|
|
85
|
+
}
|
|
86
|
+
close();
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Whether a case is the entry's test. See {@link quarantineResults}. */
|
|
91
|
+
function matches(e: CiQuarantineEntry, c: JUnitCase): boolean {
|
|
92
|
+
// Playwright joins a case's describes and title with " › "; the entry, like its grep, may give them with spaces.
|
|
93
|
+
const name = c.name.replace(/ › /g, " ");
|
|
94
|
+
if (e.file !== undefined) return (c.classname === e.file || c.suite === e.file) && (name === e.test || name.endsWith(` ${e.test}`));
|
|
95
|
+
if (c.name === e.test) return true;
|
|
96
|
+
const at = e.test.indexOf(" ");
|
|
97
|
+
return at > 0 && (c.suite === e.test.slice(0, at) || c.classname === e.test.slice(0, at)) && c.name === e.test.slice(at + 1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type QuarantineOutcome = JUnitCase["outcome"] | "not-run";
|
|
101
|
+
|
|
102
|
+
export interface QuarantineResult {
|
|
103
|
+
entry: CiQuarantineEntry;
|
|
104
|
+
outcome: QuarantineOutcome;
|
|
105
|
+
/** How many cases matched: a Playwright test runs once per project. */
|
|
106
|
+
cases: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Each entry of `phase` with how its cases ended. An entry with a `file`
|
|
111
|
+
* matches a case whose classname or suite is the file and whose name (`›`
|
|
112
|
+
* read as a space) is its test or ends with it, as Playwright writes them.
|
|
113
|
+
* One without matches a case named its test, or, for `<binary> <name>` as
|
|
114
|
+
* nextest gives it, a case named `<name>` in the suite (or classname)
|
|
115
|
+
* `<binary>`. Any failed case makes the entry failed, then any flaky, then
|
|
116
|
+
* any passed; all skipped is skipped, and none is not run.
|
|
117
|
+
*/
|
|
118
|
+
export function quarantineResults(green: CiGreen, phase: string, cases: readonly JUnitCase[]): QuarantineResult[] {
|
|
119
|
+
return (green.quarantine?.entries ?? [])
|
|
120
|
+
.filter((e) => e.phase === phase)
|
|
121
|
+
.map((entry) => {
|
|
122
|
+
const mine = cases.filter((c) => matches(entry, c));
|
|
123
|
+
const has = (o: JUnitCase["outcome"]) => mine.some((c) => c.outcome === o);
|
|
124
|
+
const outcome: QuarantineOutcome = mine.length === 0 ? "not-run" : has("failed") ? "failed" : has("flaky") ? "flaky" : has("passed") ? "passed" : "skipped";
|
|
125
|
+
return { entry, outcome, cases: mine.length };
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** `ci.quarantine-passed` for one entry that passed at `commit`. */
|
|
130
|
+
export function quarantinePassedEvent(green: CiGreen, entry: CiQuarantineEntry, commit: string, env: NodeJS.ProcessEnv = process.env): NotifyEvent {
|
|
131
|
+
const name = quarantineName(entry);
|
|
132
|
+
const run = { commit };
|
|
133
|
+
return makeNotifyEvent(
|
|
134
|
+
{
|
|
135
|
+
id: createHash("sha256").update(JSON.stringify(["chant", "ci.quarantine-passed", entry.phase, entry.file ?? null, entry.test, commit])).digest("hex"),
|
|
136
|
+
source: "chant",
|
|
137
|
+
event: "ci.quarantine-passed",
|
|
138
|
+
summary: `quarantined ${name} passed in phase ${entry.phase}'s scheduled run at ${commit.slice(0, 12)}: take it out of ci.green.quarantine if ${entry.issue} is fixed`,
|
|
139
|
+
targets: [name],
|
|
140
|
+
ci: { branch: green.branch, commit, phase: entry.phase, quarantine: { test: entry.test, ...(entry.file !== undefined ? { file: entry.file } : {}), issue: entry.issue, until: entry.until } },
|
|
141
|
+
run,
|
|
142
|
+
},
|
|
143
|
+
{ env },
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface QuarantineReport {
|
|
148
|
+
phase: string;
|
|
149
|
+
commit: string;
|
|
150
|
+
results: QuarantineResult[];
|
|
151
|
+
/** The tests told about, or that would be with `dryRun`; `sent` when a delivery went through. */
|
|
152
|
+
told: { name: string; sent: boolean }[];
|
|
153
|
+
dryRun: boolean;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Read the run's JUnit files, match them to `phase`'s entries, and send `ci.quarantine-passed` for each that passed. */
|
|
157
|
+
export async function quarantineReport(req: {
|
|
158
|
+
green: CiGreen;
|
|
159
|
+
phase: string;
|
|
160
|
+
junit: readonly string[];
|
|
161
|
+
commit: string;
|
|
162
|
+
dryRun?: boolean;
|
|
163
|
+
env?: NodeJS.ProcessEnv;
|
|
164
|
+
sendNotify?: typeof realSendNotify;
|
|
165
|
+
}): Promise<QuarantineReport> {
|
|
166
|
+
const { green, phase } = req;
|
|
167
|
+
if (!green.phases.some((p) => p.name === phase)) {
|
|
168
|
+
throw new WorkspaceReadError("declaration-invalid", `ci.green declares no phase ${JSON.stringify(phase)}; it declares ${green.phases.map((p) => p.name).join(", ")}`);
|
|
169
|
+
}
|
|
170
|
+
const cases = req.junit.flatMap((xml) => parseJUnit(xml));
|
|
171
|
+
const results = quarantineResults(green, phase, cases);
|
|
172
|
+
const dryRun = req.dryRun === true;
|
|
173
|
+
const send = req.sendNotify ?? realSendNotify;
|
|
174
|
+
const told: QuarantineReport["told"] = [];
|
|
175
|
+
for (const r of results.filter((x) => x.outcome === "passed")) {
|
|
176
|
+
const name = quarantineName(r.entry);
|
|
177
|
+
if (!green.notify) continue;
|
|
178
|
+
if (dryRun) {
|
|
179
|
+
told.push({ name, sent: false });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const deliveries: NotifyDelivery[] = await send(green.notify, quarantinePassedEvent(green, r.entry, req.commit, req.env ?? process.env), { env: req.env ?? process.env });
|
|
183
|
+
told.push({ name, sent: deliveries.some((d) => d.ok) });
|
|
184
|
+
}
|
|
185
|
+
return { phase, commit: req.commit, results, told, dryRun };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const LABEL: Record<QuarantineOutcome, string> = { passed: "passed", flaky: "flaky", failed: "failed", skipped: "skipped", "not-run": "not run" };
|
|
189
|
+
|
|
190
|
+
/** The report as text: a line per entry, then what was told. */
|
|
191
|
+
export function formatQuarantineReport(r: QuarantineReport, green: CiGreen): string {
|
|
192
|
+
const lines = [`quarantine of phase ${r.phase} at ${r.commit.slice(0, 12)}: ${r.results.length} test${r.results.length === 1 ? "" : "s"}`];
|
|
193
|
+
for (const x of r.results) {
|
|
194
|
+
const hint = x.outcome === "passed" ? ": it may be fixed; take it out once the issue says so" : "";
|
|
195
|
+
lines.push(` ${LABEL[x.outcome].padEnd(8)} ${quarantineName(x.entry)} (${x.entry.issue}, until ${x.entry.until})${hint}`);
|
|
196
|
+
}
|
|
197
|
+
const passed = r.results.filter((x) => x.outcome === "passed").length;
|
|
198
|
+
if (passed > 0 && !green.notify) lines.push(" ci.green.notify is not set, so no ci.quarantine-passed was sent");
|
|
199
|
+
for (const t of r.told) lines.push(` ${r.dryRun ? "would tell" : t.sent ? "told" : "noted (no notify variable set, or every delivery failed)"} ci.quarantine-passed: ${t.name}`);
|
|
200
|
+
return lines.join("\n");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const USAGE = "chant ci quarantine report --phase <name> --junit <file>... [--commit <sha>] [--dry-run] [--json]";
|
|
204
|
+
|
|
205
|
+
const describe = (err: unknown) => (err instanceof WorkspaceReadError ? err.describe() : err instanceof Error ? err.message : String(err));
|
|
206
|
+
|
|
207
|
+
/** `chant ci quarantine report` (#4677). */
|
|
208
|
+
export async function runCiQuarantineReport(ctx: CommandContext): Promise<number> {
|
|
209
|
+
const { args } = ctx;
|
|
210
|
+
try {
|
|
211
|
+
if (!args.phase) throw new Error("--phase names the ci.green phase whose quarantined tests the run ran");
|
|
212
|
+
const files = args.quarantineJunit ?? [];
|
|
213
|
+
if (files.length === 0) throw new Error("--junit names the JUnit XML the run wrote; repeat it for several");
|
|
214
|
+
const declaration = readDeclaration(locateWorkspace(process.cwd()).tree);
|
|
215
|
+
const green = declaration.ci?.green;
|
|
216
|
+
if (!green) throw new WorkspaceReadError("declaration-invalid", `${declaration.file} declares no ci.green, so it has no quarantine`);
|
|
217
|
+
const junit = files.map((f) => {
|
|
218
|
+
try {
|
|
219
|
+
return readFileSync(resolve(f), "utf8");
|
|
220
|
+
} catch (err) {
|
|
221
|
+
throw new Error(`could not read --junit ${f}: ${err instanceof Error ? err.message : String(err)}`);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
const commit = args.commit ?? process.env.GITHUB_SHA ?? execFileSync("git", ["rev-parse", "HEAD"], { encoding: "utf-8" }).trim();
|
|
225
|
+
const report = await quarantineReport({ green, phase: args.phase, junit, commit, dryRun: args.dryRun === true });
|
|
226
|
+
if (args.json) {
|
|
227
|
+
const { results, ...rest } = report;
|
|
228
|
+
console.log(JSON.stringify({ ...rest, results: results.map((x) => ({ test: x.entry.test, ...(x.entry.file !== undefined ? { file: x.entry.file } : {}), issue: x.entry.issue, until: x.entry.until, outcome: x.outcome, cases: x.cases })) }, null, 2));
|
|
229
|
+
} else console.log(formatQuarantineReport(report, green));
|
|
230
|
+
return 0;
|
|
231
|
+
} catch (err) {
|
|
232
|
+
console.error(formatError({ message: `chant ci quarantine report: ${describe(err)}`, hint: USAGE }));
|
|
233
|
+
return 1;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4677 — the quarantine: ci.green.quarantine read and checked, and each
|
|
3
|
+
* runner's filter from `chant ci quarantine filter`.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { afterAll, afterEach, describe, expect, test, vi } from "vitest";
|
|
11
|
+
import { parseArgs } from "../cli/parse-args";
|
|
12
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
13
|
+
import { CI_QUARANTINE_FLOOR, PLAYWRIGHT_NOTHING, quarantineFilter, quarantineProblems, runCiQuarantine, utcToday } from "./ci-quarantine";
|
|
14
|
+
import { parseDeclaration, WorkspaceReadError, type CiGreen } from "./declaration";
|
|
15
|
+
|
|
16
|
+
const TODAY = "2026-11-01";
|
|
17
|
+
|
|
18
|
+
const RUST = { test: "arugulad::integration ssh::ssh_installs_runs", issue: "1234", until: "2026-11-10", why: "Fails twice on unrelated commits." };
|
|
19
|
+
const BARE = { test: "triggers::fires_once", issue: "https://github.com/acme/app/issues/7", until: "2026-11-01", why: "Times out under load." };
|
|
20
|
+
const SPEC = { file: "chat-control.spec.ts", test: "polish: ↑ edits the last message (and Esc cancels) [1.2]?", issue: "#1235", until: "2026-11-15", why: "Races the composer." };
|
|
21
|
+
|
|
22
|
+
function ws(quarantine: unknown): Record<string, unknown> {
|
|
23
|
+
return { name: "acme", schema: 1, members: [], ci: { green: { branch: "main", phases: { test: ["test (*)"], e2e: ["e2e"], lint: ["lint"] }, require: ["test", "e2e", "lint"], ...(quarantine !== undefined ? { quarantine } : {}) } } };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const greenOf = (quarantine: unknown): CiGreen => parseDeclaration(JSON.stringify(ws(quarantine), null, 2), "chant.workspace.json").ci!.green!;
|
|
27
|
+
|
|
28
|
+
const invalid = (quarantine: unknown): WorkspaceReadError => {
|
|
29
|
+
try {
|
|
30
|
+
greenOf(quarantine);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
return err as WorkspaceReadError;
|
|
33
|
+
}
|
|
34
|
+
throw new Error("read without an error");
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
describe("ci.green.quarantine (#4677)", () => {
|
|
38
|
+
test("is read phase by phase, with maxDays 14 by default and each entry located", () => {
|
|
39
|
+
const q = greenOf({ phases: { test: [RUST, BARE], e2e: [SPEC] } }).quarantine!;
|
|
40
|
+
expect(q.maxDays).toBe(14);
|
|
41
|
+
expect(q.entries.map((e) => [e.phase, e.test, e.file ?? null, e.pointer])).toEqual([
|
|
42
|
+
["test", RUST.test, null, "/ci/green/quarantine/phases/test/0"],
|
|
43
|
+
["test", BARE.test, null, "/ci/green/quarantine/phases/test/1"],
|
|
44
|
+
["e2e", SPEC.test, SPEC.file, "/ci/green/quarantine/phases/e2e/0"],
|
|
45
|
+
]);
|
|
46
|
+
expect(q.entries[0]!.location).toMatchObject({ file: "chant.workspace.json", line: expect.any(Number) });
|
|
47
|
+
expect(greenOf(undefined).quarantine).toBeUndefined();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("refuses an undeclared phase, a day that isn't one, a test listed twice and an entry without an issue", () => {
|
|
51
|
+
expect(invalid({ phases: { unit: [RUST] } }).message).toContain('names the phase "unit", which ci.green.phases does not declare');
|
|
52
|
+
expect(invalid({ phases: { test: [{ ...RUST, until: "2026-02-30" }] } }).message).toContain("until is not a day");
|
|
53
|
+
expect(invalid({ phases: { test: [RUST, RUST] } }).message).toContain("lists");
|
|
54
|
+
const { issue: _issue, ...noIssue } = RUST;
|
|
55
|
+
expect(invalid({ phases: { test: [noIssue] } }).code).toBe("declaration-invalid");
|
|
56
|
+
expect(invalid({ maxDays: 0, phases: { test: [RUST] } }).code).toBe("declaration-invalid");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("an entry past its until, or further out than maxDays, is a problem; the last day and the 14th day out are not", () => {
|
|
60
|
+
const green = greenOf({ phases: { test: [RUST, BARE, { ...RUST, test: "x::y", until: "2026-10-31" }, { ...RUST, test: "x::z", until: "2026-11-16" }] } });
|
|
61
|
+
expect(quarantineProblems(green, TODAY).map((p) => p.message)).toEqual([
|
|
62
|
+
"ci.green.quarantine: test: x::y (1234) expired on 2026-10-31: fix the test and delete the entry, or delete the test",
|
|
63
|
+
"ci.green.quarantine: test: x::z (1234) stays out until 2026-11-16, more than 14 days from 2026-11-01 (ci.green.quarantine.maxDays)",
|
|
64
|
+
]);
|
|
65
|
+
expect(quarantineProblems(greenOf({ maxDays: 30, phases: { test: [{ ...RUST, until: "2026-11-16" }] } }), TODAY)).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("ci quarantine filter (#4677)", () => {
|
|
70
|
+
const green = greenOf({ phases: { test: [RUST, BARE], e2e: [SPEC, { file: "nav/menu.spec.ts", test: "opens", issue: "9", until: "2026-11-02", why: "w" }] } });
|
|
71
|
+
|
|
72
|
+
test("nextest: a filterset leaving the phase's tests out, or with --only selecting them", () => {
|
|
73
|
+
const set = "(binary_id(=arugulad::integration) & test(=ssh::ssh_installs_runs)) | test(=triggers::fires_once)";
|
|
74
|
+
expect(quarantineFilter(green, { phase: "test", runner: "nextest", today: TODAY }).filter).toBe(`not (${set})`);
|
|
75
|
+
expect(quarantineFilter(green, { phase: "test", runner: "nextest", only: true, today: TODAY }).filter).toBe(set);
|
|
76
|
+
expect(quarantineFilter(green, { phase: "lint", runner: "nextest", today: TODAY }).filter).toBe("all()");
|
|
77
|
+
expect(quarantineFilter(green, { phase: "lint", runner: "nextest", only: true, today: TODAY }).filter).toBe("none()");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("playwright: one pattern matching each quarantined test's title path and no other", () => {
|
|
81
|
+
const { filter, entries } = quarantineFilter(green, { phase: "e2e", runner: "playwright", today: TODAY });
|
|
82
|
+
expect(entries).toHaveLength(2);
|
|
83
|
+
// As Playwright's CLI builds a --grep-invert from a string.
|
|
84
|
+
const re = new RegExp(filter, "i");
|
|
85
|
+
expect(re.test(` chromium chat-control.spec.ts ${SPEC.test}`)).toBe(true);
|
|
86
|
+
expect(re.test(` chromium chat-control.spec.ts composer ${SPEC.test} @slow`)).toBe(true);
|
|
87
|
+
expect(re.test(` nav/menu.spec.ts opens`)).toBe(true);
|
|
88
|
+
expect(re.test(` chromium chat-control.spec.ts polish: x edits the last message (and Esc cancels) [1.2]?`)).toBe(false);
|
|
89
|
+
expect(re.test(` chromium chat-control.spec.ts ${SPEC.test} too`)).toBe(false);
|
|
90
|
+
expect(re.test(` chromium other.spec.ts ${SPEC.test}`)).toBe(false);
|
|
91
|
+
expect(re.test(` nav/menu.spec.ts opens later`)).toBe(false);
|
|
92
|
+
expect(quarantineFilter(green, { phase: "test", runner: "playwright", today: TODAY }).filter).toBe(PLAYWRIGHT_NOTHING);
|
|
93
|
+
expect(new RegExp(PLAYWRIGHT_NOTHING, "gi").test(" chromium a.spec.ts a")).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("list: every entry of the phase, a line each, file and test split by a tab", () => {
|
|
97
|
+
expect(quarantineFilter(green, { phase: "e2e", runner: "list", today: TODAY }).filter).toBe(`chat-control.spec.ts\t${SPEC.test}\nnav/menu.spec.ts\topens`);
|
|
98
|
+
expect(quarantineFilter(green, { phase: "lint", runner: "list", today: TODAY }).filter).toBe("");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("refuses the phase's expired entry, but --only and other phases don't", () => {
|
|
102
|
+
const later = "2026-11-03";
|
|
103
|
+
expect(() => quarantineFilter(green, { phase: "e2e", runner: "playwright", today: later })).toThrow(/nav\/menu.spec.ts › opens \(9\) expired on 2026-11-02/);
|
|
104
|
+
expect(quarantineFilter(green, { phase: "e2e", runner: "playwright", only: true, today: later }).entries).toHaveLength(2);
|
|
105
|
+
expect(() => quarantineFilter(green, { phase: "test", runner: "nextest", today: later })).toThrow(/expired on 2026-11-01/);
|
|
106
|
+
expect(quarantineFilter(green, { phase: "lint", runner: "nextest", today: later }).filter).toBe("all()");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("refuses a nextest name its matchers can't hold, and an undeclared phase", () => {
|
|
110
|
+
const odd = greenOf({ phases: { test: [{ ...RUST, test: "a b c" }] } });
|
|
111
|
+
expect(() => quarantineFilter(odd, { phase: "test", runner: "nextest", today: TODAY })).toThrow(/isn't a nextest test/);
|
|
112
|
+
expect(() => quarantineFilter(green, { phase: "unit", runner: "nextest", today: TODAY })).toThrow(/declares no phase "unit"/);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("chant ci quarantine (#4677)", () => {
|
|
117
|
+
const scratch: string[] = [];
|
|
118
|
+
afterAll(() => {
|
|
119
|
+
for (const d of scratch) rmSync(d, { recursive: true, force: true });
|
|
120
|
+
});
|
|
121
|
+
afterEach(() => vi.restoreAllMocks());
|
|
122
|
+
|
|
123
|
+
function run(quarantine: unknown, args: Record<string, unknown>): Promise<{ code: number; out: string; err: string }> {
|
|
124
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "chant-quarantine-")));
|
|
125
|
+
scratch.push(root);
|
|
126
|
+
execFileSync("git", ["init", "-q"], { cwd: root });
|
|
127
|
+
writeFileSync(join(root, "chant.workspace.json"), JSON.stringify(ws(quarantine), null, 2));
|
|
128
|
+
vi.spyOn(process, "cwd").mockReturnValue(root);
|
|
129
|
+
const out: string[] = [];
|
|
130
|
+
const err: string[] = [];
|
|
131
|
+
vi.spyOn(console, "log").mockImplementation((...m: unknown[]) => void out.push(m.map(String).join(" ")));
|
|
132
|
+
vi.spyOn(console, "error").mockImplementation((...m: unknown[]) => void err.push(m.map(String).join(" ")));
|
|
133
|
+
return runCiQuarantine({ args: { command: "ci", path: "quarantine", ...args }, plugins: [] } as never).then((code) => ({ code, out: out.join("\n"), err: err.join("\n") }));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const day = (offset: number) => utcToday(new Date(Date.now() + offset * 86_400_000));
|
|
137
|
+
|
|
138
|
+
test("check passes on current entries and fails at an expired one's line", async () => {
|
|
139
|
+
const ok = await run({ phases: { test: [{ ...RUST, until: day(3) }] } }, { extraPositional: "check" });
|
|
140
|
+
expect(ok).toMatchObject({ code: 0, out: expect.stringContaining("1 test quarantined, every one current") });
|
|
141
|
+
const expired = await run({ phases: { test: [{ ...RUST, until: day(-1) }] } }, { extraPositional: "check" });
|
|
142
|
+
expect(expired.code).toBe(1);
|
|
143
|
+
expect(expired.err).toMatch(/^chant\.workspace\.json:\d+:\d+: ci\.green\.quarantine: test: .* expired on /);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("its floor is the next release", () => {
|
|
147
|
+
expect(CI_QUARANTINE_FLOOR).toBe(NEXT_RELEASE);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("parses --phase, --runner and --only", () => {
|
|
151
|
+
expect(parseArgs(["ci", "quarantine", "filter", "--phase", "test", "--runner", "nextest", "--only"])).toMatchObject({ command: "ci", path: "quarantine", extraPositional: "filter", phase: "test", quarantineRunner: "nextest", quarantineOnly: true });
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("filter prints the runner's filter, and --runner is checked", async () => {
|
|
155
|
+
const q = { phases: { test: [{ ...RUST, until: day(3) }] } };
|
|
156
|
+
expect(await run(q, { extraPositional: "filter", phase: "test", quarantineRunner: "nextest" })).toMatchObject({ code: 0, out: "not ((binary_id(=arugulad::integration) & test(=ssh::ssh_installs_runs)))" });
|
|
157
|
+
const json = await run(q, { extraPositional: "filter", phase: "test", quarantineRunner: "list", json: true });
|
|
158
|
+
expect(JSON.parse(json.out)).toMatchObject({ phase: "test", runner: "list", only: false, filter: RUST.test, entries: [{ phase: "test", test: RUST.test, issue: "1234" }] });
|
|
159
|
+
expect(await run(q, { extraPositional: "filter", phase: "test", quarantineRunner: "jest" })).toMatchObject({ code: 1, err: expect.stringContaining('--runner takes nextest, playwright, list, not "jest"') });
|
|
160
|
+
});
|
|
161
|
+
});
|
|
@@ -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.
|