Skip to content

fix: add file-based fallback to check_comfy_repo for non-git installs#401

Merged
bigcat88 merged 3 commits intomainfrom
fix/check-comfy-repo-fallback-markers
Apr 1, 2026
Merged

fix: add file-based fallback to check_comfy_repo for non-git installs#401
bigcat88 merged 3 commits intomainfrom
fix/check-comfy-repo-fallback-markers

Conversation

@bigcat88
Copy link
Copy Markdown
Contributor

Fixes #205

check_comfy_repo() only validated ComfyUI installations by matching git remote URLs against a hardcoded allowlist. This caused set-default and 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 from tuple[bool, git.Repo | None] to tuple[bool, str | None], returning the resolved path string directly instead of a repo object. All callers only used repo.working_dir anyway, so this is a straightforward simplification.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

Refactors repository detection to return resolved filesystem paths (str) instead of git.Repo objects and adds marker-file-based detection for non-git/portable ComfyUI installs. CLI callers now accept and use resolved path strings. A little rhyme: "If git won't stick, markers do the trick."

Changes

Cohort / File(s) Summary
Repository Detection & Helpers
comfy_cli/workspace_manager.py
Changed check_comfy_repo(path) return type from tuple[bool, git.Repo | None] to tuple[bool, str | None]. Added _has_comfyui_markers(path: str) -> bool and _find_comfyui_root(path: str) -> str | None. On git errors, fall back to upward search for ComfyUI marker files and return resolved root path when found. Updated git lookup to use parent/custom_nodes context.
Command Line Integration
comfy_cli/cmdline.py
Updated install and set_default flows to accept (is_comfy_installed, resolved_path) and to reassign comfy_path to resolved_path (string) when provided rather than using repo.working_dir. Preserved existing guards and error/exit behavior.
Tests
tests/comfy_cli/test_workspace_manager.py
Expanded tests to cover marker-based detection and upward-root search; adjusted mocks and expectations to return plain absolute path strings instead of MagicMock repo objects. Added helpers to create marker fixtures and tests for threshold/nearest-root behavior.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as "CLI (comfy)"
  participant WM as "workspace_manager"
  participant FS as "Filesystem"
  participant GIT as "git.Repo"

  CLI->>WM: check_comfy_repo(path)
  WM->>GIT: try git.Repo(parent_of_path)
  alt Git repo valid and ComfyUI markers exist
    GIT-->>WM: git.Repo (valid)
    WM->>FS: resolve repo.working_dir -> resolved_path
    WM-->>CLI: (True, resolved_path)
  else Git invalid or no comfy remote
    GIT--x WM: raises InvalidGitRepositoryError / no comfy remote
    WM->>FS: _find_comfyui_root(path) (walk up, check markers)
    alt markers found (threshold met)
      FS-->>WM: marker_root (absolute path)
      WM-->>CLI: (True, marker_root)
    else markers not found
      FS-->>WM: None
      WM-->>CLI: (False, None)
    end
  end
Loading
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully implements file-based fallback detection for non-git ComfyUI installs, allowing set-default and workspace commands to recognize zip downloads, portable builds, and fork installations via marker file validation.
Out of Scope Changes check ✅ Passed All changes directly support the core objective: adding marker-based detection in check_comfy_repo, updating callers in cmdline.py, and expanding test coverage. No extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/check-comfy-repo-fallback-markers
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/check-comfy-repo-fallback-markers

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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
comfy_cli/cmdline.py 40.00% 3 Missing ⚠️
comfy_cli/workspace_manager.py 89.28% 3 Missing ⚠️
@@            Coverage Diff             @@
##             main     #401      +/-   ##
==========================================
+ Coverage   75.59%   75.66%   +0.07%     
==========================================
  Files          35       35              
  Lines        4127     4143      +16     
