Files
DeepSeek-Reasonix/cmd/reasonix-studio-host/packagegrants_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

51 lines
1.5 KiB
Go

package main
import (
"bytes"
"encoding/json"
"os"
"path/filepath"
"testing"
"reasonix/internal/platform/packagegrant"
)
func TestStripPackageGrantsOnlyAnswersForAnApplication(t *testing.T) {
dir := t.TempDir()
for name, app := range map[string]string{
"no application": "",
"a path that is nothing": filepath.Join(dir, "missing.exe"),
"a directory": dir,
} {
var out, logs bytes.Buffer
if code := stripPackageGrants(&out, &logs, app); code != 2 || out.Len() != 0 {
t.Errorf("%s: code=%d out=%q", name, code, out.String())
}
}
}
// The shell reads this line as structure, so both lists are present even when
// empty: a null would be a third answer it has to guess about.
func TestStripPackageGrantsReportsOneLineOfJSON(t *testing.T) {
app := filepath.Join(t.TempDir(), "Reasonix Studio.exe")
if err := os.WriteFile(app, []byte("x"), 0o755); err != nil {
t.Fatal(err)
}
var out, logs bytes.Buffer
if code := stripPackageGrants(&out, &logs, app); code != 0 {
t.Fatalf("code=%d logs=%s", code, logs.String())
}
var report packagegrant.Report
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
t.Fatalf("not JSON: %q", out.String())
}
if len(report.Stripped)+len(report.Refused)+len(report.Unread) != 0 {
t.Fatalf("a clean tree reported %+v from %q", report, out.String())
}
for _, list := range []string{`"stripped":[]`, `"refused":[]`, `"unread":[]`} {
if !bytes.Contains(out.Bytes(), []byte(list)) {
t.Fatalf("%s was not written as an empty list: %q", list, out.String())
}
}
}