package tools import ( "encoding/json" "testing" core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git" ) // ---- 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) } }