conversation-session-composer-recent-mode.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. // ZCT-2098314627607224320:首发迁移 Root 后,再新建任务必须继承最近接纳的权限。
  2. // 新建草稿按项目隔离;未归类任务仅在首发接纳后分配下一工作区。
  3. import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
  4. import { join } from "node:path";
  5. import { TID_CHAT_MODE_SELECT_TRIGGER, TID_V4_COMPOSER_SEND } from "@zcode/shared/test-ids";
  6. import { ServiceChannels } from "@zcode/shared";
  7. import {
  8. installHandoffRpcProbe,
  9. callHandoffHost,
  10. restoreHandoffProbes,
  11. } from "#e2e/helpers/remote-project-handoff-probe";
  12. import {
  13. UPSTREAM_PROVIDER_ID,
  14. ensureUpstreamProviderForE2E,
  15. UPSTREAM_MODEL,
  16. UPSTREAM_SECONDARY_MODEL,
  17. } from "#e2e/helpers/upstream-provider";
  18. import { skipOccupationOnboardingIfPresent } from "#e2e/helpers/occupation-onboarding";
  19. import { leaveProjectRowHover, startDraftFromProject } from "#e2e/helpers/project-sidebar";
  20. import { clearAppData, DEFAULT_WORKSPACE } from "#e2e/helpers/desktop-app";
  21. import { resolveE2ERuntimePath, resolveE2EToolPath } from "#e2e/helpers/e2e-runtime-paths";
  22. import { getLatestUpstreamToolResultByToolCallId } from "#e2e/helpers/conversation-session-network";
  23. import { getV4ComposerDraftScopeSnapshot } from "#e2e/helpers/conversation-session-store";
  24. import {
  25. getV4ModelConfig,
  26. getV4PaneSnapshot,
  27. selectV4TaskById,
  28. sendV4PromptAndWaitAccepted as sendPrompt,
  29. switchV4Mode,
  30. switchV4Model,
  31. setV4ComposerText,
  32. waitForV4ComposerSelectionReady,
  33. waitForV4TimelineContaining,
  34. waitForV4ComposerText,
  35. sendV4Prompt,
  36. } from "#e2e/helpers/v4-conversation";
  37. declare global {
  38. interface Window {
  39. __pdSendGate?: { count: number; release(): void; restore(): void };
  40. }
  41. }
  42. async function sendV4PromptAndWaitAccepted(prompt: string, marker: string, message: string) {
  43. try {
  44. await sendPrompt(prompt, marker, message);
  45. } catch (error) {
  46. const details = $('[data-testid="chat-error-details-button"]');
  47. if (await details.isExisting()) {
  48. await details.click();
  49. const content = $('[role="dialog"] pre');
  50. await content.waitForDisplayed();
  51. throw new Error(`${message}: ${await content.getText()}`, { cause: error });
  52. }
  53. throw error;
  54. }
  55. }
  56. const CASE_NAME = "conversation-session-composer-recent-mode";
  57. const CASE_DIR = resolveE2ERuntimePath(CASE_NAME);
  58. const OUTPUT_PATH = resolveE2EToolPath(CASE_NAME, "result.txt");
  59. const EVIDENCE_DIR = join(
  60. process.env.ZCODE_E2E_ARTIFACT_DIR ?? join(process.cwd(), ".e2e-artifacts"),
  61. CASE_NAME,
  62. );
  63. async function captureState(step: string) {
  64. await mkdir(EVIDENCE_DIR, { recursive: true });
  65. const permissionTrigger = $(`[data-testid="${TID_CHAT_MODE_SELECT_TRIGGER}"]`);
  66. await permissionTrigger.waitForDisplayed();
  67. const state = {
  68. pane: await getV4PaneSnapshot(),
  69. composer: await getV4ModelConfig(),
  70. rootDraft: await getV4ComposerDraftScopeSnapshot(DEFAULT_WORKSPACE, null),
  71. permissionLabel: await permissionTrigger.getText(),
  72. persisted: await browser.execute(() => ({
  73. entries: Object.entries(localStorage).filter(
  74. ([key]) => key.includes("composer-") || key.includes("pending-command"),
  75. ),
  76. navigation: (
  77. window as unknown as { __zcodeTabStoreE2E: { getState(): unknown } }
  78. ).__zcodeTabStoreE2E.getState(),
  79. })),
  80. };
  81. await writeFile(join(EVIDENCE_DIR, `${step}.json`), JSON.stringify(state, null, 2));
  82. await browser.saveScreenshot(join(EVIDENCE_DIR, `${step}.png`));
  83. return state;
  84. }
  85. async function expectMode(mode: string) {
  86. await $(`[data-testid="${TID_CHAT_MODE_SELECT_TRIGGER}"]`).waitForDisplayed();
  87. await waitForV4ComposerSelectionReady();
  88. expect((await getV4ModelConfig()).mode).toBe(mode);
  89. }
  90. describe("Composer Recent 权限继承", () => {
  91. it("PD01/02: 任务草稿复用执行目录,接纳后新任务换目录并继承模型权限", async () => {
  92. await skipOccupationOnboardingIfPresent();
  93. await startDraftFromProject(DEFAULT_WORKSPACE);
  94. await ensureUpstreamProviderForE2E({ skipToolbarSelection: true });
  95. const startTask = async () => {
  96. const button = $('[data-testid="virtual-project-new-task"]');
  97. await $('[data-testid="conversation-section"]').moveTo();
  98. await button.waitForDisplayed();
  99. await button.click();
  100. await browser.waitUntil(
  101. async () =>
  102. (await getV4PaneSnapshot()).sessionId === "draft" &&
  103. (await browser.execute(() => {
  104. const w = window as unknown as {
  105. __zcodeTabStoreE2E: { getState(): { activeWorkspacePath: string } };
  106. };
  107. const pending = JSON.parse(
  108. localStorage.getItem('zcode-pending-task-draft:v1:["desktop","local",null]') ??
  109. "null",
  110. );
  111. return Boolean(
  112. pending?.workspacePath &&
  113. pending.workspacePath === w.__zcodeTabStoreE2E.getState().activeWorkspacePath,
  114. );
  115. })),
  116. );
  117. };
  118. const activePath = () =>
  119. browser.execute(
  120. () =>
  121. (
  122. window as unknown as {
  123. __zcodeTabStoreE2E: { getState(): { activeWorkspacePath: string } };
  124. }
  125. ).__zcodeTabStoreE2E.getState().activeWorkspacePath,
  126. );
  127. await startTask();
  128. await switchV4Model(UPSTREAM_PROVIDER_ID, UPSTREAM_MODEL, "");
  129. await switchV4Mode("yolo");
  130. await setV4ComposerText("E2E_PD01_UNSENT");
  131. const firstPath = await activePath();
  132. await startDraftFromProject(DEFAULT_WORKSPACE);
  133. await startTask();
  134. await waitForV4ComposerText("E2E_PD01_UNSENT", "任务草稿未恢复");
  135. expect(await activePath()).toBe(firstPath);
  136. await expectMode("yolo");
  137. const selected = await getV4ModelConfig();
  138. await sendV4PromptAndWaitAccepted(
  139. "E2E_COMPOSER_RECENT_MODE_SEED 请回复测试标记。",
  140. "E2E_COMPOSER_RECENT_MODE_SEED",
  141. "任务首发未接纳",
  142. );
  143. await startTask();
  144. await waitForV4ComposerText("", "新任务不应复制已发送正文");
  145. expect(await activePath()).not.toBe(firstPath);
  146. await expectMode("yolo");
  147. expect(await getV4ModelConfig()).toMatchObject({
  148. provider: selected.provider,
  149. model: selected.model,
  150. });
  151. });
  152. it("PD03/04/09: 同目录项目独立保存草稿和默认配置,修改主要目录保留项目草稿", async () => {
  153. await installHandoffRpcProbe();
  154. try {
  155. const p = await callHandoffHost<{ id: string }>(ServiceChannels.Project, "saveProject", [
  156. { name: "E2E_PD_P", roots: [DEFAULT_WORKSPACE], primaryRoot: DEFAULT_WORKSPACE },
  157. ]);
  158. const q = await callHandoffHost<{ id: string }>(ServiceChannels.Project, "saveProject", [
  159. { name: "E2E_PD_Q", roots: [DEFAULT_WORKSPACE], primaryRoot: DEFAULT_WORKSPACE },
  160. ]);
  161. const start = async (id: string) => {
  162. const section = $(`[data-project-id="${id}"]`);
  163. await section.waitForDisplayed();
  164. await section.moveTo();
  165. await section.$('[data-testid="virtual-project-create-task"]').click();
  166. // 项目详情 hover card 会盖住 Composer 模式选择器,点完先移开指针。
  167. await leaveProjectRowHover();
  168. };
  169. await start(p.id);
  170. await setV4ComposerText("E2E_PD_PROJECT_P");
  171. await switchV4Mode("yolo");
  172. await start(q.id);
  173. await waitForV4ComposerText("", "Q 错读 P 的草稿");
  174. await setV4ComposerText("E2E_PD_PROJECT_Q");
  175. await switchV4Mode("build");
  176. await start(p.id);
  177. await waitForV4ComposerText("E2E_PD_PROJECT_P", "P 草稿被覆盖");
  178. await expectMode("yolo");
  179. await start(q.id);
  180. await waitForV4ComposerText("E2E_PD_PROJECT_Q", "Q 草稿被覆盖");
  181. await expectMode("build");
  182. await switchV4Model(UPSTREAM_PROVIDER_ID, UPSTREAM_SECONDARY_MODEL, "");
  183. await sendV4PromptAndWaitAccepted(
  184. "E2E_COMPOSER_RECENT_MODE_SECOND Q",
  185. "E2E_COMPOSER_RECENT_MODE_SECOND",
  186. "Q 首发未接纳",
  187. );
  188. await waitForV4TimelineContaining("RECENT_MODE_SECOND_DONE");
  189. await start(p.id);
  190. await waitForV4ComposerText("E2E_PD_PROJECT_P", "Q 接纳污染 P 草稿");
  191. await expectMode("yolo");
  192. await switchV4Model(UPSTREAM_PROVIDER_ID, UPSTREAM_MODEL, "");
  193. await sendV4PromptAndWaitAccepted(
  194. "E2E_COMPOSER_RECENT_MODE_SECOND P",
  195. "E2E_COMPOSER_RECENT_MODE_SECOND",
  196. "P 首发未接纳",
  197. );
  198. await waitForV4TimelineContaining("RECENT_MODE_SECOND_DONE");
  199. const pSession = (await getV4PaneSnapshot()).sessionId;
  200. await start(q.id);
  201. await waitForV4ComposerText("", "Q 已发送正文复活");
  202. await expectMode("build");
  203. expect((await getV4ModelConfig()).model).toBe(UPSTREAM_SECONDARY_MODEL);
  204. await start(p.id);
  205. await expectMode("yolo");
  206. expect((await getV4ModelConfig()).model).toBe(UPSTREAM_MODEL);
  207. await setV4ComposerText("E2E_PD_PROJECT_MOVED_ROOT");
  208. const nextRoot = join(CASE_DIR, "new-primary");
  209. await mkdir(nextRoot, { recursive: true });
  210. await callHandoffHost(ServiceChannels.Project, "saveProject", [
  211. {
  212. id: p.id,
  213. name: "E2E_PD_P_RENAMED",
  214. roots: [DEFAULT_WORKSPACE, nextRoot],
  215. primaryRoot: nextRoot,
  216. },
  217. ]);
  218. await start(p.id);
  219. await waitForV4ComposerText("E2E_PD_PROJECT_MOVED_ROOT", "项目换主要目录丢失草稿");
  220. await expectMode("yolo");
  221. const directories = await callHandoffHost<{ workspacePath: string }>(
  222. ServiceChannels.Project,
  223. "resolveSessionDirectories",
  224. [{ workspacePath: DEFAULT_WORKSPACE, taskId: pSession }],
  225. );
  226. expect(directories.workspacePath).toBe(DEFAULT_WORKSPACE);
  227. } finally {
  228. await restoreHandoffProbes();
  229. }
  230. });
  231. it("PD06/07: 首发在途切走再返回保留目录,迟到接纳完成原任务交接", async () => {
  232. const startTask = async () => {
  233. await $('[data-testid="conversation-section"]').moveTo();
  234. await $('[data-testid="virtual-project-new-task"]').click();
  235. await browser.waitUntil(
  236. async () =>
  237. (await getV4PaneSnapshot()).sessionId === "draft" &&
  238. (await browser.execute(() => {
  239. const w = window as unknown as {
  240. __zcodeTabStoreE2E: { getState(): { activeWorkspacePath: string } };
  241. };
  242. const pending = JSON.parse(
  243. localStorage.getItem('zcode-pending-task-draft:v1:["desktop","local",null]') ??
  244. "null",
  245. );
  246. return Boolean(
  247. pending?.workspacePath &&
  248. pending.workspacePath === w.__zcodeTabStoreE2E.getState().activeWorkspacePath,
  249. );
  250. })),
  251. );
  252. };
  253. const path = () =>
  254. browser.execute(
  255. () =>
  256. (
  257. window as unknown as {
  258. __zcodeTabStoreE2E: { getState(): { activeWorkspacePath: string } };
  259. }
  260. ).__zcodeTabStoreE2E.getState().activeWorkspacePath,
  261. );
  262. await startTask();
  263. await switchV4Model(UPSTREAM_PROVIDER_ID, UPSTREAM_MODEL, "");
  264. await switchV4Mode("yolo");
  265. const pendingPath = await path();
  266. await browser.execute(() => {
  267. const original = MessagePort.prototype.postMessage;
  268. const held: Array<() => void> = [];
  269. let holding = true;
  270. const gate = {
  271. count: 0,
  272. release() {
  273. holding = false;
  274. held.splice(0).forEach((send) => send());
  275. },
  276. restore() {
  277. gate.release();
  278. MessagePort.prototype.postMessage = original;
  279. delete window.__pdSendGate;
  280. },
  281. };
  282. MessagePort.prototype.postMessage = function (
  283. this: MessagePort,
  284. ...args: [unknown, (Transferable[] | StructuredSerializeOptions)?]
  285. ) {
  286. const data = args[0];
  287. const bytes =
  288. data instanceof ArrayBuffer
  289. ? new Uint8Array(data)
  290. : ArrayBuffer.isView(data)
  291. ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
  292. : null;
  293. const wire = bytes ? new TextDecoder().decode(bytes) : "";
  294. const forward = () => Reflect.apply(original, this, args);
  295. if (wire.includes("sendConversationCommandV4") && wire.includes('"type":"sendText"')) {
  296. gate.count += 1;
  297. if (holding) {
  298. held.push(forward);
  299. return;
  300. }
  301. }
  302. forward();
  303. };
  304. window.__pdSendGate = gate;
  305. });
  306. try {
  307. await sendV4Prompt("E2E_COMPOSER_RECENT_MODE_SECOND LATE_ACK");
  308. await browser.waitUntil(() => browser.execute(() => window.__pdSendGate?.count === 1));
  309. await startDraftFromProject(DEFAULT_WORKSPACE);
  310. await startTask();
  311. expect(await path()).toBe(pendingPath);
  312. expect(await $(`[data-testid="${TID_V4_COMPOSER_SEND}"]`).isEnabled()).toBe(false);
  313. await browser.execute(() => window.__pdSendGate!.release());
  314. await waitForV4TimelineContaining("RECENT_MODE_SECOND_DONE");
  315. expect(await browser.execute(() => window.__pdSendGate!.count)).toBe(1);
  316. expect((await getV4PaneSnapshot()).sessionId).not.toBe("draft");
  317. await startTask();
  318. expect(await path()).not.toBe(pendingPath);
  319. await waitForV4ComposerText("", "迟到接纳污染下一份任务草稿");
  320. await expectMode("yolo");
  321. } finally {
  322. await browser.execute(() => window.__pdSendGate?.restore());
  323. }
  324. });
  325. // CASE_DIR 位于隔离 HOME 内,由 runner 在进程退出后统一删除;Host 仍监听项目目录时
  326. // 提前删除会在 Windows 上 EBUSY。
  327. after(async () => {
  328. await clearAppData();
  329. });
  330. it("TD01/03/04: 空白不保存,文字刷新恢复,删空后 New Task 重新取默认", async () => {
  331. await skipOccupationOnboardingIfPresent();
  332. await startDraftFromProject(DEFAULT_WORKSPACE);
  333. await ensureUpstreamProviderForE2E({ skipToolbarSelection: true });
  334. await switchV4Model(UPSTREAM_PROVIDER_ID, UPSTREAM_MODEL, "");
  335. await switchV4Mode("yolo");
  336. expect((await getV4ComposerDraftScopeSnapshot(DEFAULT_WORKSPACE, null)).exists).toBe(false);
  337. await setV4ComposerText("unsent text persistence");
  338. await browser.waitUntil(
  339. async () =>
  340. (await getV4ComposerDraftScopeSnapshot(DEFAULT_WORKSPACE, null)).text ===
  341. "unsent text persistence",
  342. );
  343. await browser.refresh();
  344. try {
  345. await waitForV4ComposerText("unsent text persistence", "刷新没有恢复文字草稿");
  346. } catch (error) {
  347. const diagnosis = await browser.executeAsync(async (done) => {
  348. const script = document.querySelector<HTMLScriptElement>('script[type="module"]');
  349. let moduleError = "";
  350. try {
  351. if (script?.src) await import(script.src);
  352. } catch (cause) {
  353. moduleError = String(cause);
  354. }
  355. done({
  356. body: document.body.innerText,
  357. moduleError,
  358. url: location.href,
  359. storage: Object.entries(localStorage).filter(([key]) => key.includes("composer-")),
  360. });
  361. });
  362. await mkdir(EVIDENCE_DIR, { recursive: true });
  363. await writeFile(
  364. join(EVIDENCE_DIR, "refresh-failure.json"),
  365. JSON.stringify(diagnosis, null, 2),
  366. );
  367. throw error;
  368. }
  369. await expectMode("yolo");
  370. await setV4ComposerText(" ");
  371. await browser.waitUntil(
  372. async () => !(await getV4ComposerDraftScopeSnapshot(DEFAULT_WORKSPACE, null)).exists,
  373. );
  374. await startDraftFromProject(DEFAULT_WORKSPACE);
  375. await expectMode("build");
  376. await switchV4Mode("yolo");
  377. await startDraftFromProject(DEFAULT_WORKSPACE);
  378. await expectMode("build");
  379. expect((await getV4ComposerDraftScopeSnapshot(DEFAULT_WORKSPACE, null)).exists).toBe(false);
  380. await captureState("00-text-only-draft");
  381. });
  382. it("I74/I75: 完全访问首发后 New Task 保留权限,已有草稿与 Session 选择仍各自独立", async () => {
  383. // 修复原因:PD03 已把 CASE_DIR/new-primary 存为项目主要目录,Host 仍在监听该目录;
  384. // Windows 上删除被监听目录会 EBUSY。本用例只需清掉自己断言的写入结果。
  385. await mkdir(CASE_DIR, { recursive: true });
  386. await rm(join(CASE_DIR, "result.txt"), { force: true });
  387. await skipOccupationOnboardingIfPresent();
  388. await startDraftFromProject(DEFAULT_WORKSPACE);
  389. await ensureUpstreamProviderForE2E({ skipToolbarSelection: true });
  390. // 本用例验证模型身份和权限,不强制当前模型目录未提供的思考档位。
  391. await switchV4Model(UPSTREAM_PROVIDER_ID, UPSTREAM_MODEL, "");
  392. await expectMode("build");
  393. await switchV4Mode("yolo");
  394. await expectMode("yolo");
  395. const selected = await getV4ModelConfig();
  396. await sendV4PromptAndWaitAccepted(
  397. "E2E_COMPOSER_RECENT_MODE_SEED 请回复测试标记。",
  398. "E2E_COMPOSER_RECENT_MODE_SEED",
  399. "第一次输入未被接纳",
  400. );
  401. await waitForV4TimelineContaining("RECENT_MODE_STREAMING");
  402. const firstSession = (await getV4PaneSnapshot()).sessionId!;
  403. const first = await captureState("01-accepted-yolo");
  404. expect(first.composer.mode).toBe("yolo");
  405. expect(first.pane.canStop).toBe(true);
  406. await startDraftFromProject(DEFAULT_WORKSPACE);
  407. await waitForV4ComposerSelectionReady();
  408. const next = await captureState("02-new-task-mode");
  409. // 修复前这里稳定取得 actual=build,证明是新 Root 初始化回退。
  410. expect(next.composer.mode).toBe("yolo");
  411. expect(next.rootDraft.exists).toBe(false);
  412. expect(next.composer).toMatchObject({ provider: selected.provider, model: selected.model });
  413. await sendV4PromptAndWaitAccepted(
  414. `E2E_COMPOSER_RECENT_MODE_WRITE 请写入 ${OUTPUT_PATH}`,
  415. "E2E_COMPOSER_RECENT_MODE_WRITE",
  416. "继承权限后的输入未被接纳",
  417. );
  418. await waitForV4TimelineContaining("RECENT_MODE_DONE", 60_000);
  419. const secondSession = (await getV4PaneSnapshot()).sessionId!;
  420. expect(secondSession).not.toBe(firstSession);
  421. expect(await readFile(join(CASE_DIR, "result.txt"), "utf8")).toBe("RECENT_MODE_WRITE_OK\n");
  422. expect(
  423. (await getLatestUpstreamToolResultByToolCallId("toolu_recent_mode_write"))?.isError,
  424. ).toBe(false);
  425. await captureState("03-inherited-mode-executed");
  426. await startDraftFromProject(DEFAULT_WORKSPACE);
  427. await expectMode("yolo");
  428. // TD02:先打开空白页,再回原 Session 改选 B 并发送,旧空白页不能覆盖 Recent。
  429. await selectV4TaskById(secondSession);
  430. await switchV4Mode("build");
  431. await switchV4Model(UPSTREAM_PROVIDER_ID, UPSTREAM_SECONDARY_MODEL, "");
  432. await sendV4PromptAndWaitAccepted(
  433. "E2E_COMPOSER_RECENT_MODE_SECOND 回复标记。",
  434. "E2E_COMPOSER_RECENT_MODE_SECOND",
  435. "第二次选择未被接纳",
  436. );
  437. await waitForV4TimelineContaining("RECENT_MODE_SECOND_DONE");
  438. await startDraftFromProject(DEFAULT_WORKSPACE);
  439. await expectMode("build");
  440. const updated = await captureState("04-new-task-model-b");
  441. expect(updated.composer.model).toBe(UPSTREAM_SECONDARY_MODEL);
  442. expect(updated.rootDraft.exists).toBe(false);
  443. // TD04:同一个空白页面再次 New Task,丢弃未提交配置;删空文字后也不留记录。
  444. await switchV4Mode("yolo");
  445. await startDraftFromProject(DEFAULT_WORKSPACE);
  446. await expectMode("build");
  447. await setV4ComposerText("temporary draft");
  448. await browser.waitUntil(
  449. async () =>
  450. (await getV4ComposerDraftScopeSnapshot(DEFAULT_WORKSPACE, null)).text === "temporary draft",
  451. );
  452. await setV4ComposerText("");
  453. await browser.waitUntil(
  454. async () => !(await getV4ComposerDraftScopeSnapshot(DEFAULT_WORKSPACE, null)).exists,
  455. );
  456. await setV4ComposerText("unsent root draft");
  457. await switchV4Mode("plan");
  458. await selectV4TaskById(firstSession);
  459. await expectMode("yolo");
  460. await setV4ComposerText("unsent session draft");
  461. await switchV4Mode("build");
  462. await selectV4TaskById(secondSession);
  463. await expectMode("build");
  464. await startDraftFromProject(DEFAULT_WORKSPACE);
  465. await expectMode("build");
  466. await $('[data-testid="v4-composer-plan-marker"]').waitForDisplayed();
  467. await browser.refresh();
  468. await expectMode("build");
  469. await $('[data-testid="v4-composer-plan-marker"]').waitForDisplayed();
  470. await selectV4TaskById(firstSession);
  471. // 刷新后的缓存草稿可先于历史投影就绪;必须等旧 Snapshot 恢复后再断言不被覆盖。
  472. await waitForV4TimelineContaining("RECENT_MODE_STREAMING");
  473. // 正式会话重开恢复文字,权限取最新 Snapshot;未发送的菜单选择不替代运行事实。
  474. await expectMode("yolo");
  475. await waitForV4ComposerText("unsent session draft", "正式会话的文字草稿未恢复");
  476. await captureState("05-session-draft-isolation");
  477. });
  478. });