From ebada632593d54c859a0d12b557f5e68673e7bd4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 9 Jul 2026 15:58:41 -0700 Subject: [PATCH] [Tests] `aliases`: cover the regex-metachar cycle fix; clean up fixtures in teardown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cycle scenarios all pass with the old grep-based detection too; the bug the `case`-based detection actually fixes is resolved names interpolated into the grep pattern as regexes, where resolving axb -> a.b falsely reported ∞ because the pattern `a.b` matches the seen name `axb`. Pin both directions: the fixed false positive, and a genuine cycle through a metachar name. Also correct the space-name scenario comment (the old anchored grep passed that scenario; only token-delimited seen-storage would not), and register every new fixture name in the suite teardown, so a mid-test failure can not leak aliases into later tests. --- .../Aliases/nvm_resolve_alias handles cycles | 26 +++++++++++++++++-- test/fast/Aliases/teardown | 5 ++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/test/fast/Aliases/nvm_resolve_alias handles cycles b/test/fast/Aliases/nvm_resolve_alias handles cycles index 38567426..63f5bbea 100755 --- a/test/fast/Aliases/nvm_resolve_alias handles cycles +++ b/test/fast/Aliases/nvm_resolve_alias handles cycles @@ -38,8 +38,8 @@ EXPECTED='∞' rm -f '../../../alias/foo bar' '../../../alias/midway' # Non-cycle through an alias name containing a space. -# Token-based cycle detection would false-positive on this chain because -# 'bar' appears as a substring of the multi-token alias name 'foo bar'. +# Guards the newline-delimited SEEN_ALIASES storage: with space- or +# token-delimited storage, seen name 'foo bar' would falsely match 'bar'. # Resolves: 'foo bar' -> 'midway' -> 'bar' -> 0.0.99 echo 'midway' > '../../../alias/foo bar' echo 'bar' > '../../../alias/midway' @@ -50,3 +50,25 @@ EXPECTED='v0.0.99' [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}< for space-name chain, got >${ACTUAL}<" rm -f '../../../alias/foo bar' '../../../alias/midway' '../../../alias/bar' + +# Non-cycle through an alias name containing a regex metacharacter. +# Guards the literal `case` matching: the previous grep-based detection +# interpolated the resolved name into an anchored regex, so resolving 'axb' +# matched the seen name 'axb' against the pattern 'a.b' and falsely +# reported a cycle. +# Resolves: 'axb' -> 'a.b' -> 0.0.99 +echo 'a.b' > '../../../alias/axb' +echo '0.0.99' > '../../../alias/a.b' + +ACTUAL="$(nvm_resolve_alias axb)" +EXPECTED='v0.0.99' +[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}< for metachar-name chain, got >${ACTUAL}<" + +# ... while a genuine cycle through a metachar name is still detected +echo 'axb' > '../../../alias/a.b' + +ACTUAL="$(nvm_resolve_alias axb)" +EXPECTED='∞' +[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}< for metachar-name cycle, got >${ACTUAL}<" + +rm -f '../../../alias/axb' '../../../alias/a.b' diff --git a/test/fast/Aliases/teardown b/test/fast/Aliases/teardown index 08724ade..2795d8ed 100755 --- a/test/fast/Aliases/teardown +++ b/test/fast/Aliases/teardown @@ -17,3 +17,8 @@ rm -f "../../../alias/iojs" rm -f "../../../alias/default" rm -f "../../../alias/test-blank-lines" rm -f "../../../alias/test-multi-lines" +rm -f "../../../alias/test-edge-"* "../../../alias/test edge spaces" +rm -f "../../../alias/self" "../../../alias/link1" "../../../alias/link2" "../../../alias/link3" +rm -f "../../../alias/foo bar" "../../../alias/midway" "../../../alias/bar" +rm -f "../../../alias/hop1" "../../../alias/hop2" "../../../alias/hop3" "../../../alias/hop4" +rm -f "../../../alias/axb" "../../../alias/a.b"