==========================================
+ Hits         3120     3135      +15     
- Misses       1007     1008       +1     
Files with missing lines Coverage Δ
comfy_cli/cmdline.py 57.56% <40.00%> (ø)
comfy_cli/workspace_manager.py 75.00% <89.28%> (+1.74%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bigcat88 bigcat88 marked this pull request as ready for review March 30, 2026 19:01
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 30, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 | 🟡 Minor

Harden custom_nodes parent derivation to avoid empty-path git resolution.

When parent becomes "", 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 | 🟠 Major

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1528c51 and 0f5a1be.

📒 Files selected for processing (3)
  • comfy_cli/cmdline.py
  • comfy_cli/workspace_manager.py
  • tests/comfy_cli/test_workspace_manager.py

Comment thread comfy_cli/workspace_manager.py
bigcat88 added 3 commits April 1, 2026 06:12
- Add _find_comfyui_root() that walks up parent directories looking for
  ComfyUI markers, mirroring git's search_parent_directories behavior
  for non-git installs (zip downloads, forks, portable builds).
- Add comfy_api to marker list, bump threshold from 3/4 to 4/5 to
  reduce false positives.
- Add comprehensive tests for _has_comfyui_markers, _find_comfyui_root,
  check_comfy_repo fallback paths, and non-git integration scenarios.
@bigcat88 bigcat88 force-pushed the fix/check-comfy-repo-fallback-markers branch from 0f5a1be to 3d210d0 Compare April 1, 2026 07:15
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 1, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
comfy_cli/workspace_manager.py (1)

93-102: ⚠️ Potential issue | 🟡 Minor

Edge case: path starting with custom_nodes produces empty parent.

If path is a relative path like custom_nodes/MyNode, then index=0 and parts[:0] yields an empty list, making parent an empty string. Passing an empty string to git.Repo() may produce unexpected behavior (it would search from current working directory).

This is likely a rare edge case, but worth considering. The marker-based fallback might recover gracefully, but the git call could still produce confusing errors.

🛡️ Proposed defensive fix
             try:
                 index = parts.index("custom_nodes")
-                parent = os.sep.join(parts[:index])
+                parent = os.sep.join(parts[:index]) or "."
 
                 repo = git.Repo(parent, search_parent_directories=True)
🤖 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 93 - 102, If path_is_comfy_repo
is False and "custom_nodes" is at the start of a relative path (e.g.,
"custom_nodes/MyNode"), parts.index("custom_nodes") will be 0 and parent becomes
an empty string which should not be passed to git.Repo; update the block around
parts = path.split(os.sep) to guard before calling git.Repo(parent, ...): after
computing index and parent, check that parent is truthy (non-empty) and/or
os.path.exists(parent) and only then attempt git.Repo; if parent is empty or
does not exist, skip the git lookup and leave path_is_comfy_repo False (or
fallback to the existing marker-based logic). Ensure this change references the
same symbols: path, parts, index, parent, git.Repo, repo.remotes, and
constants.COMFY_ORIGIN_URL_CHOICES.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@comfy_cli/workspace_manager.py`:
- Around line 93-102: If path_is_comfy_repo is False and "custom_nodes" is at
the start of a relative path (e.g., "custom_nodes/MyNode"),
parts.index("custom_nodes") will be 0 and parent becomes an empty string which
should not be passed to git.Repo; update the block around parts =
path.split(os.sep) to guard before calling git.Repo(parent, ...): after
computing index and parent, check that parent is truthy (non-empty) and/or
os.path.exists(parent) and only then attempt git.Repo; if parent is empty or
does not exist, skip the git lookup and leave path_is_comfy_repo False (or
fallback to the existing marker-based logic). Ensure this change references the
same symbols: path, parts, index, parent, git.Repo, repo.remotes, and
constants.COMFY_ORIGIN_URL_CHOICES.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fc361d6d-abd7-4e37-a571-0136655c7589

📥 Commits

Reviewing files that changed from the base of the PR and between 0f5a1be and 3d210d0.

📒 Files selected for processing (3)
  • comfy_cli/cmdline.py
  • comfy_cli/workspace_manager.py
  • tests/comfy_cli/test_workspace_manager.py

@bigcat88 bigcat88 merged commit 19f555b into main Apr 1, 2026
15 checks passed
@bigcat88 bigcat88 deleted the fix/check-comfy-repo-fallback-markers branch April 1, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Having problem with set-default and --workspace commands

1 participant