Skip to content

chore(test): add ci benchmark harness#5912

Merged
killagu merged 9 commits into
nextfrom
agent/egg-dev/e176f152
May 3, 2026
Merged

chore(test): add ci benchmark harness#5912
killagu merged 9 commits into
nextfrom
agent/egg-dev/e176f152

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented May 2, 2026

Summary

  • add a reusable CI test benchmark harness that wraps Vitest JSON reporter output
  • generate Markdown, summary JSON, and raw Vitest JSON reports with environment, command, timing, parameter, project, and file-duration data
  • expose the harness as pnpm run benchmark:ci-test without changing CI required checks

Test

  • node --check scripts/ci-test-benchmark.js
  • pnpm exec oxfmt --check scripts/ci-test-benchmark.js package.json
  • pnpm exec oxlint scripts/ci-test-benchmark.js
  • pnpm run benchmark:ci-test -- --dry-run --output-dir .tmp/ci-benchmark-package-default-dry-run
  • pnpm run benchmark:ci-test -- --output-dir .tmp/ci-benchmark-package-custom-2 --top 5 -- pnpm exec vitest run packages/extend2/test/index.test.ts

Summary by CodeRabbit

  • New Features
    • Adds a CI-focused benchmark command to run or dry-run test benchmarks.
    • Produces machine-readable JSON and human-readable Markdown reports with timings, environment info, and long-tail test-duration summaries.
    • Offers CLI options to customize output location, naming, top-results limits, coverage inclusion, and execution behavior.

Copilot AI review requested due to automatic review settings May 2, 2026 15:17
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an npm script and a standalone Node CLI (scripts/ci-test-benchmark.js) that constructs and runs a Vitest (or custom) command, captures timing and environment metadata, optionally reads Vitest JSON results, summarizes per-file and per-project long-tail durations, and writes report.json and report.md to a run-specific output directory.

Changes

CI Benchmark Test Infrastructure

Layer / File(s) Summary
Script Registration
package.json
Adds benchmark:ci-test npm script mapping to node scripts/ci-test-benchmark.js.
CLI Entry & Constants
scripts/ci-test-benchmark.js
Introduces CLI entrypoint, defaults, filenames, {vitestJson} placeholder, and help text.
Argument Parsing
scripts/ci-test-benchmark.js (parseArgs)
Parses flags: --output-dir, --name, --top, --coverage, --dry-run, --no-append-vitest-json-reporter, --help; supports custom command args after -- and argv normalization.
Output Pathing & Run ID
scripts/ci-test-benchmark.js (normalizeOutputDir, createRunId)
Resolves/creates absolute output directory and constructs run-scoped file paths for reports and raw Vitest JSON.
Command Construction
scripts/ci-test-benchmark.js (buildCommand, placeholder substitution)
Builds final Vitest or user command, substitutes {vitestJson}, conditionally appends --coverage, and (unless disabled or already present) appends --reporter=json and --outputFile=<path>.
Reporter/Output Detection Helpers
scripts/ci-test-benchmark.js (hasJsonReporter, hasVitestOutputFile)
Detects existing JSON reporter or outputFile flags to avoid duplicating reporter/output options.
Process Execution & Timing
scripts/ci-test-benchmark.js (runCommand)
Spawns the command with inherited stdio, captures failure-to-start errors, exitCode/signal, ISO start/end timestamps, and high-resolution wall time; supports --dry-run.
Vitest JSON I/O & Summarization
scripts/ci-test-benchmark.js (readJsonIfExists, summarizeVitest, summarizeProjects)
Reads produced Vitest JSON (if present), computes per-file metrics (durations, status counts, inferred project), sorts by duration, and aggregates per-project totals and long-tail lists by configured top limit.
Environment & Config Collection
scripts/ci-test-benchmark.js (collectEnvironment, readVitestConfigDefaults)
Collects CI/GitHub Actions env vars, Node/platform/arch, CPU/memory, package manager from package.json, and extracts selected defaults from vitest.config.ts.
Report Creation & Persistence
scripts/ci-test-benchmark.js (createReport, writeReportJson, writeReportMarkdown, renderMarkdown)
Assembles report.json and a formatted report.md (command, timing, environment, parameters, Vitest summary, long-tail tables, output files, artifact note) and writes them to the output directory.
Main Orchestration
scripts/ci-test-benchmark.js (main)
Coordinates parse → build → run (or dry-run) → read/summarize → write reports; maps child exit code to process.exitCode and exits with code 1 on uncaught errors.

Sequence Diagram

sequenceDiagram
  participant User as CI/Developer
  participant CLI as ci-test-benchmark.js
  participant Vitest as Vitest Process
  participant FS as Filesystem

  User->>CLI: invoke `benchmark:ci-test` (npm script / node) with args/env
  CLI->>CLI: parse args, normalize argv, resolve output dir, build command
  CLI->>Vitest: spawn built command (may include JSON reporter/outputFile)
  Vitest-->>CLI: exit code, signal, produce vitest JSON file (optional)
  CLI->>FS: read vitest JSON (if exists) and vitest.config.ts
  CLI->>CLI: summarize results, collect environment/parameters
  CLI->>FS: write `report.json` and `report.md`
  CLI-->>User: print report paths, exit with child exit code
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped through args and chased the run,
timing crumbs beneath the sun.
JSON carrots, markdown cake —
little reports for speed's sake.
A tiny benchmark, neatly done.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore(test): add ci benchmark harness' accurately and concisely summarizes the main change—adding a CI benchmark harness script and npm script entry.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/egg-dev/e176f152

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 2, 2026

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: c41200d
Status: ✅  Deploy successful!
Preview URL: https://ca0672c0.egg-cci.pages.dev
Branch Preview URL: https://agent-egg-dev-e176f152.egg-cci.pages.dev

