Report preflight smoke usage with its correct scope

This commit is contained in:
2026-11-27 04:12:41 +00:00
parent f5cef61bb5
commit b96eeb57ba
5 changed files with 146 additions and 9 deletions

View File

@@ -72,7 +72,10 @@ an intended output file or `/dev/null` and suppresses optional summaries.
Provider checks can contact services. Success requires a completed supported Provider checks can contact services. Success requires a completed supported
check with positive generation, JSON, and schema observations; it does not prove check with positive generation, JSON, and schema observations; it does not prove
compatibility with every prompt or provider-side schema enforcement. Per-profile compatibility with every prompt or provider-side schema enforcement. Per-profile
smoke usage preserves native unknown and incomplete values. See the smoke usage appears on diagnostics even in ordinary mode, subject to quiet mode,
and preserves native unknown and incomplete values. Any `--show-tokens` execution
summary excludes these smoke calls; the preflight report states that distinction.
See the
[PromptKit diagnostic guide](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/consumers/pkg-promptkit.md) [PromptKit diagnostic guide](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/consumers/pkg-promptkit.md)
and [operations](operations.md#preflight) for scope and side effects. and [operations](operations.md#preflight) for scope and side effects.

View File

@@ -1,14 +1,16 @@
# Dedicated Preflight Implementation Review # Dedicated Preflight Implementation Review
Status: Open findings. Reviewed commit Status: All findings remediated. Original review covered commit
`7874ea648b756fe83abb92854b8219e1c4f26aa5` against the eight stages of the `7874ea648b756fe83abb92854b8219e1c4f26aa5` against the eight stages of the
[implementation plan](implementation.md), the [feature roadmap](preflight-command.md), [implementation plan](implementation.md), the [feature roadmap](preflight-command.md),
and the preceding baseline `645931c`. and the preceding baseline `645931c`.
The follow-up integration audit reviewed `330044b`, which adds this review The follow-up integration audit reviewed `330044b`, which adds this review
document without changing application code. It examined each stage's interaction document without changing application code. It examined each stage's interaction
with the existing configuration, reporting, output, and execution paths. R1–R3 with the existing configuration, reporting, output, and execution paths. At that
remain open; R4 records the additional integration finding. time R1–R3 remained open and R4 recorded the additional integration finding.
The findings and audit tables below describe those reviewed baselines; completion
entries record the subsequent remediation.
The shared preparation and execution boundaries are implemented. The findings The shared preparation and execution boundaries are implemented. The findings
below concern diagnostic delivery and documentation accuracy. They do not require below concern diagnostic delivery and documentation accuracy. They do not require
@@ -122,7 +124,18 @@ and historical baseline descriptions cannot be mistaken for current code.
## R4 — Integrate preflight with the existing usage-reporting feature ## R4 — Integrate preflight with the existing usage-reporting feature
**Priority:** P2. **Stages:** 5–7. **Status:** Open. **Priority:** P2. **Stages:** 5–7. **Status:** Complete.
**Completion:** An invocation-local CommandKit diagnostic-report producer now
presents native per-profile smoke observations in ordinary mode and explicitly
qualifies execution-observer totals as excluding smoke calls. Quiet mode suppresses
the report; local-only runs emit no smoke report, and ordinary processing retains
its existing native usage path. No upstream API change, local aggregation, or
synthetic execution events were needed. Controlled CLI coverage includes ordinary,
requested, verbose, quiet, local-only, failed-verification, and processing usage.
CLI documentation now describes the delivered reporting scope. The full offline
suite, source build, touched-package race checks, and local links passed with
Go 1.27.4.
**Locations:** `internal/cli/app_wiring.go:121`, **Locations:** `internal/cli/app_wiring.go:121`,
`internal/cli/preflight.go:37` and `:47`; upstream ckprompt v0.12.0 `internal/cli/preflight.go:37` and `:47`; upstream ckprompt v0.12.0
@@ -220,3 +233,13 @@ processing, and preflight passed again with Go 1.27.4. Additional controlled CLI
probes exercised the interactions above and the `--show-tokens` reporting probes exercised the interactions above and the `--show-tokens` reporting
combinations. No live inference or real credentials were used. This follow-up combinations. No live inference or real credentials were used. This follow-up
changes only the remediation document. changes only the remediation document.
## Final Remediation Validation
R1–R4 are complete as separate committed units. `go test ./...`, a source build
of `./cmd/audita`, and `go test -race ./internal/cli ./internal/framework/llm`
passed with Go 1.27.4 and module network access disabled. Affected Markdown
links, Go formatting, and whitespace checks passed. No live inference or real
credentials were used. Provider success criteria, budgets, output lifecycle,
and correction acceptance were preserved.

View File

@@ -118,7 +118,13 @@ func buildApplicationWithClient(client *http.Client, extra ...commandkit.Declara
}) })
definitions = ckprompt.WithSmokeTesting(definitions, capturePromptEngine, nil) definitions = ckprompt.WithSmokeTesting(definitions, capturePromptEngine, nil)
definitions = withPromptBootstrapContext(definitions) definitions = withPromptBootstrapContext(definitions)
declarations := []commandkit.Declaration{configCommand, commandkit.Completion("audita"), commandkit.WithInvocationFeature(processCommand(), bootstrapFeature()), commandkit.WithInvocationFeature(preflightCommand(), bootstrapFeature()), commandkit.Alias("run", "process")} declarations := []commandkit.Declaration{
configCommand,
commandkit.Completion("audita"),
commandkit.WithInvocationFeature(processCommand(), bootstrapFeature()),
commandkit.WithInvocationFeature(commandkit.WithInvocationFeature(preflightCommand(), bootstrapFeature()), preflightUsageFeature()),
commandkit.Alias("run", "process"),
}
declarations = append(declarations, ckprompt.Declarations(definitions)...) declarations = append(declarations, ckprompt.Declarations(definitions)...)
declarations = append(declarations, extra...) declarations = append(declarations, extra...)
return commandkit.New(commandkit.Identity{Name: "audita", Version: buildinfo.Version()}, declarations...) return commandkit.New(commandkit.Identity{Name: "audita", Version: buildinfo.Version()}, declarations...)

