Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

消除跨平台浏览器夹具初始化竞争

MigenAI5e6b2b21f1a6
diff --git a/test/e2e_support.py b/test/e2e_support.py
index b41e815..480b34d 100644
--- a/test/e2e_support.py
+++ b/test/e2e_support.py
@@ -40,13 +40,39 @@ class ExtensionTestSession:
return page
def seed_storage(self, page: Page, payload: dict) -> None:
- page.evaluate(
- """async (payload) => {
- await chrome.storage.local.clear();
- await chrome.storage.local.set(payload);
- }""",
- payload,
- )
+ seed_extension_storage(page, payload)
+
+
+def seed_extension_storage(page: Page, payload: dict) -> None:
+ """Seed a fixture only after the extension's first state migration has settled."""
+ result = page.evaluate(
+ """async (payload) => {
+ await chrome.runtime.sendMessage({type: 'GET_STATE'});
+ await chrome.storage.local.clear();
+ await chrome.storage.local.set(payload);
+ const state = await chrome.runtime.sendMessage({type: 'GET_STATE'});
+ const expectedEntryIds = (payload.entries ?? []).map((entry) => entry.id);
+ const actualEntryIds = new Set((state.entries ?? []).map((entry) => entry.id));
+ const expectedRunIds = (payload.creativeRuns ?? []).map((run) => run.id);
+ const actualRunIds = new Set((state.creativeRuns ?? []).map((run) => run.id));
+ const missingEntryIds = expectedEntryIds.filter((id) => !actualEntryIds.has(id));
+ const missingRunIds = expectedRunIds.filter((id) => !actualRunIds.has(id));
+ const missingSessionIds = [];
+ for (const session of payload.composerSessions ?? []) {
+ const response = await chrome.runtime.sendMessage({
+ type: 'GET_COMPOSER_SESSION',
+ sessionId: session.id
+ });
+ if (!response?.ok) missingSessionIds.push(session.id);
+ }
+ return {ok: state.ok, missingEntryIds, missingRunIds, missingSessionIds};
+ }""",
+ payload,
+ )
+ assert result["ok"] is True, result
+ assert not result["missingEntryIds"], result
+ assert not result["missingRunIds"], result
+ assert not result["missingSessionIds"], result
@contextmanager
diff --git a/test/library_132_e2e.py b/test/library_132_e2e.py
index 2aef486..b41aacb 100644
--- a/test/library_132_e2e.py
+++ b/test/library_132_e2e.py
@@ -5,7 +5,7 @@ from pathlib import Path
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError, expect, sync_playwright
-from e2e_support import launch_context
+from e2e_support import launch_context, seed_extension_storage
EXTENSION_DIR = Path(__file__).resolve().parents[1]
@@ -83,13 +83,7 @@ def main() -> None:
extension_id = worker.url.split("/")[2]
setup = context.new_page()
setup.goto(f"chrome-extension://{extension_id}/collector.html")
- setup.evaluate(
- """async (entries) => {
- await chrome.storage.local.clear();
- await chrome.storage.local.set({schemaVersion: 3, entries});
- }""",
- make_entries(),
- )
+ seed_extension_storage(setup, {"schemaVersion": 3, "entries": make_entries()})
library = context.new_page()
library.add_init_script(
diff --git a/test/text_and_image_analysis_e2e.py b/test/text_and_image_analysis_e2e.py
index 3075806..9c29800 100644
--- a/test/text_and_image_analysis_e2e.py
+++ b/test/text_and_image_analysis_e2e.py
@@ -52,7 +52,8 @@ def main() -> None:
TINY_PNG,
)
library = session.open_page("library.html", wait_until="networkidle")
- library.locator("#open-settings").click()
+ if not library.locator("#settings-dialog").is_visible():
+ library.locator("#open-settings").click()
library.locator('[data-settings-tab="tasks"]').click()
library.locator("#preview-analysis-batch").click()
expect(library.locator("#analysis-batch-summary")).to_contain_text("1 次请求")