The Messaging Service built the voice-transcription client in-process from [models].transcription and [providers.*], which the messaging boundary PRD reserves to the process that owns the model runtime and its provider credentials. The deletion gate only measured linked packages, so the PRD violation shipped green: config reads are not imports. Move the capability across the boundary: - archiemessaging no longer reads [models] or [providers], builds no transcription client, and drops the ResolvedConfig.Transcriber field. - telegram classifies a voice note as messaging.MediaTypeVoice and stops transcribing; it carries the attachment bytes and its note to the turn, which is all a frontend without the credential can do. - archied builds the transcriber beside the chat runtime from its own model-role configuration (setupTranscriber) and gives it to every gateway TurnRunner. - the turn runner transcribes a speech attachment before recording the inbound message, so stored history and the model context carry the transcript; a nil/failed/empty transcription keeps the frontend note. - messaging.TranscribedMessageText renders the transcript into the text a frontend built from its media note, preserving the sender's caption. Red first: TestTurnRunnerTranscribesSpeechOnTheModelOwningSide failed at 'Transcribe calls = 0, want 1' with the transcription call disabled.
111 lines
2.8 KiB
Go
111 lines
2.8 KiB
Go
package archiemessaging
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestOptionsDefaultsAndValidation(t *testing.T) {
|
|
opts := withDefaults(Options{})
|
|
if opts.Gateway.Target != defaultGatewayTarget {
|
|
t.Errorf("Gateway.Target = %q, want %q", opts.Gateway.Target, defaultGatewayTarget)
|
|
}
|
|
if opts.DependencyTimeout != defaultDependencyTimeout {
|
|
t.Errorf("DependencyTimeout = %v, want %v", opts.DependencyTimeout, defaultDependencyTimeout)
|
|
}
|
|
if err := opts.validate(); err != nil {
|
|
t.Errorf("validate default loopback options: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestOptionsNonLoopbackRequiresToken(t *testing.T) {
|
|
opts := Options{
|
|
Gateway: ServiceTarget{Target: "192.168.1.50:8585"},
|
|
}
|
|
opts = withDefaults(opts)
|
|
if err := opts.validate(); err == nil {
|
|
t.Error("validate non-loopback gateway target with empty token want error, got nil")
|
|
}
|
|
|
|
opts.Gateway.Token = "secret"
|
|
if err := opts.validate(); err != nil {
|
|
t.Errorf("validate non-loopback gateway target with token: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestResolveWithConfigFile(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
cfgPath := filepath.Join(tmp, "config.toml")
|
|
content := `
|
|
bot_user = "testbot"
|
|
|
|
[services.gateway]
|
|
target = "127.0.0.1:8999"
|
|
target_token = "tok-123"
|
|
|
|
[chat.telegram]
|
|
token = { engine = "env", key = "TEST_TG_TOKEN" }
|
|
allowed_user_ids = [12345]
|
|
`
|
|
if err := os.WriteFile(cfgPath, []byte(content), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("TEST_TG_TOKEN", "resolved-tg-token")
|
|
|
|
resolved, err := Resolve(Options{Config: cfgPath}, slog.Default())
|
|
if err != nil {
|
|
t.Fatalf("Resolve: %v", err)
|
|
}
|
|
|
|
if resolved.Options.Gateway.Target != "127.0.0.1:8999" {
|
|
t.Errorf("Gateway.Target = %q, want 127.0.0.1:8999", resolved.Options.Gateway.Target)
|
|
}
|
|
if resolved.TelegramToken != "resolved-tg-token" {
|
|
t.Errorf("TelegramToken = %q, want resolved-tg-token", resolved.TelegramToken)
|
|
}
|
|
if len(resolved.Telegram.AllowedUserIDs) != 1 || resolved.Telegram.AllowedUserIDs[0] != 12345 {
|
|
t.Errorf("AllowedUserIDs = %v, want [12345]", resolved.Telegram.AllowedUserIDs)
|
|
}
|
|
}
|
|
|
|
func TestServiceStartAndStop(t *testing.T) {
|
|
d := deps{
|
|
Config: ResolvedConfig{
|
|
Options: withDefaults(Options{}),
|
|
},
|
|
Log: slog.Default(),
|
|
}
|
|
srv, err := compose(t.Context(), d)
|
|
if err != nil {
|
|
t.Fatalf("compose: %v", err)
|
|
}
|
|
|
|
ctx, cancel := contextWithTimeout(t, 200*time.Millisecond)
|
|
defer cancel()
|
|
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
errCh <- srv.Start(ctx)
|
|
}()
|
|
|
|
select {
|
|
case err := <-errCh:
|
|
if err != nil {
|
|
t.Fatalf("srv.Start: %v", err)
|
|
}
|
|
case <-time.After(1 * time.Second):
|
|
t.Fatal("srv.Start timed out waiting for context cancel")
|
|
}
|
|
|
|
srv.Stop()
|
|
}
|
|
|
|
func contextWithTimeout(t *testing.T, d time.Duration) (context.Context, context.CancelFunc) {
|
|
t.Helper()
|
|
return context.WithTimeout(context.Background(), d)
|
|
}
|