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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# Manual Testing Guide - Unity Catalog Chatbot

## Prerequisites Checklist

Before starting, ensure you have:
- [ ] Databricks workspace access
- [ ] Databricks personal access token (PAT)
- [ ] Anthropic API key
- [ ] Python 3.9+ installed OR Docker installed
- [ ] All project files downloaded

---

## Quick Start - Local Deployment

### Step 1: Setup Environment

```bash
# Navigate to project directory
cd unity-catalog-chatbot

# Copy environment template
cp .env.example .env

# Edit .env file with your credentials
nano .env
```

**Edit `.env` file:**
```bash
DATABRICKS_HOST=https://your-workspace.cloud.databricks.net
DATABRICKS_TOKEN=dapi1234567890abcdef
ANTHROPIC_API_KEY=sk-ant-api03-xxxxx
```

### Step 2: Run Automated Deployment

```bash
# Make script executable
chmod +x deploy.sh

# Run deployment
./deploy.sh
```

The script will:
1. Check prerequisites
2. Configure environment
3. Install dependencies
4. Start the application
5. Run health checks
6. Perform basic tests

### Step 3: Verify Deployment

**Check if application is running:**
```bash
curl http://localhost:5000/api/health
```

**Expected response:**
```json
{
  "status": "healthy",
  "service": "Unity Catalog Chatbot API",
  "timestamp": "2025-01-01T00:00:00Z"
}
```

---

## Manual Testing Scenarios

### Test 1: Help Command

**Objective:** Verify chatbot responds to help requests

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "help"}'
```

**Expected Response:**
- `success: true`
- Message contains: "Creating Objects", "Managing Permissions", "Listing Objects"

**Pass Criteria:** βœ… Chatbot returns helpful information about available commands

---

### Test 2: List All Catalogs

**Objective:** Verify chatbot can list existing Unity Catalog catalogs

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "list all catalogs"}'
```

**Expected Response:**
```json
{
  "success": true,
  "message": "Found X catalog(s)",
  "sql": "SHOW CATALOGS",
  "data": {
    "catalogs": [...]
  }
}
```

**Pass Criteria:** βœ… Returns list of catalogs from your Databricks workspace

---

### Test 3: Create a Catalog

**Objective:** Test catalog creation

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "create a catalog named test_chatbot_catalog"}'
```

**Expected Response:**
```json
{
  "success": true,
  "message": "Successfully created catalog 'test_chatbot_catalog'",
  "sql": "CREATE CATALOG IF NOT EXISTS test_chatbot_catalog",
  "catalog": {
    "name": "test_chatbot_catalog",
    "owner": "your@email.com"
  }
}
```

**Verify in Databricks:**
```sql
-- Run this in Databricks SQL editor
SHOW CATALOGS;
-- Should see test_chatbot_catalog
```

**Pass Criteria:** βœ… Catalog appears in Databricks Unity Catalog

---

### Test 4: Create a Schema

**Objective:** Test schema creation

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "create schema analytics in test_chatbot_catalog"}'
```

**Expected Response:**
```json
{
  "success": true,
  "message": "Successfully created schema 'test_chatbot_catalog.analytics'",
  "sql": "CREATE SCHEMA IF NOT EXISTS test_chatbot_catalog.analytics"
}
```

**Verify in Databricks:**
```sql
SHOW SCHEMAS IN test_chatbot_catalog;
-- Should see analytics schema
```

**Pass Criteria:** βœ… Schema appears in the catalog

---

### Test 5: Create a Table

**Objective:** Test table creation

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "create table test_chatbot_catalog.analytics.customers"}'
```

**Expected Response:**
```json
{
  "success": true,
  "message": "Successfully created table 'test_chatbot_catalog.analytics.customers'",
  "sql": "CREATE TABLE IF NOT EXISTS test_chatbot_catalog.analytics.customers (...) USING DELTA"
}
```

**Verify in Databricks:**
```sql
SHOW TABLES IN test_chatbot_catalog.analytics;
-- Should see customers table

DESCRIBE TABLE test_chatbot_catalog.analytics.customers;
-- Should show default columns: id, created_at, data
```

**Pass Criteria:** βœ… Table is created with default schema

---

### Test 6: Grant Permissions

**Objective:** Test permission granting

**Setup:** Replace `test_user@example.com` with a real user in your workspace

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "grant SELECT on test_chatbot_catalog.analytics to test_user@example.com"}'
```

**Expected Response:**
```json
{
  "success": true,
  "message": "Granted SELECT on 'test_chatbot_catalog.analytics' to 'test_user@example.com'",
  "sql": "GRANT SELECT ON test_chatbot_catalog.analytics TO `test_user@example.com`"
}
```

**Verify in Databricks:**
```sql
SHOW GRANTS ON SCHEMA test_chatbot_catalog.analytics;
-- Should show SELECT permission for test_user@example.com
```

**Pass Criteria:** βœ… Permission is granted successfully

---

### Test 7: Show Permissions

