diff options
| author | Adam <[email protected]> | 2026-02-12 19:27:16 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2026-02-12 19:38:06 -0600 |
| commit | 0303c29e3ff4f45aff4176e496ecb3f5fa5b611a (patch) | |
| tree | b870263c3059e9c51cafc6dd69b83254a42d27fb | |
| parent | adb0c4d4f94f6260a67bb9a48ef3a7faa6042bf3 (diff) | |
| download | opencode-0303c29e3ff4f45aff4176e496ecb3f5fa5b611a.tar.gz opencode-0303c29e3ff4f45aff4176e496ecb3f5fa5b611a.zip | |
fix(app): failed to create store
| -rw-r--r-- | packages/app/src/context/global-sync/child-store.test.ts | 39 | ||||
| -rw-r--r-- | packages/app/src/context/global-sync/child-store.ts | 6 |
2 files changed, 42 insertions, 3 deletions
diff --git a/packages/app/src/context/global-sync/child-store.test.ts b/packages/app/src/context/global-sync/child-store.test.ts new file mode 100644 index 000000000..500f0fc70 --- /dev/null +++ b/packages/app/src/context/global-sync/child-store.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, test } from "bun:test" +import { createRoot, getOwner } from "solid-js" +import { createStore } from "solid-js/store" +import type { State } from "./types" +import { createChildStoreManager } from "./child-store" + +const child = () => createStore({} as State) + +describe("createChildStoreManager", () => { + test("does not evict the active directory during mark", () => { + const owner = createRoot((dispose) => { + const current = getOwner() + dispose() + return current + }) + if (!owner) throw new Error("owner required") + + const manager = createChildStoreManager({ + owner, + markStats() {}, + incrementEvictions() {}, + isBooting: () => false, + isLoadingSessions: () => false, + onBootstrap() {}, + onDispose() {}, + }) + + Array.from({ length: 30 }, (_, index) => `/pinned-${index}`).forEach((directory) => { + manager.children[directory] = child() + manager.pin(directory) + }) + + const directory = "/active" + manager.children[directory] = child() + manager.mark(directory) + + expect(manager.children[directory]).toBeDefined() + }) +}) diff --git a/packages/app/src/context/global-sync/child-store.ts b/packages/app/src/context/global-sync/child-store.ts index 2feb7fe08..af08c3bd4 100644 --- a/packages/app/src/context/global-sync/child-store.ts +++ b/packages/app/src/context/global-sync/child-store.ts @@ -36,7 +36,7 @@ export function createChildStoreManager(input: { const mark = (directory: string) => { if (!directory) return lifecycle.set(directory, { lastAccessAt: Date.now() }) - runEviction() + runEviction(directory) } const pin = (directory: string) => { @@ -106,7 +106,7 @@ export function createChildStoreManager(input: { return true } - function runEviction() { + function runEviction(skip?: string) { const stores = Object.keys(children) if (stores.length === 0) return const list = pickDirectoriesToEvict({ @@ -116,7 +116,7 @@ export function createChildStoreManager(input: { max: MAX_DIR_STORES, ttl: DIR_IDLE_TTL_MS, now: Date.now(), - }) + }).filter((directory) => directory !== skip) if (list.length === 0) return for (const directory of list) { if (!disposeDirectory(directory)) continue |
