From 49fee9f8eeaeebf2fe99d0605eb7354c65bdcbdb Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Tue, 17 Nov 2026 00:51:51 +0000 Subject: [PATCH] Verify constructor failure precedence --- docs/roadmap/implementation.md | 9 ++- .../ckprompt/constructor_outcomes_test.go | 56 +++++++++++++++++++ integrations/ckprompt/preparation_test.go | 2 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 63ac0ab..43a6c36 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -132,7 +132,14 @@ CommandKit outcomes, identity, diagnostics, reports, and comparison-side context ## Stage 3 — Preserve failure precedence and native report compatibility -Status — pending. +Status — completed. The focused constructor and preparation tests and +`GOWORK=off GOTOOLCHAIN=local go test ./...` passed against published +dependencies. Real missing-schema and malformed-YAML constructor failures +retain their causes; mixed operational and cancellation causes and pre-canceled +invocations select status 1. The prepared report retains `ParentRunID`. +Both native request adapters forward whole builder results; upstream preparation +and validation use the supplied context, while execution owns notifications and +operation timeouts. 1. Add `TestPromptConstructorFailurePrecedence` alongside Stage 2's tests. Exercise a representative catalog command and `config show --scope=promptkit` diff --git a/integrations/ckprompt/constructor_outcomes_test.go b/integrations/ckprompt/constructor_outcomes_test.go index 9c50c5b..1c7c045 100644 --- a/integrations/ckprompt/constructor_outcomes_test.go +++ b/integrations/ckprompt/constructor_outcomes_test.go @@ -73,3 +73,59 @@ func TestPromptConstructorConfigurationOutcomes(t *testing.T) { }) } } + +func TestPromptConstructorFailurePrecedence(t *testing.T) { + dir := t.TempDir() + malformed := filepath.Join(dir, "prompts.yml") + if err := os.WriteFile(malformed, []byte("profiles: [\n"), 0600); err != nil { + t.Fatal(err) + } + _, invalid := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: configkit.File(malformed)}}}, promptkit.WithBundledOpenRouter(false)) + _, missing := promptkit.NewEngine(promptkit.Config{}, promptkit.WithBundledOpenRouter(false), promptkit.WithSchemaFile(filepath.Join(dir, "missing.json"))) + if invalid == nil || missing == nil || !errors.Is(invalid, promptkit.ErrInvalidConfig) || !errors.Is(missing, promptkit.ErrInvalidConfig) || !errors.Is(missing, os.ErrNotExist) { + t.Fatalf("constructor fixtures invalid=%v missing=%v", invalid, missing) + } + operational := errors.New("independent failure") + for _, tc := range []struct { + name string + cause error + extra error + canceled bool + }{ + {"missing schema", missing, os.ErrNotExist, false}, + {"joined operational", errors.Join(invalid, operational), operational, false}, + {"joined cancellation", errors.Join(invalid, context.Canceled), context.Canceled, false}, + {"already canceled", nil, context.Canceled, true}, + } { + for _, args := range [][]string{{"promptkit", "list", "prompts"}, {"config", "show", "--scope=promptkit"}} { + t.Run(tc.name+"/"+strings.Join(args, "_"), func(t *testing.T) { + calls := 0 + load := func(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) { + calls++ + if tc.cause != nil { + return nil, tc.cause + } + return adapterEngine(t), nil + } + app := newPromptTestApp(t, Command(FromEngine[struct{}, struct{}](load)), ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{Scopes: []ckconfig.Scope[struct{}, struct{}]{ConfigScope(load)}})) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + if tc.canceled { + cancel() + } + var out bytes.Buffer + result := app.Execute(ctx, args, commandkit.Streams{Out: &out}) + if result.Kind != commandkit.OutcomeOperational || result.Status != 1 || !errors.Is(result.Cause, tc.extra) { + t.Fatalf("outcome=%#v output=%q", result, out.String()) + } + if tc.canceled { + if calls != 0 || out.Len() != 0 { + t.Fatalf("calls=%d output=%q", calls, out.String()) + } + } else if calls != 1 || !errors.Is(result.Cause, tc.cause) || !errors.Is(result.Cause, promptkit.ErrInvalidConfig) { + t.Fatalf("outcome=%#v calls=%d", result, calls) + } + }) + } + } +} diff --git a/integrations/ckprompt/preparation_test.go b/integrations/ckprompt/preparation_test.go index 7a48c54..28d95ba 100644 --- a/integrations/ckprompt/preparation_test.go +++ b/integrations/ckprompt/preparation_test.go @@ -19,7 +19,7 @@ func TestPreparationCommandForwardsOrderedInputsAndNativeReport(t *testing.T) { ctx := context.WithValue(context.Background(), key{}, "context") var received PreparationRequest calls := 0 - native := &promptkit.PreparedRun{PromptID: "native", Messages: []promptkit.RenderedMessage{{Content: "rendered"}}} + native := &promptkit.PreparedRun{PromptID: "native", ParentRunID: "parent-run", Messages: []promptkit.RenderedMessage{{Content: "rendered"}}} app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{PrepareRequest: func(got context.Context, req PreparationRequest, _, _ struct{}) (commandkit.Acquired[*promptkit.PreparedRun], error) { if got.Value(key{}) != "context" { t.Fatal("invocation context lost")