Skip to content

fix(alist_v3): set child paths so nested directories resolve - #3019

Open
Elity wants to merge 2 commits into
OpenListTeam:mainfrom
Elity:fix/alist-v3-child-path
Open

fix(alist_v3): set child paths so nested directories resolve#3019
Elity wants to merge 2 commits into
OpenListTeam:mainfrom
Elity:fix/alist-v3-child-path

Conversation

@Elity

@Elity Elity commented Sep 1, 2026

Copy link
Copy Markdown

Summary / 摘要

AListV3.List never set Path on the objects it returns. op.Get resolves a
child by handing back the object from its parent's listing verbatim, so that
object is what the next List receives as dir — and with an empty Path, the
driver asked the upstream server for "".

An OpenList/AList server resolves an empty path to its own root, so the request
did not fail; it returned the wrong directory. Every level below the mount point
served the upstream root back, producing an endless self-similar directory: you
click into a folder, get the same listing again, and the breadcrumb grows one
segment each time.

User-visible behavior change:

  • Subdirectories of an AList V3 mount now open correctly. Previously only the
    mount root worked, because op.Get builds the root object itself from
    IRootPath and that one does carry a Path.

Implementation change:

  • List now sets Path: path.Join(dir.GetPath(), f.Name) on each returned
    object, which is what drivers/openlist already does
    (drivers/openlist/driver.go:98).

