已关闭
安装/升级层全面评审第一批(v0.14.2):atomgit-cli discovery 误判 P1 + 六项 P2 #601
aflyingto创建于  9月28日关闭于  9月28日
aflyingto成员
9月28日 创建

背景

v0.14.1 发布后对安装、升级、渠道冲突、自动升级四项能力做了四路独立全面评审(30+ 项沙箱实证)。核心健康面(事务安全、跨语言锁协议、凭证隔离、版本语义、0.12/0.13 兼容性)全部实测通过。本 issue 立项第一批修复(v0.14.2 范围):1 个 P1 + 6 个 P2,全部为局部小改、现场影响明确。第二批 P1/P2 与 P3 积压见后续 issue。

问题清单

  1. [P1] 推荐坐标 atomgit-cli 全局安装 discovery 误判 npm-local(npm/lib/install-metadata.js:151):pathAPI.resolve(packageRoot, "..", "..") 上溯两级只对 scoped 包(@gitcode-cli/cli 两段名)成立;非作用域坐标上溯两级得到 <prefix>/lib(Windows 为 %APPDATA%\npm),≠ npm root -g。触发链:updater 自身 npm install -g <坐标>@latest --ignore-scripts(update.js installExact)整体替换包目录删除旧元数据 → 下次运行走 discovery → 误判 npm-local → ① gc update 报 "automatic update requires a global npm install"(实际就是全局安装,自相矛盾)② 每日后台检查静默停摆(gc.js finishUpdateLifecycle 要求 distribution==="npm")③ 错误元数据 ensureInstallMetadata 写盘后 sticky(端到端实证)。修法:按直接父目录 basename 是否 @ 开头分派——scoped 上溯两级、非作用域上溯一级;补非作用域全局(Linux/Windows)与非作用域项目级用例(现有测试只覆盖 scoped)
  2. [P2] appendLog 失败把成功的更新改写为失败(npm/lib/update.js runUpdate 成功路径 / npm/lib/bootstrap-update-helper.js run() 成功路径):update.log 不可写(sudo 属主 0600、只读目录、路径被目录占据 EISDIR)时 writeJSON 成功而 appendFileSync 抛错落入 catch,成功 summary 被覆盖为 "Automatic update failed" 且前台 exit 1(沙箱实证)。修法:appendLog 改 best-effort(内部吞错,两渠道同步)
  3. [P2] notify 默认模式每日 "is current" 摘要噪声(两渠道成功路径对所有 status 无条件写 summary):后台检查 current 也生成 shown:false 摘要 → 用户每 24h 被打印一次 "GitCode CLI X is current."(真实用户日志佐证)。修法:status==="current" 不写摘要,并清除遗留的 pending available 摘要(避免陈旧提示)
  4. [P2] bootstrap helper 锁外读/无锁写状态(bootstrap-update-helper.js run() 锁前读 state、锁后写回陈旧快照;main() catch 完全无锁写):持锁窗口(检查最长 ~63s、安装最长 ~340s)内其他进程写入的 noticeShown/summary.shown 被陈旧快照回滚(实证:首启提示重放);他进程持锁期间失败路径仍改写 state(实证:pending 摘要被替换 + nextCheck 被推进)。修法:run() 获锁后重读 state 并只更新自有字段(lastChecked/nextCheck/summary);main() catch 先 acquireLock,取不到锁跳过状态写(仅 appendLog)
  5. [P2] StartDetached 未脱离终端会话(pkg/installupdate/lifecycle.go StartDetached 无 SysProcAttr):后台 helper 与发起 shell 同会话同前台进程组(实证 pgid=sid=shell 会话);安装期间关终端(SIGHUP)或 Ctrl+C(SIGINT 发前台组)导致 helper 及 npm 子树整树死亡。npm 渠道 wrapper 用 detached:true(setsid)正确,bootstrap 侧不对称。修法:Unix SysProcAttr{Setsid: true}、Windows CREATE_NEW_PROCESS_GROUP|DETACHED_PROCESS(build-tag 分文件,参照 pkg/config/securewrite_* 模式)
  6. [P2] npm 渠道 healthCheck 10s 预算未覆盖首跑 metadata 发现(npm/lib/update.js healthCheck spawnSync timeout 10000):--ignore-scripts 安装/更新后首跑 wrapper 需走 2×5s 的 npm root -g/npm prefix -g 发现 + node 启动 + Go 二进制启动,总时长可超 10s;慢机器(Windows 冷启动 + Defender)超时 → 假阴性回滚 → 回滚的 healthCheck 同样超时 → "rollback failed"(好更新被回滚)。修法:超时 10s → 30s
  7. [P2] alias 软链 loop 逃逸为裸 ELOOP(npm/lib/install.js isAllowedAliasSymlink 仅捕获 ENOENT/EINVAL):gitcode 别名自环/互环时 fs.statSync(dst) 抛 ELOOP 直接裸奔,绕过 "refusing non-regular install target" 可操作拒绝路径(实证)。修法:捕获列表加 ELOOP + 补 alias-loop 测试

验收标准

likedislike
Aaflyingto成员
9月28日 关联了pull request:fix(install,update): resilience batch 1 from the second full review
Aaflyingto成员
9月28日 添加了label:scope/installstatus/in-progress, type/bug
Aaflyingto成员
9月28日 关闭了 issue
Aaflyingto成员
9月28日 添加了label:status/merged;删除了label:status/in-progress