Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

fix(notebook): a save that did not happen fails instead of saying "Saved."

booboosui358dc5606e19
diff --git a/core/src/main/kotlin/net/kuafuai/andee/config/NotebookBook.kt b/core/src/main/kotlin/net/kuafuai/andee/config/NotebookBook.kt
index 34aa4b4..9e8a833 100644
--- a/core/src/main/kotlin/net/kuafuai/andee/config/NotebookBook.kt
+++ b/core/src/main/kotlin/net/kuafuai/andee/config/NotebookBook.kt
@@ -108,13 +108,19 @@ class NotebookBook(private val store: NotebookStore) {
.put("scenes", JSONArray())
.put("meta", JSONObject())
+ /**
+ * Throws when the store refuses. Every caller is a tool the model called,
+ * and the throw becomes the tool's error: a save that did not happen must
+ * not come back as "Saved." — the model would tell the user it remembered.
+ */
private fun write(next: JSONObject) {
prune(next)
- // Never report a save that did not happen — see the same guard in
- // Vault.write.
if (!store.write(next.toString())) {
Log.e(TAG, "notebook: the store refused the write, nothing written")
- return
+ throw IllegalStateException(
+ "The notebook could not be saved on this device, so nothing was stored. " +
+ "Tell the user plainly that you could not remember this, rather than saying you did.",
+ )
}
cached = next
}
@@ -330,7 +336,8 @@ class NotebookBook(private val store: NotebookStore) {
.thenByDescending { it.updatedAt },
)
val take = ranked.take(limit.coerceIn(1, 30))
- if (take.isNotEmpty()) bumpHits(take.map { it.name })
+ // Bookkeeping only: a recall still answers when the counter cannot be saved.
+ if (take.isNotEmpty()) runCatching { bumpHits(take.map { it.name }) }
return take
}
diff --git a/core/src/test/kotlin/net/kuafuai/andee/config/NotebookBookTest.kt b/core/src/test/kotlin/net/kuafuai/andee/config/NotebookBookTest.kt
index ec52a10..189213d 100644
--- a/core/src/test/kotlin/net/kuafuai/andee/config/NotebookBookTest.kt
+++ b/core/src/test/kotlin/net/kuafuai/andee/config/NotebookBookTest.kt
@@ -77,14 +77,15 @@ class NotebookBookTest {
}
@Test
- fun `a write the store refuses is not reported back as saved state`() {
+ fun `a write the store refuses fails loudly and leaves nothing behind`() {
val store = object : NotebookStore {
override fun read(): String? = null
override fun write(plain: String) = false
override fun wipe() {}
}
val b = NotebookBook(store)
- b.remember("fruit", "likes mango", "", "user")
+ val failed = runCatching { b.remember("fruit", "likes mango", "", "user") }.isFailure
+ assertTrue("remember must throw so the model is not told it saved", failed)
assertTrue(b.memories().isEmpty())
}