Commit a927695
authored
fix(interpreter): populate BASH_SOURCE[0] for PATH-resolved scripts (#1087)
## Summary
- When a script is executed via PATH lookup (by name, not by path),
`BASH_SOURCE[0]` was empty because only the bare command name was passed
to `execute_script_content()` instead of the resolved path
- Fixed `try_execute_script_via_path_search()` to pass the fully
resolved `candidate` path
- Added 2 new tests: direct BASH_SOURCE check and source-guard pattern
via PATH lookup
## What changed
In `try_execute_script_via_path_search()`, the code already resolves the
full path (`candidate = PathBuf::from(dir).join(name)`) but was
discarding it when calling `execute_script_content(name, ...)`. Now
passes `&candidate.to_string_lossy()` instead.
## Test plan
- [x] `bash_source_set_via_path_lookup` — verifies BASH_SOURCE[0] equals
`/scripts/test.sh` when run by name via PATH
- [x] `bash_source_guard_via_path_lookup` — verifies source-guard
pattern (`BASH_SOURCE[0] == $0`) works correctly via PATH
- [x] All existing bash_source tests still pass (6/6)
- [x] Full test suite green (2700+ tests)
- [x] `cargo fmt --check` clean
- [x] `cargo clippy -- -D warnings` clean
Closes #10851 parent 0f63b7b commit a927695
2 files changed
Lines changed: 50 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4151 | 4151 | | |
4152 | 4152 | | |
4153 | 4153 | | |
| 4154 | + | |
4154 | 4155 | | |
4155 | | - | |
| 4156 | + | |
4156 | 4157 | | |
4157 | 4158 | | |
4158 | 4159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
53 | 101 | | |
54 | 102 | | |
55 | 103 | | |
| |||
0 commit comments