Skip to content

[jsweep] Clean performance_now.cjs - #29042

Merged
pelikhan merged 2 commits into
mainfrom
jsweep/performance-now-63114112dae7dd93
Apr 29, 2026
Merged

pelikhan merged 2 commits into
mainfrom
jsweep/performance-now-63114112dae7dd93

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Adds comprehensive test coverage for performance_now.cjs, which previously had no tests.

File: performance_now.cjs

Context: Pure Node.js module (not github-script context).

Changes:

  • No logic changes — the existing code is already clean and idiomatic
  • Created performance_now.test.cjs with 9 test cases

Test improvements

Created performance_now.test.cjs from scratch with 9 meaningful tests:

  1. exports nowMs as a function — basic export check
  2. returns a number — return type check
  3. returns a value close to Date.now() — sanity check against wall clock
  4. returns an increasing value on successive calls — monotonicity
  5. uses performance.timeOrigin + performance.now() — verifies the implementation formula
  6. returns a floating-point value when performance.now() has sub-ms precision — precision check
  7. returns epoch-scale milliseconds (greater than year 2020) — lower-bound epoch check
  8. returns epoch-scale milliseconds (less than year 2100) — upper-bound epoch check
  9. handles zero performance.now() value — edge case with zero elapsed time

Validation checks

  • ✅ Formatting: npm run format:cjs ✓
  • ✅ Linting: npm run lint:cjs ✓
  • ✅ Type checking: npm run typecheck ✓
  • ✅ Tests: npm run test:js — 9/9 tests passed ✓

Generated by jsweep - JavaScript Unbloater · ● 1.6M · ◷

  • expires on May 1, 2026, 4:52 AM UTC

Add comprehensive test coverage for performance_now.cjs which lacked tests:
- Verify nowMs() returns a number
- Verify nowMs() is close to Date.now()
- Verify successive calls return non-decreasing values
- Verify it uses performance.timeOrigin + performance.now()
- Verify sub-millisecond precision support
- Verify epoch-scale return values (year 2020–2100 range)
- Verify correct addition when performance.now() is zero

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review April 29, 2026 05:14
Copilot AI review requested due to automatic review settings April 29, 2026 05:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds Vitest test coverage for the pure Node.js helper performance_now.cjs (nowMs()), which previously had no dedicated tests.

Changes:

  • Introduces actions/setup/js/performance_now.test.cjs with 9 unit tests covering basic export/type checks, monotonicity, implementation formula, and a few boundary/edge cases.
