fix(input-helper): self-heal missing +x on packaged Swift binary (#32)#33
Open
mrz1880 wants to merge 1 commit into
Open
fix(input-helper): self-heal missing +x on packaged Swift binary (#32)#33mrz1880 wants to merge 1 commit into
mrz1880 wants to merge 1 commit into
Conversation
…botlab#32) npm pack normalizes file modes from the registry index, so dist/bin/input-helper ships as 0644 from npx installs even though the source tarball has +x. Every Swift-backed tool then surfaces a misleading "run pnpm run build:swift" error to end users who don't have a source tree or Xcode toolchain. Distinguish "binary missing" from "binary present but not executable" in runInputHelper, chmod 0o755 as a one-shot self-heal for the latter, and only fall back to a structured error if recovery fails. The new BINARY_NOT_EXECUTABLE message names the path and the chmod command; the reworded BINARY_NOT_FOUND points users at the right install step for npx vs. local-checkout consumers instead of pnpm run build:swift.
5436e88 to
c917886
Compare
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
Closes (partially) #32 — the runtime side of the fix discussed in that issue.
runInputHelperinstead of collapsing both intoBINARY_NOT_FOUND.chmod 0o755self-heal when the file exists without +x. This recovers the vast majority of broken installs in the wild today (npx cache,--ignore-scriptsconsumers, anything laid down before a publish-time fix lands) with zero user action.BINARY_NOT_EXECUTABLEincludes the actual path so the user knows exactly which file tochmod;BINARY_NOT_FOUNDno longer sends npx users topnpm run build:swift(a dead end without a source tree) and instead splits guidance for npx vs. local-checkout consumers.This is meant to complement, not replace, the publish-time
prepublishOnlymode-assertion proposed in the issue thread — that's still the right primary fix. The two together would protect future releases (prepublishOnly) while rescuing every cached install that already exists on disk today (this PR).What changed
src/helpers/input-helper.ts— newensureBinaryExecutable()helper:access(X_OK)first → fast path, unchanged behavior when everything is fine.access(F_OK)to disambiguate. Missing →BINARY_NOT_FOUNDwith path in the message.chmod(BINARY_PATH, 0o755)then re-check X_OK. Any failure in that sequence →BINARY_NOT_EXECUTABLEwith the path and the original error preserved ascause.src/constants.ts— addedERROR_MESSAGES.BINARY_NOT_EXECUTABLE; rewordedBINARY_NOT_FOUNDto be actionable for both install paths.src/__tests__/helpers/input-helper.test.ts— added two new tests:self-heals via chmod when binary exists but lacks +x(assertschmodis called with0o755and execution proceeds).throws BINARY_NOT_EXECUTABLE when binary exists but chmod fails(assertsexecFileis never invoked).Existing test for the missing-file path still covers
BINARY_NOT_FOUNDvia substring match on the message.CHANGELOG.md— entry under[Unreleased]linking to dist/bin/input-helper is published without executable bit — every Swift-backed tool fails with misleading "build:swift" error #32.Test plan
pnpm test— 184 tests pass (was 181; +3 for the new behavior).pnpm lint— clean.pnpm build— clean.npx -y mac-use-mcp@1.1.1, then verified that on this branch the first tool call (screenshot) succeeds without any manualchmod.Notes for reviewers
catchclause inensureBinaryExecutableis bare (no error binding) because the X_OK error gets superseded by either the F_OK error (missing file path) or the heal-attempt error (chmod path) — preserving the originally-caught error there would mask the more informative downstream cause. The lint rulepreserve-caught-erroris happy with this shape.BINARY_PATHis appended at the throw site rather than templated into the constant so the constants table stays a plainas constlookup (consistent with howTIMEOUTworks).access(X_OK)returns immediately and we proceed toexecFileexactly as before.