From 62c05e7f7e6573900af439047fe1579a03deea26 Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:53:51 +0800 Subject: [PATCH] test(ci): isolate flaky scenarios and retain failure diagnostics (#6622) * test(ci): isolate HTTP stubs and retain failure diagnostics * test(agent): scope compaction watchdogs to each phase * test(webui): isolate settings skeleton scenarios * test(webui): await rendered rail content before scroll checks --- .github/workflows/ci.yml | 14 ++++++++- nanobot/channels/websocket/tests/conftest.py | 2 ++ scripts/pytest_timing.py | 2 ++ tests/agent/test_auto_compact.py | 30 +++++++++----------- tests/scripts/test_pytest_timing.py | 1 + webui/browser/prompt-rail.spec.ts | 5 +++- webui/browser/skeleton-additions.spec.ts | 8 +++--- 7 files changed, 40 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a00326c3..515bf95bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,6 +185,7 @@ jobs: run: >- uv run --no-sync python -m pytest ${{ matrix.pytest_args }} + -o faulthandler_timeout=60 --junitxml=test-results/main.xml --timing-report=test-results/main.json --durations=25 --durations-min=1.0 @@ -371,7 +372,18 @@ jobs: - name: Test browser layout and history motion working-directory: webui - run: bun run test:browser + run: bun run test:browser --trace=retain-on-failure + + - name: Retain browser failure details + if: failure() + uses: actions/upload-artifact@v4 + with: + name: browser-failures + path: | + webui/test-results/browser/**/trace.zip + webui/test-results/browser/**/test-failed-*.png + webui/test-results/browser/**/error-context.md + retention-days: 7 webui: needs: [changes, webui_checks, webui_browser] diff --git a/nanobot/channels/websocket/tests/conftest.py b/nanobot/channels/websocket/tests/conftest.py index e1a4c85fe..0fe88fc9c 100644 --- a/nanobot/channels/websocket/tests/conftest.py +++ b/nanobot/channels/websocket/tests/conftest.py @@ -10,3 +10,5 @@ def isolate_websocket_runtime_data( ) -> None: """Keep transcripts and other runtime files out of the active user data directory.""" monkeypatch.setattr("nanobot.config.paths.get_data_dir", lambda: tmp_path) + # In-process routes must not intercept a later test's real listener on a reused port. + monkeypatch.setattr("nanobot.channels.websocket.tests.ws_test_client._IN_PROCESS_HTTP_CHANNELS", {}) diff --git a/scripts/pytest_timing.py b/scripts/pytest_timing.py index 141a5bb83..4bf1d3bc9 100644 --- a/scripts/pytest_timing.py +++ b/scripts/pytest_timing.py @@ -46,6 +46,8 @@ class _TimingReport: case["phases"][report.when] = { "seconds": report.duration, "outcome": report.outcome, } + if report.failed: + case["phases"][report.when]["failure"] = report.longreprtext def pytest_sessionfinish(self, exitstatus: int) -> None: elapsed = time.perf_counter() - self.started diff --git a/tests/agent/test_auto_compact.py b/tests/agent/test_auto_compact.py index e44f41b56..4075d888d 100644 --- a/tests/agent/test_auto_compact.py +++ b/tests/agent/test_auto_compact.py @@ -1361,7 +1361,7 @@ async def test_idle_compaction_rechecks_settled_activity(tmp_path, monkeypatch, _add_turns(session, 2) session.updated_at = now[0] - timedelta(minutes=20) loop.sessions.save(session) - entered, release = asyncio.Event(), asyncio.Event() + entered, release, settled = asyncio.Event(), asyncio.Event(), asyncio.Event() archived = [] other_responses = [] @@ -1381,30 +1381,30 @@ async def test_idle_compaction_rechecks_settled_activity(tmp_path, monkeypatch, try: await asyncio.wait_for(entered.wait(), 5) now[0] += timedelta(minutes=20) - if ordering == "scan_during_turn": - loop._next_idle_compact_check_at = 0 - await loop._check_expired_sessions_if_due() - other_responses.append(await asyncio.wait_for( - loop.process_direct("other input", session_key="cli:other"), 5, - )) - assert archived == [] + async with asyncio.timeout(5): + if ordering == "scan_during_turn": + loop._next_idle_compact_check_at = 0 + await loop._check_expired_sessions_if_due() + other_responses.append(await loop.process_direct("other input", session_key="cli:other")) + assert archived == [] finally: release.set() + await asyncio.wait_for(settled.wait(), 5) loop.provider.chat_stream_with_retry.side_effect = respond loop.consolidator.archive_session = archive - finishing = None try: if ordering == "archive_queued_before_turn": loop._next_idle_compact_check_at = 0 await loop._check_expired_sessions_if_due() assert key in loop.auto_compact._archiving - finishing = asyncio.create_task(finish_turn()) - # Await inline: the direct call takes the free lock before the already - # scheduled archive task runs. No scheduler or lock is replaced. - async with asyncio.timeout(5): + # Each phase owns its watchdog; the held turn intentionally waits for + # another session. A phase failure cancels the inline turn through the group. + async with asyncio.TaskGroup() as tasks: + tasks.create_task(finish_turn()) + # Await inline so admission still precedes the queued archive task. response = await loop.process_direct("new input", session_key=key) - await asyncio.wait_for(finishing, 5) + settled.set() await asyncio.wait_for(_drain_background_tasks(loop), 5) assert len(archived) == 0 saved = await loop.sessions.state.get(key) @@ -1426,6 +1426,4 @@ async def test_idle_compaction_rechecks_settled_activity(tmp_path, monkeypatch, assert key not in loop.auto_compact._archiving finally: release.set() - if finishing is not None: - await asyncio.wait_for(asyncio.gather(finishing, return_exceptions=True), 5) await asyncio.wait_for(loop.aclose(), 10) diff --git a/tests/scripts/test_pytest_timing.py b/tests/scripts/test_pytest_timing.py index bc0bd0688..c9a53b01c 100644 --- a/tests/scripts/test_pytest_timing.py +++ b/tests/scripts/test_pytest_timing.py @@ -24,6 +24,7 @@ def test_timing_report_preserves_phases_and_failed_results(pytester: pytest.Pyte cases = {key.rsplit("::", 1)[-1]: value for key, value in report["cases"].items()} assert cases["test_pass"]["phases"]["call"]["outcome"] == "passed" assert cases["test_fail"]["phases"]["call"]["outcome"] == "failed" + assert "AssertionError" in cases["test_fail"]["phases"]["call"]["failure"] assert cases["test_skip"]["phases"]["setup"]["outcome"] == "skipped" assert sum(phase["seconds"] for case in cases.values() for phase in case["phases"].values()) > 0 diff --git a/webui/browser/prompt-rail.spec.ts b/webui/browser/prompt-rail.spec.ts index 755a4f74b..70e681c36 100644 --- a/webui/browser/prompt-rail.spec.ts +++ b/webui/browser/prompt-rail.spec.ts @@ -29,7 +29,10 @@ test("complete rail scrolls independently, jumps to unloaded history and returns await expectRailCentered(); await expect.poll(() => rail.evaluate((node) => node.scrollHeight)).toBe(32024); expect(reads).toHaveLength(0); - // Lazy markdown and content-visibility can change the scroll range during startup. + // A stationary lazy-render fallback is not a settled transcript. + await expect(body.locator('[data-thread-display-unit="a1999"] .markdown-content p')).toHaveCount(8); + await page.evaluate(async () => { await document.fonts.ready; }); + // Content visibility and the camera can still settle after the renderer is ready. await body.evaluate(async (node) => { let previous = -1; let stable = 0; diff --git a/webui/browser/skeleton-additions.spec.ts b/webui/browser/skeleton-additions.spec.ts index 237e12863..ed0af5926 100644 --- a/webui/browser/skeleton-additions.spec.ts +++ b/webui/browser/skeleton-additions.spec.ts @@ -54,8 +54,8 @@ for (const width of [390, 1440]) for (const locale of ["en", "zh-CN"]) { } }); - test("settings sections preserve their loaded row layout", async ({ page }, testInfo) => { - for (const surface of ["notifications", "capabilities", "runtime", "advanced", "sandbox", "overview", "models", "about"]) { + for (const surface of ["notifications", "capabilities", "runtime", "advanced", "sandbox", "overview", "models", "about"]) { + test(`settings ${surface} preserves its loaded row layout`, async ({ page }, testInfo) => { const section = surface === "sandbox" ? "advanced" : surface; const extra = `§ion=${section}${section === "notifications" ? "¬ificationPermission=granted" : ""}${surface === "sandbox" ? "&sandboxSettings" : ""}`; await page.goto(fixture("settings", "loaded", extra)); @@ -93,8 +93,8 @@ for (const width of [390, 1440]) for (const locale of ["en", "zh-CN"]) { await testInfo.attach("notifications-layout", { body: JSON.stringify({ loaded, skeleton, loadedControls, skeletonControls }, null, 2), contentType: "application/json" }); } await accessibleSkeleton(page); - } - }); + }); + } test("appearance stays usable and keeps its layout while gateway settings load or fail", async ({ page }) => { await page.addInitScript(() => localStorage.setItem("nanobot-webui.settings-preferences", JSON.stringify({