Skip to content

feat(xvm): make self doctor see the binding state - #394

Merged
Sunrisepeak merged 1 commit into
release/0.4.70from
feat/xvm-doctor-bindings
Jul 26, 2026
Merged

Sunrisepeak merged 1 commit into
release/0.4.70from
feat/xvm-doctor-bindings

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

P0.6 of the 0.4.70 release train。

Problem

评审 §3.4 的"死路"场景:

$ xlings use gcc 15.1.0
✗ binding metadata integrity issue 'binding-group-field-invalid'
  at '/bindingGroup/rootVersion'

$ xlings self doctor --fix
✓ workspace/shim consistency OK      # ← 它看不见这个问题

$ # 然后呢?

doctor 只检查 shim 和 payload,完全不认识 binding 元数据。校验层 fail-closed 是对的,但在 xlings 里没有任何东西能说出是哪条条目坏了,用户只能手读 versions.json。

Change

新增 xvm::inspect_binding_state —— 对 (db, workspace) 的纯函数,检查选择层依赖的不变量:

  • 每个 active 版本都已注册(INV-1)
  • 每个 release 都能解析、成员齐全(INV-4)
  • 同一 release 的成员要么一起 active、要么都不(INV-2)

每条 finding 带 XvmUserError 的 code、出错条目、metadata 级问题的 JSON Pointer、以及指明修复命令的 hint。

纯函数(不碰 Config / 文件系统 / 网络),所以每个分支都能单测覆盖,doctor 退化为渲染器。

只读。修复动作单独提交 —— 停用一个组或丢弃元数据,应该在发生前先讲清楚。

Tests

7 条,含两条"不该误报"的护栏:

测试 覆盖
CleanStateReportsNothing 干净状态零输出
NamesTheCorruptFieldAndItsEntry JSON Pointer 精确到字段
ReportsAReleaseWithAMissingMember 悬空成员
ReportsAnIncoherentActiveRelease gcc@15 + g++@16 同时 active
ReportsAnActiveVersionThatIsNotRegistered INV-1
ABrokenReleaseIsReportedOncePerRelease 五成员缺一,报一次不是五次
LegacyStateWithoutGroupsIsNotFlagged 0.4.69 数据库不被误判为损坏

计划中的一项没做,原因值得记录

计划 P1.3 要求停止序列化 bindingIntegrityIssues(理由:派生数据不该变成存储状态)。实现后失败了 #384 的 7 条测试,而它们是对的。

一条 bindingGroup 没解析成功的记录,内存里根本不持有那个 group。不写回 marker 就意味着保存时把畸形值整个丢掉 —— 损坏条目被静默洗白成一条健康的无组条目,退回混合工具链风险,且不留任何痕迹。#384 的持久化正是在防这个。

真正的缺陷是:重写一条没能解析的记录,无论写不写 marker 都会丢信息。正确修法是为这类条目保留原始 JSON,那是独立的一次改动。已撤销该部分,序列化行为保持 #384 原样。

Verification

mcpp build   →  Finished release [optimized] in 49.91s
mcpp test    →  test result ok. 11 passed; 0 failed
XvmInspect   →  7 passed

CI 状态为已知上游拉取签名(见 #386),依计划 §3.1.1 合入集成分支。

The selection layer fails closed, so a malformed or dangling release
makes `xlings use` refuse. That is correct, but doctor only knew about
shims and payloads, so the refusal was a dead end: nothing in xlings
could name the offending entry and the user was left reading
versions.json by hand.

Add xvm::inspect_binding_state, a pure function over (db, workspace)
that checks the invariants the selection layer relies on:

  every active version is registered
  every release resolves, with all members present
  members of one release are active together, or not at all

Each finding carries the XvmUserError code, the entry, the JSON Pointer
when the problem is metadata-level, and a hint naming the command that
fixes it. A release short one member is reported once, not once per
member. Pre-0.4.70 databases carry no group metadata and are not flagged.

Pure by construction -- no Config, no filesystem, no network -- so every
case is reachable from a unit test and doctor stays a renderer.

Read-only. Repair lands separately: deactivating a group or dropping
metadata should be spelled out before it happens.

Not included, and worth recording why. The plan called for
bindingIntegrityIssues to stop being serialized, on the grounds that
derived data should not become stored state. Implementing it failed
seven tests from #384 that assert the opposite, and they are right: an
entry whose bindingGroup did not parse holds no group in memory, so
rewriting the record without the marker would drop the malformed value
entirely and silently launder a corrupt entry into a healthy
group-less one -- back to the mixed-toolchain risk, with nothing left to
show it happened. The real defect is that rewriting an unparsed record
loses information either way; fixing it means preserving the original
JSON for such entries, which is its own change.
@Sunrisepeak
Sunrisepeak merged commit 2d0f6c0 into release/0.4.70 Jul 26, 2026
0 of 6 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.

1 participant