remove :storage-ksqlite (conversation/message) and related tests; decouple schema from journal
ci / JVM build + tests (push) Successful in 6m6s
ci / JVM build + tests (push) Successful in 6m6s
This commit is contained in:
+37
-1
@@ -26,11 +26,38 @@ import kotlinx.coroutines.withContext
|
||||
*
|
||||
* ВНИМАНИЕ: `:storage-ksqlite/KsqliteWorkingMemoryStore.kt` остаётся на диске —
|
||||
* это копия, не замена. Не удалять старый файл; миграция consumers'ов — отдельно.
|
||||
*
|
||||
* ## Lifecycle соединения
|
||||
*
|
||||
* Семантика владения connection'ом идентична
|
||||
* `pw.binom.agentik.journal.ksqlite.KsqliteJournalStore`:
|
||||
* - `KsqliteContextStore(connection)` — внешнее соединение, store НЕ
|
||||
* закрывает его в [close].
|
||||
* - `KsqliteContextStore(path)` — открывает файловое соединение,
|
||||
* закрывает его в [close].
|
||||
* - `KsqliteContextStore.memory(name)` — in-memory, закрывает в [close].
|
||||
*
|
||||
* [Schema.migrate] прогоняется ВСЕГДА при конструировании (idempotent).
|
||||
*/
|
||||
class KsqliteContextStore(
|
||||
class KsqliteContextStore private constructor(
|
||||
private val connection: SQLiteConnection,
|
||||
private val ownsConnection: Boolean,
|
||||
) : ContextStore {
|
||||
|
||||
constructor(path: String) : this(
|
||||
connection = SQLiteConnection.open(path = path),
|
||||
ownsConnection = true,
|
||||
)
|
||||
|
||||
constructor(connection: SQLiteConnection) : this(
|
||||
connection = connection,
|
||||
ownsConnection = false,
|
||||
)
|
||||
|
||||
init {
|
||||
Schema.migrate(connection)
|
||||
}
|
||||
|
||||
private val mutex = Mutex()
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
|
||||
@@ -179,6 +206,15 @@ class KsqliteContextStore(
|
||||
maxOrderIdxStmt.close()
|
||||
dropFromIdxStmt.close()
|
||||
insertSummaryStmt.close()
|
||||
if (ownsConnection) connection.close()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun memory(name: String? = null): KsqliteContextStore =
|
||||
KsqliteContextStore(
|
||||
connection = SQLiteConnection.memory(name),
|
||||
ownsConnection = true,
|
||||
)
|
||||
}
|
||||
|
||||
private fun maxOrderIdx(conversationId: String): Long {
|
||||
|
||||
+3
-11
@@ -12,16 +12,9 @@ import kotlin.test.assertTrue
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
* Тесты для [KsqliteContextStore] — точная копия
|
||||
* `KsqliteWorkingMemoryStoreTest` из `:storage-ksqlite`, с переименованием
|
||||
* типов (`WorkingMemoryStore` → `ContextStore`) и обновлённым пакетом для
|
||||
* `Content` (`pw.binom.agentik.journal` — новый canonical, но структура
|
||||
* та же).
|
||||
*
|
||||
* Тестовая фикстура: in-memory SQLiteConnection, [Schema.migrate] в @BeforeTest,
|
||||
* `KsqliteContextStore(conn)` + ручной close в @AfterTest. Никакой внешней
|
||||
* зависимости от `KsqliteStores` из `:storage-ksqlite` — этот модуль
|
||||
* автономный.
|
||||
* Тесты для [KsqliteContextStore]. Автономная фикстура: in-memory
|
||||
* SQLiteConnection + конструктор `KsqliteContextStore(connection)` — store сам
|
||||
* прогоняет `Schema.migrate` в init, явный вызов не нужен.
|
||||
*/
|
||||
class KsqliteContextStoreTest {
|
||||
|
||||
@@ -31,7 +24,6 @@ class KsqliteContextStoreTest {
|
||||
@BeforeTest
|
||||
fun setup() {
|
||||
conn = SQLiteConnection.memory("ctx-${kotlin.random.Random.nextLong()}")
|
||||
Schema.migrate(conn)
|
||||
store = KsqliteContextStore(conn)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user