fix(agent): 卸载时指出该去哪删节点,而不是一律说 agents.json

agent 不持有运维令牌——节点不是运维,一个能删掉邻居的被控节点比它解决的问题更糟——所以
它不能自己从中继上摘掉自己。此前卸载的结束语对所有节点都写"the relay's agents.json still
lists this node",而自注册的节点根本不在那里:它在中继的状态文件里,要从手机上删。运维照着
那句话去翻一个没有这条记录的文件。

现在节点在登记时把来历写进配置(`selfEnrolled`,带 `--code` 为真),卸载结束语据此给出
正确的那一句:

- 自注册的 → "在中继的登记状态里,去 App 的「中继节点」移除"
- 手工登记的 → "在 agents.json 里,删掉那条并重启中继"
- 配置读不出来 → 两句都提,因为读不到不是让卸载失败的理由

测试两项:卸载打印的是它被告知的那一句(且不再对自注册节点说 agents.json)、登记时正确
记录来历(带码为真、不带码不写这个字段)。

Go 全包、Node 141 项、Swift 121 项通过。
This commit is contained in:
chick
2026-09-17 19:12:32 +08:00
parent 934760f8e2
commit 7d174a0261
6 changed files with 96 additions and 1 deletions
+8
View File
@@ -55,6 +55,14 @@ type File struct {
// certificate. It exists for a relay behind a private CA; the default is the system store, which
// is what a public certificate needs. Setting it pins trust rather than disabling verification.
RelayCAFile string `json:"relayCAFile,omitempty"`
// SelfEnrolled records that this node registered itself with the relay using a one-time code,
// rather than being written into the relay's agents.json by an operator.
//
// It exists so `uninstall` can tell the operator which of two removals applies, because the agent
// cannot do either: it holds no admin token, by design — a node is not an operator, and giving it
// one would let a compromised node remove its neighbours. So the node records which half of the
// relay's state mentions it, and the operator is told exactly what to delete.
SelfEnrolled bool `json:"selfEnrolled,omitempty"`
// AuditPath is where the audit log is appended.
AuditPath string `json:"auditPath"`
// Devices may be empty only in pair mode (--pair). In normal operation an agent with no