Report preflight smoke usage with its correct scope
This commit is contained in:
@@ -135,6 +135,10 @@ func TestPreflightVerifiesDistinctProfilesAfterLocalChecks(t *testing.T) {
|
||||
t.Fatalf("invalid %d models=%v err=%s", status, models, stderr.String())
|
||||
}
|
||||
negative = true
|
||||
requested := append([]string{"preflight", "--show-tokens"}, args[1:]...)
|
||||
if status := invoke(requested); status != 1 || !strings.Contains(stderr.String(), "total=10 (complete)") || !strings.Contains(stderr.String(), "execution-observer totals exclude these calls") {
|
||||
t.Fatalf("failed verification usage: status=%d diagnostic=%s", status, stderr.String())
|
||||
}
|
||||
quiet := append([]string{}, args...)
|
||||
quiet = append(quiet[:1], append([]string{"--quiet"}, quiet[1:]...)...)
|
||||
if status := invoke(quiet); status != 1 || len(models) != 2 || !strings.Contains(stderr.String(), `Profile "review": negative`) || strings.Contains(stderr.String(), "private transcript") || strings.Contains(stderr.String(), `"bad"`) {
|
||||
@@ -228,3 +232,72 @@ func TestPreflightExplainsNativePreparationError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreflightUsageReportScopesNativeObservations(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, command string
|
||||
flags []string
|
||||
smoke bool
|
||||
visible bool
|
||||
}{
|
||||
{"ordinary", "preflight", nil, true, true},
|
||||
{"requested", "preflight", []string{"--show-tokens"}, true, true},
|
||||
{"verbose", "preflight", []string{"--show-tokens", "--verbose"}, true, true},
|
||||
{"quiet", "preflight", []string{"--show-tokens", "--quiet"}, true, false},
|
||||
{"local only", "preflight", []string{"--show-tokens", "--smoke=false"}, false, false},
|
||||
{"processing", "process", []string{"--show-tokens"}, false, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
calls := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
calls++
|
||||
content := `{"status":"ok"}`
|
||||
if tc.command == "process" {
|
||||
content = `{"corrections":[]}`
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"choices": []any{map[string]any{"message": map[string]any{"role": "assistant", "content": content}}}, "usage": map[string]int{"prompt_tokens": 7, "completion_tokens": 3, "total_tokens": 10}})
|
||||
}))
|
||||
defer server.Close()
|
||||
dir := t.TempDir()
|
||||
for name, body := range map[string]string{
|
||||
"config.yml": "version: 3\nllm: {proposal_profile: fixture}\npipeline: {stages: [{module: grammar}]}\nreporting: {enabled: false}\n",
|
||||
"prompts.yml": fmt.Sprintf("profiles: [{id: fixture, endpoint: '%s/v1', model: fixture}]\n", server.URL),
|
||||
"transcript.json": `[{"speaker":"A","start":0,"end":1,"text":"hello"}]`,
|
||||
} {
|
||||
if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
app, err := buildApplication()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
args := append([]string{tc.command}, tc.flags...)
|
||||
args = append(args, "--config", filepath.Join(dir, "config.yml"), "--output", filepath.Join(dir, "out.json"), filepath.Join(dir, "transcript.json"))
|
||||
var out, diagnostic bytes.Buffer
|
||||
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if result.Status != 0 {
|
||||
t.Fatalf("status=%d diagnostic=%s", result.Status, diagnostic.String())
|
||||
}
|
||||
if strings.Contains(diagnostic.String(), "total=10 (complete)") != tc.visible || strings.Contains(diagnostic.String(), "execution-observer totals exclude these calls") != tc.visible {
|
||||
t.Fatalf("diagnostic=%s", diagnostic.String())
|
||||
}
|
||||
wantCalls := 0
|
||||
if tc.smoke || tc.command == "process" {
|
||||
wantCalls = 1
|
||||
}
|
||||
if calls != wantCalls {
|
||||
t.Fatalf("calls=%d want=%d", calls, wantCalls)
|
||||
}
|
||||
if tc.command == "process" && (!strings.Contains(diagnostic.String(), "Total tokens: 10") || strings.Contains(diagnostic.String(), "Preflight smoke usage")) {
|
||||
t.Fatalf("processing diagnostic=%s", diagnostic.String())
|
||||
}
|
||||
if slices.Contains(tc.flags, "--quiet") && diagnostic.Len() != 0 {
|
||||
t.Fatalf("quiet diagnostic=%s", diagnostic.String())
|
||||
}
|
||||
if out.Len() != 0 {
|
||||
t.Fatalf("unexpected stdout: %s", out.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user