fix: identify source archive bytes after Git newline conversion

This commit is contained in:
Agent Workbench Dev
2026-11-06 09:34:36 +08:00
parent 2a6554cdc8
commit 3494ae7ab2
5 changed files with 39 additions and 3 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
## 单独发布源码
运行 `npm run package:source`。此命令直接从 Git 的已提交 HEAD 导出源码 ZIP,并保存来源提交、Git tree、文件清单和归档 SHA-256。未提交修改不进入该包。它不连接工作台服务、不读取用户数据目录、不要求先构建或安装程序,也不打包运行时和历次实验的原始证据。
运行 `npm run package:source`。此命令直接从 Git 的已提交 HEAD 导出源码 ZIP,并保存来源提交、Git tree、文件清单和归档 SHA-256。清单同时记录实际 ZIP 条目的字节与 SHA-256、原 Git blob 身份;Windows 启动脚本依照已提交的 `.gitattributes` 导出 CRLF 换行。未提交修改不进入该包。它不连接工作台服务、不读取用户数据目录、不要求先构建或安装程序,也不打包运行时和历次实验的原始证据。
源码包含产品源码、构建脚本、测试及夹具、锁定依赖、示例、许可证与文字说明。接收方使用 Node 24,执行 `npm ci`、`npm run build`,即可构建程序。需要实际外部引擎、Python 或历史证据的专项验收另行准备依赖,不把这些材料当成程序源码。
+2
View File
@@ -17,3 +17,5 @@
补充:发行专项完整串行 16/16 已通过,权限相关原轮 5 项均通过;第一个 21 项轮次的 1 项失败仍按原事实保留。首网页11/Electron12结果属于 fda264e4 对应的第一版显示,不能代签追加最大容量后的屏幕。
追加容量展示已完成构建第3/4轮,网页与实际Electron的1440/390四组定向验证通过:自有代理上游131072上下文/32768输出如实显示且不能编辑;手动换到无元数据型号时两项均显示本地无限制。最终网页再次验证0并发无限制连接的表单可正常保存,修复了原生number输入仍min=1的遗漏。源码导出也先按允许路径筛选再核对Git blob大小,避免扫描历史证据的blob元数据;两项源码归档专项再次通过。准备冻结第二候选,正式升级尚未进行。
独立源码归档核对发现真实遗漏:git archive 会按 .gitattributes 将6个 Windows 启动脚本导出为 CRLF,首两份源码清单却只记录原 Git blob 的字节数。旧 ZIP/清单及失败日志保留,不冒称通过。现从实际 ZIP 条目记录长度及 SHA-256,同时保留原 gitBytes/gitBlob;新增带 CRLF 规则的实际 Git 归档验证,两项通过。此修复仅涉及发布/验证脚本和说明,产品源码及22份编译不变,因此不重制已经冻结的第二份程序包。最终程序来源为2a6554cd,源码发布工具修复另行提交并导出,再独立重建逐文件比对。
+26 -1
View File
@@ -3,6 +3,7 @@ import path from 'node:path';
import { execFileSync } from 'node:child_process';
import { createHash, randomUUID } from 'node:crypto';
import { fileURLToPath } from 'node:url';
import { inflateRawSync } from 'node:zlib';
// Export the committed program. No running host, user data directory, installed
// application, credentials, build output or historical evidence is consulted.
@@ -12,6 +13,24 @@ const files = ['package.json', 'package-lock.json', 'vite.config.ts', 'tsconfig.
'Start-Workbench.cmd', 'Stop-Workbench.cmd', 'Start-Desktop.cmd'];
const guide = name => /^docs\/[^/]+\.md$/.test(name) || /^docs\/research\/[^/]+\.(?:md|json)$/.test(name);
function archivedFiles(file) {
const buffer = fs.readFileSync(file), end = buffer.lastIndexOf(Buffer.from([0x50, 0x4b, 0x05, 0x06]));
if (end < 0) throw new Error('Source ZIP directory is missing.');
const count = buffer.readUInt16LE(end + 10), result = new Map(); let offset = buffer.readUInt32LE(end + 16);
for (let index = 0; index < count; index++) {
if (buffer.readUInt32LE(offset) !== 0x02014b50) throw new Error('Invalid source ZIP entry.');
const length = buffer.readUInt16LE(offset + 28), name = buffer.subarray(offset + 46, offset + 46 + length).toString('utf8');
const local = buffer.readUInt32LE(offset + 42), start = local + 30 + buffer.readUInt16LE(local + 26) + buffer.readUInt16LE(local + 28);
const compressed = buffer.subarray(start, start + buffer.readUInt32LE(offset + 20)), method = buffer.readUInt16LE(offset + 10);
if (![0, 8].includes(method) || result.has(name)) throw new Error('Unsupported or duplicate source ZIP entry.');
const bytes = method === 8 ? inflateRawSync(compressed) : compressed;
if (bytes.length !== buffer.readUInt32LE(offset + 24)) throw new Error('Source ZIP entry length mismatch.');
if (!name.endsWith('/')) result.set(name, bytes);
offset += 46 + length + buffer.readUInt16LE(offset + 30) + buffer.readUInt16LE(offset + 32);
}
return result;
}
export function packageSource({ root = process.cwd(), outputRoot = path.join(root, 'releases') } = {}) {
root = path.resolve(root); outputRoot = path.resolve(outputRoot);
const git = args => execFileSync('git', args, { cwd: root, windowsHide: true, maxBuffer: 32 * 1024 * 1024 });
@@ -35,9 +54,15 @@ export function packageSource({ root = process.cwd(), outputRoot = path.join(roo
const archive = path.join(outputRoot, name + '.zip'), fd = fs.openSync(archive, 'wx');
try { execFileSync('git', ['archive', '--format=zip', '--prefix=Agent-Workbench-' + version + '-source/', sourceCommit, '--', ...roots], { cwd: root, windowsHide: true, stdio: ['ignore', fd, 'pipe'] }); }
finally { fs.closeSync(fd); }
const archived = archivedFiles(archive), prefix = 'Agent-Workbench-' + version + '-source/';
if (archived.size !== entries.length) throw new Error('Source ZIP file scope differs from the selected committed tree.');
const exported = entries.map(row => {
const bytes = archived.get(prefix + row.path); if (!bytes) throw new Error('Committed source missing from ZIP: ' + row.path);
return { path: row.path, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex'), gitBytes: row.bytes, gitBlob: row.gitBlob };
});
const result = { kind: 'source-code', version, sourceCommit, sourceTree: git(['rev-parse', sourceCommit + '^{tree}']).toString().trim(),
path: archive, bytes: fs.statSync(archive).size, sha256: createHash('sha256').update(fs.readFileSync(archive)).digest('hex'),
createdAt: new Date().toISOString(), files: entries.map(({ path, bytes, gitBlob }) => ({ path, bytes, gitBlob })),
createdAt: new Date().toISOString(), files: exported, archiveAttributes: 'git archive applies committed .gitattributes, including CRLF for Windows launch scripts; bytes/sha256 identify exported ZIP bytes, gitBytes/gitBlob identify original committed blobs.',
scope: 'Committed program, build scripts, tests, examples, dependency lock, licenses and text guides. No user projects, sessions, API credentials, installed runtimes or historical evidence archives. Build with Node 24, npm ci and npm run build. Historical acceptance drivers may require separately retained evidence or external engines.' };
fs.writeFileSync(path.join(outputRoot, name + '.json'), JSON.stringify(result, null, 2) + '\n', { flag: 'wx' });
return result;
+1 -1
View File
@@ -45,7 +45,7 @@ with zipfile.ZipFile(archive) as bundle:
assert not relative.is_absolute() and '..' not in relative.parts
contents=bundle.read(top+'/'+item['path'])
assert len(contents)==item['bytes']
if manifest['kind']=='source-code':
if manifest['kind']=='source-code' and 'sha256' not in item:
assert hashlib.sha1(b'blob '+str(len(contents)).encode()+b'\\0'+contents).hexdigest()==item['gitBlob']
item['sha256']=hashlib.sha256(contents).hexdigest()
else:
+9
View File
@@ -5,6 +5,7 @@ import os from 'node:os';
import path from 'node:path';
import { execFileSync } from 'node:child_process';
import { inflateRawSync } from 'node:zlib';
import { createHash } from 'node:crypto';
import { packageSource } from '../scripts/package-source.mjs';
import { createProgramGuides } from '../scripts/documentation-bundle.mjs';
@@ -30,6 +31,7 @@ test('source ZIP exports committed program bytes without runtime, user data, dir
const git = args => execFileSync('git', args, { cwd: root, windowsHide: true, encoding: 'utf8' }).trim();
git(['init']);
write('package.json', JSON.stringify({ name: 'owned-source', version: '1.25.6' })); write('package-lock.json', '{}\n');
write('.gitattributes', '*.cmd text eol=crlf\n'); write('Start-Workbench.cmd', '@echo off\necho owned\n');
const original = Buffer.from('\ufeff// 中文原字节\r\nexport const value = 42;\r\n'); write('src/中文.mjs', original);
for (const name of ['scripts/build.mjs', 'tests/owned.test.mjs', 'docs/PACKAGING.md', 'docs/research/NOTES.md']) write(name, 'Committed guide or code\n');
for (const name of ['data/workbench.sqlite', '.data/session.json', '.env', 'dist-client/index.html', 'runtime/node.exe', 'docs/historical-evidence/raw.json']) write(name, 'OWNED-EXCLUDED-CANARY');
@@ -39,6 +41,13 @@ test('source ZIP exports committed program bytes without runtime, user data, dir
const result = packageSource({ root }), entries = zipFiles(result.path), prefix = 'Agent-Workbench-1.25.6-source/';
assert.equal(result.sourceCommit, commit); assert.equal(result.version, '1.25.6');
assert.deepEqual(entries.get(prefix + 'src/中文.mjs'), original);
const launcher = entries.get(prefix + 'Start-Workbench.cmd'), declaredLauncher = result.files.find(row => row.path === 'Start-Workbench.cmd');
assert.equal(launcher.toString(), '@echo off\r\necho owned\r\n');
assert.equal(declaredLauncher.bytes, launcher.length); assert.ok(declaredLauncher.gitBytes < declaredLauncher.bytes);
for (const row of result.files) {
const archived = entries.get(prefix + row.path); assert.equal(row.bytes, archived.length);
assert.equal(row.sha256, createHash('sha256').update(archived).digest('hex'));
}
assert.ok(entries.has(prefix + 'package-lock.json')); assert.ok(entries.has(prefix + 'docs/PACKAGING.md'));
assert.equal([...entries.keys()].some(name => /(?:sqlite|session\.json|\.env|dist-client|runtime|historical-evidence|untracked)/.test(name)), false);
for (const value of entries.values()) assert.equal(value.includes('OWNED-EXCLUDED-CANARY'), false);