11import { assert , it } from "@effect/vitest" ;
22import * as NodeServices from "@effect/platform-node/NodeServices" ;
3- import { ProviderInstanceId } from "@t3tools/contracts" ;
3+ import * as NodeURL from "node:url" ;
4+ import { ChatAttachmentId , ChatImageAttachment , ProviderInstanceId } from "@t3tools/contracts" ;
45import * as Deferred from "effect/Deferred" ;
56import * as Effect from "effect/Effect" ;
7+ import * as FileSystem from "effect/FileSystem" ;
68import * as Fiber from "effect/Fiber" ;
79import * as Layer from "effect/Layer" ;
810import { TestClock } from "effect/testing" ;
911
12+ import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost" ;
1013import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost" ;
1114import * as OpenCode2AdapterV2Testkit from "../orchestration-v2/Adapters/OpenCode2AdapterV2.testkit.ts" ;
1215import * as OpenCode2Server from "@t3tools/provider-opencode/server/v2/OpenCode2Server" ;
@@ -16,28 +19,58 @@ import { OPENCODE2_TITLE_GENERATION } from "./OpenCode2TextGeneration.fixture.ts
1619const layer = TestProviderHost . layer ( ) . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ;
1720
1821it . layer ( layer ) ( "OpenCode2TextGeneration" , ( it ) => {
19- it . effect ( "generates a title in a temporary session on the free tier and removes it" , ( ) =>
20- Effect . gen ( function * ( ) {
21- const server = yield * OpenCode2AdapterV2Testkit . replayServer ( {
22- provider : "opencode" ,
23- protocol : OpenCode2AdapterV2Testkit . OPENCODE2_HTTP_PROTOCOL ,
24- version : "2.0.18" ,
25- scenario : "opencode2_title_generation" ,
26- entries : [ ...OPENCODE2_TITLE_GENERATION , { type : "runtime_exit" , status : "success" } ] ,
27- } ) ;
28- const textGeneration = yield * OpenCode2TextGeneration . make ( ) . pipe (
29- Effect . provideService ( OpenCode2Server . OpenCode2Server , server ) ,
30- ) ;
31- const title = yield * textGeneration . generateThreadTitle ( {
32- cwd : process . cwd ( ) ,
33- message : "fix the login redirect loop after oauth" ,
34- modelSelection : {
35- instanceId : ProviderInstanceId . make ( "opencode" ) ,
36- model : "opencode/big-pickle" ,
37- } ,
38- } ) ;
39- assert . equal ( title . title , "Fix OAuth Login Redirect Loop" ) ;
40- } ) . pipe ( Effect . scoped ) ,
22+ it . effect . each ( [ false , true ] as const ) (
23+ "generates a title in a temporary session on the free tier and removes it (external: %s)" ,
24+ ( external ) =>
25+ Effect . gen ( function * ( ) {
26+ const host = yield * ProviderHost . ProviderHost ;
27+ const fileSystem = yield * FileSystem . FileSystem ;
28+ const image = ( id : string , name : string , mimeType : string ) =>
29+ ChatImageAttachment . make ( {
30+ type : "image" ,
31+ id : ChatAttachmentId . make ( id ) ,
32+ name,
33+ mimeType,
34+ sizeBytes : 4 ,
35+ } ) ;
36+ const screenshot = image ( "oc2-title-screenshot" , "screen.png" , "image/png" ) ;
37+ const missing = image ( "oc2-title-missing" , "missing.png" , "image/png" ) ;
38+ const unsupported = image ( "oc2-title-diagram" , "diagram.svg" , "image/svg+xml" ) ;
39+ const screenshotPath = host . resolveAttachmentPath ( screenshot ) ! ;
40+ yield * fileSystem . writeFileString ( screenshotPath , "data" ) ;
41+ yield * fileSystem . writeFileString ( host . resolveAttachmentPath ( unsupported ) ! , "<svg/>" ) ;
42+ const prompts : Array < unknown > = [ ] ;
43+ const server = yield * OpenCode2AdapterV2Testkit . replayServer (
44+ {
45+ provider : "opencode" ,
46+ protocol : OpenCode2AdapterV2Testkit . OPENCODE2_HTTP_PROTOCOL ,
47+ version : "2.0.18" ,
48+ scenario : "opencode2_title_generation" ,
49+ entries : [ ...OPENCODE2_TITLE_GENERATION , { type : "runtime_exit" , status : "success" } ] ,
50+ } ,
51+ { external, onPrompt : ( input ) => prompts . push ( input ) } ,
52+ ) ;
53+ const textGeneration = yield * OpenCode2TextGeneration . make ( ) . pipe (
54+ Effect . provideService ( OpenCode2Server . OpenCode2Server , server ) ,
55+ ) ;
56+ const title = yield * textGeneration . generateThreadTitle ( {
57+ cwd : process . cwd ( ) ,
58+ message : "fix the login redirect loop after oauth" ,
59+ attachments : [ screenshot , missing , unsupported ] ,
60+ modelSelection : {
61+ instanceId : ProviderInstanceId . make ( "opencode" ) ,
62+ model : "opencode/big-pickle" ,
63+ } ,
64+ } ) ;
65+ assert . equal ( title . title , "Fix OAuth Login Redirect Loop" ) ;
66+ if ( external ) {
67+ assert . notProperty ( prompts [ 0 ] , "files" ) ;
68+ } else {
69+ assert . deepInclude ( prompts [ 0 ] , {
70+ files : [ { uri : NodeURL . pathToFileURL ( screenshotPath ) . href , name : "screen.png" } ] ,
71+ } ) ;
72+ }
73+ } ) . pipe ( Effect . scoped ) ,
4174 ) ;
4275
4376 it . effect ( "keeps a provider's own error message out of the caller-visible detail" , ( ) =>
0 commit comments