Clean up MVP output handling
This commit is contained in:
@@ -193,7 +193,11 @@ func (output integrationOutput) Key() string {
|
||||
}
|
||||
|
||||
func (output integrationOutput) Encode(ctx context.Context, req contracts.OutputRequest) (contracts.OutputResult, error) {
|
||||
return contracts.OutputResult{Bytes: []byte(`{}`), ContentType: "application/json"}, nil
|
||||
return contracts.OutputResult{
|
||||
Files: []contracts.OutputFile{
|
||||
{Name: "output.json", ContentType: "application/json", Bytes: []byte(`{}`)},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
type integrationValidator struct {
|
||||
|
||||
@@ -49,10 +49,6 @@ type RunOutput struct {
|
||||
Rejected []artifacts.RejectedArtifact `json:"rejected,omitempty"`
|
||||
Warnings []contracts.Warning `json:"warnings,omitempty"`
|
||||
OutputFiles []contracts.OutputFile `json:"-"`
|
||||
// EncodedOutput is the legacy single-output payload. New callers should use OutputFiles.
|
||||
EncodedOutput []byte `json:"-"`
|
||||
// ContentType is the legacy single-output content type. New callers should use OutputFiles.
|
||||
ContentType string `json:"content_type,omitempty"`
|
||||
}
|
||||
|
||||
func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
||||
@@ -143,10 +139,6 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
||||
return failOutput(output), fmt.Errorf("validate output files from encoder %q: %w", encoder.Key(), err)
|
||||
}
|
||||
output.OutputFiles = files
|
||||
if len(encoded.Files) == 0 {
|
||||
output.EncodedOutput = append([]byte(nil), encoded.Bytes...)
|
||||
output.ContentType = encoded.ContentType
|
||||
}
|
||||
|
||||
return output, nil
|
||||
}
|
||||
@@ -425,19 +417,8 @@ func manifestMetadataKey(module any) string {
|
||||
}
|
||||
|
||||
func outputFilesFromResult(result contracts.OutputResult) ([]contracts.OutputFile, error) {
|
||||
files := result.Files
|
||||
if len(files) == 0 && len(result.Bytes) > 0 {
|
||||
files = []contracts.OutputFile{
|
||||
{
|
||||
Name: "output",
|
||||
ContentType: result.ContentType,
|
||||
Bytes: result.Bytes,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
out := make([]contracts.OutputFile, 0, len(files))
|
||||
for _, file := range files {
|
||||
out := make([]contracts.OutputFile, 0, len(result.Files))
|
||||
for _, file := range result.Files {
|
||||
if err := validateOutputFileName(file.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -29,13 +29,11 @@ func TestNewAndDataTypes(t *testing.T) {
|
||||
Metadata: map[string]any{"request": "test"},
|
||||
}
|
||||
output := RunOutput{
|
||||
Manifest: artifacts.RunManifest{PipelineID: "pipeline-1"},
|
||||
Approved: []artifacts.Artifact{{ExtractorKey: "extract-alpha"}},
|
||||
Rejected: []artifacts.RejectedArtifact{{ValidatorName: "validator"}},
|
||||
Warnings: []contracts.Warning{{ReasonCode: "note", Message: "message"}},
|
||||
OutputFiles: []contracts.OutputFile{{Name: "artifacts/generic.json", ContentType: "application/json", Bytes: []byte(`{}`)}},
|
||||
EncodedOutput: []byte(`{}`),
|
||||
ContentType: "application/json",
|
||||
Manifest: artifacts.RunManifest{PipelineID: "pipeline-1"},
|
||||
Approved: []artifacts.Artifact{{ExtractorKey: "extract-alpha"}},
|
||||
Rejected: []artifacts.RejectedArtifact{{ValidatorName: "validator"}},
|
||||
Warnings: []contracts.Warning{{ReasonCode: "note", Message: "message"}},
|
||||
OutputFiles: []contracts.OutputFile{{Name: "artifacts/generic.json", ContentType: "application/json", Bytes: []byte(`{}`)}},
|
||||
}
|
||||
|
||||
if input.Pipeline.ID != "pipeline-1" || input.SourceID != "source-1" {
|
||||
@@ -1140,13 +1138,11 @@ func (validator *runnerValidator) Validate(ctx context.Context, req contracts.Va
|
||||
}
|
||||
|
||||
type runnerOutputEncoder struct {
|
||||
key string
|
||||
files []contracts.OutputFile
|
||||
bytes []byte
|
||||
contentType string
|
||||
warnings []contracts.Warning
|
||||
err error
|
||||
requests []contracts.OutputRequest
|
||||
key string
|
||||
files []contracts.OutputFile
|
||||
warnings []contracts.Warning
|
||||
err error
|
||||
requests []contracts.OutputRequest
|
||||
}
|
||||
|
||||
func (encoder *runnerOutputEncoder) Key() string {
|
||||
@@ -1156,10 +1152,8 @@ func (encoder *runnerOutputEncoder) Key() string {
|
||||
func (encoder *runnerOutputEncoder) Encode(ctx context.Context, req contracts.OutputRequest) (contracts.OutputResult, error) {
|
||||
encoder.requests = append(encoder.requests, req)
|
||||
return contracts.OutputResult{
|
||||
Files: encoder.files,
|
||||
Bytes: encoder.bytes,
|
||||
ContentType: encoder.contentType,
|
||||
Warnings: encoder.warnings,
|
||||
Files: encoder.files,
|
||||
Warnings: encoder.warnings,
|
||||
}, encoder.err
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,13 @@ func TestWalkingSkeletonFixture(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v, want nil", err)
|
||||
}
|
||||
if output.ContentType != "application/json" {
|
||||
t.Fatalf("ContentType = %q, want application/json", output.ContentType)
|
||||
if len(output.OutputFiles) != 1 {
|
||||
t.Fatalf("len(OutputFiles) = %d, want 1", len(output.OutputFiles))
|
||||
}
|
||||
assertStructuralJSONEqual(t, output.EncodedOutput, expectedBytes)
|
||||
if output.OutputFiles[0].ContentType != "application/json" {
|
||||
t.Fatalf("ContentType = %q, want application/json", output.OutputFiles[0].ContentType)
|
||||
}
|
||||
assertStructuralJSONEqual(t, output.OutputFiles[0].Bytes, expectedBytes)
|
||||
if llmClient.calls != 2 {
|
||||
t.Fatalf("LLM calls = %d, want chunk count 2", llmClient.calls)
|
||||
}
|
||||
@@ -356,8 +359,9 @@ func (output walkingSkeletonOutput) Encode(ctx context.Context, req contracts.Ou
|
||||
return contracts.OutputResult{}, err
|
||||
}
|
||||
return contracts.OutputResult{
|
||||
Bytes: encoded,
|
||||
ContentType: "application/json",
|
||||
Files: []contracts.OutputFile{
|
||||
{Name: "output.json", ContentType: "application/json", Bytes: encoded},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user