@sagentlab/navarch-runtime 0.1.161 → 0.1.163
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/api.cjs +1 -1
- package/dist/git-worktree.cjs +9 -0
- package/dist/qa-fixture.cjs +179 -0
- package/dist/qa-runner.cjs +94 -18
- package/dist/session.cjs +9 -3
- package/package.json +1 -1
package/dist/api.cjs
CHANGED
|
@@ -136,7 +136,7 @@ class NavarchApiClient {
|
|
|
136
136
|
}
|
|
137
137
|
/** schema-design.md §7 — `POST /api/dispatch/claim {machine_capacity, capabilities} → task + context bundle`. */
|
|
138
138
|
async claim(req) {
|
|
139
|
-
const result = await this.request("POST", "/api/dispatch/claim", req, { allowEmpty: true });
|
|
139
|
+
const result = await this.request("POST", "/api/dispatch/claim", { ...req, delivery_baseline_protocol: 1 }, { allowEmpty: true });
|
|
140
140
|
if (!result || result.task == null)
|
|
141
141
|
return null;
|
|
142
142
|
return result;
|
package/dist/git-worktree.cjs
CHANGED
|
@@ -72,6 +72,7 @@ class GitWorktree {
|
|
|
72
72
|
sessionTokenMarker;
|
|
73
73
|
hostedCheckpointRef;
|
|
74
74
|
hostedCheckpointLocalRef;
|
|
75
|
+
hostedCheckpointLeaseId;
|
|
75
76
|
/** Set when the resumed remote branch had lost its ownership commit and must be re-marked. */
|
|
76
77
|
adoptedUnmarkedBranch = false;
|
|
77
78
|
constructor(options) {
|
|
@@ -122,6 +123,7 @@ class GitWorktree {
|
|
|
122
123
|
this.ownershipCommitIdentity = options.ownershipCommitIdentity ?? { name: "Navarch", email: "runtime@navarch.local" };
|
|
123
124
|
this.hostedCheckpointRef = options.restoreHostedCheckpoint ? hostedCheckpointRef(options.taskId) : null;
|
|
124
125
|
this.hostedCheckpointLocalRef = `refs/navarch/restored-checkpoints/${taskKey}`;
|
|
126
|
+
this.hostedCheckpointLeaseId = options.hostedCheckpointLeaseId;
|
|
125
127
|
}
|
|
126
128
|
async prepare(signal) {
|
|
127
129
|
signal?.throwIfAborted();
|
|
@@ -331,6 +333,13 @@ class GitWorktree {
|
|
|
331
333
|
if (!/^[0-9a-f]{40,64}$/i.test(sha) || !/^[0-9a-f]{40,64}$/i.test(parent)) {
|
|
332
334
|
throw new Error("the checkpoint ref did not resolve to a snapshot commit with a parent");
|
|
333
335
|
}
|
|
336
|
+
if (this.hostedCheckpointLeaseId !== undefined) {
|
|
337
|
+
const body = (await this.runGit(["--git-dir", this.repositoryPath, "show", "-s", "--format=%B", sha], false)).stdout;
|
|
338
|
+
const leases = body.split("\n").filter(line => line.startsWith("Navarch-Checkpoint-Lease:"));
|
|
339
|
+
if (leases.length !== 1 || leases[0] !== `Navarch-Checkpoint-Lease: ${this.hostedCheckpointLeaseId}`) {
|
|
340
|
+
throw new Error("checkpoint lease identity is missing or different; remote checkpoint preserved");
|
|
341
|
+
}
|
|
342
|
+
}
|
|
334
343
|
return { ref, sha: sha, parent: parent };
|
|
335
344
|
}
|
|
336
345
|
catch (error) {
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.QaFixtureError = void 0;
|
|
7
|
+
exports.createQaFixture = createQaFixture;
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const node_crypto_1 = require("node:crypto");
|
|
11
|
+
const node_http_1 = require("node:http");
|
|
12
|
+
class QaFixtureError extends Error {
|
|
13
|
+
reason;
|
|
14
|
+
failure_class = "resource";
|
|
15
|
+
constructor(reason) {
|
|
16
|
+
super(reason);
|
|
17
|
+
this.reason = reason;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.QaFixtureError = QaFixtureError;
|
|
21
|
+
/** Keep the listening socket: finding a free port then releasing it is a race. */
|
|
22
|
+
async function createQaFixture(options) {
|
|
23
|
+
const budget = options.operationTimeoutMs ?? 5000;
|
|
24
|
+
if (!Number.isInteger(budget) || budget < 1 || budget > 10_000 ||
|
|
25
|
+
options.scenarios.length > 100 || options.scenarios.some(name => !/^[a-z][a-z0-9_-]{0,63}$/.test(name))) {
|
|
26
|
+
throw new Error("Invalid local fixture limits");
|
|
27
|
+
}
|
|
28
|
+
const namespace = `qa-${(0, node_crypto_1.randomUUID)()}`;
|
|
29
|
+
const root = await node_fs_1.promises.mkdtemp(node_path_1.default.join(await node_fs_1.promises.realpath(options.worktree), ".qa-fixture-"));
|
|
30
|
+
const databaseDir = node_path_1.default.join(root, "db");
|
|
31
|
+
const token = (0, node_crypto_1.randomBytes)(32).toString("hex");
|
|
32
|
+
const lifetime = new AbortController();
|
|
33
|
+
const context = { namespace, databaseDir, signal: lifetime.signal };
|
|
34
|
+
let closed = false, uncertain = false;
|
|
35
|
+
let pending;
|
|
36
|
+
const handlers = new Set();
|
|
37
|
+
const send = (res, status, reason) => {
|
|
38
|
+
if (!res.destroyed && !res.writableEnded) {
|
|
39
|
+
res.writeHead(status, { "content-type": "application/json" });
|
|
40
|
+
res.end(JSON.stringify({ namespace, reason, ...(status >= 400 ? { failure_class: "resource" } : {}) }));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const server = (0, node_http_1.createServer)((req, res) => {
|
|
44
|
+
void (async () => {
|
|
45
|
+
if (closed) {
|
|
46
|
+
send(res, 503, "fixture_closed");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!req.url?.startsWith("/__qa/")) {
|
|
50
|
+
const handling = Promise.resolve().then(() => options.handle(req, res, context));
|
|
51
|
+
handlers.add(handling);
|
|
52
|
+
try {
|
|
53
|
+
await handling;
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
handlers.delete(handling);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (req.headers["x-navarch-fixture-token"] !== token) {
|
|
61
|
+
send(res, 403, "fixture_scope_denied");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const action = req.url === `/__qa/${namespace}/seed` ? "seed" : req.url === `/__qa/${namespace}/reset` ? "reset" : undefined;
|
|
65
|
+
if (req.method !== "POST" || !action) {
|
|
66
|
+
send(res, 404, "fixture_route_missing");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (pending || uncertain) {
|
|
70
|
+
send(res, 409, uncertain ? "fixture_completion_unknown" : "fixture_busy");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// Claim the slot before reading the body, including slow/chunked clients.
|
|
74
|
+
let release;
|
|
75
|
+
pending = new Promise(resolve => { release = resolve; });
|
|
76
|
+
const controller = new AbortController();
|
|
77
|
+
const abort = () => controller.abort();
|
|
78
|
+
lifetime.signal.addEventListener("abort", abort, { once: true });
|
|
79
|
+
let started = false;
|
|
80
|
+
const deadline = performance.now() + budget;
|
|
81
|
+
const timer = setTimeout(() => {
|
|
82
|
+
uncertain = started;
|
|
83
|
+
controller.abort();
|
|
84
|
+
send(res, 504, started ? "fixture_completion_unknown" : "fixture_request_timeout");
|
|
85
|
+
if (!started)
|
|
86
|
+
req.destroy();
|
|
87
|
+
}, budget);
|
|
88
|
+
try {
|
|
89
|
+
let body = "";
|
|
90
|
+
for await (const chunk of req) {
|
|
91
|
+
body += Buffer.from(chunk).toString("utf8");
|
|
92
|
+
if (Buffer.byteLength(body) > 1024) {
|
|
93
|
+
send(res, 413, "fixture_body_too_large");
|
|
94
|
+
req.destroy();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
let value;
|
|
99
|
+
try {
|
|
100
|
+
value = JSON.parse(body || "{}");
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
send(res, 400, "fixture_scenario_invalid");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (!value || typeof value !== "object" || Array.isArray(value) ||
|
|
107
|
+
Object.keys(value).some(key => action !== "seed" || key !== "scenario") ||
|
|
108
|
+
(action === "seed" && !(typeof value.scenario === "string" && options.scenarios.includes(value.scenario)))) {
|
|
109
|
+
send(res, 400, "fixture_scenario_invalid");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (controller.signal.aborted)
|
|
113
|
+
return;
|
|
114
|
+
started = true;
|
|
115
|
+
await options.mutate(action, value.scenario, { ...context, signal: controller.signal });
|
|
116
|
+
if (performance.now() >= deadline) {
|
|
117
|
+
uncertain = true;
|
|
118
|
+
controller.abort();
|
|
119
|
+
send(res, 504, "fixture_completion_unknown");
|
|
120
|
+
}
|
|
121
|
+
else if (!controller.signal.aborted)
|
|
122
|
+
send(res, 200, "fixture_ready");
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// A rejected adapter may have committed a write. Never replay it.
|
|
126
|
+
uncertain = started;
|
|
127
|
+
send(res, 503, started ? "fixture_completion_unknown" : "fixture_request_failed");
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
clearTimeout(timer);
|
|
131
|
+
lifetime.signal.removeEventListener("abort", abort);
|
|
132
|
+
release();
|
|
133
|
+
pending = undefined;
|
|
134
|
+
}
|
|
135
|
+
})().catch(() => send(res, 500, "fixture_runtime_error"));
|
|
136
|
+
});
|
|
137
|
+
server.requestTimeout = budget;
|
|
138
|
+
server.headersTimeout = budget;
|
|
139
|
+
const remove = () => node_fs_1.promises.rm(root, { recursive: true, force: true });
|
|
140
|
+
try {
|
|
141
|
+
await node_fs_1.promises.mkdir(databaseDir, { mode: 0o700 });
|
|
142
|
+
await node_fs_1.promises.writeFile(node_path_1.default.join(root, "owner.json"), JSON.stringify({ namespace, workerId: options.workerId, pid: process.pid }));
|
|
143
|
+
await new Promise((resolve, reject) => {
|
|
144
|
+
server.once("error", reject);
|
|
145
|
+
server.listen(0, "127.0.0.1", () => { server.removeListener("error", reject); resolve(); });
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
server.close();
|
|
150
|
+
await remove();
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
const url = `http://127.0.0.1:${server.address().port}`;
|
|
154
|
+
const mutate = async (action, scenario) => {
|
|
155
|
+
const response = await fetch(`${url}/__qa/${namespace}/${action}`, { method: "POST",
|
|
156
|
+
headers: { "x-navarch-fixture-token": token, "content-type": "application/json" },
|
|
157
|
+
body: JSON.stringify(scenario === undefined ? {} : { scenario }), signal: AbortSignal.timeout(budget + 1000) });
|
|
158
|
+
const result = await response.json();
|
|
159
|
+
if (!response.ok)
|
|
160
|
+
throw new QaFixtureError(result.reason);
|
|
161
|
+
};
|
|
162
|
+
let closing;
|
|
163
|
+
return { namespace, databaseDir, url, token,
|
|
164
|
+
seed: (scenario) => mutate("seed", scenario), reset: () => mutate("reset"),
|
|
165
|
+
close: () => closing ??= (async () => {
|
|
166
|
+
closed = true;
|
|
167
|
+
lifetime.abort();
|
|
168
|
+
server.closeAllConnections();
|
|
169
|
+
await new Promise(resolve => server.close(() => resolve()));
|
|
170
|
+
// A timed-out adapter can still be writing. Retain its directory until it
|
|
171
|
+
// settles, even if it ignores abort. Never delete data beneath a writer.
|
|
172
|
+
const active = [...handlers, ...(pending ? [pending] : [])];
|
|
173
|
+
if (active.length)
|
|
174
|
+
void Promise.allSettled(active).then(remove).catch(() => { });
|
|
175
|
+
else
|
|
176
|
+
await remove();
|
|
177
|
+
})(),
|
|
178
|
+
};
|
|
179
|
+
}
|
package/dist/qa-runner.cjs
CHANGED
|
@@ -15,22 +15,30 @@ const sandbox_cjs_1 = require("./sandbox.cjs");
|
|
|
15
15
|
const playwright_server_cjs_1 = require("./playwright-server.cjs");
|
|
16
16
|
const lease_heartbeat_cjs_1 = require("./lease-heartbeat.cjs");
|
|
17
17
|
const api_cjs_1 = require("./api.cjs");
|
|
18
|
+
const redact_cjs_1 = require("./redact.cjs");
|
|
18
19
|
/** Aggregate every matching test/project: one failed viewport fails the case. */
|
|
19
|
-
function parseQaReport(raw, assignment, missingReason = "automation_missing") {
|
|
20
|
+
function parseQaReport(raw, assignment, missingReason = "automation_missing", missingClass = "setup", sanitize = redact_cjs_1.redactText) {
|
|
20
21
|
if (!raw || typeof raw !== "object" || !Array.isArray(raw.suites))
|
|
21
22
|
throw new Error("Invalid Playwright JSON report");
|
|
23
|
+
const globalErrors = raw.errors ?? [];
|
|
22
24
|
const found = new Map();
|
|
23
25
|
const selected = new Set(assignment.items.map(item => item.case_id));
|
|
24
26
|
const walk = (suite, parents) => {
|
|
25
27
|
const titles = [...parents, suite.title ?? ""];
|
|
26
28
|
for (const spec of suite.specs ?? []) {
|
|
27
29
|
for (const test of spec.tests ?? []) {
|
|
28
|
-
const text = [...titles, spec.title ?? "", ...(spec.tags ?? []), ...(test.tags ?? [])].join(" ");
|
|
30
|
+
const text = [...titles, spec.title ?? "", ...(spec.tags ?? []).map(tag => tag.startsWith("@") ? tag : `@${tag}`), ...(test.tags ?? []).map(tag => tag.startsWith("@") ? tag : `@${tag}`)].join(" ");
|
|
29
31
|
const ids = new Set([...text.matchAll(/@TC-[A-Z0-9]+(?:-[A-Z0-9]+)*(?:#[1-9][0-9]*)?(?![A-Za-z0-9_#-])/g)].map(match => match[0].slice(1)));
|
|
30
32
|
const attempts = test.results ?? [];
|
|
31
33
|
const last = attempts.at(-1);
|
|
32
34
|
// Expected failures are still product failures for case reporting.
|
|
33
35
|
const status = last?.status === "passed" ? "passed" : last?.status === "skipped" ? "skipped" : last?.status === "interrupted" && missingReason === "runner_timeout" ? "blocked" : "failed";
|
|
36
|
+
const annotatedClass = test.annotations?.find(a => a.type === "navarch:failure_class")?.description;
|
|
37
|
+
const failures = attempts.filter(result => ["failed", "timedOut", "interrupted"].includes(result.status ?? "")).map(result => ({
|
|
38
|
+
retry: Math.min(32767, Math.max(0, result.retry ?? 0)),
|
|
39
|
+
failure_class: (result.status !== "failed" ? "runtime" : ["setup", "resource", "runtime", "product_assertion"].includes(annotatedClass ?? "") ? annotatedClass : "product_assertion"),
|
|
40
|
+
summary: sanitize(result.error?.message?.trim() || `Playwright: ${result.status}`).slice(0, 2000),
|
|
41
|
+
}));
|
|
34
42
|
for (const id of ids) {
|
|
35
43
|
if (!selected.has(id) || !last)
|
|
36
44
|
continue;
|
|
@@ -38,7 +46,8 @@ function parseQaReport(raw, assignment, missingReason = "automation_missing") {
|
|
|
38
46
|
rows.push({ run_id: assignment.run.id, case_id: id, attempt: 1, status,
|
|
39
47
|
flaky: status === "passed" && ((last.retry ?? 0) > 0 || attempts.some(result => ["failed", "timedOut", "interrupted"].includes(result.status ?? ""))),
|
|
40
48
|
duration_ms: Math.min(2147483647, attempts.reduce((sum, result) => sum + Math.max(0, result.duration ?? 0), 0)),
|
|
41
|
-
...(["failed", "blocked"].includes(status) ? { failure_summary: status === "blocked" ? missingReason : (last.error?.message
|
|
49
|
+
...(["failed", "blocked"].includes(status) ? { failure_summary: status === "blocked" ? missingReason : sanitize(last.error?.message?.trim() || `Playwright: ${last.status ?? "unknown"}`).slice(0, 8000) } : {}),
|
|
50
|
+
...(failures.length ? { failure_class: failures[0].failure_class, failure_attempts: failures.slice(0, 50), failure_attempts_truncated: failures.length > 50 } : {}),
|
|
42
51
|
traces: attempts.flatMap(result => (result.attachments ?? []).filter(a => a.name === "trace" && a.path).map(a => a.path)),
|
|
43
52
|
});
|
|
44
53
|
found.set(id, rows);
|
|
@@ -54,11 +63,29 @@ function parseQaReport(raw, assignment, missingReason = "automation_missing") {
|
|
|
54
63
|
const failed = rows.find(row => row.status === "failed");
|
|
55
64
|
const blocked = rows.find(row => row.status === "blocked");
|
|
56
65
|
const skipped = rows.some(row => row.status === "skipped");
|
|
57
|
-
|
|
66
|
+
const failures = rows.flatMap(row => row.failure_attempts ?? []);
|
|
67
|
+
const result = { run_id: assignment.run.id, case_id: item.case_id, attempt: item.attempt ?? 1,
|
|
58
68
|
status: failed ? "failed" : blocked ? "blocked" : skipped ? "skipped" : rows.length ? "passed" : "blocked",
|
|
59
69
|
flaky: rows.some(row => row.flaky), duration_ms: Math.min(2147483647, rows.reduce((sum, row) => sum + (row.duration_ms ?? 0), 0)),
|
|
60
70
|
...(!rows.length ? { failure_summary: missingReason } : failed || blocked ? { failure_summary: (failed ?? blocked).failure_summary } : {}),
|
|
71
|
+
...(!rows.length ? { failure_class: missingClass } : failures.length ? {
|
|
72
|
+
failure_class: (failed ?? blocked)?.failure_class ?? failures[0].failure_class,
|
|
73
|
+
failure_attempts: failures.slice(0, 50), failure_attempts_truncated: failures.length > 50 || rows.some(row => row.failure_attempts_truncated),
|
|
74
|
+
} : {}),
|
|
61
75
|
traces: [...new Set(rows.flatMap(row => row.traces))], };
|
|
76
|
+
if (globalErrors.length) {
|
|
77
|
+
const failure_class = found.size ? "runtime" : missingClass;
|
|
78
|
+
const diagnostics = globalErrors.slice(0, 50).map(error => ({ retry: 0, failure_class,
|
|
79
|
+
summary: sanitize(error.message?.trim() || "Playwright global error").slice(0, 2000) }));
|
|
80
|
+
if (result.status !== "failed") {
|
|
81
|
+
result.status = "blocked";
|
|
82
|
+
result.failure_class = failure_class;
|
|
83
|
+
result.failure_summary = diagnostics[0].summary;
|
|
84
|
+
}
|
|
85
|
+
result.failure_attempts_truncated ||= (result.failure_attempts?.length ?? 0) + globalErrors.length > 50;
|
|
86
|
+
result.failure_attempts = [...result.failure_attempts ?? [], ...diagnostics].slice(0, 50);
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
62
89
|
});
|
|
63
90
|
}
|
|
64
91
|
const qaCaseGrep = (ids) => `@(?:${ids.map(id => id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})(?![A-Za-z0-9_#-])`;
|
|
@@ -142,6 +169,10 @@ async function executeQaRunner(deps) {
|
|
|
142
169
|
const htmlDir = node_path_1.default.join(workDir, "playwright-report");
|
|
143
170
|
const traceDir = node_path_1.default.join(workDir, "test-results");
|
|
144
171
|
let report = { suites: [] }, failure;
|
|
172
|
+
let phase = "setup";
|
|
173
|
+
let exitCode;
|
|
174
|
+
let attempted = false;
|
|
175
|
+
const secrets = [];
|
|
145
176
|
const run = async (bin, args, env, timeoutMs) => {
|
|
146
177
|
controller.signal.throwIfAborted();
|
|
147
178
|
const result = await runner.run(bin, args, { cwd: repo, env, timeoutMs, signal: controller.signal });
|
|
@@ -166,6 +197,7 @@ async function executeQaRunner(deps) {
|
|
|
166
197
|
const value = issued.secrets[name];
|
|
167
198
|
if (typeof value !== "string")
|
|
168
199
|
throw new Error("Runner recipe secret unavailable");
|
|
200
|
+
secrets.push(value);
|
|
169
201
|
const converted = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(name) ? name : name.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
|
|
170
202
|
env[/^[0-9]/.test(converted) ? `_${converted}` : converted] = value;
|
|
171
203
|
}
|
|
@@ -184,6 +216,7 @@ async function executeQaRunner(deps) {
|
|
|
184
216
|
PLAYWRIGHT_JSON_OUTPUT_NAME: jsonFile, PLAYWRIGHT_HTML_OUTPUT_DIR: htmlDir, PLAYWRIGHT_HTML_OPEN: "never" };
|
|
185
217
|
// The runtime is outside the agent sandbox. On macOS the existing server
|
|
186
218
|
// gives loopback fixtures the same restricted browser used by agent suites.
|
|
219
|
+
phase = "resource";
|
|
187
220
|
if (process.platform === "darwin" && ["localhost", "127.0.0.1", "[::1]"].includes(new URL(assignment.target.url).hostname)) {
|
|
188
221
|
env.PW_TEST_CONNECT_WS_ENDPOINT = (await server.start({})).endpoint;
|
|
189
222
|
}
|
|
@@ -192,34 +225,65 @@ async function executeQaRunner(deps) {
|
|
|
192
225
|
const selection = await qaSelectionArgs(repo, workDir, assignment.items.filter(i => ["queued", "running"].includes(i.status)).map(i => i.case_id));
|
|
193
226
|
const executable = node_path_1.default.join(workDir, "navarch-run");
|
|
194
227
|
await node_fs_1.promises.writeFile(executable, `#!/bin/sh\nset -eu\n[ "$1" = ${JSON.stringify(commandName)} ] || exit 64\nshift\n[ "${"${1:-}"}" != -- ] || shift\n${commandScript}\n`, { mode: 0o700 });
|
|
195
|
-
|
|
228
|
+
phase = "runtime";
|
|
229
|
+
await node_fs_1.promises.rm(jsonFile, { force: true });
|
|
230
|
+
attempted = true;
|
|
231
|
+
exitCode = (await run(executable, [commandName, "--", ...selection, "--reporter=json,html", "--retries=1", "--trace=retain-on-failure", "--output", traceDir], env, command.timeout_s * 1000)).code;
|
|
196
232
|
}
|
|
197
|
-
catch {
|
|
233
|
+
catch (error) {
|
|
234
|
+
// Classify typed resource failures; do not infer a lock or timeout from prose.
|
|
235
|
+
const detail = error;
|
|
236
|
+
if (detail && (detail.failure_class === "resource" || ["EADDRINUSE", "ENOSPC", "EMFILE", "EAGAIN", "SQLITE_BUSY", "SQLITE_BUSY_SNAPSHOT"].includes(detail.code ?? "")))
|
|
237
|
+
phase = "resource";
|
|
198
238
|
failure = timedOut ? "runner_timeout" : "runner_error";
|
|
199
239
|
}
|
|
200
240
|
if (leaseLost)
|
|
201
241
|
return;
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
242
|
+
if (attempted) {
|
|
243
|
+
try {
|
|
244
|
+
report = JSON.parse(await node_fs_1.promises.readFile(jsonFile, "utf8"));
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
if (!timedOut)
|
|
248
|
+
failure ??= "runner_error";
|
|
249
|
+
}
|
|
208
250
|
}
|
|
209
251
|
let results;
|
|
210
252
|
try {
|
|
211
|
-
results = parseQaReport(report, assignment, timedOut ? "runner_timeout" : failure ?? "automation_missing");
|
|
253
|
+
results = parseQaReport(report, assignment, timedOut ? "runner_timeout" : failure ?? "automation_missing", timedOut ? "runtime" : failure ? phase : "setup", message => (0, redact_cjs_1.redactText)(message, secrets));
|
|
212
254
|
}
|
|
213
255
|
catch {
|
|
214
|
-
results = parseQaReport({ suites: [] }, assignment, timedOut ? "runner_timeout" : "runner_error");
|
|
256
|
+
results = parseQaReport({ suites: [] }, assignment, timedOut ? "runner_timeout" : "runner_error", "runtime");
|
|
257
|
+
}
|
|
258
|
+
const executionFailure = attempted && failure ? failure : exitCode !== undefined && exitCode !== 0 && !results.some(result => result.status === "failed") ? `Runner exited with code ${exitCode}` : undefined;
|
|
259
|
+
if (executionFailure && !report?.errors?.length) {
|
|
260
|
+
// A nonzero exit with no failed case is a runtime failure, even if every
|
|
261
|
+
// spec passed before a reporter or global teardown failed.
|
|
262
|
+
results = parseQaReport({ suites: Array.isArray(report?.suites) ? report.suites : [], errors: [{ message: executionFailure }] }, assignment, "runner_error", "runtime", message => (0, redact_cjs_1.redactText)(message, secrets));
|
|
263
|
+
}
|
|
264
|
+
// Summaries also use the parser sanitizer before applying size limits.
|
|
265
|
+
for (const result of results) {
|
|
266
|
+
if (result.failure_summary)
|
|
267
|
+
result.failure_summary = (0, redact_cjs_1.redactText)(result.failure_summary, secrets);
|
|
268
|
+
for (const attempt of result.failure_attempts ?? [])
|
|
269
|
+
attempt.summary = (0, redact_cjs_1.redactText)(attempt.summary, secrets);
|
|
215
270
|
}
|
|
216
271
|
const evidenceUrls = [];
|
|
272
|
+
const artifactRoots = async () => {
|
|
273
|
+
await node_fs_1.promises.mkdir(htmlDir, { recursive: true });
|
|
274
|
+
await node_fs_1.promises.mkdir(traceDir, { recursive: true });
|
|
275
|
+
const workspace = await node_fs_1.promises.realpath(workDir);
|
|
276
|
+
const roots = await Promise.all([htmlDir, traceDir].map(dir => node_fs_1.promises.realpath(dir)));
|
|
277
|
+
if (roots.some(root => !root.startsWith(workspace + node_path_1.default.sep)))
|
|
278
|
+
throw new Error("Artifact root outside runner workspace");
|
|
279
|
+
return roots;
|
|
280
|
+
};
|
|
217
281
|
const upload = async (file, mime) => {
|
|
218
282
|
if (leaseLost)
|
|
219
283
|
throw new Error("Runner lease lost");
|
|
220
284
|
const resolved = await node_fs_1.promises.realpath(file);
|
|
221
285
|
// Reports may contain arbitrary attachment paths; never upload host files.
|
|
222
|
-
const roots = await
|
|
286
|
+
const roots = await artifactRoots();
|
|
223
287
|
if (!roots.some(root => resolved.startsWith(root + node_path_1.default.sep)))
|
|
224
288
|
throw new Error("Artifact outside runner workspace");
|
|
225
289
|
const stat = await node_fs_1.promises.stat(resolved);
|
|
@@ -243,10 +307,22 @@ async function executeQaRunner(deps) {
|
|
|
243
307
|
return final.artifact_id;
|
|
244
308
|
};
|
|
245
309
|
let htmlId;
|
|
310
|
+
const diagnosticFile = node_path_1.default.join(htmlDir, `runner-diagnostics-${(0, node_crypto_1.randomUUID)()}.json`);
|
|
246
311
|
for (const result of results) {
|
|
247
|
-
if (result.status !== "failed")
|
|
312
|
+
if (result.status !== "failed" && !result.failure_attempts?.length)
|
|
248
313
|
continue;
|
|
249
|
-
|
|
314
|
+
if (!htmlId) {
|
|
315
|
+
const html = node_path_1.default.join(htmlDir, "index.html");
|
|
316
|
+
if (await node_fs_1.promises.stat(html).then(stat => stat.isFile(), () => false))
|
|
317
|
+
htmlId = await upload(html, "text/html");
|
|
318
|
+
else {
|
|
319
|
+
// Setup/report failures can have no HTML or traces. Persist safe
|
|
320
|
+
// diagnostics without inventing a product screenshot or test pass.
|
|
321
|
+
await artifactRoots();
|
|
322
|
+
await node_fs_1.promises.writeFile(diagnosticFile, JSON.stringify(results.map(({ traces: _traces, ...item }) => item)), { flag: "wx", mode: 0o600 });
|
|
323
|
+
htmlId = await upload(diagnosticFile, "text/plain");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
250
326
|
result.artifact_ids = [htmlId];
|
|
251
327
|
for (const trace of result.traces.slice(0, 49))
|
|
252
328
|
result.artifact_ids.push(await upload(node_path_1.default.resolve(repo, trace), "application/zip"));
|
|
@@ -260,7 +336,7 @@ async function executeQaRunner(deps) {
|
|
|
260
336
|
}
|
|
261
337
|
if (leaseLost)
|
|
262
338
|
return;
|
|
263
|
-
await api.completeLease(leaseId, { status: "completed", report: `QA runner (${assignment.target.commit_sha}):\n${results.map(item => `${item.case_id}: ${item.status}${item.flaky ? " (flaky)" : ""}${item.failure_summary ? ` — ${item.failure_summary}` : ""}`).join("\n")}`,
|
|
339
|
+
await api.completeLease(leaseId, { status: "completed", report: `QA runner (${assignment.target.commit_sha}):\n${results.map(item => `${item.case_id}: ${item.status}${item.failure_class ? ` [${item.failure_class}]` : ""}${item.flaky ? " (flaky)" : ""}${item.failure_summary ? ` — ${item.failure_summary}` : item.failure_attempts?.length ? ` — first failure: ${item.failure_attempts[0].summary}` : ""}`).join("\n")}`,
|
|
264
340
|
evidence_urls: evidenceUrls, cost: { tokens_in: 0, tokens_out: 0, cost_usd: 0 }, exit_status: "completed", sandbox_profile: "host" });
|
|
265
341
|
}
|
|
266
342
|
finally {
|
package/dist/session.cjs
CHANGED
|
@@ -371,6 +371,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
371
371
|
: undefined,
|
|
372
372
|
// Hosted runs skip checkpoints for verify tasks, which deliver a verdict.
|
|
373
373
|
restoreHostedCheckpoint: !deliveryBinding && !allowBranchRename && task.task_type !== "verify",
|
|
374
|
+
...(claimed.delivery_baseline_required ? { hostedCheckpointLeaseId: leaseId } : {}),
|
|
374
375
|
...(commitIdentity ? { ownershipCommitIdentity: commitIdentity.committer } : {}),
|
|
375
376
|
});
|
|
376
377
|
credentialConsumer.worktree = gitWorktree;
|
|
@@ -762,9 +763,14 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
762
763
|
// after a restart, so a retry cannot relabel inherited commits as output.
|
|
763
764
|
if (claimed.delivery_baseline_required) {
|
|
764
765
|
const initialHead = await (0, delivery_cjs_1.captureDeliveryBaseline)(gitWorktree.worktreePath);
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
766
|
+
if (!/^[0-9a-f]{40}$/.test(initialHead))
|
|
767
|
+
throw new Error("Delivery baseline capture returned an invalid SHA");
|
|
768
|
+
const baseline = await api.heartbeatLease(leaseId, { delivery_baseline_sha: initialHead }).catch((error) => {
|
|
769
|
+
throw new Error(`Delivery baseline registration failed: ${String(error)}`);
|
|
770
|
+
});
|
|
771
|
+
if (typeof baseline.delivery_baseline_sha !== "string" || !/^[0-9a-f]{40}$/.test(baseline.delivery_baseline_sha)) {
|
|
772
|
+
throw new Error("The control plane did not persist a valid required delivery baseline acknowledgement");
|
|
773
|
+
}
|
|
768
774
|
deliveryBaselineSha = baseline.delivery_baseline_sha;
|
|
769
775
|
}
|
|
770
776
|
const { browserUse, playwrightSuites } = (0, browser_evidence_cjs_1.navarchBrowserTools)({
|
package/package.json
CHANGED