Skip to content

fix(anolisa): fallback to v1 components.toml when v2 is missing (Fixes #2562) - #2564

Open
zhangtaibo wants to merge 1 commit into
alibaba:mainfrom
zhangtaibo:fix/anolisa-components-v2-fallback
Open

fix(anolisa): fallback to v1 components.toml when v2 is missing (Fixes #2562)#2564
zhangtaibo wants to merge 1 commit into
alibaba:mainfrom
zhangtaibo:fix/anolisa-components-v2-fallback

Conversation

@zhangtaibo

Copy link
Copy Markdown
Collaborator

问题

Fixes #2562

anolisa list 等命令依赖 load_component_index 从镜像拉取 components-v2.toml,但镜像尚未发布 v2 文件,导致 HTTP 404 后命令整体 hard-fail(exit code 1),所有用户的 list / install --all / update all 全瘫。

修复

参照 fetch_raw_index(raw.rs:73-91)已有的 v2→v1 fallback 模式,在 load_component_index 中实现相同的 fallback:

  • 先尝试 v2 components-v2.toml
  • 404 时 fallback 到 v1 components.toml
  • Schema validator 放宽为接受 v1+v2(v1 行无 targets,serde default 为空 vec)
  • validate() 对 v1 跳过非空 targets 校验

验证

cd /root && git clone https://github.com/alibaba/anolisa.git && cd anolisa
git apply /path/to/patch
cd src/anolisa && cargo build --release --bin anolisa
cp target/release/anolisa /usr/local/bin/
anolisa -v list
# exit 0,正确显示 9 个组件

实测 exit 0,输出组件列表完整。

Co-Authored-By: Claude noreply@anthropic.com

load_component_index hard-fails on components-v2.toml HTTP 404, breaking
anolisa list/install --all/etc. entirely. Mirror has not published v2 yet.

Add v2→v1 fallback matching the pattern in fetch_raw_index: on 404 fetch
v1 components.toml. Schema validator now accepts schema v1 and v2 (v1 rows
lack targets, which defaults to empty via #[serde(default)]), so the v2
parser loads legacy indexes gracefully.

Fixes: alibaba#2562
Discovered-by: AgenticOS Nightly nightly-20260814-170909

Co-Authored-By: Claude <noreply@anthropic.com>

@qoderai qoderai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • v2 组件索引的回退仅在 404 时触发,其他网络错误下 v1 可用也无法利用,建议扩展回退条件。
  • schema v1/v2 验证逻辑与单测覆盖存在轻微不对齐,建议补充正向与负向用例以防止回归。

🤖 Generated by QoderView workflow run

@@ -741,18 +748,43 @@ pub(crate) fn load_component_index(
let url = component_index_v2_url(&base_url);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P1] v1/v2 回退逻辑忽略非 404 场景

load_component_index 中对 v2 components-v2.toml 的 fetch 仅在 reason.contains("http status 404") 时回退到 v1,否则直接返回原始 ComponentIndexError::Fetch。这会让如超时、DNS 失败、403 等非 404 错误在 v1 也可用时依然导致命令整体失败,违背“镜像暂未部署 v2 时尽量保持可用”的目标。建议将回退条件扩展为“任何 v2 fetch 失败但 v1 fetch 成功都接受 v1”,并在错误信息中区分“v1 也失败”与“v1 成功”。

(位置:src/anolisa/crates/anolisa-cli/src/resolution.rs:748-768)


🤖 Generated by QoderFix in Qoder

Comment on lines 1357 to 1359

#[test]
fn unsupported_schema_is_rejected() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] v1/v2 schema 接受范围与测试略有不一致

ComponentIndex::validate 改为接受 schema_version 为 1 或 2,但单元测试 unsupported_schema_is_rejected 只对值 99 进行校验,未显式覆盖 v1/v2 正常路径,也未防止未来误改为只接受 2。为避免回归,建议增加覆盖:断言 1 和 2 均通过、其它值(如 0、3、99)被拒绝。

(位置:src/anolisa/crates/anolisa-cli/src/resolution.rs:473-483, 1357-1364)


🤖 Generated by QoderFix in Qoder

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa15575d4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// The v2 parser accepts v1 rows because `targets` has
// `#[serde(default)]`, so legacy indexes without targets
// still load (components simply appear as "no target info").
let v1_url = component_index_url(&base_url);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore target support when falling back to v1

When the mirror has not published components-v2.toml, this 404 path loads schema-version-1 components.toml; those files declare platforms, not targets, while this patch defaults missing targets to an empty vec and skips the non-empty validation. Downstream ComponentIndexEntry::supports_target() only checks targets, so every fallback-loaded component is treated as unsupported: anolisa list marks them unavailable and install --all filters them all out. Please translate the v1 platform data or otherwise preserve legacy target semantics before returning the fallback index.

Useful? React with 👍 / 👎.

@kongche-jbw kongche-jbw 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.

Review baseline: a50e34de6130...aa15575d4a6b

[P1] v1 fallback 会丢失平台可用性

src/anolisa/crates/anolisa-cli/src/resolution.rs:56 把 v1 缺失的 targets
默认为空,同时解析器会忽略 v1 实际使用的 platforms。在 v2 返回 404 后,
supports_target() 因此对所有组件返回 false;list 会把全部组件标为
unavailable,install --all 则输出没有可用组件并安装 0 项。

Possible direction: 在返回前把 v1 platforms 规范化为当前 target 语义,并增加
一条从 v1-only 仓库加载后走过 list 与 batch 筛选调用链的回归测试。

[P2] “未发布”检测遗漏受支持的本地仓库

src/anolisa/crates/anolisa-cli/src/resolution.rs:754 通过格式化后的错误字符串
只匹配 HTTP 404。file:// 仓库缺少 v2 时会返回 Io(NotFound),HTTP 410
也按相邻 raw index 的约定代表文件不存在;这两种情况下 v1 明明存在仍会报错。

Possible direction: 保留 DownloadError 类型并复用 404、410、I/O NotFound 的
absence 判定;测试 v1-only file 仓库、410,以及 403/timeout 不降级。

[P2] 修复会阻断 CI 的格式与 Clippy 错误

src/anolisa/crates/anolisa-cli/src/resolution.rs:17 等新增行未通过
cargo fmt --all -- --check;修正格式后,resolution.rs:1363 的单元素循环
仍触发 clippy::single-element-loop。当前 Test anolisa 已在格式步骤失败。

Possible direction: 应用 rustfmt,并改为直接断言或覆盖多个非法版本;重跑
fmt 与 clippy。

[P2] 移除截断且无关的补丁文件

0001-fix-anolisa-add-missing-Provides-anolisa-component-n.patch:1 与本次 fallback
无关;其 subject 声称修改四个 spec,正文却只包含一个文件,且
git diff --check 会报告其中的尾随空白。保留它会把不完整补丁作为源码交付。

Possible direction: 从本 PR 删除该文件,并重跑 git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Nightly] anolisa list 命令失败:components-v2.toml HTTP 404

2 participants