bmad-method-test-architecture-enterprise 4.4.1 → 4.4.2
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/lib/isolate.js +101 -51
- package/package.json +1 -1
- package/skills/bmod-tea/bmod.toml +1 -1
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"name": "bmad-method-test-architecture-enterprise",
|
|
32
32
|
"source": "./",
|
|
33
33
|
"description": "Master Test Architect module for quality strategy, test generation in red and expand modes with automatic run-and-heal, combined framework and CI setup, CI/CD quality gates, and structured testing education. Existing CI and ATDD customizations can be migrated to the new skill names. Part of the BMad Method ecosystem.",
|
|
34
|
-
"version": "4.4.
|
|
34
|
+
"version": "4.4.2",
|
|
35
35
|
"author": {
|
|
36
36
|
"name": "Murat K Ozcan (TEA Creator) & Brian (BMad) Madison"
|
|
37
37
|
},
|
package/cli/lib/isolate.js
CHANGED
|
@@ -33,6 +33,11 @@ const { spawnSync } = require('node:child_process');
|
|
|
33
33
|
const { assertProfileSafePath, executableOnPath, isInside } = require('./isolation-primitives');
|
|
34
34
|
|
|
35
35
|
const BACKEND_OVERRIDE_ENV = 'TEA_TEST_REVIEW_ISOLATION';
|
|
36
|
+
const CHMOD_SNAPSHOT_VERSION = 1;
|
|
37
|
+
const PERMISSION_BITS = 0o7777n;
|
|
38
|
+
// Node does not export these platform-specific flags.
|
|
39
|
+
const DARWIN_NOFOLLOW_ANY = 0x20_00_00_00;
|
|
40
|
+
const LINUX_PATH_ONLY = 0o1000_0000;
|
|
36
41
|
|
|
37
42
|
function isolationError(message) {
|
|
38
43
|
const error = new Error(message);
|
|
@@ -206,8 +211,8 @@ function lockedParents(writablePath, projectRoot) {
|
|
|
206
211
|
|
|
207
212
|
/**
|
|
208
213
|
* Walk a tree depth-first without following symlinks (matching `chmod -R`), and
|
|
209
|
-
* visit every entry.
|
|
210
|
-
*
|
|
214
|
+
* visit every entry that still exists. A tree we cannot read cannot be locked
|
|
215
|
+
* with a complete permission snapshot.
|
|
211
216
|
*/
|
|
212
217
|
function walkTree(root, visit) {
|
|
213
218
|
const stack = [root];
|
|
@@ -215,8 +220,9 @@ function walkTree(root, visit) {
|
|
|
215
220
|
const current = stack.pop();
|
|
216
221
|
let stats;
|
|
217
222
|
try {
|
|
218
|
-
stats = fs.lstatSync(current);
|
|
219
|
-
} catch {
|
|
223
|
+
stats = fs.lstatSync(current, { bigint: true });
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (error.code !== 'ENOENT') throw isolationError(`cannot snapshot permissions for ${current}: ${error.message}`);
|
|
220
226
|
continue;
|
|
221
227
|
}
|
|
222
228
|
if (stats.isSymbolicLink()) {
|
|
@@ -227,7 +233,8 @@ function walkTree(root, visit) {
|
|
|
227
233
|
let names;
|
|
228
234
|
try {
|
|
229
235
|
names = fs.readdirSync(current);
|
|
230
|
-
} catch {
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (error.code !== 'ENOENT') throw isolationError(`cannot snapshot permissions under ${current}: ${error.message}`);
|
|
231
238
|
continue;
|
|
232
239
|
}
|
|
233
240
|
for (const name of names) {
|
|
@@ -237,43 +244,82 @@ function walkTree(root, visit) {
|
|
|
237
244
|
}
|
|
238
245
|
}
|
|
239
246
|
|
|
240
|
-
/**
|
|
241
|
-
* Record every entry's permission bits so the lock can be undone exactly.
|
|
242
|
-
* `chmod -R u+w` is not an inverse of `chmod -R a-w`: it drops group/other write
|
|
243
|
-
* bits permanently and makes deliberately read-only files writable, so a local
|
|
244
|
-
* run would silently rewrite the permissions of the tree it was protecting.
|
|
245
|
-
*
|
|
246
|
-
* @returns {Map<string, number>|null} Path to mode, or null when the snapshot
|
|
247
|
-
* could not be taken (the caller then falls back to the blanket restore).
|
|
248
|
-
*/
|
|
247
|
+
/** Record the permission bits and identity of each entry before locking it. */
|
|
249
248
|
function snapshotModes(projectRoot) {
|
|
249
|
+
const modes = new Map();
|
|
250
|
+
walkTree(projectRoot, (entry, stats) => {
|
|
251
|
+
const saved = {
|
|
252
|
+
mode: Number(stats.mode & PERMISSION_BITS),
|
|
253
|
+
dev: stats.dev.toString(),
|
|
254
|
+
ino: stats.ino.toString(),
|
|
255
|
+
birth: stats.birthtimeNs.toString(),
|
|
256
|
+
};
|
|
257
|
+
// Check procfs before locking on Linux. On macOS, make sure every writable entry can still be opened after the lock.
|
|
258
|
+
if ((process.platform === 'linux' && entry === projectRoot) || (process.platform === 'darwin' && (saved.mode & 0o222) !== 0)) {
|
|
259
|
+
try {
|
|
260
|
+
fs.closeSync(openChmodEntry(entry, saved));
|
|
261
|
+
} catch (error) {
|
|
262
|
+
throw isolationError(`cannot safely recover permissions for ${entry}: ${error.message}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
modes.set(entry, saved);
|
|
266
|
+
});
|
|
267
|
+
if (modes.size === 0) throw isolationError(`cannot take a permission snapshot of ${projectRoot}`);
|
|
268
|
+
return modes;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function matchesSnapshot(stats, saved) {
|
|
272
|
+
return (
|
|
273
|
+
!stats.isSymbolicLink() &&
|
|
274
|
+
stats.dev.toString() === saved.dev &&
|
|
275
|
+
stats.ino.toString() === saved.ino &&
|
|
276
|
+
stats.birthtimeNs.toString() === saved.birth
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function changedEntry(entry) {
|
|
281
|
+
return new Error(`${entry} no longer names the recorded file or directory`);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Pin the object before changing its permissions. On Linux O_PATH also covers unreadable files and special entries. */
|
|
285
|
+
function openChmodEntry(entry, saved) {
|
|
286
|
+
const flags =
|
|
287
|
+
process.platform === 'linux'
|
|
288
|
+
? LINUX_PATH_ONLY | fs.constants.O_NOFOLLOW
|
|
289
|
+
: fs.constants.O_RDONLY | fs.constants.O_NONBLOCK | (process.platform === 'darwin' ? DARWIN_NOFOLLOW_ANY : fs.constants.O_NOFOLLOW);
|
|
290
|
+
const descriptor = fs.openSync(entry, flags);
|
|
250
291
|
try {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
292
|
+
if (!matchesSnapshot(fs.fstatSync(descriptor, { bigint: true }), saved)) throw changedEntry(entry);
|
|
293
|
+
// Linux's leaf-only no-follow flag allows intermediate symlinks. Verify the kernel's path for the pinned object.
|
|
294
|
+
if (process.platform === 'linux' && fs.readlinkSync(`/proc/self/fd/${descriptor}`) !== entry) throw changedEntry(entry);
|
|
295
|
+
return descriptor;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
fs.closeSync(descriptor);
|
|
298
|
+
throw error;
|
|
256
299
|
}
|
|
257
300
|
}
|
|
258
301
|
|
|
259
|
-
/**
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
function restoreModes(projectRoot, modes, { strict = false } = {}) {
|
|
264
|
-
if (modes === null) {
|
|
265
|
-
runChmod(['-R', 'u+w', projectRoot]);
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
for (const [entry, mode] of modes) {
|
|
302
|
+
/** Restore only the recorded objects. A missing entry needs no restoration. */
|
|
303
|
+
function restoreModes(modes) {
|
|
304
|
+
let firstError;
|
|
305
|
+
for (const [entry, saved] of modes) {
|
|
269
306
|
try {
|
|
270
|
-
fs.
|
|
307
|
+
const current = fs.lstatSync(entry, { bigint: true });
|
|
308
|
+
if (!matchesSnapshot(current, saved)) throw changedEntry(entry);
|
|
309
|
+
if (Number(current.mode & PERMISSION_BITS) === saved.mode) continue;
|
|
310
|
+
const descriptor = openChmodEntry(entry, saved);
|
|
311
|
+
try {
|
|
312
|
+
if (process.platform === 'linux') fs.chmodSync(`/proc/self/fd/${descriptor}`, saved.mode);
|
|
313
|
+
else fs.fchmodSync(descriptor, saved.mode);
|
|
314
|
+
} finally {
|
|
315
|
+
fs.closeSync(descriptor);
|
|
316
|
+
}
|
|
271
317
|
} catch (error) {
|
|
272
|
-
// A
|
|
273
|
-
|
|
274
|
-
if (strict && error.code !== 'ENOENT') throw error;
|
|
318
|
+
// A missing procfs descriptor or a failed chmod is an incomplete restore, not a removed project entry.
|
|
319
|
+
if (error.code !== 'ENOENT' || error.path !== entry) firstError ??= error;
|
|
275
320
|
}
|
|
276
321
|
}
|
|
322
|
+
if (firstError) throw firstError;
|
|
277
323
|
}
|
|
278
324
|
|
|
279
325
|
// Signals that end a run from outside (Ctrl-C, a cancelled CI job, a closed terminal). Node's default for each is
|
|
@@ -404,27 +450,24 @@ function writeRecordFile(file, root, record) {
|
|
|
404
450
|
const flags = fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | (fs.constants.O_NOFOLLOW ?? 0);
|
|
405
451
|
const descriptor = fs.openSync(file, flags, 0o600);
|
|
406
452
|
try {
|
|
407
|
-
fs.
|
|
453
|
+
fs.writeFileSync(descriptor, JSON.stringify({ projectRoot: root, pid: process.pid, ...record }), 'utf8');
|
|
408
454
|
fs.fsyncSync(descriptor);
|
|
409
455
|
} finally {
|
|
410
456
|
fs.closeSync(descriptor);
|
|
411
457
|
}
|
|
412
458
|
}
|
|
413
459
|
|
|
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
|
-
*/
|
|
460
|
+
/** Decode a snapshot only when every entry has an identity and names a path inside the project. */
|
|
418
461
|
function markerSnapshot(record, root) {
|
|
419
|
-
if (record.modes ===
|
|
420
|
-
if (!Array.isArray(record.modes)) return false;
|
|
462
|
+
if (!Array.isArray(record.modes) || record.modes.length === 0) return false;
|
|
421
463
|
const modes = new Map();
|
|
422
464
|
for (const item of record.modes) {
|
|
423
465
|
if (!Array.isArray(item) || item.length !== 2) return false;
|
|
424
|
-
const [entry,
|
|
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
|
-
|
|
466
|
+
const [entry, saved] = item;
|
|
467
|
+
if (typeof entry !== 'string' || !path.isAbsolute(entry) || path.resolve(entry) !== entry || !isInside(root, entry)) return false;
|
|
468
|
+
if (saved === null || typeof saved !== 'object' || !Number.isInteger(saved.mode) || saved.mode < 0 || saved.mode > 0o7777) return false;
|
|
469
|
+
if (![saved.dev, saved.ino, saved.birth].every((id) => typeof id === 'string' && /^-?\d+$/.test(id))) return false;
|
|
470
|
+
modes.set(entry, saved);
|
|
428
471
|
}
|
|
429
472
|
return modes;
|
|
430
473
|
}
|
|
@@ -459,20 +502,27 @@ function recoverInterruptedLock(projectRoot) {
|
|
|
459
502
|
fs.rmSync(marker, { force: true });
|
|
460
503
|
return false;
|
|
461
504
|
}
|
|
505
|
+
if (claimed.snapshotVersion !== CHMOD_SNAPSHOT_VERSION) {
|
|
506
|
+
console.error(
|
|
507
|
+
`tea-test-review WARNING: cannot automatically restore ${root} from the older chmod lock marker ${marker}: it lacks file identities. ` +
|
|
508
|
+
'Review the recorded paths and restore their permissions manually before removing the marker.',
|
|
509
|
+
);
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
462
512
|
const snapshot = markerSnapshot(claimed, root);
|
|
463
513
|
if (snapshot === false) {
|
|
464
514
|
console.error(
|
|
465
|
-
`tea-test-review WARNING: ignoring the chmod lock marker ${marker}: it names a path outside ${root} or an invalid
|
|
466
|
-
'
|
|
515
|
+
`tea-test-review WARNING: ignoring the chmod lock marker ${marker}: it names a path outside ${root} or has an invalid permission snapshot. ` +
|
|
516
|
+
'Review the recorded paths and restore their permissions manually before removing the marker.',
|
|
467
517
|
);
|
|
468
518
|
return false;
|
|
469
519
|
}
|
|
470
520
|
try {
|
|
471
|
-
restoreModes(
|
|
521
|
+
restoreModes(snapshot);
|
|
472
522
|
} catch (error) {
|
|
473
523
|
console.error(
|
|
474
524
|
`tea-test-review WARNING: a previous run left ${root} read-only and restoring it failed: ${error.message}. ` +
|
|
475
|
-
'
|
|
525
|
+
'Review the recorded paths and restore their permissions manually before removing the marker.',
|
|
476
526
|
);
|
|
477
527
|
return false;
|
|
478
528
|
}
|
|
@@ -567,7 +617,7 @@ function prepareChmodLock(projectRoot, writablePaths, marker, onSnapshot = () =>
|
|
|
567
617
|
const modes = snapshotModes(projectRoot);
|
|
568
618
|
// The snapshot is in the marker before the lock, so no moment exists where the tree is locked and nothing records
|
|
569
619
|
// how to undo it.
|
|
570
|
-
marker.write({ locked: true,
|
|
620
|
+
marker.write({ locked: true, snapshotVersion: CHMOD_SNAPSHOT_VERSION, modes: [...modes] });
|
|
571
621
|
onSnapshot(modes);
|
|
572
622
|
runChmod(['-R', 'a-w', projectRoot]);
|
|
573
623
|
for (const entry of insidePaths) {
|
|
@@ -639,12 +689,12 @@ function withIsolation(projectRoot, writablePaths, fn) {
|
|
|
639
689
|
return;
|
|
640
690
|
}
|
|
641
691
|
try {
|
|
642
|
-
restoreModes(
|
|
692
|
+
restoreModes(modes);
|
|
643
693
|
marker.remove();
|
|
644
694
|
} catch (error) {
|
|
645
695
|
console.error(
|
|
646
696
|
`tea-test-review WARNING: failed to restore write permissions under ${root}: ${error.message}. ` +
|
|
647
|
-
'
|
|
697
|
+
'Review the recorded paths and restore their permissions manually before removing the marker.',
|
|
648
698
|
);
|
|
649
699
|
}
|
|
650
700
|
};
|
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.
|
|
4
|
+
"version": "4.4.2",
|
|
5
5
|
"description": "Master Test Architect for quality strategy, test automation, and release gates",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"bmad",
|