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
+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);