Share typed extraction control evidence
This commit is contained in:
@@ -217,21 +217,21 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re
|
||||
ExternalProvenance: &artifactmodel.ExternalProvenance{System: "notarius", PipelineID: report.Pipeline, ArtifactID: lane.LaneID},
|
||||
})
|
||||
}
|
||||
completion := map[string]any{"pipeline": report.Pipeline, "artifact_count": report.ArtifactCount, "output_directory": bundle}
|
||||
if report.DebugDirectory != "" {
|
||||
completion["debug_directory"] = report.DebugDirectory
|
||||
}
|
||||
if report.FallbackCount > 0 {
|
||||
completion["fallback_count"] = report.FallbackCount
|
||||
env.Warn(fmt.Sprintf("Notarius completed with %d fallback operations", report.FallbackCount))
|
||||
}
|
||||
metadata := map[string]any{
|
||||
"stage": "extract", "notarius_enabled": true, "bundle_root": bundle,
|
||||
"diagnostic_path": logPath, "narratio_run_id": runID,
|
||||
"configuration_fingerprint": fingerprint, "direct_input": input.Metadata(),
|
||||
"reference_count": len(references.Identities), "references": extractReferenceMetadata(references.Identities),
|
||||
"completion": completion,
|
||||
metadataReferences := references.Identities
|
||||
if len(metadataReferences) > config.MaxNotariusReferenceBindings {
|
||||
metadataReferences = metadataReferences[:config.MaxNotariusReferenceBindings]
|
||||
}
|
||||
metadata := map[string]any{"stage": "extract", "notarius_enabled": true, "bundle_root": bundle, "diagnostic_path": logPath}
|
||||
for key, value := range artifacts.EncodeExtractionMetadata(artifacts.ExtractionMetadata{
|
||||
RunID: runID, ConfigurationFingerprint: fingerprint, Input: input, References: metadataReferences, ReferenceCount: len(references.Identities),
|
||||
Completion: artifacts.ExtractionCompletion{Pipeline: report.Pipeline, ArtifactCount: report.ArtifactCount, OutputDirectory: bundle, DebugDirectory: report.DebugDirectory, FallbackCount: report.FallbackCount},
|
||||
}) {
|
||||
metadata[key] = value
|
||||
}
|
||||
|
||||
result = &StageResult{Outputs: outputs, Logs: []string{reportPath, logPath}, Metadata: metadata}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -20,13 +20,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
||||
)
|
||||
|
||||
type extractReferenceIdentity struct {
|
||||
Selector string `json:"selector"`
|
||||
SourceID string `json:"source_id"`
|
||||
Path string `json:"path"`
|
||||
Checksum string `json:"checksum"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
}
|
||||
type extractReferenceIdentity = artifacts.ExtractionReferenceIdentity
|
||||
|
||||
func materializeExtractReferenceSnapshots(
|
||||
paths artifacts.SessionPaths,
|
||||
@@ -296,21 +290,3 @@ func resolveExtractReferences(
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
func extractReferenceMetadata(identities []extractReferenceIdentity) []map[string]any {
|
||||
limit := len(identities)
|
||||
if limit > config.MaxNotariusReferenceBindings {
|
||||
limit = config.MaxNotariusReferenceBindings
|
||||
}
|
||||
metadata := make([]map[string]any, 0, limit)
|
||||
for _, identity := range identities[:limit] {
|
||||
metadata = append(metadata, map[string]any{
|
||||
"selector": identity.Selector,
|
||||
"source_id": identity.SourceID,
|
||||
"path": identity.Path,
|
||||
"checksum": identity.Checksum,
|
||||
"size_bytes": identity.SizeBytes,
|
||||
})
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package stage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -46,7 +45,7 @@ func (extractStage) ValidateResume(_ context.Context, env *Env, m *manifest.Mani
|
||||
return ResumeValidation{}, fmt.Errorf("extract resume: build configuration fingerprint: %w", err)
|
||||
}
|
||||
record := m.Stages[(extractStage{}).Name()]
|
||||
if record == nil || metadataString(record.Metadata, "configuration_fingerprint") != fingerprint {
|
||||
if record == nil || artifacts.DecodeExtractionMetadata(record.Metadata).ConfigurationFingerprint != fingerprint {
|
||||
return NonResumable("Notarius invocation contract changed"), nil
|
||||
}
|
||||
proof := artifacts.InspectExtractionEvidence(paths, m, definitions, input)
|
||||
@@ -64,27 +63,5 @@ func (extractStage) ValidateResume(_ context.Context, env *Env, m *manifest.Mani
|
||||
|
||||
// ExtractionFallbackCount reports the positive native emitting-operation count.
|
||||
func ExtractionFallbackCount(metadata map[string]any) int {
|
||||
completion, _ := metadata["completion"].(map[string]any)
|
||||
switch value := completion["fallback_count"].(type) {
|
||||
case int:
|
||||
return value
|
||||
case float64:
|
||||
if value > 0 && value == float64(int(value)) {
|
||||
return int(value)
|
||||
}
|
||||
case json.Number:
|
||||
parsed, err := value.Int64()
|
||||
if err == nil && parsed > 0 && int64(int(parsed)) == parsed {
|
||||
return int(parsed)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func metadataString(metadata map[string]any, key string) string {
|
||||
if metadata == nil {
|
||||
return ""
|
||||
}
|
||||
value, _ := metadata[key].(string)
|
||||
return strings.TrimSpace(value)
|
||||
return artifacts.DecodeExtractionMetadata(metadata).Completion.FallbackCount
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user