Adopt native PromptKit resource inspection

This commit is contained in:
2026-11-07 04:05:51 +00:00
parent 6c35da3ab6
commit 5ff0dd4ea2
12 changed files with 313 additions and 385 deletions

View File

@@ -2,33 +2,30 @@ package ckprompt
import (
"context"
"errors"
"testing"
commandkit "go.maximumdirect.net/commandkit"
promptkit "go.maximumdirect.net/promptkit"
)
type cancelDuringYAML struct{ cancel context.CancelFunc }
type cancelDuringJSON struct{ cancel context.CancelFunc }
func (value cancelDuringYAML) MarshalYAML() (any, error) {
func (value cancelDuringJSON) MarshalJSON() ([]byte, error) {
value.cancel()
return "prepared", nil
return []byte(`"prepared"`), nil
}
func TestInspectionCancellationDuringPreparationPreventsDelivery(t *testing.T) {
func TestInspectionRetainsAcquiredReportWhenRenderingCancels(t *testing.T) {
for _, format := range []string{"text", "yaml"} {
for _, mode := range []string{"ordinary", "quiet"} {
t.Run(format+"/"+mode, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
extra := map[string]any{"controlled": cancelDuringJSON{cancel}}
app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{
InspectProfile: func(context.Context, ProfileRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.ProfileInspection], error) {
return commandkit.Acquired[*promptkit.ProfileInspection]{Value: &promptkit.ProfileInspection{
ProfileID: "demo",
EffectiveModelParams: promptkit.ExecutionTarget{ExtraParams: map[string]any{
"controlled": cancelDuringYAML{cancel},
}},
ProfileID: "demo", ExtraParams: &extra,
}}, nil
},
}))
@@ -38,7 +35,7 @@ func TestInspectionCancellationDuringPreparationPreventsDelivery(t *testing.T) {
}
output := &countingWriter{}
got := app.Execute(ctx, args, commandkit.Streams{Out: output})
if got.Kind != commandkit.OutcomeOperational || got.Status != 1 || !errors.Is(got.Cause, context.Canceled) || output.calls != 0 {
if got.Kind != commandkit.OutcomeSuccess || got.Status != 0 || ctx.Err() != context.Canceled || (mode == "ordinary" && output.calls == 0) || (mode == "quiet" && output.calls != 0) {
t.Fatalf("outcome=%#v writes=%d", got, output.calls)
}
if got.Presentation.Output.RenderError != nil || got.Presentation.Output.WriteError != nil {