Files
boss/tests/boss-agent-ota-asset.test.ts
2026-05-17 02:20:08 +08:00

52 lines
1.9 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { createHash } from "node:crypto";
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
function sha256(value: string) {
return createHash("sha256").update(value).digest("hex");
}
test("boss-agent ota asset reader exposes published mac package metadata", async () => {
const runtimeRoot = await mkdtemp(path.join(os.tmpdir(), "boss-agent-ota-asset-"));
const downloads = path.join(runtimeRoot, "public", "downloads");
await mkdir(downloads, { recursive: true });
const archive = "boss agent zip";
const hash = sha256(archive);
await writeFile(path.join(downloads, "boss-agent-mac-latest.zip"), archive, "utf8");
await writeFile(
path.join(downloads, "boss-agent-mac-latest.json"),
JSON.stringify({
version: "20260516194026",
fileName: "boss-agent-mac-latest.zip",
sizeBytes: Buffer.byteLength(archive),
sha256: hash,
updatedAt: "2026-05-16T11:40:26.000Z",
downloadUrl: "/api/v1/boss-agent/ota/package",
}),
"utf8",
);
const previousRoot = process.env.BOSS_RUNTIME_ROOT;
process.env.BOSS_RUNTIME_ROOT = runtimeRoot;
try {
const otaModule = await import(`../src/lib/boss-agent-ota.ts?asset=${Date.now()}`);
const asset = await otaModule.getPublishedBossAgentOtaAsset();
assert.ok(asset);
assert.equal(asset.version, "20260516194026");
assert.equal(asset.fileName, "boss-agent-mac-latest.zip");
assert.equal(asset.sizeBytes, Buffer.byteLength(archive));
assert.equal(asset.sha256, hash);
assert.equal(asset.downloadUrl, "/api/v1/boss-agent/ota/package");
} finally {
if (previousRoot === undefined) {
delete process.env.BOSS_RUNTIME_ROOT;
} else {
process.env.BOSS_RUNTIME_ROOT = previousRoot;
}
await rm(runtimeRoot, { recursive: true, force: true });
}
});