sshLifecycleProjectDraft.test.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { afterEach, beforeEach, expect, it, vi } from "vitest";
  2. import { connectSSHWorkspaceAndSendFirstTurn } from "#e2e/helpers/ssh-remote-lifecycle";
  3. const state = vi.hoisted(() => {
  4. const sent: Array<{ identity: string; model: string }> = [];
  5. return {
  6. identity: "",
  7. model: "local-default",
  8. localDraftCreations: 0,
  9. remoteIdentity: "remote:server:fixture:/work",
  10. sent,
  11. };
  12. });
  13. vi.mock("#e2e/helpers/project-sidebar", () => ({}));
  14. vi.mock("#e2e/helpers/desktop-app", () => ({ waitForWorkspaceApp: vi.fn() }));
  15. vi.mock("#e2e/helpers/custom-openai-provider", () => ({}));
  16. vi.mock("#e2e/helpers/upstream-provider", () => ({
  17. selectUpstreamProviderModelById: async (model: string) => {
  18. state.model = model;
  19. },
  20. selectUpstreamThoughtLevelValue: vi.fn(),
  21. }));
  22. vi.mock("#e2e/helpers/conversation-session-network", () => ({
  23. getUpstreamRequestRecordCount: async () => state.sent.length,
  24. waitForUpstreamRequest: vi.fn(),
  25. }));
  26. vi.mock("#e2e/helpers/v4-conversation", () => ({
  27. // 全局新建按产品合同切换到本地未分类任务,不能冒充远程项目内新建。
  28. startNewV4Draft: async () => {
  29. state.localDraftCreations += 1;
  30. state.identity = "";
  31. state.model = "local-default";
  32. },
  33. sendV4PromptAndWaitAccepted: async () => {
  34. state.sent.push({ identity: state.identity, model: state.model });
  35. },
  36. waitForV4ConversationState: async (predicate: (value: unknown) => boolean) => {
  37. const snapshot = {
  38. taskId: state.identity ? "remote-task" : "local-task",
  39. state: "idle",
  40. queueCount: 0,
  41. };
  42. expect(predicate(snapshot)).toBe(true);
  43. return snapshot;
  44. },
  45. waitForV4AssistantMessageContaining: vi.fn(),
  46. }));
  47. vi.mock("#e2e/helpers/ssh-remote-p0", () => ({
  48. SSH_WORKSPACE_READY_TIMEOUT_MS: 1_000,
  49. clickLastEnabledSSHDialogButton: vi.fn(),
  50. fillSSHPasswordSettings: vi.fn(),
  51. openSSHRemoteDialog: vi.fn(),
  52. ensureSSHProjectDirectoryStep: vi.fn(),
  53. selectSSHRemoteDirectory: async () => {
  54. state.identity = state.remoteIdentity;
  55. },
  56. waitForRemoteTab: async () => ({
  57. remoteKind: "ssh",
  58. remoteHost: "127.0.0.1",
  59. remoteSessionId: "attachment",
  60. secretPersistedInTab: false,
  61. workspaceIdentity: state.remoteIdentity,
  62. }),
  63. readRemoteTabSnapshot: async () => ({
  64. activeWorkspaceIdentity: state.identity || null,
  65. activeWorkspacePath: state.identity ? "/work" : "/local",
  66. }),
  67. }));
  68. beforeEach(() => {
  69. vi.stubGlobal("expect", expect);
  70. state.identity = "";
  71. state.model = "local-default";
  72. state.localDraftCreations = 0;
  73. state.sent.length = 0;
  74. });
  75. afterEach(() => vi.unstubAllGlobals());
  76. it("远程项目首发保留新建项目草稿和已选模型,不跳到全局本地任务", async () => {
  77. const task = await connectSSHWorkspaceAndSendFirstTurn({
  78. caseMarker: "E2E_REMOTE_DRAFT",
  79. config: { host: "127.0.0.1", port: 43210, username: "dev", password: "fixture" },
  80. label: "A",
  81. workspacePath: "/work",
  82. provider: {
  83. id: "fixture-provider",
  84. name: "Fixture provider",
  85. tunnel: { baseURL: "http://127.0.0.1:43211", close: async () => {} },
  86. },
  87. });
  88. expect(state.sent).toEqual([
  89. { identity: state.remoteIdentity, model: "e2e-ssh-remote-lifecycle-model" },
  90. ]);
  91. expect(task.taskId).toBe("remote-task");
  92. expect(task.identity).toBe(state.remoteIdentity);
  93. expect(state.localDraftCreations).toBe(0);
  94. });