Separate session inspection collection from reporting
This commit is contained in:
@@ -201,6 +201,9 @@ Restore uses the same inventory. Obsolete execution-snapshot declarations are
|
||||
ignored without reading their contents; unsupported local progress must be moved
|
||||
aside before creating a new local baseline.
|
||||
|
||||
Session inspection collects local catalog, remote publication and lock, and
|
||||
input-readiness evidence separately before projecting its existing report.
|
||||
|
||||
For a new-protocol current state, the pointer-selected immutable commit is the
|
||||
complete restore authority. Callers receive its declared object identities and
|
||||
must not supplement them by listing mutable session prefixes.
|
||||
|
||||
@@ -553,7 +553,7 @@ Validation: `go test ./internal/preflight ./internal/app`.
|
||||
|
||||
## Stage 20: Separate Session Inspection Collection From Reporting
|
||||
|
||||
CAT IDs: CAT-25, inspection part. Status: Pending.
|
||||
CAT IDs: CAT-25, inspection part. Status: Complete.
|
||||
|
||||
Read Stage 19's CX-04 section and `app/session_state_command.go`,
|
||||
`artifact_inspection.go`, `operator_inspection.go`, and command tests.
|
||||
|
||||
@@ -120,117 +120,91 @@ func inspectSessionState(ctx context.Context, cfg *config.Config, status, remote
|
||||
return report, errors.Join(failures...)
|
||||
}
|
||||
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 {
|
||||
local := collectLocalSessionInspection(ctx, cfg)
|
||||
if local.manifestErr != nil {
|
||||
report.LocalManifest = "error"
|
||||
fail("manifest", err)
|
||||
} else if local != nil {
|
||||
fail("manifest", local.manifestErr)
|
||||
} else if local.manifest != nil {
|
||||
report.LocalManifest = "present"
|
||||
report.PersistedConfiguration = persistedEffectiveConfigSummary(local.EffectiveConfig)
|
||||
names := make([]string, 0, len(local.Stages))
|
||||
for name := range local.Stages {
|
||||
report.PersistedConfiguration = persistedEffectiveConfigSummary(local.manifest.EffectiveConfig)
|
||||
names := make([]string, 0, len(local.manifest.Stages))
|
||||
for name := range local.manifest.Stages {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
for _, name := range names {
|
||||
record := local.Stages[name]
|
||||
if record != nil {
|
||||
if record := local.manifest.Stages[name]; 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)
|
||||
fail("artifacts", local.catalogErr)
|
||||
fail("artifacts", local.definitionsErr)
|
||||
if local.catalogErr == nil && local.definitionsErr == nil {
|
||||
for _, definition := range local.definitions.Artifacts {
|
||||
entry, _ := local.catalog.Lookup(definition.Source)
|
||||
state := "unavailable"
|
||||
if entry.Available {
|
||||
state = "available"
|
||||
}
|
||||
if definition.Key == "" {
|
||||
state, entry.Provenance = builtinArtifactInspectionState(local, entry)
|
||||
state, entry.Provenance = builtinArtifactInspectionState(local.manifest, 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
|
||||
}
|
||||
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)
|
||||
}
|
||||
remoteState := collectRemoteSessionInspection(ctx, cfg, deps, local)
|
||||
store = remoteState.store
|
||||
report.Remote = &sessionRemoteState{State: remoteState.state, Locks: []sessionLockState{}, Outputs: remoteState.outputs}
|
||||
fail("storage", remoteState.storeErr)
|
||||
if remoteState.current.Err != nil && !errors.Is(remoteState.current.Err, artifacts.ErrCurrentCommitPointerMissing) {
|
||||
fail("remote", remoteState.current.Err)
|
||||
}
|
||||
if remoteState.current.State != nil && remoteState.current.Err == nil {
|
||||
report.Remote.RunID = remoteState.current.State.RunID
|
||||
}
|
||||
fail("locks", remoteState.locks.Err)
|
||||
for _, lock := range remoteState.locks.Locks {
|
||||
report.Remote.Locks = append(report.Remote.Locks, sessionLockState{Source: lock.Source, Reason: lock.Reason})
|
||||
}
|
||||
fail("publication", remoteState.outputsErr)
|
||||
}
|
||||
if status {
|
||||
for _, check := range inspectStableInputs(cfg) {
|
||||
inputs := collectSessionInputInspection(ctx, cfg, store)
|
||||
for _, check := range inputs.stable {
|
||||
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 {
|
||||
if inputs.localAudio.Checked {
|
||||
report.LocalAudio = &sessionAudioState{State: "available", Count: len(inputs.localAudio.Paths)}
|
||||
if inputs.localAudio.Err != nil {
|
||||
report.LocalAudio.State = "unavailable"
|
||||
fail("audio", audio.Err)
|
||||
fail("audio", inputs.localAudio.Err)
|
||||
}
|
||||
}
|
||||
if cfg.Session.Inputs.AudioS3 != nil {
|
||||
if inputs.remoteAudio != 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.Count, report.RemoteAudio.Prefix = len(inputs.remoteAudio.Keys), inputs.remoteAudio.Prefix
|
||||
if inputs.remoteAudio.Err == nil {
|
||||
report.RemoteAudio.State = "available"
|
||||
} else {
|
||||
fail("audio", audio.Err)
|
||||
fail("audio", inputs.remoteAudio.Err)
|
||||
}
|
||||
}
|
||||
}
|
||||
effective, err := resolveEffectiveArtifacts(cfg, nil)
|
||||
fail("artifacts", err)
|
||||
if err == nil {
|
||||
requirements, collectErr := artifacts.CollectPreviousArtifactRequirementsForConfig(cfg, effective)
|
||||
fail("artifacts", collectErr)
|
||||
if collectErr != nil {
|
||||
return report, errors.Join(failures...)
|
||||
}
|
||||
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, requirements)
|
||||
fail("previous", previous.Err)
|
||||
for _, requirement := range previous.Requirements {
|
||||
fail("artifacts", inputs.effectiveErr)
|
||||
fail("artifacts", inputs.requirementsErr)
|
||||
if inputs.effectiveErr == nil && inputs.requirementsErr == nil {
|
||||
fail("previous", inputs.previous.Err)
|
||||
for _, requirement := range inputs.previous.Requirements {
|
||||
state := "ready"
|
||||
if previous.Err != nil || previousRequirementSkipped(previous.SkippedMissing, requirement.Name) {
|
||||
if inputs.previous.Err != nil || previousRequirementSkipped(inputs.previous.SkippedMissing, requirement.Name) {
|
||||
state = "unavailable"
|
||||
}
|
||||
report.Previous = append(report.Previous, sessionPreviousState{Name: requirement.Name, Required: requirement.Required, State: state})
|
||||
|
||||
96
internal/app/session_state_inspection.go
Normal file
96
internal/app/session_state_inspection.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
type localSessionInspection struct {
|
||||
manifest *manifest.Manifest
|
||||
manifestErr error
|
||||
catalog *artifacts.ArtifactCatalog
|
||||
catalogErr error
|
||||
definitions *artifactCatalogReport
|
||||
definitionsErr error
|
||||
}
|
||||
|
||||
func collectLocalSessionInspection(ctx context.Context, cfg *config.Config) localSessionInspection {
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
var out localSessionInspection
|
||||
out.manifest, out.manifestErr = loadLocalManifest(ctx, paths.ManifestPath)
|
||||
out.catalog, out.catalogErr = buildHelperArtifactCatalog(cfg, out.manifest)
|
||||
out.definitions, out.definitionsErr = describeArtifactDefinitions(cfg.Pipeline, cfg.ArtifactCatalog)
|
||||
return out
|
||||
}
|
||||
|
||||
type remoteSessionInspection struct {
|
||||
store storage.ObjectStore
|
||||
storeErr error
|
||||
current remoteCurrentStateCheck
|
||||
locks remoteLocksCheck
|
||||
state string
|
||||
outputs []sessionPublishedOutput
|
||||
outputsErr error
|
||||
}
|
||||
|
||||
func collectRemoteSessionInspection(ctx context.Context, cfg *config.Config, deps commandDependencies, local localSessionInspection) remoteSessionInspection {
|
||||
out := remoteSessionInspection{state: "not_configured", outputs: []sessionPublishedOutput{}}
|
||||
out.store, out.storeErr = objectStoreIfConfiguredWithDependencies(ctx, cfg, deps)
|
||||
if out.storeErr != nil {
|
||||
out.state = "error"
|
||||
return out
|
||||
}
|
||||
if out.store == nil {
|
||||
return out
|
||||
}
|
||||
out.current = inspectRemoteCurrentStateWithDependencies(ctx, cfg, out.store, deps)
|
||||
if out.current.Err != nil {
|
||||
if errors.Is(out.current.Err, artifacts.ErrCurrentCommitPointerMissing) {
|
||||
out.state = "missing"
|
||||
} else {
|
||||
out.state = "error"
|
||||
}
|
||||
} else if out.current.State != nil {
|
||||
out.state = "current"
|
||||
}
|
||||
out.locks = inspectRemoteLocks(ctx, cfg, out.store)
|
||||
if local.catalogErr == nil {
|
||||
out.outputs, out.outputsErr = inspectPublishedOutputs(ctx, cfg, out.store, local.catalog, out.current.State, out.locks.Locks, out.locks.Err == nil, out.state)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type sessionInputInspection struct {
|
||||
stable []stableInputCheck
|
||||
localAudio localAudioCheck
|
||||
remoteAudio *remoteAudioCheck
|
||||
effectiveErr, requirementsErr error
|
||||
previous previousArtifactReadiness
|
||||
}
|
||||
|
||||
func collectSessionInputInspection(ctx context.Context, cfg *config.Config, store storage.ObjectStore) sessionInputInspection {
|
||||
out := sessionInputInspection{stable: inspectStableInputs(cfg), localAudio: inspectLocalAudioPresence(cfg)}
|
||||
if cfg.Session.Inputs.AudioS3 != nil {
|
||||
audio := remoteAudioCheck{}
|
||||
if store != nil {
|
||||
audio = inspectRemoteAudioPresence(ctx, cfg, store)
|
||||
}
|
||||
out.remoteAudio = &audio
|
||||
}
|
||||
effective, err := resolveEffectiveArtifacts(cfg, nil)
|
||||
out.effectiveErr = err
|
||||
if err != nil {
|
||||
return out
|
||||
}
|
||||
requirements, err := artifacts.CollectPreviousArtifactRequirementsForConfig(cfg, effective)
|
||||
out.requirementsErr = err
|
||||
if err == nil {
|
||||
out.previous = inspectPreviousArtifactReadiness(ctx, cfg, store, requirements)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user