Files
wehub-resource-sync 555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:45 +08:00

62 lines
1.9 KiB
Python

"""Tests for rubric deduplication in on_user_prompt.sh."""
from __future__ import annotations
import json
import os
import subprocess
import pytest
SCRIPTS_DIR = os.path.join(os.path.dirname(__file__), "..", "scripts")
@pytest.fixture(autouse=True)
def _clean_rubric_flag(tmp_path, monkeypatch):
"""Use a temp dir for the rubric flag file and clean msg counter."""
monkeypatch.setenv("MEM0_RUBRIC_DIR", str(tmp_path))
msg_count_file = "/tmp/mem0_msg_count_testuser"
yield
if os.path.exists(msg_count_file):
os.unlink(msg_count_file)
def _run_hook(prompt: str, env_overrides: dict | None = None, session_id: str = "test-sess-001") -> str:
"""Run on_user_prompt.sh with a simulated prompt and return stdout."""
env = {
**os.environ,
"USER": "testuser",
"MEM0_API_KEY": "test-key-123",
"MEM0_RESOLVED_USER_ID": "testuser",
"MEM0_PROJECT_ID": "test-project",
"MEM0_BRANCH": "main",
"MEM0_PREFETCH": "false",
}
if env_overrides:
env.update(env_overrides)
input_json = json.dumps({"prompt": prompt, "session_id": session_id})
result = subprocess.run(
["bash", os.path.join(SCRIPTS_DIR, "on_user_prompt.sh")],
input=input_json,
capture_output=True,
text=True,
env=env,
timeout=10,
)
return result.stdout
def test_first_prompt_gets_full_rubric():
"""First substantial prompt of session gets full memory check rubric."""
output = _run_hook("How should we refactor the auth module?")
assert "Mem0 searches apply" in output
assert "metadata.type" in output
def test_second_prompt_gets_no_rubric():
"""Second prompt of session emits nothing — rubric and tips only on first prompt."""
_run_hook("How should we refactor the auth module?")
output = _run_hook("What about the database layer?")
assert output.strip() == ""