fix(tools): implement fileSystem Open for ConcurrentFS and fix test cases

This commit is contained in:
Administrator 2026-03-10 10:59:32 +08:00
parent e49c801054
commit eebb25753a
3 changed files with 9 additions and 2 deletions

View file

@ -842,3 +842,10 @@ func (c *ConcurrentFS) ReadDir(path string) ([]os.DirEntry, error) {
// Directories rarely suffer from single-file corruption, but we delegate anyway. // Directories rarely suffer from single-file corruption, but we delegate anyway.
return c.baseFS.ReadDir(path) return c.baseFS.ReadDir(path)
} }
func (c *ConcurrentFS) Open(path string) (fs.File, error) {
lock := getPathLock(path)
lock.RLock()
defer lock.RUnlock()
return c.baseFS.Open(path)
}

View file

@ -533,7 +533,7 @@ func TestConcurrentFS_RaceCondition(t *testing.T) {
func TestConcurrencyUpgradeable(t *testing.T) { func TestConcurrencyUpgradeable(t *testing.T) {
// Verify that ReadFileTool implements the interface and upgrades correctly // Verify that ReadFileTool implements the interface and upgrades correctly
readTool := NewReadFileTool("", false) readTool := NewReadFileTool("", false, MaxReadFileSize)
upgradable, ok := interface{}(readTool).(ConcurrencyUpgradeable) upgradable, ok := interface{}(readTool).(ConcurrencyUpgradeable)
assert.True(t, ok, "ReadFileTool should implement ConcurrencyUpgradeable") assert.True(t, ok, "ReadFileTool should implement ConcurrencyUpgradeable")

View file

@ -11,7 +11,7 @@ func TestUpgradeRegistryForConcurrency(t *testing.T) {
original := NewToolRegistry() original := NewToolRegistry()
// Register a mix of tools: some upgradeable, some not // Register a mix of tools: some upgradeable, some not
readTool := NewReadFileTool("", false) readTool := NewReadFileTool("", false, MaxReadFileSize)
listTool := NewListDirTool("", false) // Not upgradeable listTool := NewListDirTool("", false) // Not upgradeable
writeTool := NewWriteFileTool("", false) writeTool := NewWriteFileTool("", false)