Skip to content

refactor: unify lazy template expansion and concurrent-group waits - #2095

Merged
max-sixty merged 1 commit into
mainfrom
unify-shell-helpers
Apr 11, 2026
Merged

max-sixty merged 1 commit into
mainfrom
unify-shell-helpers

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Two small follow-ups to #2089, which unified shell command execution for hooks and aliases but left some duplication on the template-expansion and concurrent-wait paths.

What changed

expand_shell_template (in src/commands/command_executor.rs) — one helper that builds the &str vars map and calls expand_template with shell_escape=true. Replaces three lazy-expansion sites (foreground hooks, background pipeline runner, alias runner) and the eager sibling inside expand_commands, so every shell template expansion now flows through one helper.

wait_first_error (same file) — drains a sequence of Result<(), E> items and returns the first error. Alias's thread::scope block and the pipeline runner's concurrent group now share "wait all, return first error" semantics over different concurrency primitives (in-process threads vs OS subprocesses). The concurrent-group bail format now matches the serial-step format (command failed with {exit}: {label}), removing a minor inconsistency — per-command output already lives in each command's log file.

step_context in run_pipeline.rs — folds expand_now and build_step_context_json into one helper returning Cow<HashMap<String, String>>. Unnamed steps borrow the base context; named steps clone once and insert hook_name. Previously, named steps cloned twice (once for expansion, once for JSON).

Where to look

  • src/commands/command_executor.rs — two new helpers
  • src/commands/hooks.rs — deleted local expand_lazy_template
  • src/commands/alias.rs — concurrent block and AliasExecCtx::run
  • src/commands/run_pipeline.rs — step_context, run_concurrent_group, expand_commands in main loop

Testing

cargo run -- hook pre-merge --yes is green: 3025/3025 insta-nextest tests, pre-commit lints, doctests, cargo doc. No snapshots changed.

Extracts two helpers in command_executor.rs to consolidate duplication
left over from PR #2089:

- `expand_shell_template` replaces three lazy-expansion sites (hooks,
  aliases, pipeline runner) and the eager sibling in `expand_commands`,
  so every shell-command template expansion flows through one helper.
- `wait_first_error` drains a sequence of Result items and returns the
  first error, letting alias's `thread::scope` block and the pipeline
  runner's concurrent group share "wait all, return first error"
  semantics over different concurrency primitives.

Also folds `expand_now` and `build_step_context_json` in run_pipeline.rs
into a single `step_context` helper returning `Cow`, eliminating a
per-step double-clone of the context map. The concurrent-group bail
format now matches the serial-step format ("command failed with
{exit}: {label}"), removing a minor inconsistency.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 337ea97 into main Apr 11, 2026
24 checks passed
@max-sixty
max-sixty deleted the unify-shell-helpers branch April 11, 2026 23:11
max-sixty added a commit that referenced this pull request Apr 11, 2026
Resolves conflicts with #2095 (refactor: unify lazy template expansion
and concurrent-group waits) which independently:

- Added `wait_first_error` and `expand_shell_template` helpers in
  command_executor.rs
- Refactored AliasExecCtx::run and the alias concurrent block
- Refactored run_concurrent_group to use the new helpers

Resolution:
- alias.rs: combine my serial-test branch with main's `wait_first_error`
  scaffolding (the non-serial path now delegates to it)
- run_pipeline.rs: my serial branch sits inside the per-command loop;
  the concurrent path uses the merged helpers (`step_context`,
  `expand_shell_template`, `wait_first_error`)

Co-Authored-By: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Apr 11, 2026
Last call site still inlining the `&str` map conversion — fold onto the
helper introduced in #2095.

Co-Authored-By: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Apr 12, 2026
Last call site still inlining the `&str` map conversion — fold onto the
`expand_shell_template` helper introduced in #2095.

Follow-up from #2095 session-ending list.

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Apr 12, 2026
The lazy/eager distinction in alias template expansion was unnecessary —
alias expansion always happens at execution time (in
`AliasExecCtx::run`), so `vars.*` references naturally read fresh values
from git config without special handling. The "lazy" path was
round-tripping `context_json` back to the same `HashMap` that was
serialized from `context_map`.

Removes the intermediate `HashMap<&str, &str>`, the `is_pipeline` field,
and the `template_references_var` branching. Both dry-run and execution
paths now route through `expand_shell_template`, making it the canonical
expansion path for all three consumers (hooks, aliases, pipelines).

Follow-up to #2095 and #2103.

> _This was written by Claude Code on behalf of @max-sixty_

---------

Co-authored-by: Claude <[email protected]>
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