From fb55fbce28c45e014efd46d84aadeabf9c85a0ff Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 06:47:29 +0000 Subject: [PATCH 1/2] ADFA-7299 SQLite debugger: acknowledge before the first write to a Room database Phase 2, P2-4 (ADFA-7131 comment 41476, decision D6). On P2-3. - Room records changes with TEMP triggers on its own connection, which a write on the server's connection does not fire, so its observers miss the change and a screen can show stale data. The debugger does not make Room refresh: it must not change how the app behaves. - execute looks for room_master_table on the read-only connection. On a Room database it runs nothing and returns an error naming the risk, with details {room: true, acknowledge_with: "acknowledge_room"}, until the call is repeated with acknowledge_room: true. - The acknowledgement is kept per database path for the life of DatabaseTools (one per app process), so later writes to that database run without asking and the check is not run again. A database without room_master_table never asks. - acknowledge_room must be a boolean; it is checked before the engine. - README and execute's description and input schema updated. Limits: a database without Room's table is checked on every execute (one indexed read of sqlite_master); an acknowledgement outlives a database the app deletes and recreates under the same path. Tests: DatabaseToolsTest, McpProtocolTest and EventDecoderTest pass (119), compiled with the Kotlin compiler outside Gradle. One P2-3 test now counts the read-only connection execute opens. Revert proofs: never refusing fails aRoomDatabaseRefusesTheFirstWrite... and anAcknowledgementCoversOnlyItsOwnDatabase...; not remembering the acknowledgement fails anAcknowledgedRoomWriteRunsAndLaterWritesRun... Not run here: Gradle, spotlessCheck, a device. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba (cherry picked from commit c07fbf379b19f862ea4cee452eeb591780026544) --- subprojects/sqlite-debugger/README.md | 3 +- .../sqlitedebugger/mcp/DatabaseTools.kt | 59 +++++++++++- .../sqlitedebugger/mcp/DatabaseToolsTest.kt | 96 ++++++++++++++++++- 3 files changed, 152 insertions(+), 6 deletions(-) diff --git a/subprojects/sqlite-debugger/README.md b/subprojects/sqlite-debugger/README.md index 0b9af78712..5e4013b594 100644 --- a/subprojects/sqlite-debugger/README.md +++ b/subprojects/sqlite-debugger/README.md @@ -35,7 +35,8 @@ The layout of `sqlitedbg_event_record` lives in `sqlitedbg.h`. The JNI layer han - **Debug builds only.** `DebuggerStartup.onCreate` throws if the process is not debuggable, so a release build that includes the library by mistake crashes at once instead of opening a local server. - **Loopback HTTP, a random port and token per start.** `McpHttp` binds 127.0.0.1 only (port 0, so the system picks one) and requires `Authorization: Bearer `, a new 32-byte random token each process start. It also checks that the Host and any Origin name 127.0.0.1 or localhost, against DNS rebinding. At most 8 connections at once. The head of a request (request line and headers) must arrive within 5 s, from connecting for a connection's first request and from its first byte for later ones, and Host, Origin, path and token are checked before the body is read, so a client that trickles bytes or never authenticates frees its slot; a refused request closes the connection. It opens no event stream: GET gets 405. - **Read-only is a guard against accidents, not a security boundary.** Every tool but `execute` opens its server connection with `writable = false`: `SQLITE_OPEN_READONLY`, `PRAGMA query_only` and an authorizer that refuses ordinary writes, transactions and savepoints, and `PRAGMA locking_mode` and `busy_timeout`, so a client cannot hold a lock across statements, and `hard_heap_limit`, `soft_heap_limit` and `temp_store_directory`, which SQLite applies process-wide, to the app's connections too; the JNI query path also rolls back any transaction left open (`sqlitedbg_end_transaction`, whose ROLLBACK is the one transaction statement the authorizer lets past), and a rollback that fails is the query's error. A server connection waits up to 3 s (`SQLITEDBG_SERVER_BUSY_MS`, fixed in C) for a lock the app holds, as in rollback-journal mode, and then reports `SQLITE_BUSY`. A statement that is running holds a lock, though: on a database that is not in WAL mode (rollback journal) a read holds a SHARED lock, and the app's own COMMIT waits for it only as long as requery's busy timeout, 2500 ms (`BUSY_TIMEOUT_MS` in requery/sqlite-android 3.49.0, `android_database_SQLiteConnection.cpp`). So the JNI query path, which every tool uses, reads `PRAGMA journal_mode` (without a value, so it only reads) on each call and stops a statement on a database that is not in WAL mode after 1.5 s (`SQLITEDBG_SERVER_NON_WAL_MS`), with an error that says the database is not in WAL mode and to narrow the query or add a LIMIT. That also stops a `quick_check`, an `integrity_check` or a `get_stats` row count that runs longer than 1.5 s on such a database. A database in WAL mode keeps the 50 s limit, as readers do not block its writer. Anyone holding the token can run `execute`, so the token is the boundary, and the client decides which tools to allow (AI-Agent-MCP asks before each `execute`, ADFA-7300). -- **`execute` writes one statement, in autocommit (ADFA-7298).** Read-write is always available; there is no mode switch. `execute` runs on a second server connection per database, opened with `writable = true` (`SQLITE_OPEN_READWRITE`, never `SQLITE_OPEN_CREATE`) and cached apart from the read-only one, so a read never runs where writes are allowed. Its authorizer allows writes and schema changes and refuses what reaches the app rather than the data: transactions, savepoints, `ATTACH` (it would open a file the app may not have open), and `PRAGMA locking_mode`, `busy_timeout`, the heap limits, `temp_store_directory`, `query_only`, `writable_schema`, and setting `journal_mode` or `schema_version`; the read-only connection refuses them too. So a write cannot be part of a transaction: one statement per call, committed at once. A statement that does not write (`sqlite3_stmt_readonly`) is refused, to be run with `query`; rows from `RETURNING` are read and dropped. It binds `args` as `query` does and returns `changes`: `sqlite3_changes64`, or 0 when `sqlite3_total_changes64` did not move, since `sqlite3_changes64` keeps the previous write's count across a statement that changes no row, such as `CREATE TABLE` (ADFA-7131 comment 41489). `last_insert_rowid` is the rowid of the last row the statement inserted into a rowid table, or null when it inserted none (an `UPDATE`, a `WITHOUT ROWID` table, an ignored row). The writable connection is cached and SQLite keeps `sqlite3_last_insert_rowid` across statements, so the JNI layer sets it to 0 with `sqlite3_set_last_insert_rowid` before each statement and reports non-zero only; a row inserted with rowid 0 reads as null (accepted). Rows a trigger inserts do not count, as SQLite restores the value when the trigger ends. A write holds the database's write lock until it ends, in WAL mode too, and the app's own writes wait for it only as long as requery's 2500 ms busy timeout, so every `execute` is stopped after 1.5 s (`SQLITEDBG_SERVER_NON_WAL_MS`), whatever the journal mode, and rolled back. Without that cap, a long write in WAL mode made the app's own insert fail with `SQLITE_BUSY` in the JNI test. The transaction backstop runs after `execute` as after `query`. The app is not told about the change: Room's observers and other caches keep what they read until they read again (the Room warning is ADFA-7299). +- **`execute` writes one statement, in autocommit (ADFA-7298).** Read-write is always available; there is no mode switch. `execute` runs on a second server connection per database, opened with `writable = true` (`SQLITE_OPEN_READWRITE`, never `SQLITE_OPEN_CREATE`) and cached apart from the read-only one, so a read never runs where writes are allowed. Its authorizer allows writes and schema changes and refuses what reaches the app rather than the data: transactions, savepoints, `ATTACH` (it would open a file the app may not have open), and `PRAGMA locking_mode`, `busy_timeout`, the heap limits, `temp_store_directory`, `query_only`, `writable_schema`, and setting `journal_mode` or `schema_version`; the read-only connection refuses them too. So a write cannot be part of a transaction: one statement per call, committed at once. A statement that does not write (`sqlite3_stmt_readonly`) is refused, to be run with `query`; rows from `RETURNING` are read and dropped. It binds `args` as `query` does and returns `changes`: `sqlite3_changes64`, or 0 when `sqlite3_total_changes64` did not move, since `sqlite3_changes64` keeps the previous write's count across a statement that changes no row, such as `CREATE TABLE` (ADFA-7131 comment 41489). `last_insert_rowid` is the rowid of the last row the statement inserted into a rowid table, or null when it inserted none (an `UPDATE`, a `WITHOUT ROWID` table, an ignored row). The writable connection is cached and SQLite keeps `sqlite3_last_insert_rowid` across statements, so the JNI layer sets it to 0 with `sqlite3_set_last_insert_rowid` before each statement and reports non-zero only; a row inserted with rowid 0 reads as null (accepted). Rows a trigger inserts do not count, as SQLite restores the value when the trigger ends. A write holds the database's write lock until it ends, in WAL mode too, and the app's own writes wait for it only as long as requery's 2500 ms busy timeout, so every `execute` is stopped after 1.5 s (`SQLITEDBG_SERVER_NON_WAL_MS`), whatever the journal mode, and rolled back. Without that cap, a long write in WAL mode made the app's own insert fail with `SQLITE_BUSY` in the JNI test. The transaction backstop runs after `execute` as after `query`. The app is not told about the change: Room's observers and other caches keep what they read until they read again. +- **The first write to a Room database waits for an acknowledgement (ADFA-7299, D6).** Room records changes with TEMP triggers on its own connection, which a write on the server's connection does not fire, so its observers (Flow, LiveData, Paging, `InvalidationTracker`) miss it and a screen can show stale data. The debugger does not make Room refresh, as it must not change how the app behaves. Instead, `execute` looks for `room_master_table` on the read-only connection, and on a Room database it runs nothing and returns an error that says so, until the call is repeated with `acknowledge_room: true`. The acknowledgement is kept per database path for the life of `DatabaseTools`, one per app process (`DebuggerStartup`), so later writes to that database run without asking until the app restarts, and the check is not run again. A database without `room_master_table` never asks. The app's own connections and writes are not touched. - **Only databases an app connection has open.** `DatabaseTools` refuses any other path before the engine is called: opening a file Android's own SQLite has open, with requery's, can corrupt it. The extension has no SQLite API until an app connection has opened, so `sqlitedbg_open_server` returns `SQLITE_MISUSE` before that. - **The app's connections are never altered.** The extension never sets the progress handler or the update hook of an app connection: requery sets and clears the progress handler around cancellable statements, and the update hook belongs to the app. Only server connections use a progress handler, for the time limit. - **The app's own functions are not available.** Every tool runs on a server connection (`sqlitedbg_open_server`), never on one of the app's connections, which the SQLite debugger does not alter. SQLite registers functions per connection, so a server connection has only SQLite's built-in functions and those of extensions registered for every connection with `sqlite3_auto_extension`. What the app adds to its own connections is missing: requery's `SQLiteCustomFunction`s and `SQLiteCustomExtension`s, among them sqlite-js and the JavaScript functions it loads from `js_functions`. SQL that calls one, directly or through a view, fails with "no such function", although the app's own queries run it. The descriptions of `query` and `explain_query_plan` say so, so the agent reads the rows or computes in plain SQL instead. Both checks fail with "unknown function" when a CHECK constraint or a NOT NULL virtual generated column calls such a function; a full `integrity_check` (`full: true`) also fails on an index on such an expression and on a partial index whose WHERE calls one, while `quick_check` (the default) does not fail on those two, and the description of `integrity_check` says to use it then. Views, triggers and other generated columns make neither fail (checked with SQLite 3.46). diff --git a/subprojects/sqlite-debugger/src/main/java/org/appdevforall/sqlitedebugger/mcp/DatabaseTools.kt b/subprojects/sqlite-debugger/src/main/java/org/appdevforall/sqlitedebugger/mcp/DatabaseTools.kt index b5e920dc5c..dd0f504dd7 100644 --- a/subprojects/sqlite-debugger/src/main/java/org/appdevforall/sqlitedebugger/mcp/DatabaseTools.kt +++ b/subprojects/sqlite-debugger/src/main/java/org/appdevforall/sqlitedebugger/mcp/DatabaseTools.kt @@ -102,6 +102,23 @@ class DatabaseTools internal constructor( "A statement is stopped and rolled back after 1.5 s (best effort: it can run up to about 3 s longer), in every " + "journal mode, so a long write does not make the app's own writes fail; change fewer rows per call." + /** Said by execute's description: the first write to a Room database is refused until acknowledged (ADFA-7299). */ + const val ROOM_DESCRIPTION = + "The first write to a Room database (one with room_master_table) is refused with a warning until it is sent again " + + "with acknowledge_room true; later writes to it run without asking until the app restarts." + + /** + * Why a write to a Room database waits for acknowledge_room. Room records changes with TEMP triggers on its own + * connection, which a write on the server's connection does not fire, and the debugger must not change how the app + * behaves, so it does not make Room refresh (ADFA-7131, D6). + */ + const val ROOM_WARNING = + "Nothing was run: this is a Room database. Room learns about changes through triggers on its own connection, so it " + + "will not see a write from the debugger. Screens that observe this data (Flow, LiveData, Paging, " + + "InvalidationTracker) can show stale data, and the app's caches can keep old values, until the app queries again " + + "or restarts. Tell the user this; to write anyway, call execute again with acknowledge_room true. Later writes to " + + "this database then run without asking until the app restarts." + /** Server connections never load what the app registers on its own connections (see the README). */ private const val APP_FUNCTIONS_NOTE = "Functions the app adds to its own connections, such as sqlite-js's stored JavaScript functions, do not exist " + @@ -160,6 +177,12 @@ class DatabaseTools internal constructor( /** execute's connections, apart from the read-only ones, so a read never runs where writes are allowed. */ private val writableConnections = HashMap() + + /** + * Room databases execute may write to without asking again (ADFA-7299): acknowledged once with + * `acknowledge_room` in this server process. Guarded by [lock]. + */ + private val roomAcknowledged = HashSet() private var clientConnected = false private var lastEventsCallMs = 0L private var cancelIdleCheck: (() -> Unit)? = null @@ -294,10 +317,15 @@ class DatabaseTools internal constructor( "Also refused: ATTACH, and PRAGMA locking_mode, busy_timeout, query_only, writable_schema, the heap limits, " + "temp_store_directory, and setting journal_mode or schema_version, as they would reach the app's own " + "connections. $WRITE_NOTE The app is not told about the change: a screen showing this data may stay " + - "stale until it reads it again. $APP_FUNCTIONS_NOTE.", + "stale until it reads it again. $ROOM_DESCRIPTION $APP_FUNCTIONS_NOTE.", databaseSchema( "sql" to prop("string", "The SQL statement."), "args" to JSONObject().put("type", "array").put("description", "Values for ? parameters: null, numbers or strings."), + "acknowledge_room" to + prop( + "boolean", + "Set to true, after telling the user, to write to a Room database: Room's observers will not see the change.", + ), required = listOf("sql"), ), readOnly = false, @@ -476,12 +504,39 @@ class DatabaseTools internal constructor( ): JSONObject { val sql = stringArg(args, "sql") val bind = bindArgs(args) - val result = withConnection(call, checkedPath(call, args), writable = true) { it.execute(sql, bind, call.deadline) } + val acknowledge = + when (val v = args.opt("acknowledge_room")) { + null, JSONObject.NULL -> false + is Boolean -> v + else -> throw McpToolError("acknowledge_room must be true or false.") + } + val path = checkedPath(call, args) + if (!call.locked { path in roomAcknowledged } && isRoomDatabase(call, path)) { + if (!acknowledge) { + throw McpToolError(ROOM_WARNING, JSONObject().put("room", true).put("acknowledge_with", "acknowledge_room")) + } + call.locked { roomAcknowledged += path } + } + val result = withConnection(call, path, writable = true) { it.execute(sql, bind, call.deadline) } return JSONObject() .put("changes", encodeLong(result.changes)) .put("last_insert_rowid", result.lastInsertRowid?.let { encodeLong(it) } ?: JSONObject.NULL) } + /** Room creates room_master_table in every database it opens; read on the read-only connection. */ + private fun isRoomDatabase( + call: Call, + path: String, + ): Boolean = + runChecked( + call, + path, + "SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'room_master_table'", + emptyList(), + 0, + QueryLimits(1, MAX_TEXT_BYTES, MAX_BLOB_BYTES, MAX_TOTAL_BYTES), + ).rows.isNotEmpty() + private fun explain( call: Call, args: JSONObject, diff --git a/subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt b/subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt index 3a5dab2422..122a8a1182 100644 --- a/subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt +++ b/subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt @@ -1218,10 +1218,11 @@ class DatabaseToolsTest { engine.appConnections.clear() engine.appConnections += conn(2, "/data/a.db") ok("execute", db().put("sql", "delete from t"), t) - assertEquals(2, engine.openedServerConnections.size) - assertEquals(1, engine.closedServerConnections) - t.onServerStopped() + // execute also opens the read-only connection, to look for Room (ADFA-7299): one of each, twice + assertEquals(listOf(false, true, false, true), engine.openedServerConnections.map { it.second }) assertEquals(2, engine.closedServerConnections) + t.onServerStopped() + assertEquals(4, engine.closedServerConnections) } @Test fun executeDescribesWhatItRefusesItsTimeLimitAndThatTheAppIsNotTold() { @@ -1247,6 +1248,95 @@ class DatabaseToolsTest { ) } + /** /data/room.db has room_master_table; /data/a.db does not. Records what execute ran. */ + private fun roomSetup(): MutableList { + engine.appConnections += listOf(conn(1, "/data/a.db"), conn(2, "/data/room.db")) + engine.answer = { path, _, sql, _ -> + seenSql += sql + val room = path == "/data/room.db" && sql.contains("room_master_table") + QueryResult(listOf("1"), if (room) listOf(listOf(1L)) else emptyList(), 0, false) + } + val ran = mutableListOf() + engine.executeAnswer = { path, sql, _ -> + ran += "$path: $sql" + ExecuteResult(1) + } + return ran + } + + @Test fun aRoomDatabaseRefusesTheFirstWriteWithAWarningAndRunsNothing() { + val ran = roomSetup() + val r = runTool(tools, "execute", db("/data/room.db").put("sql", "delete from note")) + assertTrue(r.getBoolean("isError")) + val text = r.getJSONArray("content").getJSONObject(0).getString("text") + for (part in listOf("Nothing was run", "Room database", "stale data", "acknowledge_room true", "Tell the user")) { + assertTrue("$part: $text", text.contains(part)) + } + val details = r.getJSONObject("structuredContent") + assertTrue(details.getBoolean("room")) + assertEquals("acknowledge_room", details.getString("acknowledge_with")) + assertTrue(ran.isEmpty()) + // it looked on the read-only connection, and opened no writable one + assertEquals(listOf("/data/room.db" to false), engine.openedServerConnections) + // asked again without the flag, it refuses again + assertTrue(runTool(tools, "execute", db("/data/room.db").put("sql", "delete from note")).getBoolean("isError")) + assertTrue(ran.isEmpty()) + } + + @Test fun anAcknowledgedRoomWriteRunsAndLaterWritesRunWithoutAsking() { + val ran = roomSetup() + val t = tools + ok("execute", db("/data/room.db").put("sql", "delete from note where id = 1").put("acknowledge_room", true), t) + ok("execute", db("/data/room.db").put("sql", "delete from note where id = 2"), t) + ok("execute", db("/data/room.db").put("sql", "delete from note where id = 3").put("acknowledge_room", false), t) + assertEquals( + listOf( + "/data/room.db: delete from note where id = 1", + "/data/room.db: delete from note where id = 2", + "/data/room.db: delete from note where id = 3", + ), + ran, + ) + // once acknowledged, the database is not looked at again + assertEquals(1, seenSql.count { it.contains("room_master_table") }) + } + + @Test fun anAcknowledgementCoversOnlyItsOwnDatabaseAndOnlyThisServerProcess() { + engine.appConnections += conn(3, "/data/room2.db") + val ran = roomSetup() + engine.answer = { _, _, sql, _ -> QueryResult(listOf("1"), if (sql.contains("room_master_table")) listOf(listOf(1L)) else emptyList(), 0, false) } + val t = tools + ok("execute", db("/data/room.db").put("sql", "delete from note").put("acknowledge_room", true), t) + assertTrue(runTool(t, "execute", db("/data/room2.db").put("sql", "delete from note")).getBoolean("isError")) + // a new DatabaseTools, as in a new app process, asks again + assertTrue(runTool(tools, "execute", db("/data/room.db").put("sql", "delete from note")).getBoolean("isError")) + assertEquals(listOf("/data/room.db: delete from note"), ran) + } + + @Test fun aDatabaseWithoutRoomNeverAsks() { + val ran = roomSetup() + val t = tools + ok("execute", db("/data/a.db").put("sql", "delete from t"), t) + ok("execute", db("/data/a.db").put("sql", "delete from t").put("acknowledge_room", true), t) + assertEquals(listOf("/data/a.db: delete from t", "/data/a.db: delete from t"), ran) + } + + @Test fun acknowledgeRoomMustBeABooleanAndIsCheckedBeforeTheEngine() { + roomSetup() + val r = runTool(tools, "execute", db("/data/room.db").put("sql", "delete from note").put("acknowledge_room", "yes")) + assertTrue(r.getBoolean("isError")) + assertEquals(0, engine.openAttempts) + } + + @Test fun executeDescribesTheRoomAcknowledgement() { + val execute = tools.tools().first { it.name == "execute" }.describe() + assertTrue(execute.getString("description").contains("room_master_table")) + assertTrue(execute.getString("description").contains("acknowledge_room true")) + val prop = execute.getJSONObject("inputSchema").getJSONObject("properties").getJSONObject("acknowledge_room") + assertEquals("boolean", prop.getString("type")) + assertFalse(execute.getJSONObject("inputSchema").getJSONArray("required").toString().contains("acknowledge_room")) + } + @Test fun stoppingTheServerClosesServerConnections() { engine.appConnections += conn(1, "/data/a.db") val t = tools From 1f695c4afb1fbe4b42b3cf2bf51f26a49ecec805 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Tue, 24 Nov 2026 23:45:08 -0800 Subject: [PATCH 2/2] ADFA-7299 Build the Room tests against execute's last_insert_rowid result c07fbf379b was written on P2-3 before execute returned last_insert_rowid (b73b9f71c), so its Room test helper built ExecuteResult(1) and no longer compiled; it now passes lastInsertRowid = null. Its one-line fake answer in the acknowledgement test exceeded ktlint's 140 columns, which spotlessApply cannot fix; it is wrapped. Tests only, no behaviour change. :subprojects:sqlite-debugger:testDebugUnitTest 125 tests pass, assembleDebug passes, spotlessApply leaves nothing to change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn --- .../sqlitedebugger/mcp/DatabaseToolsTest.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt b/subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt index 122a8a1182..25a8c57a4b 100644 --- a/subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt +++ b/subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt @@ -1259,7 +1259,7 @@ class DatabaseToolsTest { val ran = mutableListOf() engine.executeAnswer = { path, sql, _ -> ran += "$path: $sql" - ExecuteResult(1) + ExecuteResult(changes = 1, lastInsertRowid = null) } return ran } @@ -1304,7 +1304,10 @@ class DatabaseToolsTest { @Test fun anAcknowledgementCoversOnlyItsOwnDatabaseAndOnlyThisServerProcess() { engine.appConnections += conn(3, "/data/room2.db") val ran = roomSetup() - engine.answer = { _, _, sql, _ -> QueryResult(listOf("1"), if (sql.contains("room_master_table")) listOf(listOf(1L)) else emptyList(), 0, false) } + engine.answer = { _, _, sql, _ -> + val room = sql.contains("room_master_table") + QueryResult(listOf("1"), if (room) listOf(listOf(1L)) else emptyList(), 0, false) + } val t = tools ok("execute", db("/data/room.db").put("sql", "delete from note").put("acknowledge_room", true), t) assertTrue(runTool(t, "execute", db("/data/room2.db").put("sql", "delete from note")).getBoolean("isError")) @@ -1334,7 +1337,13 @@ class DatabaseToolsTest { assertTrue(execute.getString("description").contains("acknowledge_room true")) val prop = execute.getJSONObject("inputSchema").getJSONObject("properties").getJSONObject("acknowledge_room") assertEquals("boolean", prop.getString("type")) - assertFalse(execute.getJSONObject("inputSchema").getJSONArray("required").toString().contains("acknowledge_room")) + assertFalse( + execute + .getJSONObject("inputSchema") + .getJSONArray("required") + .toString() + .contains("acknowledge_room"), + ) } @Test fun stoppingTheServerClosesServerConnections() {