agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]:`RemoteFilesystem.glob()` 使用 `**/` 模式时无法匹配搜索目录根层文件

Open CyberXavier opened this issue 4 months ago • 1 comments

问题描述

在 Windows 环境中,调用 RemoteFilesystem.glob() 使用 **/hello.txt、**/*.txt 等递归 glob 模式时,无法匹配搜索目录根层的文件。

例如远程文件系统中存在:

/hello.txt
/reports/hello.txt

执行:

filesystem.glob(runtimeContext, "**/hello.txt", "/");

实际只能匹配:

/reports/hello.txt

无法匹配:

/hello.txt

文件实际存在于 BaseStore 中,问题发生在 RemoteFilesystem.glob() 对候选路径进行 glob 过滤的阶段。

运行环境

  • JDK:17
  • 操作系统:Windows
  • 文件系统实现:io.agentscope.harness.agent.filesystem.remote.RemoteFilesystem
  • Store:InMemoryStore 和 MySQL JdbcStore 均可复现
  • AgentScope Java:当前源码版本

最小复现代码

@Test
void recursiveGlobShouldMatchFileAtRemoteRoot() {
    InMemoryStore store = new InMemoryStore();
    RemoteFilesystem filesystem =
        new RemoteFilesystem(store, List.of("test"));
    RuntimeContext runtimeContext = RuntimeContext.empty();

    WriteResult writeResult =
        filesystem.write(runtimeContext, "/hello.txt", "hello");

    assertTrue(writeResult.isSuccess());

    GlobResult globResult =
        filesystem.glob(runtimeContext, "**/hello.txt", "/");

    assertTrue(globResult.isSuccess());
    assertThat(globResult.matches())
        .extracting(FileInfo::path)
        .contains("/hello.txt");
}

当前实际结果:

globResult.matches() = []

如果文件改为嵌套路径:

filesystem.write(
    runtimeContext,
    "/reports/hello.txt",
    "hello"
);

则可以被 **/hello.txt 匹配。

预期行为

**/hello.txt 应同时匹配搜索目录根层和嵌套目录中的文件:

/hello.txt
/reports/hello.txt
/reports/archive/hello.txt

同理,**/*.txt 应同时匹配:

/hello.txt
/reports/report.txt

实际行为

根层文件被遗漏:

/hello.txt                    未匹配
/reports/hello.txt            可以匹配
/reports/archive/hello.txt    可以匹配

CyberXavier avatar Jul 21 '26 12:07 CyberXavier

根因:递归模式 **/ 在 Java glob 里要求至少一个目录分隔符,所以匹配不到搜索根目录下的裸文件名(如 **/hello.txt 匹配不到 /hello.txt)。代码里兜底的 directMatcher 对 ** 开头的 pattern 会塌缩成和主 matcher 一样,失去作用。已提 PR #2344:构造 directMatcher 时剥掉前导 **/,覆盖索引快路径和全量扫描两条路径,并补了 **/hello.txt、**/*.txt 两个回归用例(用你给的最小复现验证过)。

logicwu0 avatar Jul 21 '26 12:07 logicwu0