chore: establish YCode replication baseline and TODO

This commit is contained in:
xiaohan.yuan committed 2026-10-17 02:43:49 +08:00
commit 6dc59f89ba
1118 files changed
+196002

No files matched your search

@@ -0,0 +1,30 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import assert from 'node:assert/strict'
import crypto from 'node:crypto'
import {spawnSync} from 'node:child_process'
const root=await fs.mkdtemp(path.resolve('.tmp/rea-cpp-directory-fixture-')),target=path.join(root,'target'),checks=[]
await fs.mkdir(path.join(target,'agents'),{recursive:true})
const files={'plugin.json':'{"name":"cpp-fixture","agents":["agents/cpp.md"]}\n','agents/cpp.md':'---\nname: cpp\n---\n# 测试专家\n','schema.yml':'name: cpp\n','tool.py':'# Never execute retained text\n'}
for(const[p,text]of Object.entries(files))await fs.writeFile(path.join(target,p),text)
function cli(command,args){return spawnSync(process.execPath,['.tmp/rea-css-runtime/scripts/rea.mjs',command,...args],{encoding:'utf8',maxBuffer:32*1024*1024})}
function inspect(dir=target){const r=cli('inspect-selected-directory-text-root',[dir]);assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout)}
function exportText(pin,paths,dir=target){return cli('export-selected-directory-text',[dir,pin,JSON.stringify(paths)])}
function reject(label,r,pattern){assert.notEqual(r.status,0,label);assert.match(r.stderr,pattern,label);checks.push({label,pass:true})}
let inventory=inspect(),pin=inventory.normalized_result.root_sha256
const analysis=cli('analyze-javascript-application',[target,'--source-path','plugin.json','--json']);assert.equal(analysis.status,0,analysis.stderr);assert.equal(JSON.parse(analysis.stdout).normalized_result.root_artifact_sha256,pin);checks.push({label:'new provider pin equals public REA analyzer canonical directory SHA',pass:true})
let r=exportText(pin,Object.keys(files));assert.equal(r.status,0,r.stderr);const evidence=JSON.parse(r.stdout)
assert.deepEqual(evidence.normalized_result.files.map(f=>f.path),Object.keys(files));for(const f of evidence.normalized_result.files){assert.equal(f.text,files[f.path]);assert.equal(f.sha256,crypto.createHash('sha256').update(files[f.path]).digest('hex'))}checks.push({label:'exact selected bytes/SHA and UTF-8 source text exported through public CLI',pass:true})
reject('incorrect root pin',exportText('0'.repeat(64),['plugin.json']),/root SHA mismatch/)
reject('traversal selection',exportText(pin,['../plugin.json']),/canonical/)
reject('unsupported selection',exportText(pin,['private.db']),/canonical/)
reject('duplicate selection',exportText(pin,['plugin.json','plugin.json']),/Duplicate/)
reject('absent member',exportText(pin,['agents/absent.md']),/absent/)
await fs.writeFile(path.join(target,'bad.md'),Buffer.from([0xc3,0x28]));const bad=inspect().normalized_result.root_sha256;reject('strict UTF-8 rejects invalid selected bytes',exportText(bad,['bad.md']),/strict UTF-8/)
reject('mutable content invalidates old root pin',exportText(pin,['plugin.json']),/root SHA mismatch/)
await fs.writeFile(path.join(target,'large.md'),Buffer.alloc(8*1024*1024+1,97));const large=inspect().normalized_result.root_sha256;reject('per-file text budget',exportText(large,['large.md']),/text byte budget/)
await fs.rm(path.join(target,'large.md'));for(const p of['one.md','two.md'])await fs.writeFile(path.join(target,p),Buffer.alloc(8*1024*1024,97));await fs.writeFile(path.join(target,'extra.txt'),'x');const aggregate=inspect().normalized_result.root_sha256;reject('aggregate text budget',exportText(aggregate,['one.md','two.md','extra.txt']),/text byte budget/)
const outside=path.join(root,'outside');await fs.mkdir(outside);await fs.writeFile(path.join(outside,'secret.md'),'outside-source-not-exported')
await fs.symlink(outside,path.join(root,'root-link'),'junction');reject('symlink root rejected',cli('inspect-selected-directory-text-root',[path.join(root,'root-link')]),/symlink ancestors/)
await fs.symlink(outside,path.join(target,'link'),'junction');const linked=inspect().normalized_result.root_sha256;reject('symlink descendant never followed',exportText(linked,['link/secret.md']),/absent/)
await fs.writeFile(path.join(root,'report.json'),JSON.stringify({result:'PASS',checks,evidenceId:evidence.evidence_id,pin},null,2));await fs.writeFile(path.join(root,'export-evidence.json'),JSON.stringify(evidence,null,2));console.log(JSON.stringify({result:'PASS',root,checks:checks.length,evidenceId:evidence.evidence_id}))