Skip to content

Make File.is_installed binary-safe - #1044

Merged
podkidyshev merged 1 commit into
NVIDIA:mainfrom
MaxFreedomPollard:file-is-installed-binary-safe
Sep 21, 2026
Merged

podkidyshev merged 1 commit into
NVIDIA:mainfrom
MaxFreedomPollard:file-is-installed-binary-safe

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor

Summary

Fixes #782.

  • File.is_installed compared the installed copy with the source using read_text(), which raises UnicodeDecodeError for files that are not valid UTF-8. It now compares bytes, which matches install(), where the file is copied with shutil.copyfile.
  • A file that exists with different contents was reported as "does not exist". That case now has its own message: File <installed path> differs from <src>.

The issue lists the Slurm and Kubernetes installers, but since #885 the check lives in File.is_installed, so that is the only place that needs the change.

Test Plan

  • Added test_is_installed_binary_file and test_is_installed_missing_file, and the existing content-mismatch test now checks the message. Without the fix, the binary test fails with UnicodeDecodeError and the mismatch test gets the "does not exist" message.
  • uv run --locked --extra dev pytest: 1960 passed, 5 skipped.
  • uv run --locked --extra dev pre-commit run --files on the two changed files: all hooks pass.

Additional Notes

read_text() also normalizes line endings, so two files that differed only in CRLF vs LF used to count as the same. With a byte comparison they no longer do, which seems right for checking whether the copy made by copyfile is still identical to the source.

File.is_installed compared the installed copy with the source using
read_text(), which raises UnicodeDecodeError for files that are not
valid UTF-8. install() copies bytes with shutil.copyfile, so compare
bytes as well.

Also report a content mismatch as such. Until now the message said
that the file does not exist even when it existed with different
contents.

Fixes NVIDIA#782

Signed-off-by: Max Freedom Pollard <272618364+MaxFreedomPollard@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: NVIDIA/cloudai/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: aa7ce660-ac98-4849-9600-d3d8fc8fcb47

📥 Commits

Reviewing files that changed from the base of the PR and between ea9db35 and 7348c5d.

📒 Files selected for processing (2)
  • src/cloudai/_core/installables/file.py
  • tests/core/installables/test_file.py

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.


📝 Walkthrough

Walkthrough

Changes

File installation validation

Layer / File(s) Summary
Byte-safe file validation
src/cloudai/_core/installables/file.py, tests/core/installables/test_file.py
File.is_installed now checks for missing destinations, compares source and destination contents as bytes, and reports separate missing-file and content-mismatch errors. Tests cover path-specific errors and binary files with invalid UTF-8 bytes.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: making File.is_installed safe for binary files.
Description check ✅ Passed The description directly explains the binary-safe comparison, distinct error handling, affected scope, and test coverage.
Linked Issues check ✅ Passed Issue #782 requires binary-safe file comparison, byte-based comparison, and distinct errors for missing files and content mismatches. File.is_installed uses read_bytes() for both files. It reports…
Out of Scope Changes check ✅ Passed The changes are limited to the shared File.is_installed implementation and its automated tests. These changes directly support Issue #782. No unrelated behavior or files are identified.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@podkidyshev
podkidyshev merged commit 10f0eab into NVIDIA:main Sep 21, 2026
5 checks passed
@podkidyshev

Copy link
Copy Markdown
Contributor

@MaxFreedomPollard thank you for contribution, it's a good change 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve File installation check to handle binary files and content-mismatch errors

2 participants