View logs

@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.03%. Comparing base (88fa8e4) to head (c41200d).
⚠️ Report is 4 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5912   +/-   ##
=======================================
  Coverage   85.03%   85.03%           
=======================================
  Files         665      667    +2     
  Lines       19108    19110    +2     
  Branches     3719     3719           
=======================================
+ Hits        16249    16251    +2     
  Misses       2466     2466           
  Partials      393      393           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 2, 2026

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: c41200d
Status: ✅  Deploy successful!
Preview URL: https://1666e7d1.egg-v3.pages.dev
Branch Preview URL: https://agent-egg-dev-e176f152.egg-v3.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new benchmarking script, scripts/ci-test-benchmark.js, along with a corresponding package.json script entry. The utility executes Vitest tests, gathers environment and performance data, and generates comprehensive reports in both Markdown and JSON formats. Review feedback focused on improving the robustness of the script, specifically by refining regex patterns used for parsing configuration files to avoid matching comments and fixing a logic error in the argument parser where flags could incorrectly consume subsequent options as values.

Comment thread scripts/ci-test-benchmark.js Outdated
Comment thread scripts/ci-test-benchmark.js Outdated
Comment thread scripts/ci-test-benchmark.js Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/ci-test-benchmark.js`:
- Around line 222-227: Guard the JSON parsing in readJsonIfExists so a
malformed/truncated reporter file doesn't throw and abort the harness: wrap the
fs.readFileSync + JSON.parse logic in a try/catch inside the readJsonIfExists
function, on any error return null (optionally log a warning with the filePath
and error) so callers can handle a missing/invalid report instead of crashing.
- Around line 159-176: The current hasReporter check skips adding
--reporter=json when any reporter is present; change it to detect only JSON
reporter explicitly: examine the replaced array and set hasReporter true only if
an element is '--reporter=json' or startsWith('--reporter=json') or if an
element is '--reporter' and the next element === 'json' (to handle separated
args); leave the hasOutputFile and reporterArgs logic unchanged and continue to
append '--reporter=json' and `--outputFile=${vitestJsonPath}` only when
hasReporter/hasOutputFile are false.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: d60ec538-3c64-4db7-a317-2ae04db2ebac

📥 Commits

Reviewing files that changed from the base of the PR and between 88fa8e4 and 9372af8.

📒 Files selected for processing (2)
  • package.json
  • scripts/ci-test-benchmark.js

Comment thread scripts/ci-test-benchmark.js Outdated
Comment thread scripts/ci-test-benchmark.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a reusable CI test benchmark harness that runs (or wraps) a Vitest invocation and emits Markdown + JSON reports enriched with environment, command parameters, and per-file/per-project duration summaries.

Changes:

  • Introduces scripts/ci-test-benchmark.js to run a Vitest command and generate report.md, report.json, and raw vitest-results.json.
  • Adds a root npm script benchmark:ci-test to invoke the harness.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
scripts/ci-test-benchmark.js New CLI tool to execute (or dry-run) Vitest and generate benchmark reports from JSON reporter output.
package.json Exposes the harness via pnpm run benchmark:ci-test.

Comment thread scripts/ci-test-benchmark.js Outdated
Comment thread scripts/ci-test-benchmark.js Outdated
Comment thread scripts/ci-test-benchmark.js Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/ci-test-benchmark.js`:
- Around line 177-188: The hasJsonReporter function currently uses a redundant
arg === '--reporter=json' check and an overly broad
arg.startsWith('--reporter=json') which can falsely match reporters like
'--reporter=json-compact'; update hasJsonReporter to remove the startsWith and
only treat '--reporter=json' as a match (keep the existing handling for the
split form where arg === '--reporter' and the next token === 'json'), so only
exact '--reporter=json' or the two-token form are considered true.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f8ff088-d3d3-4919-990d-86560f532460

📥 Commits

Reviewing files that changed from the base of the PR and between 9372af8 and 56a3650.

📒 Files selected for processing (1)
  • scripts/ci-test-benchmark.js

Comment thread scripts/ci-test-benchmark.js Outdated
Copilot AI review requested due to automatic review settings May 2, 2026 15:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread scripts/ci-test-benchmark.js Outdated
Comment thread scripts/ci-test-benchmark.js Outdated
Copilot AI review requested due to automatic review settings May 2, 2026 17:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread scripts/ci-test-benchmark/environment.js Outdated
Copilot AI review requested due to automatic review settings May 2, 2026 17:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

@killagu killagu merged commit 92c0ec2 into next May 3, 2026
36 of 38 checks passed
@killagu killagu deleted the agent/egg-dev/e176f152 branch May 3, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants