Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/operating.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,16 @@ fixed vocabulary and no guessed cause:
unusable `--profile`, a backend route the profile does not carry, or a route the
policy does not admit. Nothing is launched and no provider is claimed, because
none was resolved.
- `stage=actor_admission` — the installed assets of the selected role were refused;
the following `admission_stage` names the check.
- `stage=actor_admission` — the selected runtime's install root could not be
resolved, or the installed assets of the selected role were refused. Asset
refusals also include `admission_stage` to name the check.
- `stage=model_probe` — the backend's own availability probe answered that the
routed pair is unusable. `route_provider` and `route_model` name the pair that was
actually routed (nothing else), escaped for the terminal, and `model_unavailable`
or `auth_not_ready` prints its own remedy.
- `stage=evidence_admission` — the supplied evidence sidecar was refused before
launch, with the `evidence_field` and `evidence_reason` that refused it.
launch, including failures to read the file, with the `evidence_field` and
`evidence_reason` that refused it.

The vocabulary is preflight-only. A post-launch outcome (execution, timeout,
stream, normalization) prints no stage, because no preflight question refused it.
Expand Down
5 changes: 4 additions & 1 deletion internal/cli/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func runQA(ctx context.Context, args []string, stdout, stderr io.Writer) int {
evidence, err = readQAFile(evidencePath, qapi.MaxEvidenceBytes)
if err != nil {
failure := qaFailure(stderr, "invalid_request")
_, _ = fmt.Fprintf(stderr, "stage=%s\n", qaStageEvidenceAdmission)
if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) {
_, _ = fmt.Fprintf(stderr, "evidence_field=path evidence_reason=file_not_found\n")
} else if stat, statErr := os.Stat(evidencePath); statErr == nil && stat.Size() > int64(qapi.MaxEvidenceBytes) {
Expand All @@ -379,7 +380,9 @@ func runQA(ctx context.Context, args []string, stdout, stderr io.Writer) int {
}
installRoot, err := qaInstallRoot(backend)
if err != nil {
return qaFailure(stderr, "actor_unavailable")
failure := qaFailure(stderr, "actor_unavailable")
_, _ = fmt.Fprintf(stderr, "stage=%s\n", qaStageActorAdmission)
return failure
}
report, code, err := qapi.RunLocalReportOn(ctx, qapi.ReportRequest{
Role: role, Profile: profile, CatalogRoot: catalogRoot, InstallRoot: installRoot,
Expand Down
70 changes: 70 additions & 0 deletions internal/cli/qa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,76 @@ func TestQARunProfileRefusalNamesTheSelectedProfile(t *testing.T) {
}
}

// Early file refusals happen before the report pipeline can classify them.
func TestQARunEarlyEvidenceRefusalNamesStage(t *testing.T) {
for _, tc := range []struct {
name, path, field, reason string
}{
{"missing", "missing.json", "path", "file_unavailable"},
{"directory", ".", "path", "not_a_file"},
{"oversized", "oversized.json", "top-level", "exceeds_size"},
} {
t.Run(tc.name, func(t *testing.T) {
args := reportFixture(t)
if tc.name == "oversized" {
mustOK(os.WriteFile(tc.path, bytes.Repeat([]byte(" "), qapi.MaxEvidenceBytes+1), 0o600))
}
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
code := Run(context.Background(), append(args, "--evidence", tc.path), stdout, stderr, nil)
want := "error=invalid_request\n" + qaReportNote + "stage=evidence_admission\n" + fmt.Sprintf("evidence_field=%s evidence_reason=%s\n", tc.field, tc.reason)
if code != exitFailure || stdout.Len() != 0 || !strings.HasPrefix(stderr.String(), want) || strings.Count(stderr.String(), "stage=") != 1 {
t.Fatalf("evidence refusal = %d stdout %q stderr %q, want prefix %q", code, stdout.String(), stderr.String(), want)
}
if _, err := os.Stat("qa-report-frame"); !os.IsNotExist(err) {
t.Fatal("evidence refusal must not launch the backend")
}
})
}
}

func TestQARunEarlyInstallRootRefusalNamesStage(t *testing.T) {
args := reportFixture(t)
t.Setenv("HOME", "")
mustOK(os.Unsetenv("HOME"))
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
code := Run(context.Background(), args, stdout, stderr, nil)
want := "error=actor_unavailable\n" + qaReportNote + "stage=actor_admission\n"
if code != exitFailure || stdout.Len() != 0 || stderr.String() != want {
t.Fatalf("install-root refusal = %d stdout %q stderr %q, want %q", code, stdout.String(), stderr.String(), want)
}
if _, err := os.Stat("qa-report-frame"); !os.IsNotExist(err) {
t.Fatal("install-root refusal must not launch the backend")
}
}

func TestQARunModelRefusalEscapesProfileRouteIdentity(t *testing.T) {
args := profileReportFixture(t)
// Both fields originate in a caller-owned profile; neither may emit a
// terminal command, a new diagnostic line, or a literal backslash escape.
route, err := json.Marshal(map[string]string{
"provider": "\x1b]52;c;SGVsbG8=\x07",
"model": "m\n\r\x1b]0;title\x07\\tail",
"effort": "low",
})
mustOK(err)
qaProfileBodyFixture(t, qaCatalogArgument(args), fmt.Sprintf(`{"schemaVersion":1,"defaultProfile":"fleet","profiles":{"fleet":{"routes":{"requirements-analyst":{"pi":%s}}}}}`, route))
mustOK(os.WriteFile("qa-report-scenario", []byte("model-unavailable"), 0o600))
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
code := Run(context.Background(), args, stdout, stderr, nil)
want := `route_provider=\x1b]52;c;SGVsbG8=\x07 route_model=m\x0a\x0d\x1b]0;title\x07\x5ctail` + "\n"
if code != exitFailure || stdout.Len() != 0 || !strings.Contains(stderr.String(), "error=model_unavailable\n") || !strings.Contains(stderr.String(), "stage=model_probe\n") || !strings.Contains(stderr.String(), want) {
t.Fatalf("hostile route refusal = %d stdout %q stderr %q, want %q", code, stdout.String(), stderr.String(), want)
}
for _, control := range []string{"\x1b", "\x07", "\r"} {
if strings.Contains(stderr.String(), control) {
t.Fatalf("refusal contains raw terminal control %q: %q", control, stderr.String())
}
}
if _, err := os.Stat("qa-report-frame"); !os.IsNotExist(err) {
t.Fatal("model refusal must not launch report execution")
}
}

// TestQARunNamesThePreflightRefusalStage pins #374 S4: each preflight refusal
// says which question refused — route resolution, actor admission, model probe,
// or evidence admission — using the stage vocabulary the pipeline already
Expand Down
Loading