Files
DeepSeek-Reasonix/cmd/e2ebench/compare_test.go
T
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

112 lines
3.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"reasonix/internal/base/testenv"
)
func writeArm(t *testing.T, dir, name string, results []result) string {
t.Helper()
data, err := json.Marshal(results)
if err != nil {
t.Fatalf("marshal: %v", err)
}
path := filepath.Join(dir, name)
if err := os.WriteFile(path, data, 0o644); err != nil {
t.Fatalf("write: %v", err)
}
return path
}
func TestCompareReportsRendersPerSolvedDeltas(t *testing.T) {
dir := testenv.TempDir(t)
control := result{task: task{ID: "a"}, Passed: true, WallMs: 60_000}
control.Steps = 7
control.ToolCalls = 10
control.PromptTokens = 900
control.CompletionTokens = 100
control.UsageBySource = map[string]sourceUsage{"executor": {Calls: 6}, "planner": {Calls: 1}}
control.Trajectory = &trajectorySummary{ModelRounds: 5}
ablated := result{task: task{ID: "a"}, Passed: true, WallMs: 45_000}
ablated.Steps = 5
ablated.ToolCalls = 10
ablated.PromptTokens = 700
ablated.CompletionTokens = 100
ablated.UsageBySource = map[string]sourceUsage{"executor": {Calls: 5}}
ablated.Trajectory = &trajectorySummary{ModelRounds: 5}
pathA := writeArm(t, dir, "control.json", []result{control})
pathB := writeArm(t, dir, "ablated.json", []result{ablated})
got, err := compareReports(pathA, pathB)
if err != nil {
t.Fatalf("compareReports: %v", err)
}
for _, want := range []string{
"| Solved | 1/1 (100%) | 1/1 (100%) |",
"| Model requests / solved | 7.0 | 5.0 |",
"| Planner requests / solved | 1.0 | 0.0 |",
"| Wall seconds / solved | 60.0 | 45.0 |",
} {
if !strings.Contains(got, want) {
t.Fatalf("compare table missing %q:\n%s", want, got)
}
}
}
func TestCompareReportsMarginalUtilityByClass(t *testing.T) {
dir := testenv.TempDir(t)
mk := func(id, class string, passed bool, wallMs int64) result {
r := result{task: task{ID: id, Class: class}, Passed: passed, WallMs: wallMs}
r.Steps = 1
return r
}
withPlanner := []result{
mk("bug1", "bugfix", true, 30_000), mk("bug2", "bugfix", true, 30_000),
mk("ref1", "refactor", true, 112_000),
}
without := []result{
mk("bug1", "bugfix", true, 18_000), mk("bug2", "bugfix", true, 18_000),
mk("ref1", "refactor", false, 74_000),
}
pathA := writeArm(t, dir, "with.json", withPlanner)
pathB := writeArm(t, dir, "without.json", without)
got, err := compareReports(pathA, pathB)
if err != nil {
t.Fatalf("compareReports: %v", err)
}
for _, want := range []string{
"**Marginal utility (A − B):** accuracy +33.3pp · wall/task +20.7s",
"| bugfix | 2/2 | 2/2 | +0.0pp | 30.0s | 18.0s | +12.0s |",
"| refactor | 1/1 | 0/1 | +100.0pp | 112.0s | 74.0s | +38.0s |",
} {
if !strings.Contains(got, want) {
t.Fatalf("marginal utility missing %q:\n%s", want, got)
}
}
}
func TestRequestsBySourceLineOrdersByCalls(t *testing.T) {
line := requestsBySourceLine(map[string]sourceUsage{
"planner": {Calls: 3, PromptTokens: 300},
"executor": {Calls: 9, PromptTokens: 900, CompletionTokens: 100},
"title": {Calls: 0},
})
if !strings.Contains(line, "executor 9 (1,000 tok) · planner 3 (300 tok)") {
t.Fatalf("source line = %q", line)
}
if strings.Contains(line, "title") {
t.Fatalf("zero-call sources must be omitted: %q", line)
}
if requestsBySourceLine(nil) != "" {
t.Fatal("no sources must render nothing")
}
}