Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

RuntimePolicy.test.ts

99 lines2.8 KB

1import { assert, it } from "@effect/vitest";
2import {
3 type ModelSelection,
4 type OrchestrationV2AppThread,
5 ProjectId,
6 ProviderInstanceId,
7 ThreadId,
8} from "@t3tools/contracts";
9import * as DateTime from "effect/DateTime";
10import * as Effect from "effect/Effect";
11import * as Layer from "effect/Layer";
12import * as Option from "effect/Option";
13​
14import * as ProjectionProjects from "../persistence/Services/ProjectionProjects.ts";
15import { layerFromProjectRepository, RuntimePolicyV2 } from "./RuntimePolicy.ts";
16​
17const projectId = ProjectId.make("project:runtime-policy");
18const providerInstanceId = ProviderInstanceId.make("codex");
19const modelSelection = {
20 instanceId: providerInstanceId,
21 model: "gpt-5.5",
22} satisfies ModelSelection;
23​
24function makeThread(input: {
25 readonly now: DateTime.Utc;
26 readonly worktreePath: string | null;
27}): OrchestrationV2AppThread {
28 const threadId = ThreadId.make("thread:runtime-policy");
29 return {
30 createdBy: "user",
31 creationSource: "web",
32 id: threadId,
33 projectId,
34 title: "Runtime policy",
35 providerInstanceId,
36 modelSelection,
37 runtimeMode: "full-access",
38 interactionMode: "default",
39 branch: null,
40 worktreePath: input.worktreePath,
41 activeProviderThreadId: null,
42 lineage: {
43 parentThreadId: null,
44 relationshipToParent: null,
45 rootThreadId: threadId,
46 },
47 forkedFrom: null,
48 createdAt: input.now,
49 updatedAt: input.now,
50 archivedAt: null,
51 deletedAt: null,
52 };
54​
55const TestLayer = layerFromProjectRepository.pipe(
56 Layer.provide(
57 Layer.mock(ProjectionProjects.ProjectionProjectRepository)({
58 getById: () =>
59 Effect.succeed(
60 Option.some({
61 projectId,
62 title: "Project",
63 workspaceRoot: "/project-root",
64 defaultModelSelection: null,
65 scripts: [],
66 createdAt: "2026-06-21T00:00:00.000Z",
67 updatedAt: "2026-06-21T00:00:00.000Z",
68 deletedAt: null,
69 }),
70 ),
71 }),
72 ),
73);
74​
75it.layer(TestLayer)("RuntimePolicyV2", (it) => {
76 it.effect("uses the project root for local-checkout threads", () =>
77 Effect.gen(function* () {
78 const policy = yield* RuntimePolicyV2;
79 const now = yield* DateTime.now;
80 const resolved = yield* policy.resolve({
81 thread: makeThread({ now, worktreePath: null }),
82 modelSelection,
83 });
84 assert.equal(resolved.cwd, "/project-root");
85 }),
86 );
87​
88 it.effect("prefers a provisioned worktree over the project root", () =>
89 Effect.gen(function* () {
90 const policy = yield* RuntimePolicyV2;
91 const now = yield* DateTime.now;
92 const resolved = yield* policy.resolve({
93 thread: makeThread({ now, worktreePath: "/project-worktree" }),
94 modelSelection,
95 });
96 assert.equal(resolved.cwd, "/project-worktree");
97 }),
98 );
99});