conversation-session-plugin-remote-explicit-sync-workspace.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. import { startDraftFromProject } from "#e2e/helpers/project-sidebar";
  2. import {
  3. selectUpstreamProviderModelById,
  4. selectUpstreamThoughtLevelValue,
  5. } from "#e2e/helpers/upstream-provider";
  6. import { Buffer } from "node:buffer";
  7. import { readFile } from "node:fs/promises";
  8. import { join, posix } from "node:path";
  9. import {
  10. TID_WORKSPACE_HEADER,
  11. TID_WORKSPACE_MORE_BUTTON,
  12. TID_WORKSPACE_PATH,
  13. } from "@zcode/shared/test-ids";
  14. import { clearAppData, getE2EAppDataPaths } from "#e2e/helpers/desktop-app";
  15. import {
  16. addMarketplaceSourceThroughAgent,
  17. createPluginLifecycleFixture,
  18. getPluginOverview,
  19. getPluginList,
  20. installMarketplacePluginThroughAgent,
  21. PLUGIN_LIFECYCLE_ID,
  22. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  23. PLUGIN_LIFECYCLE_MCP_TOOL_NAME,
  24. PLUGIN_LIFECYCLE_NAME,
  25. PLUGIN_LIFECYCLE_RUNTIME_MARKER,
  26. pluginStoragePath,
  27. } from "#e2e/helpers/plugin-management-lifecycle";
  28. import {
  29. getUpstreamRequestRecordCount,
  30. getUpstreamRequestToolNames,
  31. getLatestUpstreamToolResultByToolCallId,
  32. waitForUpstreamRequest,
  33. } from "#e2e/helpers/conversation-session-network";
  34. import { waitForToolCallBlockByToolName } from "#e2e/helpers/conversation-session-tool";
  35. import {
  36. connectSSHWorkspaceAndSendFirstTurn,
  37. createSSHLifecycleProvider,
  38. SSH_LIFECYCLE_MODEL_ID,
  39. type SSHLifecycleProvider,
  40. } from "#e2e/helpers/ssh-remote-lifecycle";
  41. import {
  42. readSingleSSHWorkspaceRuntimeConfig,
  43. runSSHCommand,
  44. type SSHConnectionConfig,
  45. } from "#e2e/helpers/ssh-remote-p0";
  46. import {
  47. prepareV4ConversationE2E,
  48. approveV4Permission,
  49. hasV4PermissionDialog,
  50. getV4ConfigProjection,
  51. switchV4Mode,
  52. sendV4PromptAndWaitAccepted,
  53. waitForV4AssistantMessageContaining,
  54. } from "#e2e/helpers/v4-conversation";
  55. const CASE_MARKER = "E2E_WPL_011_REMOTE_EXPLICIT_SYNC";
  56. const RUNTIME_MARKER = `${PLUGIN_LIFECYCLE_RUNTIME_MARKER}_1.0.0`;
  57. const RUNTIME_PROMPT = `${CASE_MARKER}_RUNTIME_PROMPT`;
  58. const RUNTIME_REPLY = "WPL_011_REMOTE_EXPLICIT_SYNC_REPLY";
  59. async function selectFullAccessMode(): Promise<void> {
  60. // V4 菜单不使用旧 select-item/option;实际选择后等待当前 workspace 的配置投影。
  61. await switchV4Mode("yolo");
  62. await browser.waitUntil(async () => (await getV4ConfigProjection()).mode === "yolo", {
  63. timeout: 15_000,
  64. timeoutMsg: `${CASE_MARKER}: 完全访问模式没有写入当前草稿配置`,
  65. });
  66. }
  67. describe("WPL-011 remote Workspace Plugin explicit sync E2E", () => {
  68. let provider: SSHLifecycleProvider | null = null;
  69. let target: SSHConnectionConfig | null = null;
  70. let workspacePath = "";
  71. after(async () => {
  72. await provider?.tunnel.close().catch(() => undefined);
  73. if (target && workspacePath) {
  74. await cleanupRemoteWorkspace(target, workspacePath).catch(() => undefined);
  75. }
  76. await browser.electron.restoreAllMocks();
  77. await clearAppData();
  78. });
  79. it("does not copy a local package on connect, then materializes it only through Sync Plugin", async function () {
  80. this.timeout(45 * 60_000);
  81. const remote = readSingleSSHWorkspaceRuntimeConfig(CASE_MARKER);
  82. target = remote;
  83. workspacePath = remote.workspacePath;
  84. await seedRemoteWorkspace(target, workspacePath);
  85. await prepareV4ConversationE2E({ skipProvider: true });
  86. await selectFullAccessMode();
  87. const fixture = await createPluginLifecycleFixture("1.0.0");
  88. await addMarketplaceSourceThroughAgent(fixture.marketplaceRoot);
  89. await installMarketplacePluginThroughAgent(
  90. PLUGIN_LIFECYCLE_NAME,
  91. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  92. );
  93. const localOverview = await getPluginOverview();
  94. expect(localOverview.installedPlugins).toEqual(
  95. expect.arrayContaining([
  96. expect.objectContaining({
  97. id: PLUGIN_LIFECYCLE_ID,
  98. scope: "user",
  99. version: "1.0.0",
  100. }),
  101. ]),
  102. );
  103. const localConfigPath = join(getE2EAppDataPaths().storageRoot, "cli", "config.json");
  104. const localInstalledPath = pluginStoragePath("installed_plugins.json");
  105. const localConfigBefore = await readFile(localConfigPath, "utf8");
  106. const localInstalledBefore = await readFile(localInstalledPath, "utf8");
  107. const workspaceConfigBefore = await readRemoteFile(
  108. target,
  109. posix.join(workspacePath, ".zcode", "config.json"),
  110. );
  111. provider = await createSSHLifecycleProvider(target, CASE_MARKER);
  112. const task = await connectSSHWorkspaceAndSendFirstTurn({
  113. caseMarker: CASE_MARKER,
  114. config: target,
  115. label: "A",
  116. provider,
  117. workspacePath,
  118. });
  119. expect(
  120. await getUpstreamRequestToolNames({
  121. lastUserMessageIncludes: [task.firstPrompt],
  122. }),
  123. ).not.toContain(PLUGIN_LIFECYCLE_MCP_TOOL_NAME);
  124. expect(await readRemotePluginStorageState(target)).toEqual({
  125. cacheContainsPlugin: false,
  126. installedContainsPlugin: false,
  127. marketplaceContainsPlugin: false,
  128. });
  129. const missingRemotePlugin = (await getPluginList(workspacePath, task.identity)).plugins.find(
  130. (plugin) => plugin.id === PLUGIN_LIFECYCLE_ID,
  131. );
  132. expect(missingRemotePlugin).toMatchObject({
  133. enabled: true,
  134. enabledSource: "workspace",
  135. id: PLUGIN_LIFECYCLE_ID,
  136. packageStatus: "missing",
  137. source: "missing",
  138. });
  139. expect(await readRemoteFile(target, posix.join(workspacePath, ".zcode", "config.json"))).toBe(
  140. workspaceConfigBefore,
  141. );
  142. // 票 14:Header「同步插件」打开数据同步弹窗,定位到当前 workspace 所在设备的插件分类。
  143. await openRemotePluginSyncDialog(workspacePath);
  144. await waitForDataSyncDialogOnPlugins();
  145. await waitForRemotePluginCandidate(PLUGIN_LIFECYCLE_ID.toLowerCase());
  146. await startRemotePluginSync();
  147. await waitForRemotePluginSyncComplete(PLUGIN_LIFECYCLE_ID.toLowerCase());
  148. await browser.waitUntil(
  149. async () => {
  150. const state = await readRemotePluginStorageState(target!);
  151. return (
  152. state.cacheContainsPlugin &&
  153. state.installedContainsPlugin &&
  154. state.marketplaceContainsPlugin
  155. );
  156. },
  157. {
  158. timeout: 180_000,
  159. timeoutMsg: `${CASE_MARKER}: 显式同步完成后 remote package/cache 没有物化`,
  160. },
  161. );
  162. expect(await readRemoteFile(target, posix.join(workspacePath, ".zcode", "config.json"))).toBe(
  163. workspaceConfigBefore,
  164. );
  165. expect(await readFile(localConfigPath, "utf8")).toBe(localConfigBefore);
  166. expect(await readFile(localInstalledPath, "utf8")).toBe(localInstalledBefore);
  167. await browser.waitUntil(
  168. async () =>
  169. (await getPluginList(workspacePath, task.identity)).plugins.some(
  170. (plugin) =>
  171. plugin.id === PLUGIN_LIFECYCLE_ID &&
  172. plugin.enabled &&
  173. plugin.enabledSource === "workspace",
  174. ),
  175. {
  176. timeout: 120_000,
  177. timeoutMsg: `${CASE_MARKER}: remote Plugin list 没有刷新为 Workspace enabled`,
  178. },
  179. );
  180. // 显式同步后的验证必须在同一远程项目创建新会话;全局新建会错误执行本机已安装的插件。
  181. // 同步完成保留结果弹窗;未关闭它时真实侧栏点击被遮罩拦截。
  182. const syncDialog = $('[data-testid="remote-sync-dialog"]');
  183. // 分类页没有底部「关闭」按钮,用弹窗右上角的关闭按钮。
  184. await syncDialog.$('[data-slot="dialog-close"]').click();
  185. await syncDialog.waitForExist({ reverse: true });
  186. await startDraftFromProject(workspacePath, { workspaceIdentity: task.identity });
  187. await selectUpstreamProviderModelById(SSH_LIFECYCLE_MODEL_ID, {
  188. providerId: provider.id,
  189. providerName: provider.name,
  190. includePlainModelFallback: false,
  191. });
  192. await selectUpstreamThoughtLevelValue("disabled");
  193. const requestStart = await getUpstreamRequestRecordCount();
  194. await sendV4PromptAndWaitAccepted(
  195. `${RUNTIME_PROMPT}: Call ${PLUGIN_LIFECYCLE_MCP_TOOL_NAME} exactly once, then reply with exactly ${RUNTIME_REPLY}.`,
  196. RUNTIME_PROMPT,
  197. `${CASE_MARKER}: 显式同步后的 remote 新 Session prompt 没有被接受`,
  198. );
  199. await waitForUpstreamRequest(
  200. {
  201. includes: [RUNTIME_MARKER],
  202. lastUserMessageIncludes: [RUNTIME_PROMPT],
  203. },
  204. `${CASE_MARKER}: 显式同步后的 remote 新 Session 没有暴露 Plugin MCP`,
  205. 120_000,
  206. { afterIndex: requestStart - 1 },
  207. );
  208. expect(
  209. await getUpstreamRequestToolNames({
  210. lastUserMessageIncludes: [RUNTIME_PROMPT],
  211. }),
  212. ).toContain(PLUGIN_LIFECYCLE_MCP_TOOL_NAME);
  213. await waitForToolCallBlockByToolName(PLUGIN_LIFECYCLE_MCP_TOOL_NAME, 120_000);
  214. // tool-call 已出现不代表工具已执行;远端默认模式可能随后才显示权限请求。
  215. // 持续观察到真实 tool_result,期间只响应一次当前请求,不把工具块当作完成屏障。
  216. let permissionApproved = false;
  217. await browser.waitUntil(
  218. async () => {
  219. if (!permissionApproved && (await hasV4PermissionDialog())) {
  220. expect(await approveV4Permission()).toBe(true);
  221. permissionApproved = true;
  222. }
  223. return (await getLatestUpstreamToolResultByToolCallId("call_wpl_011_plugin")) !== null;
  224. },
  225. { timeout: 120_000, timeoutMsg: `${CASE_MARKER}: Plugin MCP 没有返回真实 tool_result` },
  226. );
  227. await waitForV4AssistantMessageContaining(RUNTIME_REPLY, 120_000);
  228. const toolResult = await getLatestUpstreamToolResultByToolCallId("call_wpl_011_plugin");
  229. expect(toolResult?.isError).toBe(false);
  230. expect(toolResult?.content.trim()).toBe(RUNTIME_MARKER);
  231. });
  232. });
  233. // 本 case 会 rm -rf 远端 workspace,所以只允许重置一个约定路径,不接受任意路径。默认值
  234. // /root/workspace 是历史上唯一跑过的 root 目标;Linux e2e 服务器用 dev 用户,通过
  235. // ZCODE_E2E_WPL011_WORKSPACE 指定该机的专用目录(不能指向共享 workspace 根)。
  236. const ALLOWED_REMOTE_WORKSPACE =
  237. process.env.ZCODE_E2E_WPL011_WORKSPACE?.trim() || "/root/workspace";
  238. async function seedRemoteWorkspace(
  239. target: SSHConnectionConfig,
  240. workspacePath: string,
  241. ): Promise<void> {
  242. if (workspacePath !== ALLOWED_REMOTE_WORKSPACE) {
  243. throw new Error(`${CASE_MARKER}: refusing to reset unexpected remote path ${workspacePath}`);
  244. }
  245. const config = {
  246. plugins: {
  247. enabledPlugins: {
  248. [PLUGIN_LIFECYCLE_ID]: true,
  249. },
  250. },
  251. };
  252. const command = [
  253. "set -eu",
  254. // 远端用户不一定是 root(服务器上是 dev),配置目录一律走 $HOME 展开。
  255. `rm -rf -- "$HOME/.zcode" ${quoteShell(workspacePath)}`,
  256. `mkdir -p -- ${quoteShell(posix.join(workspacePath, ".zcode"))}`,
  257. writeBase64Command(
  258. posix.join(workspacePath, ".zcode", "config.json"),
  259. `${JSON.stringify(config, null, 2)}\n`,
  260. ),
  261. ].join(" && ");
  262. const result = await runSSHCommand(target, command);
  263. expect(result.code).toBe(0);
  264. expect(result.stderr).toBe("");
  265. }
  266. async function cleanupRemoteWorkspace(
  267. target: SSHConnectionConfig,
  268. workspacePath: string,
  269. ): Promise<void> {
  270. if (workspacePath !== ALLOWED_REMOTE_WORKSPACE) {
  271. throw new Error(`${CASE_MARKER}: refusing to clean unexpected remote path ${workspacePath}`);
  272. }
  273. await runSSHCommand(target, `rm -rf -- ${quoteShell(workspacePath)}`);
  274. }
  275. async function readRemotePluginStorageState(target: SSHConnectionConfig): Promise<{
  276. cacheContainsPlugin: boolean;
  277. installedContainsPlugin: boolean;
  278. marketplaceContainsPlugin: boolean;
  279. }> {
  280. const command = [
  281. "installed=false",
  282. `if test -f "$HOME/.zcode/cli/plugins/installed_plugins.json" && grep -Fq -- ${quoteShell(PLUGIN_LIFECYCLE_ID)} "$HOME/.zcode/cli/plugins/installed_plugins.json"; then installed=true; fi`,
  283. "cached=false",
  284. `if test -d "$HOME/.zcode/cli/plugins/cache" && find "$HOME/.zcode/cli/plugins/cache" -path ${quoteShell(`*${PLUGIN_LIFECYCLE_NAME}*`)} -print -quit | grep -q .; then cached=true; fi`,
  285. "marketplace=false",
  286. `if test -f "$HOME/.zcode/cli/plugins/known_marketplaces.json" && grep -Fq -- ${quoteShell(PLUGIN_LIFECYCLE_MARKETPLACE_ID)} "$HOME/.zcode/cli/plugins/known_marketplaces.json"; then marketplace=true; fi`,
  287. "printf '%s\\n' \"$installed $cached $marketplace\"",
  288. ].join("; ");
  289. const result = await runSSHCommand(target, command);
  290. expect(result.code).toBe(0);
  291. const [installed, cached, marketplace] = result.stdout.trim().split(/\s+/u);
  292. return {
  293. cacheContainsPlugin: cached === "true",
  294. installedContainsPlugin: installed === "true",
  295. marketplaceContainsPlugin: marketplace === "true",
  296. };
  297. }
  298. async function readRemoteFile(target: SSHConnectionConfig, path: string): Promise<string> {
  299. const result = await runSSHCommand(target, `cat -- ${quoteShell(path)}`);
  300. expect(result.code).toBe(0);
  301. return result.stdout;
  302. }
  303. async function openRemotePluginSyncDialog(workspacePath: string): Promise<void> {
  304. // 这一步串联「找到目标 workspace 的 header」→「打开更多菜单」→「点同步 Plugin」,
  305. // 三个环节任一不成立以前都只报一句超时。两条经验教训写进实现:
  306. // 1. timeoutMsg 是模板字符串,在 waitUntil 调用时就求值,之前打印的 visible=[] 是
  307. // 探测前的初始值,不是现场事实——诊断必须在超时之后收集。
  308. // 2. 菜单只在第一轮点一次的话,一旦那次点击没生效(Radix trigger 是 toggle 语义)
  309. // 后面 30 秒都在等一个不会出现的菜单。每轮按需重点,让它能自愈。
  310. type MenuProbe = {
  311. stage:
  312. | "header-missing"
  313. | "more-missing"
  314. | "more-disabled"
  315. | "menu-closed"
  316. | "item-missing"
  317. | "clicked";
  318. headers: Array<{ visible: boolean; pathAbs: string | null; hasMoreButton: boolean }>;
  319. moreState: string | null;
  320. menuCount: number;
  321. visibleItems: string[];
  322. };
  323. let probe: MenuProbe = {
  324. stage: "header-missing",
  325. headers: [],
  326. moreState: null,
  327. menuCount: 0,
  328. visibleItems: [],
  329. };
  330. await browser
  331. .waitUntil(
  332. async () => {
  333. probe = await browser.execute(
  334. (headerTestId, moreTestId, pathTestId, expectedPath) => {
  335. const headers = Array.from(
  336. document.querySelectorAll<HTMLElement>(`[data-testid="${headerTestId}"]`),
  337. );
  338. const facts = headers.map((candidate) => {
  339. const path = candidate.querySelector<HTMLElement>(`[data-testid="${pathTestId}"]`);
  340. return {
  341. visible: candidate.getClientRects().length > 0,
  342. pathAbs: path?.dataset.workspaceAbsPath ?? null,
  343. hasMoreButton: Boolean(
  344. candidate.querySelector<HTMLButtonElement>(`[data-testid="${moreTestId}"]`),
  345. ),
  346. };
  347. });
  348. const menus = Array.from(
  349. document.querySelectorAll<HTMLElement>('[role="menu"]'),
  350. ).filter((menu) => menu.getClientRects().length > 0);
  351. const visibleItems = Array.from(
  352. document.querySelectorAll<HTMLElement>('[role="menuitem"]'),
  353. )
  354. .filter((candidate) => candidate.getClientRects().length > 0)
  355. .map((candidate) => candidate.innerText.trim());
  356. const header = headers.find((candidate) => {
  357. if (candidate.getClientRects().length === 0) return false;
  358. const path = candidate.querySelector<HTMLElement>(`[data-testid="${pathTestId}"]`);
  359. // 修复原因:header 上下文改到 tooltip 承载后按钮没有 DOM title,
  360. // 只有 data-workspace-abs-path 还稳定携带工作区绝对路径。
  361. return path?.dataset.workspaceAbsPath?.startsWith(expectedPath) ?? false;
  362. });
  363. const base = { headers: facts, menuCount: menus.length, visibleItems };
  364. if (!header) return { ...base, stage: "header-missing" as const, moreState: null };
  365. const button = header.querySelector<HTMLButtonElement>(`[data-testid="${moreTestId}"]`);
  366. if (!button) return { ...base, stage: "more-missing" as const, moreState: null };
  367. const moreState = button.dataset.state ?? button.getAttribute("aria-expanded") ?? null;
  368. if (button.disabled) return { ...base, stage: "more-disabled" as const, moreState };
  369. if (menus.length === 0) {
  370. // Radix DropdownMenuTrigger 靠 pointerdown 打开;click 单独派发不够。
  371. button.dispatchEvent(
  372. new PointerEvent("pointerdown", {
  373. bubbles: true,
  374. cancelable: true,
  375. button: 0,
  376. pointerId: 1,
  377. pointerType: "mouse",
  378. }),
  379. );
  380. button.dispatchEvent(
  381. new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 0 }),
  382. );
  383. button.click();
  384. return { ...base, stage: "menu-closed" as const, moreState };
  385. }
  386. const item = Array.from(
  387. document.querySelectorAll<HTMLElement>('[role="menuitem"]'),
  388. ).find(
  389. (candidate) =>
  390. candidate.getClientRects().length > 0 &&
  391. candidate.dataset.testid === "data-sync-entry-plugins" &&
  392. candidate.getAttribute("aria-disabled") !== "true",
  393. );
  394. if (!item) return { ...base, stage: "item-missing" as const, moreState };
  395. item.click();
  396. return { ...base, stage: "clicked" as const, moreState };
  397. },
  398. TID_WORKSPACE_HEADER,
  399. TID_WORKSPACE_MORE_BUTTON,
  400. TID_WORKSPACE_PATH,
  401. workspacePath,
  402. );
  403. return probe.stage === "clicked";
  404. },
  405. { timeout: 60_000, interval: 500 },
  406. )
  407. .catch((error: unknown) => {
  408. throw new Error(
  409. `${CASE_MARKER}: 没能从 remote task header 打开“同步 Plugin”(expected=${workspacePath});现场: ${JSON.stringify(probe)}`,
  410. { cause: error },
  411. );
  412. });
  413. }
  414. async function waitForDataSyncDialogOnPlugins(): Promise<void> {
  415. await browser.waitUntil(
  416. () =>
  417. browser.execute(() => {
  418. const dialog = document.querySelector('[data-testid="remote-sync-dialog"]');
  419. const tab = document.querySelector('[data-testid="remote-sync-tab-plugins"]');
  420. const device = document.querySelector('[data-testid="remote-sync-dialog-device"]');
  421. return Boolean(
  422. dialog && device?.textContent?.trim() && tab?.getAttribute("aria-current") === "page",
  423. );
  424. }),
  425. {
  426. timeout: 30_000,
  427. timeoutMsg: `${CASE_MARKER}: Header「同步插件」没有打开数据同步弹窗的插件分类`,
  428. },
  429. );
  430. }
  431. async function readRemotePluginRow(rowKey: string) {
  432. return await browser.execute((rowTestId) => {
  433. const row = document.querySelector<HTMLElement>(`[data-testid="${rowTestId}"]`);
  434. return row
  435. ? { status: row.dataset.syncStatus ?? null, checked: row.getAttribute("aria-checked") }
  436. : null;
  437. }, `remote-sync-row-${rowKey}`);
  438. }
  439. async function waitForRemotePluginCandidate(rowKey: string): Promise<void> {
  440. await browser.waitUntil(
  441. async () => {
  442. const row = await readRemotePluginRow(rowKey);
  443. return row?.status === "push" && row.checked === "true";
  444. },
  445. {
  446. timeout: 120_000,
  447. timeoutMsg: `${CASE_MARKER}: 数据同步弹窗没有把 ${rowKey} 显示为默认勾选的「推送」`,
  448. },
  449. );
  450. }
  451. async function startRemotePluginSync(): Promise<void> {
  452. await browser.waitUntil(
  453. () =>
  454. browser.execute(() => {
  455. const button = document.querySelector<HTMLButtonElement>(
  456. '[data-testid="remote-sync-push"]',
  457. );
  458. if (!button || button.disabled) return false;
  459. button.click();
  460. return true;
  461. }),
  462. {
  463. timeout: 30_000,
  464. timeoutMsg: `${CASE_MARKER}: 插件分类的推送按钮不可点击`,
  465. },
  466. );
  467. }
  468. async function waitForRemotePluginSyncComplete(rowKey: string): Promise<void> {
  469. await browser.waitUntil(async () => (await readRemotePluginRow(rowKey))?.status === "synced", {
  470. timeout: 240_000,
  471. timeoutMsg: `${CASE_MARKER}: 推送后 ${rowKey} 没有变为「已同步」`,
  472. });
  473. const failed = await browser.execute(() =>
  474. Boolean(document.querySelector('[data-testid^="remote-sync-row-error-"]')),
  475. );
  476. expect(failed).toBe(false);
  477. }
  478. function writeBase64Command(path: string, content: string): string {
  479. const encoded = Buffer.from(content, "utf8").toString("base64");
  480. return `printf '%s' ${quoteShell(encoded)} | base64 -d > ${quoteShell(path)}`;
  481. }
  482. function quoteShell(value: string): string {
  483. return `'${value.replaceAll("'", "'\\''")}'`;
  484. }