Skip to content

Commit 0887da6

Browse files
capture more tasks
1 parent e09da62 commit 0887da6

26 files changed

Lines changed: 580 additions & 662 deletions
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# TASK-161 — Resurrection parity test suite (consolidated)
2+
3+
## Goal
4+
Create comprehensive resurrection tests verifying Zig matches Rust/C oracle for all CL (causal length) scenarios.
5+
6+
## Status
7+
- State: backlog
8+
- Priority: high (cross-impl parity, CL semantics)
9+
- Parallelizable: YES (no file conflicts with other backlog tasks)
10+
11+
## Context
12+
Consolidates TASK-161 through TASK-165 into a single test file. These scenarios from Python `test_cl_merging.py` are not covered in Zig harness:
13+
14+
1. **Live row via sentinel**: Sentinel arrives for already-live row
15+
2. **Dead row via sentinel**: Sentinel resurrects tombstoned row
16+
3. **Live row via column**: Column update on live row (normal case with CL verification)
17+
4. **Dead row via column**: Column update resurrects tombstoned row
18+
5. **Out-of-order sync**: Changes arrive in wrong order (delete after resurrect)
19+
20+
## Files to Modify
21+
- `zig/harness/test-resurrection-parity.sh` (new, ~400 lines)
22+
- `zig/harness/test-parity.sh` (wire in new test)
23+
24+
## Acceptance Criteria
25+
1. Each of 5 scenarios implemented as separate test function
26+
2. Each test runs against both Zig and Rust/C oracle
27+
3. Each test compares final state (data, clock entries, CL values)
28+
4. All tests PASS with identical behavior
29+
5. Test output clearly documents any divergences found
30+
31+
## Test Skeleton
32+
```bash
33+
#!/usr/bin/env bash
34+
# test-resurrection-parity.sh - CL resurrection scenarios
35+
36+
test_live_via_sentinel() {
37+
# Site A: INSERT row (CL=1)
38+
# Site A: DELETE row (CL=2)
39+
# Site A: INSERT row (CL=3) - resurrection
40+
# Site B: has live row (CL=1)
41+
# Site B: receives resurrection sentinel (CL=3)
42+
# Verify: both live, CL=3
43+
}
44+
45+
test_dead_via_sentinel() {
46+
# Create, delete (tombstone CL=2)
47+
# Send resurrection sentinel (CL=3)
48+
# Verify: resurrected, CL=3
49+
}
50+
51+
test_live_via_column() {
52+
# Normal UPDATE case but verify CL advances
53+
}
54+
55+
test_dead_via_column() {
56+
# Tombstoned row receives column update with higher CL
57+
# Should resurrect with that column value
58+
}
59+
60+
test_out_of_order() {
61+
# Send changes in order: INSERT(CL=1), RESURRECT(CL=3), DELETE(CL=2)
62+
# Verify: row is live (CL=3 wins)
63+
}
64+
```
65+
66+
## Parent Docs / Cross-links
67+
- Python tests: `py/correctness/tests/test_cl_merging.py`
68+
- Supersedes: TASK-162, TASK-163, TASK-164, TASK-165
69+
- Gap backlog: `research/zig-cr/92-gap-backlog.md`
70+
71+
## Progress Log
72+
- 2025-12-22: Consolidated from 5 individual tasks for efficient parallel execution.
73+
74+
## Completion Notes
75+
(Empty until done.)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# TASK-166 — Sentinel emission parity test suite (consolidated)
2+
3+
## Goal
4+
Create comprehensive sentinel tests verifying Zig matches Rust/C oracle for sentinel (cid='-1') emission rules.
5+
6+
## Status
7+
- State: backlog
8+
- Priority: high (wire format parity)
9+
- Parallelizable: YES (no file conflicts with other backlog tasks)
10+
11+
## Context
12+
Consolidates TASK-166 through TASK-169 into a single test file. These scenarios from Python `test_sentinel_omission.py` are not covered in Zig harness:
13+
14+
1. **No sentinel on INSERT**: Normal INSERT should NOT create cid='-1'
15+
2. **Sentinel on DELETE**: DELETE MUST create cid='-1' with CL
16+
3. **No sentinel on REPLACE**: INSERT OR REPLACE should NOT create sentinel
17+
4. **No sentinel on merge**: Applying remote changes should NOT create new sentinels
18+
19+
## Files to Modify
20+
- `zig/harness/test-sentinel-parity.sh` (new, ~300 lines)
21+
- `zig/harness/test-parity.sh` (wire in new test)
22+
23+
## Acceptance Criteria
24+
1. Each of 4 scenarios implemented as separate test function
25+
2. Each test runs against both Zig and Rust/C oracle
26+
3. Each test queries clock table for cid='-1' presence
27+
4. All tests PASS with identical behavior
28+
5. Sentinel propagation during sync verified (not created, just passed through)
29+
30+
## Test Skeleton
31+
```bash
32+
#!/usr/bin/env bash
33+
# test-sentinel-parity.sh - Sentinel emission rules
34+
35+
test_no_sentinel_on_insert() {
36+
# INSERT row
37+
# Query: SELECT * FROM t__crsql_clock WHERE cid = '-1'
38+
# Verify: no rows (sentinel not created)
39+
}
40+
41+
test_sentinel_on_delete() {
42+
# INSERT then DELETE
43+
# Query: SELECT * FROM t__crsql_clock WHERE cid = '-1'
44+
# Verify: 1 row with correct CL
45+
}
46+
47+
test_no_sentinel_on_replace() {
48+
# INSERT then INSERT OR REPLACE
49+
# Verify: no sentinel created
50+
}
51+
52+
test_no_sentinel_on_merge() {
53+
# Site A: INSERT
54+
# Sync to Site B
55+
# Verify: Site B has data but NO sentinel in clock
56+
# Site A: DELETE (creates sentinel)
57+
# Sync to Site B
58+
# Verify: Site B has sentinel (propagated, not new)
59+
}
60+
```
61+
62+
## Parent Docs / Cross-links
63+
- Python tests: `py/correctness/tests/test_sentinel_omission.py`
64+
- Supersedes: TASK-167, TASK-168, TASK-169
65+
- Gap backlog: `research/zig-cr/92-gap-backlog.md`
66+
67+
## Progress Log
68+
- 2025-12-22: Consolidated from 4 individual tasks for efficient parallel execution.
69+
70+
## Completion Notes
71+
(Empty until done.)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# TASK-170 — Foreign key and cascade test suite (consolidated)
2+
3+
## Goal
4+
Create tests verifying Zig handles foreign keys and cascading operations between CRR tables.
5+
6+
## Status
7+
- State: backlog
8+
- Priority: high (real-world apps have FKs)
9+
- Parallelizable: YES (no file conflicts with other backlog tasks)
10+
11+
## Context
12+
Consolidates TASK-170 and TASK-171. No existing tests verify FK behavior between CRR tables.
13+
14+
Key questions to answer:
15+
1. Can CRR tables have FK constraints to each other?
16+
2. What happens when child row syncs before parent?
17+
3. Do cascaded deletes get proper clock entries?
18+
4. Is the cascade CL correct for sync convergence?
19+
20+
## Files to Modify
21+
- `zig/harness/test-fk-crr.sh` (new, ~350 lines)
22+
- `zig/harness/test-parity.sh` (wire in new test)
23+
24+
## Acceptance Criteria
25+
1. Test FK between two CRR tables (parent/child)
26+
2. Test child arriving before parent during sync
27+
3. Test ON DELETE CASCADE behavior
28+
4. Verify cascade creates proper clock entries
29+
5. Verify cascade clock entries have correct CL
30+
6. Verify sync convergence after cascade
31+
7. Document any Zig vs Rust/C differences
32+
33+
## Test Skeleton
34+
```bash
35+
#!/usr/bin/env bash
36+
# test-fk-crr.sh - Foreign keys between CRR tables
37+
38+
setup_fk_tables() {
39+
# CREATE TABLE parent (id INTEGER PRIMARY KEY NOT NULL);
40+
# CREATE TABLE child (id INTEGER PRIMARY KEY NOT NULL,
41+
# parent_id INTEGER REFERENCES parent(id) ON DELETE CASCADE);
42+
# SELECT crsql_as_crr('parent');
43+
# SELECT crsql_as_crr('child');
44+
}
45+
46+
test_fk_basic() {
47+
# INSERT parent, INSERT child
48+
# Verify: both have clock entries
49+
}
50+
51+
test_child_before_parent_sync() {
52+
# Site A: INSERT parent, INSERT child
53+
# Site B: receive child first (via crsql_changes)
54+
# Document: does it fail? defer? succeed with dangling FK?
55+
# Site B: receive parent
56+
# Verify: FK now satisfied
57+
}
58+
59+
test_cascade_delete() {
60+
# INSERT parent + 3 children
61+
# DELETE parent (cascades to children)
62+
# Verify: all 4 rows have tombstones
63+
# Verify: child tombstones have clock entries
64+
# Verify: child tombstone CL values
65+
}
66+
67+
test_cascade_sync_convergence() {
68+
# Site A: cascade delete
69+
# Site B: has parent + children
70+
# Sync A to B
71+
# Verify: B has all tombstones
72+
}
73+
```
74+
75+
## Parent Docs / Cross-links
76+
- Supersedes: TASK-171
77+
- Gap backlog: `research/zig-cr/92-gap-backlog.md`
78+
79+
## Progress Log
80+
- 2025-12-22: Consolidated FK and cascade tasks.
81+
82+
## Completion Notes
83+
(Empty until done.)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# TASK-172 — Malformed input error handling tests
2+
3+
## Goal
4+
Verify Zig handles malformed inputs gracefully (error, not crash).
5+
6+
## Status
7+
- State: backlog
8+
- Priority: high (security/robustness)
9+
- Parallelizable: YES (no file conflicts with other backlog tasks)
10+
11+
## Context
12+
The `pk` column in crsql_changes contains packed binary data. Malformed data could crash or corrupt. We need to verify graceful error handling.
13+
14+
## Files to Modify
15+
- `zig/harness/test-error-handling.sh` (new, ~250 lines)
16+
- `zig/harness/test-parity.sh` (wire in new test)
17+
18+
## Acceptance Criteria
19+
1. Test truncated PK blob → error, not crash
20+
2. Test wrong column count header → error
21+
3. Test invalid type markers → error
22+
4. Test corrupted length prefixes → error
23+
5. Error messages are actionable (not just "error")
24+
6. Database remains uncorrupted after each error
25+
7. Zig and Rust/C produce same error behavior
26+
27+
## Test Skeleton
28+
```bash
29+
#!/usr/bin/env bash
30+
# test-error-handling.sh - Malformed input handling
31+
32+
test_truncated_pk() {
33+
# Valid PK would be X'010901' (1 col, int8, value 1)
34+
# Send X'0109' (truncated)
35+
# Expect: error, no crash
36+
}
37+
38+
test_wrong_column_count() {
39+
# Header says 3 columns but only 1 value
40+
# Expect: error
41+
}
42+
43+
test_invalid_type_marker() {
44+
# Use type marker 0xFF (invalid)
45+
# Expect: error
46+
}
47+
48+
test_db_uncorrupted_after_error() {
49+
# Insert valid row
50+
# Attempt malformed insert (fails)
51+
# Verify: valid row still intact
52+
# Verify: can still INSERT/UPDATE/DELETE
53+
}
54+
```
55+
56+
## Parent Docs / Cross-links
57+
- Gap backlog: `research/zig-cr/92-gap-backlog.md`
58+
59+
## Progress Log
60+
- 2025-12-22: Created from gap analysis.
61+
62+
## Completion Notes
63+
(Empty until done.)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# TASK-173 — Schema mismatch during sync tests
2+
3+
## Goal
4+
Verify Zig handles schema mismatches gracefully during sync.
5+
6+
## Status
7+
- State: backlog
8+
- Priority: medium (production scenario)
9+
- Parallelizable: YES (no file conflicts with other backlog tasks)
10+
11+
## Context
12+
Different sites may have different schemas due to staggered migrations. Need to document and test behavior.
13+
14+
## Files to Modify
15+
- `zig/harness/test-schema-mismatch.sh` (new, ~200 lines)
16+
- `zig/harness/test-parity.sh` (wire in new test)
17+
18+
## Acceptance Criteria
19+
1. Test: source has column destination doesn't
20+
2. Test: destination has column source doesn't
21+
3. Document behavior for each case (error? ignored? partial?)
22+
4. Zig and Rust/C produce identical behavior
23+
5. No data corruption in any case
24+
25+
## Test Skeleton
26+
```bash
27+
#!/usr/bin/env bash
28+
# test-schema-mismatch.sh - Schema mismatch handling
29+
30+
test_source_has_extra_column() {
31+
# Site A: table with columns (id, name, extra)
32+
# Site B: table with columns (id, name) - no 'extra'
33+
# Site A: INSERT with extra='value'
34+
# Sync A changes to B
35+
# Document: what happens to 'extra' column data?
36+
}
37+
38+
test_dest_has_extra_column() {
39+
# Site A: table with columns (id, name)
40+
# Site B: table with columns (id, name, extra)
41+
# Site A: INSERT
42+
# Sync A changes to B
43+
# Verify: row created, extra column is NULL/default
44+
}
45+
46+
test_type_mismatch() {
47+
# Site A: column 'val' is INTEGER
48+
# Site B: column 'val' is TEXT
49+
# Site A: INSERT val=42
50+
# Sync A to B
51+
# Document: type coercion or error?
52+
}
53+
```
54+
55+
## Parent Docs / Cross-links
56+
- Gap backlog: `research/zig-cr/92-gap-backlog.md`
57+
58+
## Progress Log
59+
- 2025-12-22: Created from gap analysis.
60+
61+
## Completion Notes
62+
(Empty until done.)

0 commit comments

Comments
 (0)