import path from "node:path"; import { fileURLToPath } from "node:url"; import { SafeWorkspace } from "../packages/harness/src/workspace.js"; import { createPptTools, validatedPpt } from "../packages/harness/src/ppt-tools.js"; import { saveTask, updateTask } from "../packages/harness/src/task.js"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const workspace = await SafeWorkspace.create(path.join(root, "workspace/sessions"), `ppt-test-${Date.now()}`); // Explicit stub: verifies generation/plumbing, not model review quality. const tools = createPptTools(workspace, root, async () => ({ passed: true, reasons: [] })); await saveTask(workspace, updateTask(undefined, "生成测试 PPT", "verification-run")!); if (process.argv.includes("--template")) { const inspected = await tools[0]!.execute("inspect-test", {}, undefined, undefined, {} as never); const records = String(inspected.details.snapshot).split("\n").filter(Boolean).map(line => JSON.parse(line)); const first = records.find(r => r.kind === "textbox" && r.text && r.text.length > 2 && r.text.length < 50); if (!first) throw new Error("NO_TEMPLATE_TEXT"); const table = records.find(r => r.kind === "table"); const output = await tools[1]!.execute("template-test", { title: "模板验证副本", template: "swads", replacements: [{ id: first.id, oldText: first.text, newText: "模板验证" }], tableCells: table ? [{ id: table.id, row: 1, column: 0, text: "测试竞品" }] : [] }, undefined, undefined, {} as never); console.log(JSON.stringify({ ...output.details, directory: workspace.resolve(`presentations/${output.details.artifactId}`) })); try { await validatedPpt(workspace, output.details.artifactId); throw new Error("DEBUG_WAS_ACCEPTED"); } catch (e) { if (!(e instanceof Error) || e.message !== "PPT_NOT_ACCEPTED") throw e; } try { await tools[1]!.execute("partial-final-test", { purpose: "final", title: "局部替换不可交付", template: "swads", replacements: [{ id: first.id, oldText: first.text, newText: "局部测试" }] }, undefined, undefined, {} as never); throw new Error("PARTIAL_WAS_ACCEPTED"); } catch (e) { if (!(e instanceof Error) || !e.message.includes("PPT_CONTENT_REJECTED")) throw e; } console.log("PASS: debug download rejected; partial final rejected"); process.exit(0); } const result = await tools[1]!.execute("test", { purpose: "final", title: "Beryl PPT 能力验收", template: "plain", slides: [ { title: "Beryl PPT 能力验收", body: "本页使用测试内容,不包含客户数据。\n文件应保留可编辑标题和正文。", sources: "本地功能测试,无外部事实。" }, { title: "交付检查", body: "实际生成 PowerPoint 文件\n校验文件结构并重新导入\n逐页渲染并提供下载入口", sources: "测试检查项。" }, ] }, undefined, undefined, {} as never); const id = result.details.artifactId; const bytes = await validatedPpt(workspace, id); console.log(JSON.stringify({ ...result.details, bytes: bytes.length, directory: workspace.resolve(`presentations/${id}`) }));