diff --git a/src/resources/asdf/asdf.ts b/src/resources/asdf/asdf.ts index 0e14f2d6..d1342607 100644 --- a/src/resources/asdf/asdf.ts +++ b/src/resources/asdf/asdf.ts @@ -92,7 +92,14 @@ export class AsdfResource extends Resource { await CoreUtils.installViaPkgMgr('curl'); } - const { data: latestVersion } = await $.spawn('curl -s https://api.github.com/repos/asdf-vm/asdf/releases/latest | grep \'"tag_name":\' | sed -E \'s/.*"([^"]+)".*/\\1/\''); + // Extract latest version from GitHub's /releases/latest redirect — avoids API rate limits + const { data: locationData } = await $.spawn( + "curl -sI https://github.com/asdf-vm/asdf/releases/latest | grep -i 'location:' | sed 's|.*/tag/||' | tr -d '\\r\\n'" + ); + const latestVersion = locationData.trim(); + if (!latestVersion) { + throw new Error('Failed to determine the latest asdf version from GitHub. Check network connectivity.'); + } // Create .asdf directory if it doesn't exist const asdfDir = path.join(os.homedir(), '.local', 'bin'); diff --git a/test/asdf/asdf-install.test.ts b/test/asdf/asdf-install.test.ts index 52909c18..2a0c17e2 100644 --- a/test/asdf/asdf-install.test.ts +++ b/test/asdf/asdf-install.test.ts @@ -34,7 +34,8 @@ describe('Asdf install tests', async () => { validateDestroy: async () => { expect(await testSpawn('which asdf')).toMatchObject({ status: SpawnStatus.ERROR }); expect(await testSpawn('which deno')).toMatchObject({ status: SpawnStatus.ERROR }); - expect(await testSpawn('which go')).toMatchObject({ status: SpawnStatus.ERROR }); + // Check the asdf shim is gone rather than `which go` — system Go may be pre-installed on the runner + expect(await testSpawn('test -f ~/.asdf/shims/go')).toMatchObject({ status: SpawnStatus.ERROR }); } }); @@ -59,7 +60,8 @@ describe('Asdf install tests', async () => { }, validateDestroy: async () => { expect(await testSpawn('which asdf')).toMatchObject({ status: SpawnStatus.ERROR }); - expect(await testSpawn('which go')).toMatchObject({ status: SpawnStatus.ERROR }); + // Check the asdf shim is gone rather than `which go` — system Go may be pre-installed on the runner + expect(await testSpawn('test -f ~/.asdf/shims/go')).toMatchObject({ status: SpawnStatus.ERROR }); } }); })