Skip to content

fix: add directory guard in formatUntrackedFile to prevent EISDIR crash#48

Open
stoneHee99 wants to merge 3 commits intoopenai:mainfrom
stoneHee99:fix/eisdir-untracked-directories
Open

fix: add directory guard in formatUntrackedFile to prevent EISDIR crash#48
stoneHee99 wants to merge 3 commits intoopenai:mainfrom
stoneHee99:fix/eisdir-untracked-directories

Conversation

@stoneHee99
Copy link
Copy Markdown

Summary

  • Add a stat.isDirectory() check in formatUntrackedFile() to skip directories instead of attempting to read them as files

Problem

When a repository contains untracked directories, git ls-files --others --exclude-standard includes directory entries. The formatUntrackedFile() function in scripts/lib/git.mjs attempts to read these paths with fs.readFileSync(), which throws an EISDIR: illegal operation on a directory, read error and crashes the review.

Fix

Added a directory check right after fs.statSync() in formatUntrackedFile() (plugins/codex/scripts/lib/git.mjs:139). When the path is a directory, it returns a (skipped: directory) message instead of trying to read it.

Test Plan

  • Added a regression test in tests/git.test.mjs that creates an untracked directory with a nested file, runs collectReviewContext with working-tree scope, and verifies it completes without crashing
  • All 5 git tests pass: node --test tests/git.test.mjs

Fixes #14

…penai#14)

Add a stat.isDirectory() guard before reading untracked file contents,
so working-tree reviews no longer crash when untracked directories exist.
@stoneHee99 stoneHee99 requested a review from a team March 31, 2026 06:43
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 407b3ab2c7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +80 to +81
fs.mkdirSync(path.join(cwd, "untracked-dir"));
fs.writeFileSync(path.join(cwd, "untracked-dir", "nested.js"), "// nested\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reproduce directory-entry case in the regression test

This setup does not exercise the new stat.isDirectory() branch: with git ls-files --others --exclude-standard, a normal untracked folder containing files is reported as file paths (e.g. untracked-dir/nested.js), not as a directory entry (git ls-files -h documents --directory as the flag that changes this behavior). Because the test creates untracked-dir/nested.js, it would pass even before this fix and cannot catch a regression of the original EISDIR crash path.

Useful? React with 👍 / 👎.

…y guard

Address review feedback — the previous integration test did not exercise
the isDirectory() guard because git ls-files returns individual file paths.
Export formatUntrackedFile and test it directly with a directory path.
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.

EISDIR crash in working-tree review when untracked directories exist

1 participant