fix: add file-based fallback to check_comfy_repo for non-git installs#401
fix: add file-based fallback to check_comfy_repo for non-git installs#401
Conversation
📝 WalkthroughWalkthroughThe pull request refactors ComfyUI repository detection to return resolved filesystem paths instead of git repository objects, and introduces a fallback mechanism for non-git installations by detecting ComfyUI marker files. This enables the tool to validate and work with both git-based and portable ComfyUI installations. Changes
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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. Comment |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #401 +/- ##
=======================================
Coverage 75.00% 75.00%
=======================================
Files 34 34
Lines 4028 4033 +5
=======================================
+ Hits 3021 3025 +4
- Misses 1007 1008 +1
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
comfy_cli/workspace_manager.py (1)
79-86:⚠️ Potential issue | 🟡 MinorHarden
custom_nodesparent derivation to avoid empty-path git resolution.When
parentbecomes"",git.Repo(parent, ...)resolves from current working directory, which can produce false positives.🔧 Proposed guard
if not path_is_comfy_repo and "custom_nodes" in path: parts = path.split(os.sep) try: index = parts.index("custom_nodes") - parent = os.sep.join(parts[:index]) + parent = os.sep.join(parts[:index]) or os.sep repo = git.Repo(parent, search_parent_directories=True) path_is_comfy_repo = any(remote.url in constants.COMFY_ORIGIN_URL_CHOICES for remote in repo.remotes) except ValueError: pass🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@comfy_cli/workspace_manager.py` around lines 79 - 86, The parent path derived for "custom_nodes" can be empty which lets git.Repo("") resolve from CWD and give false positives; before calling git.Repo(parent, search_parent_directories=True) in workspace_manager (where path, parts, index, parent, repo and path_is_comfy_repo are used), add a guard to skip git.Repo when parent is empty or not an absolute/valid directory (e.g., check if parent and os.path.isdir(parent) or normalize with os.path.abspath(parent) and only then construct repo and evaluate remotes), otherwise leave path_is_comfy_repo False.tests/comfy_cli/test_workspace_manager.py (1)
213-224: 🛠️ Refactor suggestion | 🟠 MajorAdd regression tests for marker fallback paths (non-git root + non-git subdir).
This PR’s core behavior is marker fallback, but the suite still mostly mocks
check_comfy_repo. Add direct tests that exercise real filesystem markers so future changes don’t quietly break this fix. A tiny test now avoids a big oops later.🧪 Suggested test additions
+def test_check_comfy_repo_non_git_marker_root(tmp_path): + from comfy_cli.workspace_manager import check_comfy_repo + root = tmp_path / "ComfyUI" + root.mkdir() + (root / "main.py").write_text("#") + (root / "nodes.py").write_text("#") + (root / "comfy").mkdir() + ok, resolved = check_comfy_repo(str(root)) + assert ok is True + assert resolved == str(root) + +def test_check_comfy_repo_non_git_marker_subdir(tmp_path): + from comfy_cli.workspace_manager import check_comfy_repo + root = tmp_path / "ComfyUI" + sub = root / "custom_nodes" / "x" + sub.mkdir(parents=True) + (root / "main.py").write_text("#") + (root / "nodes.py").write_text("#") + (root / "comfy_extras").mkdir() + ok, resolved = check_comfy_repo(str(sub)) + assert ok is True + assert resolved == str(root)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/comfy_cli/test_workspace_manager.py` around lines 213 - 224, Add regression tests that exercise real filesystem marker fallback instead of mocking check_comfy_repo: create a temporary directory structure with a marker file (e.g., a Comfy marker used by workspace_manager like ".comfy-repo" or the repository marker your code checks), create a subdirectory (non-git subdir), monkeypatch os.getcwd to the subdir, instantiate the manager with _make_manager(use_here=None) and _mock_config as needed, call mgr.get_workspace_path() without patching check_comfy_repo/_paths_match, and assert the returned path matches the marker-rooted resolved path; reference helpers _make_manager, get_workspace_path, and check_comfy_repo/_paths_match to locate where to integrate the new tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@comfy_cli/workspace_manager.py`:
- Around line 97-103: The fallback detection only checks the provided absolute
path (abs_path) for ComfyUI markers via _has_comfyui_markers, so paths that are
inside a ComfyUI tree (e.g. custom_nodes/...) are missed; update the logic to
walk up parent directories from abs_path until filesystem root, calling
_has_comfyui_markers on each parent and returning (True, root_path) when found
(otherwise return (False, None)); reference the existing abs_path variable and
_has_comfyui_markers function to implement the upward traversal and return the
detected ComfyUI root.
---
Outside diff comments:
In `@comfy_cli/workspace_manager.py`:
- Around line 79-86: The parent path derived for "custom_nodes" can be empty
which lets git.Repo("") resolve from CWD and give false positives; before
calling git.Repo(parent, search_parent_directories=True) in workspace_manager
(where path, parts, index, parent, repo and path_is_comfy_repo are used), add a
guard to skip git.Repo when parent is empty or not an absolute/valid directory
(e.g., check if parent and os.path.isdir(parent) or normalize with
os.path.abspath(parent) and only then construct repo and evaluate remotes),
otherwise leave path_is_comfy_repo False.
In `@tests/comfy_cli/test_workspace_manager.py`:
- Around line 213-224: Add regression tests that exercise real filesystem marker
fallback instead of mocking check_comfy_repo: create a temporary directory
structure with a marker file (e.g., a Comfy marker used by workspace_manager
like ".comfy-repo" or the repository marker your code checks), create a
subdirectory (non-git subdir), monkeypatch os.getcwd to the subdir, instantiate
the manager with _make_manager(use_here=None) and _mock_config as needed, call
mgr.get_workspace_path() without patching check_comfy_repo/_paths_match, and
assert the returned path matches the marker-rooted resolved path; reference
helpers _make_manager, get_workspace_path, and check_comfy_repo/_paths_match to
locate where to integrate the new tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8d66d251-f2cc-4df5-9469-6de0e3d3b45b
📒 Files selected for processing (3)
comfy_cli/cmdline.pycomfy_cli/workspace_manager.pytests/comfy_cli/test_workspace_manager.py
| # Fallback: file-based detection for non-git installations (zip downloads, | ||
| # portable builds, forks with non-standard remotes, etc.) | ||
| abs_path = os.path.abspath(path) | ||
| if _has_comfyui_markers(abs_path): | ||
| return True, abs_path | ||
|
|
||
| return False, None |
There was a problem hiding this comment.
Fallback currently misses subdirectory paths in non-git installs.
Line 100 checks markers only on abs_path, so paths inside a portable/zip ComfyUI tree (for example custom_nodes/...) fail detection even though the function contract says “is (or is inside).” No root, no loot.
💡 Proposed fix (walk parents to resolve ComfyUI root)
+def _find_comfyui_root(path: str) -> str | None:
+ cur = os.path.abspath(path)
+ if not os.path.isdir(cur):
+ cur = os.path.dirname(cur)
+ while True:
+ if _has_comfyui_markers(cur):
+ return cur
+ parent = os.path.dirname(cur)
+ if parent == cur:
+ return None
+ cur = parent
+
def check_comfy_repo(path) -> tuple[bool, str | None]:
@@
- abs_path = os.path.abspath(path)
- if _has_comfyui_markers(abs_path):
- return True, abs_path
+ marker_root = _find_comfyui_root(path)
+ if marker_root is not None:
+ return True, marker_root
return False, None📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Fallback: file-based detection for non-git installations (zip downloads, | |
| # portable builds, forks with non-standard remotes, etc.) | |
| abs_path = os.path.abspath(path) | |
| if _has_comfyui_markers(abs_path): | |
| return True, abs_path | |
| return False, None | |
| def _find_comfyui_root(path: str) -> str | None: | |
| cur = os.path.abspath(path) | |
| if not os.path.isdir(cur): | |
| cur = os.path.dirname(cur) | |
| while True: | |
| if _has_comfyui_markers(cur): | |
| return cur | |
| parent = os.path.dirname(cur) | |
| if parent == cur: | |
| return None | |
| cur = parent | |
| def check_comfy_repo(path) -> tuple[bool, str | None]: | |
| # ... existing code ... | |
| # Fallback: file-based detection for non-git installations (zip downloads, | |
| # portable builds, forks with non-standard remotes, etc.) | |
| marker_root = _find_comfyui_root(path) | |
| if marker_root is not None: | |
| return True, marker_root | |
| return False, None |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@comfy_cli/workspace_manager.py` around lines 97 - 103, The fallback detection
only checks the provided absolute path (abs_path) for ComfyUI markers via
_has_comfyui_markers, so paths that are inside a ComfyUI tree (e.g.
custom_nodes/...) are missed; update the logic to walk up parent directories
from abs_path until filesystem root, calling _has_comfyui_markers on each parent
and returning (True, root_path) when found (otherwise return (False, None));
reference the existing abs_path variable and _has_comfyui_markers function to
implement the upward traversal and return the detected ComfyUI root.
Fixes #205
check_comfy_repo()only validated ComfyUI installations by matching git remote URLs against a hardcoded allowlist. This causedset-defaultand workspace detection to reject perfectly valid ComfyUI installations that were set up via zip download, the Windows portable build, or cloned from a fork/mirror with a non-listed remote URL.This adds a file-based fallback that checks for ComfyUI marker files (
main.py,comfy/,nodes.py,comfy_extras/— at least 3 of 4 must be present) when the git-based check fails. The git check still runs first, so existing behavior is preserved for standard clones.The return type of
check_comfy_repo()changes fromtuple[bool, git.Repo | None]totuple[bool, str | None], returning the resolved path string directly instead of a repo object. All callers only usedrepo.working_diranyway, so this is a straightforward simplification.