generated from JacobPEvans/.github
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(content-guards): replace fragile bash expansion with explicit branching #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
9a61fbb
refactor(content-guards): replace fragile bash expansion with explici…
JacobPEvans f17a732
test(content-guards): add bats-core test suite for markdown-validator
JacobPEvans 0469b22
fix(content-guards): correct exit code capture in markdownlint valida…
JacobPEvans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...nt-guards/markdown-validator/fixtures/cross-repo-sim/feat/new-feature/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Cross-Repo Feature | ||
|
|
||
| This file simulates a cross-repo editing scenario. | ||
|
|
||
| It has no ancestor `.markdownlint*` config, so the validator should use the fallback config. |
6 changes: 6 additions & 0 deletions
6
tests/content-guards/markdown-validator/fixtures/project-with-config/.markdownlint.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "default": true, | ||
| "MD013": { | ||
| "line_length": 120 | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
tests/content-guards/markdown-validator/fixtures/project-with-config/doc.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Project Documentation | ||
|
|
||
| This markdown file lives in a directory with a `.markdownlint.json` config. | ||
|
|
||
| It should be validated using that project config. |
6 changes: 6 additions & 0 deletions
6
tests/content-guards/markdown-validator/fixtures/valid-basic.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Valid Basic Markdown | ||
|
|
||
| This is a minimal valid markdown file for testing. | ||
|
|
||
| - Item 1 | ||
| - Item 2 |
81 changes: 81 additions & 0 deletions
81
tests/content-guards/markdown-validator/validate-markdown.bats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/usr/bin/env bats | ||
| # Test suite for content-guards/scripts/validate-markdown.sh | ||
| # | ||
| # Tests the markdown validator hook behavior including: | ||
| # - File type filtering (non-markdown, missing, dotfiles) | ||
| # - Config resolution (project vs fallback) | ||
| # - Cross-repo editing scenarios | ||
| # - Unbound variable regression (PR #39, #40) | ||
| # | ||
| # Run with: bats tests/content-guards/markdown-validator/validate-markdown.bats | ||
|
|
||
| setup() { | ||
| # Path to the script under test (relative to repo root) | ||
| REPO_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/../../.." && pwd)" | ||
| SCRIPT="$REPO_ROOT/content-guards/scripts/validate-markdown.sh" | ||
| FIXTURES="$(dirname "$BATS_TEST_FILENAME")/fixtures" | ||
|
|
||
| # Verify script exists | ||
| if [[ ! -f "$SCRIPT" ]]; then | ||
| echo "ERROR: Script not found at $SCRIPT" >&2 | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| @test "TC1: non-markdown file is skipped" { | ||
| run bash -c 'echo "{\"tool_input\":{\"file_path\":\"test.py\"}}" | /bin/bash "$1"' _ "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| [ -z "$output" ] | ||
| } | ||
|
|
||
| @test "TC2: missing file is skipped" { | ||
| run bash -c 'echo "{\"tool_input\":{\"file_path\":\"/nonexistent/file.md\"}}" | /bin/bash "$1"' _ "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| [ -z "$output" ] | ||
| } | ||
|
|
||
| @test "TC3: home dotfile is skipped" { | ||
| run bash -c 'echo "{\"tool_input\":{\"file_path\":\"~/.config/foo.md\"}}" | /bin/bash "$1"' _ "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| [ -z "$output" ] | ||
| } | ||
|
|
||
| @test "TC4: .claude directory file is skipped" { | ||
| run bash -c 'echo "{\"tool_input\":{\"file_path\":\"/path/to/.claude/foo.md\"}}" | /bin/bash "$1"' _ "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| [ -z "$output" ] | ||
| } | ||
|
|
||
| @test "TC5: empty config_flag with project config does not cause unbound variable" { | ||
| run bash -c 'echo "{\"tool_input\":{\"file_path\":\"'"$FIXTURES"'/project-with-config/doc.md\"}}" | /bin/bash "$1"' _ "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| [[ ! "$output" =~ "unbound variable" ]] | ||
| } | ||
|
|
||
| @test "TC6: non-empty config_flag with fallback config" { | ||
| # File without ancestor config should use fallback (temp config or plugin default) | ||
| run bash -c 'echo "{\"tool_input\":{\"file_path\":\"'"$FIXTURES"'/cross-repo-sim/feat/new-feature/README.md\"}}" | /bin/bash "$1"' _ "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| [[ ! "$output" =~ "unbound variable" ]] | ||
| } | ||
|
|
||
| @test "TC7: cross-repo editing finds config from file directory not CWD" { | ||
| # Simulate being in a completely different directory (like ~/git/repo1) | ||
| # while editing a file in ~/git/repo2/feat/branch/ | ||
| original_dir=$(pwd) | ||
| cd /tmp | ||
|
|
||
| run bash -c 'echo "{\"tool_input\":{\"file_path\":\"'"$FIXTURES"'/project-with-config/doc.md\"}}" | /bin/bash "$1"' _ "$SCRIPT" | ||
|
|
||
| # Restore original directory | ||
| cd "$original_dir" | ||
|
|
||
| [ "$status" -eq 0 ] | ||
| [[ ! "$output" =~ "unbound variable" ]] | ||
| } | ||
|
|
||
| @test "TC8: empty JSON input is handled gracefully" { | ||
| run bash -c 'echo "{}" | /bin/bash "$1"' _ "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| [ -z "$output" ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.