Infer sync engine mode from injected state engine

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
Cursor AgentandJulius Marminge committed 2026-02-20 12:26:22 +00:00
1 parent bba3afe33b
commit 8b8ce91e37
2 files changed
+91 -1

No files matched your search

+74
View File
@@ -582,6 +582,80 @@ describe("WebSocket Server", () => {
});
});
it("infers shadow sync engine mode in server.getConfig when mode option omitted", async () => {
const stateDir = makeTempDir("t3code-ws-config-shadow-infer-state-");
const persistenceService = new PersistenceService({
dbPath: path.join(stateDir, "state.sqlite"),
});
const legacy = new LegacyStateSyncEngine({ persistenceService });
const mirror = new LiveStoreStateMirror({ storeId: "ws-config-shadow-infer-test" });
const shadow = new ShadowStateSyncEngine({
delegate: legacy,
mirror,
});
try {
server = createTestServer({
cwd: "/my/workspace",
stateSyncEngine: shadow,
});
await server.start();
const addr = server.httpServer.address();
const port = typeof addr === "object" && addr !== null ? addr.port : 0;
const ws = await connectWs(port);
connections.push(ws);
await waitForMessage(ws);
const response = await sendRequest(ws, WS_METHODS.serverGetConfig);
expect(response.error).toBeUndefined();
expect(response.result).toEqual({
cwd: "/my/workspace",
syncEngineMode: "shadow",
keybindings: DEFAULT_RESOLVED_KEYBINDINGS,
});
} finally {
shadow.close();
}
});
it("infers read-pilot sync engine mode in server.getConfig when mode option omitted", async () => {
const stateDir = makeTempDir("t3code-ws-config-readpilot-infer-state-");
const persistenceService = new PersistenceService({
dbPath: path.join(stateDir, "state.sqlite"),
});
const legacy = new LegacyStateSyncEngine({ persistenceService });
const mirror = new LiveStoreStateMirror({ storeId: "ws-config-readpilot-infer-test" });
const readPilot = new LiveStoreReadPilotStateSyncEngine({
delegate: legacy,
mirror,
});
try {
server = createTestServer({
cwd: "/my/workspace",
stateSyncEngine: readPilot,
});
await server.start();
const addr = server.httpServer.address();
const port = typeof addr === "object" && addr !== null ? addr.port : 0;
const ws = await connectWs(port);
connections.push(ws);
await waitForMessage(ws);
const response = await sendRequest(ws, WS_METHODS.serverGetConfig);
expect(response.error).toBeUndefined();
expect(response.result).toEqual({
cwd: "/my/workspace",
syncEngineMode: "livestore-read-pilot",
keybindings: DEFAULT_RESOLVED_KEYBINDINGS,
});
} finally {
readPilot.close();
}
});
it("reads keybindings from ~/.t3/keybindings.json", async () => {
const fakeHome = makeTempDir("t3code-home-");
const configDir = path.join(fakeHome, ".t3");
+17 -1
View File
@@ -35,6 +35,8 @@ import { searchWorkspaceEntries } from "./workspaceEntries";
import { PersistenceService } from "./persistenceService";
import type { StateSyncEngine } from "./stateSyncEngine";
import { LegacyStateSyncEngine } from "./stateSyncEngineLegacy";
import { LiveStoreReadPilotStateSyncEngine } from "./stateSyncEngineLiveStoreReadPilot";
import { ShadowStateSyncEngine } from "./stateSyncEngineShadow";
import type { SyncEngineMode } from "./syncEngineMode";
const MIME_TYPES: Record<string, string> = {
@@ -90,7 +92,7 @@ export function createServer(options: ServerOptions) {
gitManager: providedGitManager,
terminalManager: providedTerminalManager,
authToken,
syncEngineMode = "legacy",
syncEngineMode: providedSyncEngineMode,
} = options;
const persistenceService =
providedPersistenceService ??
@@ -100,6 +102,7 @@ export function createServer(options: ServerOptions) {
const ownsPersistenceService = providedPersistenceService === undefined;
const stateSyncEngine =
providedStateSyncEngine ?? new LegacyStateSyncEngine({ persistenceService });
const syncEngineMode = providedSyncEngineMode ?? inferSyncEngineMode(stateSyncEngine);
const ownsStateSyncEngine = providedStateSyncEngine === undefined;
const providerManager = new ProviderManager({ persistenceService });
const terminalManager = providedTerminalManager ?? new TerminalManager();
@@ -612,3 +615,16 @@ export function createServer(options: ServerOptions) {
return { start, stop, httpServer };
}
function inferSyncEngineMode(stateSyncEngine: StateSyncEngine): SyncEngineMode {
if (stateSyncEngine instanceof LiveStoreReadPilotStateSyncEngine) {
return "livestore-read-pilot";
}
if (stateSyncEngine instanceof ShadowStateSyncEngine) {
return "shadow";
}
if (stateSyncEngine instanceof LegacyStateSyncEngine) {
return "legacy";
}
return "legacy";
}