mcp-apps-host-options.mjs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { parseArgs } from "node:util";
  2. const groups = {
  3. "session-ready-only": ["session-ready"],
  4. "background-only": ["background"],
  5. "photocraft-background-only": ["background"],
  6. "showcase-only": ["showcase"],
  7. "sampling-only": ["sampling"],
  8. "rows-only": ["rows"],
  9. "managed-only": ["interaction", "managed", "managed-empty"],
  10. "chain-only": ["chain"],
  11. "retention-only": ["retention"],
  12. "storage-only": ["write", "read", "empty"],
  13. };
  14. export function parseMcpAppsHostOptions(args) {
  15. const { values } = parseArgs({
  16. args,
  17. options: {
  18. ...Object.fromEntries(Object.keys(groups).map((key) => [key, { type: "boolean" }])),
  19. "reuse-agent-build": { type: "boolean" },
  20. "output-dir": { type: "string" },
  21. },
  22. });
  23. const selected = Object.keys(groups).filter((key) => values[key]);
  24. // 正式入口不能因拼错参数或混用模式而静默运行其它场景。
  25. if (selected.length > 1) throw new Error("Select only one MCP App E2E group");
  26. if (values["output-dir"] !== undefined && !values["output-dir"].trim())
  27. throw new Error("output-dir must not be empty");
  28. return {
  29. modes: selected.length
  30. ? groups[selected[0]]
  31. : [
  32. "write",
  33. "read",
  34. "empty",
  35. "chain",
  36. "interaction",
  37. "managed",
  38. "managed-empty",
  39. "retention",
  40. "rows",
  41. "sampling",
  42. "background",
  43. ],
  44. outputDir: values["output-dir"],
  45. reuseAgentBuild: values["reuse-agent-build"] === true,
  46. };
  47. }
  48. export function resolveMcpAppsHostLaunch(electron, args, env) {
  49. // Linux replay 容器以 root 运行;仅测试容器使用这些参数,不改变本机启动方式。
  50. if (env.ZCODE_E2E_CONTAINER !== "1") return { command: electron, args };
  51. // Electron 会保留 Chromium 参数;放在末尾,避免挤占夹具按位置读取的 root/profile。
  52. const containerArgs = [...args, "--no-sandbox", "--disable-dev-shm-usage"];
  53. return env.DISPLAY
  54. ? { command: electron, args: containerArgs }
  55. : { command: "xvfb-run", args: ["--auto-servernum", electron, ...containerArgs] };
  56. }