Files
cindy/scripts/__tests__/remote-bundle-inputs.test.mjs
Lizi 8f651cf80d feat(agent-net): 接通独立中转与桌面手机完整业务路径
为自建和本机中转接入独立 V2 身份、配对、加密传输及既有 Device Link 业务。
共享任务和供应商分享固定私有来源,保留 V1 兼容,补齐执行电脑、媒体、恢复和账号边界。
手机接入原生签名、UDP、发现、加密通知和按需视频;宿主与 CLI 支持运营者的推送桥。
加入原生 CI、部署接线与验证记录;生产部署和真机推送验收另按交接手册执行。

验证:Desktop Main 458 项、相关 Device Link 422 项、Mobile 122 项、原生 SDK 27 项、内核 31 项通过。
iOS/Android 原生构建与系统视频探针通过;类型、多语言、定向深浅色 UI 与测试卫生检查通过。
全分支 UI 关联构建因资源增长终止;已记录定向覆盖和未完成的目标环境验收。

Assisted-by: Cindy (https://cindy.app)
Signed-off-by: Lizi <jiali@magiclizi.com>
2026-11-08 02:03:35 +08:00

95 lines
4.3 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
import { bundleInputDigest, bundleInputsMatch, recordBundleInputs } from '../../apps/desktop/scripts/remote-bundle-inputs.mjs';
function fixture(run) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-remote-bundle-inputs-'));
const write = (name, seconds) => {
const file = path.join(root, name);
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, 'fixture');
fs.utimesSync(file, seconds, seconds);
};
try { run(root, write); } finally { fs.rmSync(root, { recursive: true, force: true }); }
}
function cache(root, write) {
write('proxy/src/index.ts', 1000);
write('compat/src/keep.ts', 1000);
write('compat/src/remove.ts', 1000);
write('proxy/dist/proxy.mjs', 9000);
const bundle = path.join(root, 'proxy/dist/proxy.mjs');
const digest = () => bundleInputDigest(path.join(root, 'proxy'), [path.join(root, 'compat')]);
recordBundleInputs(bundle, digest());
assert.equal(bundleInputsMatch(bundle, digest()), true);
return { bundle, digest };
}
test('deleting dependency source invalidates a newer cached bundle', () => fixture((root, write) => {
const { bundle, digest } = cache(root, write);
fs.unlinkSync(path.join(root, 'compat/src/remove.ts'));
assert.equal(bundleInputsMatch(bundle, digest()), false);
}));
test('consumer source removal and renaming invalidate even with unchanged contents', () => fixture((root, write) => {
const { bundle, digest } = cache(root, write);
fs.renameSync(path.join(root, 'proxy/src/index.ts'), path.join(root, 'proxy/src/renamed.ts'));
assert.equal(bundleInputsMatch(bundle, digest()), false);
recordBundleInputs(bundle, digest());
fs.unlinkSync(path.join(root, 'proxy/src/renamed.ts'));
assert.equal(bundleInputsMatch(bundle, digest()), false);
}));
test('content changes with preserved old timestamps invalidate', () => fixture((root, write) => {
const { bundle, digest } = cache(root, write);
const file = path.join(root, 'compat/src/keep.ts');
fs.writeFileSync(file, 'changed');
fs.utimesSync(file, 1000, 1000);
assert.equal(bundleInputsMatch(bundle, digest()), false);
}));
test('license changes invalidate, generated output and timestamp-only changes do not', () => fixture((root, write) => {
const { bundle, digest } = cache(root, write);
write('compat/dist/generated.js', 10000);
fs.utimesSync(path.join(root, 'compat/src/keep.ts'), 11000, 11000);
assert.equal(bundleInputsMatch(bundle, digest()), true);
write('compat/LICENSE.opencodex', 1000);
assert.equal(bundleInputsMatch(bundle, digest()), false);
}));
test('missing/corrupt receipts and changed output rebuild; only recorded successful output is fresh', () => fixture((root, write) => {
const { bundle, digest } = cache(root, write);
fs.unlinkSync(`${bundle}.inputs.json`);
assert.equal(bundleInputsMatch(bundle, digest()), false);
for (const invalid of ['{broken', 'null', '{}']) {
fs.writeFileSync(`${bundle}.inputs.json`, invalid);
assert.equal(bundleInputsMatch(bundle, digest()), false);
}
recordBundleInputs(bundle, digest());
fs.writeFileSync(bundle, 'partial failed build');
assert.equal(bundleInputsMatch(bundle, digest()), false);
recordBundleInputs(bundle, digest());
assert.equal(bundleInputsMatch(bundle, digest()), true);
fs.unlinkSync(bundle);
assert.equal(bundleInputsMatch(bundle, digest()), false);
}));
test('missing declared dependency fails instead of accepting stale output', () => fixture((root, write) => {
write('proxy/src/index.ts', 1000);
assert.throws(() => bundleInputDigest(path.join(root, 'proxy'), [path.join(root, 'missing')]), /dependency is missing/);
}));
// Build-input integrity: changing the Rust ABI/dependency manifest must not reuse old WASM.
// Existing TS-only cache cases cannot detect Cargo-only changes; unit, temporary files, <1s.
test('Rust package and ABI manifests invalidate the staged WASM even when timestamps are preserved', () => fixture((root, write) => {
const { bundle, digest } = cache(root, write);
for (const file of ['proxy/Cargo.toml', 'proxy/Cargo.lock', 'compat/Cargo.toml']) {
recordBundleInputs(bundle, digest());
write(file, 1000);
assert.equal(bundleInputsMatch(bundle, digest()), false);
}
}));