Protect validation probes with the session lock
Some checks failed
ci/woodpecker/push/verify Pipeline was canceled
Some checks failed
ci/woodpecker/push/verify Pipeline was canceled
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -74,10 +75,9 @@ func validateSelectedSession(ctx context.Context, input *sessionInspectionInput,
|
||||
return inspectSessionValidation(ctx, cfg, deps)
|
||||
}
|
||||
|
||||
func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps commandDependencies) (*sessionValidationReport, error) {
|
||||
func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps commandDependencies) (report *sessionValidationReport, resultErr error) {
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
report := &sessionValidationReport{Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID, SessionSource: sessionSourceSummary(cfg), Findings: []finding{}}
|
||||
var resultErr error
|
||||
report = &sessionValidationReport{Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID, SessionSource: sessionSourceSummary(cfg), Findings: []finding{}}
|
||||
fail := func(category string, err error) {
|
||||
if err != nil {
|
||||
report.Findings = append(report.Findings, errorFinding(category, err.Error()))
|
||||
@@ -126,6 +126,37 @@ func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps comm
|
||||
if targetErr != nil {
|
||||
fail("preflight", targetErr)
|
||||
} else {
|
||||
probeStore := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||
paths := probeStore.SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if targets.Polish || targets.Notarius {
|
||||
// Check presence only before locking. Prepared evidence is read below
|
||||
// while locked; missing preparation must not bootstrap a workspace.
|
||||
_, statErr := os.Stat(paths.ManifestPath)
|
||||
if statErr == nil {
|
||||
lock, lockErr := probeStore.AcquireSessionLockForContext(ctx, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if lockErr != nil {
|
||||
fail("workspace", fmt.Errorf("acquire validation session lock: %w", lockErr))
|
||||
targets.Polish, targets.Notarius = false, false
|
||||
} else {
|
||||
defer func() {
|
||||
fail("workspace", probeStore.ReleaseSessionLock(lock))
|
||||
report.Valid = resultErr == nil
|
||||
}()
|
||||
}
|
||||
} else {
|
||||
if errors.Is(statErr, os.ErrNotExist) {
|
||||
if targets.Polish {
|
||||
fail("audita", fmt.Errorf("prepared inputs are unavailable; run prepare"))
|
||||
}
|
||||
if targets.Notarius {
|
||||
fail("notarius", fmt.Errorf("prepared inputs are unavailable; run prepare"))
|
||||
}
|
||||
} else {
|
||||
fail("workspace", fmt.Errorf("inspect prepared manifest: %w", statErr))
|
||||
}
|
||||
targets.Polish, targets.Notarius = false, false
|
||||
}
|
||||
}
|
||||
var inspector scriptorium.Runner
|
||||
if len(targets.Scriptorium) > 0 {
|
||||
inspector = deps.newScriptorium()
|
||||
@@ -134,7 +165,6 @@ func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps comm
|
||||
var request audita.PolishRequest
|
||||
if targets.Polish {
|
||||
report.Findings = append(report.Findings, infoFinding("audita", "preflight uses a synthetic transcript, probes destinations, and may contact providers"))
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
local, present, loadErr := loadManifestAtPathIfPresent(ctx, &manifest.LocalStore{}, paths.ManifestPath)
|
||||
if loadErr != nil {
|
||||
fail("audita", fmt.Errorf("load prepared manifest; run prepare: %w", loadErr))
|
||||
@@ -173,7 +203,6 @@ func inspectSessionValidation(ctx context.Context, cfg *config.Config, deps comm
|
||||
var native notarius.ReadinessChecker
|
||||
var probe stage.NotariusReadiness
|
||||
if targets.Notarius {
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
local, present, loadErr := loadManifestAtPathIfPresent(ctx, &manifest.LocalStore{}, paths.ManifestPath)
|
||||
switch {
|
||||
case loadErr != nil:
|
||||
|
||||
Reference in New Issue
Block a user