Define adapter interfaces and fake implementations

This commit is contained in:
2026-05-02 11:16:27 -05:00
parent 78e7e4f41b
commit 2854da48c2
24 changed files with 876 additions and 73 deletions

View File

@@ -0,0 +1,40 @@
package analyzer
import "context"
// NoopRunner is a deterministic no-op analyzer adapter.
type NoopRunner struct{}
// Run returns the requested output path with placeholder metadata.
func (n *NoopRunner) Run(ctx context.Context, req AnalyzeRequest) (AnalyzeResult, error) {
if err := ctx.Err(); err != nil {
return AnalyzeResult{}, err
}
return AnalyzeResult{ArtifactPath: req.OutputPath, Metadata: map[string]any{"placeholder": true}}, nil
}
// FakeRunner captures analyze requests and returns deterministic responses.
type FakeRunner struct {
Requests []AnalyzeRequest
Err error
Result AnalyzeResult
}
// Run records request and returns configured response.
func (f *FakeRunner) Run(ctx context.Context, req AnalyzeRequest) (AnalyzeResult, error) {
if err := ctx.Err(); err != nil {
return AnalyzeResult{}, err
}
f.Requests = append(f.Requests, req)
if f.Err != nil {
return AnalyzeResult{}, f.Err
}
res := f.Result
if res.ArtifactPath == "" {
res.ArtifactPath = req.OutputPath
}
if res.Metadata == nil {
res.Metadata = map[string]any{"fake": true}
}
return res, nil
}

View File

@@ -0,0 +1,31 @@
package analyzer
import (
"context"
"errors"
"testing"
)
func TestFakeRunnerCapturesRequestAndReturnsPath(t *testing.T) {
fake := &FakeRunner{}
req := AnalyzeRequest{ArtifactType: "session-log", OutputPath: "artifacts/session-log.md"}
res, err := fake.Run(context.Background(), req)
if err != nil {
t.Fatalf("Run() error = %v", err)
}
if len(fake.Requests) != 1 || fake.Requests[0].ArtifactType != "session-log" {
t.Fatalf("requests = %#v, want captured request", fake.Requests)
}
if res.ArtifactPath != req.OutputPath {
t.Fatalf("artifact path = %q, want %q", res.ArtifactPath, req.OutputPath)
}
}
func TestFakeRunnerError(t *testing.T) {
fake := &FakeRunner{Err: errors.New("boom")}
_, err := fake.Run(context.Background(), AnalyzeRequest{})
if err == nil {
t.Fatal("expected error, got nil")
}
}

View File

