From 1c0f2da7ce768967d01f360aa339086b352d99d9 Mon Sep 17 00:00:00 2001 From: pluginslab <57633278+pluginslab@users.noreply.github.com> Date: Mon, 21 Sep 2026 17:45:44 +0100 Subject: [PATCH] test(cli): skip the node-dependent check when node is absent The deriveIdentity assertion shells out to `node -e` with the error swallowed by 2>/dev/null, so on a host without node it did not skip -- it failed, with a baffling `got ''`. CI never caught it because ubuntu-latest ships node. It only showed up running the suite in debian:bookworm-slim. That is precisely the "the test encodes the author's machine" trap that hid the Linux mtime bug in the hooks, reintroduced in a test written to guard against exactly that class of bug. It does not get a pass for being ours. Now guarded on node being installed, and says so when it skips. The dropped 2>/dev/null means a real node failure surfaces instead of masquerading as an empty string. macOS 145 passed. Linux without node: 144 passed, 1 correctly skipped. Co-Authored-By: Claude Opus 5 (1M context) --- tests/cli/test-substitutions.sh | 42 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/tests/cli/test-substitutions.sh b/tests/cli/test-substitutions.sh index 731db23..722c7ab 100755 --- a/tests/cli/test-substitutions.sh +++ b/tests/cli/test-substitutions.sh @@ -82,21 +82,33 @@ assert_file_contains "cli → classPrefix joins on underscore" "$CLI" ".join('_' # --- Case 4: deriveIdentity produces the expected forms --- # Exercise the real derivation rather than trusting the source reads right. # node evaluates the same expressions the CLI uses, for a representative slug. -derived=$(node -e ' - const slug = "acme-order-tracker"; - const cap = s => s[0].toUpperCase() + s.slice(1); - const parts = slug.split("-").filter(Boolean); - console.log([ - parts.map(cap).join(""), // namespace - parts.map(cap).join("_"), // classPrefix - slug.toUpperCase().replace(/-/g, "_"), - slug.replace(/-/g, "_"), - ].join(" ")); -' 2>/dev/null) - -assert_equals "deriveIdentity → all four forms for acme-order-tracker" \ - "AcmeOrderTracker Acme_Order_Tracker ACME_ORDER_TRACKER acme_order_tracker" \ - "$derived" +# +# Guarded on node being installed. The CLI is a Node program, so a host without +# node cannot run the scaffolder at all and has nothing to assert about it — +# but the rest of this file is plain bash and stays useful. Without the guard +# this failed with a baffling `got ''`, because the error was swallowed by a +# 2>/dev/null. That is the same "the test encodes the author's machine" trap +# that hid the Linux mtime bug in the hooks; it does not get a pass here just +# because it is our own test. +if command -v node >/dev/null 2>&1; then + derived=$(node -e ' + const slug = "acme-order-tracker"; + const cap = s => s[0].toUpperCase() + s.slice(1); + const parts = slug.split("-").filter(Boolean); + console.log([ + parts.map(cap).join(""), // namespace + parts.map(cap).join("_"), // classPrefix + slug.toUpperCase().replace(/-/g, "_"), + slug.replace(/-/g, "_"), + ].join(" ")); + ') + + assert_equals "deriveIdentity → all four forms for acme-order-tracker" \ + "AcmeOrderTracker Acme_Order_Tracker ACME_ORDER_TRACKER acme_order_tracker" \ + "$derived" +else + echo " - skipped: deriveIdentity check needs node on PATH" +fi # --- Case 5: the main plugin file gets renamed, not just rewritten --- # WordPress expects {slug}.php; leaving pl-example.php in place breaks the