Skip to content

Handle [ and test conditional commands as safe read-only operations#69

Merged
ldayton merged 1 commit intomainfrom
test-cmd
Jan 23, 2026
Merged

Handle [ and test conditional commands as safe read-only operations#69
ldayton merged 1 commit intomainfrom
test-cmd

Conversation

@ldayton
Copy link
Copy Markdown
Owner

@ldayton ldayton commented Jan 23, 2026

Summary

Fixes #61 - The confusing "🐤 [ -n" reason message when conditional tests appeared in nested constructs like while loops.

  • Add handling for [ and test commands in _analyze_command after cmdsubs/procsubs/redirects are analyzed
  • Dangerous substitutions inside conditionals are still caught
  • Simple conditional tests return Decision("allow", "conditional test")

Tests

Added 19 tests in TestConditionalTestCommands:

  • Basic [ and test with exact reason assertions
  • Conditionals nested in while loops
  • The kinesis pipeline from the issue
  • Dangerous cmdsubs (rm, dd) - correctly asks
  • Safe cmdsubs (ls, echo, pwd) - correctly allows
  • Edge cases: process substitutions, redirects, env var cmdsubs, param expansion cmdsubs

Fixes #61 - The confusing "🐤 [ -n" reason message when conditional
tests appeared in nested constructs like while loops.

The fix adds handling in _analyze_command after cmdsubs, procsubs,
and redirects are analyzed, ensuring dangerous substitutions are
still caught while allowing simple conditional tests.
@ldayton ldayton merged commit a32b32a into main Jan 23, 2026
1 check passed
@ldayton ldayton deleted the test-cmd branch January 23, 2026 07:46
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.

Confusing reason message for nested constructs

1 participant