Publish domain artifacts without reporting sidecars
This commit is contained in:
@@ -1339,6 +1339,31 @@ unchanged. Remove old canonical-partition/resume-policy tests as superseded.
|
||||
|
||||
## Stage 29: Publish Only Domain Artifacts At Existing Paths
|
||||
|
||||
**Status:** Complete. The JSON encoder now returns only lane artifacts and
|
||||
explicitly enabled, available chunk-map/evidence-context files, preserving lane
|
||||
filename mapping, JSON payloads, intrinsic metadata, codec checks, and auxiliary
|
||||
schemas. Removed index/manifest/rejected/warnings/diagnostics sidecar generation,
|
||||
the reporting-model package, manifest/profile/validation ledgers, and reporting-only
|
||||
output inputs. Runner results expose deliverable files, process diagnostics, and
|
||||
fallback count; intermediate normalized values remain private for ordered handoffs
|
||||
and evidence construction. ArtifactCount counts deliverable files only.
|
||||
Retained filename/collision, JSON/number, auxiliary codec, source ordering/window,
|
||||
projection/type, ownership, and disabled-output coverage. Added explicit auxiliary
|
||||
selection/count and no-sidecar checks, migrated evidence preparation fixtures,
|
||||
and verified evidence reconstruction from a native cached normalization without
|
||||
semantic reassessment. The Seriatim runner contract now checks the real JSON
|
||||
domain artifact instead of a manifest or fake output.
|
||||
Focused pipeline tests/vet/repeated race checks, generic/Seriatim/contracts/cache/
|
||||
source/asset/chunk-map/evidence tests, selected vet/race checks, production
|
||||
pipeline/generic/Seriatim/config builds, and git diff checks pass. Independently
|
||||
runnable candidate-JSON, combat-turn, NPC-occurrence, scene-description, and
|
||||
source-range codec tests pass. Full pipeline/CLI and remaining D&D codec suites
|
||||
still encounter unmigrated callers of the removed reporting package, the old
|
||||
ConfigKit YAML plugin/limit import, or retired fingerprint declarations. Those
|
||||
suites are not claimed passing; scheduled command/debug integration and Stage 35
|
||||
cleanup must close the blockers before final verification. Native completion
|
||||
reporting and physical publication/failure outcomes remain Stage 34.
|
||||
|
||||
**Goal:** simplify the logical output boundary without changing payload contracts.
|
||||
|
||||
**Inspect/change:** `internal/modules/generic/output/json/encoder.go`,
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ArtifactLaneManifest struct {
|
||||
StepID string `json:"step_id,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Extractor string `json:"extractor"`
|
||||
Merger string `json:"merger"`
|
||||
Normalizer string `json:"normalizer"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
type ValidatorChainManifest struct {
|
||||
Stage string `json:"stage"`
|
||||
LaneID string `json:"lane_id,omitempty"`
|
||||
ModuleKey string `json:"module_key"`
|
||||
Validators []ValidatorManifest `json:"validators"`
|
||||
}
|
||||
|
||||
type ValidatorManifest struct {
|
||||
Key string `json:"key"`
|
||||
ExecutionClass string `json:"execution_class"`
|
||||
}
|
||||
|
||||
type LLMProfileManifest struct {
|
||||
ID string `json:"id"`
|
||||
Provider string `json:"provider,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
BackendID string `json:"backend_id,omitempty"`
|
||||
ReasoningEffort string `json:"reasoning_effort,omitempty"`
|
||||
}
|
||||
|
||||
// Normalized returns the canonical representation used for manifest identity
|
||||
// and publication.
|
||||
func (profile LLMProfileManifest) Normalized() LLMProfileManifest {
|
||||
profile.ID = strings.TrimSpace(profile.ID)
|
||||
profile.Provider = strings.TrimSpace(profile.Provider)
|
||||
profile.Model = strings.TrimSpace(profile.Model)
|
||||
profile.BackendID = strings.TrimSpace(profile.BackendID)
|
||||
profile.ReasoningEffort = strings.TrimSpace(profile.ReasoningEffort)
|
||||
return profile
|
||||
}
|
||||
|
||||
// IdentityKey returns an opaque, deterministic key for the effective profile.
|
||||
func (profile LLMProfileManifest) IdentityKey() string {
|
||||
profile = profile.Normalized()
|
||||
return profile.ID + "\x00" +
|
||||
profile.Provider + "\x00" +
|
||||
profile.Model + "\x00" +
|
||||
profile.BackendID + "\x00" +
|
||||
profile.ReasoningEffort
|
||||
}
|
||||
|
||||
type ReferenceProvenance struct {
|
||||
Stage string `json:"stage,omitempty"`
|
||||
StepID string `json:"step_id,omitempty"`
|
||||
LaneID string `json:"lane_id,omitempty"`
|
||||
SlotName string `json:"slot_name"`
|
||||
OriginType string `json:"origin_type"`
|
||||
OriginURI string `json:"origin_uri,omitempty"`
|
||||
Digest string `json:"digest,omitempty"`
|
||||
MediaType string `json:"media_type,omitempty"`
|
||||
SizeBytes int64 `json:"size_bytes,omitempty"`
|
||||
BindingSource string `json:"binding_source,omitempty"`
|
||||
ArtifactKind string `json:"artifact_kind,omitempty"`
|
||||
SchemaID string `json:"schema_id,omitempty"`
|
||||
SchemaName string `json:"schema_name,omitempty"`
|
||||
SchemaVersion string `json:"schema_version,omitempty"`
|
||||
SchemaDigest string `json:"schema_digest,omitempty"`
|
||||
ProducerPipeline string `json:"producer_pipeline_id,omitempty"`
|
||||
ProducerStep string `json:"producer_step_id,omitempty"`
|
||||
ProducerLane string `json:"producer_lane_id,omitempty"`
|
||||
ProducerModule string `json:"producer_module_key,omitempty"`
|
||||
}
|
||||
|
||||
type OutputSchemaProvenance struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type NormalizedOutputManifest struct {
|
||||
StepID string `json:"step_id,omitempty"`
|
||||
LaneID string `json:"lane_id"`
|
||||
ModuleKey string `json:"module_key,omitempty"`
|
||||
SourceID string `json:"source_id,omitempty"`
|
||||
MediaType string `json:"media_type,omitempty"`
|
||||
Schema OutputSchemaProvenance `json:"schema,omitempty"`
|
||||
}
|
||||
|
||||
type RejectedOutputManifest struct {
|
||||
Stage string `json:"stage"`
|
||||
StepID string `json:"step_id,omitempty"`
|
||||
LaneID string `json:"lane_id,omitempty"`
|
||||
ModuleKey string `json:"module_key,omitempty"`
|
||||
ChunkID string `json:"chunk_id,omitempty"`
|
||||
ChunkIndex int `json:"chunk_index,omitempty"`
|
||||
ValidatorName string `json:"validator_name,omitempty"`
|
||||
ReasonCode string `json:"reason_code,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
AttemptCount int `json:"attempt_count,omitempty"`
|
||||
DiagnosticArtifactPath string `json:"diagnostic_artifact_path,omitempty"`
|
||||
Validation *ValidationSummary `json:"validation,omitempty"`
|
||||
}
|
||||
|
||||
// ValidationSummary is the bounded, durable outcome of validating one
|
||||
// producer result. It deliberately contains identities and stable codes, not
|
||||
// model responses, corrective guidance, validator diagnostics, or payloads.
|
||||
type ValidationSummary struct {
|
||||
Stage string `json:"stage,omitempty"`
|
||||
StepID string `json:"step_id,omitempty"`
|
||||
LaneID string `json:"lane_id,omitempty"`
|
||||
ModuleKey string `json:"module_key,omitempty"`
|
||||
ChunkID string `json:"chunk_id,omitempty"`
|
||||
ChunkIndex int `json:"chunk_index,omitempty"`
|
||||
Status string `json:"status"`
|
||||
RejectingValidators []string `json:"rejecting_validators,omitempty"`
|
||||
ReasonCodes []string `json:"reason_codes,omitempty"`
|
||||
IncompleteValidators []string `json:"incomplete_validators,omitempty"`
|
||||
ProducerAttemptCount int `json:"producer_attempt_count"`
|
||||
TerminalAction string `json:"terminal_action"`
|
||||
}
|
||||
|
||||
// CloneValidationSummary returns an independently owned durable summary.
|
||||
func CloneValidationSummary(summary ValidationSummary) ValidationSummary {
|
||||
summary.RejectingValidators = append([]string(nil), summary.RejectingValidators...)
|
||||
summary.ReasonCodes = append([]string(nil), summary.ReasonCodes...)
|
||||
summary.IncompleteValidators = append([]string(nil), summary.IncompleteValidators...)
|
||||
return summary
|
||||
}
|
||||
|
||||
type CheckpointDecisionManifest struct {
|
||||
Stage string `json:"stage"`
|
||||
StepID string `json:"step_id,omitempty"`
|
||||
LaneID string `json:"lane_id,omitempty"`
|
||||
ModuleKey string `json:"module_key,omitempty"`
|
||||
Category string `json:"category"`
|
||||
ReasonCode string `json:"reason_code,omitempty"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
}
|
||||
|
||||
type ChunkPlanManifest struct {
|
||||
Mode string `json:"mode"`
|
||||
Action string `json:"action,omitempty"`
|
||||
SourceDigest string `json:"source_digest,omitempty"`
|
||||
PlanDigest string `json:"plan_digest,omitempty"`
|
||||
PlanSchemaVersion string `json:"plan_schema_version,omitempty"`
|
||||
RequestedModule string `json:"requested_module"`
|
||||
ProducerInputModule string `json:"producer_input_module,omitempty"`
|
||||
ProducerModule string `json:"producer_module,omitempty"`
|
||||
ProducerLLMProfile string `json:"producer_llm_profile,omitempty"`
|
||||
ProducerReferences []ReferenceProvenance `json:"producer_references,omitempty"`
|
||||
ProducerMetadata map[string]any `json:"producer_metadata,omitempty"`
|
||||
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||
}
|
||||
|
||||
// ChunkPlanSummary is deliberately limited to cache and validation decisions.
|
||||
// It must never contain plan units, source content, annotations, or model I/O.
|
||||
type ChunkPlanSummary struct {
|
||||
Mode string `json:"mode"`
|
||||
SourceDigest string `json:"source_digest,omitempty"`
|
||||
CandidateDigest string `json:"candidate_digest,omitempty"`
|
||||
RequestedModule string `json:"requested_module"`
|
||||
LookupStatus string `json:"lookup_status"`
|
||||
LookupReason string `json:"lookup_reason,omitempty"`
|
||||
Action string `json:"action,omitempty"`
|
||||
ValidationStatus string `json:"validation_status"`
|
||||
PublicationStatus string `json:"publication_status"`
|
||||
}
|
||||
|
||||
type RunManifest struct {
|
||||
RunID string `json:"run_id,omitempty"`
|
||||
PipelineID string `json:"pipeline_id,omitempty"`
|
||||
PipelineDigest string `json:"pipeline_digest,omitempty"`
|
||||
InputModule string `json:"input_module,omitempty"`
|
||||
Chunker string `json:"chunker,omitempty"`
|
||||
ChunkPlan *ChunkPlanManifest `json:"chunk_plan,omitempty"`
|
||||
SourceDigests []string `json:"source_digests,omitempty"`
|
||||
Extractors []string `json:"extractors,omitempty"`
|
||||
Merger string `json:"merger,omitempty"`
|
||||
Normalizer string `json:"normalizer,omitempty"`
|
||||
OutputEncoder string `json:"output_encoder,omitempty"`
|
||||
ModuleMetadata map[string]map[string]any `json:"module_metadata,omitempty"`
|
||||
ArtifactLanes []ArtifactLaneManifest `json:"artifact_lanes,omitempty"`
|
||||
ValidatorChains []ValidatorChainManifest `json:"validator_chains,omitempty"`
|
||||
References []ReferenceProvenance `json:"references,omitempty"`
|
||||
NormalizedOutputs []NormalizedOutputManifest `json:"normalized_outputs,omitempty"`
|
||||
RejectedOutputs []RejectedOutputManifest `json:"rejected_outputs,omitempty"`
|
||||
ValidationSummaries []ValidationSummary `json:"validation_summaries,omitempty"`
|
||||
CheckpointDecisions []CheckpointDecisionManifest `json:"checkpoint_decisions,omitempty"`
|
||||
LLMProfiles []LLMProfileManifest `json:"llm_profiles,omitempty"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
SchemaVersion string `json:"schema_version,omitempty"`
|
||||
ValidationStatus string `json:"validation_status,omitempty"`
|
||||
StartedAt *time.Time `json:"started_at,omitempty"`
|
||||
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRunManifestOmitsEmptyOptionalFields(t *testing.T) {
|
||||
gotJSON, err := json.Marshal(RunManifest{})
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v", err)
|
||||
}
|
||||
|
||||
if string(gotJSON) != "{}" {
|
||||
t.Fatalf("json.Marshal(RunManifest{}) = %s, want {}", gotJSON)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunManifestChunkPlanIsAdditiveAndOmitsPlanContent(t *testing.T) {
|
||||
manifest := RunManifest{ChunkPlan: &ChunkPlanManifest{
|
||||
Mode: "auto", Action: "reused", SourceDigest: "sha256:source", PlanDigest: "sha256:plan",
|
||||
PlanSchemaVersion: "notarius.chunk-plan.v2", RequestedModule: "chunk/current",
|
||||
ProducerInputModule: "input/original", ProducerModule: "chunk/original",
|
||||
}}
|
||||
encoded, err := json.Marshal(manifest)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
text := string(encoded)
|
||||
for _, want := range []string{`"chunk_plan"`, `"action":"reused"`, `"requested_module":"chunk/current"`, `"producer_module":"chunk/original"`} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatalf("manifest JSON %s does not contain %s", text, want)
|
||||
}
|
||||
}
|
||||
for _, forbidden := range []string{`"plan"`, `"units"`, `"annotations"`} {
|
||||
if strings.Contains(text, forbidden) {
|
||||
t.Fatalf("manifest JSON contains forbidden field %s: %s", forbidden, text)
|
||||
}
|
||||
}
|
||||
|
||||
var legacy RunManifest
|
||||
if err := json.Unmarshal([]byte(`{"pipeline_id":"legacy"}`), &legacy); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if legacy.PipelineID != "legacy" || legacy.ChunkPlan != nil {
|
||||
t.Fatalf("legacy manifest = %#v", legacy)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunManifestIncludesPipelineAndArtifactLaneFields(t *testing.T) {
|
||||
manifest := RunManifest{
|
||||
PipelineID: "pipeline-1",
|
||||
PipelineDigest: "sha256:abc123",
|
||||
LLMProfiles: []LLMProfileManifest{
|
||||
{
|
||||
ID: "default",
|
||||
Provider: "promptkit",
|
||||
Model: "model-a",
|
||||
BackendID: "openrouter",
|
||||
ReasoningEffort: "high",
|
||||
},
|
||||
},
|
||||
ArtifactLanes: []ArtifactLaneManifest{
|
||||
{
|
||||
ID: "events",
|
||||
Extractor: "event-extractor",
|
||||
Merger: "appendorder",
|
||||
Normalizer: "noop",
|
||||
Metadata: map[string]any{
|
||||
"extractor": map[string]any{"prompt_id": "test.prompt"},
|
||||
},
|
||||
},
|
||||
},
|
||||
ValidatorChains: []ValidatorChainManifest{
|
||||
{
|
||||
Stage: "extract",
|
||||
LaneID: "events",
|
||||
ModuleKey: "event-extractor",
|
||||
Validators: []ValidatorManifest{
|
||||
{Key: "grounded", ExecutionClass: "deterministic"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
gotJSON, err := json.Marshal(manifest)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v", err)
|
||||
}
|
||||
|
||||
var got map[string]any
|
||||
if err := json.Unmarshal(gotJSON, &got); err != nil {
|
||||
t.Fatalf("json.Unmarshal() error = %v", err)
|
||||
}
|
||||
|
||||
assertHasKeys(t, got, "pipeline_id", "pipeline_digest", "artifact_lanes", "validator_chains", "llm_profiles")
|
||||
|
||||
profiles, ok := got["llm_profiles"].([]any)
|
||||
if !ok {
|
||||
t.Fatalf("llm_profiles = %#v, want array", got["llm_profiles"])
|
||||
}
|
||||
if len(profiles) != 1 {
|
||||
t.Fatalf("len(llm_profiles) = %d, want 1", len(profiles))
|
||||
}
|
||||
profile, ok := profiles[0].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("llm_profiles[0] = %#v, want object", profiles[0])
|
||||
}
|
||||
assertHasKeys(t, profile, "id", "provider", "model", "backend_id", "reasoning_effort")
|
||||
if profile["provider"] != "promptkit" {
|
||||
t.Fatalf("llm_profiles[0].provider = %#v, want promptkit", profile["provider"])
|
||||
}
|
||||
if profile["backend_id"] != "openrouter" || profile["reasoning_effort"] != "high" {
|
||||
t.Fatalf("llm_profiles[0] = %#v, want backend and reasoning provenance", profile)
|
||||
}
|
||||
|
||||
lanes, ok := got["artifact_lanes"].([]any)
|
||||
if !ok {
|
||||
t.Fatalf("artifact_lanes = %#v, want array", got["artifact_lanes"])
|
||||
}
|
||||
if len(lanes) != 1 {
|
||||
t.Fatalf("len(artifact_lanes) = %d, want 1", len(lanes))
|
||||
}
|
||||
lane, ok := lanes[0].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("artifact_lanes[0] = %#v, want object", lanes[0])
|
||||
}
|
||||
assertHasKeys(t, lane, "id", "extractor", "merger", "normalizer", "metadata")
|
||||
|
||||
chains, ok := got["validator_chains"].([]any)
|
||||
if !ok {
|
||||
t.Fatalf("validator_chains = %#v, want array", got["validator_chains"])
|
||||
}
|
||||
if len(chains) != 1 {
|
||||
t.Fatalf("len(validator_chains) = %d, want 1", len(chains))
|
||||
}
|
||||
chain, ok := chains[0].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("validator_chains[0] = %#v, want object", chains[0])
|
||||
}
|
||||
assertHasKeys(t, chain, "stage", "lane_id", "module_key", "validators")
|
||||
}
|
||||
|
||||
func TestRunManifestIncludesReferenceProvenance(t *testing.T) {
|
||||
manifest := RunManifest{
|
||||
References: []ReferenceProvenance{
|
||||
{
|
||||
Stage: "extract",
|
||||
LaneID: "events",
|
||||
SlotName: "roster",
|
||||
OriginType: "file",
|
||||
OriginURI: "file:///tmp/roster.txt",
|
||||
Digest: "sha256:reference",
|
||||
MediaType: "text/plain; charset=utf-8",
|
||||
SizeBytes: 12,
|
||||
BindingSource: "config",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
gotJSON, err := json.Marshal(manifest)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v", err)
|
||||
}
|
||||
|
||||
var got RunManifest
|
||||
if err := json.Unmarshal(gotJSON, &got); err != nil {
|
||||
t.Fatalf("json.Unmarshal() error = %v", err)
|
||||
}
|
||||
if len(got.References) != 1 {
|
||||
t.Fatalf("len(References) = %d, want 1", len(got.References))
|
||||
}
|
||||
reference := got.References[0]
|
||||
if reference.Stage != "extract" || reference.LaneID != "events" || reference.SlotName != "roster" || reference.OriginType != "file" || reference.OriginURI != "file:///tmp/roster.txt" {
|
||||
t.Fatalf("reference provenance = %#v, want lane-scoped origin details", reference)
|
||||
}
|
||||
if reference.Digest != "sha256:reference" || reference.MediaType != "text/plain; charset=utf-8" || reference.SizeBytes != 12 || reference.BindingSource != "config" {
|
||||
t.Fatalf("reference provenance = %#v, want digest/media/size/source details", reference)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunManifestIncludesTopLevelModuleMetadata(t *testing.T) {
|
||||
manifest := RunManifest{
|
||||
ModuleMetadata: map[string]map[string]any{
|
||||
"chunker": {
|
||||
"prompt_id": "dnd.scenes",
|
||||
"prompt_version": "v1",
|
||||
"prompt_sha256": "sha256:abc123",
|
||||
"response_schema_key": "dnd_scenes_llm",
|
||||
"response_schema_name": "notarius_dnd_scenes_llm_v1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
gotJSON, err := json.Marshal(manifest)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v", err)
|
||||
}
|
||||
|
||||
var got map[string]any
|
||||
if err := json.Unmarshal(gotJSON, &got); err != nil {
|
||||
t.Fatalf("json.Unmarshal() error = %v", err)
|
||||
}
|
||||
|
||||
moduleMetadata, ok := got["module_metadata"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("module_metadata = %#v, want object", got["module_metadata"])
|
||||
}
|
||||
assertHasKeys(t, moduleMetadata, "chunker")
|
||||
|
||||
chunkerMetadata, ok := moduleMetadata["chunker"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("module_metadata.chunker = %#v, want object", moduleMetadata["chunker"])
|
||||
}
|
||||
assertHasKeys(t, chunkerMetadata, "prompt_id", "prompt_version", "prompt_sha256", "response_schema_key", "response_schema_name")
|
||||
}
|
||||
|
||||
func assertHasKeys(t *testing.T, values map[string]any, keys ...string) {
|
||||
t.Helper()
|
||||
|
||||
for _, key := range keys {
|
||||
if _, ok := values[key]; !ok {
|
||||
t.Fatalf("missing key %q in %#v", key, values)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
)
|
||||
|
||||
@@ -124,10 +123,6 @@ type LLMDebugUsage struct {
|
||||
CacheWriteTokens int `json:"cache_write_tokens,omitempty"`
|
||||
}
|
||||
|
||||
type LLMProfileManifestProvider interface {
|
||||
LLMProfileManifests() []artifacts.LLMProfileManifest
|
||||
}
|
||||
|
||||
type LLMInputMaterial struct {
|
||||
Name string `json:"name"`
|
||||
MediaType string `json:"media_type,omitempty"`
|
||||
@@ -323,15 +318,9 @@ type ValidationResult struct {
|
||||
}
|
||||
|
||||
type OutputRequest struct {
|
||||
Manifest artifacts.RunManifest `json:"manifest"`
|
||||
NormalizeOutputs []SerializedOutput `json:"normalize_outputs,omitempty"`
|
||||
Rejected []RejectedOutput `json:"rejected,omitempty"`
|
||||
Diagnostics DiagnosticCollection `json:"diagnostics,omitempty"`
|
||||
LLMProfile string `json:"llm_profile,omitempty"`
|
||||
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
ChunkMap *SerializedArtifact `json:"chunk_map,omitempty"`
|
||||
EvidenceContext *SerializedArtifact `json:"evidence_context,omitempty"`
|
||||
NormalizeOutputs []SerializedOutput `json:"normalize_outputs,omitempty"`
|
||||
ChunkMap *SerializedArtifact `json:"chunk_map,omitempty"`
|
||||
EvidenceContext *SerializedArtifact `json:"evidence_context,omitempty"`
|
||||
}
|
||||
|
||||
type OutputFile struct {
|
||||
@@ -348,22 +337,3 @@ type OutputEncoder interface {
|
||||
Key() string
|
||||
Encode(ctx context.Context, req OutputRequest) (OutputResult, error)
|
||||
}
|
||||
|
||||
type RejectedOutput struct {
|
||||
Stage string `json:"stage"`
|
||||
StepID string `json:"step_id,omitempty"`
|
||||
LaneID string `json:"lane_id,omitempty"`
|
||||
ModuleKey string `json:"module_key,omitempty"`
|
||||
ChunkID string `json:"chunk_id,omitempty"`
|
||||
ChunkIndex int `json:"chunk_index,omitempty"`
|
||||
ValidatorName string `json:"validator_name,omitempty"`
|
||||
ReasonCode string `json:"reason_code,omitempty"`
|
||||
Message string `json:"message"`
|
||||
AttemptCount int `json:"attempt_count,omitempty"`
|
||||
DiagnosticArtifactPath string `json:"diagnostic_artifact_path,omitempty"`
|
||||
Validation *artifacts.ValidationSummary `json:"validation,omitempty"`
|
||||
}
|
||||
|
||||
type ManifestMetadataProvider interface {
|
||||
ManifestMetadata() map[string]any
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ func (encoder fakeOutputEncoder) Encode(ctx context.Context, req OutputRequest)
|
||||
{
|
||||
Name: "artifacts/generic.json",
|
||||
ContentType: "application/json",
|
||||
Bytes: []byte(`{"run_id":"` + req.Manifest.RunID + `","output_count":1}`),
|
||||
Bytes: []byte(`{"output_count":1}`),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestRunnerMaterializesAndFullyAssessesEachNativePlanRevision(t *testing.T)
|
||||
if test.wantError {
|
||||
return
|
||||
}
|
||||
if len(output.NormalizeOutputs) != 1 || (output.FallbackCount == 1) != test.wantFallback {
|
||||
if len(output.normalizeOutputs) != 1 || (output.FallbackCount == 1) != test.wantFallback {
|
||||
t.Fatalf("plan disposition=%#v", output)
|
||||
}
|
||||
for _, role := range []string{"extract", "merge", "normalize"} {
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/fileio"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
@@ -348,14 +347,6 @@ func debugFirstNonEmptyString(values ...string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (client *debugLLMClient) LLMProfileManifests() []artifacts.LLMProfileManifest {
|
||||
provider, ok := client.inner.(contracts.LLMProfileManifestProvider)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return provider.LLMProfileManifests()
|
||||
}
|
||||
|
||||
func writeDebugTimed(recorder DebugRecorder, name string, envelope debugTimedEnvelope) error {
|
||||
if recorder == nil || !recorder.Enabled() {
|
||||
return nil
|
||||
@@ -680,31 +671,6 @@ func debugValidationResultEnvelope(result contracts.ValidationResult) contracts.
|
||||
return result
|
||||
}
|
||||
|
||||
func debugRejectedOutputEnvelope(rejected contracts.RejectedOutput) contracts.RejectedOutput {
|
||||
rejected.Message = string(redactSecretBytes([]byte(rejected.Message)))
|
||||
rejected.DiagnosticArtifactPath = string(redactSecretBytes([]byte(rejected.DiagnosticArtifactPath)))
|
||||
return rejected
|
||||
}
|
||||
|
||||
func debugRejectedOutputPtr(rejected *contracts.RejectedOutput) any {
|
||||
if rejected == nil {
|
||||
return nil
|
||||
}
|
||||
out := debugRejectedOutputEnvelope(*rejected)
|
||||
return out
|
||||
}
|
||||
|
||||
func debugRejectedOutputEnvelopes(rejected []contracts.RejectedOutput) []contracts.RejectedOutput {
|
||||
if len(rejected) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]contracts.RejectedOutput, 0, len(rejected))
|
||||
for _, item := range rejected {
|
||||
out = append(out, debugRejectedOutputEnvelope(item))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func debugContentDigest(content []byte) string {
|
||||
sum := sha256.Sum256(content)
|
||||
return "sha256:" + hex.EncodeToString(sum[:])
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/evidencecontext"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
type capturingEvidenceOutput struct {
|
||||
@@ -91,8 +92,7 @@ func TestRunnerBuildsEvidenceContextFromSelectedNormalizedOutputs(t *testing.T)
|
||||
return nil, nil
|
||||
}
|
||||
})
|
||||
debug := newCapturedDebugRecorder()
|
||||
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Debug: debug}); err != nil {
|
||||
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input")}); err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
|
||||
@@ -100,40 +100,26 @@ func TestRunnerBuildsEvidenceContextFromSelectedNormalizedOutputs(t *testing.T)
|
||||
if actual := []int{value[0].ID, value[1].ID, value[2].ID}; !reflect.DeepEqual(actual, []int{1, 2, 3}) {
|
||||
t.Fatalf("evidence context = %#v, want selected union", value)
|
||||
}
|
||||
debugJSON := string(debug.json["output/evidence-context.json"])
|
||||
if strings.Contains(debugJSON, "text-1") || strings.Contains(debugJSON, "metadata") || !strings.Contains(debugJSON, `"artifact_kind":"source/evidence-context"`) || !strings.Contains(debugJSON, `"schema_id":"notarius.source.evidence_context"`) || strings.Contains(debugJSON, "context_count") || !strings.Contains(debugJSON, `"unit_count":3`) {
|
||||
t.Fatalf("evidence debug envelope = %s, want only allowlisted summary", debugJSON)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRunnerEvidenceContextOmitsAbsentAndRejectedLanes(t *testing.T) {
|
||||
prepared := preparedOrderedPipeline(t, 2, orderedLaneSpec{id: "present", profile: "notes"}, orderedLaneSpec{id: "rejected", profile: "notes"})
|
||||
encoder := &capturingEvidenceOutput{}
|
||||
prepared.output = encoder
|
||||
setNormalizedNotes(prepared, map[string]codecNotes{"present": {Items: []string{"present"}}, "rejected": {Items: []string{"rejected"}}})
|
||||
prepared.Steps[1].lanes[0].mergeValidators.validators = []preparedValidator{{
|
||||
resolved: ResolvedValidator{Binding: Binding("reject"), Target: ValidatorTargetTyped, ArtifactKind: "test/notes"},
|
||||
typedValidate: func(context.Context, any, typedValidationTarget) (contracts.ValidationResult, error) {
|
||||
return contracts.ValidationResult{Approved: false, ReasonCode: "rejected", Message: "not accepted", CorrectionGuidance: "return an acceptable candidate"}, nil
|
||||
},
|
||||
}}
|
||||
prepared.Steps[1].lanes[0].resolved.MergeValidationPolicy.SemanticRejection = SemanticRejectionRejectOutput
|
||||
installEvidencePlan(prepared, 0, []string{"absent", "present", "rejected"}, func(notes codecNotes) ([]source.SourceRef, error) {
|
||||
if len(notes.Items) > 0 && notes.Items[0] == "present" {
|
||||
return []source.SourceRef{{SourceID: "source", StartUnitID: 1, EndUnitID: 1}}, nil
|
||||
}
|
||||
return []source.SourceRef{{SourceID: "source", StartUnitID: 2, EndUnitID: 2}}, nil
|
||||
func TestEvidenceContextOmitsUnselectedAndAbsentLanes(t *testing.T) {
|
||||
prepared := preparedOrderedPipeline(t, 2, orderedLaneSpec{id: "present", profile: "notes"}, orderedLaneSpec{id: "unselected", profile: "notes"})
|
||||
doc := prepared.input.(*typedTestInput).doc
|
||||
installEvidencePlan(prepared, 0, []string{"absent", "present"}, func(codecNotes) ([]source.SourceRef, error) {
|
||||
return []source.SourceRef{{SourceID: doc.ID, StartUnitID: 1, EndUnitID: 1}}, nil
|
||||
})
|
||||
result, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input")})
|
||||
artifact, err := prepared.artifactCodecs.Encode("test/notes", codecNotes{Items: []string{"accepted"}})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(result.Rejected) != 1 || result.Rejected[0].LaneID != "rejected" {
|
||||
t.Fatalf("rejections = %#v, want rejected lane unchanged", result.Rejected)
|
||||
result, _, err := buildOutputEvidenceContext(prepared, doc, []contracts.SerializedOutput{{LaneID: "present", SourceID: doc.ID, Artifact: artifact}, {LaneID: "unselected", SourceID: doc.ID, Artifact: artifact}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
value := decodeCapturedEvidence(t, encoder)
|
||||
if len(value) != 1 || value[0].ID != 1 {
|
||||
t.Fatalf("evidence context = %#v, want present lane only", value)
|
||||
value, err := evidencecontext.New().Decode(result.Content)
|
||||
if err != nil || len(value) != 1 || value[0].ID != 1 {
|
||||
t.Fatalf("evidence=%#v %v", value, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,8 +135,8 @@ func TestRunnerEvidenceContextFailurePreventsOutputEncoding(t *testing.T) {
|
||||
if err == nil || !strings.Contains(err.Error(), "accepted evidence references are invalid") {
|
||||
t.Fatalf("Run() error = %v, want evidence context failure", err)
|
||||
}
|
||||
if len(encoder.requests) != 0 || result.Manifest.ValidationStatus != "failed" || len(result.Rejected) != 0 {
|
||||
t.Fatalf("output requests = %#v manifest = %#v rejected = %#v, want failed run before output encoding", encoder.requests, result.Manifest, result.Rejected)
|
||||
if len(encoder.requests) != 0 || result.ArtifactCount() != 0 {
|
||||
t.Fatalf("invalid evidence was published: %#v", result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,33 +191,50 @@ func TestEvidenceContextOutputRequestOwnsArtifactBytes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerEvidenceContextRebuildsFromAcceptedCheckpoint(t *testing.T) {
|
||||
func TestRunnerEvidenceContextRebuildsFromCachedNormalizedArtifact(t *testing.T) {
|
||||
prepared := preparedConcurrentPipeline(t, 1)
|
||||
encoder := &capturingEvidenceOutput{}
|
||||
prepared.output = encoder
|
||||
doc := prepared.input.(*typedTestInput).doc
|
||||
lane := prepared.Steps[0].lanes[0]
|
||||
stored, err := checkpointArtifact(lane.typed.codec, lane.resolved.ID, lane.resolved.Normalize.Module, doc.ID, codecNotes{Items: []string{"stored"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
calls, assessments := 0, 0
|
||||
engine := nativeProducerEngine(t, producerClientFunc(func(context.Context, promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
||||
calls++
|
||||
return &promptkit.GenerateResponse{Content: `{"value":1}`}, nil
|
||||
}))
|
||||
lane := &prepared.Steps[0].lanes[0]
|
||||
lane.resolved.NormalizeExecutionClass = contracts.ExecutionClassLLMBacked
|
||||
lane.typed.normalize = func(ctx context.Context, _ any, request contracts.TypedNormalizeRequest[any]) (erasedTypedResult, error) {
|
||||
operation := request.Operation
|
||||
assess := operation.Assess
|
||||
operation.Assess = func(ctx context.Context, value any) (contracts.CandidateAssessment, error) {
|
||||
assessments++
|
||||
return assess(ctx, value)
|
||||
}
|
||||
value, outcome, err := RunProducer(ctx, engine, operation, nativeProducerInitial(), func(context.Context, *promptkit.RunResult) (*any, []string, error) {
|
||||
var value any = codecNotes{Items: []string{"stored"}}
|
||||
return &value, nil, nil
|
||||
}, nil, nil)
|
||||
return erasedTypedResult{Value: value, Outcome: outcome}, err
|
||||
}
|
||||
loader := newAcceptedCheckpointLoader()
|
||||
key := CheckpointLaneKey(lane.resolved.StepID, lane.resolved.ID)
|
||||
loader.accepted[key] = NormalizeCheckpoint{Output: stored}
|
||||
loader.acceptedDecision[key] = NewCheckpointDecision(CheckpointDecisionReused, CheckpointReasonAcceptedArtifactReused)
|
||||
installEvidencePlan(prepared, 0, []string{"notes"}, func(notes codecNotes) ([]source.SourceRef, error) {
|
||||
if !reflect.DeepEqual(notes.Items, []string{"stored"}) {
|
||||
return nil, errors.New("checkpoint artifact was not projected")
|
||||
return nil, errors.New("cached artifact was not projected")
|
||||
}
|
||||
return []source.SourceRef{{SourceID: doc.ID, StartUnitID: 1, EndUnitID: 1}}, nil
|
||||
})
|
||||
policy := CheckpointExecutionPolicy{RequireReusableLanes: map[string]struct{}{key: {}}}
|
||||
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Checkpoint: loader, CheckpointPolicy: policy}); err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
_, store := filesystemProducerCache(t)
|
||||
for range 2 {
|
||||
encoder.requests = nil
|
||||
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Cache: store, Workers: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
value := decodeCapturedEvidence(t, encoder)
|
||||
if len(value) != 1 || value[0].ID != 1 {
|
||||
t.Fatalf("evidence=%#v", value)
|
||||
}
|
||||
}
|
||||
value := decodeCapturedEvidence(t, encoder)
|
||||
if len(value) != 1 || value[0].ID != 1 {
|
||||
t.Fatalf("evidence context = %#v, want checkpointed normalized output", value)
|
||||
if calls != 1 || assessments != 1 {
|
||||
t.Fatalf("cache reuse calls=%d assessments=%d", calls, assessments)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ func (output testEvidenceOutput) EvidenceContextPolicy() EvidenceContextPolicy {
|
||||
}
|
||||
|
||||
func TestEvidencePolicyResolutionAndPreparationSurviveLaneFiltering(t *testing.T) {
|
||||
registries, _ := constructionRegistries(t, nil, nil)
|
||||
registries := registriesFromModuleCatalog(typedResolutionCatalog(t, completeTypedCatalogOptions()))
|
||||
registries.ArtifactEvidence = NewArtifactEvidenceRegistry()
|
||||
policy := EvidenceContextPolicy{Enabled: true, WindowUnits: 2, LaneIDs: []string{"artifact", "inactive"}}
|
||||
policy := EvidenceContextPolicy{Enabled: true, WindowUnits: 2, LaneIDs: []string{"notes", "inactive"}}
|
||||
profileValidated := false
|
||||
registerTestEvidenceOutputWithProfileValidation(t, ®istries, policy, func(context OutputProfileOptionContext, _ map[string]any) error {
|
||||
profileValidated = true
|
||||
if want := []string{"artifact", "inactive"}; !reflect.DeepEqual(context.LaneIDs, want) {
|
||||
if want := []string{"inactive", "notes"}; !reflect.DeepEqual(context.LaneIDs, want) {
|
||||
return fmt.Errorf("configured lane ids = %#v, want %#v", context.LaneIDs, want)
|
||||
}
|
||||
return nil
|
||||
@@ -38,31 +38,33 @@ func TestEvidencePolicyResolutionAndPreparationSurviveLaneFiltering(t *testing.T
|
||||
if err := RegisterArtifactEvidence(registries.ArtifactEvidence, "test/notes", func(codecNotes) []source.SourceRef { return nil }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
profile := constructionProfile()
|
||||
profile.Artifacts["inactive"] = profile.Artifacts["artifact"]
|
||||
profile := typedResolutionProfile()
|
||||
delete(profile.Artifacts, "score")
|
||||
profile.Output = Binding("output")
|
||||
profile.Artifacts["inactive"] = profile.Artifacts["notes"]
|
||||
profile.Output.Options = map[string]any{"known": true}
|
||||
resolved, err := ResolvePipeline(profile, ResolveOptions{Only: []string{"artifact"}}, registries.catalog())
|
||||
resolved, err := ResolvePipeline(profile, ResolveOptions{Only: []string{"notes"}}, registries.catalog())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !profileValidated {
|
||||
t.Fatal("output profile options were not validated")
|
||||
}
|
||||
if lanes := resolved.AllArtifactLanes(); len(lanes) != 1 || lanes[0].ID != "artifact" {
|
||||
if lanes := resolved.AllArtifactLanes(); len(lanes) != 1 || lanes[0].ID != "notes" {
|
||||
t.Fatalf("resolved lanes = %#v, want only the invocation-selected lane", lanes)
|
||||
}
|
||||
prepared, err := Prepare(resolved, registries, ModuleDependencies{})
|
||||
if err != nil {
|
||||
t.Fatalf("Prepare() error = %v, want nil", err)
|
||||
}
|
||||
if prepared.evidencePlan == nil || !reflect.DeepEqual(prepared.evidencePlan.policy.LaneIDs, []string{"artifact", "inactive"}) {
|
||||
if prepared.evidencePlan == nil || !reflect.DeepEqual(prepared.evidencePlan.policy.LaneIDs, []string{"inactive", "notes"}) {
|
||||
t.Fatalf("evidence plan = %#v, want complete configured policy", prepared.evidencePlan)
|
||||
}
|
||||
if got := prepared.evidencePlan.lanes; len(got) != 1 || got[0].laneID != "artifact" {
|
||||
if got := prepared.evidencePlan.lanes; len(got) != 1 || got[0].laneID != "notes" {
|
||||
t.Fatalf("active evidence lanes = %#v, want artifact only", got)
|
||||
}
|
||||
prepared.evidencePlan.policy.LaneIDs[0] = "mutated"
|
||||
if policy := prepared.output.(EvidenceContextPolicyProvider).EvidenceContextPolicy(); policy.LaneIDs[0] != "artifact" {
|
||||
if policy := prepared.output.(EvidenceContextPolicyProvider).EvidenceContextPolicy(); policy.LaneIDs[0] != "notes" {
|
||||
t.Fatalf("prepared plan mutated provider policy: %#v", policy)
|
||||
}
|
||||
}
|
||||
@@ -82,11 +84,13 @@ func TestPrepareEvidencePlanRejectsMissingAndMismatchedCapabilities(t *testing.T
|
||||
}, want: "requires Go type"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
registries, _ := constructionRegistries(t, nil, nil)
|
||||
registries := registriesFromModuleCatalog(typedResolutionCatalog(t, completeTypedCatalogOptions()))
|
||||
registries.ArtifactEvidence = NewArtifactEvidenceRegistry()
|
||||
registerTestEvidenceOutput(t, ®istries, EvidenceContextPolicy{Enabled: true, LaneIDs: []string{"artifact"}})
|
||||
registerTestEvidenceOutput(t, ®istries, EvidenceContextPolicy{Enabled: true, LaneIDs: []string{"notes"}})
|
||||
test.configure(®istries)
|
||||
profile := constructionProfile()
|
||||
profile := typedResolutionProfile()
|
||||
delete(profile.Artifacts, "score")
|
||||
profile.Output = Binding("output")
|
||||
profile.Output.Options = map[string]any{"known": true}
|
||||
resolved, err := ResolvePipeline(profile, ResolveOptions{}, registries.catalog())
|
||||
if err != nil {
|
||||
@@ -108,7 +112,7 @@ func registerTestEvidenceOutput(t *testing.T, registries *Registries, policy Evi
|
||||
func registerTestEvidenceOutputWithProfileValidation(t *testing.T, registries *Registries, policy EvidenceContextPolicy, validateProfile OutputProfileOptionValidator) {
|
||||
t.Helper()
|
||||
registry := NewOutputEncoderRegistry()
|
||||
if err := registry.RegisterBuilderWithProfileValidation(testModuleSpec("output", StageOutput), func(options map[string]any) error {
|
||||
if err := registry.RegisterBuilderWithProfileValidation(ModuleSpec{Key: "output", Stage: StageOutput, ExecutionClass: contracts.ExecutionClassDeterministic}, func(options map[string]any) error {
|
||||
return RejectUnknownOptions(options, "known")
|
||||
}, validateProfile, func(BuildRequest) (contracts.OutputEncoder, error) {
|
||||
return testEvidenceOutput{policy: cloneEvidenceContextPolicy(policy)}, nil
|
||||
|
||||
@@ -2,10 +2,8 @@ package pipeline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
@@ -89,12 +87,11 @@ func buildStepReferenceReuseEligibility(step PreparedPipelineStep, outputs map[g
|
||||
// buildStepReferenceSets resolves every generated binding for a step before
|
||||
// any lane in that step is allowed to start. Each returned set is a fresh
|
||||
// operation-time view; prepared reference sets are never modified.
|
||||
func buildStepReferenceSets(input RunInput, step PreparedPipelineStep, outputs []contracts.SerializedOutput) (map[referenceTargetKey]contracts.ReferenceSet, []artifacts.ReferenceProvenance, error) {
|
||||
func buildStepReferenceSets(input RunInput, step PreparedPipelineStep, outputs []contracts.SerializedOutput) (map[referenceTargetKey]contracts.ReferenceSet, error) {
|
||||
if len(step.lanes) == 0 {
|
||||
return nil, nil, nil
|
||||
return nil, nil
|
||||
}
|
||||
sets := make(map[referenceTargetKey]contracts.ReferenceSet)
|
||||
var provenance []artifacts.ReferenceProvenance
|
||||
outputsByProducer := indexGeneratedOutputs(outputs)
|
||||
canonical := make(map[generatedOutputKey]contracts.ReferenceItem)
|
||||
for _, prepared := range step.lanes {
|
||||
@@ -109,24 +106,24 @@ func buildStepReferenceSets(input RunInput, step PreparedPipelineStep, outputs [
|
||||
generated = true
|
||||
item, err := generatedReferenceItem(input, binding, outputsByProducer, canonical)
|
||||
if err != nil {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, err)
|
||||
return nil, contextualHandoffError(input, target, binding, err)
|
||||
}
|
||||
slotName := strings.TrimSpace(binding.SlotName)
|
||||
slot, ok := resolved.Slots[slotName]
|
||||
if !ok {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q has no resolved declaration", slotName))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q has no resolved declaration", slotName))
|
||||
}
|
||||
if len(slot.Items) > 0 {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q already contains materialized items", slotName))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q already contains materialized items", slotName))
|
||||
}
|
||||
if len(slot.Slot.AcceptedArtifactKinds) == 0 || !containsArtifactKind(slot.Slot.AcceptedArtifactKinds, item.ArtifactKind) {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q does not accept artifact kind %q", slotName, item.ArtifactKind))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q does not accept artifact kind %q", slotName, item.ArtifactKind))
|
||||
}
|
||||
if !referenceMediaTypeAccepted(item.MediaType, slot.Slot.AcceptedMediaTypes) {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q does not accept media type %q", slotName, item.MediaType))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q does not accept media type %q", slotName, item.MediaType))
|
||||
}
|
||||
if slot.Slot.MaxBytes > 0 && item.SizeBytes > slot.Slot.MaxBytes {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q is %d bytes, limit %d", slotName, item.SizeBytes, slot.Slot.MaxBytes))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q is %d bytes, limit %d", slotName, item.SizeBytes, slot.Slot.MaxBytes))
|
||||
}
|
||||
slot.Items = []contracts.ReferenceItem{contracts.CloneReferenceItem(item)}
|
||||
resolved.Slots[slotName] = slot
|
||||
@@ -136,12 +133,9 @@ func buildStepReferenceSets(input RunInput, step PreparedPipelineStep, outputs [
|
||||
}
|
||||
key := keyForReferenceTarget(target)
|
||||
sets[key] = resolved
|
||||
for _, item := range generatedItems(resolved) {
|
||||
provenance = append(provenance, referenceProvenanceForItem(target, item))
|
||||
}
|
||||
}
|
||||
}
|
||||
return sets, provenance, nil
|
||||
return sets, nil
|
||||
}
|
||||
|
||||
func containsArtifactKind(kinds []contracts.ArtifactKind, want contracts.ArtifactKind) bool {
|
||||
@@ -257,44 +251,3 @@ func findResolvedLane(pipeline ResolvedPipeline, stepID, laneID string) (Resolve
|
||||
}
|
||||
return ResolvedArtifactLane{}, false
|
||||
}
|
||||
|
||||
func generatedItems(set contracts.ReferenceSet) []contracts.ReferenceItem {
|
||||
var items []contracts.ReferenceItem
|
||||
keys := make([]string, 0, len(set.Slots))
|
||||
for key := range set.Slots {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
for _, item := range set.Slots[key].Items {
|
||||
if item.Origin.Type == "generated" {
|
||||
items = append(items, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func referenceProvenanceForItem(target ResolvedReferenceTarget, item contracts.ReferenceItem) artifacts.ReferenceProvenance {
|
||||
return artifacts.ReferenceProvenance{
|
||||
Stage: string(target.Stage),
|
||||
StepID: target.StepID,
|
||||
LaneID: target.LaneID,
|
||||
SlotName: item.SlotName,
|
||||
OriginType: item.Origin.Type,
|
||||
OriginURI: item.Origin.URI,
|
||||
Digest: item.Digest,
|
||||
MediaType: item.MediaType,
|
||||
SizeBytes: item.SizeBytes,
|
||||
BindingSource: item.BindingSource,
|
||||
ArtifactKind: string(item.ArtifactKind),
|
||||
SchemaID: item.ArtifactSchema.ID,
|
||||
SchemaName: item.ArtifactSchema.Name,
|
||||
SchemaVersion: item.ArtifactSchema.Version,
|
||||
SchemaDigest: contracts.DigestArtifactSchema(item.ArtifactSchema),
|
||||
ProducerPipeline: item.Producer.PipelineID,
|
||||
ProducerStep: item.Producer.StepID,
|
||||
ProducerLane: item.Producer.LaneID,
|
||||
ProducerModule: item.Producer.ModuleKey,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ func TestRunnerWorkersAndNativeBackendAdmissionAreIndependent(t *testing.T) {
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: limits.workers})
|
||||
if err == nil && len(output.NormalizeOutputs) != 2 {
|
||||
err = fmt.Errorf("got %d lane outputs", len(output.NormalizeOutputs))
|
||||
if err == nil && len(output.normalizeOutputs) != 2 {
|
||||
err = fmt.Errorf("got %d lane outputs", len(output.normalizeOutputs))
|
||||
}
|
||||
done <- err
|
||||
}()
|
||||
@@ -251,8 +251,8 @@ func TestRunnerNativeCapacityFailureUsesOperationModeWithoutAnotherQueue(t *test
|
||||
if !errors.As(err, &capacity) || output.FallbackCount != 0 || len(output.OutputFiles) != 0 {
|
||||
t.Fatalf("strict capacity failure = %v, fallbacks %d", err, output.FallbackCount)
|
||||
}
|
||||
} else if err != nil || output.FallbackCount != 2 || len(output.NormalizeOutputs) != 2 {
|
||||
t.Fatalf("permissive capacity failure = %v, fallbacks %d, outputs %d", err, output.FallbackCount, len(output.NormalizeOutputs))
|
||||
} else if err != nil || output.FallbackCount != 2 || len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("permissive capacity failure = %v, fallbacks %d, outputs %d", err, output.FallbackCount, len(output.normalizeOutputs))
|
||||
}
|
||||
if calls.Load() != 1 {
|
||||
t.Fatalf("capacity handling invoked provider %d times", calls.Load())
|
||||
@@ -288,7 +288,7 @@ func TestRunnerCancellationDrainsNativeWorkAndReleasesAdmission(t *testing.T) {
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 3})
|
||||
if output.FallbackCount != 0 || len(output.NormalizeOutputs) != 0 {
|
||||
if output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 {
|
||||
err = fmt.Errorf("cancellation delivered output: %v", err)
|
||||
}
|
||||
done <- err
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
@@ -379,61 +378,3 @@ func CloneReferenceTarget(in ResolvedReferenceTarget) ResolvedReferenceTarget {
|
||||
out.ReferenceSet = CloneReferenceSet(in.ReferenceSet)
|
||||
return out
|
||||
}
|
||||
|
||||
func ReferenceProvenance(resolved ResolvedPipeline) []artifacts.ReferenceProvenance {
|
||||
provenance := []artifacts.ReferenceProvenance{}
|
||||
provenance = append(provenance, referenceTargetProvenance(resolved.ChunkReferences)...)
|
||||
if len(resolved.Steps) > 0 {
|
||||
for _, step := range resolved.Steps {
|
||||
for _, lane := range step.ArtifactLanes {
|
||||
provenance = append(provenance, referenceTargetProvenance(lane.ExtractReferences)...)
|
||||
provenance = append(provenance, referenceTargetProvenance(lane.MergeReferences)...)
|
||||
provenance = append(provenance, referenceTargetProvenance(lane.NormalizeReferences)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
return provenance
|
||||
}
|
||||
|
||||
func referenceTargetProvenance(target ResolvedReferenceTarget) []artifacts.ReferenceProvenance {
|
||||
if len(target.ReferenceSet.Slots) == 0 {
|
||||
return nil
|
||||
}
|
||||
provenance := []artifacts.ReferenceProvenance{}
|
||||
slotNames := make([]string, 0, len(target.ReferenceSet.Slots))
|
||||
for slotName := range target.ReferenceSet.Slots {
|
||||
slotNames = append(slotNames, slotName)
|
||||
}
|
||||
sort.Strings(slotNames)
|
||||
for _, slotName := range slotNames {
|
||||
slot := target.ReferenceSet.Slots[slotName]
|
||||
for _, item := range slot.Items {
|
||||
schemaDigest := ""
|
||||
if item.ArtifactSchema.ID != "" || item.ArtifactSchema.Name != "" || item.ArtifactSchema.Version != "" || len(item.ArtifactSchema.JSONSchema) > 0 {
|
||||
schemaDigest = contracts.DigestArtifactSchema(item.ArtifactSchema)
|
||||
}
|
||||
provenance = append(provenance, artifacts.ReferenceProvenance{
|
||||
Stage: string(target.Stage),
|
||||
StepID: target.StepID,
|
||||
LaneID: target.LaneID,
|
||||
SlotName: item.SlotName,
|
||||
OriginType: item.Origin.Type,
|
||||
OriginURI: item.Origin.URI,
|
||||
Digest: item.Digest,
|
||||
MediaType: item.MediaType,
|
||||
SizeBytes: item.SizeBytes,
|
||||
BindingSource: item.BindingSource,
|
||||
ArtifactKind: string(item.ArtifactKind),
|
||||
SchemaID: item.ArtifactSchema.ID,
|
||||
SchemaName: item.ArtifactSchema.Name,
|
||||
SchemaVersion: item.ArtifactSchema.Version,
|
||||
SchemaDigest: schemaDigest,
|
||||
ProducerPipeline: item.Producer.PipelineID,
|
||||
ProducerStep: item.Producer.StepID,
|
||||
ProducerLane: item.Producer.LaneID,
|
||||
ProducerModule: item.Producer.ModuleKey,
|
||||
})
|
||||
}
|
||||
}
|
||||
return provenance
|
||||
}
|
||||
|
||||
@@ -8,11 +8,9 @@ import (
|
||||
"mime"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/chunkmap"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
@@ -53,7 +51,6 @@ type RunInput struct {
|
||||
SessionID string
|
||||
RunID string
|
||||
StartedAt time.Time
|
||||
LLMProfiles []artifacts.LLMProfileManifest
|
||||
Metadata map[string]any
|
||||
Diagnostics []contracts.ProducerDiagnostic
|
||||
|
||||
@@ -71,20 +68,22 @@ type RunInput struct {
|
||||
}
|
||||
|
||||
type RunOutput struct {
|
||||
FallbackCount int `json:"fallback_count,omitempty"`
|
||||
Manifest artifacts.RunManifest `json:"manifest"`
|
||||
FallbackCount int `json:"fallback_count,omitempty"`
|
||||
|
||||
NormalizeOutputs []contracts.SerializedOutput `json:"normalize_outputs,omitempty"`
|
||||
Rejected []contracts.RejectedOutput `json:"rejected,omitempty"`
|
||||
Diagnostics contracts.DiagnosticCollection `json:"diagnostics,omitempty"`
|
||||
OutputFiles []contracts.OutputFile `json:"-"`
|
||||
|
||||
ValidationSummaries []artifacts.ValidationSummary `json:"validation_summaries,omitempty"`
|
||||
Diagnostics contracts.DiagnosticCollection `json:"diagnostics,omitempty"`
|
||||
OutputFiles []contracts.OutputFile `json:"-"`
|
||||
|
||||
normalizeOutputs []contracts.SerializedOutput
|
||||
normalizeReuseEligibility map[generatedOutputKey]bool
|
||||
diagnosticGroups []contracts.DiagnosticGroup
|
||||
}
|
||||
|
||||
// ArtifactCount counts logical deliverables, not intermediate lane values,
|
||||
// cache entries, diagnostic records, or debug files.
|
||||
func (output RunOutput) ArtifactCount() int {
|
||||
return len(output.OutputFiles)
|
||||
}
|
||||
|
||||
func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err error) {
|
||||
if r == nil {
|
||||
return output, fmt.Errorf("runner must not be nil")
|
||||
@@ -101,12 +100,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
}
|
||||
input.pipeline = input.Prepared.resolved
|
||||
|
||||
output.Manifest = manifestFromPipeline(input)
|
||||
sessionID := strings.TrimSpace(input.SessionID)
|
||||
output.Manifest.Metadata, err = manifestMetadataWithSessionID(output.Manifest.Metadata, sessionID)
|
||||
if err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
debugRecorder := input.Debug
|
||||
if debugRecorder == nil {
|
||||
debugRecorder = NoopDebugRecorder()
|
||||
@@ -124,16 +118,13 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
Payload: map[string]any{
|
||||
"pipeline_id": input.pipeline.ID,
|
||||
"pipeline_digest": input.pipeline.Digest,
|
||||
"run_id": output.Manifest.RunID,
|
||||
"run_id": input.RunID,
|
||||
},
|
||||
}); err != nil {
|
||||
return failOutput(output), fmt.Errorf("write debug run artifact: %w", err)
|
||||
}
|
||||
|
||||
adapter := input.Prepared.input
|
||||
if err := attachModuleManifestMetadata(&output, "input", adapter); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
var doc *source.SourceDocument
|
||||
sourceStarted := time.Now().UTC()
|
||||
if err := writeDebugTimed(debugRecorder, "source/input.json", debugTimedEnvelope{
|
||||
@@ -182,12 +173,8 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
return failOutput(output), fmt.Errorf("write source debug artifact: %w", err)
|
||||
}
|
||||
sourceInput := sourceInputMaterial(input.Path, input.RawInput)
|
||||
output.Manifest.SourceDigests = []string{doc.Digest}
|
||||
|
||||
chunker := input.Prepared.chunker
|
||||
if err := attachModuleManifestMetadata(&output, "chunker", chunker); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
chunkStarted := time.Now().UTC()
|
||||
if err := writeDebugTimed(debugRecorder, "chunk/input.json", debugTimedEnvelope{
|
||||
Stage: string(StageChunk),
|
||||
@@ -264,28 +251,16 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
return failOutput(output), err
|
||||
}
|
||||
|
||||
if len(output.Rejected) > 0 {
|
||||
output.Manifest.ValidationStatus = "rejected"
|
||||
} else if output.FallbackCount > 0 || hasIncompleteValidation(output.ValidationSummaries) {
|
||||
output.Manifest.ValidationStatus = "incomplete"
|
||||
} else {
|
||||
output.Manifest.ValidationStatus = "approved"
|
||||
}
|
||||
populateOutputManifest(&output)
|
||||
output.Manifest.CompletedAt = timePtr(time.Now().UTC())
|
||||
if err := finalizeDiagnostics(&output); err != nil {
|
||||
return failOutput(output), fmt.Errorf("aggregate diagnostics: %w", err)
|
||||
}
|
||||
|
||||
encoder := input.Prepared.output
|
||||
if err := attachModuleManifestMetadata(&output, "output", encoder); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
outputStarted := time.Now().UTC()
|
||||
evidenceArtifact, evidenceSummary, err := buildOutputEvidenceContext(input.Prepared, doc, output.NormalizeOutputs)
|
||||
evidenceArtifact, evidenceSummary, err := buildOutputEvidenceContext(input.Prepared, doc, output.normalizeOutputs)
|
||||
if err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
@@ -306,9 +281,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
}
|
||||
}
|
||||
outputDebugPayload := map[string]any{
|
||||
"manifest": output.Manifest,
|
||||
"normalize_outputs": debugSerializedOutputEnvelopes(output.NormalizeOutputs),
|
||||
"rejected": debugRejectedOutputEnvelopes(output.Rejected),
|
||||
"normalize_outputs": debugSerializedOutputEnvelopes(output.normalizeOutputs),
|
||||
"options": redactSensitiveMap(input.pipeline.Output.Options),
|
||||
"metadata": redactSensitiveMap(input.Metadata),
|
||||
}
|
||||
@@ -326,20 +299,8 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
if err := ctx.Err(); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
outputMetadata, err := cloneMetadata(input.Metadata)
|
||||
if err != nil {
|
||||
return failOutput(output), fmt.Errorf("clone output encoder metadata: %w", err)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
encoded, err := encoder.Encode(ctx, contracts.OutputRequest{
|
||||
Manifest: output.Manifest,
|
||||
NormalizeOutputs: cloneSerializedOutputs(output.NormalizeOutputs),
|
||||
Rejected: cloneRejectedOutputs(output.Rejected),
|
||||
Diagnostics: contracts.CloneDiagnosticCollection(output.Diagnostics),
|
||||
LLMProfile: input.pipeline.Output.LLMProfile,
|
||||
Metadata: outputMetadata,
|
||||
NormalizeOutputs: cloneSerializedOutputs(output.normalizeOutputs),
|
||||
ChunkMap: contracts.CloneSerializedArtifactPointer(acceptedChunkMap),
|
||||
EvidenceContext: contracts.CloneSerializedArtifactPointer(evidenceArtifact),
|
||||
})
|
||||
@@ -371,30 +332,18 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func hasIncompleteValidation(summaries []artifacts.ValidationSummary) bool {
|
||||
for _, summary := range summaries {
|
||||
if summary.Status == "incomplete" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *Runner) runPreparedSteps(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, output *RunOutput) error {
|
||||
for _, step := range input.Prepared.Steps {
|
||||
stepInput := input
|
||||
stepInput.stepID = step.ID
|
||||
stepReferences, referenceProvenance, err := buildStepReferenceSets(input, step, output.NormalizeOutputs)
|
||||
stepReferences, err := buildStepReferenceSets(input, step, output.normalizeOutputs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("prepare generated references for pipeline step %q: %w", step.ID, err)
|
||||
}
|
||||
stepInput.references = stepReferences
|
||||
stepInput.referenceReuseEligibility = buildStepReferenceReuseEligibility(step, output.normalizeReuseEligibility)
|
||||
output.Manifest.References = append(output.Manifest.References, referenceProvenance...)
|
||||
laneOutput, laneErr := r.runLanes(ctx, stepInput, step, doc, sourceInput, sessionID, chunks)
|
||||
if err := mergeLaneOutput(output, laneOutput); err != nil {
|
||||
return err
|
||||
}
|
||||
mergeLaneOutput(output, laneOutput)
|
||||
if laneErr != nil {
|
||||
return fmt.Errorf("execute pipeline step %q: %w", step.ID, laneErr)
|
||||
}
|
||||
@@ -486,174 +435,14 @@ func startedTime(t time.Time) time.Time {
|
||||
return t.UTC()
|
||||
}
|
||||
|
||||
func manifestFromPipeline(input RunInput) artifacts.RunManifest {
|
||||
startedAt := input.StartedAt
|
||||
if startedAt.IsZero() {
|
||||
startedAt = time.Now().UTC()
|
||||
}
|
||||
runID := strings.TrimSpace(input.RunID)
|
||||
if runID == "" {
|
||||
runID = fmt.Sprintf("run-%d", startedAt.UnixNano())
|
||||
}
|
||||
|
||||
pipeline := input.pipeline
|
||||
manifest := artifacts.RunManifest{
|
||||
PipelineID: pipeline.ID,
|
||||
PipelineDigest: pipeline.Digest,
|
||||
InputModule: pipeline.Input.Module,
|
||||
Chunker: pipeline.Chunk.Module,
|
||||
ChunkPlan: &artifacts.ChunkPlanManifest{
|
||||
Mode: string(pipeline.ChunkControls.Cache),
|
||||
RequestedModule: pipeline.Chunk.Module,
|
||||
},
|
||||
OutputEncoder: pipeline.Output.Module,
|
||||
ArtifactLanes: make([]artifacts.ArtifactLaneManifest, 0, len(pipeline.AllArtifactLanes())),
|
||||
ValidatorChains: validatorChainManifests(pipeline.ValidatorChains),
|
||||
RunID: runID,
|
||||
StartedAt: timePtr(startedAt),
|
||||
References: ReferenceProvenance(pipeline),
|
||||
LLMProfiles: cloneLLMProfiles(input.LLMProfiles),
|
||||
}
|
||||
for _, lane := range pipeline.AllArtifactLanes() {
|
||||
laneManifest := artifacts.ArtifactLaneManifest{
|
||||
StepID: lane.StepID,
|
||||
ID: lane.ID,
|
||||
Extractor: lane.Extract.Module,
|
||||
Merger: lane.Merge.Module,
|
||||
Normalizer: lane.Normalize.Module,
|
||||
}
|
||||
manifest.ArtifactLanes = append(manifest.ArtifactLanes, laneManifest)
|
||||
}
|
||||
return manifest
|
||||
}
|
||||
|
||||
func validatorChainManifests(chains []ResolvedValidatorChain) []artifacts.ValidatorChainManifest {
|
||||
if len(chains) == 0 {
|
||||
return nil
|
||||
}
|
||||
manifests := make([]artifacts.ValidatorChainManifest, 0, len(chains))
|
||||
for _, chain := range chains {
|
||||
manifest := artifacts.ValidatorChainManifest{
|
||||
Stage: string(chain.Stage),
|
||||
LaneID: chain.LaneID,
|
||||
ModuleKey: chain.ModuleKey,
|
||||
Validators: make([]artifacts.ValidatorManifest, 0, len(chain.Validators)),
|
||||
}
|
||||
for _, validator := range chain.Validators {
|
||||
manifest.Validators = append(manifest.Validators, artifacts.ValidatorManifest{
|
||||
Key: validator.Binding.Module,
|
||||
ExecutionClass: string(validator.ExecutionClass),
|
||||
})
|
||||
}
|
||||
manifests = append(manifests, manifest)
|
||||
}
|
||||
return manifests
|
||||
}
|
||||
|
||||
func failOutput(output RunOutput) RunOutput {
|
||||
// Preserve any diagnostics already accepted by the pipeline when a later
|
||||
// operation fails. Producers and validators validate each diagnostic before
|
||||
// it is appended, so finalization here cannot introduce a new failure path.
|
||||
_ = finalizeDiagnostics(&output)
|
||||
if output.Manifest.PipelineID != "" {
|
||||
populateOutputManifest(&output)
|
||||
output.Manifest.ValidationStatus = "failed"
|
||||
output.Manifest.CompletedAt = timePtr(time.Now().UTC())
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func populateOutputManifest(output *RunOutput) {
|
||||
if output == nil {
|
||||
return
|
||||
}
|
||||
output.Manifest.NormalizedOutputs = normalizedOutputManifests(output.NormalizeOutputs)
|
||||
output.Manifest.RejectedOutputs = rejectedOutputManifests(output.Rejected)
|
||||
if len(output.ValidationSummaries) > 0 {
|
||||
output.Manifest.ValidationSummaries = cloneValidationSummaries(output.ValidationSummaries)
|
||||
}
|
||||
}
|
||||
|
||||
func normalizedOutputManifests(outputs []contracts.SerializedOutput) []artifacts.NormalizedOutputManifest {
|
||||
if len(outputs) == 0 {
|
||||
return nil
|
||||
}
|
||||
manifests := make([]artifacts.NormalizedOutputManifest, 0, len(outputs))
|
||||
for _, output := range outputs {
|
||||
manifests = append(manifests, artifacts.NormalizedOutputManifest{
|
||||
StepID: output.StepID,
|
||||
LaneID: output.LaneID,
|
||||
ModuleKey: output.NormalizerKey,
|
||||
SourceID: output.SourceID,
|
||||
MediaType: output.Artifact.MediaType,
|
||||
Schema: artifacts.OutputSchemaProvenance{
|
||||
ID: output.Artifact.Schema.ID,
|
||||
Name: output.Artifact.Schema.Name,
|
||||
Version: output.Artifact.Schema.Version,
|
||||
},
|
||||
})
|
||||
}
|
||||
return manifests
|
||||
}
|
||||
|
||||
func rejectedOutputManifests(rejected []contracts.RejectedOutput) []artifacts.RejectedOutputManifest {
|
||||
if len(rejected) == 0 {
|
||||
return nil
|
||||
}
|
||||
manifests := make([]artifacts.RejectedOutputManifest, 0, len(rejected))
|
||||
for _, output := range rejected {
|
||||
manifests = append(manifests, artifacts.RejectedOutputManifest{
|
||||
Stage: output.Stage,
|
||||
StepID: output.StepID,
|
||||
LaneID: output.LaneID,
|
||||
ModuleKey: output.ModuleKey,
|
||||
ChunkID: output.ChunkID,
|
||||
ChunkIndex: output.ChunkIndex,
|
||||
ValidatorName: output.ValidatorName,
|
||||
ReasonCode: output.ReasonCode,
|
||||
Message: output.Message,
|
||||
AttemptCount: output.AttemptCount,
|
||||
DiagnosticArtifactPath: output.DiagnosticArtifactPath,
|
||||
Validation: cloneValidationSummaryPtr(output.Validation),
|
||||
})
|
||||
}
|
||||
return manifests
|
||||
}
|
||||
|
||||
func attachModuleManifestMetadata(output *RunOutput, moduleKey string, module any) error {
|
||||
if output == nil {
|
||||
return nil
|
||||
}
|
||||
metadata, ok, err := moduleManifestMetadata(module)
|
||||
if err != nil {
|
||||
return fmt.Errorf("clone manifest metadata for module %q: %w", moduleKey, err)
|
||||
}
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if output.Manifest.ModuleMetadata == nil {
|
||||
output.Manifest.ModuleMetadata = make(map[string]map[string]any)
|
||||
}
|
||||
output.Manifest.ModuleMetadata[moduleKey] = metadata
|
||||
return nil
|
||||
}
|
||||
|
||||
func moduleManifestMetadata(module any) (map[string]any, bool, error) {
|
||||
provider, ok := module.(contracts.ManifestMetadataProvider)
|
||||
if !ok {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
moduleMetadata, err := cloneMetadata(provider.ManifestMetadata())
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if len(moduleMetadata) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
return moduleMetadata, true, nil
|
||||
}
|
||||
|
||||
func outputFilesFromResult(result contracts.OutputResult) ([]contracts.OutputFile, error) {
|
||||
out := make([]contracts.OutputFile, 0, len(result.Files))
|
||||
for _, file := range result.Files {
|
||||
@@ -693,48 +482,6 @@ func cloneMetadata(metadata map[string]any) (map[string]any, error) {
|
||||
return source.CloneMetadata(metadata)
|
||||
}
|
||||
|
||||
func cloneLLMProfiles(profiles []artifacts.LLMProfileManifest) []artifacts.LLMProfileManifest {
|
||||
if len(profiles) == 0 {
|
||||
return nil
|
||||
}
|
||||
return append([]artifacts.LLMProfileManifest(nil), profiles...)
|
||||
}
|
||||
|
||||
func llmProfileManifests(client contracts.StructuredLLMClient) []artifacts.LLMProfileManifest {
|
||||
provider, ok := client.(contracts.LLMProfileManifestProvider)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return provider.LLMProfileManifests()
|
||||
}
|
||||
|
||||
func mergeLLMProfileManifests(sources ...[]artifacts.LLMProfileManifest) []artifacts.LLMProfileManifest {
|
||||
merged := make(map[string]artifacts.LLMProfileManifest)
|
||||
for _, source := range sources {
|
||||
for _, profile := range source {
|
||||
profile = profile.Normalized()
|
||||
key := profile.IdentityKey()
|
||||
if _, exists := merged[key]; exists {
|
||||
continue
|
||||
}
|
||||
merged[key] = profile
|
||||
}
|
||||
}
|
||||
if len(merged) == 0 {
|
||||
return nil
|
||||
}
|
||||
keys := make([]string, 0, len(merged))
|
||||
for key := range merged {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
out := make([]artifacts.LLMProfileManifest, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
out = append(out, merged[key])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func sourceInputMaterial(inputPath string, content []byte) contracts.LLMInputMaterial {
|
||||
return contracts.NewLLMInputMaterial(
|
||||
"source",
|
||||
@@ -779,21 +526,6 @@ func sourceInputOriginURI(inputPath string) string {
|
||||
return fileURI(inputPath)
|
||||
}
|
||||
|
||||
func manifestMetadataWithSessionID(metadata map[string]any, sessionID string) (map[string]any, error) {
|
||||
out, err := cloneMetadata(metadata)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("clone run manifest metadata: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(sessionID) == "" {
|
||||
return out, nil
|
||||
}
|
||||
if out == nil {
|
||||
out = make(map[string]any)
|
||||
}
|
||||
out["session_id"] = sessionID
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func cloneSourceChunkPtr(chunk *source.Chunk) (*source.Chunk, error) {
|
||||
if chunk == nil {
|
||||
return nil, nil
|
||||
@@ -861,38 +593,3 @@ func cloneSerializedOutputs(outputs []contracts.SerializedOutput) []contracts.Se
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func cloneRejectedOutputs(rejected []contracts.RejectedOutput) []contracts.RejectedOutput {
|
||||
if len(rejected) == 0 {
|
||||
return nil
|
||||
}
|
||||
cloned := make([]contracts.RejectedOutput, len(rejected))
|
||||
for index, item := range rejected {
|
||||
cloned[index] = item
|
||||
cloned[index].Validation = cloneValidationSummaryPtr(item.Validation)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
func cloneValidationSummaryPtr(summary *artifacts.ValidationSummary) *artifacts.ValidationSummary {
|
||||
if summary == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := artifacts.CloneValidationSummary(*summary)
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneValidationSummaries(summaries []artifacts.ValidationSummary) []artifacts.ValidationSummary {
|
||||
if len(summaries) == 0 {
|
||||
return nil
|
||||
}
|
||||
cloned := make([]artifacts.ValidationSummary, len(summaries))
|
||||
for index, summary := range summaries {
|
||||
cloned[index] = artifacts.CloneValidationSummary(summary)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
func timePtr(t time.Time) *time.Time {
|
||||
return &t
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ func TestRunnerReusesAcceptedPredecessorAfterDownstreamFailure(t *testing.T) {
|
||||
}
|
||||
first = false
|
||||
output, err := New().Run(context.Background(), input)
|
||||
if err != nil || len(output.NormalizeOutputs) != 2 || calls != 1 || store.reads != 2 || store.writes != 1 || output.FallbackCount != 0 {
|
||||
t.Fatalf("rerun=%v outputs=%d calls=%d cache=%d/%d", err, len(output.NormalizeOutputs), calls, store.reads, store.writes)
|
||||
if err != nil || len(output.normalizeOutputs) != 2 || calls != 1 || store.reads != 2 || store.writes != 1 || output.FallbackCount != 0 {
|
||||
t.Fatalf("rerun=%v outputs=%d calls=%d cache=%d/%d", err, len(output.normalizeOutputs), calls, store.reads, store.writes)
|
||||
}
|
||||
var decisions []string
|
||||
for _, observation := range observations {
|
||||
@@ -86,8 +86,8 @@ func TestRunnerCacheWarningsDoNotFailSuccessfulPublication(t *testing.T) {
|
||||
profile := typedResolutionProfile()
|
||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "native", probe: newRunnerProbe(), native: true})}
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, engine), RawInput: []byte("input"), Cache: store, Workers: 1})
|
||||
if err != nil || len(output.NormalizeOutputs) != 1 || output.FallbackCount != 0 {
|
||||
t.Fatalf("cache warnings failed successful work: %v, outputs=%d", err, len(output.NormalizeOutputs))
|
||||
if err != nil || len(output.normalizeOutputs) != 1 || output.FallbackCount != 0 {
|
||||
t.Fatalf("cache warnings failed successful work: %v, outputs=%d", err, len(output.normalizeOutputs))
|
||||
}
|
||||
projection, err := contracts.ProjectDiagnosticCollection(output.Diagnostics)
|
||||
if err != nil || projection.WarningOccurrenceCount != 2 {
|
||||
@@ -237,10 +237,10 @@ func TestRunnerCachesAppliedMergeAndNormalizationArtifacts(t *testing.T) {
|
||||
}
|
||||
for range 2 {
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, Cache: store, RawInput: []byte("input"), Workers: 1})
|
||||
if err != nil || len(output.NormalizeOutputs) != 2 {
|
||||
t.Fatalf("cached %s execution: %v, outputs %d", role, err, len(output.NormalizeOutputs))
|
||||
if err != nil || len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("cached %s execution: %v, outputs %d", role, err, len(output.normalizeOutputs))
|
||||
}
|
||||
value, err := notesCodec().Decode(output.NormalizeOutputs[0].Artifact.Content)
|
||||
value, err := notesCodec().Decode(output.normalizeOutputs[0].Artifact.Content)
|
||||
if err != nil || !reflect.DeepEqual(value.Items, []string{"applied"}) {
|
||||
t.Fatalf("applied artifact changed on reuse: %#v, %v", value, err)
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func TestRunnerExecutesOrderedStepsWithHardBarriers(t *testing.T) {
|
||||
if want := []string{"first-normalize-done", "second-extract-started"}; !reflect.DeepEqual(gotEvents, want) {
|
||||
t.Fatalf("ordered events = %#v, want %#v", gotEvents, want)
|
||||
}
|
||||
if got := []string{output.NormalizeOutputs[0].LaneID, output.NormalizeOutputs[1].LaneID}; !reflect.DeepEqual(got, []string{"notes", "score"}) {
|
||||
if got := []string{output.normalizeOutputs[0].LaneID, output.normalizeOutputs[1].LaneID}; !reflect.DeepEqual(got, []string{"notes", "score"}) {
|
||||
t.Fatalf("normalized lane order = %#v, want notes then score", got)
|
||||
}
|
||||
}
|
||||
@@ -290,8 +290,8 @@ func TestRunnerStopsLaterOrderedStepsAfterFailure(t *testing.T) {
|
||||
if err == nil || !strings.Contains(err.Error(), `execute pipeline step "step-2"`) {
|
||||
t.Fatalf("Run() error = %v, want step-scoped failure", err)
|
||||
}
|
||||
if len(output.NormalizeOutputs) != 1 || output.NormalizeOutputs[0].LaneID != "first" {
|
||||
t.Fatalf("completed outputs = %#v, want only the first step output", output.NormalizeOutputs)
|
||||
if len(output.normalizeOutputs) != 1 || output.normalizeOutputs[0].LaneID != "first" {
|
||||
t.Fatalf("completed outputs = %#v, want only the first step output", output.normalizeOutputs)
|
||||
}
|
||||
if got := thirdCalls.Load(); got != 0 {
|
||||
t.Fatalf("later step extract calls = %d, want zero", got)
|
||||
@@ -436,8 +436,8 @@ func TestRunnerBoundsConcurrentLaneContinuations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
if len(output.NormalizeOutputs) != len(lanes) {
|
||||
t.Fatalf("normalize outputs = %d, want %d", len(output.NormalizeOutputs), len(lanes))
|
||||
if len(output.normalizeOutputs) != len(lanes) {
|
||||
t.Fatalf("normalize outputs = %d, want %d", len(output.normalizeOutputs), len(lanes))
|
||||
}
|
||||
if got := maximum.Load(); got != 2 {
|
||||
t.Fatalf("maximum concurrent lane continuations = %d, want 2", got)
|
||||
|
||||
@@ -61,8 +61,8 @@ type orderedRunError struct {
|
||||
}
|
||||
|
||||
func (r *Runner) runLanes(parent context.Context, input RunInput, step PreparedPipelineStep, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk) (RunOutput, error) {
|
||||
output := RunOutput{Manifest: manifestFromPipeline(input)}
|
||||
states, err := initializeLaneStates(input, step, chunks, &output)
|
||||
output := RunOutput{}
|
||||
states, err := initializeLaneStates(input, step, chunks)
|
||||
if err != nil {
|
||||
return output, err
|
||||
}
|
||||
@@ -70,24 +70,19 @@ func (r *Runner) runLanes(parent context.Context, input RunInput, step PreparedP
|
||||
input: input, doc: doc,
|
||||
sourceInput: sourceInput, sessionID: sessionID, chunks: chunks, states: states,
|
||||
})
|
||||
if err := mergeCompletedLanes(&output, completedOutputs); err != nil {
|
||||
return output, err
|
||||
}
|
||||
mergeCompletedLanes(&output, completedOutputs)
|
||||
if err := selectRunError(parent, runErrors); err != nil {
|
||||
return output, err
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func initializeLaneStates(input RunInput, step PreparedPipelineStep, chunks []source.Chunk, output *RunOutput) ([]*laneExtractState, error) {
|
||||
func initializeLaneStates(input RunInput, step PreparedPipelineStep, chunks []source.Chunk) ([]*laneExtractState, error) {
|
||||
states := make([]*laneExtractState, len(step.lanes))
|
||||
for i, prepared := range step.lanes {
|
||||
if prepared.typed == nil {
|
||||
return nil, fmt.Errorf("typed lane %q executor is not prepared", prepared.resolved.ID)
|
||||
}
|
||||
if err := setTypedLaneManifestMetadata(output, prepared.resolved.ID, prepared.typed.extractor, prepared.typed.merger, prepared.typed.normalizer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
states[i] = &laneExtractState{index: i, prepared: prepared, reuseEligible: !input.reuseIneligible && referenceTargetReuseEligible(input, prepared.resolved.ExtractReferences), remaining: len(chunks), results: make(map[int]extractJobResult, len(chunks))}
|
||||
}
|
||||
return states, nil
|
||||
@@ -263,13 +258,10 @@ func (e *laneEngine) handleCompletion(completion laneCompletion) {
|
||||
}
|
||||
}
|
||||
|
||||
func mergeCompletedLanes(output *RunOutput, completedOutputs []RunOutput) error {
|
||||
func mergeCompletedLanes(output *RunOutput, completedOutputs []RunOutput) {
|
||||
for i := range completedOutputs {
|
||||
if err := mergeLaneOutput(output, completedOutputs[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
mergeLaneOutput(output, completedOutputs[i])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Runner) runExtractJob(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, job extractJob) extractJobResult {
|
||||
@@ -349,7 +341,7 @@ func finalizeLaneExtract(state *laneExtractState) {
|
||||
|
||||
func (r *Runner) continueLane(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, state *laneExtractState) (RunOutput, error) {
|
||||
lane := state.prepared.resolved
|
||||
local := RunOutput{Manifest: manifestFromPipeline(input), FallbackCount: state.fallbackCount}
|
||||
local := RunOutput{FallbackCount: state.fallbackCount}
|
||||
results := finalizedExtractResults{
|
||||
accepted: state.values,
|
||||
diagnostics: state.diagnostics,
|
||||
@@ -426,15 +418,13 @@ func selectRunError(parent context.Context, values []orderedRunError) error {
|
||||
return filtered[0].err
|
||||
}
|
||||
|
||||
func mergeLaneOutput(dst *RunOutput, src RunOutput) error {
|
||||
func mergeLaneOutput(dst *RunOutput, src RunOutput) {
|
||||
if dst == nil {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
dst.FallbackCount += src.FallbackCount
|
||||
dst.NormalizeOutputs = append(dst.NormalizeOutputs, cloneSerializedOutputs(src.NormalizeOutputs)...)
|
||||
dst.Rejected = append(dst.Rejected, cloneRejectedOutputs(src.Rejected)...)
|
||||
dst.normalizeOutputs = append(dst.normalizeOutputs, cloneSerializedOutputs(src.normalizeOutputs)...)
|
||||
appendDiagnosticGroups(dst, src.diagnosticGroups)
|
||||
dst.ValidationSummaries = append(dst.ValidationSummaries, cloneValidationSummaries(src.ValidationSummaries)...)
|
||||
if len(src.normalizeReuseEligibility) > 0 {
|
||||
if dst.normalizeReuseEligibility == nil {
|
||||
dst.normalizeReuseEligibility = make(map[generatedOutputKey]bool, len(src.normalizeReuseEligibility))
|
||||
@@ -443,16 +433,4 @@ func mergeLaneOutput(dst *RunOutput, src RunOutput) error {
|
||||
dst.normalizeReuseEligibility[key] = eligible
|
||||
}
|
||||
}
|
||||
for i := range dst.Manifest.ArtifactLanes {
|
||||
for j := range src.Manifest.ArtifactLanes {
|
||||
if dst.Manifest.ArtifactLanes[i].ID == src.Manifest.ArtifactLanes[j].ID && dst.Manifest.ArtifactLanes[i].StepID == src.Manifest.ArtifactLanes[j].StepID && src.Manifest.ArtifactLanes[j].Metadata != nil {
|
||||
metadata, err := cloneMetadata(src.Manifest.ArtifactLanes[j].Metadata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("clone lane %q manifest metadata: %w", dst.Manifest.ArtifactLanes[i].ID, err)
|
||||
}
|
||||
dst.Manifest.ArtifactLanes[i].Metadata = metadata
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -177,8 +177,8 @@ func TestRunnerPropagatesLaneFallbackWithoutCountingDependents(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if output.FallbackCount != 1 || len(output.NormalizeOutputs) != 2 {
|
||||
t.Fatalf("fallback count=%d, outputs=%d", output.FallbackCount, len(output.NormalizeOutputs))
|
||||
if output.FallbackCount != 1 || len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("fallback count=%d, outputs=%d", output.FallbackCount, len(output.normalizeOutputs))
|
||||
}
|
||||
after := false
|
||||
for _, role := range []ModuleStage{StageExtract, StageMerge, StageNormalize} {
|
||||
@@ -245,7 +245,7 @@ func TestRunnerAssessesNativeRevisionsWithoutOuterRevalidation(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if providerCalls != 2 || output.FallbackCount != 0 || len(output.NormalizeOutputs) != 1 {
|
||||
if providerCalls != 2 || output.FallbackCount != 0 || len(output.normalizeOutputs) != 1 {
|
||||
t.Fatalf("native calls=%d, output=%#v", providerCalls, output)
|
||||
}
|
||||
for _, key := range []string{"first/0", "second/0", "first/1", "second/1", "native/extract", "native/merge", "native/normalize"} {
|
||||
@@ -276,8 +276,8 @@ func TestRunnerGeneratedFallbackReferencesTaintOnlyActualConsumers(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if output.FallbackCount != 1 || len(output.NormalizeOutputs) != 4 || probe.calls["consumer/reference"] != 1 {
|
||||
t.Fatalf("handoff failed: count=%d outputs=%d observations=%#v", output.FallbackCount, len(output.NormalizeOutputs), probe.calls)
|
||||
if output.FallbackCount != 1 || len(output.normalizeOutputs) != 4 || probe.calls["consumer/reference"] != 1 {
|
||||
t.Fatalf("handoff failed: count=%d outputs=%d observations=%#v", output.FallbackCount, len(output.normalizeOutputs), probe.calls)
|
||||
}
|
||||
for _, key := range []string{"earlier/extract", "earlier/merge", "earlier/normalize", "later/extract", "later/merge", "later/normalize", "consumer/extract"} {
|
||||
if !reflect.DeepEqual(probe.eligible[key], []bool{true}) {
|
||||
@@ -318,7 +318,7 @@ func TestRunnerChunkFallbackTaintsEveryDerivedOperation(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if output.FallbackCount != 1 || len(output.NormalizeOutputs) != 1 {
|
||||
if output.FallbackCount != 1 || len(output.normalizeOutputs) != 1 {
|
||||
t.Fatalf("chunk fallback = %#v", output)
|
||||
}
|
||||
for _, role := range []string{"extract", "merge", "normalize"} {
|
||||
@@ -353,7 +353,7 @@ func TestRunnerDoesNotAcceptModuleFallbackUnderStrictControls(t *testing.T) {
|
||||
profile.Chunk = Binding("fallback-chunk")
|
||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "notes", probe: probe})}
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
||||
if err == nil || output.FallbackCount != 0 || len(output.NormalizeOutputs) != 0 || probe.calls["notes/extract"] != 0 {
|
||||
if err == nil || output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 || probe.calls["notes/extract"] != 0 {
|
||||
t.Fatalf("strict controls accepted module fallback: %#v %v", output, err)
|
||||
}
|
||||
}
|
||||
@@ -367,7 +367,7 @@ func TestRunnerDiscardsDeterministicOutputReturnedAfterCancellation(t *testing.T
|
||||
profile := typedResolutionProfile()
|
||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": lane}
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
||||
if !errors.Is(err, context.Canceled) || output.FallbackCount != 0 || len(output.NormalizeOutputs) != 0 || probe.calls["notes/merge"] != 0 || probe.calls["notes/extract/fallback"] != 0 {
|
||||
if !errors.Is(err, context.Canceled) || output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 || probe.calls["notes/merge"] != 0 || probe.calls["notes/extract/fallback"] != 0 {
|
||||
t.Fatalf("cancellation = %#v %v, calls %#v", output, err, probe.calls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,9 +56,6 @@ func (r *Runner) continueTypedLane(ctx context.Context, input RunInput, doc *sou
|
||||
if prepared.typed == nil {
|
||||
return fmt.Errorf("typed lane %q executor is not prepared", lane.ID)
|
||||
}
|
||||
if err := setTypedLaneManifestMetadata(output, lane.ID, prepared.typed.extractor, prepared.typed.merger, prepared.typed.normalizer); err != nil {
|
||||
return err
|
||||
}
|
||||
merged, err := r.runMergeStage(ctx, input, doc, sourceInput, sessionID, prepared, extracts, output)
|
||||
if err != nil {
|
||||
return &laneRunError{stage: StageMerge, err: err}
|
||||
@@ -68,7 +65,7 @@ func (r *Runner) continueTypedLane(ctx context.Context, input RunInput, doc *sou
|
||||
return &laneRunError{stage: StageNormalize, err: err}
|
||||
}
|
||||
if normalized.accepted {
|
||||
output.NormalizeOutputs = append(output.NormalizeOutputs, contracts.SerializedOutput{StepID: input.stepID, LaneID: lane.ID, NormalizerKey: lane.Normalize.Module, SourceID: doc.ID, Artifact: contracts.CloneSerializedArtifact(normalized.serialized)})
|
||||
output.normalizeOutputs = append(output.normalizeOutputs, contracts.SerializedOutput{StepID: input.stepID, LaneID: lane.ID, NormalizerKey: lane.Normalize.Module, SourceID: doc.ID, Artifact: contracts.CloneSerializedArtifact(normalized.serialized)})
|
||||
if output.normalizeReuseEligibility == nil {
|
||||
output.normalizeReuseEligibility = make(map[generatedOutputKey]bool)
|
||||
}
|
||||
@@ -184,32 +181,3 @@ func (r *Runner) runNormalizeStage(ctx context.Context, input RunInput, doc *sou
|
||||
}
|
||||
return state, nil
|
||||
}
|
||||
|
||||
func setTypedLaneManifestMetadata(output *RunOutput, laneID string, extractor, merger, normalizer any) error {
|
||||
if output == nil {
|
||||
return nil
|
||||
}
|
||||
for i := range output.Manifest.ArtifactLanes {
|
||||
if output.Manifest.ArtifactLanes[i].ID != laneID {
|
||||
continue
|
||||
}
|
||||
metadata := make(map[string]any)
|
||||
for _, item := range []struct {
|
||||
name string
|
||||
module any
|
||||
}{{"extractor", extractor}, {"merger", merger}, {"normalizer", normalizer}} {
|
||||
value, ok, err := moduleManifestMetadata(item.module)
|
||||
if err != nil {
|
||||
return fmt.Errorf("clone %s manifest metadata for lane %q: %w", item.name, laneID, err)
|
||||
}
|
||||
if ok {
|
||||
metadata[item.name] = value
|
||||
}
|
||||
}
|
||||
if len(metadata) > 0 {
|
||||
output.Manifest.ArtifactLanes[i].Metadata = metadata
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -195,8 +195,8 @@ func TestRunExecutesHeterogeneousTypedLanes(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
if len(output.NormalizeOutputs) != 2 {
|
||||
t.Fatalf("normalize outputs = %#v, want two typed lane results", output.NormalizeOutputs)
|
||||
if len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("normalize outputs = %#v, want two typed lane results", output.normalizeOutputs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,6 @@ const chunkMapFileName = "chunk-map.json"
|
||||
|
||||
const evidenceContextFileName = "evidence-context.json"
|
||||
|
||||
const (
|
||||
warningsSchemaVersion = "notarius.warnings.v2"
|
||||
diagnosticsSchemaVersion = "notarius.diagnostics.v1"
|
||||
)
|
||||
|
||||
var safeOutputFileChar = regexp.MustCompile(`[^A-Za-z0-9._-]`)
|
||||
|
||||
var _ contracts.OutputEncoder = (*Encoder)(nil)
|
||||
@@ -231,73 +226,13 @@ func decodeEvidenceLaneIDs(value any) ([]string, error) {
|
||||
return lanes, nil
|
||||
}
|
||||
|
||||
type indexFile struct {
|
||||
ManifestFile string `json:"manifest_file"`
|
||||
OutputFiles []outputFileIndex `json:"output_files"`
|
||||
RejectedFile string `json:"rejected_file"`
|
||||
WarningsFile string `json:"warnings_file"`
|
||||
DiagnosticsFile string `json:"diagnostics_file"`
|
||||
ChunkMap *artifactIndex `json:"chunk_map,omitempty"`
|
||||
EvidenceContext *artifactIndex `json:"evidence_context,omitempty"`
|
||||
}
|
||||
|
||||
type artifactIndex struct {
|
||||
ArtifactKind contracts.ArtifactKind `json:"artifact_kind"`
|
||||
File string `json:"file"`
|
||||
MediaType string `json:"media_type"`
|
||||
SchemaID string `json:"schema_id"`
|
||||
SchemaName string `json:"schema_name"`
|
||||
SchemaVersion string `json:"schema_version"`
|
||||
}
|
||||
|
||||
type outputFileIndex struct {
|
||||
LaneID string `json:"lane_id"`
|
||||
MediaType string `json:"media_type,omitempty"`
|
||||
File string `json:"file"`
|
||||
ModuleKey string `json:"module_key,omitempty"`
|
||||
SchemaID string `json:"schema_id,omitempty"`
|
||||
SchemaName string `json:"schema_name,omitempty"`
|
||||
SchemaVer string `json:"schema_version,omitempty"`
|
||||
}
|
||||
|
||||
type rejectedFile struct {
|
||||
Rejected []contracts.RejectedOutput `json:"rejected"`
|
||||
}
|
||||
|
||||
type warningsFile struct {
|
||||
SchemaVersion string `json:"schema_version"`
|
||||
GroupCount int `json:"group_count"`
|
||||
OccurrenceCount int `json:"occurrence_count"`
|
||||
Groups []contracts.DiagnosticGroup `json:"groups"`
|
||||
}
|
||||
|
||||
type diagnosticsFile struct {
|
||||
SchemaVersion string `json:"schema_version"`
|
||||
GroupCount int `json:"group_count"`
|
||||
OccurrenceCount int `json:"occurrence_count"`
|
||||
Truncated bool `json:"truncated"`
|
||||
UnrepresentedOccurrenceCount int `json:"unrepresented_occurrence_count"`
|
||||
Groups []contracts.DiagnosticGroup `json:"groups"`
|
||||
}
|
||||
|
||||
func logicalFiles(req contracts.OutputRequest, options Options) ([]contracts.OutputFile, error) {
|
||||
diagnosticProjection, err := contracts.ProjectDiagnosticCollection(req.Diagnostics)
|
||||
if err != nil {
|
||||
return nil, encoderErrorf("diagnostics: %w", err)
|
||||
}
|
||||
outputs := cloneNormalizeOutputs(req.NormalizeOutputs)
|
||||
sort.SliceStable(outputs, func(i, j int) bool {
|
||||
return outputs[i].LaneID < outputs[j].LaneID
|
||||
})
|
||||
|
||||
outputIndexes := make([]outputFileIndex, 0, len(outputs))
|
||||
files := make([]contracts.OutputFile, 0, len(outputs)+6)
|
||||
manifestFile, err := jsonFile("manifest.json", req.Manifest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, manifestFile)
|
||||
|
||||
files := make([]contracts.OutputFile, 0, len(outputs)+2)
|
||||
usedOutputFiles := make(map[string]string, len(outputs))
|
||||
for _, output := range outputs {
|
||||
name, err := outputFileName(output.LaneID)
|
||||
@@ -308,15 +243,6 @@ func logicalFiles(req contracts.OutputRequest, options Options) ([]contracts.Out
|
||||
return nil, encoderErrorf("lanes %q and %q produce duplicate output file %q", existingLane, output.LaneID, name)
|
||||
}
|
||||
usedOutputFiles[name] = output.LaneID
|
||||
outputIndexes = append(outputIndexes, outputFileIndex{
|
||||
LaneID: output.LaneID,
|
||||
MediaType: output.Artifact.MediaType,
|
||||
File: name,
|
||||
ModuleKey: output.NormalizerKey,
|
||||
SchemaID: output.Artifact.Schema.ID,
|
||||
SchemaName: output.Artifact.Schema.Name,
|
||||
SchemaVer: output.Artifact.Schema.Version,
|
||||
})
|
||||
file, err := serializedOutputFile(name, output.Artifact)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -324,103 +250,63 @@ func logicalFiles(req contracts.OutputRequest, options Options) ([]contracts.Out
|
||||
files = append(files, file)
|
||||
}
|
||||
|
||||
index := indexFile{
|
||||
ManifestFile: "manifest.json",
|
||||
OutputFiles: outputIndexes,
|
||||
RejectedFile: "rejected.json",
|
||||
WarningsFile: "warnings.json",
|
||||
DiagnosticsFile: "diagnostics.json",
|
||||
}
|
||||
if options.IncludeChunkMap && req.ChunkMap != nil {
|
||||
chunkMapOutput, chunkMapDescriptor, err := serializedChunkMapFile(*req.ChunkMap)
|
||||
chunkMapOutput, err := serializedChunkMapFile(*req.ChunkMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, chunkMapOutput)
|
||||
index.ChunkMap = &chunkMapDescriptor
|
||||
}
|
||||
if req.EvidenceContext != nil {
|
||||
evidenceOutput, evidenceDescriptor, err := serializedEvidenceContextFile(*req.EvidenceContext)
|
||||
if options.EvidenceContext.Enabled && req.EvidenceContext != nil {
|
||||
evidenceOutput, err := serializedEvidenceContextFile(*req.EvidenceContext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, evidenceOutput)
|
||||
index.EvidenceContext = &evidenceDescriptor
|
||||
}
|
||||
indexOutput, err := jsonFile("index.json", index)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rejectedOutput, err := jsonFile("rejected.json", rejectedFile{Rejected: cloneRejected(req.Rejected)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
warningsOutput, err := jsonFile("warnings.json", newWarningsFile(diagnosticProjection))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
diagnosticsOutput, err := jsonFile("diagnostics.json", newDiagnosticsFile(req.Diagnostics, diagnosticProjection))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, indexOutput, rejectedOutput, warningsOutput, diagnosticsOutput)
|
||||
sort.Slice(files, func(i, j int) bool {
|
||||
return files[i].Name < files[j].Name
|
||||
})
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func serializedChunkMapFile(artifact contracts.SerializedArtifact) (contracts.OutputFile, artifactIndex, error) {
|
||||
func serializedChunkMapFile(artifact contracts.SerializedArtifact) (contracts.OutputFile, error) {
|
||||
if artifact.Kind != chunkmap.ArtifactKind {
|
||||
return contracts.OutputFile{}, artifactIndex{}, encoderErrorf("chunk map has unexpected artifact kind %q", artifact.Kind)
|
||||
return contracts.OutputFile{}, encoderErrorf("chunk map has unexpected artifact kind %q", artifact.Kind)
|
||||
}
|
||||
if artifact.Schema.ID != chunkmap.SchemaID || artifact.Schema.Name != chunkmap.SchemaName || artifact.Schema.Version != chunkmap.SchemaVersion {
|
||||
return contracts.OutputFile{}, artifactIndex{}, encoderErrorf("chunk map has unexpected schema identity")
|
||||
return contracts.OutputFile{}, encoderErrorf("chunk map has unexpected schema identity")
|
||||
}
|
||||
if strings.TrimSpace(artifact.MediaType) != chunkmap.MediaType {
|
||||
return contracts.OutputFile{}, artifactIndex{}, encoderErrorf("chunk map has unsupported media type %q", artifact.MediaType)
|
||||
return contracts.OutputFile{}, encoderErrorf("chunk map has unsupported media type %q", artifact.MediaType)
|
||||
}
|
||||
if _, err := chunkmap.New().Decode(artifact.Content); err != nil {
|
||||
return contracts.OutputFile{}, artifactIndex{}, encoderErrorf("decode chunk map: %w", err)
|
||||
return contracts.OutputFile{}, encoderErrorf("decode chunk map: %w", err)
|
||||
}
|
||||
file, err := serializedOutputFile(chunkMapFileName, artifact)
|
||||
if err != nil {
|
||||
return contracts.OutputFile{}, artifactIndex{}, err
|
||||
return contracts.OutputFile{}, err
|
||||
}
|
||||
return file, artifactIndex{
|
||||
ArtifactKind: artifact.Kind,
|
||||
File: chunkMapFileName,
|
||||
MediaType: chunkmap.MediaType,
|
||||
SchemaID: artifact.Schema.ID,
|
||||
SchemaName: artifact.Schema.Name,
|
||||
SchemaVersion: artifact.Schema.Version,
|
||||
}, nil
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func serializedEvidenceContextFile(artifact contracts.SerializedArtifact) (contracts.OutputFile, artifactIndex, error) {
|
||||
func serializedEvidenceContextFile(artifact contracts.SerializedArtifact) (contracts.OutputFile, error) {
|
||||
codec := evidencecontext.New()
|
||||
expected := codec.Schema()
|
||||
if artifact.Kind != evidencecontext.ArtifactKind ||
|
||||
artifact.Schema.ID != expected.ID || artifact.Schema.Name != expected.Name || artifact.Schema.Version != expected.Version ||
|
||||
contracts.DigestArtifactSchema(artifact.Schema) != contracts.DigestArtifactSchema(expected) ||
|
||||
strings.TrimSpace(artifact.MediaType) != evidencecontext.MediaType {
|
||||
return contracts.OutputFile{}, artifactIndex{}, encoderErrorf("evidence context artifact is invalid")
|
||||
return contracts.OutputFile{}, encoderErrorf("evidence context artifact is invalid")
|
||||
}
|
||||
if _, err := codec.Decode(artifact.Content); err != nil {
|
||||
return contracts.OutputFile{}, artifactIndex{}, encoderErrorf("evidence context artifact is invalid")
|
||||
return contracts.OutputFile{}, encoderErrorf("evidence context artifact is invalid")
|
||||
}
|
||||
file, err := serializedOutputFile(evidenceContextFileName, artifact)
|
||||
if err != nil {
|
||||
return contracts.OutputFile{}, artifactIndex{}, encoderErrorf("evidence context artifact is invalid")
|
||||
return contracts.OutputFile{}, encoderErrorf("evidence context artifact is invalid")
|
||||
}
|
||||
return file, artifactIndex{
|
||||
ArtifactKind: evidencecontext.ArtifactKind,
|
||||
File: evidenceContextFileName,
|
||||
MediaType: evidencecontext.MediaType,
|
||||
SchemaID: expected.ID,
|
||||
SchemaName: expected.Name,
|
||||
SchemaVersion: expected.Version,
|
||||
}, nil
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func serializedOutputFile(name string, artifact contracts.SerializedArtifact) (contracts.OutputFile, error) {
|
||||
@@ -464,18 +350,6 @@ func isJSONMediaType(mediaType string) bool {
|
||||
return strings.EqualFold(base, contentTypeJSON)
|
||||
}
|
||||
|
||||
func jsonFile(name string, value any) (contracts.OutputFile, error) {
|
||||
data, err := marshalPretty(value)
|
||||
if err != nil {
|
||||
return contracts.OutputFile{}, encoderErrorf("encode %s: %w", name, err)
|
||||
}
|
||||
return contracts.OutputFile{
|
||||
Name: name,
|
||||
ContentType: contentTypeJSON,
|
||||
Bytes: data,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func marshalPretty(value any) ([]byte, error) {
|
||||
data, err := stdjson.MarshalIndent(value, "", " ")
|
||||
if err != nil {
|
||||
@@ -507,33 +381,6 @@ func cloneNormalizeOutputs(outputs []contracts.SerializedOutput) []contracts.Ser
|
||||
return out
|
||||
}
|
||||
|
||||
func cloneRejected(rejected []contracts.RejectedOutput) []contracts.RejectedOutput {
|
||||
if len(rejected) == 0 {
|
||||
return []contracts.RejectedOutput{}
|
||||
}
|
||||
return append([]contracts.RejectedOutput(nil), rejected...)
|
||||
}
|
||||
|
||||
func newWarningsFile(projection contracts.DiagnosticProjection) warningsFile {
|
||||
return warningsFile{
|
||||
SchemaVersion: warningsSchemaVersion,
|
||||
GroupCount: len(projection.Warnings),
|
||||
OccurrenceCount: projection.WarningOccurrenceCount,
|
||||
Groups: projection.Warnings,
|
||||
}
|
||||
}
|
||||
|
||||
func newDiagnosticsFile(collection contracts.DiagnosticCollection, projection contracts.DiagnosticProjection) diagnosticsFile {
|
||||
return diagnosticsFile{
|
||||
SchemaVersion: diagnosticsSchemaVersion,
|
||||
GroupCount: len(projection.Diagnostics),
|
||||
OccurrenceCount: projection.DiagnosticOccurrenceCount,
|
||||
Truncated: collection.Truncated,
|
||||
UnrepresentedOccurrenceCount: collection.UnrepresentedOccurrenceCount,
|
||||
Groups: projection.Diagnostics,
|
||||
}
|
||||
}
|
||||
|
||||
func encoderErrorf(format string, args ...any) error {
|
||||
return fmt.Errorf("json output encoder: "+format, args...)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/chunkmap"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
@@ -127,27 +126,52 @@ func TestProfileValidationRejectsUnknownEvidenceLaneAndCopiesInputs(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeDeliverableSelectionAndArtifactCount(t *testing.T) {
|
||||
chunkMap := acceptedChunkMapArtifact(t)
|
||||
evidence := acceptedEvidenceContextArtifact(t)
|
||||
request := contracts.OutputRequest{
|
||||
NormalizeOutputs: []contracts.SerializedOutput{normalizeOutput("spells", `{"spell_casts":[]}`), normalizeOutput("notes/items", `{"items":[]}`)},
|
||||
ChunkMap: &chunkMap, EvidenceContext: &evidence,
|
||||
}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
chunkMap, evidence bool
|
||||
want []string
|
||||
}{
|
||||
{"lanes only", false, false, []string{"lanes/notes_items.json", "lanes/spells.json"}},
|
||||
{"chunk map", true, false, []string{"chunk-map.json", "lanes/notes_items.json", "lanes/spells.json"}},
|
||||
{"evidence", false, true, []string{"evidence-context.json", "lanes/notes_items.json", "lanes/spells.json"}},
|
||||
{"both auxiliaries", true, true, []string{"chunk-map.json", "evidence-context.json", "lanes/notes_items.json", "lanes/spells.json"}},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
result, err := NewWithOptions(Options{IncludeChunkMap: test.chunkMap, EvidenceContext: pipeline.EvidenceContextPolicy{Enabled: test.evidence}}).Encode(context.Background(), request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := outputFileNames(result.Files); !reflect.DeepEqual(got, test.want) {
|
||||
t.Fatalf("deliverable files=%v, want %v", got, test.want)
|
||||
}
|
||||
outcome := pipeline.RunOutput{OutputFiles: result.Files, FallbackCount: 1}
|
||||
if outcome.ArtifactCount() != len(test.want) || outcome.FallbackCount != 1 {
|
||||
t.Fatalf("outcome=%#v, want %d artifacts and one qualified fallback", outcome, len(test.want))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeEmptyOutputHasNoReportingSidecars(t *testing.T) {
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{})
|
||||
if err != nil || len(result.Files) != 0 {
|
||||
t.Fatalf("empty output files=%v error=%v", outputFileNames(result.Files), err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeReturnsLogicalFilesForNormalizedOutputs(t *testing.T) {
|
||||
req := contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{RunID: "run-1", PipelineID: "pipeline-1"},
|
||||
NormalizeOutputs: []contracts.SerializedOutput{
|
||||
normalizeOutput("spells", `{"spell_casts":[{"spell":"Cure Wounds"}]}`),
|
||||
normalizeOutput("notes/items", `{"items":[{"name":"Torch"}]}`),
|
||||
normalizeOutput("notes/items", `{"items":[{"name":"Torch","metadata":{"context":"intrinsic domain data"}}]}`),
|
||||
},
|
||||
Rejected: []contracts.RejectedOutput{
|
||||
{
|
||||
Stage: "extract",
|
||||
LaneID: "spells",
|
||||
ModuleKey: "dnd/spells",
|
||||
ChunkID: "chunk-1",
|
||||
ChunkIndex: 1,
|
||||
ReasonCode: "invalid",
|
||||
Message: "not accepted",
|
||||
AttemptCount: 1,
|
||||
ValidatorName: "validator",
|
||||
},
|
||||
},
|
||||
Diagnostics: warningDiagnostics("warning", "check source"),
|
||||
}
|
||||
|
||||
result, err := New().Encode(context.Background(), req)
|
||||
@@ -156,13 +180,8 @@ func TestEncodeReturnsLogicalFilesForNormalizedOutputs(t *testing.T) {
|
||||
}
|
||||
|
||||
wantNames := []string{
|
||||
"diagnostics.json",
|
||||
"index.json",
|
||||
"lanes/notes_items.json",
|
||||
"lanes/spells.json",
|
||||
"manifest.json",
|
||||
"rejected.json",
|
||||
"warnings.json",
|
||||
}
|
||||
if got := outputFileNames(result.Files); !reflect.DeepEqual(got, wantNames) {
|
||||
t.Fatalf("file names = %#v, want %#v", got, wantNames)
|
||||
@@ -182,89 +201,16 @@ func TestEncodeReturnsLogicalFilesForNormalizedOutputs(t *testing.T) {
|
||||
if spellCasts[0].(map[string]any)["spell"] != "Cure Wounds" {
|
||||
t.Fatalf("spells output = %#v, want raw normalized content", spells)
|
||||
}
|
||||
|
||||
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
|
||||
outputFiles := index["output_files"].([]any)
|
||||
if len(outputFiles) != 2 {
|
||||
t.Fatalf("len(index output_files) = %d, want 2", len(outputFiles))
|
||||
}
|
||||
firstIndex := outputFiles[0].(map[string]any)
|
||||
secondIndex := outputFiles[1].(map[string]any)
|
||||
if firstIndex["lane_id"] != "notes/items" || secondIndex["lane_id"] != "spells" {
|
||||
t.Fatalf("output_files = %#v, want sorted by lane id", outputFiles)
|
||||
}
|
||||
|
||||
rejected := decodeObject(t, fileBytes(t, result.Files, "rejected.json"))
|
||||
if got := rejected["rejected"].([]any); len(got) != 1 {
|
||||
t.Fatalf("rejected = %#v, want one rejected output", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeIncludesRejectedAndWarningsWhenEmpty(t *testing.T) {
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{RunID: "run-1"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
}
|
||||
|
||||
rejected := decodeObject(t, fileBytes(t, result.Files, "rejected.json"))
|
||||
if got := rejected["rejected"].([]any); len(got) != 0 {
|
||||
t.Fatalf("rejected = %#v, want empty array", got)
|
||||
}
|
||||
warnings := decodeObject(t, fileBytes(t, result.Files, "warnings.json"))
|
||||
if got := warnings["groups"].([]any); len(got) != 0 {
|
||||
t.Fatalf("warnings = %#v, want empty array", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodePublishesVersionedDiagnosticPartitions(t *testing.T) {
|
||||
diagnostics := contracts.DiagnosticCollection{
|
||||
Groups: []contracts.DiagnosticGroup{
|
||||
{
|
||||
Disposition: contracts.DiagnosticDispositionWarning,
|
||||
Category: contracts.DiagnosticCategoryDegradation,
|
||||
ReasonCode: "degraded",
|
||||
Origin: contracts.DiagnosticOrigin{Stage: contracts.DiagnosticOriginStageChunk},
|
||||
OccurrenceCount: 2,
|
||||
Samples: []contracts.DiagnosticSample{{Scope: "chunk", Message: "degraded"}},
|
||||
OmittedSampleCount: 1,
|
||||
},
|
||||
{
|
||||
Disposition: contracts.DiagnosticDispositionAdvisory,
|
||||
Category: contracts.DiagnosticCategoryDataQuality,
|
||||
ReasonCode: "unrelated",
|
||||
Origin: contracts.DiagnosticOrigin{Stage: contracts.DiagnosticOriginStageExtract},
|
||||
OccurrenceCount: 3,
|
||||
Samples: []contracts.DiagnosticSample{{Scope: "items[0]", Message: "unrelated"}},
|
||||
OmittedSampleCount: 2,
|
||||
},
|
||||
},
|
||||
Truncated: true,
|
||||
UnrepresentedOccurrenceCount: 5,
|
||||
}
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{Diagnostics: diagnostics})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v", err)
|
||||
}
|
||||
warnings := decodeObject(t, fileBytes(t, result.Files, "warnings.json"))
|
||||
if warnings["schema_version"] != warningsSchemaVersion || warnings["group_count"] != float64(1) || warnings["occurrence_count"] != float64(2) || len(warnings["groups"].([]any)) != 1 {
|
||||
t.Fatalf("warnings file = %#v", warnings)
|
||||
}
|
||||
publishedDiagnostics := decodeObject(t, fileBytes(t, result.Files, "diagnostics.json"))
|
||||
if publishedDiagnostics["schema_version"] != diagnosticsSchemaVersion || publishedDiagnostics["group_count"] != float64(1) || publishedDiagnostics["occurrence_count"] != float64(8) || publishedDiagnostics["truncated"] != true || publishedDiagnostics["unrepresented_occurrence_count"] != float64(5) || len(publishedDiagnostics["groups"].([]any)) != 1 {
|
||||
t.Fatalf("diagnostics file = %#v", publishedDiagnostics)
|
||||
}
|
||||
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
|
||||
if index["warnings_file"] != "warnings.json" || index["diagnostics_file"] != "diagnostics.json" {
|
||||
t.Fatalf("index = %#v", index)
|
||||
items := decodeObject(t, fileBytes(t, result.Files, "lanes/notes_items.json"))
|
||||
metadata := items["items"].([]any)[0].(map[string]any)["metadata"].(map[string]any)
|
||||
if metadata["context"] != "intrinsic domain data" {
|
||||
t.Fatalf("intrinsic artifact metadata was lost: %#v", items)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeChunkMapExportIsOptIn(t *testing.T) {
|
||||
artifact := acceptedChunkMapArtifact(t)
|
||||
request := contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{RunID: "run-1"},
|
||||
ChunkMap: &artifact,
|
||||
}
|
||||
for _, test := range []struct {
|
||||
@@ -279,13 +225,9 @@ func TestEncodeChunkMapExportIsOptIn(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
}
|
||||
if got, want := outputFileNames(result.Files), []string{"diagnostics.json", "index.json", "manifest.json", "rejected.json", "warnings.json"}; !reflect.DeepEqual(got, want) {
|
||||
if got, want := outputFileNames(result.Files), []string{}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("file names = %#v, want %#v", got, want)
|
||||
}
|
||||
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
|
||||
if _, ok := index["chunk_map"]; ok {
|
||||
t.Fatalf("index = %#v, want no chunk map descriptor", index)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -293,7 +235,6 @@ func TestEncodeChunkMapExportIsOptIn(t *testing.T) {
|
||||
func TestEncodeIncludesValidatedChunkMap(t *testing.T) {
|
||||
artifact := acceptedChunkMapArtifact(t)
|
||||
result, err := NewWithOptions(Options{IncludeChunkMap: true}).Encode(context.Background(), contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{RunID: "run-1"},
|
||||
NormalizeOutputs: []contracts.SerializedOutput{
|
||||
normalizeOutput("spells", `{"spell_casts":[]}`),
|
||||
},
|
||||
@@ -302,7 +243,7 @@ func TestEncodeIncludesValidatedChunkMap(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
}
|
||||
if got, want := outputFileNames(result.Files), []string{"chunk-map.json", "diagnostics.json", "index.json", "lanes/spells.json", "manifest.json", "rejected.json", "warnings.json"}; !reflect.DeepEqual(got, want) {
|
||||
if got, want := outputFileNames(result.Files), []string{"chunk-map.json", "lanes/spells.json"}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("file names = %#v, want %#v", got, want)
|
||||
}
|
||||
chunkMapFile := fileBytes(t, result.Files, chunkMapFileName)
|
||||
@@ -312,22 +253,6 @@ func TestEncodeIncludesValidatedChunkMap(t *testing.T) {
|
||||
if _, err := chunkmap.New().Decode(chunkMapFile); err != nil {
|
||||
t.Fatalf("Decode(chunk map file) error = %v, want nil", err)
|
||||
}
|
||||
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
|
||||
if got, want := index["chunk_map"], map[string]any{
|
||||
"artifact_kind": "source/chunk-map",
|
||||
"file": chunkMapFileName,
|
||||
"media_type": chunkmap.MediaType,
|
||||
"schema_id": chunkmap.SchemaID,
|
||||
"schema_name": chunkmap.SchemaName,
|
||||
"schema_version": chunkmap.SchemaVersion,
|
||||
}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("chunk map descriptor = %#v, want %#v", got, want)
|
||||
}
|
||||
for _, entry := range index["output_files"].([]any) {
|
||||
if entry.(map[string]any)["file"] == chunkMapFileName {
|
||||
t.Fatalf("output_files = %#v, want no chunk map", index["output_files"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodePreservesChunkMapAnnotationNumbers(t *testing.T) {
|
||||
@@ -348,19 +273,13 @@ func TestEncodePreservesChunkMapAnnotationNumbers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEncodeOmitsChunkMapWithoutAcceptedArtifact(t *testing.T) {
|
||||
result, err := NewWithOptions(Options{IncludeChunkMap: true}).Encode(context.Background(), contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{RunID: "run-1"},
|
||||
})
|
||||
result, err := NewWithOptions(Options{IncludeChunkMap: true}).Encode(context.Background(), contracts.OutputRequest{})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
}
|
||||
if got := outputFileNames(result.Files); containsString(got, chunkMapFileName) {
|
||||
t.Fatalf("file names = %#v, want no chunk map", got)
|
||||
}
|
||||
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
|
||||
if _, ok := index["chunk_map"]; ok {
|
||||
t.Fatalf("index = %#v, want no chunk map descriptor", index)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeRejectsInvalidChunkMapArtifact(t *testing.T) {
|
||||
@@ -387,7 +306,7 @@ func TestEncodeRejectsInvalidChunkMapArtifact(t *testing.T) {
|
||||
|
||||
func TestEncodeIncludesValidatedEvidenceContext(t *testing.T) {
|
||||
artifact := acceptedEvidenceContextArtifact(t)
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{EvidenceContext: &artifact})
|
||||
result, err := NewWithOptions(Options{EvidenceContext: pipeline.EvidenceContextPolicy{Enabled: true}}).Encode(context.Background(), contracts.OutputRequest{EvidenceContext: &artifact})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v", err)
|
||||
}
|
||||
@@ -401,22 +320,6 @@ func TestEncodeIncludesValidatedEvidenceContext(t *testing.T) {
|
||||
if len(value) != 1 || value[0].ID != 7 || value[0].Text != "Source content retained only in the evidence artifact." {
|
||||
t.Fatalf("evidence context = %#v, want the published source-unit array", value)
|
||||
}
|
||||
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
|
||||
if got, want := index["evidence_context"], map[string]any{
|
||||
"artifact_kind": string(evidencecontext.ArtifactKind),
|
||||
"file": evidenceContextFileName,
|
||||
"media_type": evidencecontext.MediaType,
|
||||
"schema_id": evidencecontext.SchemaID,
|
||||
"schema_name": evidencecontext.SchemaName,
|
||||
"schema_version": evidencecontext.SchemaVersion,
|
||||
}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("evidence context descriptor = %#v, want %#v", got, want)
|
||||
}
|
||||
for _, entry := range index["output_files"].([]any) {
|
||||
if entry.(map[string]any)["file"] == evidenceContextFileName {
|
||||
t.Fatalf("output_files = %#v, want no evidence context lane entry", index["output_files"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeRejectsInvalidEvidenceContextArtifactWithoutContentLeakage(t *testing.T) {
|
||||
@@ -436,7 +339,7 @@ func TestEncodeRejectsInvalidEvidenceContextArtifactWithoutContentLeakage(t *tes
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
candidate := contracts.CloneSerializedArtifact(artifact)
|
||||
test.mutate(&candidate)
|
||||
_, err := New().Encode(context.Background(), contracts.OutputRequest{EvidenceContext: &candidate})
|
||||
_, err := NewWithOptions(Options{EvidenceContext: pipeline.EvidenceContextPolicy{Enabled: true}}).Encode(context.Background(), contracts.OutputRequest{EvidenceContext: &candidate})
|
||||
if err == nil || err.Error() != "json output encoder: evidence context artifact is invalid" {
|
||||
t.Fatalf("Encode() error = %v, want fixed evidence artifact error", err)
|
||||
}
|
||||
@@ -448,17 +351,13 @@ func TestEncodeRejectsInvalidEvidenceContextArtifactWithoutContentLeakage(t *tes
|
||||
}
|
||||
|
||||
func TestEncodeOmitsEvidenceContextWhenArtifactIsAbsent(t *testing.T) {
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{Manifest: artifacts.RunManifest{RunID: "run-1"}})
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v", err)
|
||||
}
|
||||
if got := outputFileNames(result.Files); containsString(got, evidenceContextFileName) {
|
||||
t.Fatalf("file names = %#v, want no evidence context", got)
|
||||
}
|
||||
index := decodeObject(t, fileBytes(t, result.Files, "index.json"))
|
||||
if _, ok := index["evidence_context"]; ok {
|
||||
t.Fatalf("index = %#v, want no evidence context descriptor", index)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeChunkMapDoesNotMutateRequest(t *testing.T) {
|
||||
@@ -482,145 +381,13 @@ func TestEncodeChunkMapDoesNotMutateRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEncodePrettyPrintsJSON(t *testing.T) {
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{RunID: "run-1"},
|
||||
})
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{NormalizeOutputs: []contracts.SerializedOutput{normalizeOutput("events", `{"value":1}`)}})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
manifest := string(fileBytes(t, result.Files, "manifest.json"))
|
||||
if !strings.Contains(manifest, "\n \"run_id\": \"run-1\"\n") {
|
||||
t.Fatalf("manifest JSON = %q, want two-space indentation", manifest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodePublishesLLMProfileProvenance(t *testing.T) {
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{
|
||||
RunID: "run-1",
|
||||
LLMProfiles: []artifacts.LLMProfileManifest{
|
||||
{
|
||||
ID: "endpoint-profile",
|
||||
Provider: "promptkit",
|
||||
Model: "endpoint-model",
|
||||
ReasoningEffort: "low",
|
||||
},
|
||||
{
|
||||
ID: "profile",
|
||||
Provider: "promptkit",
|
||||
Model: "model",
|
||||
BackendID: "openrouter",
|
||||
ReasoningEffort: "high",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
}
|
||||
|
||||
manifest := decodeObject(t, fileBytes(t, result.Files, "manifest.json"))
|
||||
profiles := manifest["llm_profiles"].([]any)
|
||||
if len(profiles) != 2 {
|
||||
t.Fatalf("llm_profiles = %#v, want two entries", profiles)
|
||||
}
|
||||
endpointProfile := profiles[0].(map[string]any)
|
||||
if _, exists := endpointProfile["backend_id"]; exists || endpointProfile["reasoning_effort"] != "low" {
|
||||
t.Fatalf("endpoint-only LLM profile = %#v, want omitted backend and published reasoning", endpointProfile)
|
||||
}
|
||||
backendProfile := profiles[1].(map[string]any)
|
||||
if backendProfile["backend_id"] != "openrouter" || backendProfile["reasoning_effort"] != "high" {
|
||||
t.Fatalf("backend LLM profile = %#v, want published backend and reasoning fields", backendProfile)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeIncludesManifestReferences(t *testing.T) {
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{
|
||||
RunID: "run-1",
|
||||
References: []artifacts.ReferenceProvenance{
|
||||
{
|
||||
Stage: "extract",
|
||||
LaneID: "events",
|
||||
SlotName: "roster",
|
||||
OriginType: "file",
|
||||
OriginURI: "file:///tmp/roster.txt",
|
||||
Digest: "sha256:reference",
|
||||
MediaType: "text/plain; charset=utf-8",
|
||||
SizeBytes: 12,
|
||||
BindingSource: "config",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
}
|
||||
|
||||
manifest := decodeObject(t, fileBytes(t, result.Files, "manifest.json"))
|
||||
references := manifest["references"].([]any)
|
||||
if len(references) != 1 {
|
||||
t.Fatalf("references = %#v, want one entry", references)
|
||||
}
|
||||
reference := references[0].(map[string]any)
|
||||
if reference["lane_id"] != "events" || reference["slot_name"] != "roster" || reference["digest"] != "sha256:reference" {
|
||||
t.Fatalf("reference manifest = %#v, want lane slot digest", reference)
|
||||
}
|
||||
if _, ok := reference["content"]; ok {
|
||||
t.Fatalf("reference manifest = %#v, want no content field", reference)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeIncludesManifestRawOutputProvenance(t *testing.T) {
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{
|
||||
RunID: "run-1",
|
||||
NormalizedOutputs: []artifacts.NormalizedOutputManifest{
|
||||
{
|
||||
LaneID: "spells",
|
||||
ModuleKey: "noop",
|
||||
SourceID: "source-1",
|
||||
MediaType: contentTypeJSON,
|
||||
Schema: artifacts.OutputSchemaProvenance{
|
||||
ID: "schema-id",
|
||||
Name: "schema-name",
|
||||
Version: "v1",
|
||||
},
|
||||
},
|
||||
},
|
||||
RejectedOutputs: []artifacts.RejectedOutputManifest{
|
||||
{
|
||||
Stage: "extract",
|
||||
LaneID: "spells",
|
||||
ModuleKey: "dnd/spells",
|
||||
ChunkID: "chunk-0",
|
||||
ReasonCode: "raw_output_rejected",
|
||||
AttemptCount: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
}
|
||||
|
||||
manifest := decodeObject(t, fileBytes(t, result.Files, "manifest.json"))
|
||||
normalized := manifest["normalized_outputs"].([]any)
|
||||
if len(normalized) != 1 {
|
||||
t.Fatalf("normalized_outputs = %#v, want one entry", normalized)
|
||||
}
|
||||
normalizedEntry := normalized[0].(map[string]any)
|
||||
if normalizedEntry["lane_id"] != "spells" || normalizedEntry["media_type"] != contentTypeJSON {
|
||||
t.Fatalf("normalized output manifest = %#v, want lane and media type", normalizedEntry)
|
||||
}
|
||||
rejected := manifest["rejected_outputs"].([]any)
|
||||
if len(rejected) != 1 {
|
||||
t.Fatalf("rejected_outputs = %#v, want one entry", rejected)
|
||||
}
|
||||
rejectedEntry := rejected[0].(map[string]any)
|
||||
if rejectedEntry["attempt_count"] != float64(2) || rejectedEntry["chunk_id"] != "chunk-0" {
|
||||
t.Fatalf("rejected output manifest = %#v, want attempt count and chunk", rejectedEntry)
|
||||
content := string(fileBytes(t, result.Files, "lanes/events.json"))
|
||||
if !strings.Contains(content, "\n \"value\": 1\n") {
|
||||
t.Fatalf("artifact JSON=%q, want two-space indentation", content)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -703,14 +470,9 @@ func TestEncodeRejectsSanitizedFilenameCollisions(t *testing.T) {
|
||||
|
||||
func TestEncodeDoesNotMutateInputs(t *testing.T) {
|
||||
req := contracts.OutputRequest{
|
||||
Manifest: artifacts.RunManifest{RunID: "run-1"},
|
||||
NormalizeOutputs: []contracts.SerializedOutput{
|
||||
normalizeOutput("spells", `{"name":"original"}`),
|
||||
},
|
||||
Rejected: []contracts.RejectedOutput{
|
||||
{Stage: "extract", LaneID: "spells", Message: "not accepted"},
|
||||
},
|
||||
Diagnostics: warningDiagnostics("warning", "message"),
|
||||
}
|
||||
before := mustMarshal(t, req)
|
||||
|
||||
@@ -725,43 +487,10 @@ func TestEncodeDoesNotMutateInputs(t *testing.T) {
|
||||
|
||||
req.NormalizeOutputs[0].Artifact.Content[0] = '['
|
||||
req.NormalizeOutputs[0].Artifact.Metadata["name"] = "changed"
|
||||
req.Rejected[0].Message = "changed"
|
||||
req.Diagnostics.Groups[0].Samples[0].Message = "changed"
|
||||
|
||||
if !stdjson.Valid(fileBytes(t, result.Files, "lanes/spells.json")) {
|
||||
t.Fatal("output changed after request mutation")
|
||||
}
|
||||
warnings := decodeObject(t, fileBytes(t, result.Files, "warnings.json"))
|
||||
gotWarnings := warnings["groups"].([]any)
|
||||
if gotWarnings[0].(map[string]any)["samples"].([]any)[0].(map[string]any)["message"] != "message" {
|
||||
t.Fatalf("warnings output changed after request mutation: %#v", gotWarnings)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputFilesDoNotContainWarnings(t *testing.T) {
|
||||
result, err := New().Encode(context.Background(), contracts.OutputRequest{
|
||||
NormalizeOutputs: []contracts.SerializedOutput{normalizeOutput("spells", `{"spell":"Shield"}`)},
|
||||
Diagnostics: warningDiagnostics("pipeline-warning", "warning"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Encode() error = %v, want nil", err)
|
||||
}
|
||||
|
||||
outputFile := decodeObject(t, fileBytes(t, result.Files, "lanes/spells.json"))
|
||||
if _, ok := outputFile["warnings"]; ok {
|
||||
t.Fatalf("output file contains warnings: %#v", outputFile)
|
||||
}
|
||||
}
|
||||
|
||||
func warningDiagnostics(reasonCode, message string) contracts.DiagnosticCollection {
|
||||
return contracts.DiagnosticCollection{Groups: []contracts.DiagnosticGroup{{
|
||||
Disposition: contracts.DiagnosticDispositionWarning,
|
||||
Category: contracts.DiagnosticCategoryDegradation,
|
||||
ReasonCode: reasonCode,
|
||||
Origin: contracts.DiagnosticOrigin{Stage: contracts.DiagnosticOriginStageChunk},
|
||||
OccurrenceCount: 1,
|
||||
Samples: []contracts.DiagnosticSample{{Scope: "test", Message: message}},
|
||||
}}}
|
||||
}
|
||||
|
||||
func normalizeOutput(laneID string, content string) contracts.SerializedOutput {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
jsonoutput "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/output/json"
|
||||
)
|
||||
|
||||
func runPreparedPipeline(t *testing.T, registries pipeline.Registries, resolved pipeline.ResolvedPipeline, input pipeline.RunInput) (pipeline.RunOutput, error) {
|
||||
@@ -43,25 +44,14 @@ func TestRunnerProcessesSeriatimInputWithFakeModules(t *testing.T) {
|
||||
t.Fatalf("Run() error = %v, want nil", err)
|
||||
}
|
||||
|
||||
if output.Manifest.InputModule != Key {
|
||||
t.Fatalf("manifest input module = %q, want %q", output.Manifest.InputModule, Key)
|
||||
}
|
||||
if got := output.Manifest.SourceDigests; len(got) != 1 || got[0] != expectedDoc.Digest {
|
||||
t.Fatalf("manifest source digests = %#v, want %q", got, expectedDoc.Digest)
|
||||
}
|
||||
if len(output.NormalizeOutputs) != 1 {
|
||||
t.Fatalf("len(NormalizeOutputs) = %d, want 1", len(output.NormalizeOutputs))
|
||||
}
|
||||
|
||||
serializedOutput := output.NormalizeOutputs[0]
|
||||
if serializedOutput.LaneID != "events" || serializedOutput.NormalizerKey != pipeline.DefaultNormalizeModule || serializedOutput.Artifact.Schema.ID != "fake.event" || serializedOutput.Artifact.Schema.Version != "v1" {
|
||||
t.Fatalf("serialized output envelope = %#v, want fake extractor envelope", serializedOutput)
|
||||
if output.ArtifactCount() != 1 || output.OutputFiles[0].Name != "lanes/events.json" {
|
||||
t.Fatalf("output files=%#v, want the event domain artifact", output.OutputFiles)
|
||||
}
|
||||
var payload struct {
|
||||
Value string `json:"value"`
|
||||
SourceRefs []source.SourceRef `json:"source_refs"`
|
||||
}
|
||||
if err := json.Unmarshal(serializedOutput.Artifact.Content, &payload); err != nil {
|
||||
if err := json.Unmarshal(output.OutputFiles[0].Bytes, &payload); err != nil {
|
||||
t.Fatalf("Unmarshal(serialized output) error = %v, want nil", err)
|
||||
}
|
||||
if len(payload.SourceRefs) != 1 {
|
||||
@@ -100,8 +90,8 @@ func TestRunnerFailsOnInvalidSeriatimInput(t *testing.T) {
|
||||
if !strings.Contains(err.Error(), "parse input with adapter") || !strings.Contains(err.Error(), "seriatim input") {
|
||||
t.Fatalf("Run() error = %q, want Seriatim parse context", err.Error())
|
||||
}
|
||||
if output.Manifest.ValidationStatus != "failed" {
|
||||
t.Fatalf("ValidationStatus = %q, want failed", output.Manifest.ValidationStatus)
|
||||
if output.ArtifactCount() != 0 {
|
||||
t.Fatalf("invalid input produced files: %#v", output.OutputFiles)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +137,7 @@ func seriatimRunnerRegistries(t *testing.T, extractor contracts.Extractor[seriat
|
||||
t.Fatalf("register normalizer: %v", err)
|
||||
}
|
||||
if err := outputs.RegisterWithSpec(pipeline.ModuleSpec{Key: pipeline.DefaultOutputModule, Stage: pipeline.StageOutput, ExecutionClass: contracts.ExecutionClassDeterministic}, func() (contracts.OutputEncoder, error) {
|
||||
return runnerSeriatimOutput{}, nil
|
||||
return jsonoutput.New(), nil
|
||||
}); err != nil {
|
||||
t.Fatalf("register output: %v", err)
|
||||
}
|
||||
@@ -233,20 +223,6 @@ func (e *runnerSeriatimExtractor) Extract(ctx context.Context, req contracts.Typ
|
||||
}}, nil
|
||||
}
|
||||
|
||||
type runnerSeriatimOutput struct{}
|
||||
|
||||
func (runnerSeriatimOutput) Key() string {
|
||||
return pipeline.DefaultOutputModule
|
||||
}
|
||||
|
||||
func (runnerSeriatimOutput) Encode(ctx context.Context, req contracts.OutputRequest) (contracts.OutputResult, error) {
|
||||
return contracts.OutputResult{
|
||||
Files: []contracts.OutputFile{
|
||||
{Name: "output.json", ContentType: "application/json", Bytes: []byte(`{"encoded":true}`)},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func unitIDs(units []source.SourceUnit) []int {
|
||||
ids := make([]int, 0, len(units))
|
||||
for _, unit := range units {
|
||||
@@ -270,5 +246,4 @@ func equalInts(a, b []int) bool {
|
||||
var (
|
||||
_ contracts.Chunker = runnerSeriatimChunker{}
|
||||
_ contracts.Extractor[seriatimArtifact] = (*runnerSeriatimExtractor)(nil)
|
||||
_ contracts.OutputEncoder = runnerSeriatimOutput{}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user