Skip to content

CI: Add bashrs validation for generated ZSH widget code #98

@noahgift

Description

@noahgift

Feature Request

Add bashrs lint validation to CI and the zsh-widget command to catch shell scripting bugs before they reach users.

Current Problem

The ZSH widget code has multiple lint issues that could have been caught automatically:

$ aprender-shell zsh-widget | bashrs lint /dev/stdin
Summary: 0 error(s), 2 warning(s), 6 info(s)
Score: B (7.5/10)

Issues found:

  • SC2046: Unquoted command substitution (word splitting risk)
  • SC2016: Single quotes preventing expansion
  • SC2148: Missing shebang
  • SC2201: Brace expansion in assignments
  • SC2227: Redirection before pipe

Proposed Solution

1. CI Integration

Add to GitHub Actions workflow:

- name: Validate generated shell code
  run: |
    cargo run --bin aprender-shell -- zsh-widget > /tmp/widget.sh
    bashrs lint /tmp/widget.sh --strict
    bashrs audit /tmp/widget.sh

2. Build-time validation

In build.rs or as a test:

#[test]
fn test_zsh_widget_passes_lint() {
    let widget = generate_zsh_widget();
    
    let output = Command::new("bashrs")
        .args(["lint", "--format", "json", "/dev/stdin"])
        .stdin(widget.as_bytes())
        .output()
        .expect("bashrs not installed");
    
    let result: LintResult = serde_json::from_slice(&output.stdout)?;
    assert!(result.errors.is_empty(), "Widget has lint errors: {:?}", result.errors);
    assert!(result.warnings.len() < 3, "Too many warnings: {:?}", result.warnings);
}

3. Runtime warning

When generating widget code:

$ aprender-shell zsh-widget
# aprender-shell ZSH widget
# Validated with bashrs: 0 errors, 0 warnings
...

4. Quality gate

Block releases if widget score drops below threshold:

const MIN_WIDGET_SCORE: f32 = 8.0;  // Require B+ or better

Benefits

  1. Catch bugs early - Before users install broken widgets
  2. Consistent quality - Automated enforcement
  3. Documentation - Score shows widget quality
  4. Cross-shell validation - bashrs knows POSIX, bash, zsh quirks

bashrs Checks That Apply

Check Description Severity
SC2046 Unquoted command substitution Warning
SC2086 Unquoted variable Warning
SC2148 Missing shebang Info
SC2154 Unassigned variable Warning
IDEM* Idempotency issues Warning
SAFE* Safety issues Error

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions