Implement Audita subprocess adapter

This commit is contained in:
2026-05-04 07:56:35 -05:00
parent fbc53330ef
commit 28c7ab3287
4 changed files with 929 additions and 7 deletions

View File

@@ -2,7 +2,10 @@ package audita
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
)
@@ -18,7 +21,15 @@ func (n *NoopRunner) Run(ctx context.Context, req PolishRequest) (PolishResult,
if err := materializePlaceholders(req); err != nil {
return PolishResult{}, err
}
return PolishResult{ProcessedTranscriptPath: req.OutputProcessedPath, Metadata: map[string]any{"placeholder": true}}, nil
return PolishResult{
ProcessedTranscriptPath: req.OutputProcessedPath,
ReportPath: req.ReportPath,
WorkDir: req.WorkDir,
StdoutLogPath: req.StdoutLogPath,
StderrLogPath: req.StderrLogPath,
GeneratedConfigPath: req.GeneratedConfigPath,
Metadata: map[string]any{"placeholder": true},
}, nil
}
// FakeRunner captures polish requests and returns deterministic responses.
@@ -44,6 +55,21 @@ func (f *FakeRunner) Run(ctx context.Context, req PolishRequest) (PolishResult,
if res.ProcessedTranscriptPath == "" {
res.ProcessedTranscriptPath = req.OutputProcessedPath
}
if res.ReportPath == "" {
res.ReportPath = req.ReportPath
}
if res.WorkDir == "" {
res.WorkDir = req.WorkDir
}
if res.StdoutLogPath == "" {
res.StdoutLogPath = req.StdoutLogPath
}
if res.StderrLogPath == "" {
res.StderrLogPath = req.StderrLogPath
}
if res.GeneratedConfigPath == "" {
res.GeneratedConfigPath = req.GeneratedConfigPath
}
if res.Metadata == nil {
res.Metadata = map[string]any{"fake": true}
}
@@ -72,5 +98,34 @@ func materializePlaceholders(req PolishRequest) error {
return fmt.Errorf("write stderr log %q: %w", req.StderrLogPath, err)
}
}
if err := writeJSONIfRequested(req.OutputProcessedPath, map[string]any{
"schema": "audita.processed.v1",
"segments": []any{},
}); err != nil {
return err
}
if err := writeJSONIfRequested(req.ReportPath, map[string]any{
"schema": "audita.report.v1",
"steps": []any{},
}); err != nil {
return err
}
return nil
}
func writeJSONIfRequested(path string, payload any) error {
if path == "" {
return nil
}
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return fmt.Errorf("create parent directory %q: %w", filepath.Dir(path), err)
}
data, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("marshal placeholder json for %q: %w", path, err)
}
if err := subprocess.WriteFileAtomic(path, data, 0o644); err != nil {
return fmt.Errorf("write placeholder json %q: %w", path, err)
}
return nil
}