ci / vet-and-test (pull_request) Successful in 42s
Why: the library now pins eligibility, guards symlinks, reports partial
restores, and bounds the log (Agent-Native#33); the product wires
retention after successful rewinds and needed the HTTP-layer and
eligibility evidence.
Evidence: go test -count=1 ./... green; TestRewindFilesHTTPHappy and
TestRewindFilesHTTPBusy409 (HTTP happy + conflict),
TestBackendCheckpointEligibilityIsWriteFileOnly (the product surface
checkpoints exactly {fs_write_file}).
Impact: checkpoints.jsonl is compacted to the latest 200 anchors after
each successful rewind.
Refs: Agent-Native#33, Agent-Squad#37, N3 plan WP3
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package tools
|
||
|
||
import (
|
||
"encoding/json"
|
||
"testing"
|
||
|
||
core "agent-system-core"
|
||
)
|
||
|
||
// ---- N3 WP3:backend 自家工具面的回滚资格钉住(验收② 产品侧)----
|
||
|
||
type checkpointNoteCtx struct {
|
||
*fakeFSCtx
|
||
noted []string
|
||
}
|
||
|
||
func (c *checkpointNoteCtx) NoteFileCheckpoint(rel string, before []byte, existed bool, after []byte) error {
|
||
c.noted = append(c.noted, rel)
|
||
return nil
|
||
}
|
||
|
||
// backend 工具面里只有 fs_write_file 写检查点(产品面不暴露编辑工具是刻意的
|
||
// 收窄);fs_read_file / fs_list_dir 永不记录。
|
||
func TestBackendCheckpointEligibilityIsWriteFileOnly(t *testing.T) {
|
||
r := newFSRegistry(t)
|
||
ctx := &checkpointNoteCtx{fakeFSCtx: &fakeFSCtx{root: t.TempDir(), owner: "o1", conv: "c1", fsToolsOn: true}}
|
||
exec := func(name, args string) {
|
||
t.Helper()
|
||
r.Execute(ctx, core.ToolCallRequest{CallID: "c-" + name, Name: name, Arguments: json.RawMessage(args)})
|
||
}
|
||
exec("fs_write_file", `{"path":"a.txt","content":"x"}`)
|
||
if len(ctx.noted) != 1 || ctx.noted[0] != "a.txt" {
|
||
t.Fatalf("fs_write_file 必须写检查点:%v", ctx.noted)
|
||
}
|
||
exec("fs_read_file", `{"path":"a.txt"}`)
|
||
exec("fs_list_dir", `{"path":"."}`)
|
||
if len(ctx.noted) != 1 {
|
||
t.Fatalf("读类工具不得写检查点:%v", ctx.noted)
|
||
}
|
||
}
|