@@ -35,16 +35,16 @@ SELECT cloudsync_init('tasks') AS _init_a \gset
3535SELECT cloudsync_set_filter(' tasks' , ' user_id = 1' ) AS _sf_a \gset
3636
3737-- ============================================================
38- -- Test 1: Init refill should have created metadata for ALL 5 pre-existing rows
39- -- (filter was not set in settings when cloudsync_init ran the refill )
38+ -- Test 1: set_filter resets metatable to only matching rows
39+ -- cloudsync_init filled all 5, then set_filter cleaned and refilled → 3 matching (a, c, e )
4040-- ============================================================
4141
4242SELECT COUNT (DISTINCT pk) AS meta_pk_count FROM tasks_cloudsync \gset
43- SELECT (:meta_pk_count = 5 ) AS prefill_t1_ok \gset
43+ SELECT (:meta_pk_count = 3 ) AS prefill_t1_ok \gset
4444\if :prefill_t1_ok
45- \echo [PASS] (:testid) prefill: all 5 pre - existing rows have metadata after init
45+ \echo [PASS] (:testid) prefill: 3 matching rows have metadata after set_filter
4646\else
47- \echo [FAIL] (:testid) prefill: expected 5 tracked PKs after init , got :meta_pk_count
47+ \echo [FAIL] (:testid) prefill: expected 3 tracked PKs after set_filter , got :meta_pk_count
4848SELECT (:fail::int + 1 ) AS fail \gset
4949\endif
5050
@@ -54,11 +54,11 @@ SELECT (:fail::int + 1) AS fail \gset
5454
5555INSERT INTO tasks VALUES (' f' , ' Task F' , 1 );
5656SELECT COUNT (DISTINCT pk) AS meta_pk_count FROM tasks_cloudsync \gset
57- SELECT (:meta_pk_count = 6 ) AS prefill_t2_ok \gset
57+ SELECT (:meta_pk_count = 4 ) AS prefill_t2_ok \gset
5858\if :prefill_t2_ok
59- \echo [PASS] (:testid) prefill: new matching insert tracked (6 PKs)
59+ \echo [PASS] (:testid) prefill: new matching insert tracked (4 PKs)
6060\else
61- \echo [FAIL] (:testid) prefill: expected 6 PKs after matching insert, got :meta_pk_count
61+ \echo [FAIL] (:testid) prefill: expected 4 PKs after matching insert, got :meta_pk_count
6262SELECT (:fail::int + 1 ) AS fail \gset
6363\endif
6464
@@ -68,11 +68,11 @@ SELECT (:fail::int + 1) AS fail \gset
6868
6969INSERT INTO tasks VALUES (' g' , ' Task G' , 2 );
7070SELECT COUNT (DISTINCT pk) AS meta_pk_count FROM tasks_cloudsync \gset
71- SELECT (:meta_pk_count = 6 ) AS prefill_t3_ok \gset
71+ SELECT (:meta_pk_count = 4 ) AS prefill_t3_ok \gset
7272\if :prefill_t3_ok
73- \echo [PASS] (:testid) prefill: new non- matching insert not tracked (still 6 PKs)
73+ \echo [PASS] (:testid) prefill: new non- matching insert not tracked (still 4 PKs)
7474\else
75- \echo [FAIL] (:testid) prefill: expected still 6 PKs after non- matching insert, got :meta_pk_count
75+ \echo [FAIL] (:testid) prefill: expected still 4 PKs after non- matching insert, got :meta_pk_count
7676SELECT (:fail::int + 1 ) AS fail \gset
7777\endif
7878
@@ -99,13 +99,13 @@ SELECT cloudsync_set_filter('tasks', 'user_id = 1') AS _sf_b \gset
9999-- Apply payload
100100SELECT cloudsync_payload_apply(decode(:' payload_a_hex' , ' hex' )) AS _apply \gset
101101
102- -- All pre-existing rows (a-e) + matching new ( f) should arrive; non-matching new ( g) should not
102+ -- Only matching rows (a, c, e, f) should arrive; non-matching (b, d, g) should not
103103SELECT COUNT (* ) AS row_count FROM tasks \gset
104- SELECT (:row_count = 6 ) AS prefill_t4a_ok \gset
104+ SELECT (:row_count = 4 ) AS prefill_t4a_ok \gset
105105\if :prefill_t4a_ok
106- \echo [PASS] (:testid) prefill_sync: 6 rows synced to Database B
106+ \echo [PASS] (:testid) prefill_sync: 4 matching rows synced to Database B
107107\else
108- \echo [FAIL] (:testid) prefill_sync: expected 6 rows in Database B, got :row_count
108+ \echo [FAIL] (:testid) prefill_sync: expected 4 rows in Database B, got :row_count
109109SELECT (:fail::int + 1 ) AS fail \gset
110110\endif
111111
@@ -119,13 +119,13 @@ SELECT (:g_count = 0) AS prefill_t4b_ok \gset
119119SELECT (:fail::int + 1 ) AS fail \gset
120120\endif
121121
122- -- Verify pre-existing non-matching row 'b' DID sync (metadata from init refill )
122+ -- Verify pre-existing non-matching row 'b' did NOT sync (metadata removed by set_filter )
123123SELECT COUNT (* ) AS b_count FROM tasks WHERE id = ' b' AND user_id = 2 \gset
124- SELECT (:b_count = 1 ) AS prefill_t4c_ok \gset
124+ SELECT (:b_count = 0 ) AS prefill_t4c_ok \gset
125125\if :prefill_t4c_ok
126- \echo [PASS] (:testid) prefill_sync: pre- existing non- matching row ' b' synced via refill
126+ \echo [PASS] (:testid) prefill_sync: pre- existing non- matching row ' b' not synced
127127\else
128- \echo [FAIL] (:testid) prefill_sync: pre- existing row ' b' should have synced via refill metadata
128+ \echo [FAIL] (:testid) prefill_sync: pre- existing non - matching row ' b' should not have synced
129129SELECT (:fail::int + 1 ) AS fail \gset
130130\endif
131131
@@ -152,35 +152,35 @@ INSERT INTO projects VALUES (2, 2, 'Delta', 'active');
152152SELECT cloudsync_init(' projects' ) AS _init_proj \gset
153153SELECT cloudsync_set_filter(' projects' , ' org_id = 1' ) AS _sf_proj \gset
154154
155- -- All 4 pre-existing rows should have metadata
155+ -- set_filter resets metatable: only 2 matching rows (org_id=1) should have metadata
156156SELECT COUNT (DISTINCT pk) AS meta_pk_count FROM projects_cloudsync \gset
157- SELECT (:meta_pk_count = 4 ) AS prefill_t5_ok \gset
157+ SELECT (:meta_pk_count = 2 ) AS prefill_t5_ok \gset
158158\if :prefill_t5_ok
159- \echo [PASS] (:testid) prefill_composite: all 4 pre - existing rows have metadata
159+ \echo [PASS] (:testid) prefill_composite: 2 matching rows have metadata after set_filter
160160\else
161- \echo [FAIL] (:testid) prefill_composite: expected 4 tracked PKs, got :meta_pk_count
161+ \echo [FAIL] (:testid) prefill_composite: expected 2 tracked PKs, got :meta_pk_count
162162SELECT (:fail::int + 1 ) AS fail \gset
163163\endif
164164
165165-- New matching insert tracked
166166INSERT INTO projects VALUES (1 , 3 , ' Epsilon' , ' active' );
167167SELECT COUNT (DISTINCT pk) AS meta_pk_count FROM projects_cloudsync \gset
168- SELECT (:meta_pk_count = 5 ) AS prefill_t5b_ok \gset
168+ SELECT (:meta_pk_count = 3 ) AS prefill_t5b_ok \gset
169169\if :prefill_t5b_ok
170- \echo [PASS] (:testid) prefill_composite: new matching row tracked (5 PKs)
170+ \echo [PASS] (:testid) prefill_composite: new matching row tracked (3 PKs)
171171\else
172- \echo [FAIL] (:testid) prefill_composite: expected 5 PKs after matching insert, got :meta_pk_count
172+ \echo [FAIL] (:testid) prefill_composite: expected 3 PKs after matching insert, got :meta_pk_count
173173SELECT (:fail::int + 1 ) AS fail \gset
174174\endif
175175
176176-- New non-matching insert NOT tracked
177177INSERT INTO projects VALUES (3 , 1 , ' Zeta' , ' active' );
178178SELECT COUNT (DISTINCT pk) AS meta_pk_count FROM projects_cloudsync \gset
179- SELECT (:meta_pk_count = 5 ) AS prefill_t5c_ok \gset
179+ SELECT (:meta_pk_count = 3 ) AS prefill_t5c_ok \gset
180180\if :prefill_t5c_ok
181- \echo [PASS] (:testid) prefill_composite: new non- matching row not tracked (still 5 PKs)
181+ \echo [PASS] (:testid) prefill_composite: new non- matching row not tracked (still 3 PKs)
182182\else
183- \echo [FAIL] (:testid) prefill_composite: expected still 5 PKs, got :meta_pk_count
183+ \echo [FAIL] (:testid) prefill_composite: expected still 3 PKs, got :meta_pk_count
184184SELECT (:fail::int + 1 ) AS fail \gset
185185\endif
186186
0 commit comments