@sagentlab/navarch-runtime 0.1.160 → 0.1.162
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/delivery.cjs +4 -1
- package/dist/git-worktree.cjs +34 -2
- package/dist/prompt.cjs +6 -1
- package/dist/qa-fixture.cjs +179 -0
- package/dist/qa-runner.cjs +94 -18
- package/dist/session.cjs +10 -3
- package/package.json +1 -1
package/dist/delivery.cjs
CHANGED
|
@@ -111,7 +111,10 @@ async function probeWorktreeDelivery(args) {
|
|
|
111
111
|
* pushed commits with no pull request — so the reason a session is failed
|
|
112
112
|
* names the earliest point the delivery chain broke.
|
|
113
113
|
*/
|
|
114
|
-
function evaluateDelivery(probe) {
|
|
114
|
+
function evaluateDelivery(probe, binding) {
|
|
115
|
+
if (binding && (probe.branch !== binding.head_ref || probe.pullRequestUrl !== binding.pr_url || probe.pullRequestLookupFailed)) {
|
|
116
|
+
return { status: "incomplete", reason: "delivery must use the owner-assigned branch and pull request" };
|
|
117
|
+
}
|
|
115
118
|
if (probe.dirty) {
|
|
116
119
|
return {
|
|
117
120
|
status: "incomplete",
|
package/dist/git-worktree.cjs
CHANGED
|
@@ -13,6 +13,15 @@ const worktree_janitor_cjs_1 = require("./worktree-janitor.cjs");
|
|
|
13
13
|
const node_fs_1 = require("node:fs");
|
|
14
14
|
const sandbox_cjs_1 = require("./sandbox.cjs");
|
|
15
15
|
const commit_attribution_cjs_1 = require("./commit-attribution.cjs");
|
|
16
|
+
// Standalone runtime mirror of lib/navarch/branch-name.ts.
|
|
17
|
+
// delivery-branch-parity.test.cts checks ingress and both executors together.
|
|
18
|
+
function isValidBranchName(value) {
|
|
19
|
+
return typeof value === "string" &&
|
|
20
|
+
value.length >= 1 && value.length <= 255 &&
|
|
21
|
+
value.split("/").every((component) => component.length <= 250) &&
|
|
22
|
+
/^[A-Za-z0-9._/-]+$/.test(value) &&
|
|
23
|
+
!/(^[-./]|\/[-.]|\.\.|\/\/|\/$|\.$|\.lock(\/|$)|^HEAD$)/.test(value);
|
|
24
|
+
}
|
|
16
25
|
const repositoryLocks = new Map();
|
|
17
26
|
/** Rewrites a github.com HTTPS clone URL onto the proxy; other URLs are returned unchanged. */
|
|
18
27
|
function proxyCloneUrl(cloneUrl, proxyBaseUrl) {
|
|
@@ -53,6 +62,7 @@ class GitWorktree {
|
|
|
53
62
|
repoLocalTokenInstalled = false;
|
|
54
63
|
gitGrant;
|
|
55
64
|
workingBranch;
|
|
65
|
+
deliveryBinding;
|
|
56
66
|
repoLocalGithubToken;
|
|
57
67
|
prContinuation;
|
|
58
68
|
ownershipCommitIdentity;
|
|
@@ -71,7 +81,9 @@ class GitWorktree {
|
|
|
71
81
|
this.checkpointRoot = node_path_1.default.join(options.workspaceRoot, "checkpoints", projectKey, taskKey, sessionKey);
|
|
72
82
|
this.sessionRoot = node_path_1.default.join(options.workspaceRoot, "sessions", sessionKey);
|
|
73
83
|
this.worktreePath = node_path_1.default.join(this.sessionRoot, "repo");
|
|
74
|
-
|
|
84
|
+
// An owner-assigned branch can have any name. Keep its local ref isolated
|
|
85
|
+
// from other tasks and abandoned sessions that use the shared project cache.
|
|
86
|
+
this.repositoryPath = options.repoLocalGithubToken || options.deliveryBinding
|
|
75
87
|
? node_path_1.default.join(this.sessionRoot, "repository.git")
|
|
76
88
|
: node_path_1.default.join(options.workspaceRoot, "repositories", `${projectKey}.git`);
|
|
77
89
|
// One delivery task owns one remote branch across every retry. A
|
|
@@ -87,6 +99,14 @@ class GitWorktree {
|
|
|
87
99
|
// previous attempt's temporary branch in the bare cache.
|
|
88
100
|
this.branch = `navarch/${branchSlug(options)}${this.taskBranchSuffix}` +
|
|
89
101
|
(options.prContinuation ? `-${sessionKey}` : "");
|
|
102
|
+
this.deliveryBinding = options.deliveryBinding;
|
|
103
|
+
if (this.deliveryBinding) {
|
|
104
|
+
const { head_ref, head_sha } = this.deliveryBinding;
|
|
105
|
+
if (!isValidBranchName(head_ref) ||
|
|
106
|
+
!/^[a-f0-9]{40}$/.test(head_sha))
|
|
107
|
+
throw new Error("Invalid delivery binding");
|
|
108
|
+
this.branch = head_ref;
|
|
109
|
+
}
|
|
90
110
|
this.runner = options.runner ?? sandbox_cjs_1.nodeCommandRunner;
|
|
91
111
|
this.authRetryDelaysMs = options.authRetryDelaysMs ?? DEFAULT_AUTH_RETRY_DELAYS_MS;
|
|
92
112
|
this.sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
@@ -395,7 +415,8 @@ class GitWorktree {
|
|
|
395
415
|
if (tip.code !== 0 || !/^[0-9a-f]{40,64}$/i.test(staleSha))
|
|
396
416
|
return null;
|
|
397
417
|
const owned = this.branch.endsWith(this.legacyTaskBranchSuffix) ||
|
|
398
|
-
this.adoptedUnmarkedBranch ||
|
|
418
|
+
(!this.deliveryBinding && this.adoptedUnmarkedBranch) ||
|
|
419
|
+
(this.deliveryBinding && await this.isAncestor(staleSha, `refs/remotes/origin/${this.deliveryBinding.head_ref}`)) ||
|
|
399
420
|
(await this.hasTaskOwnershipMarker(localRef));
|
|
400
421
|
if (!owned) {
|
|
401
422
|
throw new Error(`Local branch ${this.branch} already exists in the cached repository but does not ` +
|
|
@@ -420,6 +441,9 @@ class GitWorktree {
|
|
|
420
441
|
else if (line.startsWith("branch ") && line.slice("branch ".length).trim() === localRef && currentPath)
|
|
421
442
|
holders.push(currentPath);
|
|
422
443
|
}
|
|
444
|
+
if (this.deliveryBinding && holders.length > 0) {
|
|
445
|
+
throw new Error(`Assigned branch ${this.branch} is held by another worktree; refusing to remove it.`);
|
|
446
|
+
}
|
|
423
447
|
for (const holder of holders) {
|
|
424
448
|
if (await (0, worktree_janitor_cjs_1.hasRecoveryMarker)(node_path_1.default.dirname(holder))) {
|
|
425
449
|
throw new Error(`Worktree ${holder} is retained for recovery; restore or remove it before reusing this branch.`);
|
|
@@ -447,6 +471,14 @@ class GitWorktree {
|
|
|
447
471
|
}
|
|
448
472
|
/** Returns the fetched task-owned remote branch when an earlier attempt pushed it. */
|
|
449
473
|
async resolveTaskBranchRef() {
|
|
474
|
+
if (this.deliveryBinding) {
|
|
475
|
+
const ref = `refs/remotes/origin/${this.deliveryBinding.head_ref}`;
|
|
476
|
+
if (!(await this.isAncestor(this.deliveryBinding.head_sha, ref))) {
|
|
477
|
+
throw new Error("Delivery binding branch no longer preserves its commits");
|
|
478
|
+
}
|
|
479
|
+
this.adoptedUnmarkedBranch = !(await this.hasTaskOwnershipMarker(ref));
|
|
480
|
+
return ref;
|
|
481
|
+
}
|
|
450
482
|
// A follow-up must check out the reviewed PR's head, not adopt a branch
|
|
451
483
|
// bearing this task's short suffix. An earlier attempt may have pushed its
|
|
452
484
|
// temporary branch after dropping the claim commit; that branch must not
|
package/dist/prompt.cjs
CHANGED
|
@@ -39,12 +39,15 @@ function renderQaShard(assignment) {
|
|
|
39
39
|
* WP-07 "write prompt file".
|
|
40
40
|
*/
|
|
41
41
|
function renderPrompt(task, bundle) {
|
|
42
|
+
const binding = bundle.repository?.delivery_binding;
|
|
43
|
+
const bindingNote = binding
|
|
44
|
+
? `Owner-assigned delivery: update ${binding.pr_url} on branch \`${binding.head_ref}\` with base \`${binding.base_ref}\`. Preserve existing commits and use this PR for delivery.` : "";
|
|
42
45
|
if (bundle.task_context) {
|
|
43
46
|
const repositoryContext = bundle.repository
|
|
44
47
|
? `Repository: ${bundle.repository.full_name} (${bundle.repository.url})\nLocal checkout: this session's isolated git worktree (current working directory).` +
|
|
45
48
|
workingBranchNote(bundle.repository.working_branch)
|
|
46
49
|
: null;
|
|
47
|
-
return [repositoryContext, PROCESS_GUIDANCE, bundle.task_context.trim(), CODE_GRAPH_GUIDANCE, bundle.retry_context?.trim()]
|
|
50
|
+
return [repositoryContext, PROCESS_GUIDANCE, bundle.task_context.trim(), bindingNote, CODE_GRAPH_GUIDANCE, bundle.retry_context?.trim()]
|
|
48
51
|
.filter((section) => Boolean(section))
|
|
49
52
|
.join("\n\n") + "\n";
|
|
50
53
|
}
|
|
@@ -78,6 +81,8 @@ function renderPrompt(task, bundle) {
|
|
|
78
81
|
sections.push("## Playbook");
|
|
79
82
|
sections.push(bundle.playbook);
|
|
80
83
|
sections.push(CODE_GRAPH_GUIDANCE);
|
|
84
|
+
if (bindingNote)
|
|
85
|
+
sections.push(bindingNote);
|
|
81
86
|
return sections.join("\n\n");
|
|
82
87
|
}
|
|
83
88
|
/**
|
|
@@ -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
|
@@ -337,6 +337,12 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
337
337
|
// `navarch/...` branch. PR-continuation tasks are the exception: their agent
|
|
338
338
|
// must check out and push the reviewed PR's existing head branch.
|
|
339
339
|
const allowBranchRename = Boolean(task.review_of_task_id);
|
|
340
|
+
const deliveryBinding = bundle.repository?.delivery_binding;
|
|
341
|
+
if (deliveryBinding && (deliveryBinding.project_id !== task.project_id ||
|
|
342
|
+
deliveryBinding.repository.toLowerCase() !== task.repo.toLowerCase() ||
|
|
343
|
+
bundle.repository?.full_name.toLowerCase() !== task.repo.toLowerCase())) {
|
|
344
|
+
throw new Error("Delivery binding project or repository mismatch");
|
|
345
|
+
}
|
|
340
346
|
let runnerPreparationSignal;
|
|
341
347
|
const gitWorktree = new git_worktree_cjs_1.GitWorktree({
|
|
342
348
|
workspaceRoot: config.workspaceRoot,
|
|
@@ -353,6 +359,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
353
359
|
githubToken,
|
|
354
360
|
githubTokenProvider: githubTokenRefresher ? () => githubTokenRefresher.current : undefined,
|
|
355
361
|
workingBranch: bundle.repository?.working_branch,
|
|
362
|
+
deliveryBinding,
|
|
356
363
|
// Grant modes never expose a GitHub token, so the Codex repo-local
|
|
357
364
|
// github-pat bootstrap is not installed.
|
|
358
365
|
repoLocalGithubToken: gitGrantMode ? undefined : secrets["github-pat"],
|
|
@@ -363,7 +370,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
363
370
|
}
|
|
364
371
|
: undefined,
|
|
365
372
|
// Hosted runs skip checkpoints for verify tasks, which deliver a verdict.
|
|
366
|
-
restoreHostedCheckpoint: !allowBranchRename && task.task_type !== "verify",
|
|
373
|
+
restoreHostedCheckpoint: !deliveryBinding && !allowBranchRename && task.task_type !== "verify",
|
|
367
374
|
...(commitIdentity ? { ownershipCommitIdentity: commitIdentity.committer } : {}),
|
|
368
375
|
});
|
|
369
376
|
credentialConsumer.worktree = gitWorktree;
|
|
@@ -1283,10 +1290,10 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
1283
1290
|
baseRef: await gitWorktree.resolveDeliveryBase(),
|
|
1284
1291
|
claimBaselineSha: deliveryBaselineSha,
|
|
1285
1292
|
});
|
|
1286
|
-
delivery = (0, delivery_cjs_1.evaluateDelivery)({ ...probe, pullRequestUrl, pullRequestLookupFailed });
|
|
1293
|
+
delivery = (0, delivery_cjs_1.evaluateDelivery)({ ...probe, pullRequestUrl, pullRequestLookupFailed }, deliveryBinding);
|
|
1287
1294
|
}
|
|
1288
1295
|
catch (err) {
|
|
1289
|
-
delivery = { status: "unknown", reason: `the delivery probe failed: ${String(err)}` };
|
|
1296
|
+
delivery = { status: deliveryBinding ? "incomplete" : "unknown", reason: `the delivery probe failed: ${String(err)}` };
|
|
1290
1297
|
}
|
|
1291
1298
|
deliveredPullRequest = delivery.status === "delivered";
|
|
1292
1299
|
if (delivery.status === "unknown") {
|
package/package.json
CHANGED