Files
openchamber/packages/ui/src/sync/child-store.test.ts
T
Bohdan Triapitsyn b36afbf5ee perf(sidebar): index session ownership and narrow live subscriptions
Replace repeated project-by-session directory matching across sidebar hooks with a shared ownership index that resolves each unique directory once and exposes direct project and folder-scope buckets.

Gate destructive folder reconciliation on authoritative session data and topology readiness, preserve last-known worktrees after discovery failures, and retain nested-project, VS Code, active/archive dedupe, and Windows drive-root semantics.

Narrow cross-directory subscriptions to session and status slices so streaming deltas no longer trigger global aggregation. Reuse a cached session ID index for permission lineage checks instead of rebuilding it on every session switch.

On the reported 15-project, 67-worktree, 14,561-session shape, ownership indexing averages 3.81 ms versus roughly 450 ms for the cache-only hotfix.

Validation: 28 targeted tests, UI type-check, UI lint, and dead-code analysis.
2026-07-13 23:18:12 +03:00

38 lines
1.1 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import { ChildStoreManager } from './child-store';
describe('ChildStoreManager.subscribeAllSelected', () => {
test('ignores unrelated child-store updates', () => {
const manager = new ChildStoreManager();
const child = manager.ensureChild('/workspace', { bootstrap: false });
let notifications = 0;
const unsubscribe = manager.subscribeAllSelected((state) => state.session, () => {
notifications += 1;
});
child.setState({ session_status: { session: { type: 'busy' } } });
expect(notifications).toBe(0);
child.setState({ session: [...child.getState().session] });
expect(notifications).toBe(1);
unsubscribe();
manager.disposeAll();
});
test('notifies when the child-store registry changes', () => {
const manager = new ChildStoreManager();
let notifications = 0;
const unsubscribe = manager.subscribeAllSelected((state) => state.session, () => {
notifications += 1;
});
manager.ensureChild('/workspace', { bootstrap: false });
expect(notifications).toBe(1);
unsubscribe();
manager.disposeAll();
});
});