test: cover benchmark dashboard renderer#302
Conversation
📝 WalkthroughWalkthroughnew test file validates the benchmark dashboard script's cli behavior by creating temporary directories, writing test summary data, spawning the process with input/output arguments, and asserting successful execution with expected html output. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes review noteswindows compatibility risk: missing regression test coverage: the test validates happy path (successful execution, correct html output) but doesn't cover error cases. consider adding tests for:
concurrency consideration: temporary directory cleanup in test isolation: ensure temp directories don't accumulate if tests fail. current recursive deletion pattern is solid but verify 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/benchmark-render-dashboard-script.test.ts`:
- Around line 23-90: Add edge-case tests alongside the existing happy-path in
test/benchmark-render-dashboard-script.test.ts: add one test that spawns the
script (using process.execPath and scriptPath) with a non-existent --input and
asserts non-zero exit and stderr includes a helpful message; add one test that
writes malformed JSON to the inputPath, spawns the script, and asserts non-zero
exit and stderr contains JSON parse or summary error; add one test that points
--output to a file inside a non-existent directory and assert either the script
creates the directory and exits 0 (check stdout "Dashboard written:" and that
file exists) or it exits non-zero with a clear stderr; use the same
mkdtempSync/tempRoots pattern and spawnSync and readFileSync to implement these
checks so they run alongside the existing test.
- Around line 79-86: Update the test that runs spawnSync so failed runs surface
stderr and the process can't hang: when calling spawnSync (the call using
process.execPath and scriptPath), add the timeout option (e.g., timeout: <ms>)
and update the assertions to include or log result.stderr when result.status is
not 0; specifically, include result.stderr in the expect failure message or an
additional expect toContain/length check so error output is visible alongside
the existing expect(result.stdout).toContain("Dashboard written:").
- Line 81: Add a regression test that passes Windows-like paths containing
spaces to the benchmark-render-dashboard script to lock in correct parsing; in
the test file (test/benchmark-render-dashboard-script.test.ts) add a case that
creates a temporary input path with spaces (e.g., using tmp or fs.mkdtemp and a
filename with a space) and invokes spawnSync with the same argument array
pattern ([scriptPath, `--input=${inputPathWithSpaces}`,
`--output=${outputPath}`]) to assert the script
(scripts/benchmark-render-dashboard.mjs) still receives and parses the
`--input=PATH` form correctly (note the script's parser at lines ~18-22 slices
after '='), then verify expected behavior or output.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0f2c8cc1-de5d-43ce-a413-054da3ac93f2
📒 Files selected for processing (1)
test/benchmark-render-dashboard-script.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Greptile Review
🧰 Additional context used
📓 Path-based instructions (1)
test/**
⚙️ CodeRabbit configuration file
tests must stay deterministic and use vitest. demand regression cases that reproduce concurrency bugs, token refresh races, and windows filesystem behavior. reject changes that mock real secrets or skip assertions.
Files:
test/benchmark-render-dashboard-script.test.ts
🔇 Additional comments (2)
test/benchmark-render-dashboard-script.test.ts (2)
14-21: cleanup logic looks solid.the
afterEachhook withrmSync({ recursive: true, force: true })handles leftover temp dirs correctly, and theforceflag avoids throws on already-deleted paths. no issues here.
1-12: imports and setup are clean.using
node:prefixed imports is good practice for clarity.tempRootsarray at module scope works fine with vitest's isolation model.
Summary
scripts/benchmark-render-dashboard.mjsValidation
npm run typechecknpm run lint -- test/benchmark-render-dashboard-script.test.tsnpm run test -- test/benchmark-render-dashboard-script.test.tsnode scripts/benchmark-render-dashboard.mjs --input=<fixture> --output=<tmp>/dashboard.htmlnote: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
adds a focused smoke-test suite for
scripts/benchmark-render-dashboard.mjs, covering the happy path, spaced paths (windows safety), and three error branches (missing input file, malformed json, missing output dir). the test follows project conventions correctly:removeWithRetrywithEBUSY/EPERM/ENOTEMPTYbackoff for windows filesystem safety,spawnSyncwith an explicit 10s timeout, and absolute temp paths viamkdtempSync.removeWithRetryimplementation correctly mirrors the pattern used acrossrepo-hygiene.test.ts,rotation-integration.test.ts, andunified-settings.test.tsstartsWith+slicerather than shell splittingafterEachregistered at module level (outsidedescribe) is idiomatic vitest and works correctly here--inputbranch exits viaprocess.exitCode = 1; return;(notprocess.exit(1)), sostderris empty and the.catch()handler never fires — this path has no test caseConfidence Score: 5/5
Important Files Changed
--inputusage branch which exits viaprocess.exitCoderather thanprocess.exitSequence Diagram
sequenceDiagram participant T as vitest test participant S as spawnSync participant N as node (child process) participant FS as filesystem (tmpdir) T->>FS: mkdtempSync → create temp root T->>FS: writeFileSync → write summary.json fixture T->>S: spawnSync(node, [scriptPath, --input=..., --output=...]) S->>N: spawn child process (timeout 10s) N->>FS: readFile(inputPath) N->>N: JSON.parse + renderDashboardHtml() N->>FS: writeFile(outputPath, html) N-->>S: stdout "Dashboard written:", status 0 S-->>T: SpawnSyncReturns T->>FS: readFileSync(outputPath) → assert html contents T->>FS: afterEach removeWithRetry(root, recursive+force)Prompt To Fix All With AI
Last reviewed commit: "test: harden benchma..."