From f6b3ebf9e486c9b6832425417882ef93f736a5d6 Mon Sep 17 00:00:00 2001 From: atlaie Date: Fri, 23 Oct 2026 17:57:37 -0700 Subject: [PATCH 1/5] feat: clearer messages when an api call is refused or held back - output_paths points to job.policy_error when a policy refused the call, and says when the output policy held the outputs back - a blocking api call prints why it ended (_print_call_result) - the api table has a Policies column - ApiResult shows the api's args and when set_policies cleared its state; print(result) shows the same text as repr - the job view shows code/params.json in a Parameters section Messages and displays only; no behaviour changes. Co-Authored-By: Claude Opus 5.5 --- packages/syft-bg/src/syft_bg/api/api.py | 4 +- packages/syft-bg/src/syft_bg/api/results.py | 12 +++ packages/syft-job/src/syft_job/job.py | 17 +++- packages/syft-job/src/syft_job/job_repr.py | 23 ++++- packages/syft-job/tests/test_policies.py | 16 +++ packages/syft-rds/src/syft_rds/apis/repr.py | 15 ++- packages/syft-rds/src/syft_rds/client.py | 12 ++- packages/syft-rds/tests/test_api_policies.py | 102 ++++++++++++++++++- tests/unit/syft_bg/test_api_result.py | 43 ++++++++ 9 files changed, 233 insertions(+), 11 deletions(-) create mode 100644 tests/unit/syft_bg/test_api_result.py diff --git a/packages/syft-bg/src/syft_bg/api/api.py b/packages/syft-bg/src/syft_bg/api/api.py index 45a7b2eb3fa..7e2982f8f1b 100644 --- a/packages/syft-bg/src/syft_bg/api/api.py +++ b/packages/syft-bg/src/syft_bg/api/api.py @@ -538,7 +538,9 @@ def set_policies( ) except (ApiNotFoundError, ValueError) as e: return ApiResult(success=False, error=str(e)) - return ApiResult.from_api(name, obj) + result = ApiResult.from_api(name, obj) + result.state_cleared = reset_state + return result def run_policy( diff --git a/packages/syft-bg/src/syft_bg/api/results.py b/packages/syft-bg/src/syft_bg/api/results.py index 8ec088844bc..5dc3a9a8ec2 100644 --- a/packages/syft-bg/src/syft_bg/api/results.py +++ b/packages/syft-bg/src/syft_bg/api/results.py @@ -294,6 +294,8 @@ class ApiResult(BaseModel): file_paths: list[str] = Field(default_factory=list) peers: list[str] = Field(default_factory=list) policies: list[str] = Field(default_factory=list) # e.g. ["input", "output"] + args: list[str] = Field(default_factory=list) # e.g. ["a: int = 1"] + state_cleared: bool = False # set_policies() cleared the api's state error: str | None = None @classmethod @@ -306,6 +308,7 @@ def from_api(cls, name: str, obj: ApiDefinition) -> ApiResult: file_paths=obj.file_paths, peers=obj.peers, policies=policies, + args=[a.describe() for a in obj.args], ) def __repr__(self) -> str: @@ -318,14 +321,23 @@ def __repr__(self) -> str: lines.append(f" - {s}") if self.file_paths: lines.append(f" file_paths: {', '.join(self.file_paths)}") + if self.args: + lines.append(" args:") + for a in self.args: + lines.append(f" - {a}") if self.peers: lines.append(f" peers: {', '.join(self.peers)}") else: lines.append(" peers: (any)") if self.policies: lines.append(f" policies: {', '.join(self.policies)}") + if self.state_cleared: + lines.append(" state: cleared (pass reset_state=False to keep it)") else: lines.append("ApiResult: FAILED") if self.error: lines.append(f" error: {self.error}") return "\n".join(lines) + + def __str__(self) -> str: + return self.__repr__() diff --git a/packages/syft-job/src/syft_job/job.py b/packages/syft-job/src/syft_job/job.py index 04b4866c003..2c7a194c64a 100644 --- a/packages/syft-job/src/syft_job/job.py +++ b/packages/syft-job/src/syft_job/job.py @@ -237,10 +237,13 @@ def _list_output_files() -> List[Path]: if status == JobStatus.FAILED: partial = _list_output_files() print(f"❌ Job '{self.name}' failed (status: {self.status}).") - print( - f" Returning {len(partial)} partial output file(s). " - "Check stderr for details: job.stderr" - ) + policy_error = self.policy_error + if policy_error: + print(f" The data owner's policy refused the call: {policy_error}") + hint = "The reason is in job.policy_error." + else: + hint = "Check stderr for details: job.stderr" + print(f" Returning {len(partial)} partial output file(s). {hint}") return partial if status != JobStatus.DONE: @@ -251,7 +254,11 @@ def _list_output_files() -> List[Path]: output_files = _list_output_files() if not output_files: print(f"⚠️ Job '{self.name}' is done but no output files were found.") - print(" The job script may not have written to the outputs/ folder.") + if self.outputs_withheld: + print(" The data owner's output policy held the outputs back.") + print(" The data owner can still share them with you later.") + else: + print(" The job script may not have written to the outputs/ folder.") return [] return output_files diff --git a/packages/syft-job/src/syft_job/job_repr.py b/packages/syft-job/src/syft_job/job_repr.py index b619bbe8813..341a47443c7 100644 --- a/packages/syft-job/src/syft_job/job_repr.py +++ b/packages/syft-job/src/syft_job/job_repr.py @@ -1,5 +1,6 @@ from __future__ import annotations +import json import re from html import escape from typing import TYPE_CHECKING, List @@ -428,6 +429,8 @@ def job_info_repr_html(job: "JobInfo") -> str: except Exception: pass + params_section = _params_html(job) + status_emoji_map = { "received": "📨", "pending": "📥", @@ -743,7 +746,7 @@ def job_info_repr_html(job: "JobInfo") -> str:

📜 Script

{script_content}
-
{code_section}{policy_section}{outputs_section} + {code_section}{params_section}{policy_section}{outputs_section} """ @@ -757,6 +760,24 @@ def _detail_html(label: str, value: str) -> str: """ +def _params_html(job: "JobInfo") -> str: + """A section with code/params.json, the arguments the job runs with.""" + try: + params = (job.code_dir / "params.json").read_text() + except (OSError, ValueError): + return "" + try: + params = json.dumps(json.loads(params), indent=2, ensure_ascii=False) + except ValueError: + pass # not JSON: show it as it is + return f""" +
+

Parameters

+
code/params.json
+
{escape(params)}
+
""" + + def _policy_html(job: "JobInfo") -> tuple[str, str]: """Detail rows (api, policy error) and a section with the policies' code.""" details = "" diff --git a/packages/syft-job/tests/test_policies.py b/packages/syft-job/tests/test_policies.py index 648f0088d78..e3925a901ca 100644 --- a/packages/syft-job/tests/test_policies.py +++ b/packages/syft-job/tests/test_policies.py @@ -1,6 +1,7 @@ """Api calls (requests), and the input and output policies run around them.""" import json +from html import escape from pathlib import Path import pytest @@ -346,6 +347,21 @@ def test_api_call_ignores_share_flags(env): assert job.outputs_withheld +def test_job_view_shows_params_escaped(env): + (env.apis.files_dir / "run.sh").write_text("echo hi\n") + params = {"code/params.json": b'{"word": "privacy", "n": 3}'} + env.ds_client.submit_api_request(DO_EMAIL, "call.job", API_NAME, params) + env.ds_client.submit_bash_job(DO_EMAIL, "echo hi", "plain.job") + + html = env.do_job("call.job")._repr_html_() + + assert "

Parameters

" in html + pretty = '{\n "word": "privacy",\n "n": 3\n}' + assert escape(pretty) in html and "privacy" not in html + # A job without code/params.json has no such section. + assert "

Parameters

" not in env.do_job("plain.job")._repr_html_() + + def test_request_becomes_approved_job_with_api_code(env): job = env.call("cp code/params.json code/outputs/params.json") diff --git a/packages/syft-rds/src/syft_rds/apis/repr.py b/packages/syft-rds/src/syft_rds/apis/repr.py index 170accb4e73..bd477b40a07 100644 --- a/packages/syft-rds/src/syft_rds/apis/repr.py +++ b/packages/syft-rds/src/syft_rds/apis/repr.py @@ -58,6 +58,13 @@ def _args_html(api: Api) -> str: ) +def _policy_kinds(api: Api) -> str: + """The policies the api has, e.g. "input, output", or "-".""" + definition = api.definition + kinds = [k for k in ("input", "output") if getattr(definition, f"{k}_policy")] + return ", ".join(kinds) or "-" + + def _row_html(index: int, api: Api) -> str: call = escape(api.call_signature) code = escape(api.python_file or "-") @@ -67,6 +74,7 @@ def _row_html(index: int, api: Api) -> str: f'{escape(api.name)}' f'{escape(api.datasite)}' f'{_args_html(api)}' + f'{escape(_policy_kinds(api))}' f'{code}' f'{call}' "" @@ -76,7 +84,7 @@ def _row_html(index: int, api: Api) -> str: def api_collection_repr_html(apis: Sequence[Api]) -> str: if not apis: return _EMPTY_HTML - headers = ["#", "Name", "Datasite", "Args", "Code", "Call"] + headers = ["#", "Name", "Datasite", "Args", "Policies", "Code", "Call"] head = "".join(f'{h}' for h in headers) rows = "".join(_row_html(i, api) for i, api in enumerate(apis)) return f"""{_STYLE} @@ -97,7 +105,10 @@ def api_collection_repr_str(apis: Sequence[Api]) -> str: lines = [f"Apis ({len(apis)}):"] for i, api in enumerate(apis): call = api.call_signature - lines.append(f" [{i}] {api.name} (from {api.datasite}) -> {call}") + policies = _policy_kinds(api) + lines.append( + f" [{i}] {api.name} (from {api.datasite}) -> {call} | policies: {policies}" + ) return "\n".join(lines) diff --git a/packages/syft-rds/src/syft_rds/client.py b/packages/syft-rds/src/syft_rds/client.py index e6d18b7b395..79c354d9386 100644 --- a/packages/syft-rds/src/syft_rds/client.py +++ b/packages/syft-rds/src/syft_rds/client.py @@ -121,6 +121,16 @@ def _peer_schema_lookup( return lambda email: peer_store.protocol_schema(email, protocol_name) +def _print_call_result(job: Any) -> None: + """Report how the job of a blocking api call ended, and why a policy stopped it.""" + print(f"Job '{job.name}' finished with status: {job.status}") + if job.policy_error: + print(f" The data owner's policy refused the call: {job.policy_error}") + elif job.status == "done" and job.outputs_withheld: + print(" The data owner's output policy held the outputs back.") + print(" The data owner can still share them with you later.") + + class SyftRDSClient(BaseModel): # Holds live service objects (sync engine + RDS-owned managers), not # serializable data, so arbitrary types are allowed. @@ -553,7 +563,7 @@ def _wait_for_call(self, job_name: str, poll_interval: float = 2.0) -> Any: self.sync_engine.sync() job = _named(self.job_client.jobs, job_name) if job is not None and job.status in FINISHED_JOB_STATUSES: - print(f"Job '{job_name}' finished with status: {job.status}") + _print_call_result(job) return job request = _named(self.job_client.requests, job_name) if request is not None and request.status == "rejected": diff --git a/packages/syft-rds/tests/test_api_policies.py b/packages/syft-rds/tests/test_api_policies.py index e235dbfd625..676552f507b 100644 --- a/packages/syft-rds/tests/test_api_policies.py +++ b/packages/syft-rds/tests/test_api_policies.py @@ -11,6 +11,9 @@ from syft_bg.approve.handlers.job import ApprovedJobHandler from syft_bg.common.config import get_default_paths from syft_rds import SyftRDSClient +from syft_rds.apis import Api, ApiDefinition, FileEntry +from syft_rds.apis.repr import api_collection_repr_html, api_collection_repr_str +from syft_rds.client import _print_call_result ADDER_CODE = """import json with open("params.json") as f: @@ -37,6 +40,12 @@ raise ValueError("Sum too large to share") """ +# Approves no reader for any file, so the outputs are held back. +HOLD_BACK_POLICY = """import os +from pathlib import Path +Path(os.environ["SYFT_POLICY_READ_PERMISSIONS_PATH"]).write_text("{}") +""" + @contextmanager def _temp_config_paths(): @@ -92,7 +101,7 @@ def _ds_job(ds_manager, name: str): return next(j for j in ds_manager.jobs if j.name == name) -def test_api_policies_allow_block_and_show(): +def test_api_policies_allow_block_and_show(capsys): ds_manager, do_manager = SyftRDSClient.pair_with_mock_drive_service_connection( use_in_memory_cache=False, sync_automatically=False, @@ -109,6 +118,11 @@ def test_api_policies_allow_block_and_show(): do_manager.sync() ds_manager.sync() + # The api table says which policies an api has. + assert "client.api.adder(a, b) | policies: input, output" in str(ds_manager.api) + table = ds_manager.api._repr_html_() + assert 'Policies' in table + assert 'input, output' in table api = ds_manager.api.adder assert "Rate limit reached" in repr(api) assert "Sum too large to share" in api._repr_html_() @@ -126,7 +140,21 @@ def test_api_policies_allow_block_and_show(): blocked = _ds_job(ds_manager, large.name) assert blocked.status == "failed" assert blocked.policy_error == "ValueError: Sum too large to share" + capsys.readouterr() assert blocked.output_paths == [] + # The DS is sent to the policy's reason, not to a stderr they don't get. + out = capsys.readouterr().out + assert ( + "The data owner's policy refused the call: " + "ValueError: Sum too large to share" in out + ) + assert "job.policy_error" in out and "job.stderr" not in out + _print_call_result(blocked) + assert capsys.readouterr().out == ( + f"Job '{large.name}' finished with status: failed\n" + " The data owner's policy refused the call: " + "ValueError: Sum too large to share\n" + ) # The rate limit of one call is used up. second = api(1, b=2, block=False) @@ -134,6 +162,12 @@ def test_api_policies_allow_block_and_show(): limited = _ds_job(ds_manager, second.name) assert limited.status == "failed" assert limited.policy_error == "ValueError: Rate limit reached: 1 call" + capsys.readouterr() + _print_call_result(limited) + assert ( + "refused the call: ValueError: Rate limit reached: 1 call" + in capsys.readouterr().out + ) # The DO's view of a call shows the api and its policies. do_job = next(j for j in do_manager.jobs if j.name == large.name) @@ -142,3 +176,69 @@ def test_api_policies_allow_block_and_show(): assert "adder" in html and "Input policy" in html and "Output policy" in html original = next(j for j in do_manager.jobs if j.name == job.name) assert original.status == "pending" + + +def test_held_back_outputs_point_to_the_policy(capsys): + ds_manager, do_manager = SyftRDSClient.pair_with_mock_drive_service_connection( + use_in_memory_cache=False, + sync_automatically=False, + ) + job = _submit_adder_job(ds_manager, do_manager, {"a": 1, "b": 2}) + + with _temp_config_paths() as (paths, tmp): + result = create_api_from_job( + job, output_policy=_write(tmp / "hold_back.py", HOLD_BACK_POLICY) + ) + assert result.success + do_manager.sync() + ds_manager.sync() + call = ds_manager.api.adder(1, b=2, block=False) + _run_calls(do_manager, paths.config) + held = _ds_job(ds_manager, call.name) + + assert held.status == "done" and held.outputs_withheld + capsys.readouterr() + assert held.output_paths == [] + # The DS is told the policy held the outputs back, not that the script + # wrote none. + out = capsys.readouterr().out + assert "The data owner's output policy held the outputs back." in out + assert "The data owner can still share them with you later." in out + assert "may not have written" not in out + _print_call_result(held) + assert capsys.readouterr().out == ( + f"Job '{call.name}' finished with status: done\n" + " The data owner's output policy held the outputs back.\n" + " The data owner can still share them with you later.\n" + ) + + +def _policy_entry(kind: str) -> list[FileEntry]: + return [FileEntry(relative_path=f"policies/{kind}/run.sh", hash="sha256:0")] + + +def test_api_table_shows_policies(tmp_path): + definitions = { + "plain": ApiDefinition(), + "checked": ApiDefinition(input_policy=_policy_entry("input")), + "filtered": ApiDefinition(output_policy=_policy_entry("output")), + "both": ApiDefinition( + input_policy=_policy_entry("input"), + output_policy=_policy_entry("output"), + ), + } + apis = [ + Api(name, "do@test.org", tmp_path, definition, client=None) + for name, definition in definitions.items() + ] + + lines = api_collection_repr_str(apis).splitlines()[1:] + assert [line.split(" | ")[1] for line in lines] == [ + "policies: -", + "policies: input", + "policies: output", + "policies: input, output", + ] + html = api_collection_repr_html(apis) + for policies in ("-", "input", "output", "input, output"): + assert f'{policies}' in html diff --git a/tests/unit/syft_bg/test_api_result.py b/tests/unit/syft_bg/test_api_result.py new file mode 100644 index 00000000000..1d472d6a3d9 --- /dev/null +++ b/tests/unit/syft_bg/test_api_result.py @@ -0,0 +1,43 @@ +"""What ApiResult shows the DO: an api's arguments, and a cleared state.""" + +from syft_bg.api.api import set_policies +from syft_bg.api.results import ApiResult +from syft_rds.apis import ApiArg, ApiDefinition + +from tests.unit.syft_bg.test_create_api import _create, _patched_paths, _write_project + +ARGS = [ + {"name": "dataset", "type": "str", "default": "adult"}, + {"name": "n", "type": "int", "required": True}, +] +STATE_CLEARED = "state: cleared (pass reset_state=False to keep it)" + + +def test_create_api_lists_args(temp_dir): + with _patched_paths(temp_dir): + result = _create(_write_project(temp_dir), allow_any_peer=True, args=ARGS) + + assert result.args == ["dataset: str = 'adult'", "n: int"] + assert " args:\n - dataset: str = 'adult'\n - n: int\n" in repr(result) + assert not result.state_cleared and STATE_CLEARED not in repr(result) + + +def test_set_policies_says_when_it_cleared_state(temp_dir): + policy = temp_dir / "policy.py" + policy.write_text("pass\n") + with _patched_paths(temp_dir): + _create(_write_project(temp_dir), allow_any_peer=True, args=ARGS) + cleared = set_policies("main", input_policy=policy) + kept = set_policies("main", output_policy=policy, reset_state=False) + + assert cleared.state_cleared and STATE_CLEARED in repr(cleared) + assert not kept.state_cleared and STATE_CLEARED not in repr(kept) + assert kept.args == ["dataset: str = 'adult'", "n: int"] + + +def test_print_shows_the_summary(): + ok = ApiResult.from_api("main", ApiDefinition(args=[ApiArg(name="a", default=1)])) + failed = ApiResult(success=False, error="No policy at x.py") + + assert str(ok) == repr(ok) and str(ok).startswith("ApiResult: OK [main]") + assert str(failed) == "ApiResult: FAILED\n error: No policy at x.py" From 14e49036ba8fdd2367a11c72c0eb827b8dcd0dee Mon Sep 17 00:00:00 2001 From: atlaie Date: Fri, 13 Nov 2026 14:26:56 +0100 Subject: [PATCH 2/5] feat: say when a log is not shared with the reader job.stderr, job.stdout and the hint of a failed job's output_paths said "No stderr file found" or "Check stderr" to a reader who was never given the log. They now say it is not shared with them, and who can share it: share_job_results for a datasite job, request_stderr / request_stdout for an enclave job. A call that a policy refused points to job.policy_error, since the log may not exist. The datasite owner, who keeps every log, still sees "No stderr file found". Messages only; no behaviour change. Co-Authored-By: Claude Opus 5.5 --- .../src/syft_enclaves/enclave_job_info.py | 5 ++++ .../tests/test_read_permissions.py | 22 +++++++++++++++ packages/syft-job/src/syft_job/job.py | 28 +++++++++++++++++-- packages/syft-job/src/syft_job/job_repr.py | 4 +-- packages/syft-job/src/syft_job/job_stdout.py | 5 ++-- packages/syft-job/tests/test_policies.py | 24 ++++++++++++++++ packages/syft-rds/tests/test_api_policies.py | 5 ++++ 7 files changed, 87 insertions(+), 6 deletions(-) diff --git a/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py b/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py index 3b6c586d6ca..166b6c94338 100644 --- a/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py +++ b/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py @@ -313,6 +313,11 @@ def update_read_permissions( self._save_own_approval(approval) return approved + def _log_release_hint(self, log_file: str) -> str: + """The data owners release a log by requesting it, see ``request_log``.""" + method = "request_stderr" if log_file == "stderr.txt" else "request_stdout" + return f"The data owners can release it with {method}." + def request_log( self, log_file: str, diff --git a/packages/syft-enclave/tests/test_read_permissions.py b/packages/syft-enclave/tests/test_read_permissions.py index 413f05721d6..fbb318315f6 100644 --- a/packages/syft-enclave/tests/test_read_permissions.py +++ b/packages/syft-enclave/tests/test_read_permissions.py @@ -813,6 +813,28 @@ def test_one_owner_requesting_log_shares_nothing(): assert not has_file(ds, "stderr.txt") +def test_unshared_log_points_to_log_requests(capsys): + enclave, do1, do2, ds = run_crash_sharing_nothing() + + job = ds.jobs["j"] + not_shared = ( + "stderr.txt is not shared with you. " + "The data owners can release it with request_stderr." + ) + assert str(job.stderr) == not_shared + assert not_shared in job.stderr._repr_html_() + assert str(job.stdout) == ( + "stdout.txt is not shared with you. " + "The data owners can release it with request_stdout." + ) + capsys.readouterr() + assert job.output_paths == [] + out = capsys.readouterr().out + assert not_shared in out and "Check stderr" not in out + # The enclave ran the job, so it has the log. + assert "ValueError" in str(enclave.jobs["j"].stderr) + + def test_log_request_defaults_to_data_owners(): enclave, do1, do2, ds = run_crash_sharing_nothing() for do in (do1, do2): diff --git a/packages/syft-job/src/syft_job/job.py b/packages/syft-job/src/syft_job/job.py index 2c7a194c64a..b25651b32c4 100644 --- a/packages/syft-job/src/syft_job/job.py +++ b/packages/syft-job/src/syft_job/job.py @@ -241,9 +241,12 @@ def _list_output_files() -> List[Path]: if policy_error: print(f" The data owner's policy refused the call: {policy_error}") hint = "The reason is in job.policy_error." - else: + elif self._log_path("stderr.txt").exists(): hint = "Check stderr for details: job.stderr" - print(f" Returning {len(partial)} partial output file(s). {hint}") + else: + hint = self._missing_log_message("stderr.txt") + print(f" Returning {len(partial)} partial output file(s).") + print(f" {hint}") return partial if status != JobStatus.DONE: @@ -277,6 +280,27 @@ def _log_path(self, log_file: str) -> Path: """Where the viewers read ``log_file`` ("stdout.txt" or "stderr.txt").""" return self.job_review_path / log_file + def _missing_log_message(self, log_file: str) -> str: + """What to tell a reader who has no ``log_file`` of this finished job. + + The datasite owner keeps every log the job wrote. Anyone else reads a + log only once it is shared with them. + """ + if self.current_user_email == self.datasite_owner_email: + return f"No {Path(log_file).stem} file found" + if self.policy_error: + # The policy may have refused the call before it ran, so the log + # may not exist. + return ( + f"{log_file} is not shared with you: the data owner's policy " + "refused the call. The reason is in job.policy_error." + ) + return f"{log_file} is not shared with you. {self._log_release_hint(log_file)}" + + def _log_release_hint(self, log_file: str) -> str: + """Who can share ``log_file`` with a reader who does not have it.""" + return "The data owner can share it with share_job_results." + @property def files(self) -> List[Path]: """Get list of relevant files across both inbox and review.""" diff --git a/packages/syft-job/src/syft_job/job_repr.py b/packages/syft-job/src/syft_job/job_repr.py index 341a47443c7..4b892b4c1fd 100644 --- a/packages/syft-job/src/syft_job/job_repr.py +++ b/packages/syft-job/src/syft_job/job_repr.py @@ -65,7 +65,7 @@ def __str__(self) -> str: stderr_file = self.job_info._log_path("stderr.txt") if not stderr_file.exists(): - return "No stderr file found" + return self.job_info._missing_log_message("stderr.txt") try: with open(stderr_file, "r") as f: @@ -94,7 +94,7 @@ def _repr_html_(self) -> str: stderr_file = self.job_info._log_path("stderr.txt") if not stderr_file.exists(): - error_msg = "No stderr file found" + error_msg = escape(self.job_info._missing_log_message("stderr.txt")) else: try: with open(stderr_file, "r") as f: diff --git a/packages/syft-job/src/syft_job/job_stdout.py b/packages/syft-job/src/syft_job/job_stdout.py index 4a79f3a09c4..85287a7e22b 100644 --- a/packages/syft-job/src/syft_job/job_stdout.py +++ b/packages/syft-job/src/syft_job/job_stdout.py @@ -1,6 +1,7 @@ from __future__ import annotations import re +from html import escape from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -70,7 +71,7 @@ def __str__(self) -> str: stdout_file = self.job_info._log_path("stdout.txt") if not stdout_file.exists(): - return "No stdout file found" + return self.job_info._missing_log_message("stdout.txt") try: with open(stdout_file, "r") as f: @@ -100,7 +101,7 @@ def _repr_html_(self) -> str: stdout_file = self.job_info._log_path("stdout.txt") if not stdout_file.exists(): - error_msg = "No stdout file found" + error_msg = escape(self.job_info._missing_log_message("stdout.txt")) else: try: with open(stdout_file, "r") as f: diff --git a/packages/syft-job/tests/test_policies.py b/packages/syft-job/tests/test_policies.py index e3925a901ca..759209bf7d8 100644 --- a/packages/syft-job/tests/test_policies.py +++ b/packages/syft-job/tests/test_policies.py @@ -291,6 +291,30 @@ def test_timed_out_api_call_shares_nothing(env): assert not env.reads(DS_EMAIL, "call.job", "returncode.txt") +def test_unshared_log_says_so(env, capsys): + """A reader without a log is told it is not shared, not that none exists.""" + job = env.call("echo private; exit 3") + assert not env.reads(DS_EMAIL, "call.job", "stderr.txt") + # The DS and the DO share one SyftBox here: the DS would not have the logs. + for log_file in ("stdout.txt", "stderr.txt"): + (job.job_review_path / log_file).unlink() + + not_shared = ( + "stderr.txt is not shared with you. " + "The data owner can share it with share_job_results." + ) + ds_job = _ds_job(env) + assert str(ds_job.stderr) == not_shared + assert not_shared in ds_job.stderr._repr_html_() + assert str(ds_job.stdout).startswith("stdout.txt is not shared with you.") + capsys.readouterr() + ds_job.output_paths + out = capsys.readouterr().out + assert not_shared in out and "Check stderr" not in out + # The data owner keeps every log, so a missing one was never written. + assert str(job.stderr) == "No stderr file found" + + def test_output_policy_with_bad_read_permissions_denies(env): env.apis.output_code = _read_permissions_policy(["not", "a", "dict"]) diff --git a/packages/syft-rds/tests/test_api_policies.py b/packages/syft-rds/tests/test_api_policies.py index 676552f507b..1c22294bee9 100644 --- a/packages/syft-rds/tests/test_api_policies.py +++ b/packages/syft-rds/tests/test_api_policies.py @@ -140,6 +140,11 @@ def test_api_policies_allow_block_and_show(capsys): blocked = _ds_job(ds_manager, large.name) assert blocked.status == "failed" assert blocked.policy_error == "ValueError: Sum too large to share" + # A refused call shares no log; the DS is sent to the policy's reason. + assert str(blocked.stderr) == ( + "stderr.txt is not shared with you: the data owner's policy " + "refused the call. The reason is in job.policy_error." + ) capsys.readouterr() assert blocked.output_paths == [] # The DS is sent to the policy's reason, not to a stderr they don't get. From 2edaf963bcaec5356ef7a716e19cfcdf6478d723 Mon Sep 17 00:00:00 2001 From: Koen van der Veen <7250009+koenvanderveen@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:53:31 +0100 Subject: [PATCH 3/5] revert: keep JobInfo.output_paths messages as on dev output_paths is a user-facing API that is also used for chaining, so it should not print much. The new branches also mixed low-level checks into it. Drop the test checks on what it prints. --- .../tests/test_read_permissions.py | 6 +----- packages/syft-job/src/syft_job/job.py | 20 +++++-------------- packages/syft-job/tests/test_policies.py | 6 +----- packages/syft-rds/tests/test_api_policies.py | 17 ++-------------- 4 files changed, 9 insertions(+), 40 deletions(-) diff --git a/packages/syft-enclave/tests/test_read_permissions.py b/packages/syft-enclave/tests/test_read_permissions.py index fbb318315f6..fcb79f2d6d4 100644 --- a/packages/syft-enclave/tests/test_read_permissions.py +++ b/packages/syft-enclave/tests/test_read_permissions.py @@ -813,7 +813,7 @@ def test_one_owner_requesting_log_shares_nothing(): assert not has_file(ds, "stderr.txt") -def test_unshared_log_points_to_log_requests(capsys): +def test_unshared_log_points_to_log_requests(): enclave, do1, do2, ds = run_crash_sharing_nothing() job = ds.jobs["j"] @@ -827,10 +827,6 @@ def test_unshared_log_points_to_log_requests(capsys): "stdout.txt is not shared with you. " "The data owners can release it with request_stdout." ) - capsys.readouterr() - assert job.output_paths == [] - out = capsys.readouterr().out - assert not_shared in out and "Check stderr" not in out # The enclave ran the job, so it has the log. assert "ValueError" in str(enclave.jobs["j"].stderr) diff --git a/packages/syft-job/src/syft_job/job.py b/packages/syft-job/src/syft_job/job.py index b25651b32c4..a0f511ac072 100644 --- a/packages/syft-job/src/syft_job/job.py +++ b/packages/syft-job/src/syft_job/job.py @@ -237,16 +237,10 @@ def _list_output_files() -> List[Path]: if status == JobStatus.FAILED: partial = _list_output_files() print(f"❌ Job '{self.name}' failed (status: {self.status}).") - policy_error = self.policy_error - if policy_error: - print(f" The data owner's policy refused the call: {policy_error}") - hint = "The reason is in job.policy_error." - elif self._log_path("stderr.txt").exists(): - hint = "Check stderr for details: job.stderr" - else: - hint = self._missing_log_message("stderr.txt") - print(f" Returning {len(partial)} partial output file(s).") - print(f" {hint}") + print( + f" Returning {len(partial)} partial output file(s). " + "Check stderr for details: job.stderr" + ) return partial if status != JobStatus.DONE: @@ -257,11 +251,7 @@ def _list_output_files() -> List[Path]: output_files = _list_output_files() if not output_files: print(f"⚠️ Job '{self.name}' is done but no output files were found.") - if self.outputs_withheld: - print(" The data owner's output policy held the outputs back.") - print(" The data owner can still share them with you later.") - else: - print(" The job script may not have written to the outputs/ folder.") + print(" The job script may not have written to the outputs/ folder.") return [] return output_files diff --git a/packages/syft-job/tests/test_policies.py b/packages/syft-job/tests/test_policies.py index 759209bf7d8..8635b9133a0 100644 --- a/packages/syft-job/tests/test_policies.py +++ b/packages/syft-job/tests/test_policies.py @@ -291,7 +291,7 @@ def test_timed_out_api_call_shares_nothing(env): assert not env.reads(DS_EMAIL, "call.job", "returncode.txt") -def test_unshared_log_says_so(env, capsys): +def test_unshared_log_says_so(env): """A reader without a log is told it is not shared, not that none exists.""" job = env.call("echo private; exit 3") assert not env.reads(DS_EMAIL, "call.job", "stderr.txt") @@ -307,10 +307,6 @@ def test_unshared_log_says_so(env, capsys): assert str(ds_job.stderr) == not_shared assert not_shared in ds_job.stderr._repr_html_() assert str(ds_job.stdout).startswith("stdout.txt is not shared with you.") - capsys.readouterr() - ds_job.output_paths - out = capsys.readouterr().out - assert not_shared in out and "Check stderr" not in out # The data owner keeps every log, so a missing one was never written. assert str(job.stderr) == "No stderr file found" diff --git a/packages/syft-rds/tests/test_api_policies.py b/packages/syft-rds/tests/test_api_policies.py index 1c22294bee9..d3b612dd02f 100644 --- a/packages/syft-rds/tests/test_api_policies.py +++ b/packages/syft-rds/tests/test_api_policies.py @@ -145,15 +145,8 @@ def test_api_policies_allow_block_and_show(capsys): "stderr.txt is not shared with you: the data owner's policy " "refused the call. The reason is in job.policy_error." ) - capsys.readouterr() assert blocked.output_paths == [] - # The DS is sent to the policy's reason, not to a stderr they don't get. - out = capsys.readouterr().out - assert ( - "The data owner's policy refused the call: " - "ValueError: Sum too large to share" in out - ) - assert "job.policy_error" in out and "job.stderr" not in out + capsys.readouterr() _print_call_result(blocked) assert capsys.readouterr().out == ( f"Job '{large.name}' finished with status: failed\n" @@ -202,14 +195,8 @@ def test_held_back_outputs_point_to_the_policy(capsys): held = _ds_job(ds_manager, call.name) assert held.status == "done" and held.outputs_withheld - capsys.readouterr() assert held.output_paths == [] - # The DS is told the policy held the outputs back, not that the script - # wrote none. - out = capsys.readouterr().out - assert "The data owner's output policy held the outputs back." in out - assert "The data owner can still share them with you later." in out - assert "may not have written" not in out + capsys.readouterr() _print_call_result(held) assert capsys.readouterr().out == ( f"Job '{call.name}' finished with status: done\n" From 1e2014a1e825aa11b74caa71123cadd639efd88b Mon Sep 17 00:00:00 2001 From: Koen van der Veen <7250009+koenvanderveen@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:15:41 +0100 Subject: [PATCH 4/5] test: split the api policies test into one test per flow test_api_policies_allow_block_and_show checked the api view, the call as a request, the output policy and the rate limit in one run, with the rate limit relying on the earlier call. Each is now its own test on a fresh api from the new _adder_api() helper, which test_held_back_outputs_point_to_the_policy also uses. Variables say what they hold (blocked_job, large_call). --- packages/syft-rds/tests/test_api_policies.py | 165 ++++++++++--------- 1 file changed, 91 insertions(+), 74 deletions(-) diff --git a/packages/syft-rds/tests/test_api_policies.py b/packages/syft-rds/tests/test_api_policies.py index d3b612dd02f..44e92558e57 100644 --- a/packages/syft-rds/tests/test_api_policies.py +++ b/packages/syft-rds/tests/test_api_policies.py @@ -5,9 +5,11 @@ from contextlib import contextmanager from dataclasses import replace from pathlib import Path +from typing import Any, NamedTuple from unittest.mock import patch from syft_bg.api import create_api_from_job +from syft_bg.api.results import ApiResult from syft_bg.approve.handlers.job import ApprovedJobHandler from syft_bg.common.config import get_default_paths from syft_rds import SyftRDSClient @@ -101,103 +103,118 @@ def _ds_job(ds_manager, name: str): return next(j for j in ds_manager.jobs if j.name == name) -def test_api_policies_allow_block_and_show(capsys): +class _ApiSetup(NamedTuple): + ds_manager: SyftRDSClient + do_manager: SyftRDSClient + job: Any # the job the api was built from + api_result: ApiResult + config_path: Path # the syft-bg config the approve service reads + + +@contextmanager +def _adder_api(input_policy: str | None = None, output_policy: str | None = None): + """Pair a DS and a DO, and turn an adder job into an api with these policies.""" ds_manager, do_manager = SyftRDSClient.pair_with_mock_drive_service_connection( use_in_memory_cache=False, sync_automatically=False, ) job = _submit_adder_job(ds_manager, do_manager, {"a": 1, "b": 2}) - with _temp_config_paths() as (paths, tmp): - result = create_api_from_job( - job, - input_policy=_write(tmp / "rate_limit.py", RATE_LIMIT_POLICY), - output_policy=_write(tmp / "block_large.py", BLOCK_LARGE_SUM_POLICY), + input_path = _write(tmp / "input.py", input_policy) if input_policy else None + output_path = ( + _write(tmp / "output.py", output_policy) if output_policy else None ) - assert result.success and result.policies == ["input", "output"] - + api_result = create_api_from_job( + job, input_policy=input_path, output_policy=output_path + ) + assert api_result.success do_manager.sync() ds_manager.sync() - # The api table says which policies an api has. - assert "client.api.adder(a, b) | policies: input, output" in str(ds_manager.api) - table = ds_manager.api._repr_html_() - assert 'Policies' in table - assert 'input, output' in table - api = ds_manager.api.adder + yield _ApiSetup(ds_manager, do_manager, job, api_result, paths.config) + + +def test_api_view_shows_policy_source(): + with _adder_api(RATE_LIMIT_POLICY, BLOCK_LARGE_SUM_POLICY) as setup: + assert setup.api_result.policies == ["input", "output"] + api = setup.ds_manager.api.adder + # The DS sees each policy's source code, which contains these error texts. assert "Rate limit reached" in repr(api) assert "Sum too large to share" in api._repr_html_() - # A call is a request: it carries the params, not the api's code. The - # DO's client turns it into an approved job, which the approve service - # runs. The job the api was built from is a whole job, which nothing - # approves. A call over 100 passes the input policy and is blocked on - # output. - large = api(100, b=1, block=False) - assert large.job is None - code_files = sorted(p.name for p in (large.request_path / "code").iterdir()) - assert code_files == ["params.json"] - assert _run_calls(do_manager, paths.config) == {large.name} - blocked = _ds_job(ds_manager, large.name) - assert blocked.status == "failed" - assert blocked.policy_error == "ValueError: Sum too large to share" - # A refused call shares no log; the DS is sent to the policy's reason. - assert str(blocked.stderr) == ( - "stderr.txt is not shared with you: the data owner's policy " - "refused the call. The reason is in job.policy_error." - ) - assert blocked.output_paths == [] - capsys.readouterr() - _print_call_result(blocked) - assert capsys.readouterr().out == ( - f"Job '{large.name}' finished with status: failed\n" - " The data owner's policy refused the call: " - "ValueError: Sum too large to share\n" - ) - # The rate limit of one call is used up. - second = api(1, b=2, block=False) - _run_calls(do_manager, paths.config) - limited = _ds_job(ds_manager, second.name) - assert limited.status == "failed" - assert limited.policy_error == "ValueError: Rate limit reached: 1 call" - capsys.readouterr() - _print_call_result(limited) - assert ( - "refused the call: ValueError: Rate limit reached: 1 call" - in capsys.readouterr().out - ) +def test_api_call_runs_as_request(): + with _adder_api(RATE_LIMIT_POLICY, BLOCK_LARGE_SUM_POLICY) as setup: + # A call is a request: it carries the params, not the api's code. + call = setup.ds_manager.api.adder(1, b=2, block=False) + assert call.job is None + code_files = sorted(p.name for p in (call.request_path / "code").iterdir()) + assert code_files == ["params.json"] + # The DO's client turns the call into an approved job, which the approve + # service runs. Nothing approves the job the api was built from. + assert _run_calls(setup.do_manager, setup.config_path) == {call.name} + do_jobs = {j.name: j for j in setup.do_manager.jobs} + assert do_jobs[setup.job.name].status == "pending" # The DO's view of a call shows the api and its policies. - do_job = next(j for j in do_manager.jobs if j.name == large.name) + do_job = do_jobs[call.name] assert do_job.api_name == "adder" html = do_job._repr_html_() - assert "adder" in html and "Input policy" in html and "Output policy" in html - original = next(j for j in do_manager.jobs if j.name == job.name) - assert original.status == "pending" + assert "Input policy" in html and "Output policy" in html -def test_held_back_outputs_point_to_the_policy(capsys): - ds_manager, do_manager = SyftRDSClient.pair_with_mock_drive_service_connection( - use_in_memory_cache=False, - sync_automatically=False, +def test_output_policy_refuses_large_sum(capsys): + with _adder_api(output_policy=BLOCK_LARGE_SUM_POLICY) as setup: + large_call = setup.ds_manager.api.adder(100, b=1, block=False) + _run_calls(setup.do_manager, setup.config_path) + blocked_job = _ds_job(setup.ds_manager, large_call.name) + + assert blocked_job.status == "failed" + assert blocked_job.policy_error == "ValueError: Sum too large to share" + # A refused call shares no log; the DS is sent to the policy's reason. + assert str(blocked_job.stderr) == ( + "stderr.txt is not shared with you: the data owner's policy " + "refused the call. The reason is in job.policy_error." + ) + assert blocked_job.output_paths == [] + capsys.readouterr() + _print_call_result(blocked_job) + assert capsys.readouterr().out == ( + f"Job '{large_call.name}' finished with status: failed\n" + " The data owner's policy refused the call: " + "ValueError: Sum too large to share\n" ) - job = _submit_adder_job(ds_manager, do_manager, {"a": 1, "b": 2}) - with _temp_config_paths() as (paths, tmp): - result = create_api_from_job( - job, output_policy=_write(tmp / "hold_back.py", HOLD_BACK_POLICY) - ) - assert result.success - do_manager.sync() - ds_manager.sync() - call = ds_manager.api.adder(1, b=2, block=False) - _run_calls(do_manager, paths.config) - held = _ds_job(ds_manager, call.name) - assert held.status == "done" and held.outputs_withheld - assert held.output_paths == [] +def test_input_policy_refuses_call_over_rate_limit(capsys): + with _adder_api(input_policy=RATE_LIMIT_POLICY) as setup: + first_call = setup.ds_manager.api.adder(1, b=2, block=False) + _run_calls(setup.do_manager, setup.config_path) + assert _ds_job(setup.ds_manager, first_call.name).status == "done" + # The first call used up the rate limit of one call. + second_call = setup.ds_manager.api.adder(1, b=2, block=False) + _run_calls(setup.do_manager, setup.config_path) + limited_job = _ds_job(setup.ds_manager, second_call.name) + + assert limited_job.status == "failed" + assert limited_job.policy_error == "ValueError: Rate limit reached: 1 call" + capsys.readouterr() + _print_call_result(limited_job) + assert ( + "refused the call: ValueError: Rate limit reached: 1 call" + in capsys.readouterr().out + ) + + +def test_held_back_outputs_point_to_the_policy(capsys): + with _adder_api(output_policy=HOLD_BACK_POLICY) as setup: + call = setup.ds_manager.api.adder(1, b=2, block=False) + _run_calls(setup.do_manager, setup.config_path) + held_job = _ds_job(setup.ds_manager, call.name) + + assert held_job.status == "done" and held_job.outputs_withheld + assert held_job.output_paths == [] capsys.readouterr() - _print_call_result(held) + _print_call_result(held_job) assert capsys.readouterr().out == ( f"Job '{call.name}' finished with status: done\n" " The data owner's output policy held the outputs back.\n" From 2fe105f122c187302b1840c260dacdc4123684ab Mon Sep 17 00:00:00 2001 From: Koen van der Veen <7250009+koenvanderveen@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:19:28 +0100 Subject: [PATCH 5/5] test: name tests and variables after what they check and hold Drop filler words from test names and give vague names a noun, e.g. test_print_shows_the_summary -> test_api_result_str_matches_repr and ok -> ok_result. --- .../tests/test_read_permissions.py | 6 ++-- packages/syft-job/tests/test_policies.py | 12 ++++---- packages/syft-rds/tests/test_api_policies.py | 2 +- tests/unit/syft_bg/test_api_result.py | 30 +++++++++++-------- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/syft-enclave/tests/test_read_permissions.py b/packages/syft-enclave/tests/test_read_permissions.py index fcb79f2d6d4..f0b55020594 100644 --- a/packages/syft-enclave/tests/test_read_permissions.py +++ b/packages/syft-enclave/tests/test_read_permissions.py @@ -817,12 +817,12 @@ def test_unshared_log_points_to_log_requests(): enclave, do1, do2, ds = run_crash_sharing_nothing() job = ds.jobs["j"] - not_shared = ( + not_shared_message = ( "stderr.txt is not shared with you. " "The data owners can release it with request_stderr." ) - assert str(job.stderr) == not_shared - assert not_shared in job.stderr._repr_html_() + assert str(job.stderr) == not_shared_message + assert not_shared_message in job.stderr._repr_html_() assert str(job.stdout) == ( "stdout.txt is not shared with you. " "The data owners can release it with request_stdout." diff --git a/packages/syft-job/tests/test_policies.py b/packages/syft-job/tests/test_policies.py index 8635b9133a0..e1d1db9ec21 100644 --- a/packages/syft-job/tests/test_policies.py +++ b/packages/syft-job/tests/test_policies.py @@ -291,7 +291,7 @@ def test_timed_out_api_call_shares_nothing(env): assert not env.reads(DS_EMAIL, "call.job", "returncode.txt") -def test_unshared_log_says_so(env): +def test_unshared_log_says_not_shared(env): """A reader without a log is told it is not shared, not that none exists.""" job = env.call("echo private; exit 3") assert not env.reads(DS_EMAIL, "call.job", "stderr.txt") @@ -299,13 +299,13 @@ def test_unshared_log_says_so(env): for log_file in ("stdout.txt", "stderr.txt"): (job.job_review_path / log_file).unlink() - not_shared = ( + not_shared_message = ( "stderr.txt is not shared with you. " "The data owner can share it with share_job_results." ) ds_job = _ds_job(env) - assert str(ds_job.stderr) == not_shared - assert not_shared in ds_job.stderr._repr_html_() + assert str(ds_job.stderr) == not_shared_message + assert not_shared_message in ds_job.stderr._repr_html_() assert str(ds_job.stdout).startswith("stdout.txt is not shared with you.") # The data owner keeps every log, so a missing one was never written. assert str(job.stderr) == "No stderr file found" @@ -376,8 +376,8 @@ def test_job_view_shows_params_escaped(env): html = env.do_job("call.job")._repr_html_() assert "

Parameters

" in html - pretty = '{\n "word": "privacy",\n "n": 3\n}' - assert escape(pretty) in html and "privacy" not in html + pretty_params = '{\n "word": "privacy",\n "n": 3\n}' + assert escape(pretty_params) in html and "privacy" not in html # A job without code/params.json has no such section. assert "

Parameters

" not in env.do_job("plain.job")._repr_html_() diff --git a/packages/syft-rds/tests/test_api_policies.py b/packages/syft-rds/tests/test_api_policies.py index 44e92558e57..3f9d50e1ab9 100644 --- a/packages/syft-rds/tests/test_api_policies.py +++ b/packages/syft-rds/tests/test_api_policies.py @@ -205,7 +205,7 @@ def test_input_policy_refuses_call_over_rate_limit(capsys): ) -def test_held_back_outputs_point_to_the_policy(capsys): +def test_held_back_outputs_point_to_policy(capsys): with _adder_api(output_policy=HOLD_BACK_POLICY) as setup: call = setup.ds_manager.api.adder(1, b=2, block=False) _run_calls(setup.do_manager, setup.config_path) diff --git a/tests/unit/syft_bg/test_api_result.py b/tests/unit/syft_bg/test_api_result.py index 1d472d6a3d9..273b47d9603 100644 --- a/tests/unit/syft_bg/test_api_result.py +++ b/tests/unit/syft_bg/test_api_result.py @@ -22,22 +22,26 @@ def test_create_api_lists_args(temp_dir): assert not result.state_cleared and STATE_CLEARED not in repr(result) -def test_set_policies_says_when_it_cleared_state(temp_dir): - policy = temp_dir / "policy.py" - policy.write_text("pass\n") +def test_set_policies_says_when_state_cleared(temp_dir): + policy_path = temp_dir / "policy.py" + policy_path.write_text("pass\n") with _patched_paths(temp_dir): _create(_write_project(temp_dir), allow_any_peer=True, args=ARGS) - cleared = set_policies("main", input_policy=policy) - kept = set_policies("main", output_policy=policy, reset_state=False) + cleared_result = set_policies("main", input_policy=policy_path) + kept_result = set_policies("main", output_policy=policy_path, reset_state=False) - assert cleared.state_cleared and STATE_CLEARED in repr(cleared) - assert not kept.state_cleared and STATE_CLEARED not in repr(kept) - assert kept.args == ["dataset: str = 'adult'", "n: int"] + assert cleared_result.state_cleared and STATE_CLEARED in repr(cleared_result) + assert not kept_result.state_cleared + assert STATE_CLEARED not in repr(kept_result) + assert kept_result.args == ["dataset: str = 'adult'", "n: int"] -def test_print_shows_the_summary(): - ok = ApiResult.from_api("main", ApiDefinition(args=[ApiArg(name="a", default=1)])) - failed = ApiResult(success=False, error="No policy at x.py") +def test_api_result_str_matches_repr(): + ok_result = ApiResult.from_api( + "main", ApiDefinition(args=[ApiArg(name="a", default=1)]) + ) + failed_result = ApiResult(success=False, error="No policy at x.py") - assert str(ok) == repr(ok) and str(ok).startswith("ApiResult: OK [main]") - assert str(failed) == "ApiResult: FAILED\n error: No policy at x.py" + assert str(ok_result) == repr(ok_result) + assert str(ok_result).startswith("ApiResult: OK [main]") + assert str(failed_result) == "ApiResult: FAILED\n error: No policy at x.py"