AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
test: make privacy and authentication fixtures discriminate (#1224)
Ilia Alshanetsky8951182ae914
diff --git a/tests/test_chrome_cookies.py b/tests/test_chrome_cookies.pyindex 8b417599..c97b6e34 100644--- a/tests/test_chrome_cookies.py+++ b/tests/test_chrome_cookies.py@@ -36,6 +36,13 @@ from lib.chrome_cookies import (KNOWN_PASSPHRASE = b"test_passphrase_for_unit_tests"KNOWN_AES_KEY = _derive_aes_key(KNOWN_PASSPHRASE)+# Independent v10 vectors: PBKDF2-HMAC-SHA1, saltysalt, 1003 iterations,+# 16-byte key; OpenSSL AES-128-CBC with a 16-space IV and PKCS7 padding.+V10_AES_KEY = bytes.fromhex("bae7b43668299f6b6839c58cff9e97db")+V10_AUTH_TOKEN = bytes.fromhex(+ "76313040a19511ccca2ce72c5b842326adf2e97a36831c0c5943045f7d66f96cbf011e"+)+V10_CT0 = bytes.fromhex("763130189b696f39999dba1b0c8f9c005b8a24")def _encrypt_value_v10(plaintext: str, aes_key: bytes) -> bytes:@@ -151,6 +158,9 @@ class TestPkcs7Padding:class TestKeyDerivation:+ def test_derive_aes_key_matches_v10_known_answer(self):+ assert _derive_aes_key(KNOWN_PASSPHRASE) == V10_AES_KEY+def test_derive_aes_key_deterministic(self):key1 = _derive_aes_key(b"my_passphrase")key2 = _derive_aes_key(b"my_passphrase")@@ -346,17 +356,14 @@ class TestUnencryptedCookies:class TestFullExtraction:@pytest.mark.skipif(not OPENSSL_AVAILABLE, reason="openssl not installed")def test_encrypted_cookies_extracted(self, tmp_path):- """End-to-end: create DB with real v10-encrypted values, extract them."""+ """Extract fixed v10 vectors through SQLite, key derivation, and OpenSSL."""auth_val = "my_auth_token_123"ct0_val = "my_ct0_csrf_456"- encrypted_auth = _encrypt_value_v10(auth_val, KNOWN_AES_KEY)- encrypted_ct0 = _encrypt_value_v10(ct0_val, KNOWN_AES_KEY)-db_path = str(tmp_path / "Cookies")_create_chrome_cookies_db(db_path, [- (".x.com", "auth_token", "", encrypted_auth),- (".x.com", "ct0", "", encrypted_ct0),+ (".x.com", "auth_token", "", V10_AUTH_TOKEN),+ (".x.com", "ct0", "", V10_CT0),(".other.com", "other", "", b""), # unrelated cookie])@@ -370,9 +377,7 @@ class TestFullExtraction:):result = extract_chrome_cookies_macos(".x.com", ["auth_token", "ct0"])- assert result is not None- assert result["auth_token"] == auth_val- assert result["ct0"] == ct0_val+ assert result == {"auth_token": auth_val, "ct0": ct0_val}def test_no_matching_cookies_returns_none(self, tmp_path):db_path = str(tmp_path / "Cookies")diff --git a/tests/test_cookie_extract.py b/tests/test_cookie_extract.pyindex 43b26107..5a65e1f6 100644--- a/tests/test_cookie_extract.py+++ b/tests/test_cookie_extract.py@@ -42,6 +42,9 @@ def mock_firefox_env(tmp_path):default_profile: [(".x.com", "auth_token", "tok_abc123"),(".x.com", "ct0", "ct0_xyz789"),+ (".x.com", "session", "sess_unrequested"),+ (".example.com", "auth_token", "foreign_auth_token"),+ (".example.com", "ct0", "foreign_ct0"),(".example.com", "session", "sess_other"),],}@@ -167,10 +170,7 @@ class TestExtractFirefoxCookies:):result = extract_firefox_cookies(".x.com", ["auth_token", "ct0"])- assert result is not None- assert result["auth_token"] == "tok_abc123"- assert result["ct0"] == "ct0_xyz789"- assert "session" not in result # different domain cookie not included+ assert result == {"auth_token": "tok_abc123", "ct0": "ct0_xyz789"}def test_multiple_profiles_selects_default(self, mock_firefox_env):"""When multiple profiles exist, the one with Default=1 is used."""@@ -314,6 +314,8 @@ class TestExtractFirefoxCookies:profiles_dir = mock_firefox_env(profiles={"abc123.default-release": [+ (".example.com", "auth_token", "foreign_auth_token"),+ (".example.com", "ct0", "foreign_ct0"),(".example.com", "session", "sess_123"),],},diff --git a/tests/test_hosted.py b/tests/test_hosted.pyindex e2189aa5..2a929628 100644--- a/tests/test_hosted.py+++ b/tests/test_hosted.py@@ -568,16 +568,27 @@ def test_persistent_network_failure_gives_up_with_message(remote_env, monkeypatcassert TEST_KEY not in captured.err-def test_emit_json_prints_terminal_row_without_stderr(remote_env, monkeypatch, capsys):+def test_emit_json_prints_terminal_row_without_stderr(remote_env, monkeypatch, capsys, tmp_path):+ terminal = {+ **POLL_COMPLETE,+ "stderr": f"PRIVATE-STDERR-{tmp_path.name}",+ "internal_trace": f"PRIVATE-TRACE-{tmp_path.name}",+ }monkeypatch.setattr(hosted.http, "post", lambda *a, **k: dict(SUBMIT_OK))- monkeypatch.setattr(hosted.http, "get", lambda *a, **k: dict(POLL_COMPLETE))+ monkeypatch.setattr(hosted.http, "get", lambda *a, **k: dict(terminal))rc = hosted.run_hosted("test topic", "default", emit="json",save_dir=None, save_suffix="")captured = capsys.readouterr()assert rc == 0payload = json.loads(captured.out)- assert payload["status"] == "complete"- assert payload["synthesis_text"].startswith("## What happened")- assert payload["raw_markdown"].startswith("# Raw markdown")- assert "stderr" not in payload+ assert payload == {+ "id": SEARCH_ID,+ "status": "complete",+ "synthesis_text": "## What happened\nSynthesized report body.",+ "raw_markdown": "# Raw markdown\nFull dump.",+ }+ assert terminal["stderr"] not in captured.out+ assert terminal["stderr"] not in captured.err+ assert terminal["internal_trace"] not in captured.out+ assert terminal["internal_trace"] not in captured.errassert TEST_KEY not in captured.outdiff --git a/tests/test_library_feed.py b/tests/test_library_feed.pyindex 9ae3f352..a404194d 100644--- a/tests/test_library_feed.py+++ b/tests/test_library_feed.py@@ -3,6 +3,7 @@from __future__ import annotationsimport io+import jsonimport osimport sysfrom contextlib import redirect_stderr, redirect_stdout@@ -11,6 +12,8 @@ from pathlib import Pathfrom unittest import mockfrom xml.etree import ElementTree as ET+import pytest+import last30days as clifrom lib import feed, html_publish, html_render, library@@ -461,27 +464,85 @@ def test_per_suffix_reports_stay_distinct(tmp_path):assert len({e.output_name for e in same_topic}) == 2-def test_scoped_library_ignores_global_briefing_archive(tmp_path, monkeypatch):- import io- from contextlib import redirect_stdout, redirect_stderr- from unittest import mock-- _write_report(tmp_path)+def public_briefing_archives(tmp_path, monkeypatch):+ memory = tmp_path / "memory"+ memory.mkdir()+ _write_report(memory)+ local_briefs = memory / "briefings"global_briefs = tmp_path / "global-briefings"- global_briefs.mkdir()- (global_briefs / "2026-07-11.json").write_text(- '{"status":"ok","date":"2026-07-11","total_new":3,"total_topics":1,'- '"top_finding":{"title":"OTHER CLIENT SECRET"},"topics":[{"name":"X","new_count":1}]}',- encoding="utf-8",- )+ local_title = f"LOCAL CLIENT FINDING {tmp_path.name}"+ foreign_title = f"OTHER CLIENT FINDING {tmp_path.name}"+ for directory, day, title in (+ (local_briefs, "2026-07-12", local_title),+ (global_briefs, "2026-07-11", foreign_title),+ ):+ directory.mkdir()+ (directory / f"{day}.json").write_text(json.dumps({+ "status": "ok", "date": day, "total_new": 3, "total_topics": 1,+ "top_finding": {+ "title": title, "source": "reddit",+ "source_url": "https://www.reddit.com/r/test/comments/dummy/finding/",+ },+ "topics": [{"name": "X", "new_count": 3}],+ }), encoding="utf-8")+ monkeypatch.delenv("LAST30DAYS_MEMORY_DIR", raising=False)+ monkeypatch.setattr(library, "DEFAULT_MEMORY_DIR", memory)monkeypatch.setattr(library, "DEFAULT_BRIEFS_DIR", global_briefs)- with mock.patch.object(cli.sys, "argv",- ["last30days.py", "library", "feed", "--save-dir", str(tmp_path)]), \- mock.patch.object(cli.env, "get_config", lambda **_k: {}), \- redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):+ monkeypatch.setattr(cli.env, "get_config", lambda **_k: {})+ return memory, local_title, foreign_title+++def test_scoped_library_ignores_global_briefing_archive(public_briefing_archives, monkeypatch):+ memory, local_title, foreign_title = public_briefing_archives+ monkeypatch.setattr(sys, "argv", [+ "last30days.py", "library", "feed", "--save-dir", str(memory),+ ])+ with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):assert cli.main() == 0- blob = (tmp_path / "index.html").read_text(encoding="utf-8")- assert "OTHER CLIENT SECRET" not in blob++ index = (memory / "index.html").read_text(encoding="utf-8")+ assert foreign_title not in index+ assert local_title in index+ namespace = {"atom": feed.ATOM_NS}+ atom = ET.parse(memory / "feed.xml")+ assert {node.text for node in atom.findall("atom:entry/atom:title", namespace)} == {+ local_title, "Agent loops are becoming durable",+ }+ expected_briefs = {+ "ai-agents-c7760ea1-2026-07-10.html",+ "daily-research-briefing-739d632a-2026-07-12.html",+ }+ assert {path.name for path in (memory / "briefs").glob("*.html")} == expected_briefs+ assert {node.attrib["href"] for node in atom.findall("atom:entry/atom:link", namespace)} == {+ f"briefs/{name}" for name in expected_briefs+ }+ for path in (memory / "briefs").glob("*.html"):+ assert foreign_title not in path.read_text(encoding="utf-8")+++def test_default_library_includes_global_briefing_archive(public_briefing_archives, monkeypatch):+ memory, local_title, foreign_title = public_briefing_archives+ monkeypatch.setattr(sys, "argv", ["last30days.py", "library", "feed"])+ with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):+ assert cli.main() == 0++ index = (memory / "index.html").read_text(encoding="utf-8")+ assert foreign_title in index+ assert local_title not in index+ namespace = {"atom": feed.ATOM_NS}+ atom = ET.parse(memory / "feed.xml")+ assert {node.text for node in atom.findall("atom:entry/atom:title", namespace)} == {+ foreign_title, "Agent loops are becoming durable",+ }+ expected_briefs = {+ "ai-agents-c7760ea1-2026-07-10.html",+ "daily-research-briefing-c99e697b-2026-07-11.html",+ }+ assert {path.name for path in (memory / "briefs").glob("*.html")} == expected_briefs+ assert foreign_title in (+ memory / "briefs" / "daily-research-briefing-c99e697b-2026-07-11.html"+ ).read_text(encoding="utf-8")def test_hand_written_index_is_backed_up_not_clobbered(tmp_path, monkeypatch):diff --git a/tests/test_x_envelope.py b/tests/test_x_envelope.pyindex 1b7bd128..ee609113 100644--- a/tests/test_x_envelope.py+++ b/tests/test_x_envelope.py@@ -510,7 +510,11 @@ class TestInputBounds:as_json.write_text('{"X_BEARER_TOKEN": "SECRETVALUE"}', encoding="utf-8")_assert_contract(str(as_json), must_not_contain=["SECRETVALUE"])- def test_config_dir_and_credential_stores_are_rejected(self, tmp_path, monkeypatch):+ @pytest.mark.parametrize("store", [".grok", ".xurl", "config"])+ @pytest.mark.parametrize("via_symlink", [False, True], ids=["direct", "symlink"])+ def test_config_dir_and_credential_stores_are_rejected(+ self, tmp_path, monkeypatch, store, via_symlink,+ ):home = tmp_path / "home"cfg = tmp_path / "cfg"for directory in (home / ".grok", home / ".xurl", cfg):@@ -519,13 +523,21 @@ class TestInputBounds:monkeypatch.setenv("USERPROFILE", str(home))monkeypatch.setattr(env, "CONFIG_DIR", cfg)monkeypatch.setattr(env, "CONFIG_FILE", cfg / ".env")- for target in (home / ".grok" / "auth.json", home / ".xurl" / "tokens.json", cfg / "posts.json"):- target.write_text(json.dumps({"token": "SECRETVALUE"}), encoding="utf-8")- _assert_contract(str(target), must_not_contain=["SECRETVALUE"])- # A symlink into a store is resolved before the check.- link = tmp_path / "link.json"- link.symlink_to(home / ".grok" / "auth.json")- _assert_contract(str(link), must_not_contain=["SECRETVALUE"])+ sentinel = f"SECRETVALUE-{tmp_path.name}"+ payload = _envelope([_call("topic", posts=[_row(0, text=sentinel)])])+ allowed = _write(tmp_path, payload)+ assert _read(allowed).accepted == 1++ directory = cfg if store == "config" else home / store+ target = Path(_write(directory, payload))+ path = target+ if via_symlink:+ path = tmp_path / "link.json"+ path.symlink_to(target)+ with mock.patch.object(Path, "read_bytes", autospec=True, side_effect=Path.read_bytes) as read_bytes:+ message = _assert_contract(str(path), must_not_contain=[sentinel])+ read_bytes.assert_not_called()+ assert "is inside a configuration or credential directory" in messagedef test_wrong_suffix_directory_and_missing_file_are_rejected(self, tmp_path):_assert_contract(_write(tmp_path, _envelope([]), "posts.txt"))