test(sandbox): add exactly-once regression for Ollama GPU unload#3221
test(sandbox): add exactly-once regression for Ollama GPU unload#3221laitingsheng wants to merge 2 commits intomainfrom
Conversation
Address the deferred suggestions on #3173: - Make `cleanupSandboxServices` injectable and exported with a `CleanupSandboxServicesDeps` shape mirroring the existing destroy.ts patterns (`RemoveSandboxImageDeps`, etc.). Runtime callers keep passing nothing and continue to resolve dependencies via lazy `require()` so the circular import boundary is preserved. - Add `test/destroy-cleanup-sandbox-services.test.ts` covering the three call-count cases that motivated the original dedup fix: - `stopHostServices=true` + Ollama provider — `stopAll()` invoked once, `unloadOllamaModels()` not called by destroy.ts (it runs transitively inside `stopAll()`). - `stopHostServices=false` + Ollama provider — `unloadOllamaModels()` invoked exactly once, `stopAll()` not called. - `stopHostServices=false` + non-Ollama provider — neither called. Plus a check that the PID directory removal and messaging-provider teardown loop run with the expected arguments. - In `unloadOllamaModels`, append a sync pointer to `test/ollama-gpu-cleanup.test.ts` and document why `-sS` (rather than `--fail`) is intentional on the POST to `/api/generate`. Per #3173 review feedback (jyaunches optional regression test, --fail nit, CodeRabbit source/test sync pointer). Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThis PR refactors ChangesSandbox cleanup with testable dependency injection
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
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 docstrings
🧪 Generate unit tests (beta)
Comment |
Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
Summary
Follow-up on the deferred review items from #3173. Adds the dedicated regression test for the Ollama GPU unload exactly-once invariant, threads injectable dependencies through
cleanupSandboxServices, and tightens two comments per CodeRabbit / jyaunches feedback.Related Issue
Follow-up to #3173. Related: #2717 (already closed by #3173).
Changes
src/lib/actions/sandbox/destroy.tscleanupSandboxServicesand add aCleanupSandboxServicesDepsshape (mirrorsRemoveSandboxImageDeps/RemoveSandboxRegistryEntryDeps).getSandbox,stopAll,unloadOllamaModels,runOpenshell, andrmSyncfrom the deps argument, falling back to lazyrequire()so runtime call sites stay unchanged and the circular-import boundary is preserved.test/destroy-cleanup-sandbox-services.test.ts(new)stopHostServices=true+ Ollama provider —stopAll()invoked once,unloadOllamaModels()not called by destroy.ts (it runs transitively insidestopAll()).stopHostServices=false+ Ollama provider —unloadOllamaModels()invoked exactly once,stopAll()not called.stopHostServices=false+ non-Ollama provider — neither called.src/lib/onboard-ollama-proxy.tstest/ollama-gpu-cleanup.test.tsin theunloadOllamaModelsJSDoc.-sS(rather than--fail) is intentional on the POST to/api/generate— best-effort teardown should not surface orphaned-GPU-memory failures into unrelated CLI exit codes.Type of Change
Verification
npx prek run --all-filespassesnpm testpassesmake docsbuilds without warnings (doc changes only)Signed-off-by: Tinson Lai tinsonl@nvidia.com
Summary by CodeRabbit
Tests
Documentation