Skip to content

Post-install self-verification of CLI usability (#738)#215

Merged
saadqbal merged 3 commits into
developfrom
fix/install-journey-738-cli-self-verify
Jun 9, 2026
Merged

Post-install self-verification of CLI usability (#738)#215
saadqbal merged 3 commits into
developfrom
fix/install-journey-738-cli-self-verify

Conversation

@LukasWodka

Copy link
Copy Markdown
Contributor

Closes #738

Summary

After Step 5 installs the tracebloc CLI, the installer told the user "open a new terminal so it's on your PATH" without ever proving a fresh terminal would find it — the cli#61 failure mode (binary lands in ~/.local/bin, which a brand-new shell does not have on PATH), undetected until a customer hits it. This adds a post-install self-verification that probes a fresh shell for tracebloc and either prints a verified verdict or the exact shell-correct PATH fix for the user's actual $SHELL. Stays non-fatal (the client is already connected by Step 5). Mirrored on Windows.

Related

Closes #738 · Part of #736 (install-journey epic)

Type of change

  • Feature
  • Bug fix

Test plan

Verified locally (macOS, bats 1.13.0):

  • bash -n scripts/lib/install-cli.sh — passes
  • bats scripts/tests/install-cli.bats8/8 pass, including:
    • fresh-shell success reports a verified verdict (asserts tracebloc version proof, asserts the old "open a new terminal" line is gone, asserts the dataset-push command is NOT duplicated here)
    • CLI-missing-from-fresh-shell prints an actionable, shell-correct PATH hint (asserts the exact export PATH="...local/bin:$PATH" line + source ~/.zshrc for zsh)
    • fish gets a fish-correct fix (fish_add_path + ~/.config/fish/config.fish, not a POSIX export)
    • verification failure is non-fatal (status 0), incl. a stress test under the orchestrator's set -e
  • bats scripts/tests/summary.bats — 15/15 pass (unchanged; confirms next-steps stay consistent and the verified command is not duplicated)
  • Unit-checked the rc-routing helper across zsh / bash-linux / bash-darwin / fish / sh / dash — all match the spec routing.

Pre-existing baseline failures (NOT introduced here): validate_config, _extract_yaml_value, and two Docker-engine RHEL/Amazon-Linux tests fail identically on clean origin/develop (macOS env-specific); untouched by this PR.

Needs CI:

  • Pester (scripts/tests/install-k8s.Tests.ps1) — pwsh is not installed on this machine, so the new Test-TraceblocCli Describe block (verified verdict / actionable hint / non-fatal when RefreshPath throws) and the updated Install-TraceblocCli cases were not run locally. Needs the Windows/Pester CI job to confirm.
  • shellcheck — not installed locally; relies on CI lint.

Deployment notes

None. Behavior change is limited to the install-time messaging of Step 5; no env vars, migrations, or rollout ordering.

Checklist

  • Tests added / updated and passing locally (bats; Pester needs CI)
  • Docs updated if behavior or config changed (installer self-describes; no separate docs)
  • No secrets / credentials in the diff
  • For security-sensitive paths: appropriate reviewer requested (assigned @saadqbal)

🤖 Generated with Claude Code

…correct PATH fix (#738)

Step 5 installed the tracebloc CLI and then told the user "open a new
terminal so it's on your PATH" — without ever proving a fresh terminal
would actually find it. That is exactly the cli#61 failure mode (binary
lands in ~/.local/bin, which a brand-new shell doesn't have on PATH),
left undetected until the customer hits it. The installer is the last
place to catch it.

After the install attempt, self-verify and report precisely:

- Probe `command -v tracebloc` in BOTH a fresh login shell ("$SHELL" -lic)
  and a non-login shell ("$SHELL" -ic) — they read different startup files
  (~/.profile vs ~/.bashrc), and cli#61 was "works in my login shell,
  missing in a plain `bash` subshell".
- If found: confirm via `tracebloc version` and print a VERIFIED verdict.
  The canonical `tracebloc dataset push ./data` next step stays in the
  summary's "What to do next" — not duplicated here.
- If a fresh shell would NOT find it: print the EXACT shell-correct fix
  for the user's actual $SHELL (zsh→~/.zshrc, bash+linux→~/.bashrc,
  bash+darwin→~/.bash_profile, fish→fish_add_path + ~/.config/fish/config.fish,
  else ~/.profile), not a generic "open a new terminal".

Stays NON-FATAL by design: the client is already connected by Step 5, so
the verification always returns 0 and is hardened against the orchestrator's
`set -e`. Mirrored in install-k8s.ps1 (RefreshPath is the faithful
"fresh terminal" probe on Windows, since the CLI installer edits the
user-scope registry PATH).

Tests: extend install-cli.bats (verified-command success, actionable
shell-correct PATH hint on miss, fish-specific fix, non-fatal under
`set -e`) and mirror in install-k8s.Tests.ps1 (Test-TraceblocCli:
verified verdict, actionable hint, non-fatal when RefreshPath throws).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@LukasWodka

Copy link
Copy Markdown
Contributor Author

👋 Heads-up — Code review queue is at 17 / 8

Above the WIP limit. The team convention is to review existing PRs before opening new work.

Open PRs currently in Code review (oldest first):

Pull from review before opening new work. (This is a nudge from the kanban WIP check, not a block.)

Two follow-ups so the Pester jobs go green (they were the only red checks
on #215; Pester is green on develop, so this PR introduced both):

- install-k8s.ps1: the new $TRACEBLOC_CLI_INSTALL_DIR ran Join-Path on
  $env:LOCALAPPDATA at top level. The Pester suite dot-sources this script,
  and on the Linux runner $env:LOCALAPPDATA is null — Join-Path throws on a
  null -Path, aborting BeforeAll and failing the whole container (0/65).
  Guard it; "" placeholder off Windows since the value is only used there.

- install-k8s.Tests.ps1: add a `function tracebloc { }` stub so
  `Mock tracebloc` can bind. Pester v5 only mocks commands that already
  exist (cf. the existing kubectl/docker/helm/k3d stubs); without it the
  "fresh-shell success" test threw CommandNotFoundException — the lone
  windows-latest failure.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@saadqbal

saadqbal commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@LukasWodka — pushed a small follow-up (ffb597b) to get the two Pester jobs green. They were the only red checks here, and both were the Windows/PowerShell parts you flagged as "needs CI" (no local pwsh). Both only surface on the runners:

1. Pester (ubuntu-latest) — 0/65, whole container crashed. The suite dot-sources install-k8s.ps1, so the new top-level $TRACEBLOC_CLI_INSTALL_DIR = (Join-Path $env:LOCALAPPDATA "Programs\tracebloc") runs on Linux too — where $env:LOCALAPPDATA is $null, and Join-Path throws on a null -Path (Cannot bind argument to parameter 'Path' because it is null), aborting BeforeAll and failing all 65 tests. Guarded it with if ($env:LOCALAPPDATA) { ... } else { "" } — the value is only ever used on Windows, so the placeholder is harmless off-platform.

2. Pester (windows-latest) — the lone failing test. Mock tracebloc { ... } in "fresh-shell success" threw CommandNotFoundException — Pester v5 only mocks commands that already exist. Added a function tracebloc { } stub to BeforeAll, mirroring the existing kubectl/docker/helm/k3d stubs.

Both Pester jobs are green now (+ Lint, bats, Unit tests, Static analysis). Marking ready for review.

@saadqbal saadqbal marked this pull request as ready for review June 8, 2026 09:19
@LukasWodka

Copy link
Copy Markdown
Contributor Author

👋 Heads-up — Code review queue is at 13 / 8

Above the WIP limit. The team convention is to review existing PRs before opening new work.

Open PRs currently in Code review (oldest first):

Pull from review before opening new work. (This is a nudge from the kanban WIP check, not a block.)

saadqbal
saadqbal previously approved these changes Jun 8, 2026
@saadqbal

saadqbal commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@cursor

cursor Bot commented Jun 8, 2026

Copy link
Copy Markdown

Bugbot couldn't run

Bugbot is not enabled for your user on this team.

Ask your team administrator to increase your team's hard limit for Bugbot seats or add you to the allowlist in the Cursor dashboard.

aptracebloc
aptracebloc previously approved these changes Jun 8, 2026
@LukasWodka

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor

cursor Bot commented Jun 8, 2026

Copy link
Copy Markdown

Bugbot couldn't run

Bugbot is not enabled for your user on this team.

Ask your team administrator to increase your team's hard limit for Bugbot seats or add you to the allowlist in the Cursor dashboard.

@saadqbal saadqbal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two non-blocking follow-ups from the review, both on scripts/lib/install-cli.sh — they bear on #738's core promise of correct, shell-specific guidance. CI is green and every failure mode here is non-fatal, so neither blocks merge.

Comment thread scripts/lib/install-cli.sh
Comment thread scripts/lib/install-cli.sh Outdated
Review follow-up on #215 (comment #2). The miss-branch hint printed a bare
`export PATH=…` (fixes only the current shell) followed by `source ${rc}` on
an rc that did not yet contain the line — so neither command persisted the
fix, while the closing note implied ${rc} should hold it. The user is never
told to write the line into the rc. Rewrite the guidance per-shell:

- POSIX shells (zsh / bash / sh / dash): `echo '<export>' >> ${rc}` then
  `source ${rc}` — one copy-pasteable step that fixes THIS terminal and every
  new one.
- fish: `fish_add_path "…"` already persists (a universal var) AND applies to
  the running shell, so drop the misleading `source ~/.config/fish/config.fish`.

Tests (install-cli.bats): the zsh miss-path now asserts the `echo … >> ~/.zshrc`
form; the fish case asserts no POSIX `export` and no `source`. bats 8/8 pass,
shellcheck --severity=error gate clean, bash -n clean.

NOTE: review comment #1 (fish fresh-shell probe using `command -v`, which fish's
`command` builtin lacks) is NOT addressed here — it needs verification on a real
fish and is tracked separately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@saadqbal saadqbal dismissed stale reviews from aptracebloc and themself via 9ec5a5d June 9, 2026 05:49
@saadqbal

saadqbal commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Pushed 9ec5a5d addressing review comment #2 (the PATH-fix guidance).

The miss-branch hint now persists correctly, per shell:

  • POSIX (zsh/bash/sh/dash): echo '<export>' >> ~/.rc then source ~/.rc — fixes this terminal and new ones in one copy-pasteable step. (The old code printed a bare export that fixed only the current shell, then sourced an rc that didn't yet contain the line, so nothing persisted.)
  • fish: fish_add_path "…" only — it persists (universal var) and applies to the running shell, so the misleading source …/config.fish is gone.

bats 8/8, shellcheck --severity=error gate clean, bash -n clean.


Update on review comment #1 — withdrawn after verification. I claimed the fresh-shell probe's command -v tracebloc would false-negative under fish because fish's command builtin "doesn't implement -v." That was wrong. I ran the actual probe against real fish 3.4.1 and 4.0.2 (Alpine containers): fish -lic 'command -v ls' returns /bin/ls and exits 0, and the bundled -lic flags parse fine. So the probe resolves the CLI correctly under fish and needs no change. Apologies for the noise — thread resolved.

@saadqbal saadqbal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. ✅

Reviewed the post-install CLI self-verification (#738):

  • #2 — PATH-fix guidance (addressed in 9ec5a5d): POSIX shells now echo '<export>' >> ~/.rc + source ~/.rc (persists for this terminal and new ones); fish uses its self-persisting fish_add_path with no bogus source. bats 8/8, shellcheck --severity=error gate clean, bash -n clean.
  • #1 — fish fresh-shell probe: verified against real fish 3.4.1 and 4.0.2 that command -v resolves correctly and -lic parses — non-issue, withdrawn.

Both review threads resolved, CI green. Design is sound: non-fatal after Step 5, two-shell (login + non-login) probe matching the cli#61 failure mode, and faithfully mirrored on Windows via RefreshPath. 👍

@saadqbal saadqbal merged commit 8ed1200 into develop Jun 9, 2026
20 checks passed
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.

3 participants