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

RuntimePolicy.test.ts

104 lines3.0 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 settledOverride: null,
52 settledAt: null,
53 lastVisitedAt: null,
54 deletedAt: null,
55 };
57​
58const TestLayer = layerFromProjectRepository.pipe(
59 Layer.provide(
60 Layer.mock(ProjectionProjects.ProjectionProjectRepository)({
61 getById: () =>
62 Effect.succeed(
63 Option.some({
64 projectId,
65 title: "Project",
66 workspaceRoot: "/project-root",
67 defaultModelSelection: null,
68 defaultThreadEnvMode: null,
69 autoPull: false,
70 scripts: [],
71 createdAt: "2026-06-21T00:00:00.000Z",
72 updatedAt: "2026-06-21T00:00:00.000Z",
73 deletedAt: null,
74 }),
75 ),
76 }),
77 ),
78);
79​
80it.layer(TestLayer)("RuntimePolicyV2", (it) => {
81 it.effect("uses the project root for local-checkout threads", () =>
82 Effect.gen(function* () {
83 const policy = yield* RuntimePolicyV2;
84 const now = yield* DateTime.now;
85 const resolved = yield* policy.resolve({
86 thread: makeThread({ now, worktreePath: null }),
87 modelSelection,
88 });
89 assert.equal(resolved.cwd, "/project-root");
90 }),
91 );
92​
93 it.effect("prefers a provisioned worktree over the project root", () =>
94 Effect.gen(function* () {
95 const policy = yield* RuntimePolicyV2;
96 const now = yield* DateTime.now;
97 const resolved = yield* policy.resolve({
98 thread: makeThread({ now, worktreePath: "/project-worktree" }),
99 modelSelection,
100 });
101 assert.equal(resolved.cwd, "/project-worktree");
102 }),
103 );
104});