| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import { expect, test } from "bun:test"
- import { mkdtemp, rm, writeFile, symlink } from "node:fs/promises"
- import { join } from "node:path"
- import { tmpdir } from "node:os"
- import { runtimeFiles, validateRuntimeBundle } from "./runtime-bundle"
- test("runtime manifest validates every dependency, not just its launcher", async () => {
- const root = await mkdtemp(join(tmpdir(), "runtime-manifest-"))
- try {
- await writeFile(join(root, process.platform === "win32" ? "agentpaas.exe" : "agentpaas"), "launcher")
- await writeFile(join(root, "dependency.bin"), "complete dependency")
- const manifest = { protocol: 1, platform: process.platform, arch: process.arch, files: await runtimeFiles(root) }
- await writeFile(join(root, "desktop-runtime.json"), JSON.stringify(manifest))
- await validateRuntimeBundle(root)
- await writeFile(join(root, "dependency.bin"), "truncated")
- await expect(validateRuntimeBundle(root)).rejects.toThrow("文件校验")
- await writeFile(join(root, "desktop-runtime.json"), JSON.stringify({ ...manifest, arch: "wrong" }))
- await expect(validateRuntimeBundle(root)).rejects.toThrow("不匹配")
- } finally {
- await rm(root, { recursive: true, force: true })
- }
- })
- test("runtime inventory rejects untracked files and external symlinks", async () => {
- const root = await mkdtemp(join(tmpdir(), "runtime-paths-"))
- try {
- await writeFile(join(root, "agentpaas"), "launcher")
- await writeFile(
- join(root, "desktop-runtime.json"),
- JSON.stringify({ protocol: 1, platform: process.platform, arch: process.arch, files: await runtimeFiles(root) }),
- )
- await writeFile(join(root, "unexpected.txt"), "extra")
- await expect(validateRuntimeBundle(root)).rejects.toThrow("文件校验")
- await symlink(join(root, "agentpaas"), join(root, "linked"))
- await expect(runtimeFiles(root)).rejects.toThrow("非普通文件")
- } finally {
- await rm(root, { recursive: true, force: true })
- }
- })
|