feat(nutrition): meals belong to the person who logged them
- meals.user_id (v1 databases gain it on open, DEFAULT '' keeps their meals the single user's); insert_meal, get_meals_between and delete_meal take the person, and delete only removes that person's meal. - turn_state.set_user / ToolContext.user_id carry the asker; logMeal, fetchMeals and deleteMeal use it. The v2 brain sets it for each reply. - Tests: two people never see or delete each other's meals, no user is v1's single user, and a v1 database opens with its meals kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -344,3 +344,28 @@ def test_the_brain_turns_off_the_single_user_memory(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(engine, "run_reply_engine", fake_engine)
|
||||
brain_mod.JarvisBrain().reply("100", "q", HistoryContext())
|
||||
assert seen["legacy_memory"] is False
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_brain_tells_tools_who_is_asking(tmp_path, monkeypatch):
|
||||
pytest.importorskip("mcp") # the real brain needs the jarvis dependencies (--brain)
|
||||
from jarvis.memory.history import HistoryContext
|
||||
from jarvis.reply import turn_state
|
||||
from voice_worker import brain as brain_mod
|
||||
|
||||
cfg = tmp_path / "config.json"
|
||||
cfg.write_text(json.dumps({"db_path": str(tmp_path / "jarvis.db")}))
|
||||
monkeypatch.setenv("JARVIS_CONFIG_PATH", str(cfg))
|
||||
seen = []
|
||||
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True):
|
||||
seen.append(turn_state.get_user())
|
||||
return "ok"
|
||||
|
||||
import jarvis.reply.engine as engine
|
||||
monkeypatch.setattr(engine, "run_reply_engine", fake_engine)
|
||||
b = brain_mod.JarvisBrain()
|
||||
b.reply("100", "q", HistoryContext())
|
||||
b.reply("200", "q", HistoryContext())
|
||||
assert seen == ["100", "200"]
|
||||
assert turn_state.get_user() is None # nothing left behind on this thread
|
||||
|
||||
Reference in New Issue
Block a user