Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix(setup): retain consented browser selections (#1209)

Ilia Alshanetsky46988ff8fbf8
diff --git a/CONFIGURATION.md b/CONFIGURATION.md
index 369d50a6..9cbd41a2 100644
--- a/CONFIGURATION.md
+++ b/CONFIGURATION.md
@@ -89,7 +89,7 @@ On the very first `/last30days` run (no `~/.config/last30days/.env`, or `SETUP_C
The Modal and Non-Modal flows share the same consent points:
-1. **Browser cookies** - the model asks before reading anything. On yes it runs `setup --allow-browser-cookies`, which extracts Firefox/Safari cookies (never Chrome unless `FROM_BROWSER=auto` or a named Chromium browser is explicitly configured) to unlock X/Twitter and other logged-in sources, and installs yt-dlp + the keyless Digg CLI. On no it runs setup without `--allow-browser-cookies` (or with `FROM_BROWSER=off`), which skips all cookie reads and still installs the tools. The engine saves the decision as `BROWSER_CONSENT=true` or `false`; refusal blocks native browser and CDP reads on later runs, even if an older `FROM_BROWSER` selection remains. A later consented setup can replace the refusal. An explicit `FROM_BROWSER=off` remains a separate denial until you change it.
+1. **Browser cookies** - the model asks before reading anything and explains that permission covers later research runs. On yes it runs `setup --allow-browser-cookies`. On macOS, the scan checks Chrome and other Chromium browsers first, then Firefox and Safari, unless you already configured `FROM_BROWSER`. On Windows and Linux, this native cookie scan supports Firefox only; under WSL2, it also falls back to Windows Firefox. Unless you already configured `FROM_BROWSER`, setup saves the browser names that supplied complete cookies in `FROM_BROWSER` so later research can read those signed-in sessions again; it never saves the cookie values. If different services use different browsers, it saves their comma-separated names. Chromium reads on macOS may prompt for Keychain access again on later runs; choose **Always Allow** if you want to grant continuing OS access. Setup also installs yt-dlp + the keyless Digg CLI. On no it runs setup without `--allow-browser-cookies` (or with `FROM_BROWSER=off`), which skips all cookie reads and still installs the tools. The engine saves the decision as `BROWSER_CONSENT=true` or `false`; refusal blocks native browser and CDP reads on later runs, even if an older `FROM_BROWSER` selection remains. To disable these reads later, set `BROWSER_CONSENT=false` or `FROM_BROWSER=off` in `~/.config/last30days/.env`. A later consented setup can replace the refusal. An explicit `FROM_BROWSER=off` remains a separate denial until you change it. The `agentcookie` sidecar has its own `AGENTCOOKIE=off` control.
2. **Full Disk Access (macOS)** - if a cookie read is permission-denied, the model surfaces the System Settings > Privacy & Security > Full Disk Access fix and offers one retry.
3. **ScrapeCreators GitHub signup** - offered on every first run (10,000 free calls). On consent it runs `setup --github`, which opens a browser for GitHub device-auth (or registers instantly via the `gh` CLI when installed) and, on success, **persists `SCRAPECREATORS_API_KEY` automatically** (0o600, masked in output) so TikTok, Instagram, empty-path Reddit search backup, and the YouTube transcript fallback activate on the next run. Decline anytime; you can run it later by asking to set up ScrapeCreators. The Step 5 opt-in has two tiers, both comment-enabled: **Recommended** (TikTok + Instagram posts AND top comments, plus YouTube comments — `INCLUDE_SOURCES=tiktok,instagram,youtube_comments,tiktok_comments,instagram_comments`) and **Everything**, which also adds Threads + Pinterest. Comments are on by default; Threads and Pinterest are the only opt-in extras.
diff --git a/changelog.d/+cr-004-chromium-setup-auth.fixed.md b/changelog.d/+cr-004-chromium-setup-auth.fixed.md
new file mode 100644
index 00000000..47376e6d
--- /dev/null
+++ b/changelog.d/+cr-004-chromium-setup-auth.fixed.md
@@ -0,0 +1,2 @@
+Fixed browser selections being lost after consented setup, including Chromium and services signed in through different browsers, so later research can reuse their sessions without saving cookie values.
+Both onboarding flows now explain future browser reads before consent, possible repeated macOS Keychain prompts, and how to disable native browser and CDP access.
diff --git a/skills/last30days/SKILL.md b/skills/last30days/SKILL.md
index 6567a30d..f91acffe 100644
--- a/skills/last30days/SKILL.md
+++ b/skills/last30days/SKILL.md
@@ -592,7 +592,7 @@ Options:
**If the user picks Auto setup:**
Get cookie consent first. Check if `BROWSER_CONSENT=true` already exists in `~/.config/last30days/.env`; if so, skip the consent prompt and run `setup --allow-browser-cookies` directly. Otherwise **call AskUserQuestion:**
-Question: "Auto setup installs the free CLIs either way - yt-dlp (YouTube), Digg, arXiv, and Techmeme. The only thing that needs your OK is reading your browser's x.com cookies to authenticate X/Twitter search: I check Chrome first (a one-time macOS Keychain prompt may appear; click Always Allow), then Firefox and Safari. Cookies are read live, never saved to disk. Include X?"
+Question: "Auto setup installs the free CLIs either way - yt-dlp (YouTube), Digg, arXiv, and Techmeme. May I read your browser's x.com cookies for X/Twitter and other logged-in sources now and on later research runs? On macOS I check Chrome and other Chromium browsers first, then Firefox and Safari. On Windows and Linux I use Firefox, with Windows Firefox as a fallback under WSL. Your existing browser selection takes precedence. Setup remembers successful browser names, never cookie values. macOS Keychain may prompt again on later runs; choose Always Allow if you want continuing OS access. You can stop native browser and CDP reads by setting BROWSER_CONSENT=false or FROM_BROWSER=off in ~/.config/last30days/.env. Include X?"
Options (give each option the description shown):
- "Yes - X cookies + all CLIs" - description: "Read x.com cookies for X/Twitter search AND install yt-dlp (YouTube), Digg, arXiv, and Techmeme." Run `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py setup --allow-browser-cookies` (relative to the skill root). The engine saves `BROWSER_CONSENT=true`; do not append a duplicate marker.
- "Skip X - just the CLIs" - description: "No cookie reads. Still installs yt-dlp (YouTube), Digg, arXiv, and Techmeme." Run `FROM_BROWSER=off "${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py setup`. The engine saves `BROWSER_CONSENT=false`, so the refusal also applies on future runs. If the invocation already includes a topic, immediately research it with `--no-browser-cookies`, then resume Step 4 (and Step 5 if a key is saved) in the same run after the findings; Step 6 stays skipped because the topic was supplied.
@@ -600,7 +600,9 @@ Options (give each option the description shown):
**Grok CLI is an opt-in backup, not a setup-time recommendation.** Do NOT check for grok first or offer it as a primary option during setup. A leftover `~/.grok/auth.json` must never steal the X lane. If the user mentions having a Grok account, tell them: "You can use the Grok CLI by pinning `LAST30DAYS_X_BACKEND=grok` in your `.env` after running `grok login`. This is opt-in because a leftover grok login should not take over X automatically." Do not call it free — it needs a Grok plan.
-The consented `setup --allow-browser-cookies` run extracts cookies (Chrome/Chromium family first via the Keychain with no Full Disk Access, then Firefox and Safari as fallbacks; the winning browser is pinned for future runs only when it is Firefox or Safari, so Chrome never re-triggers the Keychain prompt on later runs) and best-effort installs yt-dlp (YouTube), the free keyless Digg CLI (`digg-pp-cli` via `@mvanhorn/printing-press-library install digg --cli-only`; Digg activates only when the binary is on the **agent subprocess PATH**, typically `$HOME/.local/bin`; setup reports honestly if installed off-PATH; recommend-only if `npx` is unavailable), plus the free keyless arXiv and Techmeme CLIs. Show the user what was found and installed - including whether Digg landed on PATH (active) or off-PATH (installed but not yet active).
+The consented `setup --allow-browser-cookies` run extracts cookies using the platform order explained in the prompt. Unless `FROM_BROWSER` is already configured, setup saves the browsers that supplied complete cookies as a comma-separated `FROM_BROWSER` list, including Chromium browsers. It normalizes Windows Firefox's `firefox-wsl` source label to `firefox`. It never saves cookie values. Later research reads those browser sessions again; macOS Keychain may prompt again. `BROWSER_CONSENT=false` or `FROM_BROWSER=off` disables native browser and CDP reads. A later consented setup replaces a saved refusal, but an explicit `FROM_BROWSER=off` still blocks reads until changed. The `agentcookie` sidecar is controlled separately by `AGENTCOOKIE=off`.
+
+Setup also best-effort installs yt-dlp (YouTube), the free keyless Digg CLI (`digg-pp-cli` via `@mvanhorn/printing-press-library install digg --cli-only`; Digg activates only when the binary is on the **agent subprocess PATH**, typically `$HOME/.local/bin`; setup reports honestly if installed off-PATH; recommend-only if `npx` is unavailable), plus the free keyless arXiv and Techmeme CLIs. Show the user what was found and installed - including whether Digg landed on PATH (active) or off-PATH (installed but not yet active).
**Extras-host X login (Linux / Mac mini / Darwin agentcookie sink — a MacBook SKIPS this, and so does a `LAST30DAYS_HOST=grok-bot` host, which never runs it).** On a MacBook the Keychain/Firefox/Safari extract above is all X needs. On an extras host the local Chrome store can't be decrypted, so that extract finds nothing and X stays empty unless you also capture a LIVE login over CDP. After the cookie-consent setup run: run `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/box_chrome_login.py` — it prints the exact host-correct command (or launches it with `--exec`), and on a MacBook it prints "no launch needed" and spawns nothing. When `box-chrome` is on PATH it launches a throwaway profile on the last30days extras port **18800** (the last30days convention `SAND_CHROME_REMOTE_DEBUG_PORT=18800`, not box-chrome's default): `CHROME_USER_DATA_DIR=/tmp/last30days-x-chrome SAND_CHROME_REMOTE_DEBUG_PORT=18800 box-chrome --new-window https://x.com/login`. Wait for the x.com login page, then HAND THE DESKTOP to the human to type — do NOT fill or drive the form. After they sign in, append `BROWSER_CDP_URL=http://127.0.0.1:18800` to `.env` (never `AUTH_TOKEN`/`CT0`; keep `AGENTCOOKIE=off` during the harvest), then re-run `setup --allow-browser-cookies` so extras CDP reads the live pair. Full steps and the block/rate-limit stop rule are in **X on Linux / Mac mini** below. This extras-host login only runs on the consented "Yes - X cookies" path; the Research Continuation Override never skips it when the user said yes to X.
@@ -664,8 +666,8 @@ For hosts without interactive modal prompts (OpenClaw, Codex, Cursor, Gemini CLI
**1. Welcome.** Run `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py --welcome` and show its stdout to the user VERBATIM (do not summarize or reformat). The welcome is engine-owned so it renders the same everywhere.
-**2. Cookie consent (ask BEFORE reading anything).** First check if `BROWSER_CONSENT=true` already exists in `~/.config/last30days/.env` (e.g. granted in a prior Claude Code session); if so, skip this prompt and run `setup --allow-browser-cookies` directly. Otherwise ask. Example: `I can read your browser cookies to unlock X/Twitter and other logged-in sources - I check Chrome first (a one-time macOS Keychain prompt may appear; click Always Allow), then Firefox and Safari. Want me to? (yes / no)` **Wait for the answer.**
- - On **yes** → run `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py setup --allow-browser-cookies` (the engine saves `BROWSER_CONSENT=true`; do not append a duplicate marker). Extracts cookies (Chrome/Chromium family first via the Keychain with no Full Disk Access, then Firefox and Safari; only a Firefox/Safari winner is pinned for later runs, so Chrome never re-prompts) and best-effort installs yt-dlp (YouTube), the free keyless Digg CLI (`digg-pp-cli` via `@mvanhorn/printing-press-library install digg --cli-only`; activates only when on the agent subprocess PATH, typically `$HOME/.local/bin`; reports honestly if off-PATH; recommend-only if `npx` is unavailable), plus the free keyless arXiv and Techmeme CLIs.
+**2. Cookie consent (ask BEFORE reading anything).** First check if `BROWSER_CONSENT=true` already exists in `~/.config/last30days/.env` (e.g. granted in a prior Claude Code session); if so, skip this prompt and run `setup --allow-browser-cookies` directly. Otherwise ask. Example: `May I read your browser cookies for X/Twitter and other logged-in sources now and on later research runs? On macOS I check Chrome and other Chromium browsers first, then Firefox and Safari. On Windows and Linux I use Firefox, with Windows Firefox as a fallback under WSL. Your existing browser selection takes precedence. Setup remembers successful browser names, never cookie values. macOS Keychain may prompt again on later runs; choose Always Allow if you want continuing OS access. You can stop native browser and CDP reads by setting BROWSER_CONSENT=false or FROM_BROWSER=off in ~/.config/last30days/.env. (yes / no)` **Wait for the answer.**
+ - On **yes** → run `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py setup --allow-browser-cookies` (the engine saves `BROWSER_CONSENT=true`; do not append a duplicate marker). Unless `FROM_BROWSER` is already configured, setup saves the browsers that supplied complete cookies as a comma-separated `FROM_BROWSER` list, including Chromium browsers. It normalizes Windows Firefox's `firefox-wsl` source label to `firefox`. It never saves cookie values. Later research reads those browser sessions again; macOS Keychain may prompt again. `BROWSER_CONSENT=false` or `FROM_BROWSER=off` disables native browser and CDP reads. A later consented setup replaces a saved refusal, but an explicit `FROM_BROWSER=off` still blocks reads until changed. The `agentcookie` sidecar is controlled separately by `AGENTCOOKIE=off`. Setup also best-effort installs yt-dlp (YouTube), the free keyless Digg CLI (`digg-pp-cli` via `@mvanhorn/printing-press-library install digg --cli-only`; activates only when on the agent subprocess PATH, typically `$HOME/.local/bin`; reports honestly if off-PATH; recommend-only if `npx` is unavailable), plus the free keyless arXiv and Techmeme CLIs.
- **Extras hosts (Linux / Mac mini / Darwin agentcookie sink) — a MacBook SKIPS this, and so does a `LAST30DAYS_HOST=grok-bot` host.** On these hosts the Chrome cookie store can't be decrypted, so the extract above finds nothing and X stays empty unless you capture a LIVE login over CDP. Run `"${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/box_chrome_login.py` (prints the host-correct command; `--exec` launches it; a MacBook prints "no launch needed" and spawns nothing). When `box-chrome` is on PATH it launches a throwaway profile on the last30days extras port **18800** (`SAND_CHROME_REMOTE_DEBUG_PORT=18800`, not box-chrome's default): `CHROME_USER_DATA_DIR=/tmp/last30days-x-chrome SAND_CHROME_REMOTE_DEBUG_PORT=18800 box-chrome --new-window https://x.com/login`. Wait for the x.com login page, then HAND THE DESKTOP to the human to type — do NOT drive the form. After they sign in, append `BROWSER_CDP_URL=http://127.0.0.1:18800` to `.env` (never `AUTH_TOKEN`/`CT0`; keep `AGENTCOOKIE=off` during the harvest) and re-run `setup --allow-browser-cookies`. Full steps and the block/rate-limit stop rule: **X on Linux / Mac mini** below. This extras-host login only runs on the consented **yes** path; a waiting topic never skips it when the user said yes to X.
- On **no** → run `FROM_BROWSER=off "${LAST30DAYS_PYTHON:-python3}" skills/last30days/scripts/last30days.py setup`. Skips all cookie reads; still installs yt-dlp (YouTube), Digg, arXiv, and Techmeme, still writes `SETUP_COMPLETE`. The engine saves `BROWSER_CONSENT=false`, so later runs also skip native browser and CDP reads. If the invocation already includes a topic, immediately research it with `--no-browser-cookies`, then resume the deferred onboarding in the same run after the findings: the ScrapeCreators offer (step 4) and source tier (step 4b) if a key is saved. Do not re-ask cookie consent as part of the resume.
@@ -726,7 +728,7 @@ The magic of /last30days is Reddit comments + X posts together - and both are fr
**X/Twitter (pick one - the most important source):**
- `X_BEARER_TOKEN=xxx` - the official X API v2 (`api.x.com`) with an app-only bearer from the X developer console. Recent posts, about a week back on the Basic tier, unless your X developer project has full-archive access. Persist it with `setup --store-key X_BEARER_TOKEN` (value on stdin, masked in output). Outside a Grok Bot host also add `LAST30DAYS_X_BACKEND=xapi` so the engine selects it (`doctor` says so when the bearer is set without it).
- **Grok CLI (no X credential):** install with `curl -fsSL https://x.ai/cli/install.sh | bash`, then `grok login`. No X account, no cookies, no API key. Needs a Grok plan; calls draw on it.
-- `FROM_BROWSER=auto` - free. Reads your x.com login cookies live at search time (Firefox/Safari, never saved to disk).
+- `FROM_BROWSER=auto` - free. Reads your x.com login cookies live at search time: Firefox and Safari first, then Chromium browsers on macOS; Firefox only on Windows and Linux, with a Windows Firefox fallback under WSL. Cookie values are never saved to disk. Chromium reads may prompt for macOS Keychain access again; choose Always Allow for continuing OS access. A saved `BROWSER_CONSENT=false` blocks these reads until you consent again. Set `BROWSER_CONSENT=false` or `FROM_BROWSER=off` to disable native browser and CDP reads.
- `XAI_API_KEY=xxx` - no browser access needed. Get a key at api.x.ai. Best for servers.
- `XQUIK_API_KEY=xxx` - keyless-style X via Xquik.
- `AUTH_TOKEN=xxx` + `CT0=xxx` - paste your X cookies manually (x.com → F12 → Application → Cookies).
diff --git a/skills/last30days/scripts/last30days.py b/skills/last30days/scripts/last30days.py
index 45324671..fbf80edd 100644
--- a/skills/last30days/scripts/last30days.py
+++ b/skills/last30days/scripts/last30days.py
@@ -3332,21 +3332,13 @@ def _main(
config,
allow_browser_cookies=_setup_allows_browser_cookies(args, extra_argv),
)
- # Persist FROM_BROWSER only when every service's cookies came from the
- # SAME single browser — then we can fast-path future runs to it. If
- # different services matched different browsers, or none matched, leave
- # FROM_BROWSER unset so the safe default remains no browser-cookie
- # reads. We deliberately do NOT pin "auto" here (it would re-probe
- # Chrome and re-trigger the prompt) nor a single browser (it would
- # silently skip the service that used the other one).
- found_browsers = set(results.get("cookies_found", {}).values())
- from_browser = found_browsers.pop() if len(found_browsers) == 1 else None
- # Pin only a silent winner (firefox/safari). Pinning a Chromium browser
- # would make every steady-state run re-read its Keychain-encrypted store
- # and can re-trigger the "Always Allow" prompt, so Chrome is used for the
- # first-run scan but never pinned.
- if from_browser in {"chrome", "brave", "edge", "vivaldi", "opera", "arc", "chromium"}:
- from_browser = None
+ # Keep only successful browsers, including distinct service winners;
+ # "auto" would also probe browsers that did not supply any cookies.
+ found_browsers = dict.fromkeys(
+ "firefox" if browser == "firefox-wsl" else browser
+ for browser in results.get("cookies_found", {}).values()
+ )
+ from_browser = ",".join(found_browsers) or None
results["env_written"] = setup_wizard.write_setup_config(
env.CONFIG_FILE,
from_browser=from_browser,
diff --git a/skills/last30days/scripts/lib/setup_wizard.py b/skills/last30days/scripts/lib/setup_wizard.py
index 9188b45d..43cf90ed 100644
--- a/skills/last30days/scripts/lib/setup_wizard.py
+++ b/skills/last30days/scripts/lib/setup_wizard.py
@@ -600,12 +600,11 @@ def write_setup_config(
Args:
env_path: Path to the .env file (e.g. ~/.config/last30days/.env)
- from_browser: Browser extraction mode to persist. Pass the browser that
- actually yielded cookies (e.g. "firefox") to fast-path future runs.
- Pass None (default) to NOT pin FROM_BROWSER — the steady-state
- default (Firefox/Safari, no Keychain prompt) then applies. We avoid
- persisting "auto" because it makes every later run probe Chrome and
- re-trigger the Keychain prompt.
+ from_browser: Browser or comma-separated browser list that actually
+ yielded cookies after consent (e.g. "chrome,firefox"). Pass None
+ (default) to leave FROM_BROWSER unchanged; when unset, future runs
+ do not read native browser stores. Avoid "auto", which would also probe
+ browsers that did not supply cookies during setup.
browser_consent: Record the user's current cookie-access decision.
None preserves any previous decision.
diff --git a/tests/test_onboarding_contract.py b/tests/test_onboarding_contract.py
index 1ae7ef55..13eecd4f 100644
--- a/tests/test_onboarding_contract.py
+++ b/tests/test_onboarding_contract.py
@@ -336,6 +336,34 @@ class TestOnboardingContract(unittest.TestCase):
self.assertIn("Chrome", slice_text, f"{slice_name} cookie copy omits Chrome")
self.assertIn("Always Allow", slice_text, f"{slice_name} omits the Keychain cue")
+ def test_cookie_consent_explains_future_reads_before_the_answer(self):
+ prompts = (
+ self.modal.split('Question: "Auto setup', 1)[1].split("Options (", 1)[0],
+ self.prose.split("Otherwise ask. Example:", 1)[1].split("**Wait for the answer.**", 1)[0],
+ )
+ for prompt in prompts:
+ with self.subTest(prompt=prompt):
+ self.assertIn("later research runs", prompt)
+ self.assertIn("browser names", prompt)
+ self.assertIn("may prompt again", prompt)
+ self.assertIn("Always Allow", prompt)
+ self.assertIn("BROWSER_CONSENT=false", prompt)
+ self.assertIn("FROM_BROWSER=off", prompt)
+ self.assertIn("On macOS", prompt)
+ self.assertIn("Windows and Linux", prompt)
+ self.assertIn("Windows Firefox", prompt)
+
+ def test_cookie_persistence_contract_matches_each_host_flow(self):
+ for flow in (self.modal, self.prose):
+ with self.subTest(flow=flow[:30]):
+ self.assertIn("complete cookies", flow)
+ self.assertIn("comma-separated", flow)
+ self.assertIn("never saves cookie values", flow)
+ self.assertNotIn("one-time macOS Keychain prompt", flow)
+ self.assertNotIn("only when it is Firefox or Safari", flow)
+ self.assertNotIn("only a Firefox/Safari winner", flow)
+ self.assertNotIn("Chrome never re-", flow)
+
def test_fda_reframed_as_safari_fallback(self):
"""Full Disk Access is framed as Safari-only, not the default path."""
self.assertNotIn("scan your browser (Firefox/Safari)", self.modal)
diff --git a/tests/test_setup_browser_persistence.py b/tests/test_setup_browser_persistence.py
new file mode 100644
index 00000000..72be9077
--- /dev/null
+++ b/tests/test_setup_browser_persistence.py
@@ -0,0 +1,193 @@
+import os
+import platform
+import shutil
+import subprocess
+import sys
+from pathlib import Path
+from unittest.mock import patch
+
+import pytest
+
+import last30days as cli
+from lib import cookie_extract, env
+
+
+def run_setup(tmp_path, monkeypatch, capsys):
+ config_path = tmp_path / "config" / ".env"
+ monkeypatch.setattr(env, "CONFIG_FILE", config_path)
+ monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path))
+ monkeypatch.setattr(platform, "system", lambda: "Darwin")
+ installed = {"yt-dlp", "digg-pp-cli", "arxiv-pp-cli", "techmeme-pp-cli"}
+ monkeypatch.setattr(
+ shutil, "which", lambda name: f"/test/bin/{name}" if name in installed else None
+ )
+
+ def run_process(command, **kwargs):
+ assert command == ["sysctl", "-n", "hw.model"]
+ return subprocess.CompletedProcess(command, 0, "MacBookPro18,1\n", "")
+
+ monkeypatch.setattr(subprocess, "run", run_process)
+
+ def run(winners, *, flags=("--allow-browser-cookies",), existing="", cookie_results=None):
+ if existing:
+ config_path.parent.mkdir(parents=True)
+ config_path.write_text(existing)
+ config_path.chmod(0o600)
+ reads = []
+
+ def read_cookies(browser, domain, cookie_names):
+ reads.append((browser, domain))
+ if cookie_results and (browser, domain) in cookie_results:
+ result = cookie_results[(browser, domain)]
+ if isinstance(result, Exception):
+ raise result
+ return result, browser
+ winner = winners.get(domain)
+ selector = "firefox" if winner == "firefox-wsl" else winner
+ if browser != selector:
+ return None
+ return {name: f"dummy-setup-{name}" for name in cookie_names}, winner
+
+ monkeypatch.setattr(cookie_extract, "extract_cookies_with_source", read_cookies)
+ monkeypatch.setattr(sys, "argv", ["last30days", "setup", *flags])
+ with patch.dict(os.environ, {"LAST30DAYS_SKIP_KEYCHAIN": "1"}, clear=True):
+ assert cli.main() == 0
+ next_config = env.get_config(env.ConfigLoadPolicy(browser_cookies="read"))
+ saved = env.load_env_file(config_path)
+ output = capsys.readouterr()
+ assert "dummy-setup-" not in config_path.read_text()
+ assert "dummy-setup-" not in output.out + output.err
+ assert saved["SETUP_COMPLETE"] == "true"
+ return saved, next_config, reads
+
+ return run
+
+
+ "browser",
+ ["chrome", "brave", "edge", "vivaldi", "arc", "chromium", "firefox", "safari"],
+)
+def test_consented_browser_remains_usable_after_setup(run_setup, browser):
+ saved, config, _ = run_setup({".x.com": browser})
+
+ assert saved["FROM_BROWSER"] == browser
+ assert saved["BROWSER_CONSENT"] == "true"
+ assert env.cookie_extraction_browsers(config) == [browser]
+ assert config["AUTH_TOKEN"] == "dummy-setup-auth_token"
+ assert config["CT0"] == "dummy-setup-ct0"
+
+
+def test_mixed_browser_winners_remain_usable_after_setup(run_setup):
+ saved, config, _ = run_setup({".x.com": "chrome", ".truthsocial.com": "firefox"})
+
+ assert saved["FROM_BROWSER"] == "chrome,firefox"
+ assert env.cookie_extraction_browsers(config) == ["chrome", "firefox"]
+ assert config["AUTH_TOKEN"] == "dummy-setup-auth_token"
+ assert config["TRUTHSOCIAL_TOKEN"] == "dummy-setup-_session_id"
+
+
+def test_shared_browser_winner_is_saved_once(run_setup):
+ saved, config, _ = run_setup({".x.com": "chrome", ".truthsocial.com": "chrome"})
+
+ assert saved["FROM_BROWSER"] == "chrome"
+ assert config["AUTH_TOKEN"] == "dummy-setup-auth_token"
+ assert config["TRUTHSOCIAL_TOKEN"] == "dummy-setup-_session_id"
+
+
+def test_explicit_opera_selection_remains_usable_after_setup(run_setup):
+ saved, config, _ = run_setup({".x.com": "opera"}, existing="FROM_BROWSER=opera\n")
+
+ assert saved["FROM_BROWSER"] == "opera"
+ assert env.cookie_extraction_browsers(config) == ["opera"]
+ assert config["AUTH_TOKEN"] == "dummy-setup-auth_token"
+
+
+def test_wsl_firefox_source_is_saved_as_a_supported_selector(run_setup):
+ saved, config, _ = run_setup({".x.com": "firefox-wsl"})
+
+ assert saved["FROM_BROWSER"] == "firefox"
+ assert env.cookie_extraction_browsers(config) == ["firefox"]
+ assert config["AUTH_TOKEN"] == "dummy-setup-auth_token"
+
+
+def test_no_cookie_match_does_not_select_a_native_browser(run_setup):
+ saved, config, reads = run_setup({})
+
+ assert reads
+ assert "FROM_BROWSER" not in saved
+ assert env.cookie_extraction_browsers(config) == []
+ assert not config["AUTH_TOKEN"]
+
+
+ "cookies",
+ [
+ {"auth_token": "dummy-setup-auth_token"},
+ {"ct0": "dummy-setup-ct0"},
+ {"auth_token": "dummy-setup-auth_token", "ct0": ""},
+ OSError("dummy browser read failure"),
+ ],
+)
+def test_incomplete_or_failed_browser_is_not_retained(run_setup, cookies):
+ saved, config, reads = run_setup({}, cookie_results={("chrome", ".x.com"): cookies})
+
+ assert ("chrome", ".x.com") in reads
+ assert "FROM_BROWSER" not in saved
+ assert saved["BROWSER_CONSENT"] == "true"
+ assert env.cookie_extraction_browsers(config) == []
+ assert not config["AUTH_TOKEN"]
+ assert not config["CT0"]
+
+
+def test_partial_chromium_does_not_displace_complete_firefox(run_setup):
+ saved, config, _ = run_setup(
+ {".x.com": "firefox"},
+ cookie_results={("chrome", ".x.com"): {"ct0": "dummy-setup-partial-ct0"}},
+ )
+
+ assert saved["FROM_BROWSER"] == "firefox"
+ assert config["AUTH_TOKEN"] == "dummy-setup-auth_token"
+ assert config["CT0"] == "dummy-setup-ct0"
+
+
+def test_consent_can_restore_chromium_after_a_saved_refusal(run_setup):
+ saved, config, _ = run_setup({".x.com": "chrome"}, existing="BROWSER_CONSENT=false\n")
+
+ assert saved["BROWSER_CONSENT"] == "true"
+ assert saved["FROM_BROWSER"] == "chrome"
+ assert config["AUTH_TOKEN"] == "dummy-setup-auth_token"
+
+
+def test_decline_disables_previously_saved_chromium(run_setup):
+ saved, config, reads = run_setup(
+ {".x.com": "chrome"},
+ flags=(),
+ existing="BROWSER_CONSENT=true\nFROM_BROWSER=chrome\n",
+ )
+
+ assert saved["BROWSER_CONSENT"] == "false"
+ assert saved["FROM_BROWSER"] == "chrome"
+ assert env.cookie_extraction_browsers(config) == []
+ assert not config["AUTH_TOKEN"]
+ assert reads == []
+
+
[email protected]("flags", [(), ("--allow-browser-cookies", "--no-browser-cookies")])
+def test_no_consent_does_not_read_or_save_browser_credentials(run_setup, flags):
+ saved, config, reads = run_setup({".x.com": "chrome"}, flags=flags)
+
+ assert saved.get("FROM_BROWSER") in {None, "off"}
+ assert saved["BROWSER_CONSENT"] == "false"
+ assert env.cookie_extraction_browsers(config) == []
+ assert not config["AUTH_TOKEN"]
+ assert reads == []
+
+
+def test_explicit_browser_off_is_preserved(run_setup):
+ saved, config, reads = run_setup({".x.com": "chrome"}, existing="FROM_BROWSER=off\n")
+
+ assert saved["FROM_BROWSER"] == "off"
+ assert env.cookie_extraction_browsers(config) == []
+ assert not config["AUTH_TOKEN"]
+ assert reads == []