47 lines
3.7 KiB
JavaScript
47 lines
3.7 KiB
JavaScript
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))}));
|