Capture pipeline readiness diagnostics and failures
This commit is contained in:
@@ -359,6 +359,8 @@ prompt by using earlier helpers; requested capture/final failure joining follows
|
|||||||
|
|
||||||
## Stage 7: Complete Debug Lifecycle And Failure Preservation
|
## Stage 7: Complete Debug Lifecycle And Failure Preservation
|
||||||
|
|
||||||
|
**Status:** Complete.
|
||||||
|
|
||||||
**Goal:** Requested capture records preparation and smoke evidence, with native
|
**Goal:** Requested capture records preparation and smoke evidence, with native
|
||||||
cancellation and independent delivery outcomes intact.
|
cancellation and independent delivery outcomes intact.
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func NewApplication(version string, options Options) (*commandkit.App, error) {
|
|||||||
definitions = ckprompt.WithNamespaces(definitions, promptkit.Namespaces{})
|
definitions = ckprompt.WithNamespaces(definitions, promptkit.Namespaces{})
|
||||||
declarations := []commandkit.Declaration{
|
declarations := []commandkit.Declaration{
|
||||||
commandkit.Completion("notarius"),
|
commandkit.Completion("notarius"),
|
||||||
pipelineCommands(newState, func() (pipeline.ModuleCatalog, error) { return effectiveCatalog(options) }, pipelineRunCommand(version, newState, func() (pipeline.Registries, error) { return effectiveRegistries(options) }, options), pipelinePreflightCommand(newState, func() (pipeline.Registries, error) { return effectiveRegistries(options) })),
|
pipelineCommands(newState, func() (pipeline.ModuleCatalog, error) { return effectiveCatalog(options) }, pipelineRunCommand(version, newState, func() (pipeline.Registries, error) { return effectiveRegistries(options) }, options), pipelinePreflightCommand(version, newState, func() (pipeline.Registries, error) { return effectiveRegistries(options) }, options)),
|
||||||
commandkit.Alias("run", "pipeline run"),
|
commandkit.Alias("run", "pipeline run"),
|
||||||
commandkit.Alias("preflight", "pipeline preflight"),
|
commandkit.Alias("preflight", "pipeline preflight"),
|
||||||
ckconfig.Command(ckconfig.Suite[struct{}, *nativeLoaders]{
|
ckconfig.Command(ckconfig.Suite[struct{}, *nativeLoaders]{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||||
|
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/preflight"
|
"gitea.maximumdirect.net/eric/notarius/internal/preflight"
|
||||||
"go.maximumdirect.net/commandkit"
|
"go.maximumdirect.net/commandkit"
|
||||||
@@ -37,26 +38,39 @@ var preflightTemplate = template.Must(commandkit.ParseTextTemplate("pipeline-pre
|
|||||||
{{range .Checks}}{{if ne .Result "passed"}}{{.Result}}: {{.Message}}
|
{{range .Checks}}{{if ne .Result "passed"}}{{.Result}}: {{.Message}}
|
||||||
{{end}}{{end}}`, nil))
|
{{end}}{{end}}`, nil))
|
||||||
|
|
||||||
func pipelinePreflightCommand(newState func() *nativeLoaders, modules func() (pipeline.Registries, error)) commandkit.Command {
|
func pipelinePreflightCommand(version string, newState func() *nativeLoaders, modules func() (pipeline.Registries, error), options Options) commandkit.Command {
|
||||||
|
options = defaultOptions(options)
|
||||||
return commandkit.NewCommand(commandkit.CommandSpec[pipelineRunInput]{Name: "preflight", Summary: "Check readiness for a configured pipeline invocation.", Flags: runFlags(), Arguments: pipelineRunArguments(), CheckInput: checkPipelineRunInput,
|
return commandkit.NewCommand(commandkit.CommandSpec[pipelineRunInput]{Name: "preflight", Summary: "Check readiness for a configured pipeline invocation.", Flags: runFlags(), Arguments: pipelineRunArguments(), CheckInput: checkPipelineRunInput,
|
||||||
Run: func(invocation commandkit.Invocation, input pipelineRunInput) commandkit.Outcome {
|
Run: func(invocation commandkit.Invocation, input pipelineRunInput) commandkit.Outcome {
|
||||||
return executePreflight(invocation, input, newState(), modules)
|
return executePreflight(invocation, input, newState(), modules, version, options)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func executePreflight(invocation commandkit.Invocation, input pipelineRunInput, state *nativeLoaders, modules func() (pipeline.Registries, error)) commandkit.Outcome {
|
func executePreflight(invocation commandkit.Invocation, input pipelineRunInput, state *nativeLoaders, modules func() (pipeline.Registries, error), version string, options Options) commandkit.Outcome {
|
||||||
ctx := invocation.Context
|
ctx := invocation.Context
|
||||||
loaded, failure := loadPipelineInvocation(ctx, invocation, input, state)
|
loaded, failure := loadPipelineInvocation(ctx, invocation, input, state)
|
||||||
if failure != nil {
|
if failure != nil {
|
||||||
return *failure
|
return *failure
|
||||||
}
|
}
|
||||||
report := preflightReport{Pipeline: input.PipelineID, Checks: []preflightCheck{}}
|
report := preflightReport{Pipeline: input.PipelineID, Checks: []preflightCheck{}}
|
||||||
|
var capture *frameworkdebug.Recorder
|
||||||
add := func(id string, scope preflightScope, result, message string) {
|
add := func(id string, scope preflightScope, result, message string) {
|
||||||
report.Checks = append(report.Checks, preflightCheck{ID: id, Scope: scope, Result: result, Message: message})
|
report.Checks = append(report.Checks, preflightCheck{ID: id, Scope: scope, Result: result, Message: message})
|
||||||
}
|
}
|
||||||
finish := func(outcome commandkit.Outcome) commandkit.Outcome {
|
finish := func(outcome commandkit.Outcome) commandkit.Outcome {
|
||||||
report.Ready = outcome.Status == 0
|
report.Ready = outcome.Status == 0
|
||||||
|
report.DebugDirectory = capture.Path()
|
||||||
|
if err := capture.Finalize(report, outcome.Cause); err != nil {
|
||||||
|
if outcome.Status == 0 {
|
||||||
|
outcome = commandkit.Failure("Could not complete debug capture.").WithCause(err)
|
||||||
|
} else {
|
||||||
|
outcome = outcome.WithCause(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if outcome.Status != 0 && capture.Path() != "" {
|
||||||
|
outcome = outcome.WithExplanation(outcome.Explanation.Message+runLocations("", capture.Path()), outcome.Explanation.Details...)
|
||||||
|
}
|
||||||
for _, check := range report.Checks {
|
for _, check := range report.Checks {
|
||||||
if check.Result == "passed" {
|
if check.Result == "passed" {
|
||||||
_ = invocation.Reporter().Info(check.Message)
|
_ = invocation.Reporter().Info(check.Message)
|
||||||
@@ -64,11 +78,39 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
|
|||||||
}
|
}
|
||||||
if err := invocation.Reporter().Report(commandkit.Report{Value: report, TextTemplate: preflightTemplate}); err != nil {
|
if err := invocation.Reporter().Report(commandkit.Report{Value: report, TextTemplate: preflightTemplate}); err != nil {
|
||||||
if outcome.Status == 0 {
|
if outcome.Status == 0 {
|
||||||
return commandkit.Failure("Could not present pipeline readiness.")
|
return commandkit.Failure("Could not present pipeline readiness." + runLocations("", capture.Path()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outcome
|
return outcome
|
||||||
}
|
}
|
||||||
|
directory, err := input.Debug.directory(loaded.config.Debug.Directory)
|
||||||
|
if err != nil {
|
||||||
|
add("debug", preflightScope{Path: input.Debug.Directory.Value}, "failed", err.Error())
|
||||||
|
return finish(commandkit.Failure(err.Error()).WithCause(err))
|
||||||
|
}
|
||||||
|
if directory != "" {
|
||||||
|
startedAt := options.Now().UTC()
|
||||||
|
runID, err := options.RunIDGenerator(startedAt)
|
||||||
|
if err == nil {
|
||||||
|
err = validateRunID(runID)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
capture, err = startRunDebug(input.Debug, loaded.config.Debug.Directory, runID, startedAt)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
add("debug", preflightScope{Path: directory}, "failed", err.Error())
|
||||||
|
return finish(commandkit.Failure(err.Error()).WithCause(err))
|
||||||
|
}
|
||||||
|
add("debug", preflightScope{Path: capture.Path()}, "passed", "Debug capture is accessible.")
|
||||||
|
if err := capture.WriteJSON("context.json", map[string]any{"application_version": version, "pipeline": input.PipelineID, "input_path": input.InputFile.Value, "run_id": runID, "started_at": startedAt, "lanes": input.Lanes, "references": input.References, "unbinds": input.Unbinds, "resources": input.Overrides.Resources, "execution_overrides": input.Overrides.Execution}); err != nil {
|
||||||
|
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
|
||||||
|
return finish(commandkit.Failure(err.Error()).WithCause(err))
|
||||||
|
}
|
||||||
|
if err := captureRunConfiguration(capture, loaded.result); err != nil {
|
||||||
|
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
|
||||||
|
return finish(commandkit.Failure(err.Error()).WithCause(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
selected, failure := selectPipelineInvocation(ctx, loaded, input, modules)
|
selected, failure := selectPipelineInvocation(ctx, loaded, input, modules)
|
||||||
if failure != nil {
|
if failure != nil {
|
||||||
add("selection", preflightScope{Pipeline: input.PipelineID}, "failed", failure.Explanation.Message)
|
add("selection", preflightScope{Pipeline: input.PipelineID}, "failed", failure.Explanation.Message)
|
||||||
@@ -114,19 +156,33 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
|
|||||||
add("targets", preflightScope{Pipeline: input.PipelineID}, "failed", err.Error())
|
add("targets", preflightScope{Pipeline: input.PipelineID}, "failed", err.Error())
|
||||||
return finish(pipelineResourceFailure(err))
|
return finish(pipelineResourceFailure(err))
|
||||||
}
|
}
|
||||||
observations, err := preflight.RunSmokeChecks(ctx, selected.engine, targets, input.Overrides.Execution.Execution, input.Overrides.Execution.TransientRetries)
|
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 {
|
||||||
|
if observation.Report != nil {
|
||||||
|
err := evidence.WriteJSON(fmt.Sprintf("smoke/%03d.json", evidenceIndex), observation.Report)
|
||||||
|
evidenceIndex++
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
failedCheck := false
|
||||||
for _, observation := range observations {
|
for _, observation := range observations {
|
||||||
if !observation.Applicable {
|
if !observation.Applicable {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
scope := preflightScope{Profile: observation.ProfileID, Backend: observation.BackendID, Bindings: observation.Bindings}
|
scope := preflightScope{Profile: observation.ProfileID, Backend: observation.BackendID, Bindings: observation.Bindings}
|
||||||
if observation.Err != nil {
|
if observation.Err != nil {
|
||||||
|
failedCheck = true
|
||||||
add(string(observation.Kind), scope, "failed", observation.Err.Error())
|
add(string(observation.Kind), scope, "failed", observation.Err.Error())
|
||||||
} else {
|
} else {
|
||||||
add(string(observation.Kind), scope, "passed", fmt.Sprintf("%s check passed for profile %q.", observation.Kind, observation.ProfileID))
|
add(string(observation.Kind), scope, "passed", fmt.Sprintf("%s check passed for profile %q.", observation.Kind, observation.ProfileID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if !failedCheck {
|
||||||
|
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
|
||||||
|
}
|
||||||
return finish(commandkit.Failure(err.Error()).WithCause(err))
|
return finish(commandkit.Failure(err.Error()).WithCause(err))
|
||||||
}
|
}
|
||||||
return finish(commandkit.Success())
|
return finish(commandkit.Success())
|
||||||
|
|||||||
124
internal/cli/preflight_capture_test.go
Normal file
124
internal/cli/preflight_capture_test.go
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/promptkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPreflightCapturesEarlyFailureAndUpdatesLatest(t *testing.T) {
|
||||||
|
probe := &runProbe{}
|
||||||
|
_, config, input, _ := runFixture(t, probe)
|
||||||
|
client := &readinessClient{content: `{"status":"ok"}`}
|
||||||
|
root := t.TempDir()
|
||||||
|
app, err := NewApplication("test", Options{Registries: runRegistries(t, probe), LLMClient: client, Now: func() time.Time { return time.Unix(42, 0) }, RunIDGenerator: func(time.Time) (string, error) { return "inspection", nil }})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var out, stderr bytes.Buffer
|
||||||
|
outcome := app.Execute(context.Background(), []string{"preflight", "demo", "--config", config, "--input-file", input + "-missing", "--debug", "--debug-dir", root, "--format", "json"}, commandkit.Streams{Out: &out, Err: &stderr})
|
||||||
|
var report preflightReport
|
||||||
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil || outcome.Status == 0 || report.Ready || report.DebugDirectory != filepath.Join(root, "inspection") || client.calls != 0 {
|
||||||
|
t.Fatalf("outcome=%+v report=%+v error=%v", outcome, report, err)
|
||||||
|
}
|
||||||
|
target, err := os.Readlink(filepath.Join(root, "latest"))
|
||||||
|
if err != nil || target != "inspection" {
|
||||||
|
t.Fatalf("latest=%q err=%v", target, err)
|
||||||
|
}
|
||||||
|
terminal, err := os.ReadFile(filepath.Join(report.DebugDirectory, "outcome.json"))
|
||||||
|
if err != nil || !strings.Contains(string(terminal), "missing") {
|
||||||
|
t.Fatalf("capture=%s err=%v", terminal, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPreflightRetainsCancellationAndCaptureFailure(t *testing.T) {
|
||||||
|
probe := &runProbe{}
|
||||||
|
_, config, input, _ := runFixture(t, probe)
|
||||||
|
root := t.TempDir()
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
calls := 0
|
||||||
|
client := captureClient(func(ctx context.Context, _ promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
||||||
|
calls++
|
||||||
|
if err := os.Mkdir(filepath.Join(root, "inspection", "smoke", "002.json"), 0o700); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
cancel()
|
||||||
|
return nil, ctx.Err()
|
||||||
|
})
|
||||||
|
app, err := NewApplication("test", Options{Registries: runRegistries(t, probe), LLMClient: client, RunIDGenerator: func(time.Time) (string, error) { return "inspection", nil }})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var out, stderr bytes.Buffer
|
||||||
|
outcome := app.Execute(ctx, []string{"preflight", "demo", "--config", config, "--input-file", input, "--cache", "bypass", "--debug", "--debug-dir", root, "--format", "json"}, commandkit.Streams{Out: &out, Err: &stderr})
|
||||||
|
if !errors.Is(outcome.Cause, context.Canceled) || !strings.Contains(outcome.Cause.Error(), "record debug") || calls != 1 {
|
||||||
|
t.Fatalf("outcome=%+v cause=%v calls=%d stderr=%s", outcome, outcome.Cause, calls, stderr.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPreflightPositiveAssessmentSurvivesCaptureFailure(t *testing.T) {
|
||||||
|
probe := &runProbe{}
|
||||||
|
_, config, input, _ := runFixture(t, probe)
|
||||||
|
root := t.TempDir()
|
||||||
|
calls := 0
|
||||||
|
client := captureClient(func(_ context.Context, _ promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
||||||
|
calls++
|
||||||
|
if latest, err := os.Readlink(filepath.Join(root, "latest")); err != nil || latest != "inspection" {
|
||||||
|
t.Fatalf("latest before provider call = %q, %v", latest, err)
|
||||||
|
}
|
||||||
|
if err := os.Mkdir(filepath.Join(root, "inspection", "smoke", "002.json"), 0o700); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return &promptkit.GenerateResponse{Content: `{"status":"ok"}`}, nil
|
||||||
|
})
|
||||||
|
app, err := NewApplication("test", Options{Registries: runRegistries(t, probe), LLMClient: client, RunIDGenerator: func(time.Time) (string, error) { return "inspection", nil }})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var out, stderr bytes.Buffer
|
||||||
|
outcome := app.Execute(context.Background(), []string{"preflight", "demo", "--config", config, "--input-file", input, "--cache", "bypass", "--debug", "--debug-dir", root, "--format", "json"}, commandkit.Streams{Out: &out, Err: &stderr})
|
||||||
|
var report preflightReport
|
||||||
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil || !report.Ready || outcome.Status == 0 || outcome.Cause == nil || calls != 1 {
|
||||||
|
t.Fatalf("outcome=%+v report=%+v error=%v calls=%d", outcome, report, err, calls)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPreflightDebugAllocationFailureAndDisable(t *testing.T) {
|
||||||
|
probe := &runProbe{}
|
||||||
|
_, config, input, _ := runFixture(t, probe)
|
||||||
|
client := &readinessClient{content: `{"status":"ok"}`}
|
||||||
|
app, err := NewApplication("test", Options{Registries: runRegistries(t, probe), LLMClient: client})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
file := filepath.Join(t.TempDir(), "file")
|
||||||
|
if err := os.WriteFile(file, []byte("x"), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, test := range []struct {
|
||||||
|
args []string
|
||||||
|
wantReady bool
|
||||||
|
}{
|
||||||
|
{[]string{"--debug", "--debug-dir", filepath.Join(file, "bad")}, false},
|
||||||
|
{[]string{"--debug", "--debug-dir=", "--cache", "bypass"}, true},
|
||||||
|
{[]string{"--debug=false", "--debug-dir", filepath.Join(file, "bad"), "--cache", "bypass"}, true},
|
||||||
|
} {
|
||||||
|
args := append([]string{"preflight", "demo", "--config", config, "--input-file", input, "--format", "json"}, test.args...)
|
||||||
|
var out, stderr bytes.Buffer
|
||||||
|
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &stderr})
|
||||||
|
var report preflightReport
|
||||||
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil || report.Ready != test.wantReady || (outcome.Status == 0) != test.wantReady || report.DebugDirectory != "" {
|
||||||
|
t.Fatalf("%v: outcome=%+v report=%+v err=%v stderr=%s", test.args, outcome, report, err, stderr.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -115,6 +115,10 @@ func (writer *runEvidenceRecorder) WriteJSON(name string, payload any) error {
|
|||||||
copy := *value
|
copy := *value
|
||||||
copy.EffectiveModelParams = writer.target(copy.EffectiveModelParams, copy.SelectedProfileID, copy.SelectedBackendID)
|
copy.EffectiveModelParams = writer.target(copy.EffectiveModelParams, copy.SelectedProfileID, copy.SelectedBackendID)
|
||||||
payload = copy
|
payload = copy
|
||||||
|
case *promptkit.SmokeTestReport:
|
||||||
|
copy := *value
|
||||||
|
copy.Target.EffectiveSettings = writer.target(copy.Target.EffectiveSettings, copy.Target.ProfileID, copy.Target.BackendID)
|
||||||
|
payload = copy
|
||||||
}
|
}
|
||||||
return writer.Recorder.WriteJSON(name, payload)
|
return writer.Recorder.WriteJSON(name, payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ func (input runDebugInput) directory(configuredDirectory string) (string, error)
|
|||||||
return filepath.Abs(directory)
|
return filepath.Abs(directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only the run handler calls this, after configuration/run identity and before
|
// Call after configuration and identity selection, before pipeline resolution.
|
||||||
// engine construction or pipeline preflight. Shared loaders never allocate.
|
// Shared loaders never allocate.
|
||||||
func startRunDebug(input runDebugInput, configuredDirectory, runID string, startedAt time.Time) (*frameworkdebug.Recorder, error) {
|
func startRunDebug(input runDebugInput, configuredDirectory, runID string, startedAt time.Time) (*frameworkdebug.Recorder, error) {
|
||||||
directory, err := input.directory(configuredDirectory)
|
directory, err := input.directory(configuredDirectory)
|
||||||
if err != nil || directory == "" {
|
if err != nil || directory == "" {
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ type SmokeObservation struct {
|
|||||||
// RunSmokeChecks executes each selected access and structured generation check
|
// RunSmokeChecks executes each selected access and structured generation check
|
||||||
// once, stopping at the first unsuccessful required observation.
|
// once, stopping at the first unsuccessful required observation.
|
||||||
func RunSmokeChecks(ctx context.Context, engine *promptkit.Engine, targets Targets, execution *promptkit.ExecutionTargetOverride, retries *int) ([]SmokeObservation, error) {
|
func RunSmokeChecks(ctx context.Context, engine *promptkit.Engine, targets Targets, execution *promptkit.ExecutionTargetOverride, retries *int) ([]SmokeObservation, error) {
|
||||||
|
return RunSmokeChecksObserved(ctx, engine, targets, execution, retries, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunSmokeChecksObserved delivers each observation before starting the next diagnostic.
|
||||||
|
func RunSmokeChecksObserved(ctx context.Context, engine *promptkit.Engine, targets Targets, execution *promptkit.ExecutionTargetOverride, retries *int, observe func(SmokeObservation) error) ([]SmokeObservation, error) {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
return nil, errors.New("preflight context must not be nil")
|
return nil, errors.New("preflight context must not be nil")
|
||||||
}
|
}
|
||||||
@@ -29,11 +34,17 @@ func RunSmokeChecks(ctx context.Context, engine *promptkit.Engine, targets Targe
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var observations []SmokeObservation
|
var observations []SmokeObservation
|
||||||
|
total := 2*len(targets.Access) + len(targets.Profiles)
|
||||||
run := func(kind promptkit.SmokeTestKind, profile, backend string, bindings []BindingScope) error {
|
run := func(kind promptkit.SmokeTestKind, profile, backend string, bindings []BindingScope) error {
|
||||||
report, err := engine.SmokeTest(ctx, promptkit.SmokeTestRequest{Kind: kind, ProfileID: profile, Execution: execution, TransientRetries: retries})
|
report, err := engine.SmokeTest(ctx, promptkit.SmokeTestRequest{Kind: kind, ProfileID: profile, Execution: execution, TransientRetries: retries})
|
||||||
observation := SmokeObservation{Kind: kind, ProfileID: profile, BackendID: backend, Bindings: bindings, Report: report}
|
observation := SmokeObservation{Kind: kind, ProfileID: profile, BackendID: backend, Bindings: bindings, Report: report}
|
||||||
observation.Applicable, observation.Err = evaluateSmoke(kind, report, err)
|
observation.Applicable, observation.Err = evaluateSmoke(kind, report, err)
|
||||||
observations = append(observations, observation)
|
observations = append(observations, observation)
|
||||||
|
if observe != nil {
|
||||||
|
if observeErr := observe(observation); observeErr != nil && observation.Err == nil && len(observations) < total {
|
||||||
|
return observeErr
|
||||||
|
}
|
||||||
|
}
|
||||||
return observation.Err
|
return observation.Err
|
||||||
}
|
}
|
||||||
for _, target := range targets.Access {
|
for _, target := range targets.Access {
|
||||||
|
|||||||
@@ -98,3 +98,16 @@ func TestSmokeVerdictsRequireAffirmativeFacts(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSmokeCaptureFailureStopsBeforeFurtherChecks(t *testing.T) {
|
||||||
|
input := configkit.Input{Destination: configkit.Keys("promptkit"), Source: configkit.Mapping("smoke", map[string]any{"profiles": []any{map[string]any{"id": "partial", "endpoint": "http://example.invalid/v1", "model": "fixture"}}})}
|
||||||
|
engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &input}}, promptkit.WithBundledOpenRouter(false), promptkit.WithLLMClient(noGeneration{t}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
cause := errors.New("capture failed")
|
||||||
|
observations, err := RunSmokeChecksObserved(context.Background(), engine, Targets{Access: []AccessTarget{{ProfileID: "partial"}}, Profiles: []ProfileTarget{{ID: "partial"}}}, nil, nil, func(SmokeObservation) error { return cause })
|
||||||
|
if !errors.Is(err, cause) || len(observations) != 1 {
|
||||||
|
t.Fatalf("observations=%+v err=%v", observations, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user