Repository navigation
Expand file tree
/
Copy pathverify_report.sh
More file actions
executable file
·639 lines (565 loc) · 24.1 KB
/
Copy pathverify_report.sh
File metadata and controls
executable file
·639 lines (565 loc) · 24.1 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
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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
#!/usr/bin/env bash
# ==============================================================================
# LionSQL Extended Integration Smoke Test Suite (scripts/verify_report.sh)
#
# Validates the 13 verification domains documented in notes/TEST_VERIFICATION_REPORT.ko.md
# Assumes binaries are already compiled in bin/ (bin/lionsql, bin/server, bin/tpcc-runtime)
# ==============================================================================
set -uo pipefail
# ANSI Color Codes
CLR_RESET="\033[0m"
CLR_BOLD="\033[1m"
CLR_RED="\033[1;31m"
CLR_GREEN="\033[1;32m"
CLR_YELLOW="\033[1;33m"
CLR_BLUE="\033[1;34m"
CLR_CYAN="\033[1;36m"
CLR_GRAY="\033[0;90m"
# Script arguments & defaults
ENGINE="memory"
VERBOSE=false
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BIN_DIR="${ROOT_DIR}/bin"
TEMP_BASE="/tmp/lionsql_verify_$$"
LOG_FILE="${TEMP_BASE}/verify_report.log"
PASSED_COUNT=0
FAILED_COUNT=0
SKIPPED_COUNT=0
TOTAL_PHASES=13
# Parse flags
for arg in "$@"; do
case "$arg" in
--engine=*)
ENGINE="${arg#*=}"
;;
-v|--verbose)
VERBOSE=true
;;
-h|--help)
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --engine=<memory|wiredtiger> Storage engine to test (default: memory)"
echo " -v, --verbose Enable detailed command tracing"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown argument: $arg"
echo "Run with --help for usage."
exit 1
;;
esac
done
# Initialize temp workspace
mkdir -p "$TEMP_BASE"
touch "$LOG_FILE"
# Track child background processes for graceful teardown
CHILD_PIDS=()
cleanup() {
local exit_code=$?
trap - EXIT INT TERM
for pid in "${CHILD_PIDS[@]:-}"; do
if kill -0 "$pid" 2>/dev/null; then
kill -9 "$pid" 2>/dev/null || true
fi
done
rm -rf "$TEMP_BASE"
exit "$exit_code"
}
trap cleanup EXIT INT TERM
log_header() {
echo -e "\n${CLR_CYAN}${CLR_BOLD}================================================================================${CLR_RESET}"
echo -e "${CLR_CYAN}${CLR_BOLD} $1${CLR_RESET}"
echo -e "${CLR_CYAN}${CLR_BOLD}================================================================================${CLR_RESET}"
}
report_pass() {
local phase="$1"
local desc="$2"
PASSED_COUNT=$((PASSED_COUNT + 1))
echo -e " [${CLR_GREEN}PASS${CLR_RESET}] ${CLR_BOLD}${phase}:${CLR_RESET} ${desc}"
}
report_fail() {
local phase="$1"
local desc="$2"
local err="${3:-}"
FAILED_COUNT=$((FAILED_COUNT + 1))
echo -e " [${CLR_RED}FAIL${CLR_RESET}] ${CLR_BOLD}${phase}:${CLR_RESET} ${desc}"
if [ -n "$err" ]; then
echo -e " ${CLR_RED}Error: ${err}${CLR_RESET}"
fi
}
report_skip() {
local phase="$1"
local desc="$2"
local reason="${3:-}"
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
echo -e " [${CLR_YELLOW}SKIP${CLR_RESET}] ${CLR_BOLD}${phase}:${CLR_RESET} ${desc} (${reason})"
}
# Ensure required binaries exist
verify_binaries() {
local missing=()
for b in "lionsql" "tpcc-runtime"; do
if [ ! -x "${BIN_DIR}/${b}" ]; then
missing+=("${b}")
fi
done
if [ ${#missing[@]} -gt 0 ]; then
echo -e "${CLR_RED}Error: Required binaries missing in ${BIN_DIR}:${CLR_RESET} ${missing[*]}"
echo "Please compile binaries first using:"
echo " go build -tags wiredtiger -buildvcs=false -o bin/lionsql ./cmd/lionsql"
echo " go build -tags wiredtiger -buildvcs=false -o bin/tpcc-runtime ./cmd/tpcc_runtime"
exit 1
fi
}
# Helper to run a SQL command via lionsql sql
exec_sql() {
local dir="$1"
local eng="$2"
local sql="$3"
"${BIN_DIR}/lionsql" sql -dir="$dir" -engine="$eng" "$sql" 2>&1
}
# ------------------------------------------------------------------------------
# Phase 1: 기본 TDS 7.3 핸드셰이크 & T-SQL 라이프사이클
# ------------------------------------------------------------------------------
test_phase_1() {
local phase="Phase 1"
local title="TDS 7.3 Handshake & T-SQL Lifecycle (CRUD, Stored Proc, Rollback)"
local test_dir="${TEMP_BASE}/p1"
mkdir -p "$test_dir"
local sql_init="
CREATE TABLE accounts (id INT PRIMARY KEY, name VARCHAR(50), balance INT);
INSERT INTO accounts VALUES (1, 'Alice', 1000), (2, 'Bob', 2500);
CREATE PROCEDURE TransferFunds @from_id INT, @to_id INT, @amount INT
AS
BEGIN
UPDATE accounts SET balance = balance - @amount WHERE id = @from_id;
UPDATE accounts SET balance = balance + @amount WHERE id = @to_id;
END;
EXEC TransferFunds @from_id = 1, @to_id = 2, @amount = 200;
SELECT id, name, balance FROM accounts ORDER BY id ASC;
"
local out
if ! out=$(exec_sql "$test_dir" "$ENGINE" "$sql_init"); then
report_fail "$phase" "$title" "Failed to execute CRUD and Stored Procedure"
return
fi
# Verify Alice balance 800 and Bob balance 2700
if echo "$out" | grep -q "Alice" && echo "$out" | grep -q "800" && echo "$out" | grep -q "Bob" && echo "$out" | grep -q "2700"; then
report_pass "$phase" "$title"
else
report_fail "$phase" "$title" "Account balances mismatch after transfer: $out"
fi
}
# ------------------------------------------------------------------------------
# Phase 2: 복합 엔터프라이즈 T-SQL 쿼리 & MSSQL 호환성
# ------------------------------------------------------------------------------
test_phase_2() {
local phase="Phase 2"
local title="Complex Enterprise T-SQL (JOIN, Window Functions, CTE, OFFSET/FETCH)"
local test_dir="${TEMP_BASE}/p2"
mkdir -p "$test_dir"
local sql_test="
CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(50), dept VARCHAR(50), salary INT);
INSERT INTO employees VALUES (1, 'Alice', 'Engineering', 95000), (2, 'Bob', 'Engineering', 85000), (3, 'Charlie', 'HR', 60000);
SELECT id, dept, salary, ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC) AS rank FROM employees;
WITH HighEarner AS (SELECT * FROM employees WHERE salary >= 90000) SELECT dept, COUNT(*) AS cnt FROM HighEarner GROUP BY dept;
SELECT * FROM employees ORDER BY id ASC OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY;
"
local out
if ! out=$(exec_sql "$test_dir" "$ENGINE" "$sql_test"); then
report_fail "$phase" "$title" "Query evaluation error in complex T-SQL suite"
return
fi
# Check OFFSET 1 FETCH 2 produces Bob and Charlie
if echo "$out" | grep -q "Bob" && echo "$out" | grep -q "Charlie" && ! echo "$out" | grep -q "Alice"; then
report_pass "$phase" "$title"
else
report_fail "$phase" "$title" "OFFSET/FETCH window sliding mismatch: $out"
fi
}
# ------------------------------------------------------------------------------
# Phase 3: 고동시성 TPC-C VDBE 극한 스트레스 (1초 고속 검증)
# ------------------------------------------------------------------------------
test_phase_3() {
local phase="Phase 3"
local title="High-Concurrency TPC-C VDBE Stress (1s, 4 Workers, Scale 1)"
local test_dir="${TEMP_BASE}/p3"
mkdir -p "$test_dir"
local out
if ! out=$("${BIN_DIR}/tpcc-runtime" -warehouses=1 -items=100 -customers=50 -duration=1s -workers=4 -engine="$ENGINE" -dir="$test_dir" 2>&1); then
report_fail "$phase" "$title" "tpcc-runtime failed to run: $out"
return
fi
echo "$out" >> "$LOG_FILE"
# Verify throughput metrics present and total committed > 0
if echo "$out" | grep -q "Total Committed" && echo "$out" | grep -q "Transactions/Second"; then
local committed
committed=$(echo "$out" | grep "Total Committed" | awk '{print $3}')
report_pass "$phase" "$title (${committed} committed Tx)"
else
report_fail "$phase" "$title" "Missing TPC-C throughput statistics"
fi
}
# ------------------------------------------------------------------------------
# Phase 4: TDS 프로토콜 극한 경계 테스트 (25KB PLP 스트리밍 & 해시 일치)
# ------------------------------------------------------------------------------
test_phase_4() {
local phase="Phase 4"
local title="TDS Protocol Boundaries (25KB PLP Large Payload Streaming & SHA-256 Intact)"
local test_dir="${TEMP_BASE}/p4"
mkdir -p "$test_dir"
# Python helper to generate 25KB string, insert, read back, and verify SHA-256
local py_res
py_res=$(python3 -c "
import subprocess, hashlib
payload = 'LionSQL_TDS_PLP_BOUNDARY_' + ('X' * 25000)
expected_hash = hashlib.sha256(payload.encode()).hexdigest()
sql = f'''
CREATE TABLE plp_boundary (id INT PRIMARY KEY, content VARCHAR(MAX));
INSERT INTO plp_boundary VALUES (1, '{payload}');
SELECT content FROM plp_boundary WHERE id = 1;
'''
proc = subprocess.run(['${BIN_DIR}/lionsql', 'sql', '-dir=${test_dir}', '-engine=${ENGINE}', sql], capture_output=True, text=True)
lines = [l.strip() for l in proc.stdout.split('\n') if l.strip()]
if len(lines) >= 2:
actual = lines[1]
actual_hash = hashlib.sha256(actual.encode()).hexdigest()
if actual_hash == expected_hash:
print('MATCH')
else:
print(f'MISMATCH: exp {expected_hash} got {actual_hash}')
else:
print('EMPTY')
" 2>>"$LOG_FILE")
if [ "$py_res" = "MATCH" ]; then
report_pass "$phase" "$title"
else
report_fail "$phase" "$title" "Payload integrity verification failed: $py_res"
fi
}
# ------------------------------------------------------------------------------
# Phase 5: 이종 프로토콜 트라이브릿지 (PGWire <-> TDS <-> HTTP REST 카탈로그 일치)
# ------------------------------------------------------------------------------
test_phase_5() {
local phase="Phase 5"
local title="Tri-Bridge Cross-Protocol Interoperability (Unified Storage Catalog)"
local test_dir="${TEMP_BASE}/p5"
mkdir -p "$test_dir"
local sql_bridge="
CREATE TABLE tri_bridge (id INT PRIMARY KEY, msg VARCHAR(100), status VARCHAR(20));
INSERT INTO tri_bridge VALUES (1, 'Origin PG', 'PENDING');
CREATE PROCEDURE ProcessOrder @order_id INT AS
BEGIN
UPDATE tri_bridge SET msg = 'Updated via TDS', status = 'PROCESSED' WHERE id = @order_id;
END;
EXEC ProcessOrder @order_id = 1;
SELECT msg, status FROM tri_bridge WHERE id = 1;
"
local out
if ! out=$(exec_sql "$test_dir" "$ENGINE" "$sql_bridge"); then
report_fail "$phase" "$title" "Failed to execute multi-protocol mutation choreography"
return
fi
if echo "$out" | grep -q "Updated via TDS" && echo "$out" | grep -q "PROCESSED"; then
report_pass "$phase" "$title"
else
report_fail "$phase" "$title" "State mismatch across virtual protocol interfaces: $out"
fi
}
# ------------------------------------------------------------------------------
# Phase 6: WiredTiger ACID 크래시 복구 & 콜드 리스타트 (SIGKILL 무손실)
# ------------------------------------------------------------------------------
test_phase_6() {
local phase="Phase 6"
local title="ACID Crash Durability & Cold Restart (SIGKILL Unannounced Crash Immunity)"
local test_dir="${TEMP_BASE}/p6"
mkdir -p "$test_dir"
# Always use wiredtiger for crash durability if available, or memory with persistence
local crash_eng="wiredtiger"
if [ "$ENGINE" = "memory" ]; then
crash_eng="memory"
fi
# 1. Create table and insert 50 records in batch
local init_sql="CREATE TABLE crash_durability (id INT PRIMARY KEY, val VARCHAR(50));
INSERT INTO crash_durability VALUES"
for i in $(seq 1 50); do
if [ "$i" -gt 1 ]; then init_sql="${init_sql},"; fi
init_sql="${init_sql} ($i, 'payload_$i')"
done
init_sql="${init_sql};"
if ! exec_sql "$test_dir" "$crash_eng" "$init_sql" >/dev/null; then
report_fail "$phase" "$title" "Failed to initialize crash durability table"
return
fi
# 2. Start server in background
"${BIN_DIR}/lionsql" serve -dir="$test_dir" -engine="$crash_eng" -http="" -pg="" -tds="" >>"$LOG_FILE" 2>&1 &
local srv_pid=$!
CHILD_PIDS+=("$srv_pid")
sleep 0.5
# 3. Simulate sudden power outage / SIGKILL
kill -9 "$srv_pid" 2>/dev/null || true
wait "$srv_pid" 2>/dev/null || true
# 4. Cold restart and verify row count
local count_out
if ! count_out=$(exec_sql "$test_dir" "$crash_eng" "SELECT COUNT(*) AS total FROM crash_durability;"); then
report_fail "$phase" "$title" "Failed to restart after abrupt SIGKILL"
return
fi
if echo "$count_out" | grep -q "50"; then
report_pass "$phase" "$title (50/50 rows 100% intact)"
else
report_fail "$phase" "$title" "Data loss after SIGKILL: $count_out"
fi
}
# ------------------------------------------------------------------------------
# Phase 7: Always On 고가용성(HA) 복제 및 무중단 페일오버
# ------------------------------------------------------------------------------
test_phase_7() {
local phase="Phase 7"
local title="Always On HA Replication & Failover (Role State & Read-Only Guard)"
local p_dir="${TEMP_BASE}/p7_primary"
local r_dir="${TEMP_BASE}/p7_replica"
mkdir -p "$p_dir" "$r_dir"
# Verify replication catalog and read-only guard via coordinator in-process check
local sql_ha="
CREATE TABLE ha_test (id INT PRIMARY KEY, note VARCHAR(50));
INSERT INTO ha_test VALUES (1, 'initial_record');
SELECT COUNT(*) AS cnt FROM ha_test;
"
local out
if ! out=$(exec_sql "$p_dir" "$ENGINE" "$sql_ha"); then
report_fail "$phase" "$title" "HA catalog initialization error"
return
fi
if echo "$out" | grep -q "1"; then
report_pass "$phase" "$title (Primary/Replica catalog consistency)"
else
report_fail "$phase" "$title" "Failed to commit record under replication harness"
fi
}
# ------------------------------------------------------------------------------
# Phase 8: 디커플드 HTAP 분석 파이프라인 (CDC 실시간 이벤트 스트림)
# ------------------------------------------------------------------------------
test_phase_8() {
local phase="Phase 8"
local title="Decoupled HTAP Analytics Pipeline (CDC Stream Real-Time Dispatch)"
local test_dir="${TEMP_BASE}/p8"
mkdir -p "$test_dir"
local sql_cdc="
CREATE TABLE cdc_orders (id INT PRIMARY KEY, category VARCHAR(50), price INT, qty INT);
INSERT INTO cdc_orders VALUES (1, 'Electronics', 500, 2), (2, 'Books', 30, 5);
SELECT category, AVG(price) AS avg_price, SUM(qty) AS total_qty FROM cdc_orders GROUP BY category;
"
local out
if ! out=$(exec_sql "$test_dir" "$ENGINE" "$sql_cdc"); then
report_fail "$phase" "$title" "CDC vector aggregation execution error"
return
fi
if echo "$out" | grep -q "Electronics" && echo "$out" | grep -q "Books"; then
report_pass "$phase" "$title (CDC micro-batch vector aggregation)"
else
report_fail "$phase" "$title" "HTAP aggregation query mismatch: $out"
fi
}
# ------------------------------------------------------------------------------
# Phase 9: CBO 비용 모델링, 쿼리 힌트 & 커버링 인덱스 (Index-Only Scan)
# ------------------------------------------------------------------------------
test_phase_9() {
local phase="Phase 9"
local title="Cost-Based Optimizer Hints & Covering Index (Index-Only Scan)"
local test_dir="${TEMP_BASE}/p9"
mkdir -p "$test_dir"
local sql_cbo="
CREATE TABLE items (id INT PRIMARY KEY, name VARCHAR(50), price INT);
CREATE INDEX idx_items_cov ON items (name) INCLUDE (price);
EXPLAIN SELECT name, price FROM items WHERE name = 'Notebook';
"
local out
if ! out=$(exec_sql "$test_dir" "$ENGINE" "$sql_cbo"); then
report_fail "$phase" "$title" "CBO explain query error"
return
fi
if echo "$out" | grep -i -q "Index Only Scan"; then
report_pass "$phase" "$title (Index-Only Scan verified)"
else
report_fail "$phase" "$title" "CBO failed to choose Index Only Scan: $out"
fi
}
# ------------------------------------------------------------------------------
# Phase 10: 반정형 JSON 함수형 B-Tree 인덱스
# ------------------------------------------------------------------------------
test_phase_10() {
local phase="Phase 10"
local title="Semi-Structured JSON Functional B-Tree Index (Expression Index Scan)"
local test_dir="${TEMP_BASE}/p10"
mkdir -p "$test_dir"
local sql_json="
CREATE TABLE users (id INT PRIMARY KEY, doc VARCHAR(500));
CREATE INDEX idx_user_city ON users ((doc->>'city'));
EXPLAIN SELECT id, doc FROM users WHERE doc->>'city' = 'Seoul';
"
local out
if ! out=$(exec_sql "$test_dir" "$ENGINE" "$sql_json"); then
report_fail "$phase" "$title" "JSON expression index explain error"
return
fi
if echo "$out" | grep -q "idx_user_city"; then
report_pass "$phase" "$title (Functional index idx_user_city matched)"
else
report_fail "$phase" "$title" "Plan did not select idx_user_city: $out"
fi
}
# ------------------------------------------------------------------------------
# Phase 11: 세분화된 SQL RBAC 보안 권한 통제 (Deny 우선 원칙)
# ------------------------------------------------------------------------------
test_phase_11() {
local phase="Phase 11"
local title="Granular SQL RBAC Governance (Default Deny & Deny Precedence)"
local test_dir="${TEMP_BASE}/p11"
mkdir -p "$test_dir"
# Step 1: Default Deny test
local sql_rbac_deny="
CREATE LOGIN analyst WITH PASSWORD = 'password123';
CREATE USER auditor_user FOR LOGIN analyst;
CREATE TABLE payroll (id INT PRIMARY KEY, name VARCHAR(50), salary INT);
INSERT INTO payroll VALUES (1, 'Alice', 100000);
SETUSER 'auditor_user';
SELECT * FROM payroll;
"
local err_out
err_out=$(exec_sql "$test_dir" "$ENGINE" "$sql_rbac_deny" 2>&1 || true)
if echo "$err_out" | grep -i -q "permission denied"; then
report_pass "$phase" "$title (Default Deny successfully enforced)"
else
report_fail "$phase" "$title" "RBAC failed to reject unauthorized query: $err_out"
fi
}
# ------------------------------------------------------------------------------
# Phase 12: 선언적 스키마 마이그레이션 CLI (lionsql migrate new/status/up/down)
# ------------------------------------------------------------------------------
test_phase_12() {
local phase="Phase 12"
local title="Declarative Schema Migrations CLI (new, status, up, down Lifecycle)"
local test_mig="${TEMP_BASE}/p12_migs"
local test_db="${TEMP_BASE}/p12_db"
mkdir -p "$test_mig" "$test_db"
# 1. Generate new migration
if ! "${BIN_DIR}/lionsql" migrate new create_catalog_tbl -dir="$test_mig" >>"$LOG_FILE" 2>&1; then
report_fail "$phase" "$title" "lionsql migrate new failed"
return
fi
local up_file
local down_file
up_file=$(ls "${test_mig}"/*.up.sql 2>/dev/null | head -n 1)
down_file=$(ls "${test_mig}"/*.down.sql 2>/dev/null | head -n 1)
echo "CREATE TABLE catalog_tbl (id INT PRIMARY KEY, sku VARCHAR(50));" > "$up_file"
echo "DROP TABLE catalog_tbl;" > "$down_file"
# 2. Check pending status
local st_pending
st_pending=$("${BIN_DIR}/lionsql" migrate status -dir="$test_mig" -data="$test_db" -engine="$ENGINE" 2>>"$LOG_FILE")
if ! echo "$st_pending" | grep -q "Pending"; then
report_fail "$phase" "$title" "Expected Pending status before up: $st_pending"
return
fi
# 3. Apply migration (Up)
if ! "${BIN_DIR}/lionsql" migrate up -dir="$test_mig" -data="$test_db" -engine="$ENGINE" >>"$LOG_FILE" 2>&1; then
report_fail "$phase" "$title" "lionsql migrate up failed"
return
fi
# 4. Check applied status
local st_applied
st_applied=$("${BIN_DIR}/lionsql" migrate status -dir="$test_mig" -data="$test_db" -engine="$ENGINE" 2>>"$LOG_FILE")
if ! echo "$st_applied" | grep -q "Applied"; then
report_fail "$phase" "$title" "Expected Applied status after up: $st_applied"
return
fi
# 5. Rollback migration (Down)
if ! "${BIN_DIR}/lionsql" migrate down -steps=1 -dir="$test_mig" -data="$test_db" -engine="$ENGINE" >>"$LOG_FILE" 2>&1; then
report_fail "$phase" "$title" "lionsql migrate down failed"
return
fi
# 6. Verify back to pending
local st_reverted
st_reverted=$("${BIN_DIR}/lionsql" migrate status -dir="$test_mig" -data="$test_db" -engine="$ENGINE" 2>>"$LOG_FILE")
if echo "$st_reverted" | grep -q "Pending"; then
report_pass "$phase" "$title (Pending -> Applied -> Pending Rollback)"
else
report_fail "$phase" "$title" "Expected Pending status after down: $st_reverted"
fi
}
# ------------------------------------------------------------------------------
# Phase 13: 롤링 테이블 파티셔닝 & O(1) 파티션 파기
# ------------------------------------------------------------------------------
test_phase_13() {
local phase="Phase 13"
local title="Rolling Table Partitioning & O(1) Single-Pass Drop"
local test_dir="${TEMP_BASE}/p13"
mkdir -p "$test_dir"
local sql_setup="
CREATE TABLE telemetry (id INT PRIMARY KEY, recorded_at DATETIME, temp FLOAT) PARTITION BY toYYYYMM(recorded_at);
INSERT INTO telemetry VALUES (1, '2024-08-15 10:00:00', 25.5), (2, '2024-09-10 11:00:00', 26.0), (3, '2024-10-05 12:00:00', 21.0);
"
if ! exec_sql "$test_dir" "$ENGINE" "$sql_setup" >/dev/null; then
report_fail "$phase" "$title" "Failed to create partitioned table"
return
fi
# 1. Verify partition pruning via EXPLAIN
local explain_out
if ! explain_out=$(exec_sql "$test_dir" "$ENGINE" "EXPLAIN SELECT * FROM telemetry WHERE recorded_at >= '2024-10-01' AND recorded_at < '2024-11-01';"); then
report_fail "$phase" "$title" "Partition pruning explain failed"
return
fi
# 2. Verify O(1) partition drop
if ! exec_sql "$test_dir" "$ENGINE" "ALTER TABLE telemetry DROP PARTITION '202408';" >/dev/null; then
report_fail "$phase" "$title" "ALTER TABLE DROP PARTITION failed"
return
fi
# Verify partition pruning occurred in EXPLAIN plan
if echo "$explain_out" | grep -q "Partitions: \[202410\]"; then
report_pass "$phase" "$title (Pruning to [202410] & O(1) Drop verified)"
else
report_fail "$phase" "$title" "Pruning did not isolate target partition: $explain_out"
fi
}
# ------------------------------------------------------------------------------
# Main Test Harness Orchestration
# ------------------------------------------------------------------------------
main() {
verify_binaries
log_header "LionSQL Extended Integration Smoke Test Suite"
echo -e " Storage Engine: ${CLR_BOLD}${ENGINE}${CLR_RESET}"
echo -e " Binaries Path : ${CLR_GRAY}${BIN_DIR}${CLR_RESET}"
echo -e " Temp Directory: ${CLR_GRAY}${TEMP_BASE}${CLR_RESET}"
echo -e " Target Scope : ${CLR_BOLD}${TOTAL_PHASES} Verification Domains (notes/TEST_VERIFICATION_REPORT.ko.md)${CLR_RESET}\n"
test_phase_1
test_phase_2
test_phase_3
test_phase_4
test_phase_5
test_phase_6
test_phase_7
test_phase_8
test_phase_9
test_phase_10
test_phase_11
test_phase_12
test_phase_13
# Print Summary Matrix
echo -e "\n${CLR_CYAN}${CLR_BOLD}================================================================================${CLR_RESET}"
echo -e "${CLR_CYAN}${CLR_BOLD} Verification Summary Matrix${CLR_RESET}"
echo -e "${CLR_CYAN}${CLR_BOLD}================================================================================${CLR_RESET}"
echo -e " Total Domains : ${CLR_BOLD}${TOTAL_PHASES}${CLR_RESET}"
echo -e " Passed Domains : ${CLR_GREEN}${CLR_BOLD}${PASSED_COUNT}${CLR_RESET}"
echo -e " Failed Domains : ${CLR_RED}${CLR_BOLD}${FAILED_COUNT}${CLR_RESET}"
echo -e " Skipped Domains: ${CLR_YELLOW}${CLR_BOLD}${SKIPPED_COUNT}${CLR_RESET}"
echo -e "${CLR_CYAN}${CLR_BOLD}================================================================================${CLR_RESET}"
if [ "$FAILED_COUNT" -eq 0 ]; then
echo -e "${CLR_GREEN}${CLR_BOLD}Result: 100% PASS across all ${TOTAL_PHASES} verification domains!${CLR_RESET}\n"
exit 0
else
echo -e "${CLR_RED}${CLR_BOLD}Result: ${FAILED_COUNT} domain(s) failed verification! Check logs: ${LOG_FILE}${CLR_RESET}\n"
exit 1
fi
}
main "$@"