fix(portability): a bare $var before a non-ASCII byte breaks the installer on macOS's bash 3.2 - #59
Open
JasonJarvan wants to merge 1 commit into
Open
fix(portability): a bare $var before a non-ASCII byte breaks the installer on macOS's bash 3.2#59JasonJarvan wants to merge 1 commit into
JasonJarvan wants to merge 1 commit into
Conversation
…aller on macOS's bash 3.2
macOS 自带 /bin/bash 是 3.2.57(许可证原因,Apple 不升级)。bash 3.2 解析变量名时
**不认多字节字符**:
name=ok; set -u; echo "x $name:y" # 全角冒号 = EF BC 9A
bash 3.2 → line 3: name<EF>: unbound variable ← 0xEF 被并入变量名
bash 5 → x ok:y
`set -u` 之下是硬失败。实测后果:**adopt.sh 在 macOS 上 rc=1 ⇒ adopter 装不上这套
harness**;仓内 12 个测试在 setUpClass 就炸。
根因不是缺 bash4 特性(`declare -A` / `mapfile` / `${x,,}` 实测命中均为 0),所以修法是
加花括号,不是加版本门。
**它当时伪装成了别的东西**:测试用 subprocess(text=True) 去解码那个坏字节,失败呈现为
`UnicodeDecodeError` —— 看起来像测试框架的编码问题,真实缺陷是安装器炸了。这是「取证命令
的三种伪装」里第三种(数据在通往解析器的路上被改写)的又一实例。
回归门 tests/test_shell_multibyte_portability.py:
- 形态式判据,不枚举变量名也不枚举字符:凡 `$identifier` 紧跟非 ASCII 字节即拒;
- 开火构造 + 「加了花括号就不该命中」的反向构造;
- **因果层**:在 bash 3.x 上实证「裸形式 unbound variable、花括号形式 rc=0」;bash>=4 上
跳过并说明理由(前提在那里本就不成立,强行断言只会得到假绿);
- 覆盖自检:必须扫到 adopt.sh 与 harness_worktree_link.sh,否则「一个文件都没扫到」会假绿。
**门一上线就抓到我漏的 2 处**:我最初统计用手列 glob(overlay/** scripts/**)得出 13 处,
漏了 skills/;门走整棵树,得出 **15 处**。⇒ 又一次「枚举式弱于形态式」的实例,而这次弱的
是我的统计口径。
读数:红 8F+12E → **6F+0E**。12 个 error 全消;另 2 个 failure 是变异层护栏,基线转绿后
自动通过(护栏双向都在正常工作)。剩 6 处是 macOS `/var`→`/private/var` 符号链接族,另账。
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.
症状:安装器在 macOS 上装不上
macOS 自带
/bin/bash是 3.2.57(许可证原因,Apple 不升级)。bash 3.2 解析变量名时不认多字节字符:set -u之下是硬失败。实测后果:adopt.sh在 macOS 上 rc=1 ⇒ adopter 装不上这套 harness。 仓内 12 个测试在setUpClass就炸。根因不是缺 bash4 特性 ——
declare -A/mapfile/${x,,}实测命中均为 0。所以修法是加花括号,不是加版本门:版本门只会把「装不上」换成「明确拒绝装」,而这条其实能在 3.2 上正常工作。它伪装成了别的东西
测试用
subprocess(..., text=True)去解码 bash 吐的那个坏字节,于是失败呈现为UnicodeDecodeError—— 看起来像测试框架的编码问题,而真实缺陷是安装器炸了。这是 guide 里「取证命令的三种伪装」中第三种(数据在通往解析器的路上被改写)的又一个实例。回归门
tests/test_shell_multibyte_portability.py$identifier紧跟一个非 ASCII 字节即拒。$var后跟 ASCII 不该命中)。unbound variable、花括号形式 rc=0」。bash≥4 上跳过并说明理由 —— 前提在那里本就不成立,强行断言只会得到一条假绿。adopt.sh与harness_worktree_link.sh,否则「一个文件都没扫到」会假绿。为什么必须由门守:写中文输出的仓,每写一行
echo "…$var:…"都在重新引入它,而 CI 若跑在 bash 5 上永远不会报。正确写法与错误写法一样省事,错误只在别人机器上炸。门一上线就抓到我漏的 2 处
我最初统计用手列 glob(
overlay/**scripts/**)得出 13 处,漏了skills/;门走整棵树,得出 15 处(adopt.sh8 /harness_worktree_link.sh5 /skills/arborist-sync/sync.sh2)。⇒ 又一次「枚举式弱于形态式」,而这次弱的是我的统计口径。
读数
test_the_unmutated_tree_is_green_for_the_same_tests/test_removing_each_gate_turns_one_of_its_tests_red),基线转绿后自动通过 —— 护栏双向都在正常工作。/var→/private/var符号链接族(测试夹具拿未归一化路径比产品的 realpath 归一化值),另账,不在本 PR 范围。🤖 Generated with Claude Code