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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { readFile, writeFile } from "node:fs/promises";
  2. import { NodePersonalProviderConfigRepository } from "@zcode/provider-node";
  3. import { buildRemoteWorkspaceIdentity, type RemoteTarget } from "@zcode/shared";
  4. import {
  5. clearAppData,
  6. getE2EAppDataPaths,
  7. waitForWorkspaceApp,
  8. } from "../../../helpers/desktop-app.js";
  9. import { prepareV4ConversationE2E } from "../../../helpers/v4-conversation.js";
  10. import {
  11. clickLastEnabledSSHDialogButton,
  12. fillSSHPasswordSettings,
  13. openSSHRemoteDialog,
  14. readHostProcesses,
  15. readRemoteTabSnapshot,
  16. readSSHRuntimeConfig,
  17. selectSSHRemoteDirectory,
  18. waitForRemoteTab,
  19. waitForSSHDirectoryStep,
  20. waitForSSHError,
  21. SSH_WORKSPACE_READY_TIMEOUT_MS,
  22. } from "../../../helpers/ssh-remote-p0.js";
  23. const CASE_MARKER = "SSH_PROVISIONING_FAILURE";
  24. describe(CASE_MARKER, () => {
  25. after(async () => {
  26. await browser.electron.restoreAllMocks();
  27. await clearAppData();
  28. });
  29. it("SSH-P0-CONN-05 首次失败保留安全诊断,恢复凭据后失效默认不阻断连接", async function () {
  30. this.timeout(20 * 60_000);
  31. const config = readSSHRuntimeConfig(CASE_MARKER);
  32. const workspacePath = config.workspacePaths[0];
  33. const target: RemoteTarget = {
  34. kind: "ssh",
  35. host: config.host,
  36. port: config.port,
  37. username: config.username,
  38. };
  39. const identity = buildRemoteWorkspaceIdentity(workspacePath, target);
  40. await prepareV4ConversationE2E({ skipProvider: true });
  41. const hosts = await readHostProcesses();
  42. const paths = getE2EAppDataPaths();
  43. const credentials = await readFile(paths.credentialsFile, "utf8");
  44. const invalidCredential = "enc:v1:E2E_INVALID_PROVISIONING_CREDENTIAL";
  45. try {
  46. await writeFile(
  47. paths.credentialsFile,
  48. JSON.stringify({
  49. ...JSON.parse(credentials),
  50. "oauth:bigmodel:refresh_token": invalidCredential,
  51. }),
  52. );
  53. await openSSHRemoteDialog(CASE_MARKER);
  54. await fillSSHPasswordSettings(config);
  55. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  56. expect(await waitForSSHError(CASE_MARKER)).toContain("source-read-failed");
  57. const text = await browser.execute(
  58. () => document.querySelector('[data-testid="ssh-dialog"]')?.textContent ?? "",
  59. );
  60. expect(text.split("source-read-failed").length - 1).toBeGreaterThanOrEqual(2);
  61. expect(text).not.toContain(invalidCredential);
  62. expect((await readRemoteTabSnapshot(identity)).remoteSessionId).toBeNull();
  63. } finally {
  64. await writeFile(paths.credentialsFile, credentials);
  65. }
  66. const defaultModelSelection = {
  67. providerId: "e2e-removed-provider",
  68. modelId: "e2e-removed-model",
  69. };
  70. const personal = new NodePersonalProviderConfigRepository({
  71. filePath: paths.configFile,
  72. pollingIntervalMs: false,
  73. });
  74. try {
  75. await personal.update((current) => ({ ...current, defaultModelSelection }));
  76. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  77. await waitForSSHDirectoryStep(CASE_MARKER);
  78. await selectSSHRemoteDirectory(workspacePath, CASE_MARKER);
  79. await waitForWorkspaceApp(workspacePath, SSH_WORKSPACE_READY_TIMEOUT_MS);
  80. await waitForRemoteTab({
  81. caseMarker: CASE_MARKER,
  82. expectedIdentity: identity,
  83. expectedPath: workspacePath,
  84. });
  85. expect((await personal.read()).defaultModelSelection).toEqual(defaultModelSelection);
  86. expect(await readHostProcesses()).toEqual(hosts);
  87. } finally {
  88. personal.dispose();
  89. }
  90. });
  91. });