mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-15 12:15:16 +00:00
内核侧配合 SDK 仓 b2872f3:兼容性不再依赖任何自造版本号。
删除三处自造号:
- ProtocolVersion(协议号)→ 改为比对主版本段(MajorVersion)
- shmVersion(共享段 header)→ 改为校验描述符个数(field_count)
- unifiedVersion(SuperBlock)→ 结构自描述,不再校验
握手契约随之调整:
HandshakeParams: protocol(int) → core_version(string)
HandshakeResult: protocol(int) → sdk_version 承担判据
内核比对 MajorVersion(meta.Version) == MajorVersion(res.SDKVersion),
跨主版本即拒并提示重编(主版本跃迁 = 破坏性变更的定义)。
为什么废除:额外的号需要人去记得升,而它没有任何结构性约束兜底,
必然腐烂。实证:ProtocolVersion 常量在多次布局变更里只升过一次,
对应的守卫测试长期失败无人察觉(期望 18/1,实际 19/2)。
新增判据:
- TestProcess_MajorVersionMismatchRejected:跨主版本被拒(testdata/badproto)
- TestProcess_SameMajorDifferentMinorAccepted:同主版本放行(新增 testdata/oldminor)
后者是 §七「1.x 内纯追加、不调新面不用重编」规约的落地 —— 若误用全等
比较,未重编的存量插件会被无谓地全部拒绝。
两条均经变异验证:改成全等比较 → 前者过/后者挂;删掉校验 → 前者挂。
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
//go:build ignore
|
||
|
||
// oldminorplugin 上报同主版本但更早的中版本 SDK,验证内核**不会**无谓拒绝。
|
||
//
|
||
// 规约(docs/git-branching.md §七.1):1.x 内的中版本跃迁全部是纯追加 ——
|
||
// 新增方法由插件调用、内核实现,不调就不受影响。因此未重编的存量插件
|
||
// (如用 SDK 1.0.0/1.1.0 编的)必须能在新内核上直接建链。
|
||
//
|
||
// 若判据误用「全等比较」而非「主版本比较」,这条会失败 —— 正是它的价值。
|
||
package main
|
||
|
||
import (
|
||
"bufio"
|
||
"encoding/json"
|
||
"os"
|
||
)
|
||
|
||
type request struct {
|
||
ID uint64 `json:"id,omitempty"`
|
||
Method string `json:"method"`
|
||
Params json.RawMessage `json:"params,omitempty"`
|
||
}
|
||
|
||
type response struct {
|
||
ID uint64 `json:"id"`
|
||
Result interface{} `json:"result,omitempty"`
|
||
Error string `json:"error,omitempty"`
|
||
}
|
||
|
||
func main() {
|
||
in := bufio.NewScanner(bufio.NewReader(os.Stdin))
|
||
out := bufio.NewWriter(os.Stdout)
|
||
send := func(v interface{}) {
|
||
b, _ := json.Marshal(v)
|
||
out.Write(b)
|
||
out.WriteByte('\n')
|
||
out.Flush()
|
||
}
|
||
|
||
for in.Scan() {
|
||
var req request
|
||
if err := json.Unmarshal(in.Bytes(), &req); err != nil {
|
||
continue
|
||
}
|
||
if req.Method == "handshake" {
|
||
send(response{ID: req.ID, Result: map[string]interface{}{
|
||
"sdk_version": "1.0.0", // 同主版本,更早的中版本
|
||
"plugin_name": "oldminor",
|
||
"pid": os.Getpid(),
|
||
}})
|
||
continue
|
||
}
|
||
if req.ID != 0 {
|
||
send(response{ID: req.ID})
|
||
}
|
||
}
|
||
}
|