From 4a59aa14d77842911a2c9702f509df1c4f183da3 Mon Sep 17 00:00:00 2001 From: atlaie Date: Fri, 13 Nov 2026 16:47:42 +0100 Subject: [PATCH] feat: say the length and the rule when a data owner requests a log request_stderr / request_stdout print the length asked for (n_chars) and say the enclave shares the log once every data owner makes the same request: the same readers and the same n_chars. The docstrings say so too. Messages, display and docstrings only; no behaviour change. Asana: https://app.asana.com/0/0/1220519960542215/f Co-Authored-By: Claude Opus 5.5 --- .../syft-enclave/src/syft_enclaves/client.py | 4 ++-- .../src/syft_enclaves/enclave_job_info.py | 20 ++++++++++++++---- .../tests/test_read_permissions.py | 21 +++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/packages/syft-enclave/src/syft_enclaves/client.py b/packages/syft-enclave/src/syft_enclaves/client.py index 1f30ce6ff69..1a0adf284f3 100644 --- a/packages/syft-enclave/src/syft_enclaves/client.py +++ b/packages/syft-enclave/src/syft_enclaves/client.py @@ -641,8 +641,8 @@ def request_stderr( """Ask the enclave to share the job's stderr, or only its first ``n_chars`` chars. Only a data owner can ask. The enclave shares it once every data owner - made the same request. ``readers`` None means the data owners this - enclave is configured with. + made the same request: the same readers and the same ``n_chars``. + ``readers`` None means the data owners this enclave is configured with. """ self._request_log(job, "stderr.txt", readers, n_chars) 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..af7fdaedd99 100644 --- a/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py +++ b/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py @@ -321,8 +321,9 @@ def request_log( ) -> None: """Ask the enclave to share ``log_file``, or only its first ``n_chars`` chars. - The enclave shares it once every data owner made the same request. - ``readers`` None means the data owners the enclave is configured with. + The enclave shares it once every data owner made the same request: the + same readers and the same ``n_chars``. ``readers`` None means the data + owners the enclave is configured with. Raises: PermissionError: If the caller is not a data owner of this job. @@ -337,8 +338,19 @@ def request_log( request = LogRequest(readers=readers, n_chars=n_chars) warn_on_logs_release({log_file: request.readers or []}) self._save_own_log_request(log_file, request) - who = request.readers or "the enclave's data owners" - print(f"Requested {log_file} of job '{self.name}' for {who}.") + if request.n_chars is None: + what = f"all of {log_file} (n_chars=None)" + else: + what = ( + f"the first {request.n_chars:,} characters of {log_file} " + f"(n_chars={request.n_chars})" + ) + who = ", ".join(request.readers or []) or "the enclave's data owners" + print(f"Requested {what} of job '{self.name}' for {who}.") + print( + " The enclave shares it once every data owner makes the same " + "request: the same readers and the same n_chars." + ) def _save_own_log_request(self, log_file: str, request: LogRequest) -> None: """Replace this party's request for ``log_file``, and push the file.""" diff --git a/packages/syft-enclave/tests/test_read_permissions.py b/packages/syft-enclave/tests/test_read_permissions.py index 413f05721d6..d9459e442e4 100644 --- a/packages/syft-enclave/tests/test_read_permissions.py +++ b/packages/syft-enclave/tests/test_read_permissions.py @@ -842,3 +842,24 @@ def test_submitter_cannot_request_logs(): enclave, do1, do2, ds = run_crash_sharing_nothing() with pytest.raises(PermissionError, match="Only a data owner"): ds.request_stderr(ds.jobs["j"]) + + +def test_log_request_says_length_and_rule(capsys): + enclave, do1, do2, ds = run_crash_sharing_nothing() + capsys.readouterr() + + with pytest.warns(UserWarning): + do1.request_stderr(do1.jobs["j"], readers=ds.email, n_chars=1000) + assert ( + "Requested the first 1,000 characters of stderr.txt (n_chars=1000) " + f"of job 'j' for {ds.email}.\n" + " The enclave shares it once every data owner makes the same " + "request: the same readers and the same n_chars.\n" + ) in capsys.readouterr().out + + with pytest.warns(UserWarning): + do1.request_stdout(do1.jobs["j"]) + assert ( + "Requested all of stdout.txt (n_chars=None) of job 'j' for the " + "enclave's data owners." + ) in capsys.readouterr().out