为各角色配置私有临时目录并限制报告桥文件范围
This commit is contained in:
parent
079d0aaaca
commit
905bc678cd
@ -1,3 +1,4 @@
|
||||
import { workerEnvironment, workspace } from "./workspace.js";
|
||||
import { captureFrozen, assertFrozen } from "./frozen.js";
|
||||
import { Agent } from "@earendil-works/pi-agent-core";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
@ -395,10 +396,11 @@ export class Engine {
|
||||
}),
|
||||
{ mode: 0o600 },
|
||||
);
|
||||
const workspaceEnv = workerEnvironment(cwd);
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[join(here, "supervisor.js"), join(root, "spec.json")],
|
||||
{ detached: true, stdio: "ignore", env: process.env },
|
||||
{ detached: true, stdio: "ignore", env: { ...process.env, ...workspaceEnv } },
|
||||
);
|
||||
child.unref();
|
||||
r.pid = child.pid ?? null;
|
||||
@ -431,6 +433,7 @@ export class Engine {
|
||||
root: await g.api(`/issues/${t.issueNumber}`),
|
||||
rootComments: await g.pages(`/issues/${t.issueNumber}/comments`),
|
||||
frozenAcceptance: this.store.frozen(t.id),
|
||||
workspace: workspace(r.cwd),
|
||||
run: {
|
||||
id: r.id,
|
||||
role: r.role,
|
||||
@ -690,7 +693,7 @@ export class Engine {
|
||||
const resumed = spawn(
|
||||
process.execPath,
|
||||
[join(here, "supervisor.js"), specPath],
|
||||
{ detached: true, stdio: "ignore", env: process.env },
|
||||
{ detached: true, stdio: "ignore", env: { ...process.env, ...workerEnvironment(r.cwd) } },
|
||||
);
|
||||
resumed.unref();
|
||||
r.pid = resumed.pid ?? null;
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { workerEnvironment, workspacePrompt } from "./workspace.js";
|
||||
import { spawn, execFileSync } from "node:child_process";
|
||||
import {
|
||||
readFileSync,
|
||||
@ -12,6 +13,8 @@ import { redact, Gitea, secrets } from "./gitea.js";
|
||||
import { Store } from "./store.js";
|
||||
const specPath = process.argv[2];
|
||||
const spec = JSON.parse(readFileSync(specPath, "utf8"));
|
||||
const workspaceEnv = workerEnvironment(spec.cwd);
|
||||
const prompt = spec.prompt + workspacePrompt(spec.cwd);
|
||||
// Load redaction values locally; the worker never receives the model/Gitea secret in its environment.
|
||||
secrets.add(spec.token);
|
||||
const cfg = config();
|
||||
@ -87,6 +90,7 @@ try {
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
env: {
|
||||
...process.env,
|
||||
...workspaceEnv,
|
||||
PPANEL_WORKER_TOKEN: spec.token,
|
||||
PPANEL_WORKER_RUN: spec.runId,
|
||||
PPANEL_URL: spec.url,
|
||||
@ -139,7 +143,7 @@ try {
|
||||
);
|
||||
await rpc.request("turn/start", {
|
||||
threadId,
|
||||
input: [{ type: "text", text: spec.prompt }],
|
||||
input: [{ type: "text", text: prompt }],
|
||||
});
|
||||
const result = await Promise.race([
|
||||
complete,
|
||||
@ -166,7 +170,7 @@ try {
|
||||
}
|
||||
} catch {}
|
||||
});
|
||||
child.stdin!.end(spec.prompt);
|
||||
child.stdin!.end(prompt);
|
||||
const code = await exited;
|
||||
if (code !== 0) throw new Error(`执行进程退出 ${code}`);
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { reportFile } from "./workspace.js";
|
||||
import { readFileSync } from "node:fs";
|
||||
const [action, file, conclusion, headSha, baseSha, ...links] =
|
||||
process.argv.slice(2);
|
||||
@ -6,15 +7,18 @@ const url = process.env.PPANEL_URL,
|
||||
token = process.env.PPANEL_WORKER_TOKEN;
|
||||
if (!url || !run || !token) throw new Error("此桥只能在受控执行会话中使用");
|
||||
let body: unknown;
|
||||
const reportPath = action === "report" || action === "pr"
|
||||
? reportFile(file, process.env.PPANEL_RUN_ROOT ?? (() => { throw new Error("缺少本角色运行目录"); })())
|
||||
: "";
|
||||
if (action === "report")
|
||||
body = {
|
||||
body: readFileSync(file, "utf8"),
|
||||
body: readFileSync(reportPath, "utf8"),
|
||||
conclusion,
|
||||
headSha,
|
||||
baseSha,
|
||||
evidenceLinks: links,
|
||||
};
|
||||
else if (action === "pr") body = { body: readFileSync(file, "utf8") };
|
||||
else if (action === "pr") body = { body: readFileSync(reportPath, "utf8") };
|
||||
else if (action !== "read")
|
||||
throw new Error(
|
||||
"用法:read | pr 中文报告.md | report 中文报告.md pass|changes_requested|failed HEAD BASE 证据URL...",
|
||||
|
||||
25
apps/server/src/workspace.ts
Normal file
25
apps/server/src/workspace.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { mkdirSync, realpathSync } from "node:fs";
|
||||
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
||||
|
||||
export function workspace(cwd: string) {
|
||||
const root = dirname(resolve(cwd));
|
||||
const temp = join(root, "tmp");
|
||||
return { root, temp, report: join(temp, "report.md") };
|
||||
}
|
||||
export function workerEnvironment(cwd: string) {
|
||||
const { root, temp, report } = workspace(cwd);
|
||||
mkdirSync(temp, { recursive: true, mode: 0o700 });
|
||||
return { TMPDIR: temp, TMP: temp, TEMP: temp,
|
||||
PPANEL_RUN_ROOT: root, PPANEL_REPORT_PATH: report };
|
||||
}
|
||||
export function workspacePrompt(cwd: string) {
|
||||
const { root, temp, report } = workspace(cwd);
|
||||
return `\n\n本角色运行目录:${root}。所有临时报告、脚本、测试输出和临时目录必须放在 ${temp} 内;报告建议写到 ${report}。使用 TMPDIR/TMP/TEMP,不要硬编码共享 /tmp、/var/tmp 或 /private/tmp,不要访问其他角色目录。业务代码仅在 ${resolve(cwd)} 工作。此约束是协作规则,不是操作系统沙箱。`;
|
||||
}
|
||||
export function reportFile(file: string, root: string) {
|
||||
const path = realpathSync(file);
|
||||
const rel = relative(realpathSync(root), path);
|
||||
if (rel === ".." || rel.startsWith("../") || isAbsolute(rel))
|
||||
throw new Error("报告文件必须位于本角色运行目录内");
|
||||
return path;
|
||||
}
|
||||
30
apps/server/test/workspace.test.ts
Normal file
30
apps/server/test/workspace.test.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtempSync, writeFileSync, symlinkSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { workerEnvironment, workspacePrompt, reportFile } from "../src/workspace.js";
|
||||
|
||||
test("private temp paths remain stable across restart and reject foreign reports", () => {
|
||||
const base = mkdtempSync(join(tmpdir(), "ppanel-workspace-"));
|
||||
const a = workerEnvironment(join(base, "developer", "run1", "repo"));
|
||||
const b = workerEnvironment(join(base, "qa", "run2", "repo"));
|
||||
assert.notEqual(a.TMPDIR, b.TMPDIR);
|
||||
assert.deepEqual(workerEnvironment(join(base, "developer", "run1", "repo")), a);
|
||||
assert.equal(a.TMP, a.TEMP);
|
||||
assert.equal(a.TMP, a.TMPDIR);
|
||||
const observed = JSON.parse(execFileSync(process.execPath, ["-e",
|
||||
"console.log(JSON.stringify({temp:require('node:os').tmpdir(),report:process.env.PPANEL_REPORT_PATH}))"],
|
||||
{ env: { ...process.env, ...a }, encoding: "utf8" }));
|
||||
assert.equal(observed.temp, a.TMPDIR);
|
||||
assert.equal(observed.report, a.PPANEL_REPORT_PATH);
|
||||
writeFileSync(a.PPANEL_REPORT_PATH, "report");
|
||||
writeFileSync(b.PPANEL_REPORT_PATH, "foreign");
|
||||
assert.ok(reportFile(a.PPANEL_REPORT_PATH, a.PPANEL_RUN_ROOT));
|
||||
assert.throws(() => reportFile(b.PPANEL_REPORT_PATH, a.PPANEL_RUN_ROOT));
|
||||
const link = join(a.TMPDIR, "foreign.md");
|
||||
symlinkSync(b.PPANEL_REPORT_PATH, link);
|
||||
assert.throws(() => reportFile(link, a.PPANEL_RUN_ROOT));
|
||||
assert.ok(workspacePrompt(join(base, "developer", "run1", "repo")).includes(a.PPANEL_REPORT_PATH));
|
||||
});
|
||||
@ -77,3 +77,11 @@ npm test --prefix apps/server
|
||||
原样 20 场景现在全部通过,17 项后端测试通过。正在提交和 push,稍后回报固定 SHA。真实 Git clone、SQLite、HTTP 路径运行;进程启动和远端 API 为验收程序明确注入,不宣称真实模型或最终验收通过。
|
||||
|
||||
验证命令:`npm test --prefix apps/server`、`npm run build --prefix apps/server`、`node .ppanel/qa19-a07/check.mjs "$PWD" all`。固定程序 SHA-256:1771686fd3f002d3def46c574b3cc841dbb0294d98138b50b043ffcc96fb6fd1。完整日志保留于本 clone .ppanel/qa19-a07/{before,after,unit}.log。旧 queued 记录不推断为未启动;克隆或启动意图后的异常仍需恢复诊断。
|
||||
|
||||
## A05 私有临时目录修复(Issue #6 评论 #18563)
|
||||
|
||||
每个 run 使用原有运行根目录下的 tmp,启动 supervisor 及其 pi/OpenCode/Codex 子进程时覆盖 TMPDIR/TMP/TEMP,同时提供 PPANEL_RUN_ROOT、PPANEL_REPORT_PATH。所有实际发送的启动/续报提示都附带绝对私有路径及禁止共享临时目录的规则;worker read 返回 root/temp/report,pr/report 桥通过 realpath 拒绝越界报告和符号链接。路径由原 cwd 推导,不改变 run/session 身份;既有运行不原地迁移,未操作 #29。
|
||||
|
||||
验证:typecheck、build、18 项测试通过;新增真实 Node 子进程读取 os.tmpdir/env,检查两个运行路径不同、重建路径稳定、报告及符号链接边界。原样 8dcf3a4 的 20 场景程序通过。完整输出保留于当前 clone .ppanel/a05-tests.log 和 .ppanel/a05-control-plane.log。
|
||||
|
||||
限制:这是环境和提示约束及报告桥校验,不是 OS 沙箱;任意 shell 仍具本机权限。未执行三个真实模型 runtime 路径探针,未声称模型遵从或最终 A05 通过。旧进程无需迁移,由独立 CR/QA 在新 SHA 继续验证。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user