fix(backup): guard os.chmod on Windows where it is a no-op - #56946
fix(backup): guard os.chmod on Windows where it is a no-op#56946liuhao1024 wants to merge 1 commit into
Conversation
os.chmod(target, 0o600) silently succeeds on Windows without changing file permissions, causing test_import_restores_external_to_home_relative_ location to fail with (33206 & 511) == 384. Extract _tighten_file_permissions() helper that skips chmod on win32 (NTFS ACLs already restrict to owner/SYSTEM/Administrators). Update test assertion to be platform-aware. Fixes NousResearch#56923
Competing with #56949 (@AlexFucuson9) for the same fix (#56923). This PR skips the |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the Windows-specific mode-bit assertion; the current external restore test does assert POSIX 0600 after os.chmod at hermes_cli/backup.py:603-606, so the reported native-Windows failure remains relevant.
Problems
- The helper's
except OSError: passchanges the normal import path's established failure handling. Currenthermes_cli/backup.py:647-651lets a failed chmod reach the enclosing handler, which records an import error instead of incrementingrestored; the proposed helper suppresses that failure for POSIX too.
Suggested changes
- Keep the Windows skip, but preserve caller-specific OSError behavior: the external path may remain best-effort, while the normal secret-file path should retain its outer error reporting/accounting semantics.
Automated hermes-sweeper review.
| return | ||
| try: | ||
| os.chmod(path, 0o600) | ||
| except OSError: |
There was a problem hiding this comment.
This catch changes the normal import path's current behavior: run_import presently lets a chmod failure at the secret-file branch reach its enclosing handler, append an error, and avoid incrementing restored. Keep the Windows skip, but preserve that caller-specific failure handling rather than swallowing POSIX chmod errors here.
What does this PR do?
Fixes the backup import test failure on Windows where
os.chmod(target, 0o600)is a silent no-op. On Windows,os.chmodwith Unix permission bits succeeds without error but doesn't change anything — the file stays at default0o666permissions.Extracts a
_tighten_file_permissions()helper that skips the chmod on Windows (NTFS ACLs already restrict newly-created files to the owner / SYSTEM / Administrators), and makes the test assertion platform-aware.Related Issue
Fixes #56923
Type of Change
Changes Made
hermes_cli/backup.py: Added_tighten_file_permissions()helper that wrapsos.chmod(path, 0o600)with asys.platform == "win32"guard. Replaced both bareos.chmodcalls (line 604 and 648) with the helper.tests/hermes_cli/test_backup.py: Addedimport sysand wrapped thest_mode & 0o777 == 0o600assertion inif sys.platform != "win32":so the test passes on both POSIX and Windows.How to Test
pytest tests/hermes_cli/test_backup.py::TestMemoryProviderExternalPaths::test_import_restores_external_to_home_relative_location -xvs— should passassert (33206 & 511) == 384)pytest tests/hermes_cli/test_backup.py -q— all 145 tests should pass (verified on macOS)Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Before (Windows):
After (macOS/Linux):