Report structured session validation and inspection results
This commit is contained in:
@@ -499,6 +499,17 @@ operation initializes a runtime workspace or stage adapters.
|
|||||||
|
|
||||||
## Stage 12: Convert read-only session inspection commands
|
## Stage 12: Convert read-only session inspection commands
|
||||||
|
|
||||||
|
**Completed.** Native session validate/status/artifacts declarations share typed
|
||||||
|
selectors and read-only acquisition. Structured reports retain findings, local
|
||||||
|
stage/artifact evidence, audio/previous-input readiness, configuration provenance,
|
||||||
|
remote current state, locks, and exact published-output declarations including
|
||||||
|
carried origins. Partial failures retain reports and original causes; local-only
|
||||||
|
artifact inspection avoids storage and payload reads. Existing entry points
|
||||||
|
consume the same collectors. Native JSON/YAML, readiness/configuration failure,
|
||||||
|
remote partial-failure, carried-output identity, and manifest-immutability checks
|
||||||
|
pass alongside configuration, stage, artifact, focused composition, and build
|
||||||
|
checks with Go 1.27.4. Superseded parser/text assertions await final cleanup.
|
||||||
|
|
||||||
Read: `operator_session_validate.go`, `operator_status.go`,
|
Read: `operator_session_validate.go`, `operator_status.go`,
|
||||||
`operator_artifacts_list.go`, `operator_findings.go`, and `operator_inspection.go`.
|
`operator_artifacts_list.go`, `operator_findings.go`, and `operator_inspection.go`.
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"go.maximumdirect.net/commandkit"
|
"go.maximumdirect.net/commandkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,16 +52,20 @@ func loadArtifactCatalogReport(ctx context.Context, input configurationSelection
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return describeArtifactDefinitions(acquired.pipeline, catalog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func describeArtifactDefinitions(pipeline *config.PipelineConfig, catalog *config.ArtifactCatalog) (*artifactCatalogReport, error) {
|
||||||
configured := artifacts.ConfiguredArtifactDefinitions(catalog.Artifacts)
|
configured := artifacts.ConfiguredArtifactDefinitions(catalog.Artifacts)
|
||||||
effective, err := artifacts.ResolveEffectiveArtifactSet(configured, nil)
|
effective, err := artifacts.ResolveEffectiveArtifactSet(configured, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
runtime, err := artifacts.BootstrapRuntimeCatalog(configured, effective, artifacts.ExtractionDefinitionsFromConfig(acquired.pipeline.Notarius))
|
runtime, err := artifacts.BootstrapRuntimeCatalog(configured, effective, artifacts.ExtractionDefinitionsFromConfig(pipeline.Notarius))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
report = &artifactCatalogReport{Artifacts: []artifactDefinitionReport{}}
|
report := &artifactCatalogReport{Artifacts: []artifactDefinitionReport{}}
|
||||||
for _, spec := range artifacts.RuntimeTranscriptArtifacts() {
|
for _, spec := range artifacts.RuntimeTranscriptArtifacts() {
|
||||||
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Source: spec.SourceID, Producer: spec.ProducerStage, Output: spec.CanonicalRelPath, Dependencies: []string{}})
|
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Source: spec.SourceID, Producer: spec.ProducerStage, Output: spec.CanonicalRelPath, Dependencies: []string{}})
|
||||||
}
|
}
|
||||||
@@ -71,7 +76,7 @@ func loadArtifactCatalogReport(ctx context.Context, input configurationSelection
|
|||||||
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Key: record.Key, Source: record.SourceID, Producer: "analyze", Output: record.OutputPath, Enabled: &record.Enabled, Dependencies: append([]string{}, record.Dependencies...), Family: record.FamilyKey, CharacterID: record.CharacterID, DefinitionSources: record.DefinitionSources, FamilySources: record.FamilySources, PartySource: record.PartySource})
|
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Key: record.Key, Source: record.SourceID, Producer: "analyze", Output: record.OutputPath, Enabled: &record.Enabled, Dependencies: append([]string{}, record.Dependencies...), Family: record.FamilyKey, CharacterID: record.CharacterID, DefinitionSources: record.DefinitionSources, FamilySources: record.FamilySources, PartySource: record.PartySource})
|
||||||
}
|
}
|
||||||
for _, entry := range runtime.ListExtraction() {
|
for _, entry := range runtime.ListExtraction() {
|
||||||
enabled := acquired.pipeline.Notarius != nil && acquired.pipeline.Notarius.Enabled
|
enabled := pipeline.Notarius != nil && pipeline.Notarius.Enabled
|
||||||
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Key: entry.ExtractionKey, Source: entry.SourceID, Producer: entry.ProducerStage, Enabled: &enabled, Dependencies: []string{}})
|
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Key: entry.ExtractionKey, Source: entry.SourceID, Producer: entry.ProducerStage, Enabled: &enabled, Dependencies: []string{}})
|
||||||
}
|
}
|
||||||
sort.Slice(report.Artifacts, func(i, j int) bool { return report.Artifacts[i].Source < report.Artifacts[j].Source })
|
sort.Slice(report.Artifacts, func(i, j int) bool { return report.Artifacts[i].Source < report.Artifacts[j].Source })
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func newApplication(deps commandDependencies, executor pipelineExecutor) (*comma
|
|||||||
configurationCommand(deps),
|
configurationCommand(deps),
|
||||||
executionCommand("run", "Execute a session pipeline.", false, deps, executor),
|
executionCommand("run", "Execute a session pipeline.", false, deps, executor),
|
||||||
commandkit.Group("artifacts", "Inspect and regenerate configured artifacts.", artifactCatalogCommand(deps), executionCommand("regenerate", "Rebuild extraction and analysis artifacts.", true, deps, executor)),
|
commandkit.Group("artifacts", "Inspect and regenerate configured artifacts.", artifactCatalogCommand(deps), executionCommand("regenerate", "Rebuild extraction and analysis artifacts.", true, deps, executor)),
|
||||||
commandkit.Group("session", "Manage and inspect sessions.", sessionPlanCommand(deps)),
|
commandkit.Group("session", "Manage and inspect sessions.", sessionPlanCommand(deps), sessionValidationCommand(deps), sessionStateCommand("status", true, deps), sessionStateCommand("artifacts", false, deps)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,49 +156,22 @@ func remotePublishedOutputAvailabilityForCurrent(
|
|||||||
catalog *artifacts.ArtifactCatalog,
|
catalog *artifacts.ArtifactCatalog,
|
||||||
current *RemoteCurrentState,
|
current *RemoteCurrentState,
|
||||||
) map[string]string {
|
) map[string]string {
|
||||||
|
state := "current"
|
||||||
if current == nil || current.Commit == nil {
|
if current == nil || current.Commit == nil {
|
||||||
return unresolvedRemotePublishedOutputAvailability(cfg, catalog, "remote=missing")
|
state = "missing"
|
||||||
}
|
}
|
||||||
outcomes := committedPublishOutputOutcomes(current.Manifest)
|
outputs, _ := inspectPublishedOutputs(ctx, cfg, store, catalog, current, nil, false, state)
|
||||||
out := map[string]string{}
|
out := map[string]string{}
|
||||||
for _, rule := range cfg.PublicationOutputs() {
|
for _, output := range outputs {
|
||||||
source := strings.TrimSpace(rule.Source)
|
value := ""
|
||||||
dest, _, err := helperPublishedOutputDest(rule, catalog)
|
if output.Outcome != "" {
|
||||||
if err != nil {
|
value = "outcome=" + output.Outcome + " "
|
||||||
out[publishedOutputRemoteStateKey(source, "")] = "remote=error"
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
outcome := outcomes[source]
|
value += "remote=" + output.State
|
||||||
state := ""
|
if output.State == "published" && current != nil && (output.Outcome == "carried_locked" || output.OriginRun != current.RunID) {
|
||||||
if outcome != "" {
|
value += " declared_dest=" + output.DeclaredDestination + " declared_key=" + output.DeclaredKey + " origin_run=" + output.OriginRun
|
||||||
state = "outcome=" + outcome + " "
|
|
||||||
}
|
}
|
||||||
declaration, ok := committedPublishedOutput(current.Commit, source)
|
out[publishedOutputRemoteStateKey(output.Source, output.Destination)] = value
|
||||||
if !ok {
|
|
||||||
out[publishedOutputRemoteStateKey(source, dest)] = state + "remote=missing"
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
identity, err := artifacts.ParsePublishedOutputObjectKey(current.SessionPrefix, declaration.DestinationKey)
|
|
||||||
if err != nil {
|
|
||||||
out[publishedOutputRemoteStateKey(source, dest)] = state + "remote=error"
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
exists, err := store.Exists(ctx, declaration.DestinationKey)
|
|
||||||
if err != nil {
|
|
||||||
out[publishedOutputRemoteStateKey(source, dest)] = state + "remote=error"
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !exists {
|
|
||||||
out[publishedOutputRemoteStateKey(source, dest)] = state + "remote=missing"
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
state += "remote=published"
|
|
||||||
if outcome == "carried_locked" || identity.RunID != current.RunID {
|
|
||||||
state += " declared_dest=" + identity.Destination
|
|
||||||
state += " declared_key=" + declaration.DestinationKey
|
|
||||||
state += " origin_run=" + identity.RunID
|
|
||||||
}
|
|
||||||
out[publishedOutputRemoteStateKey(source, dest)] = state
|
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ArtifactsList lists effective artifact sources.
|
// ArtifactsList lists effective artifact sources.
|
||||||
@@ -27,24 +30,14 @@ func artifactsListWithDependencies(ctx context.Context, args []string, out io.Wr
|
|||||||
if strings.TrimSpace(flags.sessionID) == "" {
|
if strings.TrimSpace(flags.sessionID) == "" {
|
||||||
return fmt.Errorf("artifacts list: session_id is required")
|
return fmt.Errorf("artifacts list: session_id is required")
|
||||||
}
|
}
|
||||||
cfg, store, locks, m, cleanup, err := loadHelperContextWithDependencies(ctx, flags, remote, deps)
|
loaded, err := loadCommandConfigWithDependencies(ctx, flags.pipelinePath, flags.campaignPath, flags.campaignFilePath, flags.sessionPath, flags.sessionOptions(), flags.secretsDir.pointer(), deps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("artifacts list: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
defer cleanup()
|
defer func() { _ = loaded.Close() }()
|
||||||
catalog, err := buildHelperArtifactCatalog(cfg, m)
|
report, err := inspectSessionState(ctx, loaded.Config, false, remote, deps)
|
||||||
if err != nil {
|
if report != nil {
|
||||||
return fmt.Errorf("artifacts list: %w", err)
|
err = errors.Join(err, commandkit.RenderReport(out, commandkit.Report{Value: report}, ""))
|
||||||
}
|
}
|
||||||
publishedRemoteState := map[string]string{}
|
return err
|
||||||
if remote && store != nil {
|
|
||||||
current := inspectRemoteCurrentStateWithDependencies(ctx, cfg, store, deps)
|
|
||||||
if current.Err != nil {
|
|
||||||
publishedRemoteState = unresolvedRemotePublishedOutputAvailability(cfg, catalog, "remote=error")
|
|
||||||
} else {
|
|
||||||
publishedRemoteState = remotePublishedOutputAvailabilityForCurrent(ctx, cfg, store, catalog, current.State)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writeArtifactList(out, cfg, catalog, locks, publishedRemoteState)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type finding struct {
|
type finding struct {
|
||||||
Severity string
|
Severity string `json:"severity"`
|
||||||
Category string
|
Category string `json:"category"`
|
||||||
Message string
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type findingError struct {
|
type findingError struct {
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ func requireInspectionFile(path, label string) error {
|
|||||||
info, err := os.Stat(path)
|
info, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return fmt.Errorf("%s %q does not exist", label, path)
|
return fmt.Errorf("%s %q does not exist: %w", label, path, err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("stat %s %q: %w", label, path, err)
|
return fmt.Errorf("stat %s %q: %w", label, path, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,11 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SessionValidate performs a read-only session preflight.
|
// SessionValidate performs a read-only session preflight.
|
||||||
@@ -29,72 +27,16 @@ func sessionValidateWithDependencies(ctx context.Context, args []string, out io.
|
|||||||
return fmt.Errorf("session validate: session_id is required")
|
return fmt.Errorf("session validate: session_id is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
findings := []finding{}
|
|
||||||
loaded, err := loadCommandConfigWithDependencies(ctx, flags.pipelinePath, flags.campaignPath, flags.campaignFilePath, flags.sessionPath, flags.sessionOptions(), flags.secretsDir.pointer(), deps)
|
loaded, err := loadCommandConfigWithDependencies(ctx, flags.pipelinePath, flags.campaignPath, flags.campaignFilePath, flags.sessionPath, flags.sessionOptions(), flags.secretsDir.pointer(), deps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
findings = append(findings, errorFinding("config", err.Error()))
|
return renderFindings(out, "", "", []finding{errorFinding("config", err.Error())})
|
||||||
return renderFindings(out, "", "", findings)
|
|
||||||
}
|
}
|
||||||
defer func() { _ = loaded.Close() }()
|
defer func() { _ = loaded.Close() }()
|
||||||
cfg := loaded.Config
|
report, err := inspectSessionValidation(ctx, loaded.Config, deps)
|
||||||
if err := config.Validate(cfg); err != nil {
|
if report == nil {
|
||||||
findings = append(findings, errorFinding("config", err.Error()))
|
return err
|
||||||
} else {
|
|
||||||
findings = append(findings, okFinding("config", "resolved pipeline, campaign, and session config"))
|
|
||||||
}
|
}
|
||||||
findings = append(findings, okFinding("session", fmt.Sprintf("session source: %s", sessionSourceSummary(cfg))))
|
return errors.Join(err, renderFindings(out, report.Campaign, report.SessionID, report.Findings))
|
||||||
|
|
||||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
|
||||||
findings = append(findings, validateStableInputFindings(cfg)...)
|
|
||||||
findings = append(findings, validateLocalAudioFindings(cfg)...)
|
|
||||||
|
|
||||||
store, storeErr := objectStoreIfConfiguredWithDependencies(ctx, cfg, deps)
|
|
||||||
if storeErr != nil {
|
|
||||||
findings = append(findings, errorFinding("storage", storeErr.Error()))
|
|
||||||
}
|
|
||||||
if cfg.Session.Inputs.AudioS3 != nil {
|
|
||||||
if storeErr != nil {
|
|
||||||
findings = append(findings, errorFinding("audio", "remote audio cannot be checked because storage is unavailable"))
|
|
||||||
} else {
|
|
||||||
findings = append(findings, validateRemoteAudioFinding(ctx, cfg, store))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
effective, effectiveErr := resolveEffectiveArtifacts(cfg, nil)
|
|
||||||
if effectiveErr != nil {
|
|
||||||
findings = append(findings, errorFinding("config", effectiveErr.Error()))
|
|
||||||
return renderFindings(out, cfg.Session.Campaign, cfg.Session.SessionID, findings)
|
|
||||||
}
|
|
||||||
requirements := artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective)
|
|
||||||
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, requirements)
|
|
||||||
if len(previous.Requirements) == 0 {
|
|
||||||
findings = append(findings, okFinding("previous", "no previous-session artifacts required"))
|
|
||||||
} else if previous.Err != nil {
|
|
||||||
findings = append(findings, errorFinding("previous", previous.Err.Error()))
|
|
||||||
} else {
|
|
||||||
for _, req := range previous.Requirements {
|
|
||||||
if !req.Required && previousRequirementSkipped(previous.SkippedMissing, req.Name) {
|
|
||||||
findings = append(findings, okFinding("previous", fmt.Sprintf("%s required=false unavailable", req.Name)))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
findings = append(findings, okFinding("previous", fmt.Sprintf("%s required=%t", req.Name, req.Required)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
locks := inspectRemoteLocks(ctx, cfg, store)
|
|
||||||
if locks.Err != nil {
|
|
||||||
findings = append(findings, errorFinding("locks", locks.Err.Error()))
|
|
||||||
} else if len(locks.Locks) == 0 {
|
|
||||||
findings = append(findings, okFinding("locks", "no publish locks"))
|
|
||||||
} else {
|
|
||||||
for _, lock := range locks.Locks {
|
|
||||||
findings = append(findings, warnFinding("locks", fmt.Sprintf("%s locked: %s", lock.Source, strings.TrimSpace(lock.Reason))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if paths.ManifestPath != "" {
|
|
||||||
findings = append(findings, infoFinding("workspace", "manifest path: "+paths.ManifestPath))
|
|
||||||
}
|
|
||||||
return renderFindings(out, cfg.Session.Campaign, cfg.Session.SessionID, findings)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func previousRequirementSkipped(values []string, name string) bool {
|
func previousRequirementSkipped(values []string, name string) bool {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -9,9 +10,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"go.maximumdirect.net/commandkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Status reports effective local/remote session state.
|
// Status reports effective local/remote session state.
|
||||||
@@ -37,88 +37,11 @@ func statusWithDependencies(ctx context.Context, args []string, out io.Writer, d
|
|||||||
}
|
}
|
||||||
defer func() { _ = loaded.Close() }()
|
defer func() { _ = loaded.Close() }()
|
||||||
cfg := loaded.Config
|
cfg := loaded.Config
|
||||||
if err := config.Validate(cfg); err != nil {
|
report, err := inspectSessionState(ctx, cfg, true, true, deps)
|
||||||
return fmt.Errorf("status: %w", err)
|
if report != nil {
|
||||||
|
err = errors.Join(err, commandkit.RenderReport(out, commandkit.Report{Value: report}, ""))
|
||||||
}
|
}
|
||||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
return err
|
||||||
fmt.Fprintf(out, "Session: %s\n", cfg.Session.SessionID)
|
|
||||||
fmt.Fprintf(out, "Campaign: %s\n", cfg.Session.Campaign)
|
|
||||||
fmt.Fprintf(out, "Workspace: %s\n", paths.Root)
|
|
||||||
fmt.Fprintf(out, "Session config: %s\n", sessionSourceSummary(cfg))
|
|
||||||
fmt.Fprintf(out, "Configuration (current): %s\n", effectiveConfigSummary(cfg))
|
|
||||||
writeStatusStableInputs(out, inspectStableInputs(cfg))
|
|
||||||
writeStatusLocalAudio(out, inspectLocalAudioPresence(cfg))
|
|
||||||
|
|
||||||
var localManifest *manifest.Manifest
|
|
||||||
if m, err := loadLocalManifest(ctx, paths.ManifestPath); err != nil {
|
|
||||||
fmt.Fprintf(out, "Local manifest: error: %v\n", err)
|
|
||||||
} else if m == nil {
|
|
||||||
fmt.Fprintln(out, "Local manifest: missing")
|
|
||||||
} else {
|
|
||||||
localManifest = m
|
|
||||||
fmt.Fprintf(out, "Local manifest: %s\n", paths.ManifestPath)
|
|
||||||
fmt.Fprintf(out, "Configuration (last persisted): %s\n", persistedEffectiveConfigSummary(m.EffectiveConfig))
|
|
||||||
writeStageStatuses(out, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
store, storeErr := objectStoreIfConfiguredWithDependencies(ctx, cfg, deps)
|
|
||||||
var remoteCurrent *RemoteCurrentState
|
|
||||||
var remoteCurrentErr error
|
|
||||||
if storeErr != nil {
|
|
||||||
fmt.Fprintf(out, "Remote publish: unavailable: %v\n", storeErr)
|
|
||||||
} else if store != nil {
|
|
||||||
current := inspectRemoteCurrentStateWithDependencies(ctx, cfg, store, deps)
|
|
||||||
if current.Err != nil {
|
|
||||||
remoteCurrentErr = current.Err
|
|
||||||
fmt.Fprintf(out, "Remote publish: missing or unavailable: %v\n", current.Err)
|
|
||||||
} else {
|
|
||||||
remoteCurrent = current.State
|
|
||||||
fmt.Fprintf(out, "Remote publish: current run %s\n", current.State.RunID)
|
|
||||||
fmt.Fprintf(out, "Remote manifest: %s\n", current.State.CurrentManifestKey)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writeStatusRemoteAudio(ctx, out, cfg, store, storeErr)
|
|
||||||
effective, effectiveErr := resolveEffectiveArtifacts(cfg, nil)
|
|
||||||
if effectiveErr != nil {
|
|
||||||
return fmt.Errorf("status: resolve effective artifacts: %w", effectiveErr)
|
|
||||||
}
|
|
||||||
writeStatusPreviousArtifacts(out, inspectPreviousArtifactReadiness(
|
|
||||||
ctx,
|
|
||||||
cfg,
|
|
||||||
store,
|
|
||||||
artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective),
|
|
||||||
))
|
|
||||||
|
|
||||||
lockChecks := inspectRemoteLocks(ctx, cfg, store)
|
|
||||||
locks := lockChecks.Locks
|
|
||||||
lockErr := lockChecks.Err
|
|
||||||
if catalog, catalogErr := buildHelperArtifactCatalog(cfg, localManifest); catalogErr != nil {
|
|
||||||
fmt.Fprintf(out, "Remote outputs: error: %v\n", catalogErr)
|
|
||||||
} else if storeErr == nil {
|
|
||||||
catalogLocks := locks
|
|
||||||
if lockErr != nil {
|
|
||||||
catalogLocks = nil
|
|
||||||
}
|
|
||||||
publishedRemoteState := map[string]string{}
|
|
||||||
if store != nil {
|
|
||||||
if remoteCurrentErr != nil {
|
|
||||||
publishedRemoteState = unresolvedRemotePublishedOutputAvailability(cfg, catalog, "remote=error")
|
|
||||||
} else {
|
|
||||||
publishedRemoteState = remotePublishedOutputAvailabilityForCurrent(ctx, cfg, store, catalog, remoteCurrent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprintln(out, "Remote outputs:")
|
|
||||||
writeArtifactList(out, cfg, catalog, catalogLocks, publishedRemoteState)
|
|
||||||
}
|
|
||||||
if lockErr != nil {
|
|
||||||
fmt.Fprintf(out, "Publish locks: error: %v\n", lockErr)
|
|
||||||
} else {
|
|
||||||
writeLocks(out, cfg, locks)
|
|
||||||
}
|
|
||||||
fmt.Fprintln(out, "Next actions:")
|
|
||||||
fmt.Fprintf(out, "- narratio session validate %s\n", cfg.Session.SessionID)
|
|
||||||
fmt.Fprintf(out, "- narratio session restore %s --dry-run\n", cfg.Session.SessionID)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeStatusStableInputs(out io.Writer, checks []stableInputCheck) {
|
func writeStatusStableInputs(out io.Writer, checks []stableInputCheck) {
|
||||||
|
|||||||
146
internal/app/session_inspection_command.go
Normal file
146
internal/app/session_inspection_command.go
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sessionInspectionInput struct {
|
||||||
|
Selection configurationSelection
|
||||||
|
PreviousSession commandkit.Supplied[string]
|
||||||
|
Remote commandkit.Supplied[bool]
|
||||||
|
}
|
||||||
|
|
||||||
|
type sessionValidationReport struct {
|
||||||
|
Campaign string `json:"campaign"`
|
||||||
|
SessionID string `json:"session_id"`
|
||||||
|
SessionSource string `json:"session_source,omitempty"`
|
||||||
|
Valid bool `json:"valid"`
|
||||||
|
Findings []finding `json:"findings"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func sessionInspectionSpec(name, summary string, remoteOption bool) commandkit.CommandSpec[*sessionInspectionInput] {
|
||||||
|
common := newConfigurationFlags(func(input **sessionInspectionInput) *configurationSelection { return &(*input).Selection })
|
||||||
|
flags := []commandkit.Flag[*sessionInspectionInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile, common.SecretsDir,
|
||||||
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **sessionInspectionInput, value commandkit.Supplied[string]) {
|
||||||
|
(*input).PreviousSession = value
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
if remoteOption {
|
||||||
|
flags = append(flags, commandkit.BoolFlag(commandkit.FlagMeta{Name: "remote", Usage: "Inspect remote publication and locks."}, false, func(input **sessionInspectionInput, value commandkit.Supplied[bool]) { (*input).Remote = value }))
|
||||||
|
}
|
||||||
|
return commandkit.CommandSpec[*sessionInspectionInput]{Name: name, Summary: summary, NewInput: func() *sessionInspectionInput { return &sessionInspectionInput{} }, Flags: flags,
|
||||||
|
Arguments: []commandkit.Argument[*sessionInspectionInput]{commandkit.ValueArgument(commandkit.ArgumentMeta{Name: "SESSION", Usage: "Session identity."}, true, stringValue, func(input **sessionInspectionInput, value commandkit.Supplied[string]) {
|
||||||
|
(*input).Selection.Session = value
|
||||||
|
})},
|
||||||
|
CheckInput: func(input *sessionInspectionInput) error { return checkConfigurationSelection(input.Selection) },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sessionValidationCommand(deps commandDependencies) commandkit.Command {
|
||||||
|
spec := sessionInspectionSpec("validate", "Check session readiness without executing work.", false)
|
||||||
|
spec.Run = func(invocation commandkit.Invocation, input *sessionInspectionInput) commandkit.Outcome {
|
||||||
|
report, err := validateSelectedSession(invocation.Context, input, deps)
|
||||||
|
if report != nil {
|
||||||
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
|
}
|
||||||
|
return operationOutcome(err)
|
||||||
|
}
|
||||||
|
return commandkit.NewCommand(spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateSelectedSession(ctx context.Context, input *sessionInspectionInput, deps commandDependencies) (report *sessionValidationReport, err error) {
|
||||||
|
deps = normalizeCommandDependencies(deps)
|
||||||
|
deps.secretsBootstrap = &secretsBootstrap{}
|
||||||
|
acquired := newConfigurationAcquisition(input.Selection, deps)
|
||||||
|
acquired.previousSessionID = input.PreviousSession.Value
|
||||||
|
defer func() { err = errors.Join(err, acquired.Close()) }()
|
||||||
|
cfg, err := acquired.Domain(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return &sessionValidationReport{Campaign: input.Selection.Campaign.Value, SessionID: input.Selection.Session.Value, Findings: []finding{errorFinding("config", err.Error())}}, err
|
||||||
|
}
|
||||||
|
return inspectSessionValidation(ctx, cfg, deps)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps commandDependencies) (*sessionValidationReport, error) {
|
||||||
|
report := &sessionValidationReport{Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID, SessionSource: sessionSourceSummary(cfg), Findings: []finding{}}
|
||||||
|
var resultErr error
|
||||||
|
fail := func(category string, err error) {
|
||||||
|
if err != nil {
|
||||||
|
report.Findings = append(report.Findings, errorFinding(category, err.Error()))
|
||||||
|
resultErr = errors.Join(resultErr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := config.Validate(cfg); err != nil {
|
||||||
|
fail("config", err)
|
||||||
|
} else {
|
||||||
|
report.Findings = append(report.Findings, okFinding("config", "resolved pipeline, campaign, and session config"))
|
||||||
|
}
|
||||||
|
for _, check := range inspectStableInputs(cfg) {
|
||||||
|
if check.Err != nil {
|
||||||
|
fail("inputs", fmt.Errorf("%s: %w", check.Name, check.Err))
|
||||||
|
} else {
|
||||||
|
report.Findings = append(report.Findings, okFinding("inputs", check.Name+": "+check.Path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
local := inspectLocalAudioPresence(cfg)
|
||||||
|
if local.Checked {
|
||||||
|
if local.Err != nil {
|
||||||
|
fail("audio", local.Err)
|
||||||
|
} else {
|
||||||
|
report.Findings = append(report.Findings, okFinding("audio", fmt.Sprintf("%d local audio file(s)", len(local.Paths))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
store, storeErr := objectStoreIfConfiguredWithDependencies(ctx, cfg, deps)
|
||||||
|
fail("storage", storeErr)
|
||||||
|
if cfg.Session.Inputs.AudioS3 != nil {
|
||||||
|
if storeErr != nil {
|
||||||
|
report.Findings = append(report.Findings, errorFinding("audio", "remote audio cannot be checked because storage is unavailable"))
|
||||||
|
} else {
|
||||||
|
remote := inspectRemoteAudioPresence(ctx, cfg, store)
|
||||||
|
if remote.Err != nil {
|
||||||
|
fail("audio", remote.Err)
|
||||||
|
} else {
|
||||||
|
report.Findings = append(report.Findings, okFinding("audio", fmt.Sprintf("%d remote .flac object(s)", len(remote.Keys))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
effective, effectiveErr := resolveEffectiveArtifacts(cfg, nil)
|
||||||
|
fail("config", effectiveErr)
|
||||||
|
if effectiveErr == nil {
|
||||||
|
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective))
|
||||||
|
if len(previous.Requirements) == 0 {
|
||||||
|
report.Findings = append(report.Findings, okFinding("previous", "no previous-session artifacts required"))
|
||||||
|
} else if previous.Err != nil {
|
||||||
|
fail("previous", previous.Err)
|
||||||
|
} else {
|
||||||
|
for _, requirement := range previous.Requirements {
|
||||||
|
message := fmt.Sprintf("%s required=%t", requirement.Name, requirement.Required)
|
||||||
|
if !requirement.Required && previousRequirementSkipped(previous.SkippedMissing, requirement.Name) {
|
||||||
|
message += " unavailable"
|
||||||
|
}
|
||||||
|
report.Findings = append(report.Findings, okFinding("previous", message))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
locks := inspectRemoteLocks(ctx, cfg, store)
|
||||||
|
if locks.Err != nil {
|
||||||
|
fail("locks", locks.Err)
|
||||||
|
} else if len(locks.Locks) == 0 {
|
||||||
|
report.Findings = append(report.Findings, okFinding("locks", "no publish locks"))
|
||||||
|
} else {
|
||||||
|
for _, lock := range locks.Locks {
|
||||||
|
report.Findings = append(report.Findings, warnFinding("locks", fmt.Sprintf("%s locked: %s", lock.Source, strings.TrimSpace(lock.Reason))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
report.Findings = append(report.Findings, infoFinding("workspace", "manifest path: "+paths.ManifestPath))
|
||||||
|
report.Valid = resultErr == nil
|
||||||
|
return report, resultErr
|
||||||
|
}
|
||||||
226
internal/app/session_inspection_command_test.go
Normal file
226
internal/app/session_inspection_command_test.go
Normal file
@@ -0,0 +1,226 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSessionValidationCommandReturnsFindingsWithoutRuntimeState(t *testing.T) {
|
||||||
|
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// A missing stable input is a readiness failure, not malformed configuration.
|
||||||
|
missing := cfg.StableInputs.SpeakersFile.Path
|
||||||
|
if err := os.Remove(missing); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var out, diagnostic bytes.Buffer
|
||||||
|
deps, _ := remoteSessionLoaderDependencies(&storage.FakeBackend{})
|
||||||
|
app, err := newApplication(deps, executePlan)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
outcome := app.Execute(context.Background(), []string{"session", "validate", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
|
if outcome.Status != 1 {
|
||||||
|
t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String())
|
||||||
|
}
|
||||||
|
var report sessionValidationReport
|
||||||
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if report.Valid || report.SessionID != "2026-05-03" || len(report.Findings) == 0 {
|
||||||
|
t.Fatalf("report=%#v", report)
|
||||||
|
}
|
||||||
|
if !errors.Is(outcome.Cause, os.ErrNotExist) {
|
||||||
|
t.Fatalf("missing input cause not retained: %v", outcome.Cause)
|
||||||
|
}
|
||||||
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
if _, err := os.Stat(paths.Root); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("preflight created runtime state: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSessionValidationCommandReportsNativeConfigurationFailure(t *testing.T) {
|
||||||
|
pipeline := filepath.Join(t.TempDir(), "invalid.yml")
|
||||||
|
mustWriteTestFile(t, pipeline, "unknown_field: value\n")
|
||||||
|
var out, diagnostic bytes.Buffer
|
||||||
|
outcome := Execute(context.Background(), []string{"session", "validate", "session", "--config", pipeline, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
|
if outcome.Status != 2 {
|
||||||
|
t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String())
|
||||||
|
}
|
||||||
|
var report sessionValidationReport
|
||||||
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if report.Valid || len(report.Findings) != 1 || report.Findings[0].Category != "config" {
|
||||||
|
t.Fatalf("report=%#v", report)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSessionArtifactCommandIsLocalWithoutRemoteOption(t *testing.T) {
|
||||||
|
pipeline, campaign, session := writeValidConfigFilesWithScriptoriumArtifacts(t, t.TempDir())
|
||||||
|
app, err := newApplication(commandDependencies{newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
||||||
|
t.Fatal("local artifact inspection acquired remote storage")
|
||||||
|
return nil, nil
|
||||||
|
}}, executePlan)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var out, diagnostic bytes.Buffer
|
||||||
|
outcome := app.Execute(context.Background(), []string{"session", "artifacts", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
|
if outcome.Status != 0 {
|
||||||
|
t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String())
|
||||||
|
}
|
||||||
|
var report sessionStateReport
|
||||||
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if report.Remote != nil || report.LocalManifest != "missing" || len(report.Artifacts) == 0 {
|
||||||
|
t.Fatalf("report=%#v", report)
|
||||||
|
}
|
||||||
|
found := false
|
||||||
|
for _, entry := range report.Artifacts {
|
||||||
|
if entry.Source == "narratio.artifact.session_recap" {
|
||||||
|
found = entry.Producer == "analyze" && entry.Availability == "unavailable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Fatal("report lost configured source or producer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSessionStateCommandReturnsPartialRemoteFailure(t *testing.T) {
|
||||||
|
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
failure := errors.New("synthetic remote failure")
|
||||||
|
fake := &storage.FakeBackend{}
|
||||||
|
deps, _ := remoteSessionLoaderDependencies(fake)
|
||||||
|
deps.discoverRemoteCurrentState = func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error) {
|
||||||
|
return nil, failure
|
||||||
|
}
|
||||||
|
app, err := newApplication(deps, executePlan)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, command := range []string{"status", "artifacts"} {
|
||||||
|
args := []string{"session", command, "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", "json"}
|
||||||
|
if command == "artifacts" {
|
||||||
|
args = append(args, "--remote")
|
||||||
|
}
|
||||||
|
var out, diagnostic bytes.Buffer
|
||||||
|
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
|
if outcome.Status != 1 || !errors.Is(outcome.Cause, failure) {
|
||||||
|
t.Fatalf("command=%s status=%d cause=%v diagnostics=%s", command, outcome.Status, outcome.Cause, diagnostic.String())
|
||||||
|
}
|
||||||
|
var report sessionStateReport
|
||||||
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if report.Remote == nil || report.Remote.State != "error" || len(report.Artifacts) == 0 || len(report.Findings) == 0 {
|
||||||
|
t.Fatalf("partial report=%#v", report)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(fake.Downloads) != 0 || len(fake.Reads) != 0 || len(fake.Uploads) != 0 || len(fake.Deletes) != 0 {
|
||||||
|
t.Fatal("inspection touched remote payloads")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPublishedOutputInspectionKeepsCarriedIdentityWithoutPayloadReads(t *testing.T) {
|
||||||
|
cfg := restorePlanConfig(t)
|
||||||
|
cfg.ArtifactCatalog = &config.ArtifactCatalog{PublishOutputs: []config.PublishOutputRule{{Source: "narratio.transcript.final_trimmed", Dest: "transcripts/full.json"}}}
|
||||||
|
fake := &storage.FakeBackend{}
|
||||||
|
current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{"transcripts/full.json": []byte("carried\n")})
|
||||||
|
const originRun = "20260512T010203Z-11223344"
|
||||||
|
key := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(current.SessionPrefix, originRun), "published/transcripts/original.json")
|
||||||
|
fake.SeedObject(storage.FakeObject{Key: key, Data: []byte("carried\n")})
|
||||||
|
current.Commit.Artifacts[1].Source = "narratio.transcript.final_trimmed"
|
||||||
|
current.Commit.Artifacts[1].DestinationKey = key
|
||||||
|
current.Manifest.Stages["publish"] = &manifest.StageRecord{Name: "publish", Status: manifest.StatusSucceeded, Metadata: map[string]any{"publish_output_outcomes": []any{map[string]any{"source": "narratio.transcript.final_trimmed", "status": "carried_locked"}}}}
|
||||||
|
reads := len(fake.Reads)
|
||||||
|
outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, []artifacts.RemoteLock{{Source: "narratio.transcript.final_trimmed"}}, true, "current")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(outputs) != 1 {
|
||||||
|
t.Fatalf("outputs=%#v", outputs)
|
||||||
|
}
|
||||||
|
output := outputs[0]
|
||||||
|
if output.State != "published" || output.Outcome != "carried_locked" || output.LockState != "locked" || output.DeclaredKey != key || output.DeclaredDestination != "transcripts/original.json" || output.OriginRun != originRun {
|
||||||
|
t.Fatalf("output=%#v", output)
|
||||||
|
}
|
||||||
|
if len(fake.Reads) != reads || fake.ExistsKeys[len(fake.ExistsKeys)-1] != key {
|
||||||
|
t.Fatal("inspection did not use only the exact declared object identity")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSessionStateCommandsLeaveManifestUnchanged(t *testing.T) {
|
||||||
|
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
m := manifest.New(cfg.Session.SessionID, time.Now().UTC())
|
||||||
|
m.Campaign = cfg.Session.Campaign
|
||||||
|
m.MarkStageSucceeded("prepare", time.Now().UTC(), nil)
|
||||||
|
if err := os.MkdirAll(filepath.Dir(paths.ManifestPath), 0755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := (&manifest.LocalStore{}).Save(context.Background(), paths.ManifestPath, m); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
before, err := os.ReadFile(paths.ManifestPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
fake := &storage.FakeBackend{}
|
||||||
|
deps, _ := remoteSessionLoaderDependencies(fake)
|
||||||
|
app, err := newApplication(deps, executePlan)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, test := range []struct{ command, format string }{{"status", "json"}, {"artifacts", "yaml"}} {
|
||||||
|
args := []string{"session", test.command, "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", test.format}
|
||||||
|
if test.command == "artifacts" {
|
||||||
|
args = append(args, "--remote")
|
||||||
|
}
|
||||||
|
var out, diagnostic bytes.Buffer
|
||||||
|
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
|
if outcome.Status != 0 {
|
||||||
|
t.Fatalf("%s status=%d diagnostics=%s", test.command, outcome.Status, diagnostic.String())
|
||||||
|
}
|
||||||
|
var report map[string]any
|
||||||
|
if test.format == "json" {
|
||||||
|
err = json.Unmarshal(out.Bytes(), &report)
|
||||||
|
} else {
|
||||||
|
err = yaml.Unmarshal(out.Bytes(), &report)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if report["local_manifest"] != "present" || report["session_id"] != "2026-05-03" || report["stages"] == nil {
|
||||||
|
t.Fatalf("report=%#v", report)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
after, err := os.ReadFile(paths.ManifestPath)
|
||||||
|
if err != nil || !bytes.Equal(before, after) {
|
||||||
|
t.Fatal("inspection modified manifest")
|
||||||
|
}
|
||||||
|
if len(fake.Uploads) != 0 || len(fake.Downloads) != 0 || len(fake.Deletes) != 0 {
|
||||||
|
t.Fatal("inspection mutated remote state or downloaded payloads")
|
||||||
|
}
|
||||||
|
}
|
||||||
301
internal/app/session_state_command.go
Normal file
301
internal/app/session_state_command.go
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sessionStateReport struct {
|
||||||
|
Campaign string `json:"campaign"`
|
||||||
|
SessionID string `json:"session_id"`
|
||||||
|
SessionSource string `json:"session_source,omitempty"`
|
||||||
|
LocalManifest string `json:"local_manifest"`
|
||||||
|
Stages []sessionStageState `json:"stages"`
|
||||||
|
Artifacts []sessionArtifactState `json:"artifacts"`
|
||||||
|
Remote *sessionRemoteState `json:"remote,omitempty"`
|
||||||
|
Configuration string `json:"configuration"`
|
||||||
|
PersistedConfiguration string `json:"persisted_configuration,omitempty"`
|
||||||
|
LocalAudio *sessionAudioState `json:"local_audio,omitempty"`
|
||||||
|
RemoteAudio *sessionAudioState `json:"remote_audio,omitempty"`
|
||||||
|
Previous []sessionPreviousState `json:"previous_artifacts,omitempty"`
|
||||||
|
Findings []finding `json:"findings"`
|
||||||
|
}
|
||||||
|
type sessionAudioState struct {
|
||||||
|
State string `json:"state"`
|
||||||
|
Count int `json:"count"`
|
||||||
|
Prefix string `json:"prefix,omitempty"`
|
||||||
|
}
|
||||||
|
type sessionPreviousState struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Required bool `json:"required"`
|
||||||
|
State string `json:"state"`
|
||||||
|
}
|
||||||
|
type sessionStageState struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
SkipReason string `json:"skip_reason,omitempty"`
|
||||||
|
}
|
||||||
|
type sessionArtifactState struct {
|
||||||
|
artifactDefinitionReport
|
||||||
|
Availability string `json:"availability"`
|
||||||
|
Provenance string `json:"provenance,omitempty"`
|
||||||
|
}
|
||||||
|
type sessionRemoteState struct {
|
||||||
|
State string `json:"state"`
|
||||||
|
RunID string `json:"run_id,omitempty"`
|
||||||
|
ManifestKey string `json:"manifest_key,omitempty"`
|
||||||
|
Locks []sessionLockState `json:"locks"`
|
||||||
|
Outputs []sessionPublishedOutput `json:"outputs"`
|
||||||
|
}
|
||||||
|
type sessionLockState struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
Reason string `json:"reason,omitempty"`
|
||||||
|
}
|
||||||
|
type sessionPublishedOutput struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
Destination string `json:"destination"`
|
||||||
|
Required bool `json:"required"`
|
||||||
|
State string `json:"state"`
|
||||||
|
LockState string `json:"lock_state"`
|
||||||
|
Outcome string `json:"outcome,omitempty"`
|
||||||
|
DeclaredDestination string `json:"declared_destination,omitempty"`
|
||||||
|
DeclaredKey string `json:"declared_key,omitempty"`
|
||||||
|
OriginRun string `json:"origin_run,omitempty"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func sessionStateCommand(name string, status bool, deps commandDependencies) commandkit.Command {
|
||||||
|
spec := sessionInspectionSpec(name, "Inspect session state without changing it.", !status)
|
||||||
|
spec.Run = func(invocation commandkit.Invocation, input *sessionInspectionInput) commandkit.Outcome {
|
||||||
|
report, err := inspectSelectedSessionState(invocation.Context, input, status, deps)
|
||||||
|
if report != nil {
|
||||||
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
|
}
|
||||||
|
return operationOutcome(err)
|
||||||
|
}
|
||||||
|
return commandkit.NewCommand(spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inspectSelectedSessionState(ctx context.Context, input *sessionInspectionInput, status bool, deps commandDependencies) (report *sessionStateReport, err error) {
|
||||||
|
deps = normalizeCommandDependencies(deps)
|
||||||
|
deps.secretsBootstrap = &secretsBootstrap{}
|
||||||
|
acquired := newConfigurationAcquisition(input.Selection, deps)
|
||||||
|
acquired.previousSessionID = input.PreviousSession.Value
|
||||||
|
defer func() { err = errors.Join(err, acquired.Close()) }()
|
||||||
|
report = &sessionStateReport{Campaign: input.Selection.Campaign.Value, SessionID: input.Selection.Session.Value, LocalManifest: "not_checked", Stages: []sessionStageState{}, Artifacts: []sessionArtifactState{}, Findings: []finding{}}
|
||||||
|
cfg, err := acquired.Domain(ctx)
|
||||||
|
if err != nil {
|
||||||
|
report.Findings = append(report.Findings, errorFinding("config", err.Error()))
|
||||||
|
return report, err
|
||||||
|
}
|
||||||
|
return inspectSessionState(ctx, cfg, status, status || input.Remote.Value, deps)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inspectSessionState(ctx context.Context, cfg *config.Config, status, remote bool, deps commandDependencies) (*sessionStateReport, error) {
|
||||||
|
report := &sessionStateReport{Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID, SessionSource: sessionSourceSummary(cfg), LocalManifest: "missing", Stages: []sessionStageState{}, Artifacts: []sessionArtifactState{}, Findings: []finding{}}
|
||||||
|
var resultErr error
|
||||||
|
fail := func(category string, err error) {
|
||||||
|
if err != nil {
|
||||||
|
report.Findings = append(report.Findings, errorFinding(category, err.Error()))
|
||||||
|
resultErr = errors.Join(resultErr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := config.Validate(cfg); err != nil {
|
||||||
|
fail("config", err)
|
||||||
|
return report, resultErr
|
||||||
|
}
|
||||||
|
report.Configuration = effectiveConfigSummary(cfg)
|
||||||
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
local, err := loadLocalManifest(ctx, paths.ManifestPath)
|
||||||
|
if err != nil {
|
||||||
|
report.LocalManifest = "error"
|
||||||
|
fail("manifest", err)
|
||||||
|
} else if local != nil {
|
||||||
|
report.LocalManifest = "present"
|
||||||
|
report.PersistedConfiguration = persistedEffectiveConfigSummary(local.EffectiveConfig)
|
||||||
|
names := make([]string, 0, len(local.Stages))
|
||||||
|
for name := range local.Stages {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
sort.Strings(names)
|
||||||
|
for _, name := range names {
|
||||||
|
record := local.Stages[name]
|
||||||
|
if record != nil {
|
||||||
|
report.Stages = append(report.Stages, sessionStageState{Name: name, Status: string(record.Status), SkipReason: inspectionSkipReason(record)})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catalog, catalogErr := buildHelperArtifactCatalog(cfg, local)
|
||||||
|
fail("artifacts", catalogErr)
|
||||||
|
definitions, definitionsErr := describeArtifactDefinitions(cfg.Pipeline, cfg.ArtifactCatalog)
|
||||||
|
fail("artifacts", definitionsErr)
|
||||||
|
if catalogErr == nil && definitionsErr == nil {
|
||||||
|
for _, definition := range definitions.Artifacts {
|
||||||
|
entry, _ := catalog.Lookup(definition.Source)
|
||||||
|
state := "unavailable"
|
||||||
|
if entry.Available {
|
||||||
|
state = "available"
|
||||||
|
}
|
||||||
|
if definition.Key == "" {
|
||||||
|
state = builtinArtifactInspectionState(local, entry)
|
||||||
|
}
|
||||||
|
report.Artifacts = append(report.Artifacts, sessionArtifactState{artifactDefinitionReport: definition, Availability: state, Provenance: entry.Provenance})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var store storage.ObjectStore
|
||||||
|
if remote {
|
||||||
|
report.Remote = &sessionRemoteState{State: "not_configured", Locks: []sessionLockState{}, Outputs: []sessionPublishedOutput{}}
|
||||||
|
store, err = objectStoreIfConfiguredWithDependencies(ctx, cfg, deps)
|
||||||
|
if err != nil {
|
||||||
|
report.Remote.State = "error"
|
||||||
|
fail("storage", err)
|
||||||
|
} else if store != nil {
|
||||||
|
current := inspectRemoteCurrentStateWithDependencies(ctx, cfg, store, deps)
|
||||||
|
if current.Err != nil {
|
||||||
|
if errors.Is(current.Err, artifacts.ErrCurrentCommitPointerMissing) {
|
||||||
|
report.Remote.State = "missing"
|
||||||
|
} else {
|
||||||
|
report.Remote.State = "error"
|
||||||
|
fail("remote", current.Err)
|
||||||
|
}
|
||||||
|
} else if current.State != nil {
|
||||||
|
report.Remote.State = "current"
|
||||||
|
report.Remote.RunID = current.State.RunID
|
||||||
|
report.Remote.ManifestKey = current.State.CurrentManifestKey
|
||||||
|
}
|
||||||
|
locks := inspectRemoteLocks(ctx, cfg, store)
|
||||||
|
fail("locks", locks.Err)
|
||||||
|
for _, lock := range locks.Locks {
|
||||||
|
report.Remote.Locks = append(report.Remote.Locks, sessionLockState{Source: lock.Source, Reason: lock.Reason})
|
||||||
|
}
|
||||||
|
if catalogErr == nil {
|
||||||
|
outputs, err := inspectPublishedOutputs(ctx, cfg, store, catalog, current.State, locks.Locks, locks.Err == nil, report.Remote.State)
|
||||||
|
report.Remote.Outputs = outputs
|
||||||
|
fail("publication", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if status {
|
||||||
|
for _, check := range inspectStableInputs(cfg) {
|
||||||
|
if check.Err != nil {
|
||||||
|
fail("inputs", check.Err)
|
||||||
|
} else {
|
||||||
|
report.Findings = append(report.Findings, infoFinding("inputs", check.Name+": "+check.Path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
audio := inspectLocalAudioPresence(cfg)
|
||||||
|
if audio.Checked {
|
||||||
|
report.LocalAudio = &sessionAudioState{State: "available", Count: len(audio.Paths)}
|
||||||
|
if audio.Err != nil {
|
||||||
|
report.LocalAudio.State = "unavailable"
|
||||||
|
fail("audio", audio.Err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cfg.Session.Inputs.AudioS3 != nil {
|
||||||
|
report.RemoteAudio = &sessionAudioState{State: "unavailable"}
|
||||||
|
if store != nil {
|
||||||
|
audio := inspectRemoteAudioPresence(ctx, cfg, store)
|
||||||
|
report.RemoteAudio.Count = len(audio.Keys)
|
||||||
|
report.RemoteAudio.Prefix = audio.Prefix
|
||||||
|
if audio.Err == nil {
|
||||||
|
report.RemoteAudio.State = "available"
|
||||||
|
} else {
|
||||||
|
fail("audio", audio.Err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
effective, err := resolveEffectiveArtifacts(cfg, nil)
|
||||||
|
fail("artifacts", err)
|
||||||
|
if err == nil {
|
||||||
|
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective))
|
||||||
|
fail("previous", previous.Err)
|
||||||
|
for _, requirement := range previous.Requirements {
|
||||||
|
state := "ready"
|
||||||
|
if previous.Err != nil || previousRequirementSkipped(previous.SkippedMissing, requirement.Name) {
|
||||||
|
state = "unavailable"
|
||||||
|
}
|
||||||
|
report.Previous = append(report.Previous, sessionPreviousState{Name: requirement.Name, Required: requirement.Required, State: state})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return report, resultErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Built-in inspection reports manifest evidence without opening artifact payloads.
|
||||||
|
func builtinArtifactInspectionState(local *manifest.Manifest, entry artifacts.CatalogEntry) string {
|
||||||
|
if local == nil {
|
||||||
|
return "unavailable"
|
||||||
|
}
|
||||||
|
record := local.Stages[entry.ProducerStage]
|
||||||
|
if record == nil || record.Status != manifest.StatusSucceeded {
|
||||||
|
return "unavailable"
|
||||||
|
}
|
||||||
|
for _, output := range record.Outputs {
|
||||||
|
if output.Kind == entry.OutputKind {
|
||||||
|
return "recorded"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "unavailable"
|
||||||
|
}
|
||||||
|
|
||||||
|
func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store storage.ObjectStore, catalog *artifacts.ArtifactCatalog, current *RemoteCurrentState, locks []artifacts.RemoteLock, locksKnown bool, remoteState string) ([]sessionPublishedOutput, error) {
|
||||||
|
outputs := make([]sessionPublishedOutput, 0, len(cfg.PublicationOutputs()))
|
||||||
|
locked := remoteLockSourceSet(locks)
|
||||||
|
outcomes := map[string]string{}
|
||||||
|
if current != nil {
|
||||||
|
outcomes = committedPublishOutputOutcomes(current.Manifest)
|
||||||
|
}
|
||||||
|
var resultErr error
|
||||||
|
for _, rule := range cfg.PublicationOutputs() {
|
||||||
|
destination, _, err := helperPublishedOutputDest(rule, catalog)
|
||||||
|
_, isLocked := locked[rule.Source]
|
||||||
|
output := sessionPublishedOutput{Source: rule.Source, Destination: destination, Required: rule.Required == nil || *rule.Required, LockState: "unknown", State: "missing", Outcome: outcomes[rule.Source]}
|
||||||
|
if locksKnown {
|
||||||
|
output.LockState = "unlocked"
|
||||||
|
if isLocked {
|
||||||
|
output.LockState = "locked"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if remoteState == "error" {
|
||||||
|
output.State = "error"
|
||||||
|
}
|
||||||
|
if err == nil && current != nil && current.Commit != nil {
|
||||||
|
if declaration, ok := committedPublishedOutput(current.Commit, rule.Source); ok {
|
||||||
|
identity, identityErr := artifacts.ParsePublishedOutputObjectKey(current.SessionPrefix, declaration.DestinationKey)
|
||||||
|
if identityErr != nil {
|
||||||
|
err = identityErr
|
||||||
|
} else {
|
||||||
|
output.DeclaredDestination = identity.Destination
|
||||||
|
output.DeclaredKey = declaration.DestinationKey
|
||||||
|
output.OriginRun = identity.RunID
|
||||||
|
exists, existsErr := store.Exists(ctx, declaration.DestinationKey)
|
||||||
|
err = existsErr
|
||||||
|
if exists && err == nil {
|
||||||
|
output.State = "published"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
output.State = "error"
|
||||||
|
output.Error = err.Error()
|
||||||
|
resultErr = errors.Join(resultErr, err)
|
||||||
|
}
|
||||||
|
outputs = append(outputs, output)
|
||||||
|
}
|
||||||
|
return outputs, resultErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func inspectionSkipReason(record *manifest.StageRecord) string {
|
||||||
|
if record.Status == manifest.StatusSkipped && record.Error != nil {
|
||||||
|
return record.Error.Message
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user