benignswarm 0.12.166 → 0.12.167
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/args.js +5 -3
- package/dist/command-flags.js +1 -1
- package/dist/commands/admin.js +10 -1
- package/dist/commands/gh.js +18 -1
- package/dist/commands/health.js +44 -0
- package/dist/commands/mock.js +115 -2
- package/dist/commands/operator.js +1 -1
- package/dist/commands/ux.js +13 -4
- package/dist/commands/wu.js +89 -11
- package/dist/gate-quarantines.js +76 -0
- package/dist/gate-test-reports.js +45 -0
- package/dist/help.js +16 -7
- package/dist/index.js +2 -0
- package/dist/merge-train.js +51 -2
- package/dist/scoped-gate.js +390 -0
- package/dist/ux-jobs.js +20 -8
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
3
|
+
import { createConnection } from "node:net";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { CliError } from "./errors.js";
|
|
7
|
+
import { retryGitFetchSync } from "./git-fetch.js";
|
|
8
|
+
import { fullSha, isAncestor } from "./git.js";
|
|
9
|
+
import { parseFailedGateStep } from "./merge-train.js";
|
|
10
|
+
export const SCOPED_GATE_STAGE_ORDER = [
|
|
11
|
+
"pg baseline",
|
|
12
|
+
"migration preflight",
|
|
13
|
+
"deployment script tests",
|
|
14
|
+
"typecheck",
|
|
15
|
+
"api tests",
|
|
16
|
+
"cli build",
|
|
17
|
+
"cli tests",
|
|
18
|
+
"web tests",
|
|
19
|
+
"web build",
|
|
20
|
+
"published CLI contract",
|
|
21
|
+
];
|
|
22
|
+
export function gateCommandUsesGateSh(gateCommand) {
|
|
23
|
+
if (gateCommand === null)
|
|
24
|
+
return true;
|
|
25
|
+
return /(?:^|\s)scripts\/gate\.sh(?:\s|$)/.test(gateCommand);
|
|
26
|
+
}
|
|
27
|
+
function normalizeRepoPath(path) {
|
|
28
|
+
return path.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
29
|
+
}
|
|
30
|
+
function isNonGateDocOrAssetPath(path) {
|
|
31
|
+
if (path.startsWith("docs/")
|
|
32
|
+
|| path.startsWith(".agents/")
|
|
33
|
+
|| path.startsWith(".bschat/")
|
|
34
|
+
|| path.startsWith(".github/")
|
|
35
|
+
|| path.startsWith("logo/")
|
|
36
|
+
|| path.startsWith("artifacts/")
|
|
37
|
+
|| path.startsWith("apps/web/public/")
|
|
38
|
+
|| path.startsWith("scripts/ux-tasks/")
|
|
39
|
+
|| path.startsWith("scripts/carbon-")
|
|
40
|
+
|| path.startsWith("scripts/ux-")) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (path.endsWith(".md") && !path.startsWith("apps/api/") && !path.startsWith("packages/skill/") && !path.startsWith("packages/skill-admin/")) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
function isMigrationPath(path) {
|
|
49
|
+
return path.startsWith("apps/api/migrations/")
|
|
50
|
+
|| path.startsWith("apps/api/pg-migrations/")
|
|
51
|
+
|| path === "apps/api/scripts/migration-preflight.mjs"
|
|
52
|
+
|| path === "apps/api/scripts/generate-pg-baseline.mjs";
|
|
53
|
+
}
|
|
54
|
+
function isPgApiTestPath(path) {
|
|
55
|
+
return path.startsWith("apps/api/src/node/")
|
|
56
|
+
|| path === "apps/api/vitest.pg-suite.config.ts"
|
|
57
|
+
|| path === "apps/api/scripts/d1-to-postgres.mjs"
|
|
58
|
+
|| path.startsWith("apps/api/pg-migrations/");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Determine which train gate stages must pass locally before `wu submit` for the given changed paths.
|
|
62
|
+
* Must stay synchronized with `apps/api/src/scoped-gate.ts` and `scripts/gate.sh`.
|
|
63
|
+
*/
|
|
64
|
+
export function scopedGatePlan(changedPaths, merge) {
|
|
65
|
+
const stageSet = new Set();
|
|
66
|
+
const postgresReasons = new Set();
|
|
67
|
+
let hasCodePath = false;
|
|
68
|
+
for (const rawPath of changedPaths) {
|
|
69
|
+
const p = normalizeRepoPath(rawPath);
|
|
70
|
+
if (!p || isNonGateDocOrAssetPath(p))
|
|
71
|
+
continue;
|
|
72
|
+
hasCodePath = true;
|
|
73
|
+
if (isMigrationPath(p)) {
|
|
74
|
+
stageSet.add("pg baseline");
|
|
75
|
+
stageSet.add("migration preflight");
|
|
76
|
+
stageSet.add("typecheck");
|
|
77
|
+
stageSet.add("api tests");
|
|
78
|
+
postgresReasons.add('stage "migration preflight" requires a reachable local PostgreSQL server (PG_ADMIN_URL or 127.0.0.1:15432)');
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (p.startsWith("apps/api/")) {
|
|
82
|
+
stageSet.add("typecheck");
|
|
83
|
+
stageSet.add("api tests");
|
|
84
|
+
if (p === "apps/api/wrangler.jsonc") {
|
|
85
|
+
stageSet.add("cli build");
|
|
86
|
+
stageSet.add("published CLI contract");
|
|
87
|
+
}
|
|
88
|
+
if (isPgApiTestPath(p)) {
|
|
89
|
+
postgresReasons.add('PostgreSQL server/suite changes require a reachable local PostgreSQL server (PG_ADMIN_URL or 127.0.0.1:15432) for PostgreSQL API tests');
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (p.startsWith("apps/web/")) {
|
|
94
|
+
stageSet.add("typecheck");
|
|
95
|
+
stageSet.add("web tests");
|
|
96
|
+
stageSet.add("web build");
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (p.startsWith("packages/cli/")) {
|
|
100
|
+
stageSet.add("typecheck");
|
|
101
|
+
stageSet.add("cli build");
|
|
102
|
+
stageSet.add("cli tests");
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (p.startsWith("packages/skill/") || p.startsWith("packages/skill-admin/")) {
|
|
106
|
+
stageSet.add("typecheck");
|
|
107
|
+
stageSet.add("api tests");
|
|
108
|
+
stageSet.add("cli tests");
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (p.startsWith("packages/signing-worker/")) {
|
|
112
|
+
stageSet.add("typecheck");
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (p.startsWith("scripts/deploy-main") || p.startsWith("scripts/migration-fault-guard")) {
|
|
116
|
+
stageSet.add("deployment script tests");
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (p.startsWith("scripts/gate") || p === "scripts/verify-gate-baseline.sh") {
|
|
120
|
+
stageSet.add("deployment script tests");
|
|
121
|
+
stageSet.add("typecheck");
|
|
122
|
+
stageSet.add("cli tests");
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (p.startsWith("scripts/published-cli-contract")) {
|
|
126
|
+
stageSet.add("cli build");
|
|
127
|
+
stageSet.add("published CLI contract");
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (p.startsWith("scripts/vitest-scratch") || p === "scripts/ensure-tenant-migrations.mjs") {
|
|
131
|
+
stageSet.add("typecheck");
|
|
132
|
+
stageSet.add("api tests");
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (p === "package.json" || p === "package-lock.json" || /^tsconfig(?:\.[^/]+)?\.json$/.test(p)) {
|
|
136
|
+
stageSet.add("pg baseline");
|
|
137
|
+
stageSet.add("typecheck");
|
|
138
|
+
stageSet.add("api tests");
|
|
139
|
+
stageSet.add("cli build");
|
|
140
|
+
stageSet.add("cli tests");
|
|
141
|
+
stageSet.add("web tests");
|
|
142
|
+
stageSet.add("web build");
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
stageSet.add("typecheck");
|
|
146
|
+
}
|
|
147
|
+
if (!hasCodePath) {
|
|
148
|
+
return {
|
|
149
|
+
required: false,
|
|
150
|
+
mode: "none",
|
|
151
|
+
stages: [],
|
|
152
|
+
customCommand: null,
|
|
153
|
+
postgresRequiredReasons: [],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (!gateCommandUsesGateSh(merge.gate_command)) {
|
|
157
|
+
return {
|
|
158
|
+
required: merge.require_gate_receipt,
|
|
159
|
+
mode: "custom",
|
|
160
|
+
stages: ["gate"],
|
|
161
|
+
customCommand: merge.gate_command,
|
|
162
|
+
postgresRequiredReasons: [],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const orderedStages = SCOPED_GATE_STAGE_ORDER.filter((stage) => stageSet.has(stage));
|
|
166
|
+
return {
|
|
167
|
+
required: merge.require_gate_receipt && orderedStages.length > 0,
|
|
168
|
+
mode: orderedStages.length > 0 ? "gate_sh" : "none",
|
|
169
|
+
stages: orderedStages,
|
|
170
|
+
customCommand: null,
|
|
171
|
+
postgresRequiredReasons: [...postgresReasons],
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export function resolvePostgresTarget(env = process.env) {
|
|
175
|
+
const configured = env.PG_ADMIN_URL?.trim() || env.DATABASE_URL?.trim();
|
|
176
|
+
const fallback = "postgresql://benignswarm:benignswarm@127.0.0.1:15432/postgres";
|
|
177
|
+
const raw = configured || fallback;
|
|
178
|
+
try {
|
|
179
|
+
const url = new URL(raw);
|
|
180
|
+
const host = url.hostname === "[::1]" ? "::1" : (url.hostname || "127.0.0.1");
|
|
181
|
+
const port = Number(url.port || (configured ? 5432 : 15432));
|
|
182
|
+
const adminUrl = `${url.protocol}//${url.username ? `${url.username}${url.password ? `:${url.password}` : ""}@` : ""}${url.host}/postgres`;
|
|
183
|
+
return { host, port, adminUrl };
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return { host: "127.0.0.1", port: 15432, adminUrl: fallback };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export async function probeLocalPostgres(env = process.env) {
|
|
190
|
+
const { host, port, adminUrl } = resolvePostgresTarget(env);
|
|
191
|
+
if (!["127.0.0.1", "localhost", "::1"].includes(host)) {
|
|
192
|
+
return {
|
|
193
|
+
available: false,
|
|
194
|
+
host,
|
|
195
|
+
port,
|
|
196
|
+
adminUrl,
|
|
197
|
+
reason: `configured PostgreSQL host ${host} is not local (expected 127.0.0.1, localhost, or ::1)`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return await new Promise((resolve) => {
|
|
201
|
+
const socket = createConnection({ host, port });
|
|
202
|
+
let settled = false;
|
|
203
|
+
const finish = (result) => {
|
|
204
|
+
if (settled)
|
|
205
|
+
return;
|
|
206
|
+
settled = true;
|
|
207
|
+
socket.destroy();
|
|
208
|
+
resolve(result);
|
|
209
|
+
};
|
|
210
|
+
socket.setTimeout(500);
|
|
211
|
+
socket.once("connect", () => finish({ available: true, host, port, adminUrl }));
|
|
212
|
+
socket.once("timeout", () => finish({ available: false, host, port, adminUrl, reason: `timed out connecting to PostgreSQL at ${host}:${port}` }));
|
|
213
|
+
socket.once("error", (error) => finish({ available: false, host, port, adminUrl, reason: error.message }));
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function withGitIdentityEnv(env) {
|
|
217
|
+
return {
|
|
218
|
+
...env,
|
|
219
|
+
GIT_AUTHOR_NAME: env.GIT_AUTHOR_NAME ?? "BenignSwarm Worker Gate",
|
|
220
|
+
GIT_AUTHOR_EMAIL: env.GIT_AUTHOR_EMAIL ?? "worker-gate@benignswarm.org",
|
|
221
|
+
GIT_COMMITTER_NAME: env.GIT_COMMITTER_NAME ?? "BenignSwarm Worker Gate",
|
|
222
|
+
GIT_COMMITTER_EMAIL: env.GIT_COMMITTER_EMAIL ?? "worker-gate@benignswarm.org",
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export function prepareMergedWorktreeForSubmit(targetBranch, unitHeadInput, cwd = process.cwd(), env = process.env) {
|
|
226
|
+
const gitEnv = withGitIdentityEnv(env);
|
|
227
|
+
const fetched = retryGitFetchSync(["fetch", "--quiet", "--no-tags", "origin", `+refs/heads/${targetBranch}:refs/remotes/origin/${targetBranch}`], cwd);
|
|
228
|
+
if (fetched.status !== 0) {
|
|
229
|
+
throw new CliError("target_fetch_failed", `cannot fetch origin/${targetBranch} before running scoped submit gate: ${fetched.stderr?.trim() || "git fetch failed"}`, "Check origin connectivity and retry b9s wu submit");
|
|
230
|
+
}
|
|
231
|
+
const targetRef = `refs/remotes/origin/${targetBranch}`;
|
|
232
|
+
const targetSha = fullSha(`${targetRef}^{commit}`, cwd);
|
|
233
|
+
const unitHead = fullSha(`${unitHeadInput}^{commit}`, cwd);
|
|
234
|
+
if (!targetSha || !unitHead) {
|
|
235
|
+
throw new CliError("target_unavailable", `cannot resolve ${targetRef} or unit head commit before scoped submit gate`);
|
|
236
|
+
}
|
|
237
|
+
const tempRoot = mkdtempSync(join(tmpdir(), "b9s-submit-gate-"));
|
|
238
|
+
const worktreeDir = join(tempRoot, "repo");
|
|
239
|
+
const cleanup = () => {
|
|
240
|
+
spawnSync("git", ["-C", cwd, "worktree", "remove", "--force", worktreeDir], { cwd, env: gitEnv, encoding: "utf8" });
|
|
241
|
+
rmSync(tempRoot, { recursive: true, force: true });
|
|
242
|
+
spawnSync("git", ["-C", cwd, "worktree", "prune"], { cwd, env: gitEnv, encoding: "utf8" });
|
|
243
|
+
};
|
|
244
|
+
try {
|
|
245
|
+
const add = spawnSync("git", ["-C", cwd, "worktree", "add", "--detach", worktreeDir, targetSha], {
|
|
246
|
+
cwd,
|
|
247
|
+
env: gitEnv,
|
|
248
|
+
encoding: "utf8",
|
|
249
|
+
});
|
|
250
|
+
if (add.status !== 0) {
|
|
251
|
+
throw new CliError("submit_worktree_failed", `cannot create temporary merged worktree for scoped gate: ${(add.stderr || add.stdout).trim()}`);
|
|
252
|
+
}
|
|
253
|
+
const alreadyRebased = isAncestor(targetSha, unitHead, cwd) === true;
|
|
254
|
+
if (alreadyRebased) {
|
|
255
|
+
const co = spawnSync("git", ["-C", worktreeDir, "checkout", "--detach", unitHead], {
|
|
256
|
+
cwd: worktreeDir,
|
|
257
|
+
env: gitEnv,
|
|
258
|
+
encoding: "utf8",
|
|
259
|
+
});
|
|
260
|
+
if (co.status !== 0) {
|
|
261
|
+
throw new CliError("submit_worktree_failed", `cannot check out unit head ${unitHead.slice(0, 9)} in temporary gate worktree: ${(co.stderr || co.stdout).trim()}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
const merge = spawnSync("git", ["-C", worktreeDir, "merge", "--no-edit", "--no-ff", unitHead], {
|
|
266
|
+
cwd: worktreeDir,
|
|
267
|
+
env: gitEnv,
|
|
268
|
+
encoding: "utf8",
|
|
269
|
+
});
|
|
270
|
+
if (merge.status !== 0) {
|
|
271
|
+
spawnSync("git", ["-C", worktreeDir, "merge", "--abort"], { cwd: worktreeDir, env: gitEnv, encoding: "utf8" });
|
|
272
|
+
const detail = (merge.stderr || merge.stdout).trim().slice(0, 400);
|
|
273
|
+
throw new CliError("merge_conflict_with_target", `unit head ${unitHead.slice(0, 9)} does not merge cleanly onto current origin/${targetBranch} (${targetSha.slice(0, 9)}): ${detail}`, `Rebase or merge origin/${targetBranch} cleanly and resolve conflicts, then run b9s wu submit again`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const mergedSha = fullSha("HEAD", worktreeDir);
|
|
277
|
+
if (!mergedSha)
|
|
278
|
+
throw new CliError("submit_worktree_failed", "cannot resolve merged HEAD commit SHA in temporary gate worktree");
|
|
279
|
+
const tree = spawnSync("git", ["-C", worktreeDir, "rev-parse", "HEAD^{tree}"], { cwd: worktreeDir, env: gitEnv, encoding: "utf8" });
|
|
280
|
+
const mergedTreeSha = tree.status === 0 && /^[0-9a-f]{40}$/i.test(tree.stdout.trim()) ? tree.stdout.trim().toLowerCase() : null;
|
|
281
|
+
return {
|
|
282
|
+
dir: worktreeDir,
|
|
283
|
+
targetSha,
|
|
284
|
+
unitHead,
|
|
285
|
+
mergedSha,
|
|
286
|
+
mergedTreeSha,
|
|
287
|
+
rebased: alreadyRebased,
|
|
288
|
+
cleanup,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
cleanup();
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
export const defaultScopedGateRunner = (cmd, args, opts) => new Promise((resolve, reject) => {
|
|
297
|
+
const child = spawn(cmd, args, {
|
|
298
|
+
cwd: opts.cwd,
|
|
299
|
+
env: opts.env,
|
|
300
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
301
|
+
});
|
|
302
|
+
let output = "";
|
|
303
|
+
const handleChunk = (chunk) => {
|
|
304
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
305
|
+
output += text;
|
|
306
|
+
opts.onLine?.(text);
|
|
307
|
+
};
|
|
308
|
+
child.stdout.on("data", handleChunk);
|
|
309
|
+
child.stderr.on("data", handleChunk);
|
|
310
|
+
child.once("error", reject);
|
|
311
|
+
child.once("close", (code, signal) => {
|
|
312
|
+
resolve({ exitCode: code ?? (signal ? 1 : 0), output });
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
export function resolveLocalCustomGateCommand(gateCommand, unitNumber, mergedSha) {
|
|
316
|
+
const expanded = gateCommand.trim().replaceAll("{unit}", String(unitNumber)).replaceAll("{head}", mergedSha);
|
|
317
|
+
return expanded.replace(/^b9s\s+lock\s+run\s+complete-suite\b(?:\s+--\S+(?:\s+(?!--)\S+)?)*\s+--\s+/, "").trim();
|
|
318
|
+
}
|
|
319
|
+
export async function executeScopedGateForSubmit(opts) {
|
|
320
|
+
const env = opts.env ?? process.env;
|
|
321
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
322
|
+
const plan = scopedGatePlan(opts.changedPaths, opts.merge);
|
|
323
|
+
if (!plan.required || plan.stages.length === 0)
|
|
324
|
+
return null;
|
|
325
|
+
let pgProbe = null;
|
|
326
|
+
if (plan.postgresRequiredReasons.length > 0) {
|
|
327
|
+
pgProbe = await (opts.deps?.probePostgres ?? probeLocalPostgres)(env);
|
|
328
|
+
if (!pgProbe.available) {
|
|
329
|
+
throw new CliError("missing_postgres", `cannot run required scoped gate stage(s) [${plan.stages.join(", ")}] on this machine: ${plan.postgresRequiredReasons.join("; ")}. Local PostgreSQL is unavailable at ${pgProbe.host}:${pgProbe.port}${pgProbe.reason ? ` (${pgProbe.reason})` : ""}`, "Start local PostgreSQL on 127.0.0.1:15432 or set PG_ADMIN_URL to a reachable local PostgreSQL instance, then rerun b9s wu submit");
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const worktree = (opts.deps?.prepareWorktree ?? prepareMergedWorktreeForSubmit)(opts.targetBranch, opts.unitHead, cwd, env);
|
|
333
|
+
const startedAt = Date.now();
|
|
334
|
+
try {
|
|
335
|
+
const childEnv = {
|
|
336
|
+
...withGitIdentityEnv(env),
|
|
337
|
+
GATE_REMOTE: "origin",
|
|
338
|
+
npm_config_prefer_offline: env.npm_config_prefer_offline ?? "true",
|
|
339
|
+
...(pgProbe?.available && !env.PG_ADMIN_URL ? { PG_ADMIN_URL: pgProbe.adminUrl } : {}),
|
|
340
|
+
};
|
|
341
|
+
let cmd = "/bin/sh";
|
|
342
|
+
let args;
|
|
343
|
+
let commandSummary;
|
|
344
|
+
if (plan.mode === "gate_sh") {
|
|
345
|
+
if (!existsSync(join(worktree.dir, "scripts", "gate.sh"))) {
|
|
346
|
+
throw new CliError("scoped_gate_script_missing", `scripts/gate.sh is missing in merged commit ${worktree.mergedSha.slice(0, 9)}`, "Ensure scripts/gate.sh is present on the repository or adjust merge.gate_command");
|
|
347
|
+
}
|
|
348
|
+
args = ["scripts/gate.sh", worktree.mergedSha, ...plan.stages.flatMap((stage) => ["--stage", stage])];
|
|
349
|
+
commandSummary = `scripts/gate.sh ${worktree.mergedSha} ${plan.stages.map((s) => `--stage ${JSON.stringify(s)}`).join(" ")}`.slice(0, 500);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
const customCmd = resolveLocalCustomGateCommand(plan.customCommand ?? "", opts.unitNumber, worktree.mergedSha);
|
|
353
|
+
if (!customCmd) {
|
|
354
|
+
throw new CliError("scoped_gate_script_missing", "configured merge.gate_command resolved to an empty command");
|
|
355
|
+
}
|
|
356
|
+
args = ["-c", customCmd];
|
|
357
|
+
commandSummary = customCmd.slice(0, 500);
|
|
358
|
+
}
|
|
359
|
+
const runner = opts.deps?.runCommand ?? defaultScopedGateRunner;
|
|
360
|
+
const result = await runner(cmd, args, {
|
|
361
|
+
cwd: worktree.dir,
|
|
362
|
+
env: childEnv,
|
|
363
|
+
onLine: opts.deps?.onLog ?? ((chunk) => process.stderr.write(chunk)),
|
|
364
|
+
});
|
|
365
|
+
const durationMs = Math.max(0, Date.now() - startedAt);
|
|
366
|
+
if (result.exitCode !== 0) {
|
|
367
|
+
const failedStep = parseFailedGateStep(result.output, []);
|
|
368
|
+
const tail = result.output.trim().split(/\r?\n/).slice(-25).join("\n");
|
|
369
|
+
throw new CliError("scoped_gate_failed", `scoped submit gate failed at ${failedStep} (exit ${result.exitCode}) on merged head ${worktree.mergedSha.slice(0, 9)} (unit ${worktree.unitHead.slice(0, 9)} + origin/${opts.targetBranch} ${worktree.targetSha.slice(0, 9)})${tail ? `:\n${tail}` : ""}`, "Fix the failing test or build regression locally, commit, and run b9s wu submit again");
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
unit_head: worktree.unitHead,
|
|
373
|
+
target_branch: opts.targetBranch,
|
|
374
|
+
target_sha: worktree.targetSha,
|
|
375
|
+
merged_sha: worktree.mergedSha,
|
|
376
|
+
merged_tree_sha: worktree.mergedTreeSha,
|
|
377
|
+
rebased: worktree.rebased,
|
|
378
|
+
machine: opts.machine,
|
|
379
|
+
stages: plan.stages,
|
|
380
|
+
changed_paths: [...opts.changedPaths],
|
|
381
|
+
exit_code: 0,
|
|
382
|
+
passed_at: new Date().toISOString(),
|
|
383
|
+
command: commandSummary,
|
|
384
|
+
duration_ms: durationMs,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
finally {
|
|
388
|
+
worktree.cleanup();
|
|
389
|
+
}
|
|
390
|
+
}
|
package/dist/ux-jobs.js
CHANGED
|
@@ -17,6 +17,18 @@ import { writeFileAtomic } from "./shared-file.js";
|
|
|
17
17
|
import { runMergeTrainWorkflow } from "./merge-train.js";
|
|
18
18
|
import { retryGitFetch } from "./git-fetch.js";
|
|
19
19
|
import { recordMachineNetworkRequest } from "./machine-network-health.js";
|
|
20
|
+
function jobSubjectLabel(job) {
|
|
21
|
+
return job.work_unit_number !== null && job.work_unit_number !== undefined
|
|
22
|
+
? `WU #${job.work_unit_number}`
|
|
23
|
+
: `branch ${job.target_branch ?? job.branch}`;
|
|
24
|
+
}
|
|
25
|
+
function jobFileTag(job) {
|
|
26
|
+
if (job.work_unit_number !== null && job.work_unit_number !== undefined) {
|
|
27
|
+
return `wu${job.work_unit_number}`;
|
|
28
|
+
}
|
|
29
|
+
const branchTag = (job.target_branch ?? job.branch).replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "target";
|
|
30
|
+
return branchTag;
|
|
31
|
+
}
|
|
20
32
|
const SLUG_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
21
33
|
const SHA_RE = /^[0-9a-f]{7,64}$/i;
|
|
22
34
|
const MAX_UX_JOB_LOG_TAIL = 2000;
|
|
@@ -1127,13 +1139,13 @@ export async function executeUxJob(machineClient, job, ctx, deps = {}, resume, c
|
|
|
1127
1139
|
? `gate ${status === "succeeded" ? "PASSED" : "FAILED"}`
|
|
1128
1140
|
: [job.task, job.compare_screen ? `compare-${job.compare_screen}` : null].filter(Boolean).join(" ");
|
|
1129
1141
|
const claim = jobKind === "gate"
|
|
1130
|
-
? `Complete-suite gate run (${status === "succeeded" ? "PASSED" : "FAILED"}) on ${ctx.machineName} at ${head} for
|
|
1131
|
-
: `Seeded UX run (${jobTaskLabel}) on ${ctx.machineName} at ${head} for
|
|
1142
|
+
? `Complete-suite gate run (${status === "succeeded" ? "PASSED" : "FAILED"}) on ${ctx.machineName} at ${head} for ${jobSubjectLabel(job)}`
|
|
1143
|
+
: `Seeded UX run (${jobTaskLabel}) on ${ctx.machineName} at ${head} for ${jobSubjectLabel(job)}`;
|
|
1132
1144
|
return {
|
|
1133
1145
|
project: job.project,
|
|
1134
1146
|
project_id: job.project_id,
|
|
1135
1147
|
filename: `remote-job-${job.id}.log`,
|
|
1136
|
-
label:
|
|
1148
|
+
label: `${jobSubjectLabel(job)} ${head} ${taskTag} remote-job-${job.id}.log`,
|
|
1137
1149
|
claim,
|
|
1138
1150
|
idempotency_key: uxEvidenceIdempotencyKey(job.id, "diagnostic-log"),
|
|
1139
1151
|
};
|
|
@@ -1182,8 +1194,8 @@ export async function executeUxJob(machineClient, job, ctx, deps = {}, resume, c
|
|
|
1182
1194
|
? `gate ${status === "succeeded" ? "PASSED" : "FAILED"}`
|
|
1183
1195
|
: [job.task, job.compare_screen ? `compare-${job.compare_screen}` : null].filter(Boolean).join(" ");
|
|
1184
1196
|
const claim = jobKind === "gate"
|
|
1185
|
-
? `Complete-suite gate run (${status === "succeeded" ? "PASSED" : "FAILED"}) on ${ctx.machineName} at ${(resolvedHead ?? job.head ?? "unknown").slice(0, 9)} for
|
|
1186
|
-
: `Seeded UX run (${jobTaskLabel}) on ${ctx.machineName} at ${(resolvedHead ?? job.head ?? "unknown").slice(0, 9)} for
|
|
1197
|
+
? `Complete-suite gate run (${status === "succeeded" ? "PASSED" : "FAILED"}) on ${ctx.machineName} at ${(resolvedHead ?? job.head ?? "unknown").slice(0, 9)} for ${jobSubjectLabel(job)}`
|
|
1198
|
+
: `Seeded UX run (${jobTaskLabel}) on ${ctx.machineName} at ${(resolvedHead ?? job.head ?? "unknown").slice(0, 9)} for ${jobSubjectLabel(job)}`;
|
|
1187
1199
|
for (const artifact of artifacts) {
|
|
1188
1200
|
const alreadyUploaded = uploadedArtifacts.get(artifact.path);
|
|
1189
1201
|
if (alreadyUploaded) {
|
|
@@ -1193,7 +1205,7 @@ export async function executeUxJob(machineClient, job, ctx, deps = {}, resume, c
|
|
|
1193
1205
|
fullLogEvidenceId = alreadyUploaded;
|
|
1194
1206
|
continue;
|
|
1195
1207
|
}
|
|
1196
|
-
const label =
|
|
1208
|
+
const label = `${jobSubjectLabel(job)} ${(resolvedHead ?? job.head ?? "unknown").slice(0, 9)} ${taskTag} ${artifact.filename}`;
|
|
1197
1209
|
const artifactIdentity = artifact.path === diagnosticLogPath ? "diagnostic-log" : relative(jobArtifactDir, artifact.path);
|
|
1198
1210
|
const evidenceId = await uploadEvidence(agentCreds, job.project, {
|
|
1199
1211
|
...artifact,
|
|
@@ -1491,7 +1503,7 @@ export async function executeUxJob(machineClient, job, ctx, deps = {}, resume, c
|
|
|
1491
1503
|
scanner.push("", true);
|
|
1492
1504
|
const logDir = join(jobArtifactDir, "gate");
|
|
1493
1505
|
mkdirSync(logDir, { recursive: true });
|
|
1494
|
-
gateLogFile = join(logDir, `gate
|
|
1506
|
+
gateLogFile = join(logDir, `gate-${jobFileTag(job)}-${shortHead}.log`);
|
|
1495
1507
|
writeFileSync(gateLogFile, fullOutput || `${gateRes.stdout}\n${gateRes.stderr}` || `exit ${gateRes.status ?? 1}\n`);
|
|
1496
1508
|
return { exit_code: gateRes.status ?? 1, ...scanner.result() };
|
|
1497
1509
|
}
|
|
@@ -1616,7 +1628,7 @@ export async function executeUxJob(machineClient, job, ctx, deps = {}, resume, c
|
|
|
1616
1628
|
}, ctx.sessions);
|
|
1617
1629
|
if (completion === "cancelled")
|
|
1618
1630
|
return { id: job.id, status: "cancelled", evidence_ids: [], resolved_head: resolvedHead };
|
|
1619
|
-
ctx.log(`${jobKind} job ${job.id}: completed (${uploadedIds.length} artifact(s) posted for
|
|
1631
|
+
ctx.log(`${jobKind} job ${job.id}: completed (${uploadedIds.length} artifact(s) posted for ${jobSubjectLabel(job)} at ${shortHead})`);
|
|
1620
1632
|
return { id: job.id, status: "succeeded", evidence_ids: uploadedIds, resolved_head: resolvedHead };
|
|
1621
1633
|
}
|
|
1622
1634
|
catch (error) {
|
package/dist/version.js
CHANGED