Skip to content

test(core): add unit tests for wait utility#4894

Open
atulya-singh wants to merge 7 commits into
NVIDIA:mainfrom
atulya-singh:test/shell-quote
Open

test(core): add unit tests for wait utility#4894
atulya-singh wants to merge 7 commits into
NVIDIA:mainfrom
atulya-singh:test/shell-quote

Conversation

@atulya-singh

@atulya-singh atulya-singh commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds src/lib/core/wait.test.ts with unit tests for all four functions in src/lib/core/wait.ts
  • Covers sleepMs, sleepSeconds, waitUntil, waitForPort, and waitForHttp
  • Follows the co-located test pattern established by errno.test.ts and shell-quote.test.ts
  • Mocks node:child_process via vi.mock to test waitForPort and waitForHttp without real network calls

Test plan

  • sleepMs: verifies blocking for positive durations and immediate return for zero/negative/NaN/Infinity
  • sleepSeconds: verifies conversion from seconds to milliseconds
  • waitUntil: covers immediate true, delayed true, timeout (false), and multi-poll behavior
  • waitForPort: mocked spawnSync — success (status 0), timeout (status 1), and thrown exception
  • waitForHttp: mocked spawnSync — success (status 0), timeout (status 1), and thrown exception

DCO

Signed-off-by: Atulya Singh atulyarajsingh@gmail.com

@copy-pr-bot

copy-pr-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

PR changed again? Review this PR in Change Stack to compare snapshots and stay oriented.

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds two new Vitest test suites for utility functions. The first suite tests the shellQuote function for correct shell-safe quoting and single-quote escaping. The second suite tests wait utility functions including synchronous sleep operations, conditional polling with timeouts, and asynchronous port/HTTP networking checks using mocked process spawning.

Changes

Test coverage for utility functions

Layer / File(s) Summary
Shell quote function tests
src/lib/core/shell-quote.test.ts
Tests verify that shellQuote correctly wraps strings in single quotes, escapes embedded single quotes using the '\'' pattern, handles special characters like $, and returns empty strings and quote-only inputs correctly.
Sleep utility tests
src/lib/core/wait.test.ts (lines 11–57)
Tests for sleepMs and sleepSeconds confirm approximate blocking behavior for normal durations and verify immediate return for edge cases: zero, negative numbers, NaN, and Infinity.
Async wait utilities and networking checks
src/lib/core/wait.test.ts (lines 1–10, 59–132)
Module imports and node:child_process.spawnSync mock setup enable tests for waitUntil polling with condition functions and timeouts, waitForPort async port availability, and waitForHttp async HTTP connectivity—all validating success/failure and exception handling through mocked status codes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • NVIDIA/NemoClaw#4161: Both PRs add Vitest coverage for the shellQuote utility in src/lib/core/shell-quote.test.ts, validating the same quoting/escaping scenarios.

Suggested labels

chore

Poem

🐰 Hop-testing we go, line by line,
Shell quotes and sleeps now tested fine,
No async surprises, no timing woes,
Our tests run true—the coverage glows!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'test(core): add unit tests for wait utility' is partially related to the changeset. While it mentions adding unit tests for the wait utility, the changes also include a test file for shell-quote (src/lib/core/shell-quote.test.ts), which is not reflected in the title. Update the title to reflect all test files being added, such as 'test(core): add unit tests for wait and shell-quote utilities' or clarify the scope if shell-quote tests are unintended.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/lib/core/shell-quote.test.ts (1)

7-30: 💤 Low value

Consider adding test cases for non-string inputs.

The function signature accepts unknown and uses String(value) conversion, but all current tests use string inputs. Adding test cases for numbers, null, undefined, and objects would verify the type conversion contract.

🧪 Example test cases for non-string inputs
it("converts numbers to strings", () => {
    expect(shellQuote(42)).toBe("'42'");
});

it("converts null to string", () => {
    expect(shellQuote(null)).toBe("'null'");
});

it("converts undefined to string", () => {
    expect(shellQuote(undefined)).toBe("'undefined'");
});

it("converts objects to string", () => {
    expect(shellQuote({key: "value"})).toBe("'[object Object]'");
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/core/shell-quote.test.ts` around lines 7 - 30, Add tests covering
non-string inputs to verify shellQuote accepts unknown and uses String(value);
specifically add cases calling shellQuote with a number (e.g., 42), null,
undefined, and an object (e.g., {key:"value"}) and assert the results are the
single-quoted String(value) with proper escaping (e.g., "'42'", "'null'",
"'undefined'", and the quoted "[object Object]" form); update
src/lib/core/shell-quote.test.ts around the existing describe('shellQuote'...)
block to include these new it(...) cases so they exercise the shellQuote
function's type conversion and escaping behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/lib/core/shell-quote.test.ts`:
- Around line 7-30: Add tests covering non-string inputs to verify shellQuote
accepts unknown and uses String(value); specifically add cases calling
shellQuote with a number (e.g., 42), null, undefined, and an object (e.g.,
{key:"value"}) and assert the results are the single-quoted String(value) with
proper escaping (e.g., "'42'", "'null'", "'undefined'", and the quoted "[object
Object]" form); update src/lib/core/shell-quote.test.ts around the existing
describe('shellQuote'...) block to include these new it(...) cases so they
exercise the shellQuote function's type conversion and escaping behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f4142c87-cf72-411b-ac9f-fdc305efb457

📥 Commits

Reviewing files that changed from the base of the PR and between 76f6c77 and 686aedf.

📒 Files selected for processing (2)
  • src/lib/core/shell-quote.test.ts
  • src/lib/core/wait.test.ts

@cv

cv commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

@atulya-singh mind adding a DCO to the PR description, please?

@atulya-singh

Copy link
Copy Markdown
Contributor Author

Hi, I added the DCO to the PR description.

@wscurran wscurran added the chore Build, CI, dependency, or tooling maintenance label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Build, CI, dependency, or tooling maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants