|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
2 | 2 | import { |
3 | 3 | DEFAULT_SERVER_SETTINGS, |
| 4 | + type ScheduledTask, |
4 | 5 | type ServerConfig, |
5 | 6 | ProviderDriverKind, |
6 | 7 | ProviderInstanceId, |
7 | 8 | ProjectId, |
8 | 9 | ScheduledTaskId, |
9 | | - type ScheduledTask, |
10 | 10 | } from "@t3tools/contracts"; |
11 | 11 | import { |
12 | 12 | createDraft, |
13 | 13 | editDraft, |
| 14 | + hasScheduledTaskDraftChanges, |
| 15 | + leavesSandboxWorkspace, |
14 | 16 | scheduledTaskDefaultModel, |
15 | 17 | DEFAULT_SCHEDULE, |
16 | 18 | scheduleDraftForTask, |
@@ -245,3 +247,52 @@ describe("scheduled task worktree base", () => { |
245 | 247 | ).toBe("release"); |
246 | 248 | }); |
247 | 249 | }); |
| 250 | + |
| 251 | +describe("sandbox workspace retention", () => { |
| 252 | + const task = (workspaceStrategy: ScheduledTask["workspaceStrategy"]): ScheduledTask => ({ |
| 253 | + id: ScheduledTaskId.make("task"), |
| 254 | + title: "Nightly review", |
| 255 | + prompt: "Review open issues", |
| 256 | + enabled: true, |
| 257 | + schedule: { type: "interval", everyMs: 60_000 }, |
| 258 | + projectId: ProjectId.make("project"), |
| 259 | + threadId: null, |
| 260 | + workspaceStrategy, |
| 261 | + modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" }, |
| 262 | + runtimeMode: "full-access", |
| 263 | + interactionMode: "default", |
| 264 | + createdBy: "user", |
| 265 | + creationSource: "mobile", |
| 266 | + createdAt: "2026-09-17T00:00:00.000Z", |
| 267 | + updatedAt: "2026-09-17T00:00:00.000Z", |
| 268 | + nextRunAt: null, |
| 269 | + lastRunAt: null, |
| 270 | + lastRunStatus: "never", |
| 271 | + lastRunError: null, |
| 272 | + runCount: 0, |
| 273 | + }); |
| 274 | + |
| 275 | + it("keeps a stored sandbox strategy when editing an unrelated field", () => { |
| 276 | + const initial = editDraft(task({ type: "sandbox" })); |
| 277 | + expect(initial.workspace).toBe("sandbox"); |
| 278 | + expect(initial.storedSandbox).toBe(true); |
| 279 | + expect(leavesSandboxWorkspace(initial)).toBe(false); |
| 280 | + // Renaming the task does not move it off its fleet worker. |
| 281 | + const renamed = { ...initial, title: "Renamed" }; |
| 282 | + expect(hasScheduledTaskDraftChanges(initial, renamed)).toBe(true); |
| 283 | + expect(leavesSandboxWorkspace(renamed)).toBe(false); |
| 284 | + }); |
| 285 | + |
| 286 | + it("surfaces a warning only when the workspace control leaves the sandbox", () => { |
| 287 | + const initial = editDraft(task({ type: "sandbox" })); |
| 288 | + const moved = { ...initial, workspace: "worktree" as const }; |
| 289 | + expect(leavesSandboxWorkspace(moved)).toBe(true); |
| 290 | + expect(hasScheduledTaskDraftChanges(initial, moved)).toBe(true); |
| 291 | + // A task that never ran in a sandbox is never flagged. |
| 292 | + const worktreeDraft = editDraft( |
| 293 | + task({ type: "worktree", baseRef: "release", startFromOrigin: false }), |
| 294 | + ); |
| 295 | + expect(worktreeDraft.storedSandbox).toBe(false); |
| 296 | + expect(leavesSandboxWorkspace({ ...worktreeDraft, workspace: "root" as const })).toBe(false); |
| 297 | + }); |
| 298 | +}); |
0 commit comments