Skip to content

The agent that grows with you

fix(child-env): manifest scan skips only what plugin discovery skips

kshitijk4poor9e26d34475ef
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index ac5a1990f74..8ad92094414 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -3994,8 +3994,9 @@ PlatformManifestSource = Literal["all", "bundled", "user"]
def _is_plugin_dir_name(name: str) -> bool:
- # Same rule as plugins_discovery.scan_directory: dot dirs and __pycache__-style dunders aren't plugins.
- return not name.startswith(".") and not (name.startswith("__") and name.endswith("__"))
+ # Same rule as plugins_discovery.scan_directory: __pycache__-style dunders aren't plugins; a dot
+ # dir can be, so its secrets are declared too.
+ return not (name.startswith("__") and name.endswith("__"))
def _platform_manifest_paths(home: Optional[Path] = None, source: PlatformManifestSource = "all"):
@@ -4031,11 +4032,13 @@ def _platform_manifest_paths(home: Optional[Path] = None, source: PlatformManife
path = Path(entry.path) / file_name
try:
st = os.stat(path)
- except FileNotFoundError:
- continue
- except OSError as exc: # the dir itself is not searchable
+ except PermissionError as exc: # the dir itself is not searchable
yield entry.name, None, require_kind, exc
break
+ except OSError: # missing, a symlink loop: discovery's exists() is False too
+ continue
+ if not stat.S_ISREG(st.st_mode):
+ continue
yield entry.name, path, require_kind, st
break
diff --git a/tests/tools/test_local_env_blocklist.py b/tests/tools/test_local_env_blocklist.py
index a4d743f2399..d6dde788201 100644
--- a/tests/tools/test_local_env_blocklist.py
+++ b/tests/tools/test_local_env_blocklist.py
@@ -169,7 +169,7 @@ def test_user_platform_plugin_secrets_belong_to_their_own_profile(child_env, mon
token = set_hermes_home_override(a)
try:
assert "CHATX_WEBHOOK_KEY" not in local.hermes_subprocess_env(inherit_credentials=True)
- # Removing the plugin releases its names, and a symlinked alias of the home shares one entry.
+ # Removing the plugin releases its names.
manifest.unlink()
assert "CHATX_WEBHOOK_KEY" in local.hermes_subprocess_env(inherit_credentials=True)
finally:
@@ -227,6 +227,30 @@ def test_unreadable_platform_manifest_fails_closed(tmp_path):
finally:
locked[0].chmod(0o755)
(locked[1] / "plugin.yaml").chmod(0o644)
+ # An unlistable platforms root is skipped the same way.
+ other = tmp_path / "other"
+ _user_platform_plugin(other, "chaty", "CHATY_SIGNING_SECRET")
+ (other / "plugins" / "platforms").chmod(0o300)
+ try:
+ assert platform_manifest_secret_envs(other, strict=True) == frozenset()
+ finally:
+ (other / "plugins" / "platforms").chmod(0o755)
+
+
+def test_manifest_scan_follows_plugin_discovery_and_sees_mtime_preserving_edits(tmp_path):
+ """A __dunder__ dir is never a plugin, so it declares nothing; a rewrite that keeps the
+ manifest's size and mtime (cp -p, rsync -t) still changes the stamp."""
+ from hermes_cli.config import platform_manifest_secret_envs, platform_manifest_stamp
+ _user_platform_plugin(tmp_path, "__cache__", "CACHED_SIGNING_SECRET")
+ _user_platform_plugin(tmp_path, "chatx", "CHATX_SIGNING_SECRET")
+ assert platform_manifest_secret_envs(tmp_path) == {"CHATX_SIGNING_SECRET"}
+ manifest = tmp_path / "plugins" / "platforms" / "chatx" / "plugin.yaml"
+ before, st = platform_manifest_stamp(tmp_path), manifest.stat()
+ manifest.write_text(manifest.read_text(encoding="utf-8").replace("CHATX_SIGNING", "CHATX_SIGNINGX"),
+ encoding="utf-8")
+ os.utime(manifest, ns=(st.st_atime_ns, st.st_mtime_ns))
+ assert manifest.stat().st_mtime_ns == st.st_mtime_ns
+ assert platform_manifest_stamp(tmp_path) != before
def test_unreadable_bundled_manifest_fails_the_policy_instead_of_dropping_it(monkeypatch):
diff --git a/tools/environments/local.py b/tools/environments/local.py
index efc60952238..c5154113040 100644
--- a/tools/environments/local.py
+++ b/tools/environments/local.py
@@ -337,7 +337,7 @@ def _scrub_credentials(env: dict, *, inherit_credentials: bool) -> dict:
# itself is case-insensitive, so a lowercase-stored ``gh_token`` IS GH_TOKEN.
home_secrets = _home_adapter_secret_env() # one manifest stamp per scrub
strip_folded = _ALWAYS_STRIP_FOLDED | {k.upper() for k in _plugin_terminal_env_strip_keys()} | home_secrets
- registered = _registry_adapter_secret_env() | home_secrets
+ registered = _registry_adapter_secret_env() # home_secrets already strip above
for key in list(env):
if (key.upper() in strip_folded
or (not inherit_credentials and _is_provider_env_blocklisted(key, registered))