Add Seriatim trim adapter support
This commit is contained in:
@@ -29,11 +29,33 @@ func (n *NoopRunner) Run(ctx context.Context, req MergeRequest) (MergeResult, er
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Trim returns the requested output path with placeholder metadata.
|
||||
func (n *NoopRunner) Trim(ctx context.Context, req TrimRequest) (TrimResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return TrimResult{}, err
|
||||
}
|
||||
if err := materializeTrimPlaceholders(req); err != nil {
|
||||
return TrimResult{}, err
|
||||
}
|
||||
return TrimResult{
|
||||
OutputTrimmedPath: req.OutputTrimmedPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
InvokedBinary: "noop",
|
||||
KeepSelector: req.KeepSelector,
|
||||
Metadata: map[string]any{"placeholder": true},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FakeRunner captures merge requests and returns deterministic responses.
|
||||
type FakeRunner struct {
|
||||
Requests []MergeRequest
|
||||
Err error
|
||||
Result MergeResult
|
||||
Requests []MergeRequest
|
||||
Err error
|
||||
Result MergeResult
|
||||
TrimRequests []TrimRequest
|
||||
TrimErr error
|
||||
TrimResult TrimResult
|
||||
}
|
||||
|
||||
// Run records request and returns configured response.
|
||||
@@ -73,6 +95,43 @@ func (f *FakeRunner) Run(ctx context.Context, req MergeRequest) (MergeResult, er
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Trim records request and returns configured response.
|
||||
func (f *FakeRunner) Trim(ctx context.Context, req TrimRequest) (TrimResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return TrimResult{}, err
|
||||
}
|
||||
f.TrimRequests = append(f.TrimRequests, req)
|
||||
if f.TrimErr != nil {
|
||||
return TrimResult{}, f.TrimErr
|
||||
}
|
||||
if err := materializeTrimPlaceholders(req); err != nil {
|
||||
return TrimResult{}, err
|
||||
}
|
||||
res := f.TrimResult
|
||||
if res.OutputTrimmedPath == "" {
|
||||
res.OutputTrimmedPath = req.OutputTrimmedPath
|
||||
}
|
||||
if res.StdoutLogPath == "" {
|
||||
res.StdoutLogPath = req.StdoutLogPath
|
||||
}
|
||||
if res.StderrLogPath == "" {
|
||||
res.StderrLogPath = req.StderrLogPath
|
||||
}
|
||||
if res.GeneratedConfigPath == "" {
|
||||
res.GeneratedConfigPath = req.GeneratedConfigPath
|
||||
}
|
||||
if res.InvokedBinary == "" {
|
||||
res.InvokedBinary = "fake"
|
||||
}
|
||||
if res.KeepSelector == "" {
|
||||
res.KeepSelector = req.KeepSelector
|
||||
}
|
||||
if res.Metadata == nil {
|
||||
res.Metadata = map[string]any{"fake": true}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func materializePlaceholders(req MergeRequest) error {
|
||||
if req.OutputMergedTranscriptPath != "" {
|
||||
if err := subprocess.WriteFileAtomic(req.OutputMergedTranscriptPath, []byte(`{"schema":"seriatim.intermediate.v1","segments":[]}`), 0o644); err != nil {
|
||||
@@ -107,3 +166,35 @@ func materializePlaceholders(req MergeRequest) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func materializeTrimPlaceholders(req TrimRequest) error {
|
||||
if req.OutputTrimmedPath != "" {
|
||||
if err := subprocess.WriteFileAtomic(req.OutputTrimmedPath, []byte(`{"schema":"seriatim.intermediate.v1","segments":[]}`), 0o644); err != nil {
|
||||
return fmt.Errorf("write trimmed transcript %q: %w", req.OutputTrimmedPath, err)
|
||||
}
|
||||
}
|
||||
if req.GeneratedConfigPath != "" {
|
||||
payload := map[string]any{
|
||||
"schema": "seriatim.generated.v1",
|
||||
"placeholder": true,
|
||||
"command": "trim",
|
||||
"input_path": req.InputTranscriptPath,
|
||||
"output_path": req.OutputTrimmedPath,
|
||||
"keep_selector": req.KeepSelector,
|
||||
}
|
||||
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 trim 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 trim stderr placeholder\n"), 0o644); err != nil {
|
||||
return fmt.Errorf("write stderr log %q: %w", req.StderrLogPath, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user