ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.
Python ai-agentsamdcomfyuidockerllama-cppllmlocal-ain8nnvidiaopen-webuiragself-hostedspeech-to-textstrix-halotext-to-speechworkflow-automation
fix(macos): require native plugin runtime import proof (#8227)
Mike Bradley8914f16fe74f
diff --git a/ods/installers/macos/lib/pixel-native-bootstrap.py b/ods/installers/macos/lib/pixel-native-bootstrap.pyindex 04ffa4c7f..dd848e584 100644--- a/ods/installers/macos/lib/pixel-native-bootstrap.py+++ b/ods/installers/macos/lib/pixel-native-bootstrap.py@@ -186,14 +186,28 @@ def probe_plugins(node, runtime, plugins, temporary, env, *, entrypoint='node_mo'entries': {plugin_id: {'enabled': True} for plugin_id in paths}}}))config.chmod(0o600)output = command([str(node), str(runtime / entrypoint),- 'plugins', 'list', '--json'], cwd=temporary,+ 'plugins', 'inspect', '--all', '--runtime', '--json'], cwd=temporary,env={**env, 'HOME': str(home), 'OPENCLAW_CONFIG_PATH': str(config),'OPENCLAW_STATE_DIR': str(home / 'state'), 'OPENCLAW_SKIP_CHANNELS': '1'}, timeout=180)- result = json.loads(output)- for plugin_id, path in paths.items():- matches = [item for item in result.get('plugins', []) if item.get('id') == plugin_id- and item.get('status') == 'loaded' and item.get('rootDir') == path]- if len(matches) != 1:+ verify_plugin_report(output, paths)+++def verify_plugin_report(output, expected):+ # The pinned CLI's list command reads manifests without importing modules.+ # Runtime inspection must execute registration before a staged plugin passes.+ try:+ result = json.loads(output)+ except (TypeError, ValueError) as exc:+ raise BootstrapError('native-plugin-load-proof-failed') from exc+ if not isinstance(result, list) or any(+ not isinstance(item, dict) or not isinstance(item.get('plugin'), dict)+ for item in result):+ raise BootstrapError('native-plugin-load-proof-failed')+ for plugin_id, path in expected.items():+ matches = [item['plugin'] for item in result if item['plugin'].get('id') == plugin_id]+ if (len(matches) != 1 or matches[0].get('status') != 'loaded'+ or matches[0].get('imported') is not True+ or matches[0].get('rootDir') != path):raise BootstrapError('native-plugin-load-proof-failed')diff --git a/ods/installers/macos/lib/pixel-native-config.py b/ods/installers/macos/lib/pixel-native-config.pyindex 1486e1173..b30783586 100644--- a/ods/installers/macos/lib/pixel-native-config.py+++ b/ods/installers/macos/lib/pixel-native-config.py@@ -310,13 +310,12 @@ def validate_candidate(config, *, node, entrypoint, expected, env, cwd):'OPENCLAW_SKIP_CHANNELS': '1'}bootstrap.command([str(node), str(entrypoint), 'config', 'validate'],cwd=cwd, env=validation_env)- loaded = json.loads(bootstrap.command([str(node), str(entrypoint), 'plugins', 'list', '--json'],- cwd=cwd, env=validation_env))- for plugin_id, path in expected.items():- matches = [item for item in loaded.get('plugins', []) if item.get('id') == plugin_id]- if (len(matches) != 1 or matches[0].get('status') != 'loaded'- or matches[0].get('rootDir') != path):- raise ValueError('native-config-plugin-not-loaded')+ output = bootstrap.command([str(node), str(entrypoint),+ 'plugins', 'inspect', '--all', '--runtime', '--json'], cwd=cwd, env=validation_env)+ try:+ bootstrap.verify_plugin_report(output, expected)+ except bootstrap.BootstrapError as exc:+ raise ValueError('native-config-plugin-not-loaded') from excdef stage_bundle(*, source, ref, candidate, node, runtime, destination, services_digest=None,diff --git a/ods/tests/test_macos_pixel_candidate_bundle.py b/ods/tests/test_macos_pixel_candidate_bundle.pyindex d5ef100eb..238e773f1 100644--- a/ods/tests/test_macos_pixel_candidate_bundle.py+++ b/ods/tests/test_macos_pixel_candidate_bundle.py@@ -11,10 +11,11 @@ config = importlib.util.module_from_spec(SPEC)SPEC.loader.exec_module(config)[email protected]('fault', [None, 'duplicate', 'wrong-root', 'error', 'missing'])[email protected]('fault', [None, 'duplicate', 'wrong-root', 'error', 'missing', 'not-imported'])def test_relocated_probe_requires_unique_loaded_identity(tmp_path, monkeypatch, fault):path = str(tmp_path / 'bundle/plugins/0')item = {'id': 'pixel-ods', 'status': 'error' if fault == 'error' else 'loaded',+ 'imported': fault != 'not-imported','rootDir': '/ambient/plugin' if fault == 'wrong-root' else path}loaded = [] if fault == 'missing' else [item]if fault == 'duplicate': loaded.append(dict(item, rootDir='/ambient/plugin', status='error'))@@ -23,7 +24,7 @@ def test_relocated_probe_requires_unique_loaded_identity(tmp_path, monkeypatch,calls.append(args[2:])assert kwargs['env']['OPENCLAW_SKIP_CHANNELS'] == '1'assert kwargs['env']['OPENCLAW_CONFIG_PATH'] == str(tmp_path / 'config.json')- return json.dumps({'plugins': loaded}) if args[2:4] == ['plugins', 'list'] else ''+ return json.dumps([{'plugin': item} for item in loaded]) if args[2:4] == ['plugins', 'inspect'] else ''monkeypatch.setattr(config.bootstrap, 'command', command)def run():config.validate_candidate(tmp_path / 'config.json', node=tmp_path / 'node',@@ -33,7 +34,7 @@ def test_relocated_probe_requires_unique_loaded_identity(tmp_path, monkeypatch,with pytest.raises(ValueError, match='native-config-plugin-not-loaded'): run()else:run()- assert calls == [['config', 'validate'], ['plugins', 'list', '--json']]+ assert calls == [['config', 'validate'], ['plugins', 'inspect', '--all', '--runtime', '--json']]@pytest.mark.parametrize('fault', [None, 'root', 'duplicate', 'missing', 'foreign',diff --git a/ods/tests/test_macos_pixel_native_bootstrap.py b/ods/tests/test_macos_pixel_native_bootstrap.pyindex 0a946c214..4cb37ed5c 100644--- a/ods/tests/test_macos_pixel_native_bootstrap.py+++ b/ods/tests/test_macos_pixel_native_bootstrap.py@@ -313,7 +313,7 @@ def test_download_preserves_existing_destination_even_when_transport_is_down(assert calls == [][email protected]('fault', [None, 'root', 'arch', 'npm', 'version', 'probe', 'plugin-version', 'plugin-id'])[email protected]('fault', [None, 'root', 'arch', 'npm', 'version', 'probe', 'plugin-version', 'plugin-id', 'plugin-runtime'])def test_staging_is_nonroot_and_publishes_only_verified_runtime(tmp_path, release, monkeypatch, fault):for directory, plugin_id in bootstrap.PIXEL_PLUGINS:path = tmp_path / directory@@ -338,8 +338,9 @@ def test_staging_is_nonroot_and_publishes_only_verified_runtime(tmp_path, releasreturn json.dumps({'platform': 'darwin', 'arch': 'x64' if fault == 'arch' else 'arm64', 'major': 22})if 'plugins' in args:config = json.loads(Path(kwargs['env']['OPENCLAW_CONFIG_PATH']).read_text())- return json.dumps({'plugins': [{'id': plugin_id, 'rootDir': path, 'status': 'loaded'}- for plugin_id, path in zip(config['plugins']['allow'], config['plugins']['load']['paths'])]})+ return json.dumps([{'plugin': {'id': plugin_id, 'rootDir': path, 'imported': True,+ 'status': 'error' if fault == 'plugin-runtime' else 'loaded'}}+ for plugin_id, path in zip(config['plugins']['allow'], config['plugins']['load']['paths'])])if 'ci' in args:return ''if 'install' in args:@@ -379,23 +380,34 @@ def test_staging_is_nonroot_and_publishes_only_verified_runtime(tmp_path, releasif fault == 'root': assert not calls[email protected]('fault', [None, 'missing', 'failed', 'wrong-path', 'duplicate'])[email protected]('fault', [None, 'missing', 'failed', 'wrong-path', 'duplicate',+ 'duplicate-failed', 'manifest-only', 'malformed-json', 'malformed-report', 'malformed-plugin',+ 'not-imported', 'missing-imported', 'string-imported'])def test_plugin_probe_checks_loaded_identity_and_isolated_state(tmp_path, monkeypatch, fault):plugins = [{'id': 'searxng', 'path': 'plugins/0'}]runtime = tmp_path / 'bundle'runtime.mkdir()def command(args, **kwargs):assert args[1] == str(runtime / 'runtime/openclaw.mjs')+ assert args[2:] == ['plugins', 'inspect', '--all', '--runtime', '--json']assert kwargs['env']['HOME'] == str(tmp_path / 'probe-home')assert kwargs['env']['OPENCLAW_STATE_DIR'] == str(tmp_path / 'probe-home/state')config = Path(kwargs['env']['OPENCLAW_CONFIG_PATH'])assert config.stat().st_mode & 0o777 == 0o600- result = [{'id': 'searxng', 'rootDir': str(runtime / 'plugins/0'), 'status': 'loaded'}]+ result = [{'id': 'searxng', 'rootDir': str(runtime / 'plugins/0'), 'status': 'loaded', 'imported': True}]if fault == 'missing': result = []if fault == 'failed': result[0]['status'] = 'error'if fault == 'wrong-path': result[0]['rootDir'] = '/other/plugin'if fault == 'duplicate': result += result- return json.dumps({'plugins': result})+ if fault == 'duplicate-failed': result.append({**result[0], 'status': 'error'})+ if fault == 'not-imported': result[0]['imported'] = False+ if fault == 'missing-imported': del result[0]['imported']+ if fault == 'string-imported': result[0]['imported'] = 'true'+ if fault == 'manifest-only': return json.dumps({'plugins': result})+ if fault == 'malformed-json': return 'not JSON'+ if fault == 'malformed-report': return json.dumps([None])+ if fault == 'malformed-plugin': return json.dumps([{'plugin': []}])+ return json.dumps([{'plugin': item} for item in result])monkeypatch.setattr(bootstrap, 'command', command)def run():bootstrap.probe_plugins(Path('/node'), runtime, plugins, tmp_path, {}, entrypoint='runtime/openclaw.mjs')diff --git a/ods/tests/test_macos_pixel_native_config.py b/ods/tests/test_macos_pixel_native_config.pyindex 9e170f849..341a6d96a 100644--- a/ods/tests/test_macos_pixel_native_config.py+++ b/ods/tests/test_macos_pixel_native_config.py@@ -95,9 +95,10 @@ def test_candidate_uses_upstream_policy_without_activating_services(tmp_path, moPath(args[2]).write_text(json.dumps({'gateway': {'http': {'endpoints': {}}},'plugins': {'allow': ['searxng', 'pixel-operations-broker'], 'load': {'paths': []}},'tools': {'alsoAllow': ['pixel_ops_run', 'write', 'edit']}}))- elif args[2:4] == ['plugins', 'list']:- return json.dumps({'plugins': [{'id': key, 'rootDir': path, 'status': 'error' if fault == 'plugin-load' else 'loaded'}- for key, path in paths.items()]})+ elif args[2:] == ['plugins', 'inspect', '--all', '--runtime', '--json']:+ return json.dumps([{'plugin': {'id': key, 'rootDir': path, 'imported': True,+ 'status': 'error' if fault == 'plugin-load' else 'loaded'}}+ for key, path in paths.items()])elif args[0] == str(node):assert args[2:] == ['config', 'validate']if fault == 'schema': raise ValueError('invalid configuration')@@ -126,6 +127,55 @@ def test_candidate_uses_upstream_policy_without_activating_services(tmp_path, moif fault in ('root', 'existing-config'): assert not calls[email protected]('fault', [None, 'schema', 'command', 'malformed-json', 'manifest-only',+ 'malformed-report', 'missing', 'failed', 'duplicate-failed', 'not-imported',+ 'missing-imported', 'string-imported', 'wrong-path'])+def test_candidate_runtime_proof_preserves_config_and_isolation(tmp_path, monkeypatch, fault):+ candidate = tmp_path / 'openclaw.json'+ candidate.write_text('{"candidate":true}')+ home = tmp_path / 'home'+ expected = {'searxng': str(tmp_path / 'relocated/plugins/0')}+ calls = []+ def command(args, **kwargs):+ calls.append(args[2:])+ assert kwargs['cwd'] == tmp_path+ assert kwargs['env'] == {'HOME': str(home), 'PATH': '/bin',+ 'OPENCLAW_CONFIG_PATH': str(candidate),+ 'OPENCLAW_STATE_DIR': str(home / 'validation-state'), 'OPENCLAW_SKIP_CHANNELS': '1'}+ if args[2:] == ['config', 'validate']:+ if fault == 'schema': raise config.bootstrap.BootstrapError('schema-refused')+ return ''+ assert args[2:] == ['plugins', 'inspect', '--all', '--runtime', '--json']+ if fault == 'command': raise config.bootstrap.BootstrapError('command-refused')+ if fault == 'malformed-json': return 'not JSON'+ good = {'id': 'searxng', 'rootDir': expected['searxng'], 'status': 'loaded', 'imported': True}+ if fault == 'failed': good['status'] = 'error'+ if fault == 'wrong-path': good['rootDir'] = '/other'+ if fault == 'not-imported': good['imported'] = False+ if fault == 'missing-imported': del good['imported']+ if fault == 'string-imported': good['imported'] = 'true'+ result = [{'plugin': good}]+ if fault == 'missing': result = []+ if fault == 'malformed-report': result = [None]+ if fault == 'manifest-only': return json.dumps({'plugins': [good]})+ if fault == 'duplicate-failed': result.append({'plugin': {**good, 'status': 'error'}})+ return json.dumps(result)+ monkeypatch.setattr(config.bootstrap, 'command', command)+ def run():+ config.validate_candidate(candidate, node=tmp_path / 'node', entrypoint=tmp_path / 'openclaw.mjs',+ expected=expected, env={'HOME': str(home), 'PATH': '/bin'}, cwd=tmp_path)+ if fault in ('schema', 'command'):+ with pytest.raises(config.bootstrap.BootstrapError, match=fault + '-refused'): run()+ elif fault:+ with pytest.raises(ValueError, match='native-config-plugin-not-loaded'): run()+ else:+ run()+ assert calls == [['config', 'validate']] + ([] if fault == 'schema' else [+ ['plugins', 'inspect', '--all', '--runtime', '--json']])+ assert candidate.read_text() == '{"candidate":true}'+ assert not home.exists()++@pytest.mark.parametrize('migrating', [False, True])def test_existing_home_is_preserved_and_allowed_only_for_explicit_migration(tmp_path, monkeypatch, migrating):monkeypatch.setattr(config.sys, 'platform', 'darwin')