Skip to content

Refuse a Local Instruction Path Whose Parent Is a File - #2429

Merged
ptr727 merged 2 commits into
developfrom
feature/local-parent-not-a-dir
Oct 6, 2026
Merged

ptr727 merged 2 commits into
developfrom
feature/local-parent-not-a-dir

Conversation

@ptr727

@ptr727 ptr727 commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Summary

This fixes the third-round Copilot finding on promotion PR #2425. read_local_instructions treated NotADirectoryError from lstat as "no local file". That error comes up when a parent component of the local instruction path is a regular file, for example an absolute XDG_CONFIG_HOME pointing at a file. The configured local text was then dropped silently. Now only a missing path counts as absent. Anything else is refused as "cannot be read", and nothing is installed.

Deliberate behavior:

  • The refusal also covers the default path when ~/.config itself is a regular file, even though nothing was configured. That is a broken home directory, so a loud refusal that names the path is preferred over silently skipping.
  • On Windows, lstat raises FileNotFoundError for a file parent, so the path still reads as absent there, and the new case skips on non-POSIX like its neighbors. I haven't confirmed this on Windows.

Refs #2423

Verification

  • python3 -m unittest test_install: 124 tests OK on 3.13, and the edge cases also pass on 3.14.
  • With the old tuple restored, the new case fails.
  • The local strict review ran one pass, as the maintainer allowed, plus a verification of the test-only skip that came out of it.

🤖 Generated with Claude Code

ptr727 and others added 2 commits October 5, 2026 18:32
lstat raises NotADirectoryError where a parent component of the local
instruction path is a regular file, such as an absolute XDG_CONFIG_HOME
pointing at one, and that was read as an absent local file, so the
configured text was dropped silently. Only a missing path is absent
now, and anything else is refused as unreadable with nothing changed.

Refs #2423

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Windows raises FileNotFoundError rather than NotADirectoryError for a path whose parent is a file, so the refusal is POSIX-only and the case skips there like its POSIX-only neighbours.

Refs #2423

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 6, 2026
Copilot AI lite review requested due to automatic review settings October 6, 2026 01:36
@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7cacbbc3-14d0-4188-91f4-5f2d1f48fda1
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.47%. Comparing base (c23a2a7) to head (a487f1e).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2429   +/-   ##
========================================
  Coverage    58.47%   58.47%           
========================================
  Files           16       16           
  Lines         8062     8062           
========================================
  Hits          4714     4714           
  Misses        3348     3348           
Flag Coverage Δ
python-3.13 58.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Windows file-parent paths may still be silently skipped, and the regression test does not exercise its documented XDG_CONFIG_HOME case.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

This PR hardens local instruction loading so invalid parent paths are not silently ignored.

Changes:

  • Treats only missing paths as absent.
  • Adds POSIX regression coverage for file-parent paths.
File Summary
host-setup/​agent-safety/​claude/​install.py Refines local path error handling.
host-setup/​agent-safety/​claude/​test_install.py Tests refusal for invalid parent paths.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ptr727
ptr727 merged commit 70dc872 into develop Oct 6, 2026
13 checks passed
@ptr727
ptr727 deleted the feature/local-parent-not-a-dir branch October 6, 2026 01:41
ptr727 added a commit that referenced this pull request Oct 6, 2026
## Summary

Promotes `develop` to `main` with four pull requests, each already
reviewed and merged into `develop`:

- [#2424](#2424) Render
the Whole Global CLAUDE.md and Back Up a Hand Edit.
- The host-safety installer now owns all of `~/.claude/CLAUDE.md`. It
renders a header, the two existing blocks, and a shared host-local file,
`agent-fleet/local.md`.
- It replaces an earlier render silently. A file edited by hand, or one
written before this change, is copied to a timestamped `.bak` first.
- `merge-and-release` step 7 now also runs this kit's `--report`, so a
release flags a stale host.
- [#2427](#2427) Render
CLAUDE.md First and Let the Real Write Be the Check, the fix for this
PR's Copilot finding.
- [#2428](#2428) Read the
Local Instruction File Only When It Is a Regular File, the fix for this
PR's previously-missed Copilot finding.
- [#2429](#2429) Refuse a
Local Instruction Path Whose Parent Is a File, the fix for this PR's
third-round Copilot finding.

On a host's next install, the existing `CLAUDE.md` is backed up and
replaced. Anything host-specific moves into the local file.

Closes #2423

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants