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 6e167b4e1c6..eb9d355b93e 100644 --- a/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py +++ b/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py @@ -324,8 +324,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. @@ -342,8 +343,19 @@ def request_log( log_request_warning(log_file, request.readers), UserWarning, stacklevel=2 ) 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 e3736cec308..adf77bb3c2f 100644 --- a/packages/syft-enclave/tests/test_read_permissions.py +++ b/packages/syft-enclave/tests/test_read_permissions.py @@ -886,3 +886,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