Restore cancellation checks before report delivery
This commit is contained in:
50
integrations/ckprompt/report_cancellation_test.go
Normal file
50
integrations/ckprompt/report_cancellation_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package ckprompt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
commandkit "gitea.maximumdirect.net/eric/CommandKit"
|
||||
promptkit "gitea.maximumdirect.net/eric/promptkit"
|
||||
)
|
||||
|
||||
type cancelDuringYAML struct{ cancel context.CancelFunc }
|
||||
|
||||
func (value cancelDuringYAML) MarshalYAML() (any, error) {
|
||||
value.cancel()
|
||||
return "prepared", nil
|
||||
}
|
||||
|
||||
func TestInspectionCancellationDuringPreparationPreventsDelivery(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()
|
||||
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},
|
||||
}},
|
||||
}}, nil
|
||||
},
|
||||
}))
|
||||
args := []string{"promptkit", "show", "profile", "demo", "--format", format}
|
||||
if mode == "quiet" {
|
||||
args = append(args, "--quiet")
|
||||
}
|
||||
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 {
|
||||
t.Fatalf("outcome=%#v writes=%d", got, output.calls)
|
||||
}
|
||||
if got.Presentation.Output.RenderError != nil || got.Presentation.Output.WriteError != nil {
|
||||
t.Fatalf("operation cancellation became a presentation failure: %#v", got.Presentation.Output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user