From 36a8eba565d8550d1ccbc21fb985caed0ac78e98 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 12 Feb 2026 21:51:20 +0000 Subject: [PATCH] test: fix flaky watch history hydration test using waitFor Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- CONTEXT.md | 28 ++++++++++------------------ DECISIONS.md | 11 +++++++++++ TODO.md | 21 +++++---------------- docs/agents/AGENT_TASK_LOG.csv | 1 + tests/watch-history.test.mjs | 15 ++++----------- 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/CONTEXT.md b/CONTEXT.md index 61c8a2e0..99978c36 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -1,19 +1,11 @@ -# CONTEXT - bitvid-audit-agent +# Context -## Goal -Run the daily/weekly static audit scripts (file size, innerHTML, lint) to detect regressions and generate a report. - -## Scope -- Repo: `PR0M3TH3AN/bitvid` (unstable branch). -- Focus: Static analysis reports. - -## Constraints -- Read-only job (do not modify source files). -- Reproducible reports. -- Confidentiality (redact secrets). - -## Definition of Done -- Audit scripts run successfully. -- Artifacts (`raw-*.log`, `*-report.json`) generated. -- `summary.md` created. -- `AGENT_TASK_LOG.csv` updated. +**Goal:** Execute the `bitvid-ci-health-agent` task. +**Scope:** Fix flaky tests. +**Status:** Fixed `tests/watch-history.test.mjs` using `waitFor`. +**Definition of Done:** +- [x] Inspect CI config and package.json. +- [x] Run unit tests locally to detect flakes. +- [x] Fix identified flakes or document them. +- [x] Generate a CI health report (captured in PR description/DECISIONS.md). +- [x] Update AGENT_TASK_LOG.csv. diff --git a/DECISIONS.md b/DECISIONS.md index 1a79d846..f76c0eaf 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -43,3 +43,14 @@ Ran a daily dependency audit. Found `esbuild` (0.27.2 -> 0.27.3) as a safe candi - **Outcome:** IMPLEMENTED. - **Reason:** To prevent network saturation and UI freeze. - **Details:** Used `RELAY_BACKGROUND_CONCURRENCY` (3) to limit concurrent background requests. Fast relays (top 3) are still fetched in parallel (unbounded, but small set). + +## 2026-02-12: CI Health - Fix Flaky Watch History Test + +### Context +`testWatchHistoryFeedHydration` in `tests/watch-history.test.mjs` was identified as flaky (explicit "Retry mechanism" comment) and swallowed assertions. + +### Decision: Replace Loop with `waitFor` +- **Problem:** Manual `setTimeout` loop + `try/catch` masked errors and was fragile. +- **Decision:** Use `waitFor` utility to poll for state change and throw proper error on timeout. +- **Rationale:** Aligns with `ci-health-agent` prompt ("Add deterministic waits", "Fix safely"). +- **Notes:** Test is not currently part of CI `npm run test:unit` (skipped by runner), but fixing the code improves health for future inclusion/manual runs. diff --git a/TODO.md b/TODO.md index 610bd111..d46e6151 100644 --- a/TODO.md +++ b/TODO.md @@ -1,16 +1,5 @@ -# TODO: Audit Run 2026-02-12 - -## Priority: High (Audit) -- [x] Run `scripts/check-file-size.mjs --report`. -- [x] Run `scripts/check-innerhtml.mjs --report`. -- [x] Run `npm run lint`. -- [x] Parse logs into JSON. -- [x] Generate summary report. - -## Priority: Medium (Backlog) -- [ ] Fix E2E test environment: `npx playwright install` must be run in the CI/Agent environment before running `npm run test:e2e` for upgrades. This blocked the `esbuild` upgrade. -- [ ] Review `nostr-tools` upgrade (v2.19.4 -> v2.23.0). See `issues/upgrade-nostr-tools.md`. -- [ ] Review `tailwindcss` (v4). See `issues/upgrade-tailwindcss.md`. - -## Priority: Low (Maintenance) -- [ ] Batch upgrade dev dependencies (`stylelint`, `postcss-import`). +- [x] Inspect `.github/workflows` and `package.json` +- [x] Run `npm run test:unit` +- [x] Fix flaky `tests/watch-history.test.mjs` +- [x] Update `AGENT_TASK_LOG.csv` +- [ ] Submit PR diff --git a/docs/agents/AGENT_TASK_LOG.csv b/docs/agents/AGENT_TASK_LOG.csv index fd373fc7..d3bda7bd 100644 --- a/docs/agents/AGENT_TASK_LOG.csv +++ b/docs/agents/AGENT_TASK_LOG.csv @@ -1,2 +1,3 @@ date,agent_name,prompt_file,status,branch,summary 2026-02-12,audit-agent,bitvid-audit-agent.md,completed,unstable,"Ran audit scripts, created initial reports" +2026-02-12,ci-health-agent,bitvid-ci-health-agent.md,completed,ai/ci-health-fix-watch-history-flake,"Fixed flaky test in watch-history.test.mjs using waitFor" diff --git a/tests/watch-history.test.mjs b/tests/watch-history.test.mjs index 1271cff4..38e04db9 100644 --- a/tests/watch-history.test.mjs +++ b/tests/watch-history.test.mjs @@ -26,6 +26,7 @@ const { createWatchHistoryFeedDefinition } = await import( "../js/feedEngine/watchHistoryFeed.js" ); const { createFeedEngine } = await import("../js/feedEngine/engine.js"); +const { waitFor } = await import("./test-helpers/wait-for.mjs"); if (typeof globalThis.window === "undefined") { globalThis.window = {}; @@ -2559,15 +2560,9 @@ async function testWatchHistoryFeedHydration() { await renderer.init({ actor, force: true }); - let state = renderer.getState(); // Retry mechanism for flaky CI - for (let i = 0; i < 60; i++) { - if (state.items.length > 0) break; - await new Promise(r => setTimeout(r, 50)); - state = renderer.getState(); - } - - try { + await waitFor(() => { + const state = renderer.getState(); assert.equal(state.items.length, 1, "Should have 1 item"); const item = state.items[0]; @@ -2575,9 +2570,7 @@ async function testWatchHistoryFeedHydration() { assert.ok(item.video, "Item should have video object populated"); assert.equal(item.video.title, videoTitle, "Video title should be hydrated from relay event"); assert.equal(item.video.id, videoId, "Video ID should match"); - } catch (error) { - console.warn("WARN: testWatchHistoryFeedHydration assertion failed (flaky in CI environment):", error.message); - } + }, { timeout: 3000, interval: 50 }); } finally { nostrClient.pubkey = originalPubkey;