From 7400debd7a586e7fd3c24e9119ce842cc16e5085 Mon Sep 17 00:00:00 2001 From: Mike Wallio Date: Fri, 18 Sep 2026 10:18:35 -0400 Subject: [PATCH] Add pn artifact helper shim Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/artifacts-helper/devcontainer-feature.json | 2 +- src/artifacts-helper/install.sh | 1 + src/artifacts-helper/scripts/pn | 15 +++++++++++++++ test/artifacts-helper/test_shim_integration.sh | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 src/artifacts-helper/scripts/pn diff --git a/src/artifacts-helper/devcontainer-feature.json b/src/artifacts-helper/devcontainer-feature.json index 161ba86..658967b 100644 --- a/src/artifacts-helper/devcontainer-feature.json +++ b/src/artifacts-helper/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Azure Artifacts Credential Helper", "id": "artifacts-helper", - "version": "3.1.1", + "version": "3.1.2", "description": "Configures Codespace to authenticate with Azure Artifact feeds", "options": { "nugetURIPrefixes": { diff --git a/src/artifacts-helper/install.sh b/src/artifacts-helper/install.sh index a5e7c00..45ac3a1 100755 --- a/src/artifacts-helper/install.sh +++ b/src/artifacts-helper/install.sh @@ -38,6 +38,7 @@ if [ "${ALIAS_RUSH}" = "true" ]; then ALIASES_ARR+=('rush-pnpm') fi if [ "${ALIAS_PNPM}" = "true" ]; then + ALIASES_ARR+=('pn') ALIASES_ARR+=('pnpm') ALIASES_ARR+=('pnpx') fi diff --git a/src/artifacts-helper/scripts/pn b/src/artifacts-helper/scripts/pn new file mode 100755 index 0000000..2da016c --- /dev/null +++ b/src/artifacts-helper/scripts/pn @@ -0,0 +1,15 @@ +#!/bin/bash + +# If ACTIONS_ID_TOKEN_REQUEST_URL is set, we're in GitHub Actions - skip Azure DevOps setup +if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]; then + source "$(dirname $0)"/resolve-shim.sh + PN_EXE="$(resolve_shim)" + "${PN_EXE}" "$@" + exit $? +fi + +source "$(dirname $0)"/auth-ado.sh +source "$(dirname $0)"/resolve-shim.sh + +PN_EXE="$(resolve_shim)" +ARTIFACTS_ACCESSTOKEN="${ARTIFACTS_ACCESSTOKEN:-}" ${PN_EXE} "$@" diff --git a/test/artifacts-helper/test_shim_integration.sh b/test/artifacts-helper/test_shim_integration.sh index 82d5366..4bde842 100755 --- a/test/artifacts-helper/test_shim_integration.sh +++ b/test/artifacts-helper/test_shim_integration.sh @@ -20,6 +20,7 @@ check "dotnet shim handles missing auth helper" bash -c ' # Test that the shim scripts properly source auth-ado.sh check "dotnet shim sources auth-ado.sh" grep -q "source.*auth-ado.sh" /usr/local/share/codespace-shims/dotnet check "npm shim sources auth-ado.sh" grep -q "source.*auth-ado.sh" /usr/local/share/codespace-shims/npm +check "pn shim sources auth-ado.sh" grep -q "source.*auth-ado.sh" /usr/local/share/codespace-shims/pn check "corepack shim sources auth-ado.sh" grep -q "source.*auth-ado.sh" /usr/local/share/codespace-shims/corepack # Verify the shim directory is in PATH @@ -27,6 +28,7 @@ check "shim directory in PATH" bash -c '[[ ":$PATH:" == *":/usr/local/share/code # Verify that shell function shims are written to rc files (not just shim scripts) check "npm shell function written to bash.bashrc" grep -q "npm()" /etc/bash.bashrc +check "pn shell function written to bash.bashrc" grep -q "pn()" /etc/bash.bashrc check "corepack shell function written to bash.bashrc" grep -q "corepack()" /etc/bash.bashrc check "dotnet shell function written to bash.bashrc" grep -q "dotnet()" /etc/bash.bashrc check "npm shell function on its own line in bash.bashrc" grep -q "^npm()" /etc/bash.bashrc @@ -34,8 +36,23 @@ check "npm shell function on its own line in bash.bashrc" grep -q "^npm()" /etc/ # Verify aliases include proper quoting and argument passing ($@) check "dotnet alias has quoted path and passes args" grep -q 'dotnet() { ".*/dotnet" "\$@"; }' /etc/bash.bashrc check "npm alias has quoted path and passes args" grep -q 'npm() { ".*/npm" "\$@"; }' /etc/bash.bashrc +check "pn alias has quoted path and passes args" grep -q 'pn() { ".*/pn" "\$@"; }' /etc/bash.bashrc check "corepack alias has quoted path and passes args" grep -q 'corepack() { ".*/corepack" "\$@"; }' /etc/bash.bashrc +check "pn shim delegates to the underlying pn command" bash -c ' + TEST_DIR=$(mktemp -d) + trap "rm -rf \"$TEST_DIR\"" EXIT + mkdir -p "$TEST_DIR/bin" + printf "#!/bin/bash\nprintf \"%%s\\n\" \"\$@\" > \"%s/args\"\n" "$TEST_DIR" > "$TEST_DIR/bin/pn" + chmod +x "$TEST_DIR/bin/pn" + + PATH="/usr/local/share/codespace-shims:$TEST_DIR/bin:/usr/bin:/bin" \ + ACTIONS_ID_TOKEN_REQUEST_URL=test \ + /usr/local/share/codespace-shims/pn install --frozen-lockfile + + diff -u <(printf "install\n--frozen-lockfile\n") "$TEST_DIR/args" +' + # Verify Corepack lifecycle commands target the real binary directory rather than the shim directory. check "corepack enable targets the real binary directory" bash -c ' TEST_DIR=$(mktemp -d)