Repository navigation
v0.4.2
CLI 现在能指定账号了,顺带修掉一个**"看着成功却什么都没干"。
第一条来自 0.4.1 体检时记进「已知空缺」的那条;第二条是补它的时候旁边挖出来的**,而且更糟。
新增功能
- CLI 支持
--account <别名>:目标团队不属于默认账号时给上它。
parseArgv早就把--account解析出来了,但 16 个命令里一个都没往下传(实测改动前 0 个、改动后 13 个)——
于是它们永远走默认账号。现在 13 个命令 / 15 个调用点透传。 - 三个命令不需要它,并且写了理由:
who(职责就是跨账号判定)、accounts(用--alias指定"操作哪个账号",
与"用哪个身份"语义不同)、log(纯本地不走网络)。
体验优化
USAGE写清账号优先级:--cookie>LANHU_COOKIE>--account> 默认账号 ——
也就是显式 cookie 与环境变量会盖过--account。这是在resolveCookie里挖到的,不写出来就是静默意外。docs/CLI与开发.md补了--account与真实例子(那条30005)。
问题修复
--account传下去也没用 → 现在真的有用:示例团队属demo、默认账号是default-acct→
search/projects报code=30005 用户或团队不存在,而同样的入参用工具就正常。
假账号 → 明确报错并列出已知账号,退出码 1,不静默回退默认账号。search的人读输出会丢结果(更糟的一条):cmdSearch原先只遍历r.images,
于是"命中的是 PRD / 项目而不是稿"的搜索变成零输出 + 退出码 0 ——
即本项目最忌讳的**"看着跑成功但什么都没干"。
实测搜「某大屏」命中 2 条 PRD / 0 张稿 → 人读路径什么都不打,而--json里prds:2(数据明明在,只是不打)。
现在三类结果都打** + 一行汇总;三类全空时也明说"没有匹配"。
(工具侧lanhu_search本来就会打 PRD —— 这个 bug 是 CLI 独有的。)
渲染抽成纯函数searchLines(),5 条断言直接测它的四态(含"只有 PRD"这条回归)。
其他变更
- 新增通用绊线:每个走网络的
cmdXxx都必须把args.account传给它调的核心函数 ——
源码区间 + 字符串感知扫描,带显式白名单。
工具链早就有"参数声明了但没传"的守卫,CLI 没有 —— 这个缺口正是从那道缝里活下来的。 - 写这条守卫时踩了两个"假绿",都被自己的守卫抓住:
① 括号配平从参数表的{就开始数→( args, cookie )一闭合就返回(只拿到 **41** 字符)→ **所有命令被当成"不走网络"**(是"确实检查到了、不是空跑"那条断言判红的); ② 补完后扫描名单**漏了whoIsIt/buildAccountIndex` → 白名单成了摆设(清空白名单 0 条红,是变异测试抓出来的)。
补全后清空白名单报 2 条红。 - 自检 569 → 611 项;变异测试:删掉
search的 PRD 打印 → 红 1 条;清空白名单 → 红 2 条。
Full Changelog: v0.4.1...v0.4.2
New Features
- The CLI accepts
--account <alias>: pass it whenever the target team does not belong to the default account.
parseArgvhad been parsing--accountall along, but not one of the 16 commands passed it on (measured:
0 before, 13 after) — so they always used the default account. Now 13 commands / 15 call sites forward it. - Three commands do not need it, each with a stated reason:
who(its whole job is cross-account detection),
accounts(uses--aliasto pick which account to operate on, a different question from which identity to use),
andlog(purely local, no network).
Improvements
USAGEnow documents the account precedence:--cookie>LANHU_COOKIE>--account> default account —
i.e. an explicit cookie or the environment variable overrides--account. This was dug out ofresolveCookie;
undocumented it would be a silent surprise.docs/CLI与开发.mdgained--accountand a real example (the30005case).
Bug Fixes
--accountbeing accepted but ignored: the demo team belongs to accountdemowhile the default is
default-acct, sosearch/projectsreturnedcode=30005— while the same inputs through a tool worked fine.
An unknown alias now fails loudly and lists the known accounts with exit code 1 — no silent fallback.searchdropped results in its human-readable output (the worse one):cmdSearchiterated onlyr.images,
so a search whose hits are PRDs or projects produced no output at all with exit code 0 — exactly the
"looks successful but did nothing" failure this project fights.
Measured: searching 「某大屏」 hits 2 PRDs / 0 artboards → the human path printed nothing while--jsonshowed
prds:2(the data was there, it just was not printed). Now all three kinds are printed plus a summary line,
and an all-empty result says so explicitly.
(The toollanhu_searchalready printed PRDs — this bug was CLI-only.)
The rendering was extracted into a pure functionsearchLines(), covered by 5 assertions over its four states
(including the "PRDs only" regression).
Chores
- New general tripwire: every network-going
cmdXxxmust passargs.accountto the core function it calls —
a source-region scan that is string-aware, with an explicit allowlist.
The tool layer already had a "declared but not forwarded" guard; the CLI did not — and this gap is what survived
in that seam. - Two false-greens were hit while writing that guard, and its own assertions caught both:
① the brace matcher started counting from the{of the parameter list, so( args, cookie )closed it immediately
(41 characters captured) → every command looked like it did not touch the network (caught by the
"this check really ran, it is not a no-op" assertion); ② after fixing that, the scan list missed
whoIsIt/buildAccountIndex→ the allowlist became decorative (clearing the allowlist turned 0 red — caught by
mutation testing). With both fixed, clearing the allowlist turns 2 red. - Self-check 569 → 611 assertions; mutations: removing
search's PRD printing → 1 red; clearing the allowlist → 2 red.
Full Changelog: v0.4.1...v0.4.2