Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { ProviderInstanceId } from "@t3tools/contracts";
4import * as Effect from "effect/Effect";
5import * as Layer from "effect/Layer";
6
7import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
8import * as OpenCode2AdapterV2Testkit from "../orchestration-v2/Adapters/OpenCode2AdapterV2.testkit.ts";
9import * as OpenCode2Server from "@t3tools/provider-opencode/server/v2/OpenCode2Server";
10import * as OpenCode2TextGeneration from "@t3tools/provider-opencode/server/v2/textGeneration";
11import { OPENCODE2_TITLE_GENERATION } from "./OpenCode2TextGeneration.fixture.ts";
12
13const layer = TestProviderHost.layer().pipe(Layer.provideMerge(NodeServices.layer));
14
15it.layer(layer)("OpenCode2TextGeneration", (it) => {
16 it.effect("generates a title in a temporary session on the free tier and removes it", () =>
17 Effect.gen(function* () {
18 const server = yield* OpenCode2AdapterV2Testkit.replayServer({
19 provider: "opencode",
20 protocol: OpenCode2AdapterV2Testkit.OPENCODE2_HTTP_PROTOCOL,
21 version: "2.0.18",
22 scenario: "opencode2_title_generation",
23 entries: [...OPENCODE2_TITLE_GENERATION, { type: "runtime_exit", status: "success" }],
24 });
25 const textGeneration = yield* OpenCode2TextGeneration.make().pipe(
26 Effect.provideService(OpenCode2Server.OpenCode2Server, server),
27 );
28 const title = yield* textGeneration.generateThreadTitle({
29 cwd: process.cwd(),
30 message: "fix the login redirect loop after oauth",
31 modelSelection: {
32 instanceId: ProviderInstanceId.make("opencode"),
33 model: "opencode/big-pickle",
34 },
35 });
36 assert.equal(title.title, "Fix OAuth Login Redirect Loop");
37 }).pipe(Effect.scoped),
38 );
39
40 it.effect("keeps a provider's own error message out of the caller-visible detail", () =>
41 Effect.gen(function* () {
42 const [subscribe, connected, create, created] = OPENCODE2_TITLE_GENERATION;
43 const sessionId = "ses_f0ec85cf6ffebfalpvV2E9nocu";
44 const refusal = {
45 type: "provider.auth",
46 message:
47 "Error from provider (Console): OpenCode's free tier can only be used from within OpenCode",
48 status: 403,
49 };
50 const server = yield* OpenCode2AdapterV2Testkit.replayServer({
51 provider: "opencode",
52 protocol: OpenCode2AdapterV2Testkit.OPENCODE2_HTTP_PROTOCOL,
53 version: "2.0.18",
54 scenario: "opencode2_title_generation_refused",
55 entries: [
56 subscribe!,
57 connected!,
58 create!,
59 created!,
60 {
61 type: "expect_outbound",
62 frame: { type: "session.prompt", input: { sessionID: sessionId, text: "<any>" } },
63 },
64 {
65 type: "emit_inbound",
66 frame: {
67 type: "sdk.response",
68 operation: "session.prompt",
69 data: {
70 data: {
71 id: "msg_1",
72 sessionID: sessionId,
73 time: { created: 1 },
74 type: "user",
75 payload: { text: "t" },
76 delivery: "steer",
77 },
78 },
79 },
80 },
81 {
82 type: "emit_inbound",
83 frame: {
84 type: "sdk.event",
85 event: {
86 id: "evt_0eb7f9ae0001VCNDHVLnqTfoPG",
87 created: 1790657403616,
88 type: "session.execution.failed",
89 data: { sessionID: sessionId, error: refusal },
90 durable: { aggregateID: sessionId, seq: 7, version: 1 },
91 },
92 },
93 },
94 {
95 type: "expect_outbound",
96 frame: { type: "session.remove", input: { sessionID: sessionId } },
97 },
98 {
99 type: "emit_inbound",
100 frame: { type: "sdk.response", operation: "session.remove", data: null },
101 },
102 { type: "runtime_exit", status: "success" },
103 ],
104 });
105 const textGeneration = yield* OpenCode2TextGeneration.make().pipe(
106 Effect.provideService(OpenCode2Server.OpenCode2Server, server),
107 );
108 const failure = yield* textGeneration
109 .generateThreadTitle({
110 cwd: process.cwd(),
111 message: "fix the login redirect loop after oauth",
112 modelSelection: {
113 instanceId: ProviderInstanceId.make("opencode"),
114 model: "opencode/big-pickle",
115 },
116 })
117 .pipe(Effect.flip);
118 assert.equal(failure.detail, "OpenCode could not generate the text.");
119 assert.deepEqual(failure.cause, refusal);
120 }).pipe(Effect.scoped),
121 );
122});