conversation-session-ssh-provisioning-failure.test.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { withCredentialFault } from "#e2e/helpers/credential-fault";
  2. import { NodePersonalProviderConfigRepository } from "@zcode/provider-node";
  3. import { parseRemoteWorkspaceIdentity } from "@zcode/shared";
  4. import { clearAppData, getE2EAppDataPaths, waitForWorkspaceApp } from "#e2e/helpers/desktop-app";
  5. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  6. import {
  7. clickLastEnabledSSHDialogButton,
  8. fillSSHPasswordSettings,
  9. openSSHRemoteDialog,
  10. readHostProcesses,
  11. readRemoteTabSnapshot,
  12. readSSHRuntimeConfig,
  13. selectSSHRemoteDirectory,
  14. waitForRemoteTab,
  15. waitForSSHDirectoryStep,
  16. waitForSSHError,
  17. SSH_WORKSPACE_READY_TIMEOUT_MS,
  18. } from "#e2e/helpers/ssh-remote-p0";
  19. const CASE_MARKER = "SSH_PROVISIONING_FAILURE";
  20. describe(CASE_MARKER, () => {
  21. after(async () => {
  22. await browser.electron.restoreAllMocks();
  23. await clearAppData();
  24. });
  25. it("SSH-P0-CONN-08 首次失败保留安全诊断,恢复凭据后失效默认不阻断连接", async function () {
  26. this.timeout(20 * 60_000);
  27. const config = readSSHRuntimeConfig(CASE_MARKER);
  28. const workspacePath = config.workspacePaths[0];
  29. await prepareV4ConversationE2E({ skipProvider: true });
  30. const hosts = await readHostProcesses();
  31. const paths = getE2EAppDataPaths();
  32. const invalidCredential = "enc:v1:E2E_INVALID_PROVISIONING_CREDENTIAL";
  33. await withCredentialFault(
  34. paths.credentialsFile,
  35. "oauth:bigmodel:refresh_token",
  36. invalidCredential,
  37. async () => {
  38. await openSSHRemoteDialog(CASE_MARKER);
  39. await fillSSHPasswordSettings(config);
  40. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  41. // 首装会停在安装确认;先驱动该步骤,才能观察真正的 provisioning 失败。
  42. await expect(waitForSSHDirectoryStep(CASE_MARKER)).rejects.toThrow("SSH 连接失败");
  43. expect(await waitForSSHError(CASE_MARKER)).toMatch(/连接失败|Connection failed/iu);
  44. // 现行错误页把技术代码收进折叠详情;按真实操作展开后验证,不要求主提示重复内部代码。
  45. await $('[data-testid="ssh-error"] summary').click();
  46. const details = $('[data-testid="ssh-error"] details pre');
  47. await details.waitForDisplayed();
  48. expect(await details.getText()).toContain("source-read-failed");
  49. const text = await browser.execute(
  50. () => document.querySelector('[data-testid="ssh-dialog"]')?.textContent ?? "",
  51. );
  52. expect(text).not.toContain(invalidCredential);
  53. expect(text).not.toContain(config.password);
  54. expect((await readRemoteTabSnapshot()).remoteSessionId).toBeNull();
  55. },
  56. );
  57. const defaultModelSelection = {
  58. providerId: "e2e-removed-provider",
  59. modelId: "e2e-removed-model",
  60. };
  61. const personal = new NodePersonalProviderConfigRepository({
  62. filePath: paths.configFile,
  63. pollingIntervalMs: false,
  64. });
  65. try {
  66. await personal.update((current) => ({ ...current, defaultModelSelection }));
  67. await $('[data-testid="ssh-error"]')
  68. .$('.//button[normalize-space(.)="重试" or normalize-space(.)="Retry"]')
  69. .click();
  70. await waitForSSHDirectoryStep(CASE_MARKER);
  71. await selectSSHRemoteDirectory(workspacePath, CASE_MARKER);
  72. await waitForWorkspaceApp(workspacePath, SSH_WORKSPACE_READY_TIMEOUT_MS);
  73. const tab = await waitForRemoteTab({
  74. caseMarker: CASE_MARKER,
  75. expectedPath: workspacePath,
  76. });
  77. expect(parseRemoteWorkspaceIdentity(tab.workspaceIdentity!)).toMatchObject({
  78. kind: "server",
  79. workspacePath,
  80. });
  81. expect(tab.remoteHost).toBe(config.host);
  82. expect(tab.secretPersistedInTab).toBe(false);
  83. expect((await personal.read()).defaultModelSelection).toEqual(defaultModelSelection);
  84. expect(await readHostProcesses()).toEqual(hosts);
  85. } finally {
  86. personal.dispose();
  87. }
  88. });
  89. });