Share source evidence through the selected capture sink
This commit is contained in:
@@ -14,6 +14,13 @@ import (
|
||||
|
||||
func (*nativeEvidence) Enabled() bool { return true }
|
||||
|
||||
type failingCaptureInput struct{ cause error }
|
||||
|
||||
func (f failingCaptureInput) Key() string { return "failing-input" }
|
||||
func (f failingCaptureInput) Parse(context.Context, contracts.ParseRequest) (*source.SourceDocument, error) {
|
||||
return nil, f.cause
|
||||
}
|
||||
|
||||
func TestOperationInputsRetainSourceReferencesAndIncomingCodecBytes(t *testing.T) {
|
||||
evidence := &nativeEvidence{}
|
||||
text := strings.Repeat("sk-ordinary-source-content ", 500)
|
||||
@@ -44,6 +51,123 @@ func TestOperationInputsRetainSourceReferencesAndIncomingCodecBytes(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerSharesSourceEvidenceAtSelectedSink(t *testing.T) {
|
||||
for _, mode := range []string{"explicit", "debug", "distinct"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
prepared := preparedConcurrentPipeline(t, 2)
|
||||
selected, other := &nativeEvidence{}, &nativeEvidence{}
|
||||
input := RunInput{Prepared: prepared, RawInput: []byte("unique original input"), Workers: 2}
|
||||
switch mode {
|
||||
case "explicit":
|
||||
input.Execution.Capture = selected
|
||||
case "debug":
|
||||
input.Debug = selected
|
||||
case "distinct":
|
||||
input.Execution.Capture, input.Debug = selected, other
|
||||
}
|
||||
if _, err := New().Run(context.Background(), input); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(other.files) != 0 {
|
||||
t.Fatalf("unselected sink received records: %v", other.files)
|
||||
}
|
||||
if !strings.Contains(string(selected.files["source/input.json"]), "unique original input") || !strings.Contains(string(selected.files["source/output.json"]), "text-1") {
|
||||
t.Fatal("shared source records are missing their original content")
|
||||
}
|
||||
inputs := 0
|
||||
laneInputs := 0
|
||||
for name, content := range selected.files {
|
||||
if name == "chunk/input.json" || strings.HasPrefix(name, "extract/") && strings.HasSuffix(name, "/input.json") {
|
||||
var envelope struct {
|
||||
Payload struct {
|
||||
Source struct {
|
||||
BundleRootPath string `json:"bundle_root_path"`
|
||||
} `json:"source"`
|
||||
} `json:"payload"`
|
||||
}
|
||||
if err := json.Unmarshal(content, &envelope); err != nil || envelope.Payload.Source.BundleRootPath != "source/output.json" || len(selected.files[envelope.Payload.Source.BundleRootPath]) == 0 {
|
||||
t.Fatalf("unresolvable run input source in %s: %s, %v", name, content, err)
|
||||
}
|
||||
laneInputs++
|
||||
}
|
||||
if !strings.HasPrefix(name, "operations/") || !strings.HasSuffix(name, "/inputs.json") {
|
||||
continue
|
||||
}
|
||||
inputs++
|
||||
var payload map[string]json.RawMessage
|
||||
if err := json.Unmarshal(content, &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var link struct {
|
||||
BundleRootPath string `json:"bundle_root_path"`
|
||||
}
|
||||
if err := json.Unmarshal(payload["source"], &link); err != nil || link.BundleRootPath != "source/output.json" || len(selected.files[link.BundleRootPath]) == 0 {
|
||||
t.Fatalf("unresolvable source link in %s: %s, %v", name, payload["source"], err)
|
||||
}
|
||||
if !strings.Contains(name, "/extract/") {
|
||||
link.BundleRootPath = ""
|
||||
if err := json.Unmarshal(payload["source_input"], &link); err != nil || link.BundleRootPath != "source/input.json" || len(selected.files[link.BundleRootPath]) == 0 {
|
||||
t.Fatalf("unresolvable original input link in %s: %s, %v", name, payload["source_input"], err)
|
||||
}
|
||||
} else if !strings.Contains(string(payload["chunk"]), "text-1") && !strings.Contains(string(payload["chunk"]), "text-2") {
|
||||
t.Fatalf("chunk content missing from %s: %s", name, payload["chunk"])
|
||||
}
|
||||
if strings.Contains(string(content), "unique original input") {
|
||||
t.Fatalf("full input duplicated in %s", name)
|
||||
}
|
||||
}
|
||||
if inputs < 4 || laneInputs < 3 {
|
||||
t.Fatalf("operation inputs = %d, run inputs = %d; want chunk and multiple lanes", inputs, laneInputs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerFailsBeforeParsingWhenSharedSourceCaptureFails(t *testing.T) {
|
||||
prepared := preparedConcurrentPipeline(t, 1)
|
||||
adapter := &countingInputAdapter{InputAdapter: prepared.input}
|
||||
prepared.input = adapter
|
||||
cause := errors.New("source evidence failure")
|
||||
writer := &nativeEvidence{fail: func(name string) error {
|
||||
if name == "source/input.json" {
|
||||
return cause
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
_, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Execution: contracts.ExecutionOptions{Capture: writer}})
|
||||
var captureErr *contracts.CaptureError
|
||||
if !errors.Is(err, cause) || !errors.As(err, &captureErr) || adapter.calls.Load() != 0 {
|
||||
t.Fatalf("Run() error = %v, parses = %d", err, adapter.calls.Load())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerKeepsOnlyAvailableSourceEvidenceOnParseFailure(t *testing.T) {
|
||||
prepared := preparedConcurrentPipeline(t, 1)
|
||||
cause := errors.New("parse failure")
|
||||
prepared.input = failingCaptureInput{cause: cause}
|
||||
writer := &nativeEvidence{}
|
||||
_, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("original"), Execution: contracts.ExecutionOptions{Capture: writer}})
|
||||
if !errors.Is(err, cause) || len(writer.files["source/input.json"]) == 0 || len(writer.files["source/output.json"]) != 0 {
|
||||
t.Fatalf("Run() error = %v, files = %v", err, writer.files)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerStopsWhenParsedSourceCaptureFails(t *testing.T) {
|
||||
prepared := preparedConcurrentPipeline(t, 1)
|
||||
cause := errors.New("parsed source evidence failure")
|
||||
writer := &nativeEvidence{fail: func(name string) error {
|
||||
if name == "source/output.json" {
|
||||
return cause
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
_, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("original"), Execution: contracts.ExecutionOptions{Capture: writer}})
|
||||
var captureErr *contracts.CaptureError
|
||||
if !errors.Is(err, cause) || !errors.As(err, &captureErr) || len(writer.files["source/input.json"]) == 0 || len(writer.files["source/output.json"]) != 0 || len(writer.files["chunk/input.json"]) != 0 {
|
||||
t.Fatalf("Run() error = %v, files = %v", err, writer.files)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerCapturesActualArtifactsAndNoExecutionOnReuse(t *testing.T) {
|
||||
_, store := filesystemProducerCache(t)
|
||||
calls := 0
|
||||
@@ -66,6 +190,14 @@ func TestRunnerCapturesActualArtifactsAndNoExecutionOnReuse(t *testing.T) {
|
||||
if nativeEvidenceCount(evidence, "/inputs.json") != 4 || nativeEvidenceCount(evidence, "/outcome.json") != 4 {
|
||||
t.Fatal("missing chunk/extract/merge/normalization boundaries")
|
||||
}
|
||||
if len(evidence.files["source/input.json"]) == 0 || len(evidence.files["source/output.json"]) == 0 {
|
||||
t.Fatal("source records missing during extraction or cache reuse")
|
||||
}
|
||||
for name, content := range evidence.files {
|
||||
if strings.HasPrefix(name, "operations/") && strings.HasSuffix(name, "/inputs.json") && !strings.Contains(string(content), `"bundle_root_path": "source/output.json"`) {
|
||||
t.Fatalf("source link missing from %s: %s", name, content)
|
||||
}
|
||||
}
|
||||
if nativeEvidenceCount(evidence, "/result.json") != map[bool]int{false: 1, true: 0}[reuse] {
|
||||
t.Fatal("cache reuse fabricated a native execution")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user