Files
yhh 394da0a313 refactor: the kernel's packages live in the layer they belong to
internal/ was 141 packages side by side, so nothing but a reader's memory
said which were foundations and which assembled the rest. Each now sits in a
layer directory, and the directory is the declaration:

  base      L0  foundation with no domain in it
  contract  L1  types and interfaces the layers above agree on
  model, tools, safety, ext, state, platform
            L2  subsystems, peers of one another
  runtime   L3  the turn engine
  session   L4  the controller
  assembly  L5  the composition root
  frontend  L6  cli, serve, acp and the host adapters

Only paths change: package names, code and behaviour do not. Imports,
repolint and coverage baselines, sensitive paths, CI package lists and docs
follow the new paths; release notes keep the paths they were written with,
and sample paths inside tests and fixtures keep theirs.

repolint gains layer-order: a package may import its own layer and those
below it, read from where it lives. The 47 imports that point upward today
are recorded as that rule's opening debt (-allow-widen, a new rule's first
baseline) and can only go down. Most of it is config, which still reaches
into eight subsystems and is the next thing to take apart; the rest is
event, history and a few tools reaching into runtime for types that belong
in contract.
2026-09-23 18:28:21 -07:00

69 lines
2.7 KiB
Go

package agent
import (
"testing"
"reasonix/internal/contract/provider"
"reasonix/internal/contract/tool"
)
// A failing `go test` is the case prefix matching cannot see: the output opens
// with "=== RUN" and the failure only shows in the recorded execution.
func TestKeepErrorsSeesStructuredFailure(t *testing.T) {
failing := "=== RUN TestQuotedValues\n format_test.go:412: expected beta-7d21, got gamma-4a88\n--- FAIL: TestQuotedValues (0.01s)\nFAIL\n"
for _, tc := range []struct {
name string
ex *provider.ToolExecution
want bool
}{
{"state failed", &provider.ToolExecution{State: tool.ShellStateFailed}, true},
{"timed out", &provider.ToolExecution{State: tool.ShellStateTimedOut}, true},
{"non-zero exit", &provider.ToolExecution{State: tool.ShellStateCompleted, ExitCode: new(1)}, true},
{"verification failed", &provider.ToolExecution{Verification: tool.ShellVerificationFailed}, true},
{"clean run", &provider.ToolExecution{State: tool.ShellStateCompleted, ExitCode: new(0)}, false},
{"no execution record", nil, false},
} {
t.Run(tc.name, func(t *testing.T) {
m := provider.Message{Role: provider.RoleTool, Content: failing, ToolExecution: tc.ex}
if got := isErrorMessage(m); got != tc.want {
t.Errorf("isErrorMessage = %v, want %v", got, tc.want)
}
})
}
}
// The text fallback still classifies host-formatted failures, and a passing run
// must not be kept just because it mentions a failure in passing.
func TestKeepErrorsTextFallbackUnchanged(t *testing.T) {
cases := map[string]struct {
content string
want bool
}{
"error prefix": {"error: file not found", true},
"blocked prefix": {"blocked: permission denied", true},
"mentions failure": {"all tests pass; the earlier FAIL is fixed", false},
"ordinary output": {"ok reasonix/config\t0.2s", false},
"uppercase prefix": {"Error: broken", true},
"prefix mid-string": {"note: error: not at the start", false},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
m := provider.Message{Role: provider.RoleTool, Content: tc.content}
if got := isErrorMessage(m); got != tc.want {
t.Errorf("isErrorMessage(%q) = %v, want %v", tc.content, got, tc.want)
}
})
}
}
// Only tool results are keep-policy candidates; a failing execution record on
// another role must not promote it.
func TestKeepErrorsIgnoresNonToolRoles(t *testing.T) {
ex := &provider.ToolExecution{State: tool.ShellStateFailed, ExitCode: new(2)}
for _, role := range []provider.Role{provider.RoleUser, provider.RoleAssistant, provider.RoleSystem} {
if isErrorMessage(provider.Message{Role: role, Content: "error: x", ToolExecution: ex}) {
t.Errorf("role %v classified as an error tool result", role)
}
}
}