-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcfme_spec.sh
More file actions
186 lines (162 loc) · 7.73 KB
/
cfme_spec.sh
File metadata and controls
186 lines (162 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Describe 'cfme'
Include cfme
Include spec/helpers/load_default_env.sh
Include spec/helpers/unload_default_env.sh
setup() {
load_default_env
export EDITOR="mock_editor"
export OUTPUT_FILE="$(mktemp)"
}
teardown() {
rm -rf "${CFME_CONFIG_DIR}"
unset EDITOR
rm -f "${OUTPUT_FILE}"
unset OUTPUT_FILE
unload_default_env
}
BeforeEach 'setup'
AfterEach 'teardown'
Mock git
if [[ "$1" == "commit" ]]; then
exit 0
fi
echo "SAMPLE_DIFF"
End
Mock fzf
echo "1 | 1 entry header"
End
Mock mock_editor
sleep .2
echo "" >> "$1"
End
Mock aichat
echo "$(cat spec/samples/sample-ai-response.yaml)"
End
Mock curl
path="$3"
url="$4"
if [[ "$url" == "https://raw.githubusercontent.com/codevogel/commit-for-me/refs/heads/main/defaults/prompts/conventional-commits/default.md" ]]; then
cat "defaults/prompts/conventional-commits/default.md" > "$path"
exit 0
elif [[ "$url" == "https://raw.githubusercontent.com/codevogel/commit-for-me/refs/heads/main/defaults/prompts/conventional-commits/default-vars.yaml" ]]; then
cat "defaults/prompts/conventional-commits/default-vars.yaml" > "$path"
exit 0
else
echo "Mock curl: URL not recognized" >&2
exit 1
fi
End
spinner() {
echo "SPINNER_STARTED" >&2
}
clear_spinner() {
echo "SPINNER_CLEARED" >&2
}
It 'runs sucessfully'
cp defaults/prompts/conventional-commits/default.md "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default.md"
cp defaults/prompts/conventional-commits/default-vars.yaml "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default-vars.yaml"
When call ./cfme
The output should be blank
The stderr should not be blank
The status should be success
End
It 'runs sucessfully, silently with -s flag'
cp defaults/prompts/conventional-commits/default.md "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default.md"
cp defaults/prompts/conventional-commits/default-vars.yaml "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default-vars.yaml"
When call ./cfme -s
The output should be blank
The stderr should be blank
The status should be success
End
It 'fetches default files sucessfully when they do not exist'
When call ./cfme
The output should be blank
The stderr should include "Fetching file from https://raw.githubusercontent.com/codevogel/commit-for-me/refs/heads/main/defaults/prompts/conventional-commits/default.md"
The stderr should include "File fetched successfully and saved to '$CFME_PROMPT_DIR/conventional-commits/default.md'."
The stderr should include "Fetching file from https://raw.githubusercontent.com/codevogel/commit-for-me/refs/heads/main/defaults/prompts/conventional-commits/default-vars.yaml"
The stderr should include "File fetched successfully and saved to '$CFME_PROMPT_DIR/conventional-commits/default-vars.yaml'."
The status should be success
End
It 'fails when git diff is empty'
Mock git
if [[ "$1" == "commit" ]]; then
exit 0
fi
echo ""
End
When call ./cfme
The output should be blank
The stderr should include "Error: No staged changes found. Please stage your changes before committing."
The status should be failure
End
It 'prints the response if -r flag is set'
When call ./cfme -r
The output should eq "$(cat spec/samples/sample-ai-response.yaml)"
The status should be success
The stderr should not be blank
End
It 'prints the response silenty if -rs flags are set'
When call ./cfme -rs
The output should eq "$(cat spec/samples/sample-ai-response.yaml)"
The status should be success
The stderr should be blank
End
It 'prints the correct message when -m flag is set'
When call ./cfme -ms
The output should eq "$(cat spec/samples/sample-output-commit-message-1.txt)"
The stderr should be blank
The status should be success
End
It 'prints a correctly parsed prompt when --print-parsed-prompt flag is set'
cp spec/samples/sample-prompt-complete.md "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default.md"
cp spec/samples/sample-vars.yaml "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default-vars.yaml"
When call ./cfme --print-parsed-prompt -s
The output should eq "$(cat spec/samples/sample-rendered-prompt-without-instructions.md)"
The stderr should be blank
The status should be success
End
It 'prints a correctly parsed prompt when --print-parsed-prompt flag is set and -i flag is used to pass instructions'
cp spec/samples/sample-prompt-complete.md "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default.md"
cp spec/samples/sample-vars.yaml "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default-vars.yaml"
When call ./cfme --print-parsed-prompt -s -i "SAMPLE_INSTRUCTIONS"
The output should eq "$(cat spec/samples/sample-rendered-prompt-with-instructions.md)"
The stderr should be blank
The status should be success
End
It 'prints a correctly parsed prompt when --print-parsed-prompt flag is set and -p and -v flags are used to pass custom prompts and variables'
export CFME_PROMPT_FILE="${CFME_PROMPT_DIR}/custom.md"
export CFME_VARS_FILE="${CFME_PROMPT_DIR}/custom-vars.yaml"
cp spec/samples/sample-prompt-complete.md "${CFME_PROMPT_FILE}"
cp spec/samples/sample-vars.yaml "${CFME_VARS_FILE}"
When call ./cfme --print-parsed-prompt -s -p "${CFME_PROMPT_FILE}" -v "${CFME_VARS_FILE}"
The output should eq "$(cat spec/samples/sample-rendered-prompt-without-instructions.md)"
The stderr should be blank
The status should be success
End
It 'prints a correctly parsed prompt when --print-parsed-prompt flag is set and default env variables are set for custom prompts and variables'
export CFME_DEFAULT_PROMPT_FILE="${CFME_PROMPT_DIR}/custom.md"
export CFME_DEFAULT_PROMPT_VARIABLES_FILE="${CFME_PROMPT_DIR}/custom-vars.yaml"
cp spec/samples/sample-prompt-complete.md "${CFME_DEFAULT_PROMPT_FILE}"
cp spec/samples/sample-vars.yaml "${CFME_DEFAULT_PROMPT_VARIABLES_FILE}"
When call ./cfme --print-parsed-prompt -s
The output should eq "$(cat spec/samples/sample-rendered-prompt-without-instructions.md)"
The stderr should be blank
The status should be success
End
It 'fails when variables are missing in the vars file that are present in the prompt'
cp spec/samples/sample-prompt-complete.md "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default.md"
cp spec/samples/sample-vars-empty.yaml "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default-vars.yaml"
When call ./cfme
The output should be blank
The stderr should include "Error: custom template string '<__VAR1__>' was found in the prompt file, but is not present in the variables file."
The status should be failure
End
It 'fails when variables are missing in the prompt that are present in the vars file'
echo "" > "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default.md"
cp spec/samples/sample-vars.yaml "${CFME_PROMPT_DIR}/${CFME_PROMPT_TYPE}/default-vars.yaml"
When call ./cfme
The output should be blank
The stderr should include "Error: custom key '<__VAR2__>' was found in variables, but not present in the prompt." #VAR2 shows up as first result due to hashing
The status should be failure
End
End