Activation reaches plugin discovery before the application dependencies exist. Give PM its own locked Python project and runtime so it can install or repair the application without importing that dependency tree. Keep PM outside the application workspace. A shared uv workspace resolves the application graph and cannot provide this isolation. Route mutations through an isolated worker and preserve transaction callbacks, cancellation, custom package registrations, and correlated receipts. Use the same runtime builder for source installs and packaged payloads. Keep offline wheelhouse support in that builder. Nix builds the independent PM lock as a separate derivation. Refuse lazy-disabled bootstrap before installing tools or dependencies. Move first-party YAML readers and writers to ruamel. Keep the application lock's transitive PyYAML requirements for third-party packages. Verification: - Focused canonical Python suite: 177 passed, 1 host-gated skip. - Electron backend probes: 12 passed. Electron typecheck passed. - Both uv locks, scoped lint, Bash syntax, and whitespace checks passed. - Cold activation, corrupt-app repair, offline staging, and relocation ran. - Built and exercised the Nix PM runtime and standalone YAML merge script. Six broader caller test files retain the same 24 failing test IDs as an archive of HEAD. The existing real-home guard blocks those tests before they can exercise the affected paths. No full-suite pass is claimed. Native Windows signing and full Bionic package execution remain unverified.
54 lines
2.8 KiB
Python
54 lines
2.8 KiB
Python
"""Profile-bound agent construction must arm real shell policy."""
|
|
import os
|
|
import shlex
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import hermes_yaml as yaml
|
|
|
|
|
|
def test_agent_build_arms_only_consented_profile_policy(tmp_path, monkeypatch):
|
|
from agent import shell_hooks
|
|
from hermes_cli import plugins
|
|
from hermes_constants import reset_hermes_home_override, set_hermes_home_override
|
|
from tui_gateway import server
|
|
|
|
monkeypatch.setenv('HERMES_HOME', str(tmp_path))
|
|
monkeypatch.setenv('HOME', str(tmp_path / 'os-home'))
|
|
monkeypatch.setattr(Path, 'home', lambda: tmp_path / 'os-home')
|
|
monkeypatch.setenv('HERMES_IGNORE_RULES', '1')
|
|
monkeypatch.delenv('HERMES_ACCEPT_HOOKS', raising=False)
|
|
monkeypatch.setattr(server, '_hermes_home', tmp_path)
|
|
monkeypatch.setattr(server, '_get_db', lambda: None)
|
|
# Only provider resolution is a fixture; registration, agent, hook process,
|
|
# consent, manager selection and public dispatch are the real implementation.
|
|
monkeypatch.setattr(server, '_resolve_agent_model_runtime', lambda *_a: (
|
|
'fixture-model', {'provider': 'openai-compat', 'base_url': 'http://127.0.0.1:18019/v1', 'api_key': 'fixture-key'}))
|
|
plugins._reset_plugin_managers_for_tests()
|
|
shell_hooks.reset_for_tests()
|
|
try:
|
|
for label, consent in [('alpha', True), ('beta', True), ('unapproved', False)]:
|
|
home = tmp_path / label
|
|
home.mkdir()
|
|
script = home / 'guard.py'
|
|
script.write_text('import json\nprint(json.dumps({"decision":"block","reason":' + repr(label) + '}))\n', encoding='utf-8')
|
|
quote_command = subprocess.list2cmdline if os.name == 'nt' else shlex.join
|
|
cfg = {'hooks_auto_accept': consent, 'hooks': {'pre_tool_call': [{
|
|
'command': quote_command([sys.executable, str(script)]), 'matcher': 'write_file', 'fail_closed': True}]},
|
|
'toolsets': ['file'], 'memory': {'memory_enabled': False, 'user_profile_enabled': False}}
|
|
(home / 'config.yaml').write_text(yaml.safe_dump(cfg), encoding='utf-8')
|
|
for label in ['alpha', 'beta', 'alpha', 'unapproved']:
|
|
token = set_hermes_home_override(tmp_path / label)
|
|
try:
|
|
agent = server._make_agent(label, label, context_cwd_is_launch_artifact=False)
|
|
assert agent is not None
|
|
block = plugins.get_pre_tool_call_block_message('write_file', {'path': str(tmp_path / 'protected'), 'content': 'x'})
|
|
assert block == (None if label == 'unapproved' else label)
|
|
assert plugins.get_pre_tool_call_block_message('read_file', {'path': str(tmp_path / 'protected')}) is None
|
|
finally:
|
|
reset_hermes_home_override(token)
|
|
finally:
|
|
plugins._reset_plugin_managers_for_tests()
|
|
shell_hooks.reset_for_tests()
|