|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # Validator for Lesson 14: CLI Tools & MCP Servers |
3 | | -# Checks that tasks.db exists with a tasks table and at least one row. |
| 3 | +# Checks that api-response.json exists with valid JSON content. |
4 | 4 |
|
5 | 5 | set -euo pipefail |
6 | 6 |
|
7 | 7 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
8 | 8 | REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" |
9 | | -DB_FILE="$REPO_ROOT/exercises/sample-app/tasks.db" |
| 9 | +JSON_FILE="$REPO_ROOT/exercises/sample-app/api-response.json" |
10 | 10 |
|
11 | | -# Check 1: tasks.db must exist |
12 | | -if [ ! -f "$DB_FILE" ]; then |
13 | | - echo "[LESSON 14] INCOMPLETE: exercises/sample-app/tasks.db does not exist" |
| 11 | +# Check 1: api-response.json must exist |
| 12 | +if [ ! -f "$JSON_FILE" ]; then |
| 13 | + echo "[LESSON 14] INCOMPLETE: exercises/sample-app/api-response.json does not exist" |
14 | 14 | exit 1 |
15 | 15 | fi |
16 | | -echo "[LESSON 14] tasks.db found" |
| 16 | +echo "[LESSON 14] api-response.json found" |
17 | 17 |
|
18 | | -# Check 2: Must contain a tasks table |
19 | | -if sqlite3 "$DB_FILE" ".tables" 2>/dev/null | grep -q "tasks"; then |
20 | | - echo "[LESSON 14] tasks table found" |
21 | | -else |
22 | | - echo "[LESSON 14] INCOMPLETE: tasks.db does not contain a 'tasks' table" |
| 18 | +# Check 2: Must contain valid JSON (use Node.js — guaranteed available) |
| 19 | +if ! node -e "JSON.parse(require('fs').readFileSync('$JSON_FILE', 'utf8'))" 2>/dev/null; then |
| 20 | + echo "[LESSON 14] INCOMPLETE: api-response.json does not contain valid JSON" |
23 | 21 | exit 1 |
24 | 22 | fi |
| 23 | +echo "[LESSON 14] valid JSON" |
25 | 24 |
|
26 | | -# Check 3: Must have at least one row |
27 | | -ROW_COUNT=$(sqlite3 "$DB_FILE" "SELECT COUNT(*) FROM tasks;" 2>/dev/null || echo "0") |
28 | | -if [ "$ROW_COUNT" -ge 3 ]; then |
29 | | - echo "[LESSON 14] tasks table has $ROW_COUNT row(s)" |
| 25 | +# Check 3: Must have at least one entry (array with length > 0) |
| 26 | +ENTRY_COUNT=$(node -e "const d = JSON.parse(require('fs').readFileSync('$JSON_FILE', 'utf8')); console.log(Array.isArray(d) ? d.length : 1)" 2>/dev/null || echo "0") |
| 27 | +if [ "$ENTRY_COUNT" -ge 1 ]; then |
| 28 | + echo "[LESSON 14] JSON contains $ENTRY_COUNT entry/entries" |
30 | 29 | else |
31 | | - echo "[LESSON 14] INCOMPLETE: tasks table has $ROW_COUNT row(s) — insert at least three sample tasks" |
| 30 | + echo "[LESSON 14] INCOMPLETE: api-response.json appears to be empty" |
32 | 31 | exit 1 |
33 | 32 | fi |
34 | 33 |
|
|
0 commit comments