-
Notifications
You must be signed in to change notification settings - Fork 0
fix: shell test coverage and llm-update.sh formatting #805
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,10 @@ set -euo pipefail | |||||
| ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||||||
| MODELS="$ROOT/models.json" | ||||||
|
|
||||||
| [[ -f "$MODELS" ]] || { echo "ERROR: models.json not found" >&2; exit 1; } | ||||||
| [[ -f $MODELS ]] || { | ||||||
|
||||||
| [[ -f $MODELS ]] || { | |
| [[ -f "$MODELS" ]] || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sed command is vulnerable to command injection because it uses unvalidated input from models.json to construct substitution expressions. If a value in models.json contains the delimiter | followed by the e flag (e.g., value|e;s|a|b), GNU sed will execute the replacement as a shell command. This could lead to Remote Code Execution (RCE) if models.json is influenced by an attacker (e.g., via a malicious Pull Request).
To remediate this, ensure that all values from models.json are properly escaped before being added to sed_args. For example, you can escape the pipe character using Bash string replacement: ${value//|/\\|}. This should be applied to the value, pretty, and nondot variables where they are added to the sed_args array.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck disable=SC2329,SC2034 | ||
|
|
||
| Describe 'scripts/llm-update.sh' | ||
| SCRIPT="$PWD/scripts/llm-update.sh" | ||
|
|
||
| Describe 'script properties' | ||
| It 'uses bash shebang' | ||
| When run bash -c "head -1 '$SCRIPT'" | ||
| The output should include '#!/usr/bin/env bash' | ||
| End | ||
|
|
||
| It 'uses strict mode' | ||
| When run bash -c "head -5 '$SCRIPT'" | ||
| The output should include 'set -euo pipefail' | ||
| End | ||
| End | ||
|
|
||
| Describe 'models.json dependency' | ||
| It 'references models.json' | ||
| When run bash -c "grep 'models.json' '$SCRIPT'" | ||
| The output should include 'models.json' | ||
| End | ||
|
|
||
| It 'exits if models.json is missing' | ||
| When run bash -c "grep 'models.json not found' '$SCRIPT'" | ||
| The output should include 'ERROR' | ||
| End | ||
|
Comment on lines
+25
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test only verifies that the error message string exists within the script file, but it doesn't test the actual runtime behavior. A more robust test would execute the script in a state where Here's an example of how you could write a functional test for this case using It 'exits if models.json is missing'
# Temporarily move models.json to simulate its absence
Before 'mv "$PWD/models.json" "$PWD/models.json.bak"'
After 'mv "$PWD/models.json.bak" "$PWD/models.json"'
When run script "$SCRIPT"
The status should be failure
The stderr should include 'ERROR: models.json not found'
EndThis approach of testing behavior over implementation details could be applied to other tests in this file to make them more effective. |
||
| End | ||
|
|
||
| Describe 'template processing' | ||
| It 'uses sed for substitution' | ||
| When run bash -c "grep 'sed' '$SCRIPT'" | ||
| The output should include 'sed' | ||
| End | ||
|
|
||
| It 'defines template-to-output mappings' | ||
| When run bash -c "grep 'TEMPLATES' '$SCRIPT'" | ||
| The output should include 'TEMPLATES' | ||
| End | ||
|
|
||
| It 'processes .tpl. template files' | ||
| When run bash -c "grep '\.tpl\.' '$SCRIPT'" | ||
| The output should include '.tpl.' | ||
| End | ||
| End | ||
|
|
||
| Describe 'jq pretty-printing' | ||
| It 'defines a jq pretty function for model names' | ||
| When run bash -c "grep 'def pretty' '$SCRIPT'" | ||
| The output should include 'def pretty' | ||
| End | ||
|
|
||
| It 'capitalizes Claude model names' | ||
| When run bash -c "grep '"Claude"' '$SCRIPT'" | ||
| The output should include 'Claude' | ||
| End | ||
| End | ||
|
|
||
| Describe 'placeholder generation' | ||
| It 'converts keys to uppercase placeholders' | ||
| When run bash -c "grep 'placeholder=' '$SCRIPT'" | ||
| The output should include '__' | ||
| End | ||
|
|
||
| It 'generates PRETTY variant placeholders' | ||
| When run bash -c "grep '_PRETTY__' '$SCRIPT'" | ||
| The output should include '_PRETTY__' | ||
| End | ||
|
|
||
| It 'generates NONDOT variant placeholders' | ||
| When run bash -c "grep '_NONDOT__' '$SCRIPT'" | ||
| The output should include '_NONDOT__' | ||
| End | ||
| End | ||
|
|
||
| End | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
$MODELSvariable should be quoted to prevent issues with word splitting if the file path contains spaces. It's a good practice to always quote variables that hold file paths, as this will prevent bugs if the script is run from a directory with spaces in its name.