Skip to content

Commit 236c1be

Browse files
shivamhwpclaude
andcommitted
test: keep scheduled task destination tests lean
Drop web and mobile copies of the draft logic and the picker wiring check, keep the server refusal test, and simplify the destination guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9e1307e commit 236c1be

6 files changed

Lines changed: 14 additions & 192 deletions

File tree

‎apps/mobile/src/features/settings/scheduledTaskDraft.test.ts‎

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,14 @@ import {
55
ProviderDriverKind,
66
ProviderInstanceId,
77
ProjectId,
8-
ThreadId,
9-
ScheduledTaskId,
10-
type ScheduledTask,
118
} from "@t3tools/contracts";
129
import {
13-
changeDraftProject,
14-
createDraft,
15-
editDraft,
16-
hasScheduledTaskDraftChanges,
17-
moveDraftToThread,
18-
unbindDraftFromThread,
1910
scheduledTaskDefaultModel,
2011
DEFAULT_SCHEDULE,
2112
scheduleDraftForTask,
2213
scheduleFromDraft,
2314
} from "./scheduledTaskDraft";
2415

25-
describe("scheduled task destination", () => {
26-
const threadId = ThreadId.make("thread:bound");
27-
const bound = editDraft({
28-
id: ScheduledTaskId.make("task"),
29-
projectId: ProjectId.make("project:bound"),
30-
threadId,
31-
title: "Review",
32-
prompt: "Review issues",
33-
enabled: true,
34-
schedule: { type: "interval", everyMs: 60_000 },
35-
workspaceStrategy: { type: "root" },
36-
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
37-
runtimeMode: "full-access",
38-
} as ScheduledTask);
39-
40-
it("opens on the task's thread, and a new task has none", () => {
41-
expect(bound.threadId).toBe(threadId);
42-
expect(createDraft(null, null).threadId).toBeNull();
43-
});
44-
45-
it("moves to a thread, takes on its project, and counts as an edit", () => {
46-
const moved = moveDraftToThread(bound, {
47-
id: ThreadId.make("thread:elsewhere"),
48-
projectId: ProjectId.make("project:elsewhere"),
49-
});
50-
expect(moved).toMatchObject({ threadId: "thread:elsewhere", projectId: "project:elsewhere" });
51-
expect(hasScheduledTaskDraftChanges(bound, moved)).toBe(true);
52-
expect(hasScheduledTaskDraftChanges(bound, { ...moved, projectId: bound.projectId })).toBe(
53-
true,
54-
);
55-
});
56-
57-
it("unbinding leaves the shared checkout, and keeps a chosen workspace", () => {
58-
expect(unbindDraftFromThread(bound)).toMatchObject({
59-
threadId: null,
60-
workspace: "worktree",
61-
startFromOrigin: true,
62-
});
63-
const checkout = { ...bound, workspace: "existing_worktree" as const };
64-
expect(unbindDraftFromThread(checkout)).toEqual({ ...checkout, threadId: null });
65-
const unbound = { ...bound, threadId: null };
66-
expect(unbindDraftFromThread(unbound)).toBe(unbound);
67-
});
68-
69-
it("changing the project clears a binding the new project cannot hold", () => {
70-
expect(changeDraftProject(bound, ProjectId.make("project:new"))).toMatchObject({
71-
projectId: "project:new",
72-
threadId: null,
73-
workspace: "worktree",
74-
});
75-
expect(changeDraftProject(bound, ProjectId.make("project:bound"))).toBe(bound);
76-
});
77-
});
78-
7916
describe("scheduleDraftForTask", () => {
8017
it("opens legacy sub-minute schedules at the writable minimum", () => {
8118
const draft = scheduleDraftForTask({ schedule: { type: "interval", everyMs: 30_000 } });

‎apps/server/src/scheduledTasks/ScheduledTaskService.test.ts‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,7 @@ it.effect("checks a task's destination thread only when the destination changes"
798798
const service = yield* ScheduledTaskService.ScheduledTaskService;
799799
const id = ScheduledTaskId.make("task:destination");
800800
const save = (
801-
threadId: ThreadId | null,
802-
projectId = project,
801+
threadId: ThreadId,
803802
schedule: ScheduledTaskUpsertInput["schedule"] = { type: "interval", everyMs: 60_000 },
804803
) =>
805804
service.upsert({
@@ -808,7 +807,7 @@ it.effect("checks a task's destination thread only when the destination changes"
808807
prompt: "Check progress",
809808
enabled: true,
810809
schedule,
811-
projectId,
810+
projectId: project,
812811
threadId,
813812
workspaceStrategy: { type: "root" },
814813
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
@@ -828,7 +827,7 @@ it.effect("checks a task's destination thread only when the destination changes"
828827
assert.lengthOf((yield* service.list()).tasks, 0);
829828

830829
// A rejected save must not burn a one-shot secret.
831-
yield* save(ThreadId.make("thread:missing"), project, {
830+
yield* save(ThreadId.make("thread:missing"), {
832831
type: "webhook",
833832
signature: {
834833
header: "x-signature",
@@ -839,18 +838,12 @@ it.effect("checks a task's destination thread only when the destination changes"
839838
}).pipe(Effect.flip);
840839
assert.equal(yield* Ref.get(consumed), 0);
841840

842-
const created = yield* save(null);
843-
const moved = yield* save(destination);
844-
assert.equal(moved.task.id, created.task.id);
845-
assert.equal(moved.task.threadId, destination);
846-
847-
// A task whose thread was archived later stays editable; moving its project leaves the thread.
841+
yield* save(destination);
842+
// A task whose thread was archived later stays editable.
848843
yield* Ref.update(shells, (all) =>
849844
new Map(all).set(destination, threadShell(project, { archivedAt })),
850845
);
851-
yield* save(destination);
852-
const projectChange = yield* save(destination, otherProject);
853-
assert.isNull(projectChange.task.threadId);
846+
assert.equal((yield* save(destination)).task.threadId, destination);
854847
}).pipe(Effect.provide(layer));
855848
}).pipe(Effect.provide(SqlitePersistence.layerMemory)),
856849
);

‎apps/server/src/scheduledTasks/ScheduledTaskService.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,13 +1316,7 @@ export const layer = Layer.effect(
13161316
keptThreadId === existingTask.threadId;
13171317
const threadId = threadMode === "new_thread" || movedOffThread ? null : keptThreadId;
13181318
// An unchanged destination is not rechecked, so a task on an archived thread stays editable.
1319-
if (
1320-
threadId !== null &&
1321-
threadId === input.threadId &&
1322-
(existingTask === null ||
1323-
existingTask.threadId !== threadId ||
1324-
existingTask.projectId !== input.projectId)
1325-
) {
1319+
if (threadId !== null && threadId !== existingTask?.threadId) {
13261320
yield* requireDestinationThread(threadId, input.projectId, id);
13271321
}
13281322
// Refused on save rather than at run time; a disabled task can still be saved, so one

‎apps/web/src/components/settings/ScheduledTasksSettings.browser.test.tsx‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,6 @@ describe("ScheduledTasksSettings", () => {
200200
await expect.element(name).toHaveValue("Review stale issues");
201201
});
202202

203-
it("unbinds a task from its thread through the destination picker", async () => {
204-
setup();
205-
await using _screen = await render(<ScheduledTasksSettings taskId={task.id} />);
206-
const destination = page.getByRole("dialog").getByLabelText("Destination");
207-
await expect.element(destination).toHaveTextContent("Fix login bug");
208-
await destination.click();
209-
await page.getByRole("option", { name: "New thread each run" }).click();
210-
await expect.element(destination).toHaveTextContent("New thread each run");
211-
await expect
212-
.element(page.getByRole("dialog").getByLabelText("Workspace"))
213-
.toHaveTextContent("Create a new worktree");
214-
});
215-
216203
it("keeps an editor the user opened when the linked task loads later", async () => {
217204
setup();
218205
state.tasksLoaded = false;

‎apps/web/src/components/settings/scheduledTasksSettings.logic.test.ts‎

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
type ScheduledTask,
99
ThreadId,
1010
} from "@t3tools/contracts";
11-
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models";
1211
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
1312

1413
import type {
@@ -24,9 +23,6 @@ import {
2423
matchesScheduledTaskScope,
2524
scheduleFromDraft,
2625
taskToDraft,
27-
changeDraftProject,
28-
moveDraftToThread,
29-
scheduledTaskDestinationThreads,
3026
unbindDraftFromThread,
3127
} from "./scheduledTasksSettings.logic";
3228

@@ -177,97 +173,17 @@ describe("editing scheduled task branch settings", () => {
177173
});
178174

179175
describe("scheduled task destination", () => {
180-
const rootBound = taskToDraft({
181-
...legacyTask,
182-
threadId: ThreadId.make("thread:bound"),
183-
workspaceStrategy: { type: "root" },
184-
});
185-
186-
it("moves to a thread and takes on its project", () => {
187-
const moved = moveDraftToThread(rootBound, {
188-
id: ThreadId.make("thread:elsewhere"),
189-
projectId: ProjectId.make("project:elsewhere"),
190-
});
191-
expect(moved).toMatchObject({ threadId: "thread:elsewhere", projectId: "project:elsewhere" });
192-
const fromNewThreads = { ...rootBound, threadId: "", threadMode: "new_thread" as const };
193-
expect(
194-
moveDraftToThread(fromNewThreads, {
195-
id: ThreadId.make("thread:elsewhere"),
196-
projectId: ProjectId.make("project:elsewhere"),
197-
}).threadMode,
198-
).toBe("continue");
199-
});
200-
201176
it("unbinding leaves the shared checkout for a new worktree from the remote", () => {
202-
expect(unbindDraftFromThread(rootBound)).toMatchObject({
203-
threadId: "",
204-
workspaceMode: "worktree",
205-
startFromOrigin: true,
206-
});
207-
});
208-
209-
it("unbinding keeps a workspace that was chosen for new threads", () => {
210-
const checkout = taskToDraft({
177+
const rootBound = taskToDraft({
211178
...legacyTask,
212179
threadId: ThreadId.make("thread:bound"),
213-
workspaceStrategy: { type: "existing_worktree", worktreePath: "/work/checkout" },
180+
workspaceStrategy: { type: "root" },
214181
});
215-
expect(unbindDraftFromThread(checkout)).toEqual({ ...checkout, threadId: "" });
216-
});
217-
218-
it("leaves an unbound draft's project-checkout workspace alone", () => {
219-
const unbound = { ...rootBound, threadId: "" };
220-
expect(unbindDraftFromThread(unbound)).toBe(unbound);
221-
});
222-
223-
it("changing the project clears a binding the new project cannot hold", () => {
224-
expect(changeDraftProject(rootBound, ProjectId.make("project:new"))).toMatchObject({
225-
projectId: "project:new",
182+
expect(unbindDraftFromThread(rootBound)).toMatchObject({
226183
threadId: "",
227184
workspaceMode: "worktree",
185+
startFromOrigin: true,
228186
});
229-
expect(changeDraftProject(rootBound, rootBound.projectId)).toBe(rootBound);
230-
});
231-
232-
it("offers open top-level threads of the project, newest first, without the current one", () => {
233-
const projectId = ProjectId.make("project:wanted");
234-
const thread = (id: string, overrides: object = {}) =>
235-
({
236-
id: ThreadId.make(id),
237-
environmentId: laptopId,
238-
projectId,
239-
title: id,
240-
archivedAt: null,
241-
updatedAt: "2026-11-01T00:00:00.000Z",
242-
lineage: { relationshipToParent: null, parentThreadId: null, rootThreadId: id },
243-
...overrides,
244-
}) as unknown as EnvironmentThreadShell;
245-
const threads = [
246-
thread("older"),
247-
thread("newer docs", { updatedAt: "2026-11-02T00:00:00.000Z" }),
248-
thread("current"),
249-
thread("archived", { archivedAt: "2026-11-01T00:00:00.000Z" }),
250-
thread("subagent", {
251-
lineage: {
252-
relationshipToParent: "subagent",
253-
parentThreadId: "older",
254-
rootThreadId: "older",
255-
},
256-
}),
257-
thread("other project", { projectId: ProjectId.make("project:other") }),
258-
thread("other environment", { environmentId: serverId }),
259-
];
260-
const target = {
261-
environmentId: laptopId,
262-
projectId,
263-
currentThreadId: ThreadId.make("current"),
264-
};
265-
expect(
266-
scheduledTaskDestinationThreads(threads, { ...target, query: "" }).map(({ id }) => id),
267-
).toEqual(["newer docs", "older"]);
268-
expect(
269-
scheduledTaskDestinationThreads(threads, { ...target, query: " DOCS" }).map(({ id }) => id),
270-
).toEqual(["newer docs"]);
271187
});
272188
});
273189

‎apps/web/src/components/settings/scheduledTasksSettings.logic.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,20 +328,15 @@ export function changeDraftProject(draft: DraftState, projectId: string): DraftS
328328
}
329329

330330
/** Threads a task can move to. The current one is left out; the picker always shows it. */
331-
export function scheduledTaskDestinationThreads<
332-
TThread extends Pick<
333-
EnvironmentThreadShell,
334-
"environmentId" | "id" | "projectId" | "title" | "lineage" | "archivedAt" | "updatedAt"
335-
>,
336-
>(
337-
threads: ReadonlyArray<TThread>,
331+
export function scheduledTaskDestinationThreads(
332+
threads: ReadonlyArray<EnvironmentThreadShell>,
338333
target: {
339334
readonly environmentId: EnvironmentId;
340335
readonly projectId: string;
341336
readonly currentThreadId: ThreadId | null;
342337
readonly query: string;
343338
},
344-
): ReadonlyArray<TThread> {
339+
): ReadonlyArray<EnvironmentThreadShell> {
345340
const search = target.query.trim().toLocaleLowerCase();
346341
return threads
347342
.filter(

0 commit comments

Comments
 (0)