diff --git a/docs/cli.md b/docs/cli.md index fad685e6..cac89177 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -132,7 +132,7 @@ incur inference costs; see [Operations](operations.md#preflight-lifecycle). The assessment contains `pipeline`, `ready`, `checks`, and an optional `debug_directory`. Each check has a stable class `id`, a structured `scope`, a `result` (`passed`, `failed`, or `warning`), a `message`, and sometimes a `code`. -Scopes may identify a path, profile, backend, pipeline, or associated bindings. +Scopes may identify a path, reference, profile, backend, pipeline, or associated bindings. Cache access problems warn without making readiness false. A failed or incomplete required check makes readiness false. Default text shows the summary, failures, and warnings; verbose visibility adds successful details. JSON and YAML serialize diff --git a/docs/roadmap/future.md b/docs/roadmap/future.md index 56fcbce5..3c8b2d38 100644 --- a/docs/roadmap/future.md +++ b/docs/roadmap/future.md @@ -5,10 +5,11 @@ configuration, operations, internal, and integration docs. This backlog records proposed extensions to that implementation. Items below are ordered roughly by value and specificity, not as committed release dates. -## Active Implementation Roadmaps +## Feature Context And Implementation -- [Pipeline Preflight](preflight.md): accepted design and staged implementation - plan for invocation preparation, native provider checks, and readiness reporting. +- [Pipeline Preflight](preflight.md): accepted feature context for invocation + preparation, native provider checks, and readiness reporting; its + [implementation plan](implementation.md) records sequencing and completion. ## Near-Term D&D Pipeline diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 4241d312..b7aa887e 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -510,6 +510,8 @@ narrow cross-document edits, not a rewrite of the documentation suite. ## Stage 11: Verify End-To-End Completion +**Status:** Complete. + **Goal:** Complete the sprint with full code, documentation, and scope verification. Review every requirement in `preflight.md` against implementation and test diff --git a/docs/roadmap/preflight.md b/docs/roadmap/preflight.md index a4d80ef9..94242dc2 100644 --- a/docs/roadmap/preflight.md +++ b/docs/roadmap/preflight.md @@ -2,7 +2,7 @@ ## Purpose And Status -**Status:** Accepted design; implementation not started. +**Status:** Implemented and verified. This roadmap defines the target behavior and accepted product decisions for pipeline-aware preflight. There are no remaining open product decisions. @@ -13,7 +13,8 @@ The accepted design here governs implementation where it refines that request, including the simpler treatment of native capabilities and readiness reporting. Current behavior remains documented in [CLI Reference](../cli.md), [CLI Internals](../internal/cli.md), and [Operations](../operations.md); this -roadmap does not claim that the new command is implemented. +roadmap records the accepted feature context; those canonical documents describe +the implemented command. Private helper types, observer wiring, debug filenames, and exact check identifiers remain implementation choices within the accepted contracts. diff --git a/internal/cli/pipeline_invocation.go b/internal/cli/pipeline_invocation.go index 829aae2c..50b0e9a2 100644 --- a/internal/cli/pipeline_invocation.go +++ b/internal/cli/pipeline_invocation.go @@ -96,38 +96,39 @@ func selectPipelineInvocation(ctx context.Context, loaded loadedPipelineInvocati } type preparedPipelineInvocation struct { - resolved pipeline.ResolvedPipeline - prepared *pipeline.PreparedPipeline - raw []byte - sessionID string - diagnostics []contracts.ProducerDiagnostic + resolved pipeline.ResolvedPipeline + prepared *pipeline.PreparedPipeline + raw []byte + sessionID string + diagnostics []contracts.ProducerDiagnostic + failureTarget string } func preparePipelineInvocation(loaded loadedPipelineInvocation, selected selectedPipelineInvocation, input pipelineRunInput) (preparedPipelineInvocation, *commandkit.Outcome) { workingDirectory, err := os.Getwd() if err != nil { outcome := commandkit.Failure(err.Error()).WithCause(err) - return preparedPipelineInvocation{}, &outcome + return preparedPipelineInvocation{failureTarget: "preparation"}, &outcome } materialized, diagnostics, err := pipeline.MaterializeReferences(selected.effective.ResolvedPipeline, selected.catalog, pipeline.ReferenceMaterializationOptions{ConfigPath: loaded.loaded.MainSourcePath(), WorkingDir: workingDirectory}) if err != nil { outcome := commandkit.Failure(err.Error()).WithCause(err) - return preparedPipelineInvocation{}, &outcome + return preparedPipelineInvocation{failureTarget: "references"}, &outcome } prepared, err := pipeline.Prepare(materialized, selected.registries, pipeline.ModuleDependencies{Engine: selected.engine}) if err != nil { outcome := commandkit.Failure(err.Error()).WithCause(err) - return preparedPipelineInvocation{}, &outcome + return preparedPipelineInvocation{resolved: materialized, diagnostics: diagnostics, failureTarget: "modules"}, &outcome } raw, err := os.ReadFile(input.InputFile.Value) if err != nil { outcome := commandkit.Failure(fmt.Sprintf("Read input %q: %v", input.InputFile.Value, err)).WithCause(err) - return preparedPipelineInvocation{}, &outcome + return preparedPipelineInvocation{resolved: materialized, diagnostics: diagnostics, failureTarget: "input"}, &outcome } sessionID, err := runSessionID(input.Overrides.Resources.SessionID, materialized.Input.Module, raw) if err != nil { outcome := commandkit.Failure(err.Error()).WithCause(err) - return preparedPipelineInvocation{}, &outcome + return preparedPipelineInvocation{resolved: materialized, diagnostics: diagnostics, failureTarget: "input"}, &outcome } return preparedPipelineInvocation{resolved: materialized, prepared: prepared, raw: raw, sessionID: sessionID, diagnostics: diagnostics}, nil } diff --git a/internal/cli/pipeline_preflight.go b/internal/cli/pipeline_preflight.go index 1e969b03..aeca1501 100644 --- a/internal/cli/pipeline_preflight.go +++ b/internal/cli/pipeline_preflight.go @@ -1,7 +1,9 @@ package cli import ( + "errors" "fmt" + "os" "text/template" "gitea.maximumdirect.net/eric/notarius/internal/framework/contracts" @@ -12,11 +14,12 @@ import ( ) type preflightScope struct { - Pipeline string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"` - Path string `json:"path,omitempty" yaml:"path,omitempty"` - Profile string `json:"profile,omitempty" yaml:"profile,omitempty"` - Backend string `json:"backend,omitempty" yaml:"backend,omitempty"` - Bindings []preflight.BindingScope `json:"bindings,omitempty" yaml:"bindings,omitempty"` + Pipeline string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"` + Path string `json:"path,omitempty" yaml:"path,omitempty"` + Reference string `json:"reference,omitempty" yaml:"reference,omitempty"` + Profile string `json:"profile,omitempty" yaml:"profile,omitempty"` + Backend string `json:"backend,omitempty" yaml:"backend,omitempty"` + Bindings []preflight.BindingScope `json:"bindings,omitempty" yaml:"bindings,omitempty"` } type preflightCheck struct { @@ -118,20 +121,29 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput, } add("selection", preflightScope{Pipeline: input.PipelineID}, "passed", "Pipeline selection and resources are valid.") local, failure := preparePipelineInvocation(loaded, selected, input) - if failure != nil { - add("preparation", preflightScope{Pipeline: input.PipelineID}, "failed", failure.Explanation.Message) - return finish(*failure) - } for _, diagnostic := range local.diagnostics { for _, sample := range diagnostic.Samples { message := sample.Message if diagnostic.Disposition == contracts.DiagnosticDispositionWarning { - report.Checks = append(report.Checks, preflightCheck{ID: "reference", Scope: preflightScope{Path: sample.Scope}, Result: "warning", Code: diagnostic.ReasonCode, Message: message}) + report.Checks = append(report.Checks, preflightCheck{ID: "reference", Scope: preflightScope{Reference: sample.Scope}, Result: "warning", Code: diagnostic.ReasonCode, Message: message}) } else { _ = invocation.Reporter().Info(message) } } } + if failure != nil { + scope := preflightScope{Pipeline: input.PipelineID} + if local.failureTarget == "input" { + scope.Path = input.InputFile.Value + } else if local.failureTarget == "references" { + var pathErr *os.PathError + if errors.As(failure.Cause, &pathErr) { + scope.Path = pathErr.Path + } + } + add(local.failureTarget, scope, "failed", failure.Explanation.Message) + return finish(*failure) + } add("preparation", preflightScope{Pipeline: input.PipelineID}, "passed", "References and modules are prepared.") if _, err := local.prepared.ParseSource(ctx, contracts.ParseRequest{Path: input.InputFile.Value, Raw: local.raw}); err != nil { add("input", preflightScope{Path: input.InputFile.Value}, "failed", err.Error()) @@ -153,9 +165,18 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput, } targets, err := preflight.DiscoverTargets(ctx, selected.effective.ResolvedPipeline, selected.catalog, selected.engine) if err != nil { - add("targets", preflightScope{Pipeline: input.PipelineID}, "failed", err.Error()) + scope := preflightScope{Pipeline: input.PipelineID} + var targetErr *preflight.TargetError + if errors.As(err, &targetErr) { + scope.Bindings = []preflight.BindingScope{targetErr.Scope} + } + add("targets", scope, "failed", err.Error()) return finish(pipelineResourceFailure(err)) } + if err := capture.WriteJSON("targets.json", targets); err != nil { + add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error()) + return finish(commandkit.Failure(err.Error()).WithCause(err)) + } evidence := newRunEvidenceRecorder(capture, loaded.result) evidenceIndex := 0 observations, err := preflight.RunSmokeChecksObserved(ctx, selected.engine, targets, input.Overrides.Execution.Execution, input.Overrides.Execution.TransientRetries, func(observation preflight.SmokeObservation) error { @@ -181,7 +202,11 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput, } if err != nil { if !failedCheck { - add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error()) + if capture.Err() != nil { + add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error()) + } else { + add("diagnostics", preflightScope{Pipeline: input.PipelineID}, "failed", err.Error()) + } } return finish(commandkit.Failure(err.Error()).WithCause(err)) } diff --git a/internal/cli/pipeline_preflight_test.go b/internal/cli/pipeline_preflight_test.go index ff780032..47188e3e 100644 --- a/internal/cli/pipeline_preflight_test.go +++ b/internal/cli/pipeline_preflight_test.go @@ -90,11 +90,22 @@ func TestPreflightLocalFailureStopsBeforeProvider(t *testing.T) { if err := json.Unmarshal(out.Bytes(), &report); err != nil || outcome.Status == 0 || report.Ready || client.calls != 0 { t.Fatalf("outcome=%+v report=%+v error=%v calls=%d", outcome, report, err, client.calls) } + if last := report.Checks[len(report.Checks)-1]; last.ID != "input" || last.Scope.Path != input+"-missing" { + t.Fatalf("input failure scope = %+v", last) + } if !errors.Is(outcome.Cause, context.Canceled) && outcome.Cause == nil { t.Fatal("missing input cause") } out.Reset() stderr.Reset() + missingReference := filepath.Join(t.TempDir(), "missing.txt") + outcome = app.Execute(context.Background(), []string{"preflight", "demo", "--config", config, "--input-file", input, "--reference", "context=" + missingReference, "--format", "json"}, commandkit.Streams{Out: &out, Err: &stderr}) + report = preflightReport{} + if err := json.Unmarshal(out.Bytes(), &report); err != nil || outcome.Status == 0 || len(report.Checks) == 0 || report.Checks[len(report.Checks)-1].Scope.Path != missingReference || client.calls != 0 { + t.Fatalf("reference failure: outcome=%+v report=%+v err=%v calls=%d", outcome, report, err, client.calls) + } + out.Reset() + stderr.Reset() outcome = app.Execute(context.Background(), []string{"preflight", "demo", "--config", config}, commandkit.Streams{Out: &out, Err: &stderr}) if outcome.Status == 0 || out.Len() != 0 || client.calls != 0 { t.Fatalf("missing required flag: %+v %q", outcome, out.String()) @@ -187,3 +198,28 @@ func TestPreflightCacheFailureWarnsWithoutPreventingReadiness(t *testing.T) { t.Fatalf("missing cache warning: %+v", report) } } + +func TestPreflightRetainsReferenceWarningWhenInputReadFails(t *testing.T) { + probe := &runProbe{} + _, config, input, _ := runFixture(t, probe) + app, err := NewApplication("test", Options{Registries: runRegistries(t, probe), LLMClient: &readinessClient{content: `{"status":"ok"}`}}) + if err != nil { + t.Fatal(err) + } + empty := filepath.Join(t.TempDir(), "empty.txt") + if err := os.WriteFile(empty, nil, 0o600); err != nil { + t.Fatal(err) + } + var out, stderr bytes.Buffer + outcome := app.Execute(context.Background(), []string{"preflight", "demo", "--config", config, "--input-file", input + "-missing", "--reference", "context=" + empty, "--format", "json"}, commandkit.Streams{Out: &out, Err: &stderr}) + var report preflightReport + if err := json.Unmarshal(out.Bytes(), &report); err != nil || outcome.Status == 0 { + t.Fatalf("outcome=%+v report=%+v err=%v", outcome, report, err) + } + for _, check := range report.Checks { + if check.ID == "reference" && check.Result == "warning" && check.Code == "empty_reference" && check.Scope.Reference != "" { + return + } + } + t.Fatalf("reference warning lost: %+v", report.Checks) +} diff --git a/internal/preflight/targets.go b/internal/preflight/targets.go index b4672345..286d743e 100644 --- a/internal/preflight/targets.go +++ b/internal/preflight/targets.go @@ -35,6 +35,15 @@ type Targets struct { Access []AccessTarget } +// TargetError identifies the binding whose initial target could not be selected. +type TargetError struct { + Scope BindingScope + Cause error +} + +func (err *TargetError) Error() string { return err.Cause.Error() } +func (err *TargetError) Unwrap() error { return err.Cause } + // DiscoverTargets identifies initial request targets without invoking providers. func DiscoverTargets(ctx context.Context, resolved pipeline.ResolvedPipeline, catalog pipeline.ModuleCatalog, engine *promptkit.Engine) (Targets, error) { var targets Targets @@ -46,7 +55,12 @@ func DiscoverTargets(ctx context.Context, resolved pipeline.ResolvedPipeline, ca } profiles := make(map[string]int) access := make(map[string]int) - add := func(scope BindingScope, class contracts.ExecutionClass, profile string, prompts []string) error { + add := func(scope BindingScope, class contracts.ExecutionClass, profile string, prompts []string) (failure error) { + defer func() { + if failure != nil { + failure = &TargetError{Scope: scope, Cause: failure} + } + }() if class != contracts.ExecutionClassLLMBacked { return nil } diff --git a/internal/preflight/targets_test.go b/internal/preflight/targets_test.go index 093533f7..d886fca1 100644 --- a/internal/preflight/targets_test.go +++ b/internal/preflight/targets_test.go @@ -69,6 +69,11 @@ prompts: resolved.Chunk.LLMProfile = "missing" if _, err := DiscoverTargets(context.Background(), resolved, catalog, engine); !errors.Is(err, promptkit.ErrProfileNotFound) { t.Fatalf("missing profile cause = %v", err) + } else { + var targetErr *TargetError + if !errors.As(err, &targetErr) || targetErr.Scope.Module != "chunk" { + t.Fatalf("missing profile binding scope = %v", err) + } } resolved.Chunk.LLMProfile = "" resolved.Chunk.Module = "dynamic"