@aviaratech/ai-delivery 0.3.33 → 0.3.35
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/README.md +70 -3
- package/dist/boardReconcile.test.d.ts +1 -0
- package/dist/boardReconcile.test.js +1685 -0
- package/dist/boardReconcile.test.js.map +1 -0
- package/dist/cli.js +37 -1
- package/dist/cli.js.map +1 -1
- package/dist/cliResult.js +21 -1
- package/dist/cliResult.js.map +1 -1
- package/dist/cliResult.test.js +82 -0
- package/dist/cliResult.test.js.map +1 -1
- package/dist/config/deliveryConfig.d.ts +32 -0
- package/dist/config/deliveryConfig.js +5 -0
- package/dist/config/deliveryConfig.js.map +1 -1
- package/dist/config/deliveryConfig.test.js +67 -0
- package/dist/config/deliveryConfig.test.js.map +1 -1
- package/dist/currentTrackingScenario.test.js +6 -4
- package/dist/currentTrackingScenario.test.js.map +1 -1
- package/dist/directoryIndependent.test.js +2 -2
- package/dist/directoryIndependent.test.js.map +1 -1
- package/dist/dispatch.d.ts +1 -1
- package/dist/dispatch.js +33 -1
- package/dist/dispatch.js.map +1 -1
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/fixtures/inertEntrypoints.js +7 -0
- package/dist/fixtures/inertEntrypoints.js.map +1 -1
- package/dist/github/commandIdentityPolicy.js +1 -0
- package/dist/github/commandIdentityPolicy.js.map +1 -1
- package/dist/github/discovery.d.ts +2 -0
- package/dist/github/discovery.js +17 -3
- package/dist/github/discovery.js.map +1 -1
- package/dist/github/nativeIssueMetadata.d.ts +27 -0
- package/dist/github/nativeIssueMetadata.js +58 -0
- package/dist/github/nativeIssueMetadata.js.map +1 -1
- package/dist/github/projectDelivery.d.ts +36 -0
- package/dist/github/projectDelivery.js +136 -31
- package/dist/github/projectDelivery.js.map +1 -1
- package/dist/github/relationships.d.ts +5 -2
- package/dist/github/relationships.js +59 -2
- package/dist/github/relationships.js.map +1 -1
- package/dist/issue.d.ts +72 -3
- package/dist/issue.js +354 -117
- package/dist/issue.js.map +1 -1
- package/dist/issueBatchUpdate.test.js +229 -12
- package/dist/issueBatchUpdate.test.js.map +1 -1
- package/dist/issueDates.test.d.ts +1 -0
- package/dist/issueDates.test.js +253 -0
- package/dist/issueDates.test.js.map +1 -0
- package/dist/issueTracking.test.js +436 -11
- package/dist/issueTracking.test.js.map +1 -1
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tools.d.ts +598 -0
- package/dist/mcp/tools.js +10 -0
- package/dist/mcp/tools.js.map +1 -1
- package/dist/pluginInstaller.js +21 -23
- package/dist/pluginInstaller.js.map +1 -1
- package/dist/pluginInstaller.test.js +121 -1
- package/dist/pluginInstaller.test.js.map +1 -1
- package/dist/pluginPackaging.test.js +135 -6
- package/dist/pluginPackaging.test.js.map +1 -1
- package/dist/pr.d.ts +7 -0
- package/dist/pr.js +104 -99
- package/dist/pr.js.map +1 -1
- package/dist/pr.test.js +202 -223
- package/dist/pr.test.js.map +1 -1
- package/dist/prAssociation.test.js +11 -10
- package/dist/prAssociation.test.js.map +1 -1
- package/dist/review.d.ts +1 -0
- package/dist/review.js +7 -6
- package/dist/review.js.map +1 -1
- package/dist/review.test.js +8 -4
- package/dist/review.test.js.map +1 -1
- package/dist/services/boardReconcileService.d.ts +1204 -0
- package/dist/services/boardReconcileService.js +1571 -0
- package/dist/services/boardReconcileService.js.map +1 -0
- package/dist/services/deliveryAdmission.d.ts +2 -0
- package/dist/services/deliveryAdmission.js +2 -2
- package/dist/services/deliveryAdmission.js.map +1 -1
- package/dist/setup.test.js +474 -32
- package/dist/setup.test.js.map +1 -1
- package/dist/stdoutRegression.test.js +27 -2
- package/dist/stdoutRegression.test.js.map +1 -1
- package/dist/targetPolicyRoutes.test.js +2 -2
- package/dist/targetPolicyRoutes.test.js.map +1 -1
- package/dist/verification.js +38 -2
- package/dist/verification.js.map +1 -1
- package/dist/verificationGate.test.js +25 -2
- package/dist/verificationGate.test.js.map +1 -1
- package/dist/version.d.ts +6 -0
- package/dist/version.js +16 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -1
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +24 -0
- package/plugins/ai-delivery/runtime/dist/cli.js +68 -67
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +4 -4
package/dist/setup.test.js
CHANGED
|
@@ -109,6 +109,7 @@ const actors = vi.hoisted(() => ({
|
|
|
109
109
|
authorStarted: false,
|
|
110
110
|
authorAborted: false,
|
|
111
111
|
pauseAuthor: false,
|
|
112
|
+
authorDelayMs: 4_000,
|
|
112
113
|
}));
|
|
113
114
|
// Only GitHub HTTP/authentication is synthetic. Resolver, process ownership and file operations are real.
|
|
114
115
|
vi.mock('./github/client.js', async (original) => ({
|
|
@@ -130,7 +131,7 @@ vi.mock('./github/client.js', async (original) => ({
|
|
|
130
131
|
if (actors.pauseAuthor) {
|
|
131
132
|
await new Promise((resolve, reject) => {
|
|
132
133
|
// A delayed HTTP response bounds this fixture's request, not the stage's elapsed duration.
|
|
133
|
-
const response = setTimeout(resolve,
|
|
134
|
+
const response = setTimeout(resolve, actors.authorDelayMs);
|
|
134
135
|
const abort = () => {
|
|
135
136
|
clearTimeout(response);
|
|
136
137
|
actors.authorAborted = true;
|
|
@@ -183,6 +184,7 @@ async function fixture(native = false, parent = tmpdir()) {
|
|
|
183
184
|
actors.authorStarted = false;
|
|
184
185
|
actors.authorAborted = false;
|
|
185
186
|
actors.pauseAuthor = false;
|
|
187
|
+
actors.authorDelayMs = 4_000;
|
|
186
188
|
const base = realpathSync(mkdtempSync(join(parent, 'ai-delivery-setup-')));
|
|
187
189
|
const root = join(base, 'consumer');
|
|
188
190
|
mkdirSync(root);
|
|
@@ -247,7 +249,7 @@ async function fixture(native = false, parent = tmpdir()) {
|
|
|
247
249
|
const counter = join(base, 'installs');
|
|
248
250
|
const marker = join(base, 'installer-running');
|
|
249
251
|
// Synthetic installer boundary: the real owned command copies fixture bytes; no process manager is mocked.
|
|
250
|
-
writeFileSync(join(bin, 'npm'), `#!${process.execPath}\nconst fs=require('fs'),cp=require('child_process'),path=require('path');\nconst args=process.argv.slice(2);\nif(args[0]!=='install'||!['--omit=dev','--ignore-scripts','--no-audit','--no-fund'].every(x=>args.includes(x)))process.exit(9);\nfs.appendFileSync(${JSON.stringify(counter)},'x');\nfs.writeFileSync(${JSON.stringify(marker)},String(process.pid));\nconst prefix=args[args.indexOf('--prefix')+1],archive=args.at(-1);\nfs.writeFileSync(${JSON.stringify(join(base, 'installer-settings'))},JSON.stringify({args,cwd:process.cwd(),TMPDIR:process.env.TMPDIR,TMP:process.env.TMP,TEMP:process.env.TEMP}));\nfs.writeFileSync(${JSON.stringify(join(base, 'installer-archive'))},archive);\nconst original=${JSON.stringify(archivePath)},replacement=${JSON.stringify(join(base, 'replacement.tgz'))};\nconst saved=fs.existsSync(replacement)?fs.readFileSync(original):undefined;\nif(saved)fs.copyFileSync(replacement,original);\nconst target=path.join(prefix,'node_modules/@aviaratech/ai-delivery');fs.mkdirSync(target,{recursive:true});\ntry{cp.execFileSync('tar',['-xzf',archive,'--strip-components=1','-C',target]);}finally{if(saved)fs.writeFileSync(original,saved);}\nconst dependency={'@aviaratech/ai-delivery':'file:reviewed-archive.tgz'};fs.writeFileSync(path.join(prefix,'package.json'),JSON.stringify({dependencies:dependency}));\nif(!args.includes('--package-lock=false')){const targetPackage=JSON.parse(fs.readFileSync(path.join(target,'package.json'),'utf8')),integrity='sha512-'+require('node:crypto').createHash('sha512').update(fs.readFileSync(archive)).digest('base64');fs.writeFileSync(path.join(prefix,'package-lock.json'),JSON.stringify({lockfileVersion:3,packages:{'':{dependencies:dependency},'node_modules/@aviaratech/ai-delivery':{version:targetPackage.version,resolved:'file:reviewed-archive.tgz',integrity}}}));}\nfs.mkdirSync(path.join(prefix,'node_modules/.bin'),{recursive:true});\nfs.symlinkSync('../@aviaratech/ai-delivery/dist/cli.js',path.join(prefix,'node_modules/.bin/ai-delivery'));\nconst logs=${JSON.stringify(join(base, 'log-bytes'))};\nif(fs.existsSync(logs))process.stdout.write(Buffer.alloc(Number(fs.readFileSync(logs,'utf8')),65),()=>{if(fs.existsSync(${JSON.stringify(join(base, 'fail'))}))process.exit(7);});\nelse if(fs.existsSync(${JSON.stringify(join(base, 'fail'))}))process.exit(7);\nconst memory=${JSON.stringify(join(base, 'memory-bytes'))};\nif(fs.existsSync(memory)){globalThis.fixtureAllocation=Buffer.alloc(Number(fs.readFileSync(memory,'utf8')),1);setInterval(()=>{},1000);}\nif(fs.existsSync(${JSON.stringify(join(base, 'wait'))}))setInterval(()=>{},1000);\n`);
|
|
252
|
+
writeFileSync(join(bin, 'npm'), `#!${process.execPath}\nconst fs=require('fs'),cp=require('child_process'),path=require('path');\nconst args=process.argv.slice(2);\nif(args[0]!=='install'||!['--omit=dev','--ignore-scripts','--no-audit','--no-fund'].every(x=>args.includes(x)))process.exit(9);\nfs.appendFileSync(${JSON.stringify(counter)},'x');\nfs.writeFileSync(${JSON.stringify(marker)},String(process.pid));\nconst prefix=args[args.indexOf('--prefix')+1],archive=args.at(-1);\nfs.writeFileSync(${JSON.stringify(join(base, 'installer-settings'))},JSON.stringify({args,cwd:process.cwd(),TMPDIR:process.env.TMPDIR,TMP:process.env.TMP,TEMP:process.env.TEMP}));\nfs.writeFileSync(${JSON.stringify(join(base, 'installer-archive'))},archive);\nconst original=${JSON.stringify(archivePath)},replacement=${JSON.stringify(join(base, 'replacement.tgz'))};\nconst saved=fs.existsSync(replacement)?fs.readFileSync(original):undefined;\nif(saved)fs.copyFileSync(replacement,original);\nconst target=path.join(prefix,'node_modules/@aviaratech/ai-delivery');fs.mkdirSync(target,{recursive:true});\ntry{cp.execFileSync('tar',['-xzf',archive,'--strip-components=1','-C',target]);}finally{if(saved)fs.writeFileSync(original,saved);}\nconst dependency={'@aviaratech/ai-delivery':'file:reviewed-archive.tgz'};fs.writeFileSync(path.join(prefix,'package.json'),JSON.stringify({dependencies:dependency}));\nif(!args.includes('--package-lock=false')){const targetPackage=JSON.parse(fs.readFileSync(path.join(target,'package.json'),'utf8')),integrity='sha512-'+require('node:crypto').createHash('sha512').update(fs.readFileSync(archive)).digest('base64');fs.writeFileSync(path.join(prefix,'package-lock.json'),JSON.stringify({lockfileVersion:3,packages:{'':{dependencies:dependency},'node_modules/@aviaratech/ai-delivery':{version:targetPackage.version,resolved:'file:reviewed-archive.tgz',integrity}}}));}\nfs.mkdirSync(path.join(prefix,'node_modules/.bin'),{recursive:true});\nfs.symlinkSync('../@aviaratech/ai-delivery/dist/cli.js',path.join(prefix,'node_modules/.bin/ai-delivery'));\nconst logs=${JSON.stringify(join(base, 'log-bytes'))};\nif(fs.existsSync(logs))process.stdout.write(Buffer.alloc(Number(fs.readFileSync(logs,'utf8')),65),()=>{if(fs.existsSync(${JSON.stringify(join(base, 'fail'))}))process.exit(7);});\nelse if(fs.existsSync(${JSON.stringify(join(base, 'fail'))}))process.exit(7);\nconst memory=${JSON.stringify(join(base, 'memory-bytes'))};\nif(fs.existsSync(memory)){globalThis.fixtureAllocation=Buffer.alloc(Number(fs.readFileSync(memory,'utf8')),1);setInterval(()=>{},1000);}\nif(fs.existsSync(${JSON.stringify(join(base, 'wait'))}))setInterval(()=>{if(fs.existsSync(${JSON.stringify(join(base, 'wait-noise'))})){fs.appendFileSync(${JSON.stringify(join(base, 'noise-writes'))},'x');process.stdout.write('pending installer heartbeat\\n');}},1000);\n`);
|
|
251
253
|
chmodSync(join(bin, 'npm'), 0o755);
|
|
252
254
|
const previousPath = process.env.PATH;
|
|
253
255
|
process.env.PATH = `${bin}:${previousPath ?? ''}`;
|
|
@@ -269,9 +271,10 @@ async function fixture(native = false, parent = tmpdir()) {
|
|
|
269
271
|
input,
|
|
270
272
|
counter,
|
|
271
273
|
marker,
|
|
272
|
-
cleanup: () => {
|
|
274
|
+
cleanup: (retainFiles = false) => {
|
|
273
275
|
process.env.PATH = previousPath;
|
|
274
|
-
|
|
276
|
+
if (!retainFiles)
|
|
277
|
+
rmSync(base, { recursive: true, force: true });
|
|
275
278
|
},
|
|
276
279
|
};
|
|
277
280
|
}
|
|
@@ -403,9 +406,25 @@ test('runtime-stage unavailable initial controller observation refuses preflight
|
|
|
403
406
|
minFreeDiskBytes: 1,
|
|
404
407
|
maxNewOutputBytes: 128 * 1024 ** 2,
|
|
405
408
|
},
|
|
406
|
-
}), {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
+
}), (error) => {
|
|
410
|
+
assert.ok(error instanceof Error);
|
|
411
|
+
assert.equal(error.name, 'DeliveryError');
|
|
412
|
+
const prefix = 'Owned process resource observation failed. ';
|
|
413
|
+
assert.ok(error.message.startsWith(prefix));
|
|
414
|
+
const metadata = JSON.parse(error.message.slice(prefix.length));
|
|
415
|
+
assert.ok(typeof metadata.elapsedMs === 'number' && Number.isSafeInteger(metadata.elapsedMs));
|
|
416
|
+
assert.ok(metadata.elapsedMs >= 0);
|
|
417
|
+
assert.deepEqual(metadata, {
|
|
418
|
+
status: null,
|
|
419
|
+
errorCode: 'ETIMEDOUT',
|
|
420
|
+
signal: 'SIGTERM',
|
|
421
|
+
stdoutPresent: true,
|
|
422
|
+
stdoutTerminated: false,
|
|
423
|
+
elapsedMs: metadata.elapsedMs,
|
|
424
|
+
stdoutBytes: 0,
|
|
425
|
+
completeLines: 0,
|
|
426
|
+
});
|
|
427
|
+
return true;
|
|
409
428
|
});
|
|
410
429
|
assert.equal(actors.authorCalls, 0, 'unavailable observation must refuse before authenticated preflight');
|
|
411
430
|
assert.equal(existsSync(f.counter), false, 'unavailable observation must not release the npm command');
|
|
@@ -1543,7 +1562,26 @@ async function assertRetirementErrorBoundaries(error, repoRoot, forbidden) {
|
|
|
1543
1562
|
invoke.mockRestore();
|
|
1544
1563
|
}
|
|
1545
1564
|
}
|
|
1546
|
-
for (const fault of [
|
|
1565
|
+
for (const fault of [
|
|
1566
|
+
'installer',
|
|
1567
|
+
'accessors',
|
|
1568
|
+
'cycle',
|
|
1569
|
+
'proxy',
|
|
1570
|
+
'observer',
|
|
1571
|
+
'observer-zero',
|
|
1572
|
+
'observer-retired',
|
|
1573
|
+
'observer-missing',
|
|
1574
|
+
'observer-negative',
|
|
1575
|
+
'observer-fractional',
|
|
1576
|
+
'observer-unsafe',
|
|
1577
|
+
'observer-nonfinite',
|
|
1578
|
+
'observer-string',
|
|
1579
|
+
'observer-array',
|
|
1580
|
+
'observer-malformed',
|
|
1581
|
+
'observer-trailing',
|
|
1582
|
+
'inherited-message',
|
|
1583
|
+
'proxy-root',
|
|
1584
|
+
]) {
|
|
1547
1585
|
test(`output retirement retains a bounded operation cause without exposing ${fault} failure data`, async () => {
|
|
1548
1586
|
const api = await producer();
|
|
1549
1587
|
const f = await fixture();
|
|
@@ -1554,6 +1592,67 @@ for (const fault of ['installer', 'accessors', 'cycle', 'proxy']) {
|
|
|
1554
1592
|
const primary = new Error('Synthetic retirement refusal', { cause: prior });
|
|
1555
1593
|
let reads = 0;
|
|
1556
1594
|
let operation = new Error(secret.repeat(2048));
|
|
1595
|
+
let expectedNumbers;
|
|
1596
|
+
if (fault.startsWith('observer') || fault === 'inherited-message' || fault === 'proxy-root') {
|
|
1597
|
+
const metadata = {
|
|
1598
|
+
errorCode: 'ETIMEDOUT',
|
|
1599
|
+
elapsedMs: 1001,
|
|
1600
|
+
stdoutBytes: 57,
|
|
1601
|
+
completeLines: 1,
|
|
1602
|
+
rawRows: secret,
|
|
1603
|
+
argv: [secret],
|
|
1604
|
+
};
|
|
1605
|
+
if (fault === 'observer-missing') {
|
|
1606
|
+
delete metadata.completeLines;
|
|
1607
|
+
Object.defineProperty(metadata, '__proto__', { value: { completeLines: 1 }, enumerable: true });
|
|
1608
|
+
}
|
|
1609
|
+
else if (fault === 'observer-negative')
|
|
1610
|
+
metadata.elapsedMs = -1;
|
|
1611
|
+
else if (fault === 'observer-fractional')
|
|
1612
|
+
metadata.stdoutBytes = 0.5;
|
|
1613
|
+
else if (fault === 'observer-unsafe')
|
|
1614
|
+
metadata.completeLines = Number.MAX_SAFE_INTEGER + 1;
|
|
1615
|
+
else if (fault === 'observer-nonfinite')
|
|
1616
|
+
metadata.elapsedMs = Infinity;
|
|
1617
|
+
else if (fault === 'observer-string')
|
|
1618
|
+
metadata.stdoutBytes = '57';
|
|
1619
|
+
else if (fault === 'observer-zero') {
|
|
1620
|
+
metadata.elapsedMs = 0;
|
|
1621
|
+
metadata.stdoutBytes = 0;
|
|
1622
|
+
metadata.completeLines = 0;
|
|
1623
|
+
}
|
|
1624
|
+
let payload = JSON.stringify(fault === 'observer-array' ? [metadata] : metadata);
|
|
1625
|
+
if (fault === 'observer-malformed')
|
|
1626
|
+
payload = `{"errorCode":"ETIMEDOUT","rawRows":"${secret}"`;
|
|
1627
|
+
else if (fault === 'observer-trailing')
|
|
1628
|
+
payload += secret;
|
|
1629
|
+
else if (fault === 'observer-retired')
|
|
1630
|
+
payload += ' Output-gate retirement: wrappedOperation=failed.';
|
|
1631
|
+
const message = 'Owned process resource observation failed. ' + payload;
|
|
1632
|
+
operation = new Error(message);
|
|
1633
|
+
if (fault === 'observer' || fault === 'observer-retired')
|
|
1634
|
+
expectedNumbers = 'elapsedMs=1001; stdoutBytes=57; completeLines=1';
|
|
1635
|
+
else if (fault === 'observer-zero')
|
|
1636
|
+
expectedNumbers = 'elapsedMs=0; stdoutBytes=0; completeLines=0';
|
|
1637
|
+
if (fault === 'inherited-message') {
|
|
1638
|
+
Reflect.deleteProperty(operation, 'message');
|
|
1639
|
+
Object.setPrototypeOf(operation, Object.create(Error.prototype, {
|
|
1640
|
+
message: {
|
|
1641
|
+
get: () => {
|
|
1642
|
+
reads++;
|
|
1643
|
+
throw new Error(message);
|
|
1644
|
+
},
|
|
1645
|
+
},
|
|
1646
|
+
}));
|
|
1647
|
+
}
|
|
1648
|
+
else if (fault === 'proxy-root') {
|
|
1649
|
+
const trap = () => {
|
|
1650
|
+
reads++;
|
|
1651
|
+
throw new Error(secret);
|
|
1652
|
+
};
|
|
1653
|
+
operation = new Proxy(operation, { get: trap, ownKeys: trap, getOwnPropertyDescriptor: trap });
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1557
1656
|
if (fault === 'accessors') {
|
|
1558
1657
|
operation = Object.defineProperties(new Error(), {
|
|
1559
1658
|
message: {
|
|
@@ -1624,6 +1723,12 @@ for (const fault of ['installer', 'accessors', 'cycle', 'proxy']) {
|
|
|
1624
1723
|
assert.match(cause.message, /^Wrapped operation failed/u);
|
|
1625
1724
|
if (fault === 'installer')
|
|
1626
1725
|
assert.match(cause.message, /exit=7/u);
|
|
1726
|
+
if (fault.startsWith('observer'))
|
|
1727
|
+
assert.match(cause.message, /observation=ETIMEDOUT/u);
|
|
1728
|
+
if (expectedNumbers === undefined)
|
|
1729
|
+
assert.doesNotMatch(cause.message, /elapsedMs=|stdoutBytes=|completeLines=/u);
|
|
1730
|
+
else
|
|
1731
|
+
assert.ok(cause.message.includes(expectedNumbers));
|
|
1627
1732
|
assert.ok(cause.message.length < 1024);
|
|
1628
1733
|
assert.equal(cause.message.includes(secret), false);
|
|
1629
1734
|
assert.equal(Object.getOwnPropertyDescriptor(cause, 'cause')?.value, prior, 'existing retirement cause is retained');
|
|
@@ -1644,6 +1749,75 @@ for (const fault of ['installer', 'accessors', 'cycle', 'proxy']) {
|
|
|
1644
1749
|
}
|
|
1645
1750
|
});
|
|
1646
1751
|
}
|
|
1752
|
+
for (const shape of ['nonextensible', 'readonly', 'accessor', 'mutable-nonextensible']) {
|
|
1753
|
+
test(`output retirement preserves primary cause descriptors for ${shape} errors`, async () => {
|
|
1754
|
+
const api = await producer();
|
|
1755
|
+
const f = await fixture();
|
|
1756
|
+
const secret = 'fictional_descriptor_credential';
|
|
1757
|
+
const prior = new Error(secret);
|
|
1758
|
+
const primary = new Error('Synthetic retirement refusal');
|
|
1759
|
+
let reads = 0;
|
|
1760
|
+
if (shape === 'readonly')
|
|
1761
|
+
Object.defineProperty(primary, 'cause', { value: prior, configurable: false, writable: false, enumerable: true });
|
|
1762
|
+
else if (shape === 'accessor')
|
|
1763
|
+
Object.defineProperty(primary, 'cause', {
|
|
1764
|
+
configurable: true,
|
|
1765
|
+
get: () => {
|
|
1766
|
+
reads++;
|
|
1767
|
+
throw new Error(secret);
|
|
1768
|
+
},
|
|
1769
|
+
});
|
|
1770
|
+
else if (shape === 'mutable-nonextensible')
|
|
1771
|
+
Object.defineProperty(primary, 'cause', { value: prior, configurable: false, writable: true, enumerable: true });
|
|
1772
|
+
if (shape === 'nonextensible' || shape === 'mutable-nonextensible')
|
|
1773
|
+
Object.preventExtensions(primary);
|
|
1774
|
+
const before = Object.getOwnPropertyDescriptor(primary, 'cause');
|
|
1775
|
+
const operation = new Error('Owned process resource observation failed. {"errorCode":"ETIMEDOUT","elapsedMs":1001,"stdoutBytes":57,"completeLines":1}');
|
|
1776
|
+
const write = atomicJson.writePrivateJsonFileAtomically;
|
|
1777
|
+
const injected = vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
|
|
1778
|
+
if (path === join(f.input.runtimeDirectory, 'runtime-stage.json'))
|
|
1779
|
+
throw operation;
|
|
1780
|
+
write(path, value);
|
|
1781
|
+
});
|
|
1782
|
+
try {
|
|
1783
|
+
retirementFailure.directory = join(f.root, '.git/ai-delivery/output-observation');
|
|
1784
|
+
retirementFailure.error = primary;
|
|
1785
|
+
retirementFailure.hits = 0;
|
|
1786
|
+
let received;
|
|
1787
|
+
try {
|
|
1788
|
+
await api.stageRuntime(f.input);
|
|
1789
|
+
}
|
|
1790
|
+
catch (error) {
|
|
1791
|
+
received = error;
|
|
1792
|
+
}
|
|
1793
|
+
assert.equal(received, primary);
|
|
1794
|
+
assert.equal(primary.message, 'Synthetic retirement refusal');
|
|
1795
|
+
assert.equal(retirementFailure.hits, 1);
|
|
1796
|
+
const after = Object.getOwnPropertyDescriptor(primary, 'cause');
|
|
1797
|
+
if (shape === 'mutable-nonextensible') {
|
|
1798
|
+
assert.ok(after?.value instanceof Error);
|
|
1799
|
+
assert.notEqual(after.value, prior);
|
|
1800
|
+
assert.match(after.value.message, /elapsedMs=1001; stdoutBytes=57; completeLines=1/u);
|
|
1801
|
+
assert.equal(Object.getOwnPropertyDescriptor(after.value, 'cause')?.value, prior);
|
|
1802
|
+
assert.deepEqual({ ...after, value: undefined }, { ...before, value: undefined });
|
|
1803
|
+
}
|
|
1804
|
+
else
|
|
1805
|
+
assert.deepEqual(after, before);
|
|
1806
|
+
assert.equal(Object.isExtensible(primary), shape === 'readonly' || shape === 'accessor');
|
|
1807
|
+
assert.equal(reads, 0);
|
|
1808
|
+
await assertRetirementErrorBoundaries(primary, f.root, [secret]);
|
|
1809
|
+
assert.equal(reads, 0);
|
|
1810
|
+
assert.equal(existsSync(f.input.runtimeDirectory), false);
|
|
1811
|
+
assert.equal(existsSync(f.counter), false);
|
|
1812
|
+
}
|
|
1813
|
+
finally {
|
|
1814
|
+
retirementFailure.directory = '';
|
|
1815
|
+
retirementFailure.error = undefined;
|
|
1816
|
+
injected.mockRestore();
|
|
1817
|
+
f.cleanup();
|
|
1818
|
+
}
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1647
1821
|
test('output retirement preserves an operation failure when native retirement succeeds', async () => {
|
|
1648
1822
|
const api = await producer();
|
|
1649
1823
|
const f = await fixture();
|
|
@@ -2115,6 +2289,31 @@ async function prepareOwnedCliStage() {
|
|
|
2115
2289
|
process.env.PATH = previousPath;
|
|
2116
2290
|
}
|
|
2117
2291
|
}
|
|
2292
|
+
const cliBindingSchema = z.strictObject({
|
|
2293
|
+
ownerRoot: z.string(),
|
|
2294
|
+
scenario: z.string(),
|
|
2295
|
+
repoRoot: z.string(),
|
|
2296
|
+
sourceCommit: z.string().regex(/^[a-f0-9]{40}$/u),
|
|
2297
|
+
configDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/u),
|
|
2298
|
+
userConfigDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/u),
|
|
2299
|
+
archivePath: z.string(),
|
|
2300
|
+
archiveSha256: z.string().regex(/^sha256:[a-f0-9]{64}$/u),
|
|
2301
|
+
runtimeDirectory: z.string(),
|
|
2302
|
+
});
|
|
2303
|
+
const cliUnitSchema = z.strictObject({
|
|
2304
|
+
command: z.enum(['runtime:stage', 'runtime:admit']),
|
|
2305
|
+
kind: z.enum(['context', 'preflight', 'installer', 'authority']),
|
|
2306
|
+
call: z.number().int().min(1).max(3),
|
|
2307
|
+
binding: z.string().regex(/^sha256:[a-f0-9]{64}$/u),
|
|
2308
|
+
result: z
|
|
2309
|
+
.string()
|
|
2310
|
+
.regex(/^sha256:[a-f0-9]{64}$/u)
|
|
2311
|
+
.optional(),
|
|
2312
|
+
});
|
|
2313
|
+
function cliUnitResult(unit) {
|
|
2314
|
+
const { result: _result, ...operation } = unit;
|
|
2315
|
+
return digestValue({ ...operation, result: 'validated-success' });
|
|
2316
|
+
}
|
|
2118
2317
|
// Re-enter this same case so cancellation can contain synchronous CLI work as well as promises.
|
|
2119
2318
|
// The existing producer supervisor owns the native process; these callbacks only retain its observations.
|
|
2120
2319
|
async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
@@ -2128,6 +2327,10 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2128
2327
|
let lastPhase = [];
|
|
2129
2328
|
let deadline = 0;
|
|
2130
2329
|
const active = new Map();
|
|
2330
|
+
const pendingUnits = new Map();
|
|
2331
|
+
const startedUnits = new Set();
|
|
2332
|
+
const completedUnits = [];
|
|
2333
|
+
let fixtureBinding;
|
|
2131
2334
|
let seen = 0;
|
|
2132
2335
|
let cancelledPhase;
|
|
2133
2336
|
let failure;
|
|
@@ -2154,7 +2357,10 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2154
2357
|
assert.ok(Array.isArray(value) && value.length <= 64, 'CLI phase count exceeded its bound');
|
|
2155
2358
|
let previous = -1;
|
|
2156
2359
|
for (const item of value) {
|
|
2157
|
-
assert.ok(item !== null &&
|
|
2360
|
+
assert.ok(item !== null &&
|
|
2361
|
+
typeof item === 'object' &&
|
|
2362
|
+
Object.keys(item).length === ('unit' in item ? 4 : 3) &&
|
|
2363
|
+
Object.keys(item).every((key) => ['phase', 'event', 'atMs', 'unit'].includes(key)), 'CLI phase entry is invalid');
|
|
2158
2364
|
const entry = item;
|
|
2159
2365
|
assert.ok(typeof entry.phase === 'string' &&
|
|
2160
2366
|
entry.phase.length <= 64 &&
|
|
@@ -2164,12 +2370,17 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2164
2370
|
entry.atMs >= 0 &&
|
|
2165
2371
|
entry.atMs >= previous, 'CLI phase entry is invalid');
|
|
2166
2372
|
previous = entry.atMs;
|
|
2373
|
+
if (entry.unit !== undefined)
|
|
2374
|
+
cliUnitSchema.parse(entry.unit);
|
|
2167
2375
|
}
|
|
2168
2376
|
const phases = value;
|
|
2169
2377
|
assert.ok(phases.length >= lastPhase.length &&
|
|
2170
2378
|
lastPhase.every((entry, index) => {
|
|
2171
2379
|
const current = phases[index];
|
|
2172
|
-
return current.phase === entry.phase &&
|
|
2380
|
+
return (current.phase === entry.phase &&
|
|
2381
|
+
current.event === entry.event &&
|
|
2382
|
+
current.atMs === entry.atMs &&
|
|
2383
|
+
JSON.stringify(current.unit) === JSON.stringify(entry.unit));
|
|
2173
2384
|
}), 'CLI phase history changed after observation');
|
|
2174
2385
|
return phases;
|
|
2175
2386
|
};
|
|
@@ -2185,22 +2396,82 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2185
2396
|
}
|
|
2186
2397
|
};
|
|
2187
2398
|
let watch;
|
|
2188
|
-
const
|
|
2399
|
+
const readBinding = () => {
|
|
2400
|
+
const binding = cliBindingSchema.parse(JSON.parse(privateFiles.assertPrivateFile(join(root, 'producer-binding.json'), { maxBytes: 8 * 1024 }).toString('utf8')));
|
|
2401
|
+
assert.equal(binding.ownerRoot, root);
|
|
2402
|
+
assert.equal(binding.scenario, scenario);
|
|
2403
|
+
assert.equal(realpathSync(binding.repoRoot), binding.repoRoot);
|
|
2404
|
+
assert.equal(dirname(dirname(binding.repoRoot)), root);
|
|
2405
|
+
assert.equal(binding.runtimeDirectory, join(dirname(binding.repoRoot), 'staged'));
|
|
2406
|
+
assert.equal(binding.archivePath, join(dirname(binding.repoRoot), 'reviewed archive; inert.tgz'));
|
|
2407
|
+
assert.equal(digestBytes(privateFiles.assertPrivateFile(join(dirname(binding.repoRoot), 'user.json'))), binding.userConfigDigest);
|
|
2408
|
+
if (fixtureBinding === undefined) {
|
|
2409
|
+
assert.equal(git(binding.repoRoot, 'rev-parse', 'HEAD'), binding.sourceCommit);
|
|
2410
|
+
assert.equal(digestBytes(readFileSync(binding.archivePath)), binding.archiveSha256);
|
|
2411
|
+
fixtureBinding = binding;
|
|
2412
|
+
}
|
|
2413
|
+
else
|
|
2414
|
+
assert.deepEqual(binding, fixtureBinding, 'CLI producer binding changed');
|
|
2415
|
+
return binding;
|
|
2416
|
+
};
|
|
2417
|
+
const watchPhases = (injectFault = true) => {
|
|
2189
2418
|
try {
|
|
2190
2419
|
if (existsSync(tracePath)) {
|
|
2191
2420
|
const phases = readPhases();
|
|
2192
2421
|
unreadableSince = undefined;
|
|
2193
|
-
lastPhase = phases;
|
|
2194
2422
|
for (const entry of phases.slice(seen)) {
|
|
2423
|
+
if (entry.unit !== undefined) {
|
|
2424
|
+
const unit = cliUnitSchema.parse(entry.unit);
|
|
2425
|
+
assert.equal(entry.phase, `unit:${unit.command}:${unit.kind}:${unit.call}`);
|
|
2426
|
+
assert.equal(unit.binding, digestValue(readBinding()));
|
|
2427
|
+
assert.ok(active.has(unit.command), 'Completion record is outside its actual CLI invocation');
|
|
2428
|
+
assert.ok(unit.kind !== 'installer' || (unit.command === 'runtime:stage' && unit.call === 1));
|
|
2429
|
+
assert.ok(unit.kind !== 'authority' || unit.command === 'runtime:admit');
|
|
2430
|
+
if (entry.event === 'start') {
|
|
2431
|
+
assert.equal(unit.result, undefined);
|
|
2432
|
+
assert.ok(!startedUnits.has(entry.phase), 'Duplicate CLI unit start');
|
|
2433
|
+
assert.equal(unit.call, 1 + [...startedUnits].filter((name) => name.startsWith(`unit:${unit.command}:${unit.kind}:`)).length);
|
|
2434
|
+
if (unit.kind === 'preflight')
|
|
2435
|
+
assert.ok(completedUnits.includes(`unit:${unit.command}:context:${unit.call}`), 'Preflight preceded its validated context');
|
|
2436
|
+
if (unit.kind === 'context' && unit.call > 1)
|
|
2437
|
+
assert.ok(completedUnits.includes(`unit:${unit.command}:preflight:${unit.call - 1}`), 'Context recheck preceded its prior preflight');
|
|
2438
|
+
if (unit.kind === 'installer')
|
|
2439
|
+
assert.ok(completedUnits.includes('unit:runtime:stage:preflight:1'), 'Installer preceded real preflight');
|
|
2440
|
+
if (unit.kind === 'authority')
|
|
2441
|
+
assert.ok(pendingUnits.has(`unit:runtime:admit:preflight:${unit.call}`), 'Authority check is outside its real preflight');
|
|
2442
|
+
startedUnits.add(entry.phase);
|
|
2443
|
+
pendingUnits.set(entry.phase, unit);
|
|
2444
|
+
}
|
|
2445
|
+
else {
|
|
2446
|
+
assert.equal(entry.event, 'end', 'Only successful delegated units may report completion');
|
|
2447
|
+
const started = pendingUnits.get(entry.phase);
|
|
2448
|
+
assert.ok(started, 'Unmatched or duplicate CLI unit completion');
|
|
2449
|
+
assert.deepEqual({ ...unit, result: undefined }, { ...started, result: undefined });
|
|
2450
|
+
assert.equal(unit.result, cliUnitResult(started), 'CLI unit result binding is invalid');
|
|
2451
|
+
if (unit.command === 'runtime:admit' && unit.kind === 'preflight')
|
|
2452
|
+
assert.ok(completedUnits.includes(`unit:runtime:admit:authority:${unit.call}`), 'Admission preflight lacks successful authority readback');
|
|
2453
|
+
pendingUnits.delete(entry.phase);
|
|
2454
|
+
completedUnits.push(entry.phase);
|
|
2455
|
+
// This measures inactivity between verified substantive units, never total command duration.
|
|
2456
|
+
active.set(unit.command, performance.now() + (scenario === 'unfinished' && unit.command === 'runtime:stage' ? 30_000 : 15_000));
|
|
2457
|
+
}
|
|
2458
|
+
continue;
|
|
2459
|
+
}
|
|
2460
|
+
if (entry.phase.startsWith('unit:')) {
|
|
2461
|
+
assert.equal(entry.event, 'settled', 'CLI unit completion lacks a validated result');
|
|
2462
|
+
assert.ok(pendingUnits.delete(entry.phase), 'Unmatched rejected CLI unit');
|
|
2463
|
+
continue; // A rejected operation is settled, but cannot refresh the stall clock.
|
|
2464
|
+
}
|
|
2195
2465
|
if (entry.event === 'start')
|
|
2196
2466
|
active.set(entry.phase, performance.now() + (scenario === 'unfinished' && entry.phase === 'runtime:stage' ? 30_000 : 15_000));
|
|
2197
2467
|
else if (entry.event === 'end' || entry.event === 'settled')
|
|
2198
2468
|
active.delete(entry.phase);
|
|
2199
2469
|
}
|
|
2470
|
+
lastPhase = phases;
|
|
2200
2471
|
if (phases.length > seen)
|
|
2201
2472
|
deadline = performance.now() + 15_000;
|
|
2202
2473
|
seen = phases.length;
|
|
2203
|
-
if (traceFault !== undefined && traceFault !== 'write' && !traceFaultInjected) {
|
|
2474
|
+
if (injectFault && !idle && traceFault !== undefined && traceFault !== 'write' && !traceFaultInjected) {
|
|
2204
2475
|
const fixtureRoot = readdirSync(root).find((name) => name.startsWith('ai-delivery-setup-'));
|
|
2205
2476
|
const marker = fixtureRoot === undefined ? undefined : join(root, fixtureRoot, 'installer-running');
|
|
2206
2477
|
if (marker !== undefined && existsSync(marker)) {
|
|
@@ -2212,6 +2483,27 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2212
2483
|
writeFileSync(tracePath, Buffer.alloc(64 * 1024 + 1, 32));
|
|
2213
2484
|
sharedOutputRead.path = tracePath;
|
|
2214
2485
|
}
|
|
2486
|
+
else if (traceFault.startsWith('completion-')) {
|
|
2487
|
+
const source = phases.find((entry) => traceFault === 'completion-malformed'
|
|
2488
|
+
? entry.unit?.kind === 'installer' && entry.event === 'start' && pendingUnits.has(entry.phase)
|
|
2489
|
+
: entry.unit !== undefined && entry.event === 'end');
|
|
2490
|
+
assert.ok(source?.unit, 'A completion fault needs its matching real delegated unit first');
|
|
2491
|
+
const injected = {
|
|
2492
|
+
...source,
|
|
2493
|
+
event: 'end',
|
|
2494
|
+
atMs: phases.at(-1).atMs + 0.001,
|
|
2495
|
+
unit: { ...source.unit },
|
|
2496
|
+
};
|
|
2497
|
+
if (traceFault === 'completion-unmatched') {
|
|
2498
|
+
injected.unit.call++;
|
|
2499
|
+
injected.phase = `unit:${injected.unit.command}:${injected.unit.kind}:${injected.unit.call}`;
|
|
2500
|
+
}
|
|
2501
|
+
else if (traceFault === 'completion-rejected')
|
|
2502
|
+
injected.event = 'settled';
|
|
2503
|
+
else if (traceFault === 'completion-malformed')
|
|
2504
|
+
injected.unit.result = 'sha256:' + '0'.repeat(64);
|
|
2505
|
+
writeFileSync(tracePath, JSON.stringify([...phases, injected]));
|
|
2506
|
+
}
|
|
2215
2507
|
else
|
|
2216
2508
|
writeFileSync(tracePath, JSON.stringify(Array.from({ length: 65 }, () => phases[0])));
|
|
2217
2509
|
}
|
|
@@ -2358,7 +2650,7 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2358
2650
|
receiptFailure ??= 'CLI preparation failed before completed handoff';
|
|
2359
2651
|
else {
|
|
2360
2652
|
try {
|
|
2361
|
-
|
|
2653
|
+
watchPhases(false);
|
|
2362
2654
|
}
|
|
2363
2655
|
catch (error) {
|
|
2364
2656
|
receiptFailure ??= error instanceof Error ? error.message : String(error);
|
|
@@ -2374,6 +2666,7 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2374
2666
|
residualInstaller = {
|
|
2375
2667
|
pid: Number(readFileSync(marker, 'utf8')),
|
|
2376
2668
|
counter: readFileSync(join(base, 'installs'), 'utf8'),
|
|
2669
|
+
noiseWrites: existsSync(join(base, 'noise-writes')) ? lstatSync(join(base, 'noise-writes')).size : 0,
|
|
2377
2670
|
};
|
|
2378
2671
|
}
|
|
2379
2672
|
}
|
|
@@ -2398,6 +2691,7 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2398
2691
|
residualInstaller,
|
|
2399
2692
|
preparationElapsedMs,
|
|
2400
2693
|
preparationCompleted,
|
|
2694
|
+
completedUnits,
|
|
2401
2695
|
}) +
|
|
2402
2696
|
'\n');
|
|
2403
2697
|
}
|
|
@@ -2412,6 +2706,33 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2412
2706
|
traceFaultInjected,
|
|
2413
2707
|
restoredGlobalsWithPending: failedBytes?.includes(Buffer.from('SETUP_CLI_ENV_RESTORED_WITH_PENDING')) ?? false,
|
|
2414
2708
|
});
|
|
2709
|
+
if (fixtureBinding !== undefined) {
|
|
2710
|
+
const savedConfig = process.env.AI_DELIVERY_CONFIG;
|
|
2711
|
+
try {
|
|
2712
|
+
process.env.AI_DELIVERY_CONFIG = join(dirname(fixtureBinding.repoRoot), 'user.json');
|
|
2713
|
+
assert.equal((await loadDeliveryConfig(fixtureBinding.repoRoot)).configDigest, fixtureBinding.configDigest);
|
|
2714
|
+
}
|
|
2715
|
+
finally {
|
|
2716
|
+
if (savedConfig === undefined)
|
|
2717
|
+
delete process.env.AI_DELIVERY_CONFIG;
|
|
2718
|
+
else
|
|
2719
|
+
process.env.AI_DELIVERY_CONFIG = savedConfig;
|
|
2720
|
+
}
|
|
2721
|
+
if (failure === undefined) {
|
|
2722
|
+
assert.equal(pendingUnits.size, 0, 'A successful CLI retained an unfinished semantic unit');
|
|
2723
|
+
const stage = JSON.parse(privateFiles.assertPrivateFile(join(fixtureBinding.runtimeDirectory, 'runtime-stage.json')).toString('utf8'));
|
|
2724
|
+
const { recordId, ...content } = stage;
|
|
2725
|
+
assert.equal(recordId, digestValue(content));
|
|
2726
|
+
assert.equal(stage.status, 'complete');
|
|
2727
|
+
assert.equal(stage.intent.sourceCommit, fixtureBinding.sourceCommit);
|
|
2728
|
+
assert.equal(stage.intent.configDigest, fixtureBinding.configDigest);
|
|
2729
|
+
assert.equal(stage.intent.archiveSha256, fixtureBinding.archiveSha256);
|
|
2730
|
+
assert.deepEqual(JSON.parse(privateFiles
|
|
2731
|
+
.assertPrivateFile(join(fixtureBinding.repoRoot, '.git/ai-delivery/runtime-admission.json'))
|
|
2732
|
+
.toString('utf8')), stage.admission);
|
|
2733
|
+
assert.ok(completedUnits.includes('unit:runtime:stage:installer:1') || prepared !== undefined);
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2415
2736
|
if (prepared !== undefined) {
|
|
2416
2737
|
// Parent retains original validated bindings even when the child receives the mismatch fault.
|
|
2417
2738
|
for (const file of prepared.files)
|
|
@@ -2425,6 +2746,7 @@ async function observeStageAdmitCase(scenario = 'normal', traceFault) {
|
|
|
2425
2746
|
assert.equal(existsSync(root), false, 'Owned CLI case root was not removed');
|
|
2426
2747
|
return {
|
|
2427
2748
|
phases: lastPhase,
|
|
2749
|
+
completedUnits,
|
|
2428
2750
|
nativeIdle: idle,
|
|
2429
2751
|
cancelledPhase,
|
|
2430
2752
|
failure,
|
|
@@ -2447,12 +2769,12 @@ test(stageAdmitCase, async () => {
|
|
|
2447
2769
|
const phases = [];
|
|
2448
2770
|
let activeCommands = 0;
|
|
2449
2771
|
let traceFailure;
|
|
2450
|
-
const phase = (name, event) => {
|
|
2772
|
+
const phase = (name, event, unit) => {
|
|
2451
2773
|
if (traceFailure !== undefined)
|
|
2452
2774
|
return;
|
|
2453
2775
|
try {
|
|
2454
2776
|
assert.ok(phases.length < 64, 'CLI phase count exceeded its bound');
|
|
2455
|
-
phases.push({ phase: name, event, atMs: performance.now() });
|
|
2777
|
+
phases.push({ phase: name, event, atMs: performance.now(), ...(unit === undefined ? {} : { unit }) });
|
|
2456
2778
|
if (traceFault === 'write' && name === 'import:runtime:stage' && event === 'end') {
|
|
2457
2779
|
assert.ok(activeCommands > 0, 'Trace write fault requires an actually pending CLI command');
|
|
2458
2780
|
process.stderr.write('SETUP_CLI_TRACE_WRITE_FAULT_WITH_PENDING\n');
|
|
@@ -2494,16 +2816,31 @@ test(stageAdmitCase, async () => {
|
|
|
2494
2816
|
assert.equal(existsSync(join(f.root, '.git/ai-delivery/runtime-admission.json')), false);
|
|
2495
2817
|
preparedCliClosure(f.input);
|
|
2496
2818
|
}
|
|
2497
|
-
if (scenario === 'unfinished')
|
|
2819
|
+
if (scenario === 'unfinished') {
|
|
2498
2820
|
writeFileSync(join(f.base, 'wait'), '');
|
|
2821
|
+
writeFileSync(join(f.base, 'wait-noise'), '');
|
|
2822
|
+
}
|
|
2499
2823
|
if (scenario === 'installer-failure')
|
|
2500
2824
|
writeFileSync(join(f.base, 'fail'), '');
|
|
2825
|
+
chmodSync(join(f.base, 'user.json'), 0o600);
|
|
2826
|
+
const binding = {
|
|
2827
|
+
ownerRoot: dirname(tracePath),
|
|
2828
|
+
scenario,
|
|
2829
|
+
repoRoot: f.root,
|
|
2830
|
+
sourceCommit: f.input.expectedSourceCommit,
|
|
2831
|
+
configDigest: f.input.expectedConfigDigest,
|
|
2832
|
+
userConfigDigest: digestBytes(readFileSync(join(f.base, 'user.json'))),
|
|
2833
|
+
archivePath: f.input.archivePath,
|
|
2834
|
+
archiveSha256: f.input.expectedArchiveSha256,
|
|
2835
|
+
runtimeDirectory: f.input.runtimeDirectory,
|
|
2836
|
+
};
|
|
2837
|
+
atomicJson.writePrivateJsonFileAtomically(join(dirname(tracePath), 'producer-binding.json'), binding);
|
|
2501
2838
|
phase('preparation', 'end');
|
|
2502
2839
|
const argv = process.argv;
|
|
2503
2840
|
const exitCode = process.exitCode;
|
|
2504
2841
|
const stdout = vi.spyOn(process.stdout, 'write');
|
|
2505
2842
|
const pending = [];
|
|
2506
|
-
const
|
|
2843
|
+
const restoreObservations = [];
|
|
2507
2844
|
const restoreEnvs = vi.unstubAllEnvs.bind(vi);
|
|
2508
2845
|
const environmentProbe = traceFault === 'write'
|
|
2509
2846
|
? vi.spyOn(vi, 'unstubAllEnvs').mockImplementation(() => {
|
|
@@ -2526,6 +2863,78 @@ test(stageAdmitCase, async () => {
|
|
|
2526
2863
|
...args,
|
|
2527
2864
|
];
|
|
2528
2865
|
vi.resetModules();
|
|
2866
|
+
const calls = { context: 0, preflight: 0, installer: 0, authority: 0 };
|
|
2867
|
+
const observeUnit = async (kind, operation, validate) => {
|
|
2868
|
+
const unit = {
|
|
2869
|
+
command: args[0],
|
|
2870
|
+
kind,
|
|
2871
|
+
call: ++calls[kind],
|
|
2872
|
+
binding: digestValue(binding),
|
|
2873
|
+
};
|
|
2874
|
+
const name = `unit:${unit.command}:${unit.kind}:${unit.call}`;
|
|
2875
|
+
phase(name, 'start', unit);
|
|
2876
|
+
try {
|
|
2877
|
+
const value = await operation();
|
|
2878
|
+
validate(value);
|
|
2879
|
+
phase(name, 'end', { ...unit, result: cliUnitResult(unit) });
|
|
2880
|
+
return value;
|
|
2881
|
+
}
|
|
2882
|
+
catch (error) {
|
|
2883
|
+
phase(name, 'settled'); // Failure is evidence of settlement, never successful progress.
|
|
2884
|
+
throw error;
|
|
2885
|
+
}
|
|
2886
|
+
};
|
|
2887
|
+
const contextModule = await import('./issue.js');
|
|
2888
|
+
const context = contextModule.loadDeliveryContext;
|
|
2889
|
+
const contextObserver = vi.spyOn(contextModule, 'loadDeliveryContext').mockImplementation((...input) => observeUnit('context', () => context(...input), (value) => {
|
|
2890
|
+
assert.equal(input[0].repoRoot, f.root);
|
|
2891
|
+
assert.equal(input[0].identity, 'host-author');
|
|
2892
|
+
assert.equal(input[0].role, 'author');
|
|
2893
|
+
assert.equal(value.config.repository, 'example/widget');
|
|
2894
|
+
assert.equal(value.configuration?.configDigest, f.input.expectedConfigDigest);
|
|
2895
|
+
assert.equal(value.clients.role, 'author');
|
|
2896
|
+
assert.equal(value.clients.authSource, 'personal');
|
|
2897
|
+
assert.equal(value.clients.credentialSource, 'env:AUTHOR_TOKEN');
|
|
2898
|
+
}));
|
|
2899
|
+
restoreObservations.push(() => contextObserver.mockRestore());
|
|
2900
|
+
const preflightModule = await import('./pr.js');
|
|
2901
|
+
const preflight = preflightModule.preflightReviewRoute;
|
|
2902
|
+
const preflightObserver = vi.spyOn(preflightModule, 'preflightReviewRoute').mockImplementation((...input) => observeUnit('preflight', () => preflight(...input), (value) => {
|
|
2903
|
+
assert.equal(value.author.actorLogin, 'host-user');
|
|
2904
|
+
assert.equal(value.author.identity, 'host-author');
|
|
2905
|
+
assert.equal(value.author.authSource, 'personal');
|
|
2906
|
+
assert.equal(value.reviewer.actorLogin, 'reviewer[bot]');
|
|
2907
|
+
assert.equal(value.reviewer.identity, 'synthetic-reviewer');
|
|
2908
|
+
assert.equal(value.reviewer.repositoryAccess, 'readable');
|
|
2909
|
+
assert.equal(value.rules.visibility, 'unknown');
|
|
2910
|
+
assert.equal(value.rules.observedRequiredApprovals, null);
|
|
2911
|
+
assert.equal(value.approvalEligibility, 'unknown');
|
|
2912
|
+
}));
|
|
2913
|
+
restoreObservations.push(() => preflightObserver.mockRestore());
|
|
2914
|
+
const verificationModule = await import('./verification.js');
|
|
2915
|
+
const writer = verificationModule.withRuntimeSetupWriter;
|
|
2916
|
+
const observedWriter = (root, operation, scope) => writer(root, (runner) => operation({
|
|
2917
|
+
...runner,
|
|
2918
|
+
run: (...input) => observeUnit('installer', () => runner.run(...input), () => {
|
|
2919
|
+
assert.equal(root, f.root);
|
|
2920
|
+
assert.equal(input[0][0], 'npm');
|
|
2921
|
+
assert.equal(input[0][1], 'install');
|
|
2922
|
+
assert.equal(input[0][input[0].indexOf('--prefix') + 1], f.input.runtimeDirectory);
|
|
2923
|
+
assert.equal(input[0].at(-1), join(f.input.runtimeDirectory, 'reviewed-archive.tgz'));
|
|
2924
|
+
assert.equal(input[4], f.input.runtimeDirectory);
|
|
2925
|
+
runner.assertQuiescent();
|
|
2926
|
+
assert.equal(readFileSync(f.counter, 'utf8'), 'x');
|
|
2927
|
+
const installed = JSON.parse(readFileSync(join(f.input.runtimeDirectory, 'node_modules/@aviaratech/ai-delivery/package.json'), 'utf8'));
|
|
2928
|
+
assert.equal(installed.name, '@aviaratech/ai-delivery');
|
|
2929
|
+
assert.equal(installed.version, f.input.packageVersion);
|
|
2930
|
+
const lock = JSON.parse(readFileSync(join(f.input.runtimeDirectory, 'package-lock.json'), 'utf8'));
|
|
2931
|
+
assert.equal(lock.packages['node_modules/@aviaratech/ai-delivery']?.version, f.input.packageVersion);
|
|
2932
|
+
}),
|
|
2933
|
+
}), scope);
|
|
2934
|
+
const writerObserver = vi
|
|
2935
|
+
.spyOn(verificationModule, 'withRuntimeSetupWriter')
|
|
2936
|
+
.mockImplementation(observedWriter);
|
|
2937
|
+
restoreObservations.push(() => writerObserver.mockRestore());
|
|
2529
2938
|
if (args[0] === 'runtime:admit') {
|
|
2530
2939
|
const clientsModule = await import('./github/client.js');
|
|
2531
2940
|
const create = clientsModule.createDeliveryGitHubClients;
|
|
@@ -2541,11 +2950,16 @@ test(stageAdmitCase, async () => {
|
|
|
2541
2950
|
phase(name, 'start');
|
|
2542
2951
|
try {
|
|
2543
2952
|
assert.ok(scenario !== 'budget' || authorChecks === 1 || !actors.pauseAuthor, 'Budget fixture repeated its deliberate HTTP delay at another required authority check');
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2953
|
+
return await observeUnit('authority', async () => {
|
|
2954
|
+
const response = await authenticatedAuthor(...request);
|
|
2955
|
+
// This fictional HTTP port can withhold its response; the actual CLI parse remains pending.
|
|
2956
|
+
if (scenario === 'admission-stall')
|
|
2957
|
+
await new Promise(() => { });
|
|
2958
|
+
return response;
|
|
2959
|
+
}, (response) => {
|
|
2960
|
+
assert.equal(response.actorLogin, 'host-user');
|
|
2961
|
+
assert.equal(response.credentialIdentity, 'user:37');
|
|
2962
|
+
});
|
|
2549
2963
|
}
|
|
2550
2964
|
finally {
|
|
2551
2965
|
// The budget regression needs one four-second response, not one per required recheck.
|
|
@@ -2557,7 +2971,7 @@ test(stageAdmitCase, async () => {
|
|
|
2557
2971
|
}
|
|
2558
2972
|
return client;
|
|
2559
2973
|
});
|
|
2560
|
-
|
|
2974
|
+
restoreObservations.push(() => clients.mockRestore());
|
|
2561
2975
|
}
|
|
2562
2976
|
const { Command } = await import('commander');
|
|
2563
2977
|
const descriptor = Object.getOwnPropertyDescriptor(Command.prototype, 'parseAsync');
|
|
@@ -2623,6 +3037,11 @@ test(stageAdmitCase, async () => {
|
|
|
2623
3037
|
'--runtime-directory',
|
|
2624
3038
|
f.input.runtimeDirectory,
|
|
2625
3039
|
];
|
|
3040
|
+
if (scenario === 'progress') {
|
|
3041
|
+
// Two actual authority responses alone exceed the old aggregate command limit.
|
|
3042
|
+
actors.pauseAuthor = true;
|
|
3043
|
+
actors.authorDelayMs = 8_000;
|
|
3044
|
+
}
|
|
2626
3045
|
const staged = await runCli([
|
|
2627
3046
|
'runtime:stage',
|
|
2628
3047
|
'--authorize-stage',
|
|
@@ -2644,6 +3063,8 @@ test(stageAdmitCase, async () => {
|
|
|
2644
3063
|
assert.equal(digestBytes(readFileSync(file.path)), file.digest);
|
|
2645
3064
|
}
|
|
2646
3065
|
phase('assertions:stageId', 'end');
|
|
3066
|
+
if (scenario === 'progress')
|
|
3067
|
+
actors.pauseAuthor = false;
|
|
2647
3068
|
const authorCallsBeforeAdmission = actors.authorCalls;
|
|
2648
3069
|
if (scenario === 'budget')
|
|
2649
3070
|
actors.pauseAuthor = true;
|
|
@@ -2665,7 +3086,7 @@ test(stageAdmitCase, async () => {
|
|
|
2665
3086
|
finally {
|
|
2666
3087
|
phase('drain', 'start');
|
|
2667
3088
|
await Promise.allSettled(pending);
|
|
2668
|
-
for (const restore of
|
|
3089
|
+
for (const restore of restoreObservations)
|
|
2669
3090
|
restore();
|
|
2670
3091
|
environmentProbe?.mockRestore();
|
|
2671
3092
|
phase('drain', 'end');
|
|
@@ -2673,8 +3094,9 @@ test(stageAdmitCase, async () => {
|
|
|
2673
3094
|
stdout.mockRestore();
|
|
2674
3095
|
process.argv = argv;
|
|
2675
3096
|
process.exitCode = exitCode;
|
|
3097
|
+
// The existing parent owns final artifact corroboration and disposal after native quiescence.
|
|
2676
3098
|
if (ownedFixture !== undefined)
|
|
2677
|
-
ownedFixture.cleanup();
|
|
3099
|
+
ownedFixture.cleanup(true);
|
|
2678
3100
|
else
|
|
2679
3101
|
process.env.PATH = previousPath;
|
|
2680
3102
|
phase('cleanup', 'end');
|
|
@@ -2685,7 +3107,16 @@ test(stageAdmitCase, async () => {
|
|
|
2685
3107
|
// The parent supervises bootstrap, each overlapping phase, and native drain independently.
|
|
2686
3108
|
// Cancellation may terminate this isolated process; it never proves JavaScript settlement.
|
|
2687
3109
|
0);
|
|
2688
|
-
test('CLI stage/admit
|
|
3110
|
+
test('CLI stage/admit completes substantive work beyond the former aggregate command limit', async () => {
|
|
3111
|
+
const result = await observeStageAdmitCase('progress');
|
|
3112
|
+
assert.equal(result.failure, undefined, 'The actual CLI must complete while real producer units keep completing');
|
|
3113
|
+
const start = result.phases.find((entry) => entry.phase === 'runtime:stage' && entry.event === 'start');
|
|
3114
|
+
const end = result.phases.find((entry) => entry.phase === 'runtime:stage' && entry.event === 'settled');
|
|
3115
|
+
assert.ok(start && end && end.atMs - start.atMs > 15_000);
|
|
3116
|
+
assert.ok(result.nativeIdle && result.rootRemoved);
|
|
3117
|
+
assert.ok(result.phases.some((entry) => entry.phase === 'runtime:admit' && entry.event === 'settled'));
|
|
3118
|
+
});
|
|
3119
|
+
test('CLI stage/admit separates preparation from substantive command progress', async () => {
|
|
2689
3120
|
const result = await observeStageAdmitCase('budget');
|
|
2690
3121
|
const authorChecks = result.phases.filter((entry) => entry.phase.startsWith('admit:author:') && entry.event === 'start');
|
|
2691
3122
|
assert.equal(authorChecks.length, 3, 'All three admission authority checks must execute');
|
|
@@ -2694,7 +3125,7 @@ test('CLI stage/admit preparation and commands retain separate finite budgets',
|
|
|
2694
3125
|
assert.ok(result.phases.at(-1).atMs - result.phases[0].atMs > 15_000);
|
|
2695
3126
|
for (const entry of result.phases.filter((entry) => entry.event === 'start')) {
|
|
2696
3127
|
const end = result.phases.find((candidate) => candidate.phase === entry.phase && ['end', 'settled'].includes(candidate.event));
|
|
2697
|
-
assert.ok(end !== undefined
|
|
3128
|
+
assert.ok(end !== undefined, `${entry.phase} did not settle`);
|
|
2698
3129
|
}
|
|
2699
3130
|
});
|
|
2700
3131
|
test('CLI prepared handoff rejects a mismatched stage identity without reinstall or admission', async () => {
|
|
@@ -2756,6 +3187,8 @@ test('CLI stage/admit keeps an unfinished real installer owned until native quie
|
|
|
2756
3187
|
assert.ok(result.identities.some((member) => member.pid === result.residualInstaller?.pid), 'Installer birth identity was not observed by the native supervisor');
|
|
2757
3188
|
assert.equal(result.phases.some((entry) => entry.event === 'pending'), false, 'CLI caller relinquished an unfinished command');
|
|
2758
3189
|
assert.equal(result.cancelledPhase, 'runtime:stage');
|
|
3190
|
+
assert.ok((result.residualInstaller?.noiseWrites ?? 0) >= 2, 'The actually stalled installer must emit repeated noise');
|
|
3191
|
+
assert.equal(result.completedUnits.includes('unit:runtime:stage:installer:1'), false);
|
|
2759
3192
|
assert.equal(result.phases.some((entry) => entry.phase === 'cleanup'), false, 'Child cleaned a fixture with active work');
|
|
2760
3193
|
});
|
|
2761
3194
|
test('CLI stage/admit joins a failed real installer before restoring its fixture', async () => {
|
|
@@ -2777,7 +3210,16 @@ test('CLI stage/admit keeps a stalled admission response owned until native quie
|
|
|
2777
3210
|
entry.phase === 'return:runtime:admit' ||
|
|
2778
3211
|
(entry.phase === 'admit:author:1' && entry.event === 'end')), false, 'The stalled HTTP response must keep the original command pending until native cancellation');
|
|
2779
3212
|
});
|
|
2780
|
-
test.each([
|
|
3213
|
+
test.each([
|
|
3214
|
+
'missing',
|
|
3215
|
+
'oversized',
|
|
3216
|
+
'records',
|
|
3217
|
+
'write',
|
|
3218
|
+
'completion-duplicate',
|
|
3219
|
+
'completion-unmatched',
|
|
3220
|
+
'completion-rejected',
|
|
3221
|
+
'completion-malformed',
|
|
3222
|
+
])('CLI stage/admit preserves owned recovery evidence when its trace fails: %s', async (fault) => {
|
|
2781
3223
|
let failure;
|
|
2782
3224
|
sharedOutputRead.unboundedReads = 0;
|
|
2783
3225
|
try {
|
|
@@ -2789,6 +3231,8 @@ test.each(['missing', 'oversized', 'records', 'write'])('CLI stage/admit preserv
|
|
|
2789
3231
|
failure = error;
|
|
2790
3232
|
}
|
|
2791
3233
|
assert.ok(failure?.receiptFailure, 'Unavailable phase evidence was accepted');
|
|
3234
|
+
if (fault === 'completion-malformed')
|
|
3235
|
+
assert.match(failure.receiptFailure, /CLI unit result binding is invalid/u);
|
|
2792
3236
|
assert.equal(failure.nativeIdle, true);
|
|
2793
3237
|
assert.equal(failure.traceFaultInjected, true, 'The real pending CLI trace fault did not execute');
|
|
2794
3238
|
assert.equal(existsSync(failure.root), true, 'Untrusted phase evidence was discarded before recovery');
|
|
@@ -2801,9 +3245,7 @@ test.each(['missing', 'oversized', 'records', 'write'])('CLI stage/admit preserv
|
|
|
2801
3245
|
finally {
|
|
2802
3246
|
sharedOutputRead.path = '';
|
|
2803
3247
|
if (failure?.nativeIdle && failure.cleanupState !== undefined) {
|
|
2804
|
-
const recorded = JSON.parse(privateFiles
|
|
2805
|
-
.assertPrivateFile(join(failure.root, 'ownership.json'), { maxBytes: 256 * 1024 })
|
|
2806
|
-
.toString('utf8'));
|
|
3248
|
+
const recorded = JSON.parse(privateFiles.assertPrivateFile(join(failure.root, 'ownership.json'), { maxBytes: 256 * 1024 }).toString('utf8'));
|
|
2807
3249
|
assert.equal(recorded.idle, true);
|
|
2808
3250
|
assert.equal(recorded.owned.rootPid, failure.cleanupState.rootPid);
|
|
2809
3251
|
const { confirmOwnedCleanup } = await import('./verification.js');
|