This is a regression from 96cd7143refactor(op): remove automatic Path
assignment
(#1734). That commit removed the block in op.List that used to
fill in a child's Path:

- if s, ok := f.(model.SetPath); ok && f.GetPath() == "" && dir.GetPath() != "" {
-     s.SetPath(stdpath.Join(dir.GetPath(), f.GetName()))

on the stated grounds that "Path和Id只在驱动内使用,不应由op.List设置Path", and
migrated the affected drivers to set it themselves. drivers/alist_v3 was
missed in that migration; drivers/openlist, which is otherwise a near-identical
file, was not.

Scope notes:

  • ListArchive also returns objects without a Path, but drivers/openlist
    behaves identically there, so it is left untouched.
  • drivers/alist_v3 lacks PassRefreshFlagToUpsteam. That is a feature
    difference, not part of this defect.

No configuration, storage format, API or migration behavior is affected.

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。
  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。
  • This PR requires corresponding changes in related repositories.
    / 此 PR 需要关联仓库同步修改。

Related repository PRs / 关联仓库 PR:

  • OpenList-Frontend: N/A
  • OpenList-Docs: N/A

Related Issues / 关联 Issue

Fixes #2077 — reported as "点击任意子目录继续进入时,发现会出现套娃". That issue was
closed after the reporter switched to the OpenList driver, but the AList V3
driver bug itself was never fixed.

cc @xrgzs — you triaged #2077 and noted that this driver is a copy kept for
newer AList API compatibility, so you are probably the right person to check
that aligning it with drivers/openlist here is the intended direction.

Testing / 测试

  • go test ./...
  • Manual test / 手动测试:

go test ./... is not checked because it does not pass on main in this
environment, for reasons unrelated to this change:

  • go vet's printf analyzer, which go test runs by default, fails the build
    of drivers/123, drivers/189, drivers/189pc, drivers/chaoxing,
    drivers/google_drive, drivers/google_photo, drivers/lanzou and three
    internal/offline_download/* packages with non-constant format string.
  • drivers/onedrive_sharelink.TestNoRedirectClientUsesSharedSettings panics
    with a nil pointer dereference at internal/net/serve.go:289, because
    conf.Conf is nil outside a booted server.

What was run instead:

go build ./...
go vet ./drivers/alist_v3/...
gofmt -l drivers/alist_v3/
go test -race -count=1 ./drivers/alist_v3/...

Manual test: an OpenList v4 instance mounting another OpenList v4 instance over
AList V3. Before the fix, every directory below the mount point returned the
upstream server's root. After the fix, a 384-entry directory and its children
list correctly, three levels deep.

Two tests are added in drivers/alist_v3/driver_test.go:

  • TestListSetsChildPaths — every returned object carries
    path.Join(dir.GetPath(), name).
  • TestListDoesNotLoopOnNestedDirectories — descends three levels, feeding each
    listing's object back into List the way op.Get does, and asserts both the
    listings and the exact paths the upstream server was asked for.

The fake upstream deliberately falls back to its own root for an unknown path
instead of returning 404, because that is what a real server does. Answering 404
would turn the defect into a loud error and the loop would not reproduce.

Both tests fail on main:

--- FAIL: TestListSetsChildPaths
    child "concerts" has path "", want "/drive/concerts"
--- FAIL: TestListDoesNotLoopOnNestedDirectories
    listing under "/drive/concerts" is [drive public], want [live-in-tokyo]

Mutation-checked: Path: f.Name, Path: dir.GetPath() and Path: "" are each
caught by the tests.

The new tests install their own resty client rather than calling
base.InitClient(), to avoid the same nil conf.Conf dereference that makes
drivers/onedrive_sharelink panic.

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
    / 我已按适用情况使用 gofmtgo fmtprettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 我已在适用情况下请求相关维护者或代码所有者审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
    / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • ChatGPT
  • Codex
  • GitHub Copilot
  • Claude
  • Gemini
  • Other (please specify) / 其他(请注明):

Usage scope / 使用范围:

  • Code generation / 代码生成

  • Refactoring / 重构

  • Documentation / 文档

  • Tests / 测试

  • Translation / 翻译

  • Review assistance / 审查辅助

  • I have reviewed and validated all AI-assisted content included in this PR.
    / 我已审核并验证此 PR 中的所有 AI 辅助内容。

  • I have ensured that all AI-assisted commits include Co-Authored-By attribution.
    / 我已确保所有 AI 辅助提交都包含 Co-Authored-By 归属信息。

  • I can reproduce all AI-assisted content included in this PR without any AI tools.
    / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。

- Set `Path` on every object returned by `List`, matching the OpenList
  driver. `op.Get` hands a child object straight back to `List`, so a
  child without a path made the driver request `""` from the upstream
  server, which answered with its own root: every directory below the
  mount point served the same listing back, endlessly.
- Add tests covering the child paths and a three-level descent.

Co-authored-by: Claude <81847+claude@users.noreply.github.com>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest reducing the test code from 173 lines to around 20–50 lines, or just remove it. There’s no need to introduce an entire fake server just to cover a single line of production code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cut to a single test: 65 lines, 46 of them code. Dropped the second test, the recorder type and the helper funcs, and inlined the driver setup.

I kept the httptest server rather than removing the file. List does its work over HTTP, so there is no seam to exercise it without a server — the alternative here is no test at all. The fake upstream falls back to its own root for unknown paths, which is what makes the loop reproduce; without the one-line fix it fails with:

child of "/drive" has path "", want "/drive/concerts"

Happy to drop the file entirely if you would rather this package stay test-free.

Collapse the two tests into one two-level descent, drop the recorder
type and the helper funcs, and inline the driver setup. 173 -> 65 lines.

Co-authored-by: Claude <81847+claude@users.noreply.github.com>
@Elity
Elity force-pushed the fix/alist-v3-child-path branch from 248c2d9 to 41736cf Compare September 2, 2026 04:27

@pikachuren pikachuren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 感谢 @Elity 提交!
🤖 AI 自动审核声明:本评审报告由 AI 自动生成,当前使用 Claude Opus 5 模型进行分析。
⚠️ AI 分析结果仅供参考,可能存在误判或遗漏。如您发现任何问题或有不同意见,欢迎随时提出讨论和纠正。
⚠️ 重要提醒:即使 AI 评审认为代码质量良好且建议合并,最终是否合并仍需由项目维护者进行人工判定。项目维护者会综合考虑代码质量、项目规划、技术方向、团队资源等多方面因素做出是否合并的决策。

🎯 结论

✅ Approve — 修复关键 bug,代码质量优秀,测试覆盖充分,符合最小改动原则

📖 概要

fix(alist_v3): set child paths so nested directories resolve · 修复 AList V3 驱动嵌套目录无限循环 bug
核心改动:在 List 方法中为子对象设置 Path 字段,修复 #1734 引入的回归问题

🧭 整体方案

这是一个教科书级别的 bug 修复 PR

  • 问题诊断精准:清晰追溯到 commit 96cd7143 的重构遗漏
  • 根因分析深入op.Get 将父目录 listing 的对象原样传给下一层 List,空 Path 导致向上游请求 "",服务器返回根目录,形成无限循环
  • 修复方案最小化:仅添加一行 Path: path.Join(dir.GetPath(), f.Name),与 drivers/openlist 对齐
  • 测试覆盖完整:新增 2 个单元测试,模拟真实 HTTP 交互,覆盖边界情况

📊 变更统计

2 个文件(+66 / -0 行) | 功能 ⭐⭐⭐⭐⭐ | 最小改动 ⭐⭐⭐⭐⭐ | 前向兼容 ⭐⭐⭐⭐⭐ | 方案设计 ⭐⭐⭐⭐⭐

🚨 关键问题

无关键问题

📂 逐文件分析

drivers/alist_v3/driver.go

改动意图:修复 List 方法未设置子对象 Path 字段的 bug
代码逻辑:在构造 model.Object 时添加 Path: path.Join(dir.GetPath(), f.Name)
问题分析

  • ✅ 与 drivers/openlist 的实现完全对齐(见 drivers/openlist/driver.go:98
  • ✅ 修复了 #1734 重构时的遗漏,当时迁移了其他驱动但漏掉了 alist_v3
  • ✅ 最小改动:仅添加一行,不影响其他逻辑
  • ✅ 向后兼容:不涉及 API、配置、存储格式或迁移行为

用户可见行为变化

  • 修复前:AList V3 挂载点的子目录点击后显示上游根目录,形成"套娃"无限循环
  • 修复后:子目录正常打开,显示正确内容

drivers/alist_v3/driver_test.go(新文件)

改动意图:添加单元测试覆盖 bug 修复
代码逻辑

  • TestListSetsChildPaths:验证 List 返回的每个对象都携带正确的 Pathpath.Join(dir.GetPath(), name)
  • 模拟真实场景:使用 httptest 创建假的上游服务器,模拟 AList V3 的 HTTP 响应
  • 边界情况覆盖:故意让假上游对未知路径返回根目录(而非 404),复现真实服务器行为
  • Mutation testing:PR 描述中提到测试了 Path: f.NamePath: dir.GetPath()Path: "" 等错误实现,均被测试捕获

问题分析

  • ✅ 测试设计优秀,完整模拟了 op.Get 将子对象传回 List 的真实调用链
  • ✅ 避免了 conf.Conf nil 问题,手动初始化 resty.Client 而非调用 base.InitClient()
  • ✅ 测试在 main 分支失败,在修复后通过,证明测试有效
  • ✅ 代码质量高,注释清晰说明了测试意图和边界情况

覆盖的场景

  • 两层嵌套目录(/drive/drive/concerts/drive/concerts/show.mkv
  • 验证每层的 Path 字段正确拼接
  • 模拟上游服务器对空路径返回根目录的真实行为

💡 优势

  • 问题诊断精准:PR 描述详尽,包含 root cause 分析、受影响提交、用户可见行为变化
  • 修复方案最小化:仅一行代码,不引入额外复杂度
  • 测试覆盖充分:2 个单元测试,覆盖核心逻辑和边界情况
  • 代码质量优秀:AI 辅助内容经过人工验证,符合贡献规范
  • 历史追溯清晰:明确指出 #1734 引入的回归,帮助理解上下文
  • 影响范围透明:明确说明不涉及破坏性变更、配置、API 或迁移

📝 建议

  • 💡 非阻塞建议:考虑在 drivers/alist_v3/driver_test.go 中添加第二个测试 TestListDoesNotLoopOnNestedDirectories(PR 描述中提到但未包含在 diff 中),进一步验证不会陷入无限循环
  • 💡 建议 maintainer @xrgzs 确认与 drivers/openlist 对齐是预期方向(PR 已 cc)

✅ 待处理清单

无待处理项

🎖️ 特别表彰

这是一个示范级别的 bug 修复 PR

  • 问题分析深入,根因追溯到具体 commit
  • 修复方案最小化,仅一行代码
  • 测试覆盖充分,模拟真实场景
  • PR 描述详尽,包含用户影响、技术细节、测试结果
  • 符合贡献规范,AI 辅助内容经过验证

🎯 结论:✅ Approve — 这是一个高质量的 bug 修复,建议立即合并以修复用户报告的 #2077 问题

@xrgzs
xrgzs enabled auto-merge (squash) September 5, 2026 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Alist v3驱动挂载无法访问

3 participants