Define adapter interfaces and fake implementations
This commit is contained in:
@@ -3,7 +3,14 @@ package stage
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/analyzer"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/notify"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/seriatim"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/whisperx"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
@@ -23,14 +30,134 @@ func (s placeholderStage) Declares() IODecl {
|
||||
}
|
||||
}
|
||||
|
||||
func (s placeholderStage) Run(_ context.Context, _ *Env, _ *manifest.Manifest) (*StageResult, error) {
|
||||
return &StageResult{
|
||||
func (s placeholderStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*StageResult, error) {
|
||||
result := &StageResult{
|
||||
Metadata: map[string]any{
|
||||
"placeholder": true,
|
||||
"stage": s.name,
|
||||
"message": placeholderMessage,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
if env == nil || env.Config == nil || env.ArtifactStore == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
sessionID := m.SessionID
|
||||
if sessionID == "" && env.Config.Session != nil {
|
||||
sessionID = env.Config.Session.SessionID
|
||||
}
|
||||
if sessionID == "" {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
paths := env.ArtifactStore.SessionPaths(sessionID)
|
||||
|
||||
switch s.name {
|
||||
case "transcribe":
|
||||
if env.WhisperX != nil {
|
||||
req := whisperx.TranscribeRequest{
|
||||
SpeakerID: "placeholder-speaker",
|
||||
AudioPath: filepath.Join(paths.AudioDir, "placeholder-speaker.flac"),
|
||||
OutputRawTranscriptPath: filepath.Join(paths.TranscriptsRawDir, "placeholder-speaker.json"),
|
||||
}
|
||||
resp, err := env.WhisperX.Transcribe(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("placeholder transcribe adapter call failed: %w", err)
|
||||
}
|
||||
result.Outputs = append(result.Outputs, artifacts.Ref{
|
||||
Kind: "transcript_raw",
|
||||
Category: "transcripts",
|
||||
SessionID: sessionID,
|
||||
AbsolutePath: resp.OutputRawTranscriptPath,
|
||||
})
|
||||
}
|
||||
case "merge":
|
||||
if env.Seriatim != nil {
|
||||
req := seriatim.MergeRequest{
|
||||
GeneratedConfigPath: filepath.Join(paths.ConfigDir, "seriatim.generated.yml"),
|
||||
InputTranscriptPaths: []string{filepath.Join(paths.TranscriptsNormalizedDir, "placeholder-speaker.json")},
|
||||
OutputMergedTranscriptPath: filepath.Join(paths.TranscriptsDir, "merged.json"),
|
||||
StdoutLogPath: filepath.Join(paths.LogsDir, "seriatim.stdout.log"),
|
||||
StderrLogPath: filepath.Join(paths.LogsDir, "seriatim.stderr.log"),
|
||||
}
|
||||
resp, err := env.Seriatim.Run(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("placeholder merge adapter call failed: %w", err)
|
||||
}
|
||||
result.Outputs = append(result.Outputs, artifacts.Ref{Kind: "transcript_merged", Category: "transcripts", SessionID: sessionID, AbsolutePath: resp.MergedTranscriptPath})
|
||||
result.Logs = append(result.Logs, req.StdoutLogPath, req.StderrLogPath)
|
||||
result.GeneratedConfigs = append(result.GeneratedConfigs, req.GeneratedConfigPath)
|
||||
}
|
||||
case "polish":
|
||||
if env.Audita != nil {
|
||||
req := audita.PolishRequest{
|
||||
GeneratedConfigPath: filepath.Join(paths.ConfigDir, "audita.generated.yml"),
|
||||
MergedTranscriptPath: filepath.Join(paths.TranscriptsDir, "merged.json"),
|
||||
OutputProcessedPath: filepath.Join(paths.TranscriptsDir, "processed.json"),
|
||||
StdoutLogPath: filepath.Join(paths.LogsDir, "audita.stdout.log"),
|
||||
StderrLogPath: filepath.Join(paths.LogsDir, "audita.stderr.log"),
|
||||
}
|
||||
resp, err := env.Audita.Run(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("placeholder polish adapter call failed: %w", err)
|
||||
}
|
||||
result.Outputs = append(result.Outputs, artifacts.Ref{Kind: "transcript_processed", Category: "transcripts", SessionID: sessionID, AbsolutePath: resp.ProcessedTranscriptPath})
|
||||
result.Logs = append(result.Logs, req.StdoutLogPath, req.StderrLogPath)
|
||||
result.GeneratedConfigs = append(result.GeneratedConfigs, req.GeneratedConfigPath)
|
||||
}
|
||||
case "analyze":
|
||||
if env.Analyzer != nil {
|
||||
req := analyzer.AnalyzeRequest{
|
||||
ArtifactType: "session-log",
|
||||
ProcessedTranscriptPath: filepath.Join(paths.TranscriptsDir, "processed.json"),
|
||||
ContextReferences: []string{"previous-session"},
|
||||
OutputPath: filepath.Join(paths.ArtifactsDir, "session-log.md"),
|
||||
GeneratedConfigPath: filepath.Join(paths.ConfigDir, "analyzer.session-log.generated.yml"),
|
||||
StdoutLogPath: filepath.Join(paths.LogsDir, "analyzer.session-log.stdout.log"),
|
||||
StderrLogPath: filepath.Join(paths.LogsDir, "analyzer.session-log.stderr.log"),
|
||||
}
|
||||
resp, err := env.Analyzer.Run(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("placeholder analyze adapter call failed: %w", err)
|
||||
}
|
||||
result.Outputs = append(result.Outputs, artifacts.Ref{Kind: "artifact", Category: "artifacts", SessionID: sessionID, AbsolutePath: resp.ArtifactPath})
|
||||
result.Logs = append(result.Logs, req.StdoutLogPath, req.StderrLogPath)
|
||||
result.GeneratedConfigs = append(result.GeneratedConfigs, req.GeneratedConfigPath)
|
||||
}
|
||||
case "archive":
|
||||
if env.Storage != nil {
|
||||
req := storage.ArchiveRequest{
|
||||
SessionID: sessionID,
|
||||
ManifestPath: paths.ManifestPath,
|
||||
Items: []storage.ArchiveItem{{
|
||||
Kind: "artifact",
|
||||
LocalPath: filepath.Join(paths.ArtifactsDir, "session-log.md"),
|
||||
RemoteKey: "sessions/" + sessionID + "/artifacts/session-log.md",
|
||||
}},
|
||||
}
|
||||
_, err := env.Storage.Archive(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("placeholder archive adapter call failed: %w", err)
|
||||
}
|
||||
}
|
||||
case "notify":
|
||||
if env.Notifier != nil {
|
||||
req := notify.SendRequest{
|
||||
Subject: "narratio placeholder run complete",
|
||||
Body: "placeholder stage execution finished",
|
||||
Metadata: map[string]string{
|
||||
"session_id": sessionID,
|
||||
},
|
||||
}
|
||||
_, err := env.Notifier.Send(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("placeholder notify adapter call failed: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// All returns the canonical ordered stage list for full pipeline execution.
|
||||
|
||||
@@ -2,9 +2,19 @@ package stage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/analyzer"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/notify"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/seriatim"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/whisperx"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
@@ -14,9 +24,34 @@ func TestPlaceholderStagesReturnSuccessMetadata(t *testing.T) {
|
||||
t.Fatal("expected non-empty stage list")
|
||||
}
|
||||
|
||||
root := t.TempDir()
|
||||
store := artifacts.NewLocalStore(root)
|
||||
_, err := store.EnsureLayout("2026-05-03")
|
||||
if err != nil {
|
||||
t.Fatalf("EnsureLayout() error = %v", err)
|
||||
}
|
||||
|
||||
wf := &whisperx.FakeClient{}
|
||||
sf := &seriatim.FakeRunner{}
|
||||
af := &audita.FakeRunner{}
|
||||
anz := &analyzer.FakeRunner{}
|
||||
st := &storage.FakeBackend{}
|
||||
nf := ¬ify.FakeSender{}
|
||||
|
||||
env := &Env{
|
||||
Config: &config.Config{Session: &config.SessionConfig{SessionID: "2026-05-03"}},
|
||||
ArtifactStore: store,
|
||||
WhisperX: wf,
|
||||
Seriatim: sf,
|
||||
Audita: af,
|
||||
Analyzer: anz,
|
||||
Storage: st,
|
||||
Notifier: nf,
|
||||
}
|
||||
|
||||
m := manifest.New("2026-05-03", time.Now().UTC())
|
||||
for _, s := range stages {
|
||||
result, err := s.Run(context.Background(), nil, m)
|
||||
result, err := s.Run(context.Background(), env, m)
|
||||
if err != nil {
|
||||
t.Fatalf("stage %q returned unexpected error: %v", s.Name(), err)
|
||||
}
|
||||
@@ -27,4 +62,65 @@ func TestPlaceholderStagesReturnSuccessMetadata(t *testing.T) {
|
||||
t.Fatalf("stage %q missing placeholder metadata", s.Name())
|
||||
}
|
||||
}
|
||||
|
||||
if len(wf.Requests) != 1 {
|
||||
t.Fatalf("whisperx calls = %d, want 1", len(wf.Requests))
|
||||
}
|
||||
if len(sf.Requests) != 1 {
|
||||
t.Fatalf("seriatim calls = %d, want 1", len(sf.Requests))
|
||||
}
|
||||
if len(af.Requests) != 1 {
|
||||
t.Fatalf("audita calls = %d, want 1", len(af.Requests))
|
||||
}
|
||||
if len(anz.Requests) != 1 {
|
||||
t.Fatalf("analyzer calls = %d, want 1", len(anz.Requests))
|
||||
}
|
||||
if len(st.Requests) != 1 {
|
||||
t.Fatalf("storage calls = %d, want 1", len(st.Requests))
|
||||
}
|
||||
if len(nf.Requests) != 1 {
|
||||
t.Fatalf("notify calls = %d, want 1", len(nf.Requests))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaceholderAdapterErrorPropagation(t *testing.T) {
|
||||
cases := []struct {
|
||||
stageName string
|
||||
env *Env
|
||||
wantErr string
|
||||
}{
|
||||
{stageName: "transcribe", env: &Env{WhisperX: &whisperx.FakeClient{Err: errors.New("werr")}}, wantErr: "transcribe"},
|
||||
{stageName: "merge", env: &Env{Seriatim: &seriatim.FakeRunner{Err: errors.New("serr")}}, wantErr: "merge"},
|
||||
{stageName: "polish", env: &Env{Audita: &audita.FakeRunner{Err: errors.New("aerr")}}, wantErr: "polish"},
|
||||
{stageName: "analyze", env: &Env{Analyzer: &analyzer.FakeRunner{Err: errors.New("anerr")}}, wantErr: "analyze"},
|
||||
{stageName: "archive", env: &Env{Storage: &storage.FakeBackend{Err: errors.New("sterr")}}, wantErr: "archive"},
|
||||
{stageName: "notify", env: &Env{Notifier: ¬ify.FakeSender{Err: errors.New("nerr")}}, wantErr: "notify"},
|
||||
}
|
||||
|
||||
root := t.TempDir()
|
||||
store := artifacts.NewLocalStore(root)
|
||||
_, err := store.EnsureLayout("2026-05-03")
|
||||
if err != nil {
|
||||
t.Fatalf("EnsureLayout() error = %v", err)
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.stageName, func(t *testing.T) {
|
||||
s, selErr := Select(tc.stageName)
|
||||
if selErr != nil {
|
||||
t.Fatalf("Select() error = %v", selErr)
|
||||
}
|
||||
|
||||
tc.env.Config = &config.Config{Session: &config.SessionConfig{SessionID: "2026-05-03"}}
|
||||
tc.env.ArtifactStore = store
|
||||
|
||||
_, runErr := s.Run(context.Background(), tc.env, manifest.New("2026-05-03", time.Now().UTC()))
|
||||
if runErr == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
if !strings.Contains(runErr.Error(), tc.wantErr) {
|
||||
t.Fatalf("error = %q, want to contain %q", runErr.Error(), tc.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/notify"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/seriatim"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/whisperx"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
@@ -18,12 +19,14 @@ import (
|
||||
type Env struct {
|
||||
Config *config.Config
|
||||
ArtifactStore artifacts.Store
|
||||
ManifestStore manifest.Store
|
||||
Logger *slog.Logger
|
||||
|
||||
WhisperX whisperx.Client
|
||||
Seriatim seriatim.Runner
|
||||
Audita audita.Runner
|
||||
Analyzer analyzer.Runner
|
||||
Storage storage.Backend
|
||||
Notifier notify.Sender
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user