model-io-preferences.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { describe, expect, it, vi } from "vitest";
  2. import { zcodeWorkspaceUpdateModelIoPreferencesResultSchema } from "@zcode/shared";
  3. import { updateModelIoPreferences } from "../src/zcode-protocol/model-io-preferences.js";
  4. import type { ZCodeProtocolAgentServerContext } from "../src/zcode-protocol/server-types.js";
  5. import { createFakeApp } from "./helpers/fake-zcode-app.js";
  6. const workspace = {
  7. workspacePath: "/workspace/app",
  8. workspaceKey: "/workspace/app",
  9. };
  10. describe("ModelIO runtime preferences", () => {
  11. it("applies full retention to resident apps and caches it for future apps", async () => {
  12. const setModelIoFullRetentionEnabled = vi.fn();
  13. const context = {
  14. appRuntimePreferences: {
  15. askUserQuestionAutoResolutionEnabled: true,
  16. modelIoFullRetentionEnabled: false,
  17. offPeakToolEnabled: false,
  18. },
  19. sessions: new Map([
  20. [
  21. "sess_model_io",
  22. {
  23. app: createFakeApp(undefined, { setModelIoFullRetentionEnabled }),
  24. },
  25. ],
  26. ]),
  27. } as unknown as ZCodeProtocolAgentServerContext;
  28. const result = zcodeWorkspaceUpdateModelIoPreferencesResultSchema.parse(
  29. await updateModelIoPreferences(context, {
  30. workspace,
  31. preferences: { fullRetentionEnabled: true },
  32. }),
  33. );
  34. expect(result).toEqual({
  35. workspace,
  36. fullRetentionEnabled: true,
  37. updatedSessionCount: 1,
  38. });
  39. expect(context.appRuntimePreferences.modelIoFullRetentionEnabled).toBe(true);
  40. expect(setModelIoFullRetentionEnabled).toHaveBeenCalledWith(true);
  41. });
  42. });