conversation-session-ssh-remote-p0.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. import { releaseControlledReplay } from "#e2e/helpers/controlled-replay";
  2. import { parseRemoteWorkspaceIdentity } from "@zcode/shared";
  3. import { clearAppData, waitForWorkspaceApp } from "../helpers/desktop-app.js";
  4. import {
  5. refreshSeededOpenAIProvidersThroughSettings,
  6. seedCustomOpenAIChatCompletionsProvider,
  7. } from "../helpers/custom-openai-provider.js";
  8. import { resolveSeededReplayBaseUrl } from "../helpers/custom-openai-provider-store.js";
  9. import {
  10. selectUpstreamProviderModelById,
  11. selectUpstreamThoughtLevelValue,
  12. } from "../helpers/upstream-provider.js";
  13. import {
  14. getUpstreamRequestRecordCount,
  15. waitForUpstreamRequest,
  16. } from "../helpers/conversation-session-network.js";
  17. import {
  18. prepareV4ConversationE2E,
  19. selectV4TaskById,
  20. sendV4PromptAndWaitAccepted,
  21. waitForV4AssistantMessageContaining,
  22. waitForV4ConversationState,
  23. } from "../helpers/v4-conversation.js";
  24. import {
  25. beginConversationTelemetryCapture,
  26. waitForConversationReportInventory,
  27. } from "../helpers/conversation-telemetry-parity-capture.js";
  28. import {
  29. clickLastEnabledSSHDialogButton,
  30. createSSHReplayTunnel,
  31. readHostProcesses,
  32. fillSSHPasswordSettings,
  33. openSSHRemoteDialog,
  34. openSSHSourceDirectory,
  35. runSSHCommand,
  36. selectSSHRemoteDirectory,
  37. waitForSSHDirectoryStep,
  38. } from "../helpers/ssh-remote-p0.js";
  39. import { readProjectTaskRowState, type ProjectTaskRowState } from "../helpers/project-sidebar.js";
  40. const CASE_MARKER = "R1_SSH_P0_01";
  41. const PROMPT_MARKER = "E2E_SSH_REMOTE_P0";
  42. const MODEL_ID = "e2e-ssh-remote-p0-model";
  43. const WORKSPACE_READY_TIMEOUT_MS = 2 * 60_000;
  44. const TURN_TIMEOUT_MS = 2 * 60_000;
  45. interface SSHRuntimeConfig {
  46. host: string;
  47. password: string;
  48. port: number;
  49. username: string;
  50. workspacePaths: readonly [string, string];
  51. }
  52. interface RemoteTabSnapshot {
  53. activeWorkspaceIdentity: string | null;
  54. activeWorkspacePath: string | null;
  55. remoteHost: string | null;
  56. remoteKind: string | null;
  57. remoteSessionId: string | null;
  58. secretPersistedInTab: boolean;
  59. workspaceIdentity: string | null;
  60. workspacePath: string | null;
  61. }
  62. interface ReplayTunnel {
  63. baseURL: string;
  64. close(): Promise<void>;
  65. }
  66. interface TaskCase {
  67. firstPrompt: string;
  68. firstReply: string;
  69. followPrompt: string;
  70. followReply: string;
  71. identity: string;
  72. label: "A" | "B";
  73. remoteSessionId: string;
  74. taskId: string;
  75. workspacePath: string;
  76. }
  77. const runningRowMismatches: Array<{
  78. taskId: string;
  79. label: string;
  80. observed: ProjectTaskRowState;
  81. }> = [];
  82. describe(`${CASE_MARKER}: SSH remote workspace P0`, () => {
  83. let replayTunnel: ReplayTunnel | null = null;
  84. after(async () => {
  85. await replayTunnel?.close();
  86. replayTunnel = null;
  87. await browser.electron.restoreAllMocks();
  88. await clearAppData();
  89. });
  90. it("R1-SSH-P0-01 在两个 SSH workspace 各自首发,并切回 task 续发", async function () {
  91. this.timeout(20 * 60_000);
  92. runningRowMismatches.length = 0;
  93. const config = readSSHRuntimeConfig();
  94. const [workspaceA, workspaceB] = config.workspacePaths;
  95. await prepareV4ConversationE2E({ skipProvider: true });
  96. const initialHosts = await readHostProcesses();
  97. expect(initialHosts).toHaveLength(1);
  98. const telemetryCapture = await beginConversationTelemetryCapture();
  99. replayTunnel = await createReplayTunnel(config);
  100. const previousReplayBaseURL = process.env.E2E_PROVIDER_RUNTIME_BASE_URL;
  101. let provider: { id: string; name: string };
  102. process.env.E2E_PROVIDER_RUNTIME_BASE_URL = replayTunnel.baseURL;
  103. try {
  104. provider = await seedCustomOpenAIChatCompletionsProvider({
  105. modelId: MODEL_ID,
  106. providerId: "e2e-ssh-remote-p0-provider",
  107. providerName: "SSH Remote P0",
  108. });
  109. await refreshSeededOpenAIProvidersThroughSettings([provider.name]);
  110. } finally {
  111. if (previousReplayBaseURL === undefined) {
  112. delete process.env.E2E_PROVIDER_RUNTIME_BASE_URL;
  113. } else {
  114. process.env.E2E_PROVIDER_RUNTIME_BASE_URL = previousReplayBaseURL;
  115. }
  116. }
  117. const provisioningRecordsBeforeConnect = await readProvisioningRecordCount(config);
  118. const taskA = await connectWorkspaceAndSendFirstTurn({
  119. config,
  120. label: "A",
  121. provider,
  122. workspacePath: workspaceA,
  123. });
  124. const provisioningRecordsAfterFirstWorkspace = await waitForProvisioningRecordCountGreaterThan(
  125. config,
  126. provisioningRecordsBeforeConnect,
  127. );
  128. const taskB = await connectWorkspaceAndSendFirstTurn({
  129. config,
  130. label: "B",
  131. provider,
  132. workspacePath: workspaceB,
  133. });
  134. // 修复原因:Provisioning 的同步身份是 Remote Environment,不是 Workspace。
  135. // 同一 SSH Environment 打开第二个目录时必须复用已经完成的同步,不能再写一条记录。
  136. expect(await readProvisioningRecordCount(config)).toBe(provisioningRecordsAfterFirstWorkspace);
  137. expect(taskA.remoteSessionId).not.toBe(taskB.remoteSessionId);
  138. expect(await readHostProcesses()).toEqual(initialHosts);
  139. await switchTaskAndSendFollowTurn(taskA, taskB.firstPrompt);
  140. await switchTaskAndSendFollowTurn(taskB, taskA.firstPrompt);
  141. await assertTaskRow(taskA, { active: false, running: false });
  142. await assertTaskRow(taskB, { active: true, running: false });
  143. expect(await readHostProcesses()).toEqual(initialHosts);
  144. const reports = await waitForConversationReportInventory(telemetryCapture, {
  145. agent_step: 4,
  146. message_completion: 4,
  147. });
  148. for (const task of [taskA, taskB]) {
  149. const taskReports = reports.filter((report) => report.talk_id === task.taskId);
  150. expect(taskReports.filter((report) => report.element_name === "agent_step")).toHaveLength(2);
  151. expect(
  152. taskReports.filter((report) => report.element_name === "message_completion"),
  153. ).toHaveLength(2);
  154. for (const report of taskReports.filter(
  155. (candidate) =>
  156. candidate.element_name === "agent_step" ||
  157. candidate.element_name === "message_completion",
  158. )) {
  159. // 遥测合同(docs/monitoring/conversation-telemetry-v4.md):remote_kind 由稳定 workspace
  160. // identity 经 parseRemoteWorkspaceIdentity 解析,R3 Source Server 工作区的 identity kind 是
  161. // "server"(上方 waitForRemoteTab 亦按此断言);SSH 只是物理线路,不是该字段的取值。
  162. expect(report.event_extra_detail).toMatchObject({
  163. workspace_kind: "remote",
  164. remote_kind: "server",
  165. });
  166. }
  167. }
  168. process.stdout.write(
  169. `[${CASE_MARKER}] telemetry ${JSON.stringify(
  170. [taskA, taskB].map((task) => {
  171. const taskReports = reports.filter((report) => report.talk_id === task.taskId);
  172. return {
  173. agentStepCount: taskReports.filter((report) => report.element_name === "agent_step")
  174. .length,
  175. completionCount: taskReports.filter(
  176. (report) => report.element_name === "message_completion",
  177. ).length,
  178. taskId: task.taskId,
  179. };
  180. }),
  181. )}\n`,
  182. );
  183. expect(runningRowMismatches).toEqual([]);
  184. });
  185. });
  186. async function readProvisioningRecordCount(config: SSHRuntimeConfig): Promise<number> {
  187. const result = await runSSHCommand(
  188. config,
  189. 'if [ -f "$HOME/.zcode/v2/runtime/provider/provisioning.json" ]; then cat "$HOME/.zcode/v2/runtime/provider/provisioning.json"; else printf \'{"records":[]}\'; fi',
  190. );
  191. if (result.code !== 0) {
  192. throw new Error(`${CASE_MARKER}: 读取远端 Provisioning 状态失败:${result.stderr}`);
  193. }
  194. const parsed = JSON.parse(result.stdout) as { records?: unknown };
  195. if (!Array.isArray(parsed.records)) {
  196. throw new Error(`${CASE_MARKER}: 远端 Provisioning 状态缺少 records`);
  197. }
  198. return parsed.records.length;
  199. }
  200. async function waitForProvisioningRecordCountGreaterThan(
  201. config: SSHRuntimeConfig,
  202. baseline: number,
  203. ): Promise<number> {
  204. let observed = baseline;
  205. await browser.waitUntil(
  206. async () => {
  207. observed = await readProvisioningRecordCount(config);
  208. return observed > baseline;
  209. },
  210. {
  211. timeout: 30_000,
  212. interval: 500,
  213. timeoutMsg: `${CASE_MARKER}: 首个远端 Workspace 没有完成 Provisioning`,
  214. },
  215. );
  216. return observed;
  217. }
  218. function readSSHRuntimeConfig(): SSHRuntimeConfig {
  219. const host = requireSecretEnv("ZCODE_E2E_SSH_HOST");
  220. const username = requireSecretEnv("ZCODE_E2E_SSH_USERNAME");
  221. const password = requireSecretEnv("ZCODE_E2E_SSH_PASSWORD");
  222. const portText = process.env.ZCODE_E2E_SSH_PORT?.trim() || "22";
  223. const port = Number.parseInt(portText, 10);
  224. if (!Number.isSafeInteger(port) || port < 1 || port > 65_535) {
  225. throw new Error(`${CASE_MARKER}: ZCODE_E2E_SSH_PORT 必须是 1..65535 的整数`);
  226. }
  227. const workspacePaths = (
  228. process.env.ZCODE_E2E_SSH_WORKSPACE_PATHS?.split(",") ?? ["/root", "/home"]
  229. )
  230. .map((value) => value.trim())
  231. .filter(Boolean);
  232. if (
  233. workspacePaths.length !== 2 ||
  234. workspacePaths.some((value) => !value.startsWith("/")) ||
  235. workspacePaths[0] === workspacePaths[1]
  236. ) {
  237. throw new Error(`${CASE_MARKER}: ZCODE_E2E_SSH_WORKSPACE_PATHS 必须是两个不同的绝对路径`);
  238. }
  239. return {
  240. host,
  241. password,
  242. port,
  243. username,
  244. workspacePaths: [workspacePaths[0]!, workspacePaths[1]!],
  245. };
  246. }
  247. function requireSecretEnv(name: string): string {
  248. const value = process.env[name]?.trim();
  249. if (!value) {
  250. throw new Error(`${CASE_MARKER}: 缺少 ${name}`);
  251. }
  252. return value;
  253. }
  254. async function connectWorkspaceAndSendFirstTurn(options: {
  255. config: SSHRuntimeConfig;
  256. label: "A" | "B";
  257. provider: { id: string; name: string };
  258. workspacePath: string;
  259. }): Promise<TaskCase> {
  260. // Bug 原因:本 spec 曾自带一份 SSH 向导轮询副本,只认独立 ConfirmDialog 的安装确认和
  261. // 目录页;产品已把安装确认内联到连接步骤(“安装并继续”),副本可能等满连接超时。
  262. // 统一复用 helpers/ssh-remote-p0.ts 的共享流程,与 connection-p0 / soak-dual 保持同一状态机。
  263. await openSSHRemoteDialog(CASE_MARKER);
  264. await fillSSHPasswordSettings(options.config);
  265. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  266. const flow = await waitForSSHDirectoryStep(CASE_MARKER);
  267. if (flow === "closed") {
  268. // 向导已收起:从已注册设备行进入目录选择,追加 project workspace。
  269. await openSSHSourceDirectory(options.config, CASE_MARKER);
  270. }
  271. await selectSSHRemoteDirectory(options.workspacePath, CASE_MARKER);
  272. await waitForWorkspaceApp(options.workspacePath, WORKSPACE_READY_TIMEOUT_MS);
  273. const tab = await waitForRemoteTab({
  274. expectedPath: options.workspacePath,
  275. });
  276. expect(tab.remoteKind).toBe("ssh");
  277. expect(tab.remoteHost).toBe(options.config.host);
  278. expect(tab.secretPersistedInTab).toBe(false);
  279. if (!tab.remoteSessionId) {
  280. throw new Error(`${CASE_MARKER}: workspace ${options.label} 缺少 remoteSessionId`);
  281. }
  282. if (!tab.workspaceIdentity) {
  283. throw new Error(`${CASE_MARKER}: workspace ${options.label} 缺少稳定 workspaceIdentity`);
  284. }
  285. await selectUpstreamProviderModelById(MODEL_ID, {
  286. includePlainModelFallback: false,
  287. providerId: options.provider.id,
  288. providerName: options.provider.name,
  289. });
  290. // 项目创建已打开远程草稿;全局新建会切到本地未分类并丢失目标模型。
  291. await selectUpstreamThoughtLevelValue("disabled");
  292. const draft = await readRemoteTabSnapshot(tab.workspaceIdentity, options.workspacePath);
  293. expect(draft.activeWorkspaceIdentity).toBe(tab.workspaceIdentity);
  294. expect(draft.activeWorkspacePath).toBe(options.workspacePath);
  295. const firstPrompt = `${PROMPT_MARKER}_${options.label}_FIRST_PROMPT`;
  296. const firstReply = `${PROMPT_MARKER}_${options.label}_FIRST_REPLY`;
  297. const followPrompt = `${PROMPT_MARKER}_${options.label}_FOLLOW_PROMPT`;
  298. const followReply = `${PROMPT_MARKER}_${options.label}_FOLLOW_REPLY`;
  299. const requestStart = await getUpstreamRequestRecordCount();
  300. await sendV4PromptAndWaitAccepted(
  301. `${firstPrompt}: 只回复 ${firstReply}`,
  302. firstPrompt,
  303. `${options.label} 首发没有进入远端 task`,
  304. );
  305. const running = await waitForV4ConversationState(
  306. (snapshot) =>
  307. Boolean(snapshot.taskId && snapshot.taskId !== "draft") && snapshot.state === "streaming",
  308. `${options.label} 首发没有进入 running`,
  309. TURN_TIMEOUT_MS,
  310. );
  311. if (!running.taskId) {
  312. throw new Error(`${CASE_MARKER}: workspace ${options.label} 首发没有 taskId`);
  313. }
  314. const task: TaskCase = {
  315. firstPrompt,
  316. firstReply,
  317. followPrompt,
  318. followReply,
  319. identity: tab.workspaceIdentity,
  320. label: options.label,
  321. remoteSessionId: tab.remoteSessionId,
  322. taskId: running.taskId,
  323. workspacePath: options.workspacePath,
  324. };
  325. await assertTaskRow(task, { active: true, running: true });
  326. await releaseControlledReplay(`ssh-remote-p0-${task.label.toLowerCase()}-first`);
  327. await waitForUpstreamRequest(
  328. {
  329. lastUserMessageIncludes: [firstPrompt],
  330. },
  331. `${options.label} 首发请求没有到达 provider`,
  332. TURN_TIMEOUT_MS,
  333. { afterIndex: requestStart - 1 },
  334. );
  335. await waitForV4AssistantMessageContaining(firstReply, TURN_TIMEOUT_MS);
  336. await waitForV4ConversationState(
  337. (snapshot) =>
  338. snapshot.taskId === task.taskId && snapshot.state === "idle" && snapshot.queueCount === 0,
  339. `${options.label} 首发完成后没有回到 idle`,
  340. TURN_TIMEOUT_MS,
  341. );
  342. await assertTaskRow(task, { active: true, running: false });
  343. return task;
  344. }
  345. async function switchTaskAndSendFollowTurn(
  346. task: TaskCase,
  347. foreignFirstPrompt: string,
  348. ): Promise<void> {
  349. await selectV4TaskById(task.taskId, 30_000);
  350. await waitForRemoteTab({
  351. expectedIdentity: task.identity,
  352. expectedPath: task.workspacePath,
  353. expectedRemoteSessionId: task.remoteSessionId,
  354. });
  355. await assertTaskRow(task, { active: true, running: false });
  356. const requestStart = await getUpstreamRequestRecordCount();
  357. await sendV4PromptAndWaitAccepted(
  358. `${task.followPrompt}: 只回复 ${task.followReply}`,
  359. task.followPrompt,
  360. `${task.label} 续发没有进入原 task`,
  361. );
  362. await assertTaskRow(task, { active: true, running: true });
  363. await releaseControlledReplay(`ssh-remote-p0-${task.label.toLowerCase()}-follow`);
  364. await waitForUpstreamRequest(
  365. {
  366. excludes: [foreignFirstPrompt],
  367. includes: [task.firstPrompt],
  368. lastUserMessageIncludes: [task.followPrompt],
  369. },
  370. `${task.label} 续发请求没有携带本 task 历史,或混入另一 workspace`,
  371. TURN_TIMEOUT_MS,
  372. { afterIndex: requestStart - 1 },
  373. );
  374. await waitForV4AssistantMessageContaining(task.followReply, TURN_TIMEOUT_MS);
  375. await waitForV4ConversationState(
  376. (snapshot) =>
  377. snapshot.taskId === task.taskId && snapshot.state === "idle" && snapshot.queueCount === 0,
  378. `${task.label} 续发完成后没有回到 idle`,
  379. TURN_TIMEOUT_MS,
  380. );
  381. await assertTaskRow(task, { active: true, running: false });
  382. }
  383. async function assertTaskRow(
  384. task: TaskCase,
  385. expected: { active: boolean; running: boolean },
  386. ): Promise<void> {
  387. let latest: ProjectTaskRowState | null = null;
  388. await browser
  389. .waitUntil(
  390. async () => {
  391. // 虚拟项目侧栏:task 行必须落在其 workspace 对应的项目 section 内。
  392. latest = await readProjectTaskRowState(task.taskId, task.workspacePath);
  393. return (
  394. latest.exists &&
  395. latest.inProject &&
  396. latest.active === expected.active &&
  397. latest.running === expected.running &&
  398. !latest.error
  399. );
  400. },
  401. {
  402. timeout: 30_000,
  403. interval: 100,
  404. timeoutMsg: `${CASE_MARKER}: task ${task.label} 列表状态不正确`,
  405. },
  406. )
  407. .catch((cause: unknown) => {
  408. // 运行图标缺失不应挡住历史隔离与遥测取证;严格保留末尾失败,不能放行归属或错误异常。
  409. if (
  410. expected.running &&
  411. latest?.exists &&
  412. latest.inProject &&
  413. latest.active === expected.active &&
  414. !latest.error &&
  415. !latest.running
  416. ) {
  417. runningRowMismatches.push({ taskId: task.taskId, label: task.label, observed: latest });
  418. process.stdout.write(
  419. `[${CASE_MARKER}] running-row-mismatch ${JSON.stringify(runningRowMismatches.at(-1))}\n`,
  420. );
  421. return;
  422. }
  423. throw new Error(
  424. `${CASE_MARKER}: task ${task.label} 列表状态不正确 expected=${JSON.stringify(expected)} latest=${JSON.stringify(latest)}`,
  425. { cause },
  426. );
  427. });
  428. }
  429. async function createReplayTunnel(config: SSHRuntimeConfig): Promise<ReplayTunnel> {
  430. return createSSHReplayTunnel(config, CASE_MARKER);
  431. }
  432. async function waitForRemoteTab(options: {
  433. expectedIdentity?: string;
  434. expectedPath: string;
  435. expectedRemoteSessionId?: string | null;
  436. timeoutMs?: number;
  437. }): Promise<RemoteTabSnapshot> {
  438. let snapshot: RemoteTabSnapshot | null = null;
  439. try {
  440. await browser.waitUntil(
  441. async () => {
  442. try {
  443. snapshot = await readRemoteTabSnapshot(options.expectedIdentity, options.expectedPath);
  444. const parsedIdentity = snapshot.workspaceIdentity
  445. ? parseRemoteWorkspaceIdentity(snapshot.workspaceIdentity)
  446. : null;
  447. const expectedIdentityMatches = options.expectedIdentity
  448. ? snapshot.workspaceIdentity === options.expectedIdentity
  449. : parsedIdentity?.kind === "server" &&
  450. parsedIdentity.workspacePath === options.expectedPath;
  451. return (
  452. snapshot.workspacePath === options.expectedPath &&
  453. snapshot.activeWorkspacePath === options.expectedPath &&
  454. expectedIdentityMatches &&
  455. snapshot.activeWorkspaceIdentity === snapshot.workspaceIdentity &&
  456. Boolean(snapshot.remoteSessionId) &&
  457. (!options.expectedRemoteSessionId ||
  458. snapshot.remoteSessionId === options.expectedRemoteSessionId)
  459. );
  460. } catch {
  461. return false;
  462. }
  463. },
  464. {
  465. timeout: options.timeoutMs ?? WORKSPACE_READY_TIMEOUT_MS,
  466. interval: 1_000,
  467. timeoutMsg: `${CASE_MARKER}: remote tab identity/session 没有收敛`,
  468. },
  469. );
  470. } catch (error) {
  471. // Bug 定位需要区分“remote tab 丢失”和“reload 后错误恢复到 local active tab”;
  472. // snapshot 不包含凭据,可以安全进入 E2E 失败证据。
  473. throw new Error(
  474. `${CASE_MARKER}: remote tab identity/session 没有收敛,latest=${JSON.stringify(snapshot)}`,
  475. { cause: error },
  476. );
  477. }
  478. if (!snapshot) throw new Error(`${CASE_MARKER}: remote tab snapshot 缺失`);
  479. return snapshot;
  480. }
  481. function readRemoteTabSnapshot(
  482. expectedIdentity?: string,
  483. expectedPath?: string,
  484. ): Promise<RemoteTabSnapshot> {
  485. return browser.execute(
  486. (identity, workspacePath) => {
  487. type RemoteTab = {
  488. id: string;
  489. kind: string;
  490. remoteSessionId?: string;
  491. remoteTarget?: Record<string, unknown>;
  492. workspaceIdentity?: string;
  493. workspacePath?: string;
  494. };
  495. const store = (
  496. window as Window & {
  497. __zcodeTabStoreE2E?: {
  498. getState?: () => {
  499. activeTabId?: string | null;
  500. activeWorkspaceIdentity?: string | null;
  501. activeWorkspacePath?: string | null;
  502. tabs?: RemoteTab[];
  503. };
  504. };
  505. }
  506. ).__zcodeTabStoreE2E;
  507. const state = store?.getState?.();
  508. const matchingRemoteTab = state?.tabs?.find((tab) =>
  509. identity ? tab.workspaceIdentity === identity : tab.workspacePath === workspacePath,
  510. );
  511. const remoteTarget = matchingRemoteTab?.remoteTarget;
  512. return {
  513. activeWorkspaceIdentity: state?.activeWorkspaceIdentity ?? null,
  514. activeWorkspacePath: state?.activeWorkspacePath ?? null,
  515. remoteHost: typeof remoteTarget?.host === "string" ? remoteTarget.host : null,
  516. remoteKind: typeof remoteTarget?.kind === "string" ? remoteTarget.kind : null,
  517. remoteSessionId: matchingRemoteTab?.remoteSessionId ?? null,
  518. secretPersistedInTab: Boolean(
  519. remoteTarget && ("password" in remoteTarget || "privateKeyPassphrase" in remoteTarget),
  520. ),
  521. workspaceIdentity: matchingRemoteTab?.workspaceIdentity ?? null,
  522. workspacePath: matchingRemoteTab?.workspacePath ?? null,
  523. };
  524. },
  525. expectedIdentity ?? null,
  526. expectedPath ?? null,
  527. );
  528. }