Skip to content

Fix integration tests for asdf-managed yarn#549

Merged
sorenlouv merged 2 commits intosorenlouv:mainfrom
kapral18:fix-postinstall-test-asdf
Nov 7, 2025
Merged

Fix integration tests for asdf-managed yarn#549
sorenlouv merged 2 commits intosorenlouv:mainfrom
kapral18:fix-postinstall-test-asdf

Conversation

@kapral18
Copy link
Copy Markdown
Contributor

@kapral18 kapral18 commented Oct 11, 2025

Summary

Fixes integration tests that fail when yarn is managed by asdf, suppressing "/bin/sh: asdf: command not found" errors when HOME is overridden.

Problem

Integration tests override HOME to test config file creation in isolated directories. When yarn is managed by asdf, the yarn command resolves to a shell shim at ~/.asdf/shims/yarn that executes asdf exec yarn. When HOME is overridden, the shim can't find asdf in PATH and fails with "/bin/sh: asdf: command not found".

Solution

Extract yarn command resolution into a shared helper that bypasses the asdf shim by:

  1. Finding the actual asdf binary using which asdf + realpath
  2. Using asdf which yarn to get the actual yarn binary path
  3. Using that direct binary path instead of the shim wrapper

Changes

  • Created shared getYarnCommand() helper in src/test/integration-test-helpers.ts
  • Updated postinstall.integration.test.ts and binary.integration.test.ts to use helper
  • Uses dynamic which asdf detection instead of hardcoded paths

Benefits

  • Suppresses "/bin/sh: asdf: command not found" errors
  • Works with any asdf installation method
  • Falls back to 'yarn' in non-asdf environments
  • Reusable helper for future integration tests

@kapral18 kapral18 force-pushed the fix-postinstall-test-asdf branch 2 times, most recently from ebf983c to 02fa2d0 Compare October 11, 2025 13:22
@sorenlouv
Copy link
Copy Markdown
Owner

When running the test yarn test postinstall.integration.test I see the error "/bin/sh: asdf: command not found" in the output. Can you suppress this?

yarn run v1.22.22
$ jest postinstall.integration.test
/bin/sh: asdf: command not found
/bin/sh: asdf: command not found
 PASS  src/scripts/postinstall.integration.test.ts (13.481 s)
  postinstall (integration)
    ✓ creates ~/.backport/config.json (3 ms)
    ✓ does not overwrite existing config file (5534 ms)
    ✓ creates config with the expected template content (1 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        13.829 s, estimated 24 s

@kapral18
Copy link
Copy Markdown
Contributor Author

kapral18 commented Oct 30, 2025

When running the test yarn test postinstall.integration.test I see the error "/bin/sh: asdf: command not found" in the output. Can you suppress this?

yarn run v1.22.22
$ jest postinstall.integration.test
/bin/sh: asdf: command not found
/bin/sh: asdf: command not found
 PASS  src/scripts/postinstall.integration.test.ts (13.481 s)
  postinstall (integration)
    ✓ creates ~/.backport/config.json (3 ms)
    ✓ does not overwrite existing config file (5534 ms)
    ✓ creates config with the expected template content (1 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        13.829 s, estimated 24 s

@sorenlouv Done changed the approach

@kapral18 kapral18 changed the title Fix postinstall integration test for asdf-managed yarn Fix integration tests for asdf-managed yarn Oct 30, 2025
The postinstall integration test was failing with exit code 126 when
yarn is managed by asdf. This occurs because the test overrides the
HOME environment variable, which breaks the asdf shim's ability to
locate its configuration and execute.

The issue is specific to development environments using asdf to manage
tool versions. In these environments, 'yarn' is typically a shell shim
at ~/.asdf/shims/yarn that requires the original HOME to function.

Solution:
- Detect if yarn is managed by asdf using 'asdf which yarn'
- Use the actual yarn binary path instead of the shim
- Use 'shell: /bin/bash' to ensure proper HOME variable handling
- Falls back to 'yarn' from PATH if asdf is not available

This fix ensures the test works in both asdf and non-asdf environments.
Refactor yarn command resolution into shared helper that uses 'asdf which yarn'
to get the actual binary path instead of the shim. This suppresses the
'/bin/sh: asdf: command not found' error when HOME is overridden in tests.

- Extract getYarnCommand() helper to shared integration-test-helpers.ts
- Use 'which asdf' + realpath to find actual asdf binary
- Use 'asdf which yarn' to resolve actual yarn binary path
- Apply helper to all yarn commands in both integration test files
@kapral18 kapral18 force-pushed the fix-postinstall-test-asdf branch from 526e017 to f5ef903 Compare October 30, 2025 23:34
@sorenlouv sorenlouv merged commit 47c7ff3 into sorenlouv:main Nov 7, 2025
2 of 3 checks passed
@kapral18 kapral18 deleted the fix-postinstall-test-asdf branch November 17, 2025 20:17
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.

2 participants