feat(archivar): Auto-Onboarding v2 — strukturiertes 4-Fragen-Interview pro Raum

Ersetzt den v1-Text-Flow ('Name = Thema') durch ein strukturiertes
Interview mit 4 Fragen pro fehlendem Raum:

1. theme — 'Worum geht es in diesem Raum? (1–2 Sätze)'
2. keywords_100 — 'Welche Begriffe treffen SICHER zu? (Sofort-Match)'
3. keywords_context — 'Welche Begriffe deuten auf das Thema hin? (Kontext-Match)'
4. catch_all — 'Soll dieser Raum der Catch-All sein? (Ja/Nein)'

Änderungen:
- adapter.py: _start_onboarding() sendet Buttons pro Raum
  [Projektraum einrichten] [Überspringen] [Später]
- adapter.py: _onboarding_state dict steuert Interview-Phasen
- adapter.py: _process_onboarding_response() verarbeitet Button-Klicks
  (ONBOARD:<room_id>::<action>) und Text-Antworten auf die 4 Fragen
- adapter.py: _ask_onboarding_question(), _onboarding_next_room(),
  _finish_onboarding() für den strukturierten Ablauf
- adapter.py: _process_incoming() erkennt ONBOARD:-Prefix und
  prüft Operator-Raum-Zugehörigkeit
- room_map.py: RoomMap.save() mit fcntl.flock File-Lock gegen
  parallele Schreibzugriffe
- room_map.py: add_or_update_room() akzeptiert keywords_100 und
  keywords_context getrennt (v2-Schema)
- room-map.schema.json: version minimum=2, keywords→keywords_100
  + keywords_context
- room-map.json: generische Platzhalter (öffentliches Repo)
- Tests: 4 neue v2-Tests (keyword-Trennung, File-Lock, reload,
  Single-Room v2-Felder), bestehende Tests auf v2-Schema migriert

