Skip to content

fix: resolve SemVer constraints through the index route, not the registry - #309

Merged
speak-agent merged 1 commit into
mainfrom
fix/semver-index-route
Jul 29, 2026
Merged

fix: resolve SemVer constraints through the index route, not the registry#309
speak-agent merged 1 commit into
mainfrom
fix/semver-index-route

Conversation

@speak-agent

Copy link
Copy Markdown
Member

Summary

resolve_semver / try_merge_semverFetcher& 并直接 read_xpkg_lua,只读共享 registry;而候选选择走的是 mcpp.pm.index_route 的三路分发(本地 path 索引 / 项目 clone / registry)。

结果:项目 [indices] 里的包,写死版本能解析,一旦带 SemVer 约束就挂 ——

dependency 'acme.gadget' has SemVer constraint '^2.0' but the index entry
isn't cloned locally yet — run `mcpp index update` first

对本地 path 索引来说这条提示毫无作用,用户没有出路。

  • 两个函数改收 const IndexRoute&,描述符在所有路径上以同一种方式获取
  • mcpp new --template 传一个不含项目索引的 route —— 这正是它一直以来的语义(还没有工程)
  • 未找到时,若负责的是本地 path 索引,不再给 mcpp index update 提示
  • prepare.cppmindex_route lambda 上移到 resolveSemver 之前,自身无改动

Closes #308

Test plan

  • mcpp build 通过
  • 单元测试 38/38
  • 新增 tests/e2e/169_semver_project_index.sh:本地 path 索引 + ^2.0 → v2.1.0,同时锁住写死版本那条路径;载荷预置在工程 xlings data 目录,全程不联网
  • 负向对照:同一份测试在 origin/main(9959be5)构出的二进制上复现 issue 原文报错
  • 索引相关 e2e 全过:12 / 42 / 43 / 44 / 120 / 121 / 169
  • 完整 e2e 套件

顺带发现(未在本 PR 处理)

lock 文件记的是约束而不是解析后的版本(version = "^2.0"),共享 registry 依赖同样如此,属既有行为、非本次改动引入。锁不住版本对 lockfile 来说是个真问题,建议单开 issue。

…stry

`resolve_semver` / `try_merge_semver` took a `Fetcher&` and called
`read_xpkg_lua` on it, which only ever reads the shared registry under
`<XLINGS_HOME>/data`. Candidate selection, meanwhile, dispatches across all
three descriptor transports (local path index, project clone, registry).

The split meant a package served by a project `[indices]` entry resolved
fine as an exact version and failed the moment the same dependency carried
a constraint:

    dependency 'acme.util' has SemVer constraint '^2.0' but the index entry
    isn't cloned locally yet — run `mcpp index update` first

— advice that does nothing for a local path index, leaving no way forward.

Both functions now take `const IndexRoute&`, so the descriptor is reached
the same way everywhere. `mcpp new --template` passes a route with no
project indices, which is what it always meant: there is no project yet.
The not-found message drops the `mcpp index update` hint when a local path
index is what would have answered.

`prepare.cppm`'s `index_route` lambda moves above `resolveSemver` so the
resolver call can use it; nothing else about it changes.

Closes #308

@Sunrisepeak Sunrisepeak left a comment

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.

Verified: negative control reproduces #308 on 9959be5, fix resolves ^2.0 → v2.1.0 through the project index. Full e2e 161/0/5 locally, 15/15 CI.

@speak-agent
speak-agent merged commit 413b8d4 into main Jul 29, 2026
15 checks passed
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.

fix: SemVer constraints cannot resolve for packages served by a project [indices] entry

2 participants