import { describe, expect, it, vi } from "vitest"; import { zcodeWorkspaceUpdateModelIoPreferencesResultSchema } from "@zcode/shared"; import { updateModelIoPreferences } from "../src/zcode-protocol/model-io-preferences.js"; import type { ZCodeProtocolAgentServerContext } from "../src/zcode-protocol/server-types.js"; import { createFakeApp } from "./helpers/fake-zcode-app.js"; const workspace = { workspacePath: "/workspace/app", workspaceKey: "/workspace/app", }; describe("ModelIO runtime preferences", () => { it("applies full retention to resident apps and caches it for future apps", async () => { const setModelIoFullRetentionEnabled = vi.fn(); const context = { appRuntimePreferences: { askUserQuestionAutoResolutionEnabled: true, modelIoFullRetentionEnabled: false, offPeakToolEnabled: false, }, sessions: new Map([ [ "sess_model_io", { app: createFakeApp(undefined, { setModelIoFullRetentionEnabled }), }, ], ]), } as unknown as ZCodeProtocolAgentServerContext; const result = zcodeWorkspaceUpdateModelIoPreferencesResultSchema.parse( await updateModelIoPreferences(context, { workspace, preferences: { fullRetentionEnabled: true }, }), ); expect(result).toEqual({ workspace, fullRetentionEnabled: true, updatedSessionCount: 1, }); expect(context.appRuntimePreferences.modelIoFullRetentionEnabled).toBe(true); expect(setModelIoFullRetentionEnabled).toHaveBeenCalledWith(true); }); });