test: fix flaky watch history hydration test using waitFor

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-12 21:51:20 +00:00
1 parent f482909550
commit 36a8eba565
5 files changed
+31 -45

No files matched your search

+10 -18
View File
@@ -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.
+11
View File
@@ -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.
+5 -16
View File
@@ -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
+1
View File
@@ -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"
1 date agent_name prompt_file status branch summary
2 2026-02-12 audit-agent bitvid-audit-agent.md completed unstable Ran audit scripts, created initial reports
3 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
+4 -11
View File
@@ -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;