package tools import ( "context" "os" "path/filepath" "testing" ) func TestWriteAllowlistRestrictsDocumentTools(t *testing.T) { root := t.TempDir() reg := WorkspaceTools(root) ApplyWriteAllowlist(reg, []string{"allowed.md"}) ok := reg.Execute(context.Background(), "write_file", []byte(`{"path":"allowed.md","content":"yes"}`)) if ok.IsError { t.Fatalf("allowed write rejected: %s", ok.Content) } denied := reg.Execute(context.Background(), "write_file", []byte(`{"path":"other.md","content":"no"}`)) if !denied.IsError { t.Fatal("write outside writable set must fail") } if _, err := os.Stat(filepath.Join(root, "other.md")); !os.IsNotExist(err) { t.Fatal("denied path must not be created") } }