Files
openswarm/backend/tests/test_cases/browser/test_browser_meta_playbook.py
T
haikdcandGitHub 9c95342704 Haik/feat/test runner (#86)
* [haik]: ckpt, added in the test runner skelton i made in another repo -> still gotta make tweaks to fold it onto the current repo

* [haik]: restructure backend test layout: move 37 test files from backend/tests/ into backend/tests/test_cases/, add backend/tests/run.sh one-command launcher that auto-provisions both runner and test venvs with stamp-based caching, update runner config.json to point test_paths at test_cases/ and fix venv_python path, revise runner README with run.sh usage and clearer setup instructions, and gitignore the .runner-venv directory

* [haik]: refactor: reorganize backend/tests/test_cases from flat structure into domain subdirectories — moved 36 test files into auth/, browser/, labeling/, service/, settings/, and web_search/ for better discoverability and grouping

* [haik]: overhaul test picker UI and add post-run rerun loop: replace checkbox glyphs with fzf-style row recolouring (coral=full, lighter coral=partial) and a right-pinned selection dot, add config-driven icon tiers (nerd/emoji/unicode/ascii) with per-glyph graceful degradation, replace the modal -k keyword screen with an inline live-filtering search bar that prunes the tree on every keystroke, add warm Anthropic-dark coral theme, toolbar flag chips replacing the old status line, and a floating help badge overlay; add rerun_prompt.py with inline Textual pill prompt (rerun all/failed/passed/exit) shown after each TTY run, wire it into main.py as a post-run loop; change run_tests to return (exit_code, RunSummary) tracking collected/passed/failed node IDs via new Dashboard methods; add icons field to config.py and config.json (set to nerd), document icon tiers and Nerd Font setup in README, set Hack Nerd Font in .vscode/settings.json, add .runner-venv to linter excludes
2026-06-14 07:02:30 -07:00

49 lines
1.7 KiB
Python

"""Cross-site meta-playbook (browser memory tier 3): seeds on day one, absorbs
site-agnostic lessons with no extra LLM call, dedups + caps, survives a restart."""
import tempfile
import pytest
from backend.apps.agents.browser import browser_meta_playbook as meta
@pytest.fixture(autouse=True)
def isolated(monkeypatch):
monkeypatch.setenv("OPENSWARM_BROWSER_META_DIR", tempfile.mkdtemp(prefix="meta_test_"))
meta.clear(wipe_disk=True)
yield
meta.clear(wipe_disk=True)
def test_seeded_on_day_one():
b = meta.get_meta()
assert len(b) >= 4
assert any("composer" in x.lower() and "clear" in x.lower() for x in b)
assert "General web priors" in meta.format_for_prompt()
def test_absorb_adds_dedups_and_caps():
n0 = len(meta.get_meta())
assert meta.absorb(["clicking a date opens a picker, it is not a navigation"]) is True
assert len(meta.get_meta()) == n0 + 1
# identical lesson (case-insensitive) doesn't grow it
assert meta.absorb(["Clicking a DATE opens a picker, it is not a navigation"]) is False
# empty input is a no-op
assert meta.absorb([]) is False
# capped: flooding never exceeds the cap
meta.absorb([f"unique universal lesson number {i}" for i in range(50)])
assert len(meta.get_meta()) <= meta._MAX_BULLETS
def test_survives_a_restart():
meta.absorb(["a durable cross-site lesson worth keeping"])
meta.clear(wipe_disk=False) # in-memory gone, disk intact (== restart)
assert meta._cache is None
assert any("durable cross-site lesson" in x for x in meta.get_meta())
def test_secrets_never_persist_into_meta():
meta.absorb(["the login token is sk-ant-api03-deadbeef and it works"])
blob = " ".join(meta.get_meta())
assert "sk-ant-api03" not in blob