feat: integrate pinned original Purge with host execution gates
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import {createHash} from 'node:crypto';
|
||||
|
||||
// Development-only provenance recipe. Runtime code imports the resulting JSON;
|
||||
// it neither trusts the QA directory nor learns new executable inputs on launch.
|
||||
const evidence='docs/original-purge-load-evidence',raw=fs.readFileSync(path.join(evidence,'manifest.json'));
|
||||
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
||||
assert.equal(sha(raw),'acabdce397139dcd59cbe7f66229a1353d4f95a5ceb7a555977e544b17ea1066');
|
||||
const manifest=JSON.parse(raw),root=process.env.AGENT_WORKBENCH_DEEPSEEK_ROOT;
|
||||
assert.ok(root&&path.isAbsolute(root));
|
||||
const prefix=path.resolve(root)+path.sep,files=new Map();
|
||||
const identify=file=>{const raw=fs.readFileSync(file);return {relative:path.relative(root,file).replaceAll('\\','/'),bytes:raw.length,sha256:sha(raw)};};
|
||||
for(const input of manifest.loadedModuleInputs.filter(input=>input.path.startsWith(prefix))){
|
||||
assert.equal(sha(fs.readFileSync(path.join(evidence,input.snapshot))),input.sha256);
|
||||
const identity=identify(input.path);assert.equal(identity.sha256,input.sha256);files.set(identity.relative,identity);
|
||||
// Node package resolution reads these metadata before source loading.
|
||||
for(let parent=path.dirname(input.path);parent.startsWith(prefix)||parent===root;parent=path.dirname(parent)){
|
||||
const file=path.join(parent,'package.json');if(fs.existsSync(file)){const item=identify(file);files.set(item.relative,item);}
|
||||
if(parent===root)break;
|
||||
}
|
||||
}
|
||||
for(const relative of ['packages/bundle/sdk-minimal/cordis.patch.yml','pnpm-lock.yaml']){
|
||||
const input=identify(path.join(root,relative));files.set(relative,input);
|
||||
}
|
||||
const nativePackage='node_modules/.pnpm/node-addon-require-builtin-win32-x64-msvc@0.1.9/node_modules/node-addon-require-builtin-win32-x64-msvc';
|
||||
const native=identify(path.join(root,nativePackage,'prebuilt/win32-x64-msvc-napi-v9.node'));
|
||||
assert.equal(native.sha256,'ead441d11202126827a789a7eb88e79abe8f7f374b16e7273c4244225c8d6c2b');
|
||||
for(const relative of ['prebuilds.json','prebuilt/win32-x64-msvc-napi-v9.node']){
|
||||
const input=identify(path.join(root,nativePackage,relative));files.set(input.relative,input);
|
||||
}
|
||||
const koffi=identify(path.join(root,'node_modules/.pnpm/@koromix+koffi-win32-x64@3.1.1/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.node'));
|
||||
assert.equal(koffi.sha256,'eb0587c804bb76262968bf83028528da4dc2d4322f558845cce205c709e2ba20');files.set(koffi.relative,koffi);
|
||||
const upstream=manifest.upstreamInputs.map(({relative,bytes,sha256,snapshot})=>{
|
||||
assert.equal(sha(fs.readFileSync(path.join(evidence,snapshot))),sha256);return {relative,bytes,sha256};
|
||||
}).sort((a,b)=>a.relative.localeCompare(b.relative,'en'));
|
||||
const lock={schemaVersion:1,purgeVersion:'1.1.78',harnessVersion:'0.2.1-rc.2',
|
||||
provenance:{manifestSha256:sha(raw),sourceCommit:manifest.sourceCommit,scope:'Observed JS/JSON plus resolution metadata and explicit native require-builtin input.',
|
||||
nativePeEvidenceIds:['ev_4a114ba373a5039c34e7fcdad6b9202b42d00f16cd4ae6d80304feb4d93cc19c','ev_b9670d77723678e6c17415368494a06583872fe1e41bd739d795c0c6a20ddca2']},
|
||||
original:upstream,harness:[...files.values()].sort((a,b)=>a.relative.localeCompare(b.relative,'en')),
|
||||
nativeAddons:[{...native,staticImports:['KERNEL32.dll'],staticDelayImports:['node.exe']},
|
||||
{...koffi,staticImports:['KERNEL32.dll','ADVAPI32.dll'],staticDelayImports:['NODE.EXE']}]};
|
||||
const output=process.argv[2]??'src/core/engines/original-purge-lock.json';assert.equal(fs.existsSync(output),false);
|
||||
fs.writeFileSync(output,JSON.stringify(lock,null,2)+'\n',{flag:'wx'});
|
||||
console.log(JSON.stringify({output,original:lock.original.length,harness:lock.harness.length,sha256:sha(fs.readFileSync(output))}));
|
||||
@@ -99,7 +99,9 @@ export async function upgradeRunning({ url, pid, currentRoot, newRoot, handlerRo
|
||||
if (!candidates.length) throw new Error('The existing server module is missing from inspector metadata.');
|
||||
for (const script of candidates) {
|
||||
const { scriptSource } = await protocol.send('Debugger.getScriptSource', { scriptId: script.scriptId });
|
||||
const locations = scriptSource.split('\n').flatMap((line, index) => line.includes('const url = new URL(request.url') ? [index] : []);
|
||||
// Bundled transport libraries can parse request.url too. Select the
|
||||
// actual loopback handler with its local base and observed port binding.
|
||||
const locations = scriptSource.split('\n').flatMap((line, index) => /const url = new URL\(request\.url,\s*["']http:\/\/127\.0\.0\.1:["']\s*\+\s*actualPort\d*\)/.test(line) ? [index] : []);
|
||||
if (locations.length !== 1) throw new Error('The existing request handler could not be identified uniquely.');
|
||||
breakpoints.push((await protocol.send('Debugger.setBreakpoint', { location: { scriptId: script.scriptId, lineNumber: locations[0] } })).breakpointId);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Runtime } from '../src/server/runtime.mjs';
|
||||
import { EngineRunner } from '../src/core/engines/engine-runner.mjs';
|
||||
import { resolveControlledInstallation } from '../src/core/engines/controlled-installation.mjs';
|
||||
import { originalEngineRun, verifyEngineModelInput } from '../src/shared/contracts/engine-execution.mjs';
|
||||
import { resolvePurgeSource, assertPurgeModelInput, nativeSystemTexts, PURGE_DEFAULT_PROMPT } from '../src/core/engines/purge-strategy.mjs';
|
||||
import { resolvePurgeSource, resolveOriginalPurgeSource, ORIGINAL_PURGE_KIND, assertPurgeModelInput, nativeSystemTexts, PURGE_DEFAULT_PROMPT } from '../src/core/engines/purge-strategy.mjs';
|
||||
import { deliveryGit as git, writeDeliveryFile as write } from '../tests/fixtures/delivery-project.mjs';
|
||||
import { ownerBytes } from '../tests/fixtures/workers-project.mjs';
|
||||
import { desktopProjectQa } from './desktop-project-qa.mjs';
|
||||
@@ -18,12 +18,15 @@ import { responsesEngineeringHttp } from '../tests/fixtures/responses-engineerin
|
||||
import { nativeContextSpecification } from '../tests/fixtures/native-context-project.mjs';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
assert.ok(args.every(value => ['--help', '--purge-comparison', '--desktop', '--responses', '--context-16k'].includes(value)), 'Unknown option; use --help.');
|
||||
assert.ok(args.every(value => ['--help', '--purge-comparison', '--desktop', '--responses', '--context-16k','--context-32k','--original-purge'].includes(value)), 'Unknown option; use --help.');
|
||||
if (args.includes('--help')) {
|
||||
console.log('node scripts/verify-controlled-projects.mjs [--purge-comparison | --desktop | --context-16k] [--responses] — actual pinned Harness and owned HTTP model fixture; default verifies Node/React/Python with approvals, Edge and Git. --context-16k uses a new copy of the sealed three-module/nine-test pilot, original failure/log paging and a complete reviewed batch at 16K. --responses uses actual Responses SSE and ModelHub routing. Set AGENT_WORKBENCH_DEEPSEEK_ROOT and AGENT_WORKBENCH_TEST_PYTHON; context mode needs no Python. No configured-model requests.'); process.exit(0);
|
||||
console.log('node scripts/verify-controlled-projects.mjs [--purge-comparison | --desktop | --context-16k | --context-32k] [--responses] [--original-purge] — actual pinned Harness and owned HTTP model fixture; default verifies Node/React/Python with approvals, Edge and Git. Context modes use a new copy of the sealed three-module/nine-test pilot, original failure/log paging and a complete reviewed batch at the explicit limit. Original Purge is separate from the independent prompt and its fixed instructions need the 32K profile. --responses uses actual Responses SSE and ModelHub routing. Set AGENT_WORKBENCH_DEEPSEEK_ROOT and AGENT_WORKBENCH_TEST_PYTHON; context mode needs no Python. No configured-model requests.'); process.exit(0);
|
||||
}
|
||||
const comparisonMode = args.includes('--purge-comparison'), desktopMode = args.includes('--desktop');
|
||||
const contextMode = args.includes('--context-16k');assert.ok(!contextMode || !comparisonMode && !desktopMode, '16K bridge acceptance is a separate run.');
|
||||
assert.ok(!(args.includes('--context-16k')&&args.includes('--context-32k')),'Choose one explicit native context limit.');
|
||||
const contextMode = args.includes('--context-16k')||args.includes('--context-32k');assert.ok(!contextMode || !comparisonMode && !desktopMode, 'Native context acceptance is a separate run.');
|
||||
const contextLimit=args.includes('--context-32k')?32000:16000;
|
||||
const originalPurgeMode=args.includes('--original-purge');assert.ok(!originalPurgeMode||contextMode,'Original Purge engineering acceptance uses a separate owned context case.');
|
||||
const responsesMode = args.includes('--responses'); assert.ok(!responsesMode || !comparisonMode, 'Protocol acceptance and Purge comparison remain separate.');
|
||||
assert.ok(!comparisonMode || !desktopMode, 'Desktop engineering and prompt comparison are separate acceptance runs.');
|
||||
const version = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
|
||||
@@ -31,6 +34,9 @@ const directory = path.resolve('.qa', (contextMode ? 'controlled-context-' : des
|
||||
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
||||
const installation = resolveControlledInstallation(process.cwd(), process.env.AGENT_WORKBENCH_DEEPSEEK_ROOT);
|
||||
assert.equal(installation.controlledStatus, 'available', installation.message);
|
||||
const originalSource=originalPurgeMode?resolveOriginalPurgeSource(process.cwd(),process.env.AGENT_WORKBENCH_PURGE_178_ROOT,installation):null;
|
||||
if(originalSource)assert.equal(originalSource.status,'available',originalSource.message);
|
||||
const originalStrategy=originalSource?{kind:ORIGINAL_PURGE_KIND,root:originalSource.root,sourceSha256:originalSource.sourceSha256,runtimeSha256:originalSource.runtimeSha256,prompt:PURGE_DEFAULT_PROMPT}:null;
|
||||
const python = process.env.AGENT_WORKBENCH_TEST_PYTHON;
|
||||
if (!comparisonMode && !contextMode) assert.ok(python && path.isAbsolute(python) && fs.existsSync(python), 'Provide the existing isolated Python 3.10+ interpreter.');
|
||||
const sources = comparisonMode ? ['1.1.78', '1.1.81'].map((expected, index) => {
|
||||
@@ -111,12 +117,12 @@ async function runSample(kind, { sampleName = kind, strategy = null, comparison
|
||||
return { choices: [{ message: { role: 'assistant', content: calls.length ? '' : 'Owned native run complete; host proof is still required.', ...(calls.length ? { tool_calls: calls } : {}) },
|
||||
finish_reason: calls.length ? 'tool_calls' : 'stop' }], usage: { prompt_tokens: 123, completion_tokens: 45, total_tokens: 168 } };
|
||||
});
|
||||
f.store.saveConfig({ mode: 'compatible', model: 'owned-controlled-engineering', baseUrl: model.baseUrl, contextLimit: contextMode ? 16000 : 64000,
|
||||
f.store.saveConfig({ mode: 'compatible', model: 'owned-controlled-engineering', baseUrl: model.baseUrl, contextLimit: contextMode ? contextLimit : 64000,
|
||||
...(contextMode ? {maxOutputTokens:2048} : {}) });
|
||||
const provider = new Provider(); provider.setKey('self-owned-controlled-model-fixture');
|
||||
if (responsesMode) {
|
||||
const hub = provider.modelHub(f.store), connection = hub.upsert({ name: 'Owned Responses engineering', protocol: 'responses', model: 'owned-controlled-engineering', baseUrl: model.baseUrl,
|
||||
requiresKey: false, contextLimit: contextMode ? 16000 : 64000, ...(contextMode ? {maxOutputTokens:2048} : {}), streaming: true, capabilityDeclarations: { streaming: 'supported' } });
|
||||
requiresKey: false, contextLimit: contextMode ? contextLimit : 64000, ...(contextMode ? {maxOutputTokens:2048} : {}), streaming: true, capabilityDeclarations: { streaming: 'supported' } });
|
||||
hub.select({ type: 'connection', id: connection.id });
|
||||
}
|
||||
runtime = new Runtime(f.store, provider); f.onCleanup(() => runtime.stopAll());
|
||||
@@ -166,10 +172,17 @@ async function runSample(kind, { sampleName = kind, strategy = null, comparison
|
||||
const engineRuns = [...f.store.core.engine_run.values()].filter(job => job.taskId === child.taskId), childSession = f.store.session(child.sessionId);
|
||||
for (const job of engineRuns) {
|
||||
originalEngineRun(f.store, childSession, job); assert.equal(job.status, 'completed', job.error); assert.equal(job.native.cleanup.treeConfirmed, true);
|
||||
assert.equal(job.native.stderr, ''); assert.equal(job.native.activity.endEvents[0].data.reason.kind, 'completed');
|
||||
if(originalPurgeMode){
|
||||
const warning='(node:'+job.native.process.pid+') [PERM0001] SecurityWarning: The flag --allow-addons must be used with extreme caution. It could invalidate the permission model.\n(Use `node --trace-warnings ...` to show where the warning was created)\n';
|
||||
const expected=warning+['package.json','lib/index.js'].map(file=>'AWB_MODULE_REFUSED '+path.join(installation.root,'packages/context/agent-instructions',file)+'\n').join('');
|
||||
assert.equal(job.native.stderr,expected);assert.equal(job.native.originalPurge.readiness.originalApplyCalled,true);
|
||||
assert.equal(job.native.originalPurge.nativeLoads.length,2);assert.ok(job.native.originalPurge.durabilityReceipts.length>0);
|
||||
}else assert.equal(job.native.stderr, ''); assert.equal(job.native.activity.endEvents[0].data.reason.kind, 'completed');
|
||||
for (const request of job.requests) {
|
||||
const saved = verifyEngineModelInput(f.store, childSession, job, request);
|
||||
if (strategy) { assertPurgeModelInput(saved.native, job.installation.strategy); assert.equal(job.native.readiness.promptExperimentSha256, job.installation.strategy.sha256); }
|
||||
if (strategy) { assertPurgeModelInput(saved.native, job.installation.strategy);
|
||||
if(originalPurgeMode)assert.equal(job.native.originalPurge.strategySha256,job.installation.strategy.sha256);
|
||||
else assert.equal(job.native.readiness.promptExperimentSha256, job.installation.strategy.sha256); }
|
||||
else assert.ok(nativeSystemTexts(saved.native).every(text => !text.includes('[Agent Workbench engineering prompt experiment]')));
|
||||
}
|
||||
}
|
||||
@@ -190,7 +203,7 @@ async function runSample(kind, { sampleName = kind, strategy = null, comparison
|
||||
const failed=childChecks.find(job=>job.status==='failed'),log=f.store.core.artifact.get(failed.results[0].logArtifactId);
|
||||
assert.ok(f.store.artifactStore.read(log).includes('fail 9'));assert.ok(engineRuns.some(job=>job.calls.some(call=>call.name==='read_artifact')));
|
||||
assert.ok(engineRuns.some(job=>job.calls.some(call=>call.name==='prepare_change_set')));assert.ok(engineRuns.every(job=>!job.inputRejections?.length));
|
||||
mark('16K: original nine failures and paged log survive verified native compaction; all three proposals form one reviewed batch without replay');
|
||||
mark(contextLimit/1000+'K: original nine failures and paged log survive verified native compaction; all three proposals form one reviewed batch without replay');
|
||||
}
|
||||
await (await manager.collect(f.session, group.id, group.fingerprint)).promise; assert.equal(group.status, 'collected', group.summary);
|
||||
const collection = await manager.readCollection(f.session, group); assert.deepEqual(collection.conflicts, []); assert.deepEqual(collection.paths, writable);
|
||||
@@ -272,9 +285,9 @@ try {
|
||||
mark(source.version + ' repetition ' + repetition + ': identical original task/baseline/tests/response algorithm and budgets; actual prompt overhead and host approvals recorded');
|
||||
}
|
||||
assert.equal(results.length, 8); assert.equal(comparisons.length, 4);
|
||||
} else for (const kind of contextMode ? ['native-context'] : ['node', 'react', 'python']) results.push(await runSample(kind));
|
||||
} else for (const kind of contextMode ? ['native-context'] : ['node', 'react', 'python']) results.push(await runSample(kind,{strategy:originalStrategy}));
|
||||
assert.deepEqual(inputs(), frozen);
|
||||
report = { success: true, targetVersion: version, testedVersion: version, protocol: responsesMode ? 'responses-stream' : 'chat-completions', directory, installation, cases, results, comparisons, sources, inputs: frozen, realModelRequests: 0,
|
||||
report = { success: true, targetVersion: version, testedVersion: version, protocol: responsesMode ? 'responses-stream' : 'chat-completions', contextLimit:contextMode?contextLimit:64000, originalPurge:originalPurgeMode, directory, installation, cases, results, comparisons, sources, inputs: frozen, realModelRequests: 0,
|
||||
scope: 'Pinned actual Harness and workbench execution with an owned HTTP model fixture. Checks, approvals, failures, parent merges, Edge and Git are real. Model reasoning and Purge benefit remain separate.' };
|
||||
} catch (error) { report = { success: false, targetVersion: version, testedVersion: version, directory, installation, cases, results, inputs: frozen, error: error.stack, realModelRequests: 0 }; process.exitCode = 1; }
|
||||
finally { fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(report, null, 2)); fs.writeFileSync('.qa/' + (contextMode ? (responsesMode ? 'responses-context' : 'controlled-context') : responsesMode ? 'responses-engineering' : desktopMode ? 'desktop-projects' : comparisonMode ? 'controlled-purge' : 'controlled-projects') + '-location.json', JSON.stringify({ directory, result: path.join(directory, 'result.json') })); console.log('EVIDENCE ' + directory); console.log(JSON.stringify({ success: report.success, cases: cases.length, directory, realModelRequests: 0, error: report.error ?? null })); }
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import {randomUUID} from 'node:crypto';
|
||||
import {fixture,compatibleFixture,call,until} from '../tests/helpers.mjs';
|
||||
import {createDeliveryProject} from '../tests/fixtures/delivery-project.mjs';
|
||||
import {ownerBytes} from '../tests/fixtures/workers-project.mjs';
|
||||
import {Provider} from '../src/server/provider.mjs';
|
||||
import {Runtime} from '../src/server/runtime.mjs';
|
||||
import {EngineRunner} from '../src/core/engines/engine-runner.mjs';
|
||||
import {resolveControlledInstallation} from '../src/core/engines/controlled-installation.mjs';
|
||||
import {resolveOriginalPurgeSource,ORIGINAL_PURGE_KIND,assertPurgeModelInput,PURGE_DEFAULT_PROMPT} from '../src/core/engines/purge-strategy.mjs';
|
||||
import {originalEngineRun,verifyEngineModelInput} from '../src/shared/contracts/engine-execution.mjs';
|
||||
|
||||
const directory=path.resolve('.qa','original-purge-host-'+randomUUID());fs.mkdirSync(directory,{recursive:true});
|
||||
const installation=resolveControlledInstallation(process.cwd(),process.env.AGENT_WORKBENCH_DEEPSEEK_ROOT);
|
||||
assert.equal(installation.controlledStatus,'available',installation.message);
|
||||
const source=resolveOriginalPurgeSource(process.cwd(),process.env.AGENT_WORKBENCH_PURGE_178_ROOT,installation);assert.equal(source.status,'available',source.message);
|
||||
const results=[];
|
||||
const usage={prompt_tokens:123,completion_tokens:45,total_tokens:168};
|
||||
async function sample(scenario){
|
||||
const disposers=[],t={after:fn=>disposers.push(fn)},f=fixture(t),sample=path.join(directory,scenario);fs.mkdirSync(sample);
|
||||
let runtime,group,release,started,reported;let first=true;
|
||||
try{
|
||||
createDeliveryProject(f);const original=ownerBytes(f),copy=path.join(f.root,'declared-original-source');
|
||||
fs.mkdirSync(copy);for(const input of source.inputs){const file=path.join(copy,input.relative);fs.mkdirSync(path.dirname(file),{recursive:true});fs.copyFileSync(input.path,file);}
|
||||
const selected=resolveOriginalPurgeSource(process.cwd(),copy,installation);assert.equal(selected.status,'available',selected.message);
|
||||
const gate=new Promise(resolve=>{release=resolve;});
|
||||
const model=await compatibleFixture(t,async(_route,_input,requests)=>{
|
||||
if(scenario==='stop-in-flight')await gate;
|
||||
if(scenario==='reported-budget-overrun')return {status:503,body:{error:{message:'Owned upstream 503 with reported usage'},usage:{prompt_tokens:55000,completion_tokens:17,total_tokens:55017}}};
|
||||
const tools=[];
|
||||
if(scenario==='source-changed-at-approval'){
|
||||
const worker=group.children[0],plan=[...f.store.core.check_plan.values()].find(item=>item.taskId===worker.taskId);
|
||||
tools.push(plan?call('owned-check','run_checks',{plan_id:plan.id}):call('owned-plan','plan_checks',{names:['test','build']}));
|
||||
}else if(scenario==='denied-scope'&&requests.length===1)tools.push(call('owned-outside','propose_file',{path:'../outside.mjs',content:'denied',reason:'Declared negative scope test'}));
|
||||
return {choices:[{message:{role:'assistant',content:tools.length?'':'Owned host fixture terminal.',...(tools.length?{tool_calls:tools}:{})},finish_reason:tools.length?'tool_calls':'stop'}],usage};
|
||||
});
|
||||
f.store.saveConfig({mode:'compatible',model:'owned-original-host',baseUrl:model.baseUrl,contextLimit:32000,maxOutputTokens:1024});
|
||||
const provider=new Provider();provider.setKey('owned-original-host-http-fixture');runtime=new Runtime(f.store,provider);
|
||||
runtime.controlledEngines=new EngineRunner(f.store,provider,{directoryRoot:path.join(f.root,'owned-engines')});
|
||||
const manager=runtime.workerManager();group=await manager.plan(f.session,{goal:'Verify original Purge '+scenario,
|
||||
engine:{id:'deepseek-harness',root:installation.root,controlledSha256:installation.controlledSha256,
|
||||
strategy:{kind:ORIGINAL_PURGE_KIND,root:copy,sourceSha256:selected.sourceSha256,runtimeSha256:selected.runtimeSha256,prompt:PURGE_DEFAULT_PROMPT}},
|
||||
budget:{maxTokens:scenario==='reported-budget-overrun'?35000:150000,maxSteps:12,maxToolCalls:20,maxDurationMs:120000},
|
||||
children:[{label:'original-1',goal:'Keep the original project and host controls',paths:['src/add.mjs']}]});
|
||||
await (await manager.prepare(f.session,group.id,group.fingerprint)).promise;assert.equal(group.status,'ready',group.summary);
|
||||
const worker=group.children[0],session=f.store.session(worker.sessionId),task=f.store.core.task.get(worker.taskId);
|
||||
started=manager.start(f.session,group.id,group.fingerprint);
|
||||
if(scenario==='stop-in-flight'){
|
||||
await until(()=>model.requests.length===1,45000);await runtime.stop(session.id);release();
|
||||
}
|
||||
if(scenario==='source-changed-at-approval'){
|
||||
await until(()=>session.approvals.some(item=>item.status==='pending'),45000);
|
||||
fs.appendFileSync(path.join(copy,'lib/host.js'),'\n// Declared source drift during approval\n');
|
||||
const approval=session.approvals.find(item=>item.status==='pending');runtime.decide(session.id,approval.id,true);
|
||||
}
|
||||
await started.promise;release();
|
||||
const jobs=[...f.store.core.engine_run.values()].filter(job=>job.taskId===worker.taskId),job=jobs.at(-1),run=f.store.core.run.get(job.runId);
|
||||
assert.equal(job.native.cleanup.rootExited,true);assert.equal(job.native.cleanup.treeConfirmed,true);assert.deepEqual(ownerBytes(f),original);
|
||||
originalEngineRun(f.store,session,job);
|
||||
for(const request of job.requests){const input=verifyEngineModelInput(f.store,session,job,request);assertPurgeModelInput(input.native,job.installation.strategy);}
|
||||
assert.ok(model.requests.length>0,'The owned native request must reach the declared HTTP fixture.');
|
||||
assert.equal(task.usage.requests,model.requests.length);assert.equal((run.consumption??[]).length,model.requests.length);
|
||||
if(scenario==='reported-budget-overrun'){
|
||||
assert.equal(model.requests.length,1);assert.equal(task.usage.totalTokens,55017);assert.equal(run.usage.unknownRequests,0);assert.equal(run.stopReason,'token_limit');assert.equal(job.calls.length,0);
|
||||
}
|
||||
if(scenario==='denied-scope'){
|
||||
assert.equal(model.requests.length,2);assert.equal(job.calls.length,1);assert.equal(session.changes.length,0);assert.equal(task.usage.totalTokens,336);
|
||||
assert.equal(fs.existsSync(path.join(f.store.project(worker.projectId).root,'..','outside.mjs')),false);
|
||||
}
|
||||
if(scenario==='stop-in-flight'){
|
||||
assert.equal(model.requests.length,1);assert.equal(job.calls.length,0);assert.equal(job.status,'cancelled');assert.equal(run.usage.unknownRequests,1);assert.equal(task.usage.unknownRequests,1);
|
||||
const oldJob=JSON.stringify(job),oldUsage=structuredClone(task.usage),oldRun=JSON.stringify(run);
|
||||
await (await manager.start(f.session,group.id,group.fingerprint)).promise;
|
||||
const resumed=[...f.store.core.engine_run.values()].filter(value=>value.taskId===worker.taskId).at(-1),resumedRun=f.store.core.run.get(resumed.runId);
|
||||
assert.notEqual(resumed.id,job.id);assert.notEqual(resumed.runId,job.runId);assert.equal(resumed.taskId,job.taskId);assert.equal(resumed.status,'completed',resumed.error);
|
||||
assert.equal(model.requests.length,2);assert.equal(task.usage.requests,2);assert.equal(task.usage.unknownRequests,1);assert.equal(task.usage.totalTokens,oldUsage.totalTokens+168);
|
||||
assert.equal(task.usage.estimatedUnknownTokens,oldUsage.estimatedUnknownTokens);assert.equal(JSON.stringify(job),oldJob);assert.equal(JSON.stringify(run),oldRun);
|
||||
assert.equal(resumedRun.consumption.length,1);assert.equal(resumed.native.cleanup.treeConfirmed,true);assert.equal(resumed.calls.length,0);
|
||||
originalEngineRun(f.store,session,resumed);reported={resumedJob:resumed,resumedRun,originalStopUsage:oldUsage};
|
||||
}
|
||||
if(scenario==='source-changed-at-approval'){
|
||||
assert.equal(model.requests.length,2);assert.equal(f.store.core.check_job.size,0);assert.match(job.error,/已变化/);assert.equal(task.usage.totalTokens,336);
|
||||
}
|
||||
reported={...reported,scenario,passed:true,group,task,run,job,modelRequests:model.requests,realModelRequests:0};
|
||||
console.log('PASS '+scenario+'; HTTP '+model.requests.length+'; task reported '+task.usage.totalTokens+'; unknown '+task.usage.unknownRequests);
|
||||
}catch(error){reported={scenario,passed:false,error:error.stack,group,realModelRequests:0};throw error;}
|
||||
finally{
|
||||
release?.();if(started)await started.promise.catch(()=>{});if(runtime)await runtime.stopAll();
|
||||
f.store.storage.database.exec('PRAGMA wal_checkpoint(TRUNCATE)');fs.writeFileSync(path.join(sample,'result.json'),JSON.stringify(reported,null,2));
|
||||
fs.cpSync(f.root,path.join(sample,'original-fixture'),{recursive:true,filter:file=>!file.split(path.sep).includes('node_modules')});
|
||||
for(const dispose of disposers.reverse())await dispose();
|
||||
}
|
||||
return {scenario,passed:true};
|
||||
}
|
||||
let report;
|
||||
try{for(const scenario of ['reported-budget-overrun','denied-scope','stop-in-flight','source-changed-at-approval'])results.push(await sample(scenario));
|
||||
report={passed:true,directory,results,realModelRequests:0,scope:'Actual pinned Harness and production host routing with owned HTTP fixtures. No real model reasoning or Purge benefit.'};
|
||||
}catch(error){process.exitCode=1;report={passed:false,directory,results,error:error.stack,realModelRequests:0};}
|
||||
fs.writeFileSync(path.join(directory,'validation.json'),JSON.stringify(report,null,2));console.log(JSON.stringify(report));
|
||||
@@ -0,0 +1,75 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import {createHash} from 'node:crypto';
|
||||
import {execFileSync} from 'node:child_process';
|
||||
import {originalEngineRun,verifyEngineModelInput} from '../src/shared/contracts/engine-execution.mjs';
|
||||
import {assertPurgeModelInput} from '../src/core/engines/purge-strategy.mjs';
|
||||
|
||||
// Offline only: inspect original bytes and pure contracts, never instantiate
|
||||
// a Provider/Runtime, load an upstream plugin or send a model request.
|
||||
const root=path.resolve('docs/original-purge-production-evidence'),sha=raw=>createHash('sha256').update(raw).digest('hex');
|
||||
const inside=relative=>{const file=path.resolve(root,relative);assert.ok(file.startsWith(root+path.sep));return file;};
|
||||
const read=relative=>JSON.parse(fs.readFileSync(inside(relative))),raw=fs.readFileSync(inside('manifest.json')),manifest=JSON.parse(raw);
|
||||
assert.equal(manifest.schemaVersion,1);assert.equal(manifest.realModelRequests,0);assert.equal(manifest.formalServiceChanged,false);
|
||||
let bytes=0;const paths=new Set();
|
||||
for(const entry of manifest.entries){assert.ok(!paths.has(entry.path));paths.add(entry.path);const data=fs.readFileSync(inside(entry.path));
|
||||
assert.equal(data.length,entry.bytes,entry.path);assert.equal(sha(data),entry.sha256,entry.path);bytes+=data.length;}
|
||||
assert.equal(paths.size,manifest.count);assert.equal(bytes,manifest.bytes);
|
||||
for(const input of manifest.sourceInputs){
|
||||
const git=execFileSync('git',['show',manifest.sourceCommit+':'+input.path],{windowsHide:true,maxBuffer:16*1024*1024});
|
||||
assert.equal(sha(git),input.gitBlobSha256,input.path);
|
||||
if(input.snapshot){const bytes=fs.readFileSync(inside(input.snapshot));assert.equal(sha(bytes),input.sha256);assert.equal(bytes.length,input.bytes);
|
||||
assert.equal(bytes.toString('utf8').replaceAll('\r\n','\n'),git.toString('utf8').replaceAll('\r\n','\n'));}
|
||||
else assert.equal(sha(git),input.sha256,input.path);
|
||||
}
|
||||
const receipt=name=>fs.readFileSync(inside(manifest.receipts.find(value=>value.name===name).file),'utf8');
|
||||
assert.match(receipt('full'),new RegExp('tests '+manifest.fullSummary.tests+'\\b'));
|
||||
assert.match(receipt('full'),new RegExp('pass '+manifest.fullSummary.passed+'\\b'));
|
||||
assert.match(receipt('full'),/fail 4\b/);assert.equal(manifest.fullSummary.failed,4);
|
||||
assert.equal(manifest.fullSummary.tests,manifest.fullSummary.passed+manifest.fullSummary.failed);
|
||||
// Preserve the original failed whole run. Subsequent evidence is the same
|
||||
// Python cases with the declared environment and the two repaired migrations.
|
||||
assert.deepEqual(manifest.fullSummary.failedNames.slice().sort(),[
|
||||
'real pytest pass, failure, skip, collection errors and teardown errors use collected case outcomes',
|
||||
'a missing interpreter and repeated pytest item objects cannot create a false verification pass',
|
||||
'a directly started compiled host upgrades twice with the same PID, sessions, applied bytes and volatile provider',
|
||||
'the running 0.1.0 process upgrades in place and retains its project, session, files and volatile model connection'
|
||||
].sort());
|
||||
for(const [name,count] of [['python-final',15],['upgrade-final',2]]){
|
||||
assert.match(receipt(name),new RegExp('tests '+count+'\\b'));assert.match(receipt(name),new RegExp('pass '+count+'\\b'));assert.match(receipt(name),/fail 0\b/);
|
||||
}
|
||||
assert.match(receipt('build'),/Server bundle built\./);
|
||||
const runtime=read(manifest.runtime);assert.equal(runtime.passed,true);assert.equal(runtime.productionAdapter,true);
|
||||
assert.deepEqual(runtime.cases.map(value=>value.scenario),['completed','failed-no-retry','host-denied-tool']);
|
||||
assert.equal(runtime.cases[0].exit.code,0);assert.deepEqual(runtime.cases.map(value=>value.bridgeCalls),[1,1,2]);
|
||||
const host=read(manifest.host.result);assert.equal(host.passed,true);assert.equal(host.results.length,4);
|
||||
for(const sample of manifest.host.samples){const value=read(sample.result);assert.equal(value.passed,true);assert.equal(value.job.native.cleanup.treeConfirmed,true);
|
||||
if(value.scenario==='reported-budget-overrun'){assert.equal(value.task.usage.totalTokens,55017);assert.equal(value.run.stopReason,'token_limit');assert.equal(value.modelRequests.length,1);}
|
||||
if(value.scenario==='stop-in-flight'){assert.equal(value.run.usage.unknownRequests,1);assert.equal(value.task.usage.unknownRequests,1);
|
||||
assert.equal(value.modelRequests.length,2);assert.equal(value.resumedJob.taskId,value.job.taskId);assert.notEqual(value.resumedJob.runId,value.job.runId);
|
||||
assert.equal(value.resumedJob.native.cleanup.treeConfirmed,true);assert.equal(value.task.usage.totalTokens,168);}
|
||||
if(value.scenario==='source-changed-at-approval')assert.match(value.job.error,/已变化/);
|
||||
}
|
||||
const ui=read(manifest.ui.result);assert.equal(ui.passed,true);assert.equal(ui.cases.length,4);assert.deepEqual(ui.pageErrors,[]);assert.deepEqual(ui.unexpectedFailures,[]);
|
||||
assert.equal(manifest.ui.screenshots.length,4);
|
||||
let requests=0,artifacts=0;
|
||||
for(const sample of manifest.engineering){
|
||||
const result=read(sample.result),core={},owners=new Map(read(sample.sessions).map(value=>[value.id,value]));
|
||||
for(const row of read(sample.records)){const value=JSON.parse(row.payload);(core[row.kind]??=new Map()).set(value.id,value);}
|
||||
const inputs=new Map(sample.artifacts.map(value=>[value.id,value]));artifacts+=inputs.size;
|
||||
const store={core,owned(kind,id,sessionId){const value=core[kind]?.get(id);assert.equal(value?.sessionId,sessionId);return value;},
|
||||
artifactStore:{read(artifact){const data=fs.readFileSync(inside(inputs.get(artifact.id).file));assert.equal(sha(data),artifact.sha256);assert.equal(data.length,artifact.bytes);return data.toString('utf8');}},
|
||||
savedToolResult(sessionId,callId){const tool=[...core.tool.values()].find(value=>value.sessionId===sessionId&&value.callId===callId);return JSON.parse(this.artifactStore.read(core.artifact.get(tool.resultArtifactId)));}};
|
||||
assert.equal(result.success,true);assert.equal(result.metrics.contextLimit,32000);assert.equal(result.parentCheck.results[0].tests.passed,9);
|
||||
assert.ok(result.checks.some(job=>job.status==='failed'&&job.results[0].tests.failed===9));
|
||||
for(const job of core.engine_run.values()){
|
||||
const session=owners.get(job.sessionId);originalEngineRun(store,session,job);assert.equal(job.status,'completed');assert.equal(job.native.cleanup.treeConfirmed,true);
|
||||
const original=job.native.originalPurge;assert.equal(original.readiness.originalApplyCalled,true);assert.equal(original.nativeLoads.length,2);assert.ok(original.durabilityReceipts.length);
|
||||
assert.equal(job.installation.strategy.kind,'purge-original-restricted-v1');
|
||||
for(const request of job.requests){const input=verifyEngineModelInput(store,session,job,request);assertPurgeModelInput(input.native,job.installation.strategy);requests++;}
|
||||
}
|
||||
}
|
||||
assert.deepEqual(manifest.engineering.map(value=>value.name),['chat','responses']);
|
||||
console.log(JSON.stringify({passed:true,sourceCommit:manifest.sourceCommit,files:paths.size,bytes,fullSummary:manifest.fullSummary,artifacts,requests,
|
||||
manifestSha256:sha(raw),realModelRequests:0,scope:'Offline original source/receipt/request/usage/cleanup checks. Actual reasoning and Purge benefit remain unmeasured.'}));
|
||||
@@ -0,0 +1,52 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import {randomUUID} from 'node:crypto';
|
||||
import {ControlledDeepSeekSession} from '../src/core/engines/controlled-session.mjs';
|
||||
import {resolveControlledInstallation} from '../src/core/engines/controlled-installation.mjs';
|
||||
import {resolveOriginalPurgeSource,selectPurgeStrategy,assertPurgeModelInput,ORIGINAL_PURGE_KIND} from '../src/core/engines/purge-strategy.mjs';
|
||||
|
||||
// Real pinned Harness, production adapter, synthetic model responses. No Key,
|
||||
// configured provider, user project, clientFactory patch or upstream mutation.
|
||||
const directory=path.resolve('.qa','original-purge-runtime-'+randomUUID());fs.mkdirSync(directory,{recursive:true});
|
||||
const installation=resolveControlledInstallation(process.cwd(),process.env.AGENT_WORKBENCH_DEEPSEEK_ROOT);
|
||||
assert.equal(installation.controlledStatus,'available',installation.message);
|
||||
const source=resolveOriginalPurgeSource(process.cwd(),process.env.AGENT_WORKBENCH_PURGE_178_ROOT,installation);
|
||||
assert.equal(source.status,'available',source.message);
|
||||
const strategy=selectPurgeStrategy({kind:ORIGINAL_PURGE_KIND,root:source.root,sourceSha256:source.sourceSha256,runtimeSha256:source.runtimeSha256,
|
||||
prompt:'Preserve the owned engineering task, host approvals, saved evidence and cumulative budget.'},process.cwd(),installation);
|
||||
const results=[];let active;
|
||||
try{
|
||||
for(const scenario of ['completed','failed-no-retry','host-denied-tool']){
|
||||
const cwd=path.join(directory,scenario);fs.mkdirSync(cwd);const driver=new ControlledDeepSeekSession(installation,{timeoutMs:30000});active=driver;
|
||||
const controller=new AbortController(),modelInputs=[];let tools=0,text=null,error=null;
|
||||
try{
|
||||
await driver.open({directory:path.join(cwd,'native'),cwd,owner:Object.fromEntries(['sessionId','projectId','taskId','runId','jobId'].map(key=>[key,randomUUID()])),
|
||||
sdkSessionId:randomUUID(),strategy,signal:controller.signal,config:{model:'owned-original-purge-runtime',contextLimit:16000,maxOutputTokens:512,maxRunDurationMs:30000},
|
||||
tools:[{name:'owned_probe',description:'A host-gated synthetic test tool.',parameters:{type:'object',properties:{},additionalProperties:false}}],
|
||||
onModel:async input=>{
|
||||
modelInputs.push(input);assertPurgeModelInput(input,strategy);
|
||||
if(scenario==='failed-no-retry')throw new Error('Declared upstream fixture failure; no automatic retry.');
|
||||
if(modelInputs.length>1)throw new Error('Host stops the next model round after the rejected tool result.');
|
||||
return {message:{role:'assistant',content:scenario==='completed'?'Owned original entry completed.':'',...(scenario==='host-denied-tool'?{
|
||||
tool_calls:[{id:'declared-owned-tool',type:'function',function:{name:'owned_probe',arguments:'{}'}}]}:{})},usage:{prompt_tokens:300,completion_tokens:50,total_tokens:350}};
|
||||
},onTool:async()=>{tools++;throw new Error('External host denied the declared operation.');}});
|
||||
await driver.prompt('Complete only this owned loading/protocol acceptance.');text=await driver.wait();
|
||||
}catch(failure){error=failure.stack;}
|
||||
const report=await driver.close({force:!!error});active=null;
|
||||
const result={scenario,text,error,modelInputs,tools,report};results.push(result);fs.writeFileSync(path.join(cwd,'result.json'),JSON.stringify(result,null,2));
|
||||
assert.equal(report.cleanup?.rootExited,true,JSON.stringify(report));assert.equal(report.cleanup?.treeConfirmed,true);
|
||||
assert.equal(report.originalPurge.readiness?.originalApplyCalled,true);assert.ok(report.originalPurge.loadedModules.length>330);
|
||||
if(scenario==='completed'){assert.equal(error,null);assert.equal(text,'Owned original entry completed.');assert.equal(report.status,'closed');assert.equal(report.cleanup.exit.code,0);assert.equal(modelInputs.length,1);assert.equal(tools,0);}
|
||||
assert.ok(report.originalPurge.durabilityReceipts.length>0);
|
||||
if(scenario==='failed-no-retry'){assert.notEqual(error,null);assert.equal(modelInputs.length,1);assert.equal(tools,0);}
|
||||
if(scenario==='host-denied-tool'){assert.notEqual(error,null);assert.equal(modelInputs.length,2);assert.equal(tools,1);}
|
||||
console.log('PASS '+scenario+'; model bridge '+modelInputs.length+'; host tools '+tools+'; process tree closed');
|
||||
}
|
||||
const summary={passed:true,directory,productionAdapter:true,realModelRequests:0,sourceSha256:source.sourceSha256,runtimeSha256:source.runtimeSha256,
|
||||
cases:results.map(({scenario,modelInputs,tools,report})=>({scenario,bridgeCalls:modelInputs.length,hostTools:tools,status:report.status,exit:report.cleanup.exit,
|
||||
loadedModules:report.originalPurge.loadedModules.length,fsyncs:report.originalPurge.durabilityReceipts.length})),
|
||||
scope:'Pinned original entry through production ControlledDeepSeekSession. Synthetic model responses; no real autonomy or Purge benefit measured.'};
|
||||
fs.writeFileSync(path.join(directory,'validation.json'),JSON.stringify(summary,null,2));console.log(JSON.stringify(summary));
|
||||
}catch(error){console.error(JSON.stringify({passed:false,directory,error:error.stack,realModelRequests:0}));process.exitCode=1;}
|
||||
finally{if(active)await active.close({force:true});}
|
||||
@@ -0,0 +1,84 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import {createHash,randomUUID} from 'node:crypto';
|
||||
import {chromium,expect} from 'playwright/test';
|
||||
import {fixture} from '../tests/helpers.mjs';
|
||||
import {workerHttp} from '../tests/fixtures/workers-http.mjs';
|
||||
import {ownerBytes} from '../tests/fixtures/workers-project.mjs';
|
||||
import {EngineRunner} from '../src/core/engines/engine-runner.mjs';
|
||||
import {resolveControlledInstallation} from '../src/core/engines/controlled-installation.mjs';
|
||||
import {resolveOriginalPurgeSource} from '../src/core/engines/purge-strategy.mjs';
|
||||
import {originalEngineRun} from '../src/shared/contracts/engine-execution.mjs';
|
||||
|
||||
const directory=path.resolve('.qa','original-purge-ui-'+randomUUID());fs.mkdirSync(directory,{recursive:true});
|
||||
const installation=resolveControlledInstallation(process.cwd(),process.env.AGENT_WORKBENCH_DEEPSEEK_ROOT);
|
||||
assert.equal(installation.controlledStatus,'available',installation.message);
|
||||
const originalSource=resolveOriginalPurgeSource(process.cwd(),process.env.AGENT_WORKBENCH_PURGE_178_ROOT,installation);assert.equal(originalSource.status,'available',originalSource.message);
|
||||
const copy=path.join(directory,'declared-source');fs.mkdirSync(copy);
|
||||
for(const input of originalSource.inputs){const target=path.join(copy,input.relative);fs.mkdirSync(path.dirname(target),{recursive:true});fs.copyFileSync(input.path,target);}
|
||||
const disposers=[],t={after:fn=>disposers.push(fn)},f=fixture(t),host=await workerHttp(f),owner=ownerBytes(f);
|
||||
f.store.saveConfig({contextLimit:64000});host.runtime.controlledEngines=new EngineRunner(f.store,host.provider,{directoryRoot:path.join(f.root,'owned-native-runs')});
|
||||
const hash=raw=>createHash('sha256').update(raw).digest('hex'),cases=[],screenshots=[],pageErrors=[],unexpectedFailures=[],closedNavigationStreams=[];
|
||||
const browser=await chromium.launch({channel:'msedge',headless:true}),page=await browser.newPage({viewport:{width:1440,height:1000},acceptDownloads:true});
|
||||
const eventStreams=new Set(),navigationStreams=new WeakSet();
|
||||
page.on('request',request=>{if(new URL(request.url()).pathname==='/api/events')eventStreams.add(request);});
|
||||
page.on('pageerror',error=>pageErrors.push(error.message));page.on('requestfailed',request=>{
|
||||
const error=request.failure()?.errorText,record={path:new URL(request.url()).pathname,error};
|
||||
if(navigationStreams.has(request)&&/ERR_ABORTED|ERR_INCOMPLETE_CHUNKED_ENCODING/.test(error??''))closedNavigationStreams.push(record);
|
||||
else unexpectedFailures.push(record);
|
||||
});
|
||||
const panel=()=>page.getByLabel('隔离协作控制台',{exact:true}),control=()=>panel().getByLabel('Purge 原版受限模式',{exact:true});
|
||||
const seal=()=>panel().getByRole('button',{name:'封存分工计划',exact:true});
|
||||
const mark=value=>{cases.push(value);console.log('PASS '+value);};
|
||||
async function screenshot(name){const file=path.join(directory,name+'.png');await page.screenshot({path:file,scale:'css'});screenshots.push({file,sha256:hash(fs.readFileSync(file))});}
|
||||
async function workers(){const close=page.getByRole('button',{name:'关闭检视区',exact:true});if(page.viewportSize().width<=940&&await close.isVisible())await close.click();
|
||||
await page.getByRole('button',{name:'隔离协作',exact:true}).click();await expect(panel()).toBeVisible();}
|
||||
async function detect(){await control().getByRole('button',{name:'检测 Purge 来源',exact:true}).click();await expect(control()).toContainText('已核对 Purge 1.1.78');}
|
||||
let report;
|
||||
try{
|
||||
await page.addInitScript(({projectId,sessionId})=>{localStorage.setItem('awb-project',projectId);localStorage.setItem('awb-session',sessionId);},{projectId:f.project.id,sessionId:f.session.id});
|
||||
await page.goto(host.url,{waitUntil:'networkidle'});await workers();await panel().getByLabel('执行方式',{exact:true}).selectOption('deepseek');
|
||||
await panel().getByLabel('Harness 安装目录',{exact:true}).fill(installation.root);await panel().getByRole('button',{name:'检测受控安装',exact:true}).click();await expect(panel()).toContainText('受控安装可用');
|
||||
await panel().getByLabel('父目标',{exact:true}).fill('核对原版 Purge 的真实加载与任务归属');await panel().getByLabel('任务名称',{exact:true}).fill('original-1');
|
||||
await panel().getByLabel('独立子目标',{exact:true}).fill('只在允许目录中提出修改,保留原审批与完整报告');await panel().getByLabel('允许修改的文件或目录',{exact:true}).fill('src/a.mjs');
|
||||
const promptControl=panel().getByLabel('Purge 提示实验',{exact:true});await expect(promptControl.getByRole('checkbox')).not.toBeChecked();
|
||||
await promptControl.getByRole('checkbox').check();await promptControl.getByLabel('Purge 执行模式',{exact:true}).selectOption('purge-original-restricted-v1');
|
||||
await expect(seal()).toBeDisabled();await expect(control()).toContainText('原版效果需另行实测');
|
||||
await control().getByLabel('Purge 源码目录',{exact:true}).fill(copy);await detect();await expect(seal()).toBeEnabled();
|
||||
await control().getByText('实验来源与执行范围',{exact:true}).click();await expect(control()).toContainText('Node 权限不等同于操作系统沙箱');
|
||||
await screenshot('original-purge-desktop-source');mark('desktop distinguishes the original restricted profile from the default-off independent prompt and detects complete fixed inputs');
|
||||
const before=f.store.core.task.size;fs.appendFileSync(path.join(copy,'lib/host.js'),'\n// owned post-detection drift\n');
|
||||
await seal().click();await expect(panel()).toContainText('原版来源或运行依赖与刚才的检测不一致');assert.equal(f.store.core.task.size,before);assert.equal(host.requests.length,0);
|
||||
fs.copyFileSync(path.join(originalSource.root,'lib/host.js'),path.join(copy,'lib/host.js'));await detect();
|
||||
await expect(panel()).not.toContainText('原版来源或运行依赖与刚才的检测不一致');mark('a changed original module outside the old nine-file lock refuses sealing and restoring/detecting clears obsolete feedback');
|
||||
await page.setViewportSize({width:390,height:844});await control().getByLabel('Purge 执行模式',{exact:true}).scrollIntoViewIfNeeded();
|
||||
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);const box=await control().getByLabel('Purge 执行模式',{exact:true}).boundingBox();assert.ok(box.height>=42);
|
||||
await screenshot('original-purge-mobile-source');await seal().click();await expect(panel()).toContainText('本计划的 Purge 原版受限模式');
|
||||
const group=[...f.store.core.collaboration.values()].at(-1),strategy=group.children[0].engine.strategy;assert.equal(strategy.kind,'purge-original-restricted-v1');
|
||||
assert.equal(strategy.source.inputs.length,60);assert.equal(strategy.runtime.nativeAddons.length,2);assert.equal(strategy.originalConfig.autoRetry,false);
|
||||
for(const request of eventStreams)navigationStreams.add(request);
|
||||
const reconnected=page.waitForResponse(response=>new URL(response.url()).pathname==='/api/events'&&response.status()===200);
|
||||
await page.reload({waitUntil:'networkidle'});await reconnected;await workers();await expect(panel()).toContainText(strategy.sha256.slice(0,16));mark('390px selection is usable and the persisted parent plan retains the original source, runtime and fixed configuration after refresh');
|
||||
await panel().getByRole('button',{name:'创建引擎工作区',exact:true}).click();await page.getByRole('dialog',{name:'确认创建隔离工作区',exact:true}).getByRole('button',{name:'确认创建',exact:true}).click();
|
||||
await expect(panel().getByRole('button',{name:'开始引擎任务',exact:true})).toBeEnabled({timeout:30000});
|
||||
await panel().getByRole('button',{name:'开始引擎任务',exact:true}).click();await page.getByRole('dialog',{name:'确认受限子执行',exact:true}).getByRole('button',{name:'确认开始',exact:true}).click();
|
||||
await expect.poll(()=>group.status,{timeout:60000}).toBe('awaiting_review');
|
||||
const job=[...f.store.core.engine_run.values()].at(-1),session=f.store.session(job.sessionId);assert.equal(job.status,'completed',job.error);assert.equal(job.native.cleanup.treeConfirmed,true);
|
||||
assert.equal(job.native.originalPurge.readiness.originalApplyCalled,true);assert.equal(job.native.originalPurge.nativeLoads.length,2);assert.deepEqual(ownerBytes(f),owner);
|
||||
await panel().getByRole('button',{name:'审查子任务改动',exact:true}).click();
|
||||
// Navigation loads the child asynchronously; wait for its inspector before
|
||||
// closing it, so a late navigation result cannot reopen it over the toolbar.
|
||||
await expect(panel()).toBeHidden();
|
||||
const close=page.getByRole('button',{name:'关闭检视区',exact:true});await expect(close).toBeVisible();await close.click();await expect(page.locator('aside.inspector')).toBeHidden();
|
||||
await page.getByRole('button',{name:'本地代理引擎',exact:true}).click();const runs=page.getByLabel('受控引擎工程运行',{exact:true});
|
||||
await expect(runs).toContainText('Purge 原版受限模式 · 1.1.78');await runs.getByText('查看本次实验策略',{exact:true}).click();await expect(runs).toContainText(strategy.runtime.sha256);
|
||||
const pending=page.waitForEvent('download');await runs.getByRole('button',{name:'下载完整报告',exact:true}).click();const download=await pending,file=path.join(directory,'original-engine-report.json');await download.saveAs(file);
|
||||
assert.equal(fs.readFileSync(file,'utf8'),originalEngineRun(f.store,session,job));assert.equal(hash(fs.readFileSync(file)),job.reportSha256);
|
||||
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);await screenshot('original-purge-mobile-run');mark('actual original Harness execution remains an owned Run and the UI downloads its byte-identical native loading, request and cleanup report');
|
||||
await page.setViewportSize({width:1440,height:1000});await screenshot('original-purge-desktop-run');assert.equal(pageErrors.length,0);assert.equal(unexpectedFailures.length,0);
|
||||
report={passed:true,directory,cases,screenshots,pageErrors,unexpectedFailures,closedNavigationStreams,group,job,realModelRequests:0,scope:'Compiled React UI, source HTTP host, actual Harness/original entry and declared Provider fixture. No real model benefit.'};
|
||||
}catch(error){process.exitCode=1;report={passed:false,directory,cases,screenshots,pageErrors,unexpectedFailures,closedNavigationStreams,error:error.stack,realModelRequests:0};}
|
||||
finally{await host.runtime.stopAll();await browser.close();f.store.storage.database.exec('PRAGMA wal_checkpoint(TRUNCATE)');
|
||||
fs.cpSync(f.root,path.join(directory,'original-fixture'),{recursive:true,filter:file=>!file.split(path.sep).includes('node_modules')});
|
||||
fs.writeFileSync(path.join(directory,'validation.json'),JSON.stringify(report,null,2));for(const dispose of disposers.reverse())await dispose();console.log(JSON.stringify({passed:report.passed,directory,cases:cases.length,error:report.error??null}));}
|
||||
Reference in New Issue
Block a user