feat: complete catalog-driven preprocessing
Publish documentation / publish (push) Successful in 2m12s

This commit is contained in:
Codex
2026-09-06 17:49:35 +02:00
parent 8707ae1d46
commit cffa60772e
141 changed files with 5898 additions and 3015 deletions
+14 -1
View File
@@ -1,4 +1,4 @@
import { beforeEach, expect, test } from "vitest";
import { beforeEach, expect, test, vi } from "vitest";
import { workspacePreferences } from "./preferences";
beforeEach(() => {
@@ -37,3 +37,16 @@ test("seeds memory from backend settings once and returns defensive copies", ()
workspaceId: "psd-clinical", provider: "zai", model: "glm-5.2", thinking: "medium",
});
});
test("notifies shell consumers when the selected workspace changes", () => {
const listener = vi.fn();
const unsubscribe = workspacePreferences.subscribe(listener);
workspacePreferences.save({ workspaceId: "catalog-one" });
workspacePreferences.save({ workspaceId: "catalog-two" });
unsubscribe();
workspacePreferences.save({ workspaceId: "catalog-three" });
expect(listener).toHaveBeenCalledTimes(2);
expect(listener).toHaveBeenLastCalledWith({ workspaceId: "catalog-two" });
});
+17 -1
View File
@@ -6,11 +6,17 @@ export interface WorkspacePreference {
}
let current: WorkspacePreference | undefined;
const listeners = new Set<(value: WorkspacePreference) => void>();
function snapshot(value: WorkspacePreference | undefined): WorkspacePreference {
return value === undefined ? {} : { ...value };
}
function notify(): void {
const value = snapshot(current);
for (const listener of listeners) listener(value);
}
/** Ephemeral workspace choices for the current application process. */
export const workspacePreferences = {
load(): WorkspacePreference {
@@ -19,17 +25,27 @@ export const workspacePreferences = {
save(value: WorkspacePreference): WorkspacePreference {
current = { ...value };
notify();
return snapshot(current);
},
/** Seed current memory from backend installation settings only before the first local choice. */
migrate(settings: WorkspacePreference): WorkspacePreference {
if (current === undefined) current = { ...settings };
if (current === undefined) {
current = { ...settings };
notify();
}
return snapshot(current);
},
subscribe(listener: (value: WorkspacePreference) => void): () => void {
listeners.add(listener);
return () => { listeners.delete(listener); };
},
/** Clear ephemeral state on application/test lifecycle reset. */
reset(): void {
current = undefined;
notify();
},
};