fix(lc): lc code 在 registry 没有默认上游时说人话,不吐 subprocess traceback - #48
Merged
Conversation
registry 里 default 是 null 时(`lc rm` 掉最后一个上游就会到这个状态), `cmd_code` 把 None 直接塞进 subprocess.call 的参数列表,用户看到的是 `TypeError: expected str, bytes or os.PathLike object, not NoneType` 和一段 CPython 内部的栈,完全看不出根因是「没有默认上游」。 #12 第三梯队给 test / e2e 修过同一个形态(`_targets()`),code 漏了。 `_targets()` 不能直接复用——它把 argv 当上游名解析,而 `lc code` 的 argv 是要透传给 Codex 的参数。所以抽了一个只取默认值的 `_default_target()`, 两条失败路径的措辞和 `_targets()` 保持一致。 顺带挡下第三条:default 指向一个已经不存在的上游(手改 registry 之后)。 它不会炸,但更坏——Codex 对不存在的 profile 是静默回落到默认 model 的。 Closes #47 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #47
问题
registry.json里default是null、且网关活着时跑lc code:cmd_code把reg.get("default")的None直接塞进了subprocess.call的参数列表,用户看到的是一段 CPython 内部的栈,看不出根因是「没有默认上游」。
这个状态不难到达:
lc rm掉最后一个上游时cmd_rm会把default置回None,而网关还在跑着。网关没起时被
die("网关没起来")提前短路,所以这条只在「网关正常 + registry 没有默认上游」时暴露。
#12 第三梯队给
lc test/lc e2e修过同一个形态(_targets()的 docstring 里写着这段历史),
lc code不走那条路,于是漏了。改了什么
bin/lc— 新增_default_target(reg),cmd_code用它取 profile。不直接复用
_targets():那个函数把 argv 当上游名解析,而lc code的 argv 是要原样透传给 Codex 的参数(
--sandbox read-only之类)。失败措辞与_targets()对齐——空注册表指向
lc init,有上游但没选默认指向lc use <name>并列出可用的。按 issue 里「顺带扫一遍同类」,多挡下一条:
default指向一个已经不存在的上游(手改 registry 之后)。它不会炸,但后果更坏——Codex 对不存在的 profile 是
静默回落到默认 model 的,表现成「以为在用 A 其实在用 B」,正是本项目在别处
一直当作缺陷处理的那个形态。
扫过的其它读
default的地方:cmd_e2e走_targets(),已经干净;gen_codex在
default为None时回落到排序后的第一个上游,只影响生成配置里的顶层model =,不会传进 subprocess,行为可接受,未改动。scripts/test-lc-commands.sh— 新增[6f]/[6g](网关桩此时还活着,正是这条 bug 的先决条件)。
CI 覆盖
ci.yml已经在跑bash scripts/test-lc-commands.sh(static job),断言随脚本一起进 CI,不需要改
.github/。新增断言:
default: nullTraceback/ 无TypeError/ 说「没有默认上游」/ 指向lc use <name>/ 列出alpha, beta/ 压根没启动 Codexdefault: "ghost"默认上游 'ghost' 不在 registry 里/ 没拿不存在的 profile 去启动 Codexupstreams: {}lc init、且不建议lc use「无
TypeError」和「压根没启动 Codex」是这条 issue 真正的不变量——只查「非零退出」的话,一段 traceback 也能让它绿。
验证
把
cmd_code那一行改回profile = reg.get("default"),新增断言 9 条变红(含
argv=--profile ghost那条,证明失效 default 确实会带着不存在的 profile启动 Codex);改回来后全绿。
本地跑过(无 GPU / 无模型 / 无 API Key):
python3 -m py_compile bin/lc scripts/*.pybash -n scripts/*.sh docker/entrypoint.shpython3 bin/lc --helpbash scripts/test-lc-commands.sh→ 全部通过test-lc-secrets.sh/test-export.sh/test-version.sh/test-doctor-probe.sh/test-entrypoint.sh/test-codex-review-script.sh/test-project-metadata.py→ 全部通过🤖 Generated with Claude Code