Add subprocess runner and generated config helpers

This commit is contained in:
2026-05-02 11:32:33 -05:00
parent 1f9d8d0ef7
commit 77f421feef
7 changed files with 545 additions and 4 deletions

View File

@@ -1,6 +1,11 @@
package seriatim
import "context"
import (
"context"
"fmt"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
)
// NoopRunner is a deterministic no-op seriatim adapter.
type NoopRunner struct{}
@@ -10,6 +15,9 @@ func (n *NoopRunner) Run(ctx context.Context, req MergeRequest) (MergeResult, er
if err := ctx.Err(); err != nil {
return MergeResult{}, err
}
if err := materializePlaceholders(req); err != nil {
return MergeResult{}, err
}
return MergeResult{MergedTranscriptPath: req.OutputMergedTranscriptPath, Metadata: map[string]any{"placeholder": true}}, nil
}
@@ -29,6 +37,9 @@ func (f *FakeRunner) Run(ctx context.Context, req MergeRequest) (MergeResult, er
if f.Err != nil {
return MergeResult{}, f.Err
}
if err := materializePlaceholders(req); err != nil {
return MergeResult{}, err
}
res := f.Result
if res.MergedTranscriptPath == "" {
res.MergedTranscriptPath = req.OutputMergedTranscriptPath
@@ -38,3 +49,28 @@ func (f *FakeRunner) Run(ctx context.Context, req MergeRequest) (MergeResult, er
}
return res, nil
}
func materializePlaceholders(req MergeRequest) error {
if req.GeneratedConfigPath != "" {
payload := map[string]any{
"schema": "seriatim.generated.v1",
"placeholder": true,
"input_transcript_paths": req.InputTranscriptPaths,
"output_path": req.OutputMergedTranscriptPath,
}
if err := subprocess.WriteYAMLAtomic(req.GeneratedConfigPath, payload, 0o644); err != nil {
return fmt.Errorf("write generated config %q: %w", req.GeneratedConfigPath, err)
}
}
if req.StdoutLogPath != "" {
if err := subprocess.WriteFileAtomic(req.StdoutLogPath, []byte("seriatim noop/fake stdout placeholder\n"), 0o644); err != nil {
return fmt.Errorf("write stdout log %q: %w", req.StdoutLogPath, err)
}
}
if req.StderrLogPath != "" {
if err := subprocess.WriteFileAtomic(req.StderrLogPath, []byte("seriatim noop/fake stderr placeholder\n"), 0o644); err != nil {
return fmt.Errorf("write stderr log %q: %w", req.StderrLogPath, err)
}
}
return nil
}

View File

@@ -3,12 +3,21 @@ package seriatim
import (
"context"
"errors"
"os"
"path/filepath"
"strings"
"testing"
)
func TestFakeRunnerCapturesRequestAndReturnsPath(t *testing.T) {
fake := &FakeRunner{}
req := MergeRequest{GeneratedConfigPath: "config/seriatim.yml", OutputMergedTranscriptPath: "transcripts/merged.json"}
dir := t.TempDir()
req := MergeRequest{
GeneratedConfigPath: filepath.Join(dir, "config", "seriatim.yml"),
OutputMergedTranscriptPath: filepath.Join(dir, "transcripts", "merged.json"),
StdoutLogPath: filepath.Join(dir, "logs", "seriatim.stdout.log"),
StderrLogPath: filepath.Join(dir, "logs", "seriatim.stderr.log"),
}
res, err := fake.Run(context.Background(), req)
if err != nil {
@@ -20,6 +29,19 @@ func TestFakeRunnerCapturesRequestAndReturnsPath(t *testing.T) {
if res.MergedTranscriptPath != req.OutputMergedTranscriptPath {
t.Fatalf("merged path = %q, want %q", res.MergedTranscriptPath, req.OutputMergedTranscriptPath)
}
cfgData, err := os.ReadFile(req.GeneratedConfigPath)
if err != nil {
t.Fatalf("read generated config: %v", err)
}
if !strings.Contains(string(cfgData), "placeholder: true") {
t.Fatalf("generated config = %q, want placeholder marker", string(cfgData))
}
for _, logPath := range []string{req.StdoutLogPath, req.StderrLogPath} {
if _, err := os.Stat(logPath); err != nil {
t.Fatalf("expected log file %q to exist: %v", logPath, err)
}
}
}
func TestFakeRunnerError(t *testing.T) {