// Fixed local model output tests the driver/execution path only. It is never a // real-provider sample or evidence of autonomous reasoning/engineering. import fs from 'node:fs'; import path from 'node:path'; import assert from 'node:assert/strict'; import { randomUUID } from 'node:crypto'; import { fixture, compatibleFixture, launchWorkbench, completion, call } from '../../tests/helpers.mjs'; import { configureFixture, save, connectionDefinition } from './common.mjs'; const output = path.resolve('.qa/ad-node-driver-' + randomUUID()); fs.mkdirSync(output); const disposers = [], t = { after: fn => disposers.push(fn) }, f = fixture(t, { modernDefaults: true }); f.store.saveConfig({ approvalMode: 'full', mode: 'compatible' }); f.store.close(); let result; const files = { 'src/amount.mjs': `export function amountToCents(input) { if (!['string','number'].includes(typeof input) || typeof input === 'number' && !Number.isFinite(input)) throw new TypeError('amount'); const match = String(input).trim().match(/^([+-]?)([0-9]+)(?:\\.([0-9]{1,2}))?$/); if (!match) throw new TypeError('amount'); const n = (BigInt(match[2]) * 100n + BigInt((match[3] || '').padEnd(2,'0'))) * (match[1] === '-' ? -1n : 1n); if (n > BigInt(Number.MAX_SAFE_INTEGER) || n < BigInt(Number.MIN_SAFE_INTEGER)) throw new TypeError('unsafe'); return n === 0n ? 0 : Number(n); }\n`, 'src/summary.mjs': `import {amountToCents} from './amount.mjs'; export function summarize(rows) { if (!Array.isArray(rows)) throw new TypeError('rows'); const map = new Map(); for (const row of rows) { if (!row || typeof row.currency !== 'string') throw new TypeError('row'); const currency = row.currency.trim().toUpperCase(); if (!/^[A-Z]{3}$/.test(currency)) throw new TypeError('currency'); const item = map.get(currency) || {currency,cents:0,count:0}; const cents = item.cents + amountToCents(row.amount); if (!Number.isSafeInteger(cents)) throw new TypeError('unsafe'); map.set(currency,{currency,cents,count:item.count+1}); } return [...map.values()].sort((a,b)=>a.currency.localeCompare(b.currency)); }\n`, 'src/report.mjs': `export function formatReport(rows) {return rows.map(({currency,cents,count})=>currency+' '+(cents<0?'-':'')+Math.floor(Math.abs(cents)/100)+'.'+String(Math.abs(cents)%100).padStart(2,'0')+' ('+count+')').join('\\n');}\n`, }; try { let requests = 0; const model = await compatibleFixture(t, (_url, body) => { assert.ok(['max_tokens','max_output_tokens','max_completion_tokens'].every(key => !Object.hasOwn(body,key))); let response; if (++requests === 1) response = completion(Object.entries(files).map(([name, content], index) => call('owned-file-' + index, 'propose_file', { path: name, content, reason: 'Fixed local driver fixture only.' }))); else if (requests === 2) { const node = process.execPath.replaceAll("'", "''"); const command = `& '${node}' --test test/expense.test.mjs\nif ($LASTEXITCODE -ne 0) { throw 'fixture tests failed' }\n& '${node}' scripts/build.mjs\nif ($LASTEXITCODE -ne 0) { throw 'fixture build failed' }\ngit add -- src/amount.mjs src/summary.mjs src/report.mjs\ngit -c core.hooksPath=NUL commit --only --no-gpg-sign -m 'Fixed local driver fixture' -- src/amount.mjs src/summary.mjs src/report.mjs\nif ($LASTEXITCODE -ne 0) { throw 'fixture commit failed' }`; response = completion([call('owned-terminal', 'run_command', { command, reason: 'Verify actual command checks and Git driver acceptance, no supervisor approvals.' })]); } else response = completion([], 'Fixed local fixture finished.'); return { ...response, model: body.model }; }); const host = await launchWorkbench(t, f.data), originalCenter = await host.api('/model-center'); const connection = await host.api('/model-center/connections', { name: 'Owned driver fixture', brand: 'Owned fixture', concurrency: 3, model: 'owned-node', protocol: 'chat-completions', baseUrl: model.baseUrl, apiKey: 'owned-node-driver-secret', streaming: false }); const boot = await host.api('/bootstrap'), center = await host.api('/model-center'), health = await host.api('/host/status'); configureFixture({ root: output, origin: host.url }); save('current.json', { host: health, config: boot.config, center, connections: [connection], engineeringPriority: [connection.id], fixture: true }); save('compatibility/result.json', { results: [{ connectionId: connection.id, engineeringAllowed: true }], fixture: true }); await import('./node.mjs'); const node = JSON.parse(fs.readFileSync(path.join(output, 'node/result.json'), 'utf8')); assert.equal(node.success, true, JSON.stringify(node)); assert.equal(node.requests, 3); assert.equal(node.final.test.stats.pass, 9); assert.equal(node.identitiesPassed, true); assert.equal(node.allOriginalOwnerBytesAndIndexPreserved, true); const after = await host.api('/model-center'), restored = after.connections.find(value => value.id === connection.id); assert.deepEqual(after.selected, originalCenter.selected); const beforeDefinition = connectionDefinition(connection), afterDefinition = connectionDefinition(restored); assert.equal(afterDefinition.revision, beforeDefinition.revision + 2); assert.ok(afterDefinition.updatedAt >= beforeDefinition.updatedAt); for (const key of ['revision','updatedAt','modelIdentityPolicy','modelIdentityAliases','modelIdentityAliasSource']) delete afterDefinition[key]; const expected = { ...beforeDefinition }; for (const key of ['revision','updatedAt','modelIdentityPolicy','modelIdentityAliases','modelIdentityAliasSource']) delete expected[key]; assert.deepEqual(afterDefinition, expected); assert.equal(restored.modelIdentityPolicy, 'record'); assert.deepEqual(restored.modelIdentityAliases, []); assert.equal(restored.modelIdentityAliasSource, ''); result = { success: true, fixtureRequests: requests, realModelRequests: 0, implementationSuppliedToFixtureOnly: true, actualNodeDriverExecuted: true, originalTests: 9, protectedOwnerBytesAndIndex: true, connectionRestoredExceptRevisionTimestampAndExplicitIdentityDefaults: true }; } catch (error) { result = { success: false, error: error.stack, realModelRequests: 0 }; process.exitCode = 1; } finally { for (const dispose of disposers.reverse()) await dispose(); fs.writeFileSync(path.join(output,'result.json'), JSON.stringify(result,null,2)); } console.log(JSON.stringify({ output, ...result }));