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(env): treat unsubstituted config templates as unconfigured (#1126)

Som Samantrayd01a3e0d26d6
diff --git a/changelog.d/1081.fixed.md b/changelog.d/1081.fixed.md
new file mode 100644
index 00000000..1fe74d27
--- /dev/null
+++ b/changelog.d/1081.fixed.md
@@ -0,0 +1 @@
+A config value left as an unsubstituted `${user_config.*}` extension template is now treated as unset. `doctor` and `permission_preflight` report it as an unsubstituted template instead of a healthy credential, and backends fall back rather than sending the placeholder upstream. Previously the placeholder read as configured, so the diagnostics cleared a setup that could not work and the failure surfaced as a vendor auth error. (#1081)
diff --git a/skills/last30days/scripts/lib/doctor.py b/skills/last30days/scripts/lib/doctor.py
index 325e585c..23bfe4fb 100644
--- a/skills/last30days/scripts/lib/doctor.py
+++ b/skills/last30days/scripts/lib/doctor.py
@@ -1154,6 +1154,13 @@ def _setup_block(config: Dict[str, Any]) -> Dict[str, Any]:
return {
"setup_complete": env.is_setup_complete(config),
"keys_present": keys_present,
+ # get_config() rejected these before any presence check ran, so
+ # keys_present already reads them as absent. Carrying the names here is
+ # what lets the text renderer say *why* they are absent instead of
+ # leaving the user to read "credentials present: none". Only keys left
+ # unset are listed: one whose placeholder fell through to a real
+ # lower-priority credential is configured and does not appear.
+ "unsubstituted_templates": env.templated_config_keys(config),
}
@@ -1398,6 +1405,13 @@ def render_text(report: Dict[str, Any]) -> str:
+ (", ".join(present) if present else "none")
+ " (values never shown)"
)
+ templated = setup.get("unsubstituted_templates") or []
+ if templated:
+ lines.append(
+ "note: unsubstituted config template(s), counted as unset: "
+ + ", ".join(templated)
+ + " (set a real value or remove each)"
+ )
permissions = report.get("permissions") or {}
if permissions.get("status"):
diff --git a/skills/last30days/scripts/lib/env.py b/skills/last30days/scripts/lib/env.py
index 509342c4..f34000d0 100644
--- a/skills/last30days/scripts/lib/env.py
+++ b/skills/last30days/scripts/lib/env.py
@@ -6,6 +6,7 @@ import datetime
import json
import locale
import os
+import re
import sys
from dataclasses import dataclass
from pathlib import Path
@@ -126,6 +127,60 @@ def _truthy(value: Any) -> bool:
return str(value).strip().lower() in {"1", "true", "yes", "on"}
+# A Claude Desktop extension maps every unset field in its config modal to the
+# literal string ``${user_config.<field>}`` in the engine's environment. The
+# placeholder is non-empty, so a presence check reads it as a real credential:
+# doctor reports the source healthy, preflight returns ready, and the backend
+# sends the literal placeholder upstream and surfaces the vendor's 401 instead
+# of falling back. Two constraints keep legitimate values out of scope. The
+# match is anchored to the whole trimmed value, so a real credential containing
+# ``$`` or braces is untouched. And the field name is restricted to the
+# identifier charset the manifest uses, so shell-default syntax is not mistaken
+# for a placeholder - both the generic form a user may paste into ``.env``
+# (``${VAR:-default}``) and the namespaced form with a default
+# (``${user_config.x:-default}``). Only the extension namespace, as issue
+# #1081's own suggested fix names, is rejected.
+_UNSUBSTITUTED_TEMPLATE = re.compile(r"^\$\{user_config\.[A-Za-z0-9_]+\}$")
+
+# Config-record key holding the names of values rejected above, so diagnostics
+# report the templated state instead of silently counting the key absent.
+TEMPLATE_CONFIG_KEYS = "_TEMPLATE_CONFIG_KEYS"
+
+
+def is_unsubstituted_template(value: Any) -> bool:
+ """True when ``value`` is a whole, unexpanded ``${user_config.*}`` placeholder."""
+ if not isinstance(value, str):
+ return False
+ return bool(_UNSUBSTITUTED_TEMPLATE.match(value.strip()))
+
+
+def templated_config_keys(config: dict[str, Any]) -> list[str]:
+ """Public view of the keys ``get_config()`` rejected as unsubstituted templates.
+
+ Thin reader so diagnostics report the templated state without re-deriving
+ the record key, in the same spirit as ``include_sources`` and
+ ``is_setup_complete``. Sorted here too: these call sites also see hand-built
+ configs, and the order is user-visible in both diagnostics.
+ """
+ return sorted(config.get(TEMPLATE_CONFIG_KEYS) or [])
+
+
+def _rotate_scrapecreators_key(config: dict[str, Any]) -> None:
+ """Round-robin a comma-separated SCRAPECREATORS_API_KEY to one key per run.
+
+ Extracted so the placeholder sweep can reapply it: the sweep may restore a
+ value from a lower-priority source after the ordinary rotation already ran,
+ and a comma-separated list handed to a backend whole fails authentication.
+ A second call on an already-rotated value is a no-op (no comma remains).
+ """
+ raw = config.get('SCRAPECREATORS_API_KEY') or ''
+ if ',' not in raw:
+ return
+ import random
+ sc_keys = [k.strip() for k in raw.split(',') if k.strip()]
+ config['SCRAPECREATORS_API_KEY'] = random.choice(sc_keys) if sc_keys else ''
+
+
def is_timestamp_fresh(timestamp_value: Any, ttl_seconds: int) -> bool:
"""True when ``timestamp_value`` (ISO-8601 string) is within ``ttl_seconds``.
@@ -684,11 +739,7 @@ def get_config(policy: ConfigLoadPolicy | None = None) -> dict[str, Any]:
# Multi-key rotation: comma-separated SCRAPECREATORS_API_KEY round-robins
# via random.choice per run. Originally added in #268, accidentally dropped
# in v3.0.6, restored here.
- sc_key_raw = config.get('SCRAPECREATORS_API_KEY') or ''
- if ',' in sc_key_raw:
- import random
- sc_keys = [k.strip() for k in sc_key_raw.split(',') if k.strip()]
- config['SCRAPECREATORS_API_KEY'] = random.choice(sc_keys) if sc_keys else ''
+ _rotate_scrapecreators_key(config)
# Track which config source was used (highest-priority file source wins
# the label; keychain is only reported when nothing else is configured).
@@ -713,6 +764,51 @@ def get_config(policy: ConfigLoadPolicy | None = None) -> dict[str, Any]:
# host the browser list is empty unless bird is pinned (x_policy).
config['_BROWSER_COOKIE_BROWSERS'] = cookie_extraction_browsers(config)
+ # Reject unsubstituted extension placeholders last among the value-producing
+ # steps, so the legacy ScrapeCreators spelling, the multi-key rotation, and
+ # the OpenAI auth fields assembled above are all covered by one sweep rather
+ # than by a predicate repeated at each presence check. Rejection means
+ # "absent", not "empty": the placeholder is removed from the process
+ # environment and the key is then re-resolved from the lower-priority
+ # sources exactly as it would be had the host never written it, so a real
+ # .env, Keychain, or pass credential it was shadowing is not discarded.
+ # Every consumer of a rejected config key therefore agrees the credential is
+ # unset, and the keys left genuinely unset are published for the diagnostics
+ # to report. The sweep is bounded by the keys get_config registers: a
+ # credential read straight from the environment under a name it does not
+ # register - LAST30DAYS_API_KEY, or a bare SCRAPE_CREATORS_API_KEY spelling
+ # left behind after the canonical key resolved - keeps its placeholder.
+ declared_defaults = {key: default for key, default in keys}
+ templated_keys = sorted(
+ key
+ for key, value in config.items()
+ if not key.startswith('_') and is_unsubstituted_template(value)
+ )
+ for key in templated_keys:
+ os.environ.pop(key, None)
+ fallback = merged_env.get(key)
+ # A lower-priority value that is itself a placeholder is not a credential.
+ if is_unsubstituted_template(fallback):
+ fallback = None
+ resolved = fallback if fallback is not None else declared_defaults.get(key)
+ config[key] = resolved if resolved is not None else ''
+ # The rotation ran before this sweep, so a fallback restored from a
+ # comma-separated list would otherwise reach a backend whole. Reapply it,
+ # then reject the picked key if it is itself a placeholder.
+ _rotate_scrapecreators_key(config)
+ if is_unsubstituted_template(config.get('SCRAPECREATORS_API_KEY')):
+ config['SCRAPECREATORS_API_KEY'] = ''
+ # Report only the keys still leaving the credential unset. A placeholder that
+ # fell through to a real lower-priority credential (or to a usable default)
+ # is handled, and reporting it would nag about a setup that works.
+ config[TEMPLATE_CONFIG_KEYS] = [
+ key for key in templated_keys if not config.get(key)
+ ]
+ if 'OPENAI_API_KEY' in templated_keys and not config.get('OPENAI_API_KEY'):
+ # Keep the derived auth record consistent with the token it describes.
+ config['OPENAI_AUTH_SOURCE'] = AUTH_SOURCE_NONE
+ config['OPENAI_AUTH_STATUS'] = AUTH_STATUS_MISSING
+
if policy.browser_cookies == "read":
_discover_and_apply_x_credentials(config)
diff --git a/skills/last30days/scripts/lib/permission_preflight.py b/skills/last30days/scripts/lib/permission_preflight.py
index 0ddbc9c0..81c1b12c 100644
--- a/skills/last30days/scripts/lib/permission_preflight.py
+++ b/skills/last30days/scripts/lib/permission_preflight.py
@@ -4,6 +4,8 @@ from __future__ import annotations
from typing import Any
+from . import env
+
ENDPOINT_OVERRIDE_KEYS = {
"BSKY_SEARCH_HOST",
@@ -122,6 +124,16 @@ def build(
action_items: list[str] = []
if ignored_project_config:
action_items.append("Project config was ignored; set LAST30DAYS_TRUST_PROJECT_CONFIG=1 to trust it.")
+ # get_config() already emptied these, so the provider flags above read them
+ # as absent. Name them anyway: the user's setup is broken in a way the
+ # presence booleans alone describe as "nothing configured".
+ templated_keys = env.templated_config_keys(config)
+ if templated_keys:
+ action_items.append(
+ "Unsubstituted config template(s) count as unset: "
+ + _format_names(templated_keys)
+ + ". Replace each with a real value or remove it."
+ )
return {
"status": "action_needed" if action_items else "ready",
diff --git a/tests/test_doctor.py b/tests/test_doctor.py
index b8046d3f..0fd984e9 100644
--- a/tests/test_doctor.py
+++ b/tests/test_doctor.py
@@ -1616,5 +1616,35 @@ class GrokBotParityTable(unittest.TestCase):
self.assertLessEqual(x_text.count(pin), 1, x_text)
self.assertNotIn("last30days_x_backend", x_text)
+
+class UnsubstitutedTemplateReporting(unittest.TestCase):
+ """Issue #1081 defect 2: a rejected `${user_config.*}` placeholder is named
+ as unsubstituted instead of reading as "nothing configured"."""
+
+ def test_setup_block_carries_the_rejected_key_names(self):
+ block = doctor._setup_block({env.TEMPLATE_CONFIG_KEYS: ["GEMINI_API_KEY"]})
+
+ self.assertEqual(["GEMINI_API_KEY"], block["unsubstituted_templates"])
+ self.assertFalse(block["keys_present"]["GEMINI_API_KEY"])
+
+ def test_setup_block_defaults_to_an_empty_list(self):
+ self.assertEqual([], doctor._setup_block({})["unsubstituted_templates"])
+
+ def test_render_names_the_template_without_listing_it_as_present(self):
+ report = _build({env.TEMPLATE_CONFIG_KEYS: ["GEMINI_API_KEY"]})
+
+ text = doctor.render_text(report)
+
+ self.assertIn(
+ "unsubstituted config template(s), counted as unset: GEMINI_API_KEY", text
+ )
+ self.assertNotIn("credentials present: GEMINI_API_KEY", text)
+
+ def test_render_is_unchanged_without_templates(self):
+ self.assertNotIn(
+ "unsubstituted config template(s)", doctor.render_text(_build({}))
+ )
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_env_unsubstituted_template.py b/tests/test_env_unsubstituted_template.py
new file mode 100644
index 00000000..f4e29db1
--- /dev/null
+++ b/tests/test_env_unsubstituted_template.py
@@ -0,0 +1,243 @@
+"""Unsubstituted `${user_config.*}` placeholders must read as unconfigured.
+
+A Claude Desktop extension writes the literal placeholder for every field the
+user has not filled in. The value is non-empty, so before this fix every
+presence check downstream read it as a real credential: doctor reported the
+source healthy, preflight returned ready, and the backend sent the placeholder
+upstream and surfaced the vendor's auth error instead of falling back.
+"""
+
+from __future__ import annotations
+
+from unittest import mock
+
+from lib import env
+
+
+TEMPLATE = "${user_config.scrapecreators_api_key}"
+
+_KEYS = (
+ "SCRAPECREATORS_API_KEY",
+ "SCRAPE_CREATORS_API_KEY",
+ "GEMINI_API_KEY",
+ "OPENAI_API_KEY",
+ "GITHUB_TOKEN",
+ "LAST30DAYS_MEMORY_DIR",
+ "LAST30DAYS_YT_PLAYER_CLIENT",
+)
+
+
+def _isolate(monkeypatch, tmp_path):
+ """Point config loading at an empty world so only the test's env applies."""
+ monkeypatch.setattr(env, "CONFIG_FILE", tmp_path / "does-not-exist.env")
+ monkeypatch.setattr(env, "_find_project_env", lambda: None)
+ monkeypatch.setattr(env, "_load_keychain", lambda *a, **k: {})
+ monkeypatch.setattr(env, "_load_pass", lambda *a, **k: {})
+ monkeypatch.chdir(tmp_path)
+ for key in _KEYS:
+ monkeypatch.delenv(key, raising=False)
+ # Drop any ambient SETUP_COMPLETE so a truthy value on the machine running
+ # the suite cannot leak into the config under test.
+ monkeypatch.delenv("SETUP_COMPLETE", raising=False)
+
+
+def _isolate_with_env_file(monkeypatch, tmp_path, contents):
+ """Like ``_isolate``, but the global .env holds real values."""
+ _isolate(monkeypatch, tmp_path)
+ config_file = tmp_path / ".env"
+ config_file.write_text(contents, encoding="utf-8")
+ config_file.chmod(0o600)
+ monkeypatch.setattr(env, "CONFIG_FILE", config_file)
+
+
+def test_placeholder_falls_through_to_a_real_lower_priority_credential(monkeypatch, tmp_path):
+ # The host's placeholder occupies the highest-priority source. It must read
+ # as absent, not as an empty override, or the credential the user already
+ # configured in .env (or Keychain, or pass) is silently discarded and the
+ # run degrades despite having a valid key.
+ _isolate_with_env_file(
+ monkeypatch, tmp_path, "SCRAPECREATORS_API_KEY=sc_real_from_dotenv\n"
+ )
+ monkeypatch.setenv("SCRAPECREATORS_API_KEY", TEMPLATE)
+
+ config = env.get_config()
+
+ assert config["SCRAPECREATORS_API_KEY"] == "sc_real_from_dotenv"
+ # A credential that resolved is configured, so it is not reported as unset.
+ assert "SCRAPECREATORS_API_KEY" not in config[env.TEMPLATE_CONFIG_KEYS]
+ # The placeholder itself still leaves the process environment.
+ assert env.read_secret_env("SCRAPECREATORS_API_KEY") is None
+
+
+def test_a_restored_key_list_is_still_rotated_to_a_single_key(monkeypatch, tmp_path):
+ # The rotation runs before the sweep, so a list restored from a lower-priority
+ # source must be rotated again - otherwise the backend receives "k1,k2" as one
+ # credential and authentication fails despite valid fallback keys existing.
+ _isolate_with_env_file(
+ monkeypatch, tmp_path, "SCRAPECREATORS_API_KEY=sc_one,sc_two\n"
+ )
+ monkeypatch.setenv("SCRAPECREATORS_API_KEY", TEMPLATE)
+
+ config = env.get_config()
+
+ assert config["SCRAPECREATORS_API_KEY"] in {"sc_one", "sc_two"}
+ assert "," not in config["SCRAPECREATORS_API_KEY"]
+
+
+def test_a_lower_priority_placeholder_is_not_a_fallback(monkeypatch, tmp_path):
+ # A placeholder in .env is no more a credential than one in the environment.
+ _isolate_with_env_file(
+ monkeypatch, tmp_path, f"SCRAPECREATORS_API_KEY={TEMPLATE}\n"
+ )
+ monkeypatch.setenv("SCRAPECREATORS_API_KEY", TEMPLATE)
+
+ config = env.get_config()
+
+ assert config["SCRAPECREATORS_API_KEY"] == ""
+ assert "SCRAPECREATORS_API_KEY" in config[env.TEMPLATE_CONFIG_KEYS]
+
+
+def test_templated_openai_key_clears_the_derived_auth_record(monkeypatch, tmp_path):
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("OPENAI_API_KEY", "${user_config.openai_api_key}")
+
+ config = env.get_config()
+
+ assert config["OPENAI_API_KEY"] == ""
+ assert config["OPENAI_AUTH_STATUS"] == env.AUTH_STATUS_MISSING
+ assert config["OPENAI_AUTH_SOURCE"] == env.AUTH_SOURCE_NONE
+ assert "OPENAI_API_KEY" in config[env.TEMPLATE_CONFIG_KEYS]
+
+
+def test_whole_value_template_is_emptied_and_recorded(monkeypatch, tmp_path):
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("SCRAPECREATORS_API_KEY", TEMPLATE)
+
+ config = env.get_config()
+
+ assert config["SCRAPECREATORS_API_KEY"] == ""
+ assert "SCRAPECREATORS_API_KEY" in config[env.TEMPLATE_CONFIG_KEYS]
+
+
+def test_template_is_removed_from_the_process_environment(monkeypatch, tmp_path):
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("GITHUB_TOKEN", "${user_config.github_token}")
+
+ env.get_config()
+
+ # doctor's GitHub record and the GitHub backend read this name straight
+ # from os.environ, bypassing the config dict entirely.
+ assert env.read_secret_env("GITHUB_TOKEN") is None
+
+
+def test_real_credential_is_untouched_and_stays_in_the_environment(monkeypatch, tmp_path):
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("SCRAPECREATORS_API_KEY", "sc_abc123")
+
+ config = env.get_config()
+
+ assert config["SCRAPECREATORS_API_KEY"] == "sc_abc123"
+ assert config[env.TEMPLATE_CONFIG_KEYS] == []
+ assert env.read_secret_env("SCRAPECREATORS_API_KEY") == "sc_abc123"
+
+
+def test_placeholder_alongside_other_text_is_kept(monkeypatch, tmp_path):
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("SCRAPECREATORS_API_KEY", "prefix-${user_config.x}-suffix")
+
+ config = env.get_config()
+
+ assert config["SCRAPECREATORS_API_KEY"] == "prefix-${user_config.x}-suffix"
+ assert config[env.TEMPLATE_CONFIG_KEYS] == []
+
+
+def test_shell_default_syntax_is_not_a_template(monkeypatch, tmp_path):
+ # SKILL.md itself ships this shape as a .env example.
+ _isolate(monkeypatch, tmp_path)
+ shell_default = "${LAST30DAYS_MEMORY_DIR:-$HOME/Documents/Last30Days}"
+ monkeypatch.setenv("LAST30DAYS_MEMORY_DIR", shell_default)
+
+ config = env.get_config()
+
+ assert config["LAST30DAYS_MEMORY_DIR"] == shell_default
+ assert config[env.TEMPLATE_CONFIG_KEYS] == []
+
+
+def test_key_assembled_before_the_registered_key_loop_is_covered(monkeypatch, tmp_path):
+ # OPENAI_API_KEY is set from get_openai_auth() before the `keys` loop.
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("OPENAI_API_KEY", "${user_config.openai_api_key}")
+
+ config = env.get_config()
+
+ assert config["OPENAI_API_KEY"] == ""
+ assert "OPENAI_API_KEY" in config[env.TEMPLATE_CONFIG_KEYS]
+
+
+def test_templated_legacy_spelling_does_not_repopulate_the_canonical_key(
+ monkeypatch, tmp_path
+):
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("SCRAPE_CREATORS_API_KEY", "${user_config.scrapecreators_api_key}")
+
+ config = env.get_config()
+
+ assert config["SCRAPECREATORS_API_KEY"] == ""
+
+
+def test_templated_credential_reads_as_absent_to_diagnose(monkeypatch, tmp_path):
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("GEMINI_API_KEY", "${user_config.gemini_api_key}")
+
+ config = env.get_config()
+ with mock.patch("lib.bird_x.get_bird_status", return_value={
+ "installed": False, "authenticated": False, "username": None,
+ "can_install": False,
+ }), mock.patch("lib.bird_x.set_credentials", lambda *a, **k: None), \
+ mock.patch("lib.grok_x.has_stored_auth", return_value=False), \
+ mock.patch("lib.xurl_x.has_stored_auth", return_value=False):
+ from lib import pipeline
+
+ diag = pipeline.diagnose(config, None, safe=True)
+
+ assert diag["providers"]["google"] is False
+
+
+def test_key_the_earlier_export_loop_pushed_out_is_cleared_too(monkeypatch, tmp_path):
+ # The YT knob export loop runs before the sweep and passes this key through
+ # on `is not None`, so the sweep has to clear what that loop just exported.
+ _isolate(monkeypatch, tmp_path)
+ monkeypatch.setenv("LAST30DAYS_YT_PLAYER_CLIENT", "${user_config.player_client}")
+
+ config = env.get_config()
+
+ assert config["LAST30DAYS_YT_PLAYER_CLIENT"] == ""
+ assert env.read_secret_env("LAST30DAYS_YT_PLAYER_CLIENT") is None
+
+
+def test_no_templates_leaves_an_empty_record(monkeypatch, tmp_path):
+ _isolate(monkeypatch, tmp_path)
+
+ config = env.get_config()
+
+ assert config[env.TEMPLATE_CONFIG_KEYS] == []
+
+
+def test_is_unsubstituted_template_matches_only_the_whole_placeholder():
+ assert env.is_unsubstituted_template(TEMPLATE) is True
+ assert env.is_unsubstituted_template(" ${user_config.x} ") is True
+ assert env.is_unsubstituted_template("${user_config.x} ") is True
+ assert env.is_unsubstituted_template("${user_config.x}-tail") is False
+ assert env.is_unsubstituted_template("${LAST30DAYS_MEMORY_DIR:-x}") is False
+ assert env.is_unsubstituted_template("") is False
+ assert env.is_unsubstituted_template(None) is False
+ assert env.is_unsubstituted_template(1234) is False
+
+
+def test_shell_default_in_the_extension_namespace_is_not_a_template():
+ # `${user_config.x:-default}` is shell-default syntax, not an unexpanded
+ # placeholder: the field name is not the bare identifier the manifest emits.
+ assert env.is_unsubstituted_template("${user_config.x:-default}") is False
+ assert env.is_unsubstituted_template("${user_config.}") is False
+ assert env.is_unsubstituted_template("${user_config.a}${user_config.b}") is False
+ assert env.is_unsubstituted_template("${user_config.x y}") is False
diff --git a/tests/test_permission_preflight.py b/tests/test_permission_preflight.py
index dda6dc58..c298c610 100644
--- a/tests/test_permission_preflight.py
+++ b/tests/test_permission_preflight.py
@@ -295,3 +295,28 @@ def test_preflight_reports_x_bearer_presence_as_boolean_without_value():
def test_preflight_x_bearer_ignores_whitespace_only_value():
diag = _diag()
assert permission_preflight.build({"X_BEARER_TOKEN": " "}, diag)["credentials"]["x_bearer"]["present"] is False
+
+
+def test_preflight_names_unsubstituted_templates_and_reports_action_needed():
+ # get_config() already emptied these values, so the provider flags read as
+ # absent; the record is what turns "nothing is configured" into an
+ # explanation the user can act on.
+ config = {env.TEMPLATE_CONFIG_KEYS: ["GEMINI_API_KEY", "SCRAPECREATORS_API_KEY"]}
+ preflight = permission_preflight.build(config, _diag())
+
+ assert preflight["status"] == "action_needed"
+ item = next(
+ i for i in preflight["action_items"] if "Unsubstituted config template" in i
+ )
+ assert "GEMINI_API_KEY" in item
+ assert "SCRAPECREATORS_API_KEY" in item
+ assert [n for n, info in preflight["credentials"].items() if info["present"]] == []
+ assert "Unsubstituted config template" in permission_preflight.render_text(preflight)
+
+
+def test_preflight_without_templates_keeps_the_ready_shape():
+ preflight = permission_preflight.build({}, _diag())
+
+ assert preflight["status"] == "ready"
+ assert preflight["action_items"] == []
+ assert "Unsubstituted config template" not in permission_preflight.render_text(preflight)
diff --git a/tests/test_source_outcomes.py b/tests/test_source_outcomes.py
index db2a3942..a83ffe58 100644
--- a/tests/test_source_outcomes.py
+++ b/tests/test_source_outcomes.py
@@ -384,11 +384,18 @@ def test_pipeline_records_both_mode_semantic_leg_failure_as_partial():
"PERPLEXITY_API_KEY": "pplx-test",
},
depth="quick",
+ # Pin both ends of the window. The fixture item is dated 2026-08-10,
+ # so an unpinned window drops it once the wall clock moves 30 days
+ # past that date and the failure then records as ERROR, not PARTIAL.
+ lookback_days=30,
+ as_of_date="2026-08-20",
requested_sources=["perplexity"],
mock=True,
external_plan=_perplexity_plan(),
)
+ assert report.range_from == "2026-07-21"
+ assert report.range_to == "2026-08-20"
outcome = report.source_status["perplexity"]
assert outcome.state == schema.PARTIAL
assert outcome.items_returned == 1