fix test that was broken if sh points to dash#2436
Open
evgunter wants to merge 1 commit into
Open
Conversation
The _build_remote_lock_command tests ran `sh -n -c <cmd>` intending a no-exec syntax check, but dash (default /bin/sh on Debian/Ubuntu) ignores -n for -c scripts and executes them. The command's `mkdir -p /mngr/...` therefore ran and failed on an unprivileged or read-only /. Feed the script via stdin (`sh -n` with input=cmd), where dash honors -n and does a true no-exec syntax check. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
or could just ensure it doesn't use dash
Problem
libs/mngr/imbue/mngr/hosts/host_test.py'stest_build_remote_lock_command_*tests validated the generated remote lock command withsubprocess.run(["sh", "-n", "-c", cmd]), intending a no-exec syntax check.But dash ignores
-nwhen the script comes via-c(it only honors-nfor stdin/file input). Since/bin/sh-> dash on Debian/Ubuntu, the command actually ran, executing itsmkdir -p /mngr/.... This passed on CI (root, writable/) but failed locally on an unprivileged or read-only/withmkdir: cannot create directory '/mngr': Permission denied.Fix
Feed the script via stdin (
subprocess.run(["sh", "-n"], input=cmd, text=True, ...)), where dash honors-nand performs a genuine no-exec syntax check. Verified: dash executessh -n -c 'echo X'(prints X) but does not executeecho X | sh -n, while still catching syntax errors (rc 2).Latent test fragility, not a product bug.
🤖 Generated with Claude Code