Skip to content

The agent that grows with you

fix(desktop): local-runtime job poller no longer throws after the test env tears down

teknium19b5f5a0c84ab
diff --git a/apps/desktop/src/app/settings/local-models-settings.test.tsx b/apps/desktop/src/app/settings/local-models-settings.test.tsx
index 5fdee3924b9..237d4b7b77d 100644
--- a/apps/desktop/src/app/settings/local-models-settings.test.tsx
+++ b/apps/desktop/src/app/settings/local-models-settings.test.tsx
@@ -134,6 +134,9 @@ beforeEach(() => {
afterEach(() => {
cleanup()
vi.clearAllMocks()
+ // A running job arms the store's 700ms re-poll; drain it so the timer cannot
+ // fire into a torn-down test environment.
+ $localRuntimeJobs.set([])
})
describe('LocalModelsSettings', () => {
diff --git a/apps/desktop/src/store/local-runtime-jobs.ts b/apps/desktop/src/store/local-runtime-jobs.ts
index 06170cdebc1..dc2ab720bc3 100644
--- a/apps/desktop/src/store/local-runtime-jobs.ts
+++ b/apps/desktop/src/store/local-runtime-jobs.ts
@@ -74,7 +74,7 @@ export async function startLocalRuntimeInstall(): Promise<void> {
}
const POLL_ACTIVE_MS = 700
-let timer: null | number = null
+let timer: null | ReturnType<typeof setTimeout> = null
let polling: Promise<void> | null = null
let generation = 0
interface JobContext {
@@ -124,7 +124,7 @@ function resetContext() {
const context = ++generation
if (timer !== null) {
- window.clearTimeout(timer)
+ clearTimeout(timer)
}
timer = null
@@ -229,7 +229,7 @@ function poll(): Promise<void> {
const accepted = owner.acceptedInstall
if (timer !== null) {
- window.clearTimeout(timer)
+ clearTimeout(timer)
}
timer = null
@@ -263,7 +263,7 @@ function poll(): Promise<void> {
polling = null
if (owner.readPending || $localRuntimeJobs.get().some(j => j.status === 'running')) {
- timer = window.setTimeout(() => void poll(), POLL_ACTIVE_MS)
+ timer = setTimeout(() => void poll(), POLL_ACTIVE_MS)
}
}
}