memoryd: Wissensbasen raus (eigener Dienst wikid), git-Verlauf rein
Die kb_*-Werkzeuge sind nach wikid gewandert — ein Dienst je Aufgabe, wie tasksd und skilld. memoryd hat wieder sieben Werkzeuge und tut eine Sache: sich merken. Neu: ist git installiert, wird $MEMORYDIR beim ersten Schreiben ein Repository, und jede Änderung wird festgeschrieben (memory_add/memory_update/memory_delete je Kennung). Ein Speicher ohne Verlauf lässt sich nicht zurückdrehen; "lösche die Erinnerung, die war falsch" ist keine Antwort, wenn sie schon weg ist. Ohne git läuft alles weiter. Die Commit-Meldung besteht nur aus eigenen Kennungen (m00001) — nichts zu quoten, nichts zu injizieren. Tests: 17 (neu: jede Änderung ist ein Commit).
This commit is contained in:
1 parent
d0bd1efe54
commit
f8e336c0f6
2 files changed
+92
-1098
No files matched your search
+14
-94
@@ -148,11 +148,10 @@ def main():
|
||||
|
||||
tools = c.call("tools/list").get("result", {}).get("tools", [])
|
||||
names = sorted(t["name"] for t in tools)
|
||||
want = ["kb_create", "kb_delete", "kb_drop", "kb_entries", "kb_list", "kb_read",
|
||||
"kb_search", "kb_write", "memory_add", "memory_delete", "memory_get",
|
||||
"memory_list", "memory_scopes", "memory_search", "memory_update"]
|
||||
want = ["memory_add", "memory_delete", "memory_get", "memory_list",
|
||||
"memory_scopes", "memory_search", "memory_update"]
|
||||
if names == want:
|
||||
ok("fifteen tools: seven for memories, eight for knowledge bases")
|
||||
ok("seven tools (the knowledge bases moved to wikid)")
|
||||
else:
|
||||
bad("tools are %s" % names)
|
||||
|
||||
@@ -217,96 +216,6 @@ def main():
|
||||
else:
|
||||
bad("memory_scopes: %s" % t[:160])
|
||||
|
||||
# ---- Wissensbasis: benannte Sammlungen, Seiten wie Erinnerungen ----
|
||||
t, err = c.tool("kb_create", name="Olivia Technik",
|
||||
description="was am Fahrzeug gemessen und entschieden wurde")
|
||||
if not err and "created" in t and "olivia-technik" in t:
|
||||
ok("a knowledge base gets a readable slug (Olivia Technik → olivia-technik)")
|
||||
else:
|
||||
bad("kb_create: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_write", kb="olivia-technik", title="Frostschutz",
|
||||
text="G12+ blau, Mischung 50:50, geprüft bei -25 Grad.",
|
||||
tags="kühlmittel")
|
||||
if not err and "created" in t:
|
||||
ok("a page is created in the base")
|
||||
else:
|
||||
bad("kb_write: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_write", kb="olivia-technik", title="Frostschutz",
|
||||
text="G12+ blau, Mischung 60:40, geprüft bei -32 Grad.")
|
||||
if not err and "updated" in t and "e00001" in t:
|
||||
ok("the same title updates the page instead of duplicating it")
|
||||
else:
|
||||
bad("second write: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_read", kb="olivia-technik", title="Frostschutz", history=True)
|
||||
if not err and "-32 Grad" in t and "-25 Grad" in t and "earlier version" in t:
|
||||
ok("the earlier version survives in the page history")
|
||||
else:
|
||||
bad("kb_read with history: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_write", kb="Olivia Technik", title="Ölwechsel",
|
||||
text="OM 364 A: 12 Liter 15W-40, Filter alle 10 000 km.")
|
||||
if not err:
|
||||
ok("the base is addressed by name, not by slug")
|
||||
else:
|
||||
bad("write by display name: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_search", query="wie viel öl braucht der motor", limit=2)
|
||||
if not err and "Ölwechsel" in t and "score=" in t:
|
||||
ok("search finds the right page by meaning across bases")
|
||||
else:
|
||||
bad("kb_search: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_search", query="öl", kb="olivia-technik")
|
||||
if not err and "Ölwechsel" in t and "Frostschutz" not in t.split("\n")[0]:
|
||||
ok("restricting to one base keeps the others out")
|
||||
else:
|
||||
bad("kb_search with kb: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_entries", kb="olivia-technik")
|
||||
if not err and "Frostschutz" in t and "Ölwechsel" in t and "2 entries" in t:
|
||||
ok("kb_entries lists both pages")
|
||||
else:
|
||||
bad("kb_entries: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_list")
|
||||
if not err and "olivia-technik" in t and "2 entries" in t:
|
||||
ok("kb_list shows the base with its page count")
|
||||
else:
|
||||
bad("kb_list: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_drop", kb="olivia-technik")
|
||||
if not err and "not deleting" in t and "confirm" in t:
|
||||
ok("dropping a base needs an explicit yes")
|
||||
else:
|
||||
bad("kb_drop without confirm: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_delete", kb="olivia-technik", title="Frostschutz")
|
||||
if not err and "deleted" in t:
|
||||
ok("a single page can be deleted")
|
||||
else:
|
||||
bad("kb_delete: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_read", kb="olivia-technik", title="Frostschutz")
|
||||
if err or "no page" in t:
|
||||
ok("the deleted page is gone")
|
||||
else:
|
||||
bad("the page is still there: %s" % t[:120])
|
||||
|
||||
t, err = c.tool("kb_drop", kb="olivia-technik", confirm="yes")
|
||||
if not err and "dropped" in t:
|
||||
ok("dropping with confirm removes the base")
|
||||
else:
|
||||
bad("kb_drop with confirm: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_list")
|
||||
if "no knowledge bases" in t:
|
||||
ok("and it is no longer listed")
|
||||
else:
|
||||
bad("the base is still listed: %s" % t[:120])
|
||||
|
||||
# Ohne Embedder: speichern geht weiter, die Suche sagt, was sie tut.
|
||||
stub.shutdown()
|
||||
t, err = c.tool("memory_add", text="Die Pumpe läuft seit März leise.", scope="van/technik")
|
||||
@@ -321,6 +230,17 @@ def main():
|
||||
else:
|
||||
bad("fallback search: %s" % t[:200])
|
||||
|
||||
# ---- Verlauf: git, wenn vorhanden ----
|
||||
if shutil.which("git"):
|
||||
log = subprocess.run(["git", "-C", env["MEMORYDIR"], "log", "--oneline"],
|
||||
capture_output=True, text=True).stdout.strip().splitlines()
|
||||
if len(log) >= 3:
|
||||
ok("every memory change is committed (%d commits)" % len(log))
|
||||
else:
|
||||
bad("expected at least 3 commits, got %s" % log)
|
||||
else:
|
||||
ok("git is not installed here - the versioning test is skipped, not faked")
|
||||
|
||||
t, err = c.tool("memory_delete", id="m00002")
|
||||
if not err and "deleted" in t and not os.path.exists(
|
||||
os.path.join(env["MEMORYDIR"], "m00002.json")):
|
||||
|
||||
Reference in new issue
Block a user