Invarianten erhalten: Single-Room-Regel, DM-Ignorierung,
onboarding_active-Flag, kein Dauer-Check.
This commit is contained in:
Bernd (Hermes)
2026-06-15 19:39:04 +02:00
parent 6e02a12431
commit 2eb723fb63
5 changed files with 519 additions and 217 deletions
+128 -6
View File
@@ -24,14 +24,15 @@ class TestAutoOnboarding(unittest.TestCase):
self.temp_dir = tempfile.TemporaryDirectory()
self.temp_path = Path(self.temp_dir.name) / "room-map.json"
# Mock-Daten für die RoomMap
# Mock-Daten für die RoomMap (v2 Schema)
self.test_data = {
"version": 1,
"version": 2,
"rooms": {
"catchall_room_id": {
"name": "#CatchAll",
"theme": "Catch-all room for everything else",
"keywords": [],
"keywords_100": [],
"keywords_context": [],
"catch_all": True
}
},
@@ -136,18 +137,20 @@ class TestAutoOnboarding(unittest.TestCase):
# Erstelle Testdaten mit bereits vorhandenen Räumen
test_data_with_rooms = {
"version": 1,
"version": 2,
"rooms": {
"catchall_room_id": {
"name": "#CatchAll",
"theme": "Catch-all room for everything else",
"keywords": [],
"keywords_100": [],
"keywords_context": [],
"catch_all": True
},
"room1_id": {
"name": "#Room1",
"theme": "First test room",
"keywords": ["test"],
"keywords_100": ["test"],
"keywords_context": [],
"catch_all": False
}
},
@@ -174,5 +177,124 @@ class TestAutoOnboarding(unittest.TestCase):
self.assertEqual(len(missing), 0)
class TestAutoOnboardingV2(unittest.TestCase):
"""v2-spezifische Tests: keywords_100/keywords_context Trennung, File-Lock."""
def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
self.temp_path = Path(self.temp_dir.name) / "room-map.json"
self.test_data = {
"version": 2,
"rooms": {
"catchall_room_id": {
"name": "#CatchAll",
"theme": "Catch-all room",
"keywords_100": [],
"keywords_context": [],
"catch_all": True
}
},
"excluded_rooms": [],
"fact_store_path": str(self.temp_path.parent / "docs")
}
with open(self.temp_path, 'w') as f:
json.dump(self.test_data, f)
def tearDown(self):
self.temp_dir.cleanup()
def test_v2_add_or_update_room_separate_keywords(self):
"""Testet dass add_or_update_room keywords_100 und keywords_context trennt."""
room_map = RoomMap._from_dict(self.test_data)
room_map.add_or_update_room(
room_id="proj_room_id",
name="#Projektraum",
theme="Entwicklung des Plugins",
keywords_100=["plugin", "gateway"],
keywords_context=["architektur", "deployment"],
catch_all=False,
)
entry = room_map.rooms["proj_room_id"]
self.assertEqual(entry.keywords_100, ["plugin", "gateway"])
self.assertEqual(entry.keywords_context, ["architektur", "deployment"])
self.assertNotEqual(entry.keywords_100, entry.keywords_context)
def test_v2_single_room_auto_catch_all_fields(self):
"""Testet dass Single-Room-Regel v2-Felder korrekt setzt."""
room_map = RoomMap._from_dict(self.test_data)
# Simuliere: nur 1 relevanter Raum, nicht in Map
room_map.add_or_update_room(
room_id="single_room_id",
name="#SingleRoom",
theme="Automatisch zugewiesener Catch-All-Raum",
keywords_100=[],
keywords_context=[],
catch_all=True,
)
entry = room_map.rooms["single_room_id"]
self.assertTrue(entry.catch_all)
self.assertEqual(entry.keywords_100, [])
self.assertEqual(entry.keywords_context, [])
# Altes catch_all (catchall_room_id) sollte NICHT mehr catch_all sein
self.assertFalse(room_map.rooms["catchall_room_id"].catch_all)
def test_v2_save_with_file_lock(self):
"""Testet dass RoomMap.save() mit File-Lock funktioniert."""
room_map = RoomMap._from_dict(self.test_data)
room_map.add_or_update_room(
room_id="test_room_id",
name="#TestRaum",
theme="Test-Thema",
keywords_100=["test"],
keywords_context=["versuch"],
catch_all=False,
)
# Save sollte ohne Exception durchlaufen
RoomMap.save(room_map, self.temp_path)
# Reload und verifiziere
reloaded = RoomMap.load(self.temp_path)
entry = reloaded.rooms["test_room_id"]
self.assertEqual(entry.name, "#TestRaum")
self.assertEqual(entry.theme, "Test-Thema")
self.assertEqual(entry.keywords_100, ["test"])
self.assertEqual(entry.keywords_context, ["versuch"])
self.assertFalse(entry.catch_all)
def test_v2_reload_updates_in_memory(self):
"""Testet dass reload() die In-Memory-Daten aktualisiert."""
room_map = RoomMap._from_dict(self.test_data)
# Schreibe eine geänderte Map auf Disk
modified_data = dict(self.test_data)
modified_data["rooms"]["new_room_id"] = {
"name": "#NeuerRaum",
"theme": "Neues Thema",
"keywords_100": ["neu"],
"keywords_context": ["frisch"],
"catch_all": False,
}
with open(self.temp_path, 'w') as f:
json.dump(modified_data, f)
# Vor reload: new_room_id nicht in Map
self.assertNotIn("new_room_id", room_map.rooms)
# Reload
room_map.reload(self.temp_path)
# Nach reload: new_room_id in Map
self.assertIn("new_room_id", room_map.rooms)
entry = room_map.rooms["new_room_id"]
self.assertEqual(entry.keywords_100, ["neu"])
self.assertEqual(entry.keywords_context, ["frisch"])
if __name__ == '__main__':
unittest.main()