@@ -20,6 +20,17 @@ describe('targetsCloudflareInternalTable', () => {
2020 [ 'cf_ai_ prefix' , 'INSERT INTO cf_ai_chat_stream_chunks (id) VALUES (?)' ] ,
2121 [ 'cf_mcp_ prefix' , 'SELECT * FROM cf_mcp_agent_event' ] ,
2222 [ 'schema version' , 'SELECT version FROM cf_schema_version' ] ,
23+ // SQLite upsert forms used by the agents framework for state/schedule/MCP persistence
24+ [ 'INSERT OR REPLACE' , 'INSERT OR REPLACE INTO cf_agents_state (id, state) VALUES (?, ?)' ] ,
25+ [
26+ 'INSERT OR REPLACE with column list' ,
27+ `INSERT OR REPLACE INTO cf_agents_mcp_servers ( id, name, server_url, client_id, auth_url,
28+ callback_url, server_options )
29+ VALUES ( ?, ?, ?, ?, ?, ?, ? )` ,
30+ ] ,
31+ [ 'INSERT OR IGNORE' , 'INSERT OR IGNORE INTO cf_agents_sub_agents (class, name) VALUES (?, ?)' ] ,
32+ [ 'REPLACE INTO' , 'REPLACE INTO cf_agents_queues (id, payload) VALUES (?, ?)' ] ,
33+ [ 'UPDATE OR REPLACE' , 'UPDATE OR REPLACE cf_agents_state SET state = ? WHERE id = ?' ] ,
2334 ] ) ( 'returns true for %s on internal tables' , ( _label , query ) => {
2435 expect ( targetsCloudflareInternalTable ( summarize ( query ) ) ) . toBe ( true ) ;
2536 } ) ;
@@ -55,6 +66,9 @@ describe('targetsCloudflareInternalTable', () => {
5566 [ 'CREATE TABLE' , 'CREATE TABLE users (id TEXT PRIMARY KEY)' ] ,
5667 [ 'table with cf in the middle' , 'SELECT * FROM my_cf_table' ] ,
5768 [ 'table starting with cfg' , 'SELECT * FROM cfg_settings' ] ,
69+ [ 'INSERT OR REPLACE' , 'INSERT OR REPLACE INTO users (id, name) VALUES (?, ?)' ] ,
70+ [ 'REPLACE INTO' , 'REPLACE INTO sessions (id, token) VALUES (?, ?)' ] ,
71+ [ 'UPDATE OR IGNORE' , 'UPDATE OR IGNORE products SET price = ? WHERE id = ?' ] ,
5872 ] ) ( 'returns false for %s on user tables' , ( _label , query ) => {
5973 expect ( targetsCloudflareInternalTable ( summarize ( query ) ) ) . toBe ( false ) ;
6074 } ) ;
@@ -69,6 +83,14 @@ describe('targetsCloudflareInternalTable', () => {
6983 expect ( targetsCloudflareInternalTable ( summarize ( 'SELECT * FROM cf_reports_daily' ) , [ / ^ c f _ r e p o r t s _ / ] ) ) . toBe ( false ) ;
7084 } ) ;
7185
86+ it ( 'returns false for an allowlisted table targeted by an upsert' , ( ) => {
87+ expect (
88+ targetsCloudflareInternalTable ( summarize ( 'INSERT OR REPLACE INTO cf_my_table (id) VALUES (?)' ) , [
89+ 'cf_my_table' ,
90+ ] ) ,
91+ ) . toBe ( false ) ;
92+ } ) ;
93+
7294 it ( 'requires an exact match for string entries' , ( ) => {
7395 // Substring matches must not opt a table back in, otherwise `cf_` would allowlist everything.
7496 expect ( targetsCloudflareInternalTable ( summarize ( 'SELECT * FROM cf_agents_state' ) , [ 'cf_agents' ] ) ) . toBe ( true ) ;
0 commit comments