Verify native usage reporting across recovery and delivery boundaries
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func decodeCompletionReport(t *testing.T, format commandkit.Format, content []byte) map[string]any {
|
||||
@@ -83,8 +84,8 @@ func TestNativeRunCompletionFormatsFollowPublicationAndCapture(t *testing.T) {
|
||||
app, file, input, _ := runFixture(t, probe)
|
||||
output := &completedRunWriter{t: t, file: file, captured: true}
|
||||
var diagnostics bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"run", "demo", "--config", file, "--input-file", input, "--cache", "bypass", "--debug", "--format", string(format)}, commandkit.Streams{Out: output, Err: &diagnostics})
|
||||
if outcome.Status != 0 || !strings.Contains(diagnostics.String(), "Running pipeline") {
|
||||
outcome := app.Execute(context.Background(), []string{"run", "demo", "--config", file, "--input-file", input, "--cache", "bypass", "--debug", "--show-tokens", "--format", string(format)}, commandkit.Streams{Out: output, Err: &diagnostics})
|
||||
if outcome.Status != 0 || !strings.Contains(diagnostics.String(), "Running pipeline") || !strings.Contains(diagnostics.String(), "Observed PromptKit execution usage") {
|
||||
t.Fatalf("completion: %#v stderr=%s", outcome, diagnostics.String())
|
||||
}
|
||||
directory := filepath.Join(filepath.Dir(file), "output-must-not-exist", "run-1")
|
||||
@@ -151,11 +152,14 @@ func TestNativeRunQuietAndDebugUseNativeModeOrdering(t *testing.T) {
|
||||
probe := &runProbe{}
|
||||
app, file, input, _ := runFixture(t, probe)
|
||||
var output, diagnostics bytes.Buffer
|
||||
args := append([]string{"run", "demo", "--config", file, "--input-file", input, "--cache", "bypass", "--format", "json"}, test.flags...)
|
||||
args := append([]string{"run", "demo", "--config", file, "--input-file", input, "--cache", "bypass", "--show-tokens", "--format", "json"}, test.flags...)
|
||||
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||
if outcome.Status != 0 || test.quiet != (output.Len() == 0) || test.progress != strings.Contains(diagnostics.String(), "Running pipeline") {
|
||||
t.Fatalf("native mode order: %#v output=%s stderr=%s", outcome, output.String(), diagnostics.String())
|
||||
}
|
||||
if test.quiet == strings.Contains(diagnostics.String(), "Observed PromptKit execution usage") {
|
||||
t.Fatalf("usage quiet selection: %q", diagnostics.String())
|
||||
}
|
||||
assertCompletedRunFiles(t, file, true)
|
||||
}
|
||||
}
|
||||
@@ -167,10 +171,14 @@ func TestNativeRunCancellationKeepsItsCauseAndPublishesNothing(t *testing.T) {
|
||||
defer cancel()
|
||||
probe.onGenerate = cancel
|
||||
var output, diagnostics bytes.Buffer
|
||||
outcome := app.Execute(ctx, []string{"run", "demo", "--config", file, "--input-file", input, "--cache", "bypass", "--debug", "--quiet"}, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||
outcome := app.Execute(ctx, []string{"run", "demo", "--config", file, "--input-file", input, "--cache", "bypass", "--debug", "--show-tokens"}, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||
if outcome.Status != 1 || !errors.Is(outcome.Cause, context.Canceled) || output.Len() != 0 || diagnostics.Len() == 0 {
|
||||
t.Fatalf("cancellation: %#v stdout=%s stderr=%s", outcome, output.String(), diagnostics.String())
|
||||
}
|
||||
summary := readProductionJSON[promptkit.ExecutionGroupSummary](t, filepath.Join(filepath.Dir(file), "debug-must-not-exist", "run-1", "executions.json"))
|
||||
if len(summary.Members) != 1 || !summary.TerminalCoverageComplete || !strings.Contains(diagnostics.String(), "Prompts: 1") {
|
||||
t.Fatalf("canceled work lost: %#v %s", summary, diagnostics.String())
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(filepath.Dir(file), "output-must-not-exist")); !os.IsNotExist(err) {
|
||||
t.Fatalf("cancellation published artifacts: %v", err)
|
||||
}
|
||||
@@ -223,21 +231,34 @@ func TestNativeRunReportDeliveryFailuresRetainArtifactsAndNativePresentation(t *
|
||||
}
|
||||
|
||||
func TestNativeRunDiagnosticDeliveryFailureIsNotAnOperationFailure(t *testing.T) {
|
||||
sentinel := errors.New("diagnostic delivery sentinel")
|
||||
probe := &runProbe{correctFirst: true}
|
||||
app, file, input, _ := runFixture(t, probe)
|
||||
var output bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"run", "demo", "--config", file, "--input-file", input, "--cache", "bypass", "--set", `/pipelines/demo/mode="permissive"`, "--set", "/pipelines/demo/max_additional_turns=0", "--format", "json", "--verbose"}, commandkit.Streams{Out: &output, Err: failingResultWriter{cause: sentinel}})
|
||||
if outcome.Status != 1 || outcome.Cause != nil || !errors.Is(outcome.Presentation.Diagnostics.WriteError, sentinel) || outcome.Presentation.Diagnostics.State != commandkit.DeliveryIncomplete {
|
||||
t.Fatalf("diagnostic delivery: %#v", outcome)
|
||||
for _, showUsage := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "warnings", true: "usage"}[showUsage], func(t *testing.T) {
|
||||
sentinel := errors.New("diagnostic delivery sentinel")
|
||||
probe := &runProbe{correctFirst: true}
|
||||
app, file, input, _ := runFixture(t, probe)
|
||||
var output bytes.Buffer
|
||||
args := []string{"run", "demo", "--config", file, "--input-file", input, "--cache", "bypass", "--set", `/pipelines/demo/mode="permissive"`, "--set", "/pipelines/demo/max_additional_turns=0", "--format", "json"}
|
||||
if showUsage {
|
||||
args = append(args, "--show-tokens", "--progress=false")
|
||||
} else {
|
||||
args = append(args, "--verbose")
|
||||
}
|
||||
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &output, Err: failingResultWriter{cause: sentinel}})
|
||||
if outcome.Status != 1 || outcome.Cause != nil || !errors.Is(outcome.Presentation.Diagnostics.WriteError, sentinel) || outcome.Presentation.Diagnostics.State != commandkit.DeliveryIncomplete {
|
||||
t.Fatalf("diagnostic delivery: %#v", outcome)
|
||||
}
|
||||
if report := decodeCompletionReport(t, commandkit.FormatJSON, output.Bytes()); report["fallback_count"] != float64(1) {
|
||||
t.Fatalf("completed report was replaced by a delivery envelope: %#v", report)
|
||||
}
|
||||
if !strings.Contains(outcome.Explanation.Message, filepath.Join(filepath.Dir(file), "output-must-not-exist", "run-1")) {
|
||||
t.Fatalf("presentation failure lost available artifacts: %#v", outcome)
|
||||
}
|
||||
if probe.produced != 1 {
|
||||
t.Fatalf("reporting reran model work: %d", probe.produced)
|
||||
}
|
||||
assertCompletedRunFiles(t, file, false)
|
||||
})
|
||||
}
|
||||
if report := decodeCompletionReport(t, commandkit.FormatJSON, output.Bytes()); report["fallback_count"] != float64(1) {
|
||||
t.Fatalf("completed report was replaced by a delivery envelope: %#v", report)
|
||||
}
|
||||
if !strings.Contains(outcome.Explanation.Message, filepath.Join(filepath.Dir(file), "output-must-not-exist", "run-1")) {
|
||||
t.Fatalf("presentation failure lost available artifacts: %#v", outcome)
|
||||
}
|
||||
assertCompletedRunFiles(t, file, false)
|
||||
}
|
||||
|
||||
func TestNativeRunCaptureFailureAfterPublicationDoesNotReportSuccess(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user