Define adapter interfaces and fake implementations
This commit is contained in:
@@ -3,18 +3,20 @@ package whisperx
|
||||
|
||||
import "context"
|
||||
|
||||
// Client is a placeholder adapter interface for WhisperX interactions.
|
||||
// Client is the adapter boundary for WhisperX transcription jobs.
|
||||
type Client interface {
|
||||
Transcribe(ctx context.Context, req TranscriptionRequest) (TranscriptionResult, error)
|
||||
Transcribe(ctx context.Context, req TranscribeRequest) (TranscribeResult, error)
|
||||
}
|
||||
|
||||
// TranscriptionRequest is a placeholder transcription input.
|
||||
type TranscriptionRequest struct {
|
||||
Speaker string
|
||||
AudioPath string
|
||||
// TranscribeRequest describes one speaker audio transcription request.
|
||||
type TranscribeRequest struct {
|
||||
SpeakerID string
|
||||
AudioPath string
|
||||
OutputRawTranscriptPath string
|
||||
}
|
||||
|
||||
// TranscriptionResult is a placeholder transcription output.
|
||||
type TranscriptionResult struct {
|
||||
TranscriptPath string
|
||||
// TranscribeResult describes the transcript output and adapter metadata.
|
||||
type TranscribeResult struct {
|
||||
OutputRawTranscriptPath string
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
45
internal/adapters/whisperx/fake.go
Normal file
45
internal/adapters/whisperx/fake.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package whisperx
|
||||
|
||||
import "context"
|
||||
|
||||
// NoopClient is a deterministic no-op WhisperX adapter.
|
||||
type NoopClient struct{}
|
||||
|
||||
// Transcribe returns the requested output path with placeholder metadata.
|
||||
func (n *NoopClient) Transcribe(ctx context.Context, req TranscribeRequest) (TranscribeResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return TranscribeResult{}, err
|
||||
}
|
||||
return TranscribeResult{
|
||||
OutputRawTranscriptPath: req.OutputRawTranscriptPath,
|
||||
Metadata: map[string]any{
|
||||
"placeholder": true,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FakeClient captures requests and returns deterministic responses for tests.
|
||||
type FakeClient struct {
|
||||
Requests []TranscribeRequest
|
||||
Err error
|
||||
Result TranscribeResult
|
||||
}
|
||||
|
||||
// Transcribe records the request and returns either configured error or result.
|
||||
func (f *FakeClient) Transcribe(ctx context.Context, req TranscribeRequest) (TranscribeResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return TranscribeResult{}, err
|
||||
}
|
||||
f.Requests = append(f.Requests, req)
|
||||
if f.Err != nil {
|
||||
return TranscribeResult{}, f.Err
|
||||
}
|
||||
res := f.Result
|
||||
if res.OutputRawTranscriptPath == "" {
|
||||
res.OutputRawTranscriptPath = req.OutputRawTranscriptPath
|
||||
}
|
||||
if res.Metadata == nil {
|
||||
res.Metadata = map[string]any{"fake": true}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
31
internal/adapters/whisperx/fake_test.go
Normal file
31
internal/adapters/whisperx/fake_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package whisperx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFakeClientCapturesRequestAndReturnsPath(t *testing.T) {
|
||||
fake := &FakeClient{}
|
||||
req := TranscribeRequest{SpeakerID: "alice", AudioPath: "audio/alice.flac", OutputRawTranscriptPath: "transcripts/raw/alice.json"}
|
||||
|
||||
res, err := fake.Transcribe(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("Transcribe() error = %v", err)
|
||||
}
|
||||
if len(fake.Requests) != 1 || fake.Requests[0].SpeakerID != "alice" {
|
||||
t.Fatalf("requests = %#v, want one alice request", fake.Requests)
|
||||
}
|
||||
if res.OutputRawTranscriptPath != req.OutputRawTranscriptPath {
|
||||
t.Fatalf("output path = %q, want %q", res.OutputRawTranscriptPath, req.OutputRawTranscriptPath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFakeClientError(t *testing.T) {
|
||||
fake := &FakeClient{Err: errors.New("boom")}
|
||||
_, err := fake.Transcribe(context.Background(), TranscribeRequest{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user