The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import { EnvironmentId, type EnvironmentSpeechModel } from "@t3tools/contracts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { HttpClient, HttpClientResponse } from "effect/http"; |
| 5 | |
| 6 | import { BearerConnectionTarget, type PreparedConnection } from "../connection/model.ts"; |
| 7 | import { installEnvironmentSpeechModel } from "./environment.ts"; |
| 8 | |
| 9 | const ENVIRONMENT_ID = EnvironmentId.make("environment-1"); |
| 10 | const PREPARED: PreparedConnection = { |
| 11 | environmentId: ENVIRONMENT_ID, |
| 12 | label: "Remote environment", |
| 13 | httpBaseUrl: "https://remote.example.test", |
| 14 | socketUrl: "wss://remote.example.test/ws", |
| 15 | httpAuthorization: { _tag: "Bearer", token: "token" }, |
| 16 | target: new BearerConnectionTarget({ |
| 17 | environmentId: ENVIRONMENT_ID, |
| 18 | label: "Remote environment", |
| 19 | connectionId: "connection-1", |
| 20 | }), |
| 21 | }; |
| 22 | |
| 23 | const model = ( |
| 24 | state: EnvironmentSpeechModel["state"], |
| 25 | active: boolean, |
| 26 | ): EnvironmentSpeechModel => ({ |
| 27 | id: "voxtral-mini", |
| 28 | name: "Voxtral Mini", |
| 29 | description: "", |
| 30 | size: 1, |
| 31 | languages: ["en"], |
| 32 | accuracy: 1, |
| 33 | speed: 1, |
| 34 | recommended: false, |
| 35 | supportsStreaming: false, |
| 36 | supportsLanguageDetection: false, |
| 37 | supportsTranslation: false, |
| 38 | active, |
| 39 | state, |
| 40 | }); |
| 41 | |
| 42 | describe("installEnvironmentSpeechModel", () => { |
| 43 | it.effect.each([ |
| 44 | { |
| 45 | name: "keeps the current model after a cancelled download", |
| 46 | downloaded: model("downloadable", false), |
| 47 | selects: false, |
| 48 | }, |
| 49 | { |
| 50 | name: "selects the model once its download finishes", |
| 51 | downloaded: model("installed", false), |
| 52 | selects: true, |
| 53 | }, |
| 54 | { |
| 55 | name: "leaves a model already in use alone", |
| 56 | downloaded: model("installed", true), |
| 57 | selects: false, |
| 58 | }, |
| 59 | ])("$name", ({ downloaded, selects }) => |
| 60 | Effect.gen(function* () { |
| 61 | const paths: string[] = []; |
| 62 | const client = HttpClient.make((request) => { |
| 63 | const path = new URL(request.url).pathname; |
| 64 | paths.push(path); |
| 65 | const answer = path.endsWith("/select") ? model("installed", true) : downloaded; |
| 66 | return Effect.succeed( |
| 67 | HttpClientResponse.fromWeb(request, Response.json({ models: [answer] })), |
| 68 | ); |
| 69 | }); |
| 70 | |
| 71 | const { models } = yield* installEnvironmentSpeechModel(PREPARED, downloaded.id).pipe( |
| 72 | Effect.provideService(HttpClient.HttpClient, client), |
| 73 | ); |
| 74 | |
| 75 | expect(paths).toEqual([ |
| 76 | "/api/voice/models/download", |
| 77 | ...(selects ? ["/api/voice/models/select"] : []), |
| 78 | ]); |
| 79 | expect(models[0]?.active).toBe(selects || downloaded.active); |
| 80 | }), |
| 81 | ); |
| 82 | |
| 83 | it.effect("keeps the current model when cancellation leaves the weights installed", () => |
| 84 | Effect.gen(function* () { |
| 85 | const downloaded = model("installed", false); |
| 86 | const client = HttpClient.make((request) => |
| 87 | Effect.succeed( |
| 88 | HttpClientResponse.fromWeb( |
| 89 | request, |
| 90 | Response.json( |
| 91 | new URL(request.url).pathname.endsWith("/select") |
| 92 | ? { models: [model("installed", true)] } |
| 93 | : { models: [downloaded], cancelled: true }, |
| 94 | ), |
| 95 | ), |
| 96 | ), |
| 97 | ); |
| 98 | const { models } = yield* installEnvironmentSpeechModel(PREPARED, downloaded.id).pipe( |
| 99 | Effect.provideService(HttpClient.HttpClient, client), |
| 100 | ); |
| 101 | expect(models).toEqual([downloaded]); |
| 102 | }), |
| 103 | ); |
| 104 | }); |