conversation-session-preinstalled-tools-python-resource.test.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { execFile } from "node:child_process";
  2. import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
  3. import { join } from "node:path";
  4. import { promisify } from "node:util";
  5. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  6. import { resolveE2EStorageRoot } from "#e2e/helpers/e2e-runtime-paths";
  7. import { setPluginPresentation } from "#e2e/helpers/plugin-management-lifecycle";
  8. const exec = promisify(execFile);
  9. describe("Python 真实预装资源(待审核)", () => {
  10. it("PY-08: 删除确认说明附加区,并随版本一起删除", async function () {
  11. this.timeout(240000);
  12. await prepareV4ConversationE2E();
  13. await $('[data-testid="workspace-help-menu-trigger"]').click();
  14. await $('[data-testid="workspace-help-menu-preinstalled-tools"]').click();
  15. await $('[data-testid="preinstalled-tools-dialog"]').waitForDisplayed();
  16. const card = $('[data-testid="preinstalled-tools-card"][data-tool-id="python"]');
  17. await card.waitForDisplayed();
  18. await fetch(`${process.env.ZCODE_E2E_PREINSTALL_FIXTURE_URL}/release`);
  19. await browser.waitUntil(
  20. async () =>
  21. (await card.$('[data-testid="preinstalled-tools-status"]').getAttribute("data-status")) ===
  22. "ready",
  23. { timeout: 180000 },
  24. );
  25. const roots = join(resolveE2EStorageRoot(), "preinstalled-tools");
  26. const release = join(roots, (await readdir(roots))[0]!);
  27. const record = JSON.parse(
  28. await readFile(join(release, "tools/python/installation.json"), "utf8"),
  29. );
  30. const result = await exec(
  31. join(release, "bin/zcode-python"),
  32. ["-c", "import sys; print(sys.prefix)"],
  33. { timeout: 30000 },
  34. );
  35. expect(result.stdout.trim()).toBe(join(record.installationDir, "overlay"));
  36. const additionalPackage = join(
  37. record.installationDir,
  38. "overlay/lib/python3.12/site-packages/zcode_delete_probe",
  39. );
  40. await mkdir(additionalPackage, { recursive: true });
  41. await writeFile(join(additionalPackage, "__init__.py"), "VALUE = 'delete-probe'\n");
  42. const imported = await exec(
  43. join(release, "bin/zcode-python"),
  44. ["-c", "import zcode_delete_probe; print(zcode_delete_probe.VALUE)"],
  45. { timeout: 30000 },
  46. );
  47. expect(imported.stdout.trim()).toBe("delete-probe");
  48. for (const locale of ["zh-CN", "en-US"] as const) {
  49. for (const theme of ["zai-dark", "zai-light"] as const) {
  50. await setPluginPresentation({ locale, theme, width: 760, height: 640 });
  51. await card.$('[data-testid="preinstalled-tools-delete"]').click();
  52. const confirmation = $('[data-testid="preinstalled-tools-delete-confirm"]');
  53. await confirmation.waitForDisplayed();
  54. expect(await confirmation.getText()).toContain(
  55. locale === "zh-CN"
  56. ? "Agent 额外安装的 Python 包也会删除。"
  57. : "Python packages added by the Agent will also be deleted.",
  58. );
  59. await browser.saveScreenshot(
  60. `${process.env.ZCODE_E2E_ARTIFACT_DIR}/python-delete-${locale}-${theme}.png`,
  61. );
  62. await $('[data-testid="preinstalled-tools-delete-confirm-cancel"]').click();
  63. }
  64. }
  65. await card.$('[data-testid="preinstalled-tools-delete"]').click();
  66. await $('[data-testid="preinstalled-tools-delete-confirm-accept"]').click();
  67. await browser.waitUntil(
  68. async () =>
  69. (await card.$('[data-testid="preinstalled-tools-status"]').getAttribute("data-status")) ===
  70. "not-installed",
  71. { timeout: 30000 },
  72. );
  73. // owner 先删除记录并发布未安装,再回收大目录;控件恢复可用才表示删除命令已回执。
  74. await card.$('[data-testid="preinstalled-tools-download"]').waitForEnabled({ timeout: 30000 });
  75. await expect(stat(additionalPackage)).rejects.toHaveProperty("code", "ENOENT");
  76. await expect(stat(record.installationDir)).rejects.toHaveProperty("code", "ENOENT");
  77. await expect(stat(join(release, "bin/zcode-python"))).rejects.toHaveProperty("code", "ENOENT");
  78. });
  79. });