Open History to see the last commit
1import { assert, it, vi } from "@effect/vitest";
2import { ProjectId } from "@t3tools/contracts";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import * as Option from "effect/Option";
6
7import * as TerminalManager from "../terminal/Manager.ts";
8import * as ProjectService from "./ProjectService.ts";
9import * as ProjectSetupScriptRunner from "./ProjectSetupScriptRunner.ts";
10
11it.effect("resolves setup scripts through the standalone project service", () => {
12 const open = vi.fn((input: Parameters<TerminalManager.TerminalManager["Service"]["open"]>[0]) =>
13 Effect.succeed({
14 threadId: input.threadId,
15 terminalId: input.terminalId,
16 cwd: input.cwd,
17 worktreePath: input.worktreePath ?? null,
18 status: "running" as const,
19 pid: 123,
20 history: "",
21 exitCode: null,
22 exitSignal: null,
23 label: "Shell",
24 updatedAt: "2026-06-20T00:00:00.000Z",
25 }),
26 );
27 const write = vi.fn(
28 (_input: Parameters<TerminalManager.TerminalManager["Service"]["write"]>[0]) => Effect.void,
29 );
30 const projectId = ProjectId.make("project:setup-runner-v2");
31 const project = {
32 id: projectId,
33 title: "Project",
34 workspaceRoot: "/repo",
35 repositoryIdentity: null,
36 faviconPath: null,
37 defaultModelSelection: null,
38 scripts: [
39 {
40 id: "setup",
41 name: "Setup",
42 command: "vp install",
43 icon: "configure" as const,
44 runOnWorktreeCreate: true,
45 },
46 ],
47 createdAt: "2026-06-20T00:00:00.000Z",
48 updatedAt: "2026-06-20T00:00:00.000Z",
49 deletedAt: null,
50 };
51 const layer = ProjectSetupScriptRunner.layer.pipe(
52 Layer.provide(
53 Layer.mergeAll(
54 Layer.mock(ProjectService.ProjectService)({
55 getById: () => Effect.succeed(Option.some(project)),
56 }),
57 Layer.mock(TerminalManager.TerminalManager)({ open, write }),
58 ),
59 ),
60 );
61
62 return Effect.gen(function* () {
63 const runner = yield* ProjectSetupScriptRunner.ProjectSetupScriptRunner;
64 const result = yield* runner.runForThread({
65 threadId: "thread-1",
66 projectId,
67 worktreePath: "/repo-worktree",
68 });
69 assert.deepEqual(result, {
70 status: "started",
71 scriptId: "setup",
72 scriptName: "Setup",
73 terminalId: "setup-setup",
74 cwd: "/repo-worktree",
75 });
76 assert.equal(open.mock.calls[0]?.[0].cwd, "/repo-worktree");
77 assert.equal(write.mock.calls[0]?.[0].data, "vp install\r");
78 }).pipe(Effect.provide(layer));
79});