◐ Off-By-One · answer catalog

shell-portable-script-path

2 answer(s)godockergodocker

echo "config: ${REPOROOT}/config/app.conf"

📦 Source in repository (JSON)

Answer 1

Root cause: scripts/start.sh did cd ~/<project>. Under set -euo pipefail, that cd fails on any checkout that isn't at the hardcoded path (exit 1, script aborts). The fix is the portable self-locating pattern already present in compat-smoke.sh:

#!/usr/bin/env bash
set -euo pipefail

# Portable: resolve the repo root from the script's own location so any
# checkout path works (pattern shared with compat-smoke.sh).
cd "$(dirname "$0")/.."
REPO_ROOT="$(pwd)"

echo "repo root: ${REPO_ROOT}"
echo "config:    ${REPO_ROOT}/config/app.conf"
test -f "${REPO_ROOT}/config/app.conf"
echo "start OK"

dirname "$0" points at scripts/ regardless of cwd or checkout location; .. climbs to the repo root. All subsequent paths use $REPO_ROOT instead of absolute literals.

Same class, fixed alongside: - docs/skills/packaging.md — replaced hardcoded ~/&lt;project&gt; with a <path-to-repo> placeholder: "run from the repository root (<path-to-repo>): bash scripts/start.sh". - .gitignore — added .bak* so untracked sidecar backup artifacts never get committed:

node_modules/
dist/
.bak*

Evidence & signatures

Reproduction (before fix), run from a non-standard checkout at `/tmp/chimera-demo`:

```
scripts/start.sh: line 5: cd: ~/<project>: No such file or directory
exit=1            # set -e killed the script
```

After the fix, full verification sweep:

| Check | Result |
|---|---|
| Run from non-standard checkout `/tmp/chimera-demo` | `repo root: /tmp/chimera-demo` → `start OK`, exit 0 |
| Run from unrelated cwd (`cd /` + absolute script path) | exit 0 |
| Checkout path containing spaces (`/tmp/chimera demo copy`) | exit 0 |
| `bash -n scripts/start.sh` | exit 0 |
| `bash -n scripts/compat-smoke.sh` | exit 0 |
| `grep -rn "~" .` | 0 matches (grep exit 1) |
| `git add -A` + `git ls-files` | no `.bak` sidecars tracked |
| `git check-ignore -v config/.bak config/.bak~ config/.bak-2026-08-11` | all matched by `.gitignore:3:.bak*`; `git status --ignored` shows `!!` |

Edge cases tested: cwd independence, absolute-path invocation, spaces in checkout path, and gitignore boundary behavior — `.bak*` matches basenames *starting* with `.bak` (`.bak`, `.bak~`, `.bak-2026-08-11`) but not `app.conf.bak` (basename starts with `app`); artifacts were named to match the pattern as specified. Demo repo left at `/tmp/chimera-demo` for inspection.
{"model": "deepseek-v4-flash", "problem_class": "shell-portable-script-path", "result": "passed", "tests": 9}

Answer 2

Root cause: scripts/start.sh did cd ~/&lt;project&gt;. Under set -euo pipefail, that cd fails on any checkout that isn't at the hardcoded path (exit 1, script aborts). The fix is the portable self-locating pattern already present in compat-smoke.sh:

#!/usr/bin/env bash
set -euo pipefail

# Portable: resolve the repo root from the script's own location so any
# checkout path works (pattern shared with compat-smoke.sh).
cd "$(dirname "$0")/.."
REPO_ROOT="$(pwd)"

echo "repo root: ${REPO_ROOT}"
echo "config:    ${REPO_ROOT}/config/app.conf"
test -f "${REPO_ROOT}/config/app.conf"
echo "start OK"

dirname "$0" points at scripts/ regardless of cwd or checkout location; .. climbs to the repo root. All subsequent paths use $REPO_ROOT instead of absolute literals.

Same class, fixed alongside: - docs/skills/packaging.md — replaced hardcoded ~/&lt;project&gt; with a <path-to-repo> placeholder: "run from the repository root (<path-to-repo>): bash scripts/start.sh". - .gitignore — added .bak* so untracked sidecar backup artifacts never get committed:

node_modules/
dist/
.bak*

Evidence & signatures

Reproduction (before fix), run from a non-standard checkout at `/tmp/chimera-demo`:

```
scripts/start.sh: line 5: cd: ~/<project>: No such file or directory
exit=1            # set -e killed the script
```

After the fix, full verification sweep:

| Check | Result |
|---|---|
| Run from non-standard checkout `/tmp/chimera-demo` | `repo root: /tmp/chimera-demo` → `start OK`, exit 0 |
| Run from unrelated cwd (`cd /` + absolute script path) | exit 0 |
| Checkout path containing spaces (`/tmp/chimera demo copy`) | exit 0 |
| `bash -n scripts/start.sh` | exit 0 |
| `bash -n scripts/compat-smoke.sh` | exit 0 |
| `grep -rn "~" .` | 0 matches (grep exit 1) |
| `git add -A` + `git ls-files` | no `.bak` sidecars tracked |
| `git check-ignore -v config/.bak config/.bak~ config/.bak-2026-08-11` | all matched by `.gitignore:3:.bak*`; `git status --ignored` shows `!!` |

Edge cases tested: cwd independence, absolute-path invocation, spaces in checkout path, and gitignore boundary behavior — `.bak*` matches basenames *starting* with `.bak` (`.bak`, `.bak~`, `.bak-2026-08-11`) but not `app.conf.bak` (basename starts with `app`); artifacts were named to match the pattern as specified. Demo repo left at `/tmp/chimera-demo` for inspection.
{"model": "deepseek-v4-flash", "problem_class": "shell-portable-script-path", "result": "passed", "tests": 9}
Generated from the verified corpus · MIT licensedBack to the catalog