Skip to content

shell: reintroduce shell variants - #759

Merged
ewhauser merged 4 commits into
mainfrom
ewhauser/reintroduce-shell-variants
Mar 28, 2026
Merged

ewhauser merged 4 commits into
mainfrom
ewhauser/reintroduce-shell-variants

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • add shared ShellVariant plumbing across public/internal requests and session.exec
  • resolve one active shell variant in the shell core and use it throughout parse, expand, interpret, and diagnostics
  • restore sh, mksh, and zsh execution paths, reject bats runner features explicitly, and update SPEC.md

Why

We removed the upstream mvdan/sh shell-specific support during the port, which left the runtime effectively Bash-only and hard-coded Bash behavior into several parser and interpreter helper paths. This change makes shell variant selection first-class again without pretending that bats has a full harness implementation.

Impact

  • callers can set shell_variant directly on execution and interactive requests
  • sh now starts in POSIX mode with brace expansion disabled
  • mksh and zsh select their syntax variants while keeping the current non-POSIX runtime defaults
  • bats parses as a dialect but @test execution and #!/bin/bats dispatch fail with an explicit runner-not-implemented error

Validation

  • make test
  • make lint

@ewhauser ewhauser changed the title [codex] shell: reintroduce shell variants shell: reintroduce shell variants Mar 28, 2026
@ewhauser
ewhauser marked this pull request as ready for review March 28, 2026 15:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 045e4c8f5d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/builtins/registry.go Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4becfcd202

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/shell/core.go
cfg.NewPipe = exec.NewPipe
cfg.LegacyBashCompat = exec.Interpreter == "bash" || exec.Interpreter == "sh"
cfg.ShellVariant = executionShellVariant(exec)
cfg.LegacyBashCompat = path.Base(strings.TrimSpace(exec.Interpreter)) == "bash"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Derive legacy-compat mode from resolved shell variant

runnerConfig still enables LegacyBashCompat from Interpreter instead of the already-resolved shell variant, so requests that intentionally override parser behavior (for example Interpreter="bash" with ShellVariant="sh") still inherit Bash-legacy behavior. That leaks interpreter metadata back into runtime semantics (not just argv0/presentation), which can change observable behavior such as POSIX-mode shift diagnostics and [[ =~ ]] parse diagnostics even when the caller explicitly selected a non-Bash variant.

Useful? React with 👍 / 👎.

@ewhauser
ewhauser merged commit d5db727 into main Mar 28, 2026
15 checks passed
@ewhauser
ewhauser deleted the ewhauser/reintroduce-shell-variants branch March 28, 2026 16:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca83d13cd1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread shell/expand/varref.go
Comment on lines 80 to +82
func (v Variable) ResolveRefState(env Environ, ref *syntax.VarRef) (RefResolution, error) {
return v.ResolveRefStateVariant(env, ref, syntax.LangBash)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use active variant for default nameref resolution

ResolveRefState now hard-codes syntax.LangBash, while runner paths still call Variable.ResolveRef for nameref traversal in non-Bash variants. In ShellVariant=sh, this lets nameref targets be reparsed with Bash rules (for example array-style targets) and can bypass the new POSIX varref restrictions added elsewhere. Please route runner nameref resolution through the variant-aware path so SH mode cannot resolve references that only parse in Bash.

Useful? React with 👍 / 👎.

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.

1 participant