-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathtaskService.test.ts
More file actions
77 lines (71 loc) · 2.58 KB
/
Copy pathtaskService.test.ts
File metadata and controls
77 lines (71 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import type { SessionService } from "@posthog/core/sessions/sessionService";
import type { RootLogger } from "@posthog/di/logger";
import { describe, expect, it, vi } from "vitest";
import type { TaskCreationEffects } from "./taskCreationEffects";
import type { ITaskCreationHost } from "./taskCreationHost";
import { buildWorktreeAdoptionInput } from "./taskInput";
import { TaskService } from "./taskService";
const scopedLog = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};
const rootLogger = {
...scopedLog,
scope: () => scopedLog,
} as unknown as RootLogger;
function makeService(): TaskService {
const host = {
// The API client's createTask rejects so tests can observe that an input
// made it past validation (failedStep lands on task_creation, not
// validation) without faking the whole saga.
getAuthenticatedClient: vi.fn(async () => ({
createTask: vi.fn().mockRejectedValue(new Error("api down")),
deleteTask: vi.fn(),
getTask: vi.fn(),
createTaskRun: vi.fn(),
startTaskRun: vi.fn(),
sendRunCommand: vi.fn(),
updateTask: vi.fn(),
})),
detectRepo: vi.fn(async () => null),
getFolders: vi.fn(async () => []),
addFolder: vi.fn(async () => ({ id: "folder-1", path: "/repo" })),
track: vi.fn(),
} as unknown as ITaskCreationHost;
const sessionService = {
markTaskCreationInFlight: vi.fn(),
connectToTask: vi.fn(),
disconnectFromTask: vi.fn(),
} as unknown as SessionService;
const effects = {
onWorkspaceCreated: vi.fn(),
onCreateSuccess: vi.fn(),
} as unknown as TaskCreationEffects;
return new TaskService(host, sessionService, effects, rootLogger);
}
describe("TaskService.createTask validation", () => {
it("rejects an input with neither content nor a taskDescription", async () => {
const result = await makeService().createTask({
content: " ",
repoPath: "/repo",
workspaceMode: "worktree",
});
expect(result.success).toBe(false);
if (result.success) throw new Error("expected validation failure");
expect(result.failedStep).toBe("validation");
});
it("accepts a promptless worktree-adoption input", async () => {
const result = await makeService().createTask(
buildWorktreeAdoptionInput({
repoPath: "/repo",
branch: "feature/orphan",
}),
);
// The stubbed API call fails, proving the input got past validation.
expect(result.success).toBe(false);
if (result.success) throw new Error("expected task_creation failure");
expect(result.failedStep).toBe("task_creation");
});
});