Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements. Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate. Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable. Refs: Versioned dependencies U1/U3; feature/dependency-workspace
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"git-ssh.u1680832.nyat.app/weichen/Agent-Native.git/runtime/checkpoint"
|
|
)
|
|
|
|
func TestWriteAndEditRecordCheckpoints(t *testing.T) {
|
|
root := t.TempDir()
|
|
log, err := checkpoint.Open(filepath.Join(t.TempDir(), "cp.jsonl"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reg := WorkspaceToolsCheckpointed(root, nil, log, func() string { return "m1" })
|
|
if reg.Execute(context.Background(), "write_file", []byte(`{"path":"a.txt","content":"one"}`)).IsError {
|
|
t.Fatal("write")
|
|
}
|
|
if reg.Execute(context.Background(), "edit_file", []byte(`{"path":"a.txt","old":"one","new":"two"}`)).IsError {
|
|
t.Fatal("edit")
|
|
}
|
|
if err := os.WriteFile(filepath.Join(root, "shell.txt"), []byte("nope"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := log.Rewind("m1", []string{"m1"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got.Restored) != 1 || got.Restored[0] != "a.txt" {
|
|
t.Fatalf("restored %#v skipped %#v", got.Restored, got.Skipped)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(root, "a.txt")); !os.IsNotExist(err) {
|
|
t.Fatal("created file was kept")
|
|
}
|
|
side, err := os.ReadFile(filepath.Join(root, "shell.txt"))
|
|
if err != nil || string(side) != "nope" {
|
|
t.Fatalf("shell file %q %v", side, err)
|
|
}
|
|
}
|
|
|
|
// ---- N3 WP3:回滚资格集合钉住(验收② 的机器证据)----
|
|
|
|
// 资格集合恰为 {write_file, edit_file, multi_edit}:三者在集且生产记录,
|
|
// 其余内置工具(read/grep/glob/list_dir)永不在集。
|
|
func TestCheckpointedToolSetIsPinned(t *testing.T) {
|
|
want := map[string]bool{"write_file": true, "edit_file": true, "multi_edit": true}
|
|
if len(CheckpointedTools) != len(want) {
|
|
t.Fatalf("资格集合漂移:%v", CheckpointedTools)
|
|
}
|
|
for _, n := range CheckpointedTools {
|
|
if !want[n] || !Checkpointed(n) {
|
|
t.Fatalf("资格集合漂移:%v", CheckpointedTools)
|
|
}
|
|
}
|
|
for _, n := range []string{"read_file", "grep", "glob", "list_dir", "run_python", "run_shell"} {
|
|
if Checkpointed(n) {
|
|
t.Fatalf("%s 不得在回滚资格集内", n)
|
|
}
|
|
}
|
|
}
|