Show a summary per file
File Description
actions/setup/js/performance_now.test.cjs Adds a new Vitest test suite for nowMs() behavior and implementation details.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines +23 to +30
it("returns a value close to Date.now()", () => {
const { nowMs } = req("./performance_now.cjs");
const before = Date.now();
const result = nowMs();
const after = Date.now();
// Allow 5ms slack for test execution overhead
expect(result).toBeGreaterThanOrEqual(before - 5);
expect(result).toBeLessThanOrEqual(after + 5);

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

The assertion that nowMs() is within ±5ms of Date.now() can be flaky and may fail even when the implementation is correct: performance.timeOrigin + performance.now() is based on the wall clock at process start plus a monotonic clock, so it won’t track later system clock adjustments (e.g., NTP/time drift), while Date.now() will. Consider loosening this to a much larger tolerance (e.g., seconds) or rewriting the check to avoid relying on live wall-clock alignment.

Suggested change
it("returns a value close to Date.now()", () => {
const { nowMs } = req("./performance_now.cjs");
const before = Date.now();
const result = nowMs();
const after = Date.now();
// Allow 5ms slack for test execution overhead
expect(result).toBeGreaterThanOrEqual(before - 5);
expect(result).toBeLessThanOrEqual(after + 5);
it("returns a value within the current performance-based epoch range", () => {
const { nowMs } = req("./performance_now.cjs");
const before = perfHooks.performance.timeOrigin + perfHooks.performance.now();
const result = nowMs();
const after = perfHooks.performance.timeOrigin + perfHooks.performance.now();
expect(result).toBeGreaterThanOrEqual(before);
expect(result).toBeLessThanOrEqual(after);

Copilot uses AI. Check for mistakes.
@github-actions

Copy link
Copy Markdown
Contributor Author

🧪 Test Quality Sentinel Report

Test Quality Score: 87/100

✅ Excellent test quality

Metric Value
New/modified tests analyzed 9
✅ Design tests (behavioral contracts) 9 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases 5 (56%)
Duplicate test clusters 0
Test inflation detected N/A (new test file for existing code — jsweep)
🚨 Coding-guideline violations None

Test Classification Details

View all 9 test classifications
Test File Classification Notes
exports nowMs as a function performance_now.test.cjs ✅ Design Verifies public API contract — nowMs is callable
returns a number performance_now.test.cjs ✅ Design Behavioral contract: return type is numeric
returns a value close to Date.now() performance_now.test.cjs ✅ Design Temporal accuracy contract with range bounds
returns an increasing value on successive calls performance_now.test.cjs ✅ Design Monotonicity invariant
uses performance.timeOrigin + performance.now() performance_now.test.cjs ✅ Design Verifies documented formula (JSDoc contract) with controlled mock values
returns a floating-point value when sub-ms precision performance_now.test.cjs ✅ Design Sub-millisecond precision contract
returns epoch-scale milliseconds (greater than year 2020) performance_now.test.cjs ✅ Design Epoch-scale sanity bound
returns epoch-scale milliseconds (less than year 2100) performance_now.test.cjs ✅ Design Epoch-scale sanity bound
handles zero performance.now() value performance_now.test.cjs ✅ Design Edge case: zero offset

Flagged Tests — Requires Review

No tests flagged. All tests verify observable behavioral contracts.


Language Support

Tests analyzed:

  • 🐹 Go (*_test.go): 0 tests
  • 🟨 JavaScript (*.test.cjs): 9 tests (vitest)

Verdict

✅ Check passed. 0% of new tests are implementation tests (threshold: 30%). The test suite covers the public API contract, temporal accuracy, monotonicity, sub-ms precision, epoch-scale bounds, and a zero-offset edge case — all meaningful behavioral invariants for a timing utility.


📖 Understanding Test Classifications

Design Tests (High Value) verify what the system does:

  • Assert on observable outputs, return values, or state changes
  • Cover error paths and boundary conditions
  • Would catch a behavioral regression if deleted
  • Remain valid even after internal refactoring

Implementation Tests (Low Value) verify how the system does it:

  • Assert on internal function calls (mocking internals)
  • Only test the happy path with typical inputs
  • Break during legitimate refactoring even when behavior is correct
  • Give false assurance: they pass even when the system is wrong

Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.

🧪 Test quality analysis by Test Quality Sentinel · ● 336.1K · ◷

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 87/100. Test quality is excellent — 0% of new tests are implementation tests (threshold: 30%).

@github-actions github-actions Bot mentioned this pull request Apr 29, 2026
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot review all comments

…et test

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/7724fa1c-419a-4d83-9c59-d5c79a08ee45

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

@copilot review all comments

Addressed the flaky test in ad5ef12. Replaced the Date.now() ± 5ms check with a bracket test that samples performance.timeOrigin + performance.now() immediately before and after calling nowMs(), so the assertion is entirely within the monotonic clock domain and immune to NTP/wall-clock drift.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid.example.invalid
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin https://invalid.example.invalid/nonexistent-repo.git git diff�� --binary --output=/tmp/gh-aw/aw-auth-cleanup-success.patch.diff.tmp tions/setup/node_modules/.bin/git --binary --output=/tmp/ghmaintenance ning-branch git add . git odules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin/git -m Initial commit ache/go/1.25.8/xagent-change.txt git (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan April 29, 2026 05:30
@pelikhan
pelikhan merged commit ae9557a into main Apr 29, 2026
@pelikhan
pelikhan deleted the jsweep/performance-now-63114112dae7dd93 branch April 29, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants