-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.sh
More file actions
253 lines (133 loc) · 4.29 KB
/
commands.sh
File metadata and controls
253 lines (133 loc) · 4.29 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/env bash
# Lab 30 - AI Test Suggestion Pipeline
# Commands executed during the lab
# Install Required Tools
sudo apt update
sudo apt install -y python3 python3-pip python3-venv git curl
mkdir -p ~/ai-test-pipeline
cd ~/ai-test-pipeline
python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip
pip install openai gitpython requests
# Step 1: Create Project Structure
cd ~/ai-test-pipeline
mkdir -p src tests sample_project suggestions
touch src/code_analyzer.py src/test_suggester.py src/pipeline.py
find . -maxdepth 2 -type d -o -type f | sort
# Create `src/code_analyzer.py`
nano ~/ai-test-pipeline/src/code_analyzer.py
# Syntax verification
python3 -m py_compile src/code_analyzer.py
echo $?
# Create `sample_project/calculator.py`
nano ~/ai-test-pipeline/sample_project/calculator.py
# Initialize the Git repository
cd ~/ai-test-pipeline/sample_project
git init
git config user.name "Lab User"
git config user.email "lab@example.com"
git add calculator.py
git commit -m "Initial calculator implementation"
# Verify git state
git log --oneline --decorate
# Create `tests/test_analyzer.py`
cd ~/ai-test-pipeline
nano ~/ai-test-pipeline/tests/test_analyzer.py
# Run the analyzer test
cd ~/ai-test-pipeline
source venv/bin/activate
python3 tests/test_analyzer.py
# Additional realistic changed-file check
python3 - <<'PY'
import sys
from pathlib import Path
project_root = Path.cwd()
sys.path.insert(0, str(project_root / "src"))
from code_analyzer import CodeAnalyzer
analyzer = CodeAnalyzer(str(project_root / "sample_project"))
print(analyzer.get_changed_files("HEAD~1..HEAD"))
PY
# Install Ollama for local AI inference
curl -fsSL https://ollama.com/install.sh | sh
sudo systemctl enable --now ollama 2>/dev/null || true
pgrep -x ollama >/dev/null || nohup ollama serve >/tmp/ollama.log 2>&1 &
sleep 5
ollama pull codellama:7b
ollama list
# Verify Ollama listener
ss -tulpen | grep 11434
# Create `src/test_suggester.py`
nano ~/ai-test-pipeline/src/test_suggester.py
# Syntax verification
python3 -m py_compile src/test_suggester.py
echo $?
# Create `src/pipeline.py`
nano ~/ai-test-pipeline/src/pipeline.py
# Syntax verification
python3 -m py_compile src/pipeline.py
echo $?
# Step 4: Run the Complete Pipeline
cd ~/ai-test-pipeline
source venv/bin/activate
python3 src/pipeline.py --repo ./sample_project --output ./suggestions
# Inspect JSON output
cat suggestions/test_suggestions.json
# Inspect Markdown report
cat suggestions/report.md
# Update `sample_project/calculator.py`
nano ~/ai-test-pipeline/sample_project/calculator.py
# Commit the change
cd ~/ai-test-pipeline/sample_project
git add calculator.py
git commit -m "Add tax calculation with regional logic"
# Verify commit history
git log --oneline --decorate -2
# Run the pipeline on this change
cd ~/ai-test-pipeline
source venv/bin/activate
python3 src/pipeline.py --repo ./sample_project --output ./suggestions --commit-range HEAD~1..HEAD
# Verify Code Analyzer
cd ~/ai-test-pipeline
source venv/bin/activate
python3 tests/test_analyzer.py
# Check Ollama model availability
ollama list
# Check output directory exists
ls -la suggestions/
# Verify JSON output structure
python3 -m json.tool suggestions/test_suggestions.json
# Check report generated
cat suggestions/report.md
# Quick grep for `calculate_tax`
grep -n "calculate_tax" -A 40 suggestions/report.md
# Check Ollama service
systemctl status ollama
# Restart if needed
sudo systemctl restart ollama
systemctl status ollama | head -8
# If not managed by systemd
pkill ollama
nohup ollama serve >/tmp/ollama.log 2>&1 &
sleep 5
ss -tulpen | grep 11434
# Ensure `sample_project` is initialized
cd ~/ai-test-pipeline/sample_project
git status
# If Git user identity is missing, set it locally
git config user.name "Lab User"
git config user.email "lab@example.com"
git config --list | grep '^user\.'
# Verify virtual environment is activated
which python3
source ~/ai-test-pipeline/venv/bin/activate
which python3
# Reinstall packages if needed
cd ~/ai-test-pipeline
source venv/bin/activate
pip install --force-reinstall openai gitpython requests
# AST parsing errors
python3 -m py_compile src/code_analyzer.py src/test_suggester.py src/pipeline.py sample_project/calculator.py
echo $?
# Final project snapshot
ls -R