Files
pipelines/internal/filediff/policy_test.go
T
alan 87016ef5dc Engine: check stages, harness-agnostic delivery, read-only enforcement, complete captures
- New `type=check` stage: the server runs a `commands` block (sh -c, per
  command_timeout, workspace env) and routes on pass/fail; per-command status,
  exit code, duration and bounded output are recorded and the failing output is
  the handoff. With delivery=true it is the landing gate (commit leftovers,
  merge moved main, checks in a fresh candidate worktree, fast-forward main).
  Parser/registry, lint (silent guards), format docs, CLI inspect, app graph and
  run detail rendering.
- delivery=true is accepted on every harness (and on check stages).
- permissions.shell on claude stages maps to Bash(cmd) / Bash(prefix:*) rules
  instead of a bare Bash allow; stages without edit that change the workspace
  fail the visit with the changed files listed (allow_workspace_changes=true
  opts out; artifacts, public and harness state dirs are ignored).
- File-change capture: symlinks compared by target, untouched protected files no
  longer make captures partial, untracked caches/dependency/build output left
  out, lockfiles listed without patch, huge files compared by metadata, raised
  patch/line limits. Outcome repair follow-ups are logged and counted on the
  step (control.outcome_repairs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 12:52:16 +00:00

74 lines
2.4 KiB
Go

package filediff
import (
"context"
"os"
"path/filepath"
"testing"
)
// A committed symlink no longer makes every capture partial, and a symlink a
// stage creates (a read-only reviewer's stray link) is listed.
func TestSymlinksAreComparedByTarget(t *testing.T) {
dir, git := gitRepo(t)
put(t, dir, "real.md", "skill\n")
if err := os.Symlink("real.md", filepath.Join(dir, "linked")); err != nil {
t.Fatal(err)
}
git("add", "real.md", "linked")
git("commit", "-qm", "init")
ctx := context.Background()
before := Capture(ctx, dir)
if quiet := Compare(before, Capture(ctx, dir, before)); quiet.Status != "complete" || quiet.Skipped != 0 || len(quiet.Files) != 0 {
t.Fatalf("an untouched symlink: %+v", quiet)
}
if err := os.Symlink("/etc", filepath.Join(dir, "stray")); err != nil {
t.Fatal(err)
}
changes := Compare(before, Capture(ctx, dir, before))
if changes.Status != "complete" || len(changes.Files) != 1 {
t.Fatalf("%+v", changes)
}
if f := changes.Files[0]; f.Path != "stray" || f.Kind != "added" || f.NoPatchReason != reasonSymlink || f.Truncated {
t.Fatalf("%+v", f)
}
}
func TestToolOutputIsExcludedOrListedWithoutPatch(t *testing.T) {
dir, git := gitRepo(t)
for _, name := range []string{"build/keep.sh", "go.sum", "src/a.go"} {
if err := os.MkdirAll(filepath.Join(dir, filepath.Dir(name)), 0o700); err != nil {
t.Fatal(err)
}
put(t, dir, name, "v1\n")
}
git("add", ".")
git("commit", "-qm", "init")
ctx := context.Background()
before := Capture(ctx, dir)
for _, name := range []string{"node_modules/x/index.js", "dist/app.js", "src/__pycache__/a.pyc", "build/new.sh"} {
if err := os.MkdirAll(filepath.Join(dir, filepath.Dir(name)), 0o700); err != nil {
t.Fatal(err)
}
put(t, dir, name, "generated\n")
}
put(t, dir, "go.sum", "v2\n")
put(t, dir, "src/a.go", "v2\n")
changes := Compare(before, Capture(ctx, dir, before))
got := map[string]string{}
for _, f := range changes.Files {
got[f.Path] = f.NoPatchReason
}
// Untracked caches and an untracked build directory are left out; a new
// file in a tracked build directory is stage work; a lockfile has no patch.
want := map[string]string{"build/new.sh": "", "go.sum": reasonGenerated, "src/a.go": ""}
if len(got) != len(want) || changes.Status != "complete" {
t.Fatalf("got %v (%+v)", got, changes)
}
for name, reason := range want {
if r, ok := got[name]; !ok || r != reason {
t.Fatalf("%s: got %q (%v)", name, r, got)
}
}
}