bmad-method-test-architecture-enterprise 4.3.1 → 4.4.1
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/.claude-plugin/marketplace.json +1 -1
- package/cli/evaluate.js +6 -2
- package/cli/lib/evaluate/check.js +217 -11
- package/cli/lib/evaluate/corpus-index.js +52 -0
- package/cli/lib/evaluate/held-refusal.js +2 -3
- package/cli/lib/evaluate/run.js +16 -3
- package/cli/lib/evaluate/schemas/evaluation.schema.json +13 -0
- package/cli/lib/evaluate/score-inputs.js +13 -2
- package/cli/lib/isolate.js +351 -13
- package/cli/lib/run-agent.js +4 -0
- package/cli/lib/trace-live.js +54 -3
- package/cli/test-review.js +18 -5
- package/package.json +2 -2
- package/skills/bmad-tea/SKILL.md +2 -2
- package/skills/bmad-tea-automate/SKILL.md +2 -2
- package/skills/bmad-tea-automate/red/instructions.md +1 -1
- package/skills/bmad-tea-automate/red/steps-c/step-05-validate-and-complete.md +1 -1
- package/skills/bmad-tea-automate/red/steps-e/step-02-apply-edit.md +1 -1
- package/skills/bmad-tea-automate/red/steps-v/step-01-validate.md +1 -1
- package/skills/bmad-tea-automate/resources/test-generation-routing.md +1 -1
- package/skills/bmad-tea-automate/steps-c/step-04-validate-and-summarize.md +1 -1
- package/skills/bmad-tea-automate/steps-e/step-02-apply-edit.md +1 -1
- package/skills/bmad-tea-automate/steps-v/step-01-validate.md +1 -1
- package/skills/bmad-tea-evaluate/SKILL.md +3 -3
- package/skills/bmad-tea-evaluate/assets/README.md +1 -0
- package/skills/bmad-tea-evaluate/assets/gap-report.template.md +29 -0
- package/skills/bmad-tea-evaluate/references/ci.md +13 -0
- package/skills/bmad-tea-evaluate/references/corpus.md +2 -2
- package/skills/bmad-tea-evaluate/references/gaps.md +4 -0
- package/skills/bmad-tea-framework/SKILL.md +2 -2
- package/skills/bmad-tea-framework/resources/setup-phase-completion.md +1 -1
- package/skills/bmad-tea-framework/resources/setup-routing.md +1 -1
- package/skills/bmad-tea-nfr/SKILL.md +2 -2
- package/skills/bmad-tea-nfr/steps-c/step-05-generate-report.md +1 -1
- package/skills/bmad-tea-nfr/steps-e/step-02-apply-edit.md +1 -1
- package/skills/bmad-tea-nfr/steps-v/step-01-validate.md +1 -1
- package/skills/bmad-tea-teach-me-testing/SKILL.md +2 -2
- package/skills/bmad-tea-teach-me-testing/steps-c/step-05-completion.md +1 -1
- package/skills/bmad-tea-teach-me-testing/steps-e/step-e-02-apply-edits.md +1 -1
- package/skills/bmad-tea-teach-me-testing/steps-v/step-v-01-validate.md +1 -1
- package/skills/bmad-tea-test-design/SKILL.md +2 -2
- package/skills/bmad-tea-test-design/steps-c/step-01-detect-mode.md +2 -2
- package/skills/bmad-tea-test-design/steps-c/step-05-generate-output.md +1 -1
- package/skills/bmad-tea-test-design/steps-e/step-02-apply-edit.md +1 -1
- package/skills/bmad-tea-test-design/steps-v/step-01-validate.md +1 -1
- package/skills/bmad-tea-test-review/SKILL.md +2 -2
- package/skills/bmad-tea-test-review/steps-c/step-04-generate-report.md +1 -1
- package/skills/bmad-tea-test-review/steps-e/step-02-apply-edit.md +1 -1
- package/skills/bmad-tea-test-review/steps-v/step-01-validate.md +1 -1
- package/skills/bmad-tea-trace/SKILL.md +2 -2
- package/skills/bmad-tea-trace/steps-c/step-05-gate-decision.md +1 -1
- package/skills/bmad-tea-trace/steps-e/step-02-apply-edit.md +1 -1
- package/skills/bmad-tea-trace/steps-v/step-01-validate.md +1 -1
- package/skills/bmod-tea/bmod.toml +1 -1
- package/skills/bmod-tea/help/help.md +1 -1
package/cli/lib/isolate.js
CHANGED
|
@@ -13,12 +13,18 @@
|
|
|
13
13
|
* writes on the writable paths and their parents, and ALWAYS restores in a
|
|
14
14
|
* finally from a permission-bit snapshot taken before the lock, so the tree
|
|
15
15
|
* comes back with its exact original modes. A restore failure prints a loud
|
|
16
|
-
* warning but never masks the run result.
|
|
16
|
+
* warning but never masks the run result. Root ignores permission bits, so
|
|
17
|
+
* the fallback is never chosen for uid 0: there it would isolate nothing.
|
|
18
|
+
* While locked, SIGINT, SIGTERM and SIGHUP cannot end the process before
|
|
19
|
+
* that restore, and a lock
|
|
20
|
+
* marker in the temp directory lets the next isolated run restore a tree
|
|
21
|
+
* that a SIGKILL left locked.
|
|
17
22
|
*
|
|
18
23
|
* TEA_TEST_REVIEW_ISOLATION (sandbox-exec|bwrap|chmod|none) overrides backend
|
|
19
24
|
* selection; it exists so tests can force the chmod fallback on any platform.
|
|
20
25
|
*/
|
|
21
26
|
|
|
27
|
+
const crypto = require('node:crypto');
|
|
22
28
|
const fs = require('node:fs');
|
|
23
29
|
const os = require('node:os');
|
|
24
30
|
const path = require('node:path');
|
|
@@ -34,14 +40,24 @@ function isolationError(message) {
|
|
|
34
40
|
return error;
|
|
35
41
|
}
|
|
36
42
|
|
|
43
|
+
/** The effective uid, or null where the platform has none (win32). */
|
|
44
|
+
function currentUid() {
|
|
45
|
+
return typeof process.getuid === 'function' ? process.getuid() : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Why chmod cannot isolate a run as root, for the messages that would otherwise name it as an option. */
|
|
49
|
+
const CHMOD_ROOT_REASON =
|
|
50
|
+
'chmod cannot isolate a run as root, because root ignores permission bits; install bubblewrap (bwrap) or run as a non-root user';
|
|
51
|
+
|
|
37
52
|
/**
|
|
38
53
|
* Pick the isolation backend for this platform.
|
|
39
54
|
*
|
|
40
55
|
* @param {object} [env] - Environment to read the override/PATH from.
|
|
41
56
|
* @param {string} [platform] - Platform override for tests.
|
|
57
|
+
* @param {number|null} [uid] - Effective uid override for tests; root (0) never gets the chmod fallback.
|
|
42
58
|
* @returns {'sandbox-exec'|'bwrap'|'chmod'|null}
|
|
43
59
|
*/
|
|
44
|
-
function selectBackend(env = process.env, platform = process.platform) {
|
|
60
|
+
function selectBackend(env = process.env, platform = process.platform, uid = currentUid()) {
|
|
45
61
|
const override = env[BACKEND_OVERRIDE_ENV];
|
|
46
62
|
if (override) {
|
|
47
63
|
if (override === 'none') {
|
|
@@ -54,6 +70,10 @@ function selectBackend(env = process.env, platform = process.platform) {
|
|
|
54
70
|
return 'bwrap';
|
|
55
71
|
}
|
|
56
72
|
if (override === 'chmod' && platform !== 'win32') {
|
|
73
|
+
if (uid === 0) {
|
|
74
|
+
// Forcing a backend that cannot hold must fail, like a wrong platform, not run the agent unrestricted.
|
|
75
|
+
throw isolationError(`${BACKEND_OVERRIDE_ENV}=chmod: ${CHMOD_ROOT_REASON}.`);
|
|
76
|
+
}
|
|
57
77
|
return 'chmod';
|
|
58
78
|
}
|
|
59
79
|
// A typo (e.g. "chmodd") or a backend name that is real but wrong for this
|
|
@@ -71,12 +91,26 @@ function selectBackend(env = process.env, platform = process.platform) {
|
|
|
71
91
|
if (platform === 'linux' && executableOnPath('bwrap', env) !== null) {
|
|
72
92
|
return 'bwrap';
|
|
73
93
|
}
|
|
74
|
-
if (platform !== 'win32') {
|
|
94
|
+
if (platform !== 'win32' && uid !== 0) {
|
|
75
95
|
return 'chmod';
|
|
76
96
|
}
|
|
77
97
|
return null;
|
|
78
98
|
}
|
|
79
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Why no backend is available, for the warning or the exit 2 that follows: the root case names its own fix.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} [platform] - Platform override for tests.
|
|
104
|
+
* @param {number|null} [uid] - Effective uid override for tests.
|
|
105
|
+
* @returns {string}
|
|
106
|
+
*/
|
|
107
|
+
function noBackendReason(platform = process.platform, uid = currentUid()) {
|
|
108
|
+
if (platform !== 'win32' && uid === 0) {
|
|
109
|
+
return `no isolation backend is available: ${CHMOD_ROOT_REASON}`;
|
|
110
|
+
}
|
|
111
|
+
return 'no isolation backend (sandbox-exec, bwrap, chmod) is available on this platform';
|
|
112
|
+
}
|
|
113
|
+
|
|
80
114
|
/**
|
|
81
115
|
* Whether any isolation backend can run on this machine. Propagates
|
|
82
116
|
* selectBackend's ISOLATION_ERROR for an invalid override rather than
|
|
@@ -226,7 +260,7 @@ function snapshotModes(projectRoot) {
|
|
|
226
260
|
* Undo the lock. With a snapshot, every recorded entry goes back to its exact
|
|
227
261
|
* mode; entries created during the run were never locked and are left alone.
|
|
228
262
|
*/
|
|
229
|
-
function restoreModes(projectRoot, modes) {
|
|
263
|
+
function restoreModes(projectRoot, modes, { strict = false } = {}) {
|
|
230
264
|
if (modes === null) {
|
|
231
265
|
runChmod(['-R', 'u+w', projectRoot]);
|
|
232
266
|
return;
|
|
@@ -234,18 +268,285 @@ function restoreModes(projectRoot, modes) {
|
|
|
234
268
|
for (const [entry, mode] of modes) {
|
|
235
269
|
try {
|
|
236
270
|
fs.chmodSync(entry, mode);
|
|
237
|
-
} catch {
|
|
238
|
-
// entry
|
|
271
|
+
} catch (error) {
|
|
272
|
+
// A removed entry needs no restore. On recovery, preserve its marker
|
|
273
|
+
// if another failure made the restore incomplete.
|
|
274
|
+
if (strict && error.code !== 'ENOENT') throw error;
|
|
239
275
|
}
|
|
240
276
|
}
|
|
241
277
|
}
|
|
242
278
|
|
|
279
|
+
// Signals that end a run from outside (Ctrl-C, a cancelled CI job, a closed terminal). Node's default for each is
|
|
280
|
+
// to exit at once, which would skip the restore and leave the whole tree, .git included, read-only.
|
|
281
|
+
const STOP_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
282
|
+
|
|
283
|
+
/** The locks this process holds now: project root to restore function. */
|
|
284
|
+
const heldLocks = new Map();
|
|
285
|
+
let stopHandlersInstalled = false;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Keep a stop signal from killing the process while a tree is locked. The agent runs under spawnSync, so a handler
|
|
289
|
+
* runs only once that returns: by then the supervisor, which gets the same signal, has stopped the agent and
|
|
290
|
+
* withIsolation's finally has restored the tree. If a lock is still held when the handler runs, it restores it.
|
|
291
|
+
* Either way it then re-raises the signal with Node's default action, so the process ends as the signal asked.
|
|
292
|
+
*/
|
|
293
|
+
function installStopHandlers() {
|
|
294
|
+
if (stopHandlersInstalled) return;
|
|
295
|
+
stopHandlersInstalled = true;
|
|
296
|
+
const onStop = (signal) => {
|
|
297
|
+
for (const restore of heldLocks.values()) restore();
|
|
298
|
+
for (const name of STOP_SIGNALS) process.removeListener(name, onStop);
|
|
299
|
+
stopHandlersInstalled = false;
|
|
300
|
+
process.kill(process.pid, signal);
|
|
301
|
+
};
|
|
302
|
+
for (const name of STOP_SIGNALS) process.on(name, onStop);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** The real path of projectRoot, so a project reached through a symlink has one identity and one marker. */
|
|
306
|
+
function canonicalRoot(projectRoot) {
|
|
307
|
+
const resolved = path.resolve(projectRoot);
|
|
308
|
+
try {
|
|
309
|
+
return fs.realpathSync(resolved);
|
|
310
|
+
} catch {
|
|
311
|
+
return resolved;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** The per-user directory the lock markers live in: in the temp directory, but only this user can enter it. */
|
|
316
|
+
function markerDirectory() {
|
|
317
|
+
const uid = currentUid();
|
|
318
|
+
return path.join(os.tmpdir(), `tea-test-review-${uid === null ? 'user' : uid}`);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Whether the marker directory is one this user owns and nobody else can write: a directory (not a link), owned by
|
|
323
|
+
* this uid, with no group or other permission bits. Anything else in its place may have been planted.
|
|
324
|
+
*/
|
|
325
|
+
function markerDirectoryTrusted(directory) {
|
|
326
|
+
let stats;
|
|
327
|
+
try {
|
|
328
|
+
stats = fs.lstatSync(directory);
|
|
329
|
+
} catch {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
const uid = currentUid();
|
|
333
|
+
return stats.isDirectory() && !stats.isSymbolicLink() && (uid === null || stats.uid === uid) && (stats.mode & 0o077) === 0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Create the marker directory owner-only, or refuse one that is not; a planted directory must never hold a marker. */
|
|
337
|
+
function ensureMarkerDirectory() {
|
|
338
|
+
const directory = markerDirectory();
|
|
339
|
+
try {
|
|
340
|
+
fs.mkdirSync(directory, { mode: 0o700 });
|
|
341
|
+
} catch (error) {
|
|
342
|
+
if (error.code !== 'EEXIST') throw isolationError(`cannot create the chmod lock directory ${directory}: ${error.message}`);
|
|
343
|
+
}
|
|
344
|
+
if (!markerDirectoryTrusted(directory)) {
|
|
345
|
+
throw isolationError(
|
|
346
|
+
`the chmod lock directory ${directory} is not a directory owned by this user with mode 0700; remove it and rerun.`,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
return directory;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Where the lock marker for projectRoot lives: outside the locked tree, one per project, in the per-user directory. */
|
|
353
|
+
function lockMarkerPath(projectRoot) {
|
|
354
|
+
const digest = crypto.createHash('sha256').update(canonicalRoot(projectRoot)).digest('hex').slice(0, 16);
|
|
355
|
+
return path.join(markerDirectory(), `lock-${digest}.json`);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function processAlive(pid) {
|
|
359
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
360
|
+
try {
|
|
361
|
+
process.kill(pid, 0);
|
|
362
|
+
return true;
|
|
363
|
+
} catch (error) {
|
|
364
|
+
return error.code === 'EPERM';
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Read a marker-format file, or null: only a regular file this user owns (never through a link), holding a complete
|
|
370
|
+
* record for this project. A marker is only ever published whole, so anything unparseable is not ours to act on.
|
|
371
|
+
*/
|
|
372
|
+
function readMarkerFile(file, root) {
|
|
373
|
+
let text;
|
|
374
|
+
try {
|
|
375
|
+
const stats = fs.lstatSync(file);
|
|
376
|
+
const uid = currentUid();
|
|
377
|
+
if (!stats.isFile() || (uid !== null && stats.uid !== uid)) return null;
|
|
378
|
+
const descriptor = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
|
|
379
|
+
try {
|
|
380
|
+
text = fs.readFileSync(descriptor, 'utf8');
|
|
381
|
+
} finally {
|
|
382
|
+
fs.closeSync(descriptor);
|
|
383
|
+
}
|
|
384
|
+
const record = JSON.parse(text);
|
|
385
|
+
return record && typeof record === 'object' && record.projectRoot === root ? record : null;
|
|
386
|
+
} catch {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Read the lock marker at markerPath, or null; it is read only from a trusted marker directory. */
|
|
392
|
+
function readMarker(markerPath, root) {
|
|
393
|
+
if (!markerDirectoryTrusted(path.dirname(markerPath))) return null;
|
|
394
|
+
return readMarkerFile(markerPath, root);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** A private name beside the marker, unique to this call: a file there is this process's alone. */
|
|
398
|
+
function privateName(marker, kind) {
|
|
399
|
+
return `${marker}.${kind}.${process.pid}.${crypto.randomBytes(6).toString('hex')}`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Write a complete marker record to a new private file (never an existing one), flushed to disk. */
|
|
403
|
+
function writeRecordFile(file, root, record) {
|
|
404
|
+
const flags = fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | (fs.constants.O_NOFOLLOW ?? 0);
|
|
405
|
+
const descriptor = fs.openSync(file, flags, 0o600);
|
|
406
|
+
try {
|
|
407
|
+
fs.writeSync(descriptor, JSON.stringify({ projectRoot: root, pid: process.pid, ...record }), 0, 'utf8');
|
|
408
|
+
fs.fsyncSync(descriptor);
|
|
409
|
+
} finally {
|
|
410
|
+
fs.closeSync(descriptor);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* The snapshot a marker holds, as restoreModes takes it, when every entry is a path inside the project with a plain
|
|
416
|
+
* permission value; otherwise false, and nothing is applied.
|
|
417
|
+
*/
|
|
418
|
+
function markerSnapshot(record, root) {
|
|
419
|
+
if (record.modes === null) return null;
|
|
420
|
+
if (!Array.isArray(record.modes)) return false;
|
|
421
|
+
const modes = new Map();
|
|
422
|
+
for (const item of record.modes) {
|
|
423
|
+
if (!Array.isArray(item) || item.length !== 2) return false;
|
|
424
|
+
const [entry, mode] = item;
|
|
425
|
+
if (typeof entry !== 'string' || !path.isAbsolute(entry) || !isInside(root, entry)) return false;
|
|
426
|
+
if (!Number.isInteger(mode) || mode < 0 || mode > 0o7777) return false;
|
|
427
|
+
modes.set(entry, mode);
|
|
428
|
+
}
|
|
429
|
+
return modes;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Restore a tree an earlier chmod-isolated run left locked: it was killed in a way no handler could catch (SIGKILL,
|
|
434
|
+
* a lost container). Its marker holds the permission snapshot. A marker of a process still running is left alone,
|
|
435
|
+
* and one that names a path outside the project is refused rather than applied.
|
|
436
|
+
*
|
|
437
|
+
* @returns {boolean} Whether a lock was found and restored.
|
|
438
|
+
*/
|
|
439
|
+
function recoverInterruptedLock(projectRoot) {
|
|
440
|
+
const root = canonicalRoot(projectRoot);
|
|
441
|
+
const marker = lockMarkerPath(root);
|
|
442
|
+
const record = readMarker(marker, root);
|
|
443
|
+
if (record === null || processAlive(record.pid)) return false;
|
|
444
|
+
// Serialize stale recovery separately while leaving the original marker at
|
|
445
|
+
// its canonical name. Acquirers must keep seeing it until restoration is done.
|
|
446
|
+
const claim = `${marker}.recover`;
|
|
447
|
+
try {
|
|
448
|
+
fs.mkdirSync(claim, { mode: 0o700 });
|
|
449
|
+
} catch (error) {
|
|
450
|
+
if (error.code === 'EEXIST') return false;
|
|
451
|
+
throw isolationError(`cannot claim chmod lock recovery for ${root}: ${error.message}`);
|
|
452
|
+
}
|
|
453
|
+
try {
|
|
454
|
+
// The lock may have been recovered or acquired by another process since
|
|
455
|
+
// the first read. Never restore based on a record read before the claim.
|
|
456
|
+
const claimed = readMarker(marker, root);
|
|
457
|
+
if (claimed === null || processAlive(claimed.pid)) return false;
|
|
458
|
+
if (claimed.locked !== true) {
|
|
459
|
+
fs.rmSync(marker, { force: true });
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
const snapshot = markerSnapshot(claimed, root);
|
|
463
|
+
if (snapshot === false) {
|
|
464
|
+
console.error(
|
|
465
|
+
`tea-test-review WARNING: ignoring the chmod lock marker ${marker}: it names a path outside ${root} or an invalid mode. ` +
|
|
466
|
+
'If the project is still read-only, restore it manually with: chmod -R u+w <path>',
|
|
467
|
+
);
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
try {
|
|
471
|
+
restoreModes(root, snapshot, { strict: true });
|
|
472
|
+
} catch (error) {
|
|
473
|
+
console.error(
|
|
474
|
+
`tea-test-review WARNING: a previous run left ${root} read-only and restoring it failed: ${error.message}. ` +
|
|
475
|
+
'Restore manually with: chmod -R u+w <path>',
|
|
476
|
+
);
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
fs.rmSync(marker, { force: true });
|
|
480
|
+
console.error(`tea-test-review: restored the write permissions an interrupted run (pid ${claimed.pid}) left on ${root}.`);
|
|
481
|
+
return true;
|
|
482
|
+
} finally {
|
|
483
|
+
fs.rmdirSync(claim);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Take the lock marker for root before anything is snapshotted or locked. The record is written whole to a private
|
|
489
|
+
* file and published with an exclusive hard link, so the marker either does not exist or is complete: no run ever
|
|
490
|
+
* sees an empty one, and a second run on the same project cannot record the first run's locked modes as its own.
|
|
491
|
+
* A live holder fails this run; a dead holder's lock is recovered first.
|
|
492
|
+
*
|
|
493
|
+
* @returns {{ write: (record: object) => void, remove: () => void }}
|
|
494
|
+
*/
|
|
495
|
+
function acquireLockMarker(root) {
|
|
496
|
+
ensureMarkerDirectory();
|
|
497
|
+
const marker = lockMarkerPath(root);
|
|
498
|
+
const initial = privateName(marker, 'new');
|
|
499
|
+
writeRecordFile(initial, root, { locked: false, modes: null });
|
|
500
|
+
try {
|
|
501
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
502
|
+
try {
|
|
503
|
+
fs.linkSync(initial, marker);
|
|
504
|
+
break;
|
|
505
|
+
} catch (error) {
|
|
506
|
+
if (error.code !== 'EEXIST') throw isolationError(`cannot take the chmod lock for ${root}: ${error.message}`);
|
|
507
|
+
const holder = readMarker(marker, root);
|
|
508
|
+
if (holder !== null && processAlive(holder.pid)) {
|
|
509
|
+
throw isolationError(
|
|
510
|
+
`another tea-test-review run (pid ${holder.pid}) holds the chmod lock on ${root}; wait for it to finish and rerun.`,
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
if (attempt > 0) {
|
|
514
|
+
const claim = `${marker}.recover`;
|
|
515
|
+
if (fs.existsSync(claim)) {
|
|
516
|
+
throw isolationError(
|
|
517
|
+
`chmod lock recovery for ${root} is already claimed at ${claim}; wait for it to finish. ` +
|
|
518
|
+
'If the recovering process was killed, make sure no recovery is running, then remove only the empty .recover directory and retry.',
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
throw isolationError(`a chmod lock marker ${marker} could not be recovered; check ${root} and remove the marker.`);
|
|
522
|
+
}
|
|
523
|
+
recoverInterruptedLock(root);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
} finally {
|
|
527
|
+
fs.rmSync(initial, { force: true });
|
|
528
|
+
}
|
|
529
|
+
// Each update is written whole beside the marker and renamed over it, so a run killed mid-write leaves the previous
|
|
530
|
+
// complete record, never a torn one.
|
|
531
|
+
const write = (record) => {
|
|
532
|
+
const temporary = privateName(marker, 'tmp');
|
|
533
|
+
try {
|
|
534
|
+
writeRecordFile(temporary, root, record);
|
|
535
|
+
fs.renameSync(temporary, marker);
|
|
536
|
+
} finally {
|
|
537
|
+
fs.rmSync(temporary, { force: true });
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
const remove = () => fs.rmSync(marker, { force: true });
|
|
541
|
+
return { write, remove };
|
|
542
|
+
}
|
|
543
|
+
|
|
243
544
|
/**
|
|
244
545
|
* Lock projectRoot (chmod -R a-w) while keeping the requested artifact paths
|
|
245
546
|
* writable. Only paths inside the project root need unlocking; the root itself
|
|
246
547
|
* stays locked so the agent cannot create new top-level entries.
|
|
247
548
|
*/
|
|
248
|
-
function prepareChmodLock(projectRoot, writablePaths) {
|
|
549
|
+
function prepareChmodLock(projectRoot, writablePaths, marker, onSnapshot = () => {}) {
|
|
249
550
|
const root = path.resolve(projectRoot);
|
|
250
551
|
const insidePaths = writablePaths.map((entry) => path.resolve(entry)).filter((entry) => entry !== root && isInside(root, entry));
|
|
251
552
|
// Snapshot phase: the artifact parent directories must exist before the tree
|
|
@@ -264,6 +565,10 @@ function prepareChmodLock(projectRoot, writablePaths) {
|
|
|
264
565
|
}
|
|
265
566
|
}
|
|
266
567
|
const modes = snapshotModes(projectRoot);
|
|
568
|
+
// The snapshot is in the marker before the lock, so no moment exists where the tree is locked and nothing records
|
|
569
|
+
// how to undo it.
|
|
570
|
+
marker.write({ locked: true, modes: modes === null ? null : [...modes] });
|
|
571
|
+
onSnapshot(modes);
|
|
267
572
|
runChmod(['-R', 'a-w', projectRoot]);
|
|
268
573
|
for (const entry of insidePaths) {
|
|
269
574
|
if (fs.existsSync(entry)) {
|
|
@@ -287,6 +592,7 @@ function prepareChmodLock(projectRoot, writablePaths) {
|
|
|
287
592
|
* @returns {any} fn's return value.
|
|
288
593
|
*/
|
|
289
594
|
function withIsolation(projectRoot, writablePaths, fn) {
|
|
595
|
+
recoverInterruptedLock(projectRoot);
|
|
290
596
|
const backend = selectBackend();
|
|
291
597
|
if (backend === null) {
|
|
292
598
|
return fn({ agentCwd: projectRoot, spawnPrefix: [] });
|
|
@@ -312,24 +618,56 @@ function withIsolation(projectRoot, writablePaths, fn) {
|
|
|
312
618
|
}
|
|
313
619
|
}
|
|
314
620
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
621
|
+
// The lock works on the project's real path, so the marker, the snapshot and the restore agree on one identity.
|
|
622
|
+
const root = canonicalRoot(projectRoot);
|
|
623
|
+
const resolved = path.resolve(projectRoot);
|
|
624
|
+
const lockedWritable = writablePaths.map((entry) => {
|
|
625
|
+
const absolute = path.resolve(entry);
|
|
626
|
+
return isInside(resolved, absolute) ? path.join(root, path.relative(resolved, absolute)) : absolute;
|
|
627
|
+
});
|
|
628
|
+
let released = false;
|
|
629
|
+
let marker = null;
|
|
630
|
+
let locking = false;
|
|
631
|
+
let modes = null;
|
|
632
|
+
const release = () => {
|
|
633
|
+
if (released) return;
|
|
634
|
+
released = true;
|
|
635
|
+
heldLocks.delete(root);
|
|
636
|
+
if (marker === null) return; // the lock was never taken
|
|
637
|
+
if (!locking) {
|
|
638
|
+
marker.remove(); // nothing was locked, so there is nothing to undo
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
319
641
|
try {
|
|
320
|
-
restoreModes(
|
|
642
|
+
restoreModes(root, modes);
|
|
643
|
+
marker.remove();
|
|
321
644
|
} catch (error) {
|
|
322
645
|
console.error(
|
|
323
|
-
`tea-test-review WARNING: failed to restore write permissions under ${
|
|
646
|
+
`tea-test-review WARNING: failed to restore write permissions under ${root}: ${error.message}. ` +
|
|
324
647
|
'Restore manually with: chmod -R u+w <path>',
|
|
325
648
|
);
|
|
326
649
|
}
|
|
650
|
+
};
|
|
651
|
+
installStopHandlers();
|
|
652
|
+
heldLocks.set(root, release);
|
|
653
|
+
try {
|
|
654
|
+
marker = acquireLockMarker(root);
|
|
655
|
+
prepareChmodLock(root, lockedWritable, marker, (snapshot) => {
|
|
656
|
+
modes = snapshot;
|
|
657
|
+
locking = true;
|
|
658
|
+
});
|
|
659
|
+
return fn({ agentCwd: projectRoot, spawnPrefix: [] });
|
|
660
|
+
} finally {
|
|
661
|
+
release();
|
|
327
662
|
}
|
|
328
663
|
}
|
|
329
664
|
|
|
330
665
|
module.exports = {
|
|
331
666
|
withIsolation,
|
|
667
|
+
lockMarkerPath,
|
|
668
|
+
recoverInterruptedLock,
|
|
332
669
|
isolationAvailable,
|
|
670
|
+
noBackendReason,
|
|
333
671
|
selectBackend,
|
|
334
672
|
buildSandboxProfile,
|
|
335
673
|
buildBwrapPrefix,
|
package/cli/lib/run-agent.js
CHANGED
|
@@ -304,9 +304,13 @@ function agentAnswer({ outcome, stdout, stderr }, { command: spawned, agentComma
|
|
|
304
304
|
}
|
|
305
305
|
const error = new Error(`Agent "${command}" ${ending}${stopped}.`);
|
|
306
306
|
error.code = 'AGENT_FAILED';
|
|
307
|
+
// The signal that asked the agent's group to stop, so a caller can tell a cancelled run from a failed one.
|
|
308
|
+
if (typeof outcome.stoppedBy === 'string') error.stoppedBy = outcome.stoppedBy;
|
|
307
309
|
throw withStreams(error);
|
|
308
310
|
}
|
|
309
311
|
|
|
312
|
+
// An agent that exits 0 after a stop still ran under one: a caller must not retry what was cancelled.
|
|
313
|
+
if (typeof outcome.stoppedBy === 'string') return { stdout: stdout || '', stderr: stderr || '', stoppedBy: outcome.stoppedBy };
|
|
310
314
|
return { stdout: stdout || '', stderr: stderr || '' };
|
|
311
315
|
}
|
|
312
316
|
|
package/cli/lib/trace-live.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
4
6
|
const { spawnSync } = require('node:child_process');
|
|
5
7
|
|
|
6
8
|
const normalizedSha = (value) => {
|
|
@@ -15,10 +17,39 @@ const shaMatches = (left, right) => {
|
|
|
15
17
|
};
|
|
16
18
|
const asString = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
17
19
|
|
|
20
|
+
const REPOSITORY_ENV = ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_COMMON_DIR'];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The `safe.directory` entries of the user's system and global Git config, in the order Git reads them. Git honors
|
|
24
|
+
* this key only from protected config, so a checkout owned by another user (a container job, where
|
|
25
|
+
* `actions/checkout` adds the entry globally) is refused once that config is hidden. Read in the user's normal
|
|
26
|
+
* environment, outside any repository, so the repository's own config cannot add one, and through the files those
|
|
27
|
+
* scopes include, as Git reads them.
|
|
28
|
+
*/
|
|
29
|
+
function safeDirectories() {
|
|
30
|
+
const env = { ...process.env };
|
|
31
|
+
for (const key of REPOSITORY_ENV) delete env[key];
|
|
32
|
+
const values = [];
|
|
33
|
+
for (const scope of ['--system', '--global']) {
|
|
34
|
+
// --includes: a scoped read skips include.path files unless asked, and plain Git reads them. -z: a value may hold
|
|
35
|
+
// a newline, so values are NUL-terminated; an empty value (which resets the list) is kept.
|
|
36
|
+
const result = spawnSync('git', ['config', scope, '--includes', '-z', '--get-all', 'safe.directory'], {
|
|
37
|
+
encoding: 'utf8',
|
|
38
|
+
env,
|
|
39
|
+
cwd: os.tmpdir(),
|
|
40
|
+
});
|
|
41
|
+
if (result.status === 0 && result.stdout) values.push(...result.stdout.split('\0').slice(0, -1));
|
|
42
|
+
}
|
|
43
|
+
return values;
|
|
44
|
+
}
|
|
45
|
+
|
|
18
46
|
function git(projectRoot, ...args) {
|
|
47
|
+
// The user's config stays out (aliases, hooks and the like), except `safe.directory`, passed on the command line,
|
|
48
|
+
// which Git also honors, so Trace reads HEAD wherever plain `git` can.
|
|
49
|
+
const trusted = safeDirectories().flatMap((value) => ['-c', `safe.directory=${value}`]);
|
|
19
50
|
const env = { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' };
|
|
20
|
-
for (const key of
|
|
21
|
-
return spawnSync('git', ['-C', projectRoot, ...args], { encoding: 'utf8', env });
|
|
51
|
+
for (const key of REPOSITORY_ENV) delete env[key];
|
|
52
|
+
return spawnSync('git', [...trusted, '-C', projectRoot, ...args], { encoding: 'utf8', env });
|
|
22
53
|
}
|
|
23
54
|
|
|
24
55
|
/** The project's own full Git object ID for HEAD, or '' when Git does not resolve one. */
|
|
@@ -32,7 +63,26 @@ function gitHead(projectRoot) {
|
|
|
32
63
|
function currentSourceSha(projectRoot) {
|
|
33
64
|
const head = gitHead(projectRoot);
|
|
34
65
|
if (head) return head;
|
|
35
|
-
|
|
66
|
+
const location = git(projectRoot, 'rev-parse', '--is-inside-work-tree');
|
|
67
|
+
// An unreadable or untrusted checkout is not a source archive. Refuse the
|
|
68
|
+
// CI fallback if Git failed or if checkout metadata is still present.
|
|
69
|
+
if (location.error || location.status !== 128) return '';
|
|
70
|
+
let directory;
|
|
71
|
+
try {
|
|
72
|
+
directory = fs.realpathSync(projectRoot);
|
|
73
|
+
} catch {
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
for (; ; directory = path.dirname(directory)) {
|
|
77
|
+
try {
|
|
78
|
+
fs.lstatSync(path.join(directory, '.git'));
|
|
79
|
+
return '';
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error.code !== 'ENOENT') return '';
|
|
82
|
+
}
|
|
83
|
+
if (directory === path.dirname(directory)) break;
|
|
84
|
+
}
|
|
85
|
+
return normalizedSha(process.env.GITHUB_SHA);
|
|
36
86
|
}
|
|
37
87
|
|
|
38
88
|
/**
|
|
@@ -154,6 +204,7 @@ module.exports = {
|
|
|
154
204
|
normalizedSha,
|
|
155
205
|
gitHead,
|
|
156
206
|
currentSourceSha,
|
|
207
|
+
safeDirectories,
|
|
157
208
|
captureLiveResults,
|
|
158
209
|
assertLiveSourceRevision,
|
|
159
210
|
liveAliasMap,
|
package/cli/test-review.js
CHANGED
|
@@ -82,7 +82,7 @@ const { loadRegistryRowSeverities } = require('./lib/registry-rows');
|
|
|
82
82
|
const { runAgent } = require('./lib/run-agent');
|
|
83
83
|
const { neutralizeWorkflowCommands } = require('./lib/safe-log');
|
|
84
84
|
const { AGENT_ADAPTERS, resolveModel, resolvedModelFromAnswer, agentAnswerText } = require('./lib/agent-adapters');
|
|
85
|
-
const { withIsolation, selectBackend } = require('./lib/isolate');
|
|
85
|
+
const { withIsolation, selectBackend, noBackendReason, recoverInterruptedLock } = require('./lib/isolate');
|
|
86
86
|
const { resolveTeaConfig, PACT_MCP_VALUES, EXECUTION_MODE_VALUES } = require('./lib/resolve-tea-config');
|
|
87
87
|
const { RUBRIC_VERSION, TEA_CLI_VERSION, buildReviewProvenance, skillRubricVersion } = require('./lib/review-provenance');
|
|
88
88
|
const { validInterval } = require('./lib/heartbeat');
|
|
@@ -1366,6 +1366,10 @@ async function runReview(session) {
|
|
|
1366
1366
|
}
|
|
1367
1367
|
}
|
|
1368
1368
|
|
|
1369
|
+
// A chmod-isolated run killed by SIGKILL left the tree read-only; restore it from its marker before the output
|
|
1370
|
+
// checks below, which would otherwise fail on the locked directories (#514).
|
|
1371
|
+
recoverInterruptedLock(projectRoot);
|
|
1372
|
+
|
|
1369
1373
|
// An output the agent cannot write fails every attempt after the paid agent run,
|
|
1370
1374
|
// so the directories are made and checked once, up front, as an environment error.
|
|
1371
1375
|
for (const artifact of [outputPath, jsonPath]) {
|
|
@@ -1409,9 +1413,9 @@ async function runReview(session) {
|
|
|
1409
1413
|
if (backend !== null) {
|
|
1410
1414
|
isolationActive = true;
|
|
1411
1415
|
} else if (isolateExplicit) {
|
|
1412
|
-
fail(EXIT.ENV_ERROR,
|
|
1416
|
+
fail(EXIT.ENV_ERROR, `--isolate was requested but ${noBackendReason()}.`);
|
|
1413
1417
|
} else {
|
|
1414
|
-
console.error(
|
|
1418
|
+
console.error(`tea-test-review: CI requested isolation but ${noBackendReason()}; continuing without it.`);
|
|
1415
1419
|
}
|
|
1416
1420
|
}
|
|
1417
1421
|
|
|
@@ -1485,6 +1489,8 @@ async function runReview(session) {
|
|
|
1485
1489
|
runId: randomUUID(),
|
|
1486
1490
|
});
|
|
1487
1491
|
|
|
1492
|
+
// The stop signal an agent that exited 0 ran under: a report it left incomplete is a stopped run, not a retry.
|
|
1493
|
+
let agentStoppedBy = null;
|
|
1488
1494
|
const executeAgent = ({ agentCwd, spawnPrefix }) => {
|
|
1489
1495
|
const stopHeartbeat = startHeartbeat();
|
|
1490
1496
|
let agentResult;
|
|
@@ -1505,6 +1511,7 @@ async function runReview(session) {
|
|
|
1505
1511
|
stopHeartbeat();
|
|
1506
1512
|
}
|
|
1507
1513
|
|
|
1514
|
+
agentStoppedBy = agentResult.stoppedBy ?? null;
|
|
1508
1515
|
const ranModel = resolvedModelFromAnswer(options.agent, agentResult.stdout);
|
|
1509
1516
|
if (ranModel !== null) {
|
|
1510
1517
|
resolvedModel = ranModel;
|
|
@@ -1793,6 +1800,10 @@ async function runReview(session) {
|
|
|
1793
1800
|
}
|
|
1794
1801
|
processReport();
|
|
1795
1802
|
return gateFailures;
|
|
1803
|
+
} catch (error) {
|
|
1804
|
+
// A complete report written before the stop still counts; a missing or broken one is not retried.
|
|
1805
|
+
if (agentStoppedBy !== null && error && error.stoppedBy === undefined) error.stoppedBy = agentStoppedBy;
|
|
1806
|
+
throw error;
|
|
1796
1807
|
} finally {
|
|
1797
1808
|
cleanupRunArtifacts();
|
|
1798
1809
|
}
|
|
@@ -1813,7 +1824,9 @@ async function runReview(session) {
|
|
|
1813
1824
|
}
|
|
1814
1825
|
if (error.code === 'AGENT_FAILED' || error.code === 'REPORT_MISSING' || error.code === 'REPORT_UNPARSEABLE') {
|
|
1815
1826
|
if (error.code === 'AGENT_FAILED') printAgentFailureDiagnostics(error, options.agent);
|
|
1816
|
-
|
|
1827
|
+
// A run someone stopped (Ctrl-C, a cancelled CI job) is not a transient failure: a retry would start the agent again.
|
|
1828
|
+
const stopped = typeof error.stoppedBy === 'string';
|
|
1829
|
+
if (attempt < retries && !stopped) {
|
|
1817
1830
|
console.error(`tea-test-review: ${error.message}`);
|
|
1818
1831
|
const retryNotice = `attempt ${attempt + 1} of ${retries + 1} failed (exit 3); retrying.`;
|
|
1819
1832
|
console.error(`tea-test-review: ${retryNotice}`);
|
|
@@ -1824,7 +1837,7 @@ async function runReview(session) {
|
|
|
1824
1837
|
}
|
|
1825
1838
|
continue;
|
|
1826
1839
|
}
|
|
1827
|
-
fail(EXIT.AGENT_OR_PARSE_ERROR, error.message);
|
|
1840
|
+
fail(EXIT.AGENT_OR_PARSE_ERROR, stopped ? `${error.message} Not retried: the run was stopped.` : error.message);
|
|
1828
1841
|
}
|
|
1829
1842
|
if (error.code === 'ISOLATION_ERROR' || error.code === 'AGENT_NOT_FOUND') {
|
|
1830
1843
|
fail(EXIT.ENV_ERROR, error.message);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "bmad-method-test-architecture-enterprise",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.4.1",
|
|
5
5
|
"description": "Master Test Architect for quality strategy, test automation, and release gates",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"bmad",
|
|
@@ -386,7 +386,7 @@
|
|
|
386
386
|
"zod-to-json-schema": "3.25.1"
|
|
387
387
|
},
|
|
388
388
|
"peerDependencies": {
|
|
389
|
-
"eval-quality": ">=10.1.
|
|
389
|
+
"eval-quality": ">=10.1.1"
|
|
390
390
|
},
|
|
391
391
|
"peerDependenciesMeta": {
|
|
392
392
|
"eval-quality": {
|
package/skills/bmad-tea/SKILL.md
CHANGED
|
@@ -23,7 +23,7 @@ Before resolving the agent menu, inspect `{project-root}/_bmad/custom/bmad-tea.t
|
|
|
23
23
|
|
|
24
24
|
### Step 1: Resolve the Agent Block
|
|
25
25
|
|
|
26
|
-
Run: `uv run {project-root}/_bmad/scripts/resolve_customization.py --skill {skill-root} --project-root {project-root} --key agent`
|
|
26
|
+
Run: `uv run "{project-root}/_bmad/scripts/resolve_customization.py" --skill "{skill-root}" --project-root "{project-root}" --key agent`
|
|
27
27
|
|
|
28
28
|
**If the script fails**, resolve the `agent` block yourself by reading these three files in base → team → user order and applying the same structural merge rules as the resolver:
|
|
29
29
|
|
|
@@ -49,7 +49,7 @@ Treat every entry in `{agent.persistent_facts}` as foundational context you carr
|
|
|
49
49
|
|
|
50
50
|
### Step 5: Load Config
|
|
51
51
|
|
|
52
|
-
Run `uv run {project-root}/_bmad/scripts/resolve_config.py --project-root {project-root} --key core --key modules.tea`. If the script fails, merge `{project-root}/_bmad/config.toml`, `{project-root}/_bmad/custom/config.toml` and `{project-root}/_bmad/custom/config.user.toml` yourself, in that order, with the merge rules above. If `_bmad/config.toml` is missing or has no `modules.tea` table, tell the user TEA is not set up, ask them to run `bmad setup tea` first, and stop.
|
|
52
|
+
Run `uv run "{project-root}/_bmad/scripts/resolve_config.py" --project-root "{project-root}" --key core --key modules.tea`. If the script fails, merge `{project-root}/_bmad/config.toml`, `{project-root}/_bmad/custom/config.toml` and `{project-root}/_bmad/custom/config.user.toml` yourself, in that order, with the merge rules above. If `_bmad/config.toml` is missing or has no `modules.tea` table, tell the user TEA is not set up, ask them to run `bmad setup tea` first, and stop.
|
|
53
53
|
|
|
54
54
|
Each `core` and `modules.tea` key is available as `{<key>}`, and as `config.<key>` in later steps. Replace `{project-root}` inside a value with the project root. Setup answers are strings: read `"true"` and `"false"` as booleans.
|
|
55
55
|
|