diff --git a/scripts/web-live-dom-probe.mjs b/scripts/web-live-dom-probe.mjs index 531534cb..fb668489 100644 --- a/scripts/web-live-dom-probe.mjs +++ b/scripts/web-live-dom-probe.mjs @@ -737,7 +737,8 @@ async function waitForSessionShellReady(page, args, actions) { const statusText = document.querySelector("#session-status")?.textContent?.trim() ?? ""; const workspace = document.querySelector("#workspace"); const create = document.querySelector("#session-create"); - return Boolean(workspace && create && !create.disabled && statusText && !/加载中|等待 workspace/u.test(statusText)); + const input = document.querySelector("#command-input"); + return Boolean(workspace && create && !create.disabled && input && !input.disabled && statusText && !/加载中/u.test(statusText)); }, null, { timeout: timeoutMs }).catch(() => null); const after = await collectSessionState(page, args); const result = { action: "session-shell-ready", ready: Boolean(ready), timeoutMs, before, after }; @@ -880,6 +881,9 @@ function summarizeConversationsFetch(fetchResult) { async function submitPrompt(page, args, actions) { const readyBefore = await waitForCommandReady(page, args, actions); + const fresh = [...actions].reverse().find((item) => item.action === "fresh-session") ?? null; + const targetConversationId = firstNonEmpty(fresh?.alignment?.check?.conversationId, fresh?.alignment?.after?.routeConversationId, fresh?.after?.routeConversationId); + if (targetConversationId) await ensureConversationAligned(page, args, targetConversationId, actions, "pre-submit-realign"); await page.locator("#command-input").fill(args.message); await page.waitForFunction((expected) => { const input = document.querySelector("#command-input"); @@ -894,6 +898,21 @@ async function submitPrompt(page, args, actions) { await page.waitForTimeout(args.waitAfterSubmitMs); } +async function ensureConversationAligned(page, args, conversationId, actions, action) { + const before = await collectSessionState(page, args); + const beforeAligned = before.routeConversationId === conversationId && before.api?.workspace?.selectedConversationId === conversationId; + if (beforeAligned) { + actions.push({ action, conversationId, aligned: true, repaired: false, before: compactSessionState(before) }); + return before; + } + const repair = await realignFreshSession(page, args, conversationId); + const after = await collectSessionState(page, args); + const aligned = after.routeConversationId === conversationId && after.api?.workspace?.selectedConversationId === conversationId; + actions.push({ action, conversationId, aligned, repaired: true, before: compactSessionState(before), after: compactSessionState(after), repair }); + if (!aligned) throw new Error(`${action} failed: ${JSON.stringify({ conversationId, before: compactSessionState(before), after: compactSessionState(after), repair })}`); + return after; +} + async function sampleTraceTimeline(page, args, actions) { const samples = []; for (let index = 0; index < args.traceSampleCount; index += 1) {