fix(sandbox): 子进程环境保留 PATH,编译产物里沙箱任务恢复;编译自检加沙箱启动
清空环境后编译产物在入口按 PATH 解析 --allow-run 失败直接退出,Bangumi 热门、字幕验证码 / 解压等沙箱任务一直报错。 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
1 parent
0d796d92ef
commit
3f1c6d02f6
3 files changed
+27
-4
No files matched your search
@@ -1,13 +1,19 @@
|
||||
import { buildFakeTorrent, RAR5_SAMPLE_BASE64, SEVENZIP_SUBTITLE_BASE64, ZIMUKU_CAPTCHA } from "@umt/testkit";
|
||||
import { zipSync } from "fflate";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runSandbox, SandboxError } from "../../src/sandbox/client.ts";
|
||||
import { runSandbox, SandboxError, sandboxEnv } from "../../src/sandbox/client.ts";
|
||||
import { b64encode } from "../../src/sandbox/jobs.ts";
|
||||
|
||||
// 沙箱(docs/adr/ADR-005-sandbox.md):子进程撤销全部权限;卡死超时强杀;内存超限强杀;任务错误原样带回
|
||||
const enc = (s: string) => new TextEncoder().encode(s);
|
||||
|
||||
describe("沙箱子进程", () => {
|
||||
it("子进程环境只带 PATH(编译产物入口要按 PATH 解析 --allow-run 的命令名,没有会直接退出)", () => {
|
||||
const env = sandboxEnv();
|
||||
expect(Object.keys(env)).toEqual(["PATH"]);
|
||||
expect(env.PATH).toBeTruthy();
|
||||
});
|
||||
|
||||
it("正常返回;子进程里读文件被拒绝", async () => {
|
||||
expect(await runSandbox("self.test", { mode: "ok" })).toEqual({ ok: true });
|
||||
await expect(runSandbox("self.test", { mode: "io" })).rejects.toMatchObject({ kind: "job", message: /NotCapable/ });
|
||||
|
||||
Reference in new issue
Block a user