fix(careful): BSD sed compatibility for safe exception detection on macOS#1242
Open
ToraDady wants to merge 1 commit intogarrytan:mainfrom
Open
fix(careful): BSD sed compatibility for safe exception detection on macOS#1242ToraDady wants to merge 1 commit intogarrytan:mainfrom
ToraDady wants to merge 1 commit intogarrytan:mainfrom
Conversation
…acOS
The sed regex in check-careful.sh uses \s+, which is a GNU sed
extension not supported by BSD sed (macOS default). On macOS, this
causes the RM_ARGS strip to fail silently, making rm -rf of safe
exceptions (node_modules, .next, dist, etc.) trigger the destructive
warning instead of being permitted as designed.
Fix: replace \s+ with POSIX [[:space:]]+, which works on both GNU sed
(Linux) and BSD sed (macOS).
The existing test/hook-scripts.test.ts already documented this
limitation via a detectSafeRmWorks() helper and a platform-conditional
assertion ("if GNU sed: expect undefined, else: expect ask"). Now that
the regex works on both platforms, this dead path is removed and the
safe-exception tests assert the same expectation on every OS.
Note: the grep regex in the same file also uses \s+, but BSD grep -E
on macOS does support \s (verified via bash -x trace), so only the
sed expression needs the fix.
Discovered while translating the careful skill for a Japanese
derivative project (uzustack). Reference:
uzumaki-inc/uzustack@bc67c8d
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.
Summary
careful/bin/check-careful.shuses\s+in its sed regex, which is a GNU sed extension not supported by BSD sed (the default on macOS). On macOS this causes the safe-exception detection to fail silently, so even safe commands likerm -rf node_modulestrigger the destructive warning instead of being permitted as designed.Replacing
\s+with the POSIX[[:space:]]+makes the expression work correctly on both GNU sed (Linux) and BSD sed (macOS).Reproduction (on macOS)
bash -xtracing confirmed thatsed -E 's/.*rm\s+(-[a-zA-Z]+\s+)*//'does not strip anything on macOS BSD sed.Fix
Note: the
grep -qEline in the same file also uses\s+, but BSD grep on macOS does support\s(verified viabash -xtrace), so only the sed expression needs the fix.Test cleanup
test/hook-scripts.test.tsalready documented this limitation with adetectSafeRmWorks()helper and a platform-conditional assertion (`if GNU sed: expect undefined, else: expect ask`). Now that the regex works on both platforms, this dead path is removed and the safe-exception tests assert the same expectation on every OS.Net diff: 3 insertions(+), 21 deletions(-) across the two files.
Test plan
After applying the fix, verified on macOS:
`bun test test/hook-scripts.test.ts` → 32 pass, 0 fail. Full `bun test` shows the same 6 pre-existing failures on `main` (all in `browse/test/server-auth.test.ts`, `integration smoke`, `gstack-gbrain-lib.sh`) — unrelated to this change.
Discovery
I found this while translating gstack's careful skill into Japanese for a derivative project (uzustack — https://github.com/uzumaki-inc/uzustack). During integration testing on macOS, the safe exception logic appeared broken, and `bash -x` tracing revealed the BSD sed compatibility issue.
Reference: same fix applied in uzustack at uzumaki-inc/uzustack@bc67c8d