conversation-session-r3-settings-scopes.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. import { mkdir, writeFile } from "node:fs/promises";
  2. import { basename, join, resolve } from "node:path";
  3. import { parseRemoteWorkspaceIdentity, encodeCustomModelValue } from "@zcode/shared";
  4. import {
  5. TID_CHAT_MODEL_SELECT_GROUP,
  6. TID_CHAT_MODEL_SELECT_ITEM,
  7. TID_CHAT_MODEL_SELECT_TRIGGER,
  8. TID_CHAT_THOUGHT_LEVEL_SELECT_ITEM,
  9. TID_CHAT_THOUGHT_LEVEL_SELECT_TRIGGER,
  10. TID_SETTINGS_BACK_BUTTON,
  11. TID_SETTINGS_PAGE,
  12. TID_SETTINGS_SECTION_NAV,
  13. TID_SUBAGENT_ROW,
  14. TID_TASK_SETTINGS_BUTTON,
  15. testId,
  16. } from "@zcode/shared/test-ids";
  17. import { access } from "node:fs/promises";
  18. import {
  19. clearAppData,
  20. clickTestIdByDom,
  21. DEFAULT_WORKSPACE,
  22. waitForTestIdByDom,
  23. } from "../helpers/desktop-app.js";
  24. import { resolveE2EStorageRoot } from "../helpers/e2e-runtime-paths.js";
  25. import {
  26. clickOpenScopeMenuOption,
  27. readOpenScopeMenuOptions,
  28. } from "../helpers/settings-scope-menu.js";
  29. import {
  30. createSSHLifecycleProvider,
  31. SSH_LIFECYCLE_MODEL_ID,
  32. type SSHLifecycleProvider,
  33. } from "../helpers/ssh-remote-lifecycle.js";
  34. import {
  35. clickLastEnabledSSHDialogButton,
  36. fillSSHPasswordSettings,
  37. openSSHRemoteDialog,
  38. openSSHSourceDirectory,
  39. readHostProcesses,
  40. readSSHRuntimeConfig,
  41. prepareSSHConnectionPage,
  42. runSSHCommand,
  43. selectSSHRemoteDirectory,
  44. waitForRemoteTab,
  45. completeSSHProjectConnection,
  46. waitForSSHDirectoryStep,
  47. } from "../helpers/ssh-remote-p0.js";
  48. import { prepareV4ConversationE2E, startNewV4Draft } from "../helpers/v4-conversation.js";
  49. const CASE_MARKER = "E2E_R3_SETTINGS_SCOPES";
  50. const artifactDir = resolve(
  51. process.env.ZCODE_E2E_ARTIFACT_DIR ?? ".e2e-artifacts/r3-settings-scopes",
  52. );
  53. const AGENT_NAME = "r3-remote-conversation-agent";
  54. const AGENT_NAME_PROJECT = "r3-remote-project-agent";
  55. const SUBAGENT_FORM_SELECTOR = `form:has(input[type="text"]):has([data-testid="${TID_CHAT_MODEL_SELECT_TRIGGER}"])`;
  56. const SECTIONS = ["skill", "mcp", "plugin", "hooks", "subagents", "memory", "general"] as const;
  57. async function openSettingsSection(section: string): Promise<void> {
  58. const onSettings = await browser.execute(
  59. (pageId) => Boolean(document.querySelector(`[data-testid="${pageId}"]`)),
  60. TID_SETTINGS_PAGE,
  61. );
  62. if (!onSettings) {
  63. await clickTestIdByDom(TID_TASK_SETTINGS_BUTTON, {
  64. timeout: 15_000,
  65. timeoutMsg: `${CASE_MARKER}: 没有设置入口`,
  66. });
  67. await waitForTestIdByDom(TID_SETTINGS_PAGE, {
  68. timeout: 15_000,
  69. timeoutMsg: `${CASE_MARKER}: 设置页没有渲染`,
  70. });
  71. }
  72. await clickTestIdByDom(testId(TID_SETTINGS_SECTION_NAV, section), {
  73. timeout: 15_000,
  74. timeoutMsg: `${CASE_MARKER}: 设置页没有 ${section} 分区`,
  75. });
  76. const scopedSection = ["skill", "mcp", "plugin", "hooks", "subagents"].includes(section);
  77. await browser.waitUntil(
  78. async () => (await $('[data-plugin-scope-trigger="true"]').isExisting()) === scopedSection,
  79. { timeout: 15_000, timeoutMsg: `${CASE_MARKER}: ${section} 分区的 scope 入口未就绪` },
  80. );
  81. }
  82. /** 读取当前分区的 scope 选择器可选项(Source/项目/User 等),没有 scope 选择器时返回 null。 */
  83. async function readScopeOptions(): Promise<{ current: string; options: string[] } | null> {
  84. const trigger = $('[data-plugin-scope-trigger="true"]');
  85. if (!(await trigger.isExisting())) return null;
  86. const current = (await trigger.getText()).trim();
  87. await trigger.click();
  88. await browser.waitUntil(
  89. () => browser.execute(() => document.querySelectorAll('[role="menuitemradio"]').length > 0),
  90. { timeout: 10_000, timeoutMsg: "scope-menu" },
  91. );
  92. // 项目在各设备的「项目」子菜单里,逐个打开后合并。
  93. const options = (await readOpenScopeMenuOptions()).map((option) => option.text);
  94. await browser.keys(["Escape"]);
  95. return { current, options };
  96. }
  97. /** 打开 scope 菜单(等待上一次菜单完全关闭,最多重试 3 次)。 */
  98. async function openScopeMenu(): Promise<void> {
  99. const trigger = $('[data-plugin-scope-trigger="true"]');
  100. await trigger.waitForClickable({ timeout: 15_000 });
  101. await browser
  102. .waitUntil(
  103. () => browser.execute(() => document.querySelectorAll('[role="menuitemradio"]').length === 0),
  104. { timeout: 10_000, timeoutMsg: `${CASE_MARKER}: 旧 scope 菜单没有关闭` },
  105. )
  106. .catch(() => undefined);
  107. for (let attempt = 0; attempt < 3; attempt += 1) {
  108. await trigger.click();
  109. const opened = await browser
  110. .waitUntil(
  111. () => browser.execute(() => document.querySelectorAll('[role="menuitemradio"]').length > 0),
  112. { timeout: 5_000, timeoutMsg: "scope-menu-open" },
  113. )
  114. .then(() => true)
  115. .catch(() => false);
  116. if (opened) return;
  117. await browser.pause(500);
  118. }
  119. throw new Error(`${CASE_MARKER}: scope 菜单打不开`);
  120. }
  121. async function createSubagent(name: string, providerId: string, modelId: string): Promise<void> {
  122. const newButton = $('button[aria-label="新建"], button[aria-label="New"]');
  123. await newButton.waitForClickable({ timeout: 15_000 });
  124. await newButton.click();
  125. const form = $(SUBAGENT_FORM_SELECTOR);
  126. await form.waitForDisplayed({ timeout: 15_000 });
  127. const inputs = await form.$$('input[type="text"]');
  128. await inputs[0]!.setValue(name);
  129. await inputs[1]!.setValue(`${CASE_MARKER} description`);
  130. await form.$("textarea").setValue(`${CASE_MARKER} system prompt for ${name}`);
  131. // 模型:与 settings-subagent E2E 同一路径(provider 分组 → 模型项),值为 encodeCustomModelValue。
  132. const model = encodeCustomModelValue(providerId, modelId);
  133. const itemTestId = testId(TID_CHAT_MODEL_SELECT_ITEM, model);
  134. const groupTestId = testId(TID_CHAT_MODEL_SELECT_GROUP, `registry-provider:${providerId}`);
  135. const trigger = form.$(`[data-testid="${TID_CHAT_MODEL_SELECT_TRIGGER}"]`);
  136. await trigger.waitForClickable({ timeout: 15_000 });
  137. await trigger.click();
  138. await browser.waitUntil(
  139. () =>
  140. browser.execute(
  141. (item, group) =>
  142. Boolean(
  143. document.querySelector(`[data-testid="${item}"]`) ||
  144. document.querySelector(`[data-testid="${group}"]`),
  145. ),
  146. itemTestId,
  147. groupTestId,
  148. ),
  149. { timeout: 15_000, timeoutMsg: `${CASE_MARKER}: Subagent 表单模型菜单没有 ${providerId}` },
  150. );
  151. await browser.execute(
  152. (item, group) => {
  153. if (document.querySelector(`[data-testid="${item}"]`)) return;
  154. const node = document.querySelector<HTMLElement>(`[data-testid="${group}"]`);
  155. if (!node) return;
  156. node.focus();
  157. for (const eventName of ["pointerenter", "mouseenter", "mousemove"])
  158. node.dispatchEvent(
  159. new MouseEvent(eventName, { bubbles: true, cancelable: true, view: window }),
  160. );
  161. node.click();
  162. },
  163. itemTestId,
  164. groupTestId,
  165. );
  166. await browser.waitUntil(
  167. () =>
  168. browser.execute(
  169. (item) => Boolean(document.querySelector(`[data-testid="${item}"]`)),
  170. itemTestId,
  171. ),
  172. { timeout: 15_000, timeoutMsg: `${CASE_MARKER}: 模型菜单没有出现 ${model}` },
  173. );
  174. await browser.execute(
  175. (item) => document.querySelector<HTMLElement>(`[data-testid="${item}"]`)?.click(),
  176. itemTestId,
  177. );
  178. await browser.waitUntil(
  179. async () => (await trigger.getAttribute("data-model-current-value")) === model,
  180. { timeout: 15_000, timeoutMsg: `${CASE_MARKER}: 模型控件没有切换到 ${model}` },
  181. );
  182. // 思考档位可选:产品 canSave 只校验"填了必须有效"(SubagentsSection
  183. // thoughtLevelInvalid),不要求非空。经 UI 流程种的自定义 openai 模型没有
  184. // reasoning 元数据(ProviderModelMetadataDialog 无该字段,与 store 直写版
  185. // seed 的 reasoningLevel:disabled 不同),档位控件可能不渲染或菜单无
  186. // disabled 项——均跳过,不影响提交;模型带档位时仍优先选 disabled。
  187. let levelSelected = false;
  188. const levelTrigger = form.$(`[data-testid="${TID_CHAT_THOUGHT_LEVEL_SELECT_TRIGGER}"]`);
  189. const levelTriggerClickable = await levelTrigger.waitForClickable({ timeout: 5_000 }).then(
  190. () => true,
  191. () => false,
  192. );
  193. for (let attempt = 0; attempt < 3 && levelTriggerClickable && !levelSelected; attempt += 1) {
  194. await levelTrigger.click();
  195. try {
  196. const item = $(`[data-testid="${testId(TID_CHAT_THOUGHT_LEVEL_SELECT_ITEM, "disabled")}"]`);
  197. await item.waitForClickable({ timeout: 3_000 });
  198. await item.click();
  199. levelSelected = true;
  200. } catch {
  201. await browser.keys(["Escape"]);
  202. }
  203. }
  204. // 等下拉菜单完全关闭再提交;提交后 8s 未关闭则再点一次(Radix 菜单退场期间的点击会被吞)。
  205. await browser
  206. .waitUntil(
  207. () =>
  208. browser.execute(
  209. () => !document.querySelector('[role="menu"][data-state="open"], [role="listbox"]'),
  210. ),
  211. { timeout: 5_000, timeoutMsg: "menus-closed" },
  212. )
  213. .catch(() => undefined);
  214. for (let attempt = 0; attempt < 3; attempt += 1) {
  215. // 先经 DOM requestSubmit 触发 onSubmit(不依赖按钮命中),再退回真实点击。
  216. const submitted = await browser.execute(
  217. (selector, attemptIndex) => {
  218. const formNode = document.querySelector<HTMLFormElement>(selector);
  219. if (!formNode) return "no-form";
  220. const button = formNode.querySelector<HTMLButtonElement>('button[type="submit"]');
  221. if (button?.disabled) return "disabled";
  222. if (attemptIndex === 0) {
  223. formNode.requestSubmit(button ?? undefined);
  224. return "requestSubmit";
  225. }
  226. button?.click();
  227. return "click";
  228. },
  229. SUBAGENT_FORM_SELECTOR,
  230. attempt,
  231. );
  232. void submitted;
  233. const closed = await browser
  234. .waitUntil(async () => !(await $(SUBAGENT_FORM_SELECTOR).isExisting()), {
  235. timeout: 20_000,
  236. timeoutMsg: "form-close",
  237. })
  238. .then(() => true)
  239. .catch(() => false);
  240. if (closed) break;
  241. }
  242. await browser
  243. .waitUntil(async () => !(await $(SUBAGENT_FORM_SELECTOR).isExisting()), {
  244. timeout: 5_000,
  245. timeoutMsg: `${CASE_MARKER}: Subagent 保存后表单没有关闭`,
  246. })
  247. .catch(async (error) => {
  248. const diagnostics = await browser.execute((selector) => {
  249. const formNode = document.querySelector<HTMLElement>(selector);
  250. const alerts = Array.from(
  251. document.querySelectorAll<HTMLElement>(
  252. '[role="alert"], [role="status"], [data-sonner-toast]',
  253. ),
  254. )
  255. .map((n) => (n.innerText ?? "").trim())
  256. .filter(Boolean);
  257. return {
  258. formText: (formNode?.innerText ?? "").replace(/\s+/gu, " ").slice(0, 600),
  259. alerts: alerts.slice(0, 5),
  260. submitDisabled:
  261. formNode?.querySelector<HTMLButtonElement>('button[type="submit"]')?.disabled ?? null,
  262. };
  263. }, SUBAGENT_FORM_SELECTOR);
  264. throw new Error(`${String(error)}; diagnostics=${JSON.stringify(diagnostics)}`);
  265. });
  266. await waitForTestIdByDom(testId(TID_SUBAGENT_ROW, name), {
  267. timeout: 15_000,
  268. timeoutMsg: `${CASE_MARKER}: Subagent 行没有出现: ${name}`,
  269. });
  270. }
  271. /** 同名 default 工作区必须按 identity 选择,不能用位置推断归属。 */
  272. async function selectScopeKey(key: string): Promise<void> {
  273. await openScopeMenu();
  274. await clickOpenScopeMenuOption(key, { timeoutMsg: `${CASE_MARKER}: scope 菜单没有 ${key}` });
  275. await browser.waitUntil(
  276. async () =>
  277. (await $('[data-plugin-scope-trigger="true"]').getAttribute("data-plugin-scope-key")) === key,
  278. { timeout: 15_000, timeoutMsg: CASE_MARKER + ": scope identity 未切换" },
  279. );
  280. }
  281. async function localFileExists(path: string, waitMs = 0): Promise<boolean> {
  282. const deadline = Date.now() + waitMs;
  283. for (;;) {
  284. try {
  285. await access(path);
  286. return true;
  287. } catch {
  288. if (Date.now() >= deadline) return false;
  289. await browser.pause(500);
  290. }
  291. }
  292. }
  293. describe(`${CASE_MARKER}: 远端 Source 在线时设置 scope 与子智能体落盘位置`, () => {
  294. let provider: SSHLifecycleProvider | null = null;
  295. const facts: Record<string, unknown> = {};
  296. after(async () => {
  297. await mkdir(artifactDir, { recursive: true });
  298. await writeFile(resolve(artifactDir, "settings-scopes.json"), JSON.stringify(facts, null, 2));
  299. await provider?.tunnel.close().catch(() => undefined);
  300. provider = null;
  301. await browser.electron.restoreAllMocks();
  302. await clearAppData();
  303. });
  304. it("R3A-DEV-06 远程项目 B 激活时默认选中该设备「用户」;「本机 · 用户」新建只落本机;项目 A/B scope 按 identity 分别落盘", async function () {
  305. this.timeout(30 * 60_000);
  306. const config = readSSHRuntimeConfig(CASE_MARKER);
  307. const [workspaceA, workspaceB] = config.workspacePaths;
  308. // 冷启动先等待并关闭引导页,再进入工作区;否则测试停在 onboarding,尚未触达设置。
  309. await prepareSSHConnectionPage(CASE_MARKER);
  310. await prepareV4ConversationE2E({ skipProvider: true });
  311. const initialHosts = await readHostProcesses();
  312. provider = await createSSHLifecycleProvider(config, CASE_MARKER, { tunnelUsername: "tunnel" });
  313. await runSSHCommand(
  314. config,
  315. `rm -f "$HOME/.zcode/agents/${AGENT_NAME}.md" "${workspaceA}/.zcode/agents/${AGENT_NAME_PROJECT}.md"`,
  316. );
  317. // Source 在线,先激活远程项目 B;远程无项目入口已退役。
  318. await startNewV4Draft();
  319. await openSSHRemoteDialog(CASE_MARKER);
  320. await fillSSHPasswordSettings(config);
  321. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  322. // 全新容器首连必须经过“安装并继续”确认(inline 在 connecting 步);缺这一步
  323. // 安装确认悬挂,conversation 永不打开(0910 实锤:auth 成功 → probe INSTALLED=0
  324. // → 无后续 channel 活动,keepalive 吊 2min 至超时)。与 entry-attribution 同款。
  325. const conversation = await completeSSHProjectConnection(
  326. { ...config, workspacePaths: [workspaceB, workspaceA] },
  327. CASE_MARKER,
  328. );
  329. const sourceId =
  330. parseRemoteWorkspaceIdentity(conversation.workspaceIdentity!)?.sourceServerId ?? "";
  331. expect(sourceId).toBeTruthy();
  332. // 各分区都必须实际打开;可选项不能仅记录或吞掉失败。
  333. const scopesProjectB: Record<string, unknown> = {};
  334. for (const section of SECTIONS) {
  335. await openSettingsSection(section);
  336. const scopes = await readScopeOptions();
  337. scopesProjectB[section] = scopes;
  338. if (["memory", "general"].includes(section)) {
  339. expect(scopes).toBeNull();
  340. } else {
  341. expect(scopes?.options).toEqual(
  342. expect.arrayContaining([
  343. expect.stringContaining("用户"),
  344. expect.stringContaining(basename(workspaceB)),
  345. ]),
  346. );
  347. expect(scopes?.options).not.toContain(basename(workspaceA));
  348. }
  349. }
  350. facts.scopeOptionsForProjectB = scopesProjectB;
  351. // DEV-06(2026-10 数据同步票 15 修订):Scope 菜单按设备分组,远程 tab 默认选中该设备的「用户」;
  352. // 显式选「本机 · 用户」后新建只落本机。
  353. await openSettingsSection("subagents");
  354. await waitForTestIdByDom(testId(TID_SUBAGENT_ROW, "general-purpose"), { timeout: 30_000 });
  355. const subagentScopes = await readScopeOptions();
  356. facts.subagentScopesForProjectB = subagentScopes;
  357. expect(
  358. await $('[data-plugin-scope-trigger="true"]').getAttribute("data-plugin-scope-key"),
  359. ).toBe(`source-user:${sourceId}`);
  360. // 对照组:本机“用户”scope 新建 → 落本机 storage/agents(证明表单与模型选择路径正常)。
  361. await selectScopeKey("user");
  362. const localControlName = "r3-local-user-agent";
  363. await createSubagent(localControlName, provider.id, SSH_LIFECYCLE_MODEL_ID);
  364. facts.localControlFileExists = await localFileExists(
  365. join(resolveE2EStorageRoot(), "agents", `${localControlName}.md`),
  366. 15_000,
  367. );
  368. expect(facts.localControlFileExists).toBe(true);
  369. const remoteControlFile = await runSSHCommand(
  370. config,
  371. 'find "$HOME" -name "r3-local-user-agent.md" -print',
  372. );
  373. facts.remoteControlFiles = remoteControlFile.stdout.trim();
  374. expect(remoteControlFile.stdout.trim()).toBe("");
  375. // 项目 B 的 scope 必须落在自己的 workspace,不能冒充 Source User。
  376. await selectScopeKey(conversation.workspaceIdentity!);
  377. await createSubagent(AGENT_NAME, provider.id, SSH_LIFECYCLE_MODEL_ID);
  378. const remoteConversationFile = await runSSHCommand(
  379. config,
  380. `test -f "${conversation.workspacePath}/.zcode/agents/${AGENT_NAME}.md" && echo FOUND; test ! -f "$HOME/.zcode/agents/${AGENT_NAME}.md" && echo USER_UNCHANGED`,
  381. );
  382. facts.remoteConversationFile = remoteConversationFile.stdout.trim();
  383. expect(remoteConversationFile.stdout).toContain("FOUND");
  384. expect(remoteConversationFile.stdout).toContain("USER_UNCHANGED");
  385. expect(await localFileExists(join(resolveE2EStorageRoot(), "agents", AGENT_NAME + ".md"))).toBe(
  386. false,
  387. );
  388. facts.sourceUserCoverage = "未覆盖:显式 Source User 与 conversation workspace 分别验收";
  389. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON, {
  390. timeout: 15_000,
  391. timeoutMsg: `${CASE_MARKER}: 设置页返回按钮没有出现`,
  392. });
  393. // 打开远端 project a → Subagents 选中项目 scope 新建 → 远端项目 .zcode/agents。
  394. await openSSHSourceDirectory(config, CASE_MARKER);
  395. expect(await waitForSSHDirectoryStep(CASE_MARKER)).toBe("directory");
  396. await selectSSHRemoteDirectory(workspaceA, CASE_MARKER);
  397. const project = await waitForRemoteTab({
  398. caseMarker: CASE_MARKER,
  399. expectedPath: workspaceA,
  400. timeoutMs: 120_000,
  401. });
  402. await openSettingsSection("subagents");
  403. await waitForTestIdByDom(testId(TID_SUBAGENT_ROW, "general-purpose"), { timeout: 30_000 });
  404. const subagentScopesWithProject = await readScopeOptions();
  405. facts.subagentScopesWithProject = subagentScopesWithProject;
  406. const projectScope =
  407. subagentScopesWithProject?.options.find((option) => option.includes(basename(workspaceA))) ??
  408. null;
  409. facts.projectScopeLabel = projectScope;
  410. expect(projectScope).toBeTruthy();
  411. await selectScopeKey(project.workspaceIdentity!);
  412. let projectScopeSaveError: string | null = null;
  413. await createSubagent(AGENT_NAME_PROJECT, provider.id, SSH_LIFECYCLE_MODEL_ID).catch(
  414. async (error) => {
  415. projectScopeSaveError = String(error).slice(0, 600);
  416. await browser.execute(() => {
  417. const cancel = Array.from(document.querySelectorAll<HTMLButtonElement>("button")).find(
  418. (b) => b.innerText.trim() === "取消" && b.getClientRects().length,
  419. );
  420. cancel?.click();
  421. });
  422. await browser.pause(500);
  423. },
  424. );
  425. facts.remoteProjectScopeSaveError = projectScopeSaveError;
  426. await browser.pause(3_000);
  427. const remoteProjectFile = await runSSHCommand(
  428. config,
  429. `test -f "${workspaceA}/.zcode/agents/${AGENT_NAME_PROJECT}.md" && echo FOUND || echo MISSING; find "$HOME/.zcode" "${workspaceA}" -name "${AGENT_NAME_PROJECT}.md" 2>/dev/null`,
  430. );
  431. facts.remoteProjectAgentFile = remoteProjectFile.stdout.trim().split("\n");
  432. facts.localProjectAgentFileExists = await localFileExists(
  433. join(DEFAULT_WORKSPACE, ".zcode", "agents", `${AGENT_NAME_PROJECT}.md`),
  434. );
  435. facts.localStorageProjectAgentFileExists = await localFileExists(
  436. join(resolveE2EStorageRoot(), "agents", `${AGENT_NAME_PROJECT}.md`),
  437. );
  438. expect(facts.localProjectAgentFileExists).toBe(false);
  439. // 其余分区在选中远端 project 时的 scope 选项。
  440. const scopesWithProject: Record<string, unknown> = {};
  441. for (const section of SECTIONS) {
  442. if (section === "subagents") continue;
  443. await openSettingsSection(section);
  444. const scopes = await readScopeOptions();
  445. scopesWithProject[section] = scopes;
  446. if (["memory", "general"].includes(section)) {
  447. expect(scopes).toBeNull();
  448. } else {
  449. expect(scopes?.options).toEqual(
  450. expect.arrayContaining([
  451. expect.stringContaining("用户"),
  452. expect.stringContaining(basename(workspaceA)),
  453. expect.stringContaining(basename(workspaceB)),
  454. ]),
  455. );
  456. }
  457. }
  458. facts.scopeOptionsWithProject = scopesWithProject;
  459. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON, {
  460. timeout: 15_000,
  461. timeoutMsg: `${CASE_MARKER}: 设置页返回按钮没有出现`,
  462. });
  463. expect(await readHostProcesses()).toEqual(initialHosts);
  464. expect(facts.localStorageProjectAgentFileExists).toBe(false);
  465. expect(projectScopeSaveError).toBeNull();
  466. expect(remoteProjectFile.stdout).toContain("FOUND");
  467. });
  468. });