Skip to content

fix: correct sed delimiter in GH_REPO_URL extraction (#63)#64

Merged
kurok merged 1 commit into
mainfrom
fix/issue-63-gh-repo-url-sed-delimiter
Jul 6, 2026
Merged

fix: correct sed delimiter in GH_REPO_URL extraction (#63)#64
kurok merged 1 commit into
mainfrom
fix/issue-63-gh-repo-url-sed-delimiter

Conversation

@kurok

@kurok kurok commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Fixes #63.

buildReusableUserData()'s per-boot registerScript extracted GH_REPO_URL with sed using # as the delimiter, while the GH_TOKEN and GH_LABEL extraction lines directly above it correctly use /. Because the sed pattern ends in the end-of-line anchor $ immediately followed by the # delimiter, and the whole sed argument sits inside a double-quoted shell string, bash expands $# (the special "number of positional arguments" parameter, always 0 for this script) before sed ever sees it. That corrupts the sed script into s#^GH_REPO_URL='\(.*\)'0\1#p, which errors with unterminated 's' command.

Since this is a plain GH_REPO_URL=$(...) assignment under set -euo pipefail (no || true guard), the sed failure aborts the whole registerScript at the configuring phone-home step — before config.sh is ever invoked. This is a 100% reproducible failure for every reuse: stop warm-pool launch.

Fix

Swap the delimiter to ,, which isn't a bash special-parameter suffix when preceded by $:

-'GH_REPO_URL=$(printf \'%s\\n\' "$UD" | sed -n "s#^GH_REPO_URL=\'\\(.*\\)\'$#\\1#p" | head -n1)',
+'GH_REPO_URL=$(printf \'%s\\n\' "$UD" | sed -n "s,^GH_REPO_URL=\'\\(.*\\)\'$,\\1,p" | head -n1)',

Verified against both BSD sed (macOS) and GNU sed semantics — this mirrors the exact root cause and fix from the issue writeup.

Test plan

  • Added a regression test in tests/warmpool.test.js that extracts the actual GH_REPO_URL=$(... sed ...) line out of the real generated user-data (not a reimplementation) and executes it in bash with a controlled fake IMDS user-data value.
  • Verified the new test fails against the old #-delimiter line (sed: unescaped newline inside substitute pattern, command exits non-zero under set -e).
  • Verified the new test passes against the fix (extracts https://github.com/foo/bar correctly).
  • Full suite: npm test — 227/227 passing (226 pre-existing + 1 new).
  • npm run lint — clean.
  • npm run package — rebuilt dist/index.js; confirmed the rebuild is deterministic (byte-identical across two consecutive runs) and the diff is scoped to the single fixed line.

buildReusableUserData()'s per-boot registerScript extracted GH_REPO_URL
with sed using "#" as the delimiter, while GH_TOKEN and GH_LABEL used
"/". Because the pattern ends in the sed end-of-line anchor "$"
immediately followed by "#", and the whole sed argument sits inside a
double-quoted shell string, bash expands "$#" (number of positional
arguments, always 0 for this script) before sed ever runs. That
corrupts the sed script and makes it error out with "unterminated 's'
command". Since the assignment isn't guarded with `|| true` and the
script runs under `set -euo pipefail`, the failure aborted the whole
registerScript at the "configuring" phone-home step, so every
`reuse: stop` warm-pool launch failed registration before config.sh
was ever invoked.

Switch the delimiter to "," which isn't a bash special-parameter
suffix, matching the fix verified in the issue against both BSD and
GNU sed.

Adds a regression test that extracts the real GH_REPO_URL sed line out
of the generated user-data and executes it in bash, so it fails
against the old "#" delimiter and passes with the fix.

Fixes #63

Signed-off-by: kurok <22548029+kurok@users.noreply.github.com>
@kurok kurok merged commit 301e1c1 into main Jul 6, 2026
5 checks passed
@kurok kurok deleted the fix/issue-63-gh-repo-url-sed-delimiter branch July 6, 2026 15:07
kurok added a commit to namecheap/terraform-provider-namecheap that referenced this pull request Jul 6, 2026
The previous re-pin (aa10310) got us the #62 phone-home fix, which then
revealed the real blocker: buildReusableUserData()'s GH_REPO_URL
extraction used '#' as its sed delimiter, but '$#' inside the
double-quoted sed script is bash's positional-argument-count special
parameter, which silently corrupts the pattern before sed ever sees it
(confirmed via bash -x tracing and reproduced against both BSD and GNU
sed). Every reuse:stop registration failed at the configuring step as a
result. Fixed upstream in namecheap/ec2-github-runner#64 (fixes #63),
merged as 301e1c1, v4.0.0 moved to match. Re-pinning this PR's 4 usages
to that commit.

Signed-off-by: kurok <22548029+kurok@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

buildReusableUserData(): $# collides with sed delimiter in GH_REPO_URL extraction, breaks all reuse:stop registrations

1 participant