View File

@@ -1,9 +1,11 @@
package cli package cli
import ( import (
"context"
"fmt" "fmt"
"io" "io"
"strings" "strings"
"text/template"
"gitea.maximumdirect.net/eric/audita/v4/internal/core/diagnostics" "gitea.maximumdirect.net/eric/audita/v4/internal/core/diagnostics"
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/llm" "gitea.maximumdirect.net/eric/audita/v4/internal/framework/llm"
@@ -11,6 +13,33 @@ import (
pk "go.maximumdirect.net/promptkit" pk "go.maximumdirect.net/promptkit"
) )
// preflightUsage carries native observations to CommandKit's diagnostic report.
// Smoke calls are deliberately absent from PromptKit's execution observer.
type preflightUsageKey struct{}
type preflightUsage struct {
Lines []string
Failed bool
}
var preflightUsageTemplate = template.Must(commandkit.ParseTextTemplate("preflight smoke usage", `{{if .Lines}}Preflight smoke usage; execution-observer totals exclude these calls.
{{if .Failed}}See per-profile failure details below.
{{else}}{{range .Lines}}{{.}}
{{end}}{{end}}{{end}}`, nil))
func preflightUsageFeature() commandkit.InvocationFeature {
return commandkit.NewInvocationFeature(commandkit.InvocationFeatureSpec[struct{}]{
Start: func(inv commandkit.Invocation, _ struct{}) (context.Context, func() commandkit.Report) {
if inv.CanonicalPath() != "preflight" {
return inv.Context, nil
}
usage := new(preflightUsage)
return context.WithValue(inv.Context, preflightUsageKey{}, usage), func() commandkit.Report {
return commandkit.Report{Value: usage, TextTemplate: preflightUsageTemplate}
}
},
})
}
func runPreflight(inv commandkit.Invocation, input processInput) commandkit.Outcome { func runPreflight(inv commandkit.Invocation, input processInput) commandkit.Outcome {
reporter := inv.Reporter() reporter := inv.Reporter()
_ = reporter.Progress("Checking local processing readiness.") _ = reporter.Progress("Checking local processing readiness.")
@@ -37,6 +66,12 @@ func runPreflight(inv commandkit.Invocation, input processInput) commandkit.Outc
results, err := llm.VerifyStructuredOutput(inv.Context, loaded.Runtime.Engine, prepared.Plan.Profiles, func(id string) { results, err := llm.VerifyStructuredOutput(inv.Context, loaded.Runtime.Engine, prepared.Plan.Profiles, func(id string) {
_ = reporter.Progress(fmt.Sprintf("Checking structured output for profile %q.", id)) _ = reporter.Progress(fmt.Sprintf("Checking structured output for profile %q.", id))
}) })
if usage, ok := inv.Context.Value(preflightUsageKey{}).(*preflightUsage); ok {
usage.Failed = err != nil
for _, result := range results {
usage.Lines = append(usage.Lines, verificationLine(result))
}
}
if err != nil { if err != nil {
details := make([]commandkit.Detail, 0, len(results)) details := make([]commandkit.Detail, 0, len(results))
for _, result := range results { for _, result := range results {
@@ -45,9 +80,6 @@ func runPreflight(inv commandkit.Invocation, input processInput) commandkit.Outc
} }
return commandkit.Failure("Structured-output verification failed.", details...).WithCause(err) return commandkit.Failure("Structured-output verification failed.", details...).WithCause(err)
} }
for _, result := range results {
_ = reporter.Info(verificationLine(result))
}
_ = reporter.AtEnd().Info("Local and structured-output preflight checks passed.") _ = reporter.AtEnd().Info("Local and structured-output preflight checks passed.")
return commandkit.Success() return commandkit.Success()
} }

View File

@@ -135,6 +135,10 @@ func TestPreflightVerifiesDistinctProfilesAfterLocalChecks(t *testing.T) {
t.Fatalf("invalid %d models=%v err=%s", status, models, stderr.String()) t.Fatalf("invalid %d models=%v err=%s", status, models, stderr.String())
} }
negative = true 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([]string{}, args...)
quiet = append(quiet[:1], append([]string{"--quiet"}, quiet[1:]...)...) 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"`) { 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())
}
})
}
}