Skip to content
Merged
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
23 changes: 18 additions & 5 deletions docs/operating.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ output does. A stage says which check refused: it does not claim the failure is
transient or persistent, and it is not a remedy. Re-read the same assets and fix
whichever one the stage names.

`cortex doctor` reports the same refusals for its probe role: an asset check that
cannot conclude — `binding_invalid`, `install_root_invalid`,
`current_directory_invalid`, `actor_guidance_invalid`, `actor_shadow_unverified` —
is reported as `qa_availability=assets_unverifiable` with the same `qa_assets_stage`,
rather than as a digest mismatch that was never observed. A foreign catalog keeps
naming both fingerprints (`assets_mismatch` with `expected` and `found`).

## Walk the QA fleet end to end

Expand All @@ -277,13 +283,20 @@ run looks like, and where it currently stops:
from an empty directory. Expect `status=completed`, per-runtime lines, and the
`warning=uncertified_admission` disclosure. Verify readiness with `cortex doctor`:
every runtime reports `qa_availability` for the probe role only — it is a model
availability probe, not an admission guarantee.
availability probe, not an admission guarantee. `qa_route_scope=embedded_default_route`
states what was probed: the binary's embedded catalog and the policy default route.
Doctor reads no caller catalog and no `--profile` route, names the routed pair only
when the probe's verdict carried one, and is not a per-run profile check.
2. **Configure the route.** The fleet ships no models, so pick a provider/model pair
from the runtime's extension-free surface and run
`cortex qa setup --catalog <abs-path>/catalog --provider <p> --model <m>`. Use an
**absolute** catalog path: `qa run` only reads the route profile from a canonical
absolute root (#324). `qa setup` writes `<catalog>/cortex/qa-profiles.json` with one
route per fleet role, pi-backend scoped (#328).
`cortex qa setup --catalog <catalog-root> --provider <p> --model <m>`. Relative and
absolute roots are both accepted: the command resolves the path before it writes,
so `qa setup --catalog catalog` and `qa run --catalog catalog` from the same
directory address the same file (#324). The root must already exist and contain
`catalog.json`; `qa setup` validates it before probing models and refuses to create
the tree, so a typo fails instead of writing a profile no run reads. `qa setup`
writes `<catalog>/cortex/qa-profiles.json` with one route per fleet role,
pi-backend scoped (#328).
3. **Run one role with evidence.** Write a short bounded `request.txt`, then:

```sh
Expand Down
9 changes: 8 additions & 1 deletion internal/cli/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,14 @@ func probeCompatibilityMatrix(ctx context.Context, runner runtimeprobe.Runner, p
// The note is separate from the per-runtime records: their machine-readable
// fields and order stay intact, while the scope and safe next check remain
// visible even if every probed backend reports ready.
const doctorScopeNote = "note=qa_availability is backend/model readiness for qa_probe_role only (not_probed means no probe); it does not check asset ownership or install/update conflicts; for a separate read-only ownership plan run cortex update --runtime pi --catalog ./catalog\n"
//
// It states the route scope explicitly (#374 S7). Doctor resolves the policy
// default route against the binary's embedded catalog: it reads no caller
// catalog and no `--profile` route, so a maintainer must not read its answer as
// an evaluation of either. The availability lines name the routed pair only
// when the probe's verdict carried one, which is why the scope belongs here
// rather than guessed per line.
const doctorScopeNote = "note=qa_availability is backend/model readiness for qa_probe_role only (not_probed means no probe); qa_route_scope=embedded_default_route means doctor probes the binary's embedded catalog and the policy default route, never a caller catalog or a --profile route; it does not check asset ownership or install/update conflicts; for a separate read-only ownership plan run cortex update --runtime pi --catalog ./catalog\n"

// doctorReport extends the shared per-runtime line with what doctor alone is
// asked for: whether that runtime's QA backend could actually run a report.
Expand Down
55 changes: 50 additions & 5 deletions internal/cli/doctor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"testing"

"github.com/refactor-ia/cortex/internal/installobserve"
"github.com/refactor-ia/cortex/internal/qaadmission"
"github.com/refactor-ia/cortex/internal/qapi"
"github.com/refactor-ia/cortex/internal/runtimecompat"
"github.com/refactor-ia/cortex/internal/runtimematrix"
"github.com/refactor-ia/cortex/internal/runtimeprobe"
Expand Down Expand Up @@ -79,12 +81,15 @@ func stubQABackendProbe(t *testing.T, answers map[string]string) {
originalAssetCheck := qaAssetCheck
qaAssetCheck = func(_ string) error { return nil }
t.Cleanup(func() { qaAssetCheck = originalAssetCheck })
qaBackendProbe = func(_ context.Context, backend string) string {
qaBackendProbe = func(_ context.Context, backend string) qapi.AvailabilityVerdict {
answer, known := answers[backend]
if !known {
t.Fatalf("doctor probed an unexpected backend: %q", backend)
}
return answer
if answer == qaAvailabilityReady {
return qapi.AvailabilityVerdict{Available: true}
}
return qapi.AvailabilityVerdict{Code: qaadmission.Code(answer)}
}
t.Cleanup(func() { qaBackendProbe = original })
}
Expand Down Expand Up @@ -189,6 +194,10 @@ func TestQAAssetAvailabilityFromError(t *testing.T) {
{name: "missing skill is assets_missing", err: &installobserve.AdmissionUnavailableError{Stage: "skill_missing", Expected: "aa"}, token: "assets_missing", diagnostic: " qa_assets_stage=skill_missing expected=aa"},
{name: "foreign catalog is assets_mismatch with identity", err: &installobserve.AdmissionUnavailableError{Stage: "catalog_fingerprint", Expected: "cc11", Found: "ff22"}, token: "assets_mismatch", diagnostic: " qa_assets_stage=catalog_fingerprint expected=cc11 found=ff22"},
{name: "skill drift is assets_mismatch", err: &installobserve.AdmissionUnavailableError{Stage: "skill_mismatch", Expected: "aa", Found: "bb"}, token: "assets_mismatch", diagnostic: " qa_assets_stage=skill_mismatch expected=aa found=bb"},
{name: "unadmitted binding is unverifiable, not a digest mismatch", err: &installobserve.AdmissionUnavailableError{Stage: "binding_invalid"}, token: "assets_unverifiable", diagnostic: " qa_assets_stage=binding_invalid"},
{name: "non-canonical root is unverifiable", err: &installobserve.AdmissionUnavailableError{Stage: "current_directory_invalid"}, token: "assets_unverifiable", diagnostic: " qa_assets_stage=current_directory_invalid"},
{name: "unproven actor guidance is unverifiable", err: &installobserve.AdmissionUnavailableError{Stage: "actor_guidance_invalid"}, token: "assets_unverifiable", diagnostic: " qa_assets_stage=actor_guidance_invalid"},
{name: "unproven shadow scan is unverifiable, not a catalog mismatch", err: &installobserve.AdmissionUnavailableError{Stage: "actor_shadow_unverified"}, token: "assets_unverifiable", diagnostic: " qa_assets_stage=actor_shadow_unverified"},
{name: "untyped check failure fails closed", err: errors.New("unrelated"), token: "assets_check_failed", diagnostic: " qa_assets_stage=check_failed"},
} {
token, diagnostic := qaAssetAvailabilityFromError(tc.err)
Expand All @@ -202,7 +211,9 @@ func TestDoctorQALineGatesReadyOnInstalledAssets(t *testing.T) {
originalProbe := qaBackendProbe
originalCheck := qaAssetCheck
t.Cleanup(func() { qaBackendProbe = originalProbe; qaAssetCheck = originalCheck })
qaBackendProbe = func(_ context.Context, _ string) string { return qaAvailabilityReady }
qaBackendProbe = func(_ context.Context, _ string) qapi.AvailabilityVerdict {
return qapi.AvailabilityVerdict{Available: true}
}
qaAssetCheck = func(_ string) error {
return &installobserve.AdmissionUnavailableError{Stage: "catalog_fingerprint", Expected: "cc11", Found: "ff22"}
}
Expand All @@ -228,6 +239,40 @@ func TestDoctorQALineGatesReadyOnInstalledAssets(t *testing.T) {
}
}

// TestDoctorNamesTheProbedRouteAndItsScope pins #374 S7: doctor probes the
// binary's embedded catalog and the policy default route, so the line names the
// routed pair its verdict answered about (which doctor used to discard) and the
// note discloses that scope instead of implying a caller catalog or `--profile`
// route was evaluated.
func TestDoctorNamesTheProbedRouteAndItsScope(t *testing.T) {
originalProbe := qaBackendProbe
originalCheck := qaAssetCheck
t.Cleanup(func() { qaBackendProbe = originalProbe; qaAssetCheck = originalCheck })
qaAssetCheck = func(_ string) error { return nil }
qaBackendProbe = func(_ context.Context, _ string) qapi.AvailabilityVerdict {
return qapi.AvailabilityVerdict{Code: qaadmission.CodeModelUnavailable, Provider: "nan", Model: "glm5.3"}
}
line := qaBackendLine(context.Background(), runtimematrix.RuntimePi, true)
for _, want := range []string{"qa_availability=model_unavailable", "qa_route_provider=nan qa_route_model=glm5.3"} {
if !strings.Contains(line, want) {
t.Fatalf("line = %q, want it to name %q", line, want)
}
}
// A ready verdict names no pair, so the line must not invent one.
qaBackendProbe = func(_ context.Context, _ string) qapi.AvailabilityVerdict {
return qapi.AvailabilityVerdict{Available: true}
}
line = qaBackendLine(context.Background(), runtimematrix.RuntimePi, true)
if strings.Contains(line, "qa_route_provider") || strings.Contains(line, "qa_route_model") {
t.Fatalf("line = %q, want no claimed route pair for a ready verdict", line)
}
for _, want := range []string{"qa_route_scope=embedded_default_route", "never a caller catalog", "--profile"} {
if !strings.Contains(doctorScopeNote, want) {
t.Fatalf("doctor note = %q, want it to disclose %q", doctorScopeNote, want)
}
}
}

func TestQARouteSetupNoteNamesProfilePathAndShape(t *testing.T) {
note := qaRouteSetupNote("/home/user/fleet-catalog")
for _, want := range []string{
Expand Down Expand Up @@ -300,9 +345,9 @@ func TestDoctorDoesNotProbeAbsentRuntimes(t *testing.T) {
originalAssetCheck := qaAssetCheck
qaAssetCheck = func(_ string) error { return nil }
t.Cleanup(func() { qaAssetCheck = originalAssetCheck })
qaBackendProbe = func(_ context.Context, backend string) string {
qaBackendProbe = func(_ context.Context, backend string) qapi.AvailabilityVerdict {
probed = append(probed, backend)
return "ready"
return qapi.AvailabilityVerdict{Available: true}
}
t.Cleanup(func() { qaBackendProbe = original })
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
Expand Down
80 changes: 80 additions & 0 deletions internal/cli/qa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,86 @@ func TestQARunProfileFlagSelectsTheRequestedProfile(t *testing.T) {
})
}

// TestQARunWithoutAProfileUsesTheDocumentedPlaceholder keeps the legitimate
// default: with no profile source at all, the policy placeholder still routes
// the run (issue #298).
func TestQARunWithoutAProfileUsesTheDocumentedPlaceholder(t *testing.T) {
args := reportFixture(t)
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
if code := Run(context.Background(), args, stdout, stderr, nil); code != exitOK || stdout.String() != fixtureReport+"\n" || stderr.Len() != 0 {
t.Fatalf("placeholder run = %d stdout %q stderr %q", code, stdout.String(), stderr.String())
}
frame := must(os.ReadFile("qa-report-frame"))
for _, want := range []string{"route_profile role-default", "route_model qwen3.6"} {
if !bytes.Contains(frame, []byte(want)) {
t.Fatalf("frame does not carry the placeholder %q: %q", want, frame)
}
}
}

// TestQARunRefusesAnUnusableDefaultProfileInsteadOfFallingBack pins the other
// half of #324: a profile source that exists but cannot be read safely is a
// named refusal, never a silent placeholder route and never a launch.
func TestQARunRefusesAnUnusableDefaultProfileInsteadOfFallingBack(t *testing.T) {
for _, testCase := range []struct {
name string
install func(t *testing.T, path string)
}{
{name: "symlinked profile file", install: func(t *testing.T, path string) {
mustOK(os.Symlink(path+".elsewhere", path))
}},
{name: "malformed profile file", install: func(t *testing.T, path string) {
mustOK(os.WriteFile(path, []byte(`{"schemaVersion":1,"defaultProfile":"9bad","profiles":{}}`), 0o600))
}},
} {
t.Run(testCase.name, func(t *testing.T) {
args := roleReportFixture(t, qarole.RequirementsAnalyst)
// Stage the profile in a disposable copy: the repository catalog
// must never be mutated by a test that plants an unsafe file.
catalogRoot := filepath.Join(must(os.Getwd()), "catalog-copy")
mustOK(os.CopyFS(catalogRoot, os.DirFS(qaCatalogArgument(args))))
for index, arg := range args {
if arg == "--catalog" && index+1 < len(args) {
args[index+1] = catalogRoot
}
}
profileDirectory := filepath.Join(catalogRoot, "cortex")
mustOK(os.MkdirAll(profileDirectory, 0o700))
testCase.install(t, filepath.Join(profileDirectory, "qa-profiles.json"))

stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
code := Run(context.Background(), args, stdout, stderr, nil)
want := "error=profile_invalid\n" + qaReportNote + "stage=route_resolution\nprofile_source=unusable route_setup=" + filepath.Join(catalogRoot, "cortex", "qa-profiles.json") + "\n"
if code != exitFailure || stdout.Len() != 0 || stderr.String() != want {
t.Fatalf("unusable default profile = %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("a refused default profile must not launch the backend")
}
})
}
}

// TestQARunProfileRefusalNamesTheSelectedProfile pins the refusal half of S6
// (#374): an unknown --profile id names the selection, what the profile source
// actually offers, and the file to edit, without echoing anything unbounded.
func TestQARunProfileRefusalNamesTheSelectedProfile(t *testing.T) {
args := profileReportFixture(t)
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
code := Run(context.Background(), append(append([]string{}, args...), "--profile", "no-such-profile"), stdout, stderr, nil)
want := "error=profile_invalid\n" + qaReportNote + "stage=route_resolution\nprofile_selected=no-such-profile profile_source=readable profile_default=fleet-default profile_valid_ids=fleet-default,qa-fleet route_setup=" + filepath.Join(qaCatalogArgument(args), "cortex", "qa-profiles.json") + "\n"
if code != exitFailure || stdout.Len() != 0 || stderr.String() != want {
t.Fatalf("unknown --profile = %d stdout %q stderr %q, want %q", code, stdout.String(), stderr.String(), want)
}
// A hostile id is never echoed: the diagnostic is bounded to the profile-id
// character set and carries no escape or control bytes.
stdout, stderr = &bytes.Buffer{}, &bytes.Buffer{}
code = Run(context.Background(), append(append([]string{}, args...), "--profile", "../\x1b[2Jevil"), stdout, stderr, nil)
if code != exitFailure || strings.Contains(stderr.String(), "\x1b") || !strings.Contains(stderr.String(), "profile_selected=<redacted> ") {
t.Fatalf("hostile --profile = %d stdout %q stderr %q", code, stdout.String(), stderr.String())
}
}

// 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
Loading