refactor(rebuild): lower cognitive complexity ratchet to 244 - #5421
Conversation
Signed-off-by: Carlos Villela <cvillela@nvidia.com> (cherry picked from commit 41fcd6a)
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
📝 WalkthroughWalkthrough
ChangesActive SSH session detection refactor and tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Code Coverage OverviewLanguages: TypeScript TypeScript / code-coverage/pluginThe overall coverage in the Show a code coverage summary of the most covered files.
TypeScript / code-coverage/cliThe overall coverage in the Show a code coverage summary of the most covered files.
Updated |
PR Review AdvisorFindings: 0 needs attention, 0 worth checking, 0 nice ideas Consider writing more tests for
This is an automated advisory review. A human maintainer must make the final merge decision. |
E2E Advisor RecommendationRequired E2E: Dispatch hint: Full advisor summaryE2E Recommendation AdvisorBase: Required E2E
Optional E2E
New E2E recommendations
Dispatch hint
|
Vitest E2E Scenario RecommendationRequired Vitest E2E scenarios: Dispatch required Vitest E2E scenarios:
Full Vitest E2E advisor summaryVitest E2E Scenario AdvisorBase: Required Vitest E2E scenarios
Optional Vitest E2E scenarios
Relevant changed files
|
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
…t/244-rebuild-cognitive-complexity
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
…t/244-rebuild-cognitive-complexity
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
…t/244-rebuild-cognitive-complexity
…ognitive-complexity # Conflicts: # biome.json
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@test/rebuild-credential-preflight.test.ts`:
- Around line 369-372: The test assertions on lines 369-372 in
test/rebuild-credential-preflight.test.ts use multiple toContain() checks that
only verify string presence but not their ordering. To ensure the warning
messages appear before the confirmation prompt as intended, replace the
individual toContain() assertions with a single assertion that verifies the
substring order—for example, check that the index of "Active SSH sessions
detected (2 connections)" and "terminate all active sessions with a Broken pipe
error" appear before the index of "Proceed? [y/N]:" in the output string, or use
a regex or index-based approach to enforce the correct sequence.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: e1c0e611-471e-457b-a440-ef6a74fb8e39
📒 Files selected for processing (3)
biome.jsonsrc/lib/actions/sandbox/rebuild.tstest/rebuild-credential-preflight.test.ts
| expect(output).toContain("Active SSH sessions detected (2 connections)"); | ||
| expect(output).toContain("terminate all active sessions with a Broken pipe error"); | ||
| expect(output).toContain("Proceed? [y/N]:"); | ||
| expect(output).toContain("Cancelled."); |
There was a problem hiding this comment.
Assert output ordering, not just presence, for warning vs confirmation prompt.
On Lines 369-372, the test checks both strings exist but does not verify the warning appears before Proceed? [y/N]:, so the intended sequencing can regress undetected.
Suggested test assertion update
expect(output).toContain("Active SSH sessions detected (2 connections)");
expect(output).toContain("terminate all active sessions with a Broken pipe error");
expect(output).toContain("Proceed? [y/N]:");
+ expect(output.indexOf("Active SSH sessions detected (2 connections)")).toBeLessThan(
+ output.indexOf("Proceed? [y/N]:"),
+ );📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| expect(output).toContain("Active SSH sessions detected (2 connections)"); | |
| expect(output).toContain("terminate all active sessions with a Broken pipe error"); | |
| expect(output).toContain("Proceed? [y/N]:"); | |
| expect(output).toContain("Cancelled."); | |
| expect(output).toContain("Active SSH sessions detected (2 connections)"); | |
| expect(output).toContain("terminate all active sessions with a Broken pipe error"); | |
| expect(output).toContain("Proceed? [y/N]:"); | |
| expect(output.indexOf("Active SSH sessions detected (2 connections)")).toBeLessThan( | |
| output.indexOf("Proceed? [y/N]:"), | |
| ); | |
| expect(output).toContain("Cancelled."); |
🤖 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 `@test/rebuild-credential-preflight.test.ts` around lines 369 - 372, The test
assertions on lines 369-372 in test/rebuild-credential-preflight.test.ts use
multiple toContain() checks that only verify string presence but not their
ordering. To ensure the warning messages appear before the confirmation prompt
as intended, replace the individual toContain() assertions with a single
assertion that verifies the substring order—for example, check that the index of
"Active SSH sessions detected (2 connections)" and "terminate all active
sessions with a Broken pipe error" appear before the index of "Proceed? [y/N]:"
in the output string, or use a regex or index-based approach to enforce the
correct sequence.
Summary
Continue the cognitive-complexity ratchet by lowering the threshold from 245 to 244. This addresses the next offender with a small rebuild refactor and keeps the stack free of per-file exceptions or suppressions.
Changes
complexity/noExcessiveCognitiveComplexityfrom245to244inbiome.json.src/lib/actions/sandbox/rebuild.tsintocountActiveSandboxSessionsForRebuild.rebuildSandboxcognitive complexity below the new ceiling.Type of Change
Verification
npx @biomejs/biome lint --only=complexity/noExcessiveCognitiveComplexity --max-diagnostics=none .npm run typecheck:clinpx vitest run --project cli src/lib/actions/sandbox/rebuild-gpu-opt-out.test.ts src/lib/actions/sandbox/rebuild-shields-finally.test.ts src/lib/actions/sandbox/rebuild-gateway-drift.test.ts src/lib/actions/sandbox/rebuild-config-hash.test.ts src/lib/actions/sandbox/rebuild-resume-snapshot.test.ts test/rebuild-credential-preflight.test.ts test/rebuild-credential-hydration.test.ts test/rebuild-policy-presets.test.ts test/rebuild-shields-window.test.ts test/rebuild-stale-recovery.test.tsnpx vitest run --project cli test/rebuild-credential-preflight.test.tsGit hooks passed during commit and push, or
npx prek run --from-ref main --to-ref HEADpassesTargeted tests pass for changed behavior
Tests added or updated for new or changed behavior
Full
npm testpasses (broad runtime changes only)No secrets, API keys, or credentials committed
Docs updated for user-facing behavior changes
npm run docsbuilds without warnings (doc changes only)Doc pages follow the style guide (doc changes only)
New doc pages include SPDX header and frontmatter (new pages only)
Signed-off-by: Carlos Villela cvillela@nvidia.com
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests