Skip to content

armgit / ODS

Public Imported from GitHub
0

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.

23.9 KB
Raw Blame
import base64
import hashlib
import http.client
import importlib.util
import json
import shutil
import subprocess
import urllib.request
from pathlib import Path
from types import SimpleNamespace

import pytest


SPEC = importlib.util.spec_from_file_location('native_bootstrap',
    Path(__file__).resolve().parents[1] / 'installers/macos/lib/pixel-native-bootstrap.py')
bootstrap = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(bootstrap)


@pytest.mark.parametrize('tampered', [False, True])
def test_public_ods_bundle_acquires_without_private_repository(tmp_path, monkeypatch, tampered):
    monkeypatch.setattr(bootstrap.sys, 'platform', 'darwin')
    monkeypatch.setattr(bootstrap.os, 'geteuid', lambda: 501)
    bundle = tmp_path / 'pixel.bundle'
    shutil.copy2(Path(__file__).resolve().parents[1] / 'vendor/pixel.bundle', bundle)
    if tampered:
        with bundle.open('ab') as handle:
            handle.write(b'changed')
    destination = tmp_path / 'source'
    if tampered:
        with pytest.raises(bootstrap.BootstrapError, match='bundled-pixel-source-digest-mismatch'):
            bootstrap.acquire_source(ref=bootstrap.ODS_BUNDLED_REF,
                destination=destination, source_url=str(bundle))
        assert not destination.exists()
    else:
        assert bootstrap.acquire_source(ref=bootstrap.ODS_BUNDLED_REF,
            destination=destination, source_url=str(bundle)) == destination
        assert bootstrap.selected_release(destination, bootstrap.ODS_BUNDLED_REF)['pixel'] == '4.3.33'


def test_standalone_acquisition_defaults_to_ods_bundle(tmp_path, monkeypatch):
    monkeypatch.setattr(bootstrap.sys, 'platform', 'darwin')
    monkeypatch.setattr(bootstrap.os, 'geteuid', lambda: 501)
    monkeypatch.setenv('GIT_CONFIG_GLOBAL', '/untrusted/host-gitconfig')
    monkeypatch.setenv('GIT_ALLOW_PROTOCOL', 'https')
    original_command = bootstrap.command
    local_git_calls = []

    def audited_command(args, **kwargs):
        if any(action in args for action in ('clone', 'fetch')):
            env = kwargs['env']
            assert env['GIT_CONFIG_NOSYSTEM'] == '1'
            assert env['GIT_CONFIG_GLOBAL'] == bootstrap.os.devnull
            assert env['GIT_ALLOW_PROTOCOL'] == 'file'
            assert env['GIT_TERMINAL_PROMPT'] == '0'
            local_git_calls.append(args)
        return original_command(args, **kwargs)

    monkeypatch.setattr(bootstrap, 'command', audited_command)
    destination = tmp_path / 'source'
    assert bootstrap.acquire_source(ref=bootstrap.ODS_BUNDLED_REF, destination=destination) == destination
    assert bootstrap.selected_release(destination, bootstrap.ODS_BUNDLED_REF)['pixel'] == '4.3.33'
    assert len(local_git_calls) == 2


@pytest.mark.parametrize('source_url', [
    'https://github.com/Osmantic/Pixel.git',
    '[email protected]:Osmantic/Pixel.git',
    'ssh://[email protected]/Osmantic/Pixel.git',
    'relative/pixel.bundle',
])
def test_acquisition_refuses_remote_and_relative_sources(tmp_path, monkeypatch, source_url):
    monkeypatch.setattr(bootstrap.sys, 'platform', 'darwin')
    monkeypatch.setattr(bootstrap.os, 'geteuid', lambda: 501)
    destination = tmp_path / 'source'
    with pytest.raises(bootstrap.BootstrapError, match='local-pixel-source-required'):
        bootstrap.acquire_source(ref=bootstrap.ODS_BUNDLED_REF,
            destination=destination, source_url=source_url)
    assert not destination.exists()


@pytest.mark.parametrize('fault', [None, 'unreferenced', 'ref', 'existing', 'missing-commit', 'release'])
def test_source_acquisition_uses_exact_commit_without_changing_input(tmp_path, release, monkeypatch, fault):
    monkeypatch.setattr(bootstrap.sys, 'platform', 'darwin')
    monkeypatch.setattr(bootstrap.os, 'geteuid', lambda: 501)
    source = tmp_path / 'Original Source'
    source.mkdir()
    def git(*args):
        return subprocess.check_output(['git', *args], cwd=source, text=True).strip()
    git('init', '-q')
    constants = source / 'scripts/generated/release-constants.json'
    constants.parent.mkdir(parents=True)
    constants.write_text(json.dumps({} if fault == 'release' else release))
    git('add', '.')
    git('-c', 'user.name=Fixture', '-c', '[email protected]',
        '-c', 'commit.gpgsign=false', 'commit', '-qm', 'selected')
    ref = git('rev-parse', 'HEAD')
    original_head = ref
    if fault == 'unreferenced':
        git('checkout', '--detach', '-q', original_head)
        (source / 'selected-marker').write_text('selected commit, no branch')
        git('add', '.')
        git('-c', 'user.name=Fixture', '-c', '[email protected]',
            '-c', 'commit.gpgsign=false', 'commit', '-qm', 'unreferenced selected commit')
        ref = git('rev-parse', 'HEAD')
        git('checkout', '--detach', '-q', original_head)
    constants.write_text('uncommitted owner change')
    destination = tmp_path / 'Acquired Source'
    if fault == 'existing':
        destination.mkdir()
        (destination / 'keep').write_text('owner file')
    def run():
        return bootstrap.acquire_source(ref=('main' if fault == 'ref' else
            '0' * 40 if fault == 'missing-commit' else ref), destination=destination,
            source_url=str(source))
    if fault not in (None, 'unreferenced'):
        with pytest.raises((bootstrap.BootstrapError, KeyError)):
            run()
        if fault == 'existing':
            assert (destination / 'keep').read_text() == 'owner file'
        else:
            assert not destination.exists()
    else:
        assert run() == destination
        assert bootstrap.selected_release(destination, ref) == release
    assert constants.read_text() == 'uncommitted owner change'
    assert git('rev-parse', 'HEAD') == original_head
    assert not list(tmp_path.glob('.pixel-source-*'))


@pytest.fixture
def release():
    body = b'fixture archive'
    value = {'schemaVersion': 1, 'pixel': '4.3.27', 'node': '>=22', 'openclaw': '2026.6.33',
            'openclawPackage': {'url': 'https://registry.npmjs.org/openclaw/-/openclaw-2026.6.33.tgz',
                'sha256': hashlib.sha256(body).hexdigest(),
                'integrity': 'sha512-' + base64.b64encode(hashlib.sha512(body).digest()).decode()}}
    value['openclawPlugins'] = {name: '2026.6.33' for _, _, name in bootstrap.PLUGINS}
    value['openclawPluginPackages'] = {key: {**value['openclawPackage'],
        'url': 'https://registry.npmjs.org/' + name + '/-/' + name.split('/')[-1] + '-2026.6.33.tgz'}
        for key, _, name in bootstrap.PLUGINS}
    value['sandboxNodeRuntime'] = {'version': '24.21.0', 'artifacts': {}}
    return value


@pytest.mark.parametrize('fault', [None, 'ref', 'dirty', 'url', 'digest', 'changed', 'plugin-url'])
def test_release_requires_exact_clean_source(tmp_path, release, monkeypatch, fault):
    if fault == 'url': release['openclawPackage']['url'] = 'https://example.com/package'
    if fault == 'digest': release['openclawPackage']['sha256'] = 'missing'
    if fault == 'plugin-url': release['openclawPluginPackages']['searxng']['url'] = 'https://example.com/plugin'
    path = tmp_path / 'scripts/generated/release-constants.json'
    path.parent.mkdir(parents=True)
    path.write_text(json.dumps(release))
    def command(args, **kwargs):
        if args[1] == 'rev-parse': return 'b' * 40 if fault == 'ref' else 'a' * 40
        if args[1] == 'status': return ' M changed' if fault == 'dirty' else ''
        return '{}' if fault == 'changed' else json.dumps(release)
    monkeypatch.setattr(bootstrap, 'command', command)
    if fault:
        with pytest.raises(bootstrap.BootstrapError): bootstrap.selected_release(tmp_path, 'a' * 40)
    else:
        assert bootstrap.selected_release(tmp_path, 'a' * 40) == release


@pytest.mark.parametrize('fault', [None, 'checksum', 'integrity'])
def test_download_verifies_both_hashes(tmp_path, release, monkeypatch, fault):
    import io
    monkeypatch.setattr(bootstrap.urllib.request, 'build_opener',
        lambda *a: SimpleNamespace(open=lambda *a, **k: io.BytesIO(b'fixture archive')))
    package = release['openclawPackage']
    if fault == 'checksum': package['sha256'] = '0' * 64
    if fault == 'integrity': package['integrity'] = 'sha512-' + 'A' * 86 + '=='
    if fault:
        with pytest.raises(bootstrap.BootstrapError, match='checksum-mismatch'):
            bootstrap.download(package, tmp_path / 'archive')
        assert not (tmp_path / 'archive').exists()
    else:
        bootstrap.download(package, tmp_path / 'archive')
        assert (tmp_path / 'archive').read_bytes() == b'fixture archive'


@pytest.mark.parametrize('network_error', [
    ConnectionResetError('Connection reset by peer'),
    urllib.request.URLError('connection refused'),
    TimeoutError('operation timed out'),
    http.client.RemoteDisconnected('Remote end closed connection without response'),
])
@pytest.mark.parametrize('mid_stream', [False, True])
def test_download_network_drop_cleans_up_and_reports_bootstrap_error(
        tmp_path, release, monkeypatch, network_error, mid_stream):
    class MockStream:
        def __init__(self):
            self.delivered = False

        def __enter__(self):
            return self

        def __exit__(self, *args):
            pass

        def read(self, block_size):
            if mid_stream and not self.delivered:
                self.delivered = True
                return b'partial block of bytes'
            raise network_error

    class MockOpener:
        def open(self, *args, **kwargs):
            if not mid_stream:
                raise network_error
            return MockStream()

    sleep_calls = []
    monkeypatch.setattr(bootstrap.time, 'sleep', sleep_calls.append)
    monkeypatch.setattr(bootstrap.urllib.request, 'build_opener', lambda *a: MockOpener())
    package = release['openclawPackage']
    destination = tmp_path / 'archive.tgz'
    with pytest.raises(bootstrap.BootstrapError, match='pinned-package-download-failed') as exc_info:
        bootstrap.download(package, destination)

    assert isinstance(exc_info.value, ValueError)
    assert exc_info.value.__cause__ is network_error
    assert not destination.exists()
    assert sleep_calls == [1, 2]


@pytest.mark.parametrize('error_cls', [ConnectionResetError, urllib.request.URLError, TimeoutError])
def test_download_transient_network_drop_recovers_within_retry_budget(
        tmp_path, release, monkeypatch, error_cls):
    import io
    attempts = []

    class FlakyOpener:
        def open(self, *args, **kwargs):
            attempts.append(True)
            if len(attempts) == 1:
                raise error_cls('transient drop')
            return io.BytesIO(b'fixture archive')

    sleep_calls = []
    monkeypatch.setattr(bootstrap.time, 'sleep', sleep_calls.append)
    monkeypatch.setattr(bootstrap.urllib.request, 'build_opener', lambda *a: FlakyOpener())
    package = release['openclawPackage']
    destination = tmp_path / 'archive.tgz'
    bootstrap.download(package, destination)

    assert destination.read_bytes() == b'fixture archive'
    assert len(attempts) == 2
    assert sleep_calls == [1]


def test_download_oversized_package_cleans_up(tmp_path, release, monkeypatch):
    class OversizedStream:
        def __init__(self):
            self.count = 0

        def __enter__(self):
            return self

        def __exit__(self, *args):
            pass

        def read(self, block_size):
            if self.count < 65:
                self.count += 1
                return b'x' * (1024 * 1024)
            return b''

    sleep_calls = []
    monkeypatch.setattr(bootstrap.time, 'sleep', sleep_calls.append)
    monkeypatch.setattr(bootstrap.urllib.request, 'build_opener',
        lambda *a: SimpleNamespace(open=lambda *a, **k: OversizedStream()))
    package = release['openclawPackage']
    destination = tmp_path / 'oversized.tgz'
    with pytest.raises(bootstrap.BootstrapError, match='pinned-package-too-large'):
        bootstrap.download(package, destination)
    assert not destination.exists()
    assert sleep_calls == []


def test_download_refuses_preexisting_destination_without_deleting(tmp_path, release, monkeypatch):
    import io
    monkeypatch.setattr(bootstrap.urllib.request, 'build_opener',
        lambda *a: SimpleNamespace(open=lambda *a, **k: io.BytesIO(b'fixture archive')))
    destination = tmp_path / 'preexisting.tgz'
    destination.write_bytes(b'pre-existing artifact data')
    with pytest.raises(FileExistsError):
        bootstrap.download(release['openclawPackage'], destination)
    assert destination.read_bytes() == b'pre-existing artifact data'


@pytest.mark.parametrize('network_error', [
    ConnectionResetError('connection dropped before opening destination'),
    urllib.request.URLError('DNS resolution failed'),
])
def test_download_preserves_existing_destination_even_when_transport_is_down(
        tmp_path, release, monkeypatch, network_error):
    calls = []

    def unavailable(*args, **kwargs):
        calls.append(True)
        raise network_error

    monkeypatch.setattr(bootstrap.urllib.request, 'build_opener',
        lambda *a: SimpleNamespace(open=unavailable))
    monkeypatch.setattr(bootstrap.time, 'sleep', lambda seconds: None)
    destination = tmp_path / 'existing.tgz'
    destination.write_bytes(b'owner artifact')
    with pytest.raises(FileExistsError):
        bootstrap.download(release['openclawPackage'], destination)
    assert destination.read_bytes() == b'owner artifact'
    assert calls == []


@pytest.mark.parametrize('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
        path.mkdir()
        (path / 'package.json').write_text(json.dumps({'version': release['pixel']}))
        (path / 'openclaw.plugin.json').write_text(json.dumps({'id': plugin_id}))
    monkeypatch.setattr(bootstrap.sys, 'platform', 'darwin')
    monkeypatch.setattr(bootstrap.os, 'geteuid', lambda: 0 if fault == 'root' else 501)
    monkeypatch.setattr(bootstrap, 'selected_release', lambda *a: release)
    node, npm = tmp_path / 'node', tmp_path / 'npm-cli.js'
    node.touch()
    npm.touch()
    ca_bundle = tmp_path / 'system-ca.pem'
    ca_bundle.write_text('fixture CA bundle')
    monkeypatch.setattr(bootstrap, 'MACOS_CA_BUNDLE', ca_bundle)
    calls = []
    def command(args, **kwargs):
        calls.append(args)
        assert kwargs['env']['PATH'].startswith(str(node.parent))
        assert kwargs['env']['NODE_EXTRA_CA_CERTS'] == str(ca_bundle)
        if args[1] == '-p':
            return 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([{'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:
            # npm may be a Volta shell launcher, not JavaScript for node to run.
            assert args[0] == str(npm)
            assert '--install-strategy=nested' in args and '--omit=dev' in args
            if fault == 'npm': raise bootstrap.BootstrapError('npm failure')
            runtime = Path(args[args.index('--prefix') + 1]) / 'node_modules/openclaw'
            runtime.mkdir(parents=True)
            (runtime / 'package.json').write_text(json.dumps({'name': 'openclaw',
                'version': 'other' if fault == 'version' else release['openclaw']}))
            (runtime / 'openclaw.mjs').touch()
            for _, plugin_id, name in bootstrap.PLUGINS:
                path = runtime.parent / name
                path.mkdir(parents=True)
                (path / 'package.json').write_text(json.dumps({'name': name,
                    'version': 'wrong' if fault == 'plugin-version' else release['openclawPlugins'][name]}))
                (path / 'openclaw.plugin.json').write_text(json.dumps({
                    'id': 'wrong' if fault == 'plugin-id' else plugin_id}))
            return ''
        return 'other' if fault == 'probe' else release['openclaw']
    monkeypatch.setattr(bootstrap, 'command', command)
    monkeypatch.setattr(bootstrap, 'download', lambda package, path: path.write_bytes(b'archive'))
    destination = tmp_path / 'Owner Runtime'
    def run():
        return bootstrap.stage(source=tmp_path, ref='a' * 40, destination=destination, node=node, npm=npm)
    if fault:
        with pytest.raises(bootstrap.BootstrapError): run()
        assert not destination.exists()
    else:
        assert run() == destination / 'node_modules/openclaw'
        receipt = json.loads((destination / 'ods-bootstrap.json').read_text())
        assert receipt['pixelSourceRef'] == 'a' * 40
        assert [p['id'] for p in receipt['plugins']] == ['discord', 'searxng', 'llama-cpp']
        assert [p['id'] for p in receipt['pixelPlugins']] == [item[1] for item in bootstrap.PIXEL_PLUGINS]
    assert not list(tmp_path.glob('.pixel-bootstrap-*'))
    if fault == 'root': assert not calls


@pytest.mark.parametrize('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', '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
        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')
    if fault:
        with pytest.raises(bootstrap.BootstrapError, match='load-proof-failed'): run()
    else:
        run()


NODE_PROOF_FAULTS = {
    'node-missing': None,
    'node-version': ['v22.23.1', 'arm64'],
    'node-arch': ['v24.21.0', 'x64'],
}


@pytest.mark.parametrize('fault', [None, 'root', 'arch', 'user', 'label', 'uid', 'tools', 'run', 'changed',
                                   'build', 'no-node-pin', 'npm-present', *NODE_PROOF_FAULTS])
@pytest.mark.parametrize('existing', [False, True])
def test_sandbox_build_and_proof_are_owner_bound(tmp_path, release, monkeypatch, fault, existing):
    monkeypatch.setattr(bootstrap.sys, 'platform', 'darwin')
    monkeypatch.setattr(bootstrap.os, 'geteuid', lambda: 0 if fault == 'root' else 501)
    monkeypatch.setattr(bootstrap.os, 'getuid', lambda: 501)
    if fault == 'no-node-pin':
        del release['sandboxNodeRuntime']
    monkeypatch.setattr(bootstrap, 'selected_release', lambda *a: release)
    docker = tmp_path / 'docker'
    docker.touch()
    calls, inspections = [], []
    def command(args, **kwargs):
        calls.append(args)
        if args[1:3] == ['image', 'ls']: return '{}' if existing else ''
        if args[1] == 'build':
            assert 'PIXEL_SANDBOX_UID=501' in args and 'linux/arm64' in args
            if fault == 'build': raise bootstrap.BootstrapError('native-bootstrap-command-failed')
            return ''
        if args[1:3] == ['image', 'inspect']:
            inspections.append(True)
            return json.dumps([{'Id': 'sha256:' + ('b' if fault == 'changed' and len(inspections) > 1 else 'a') * 64,
                'Architecture': 'amd64' if fault == 'arch' else 'arm64', 'Os': 'linux',
                'Config': {'User': 'root' if fault == 'user' else 'sandbox', 'Labels': {
                    'org.osmantic.pixel.sandbox-version': release['pixel'],
                    'org.osmantic.pixel.sandbox-uid': '501',
                    'org.osmantic.pixel.source-ref': 'wrong' if fault == 'label' else 'a' * 40}}}])
        assert args[1] == 'run'
        assert 'sha256:' + 'a' * 64 in args
        assert args[args.index('--network') + 1] == 'none'
        assert '--read-only' in args and '--cap-drop' in args
        assert 'no-new-privileges:true' in args and '--memory' in args
        assert not any(x in args for x in ('--privileged', '--volume', '-v'))
        if fault == 'run': raise bootstrap.BootstrapError('run-failed')
        mount = args[args.index('--mount') + 1]
        workspace = Path(mount.removeprefix('type=bind,source=').removesuffix(',target=/workspace'))
        assert workspace.name.startswith('ods-sandbox-workspace-')
        assert workspace.parent == tmp_path.parent
        (workspace / 'ods-proof.txt').write_text('ods-sandbox-proof')
        # The proof runs node inside the image and lists any package manager.
        program = args[args.index('-c') + 1]
        assert '"-p","JSON.stringify([process.version,process.arch])"' in program
        assert '["npm","npx","corepack"]' in program
        return json.dumps({'uid': 0 if fault == 'uid' else 501,
                           'readback': 'ods-sandbox-proof', 'tools': fault != 'tools',
                           'node': NODE_PROOF_FAULTS.get(fault, ['v24.21.0', 'arm64']),
                           'packageManagers': ['npm', 'npx'] if fault == 'npm-present' else []})
    monkeypatch.setattr(bootstrap, 'command', command)
    cleanups = []
    monkeypatch.setattr(bootstrap.subprocess, 'run', lambda args, **kwargs: cleanups.append(args))
    def run():
        return bootstrap.prepare_sandbox(source=tmp_path, ref='a' * 40, docker=docker)
    expected_error = {'build': 'native-sandbox-build-failed', 'no-node-pin': 'invalid-sandbox-node-runtime',
        'run': 'native-sandbox-execution-proof-failed', 'tools': 'native-sandbox-execution-proof-failed',
        'npm-present': 'native-sandbox-execution-proof-failed',
        **{name: 'native-sandbox-execution-proof-failed' for name in NODE_PROOF_FAULTS}}.get(fault)
    if fault == 'build' and existing:
        receipt = run()  # an existing tag is not rebuilt; it still passes the proof
        assert receipt['imageId'] == 'sha256:' + 'a' * 64
    elif fault:
        with pytest.raises(bootstrap.BootstrapError, match=expected_error): run()
    else:
        receipt = run()
        assert receipt['ownerUid'] == 501 and receipt['imageId'] == 'sha256:' + 'a' * 64
    if fault not in ('root', 'no-node-pin'):
        assert any(args[1] == 'build' for args in calls) is not existing
    if fault == 'no-node-pin':
        assert calls == [], 'refuse before building or running anything'
    ran = [args for args in calls if args[1] == 'run']
    assert bool(cleanups) == bool(ran)
    if ran:
        assert cleanups[0] == [str(docker), 'rm', '-f', ran[0][ran[0].index('--name') + 1]]