77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package audita
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
|
|
)
|
|
|
|
// 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
|
|
}
|
|
if err := materializePlaceholders(req); 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
|
|
}
|
|
if err := materializePlaceholders(req); err != nil {
|
|
return PolishResult{}, 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
|
|
}
|
|
|
|
func materializePlaceholders(req PolishRequest) error {
|
|
if req.GeneratedConfigPath != "" {
|
|
payload := map[string]any{
|
|
"schema": "audita.generated.v1",
|
|
"placeholder": true,
|
|
"merged_transcript_path": req.MergedTranscriptPath,
|
|
"output_path": req.OutputProcessedPath,
|
|
}
|
|
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("audita 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("audita noop/fake stderr placeholder\n"), 0o644); err != nil {
|
|
return fmt.Errorf("write stderr log %q: %w", req.StderrLogPath, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|