|
1 | 1 | import { assert, it } from "@effect/vitest"; |
2 | 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
3 | 3 | import { ProviderInstanceId } from "@t3tools/contracts"; |
| 4 | +import * as Deferred from "effect/Deferred"; |
4 | 5 | import * as Effect from "effect/Effect"; |
| 6 | +import * as Fiber from "effect/Fiber"; |
5 | 7 | import * as Layer from "effect/Layer"; |
| 8 | +import { TestClock } from "effect/testing"; |
6 | 9 |
|
7 | 10 | import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost"; |
8 | 11 | import * as OpenCode2AdapterV2Testkit from "../orchestration-v2/Adapters/OpenCode2AdapterV2.testkit.ts"; |
@@ -119,4 +122,70 @@ it.layer(layer)("OpenCode2TextGeneration", (it) => { |
119 | 122 | assert.deepEqual(failure.cause, refusal); |
120 | 123 | }).pipe(Effect.scoped), |
121 | 124 | ); |
| 125 | + |
| 126 | + it.effect("times out when the prompt request and its interrupt never answer", () => |
| 127 | + Effect.gen(function* () { |
| 128 | + const [subscribe, connected, create, created] = OPENCODE2_TITLE_GENERATION; |
| 129 | + const sessionId = "ses_f0ec85cf6ffebfalpvV2E9nocu"; |
| 130 | + const prompted = yield* Deferred.make<void>(); |
| 131 | + const server = yield* OpenCode2AdapterV2Testkit.replayServer( |
| 132 | + { |
| 133 | + provider: "opencode", |
| 134 | + protocol: OpenCode2AdapterV2Testkit.OPENCODE2_HTTP_PROTOCOL, |
| 135 | + version: "2.0.18", |
| 136 | + scenario: "opencode2_title_generation_stalled", |
| 137 | + entries: [ |
| 138 | + subscribe!, |
| 139 | + connected!, |
| 140 | + create!, |
| 141 | + created!, |
| 142 | + { |
| 143 | + type: "expect_outbound", |
| 144 | + frame: { type: "session.prompt", input: { sessionID: sessionId, text: "<any>" } }, |
| 145 | + }, |
| 146 | + { |
| 147 | + type: "emit_inbound", |
| 148 | + frame: { type: "sdk.response", operation: "session.prompt", data: "<hang>" }, |
| 149 | + }, |
| 150 | + { |
| 151 | + type: "expect_outbound", |
| 152 | + frame: { type: "session.interrupt", input: { sessionID: sessionId } }, |
| 153 | + }, |
| 154 | + { |
| 155 | + type: "emit_inbound", |
| 156 | + frame: { type: "sdk.response", operation: "session.interrupt", data: "<hang>" }, |
| 157 | + }, |
| 158 | + { |
| 159 | + type: "expect_outbound", |
| 160 | + frame: { type: "session.remove", input: { sessionID: sessionId } }, |
| 161 | + }, |
| 162 | + { |
| 163 | + type: "emit_inbound", |
| 164 | + frame: { type: "sdk.response", operation: "session.remove", data: null }, |
| 165 | + }, |
| 166 | + { type: "runtime_exit", status: "success" }, |
| 167 | + ], |
| 168 | + }, |
| 169 | + { onPrompt: () => Deferred.doneUnsafe(prompted, Effect.void) }, |
| 170 | + ); |
| 171 | + const textGeneration = yield* OpenCode2TextGeneration.make().pipe( |
| 172 | + Effect.provideService(OpenCode2Server.OpenCode2Server, server), |
| 173 | + ); |
| 174 | + const generation = yield* textGeneration |
| 175 | + .generateThreadTitle({ |
| 176 | + cwd: process.cwd(), |
| 177 | + message: "fix the login redirect loop after oauth", |
| 178 | + modelSelection: { |
| 179 | + instanceId: ProviderInstanceId.make("opencode"), |
| 180 | + model: "opencode/big-pickle", |
| 181 | + }, |
| 182 | + }) |
| 183 | + .pipe(Effect.flip, Effect.forkScoped); |
| 184 | + yield* Deferred.await(prompted); |
| 185 | + yield* TestClock.adjust("3 minutes"); |
| 186 | + yield* TestClock.adjust("5 seconds"); |
| 187 | + const failure = yield* Fiber.join(generation); |
| 188 | + assert.equal(failure.detail, "OpenCode did not finish generating in time."); |
| 189 | + }).pipe(Effect.scoped), |
| 190 | + ); |
122 | 191 | }); |
0 commit comments