mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-10 13:11:31 -10:00
* Checkpoint UI polish * Fix structured apply patch handling * Restore tool previews when resuming sessions * Improve theme-aware code rendering * Replace persistent sidebar with run details * Remove inert transcript interactions * Cover resumed edit previews * Smooth active run status feedback * Preserve semantic colors behind overlays * Normalize ChatGPT model aliases * Render staged image attachments in terminal * Polish transcript and tool feedback * Resolve rebased diff renderer conflict * Address UI polish review findings * Fix smoke test regressions * Harden patch and transcript edge cases * Bind structured patches to workspace root * Use unique structured patch temp files * Retry structured patch temp allocation * Reuse rooted patch temp allocator * Fix Windows CI process checks * Fix structured patch safety boundaries Preserve read-before-write credit only when the model already knew the full source, reject ambiguous hunk matches, and retain CRLF line endings. Add regression coverage for unsafe overwrites, positive tracking cases, duplicate matches, and Windows-style files. * Resolve plan test seam after rebase Drop the obsolete sticky-plan height helper while retaining the PR status test seams brought forward by the UI changes. * Address final review correctness gaps Bound narrow waiting labels, reject malformed plan records, preserve missing final newlines, reject out-of-order EOF hunks, clear stale tracking after failed rollback, and keep deferred tool loading aligned with model visibility. * Harden patch transactions and review edges Publish new patch targets without overwriting raced destinations, journal only completed mutations, and create replacement temps beside their targets. Reject pre-plan diagnostics, cover tool-search transcript suppression, and leave sufficient cleanup time in the Windows process fixture. * Bind patch rollback to committed versions Capture file identity and content before publication, quarantine rollback targets atomically, and refuse destructive undo when a path was replaced or modified in place. Add deterministic coverage for publication and rollback races. * Align structured patch failure semantics Use prevalidated sequential application with explicit partial-success errors instead of unsafe multi-file rollback. Retain atomic per-file publication, no-overwrite creates, unsupported-hardlink fallback, and conservative tracker invalidation. * Preserve patch context bytes Track source offsets for structured-patch context lines and reuse the exact matched source text during replacement. This keeps tolerant matching from changing indentation or mixed line endings outside the requested edit.
94 lines
3.0 KiB
Go
94 lines
3.0 KiB
Go
package worktrees
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The constructor every git call goes through must carry the hardening, so a
|
|
// future call site cannot get an unhardened command by using it.
|
|
func TestTheGitConstructorHardens(t *testing.T) {
|
|
command := newHardenedCommand(context.Background(), t.TempDir(), "git", "status")
|
|
if command.WaitDelay == 0 {
|
|
t.Fatal("WaitDelay is unset; a cancelled git can block Wait indefinitely")
|
|
}
|
|
if command.Dir == "" {
|
|
t.Fatal("the working directory was dropped")
|
|
}
|
|
// The process-group half is POSIX-only and is asserted in
|
|
// run_git_unix_test.go, which can name Setpgid at all — this file must
|
|
// compile on Windows, where it does not exist.
|
|
if runtime.GOOS != "windows" && command.Cancel == nil {
|
|
t.Fatal("Cancel is unset; the process group is never signalled")
|
|
}
|
|
}
|
|
|
|
// ...and the git runner itself still works, so the hardening did not break the
|
|
// ordinary path.
|
|
func TestHardenedGitStillRuns(t *testing.T) {
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
t.Skipf("no git: %v", err)
|
|
}
|
|
result, err := defaultRunGit(context.Background(), t.TempDir(), "--version")
|
|
if err != nil {
|
|
t.Fatalf("git --version: %v", err)
|
|
}
|
|
if result.ExitCode != 0 || result.Stdout == "" {
|
|
t.Fatalf("result = %+v", result)
|
|
}
|
|
}
|
|
|
|
// EXACTLY ONE PLACE BUILDS A SUBPROCESS IN THIS PACKAGE.
|
|
//
|
|
// Every behavioural test above goes through newHardenedCommand, so all of them
|
|
// pass against a defaultRunGit that quietly builds its own unhardened command —
|
|
// which is the wiring gap this feature has produced five times, and the only one
|
|
// no runtime assertion here can reach: defaultRunGit returns a result, not the
|
|
// command it used.
|
|
//
|
|
// So the invariant is enforced at the SOURCE. This is the small, local form of
|
|
// the AST enforcement the repo-wide hardening sweep would need, applied to the
|
|
// one package a plan reaches.
|
|
func TestOnlyTheHardenedConstructorBuildsSubprocesses(t *testing.T) {
|
|
entries, err := os.ReadDir(".")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
offenders := []string{}
|
|
checked := 0
|
|
for _, entry := range entries {
|
|
name := entry.Name()
|
|
if entry.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
|
|
continue
|
|
}
|
|
raw, err := os.ReadFile(name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
checked++
|
|
for index, line := range strings.Split(string(raw), "\n") {
|
|
if !strings.Contains(line, "exec.Command") {
|
|
continue
|
|
}
|
|
// The one permitted site is inside newHardenedCommand, which
|
|
// hardens what it builds.
|
|
if name == "worktrees.go" && strings.Contains(line, "exec.CommandContext(ctx, name, args...)") {
|
|
continue
|
|
}
|
|
offenders = append(offenders, fmt.Sprintf("%s:%d: %s", name, index+1, strings.TrimSpace(line)))
|
|
}
|
|
}
|
|
if checked == 0 {
|
|
t.Fatal("no source files were scanned; this test checked nothing")
|
|
}
|
|
if len(offenders) > 0 {
|
|
t.Fatalf("a subprocess is built outside newHardenedCommand, so it is not hardened:\n %s",
|
|
strings.Join(offenders, "\n "))
|
|
}
|
|
}
|