Skip to content

Commit 862b5a7

Browse files
oleanderGit AI Test
and
Git AI Test
authored
feat: Add Comprehensive Testing Infrastructure (#31)
* feat: Testing Infrastructure changes * Update version in Cargo.lock and refactor patch_test.rs Based solely on the changes visible in the diff, this commit: - Updates the version of 'git-ai' in Cargo.lock from '0.2.56' to '0.2.57'. - Refactors 'patch_test.rs', introducing the 'TestRepository' trait, which provides a 'to_diff' method, and modifies the usage of the 'to_diff' method throughout the test file to now be associated with the 'TestRepository' trait. - Removes the staging and committing operations in the 'test_patch_diff_to_patch' test. - Adds new methods to capture diffs in different scenarios, such as staged changes, no staged changes, and initial state comparison against HEAD or working directory. Please note this message only encompasses alterations marked with '+' or '-' in the diff. --------- Co-authored-by: Git AI Test <[email protected]>
1 parent af0899e commit 862b5a7

File tree

5 files changed

+642
-40
lines changed

5 files changed

+642
-40
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ http-cacache/*
55
.env.local
66
${env:TMPDIR}
77
bin/
8+
tmp/

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/comprehensive-tests

+292
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
#!/usr/bin/env fish
2+
3+
set -x fish_trace 1
4+
5+
# Load environment variables from .env.local if it exists
6+
if test -f .env.local
7+
for line in (cat .env.local)
8+
if not string match -q "#*" $line # Skip comments
9+
and test -n "$line" # Skip empty lines
10+
set -l key (string split -m 1 = $line)[1]
11+
set -l value (string split -m 1 = $line)[2]
12+
# Remove quotes if they exist
13+
set value (string trim -c '"' $value)
14+
set value (string trim -c "'" $value)
15+
set -gx $key $value
16+
end
17+
end
18+
else
19+
echo "Warning: .env.local file not found. Make sure you have the required environment variables set."
20+
end
21+
22+
set -Ux OPENAI_API_KEY $OPENAI_API_KEY
23+
set -x RUST_LOG debug
24+
25+
if not test -n "$OPENAI_API_KEY"
26+
echo "Please set the OPENAI_API_KEY environment variable."
27+
exit 1
28+
end
29+
30+
if not command -v cargo
31+
echo "Cargo not found. Please install Rust."
32+
exit 1
33+
end
34+
35+
function on_exit --on-event fish_exit
36+
if test -d $TEST_DIR
37+
rm -rf $TEST_DIR
38+
end
39+
end
40+
41+
function generate_random_content
42+
set size $argv[1]
43+
head -c $size /dev/urandom | base64
44+
end
45+
46+
function last_commit
47+
git log -1 --pretty=%B | tr -d '\n'
48+
end
49+
50+
function fail
51+
echo "Test failed: $argv"
52+
exit 1
53+
end
54+
55+
function test_step
56+
set description $argv[1]
57+
echo "=== Testing: $description ==="
58+
end
59+
60+
set TEST_DIR /tmp/git-ai-test-(date +%s)
61+
62+
# Install git-ai
63+
cargo install --force --debug --path . || fail "Cargo installation failed"
64+
65+
# Setup test repository
66+
rm -rf $TEST_DIR
67+
mkdir -p $TEST_DIR
68+
cd $TEST_DIR
69+
70+
git init || fail "Git init failed"
71+
git config user.name "Test User"
72+
git config user.email "[email protected]"
73+
git config --global init.defaultBranch main
74+
git branch -m main
75+
76+
# Test 1: Hook Installation and Configuration
77+
test_step "Hook Installation and Configuration"
78+
79+
git-ai hook || echo "As expected"
80+
git-ai hook install || fail "Hook installation failed"
81+
git-ai hook uninstall || fail "Hook uninstallation failed"
82+
git-ai hook install || fail "Hook reinstallation failed"
83+
git-ai hook reinstall || fail "Hook reinstall failed"
84+
85+
git-ai config reset
86+
git-ai config || echo "As expected"
87+
git-ai config set || echo "As expected"
88+
git-ai config set model gpt-4 || fail "Setting model failed"
89+
git-ai config set max-tokens 512 || fail "Setting max tokens failed"
90+
git-ai config set max-commit-length 1024 || fail "Setting max commit length failed"
91+
git-ai config set openai-api-key "$OPENAI_API_KEY" || fail "Setting OpenAI API key failed"
92+
93+
# Test 2: Basic Git Operations
94+
test_step "Basic Git Operations"
95+
96+
# 2.1 Initial commit
97+
echo "Hello World 0" >README.md
98+
git add README.md
99+
git status --porcelain || fail "Git status failed before initial commit"
100+
test -f README.md || fail "README.md was not created"
101+
git commit -m "Initial commit: Add README.md" || fail "Initial commit failed"
102+
git status --porcelain || fail "Git status failed after initial commit"
103+
104+
# 2.2 Commit with message
105+
echo "Hello World" >README.md
106+
git add README.md
107+
git commit -m "Initial commit" || fail "Commit with message failed"
108+
last_commit | grep "Initial commit" || fail "Commit message 'Initial commit' not found"
109+
110+
# 2.3 Commit with --no-edit
111+
echo "Hello World 2" >README.md
112+
git add README.md
113+
git commit --no-edit || fail "Commit --no-edit failed"
114+
git status --porcelain || fail "Git status failed after commit --no-edit"
115+
116+
# Test 3: File Creation Permutations
117+
test_step "File Creation Permutations"
118+
119+
# 3.1 Empty file
120+
touch empty_file.txt
121+
git add empty_file.txt
122+
git commit -a --no-edit || fail "Empty file commit failed"
123+
124+
# 3.2 Multiple empty files
125+
touch empty1.txt empty2.txt empty3.txt
126+
git add .
127+
git commit -a --no-edit || fail "Multiple empty files commit failed"
128+
129+
# 3.3 Files with different content types
130+
echo "Normal text" >normal.txt
131+
echo -e "Line 1\nLine 2\nLine 3" >multiline.txt
132+
echo -n "No newline" >no_newline.txt
133+
echo "Tab Space Space End" >whitespace.txt
134+
git add .
135+
git commit -a --no-edit || fail "Different content types commit failed"
136+
137+
# Test 4: File Modification Permutations
138+
test_step "File Modification Permutations"
139+
140+
# 4.1 Modify start of file
141+
echo "Modified start + Normal text" >normal.txt
142+
git commit -a --no-edit || fail "Start modification commit failed"
143+
144+
# 4.2 Modify end of file
145+
echo -e "Line 1\nLine 2\nLine 3\nLine 4" >multiline.txt
146+
git commit -a --no-edit || fail "End modification commit failed"
147+
148+
# 4.3 Modify middle of file
149+
echo -e "Line 1\nNew Line\nLine 3\nLine 4" >multiline.txt
150+
git commit -a --no-edit || fail "Middle modification commit failed"
151+
152+
# Test 5: Advanced Git Operations
153+
test_step "Advanced Git Operations"
154+
155+
# 5.1 Amend commit
156+
set prev_commit (last_commit)
157+
git commit --amend --no-edit || fail "Commit amend --no-edit failed"
158+
git status --porcelain || fail "Git status failed after amend --no-edit"
159+
last_commit | grep "$prev_commit" || fail "Amended commit message not found"
160+
161+
# 5.2 Commit with template
162+
echo "Commit from template" >template.txt
163+
git add template.txt
164+
git commit -t template.txt --no-edit || true
165+
166+
# 5.3 Squash commits
167+
echo "Squash test" >squash.txt
168+
git add squash.txt
169+
git commit -m "Pre-squash commit" || fail "Pre-squash commit failed"
170+
git reset --soft HEAD~1 || fail "Reset failed"
171+
git commit --squash HEAD~2 -m "Squashed commit" || fail "Squash commit failed"
172+
last_commit | grep "Squashed commit" || fail "Squash commit message not found"
173+
174+
# Test 6: Branch and Merge Operations
175+
test_step "Branch and Merge Operations"
176+
177+
# 6.1 Feature branch
178+
git checkout -b feature-branch || fail "Checkout to feature-branch failed"
179+
echo "Feature branch change" >feature.txt
180+
git add feature.txt
181+
git commit -m "Feature commit" || fail "Feature branch commit failed"
182+
last_commit | grep "Feature commit" || fail "Feature branch commit message not found"
183+
184+
# 6.2 Merge
185+
git checkout main || fail "Checkout to main failed"
186+
git merge --no-edit --no-ff feature-branch || fail "Merge feature-branch failed"
187+
last_commit | grep "Merge branch 'feature-branch'" || fail "Merge commit message not found"
188+
189+
# Test 7: File Operations
190+
test_step "File Operations"
191+
192+
# 7.1 File deletions
193+
rm empty_file.txt
194+
git add --all
195+
git commit -a --no-edit || fail "Single deletion commit failed"
196+
197+
rm empty1.txt empty2.txt
198+
git add --all
199+
git commit -a --no-edit || fail "Multiple deletions commit failed"
200+
201+
# 7.2 Mixed operations
202+
touch new_file1.txt
203+
rm empty3.txt
204+
echo "Modified again" >normal.txt
205+
git add --all
206+
git commit -a --no-edit || fail "Mixed operations commit failed"
207+
208+
# Test 8: Special Content
209+
test_step "Special Content"
210+
211+
# 8.1 Binary and large files
212+
generate_random_content 1048576 >large_file.bin
213+
git add large_file.bin
214+
git commit -m "Add binary file large_file.bin (1MB)" || fail "Large file commit failed"
215+
216+
# 8.2 Special characters
217+
echo "Special chars: ¡™£¢∞§¶•ªº" >special_chars.txt
218+
git add special_chars.txt
219+
git commit -a --no-edit || fail "Special chars commit failed"
220+
221+
# 8.3 Unicode content
222+
echo "🚀 Unicode content 你好 привет" >unicode_file.txt
223+
git add unicode_file.txt
224+
git commit -a --no-edit || fail "Unicode commit failed"
225+
226+
# Test 9: File System Operations
227+
test_step "File System Operations"
228+
229+
# 9.1 Directory operations
230+
mkdir -p src/nested/deep
231+
echo "Moving file" >src/nested/deep/file.txt
232+
git add src
233+
git commit -a --no-edit || fail "Initial directory commit failed"
234+
git mv src dst
235+
git commit -a --no-edit || fail "Directory move commit failed"
236+
237+
# 9.2 Symlink operations
238+
ln -s dst/nested/deep/file.txt symlink.txt
239+
git add symlink.txt
240+
git commit -a --no-edit || fail "Symlink creation commit failed"
241+
242+
# 9.3 Permission changes
243+
chmod +x dst/nested/deep/file.txt
244+
git add --all
245+
git commit -a --no-edit || fail "Permission change commit failed"
246+
247+
# Test 10: Edge Cases
248+
test_step "Edge Cases"
249+
250+
# 10.1 Empty commit (should fail)
251+
if git commit --allow-empty --no-edit
252+
fail "Empty commit should have failed but succeeded"
253+
end
254+
echo "Empty commit failed as expected"
255+
256+
# 10.2 Case sensitivity
257+
echo "Case sensitive" >case.txt
258+
git add case.txt
259+
git commit -a --no-edit || fail "Case file commit failed"
260+
git mv case.txt CASE.txt
261+
git commit -a --no-edit || fail "Case rename commit failed"
262+
263+
# 10.3 File/directory conversion
264+
rm dst/nested/deep/file.txt
265+
mkdir dst/nested/deep/file.txt
266+
echo "Now a directory" >dst/nested/deep/file.txt/content.txt
267+
git add --all
268+
git commit -a --no-edit || fail "File to directory commit failed"
269+
270+
rm -rf dst/nested/deep/file.txt
271+
echo "Now a file again" >dst/nested/deep/file.txt
272+
git add --all
273+
git commit -a --no-edit || fail "Directory to file commit failed"
274+
275+
# Test 11: Bulk Operations
276+
test_step "Bulk Operations"
277+
278+
# 11.1 Many files
279+
for i in (seq 1 100)
280+
echo "Content $i" >"file$i.txt"
281+
end
282+
git add .
283+
git commit -a --no-edit || fail "Many files commit failed"
284+
285+
# 11.2 Many changes
286+
for i in (seq 1 1000)
287+
echo "Line $i" >>large_changes.txt
288+
end
289+
git add large_changes.txt
290+
git commit -a --no-edit || fail "Many changes commit failed"
291+
292+
echo "All comprehensive tests completed successfully!"

0 commit comments

Comments
 (0)