@@ -3,18 +3,24 @@ package analyzer
import "context"
// Runner is a placeholder adapter interface for session artifact generation.
// Runner is the adapter boundary for analyzer invocations.
type Runner interface {
Run(ctx context.Context, req AnalysisRequest) (AnalysisResult, error)
Run(ctx context.Context, req AnalyzeRequest) (AnalyzeResult, error)
}
// AnalysisRequest is a placeholder analyzer input.
type AnalysisRequest struct {
// AnalyzeRequest describes one analyzer artifact generation request.
type AnalyzeRequest struct {
ArtifactType string
ProcessedTranscriptPath string
OutputDir string
ContextReferences []string
OutputPath string
GeneratedConfigPath string
StdoutLogPath string
StderrLogPath string
}
// AnalysisResult is a placeholder analyzer output.
type AnalysisResult struct {
ArtifactPaths []string
// AnalyzeResult describes analyzer output.
type AnalyzeResult struct {
ArtifactPath string
Metadata map[string]any
}

View File

@@ -0,0 +1,40 @@
package audita
import "context"
// NoopRunner is a deterministic no-op audita adapter.
type NoopRunner struct{}
// Run returns requested output path with placeholder metadata.
func (n *NoopRunner) Run(ctx context.Context, req PolishRequest) (PolishResult, error) {
if err := ctx.Err(); err != nil {
return PolishResult{}, err
}
return PolishResult{ProcessedTranscriptPath: req.OutputProcessedPath, Metadata: map[string]any{"placeholder": true}}, nil
}
// FakeRunner captures polish requests and returns deterministic responses.
type FakeRunner struct {
Requests []PolishRequest
Err error
Result PolishResult
}
// Run records request and returns configured response.
func (f *FakeRunner) Run(ctx context.Context, req PolishRequest) (PolishResult, error) {
if err := ctx.Err(); err != nil {
return PolishResult{}, err
}
f.Requests = append(f.Requests, req)
if f.Err != nil {
return PolishResult{}, f.Err
}
res := f.Result
if res.ProcessedTranscriptPath == "" {
res.ProcessedTranscriptPath = req.OutputProcessedPath
}
if res.Metadata == nil {
res.Metadata = map[string]any{"fake": true}
}
return res, nil
}

View File

@@ -0,0 +1,31 @@
package audita
import (
"context"
"errors"
"testing"
)
func TestFakeRunnerCapturesRequestAndReturnsPath(t *testing.T) {
fake := &FakeRunner{}
req := PolishRequest{GeneratedConfigPath: "config/audita.yml", OutputProcessedPath: "transcripts/processed.json"}
res, err := fake.Run(context.Background(), req)
if err != nil {
t.Fatalf("Run() error = %v", err)
}
if len(fake.Requests) != 1 || fake.Requests[0].GeneratedConfigPath == "" {
t.Fatalf("requests = %#v, want captured request", fake.Requests)
}
if res.ProcessedTranscriptPath != req.OutputProcessedPath {
t.Fatalf("processed path = %q, want %q", res.ProcessedTranscriptPath, req.OutputProcessedPath)
}
}
func TestFakeRunnerError(t *testing.T) {
fake := &FakeRunner{Err: errors.New("boom")}
_, err := fake.Run(context.Background(), PolishRequest{})
if err == nil {
t.Fatal("expected error, got nil")
}
}

View File

@@ -3,18 +3,22 @@ package audita
import "context"
// Runner is a placeholder adapter interface for audita invocation.
// Runner is the adapter boundary for audita polish invocations.
type Runner interface {
Run(ctx context.Context, req PolishRequest) (PolishResult, error)
}
// PolishRequest is a placeholder polish input.
// PolishRequest describes an audita invocation.
type PolishRequest struct {
GeneratedConfigPath string
MergedTranscriptPath string
OutputPath string
OutputProcessedPath string
StdoutLogPath string
StderrLogPath string
}
// PolishResult is a placeholder polish output.
// PolishResult describes a polish output.
type PolishResult struct {
ProcessedPath string
ProcessedTranscriptPath string
Metadata map[string]any
}

View File

@@ -0,0 +1,40 @@
package notify
import "context"
// NoopSender is a deterministic no-op notifier.
type NoopSender struct{}
// Send returns a placeholder successful result.
func (n *NoopSender) Send(ctx context.Context, _ SendRequest) (SendResult, error) {
if err := ctx.Err(); err != nil {
return SendResult{}, err
}
return SendResult{ProviderMessageID: "noop", Metadata: map[string]any{"placeholder": true}}, nil
}
// FakeSender captures send requests and returns deterministic responses.
type FakeSender struct {
Requests []SendRequest
Err error
Result SendResult
}
// Send records request and returns configured response.
func (f *FakeSender) Send(ctx context.Context, req SendRequest) (SendResult, error) {
if err := ctx.Err(); err != nil {
return SendResult{}, err
}
f.Requests = append(f.Requests, req)
if f.Err != nil {
return SendResult{}, f.Err
}
res := f.Result
if res.ProviderMessageID == "" {
res.ProviderMessageID = "fake"
}
if res.Metadata == nil {
res.Metadata = map[string]any{"fake": true}
}
return res, nil
}

View File

@@ -0,0 +1,31 @@
package notify
import (
"context"
"errors"
"testing"
)
func TestFakeSenderCapturesRequestAndReturnsResult(t *testing.T) {
fake := &FakeSender{}
req := SendRequest{Subject: "done", Body: "body"}
res, err := fake.Send(context.Background(), req)
if err != nil {
t.Fatalf("Send() error = %v", err)
}
if len(fake.Requests) != 1 || fake.Requests[0].Subject != "done" {
t.Fatalf("requests = %#v, want captured request", fake.Requests)
}
if res.ProviderMessageID == "" {
t.Fatal("provider message id should be set")
}
}
func TestFakeSenderError(t *testing.T) {
fake := &FakeSender{Err: errors.New("boom")}
_, err := fake.Send(context.Background(), SendRequest{})
if err == nil {
t.Fatal("expected error, got nil")
}
}

View File

@@ -3,13 +3,20 @@ package notify
import "context"
// Sender is a placeholder adapter interface for notifications.
// Sender is the adapter boundary for notifications.
type Sender interface {
Send(ctx context.Context, msg Message) error
Send(ctx context.Context, req SendRequest) (SendResult, error)
}
// Message is a placeholder notification payload.
type Message struct {
Subject string
Body string
// SendRequest describes one notification request.
type SendRequest struct {
Subject string
Body string
Metadata map[string]string
}
// SendResult describes notification send outcome metadata.
type SendResult struct {
ProviderMessageID string
Metadata map[string]any
}

View File

@@ -0,0 +1,40 @@
package seriatim
import "context"
// NoopRunner is a deterministic no-op seriatim adapter.
type NoopRunner struct{}
// Run returns the requested output path with placeholder metadata.
func (n *NoopRunner) Run(ctx context.Context, req MergeRequest) (MergeResult, error) {
if err := ctx.Err(); err != nil {
return MergeResult{}, err
}
return MergeResult{MergedTranscriptPath: req.OutputMergedTranscriptPath, Metadata: map[string]any{"placeholder": true}}, nil
}
// FakeRunner captures merge requests and returns deterministic responses.
type FakeRunner struct {
Requests []MergeRequest
Err error
Result MergeResult
}
// Run records request and returns configured response.
func (f *FakeRunner) Run(ctx context.Context, req MergeRequest) (MergeResult, error) {
if err := ctx.Err(); err != nil {
return MergeResult{}, err
}
f.Requests = append(f.Requests, req)
if f.Err != nil {
return MergeResult{}, f.Err
}
res := f.Result
if res.MergedTranscriptPath == "" {
res.MergedTranscriptPath = req.OutputMergedTranscriptPath
}
if res.Metadata == nil {
res.Metadata = map[string]any{"fake": true}
}
return res, nil
}

View File

@@ -0,0 +1,31 @@
package seriatim
import (
"context"
"errors"
"testing"
)
func TestFakeRunnerCapturesRequestAndReturnsPath(t *testing.T) {
fake := &FakeRunner{}
req := MergeRequest{GeneratedConfigPath: "config/seriatim.yml", OutputMergedTranscriptPath: "transcripts/merged.json"}
res, err := fake.Run(context.Background(), req)
if err != nil {
t.Fatalf("Run() error = %v", err)
}
if len(fake.Requests) != 1 || fake.Requests[0].GeneratedConfigPath == "" {
t.Fatalf("requests = %#v, want captured request", fake.Requests)
}
if res.MergedTranscriptPath != req.OutputMergedTranscriptPath {
t.Fatalf("merged path = %q, want %q", res.MergedTranscriptPath, req.OutputMergedTranscriptPath)
}
}
func TestFakeRunnerError(t *testing.T) {
fake := &FakeRunner{Err: errors.New("boom")}
_, err := fake.Run(context.Background(), MergeRequest{})
if err == nil {
t.Fatal("expected error, got nil")
}
}

View File

@@ -3,18 +3,22 @@ package seriatim
import "context"
// Runner is a placeholder adapter interface for seriatim invocation.
// Runner is the adapter boundary for seriatim merge invocations.
type Runner interface {
Run(ctx context.Context, req MergeRequest) (MergeResult, error)
}
// MergeRequest is a placeholder merge input.
// MergeRequest describes a seriatim merge invocation.
type MergeRequest struct {
TranscriptPaths []string
OutputPath string
GeneratedConfigPath string
InputTranscriptPaths []string
OutputMergedTranscriptPath string
StdoutLogPath string
StderrLogPath string
}
// MergeResult is a placeholder merge output.
// MergeResult describes a merge output.
type MergeResult struct {
MergedPath string
MergedTranscriptPath string
Metadata map[string]any
}

View File

@@ -0,0 +1,29 @@
// Package storage declares archive/storage backend adapter boundaries.
package storage
import "context"
// Backend is the adapter boundary for archive/storage operations.
type Backend interface {
Archive(ctx context.Context, req ArchiveRequest) (ArchiveResult, error)
}
// ArchiveItem describes one item to archive.
type ArchiveItem struct {
Kind string
LocalPath string
RemoteKey string
}
// ArchiveRequest describes one archive operation.
type ArchiveRequest struct {
SessionID string
ManifestPath string
Items []ArchiveItem
}
// ArchiveResult describes archive operation output.
type ArchiveResult struct {
Archived []ArchiveItem
Metadata map[string]any
}

View File

@@ -0,0 +1,40 @@
package storage
import "context"
// NoopBackend is a deterministic no-op archive/storage adapter.
type NoopBackend struct{}
// Archive returns the requested items as archived with placeholder metadata.
func (n *NoopBackend) Archive(ctx context.Context, req ArchiveRequest) (ArchiveResult, error) {
if err := ctx.Err(); err != nil {
return ArchiveResult{}, err
}
return ArchiveResult{Archived: append([]ArchiveItem(nil), req.Items...), Metadata: map[string]any{"placeholder": true}}, nil
}
// FakeBackend captures archive requests and returns deterministic responses.
type FakeBackend struct {
Requests []ArchiveRequest
Err error
Result ArchiveResult
}
// Archive records request and returns configured response.
func (f *FakeBackend) Archive(ctx context.Context, req ArchiveRequest) (ArchiveResult, error) {
if err := ctx.Err(); err != nil {
return ArchiveResult{}, err
}
f.Requests = append(f.Requests, req)
if f.Err != nil {
return ArchiveResult{}, f.Err
}
res := f.Result
if res.Archived == nil {
res.Archived = append([]ArchiveItem(nil), req.Items...)
}
if res.Metadata == nil {
res.Metadata = map[string]any{"fake": true}
}
return res, nil
}

View File

@@ -0,0 +1,31 @@
package storage
import (
"context"
"errors"
"testing"
)
func TestFakeBackendCapturesRequestAndReturnsItems(t *testing.T) {
fake := &FakeBackend{}
req := ArchiveRequest{SessionID: "s1", Items: []ArchiveItem{{Kind: "artifact", LocalPath: "artifacts/log.md"}}}
res, err := fake.Archive(context.Background(), req)
if err != nil {
t.Fatalf("Archive() error = %v", err)
}
if len(fake.Requests) != 1 || fake.Requests[0].SessionID != "s1" {
t.Fatalf("requests = %#v, want captured request", fake.Requests)
}
if len(res.Archived) != 1 {
t.Fatalf("archived len = %d, want 1", len(res.Archived))
}
}
func TestFakeBackendError(t *testing.T) {
fake := &FakeBackend{Err: errors.New("boom")}
_, err := fake.Archive(context.Background(), ArchiveRequest{})
if err == nil {
t.Fatal("expected error, got nil")
}
}

View File

@@ -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
}

View 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
}

View 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")
}
}