**Objective:** Verify permission listing

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "show permissions for test_chatbot_catalog.analytics"}'
```

**Expected Response:**
```json
{
  "success": true,
  "message": "Permissions for 'test_chatbot_catalog.analytics'",
  "sql": "SHOW GRANTS ON test_chatbot_catalog.analytics",
  "data": {
    "permissions": [
      {
        "principal": "test_user@example.com",
        "privileges": ["SELECT"]
      }
    ]
  }
}
```

**Pass Criteria:** βœ… Returns list of permissions

---

### Test 8: Revoke Permissions

**Objective:** Test permission revocation

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "revoke SELECT on test_chatbot_catalog.analytics from test_user@example.com"}'
```

**Expected Response:**
```json
{
  "success": true,
  "message": "Revoked SELECT on 'test_chatbot_catalog.analytics' from 'test_user@example.com'",
  "sql": "REVOKE SELECT ON test_chatbot_catalog.analytics FROM `test_user@example.com`"
}
```

**Verify in Databricks:**
```sql
SHOW GRANTS ON SCHEMA test_chatbot_catalog.analytics;
-- Should NOT show SELECT permission for test_user@example.com
```

**Pass Criteria:** βœ… Permission is revoked successfully

---

### Test 9: Complex Query

**Objective:** Test multi-part natural language query

**Request:**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "I need to create a new catalog for our sales team called sales_data, then create a schema called staging in it"}'
```

**Expected Response:**
- Should recognize intent to create catalog
- May ask for clarification or execute first step

**Pass Criteria:** βœ… Chatbot understands complex intent

---

### Test 10: Error Handling

**Objective:** Test invalid requests

**Request (Invalid catalog name):**
```bash
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "create a catalog named invalid-name-with-dashes"}'
```

**Expected Behavior:**
- May attempt creation and get error from Databricks
- Should return error message to user

**Pass Criteria:** βœ… Errors are handled gracefully

---

## Automated Testing

### Run Full Test Suite

```bash
# Make test script executable
chmod +x test.sh

# Run all automated tests
./test.sh
```

**The test script will:**
1. Test basic connectivity
2. Test help commands
3. Test catalog operations
4. Test schema operations
5. Test table operations
6. Test permissions
7. Test complex queries
8. Test error handling
9. Run performance tests
10. Generate test report

**View Test Report:**
```bash
cat test_report.txt
```

---

## Performance Testing

### Response Time Test

```bash
# Measure response time
time curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "help"}'
```

**Expected:** Response < 3 seconds

### Load Test (Optional)

```bash
# Install Apache Bench
sudo apt-get install apache2-utils  # Ubuntu/Debian

# Run load test (100 requests, 10 concurrent)
ab -n 100 -c 10 -T 'application/json' \
  -p <(echo '{"message":"help"}') \
  http://localhost:5000/api/chat
```

---

## Frontend Testing (React Component)

### Test in Browser

1. **Create a simple HTML file:**

```html
<!DOCTYPE html>
<html>
<head>
  <title>Unity Catalog Chatbot</title>
</head>
<body>
  <div id="root"></div>
  
  <!-- Include React and dependencies -->
  <script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
  
  <!-- Include your compiled chatbot component -->
  <script src="unity-catalog-chatbot.js"></script>
</body>
</html>
```

2. **Test interactions:**
- Type messages in chat input
- Click quick action buttons
- Verify messages appear
- Check action log updates
- Verify SQL commands display

---

## Cleanup After Testing

```bash
# Delete test catalog and all contents
curl -X POST http://localhost:5000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "delete catalog test_chatbot_catalog"}'

# Or manually in Databricks SQL:
DROP CATALOG IF EXISTS test_chatbot_catalog CASCADE;
```

---

## Troubleshooting

### Issue: Application won't start

**Check logs:**
```bash
# For local deployment
tail -f app.log

# For Docker
docker logs unity-catalog-chatbot

# For Docker Compose
docker-compose logs -f
```

**Common fixes:**
- Verify .env credentials are correct
- Check port 5000 is not in use: `lsof -i :5000`
- Ensure dependencies are installed

---

### Issue: Databricks connection failed

**Test Databricks connectivity:**
```bash
curl -H "Authorization: Bearer $DATABRICKS_TOKEN" \
  $DATABRICKS_HOST/api/2.0/clusters/list
```

**Common fixes:**
- Verify DATABRICKS_HOST has https://
- Check token hasn't expired
- Ensure network allows connection to Databricks

---

### Issue: Claude API errors

**Test Anthropic API:**
```bash
curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-4-20250514","max_tokens":100,"messages":[{"role":"user","content":"test"}]}'
```

**Common fixes:**
- Verify API key is correct (starts with sk-ant-)
- Check API credits/billing
- Ensure internet connectivity

---

## Success Criteria

Your deployment is successful when:
- [x] Health check returns 200 OK
- [x] Help command returns useful information
- [x] Can list existing catalogs
- [x] Can create a new catalog
- [x] Can create schemas and tables
- [x] Can grant and revoke permissions
- [x] SQL commands are generated correctly
- [x] Action log tracks operations
- [x] Error messages are clear and helpful

---

## Next Steps

After successful testing:
1. Review logs for any warnings
2. Customize chatbot prompts if needed
3. Add user authentication for production
4. Set up monitoring and alerts
5. Deploy to production environment
6. Document custom workflows
7. Train team on usage

---

## Support

If you encounter issues:
1. Check logs first
2. Review DEPLOYMENT.md for detailed guides
3. Test individual components separately
4. Verify all credentials are valid
5. Check network connectivity

**Happy Testing! πŸš€**