Skip to content

Commit 3586ca0

Browse files
committed
Update Helper Functions, Tests, and Markdown Installation
Updated function name and tests for consistency Improved error handling in markdown installation script Refactored test files to use new function name Fixed argument parsing test cases for document subcommand
1 parent 1cbda6c commit 3586ca0

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

src/helpers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ json_escape() {
198198
}
199199

200200
extract_content_from_response() {
201-
# Usage: extract_content "$json_string"
201+
# Usage: extract_content_from_response "$json_string"
202202
json=$1
203203

204204
# 1) Extract all lines from the "content" property (handles multi-line content)

src/markdown.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ install_from_github() {
327327
curl -fsSL "https://github.com/charmbracelet/glow/releases/download/$tag/$file" -o "$tmpdir/glow.tar.gz"
328328
curl -fsSL "https://github.com/charmbracelet/glow/releases/download/$tag/checksums.txt" -o "$tmpdir/checksums.txt"
329329

330-
cd "$tmpdir"
330+
cd "$tmpdir" || exit 1
331331
sha256sum -c checksums.txt --ignore-missing --quiet || {
332332
echo "Checksum verification failed"
333333
exit 1
@@ -343,7 +343,7 @@ install_from_github() {
343343
sudo mv glow "$bindir"
344344
fi
345345

346-
cd -
346+
cd - || exit 1
347347
rm -rf "$tmpdir"
348348

349349
echo "glow installed to $bindir"

tests/test_extract_content.bats

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,43 @@ setup() {
1414

1515
@test "extracts simple single-line content" {
1616
json='{"message":{"content":"Hello World"}}'
17-
run extract_content "$json"
17+
run extract_content_from_response "$json"
1818
[ "$status" -eq 0 ]
1919
[ "$output" = "Hello World" ]
2020
}
2121

2222
@test "extracts multi-line content with \\n escapes" {
2323
json='{"message":{"content":"Line1\nLine2\nLine3"}}'
24-
run extract_content "$json"
24+
run extract_content_from_response "$json"
2525
[ "$status" -eq 0 ]
2626
expected=$'Line1\nLine2\nLine3'
2727
[ "$output" = "$expected" ]
2828
}
2929

3030
@test "extracts content containing escaped quotes" {
3131
json='{"message":{"content":"He said: \"Hi there\""}}'
32-
run extract_content "$json"
32+
run extract_content_from_response "$json"
3333
assert_success
3434
assert_output 'He said: "Hi there"'
3535
}
3636

3737
@test "extracts content with backslashes" {
3838
json='{"message":{"content":"Path C:\\Windows\\System32"}}'
39-
run extract_content "$json"
39+
run extract_content_from_response "$json"
4040
assert_success
4141
assert_output 'Path C:\Windows\System32'
4242
}
4343

4444
@test "returns empty string when content key is missing" {
4545
json='{"foo":"bar"}'
46-
run extract_content "$json"
46+
run extract_content_from_response "$json"
4747
assert_success
4848
[ -z "$output" ]
4949
}
5050

5151
@test "extracts content when other keys present" {
5252
json='{"choices":[{"foo":123,"message":{"content":"# Announcement\nUpdate complete."},"other":true}]}'
53-
run extract_content "$json"
53+
run extract_content_from_response "$json"
5454
assert_success
5555
expected=$'# Announcement\nUpdate complete.'
5656
assert_output "$expected"
@@ -59,7 +59,7 @@ setup() {
5959
@test "extracts content from example_response.json file" {
6060
json=$(cat "$BATS_TEST_DIRNAME/assets/example_response.json")
6161
tmp_output=$(mktemp)
62-
response="$(extract_content "${json}")"
62+
response="$(extract_content_from_response "${json}")"
6363
echo $response >"$tmp_output"
6464
output=$(cat "$tmp_output")
6565
[ -n "$output" ]

tests/test_parse_args.bats

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ setup_git_range() {
147147
}
148148

149149
@test "subcommand 'document' is accepted and printed" {
150-
run parse_args document --verbose
150+
run parse_args document --verbose --prompt-file "TEST"
151151
assert_success
152152
assert_output --partial "Subcommand: document"
153153
}
@@ -274,12 +274,7 @@ setup_git_range() {
274274
assert_output --partial "Pathspec: "
275275
}
276276

277-
# Insert the new test cases for the 'document' subcommand
278-
@test "subcommand 'document' is accepted and printed" {
279-
run parse_args document --verbose --prompt-file PROMPT
280-
assert_success
281-
assert_output --partial "Subcommand: document"
282-
}
277+
283278

284279
@test "document subcommand without --prompt-file errors out" {
285280
run parse_args document --verbose

tests/tests.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ EOF
387387
@test "Env API key required for remote" {
388388
unset GIV_API_KEY
389389
gen_commits
390-
run "$GIV_SCRIPT" changelog HEAD --model-provider remote --api-url http://fake --api-model dummy
390+
run "$GIV_SCRIPT" changelog HEAD --model-mode remote --api-url http://fake --api-model dummy
391391
assert_output --partial "GIV_API_KEY"
392392
}
393393

0 commit comments

Comments
 (0)