Add Seriatim normalize adapter support
This commit is contained in:
@@ -48,14 +48,37 @@ func (n *NoopRunner) Trim(ctx context.Context, req TrimRequest) (TrimResult, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Normalize returns the requested output path with placeholder metadata.
|
||||
func (n *NoopRunner) Normalize(ctx context.Context, req NormalizeRequest) (NormalizeResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return NormalizeResult{}, err
|
||||
}
|
||||
if err := materializeNormalizePlaceholders(req); err != nil {
|
||||
return NormalizeResult{}, err
|
||||
}
|
||||
return NormalizeResult{
|
||||
OutputNormalizedPath: req.OutputNormalizedPath,
|
||||
ReportPath: req.ReportPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
InvokedBinary: "noop",
|
||||
OutputSchema: req.OutputSchema,
|
||||
Metadata: map[string]any{"placeholder": true},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FakeRunner captures merge requests and returns deterministic responses.
|
||||
type FakeRunner struct {
|
||||
Requests []MergeRequest
|
||||
Err error
|
||||
Result MergeResult
|
||||
TrimRequests []TrimRequest
|
||||
TrimErr error
|
||||
TrimResult TrimResult
|
||||
Requests []MergeRequest
|
||||
Err error
|
||||
Result MergeResult
|
||||
NormalizeRequests []NormalizeRequest
|
||||
NormalizeErr error
|
||||
NormalizeResult NormalizeResult
|
||||
TrimRequests []TrimRequest
|
||||
TrimErr error
|
||||
TrimResult TrimResult
|
||||
}
|
||||
|
||||
// Run records request and returns configured response.
|
||||
@@ -132,6 +155,46 @@ func (f *FakeRunner) Trim(ctx context.Context, req TrimRequest) (TrimResult, err
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Normalize records request and returns configured response.
|
||||
func (f *FakeRunner) Normalize(ctx context.Context, req NormalizeRequest) (NormalizeResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return NormalizeResult{}, err
|
||||
}
|
||||
f.NormalizeRequests = append(f.NormalizeRequests, req)
|
||||
if f.NormalizeErr != nil {
|
||||
return NormalizeResult{}, f.NormalizeErr
|
||||
}
|
||||
if err := materializeNormalizePlaceholders(req); err != nil {
|
||||
return NormalizeResult{}, err
|
||||
}
|
||||
res := f.NormalizeResult
|
||||
if res.OutputNormalizedPath == "" {
|
||||
res.OutputNormalizedPath = req.OutputNormalizedPath
|
||||
}
|
||||
if res.ReportPath == "" {
|
||||
res.ReportPath = req.ReportPath
|
||||
}
|
||||
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.OutputSchema == "" {
|
||||
res.OutputSchema = req.OutputSchema
|
||||
}
|
||||
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 {
|
||||
@@ -198,3 +261,43 @@ func materializeTrimPlaceholders(req TrimRequest) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func materializeNormalizePlaceholders(req NormalizeRequest) error {
|
||||
if req.OutputNormalizedPath != "" {
|
||||
if err := subprocess.WriteFileAtomic(req.OutputNormalizedPath, []byte(`{"schema":"seriatim.intermediate.v1","segments":[]}`), 0o644); err != nil {
|
||||
return fmt.Errorf("write normalized transcript %q: %w", req.OutputNormalizedPath, err)
|
||||
}
|
||||
}
|
||||
if req.GeneratedConfigPath != "" {
|
||||
payload := map[string]any{
|
||||
"schema": "seriatim.generated.v1",
|
||||
"placeholder": true,
|
||||
"command": "normalize",
|
||||
"input_path": req.InputTranscriptPath,
|
||||
"output_path": req.OutputNormalizedPath,
|
||||
"output_schema": req.OutputSchema,
|
||||
}
|
||||
if req.ReportPath != "" {
|
||||
payload["report_path"] = req.ReportPath
|
||||
}
|
||||
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 normalize 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 normalize stderr placeholder\n"), 0o644); err != nil {
|
||||
return fmt.Errorf("write stderr log %q: %w", req.StderrLogPath, err)
|
||||
}
|
||||
}
|
||||
if req.ReportPath != "" {
|
||||
if err := subprocess.WriteFileAtomic(req.ReportPath, []byte(`{"schema":"seriatim.report.v1","placeholder":true}`), 0o644); err != nil {
|
||||
return fmt.Errorf("write report %q: %w", req.ReportPath, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user