Compare commits

..

1 Commits

Author SHA1 Message Date
Dr.Lt.Data
2866193baf ● feat: Draft pip package policy management system (not yet integrated)
Add comprehensive pip dependency conflict resolution framework as draft implementation. This is self-contained and does not affect existing
ComfyUI Manager functionality.

Key components:
- pip_util.py with PipBatch class for policy-driven package management
- Lazy-loaded policy system supporting base + user overrides
- Multi-stage policy execution (uninstall → apply_first_match → apply_all_matches → restore)
- Conditional policies based on platform, installed packages, and ComfyUI version
- Comprehensive test suite covering edge cases, workflows, and platform scenarios
- Design and implementation documentation

Policy capabilities (draft):
- Package replacement (e.g., PIL → Pillow, opencv-python → opencv-contrib-python)
- Version pinning to prevent dependency conflicts
- Dependency protection during installations
- Platform-specific handling (Linux/Windows, GPU detection)
- Pre-removal and post-restoration workflows

Testing infrastructure:
- Pytest-based test suite with isolated environments
- Dependency analysis tools for conflict detection
- Coverage for policy priority, edge cases, and environment recovery

Status: Draft implementation complete, integration with manager workflows pending.
2025-10-04 08:55:59 +09:00
92 changed files with 20907 additions and 18142 deletions

View File

@@ -1,56 +0,0 @@
# Example: GitHub Actions workflow to auto-update test durations
# Rename to .github/workflows/update-test-durations.yml to enable
name: Update Test Durations
on:
schedule:
# Run weekly on Sundays at 2 AM UTC
- cron: '0 2 * * 0'
workflow_dispatch: # Allow manual trigger
jobs:
update-durations:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest pytest-split
- name: Update test durations
run: |
chmod +x tests/update_test_durations.sh
./tests/update_test_durations.sh
- name: Check for changes
id: check_changes
run: |
if git diff --quiet .test_durations; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.check_changes.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update test duration data'
title: 'Update test duration data'
body: |
Automated update of `.test_durations` file for optimal parallel test distribution.
This ensures pytest-split can effectively balance test load across parallel environments.
branch: auto/update-test-durations
delete-branch: true

9
.gitignore vendored
View File

@@ -21,11 +21,4 @@ check2.sh
build
dist
*.egg-info
.env
.git
.claude
.hypothesis
# Test artifacts
tests/tmp/
tests/env/
.env

170
CLAUDE.md
View File

@@ -1,170 +0,0 @@
# CLAUDE.md - Development Guidelines
## Project Context
This is ComfyUI Manager, a Python package that provides management functions for ComfyUI custom nodes, models, and extensions. The project follows modern Python packaging standards and maintains both current (`glob`) and legacy implementations.
## Code Architecture
- **Current Development**: Work in `comfyui_manager/glob/` package
- **Legacy Code**: `comfyui_manager/legacy/` (reference only, do not modify unless explicitly asked)
- **Common Utilities**: `comfyui_manager/common/` for shared functionality
- **Data Models**: `comfyui_manager/data_models/` for API schemas and types
## Development Workflow for API Changes
When modifying data being sent or received:
1. Update `openapi.yaml` file first
2. Verify YAML syntax using `yaml.safe_load`
3. Regenerate types following `data_models/README.md` instructions
4. Verify new data model generation
5. Verify syntax of generated type files
6. Run formatting and linting on generated files
7. Update `__init__.py` files in `data_models` to export new models
8. Make changes to rest of codebase
9. Run CI tests to verify changes
## Coding Standards
### Python Style
- Follow PEP 8 coding standards
- Use type hints for all function parameters and return values
- Target Python 3.9+ compatibility
- Line length: 120 characters (as configured in ruff)
### Security Guidelines
- Never hardcode API keys, tokens, or sensitive credentials
- Use environment variables for configuration
- Validate all user input and file paths
- Use prepared statements for database operations
- Implement proper error handling without exposing internal details
- Follow principle of least privilege for file/network access
### Code Quality
- Write descriptive variable and function names
- Include docstrings for public functions and classes
- Handle exceptions gracefully with specific error messages
- Use logging instead of print statements for debugging
- Maintain test coverage for new functionality
## Dependencies & Tools
### Core Dependencies
- GitPython, PyGithub for Git operations
- typer, rich for CLI interface
- transformers, huggingface-hub for AI model handling
- uv for fast package management
### Development Tools
- **Linting**: ruff (configured in pyproject.toml)
- **Testing**: pytest with coverage
- **Pre-commit**: pre-commit hooks for code quality
- **Type Checking**: Use type hints, consider mypy for strict checking
## File Organization
- Keep business logic in appropriate modules under `glob/`
- Place utility functions in `common/` for reusability
- Store UI/frontend code in `js/` directory
- Maintain documentation in `docs/` with multilingual support
### Large Data Files Policy
- **NEVER read .json files directly** - These contain large datasets that cause unnecessary token consumption
- Use `JSON_REFERENCE.md` for understanding JSON file structures and schemas
- Work with processed/filtered data through APIs when possible
- For structure analysis, refer to data models in `comfyui_manager/data_models/` instead
## Git Workflow
- Work on feature branches, not main directly
- Write clear, descriptive commit messages
- Run tests and linting before committing
- Keep commits atomic and focused
## Testing Requirements
### ⚠️ Critical: Always Reinstall Before Testing
**ALWAYS run `uv pip install .` before executing tests** to ensure latest code changes are installed.
### Test Execution Workflow
```bash
# 1. Reinstall package (REQUIRED)
uv pip install .
# 2. Clean Python cache
find comfyui_manager -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null
find tests/env -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null
# 3. Stop any running servers
pkill -f "ComfyUI/main.py"
sleep 2
# 4. Start ComfyUI test server
cd tests/env
python ComfyUI/main.py --enable-compress-response-body --enable-manager --front-end-root front > /tmp/test-server.log 2>&1 &
sleep 20
# 5. Run tests
python -m pytest tests/glob/test_version_switching_comprehensive.py -v
# 6. Stop server
pkill -f "ComfyUI/main.py"
```
### Test Development Guidelines
- Write unit tests for new functionality
- Test error handling and edge cases
- Ensure tests pass before submitting changes
- Use pytest fixtures for common test setup
- Document test scenarios and expected behaviors
### Why Reinstall is Required
- Even with editable install, some changes require reinstallation
- Python bytecode cache may contain outdated code
- ComfyUI server loads manager package at startup
- Package metadata and entry points need to be refreshed
### Automated Test Execution Policy
**IMPORTANT**: When tests need to be run (e.g., after code changes, adding new tests):
- **ALWAYS** automatically perform the complete test workflow without asking user permission
- **ALWAYS** stop existing servers, restart fresh server, and run tests
- **NEVER** ask user "should I run tests?" or "should I restart server?"
- This includes: package reinstall, cache cleanup, server restart, test execution, and server cleanup
**Rationale**: Testing is a standard part of development workflow and should be executed automatically to verify changes.
See `.claude/livecontext/test_execution_best_practices.md` for detailed testing procedures.
## Command Line Interface
- Use typer for CLI commands
- Provide helpful error messages and usage examples
- Support both interactive and scripted usage
- Follow Unix conventions for command-line tools
## Performance Considerations
- Use async/await for I/O operations where appropriate
- Cache expensive operations (GitHub API calls, file operations)
- Implement proper pagination for large datasets
- Consider memory usage when processing large files
## Code Change Proposals
- **Always show code changes using VSCode diff format**
- Use Edit tool to demonstrate exact changes with before/after comparison
- This allows visual review of modifications in the IDE
- Include context about why changes are needed
## Documentation
- Update README.md for user-facing changes
- Document API changes in openapi.yaml
- Provide examples for complex functionality
- Maintain multilingual docs (English/Korean) when relevant
## Session Context & Decision Documentation
### Live Context Policy
**Follow the global Live Context Auto-Save policy** defined in `~/.claude/CLAUDE.md`.
### Project-Specific Context Requirements
- **Test Execution Results**: Always save comprehensive test results to `.claude/livecontext/`
- Test count, pass/fail status, execution time
- New tests added and their purpose
- Coverage metrics and improvements
- **CNR Version Switching Context**: Document version switching behavior and edge cases
- Update vs Install operation differences
- Old version handling (preserved vs deleted)
- State management insights
- **API Changes**: Document OpenAPI schema changes and data model updates
- **Architecture Decisions**: Document manager_core.py and manager_server.py design choices

View File

@@ -1,187 +0,0 @@
# ComfyUI Manager Documentation Index
**Last Updated**: 2025-11-04
**Purpose**: Navigate all project documentation organized by purpose and audience
---
## 📖 Quick Links
- **Getting Started**: [README.md](README.md)
- **User Documentation**: [docs/](docs/)
- **Test Documentation**: [tests/glob/](tests/glob/)
- **Contributing**: [CONTRIBUTING.md](CONTRIBUTING.md)
- **Development**: [CLAUDE.md](CLAUDE.md)
---
## 📚 Documentation Structure
### Root Level
| Document | Purpose | Audience |
|----------|---------|----------|
| [README.md](README.md) | Project overview and quick start | Everyone |
| [CONTRIBUTING.md](CONTRIBUTING.md) | Contribution guidelines | Contributors |
| [CLAUDE.md](CLAUDE.md) | Development guidelines for AI-assisted development | Developers |
| [JSON_REFERENCE.md](JSON_REFERENCE.md) | JSON file schema reference | Developers |
### User Documentation (`docs/`)
| Document | Purpose | Language |
|----------|---------|----------|
| [docs/README.md](docs/README.md) | Documentation overview | English |
| [docs/PACKAGE_VERSION_MANAGEMENT.md](docs/PACKAGE_VERSION_MANAGEMENT.md) | Package version management guide | English |
| [docs/SECURITY_ENHANCED_INSTALLATION.md](docs/SECURITY_ENHANCED_INSTALLATION.md) | Security features for URL installation | English |
| [docs/en/cm-cli.md](docs/en/cm-cli.md) | CLI usage guide | English |
| [docs/en/use_aria2.md](docs/en/use_aria2.md) | Aria2 download configuration | English |
| [docs/ko/cm-cli.md](docs/ko/cm-cli.md) | CLI usage guide | Korean |
### Package Documentation
| Package | Document | Purpose |
|---------|----------|---------|
| comfyui_manager | [comfyui_manager/README.md](comfyui_manager/README.md) | Package overview |
| common | [comfyui_manager/common/README.md](comfyui_manager/common/README.md) | Common utilities documentation |
| data_models | [comfyui_manager/data_models/README.md](comfyui_manager/data_models/README.md) | Data model generation guide |
| glob | [comfyui_manager/glob/CLAUDE.md](comfyui_manager/glob/CLAUDE.md) | Glob module development guide |
| js | [comfyui_manager/js/README.md](comfyui_manager/js/README.md) | JavaScript components |
### Test Documentation (`tests/`)
| Document | Purpose | Status |
|----------|---------|--------|
| [tests/TEST.md](tests/TEST.md) | Testing overview | ✅ |
| [tests/glob/README.md](tests/glob/README.md) | Glob API endpoint tests | ✅ Translated |
| [tests/glob/TESTING_GUIDE.md](tests/glob/TESTING_GUIDE.md) | Test execution guide | ✅ |
| [tests/glob/TEST_INDEX.md](tests/glob/TEST_INDEX.md) | Test documentation unified index | ✅ Translated |
| [tests/glob/TEST_LOG.md](tests/glob/TEST_LOG.md) | Test execution log | ✅ Translated |
### Node Database
| Document | Purpose |
|----------|---------|
| [node_db/README.md](node_db/README.md) | Node database information |
---
## 🔒 Internal Documentation (`docs/internal/`)
### CLI Migration (`docs/internal/cli_migration/`)
Historical documentation for CLI migration from legacy to glob module (completed).
| Document | Purpose |
|----------|---------|
| [README.md](docs/internal/cli_migration/README.md) | Migration plan overview |
| [CLI_COMPATIBILITY_ANALYSIS.md](docs/internal/cli_migration/CLI_COMPATIBILITY_ANALYSIS.md) | Legacy vs Glob compatibility analysis |
| [CLI_IMPLEMENTATION_CONTEXT.md](docs/internal/cli_migration/CLI_IMPLEMENTATION_CONTEXT.md) | Implementation context |
| [CLI_IMPLEMENTATION_TODO.md](docs/internal/cli_migration/CLI_IMPLEMENTATION_TODO.md) | Implementation checklist |
| [CLI_PURE_GLOB_MIGRATION_PLAN.md](docs/internal/cli_migration/CLI_PURE_GLOB_MIGRATION_PLAN.md) | Technical migration specification |
| [CLI_GLOB_API_REFERENCE.md](docs/internal/cli_migration/CLI_GLOB_API_REFERENCE.md) | Glob API reference |
| [CLI_IMPLEMENTATION_CONSTRAINTS.md](docs/internal/cli_migration/CLI_IMPLEMENTATION_CONSTRAINTS.md) | Migration constraints |
| [CLI_TESTING_CHECKLIST.md](docs/internal/cli_migration/CLI_TESTING_CHECKLIST.md) | Testing checklist |
| [CLI_SHOW_LIST_REVISION.md](docs/internal/cli_migration/CLI_SHOW_LIST_REVISION.md) | show_list implementation plan |
### Test Planning (`docs/internal/test_planning/`)
Internal test planning documents (in Korean).
| Document | Purpose | Language |
|----------|---------|----------|
| [TEST_PLAN_ADDITIONAL.md](docs/internal/test_planning/TEST_PLAN_ADDITIONAL.md) | Additional test scenarios | Korean |
| [COMPLEX_SCENARIOS_TEST_PLAN.md](docs/internal/test_planning/COMPLEX_SCENARIOS_TEST_PLAN.md) | Complex multi-version test scenarios | Korean |
---
## 📋 Documentation by Audience
### For Users
1. [README.md](README.md) - Start here
2. [docs/en/cm-cli.md](docs/en/cm-cli.md) - CLI usage
3. [docs/PACKAGE_VERSION_MANAGEMENT.md](docs/PACKAGE_VERSION_MANAGEMENT.md) - Version management
### For Contributors
1. [CONTRIBUTING.md](CONTRIBUTING.md) - Contribution process
2. [CLAUDE.md](CLAUDE.md) - Development guidelines
3. [comfyui_manager/data_models/README.md](comfyui_manager/data_models/README.md) - Data model workflow
### For Developers
1. [CLAUDE.md](CLAUDE.md) - Development workflow
2. [comfyui_manager/glob/CLAUDE.md](comfyui_manager/glob/CLAUDE.md) - Glob module guide
3. [JSON_REFERENCE.md](JSON_REFERENCE.md) - Schema reference
4. [docs/PACKAGE_VERSION_MANAGEMENT.md](docs/PACKAGE_VERSION_MANAGEMENT.md) - Package management internals
### For Testers
1. [tests/TEST.md](tests/TEST.md) - Testing overview
2. [tests/glob/TEST_INDEX.md](tests/glob/TEST_INDEX.md) - Test documentation index
3. [tests/glob/TESTING_GUIDE.md](tests/glob/TESTING_GUIDE.md) - Test execution guide
---
## 🔄 Documentation Maintenance
### When to Update
- **README.md**: Project structure or main features change
- **CLAUDE.md**: Development workflow changes
- **Test Documentation**: New tests added or test structure changes
- **User Documentation**: User-facing features change
- **This Index**: New documentation added or reorganized
### Documentation Standards
- Use clear, descriptive titles
- Include "Last Updated" date
- Specify target audience
- Provide examples where applicable
- Keep language simple and accessible
- Translate user-facing docs to Korean when possible
---
## 🗂️ File Organization
```
comfyui-manager/
├── DOCUMENTATION_INDEX.md (this file)
├── README.md
├── CONTRIBUTING.md
├── CLAUDE.md
├── JSON_REFERENCE.md
├── docs/
│ ├── README.md
│ ├── PACKAGE_VERSION_MANAGEMENT.md
│ ├── SECURITY_ENHANCED_INSTALLATION.md
│ ├── en/
│ │ ├── cm-cli.md
│ │ └── use_aria2.md
│ ├── ko/
│ │ └── cm-cli.md
│ └── internal/
│ ├── cli_migration/ (9 files - completed migration docs)
│ └── test_planning/ (2 files - Korean test plans)
├── comfyui_manager/
│ ├── README.md
│ ├── common/README.md
│ ├── data_models/README.md
│ ├── glob/CLAUDE.md
│ └── js/README.md
├── tests/
│ ├── TEST.md
│ └── glob/
│ ├── README.md
│ ├── TESTING_GUIDE.md
│ ├── TEST_INDEX.md
│ └── TEST_LOG.md
└── node_db/
└── README.md
```
---
**Total Documentation Files**: 36 files organized across 6 categories
**Translation Status**:
- ✅ Core user documentation: English
- ✅ CLI guide: English + Korean
- ✅ Test documentation: English (translated from Korean)
- 📝 Internal planning docs: Korean (preserved as-is for historical reference)

View File

@@ -11,4 +11,5 @@ include extras.json
include github-stats.json
include model-list.json
include alter-list.json
include comfyui_manager/channels.list.template
include comfyui_manager/channels.list.template
include comfyui_manager/pip-policy.json

View File

@@ -36,9 +36,9 @@ if not os.path.exists(os.path.join(comfy_path, 'folder_paths.py')):
import utils.extra_config
from ..common import cm_global
from ..glob import manager_core as core
from ..legacy import manager_core as core
from ..common import context
from ..glob.manager_core import unified_manager
from ..legacy.manager_core import unified_manager
from ..common import cnr_utils
comfyui_manager_path = os.path.abspath(os.path.dirname(__file__))
@@ -129,7 +129,8 @@ class Ctx:
if channel is not None:
self.channel = channel
unified_manager.reload()
asyncio.run(unified_manager.reload(cache_mode=self.mode, dont_wait=False))
asyncio.run(unified_manager.load_nightly(self.channel, self.mode))
def set_no_deps(self, no_deps):
self.no_deps = no_deps
@@ -187,14 +188,9 @@ def install_node(node_spec_str, is_all=False, cnt_msg='', **kwargs):
exit_on_fail = kwargs.get('exit_on_fail', False)
print(f"install_node exit on fail:{exit_on_fail}...")
if unified_manager.is_url_like(node_spec_str):
# install via git URLs
repo_name = os.path.basename(node_spec_str)
if repo_name.endswith('.git'):
repo_name = repo_name[:-4]
res = asyncio.run(unified_manager.repo_install(
node_spec_str, repo_name, instant_execution=True, no_deps=cmd_ctx.no_deps
))
if core.is_valid_url(node_spec_str):
# install via urls
res = asyncio.run(core.gitclone_install(node_spec_str, no_deps=cmd_ctx.no_deps))
if not res.result:
print(res.msg)
print(f"[bold red]ERROR: An error occurred while installing '{node_spec_str}'.[/bold red]")
@@ -228,7 +224,7 @@ def install_node(node_spec_str, is_all=False, cnt_msg='', **kwargs):
print(f"{cnt_msg} [INSTALLED] {node_name:50}[{res.target}]")
elif res.action == 'switch-cnr' and res.result:
print(f"{cnt_msg} [INSTALLED] {node_name:50}[{res.target}]")
elif (res.action == 'switch-cnr' or res.action == 'install-cnr') and not res.result and cnr_utils.get_nodepack(node_name):
elif (res.action == 'switch-cnr' or res.action == 'install-cnr') and not res.result and node_name in unified_manager.cnr_map:
print(f"\nAvailable version of '{node_name}'")
show_versions(node_name)
print("")
@@ -319,10 +315,10 @@ def update_parallel(nodes):
if 'all' in nodes:
is_all = True
nodes = []
for packages in unified_manager.installed_node_packages.values():
for pack in packages:
if pack.is_enabled:
nodes.append(pack.id)
for x in unified_manager.active_nodes.keys():
nodes.append(x)
for x in unified_manager.unknown_active_nodes.keys():
nodes.append(x+"@unknown")
else:
nodes = [x for x in nodes if x.lower() not in ['comfy', 'comfyui']]
@@ -420,60 +416,121 @@ def disable_node(node_spec_str: str, is_all=False, cnt_msg=''):
def show_list(kind, simple=False):
"""
Show installed nodepacks only with on-demand metadata retrieval
Supported kinds: 'installed', 'enabled', 'disabled'
"""
# Validate supported commands
if kind not in ['installed', 'enabled', 'disabled']:
print(f"[bold red]Unsupported: 'show {kind}'. Available options: installed/enabled/disabled[/bold red]")
print("Note: 'show all', 'show not-installed', and 'show cnr' are no longer supported.")
print("Use 'show installed' to see all installed packages.")
return
custom_nodes = asyncio.run(unified_manager.get_custom_nodes(channel=cmd_ctx.channel, mode=cmd_ctx.mode))
# Get all installed packages from glob unified_manager
all_packages = []
for packages in unified_manager.installed_node_packages.values():
all_packages.extend(packages)
# Filter by status
if kind == 'enabled':
packages = [pkg for pkg in all_packages if pkg.is_enabled]
elif kind == 'disabled':
packages = [pkg for pkg in all_packages if pkg.is_disabled]
else: # 'installed'
packages = all_packages
# collect not-installed unknown nodes
not_installed_unknown_nodes = []
repo_unknown = {}
# Display packages
for package in sorted(packages, key=lambda x: x.id):
# Basic info from InstalledNodePackage
status = "[ ENABLED ]" if package.is_enabled else "[ DISABLED ]"
# Enhanced info with on-demand CNR retrieval
display_name = package.id
author = "Unknown"
version = package.version
# Try to get additional info from CNR for better display
if package.is_from_cnr:
try:
cnr_info = cnr_utils.get_nodepack(package.id)
if cnr_info:
display_name = cnr_info.get('name', package.id)
if 'publisher' in cnr_info and 'name' in cnr_info['publisher']:
author = cnr_info['publisher']['name']
except Exception:
# Fallback to basic info if CNR lookup fails
pass
elif package.is_nightly:
version = "nightly"
elif package.is_unknown:
version = "unknown"
if simple:
print(f"{display_name}@{version}")
for k, v in custom_nodes.items():
if 'cnr_latest' not in v:
if len(v['files']) == 1:
repo_url = v['files'][0]
node_name = repo_url.split('/')[-1]
if node_name not in unified_manager.unknown_inactive_nodes and node_name not in unified_manager.unknown_active_nodes:
not_installed_unknown_nodes.append(v)
else:
repo_unknown[node_name] = v
processed = {}
unknown_processed = []
flag = kind in ['all', 'cnr', 'installed', 'enabled']
for k, v in unified_manager.active_nodes.items():
if flag:
cnr = unified_manager.cnr_map.get(k)
if cnr:
processed[k] = "[ ENABLED ] ", cnr['name'], k, cnr['publisher']['name'], v[0]
else:
processed[k] = None
else:
print(f"{status} {display_name:50} {package.id:30} (author: {author:20}) [{version}]")
processed[k] = None
if flag and kind != 'cnr':
for k, v in unified_manager.unknown_active_nodes.items():
item = repo_unknown.get(k)
if item is None:
continue
log_item = "[ ENABLED ] ", item['title'], k, item['author']
unknown_processed.append(log_item)
flag = kind in ['all', 'cnr', 'installed', 'disabled']
for k, v in unified_manager.cnr_inactive_nodes.items():
if k in processed:
continue
if flag:
cnr = unified_manager.cnr_map.get(k) # NOTE: can this be None if removed from CNR after installed
if cnr:
processed[k] = "[ DISABLED ] ", cnr['name'], k, cnr['publisher']['name'], ", ".join(list(v.keys()))
else:
processed[k] = None
else:
processed[k] = None
for k, v in unified_manager.nightly_inactive_nodes.items():
if k in processed:
continue
if flag:
cnr = unified_manager.cnr_map.get(k)
if cnr:
processed[k] = "[ DISABLED ] ", cnr['name'], k, cnr['publisher']['name'], 'nightly'
else:
processed[k] = None
else:
processed[k] = None
if flag and kind != 'cnr':
for k, v in unified_manager.unknown_inactive_nodes.items():
item = repo_unknown.get(k)
if item is None:
continue
log_item = "[ DISABLED ] ", item['title'], k, item['author']
unknown_processed.append(log_item)
flag = kind in ['all', 'cnr', 'not-installed']
for k, v in unified_manager.cnr_map.items():
if k in processed:
continue
if flag:
cnr = unified_manager.cnr_map.get(k)
if cnr:
ver_spec = v['latest_version']['version'] if 'latest_version' in v else '0.0.0'
processed[k] = "[ NOT INSTALLED ] ", cnr['name'], k, cnr['publisher']['name'], ver_spec
else:
processed[k] = None
else:
processed[k] = None
if flag and kind != 'cnr':
for x in not_installed_unknown_nodes:
if len(x['files']) == 1:
node_id = os.path.basename(x['files'][0])
log_item = "[ NOT INSTALLED ] ", x['title'], node_id, x['author']
unknown_processed.append(log_item)
for x in processed.values():
if x is None:
continue
prefix, title, short_id, author, ver_spec = x
if simple:
print(title+'@'+ver_spec)
else:
print(f"{prefix} {title:50} {short_id:30} (author: {author:20}) \\[{ver_spec}]")
for x in unknown_processed:
prefix, title, short_id, author = x
if simple:
print(title+'@unknown')
else:
print(f"{prefix} {title:50} {short_id:30} (author: {author:20}) [UNKNOWN]")
async def show_snapshot(simple_mode=False):
@@ -514,14 +571,37 @@ async def auto_save_snapshot():
def get_all_installed_node_specs():
"""
Get all installed node specifications using glob InstalledNodePackage data structure
"""
res = []
for packages in unified_manager.installed_node_packages.values():
for pack in packages:
node_spec_str = f"{pack.id}@{pack.version}"
processed = set()
for k, v in unified_manager.active_nodes.items():
node_spec_str = f"{k}@{v[0]}"
res.append(node_spec_str)
processed.add(k)
for k in unified_manager.cnr_inactive_nodes.keys():
if k in processed:
continue
latest = unified_manager.get_from_cnr_inactive_nodes(k)
if latest is not None:
node_spec_str = f"{k}@{str(latest[0])}"
res.append(node_spec_str)
for k in unified_manager.nightly_inactive_nodes.keys():
if k in processed:
continue
node_spec_str = f"{k}@nightly"
res.append(node_spec_str)
for k in unified_manager.unknown_active_nodes.keys():
node_spec_str = f"{k}@unknown"
res.append(node_spec_str)
for k in unified_manager.unknown_inactive_nodes.keys():
node_spec_str = f"{k}@unknown"
res.append(node_spec_str)
return res
@@ -1197,21 +1277,19 @@ def export_custom_node_ids(
cmd_ctx.set_channel_mode(channel, mode)
with open(path, "w", encoding='utf-8') as output_file:
# Export CNR package IDs using cnr_utils
try:
all_cnr = cnr_utils.get_all_nodepackages()
for package_id in all_cnr.keys():
print(package_id, file=output_file)
except Exception:
# If CNR lookup fails, continue with installed packages
pass
for x in unified_manager.cnr_map.keys():
print(x, file=output_file)
# Export installed packages that are not from CNR
for packages in unified_manager.installed_node_packages.values():
for pack in packages:
if pack.is_unknown or pack.is_nightly:
version_suffix = "@unknown" if pack.is_unknown else "@nightly"
print(f"{pack.id}{version_suffix}", file=output_file)
custom_nodes = asyncio.run(unified_manager.get_custom_nodes(channel=cmd_ctx.channel, mode=cmd_ctx.mode))
for x in custom_nodes.values():
if 'cnr_latest' not in x:
if len(x['files']) == 1:
repo_url = x['files'][0]
node_id = repo_url.split('/')[-1]
print(f"{node_id}@unknown", file=output_file)
if 'id' in x:
print(f"{x['id']}@unknown", file=output_file)
def main():

View File

@@ -34,11 +34,6 @@ variables = {}
APIs = {}
pip_overrides = {}
pip_blacklist = {}
pip_downgrade_blacklist = {}
def register_api(k, f):
global APIs
APIs[k] = f

View File

@@ -11,11 +11,6 @@ from . import manager_util
import requests
import toml
import logging
from . import git_utils
from cachetools import TTLCache, cached
query_ttl_cache = TTLCache(maxsize=100, ttl=60)
base_url = "https://api.comfy.org"
@@ -24,34 +19,11 @@ lock = asyncio.Lock()
is_cache_loading = False
def normalize_package_name(name: str) -> str:
"""
Normalize package name for case-insensitive matching.
This follows the same normalization pattern used throughout CNR:
- Strip leading/trailing whitespace
- Convert to lowercase
Args:
name: Package name to normalize (e.g., "ComfyUI_SigmoidOffsetScheduler" or " NodeName ")
Returns:
Normalized package name (e.g., "comfyui_sigmoidoffsetscheduler")
Examples:
>>> normalize_package_name("ComfyUI_SigmoidOffsetScheduler")
"comfyui_sigmoidoffsetscheduler"
>>> normalize_package_name(" NodeName ")
"nodename"
"""
return name.strip().lower()
async def get_cnr_data(cache_mode=True, dont_wait=True):
try:
return await _get_cnr_data(cache_mode, dont_wait)
except asyncio.TimeoutError:
logging.info("A timeout occurred during the fetch process from ComfyRegistry.")
print("A timeout occurred during the fetch process from ComfyRegistry.")
return await _get_cnr_data(cache_mode=True, dont_wait=True) # timeout fallback
async def _get_cnr_data(cache_mode=True, dont_wait=True):
@@ -64,6 +36,7 @@ async def _get_cnr_data(cache_mode=True, dont_wait=True):
page = 1
full_nodes = {}
# Determine form factor based on environment and platform
is_desktop = bool(os.environ.get('__COMFYUI_DESKTOP_VERSION__'))
@@ -106,12 +79,12 @@ async def _get_cnr_data(cache_mode=True, dont_wait=True):
full_nodes[x['id']] = x
if page % 5 == 0:
logging.info(f"FETCH ComfyRegistry Data: {page}/{sub_json_obj['totalPages']}")
print(f"FETCH ComfyRegistry Data: {page}/{sub_json_obj['totalPages']}")
page += 1
time.sleep(0.5)
logging.info("FETCH ComfyRegistry Data [DONE]")
print("FETCH ComfyRegistry Data [DONE]")
for v in full_nodes.values():
if 'latest_version' not in v:
@@ -127,7 +100,7 @@ async def _get_cnr_data(cache_mode=True, dont_wait=True):
if cache_state == 'not-cached':
return {}
else:
logging.info("[ComfyUI-Manager] The ComfyRegistry cache update is still in progress, so an outdated cache is being used.")
print("[ComfyUI-Manager] The ComfyRegistry cache update is still in progress, so an outdated cache is being used.")
with open(manager_util.get_cache_path(uri), 'r', encoding="UTF-8", errors="ignore") as json_file:
return json.load(json_file)['nodes']
@@ -141,7 +114,7 @@ async def _get_cnr_data(cache_mode=True, dont_wait=True):
return json_obj['nodes']
except Exception:
res = {}
logging.warning("Cannot connect to comfyregistry.")
print("Cannot connect to comfyregistry.")
finally:
if cache_mode:
is_cache_loading = False
@@ -164,7 +137,7 @@ def map_node_version(api_node_version):
Maps node version data from API response to NodeVersion dataclass.
Args:
api_node_version (dict): The 'node_version' part of the API response.
api_data (dict): The 'node_version' part of the API response.
Returns:
NodeVersion: An instance of NodeVersion dataclass populated with data from the API.
@@ -215,80 +188,6 @@ def install_node(node_id, version=None):
return None
@cached(query_ttl_cache)
def get_nodepack(packname):
"""
Retrieves the nodepack
Args:
packname (str): The unique identifier of the node.
Returns:
nodepack info {id, latest_version}
"""
url = f"{base_url}/nodes/{packname}"
response = requests.get(url, verify=not manager_util.bypass_ssl)
if response.status_code == 200:
info = response.json()
res = {
'id': info['id']
}
if 'latest_version' in info:
res['latest_version'] = info['latest_version']['version']
if 'repository' in info:
res['repository'] = info['repository']
return res
else:
return None
@cached(query_ttl_cache)
def get_nodepack_by_url(url):
"""
Retrieves the nodepack info for installation.
Args:
url (str): The unique identifier of the node.
Returns:
NodeVersion: Node version data or error message.
"""
# example query: https://api.comfy.org/nodes/search?repository_url_search=ltdrdata/ComfyUI-Impact-Pack&limit=1
url = f"nodes/search?repository_url_search={url}&limit=1"
response = requests.get(url, verify=not manager_util.bypass_ssl)
if response.status_code == 200:
# Convert the API response to a NodeVersion object
info = response.json().get('nodes', [])
if len(info) > 0:
info = info[0]
repo_url = info['repository']
if git_utils.compact_url(url) != git_utils.compact_url(repo_url):
return None
res = {
'id': info['id']
}
if 'latest_version' in info:
res['latest_version'] = info['latest_version']['version']
res['repository'] = info['repository']
return res
else:
return None
else:
return None
def all_versions_of_node(node_id):
url = f"{base_url}/nodes/{node_id}/versions?statuses=NodeVersionStatusActive&statuses=NodeVersionStatusPending"
@@ -311,7 +210,8 @@ def read_cnr_info(fullpath):
data = toml.load(f)
project = data.get('project', {})
name = project.get('name').strip()
name = project.get('name').strip().lower()
original_name = project.get('name')
# normalize version
# for example: 2.5 -> 2.5.0
@@ -323,6 +223,7 @@ def read_cnr_info(fullpath):
if name and version: # repository is optional
return {
"id": name,
"original_name": original_name,
"version": version,
"url": repository
}
@@ -339,7 +240,7 @@ def generate_cnr_id(fullpath, cnr_id):
with open(cnr_id_path, "w") as f:
return f.write(cnr_id)
except Exception:
logging.error(f"[ComfyUI Manager] unable to create file: {cnr_id_path}")
print(f"[ComfyUI Manager] unable to create file: {cnr_id_path}")
def read_cnr_id(fullpath):
@@ -352,3 +253,4 @@ def read_cnr_id(fullpath):
pass
return None

View File

@@ -77,14 +77,6 @@ def normalize_to_github_id(url) -> str:
return None
def compact_url(url):
github_id = normalize_to_github_id(url)
if github_id is not None:
return github_id
return url
def get_url_for_clone(url):
url = normalize_url(url)

View File

@@ -15,7 +15,6 @@ import re
import logging
import platform
import shlex
from functools import lru_cache
cache_lock = threading.Lock()
@@ -39,64 +38,18 @@ def add_python_path_to_env():
os.environ['PATH'] = os.path.dirname(sys.executable)+sep+os.environ['PATH']
@lru_cache(maxsize=2)
def get_pip_cmd(force_uv=False):
"""
Get the base pip command, with automatic fallback to uv if pip is unavailable.
Args:
force_uv (bool): If True, use uv directly without trying pip
Returns:
list: Base command for pip operations
"""
embedded = 'python_embeded' in sys.executable
# Try pip first (unless forcing uv)
if not force_uv:
try:
test_cmd = [sys.executable] + (['-s'] if embedded else []) + ['-m', 'pip', '--version']
subprocess.check_output(test_cmd, stderr=subprocess.DEVNULL, timeout=5)
return [sys.executable] + (['-s'] if embedded else []) + ['-m', 'pip']
except Exception:
logging.warning("[ComfyUI-Manager] python -m pip not available. Falling back to uv.")
# Try uv (either forced or pip failed)
import shutil
# Try uv as Python module
try:
test_cmd = [sys.executable] + (['-s'] if embedded else []) + ['-m', 'uv', '--version']
subprocess.check_output(test_cmd, stderr=subprocess.DEVNULL, timeout=5)
logging.info("[ComfyUI-Manager] Using uv as Python module for pip operations.")
return [sys.executable] + (['-s'] if embedded else []) + ['-m', 'uv', 'pip']
except Exception:
pass
# Try standalone uv
if shutil.which('uv'):
logging.info("[ComfyUI-Manager] Using standalone uv for pip operations.")
return ['uv', 'pip']
# Nothing worked
logging.error("[ComfyUI-Manager] Neither python -m pip nor uv are available. Cannot proceed with package operations.")
raise Exception("Neither pip nor uv are available for package management")
def make_pip_cmd(cmd):
"""
Create a pip command by combining the cached base pip command with the given arguments.
Args:
cmd (list): List of pip command arguments (e.g., ['install', 'package'])
Returns:
list: Complete command list ready for subprocess execution
"""
global use_uv
base_cmd = get_pip_cmd(force_uv=use_uv)
return base_cmd + cmd
if 'python_embeded' in sys.executable:
if use_uv:
return [sys.executable, '-s', '-m', 'uv', 'pip'] + cmd
else:
return [sys.executable, '-s', '-m', 'pip'] + cmd
else:
# FIXED: https://github.com/ltdrdata/ComfyUI-Manager/issues/1667
if use_uv:
return [sys.executable, '-m', 'uv', 'pip'] + cmd
else:
return [sys.executable, '-m', 'pip'] + cmd
# DON'T USE StrictVersion - cannot handle pre_release version
# try:

View File

@@ -14,7 +14,6 @@ class InstalledNodePackage:
fullpath: str
disabled: bool
version: str
repo_url: str = None # Git repository URL for nightly packages
@property
def is_unknown(self) -> bool:
@@ -47,8 +46,6 @@ class InstalledNodePackage:
@staticmethod
def from_fullpath(fullpath: str, resolve_from_path) -> InstalledNodePackage:
from . import git_utils
parent_folder_name = os.path.basename(os.path.dirname(fullpath))
module_name = os.path.basename(fullpath)
@@ -57,10 +54,6 @@ class InstalledNodePackage:
disabled = True
elif parent_folder_name == ".disabled":
# Nodes under custom_nodes/.disabled/* are disabled
# Parse directory name format: packagename@version
# Examples:
# comfyui_sigmoidoffsetscheduler@nightly → id: comfyui_sigmoidoffsetscheduler, version: nightly
# comfyui_sigmoidoffsetscheduler@1_0_2 → id: comfyui_sigmoidoffsetscheduler, version: 1.0.2
node_id = module_name
disabled = True
else:
@@ -68,35 +61,12 @@ class InstalledNodePackage:
disabled = False
info = resolve_from_path(fullpath)
repo_url = None
version_from_dirname = None
# For disabled packages, try to extract version from directory name
if disabled and parent_folder_name == ".disabled" and '@' in module_name:
parts = module_name.split('@')
if len(parts) == 2:
node_id = parts[0] # Use the normalized name from directory
version_from_dirname = parts[1].replace('_', '.') # Convert 1_0_2 → 1.0.2
if info is None:
version = version_from_dirname if version_from_dirname else 'unknown'
version = 'unknown'
else:
node_id = info['id'] # robust module guessing
# Prefer version from directory name for disabled packages (preserves 'nightly' literal)
# Otherwise use version from package inspection (commit hash for git repos)
if version_from_dirname:
version = version_from_dirname
else:
version = info['ver']
# Get repository URL for both nightly and CNR packages
if version == 'nightly':
# For nightly packages, get repo URL from git
repo_url = git_utils.git_url(fullpath)
elif 'url' in info and info['url']:
# For CNR packages, get repo URL from pyproject.toml
repo_url = info['url']
version = info['ver']
return InstalledNodePackage(
id=node_id, fullpath=fullpath, disabled=disabled, version=version, repo_url=repo_url
id=node_id, fullpath=fullpath, disabled=disabled, version=version
)

View File

@@ -0,0 +1,713 @@
# Design Document for pip_util.py Implementation
This is designed to minimize breaking existing installed dependencies.
## List of Functions to Implement
## Global Policy Management
### Global Variables
```python
_pip_policy_cache = None # Policy cache (program-wide, loaded once)
```
### Global Functions
* get_pip_policy(): Returns policy for resolving pip dependency conflicts (lazy loading)
- **Call timing**: Called whenever needed (automatically loads only once on first call)
- **Purpose**: Returns policy cache, automatically loads if cache is empty
- **Execution flow**:
1. Declare global _pip_policy_cache
2. If _pip_policy_cache is already loaded, return immediately (prevent duplicate loading)
3. Read base policy file:
- Path: {manager_util.comfyui_manager_path}/pip-policy.json
- Use empty dictionary if file doesn't exist
- Log error and use empty dictionary if JSON parsing fails
4. Read user policy file:
- Path: {context.manager_files_path}/pip-policy.user.json
- Create empty JSON file if doesn't exist ({"_comment": "User-specific pip policy overrides"})
- Log warning and use empty dictionary if JSON parsing fails
5. Apply merge rules (merge by package name):
- Start with base policy as base
- For each package in user policy:
* Package only in user policy: add to base
* Package only in base policy: keep in base
* Package in both: completely replace with user policy (entire package replacement, not section-level)
6. Store merged policy in _pip_policy_cache
7. Log policy load success (include number of loaded package policies)
8. Return _pip_policy_cache
- **Return value**: Dict (merged policy dictionary)
- **Exception handling**:
- File read failure: Log warning and treat file as empty dictionary
- JSON parsing failure: Log error and treat file as empty dictionary
- **Notes**:
- Lazy loading pattern automatically loads on first call
- Not thread-safe, caution needed in multi-threaded environments
- Policy file structure should support the following scenarios:
- Dictionary structure of {dependency name -> policy object}
- Policy object has four policy sections:
- **uninstall**: Package removal policy (pre-processing, condition optional)
- **apply_first_match**: Evaluate top-to-bottom and execute only the first policy that satisfies condition (exclusive)
- **apply_all_matches**: Execute all policies that satisfy conditions (cumulative)
- **restore**: Package restoration policy (post-processing, condition optional)
- Condition types:
- installed: Check version condition of already installed dependencies
- spec is optional
- package field: Specify package to check (optional, defaults to self)
- Explicit: Reference another package (e.g., numba checks numpy version)
- Omitted: Check own version (e.g., critical-package checks its own version)
- platform: Platform conditions (os, has_gpu, comfyui_version, etc.)
- If condition is absent, always considered satisfied
- uninstall policy (pre-removal policy):
- Removal policy list (condition is optional, evaluate top-to-bottom and execute only first match)
- When condition satisfied (or always if no condition): remove target package and abort installation
- If this policy is applied, all subsequent steps are ignored
- target field specifies package to remove
- Example: Unconditionally remove if specific package is installed
- Actions available in apply_first_match (determine installation method, exclusive):
- skip: Block installation of specific dependency
- force_version: Force change to specific version during installation
- extra_index_url field can specify custom package repository (optional)
- replace: Replace with different dependency
- extra_index_url field can specify custom package repository (optional)
- Actions available in apply_all_matches (installation options, cumulative):
- pin_dependencies: Pin currently installed versions of other dependencies
- pinned_packages field specifies package list
- Example: `pip install requests urllib3==1.26.15 certifi==2023.7.22 charset-normalizer==3.2.0`
- Real use case: Prevent urllib3 from upgrading to 2.x when installing requests
- on_failure: "fail" or "retry_without_pin"
- install_with: Specify additional dependencies to install together
- warn: Record warning message in log
- restore policy (post-restoration policy):
- Restoration policy list (condition is optional, evaluate top-to-bottom and execute only first match)
- Executed after package installation completes (post-processing)
- When condition satisfied (or always if no condition): force install target package to specific version
- target field specifies package to restore (can be different package)
- version field specifies version to install
- extra_index_url field can specify custom package repository (optional)
- Example: Reinstall/change version if specific package is deleted or wrong version
- Execution order:
1. uninstall evaluation: If condition satisfied, remove package and **terminate** (ignore subsequent steps)
2. apply_first_match evaluation:
- Execute first policy that satisfies condition among skip/force_version/replace
- If no matching policy, proceed with default installation of originally requested package
3. apply_all_matches evaluation: Apply all pin_dependencies, install_with, warn that satisfy conditions
4. Execute actual package installation (pip install or uv pip install)
5. restore evaluation: If condition satisfied, restore target package (post-processing)
## Batch Unit Class (PipBatch)
### Class Structure
```python
class PipBatch:
"""
pip package installation batch unit manager
Maintains pip freeze cache during batch operations for performance optimization
Usage pattern:
# Batch operations (policy auto-loaded)
with PipBatch() as batch:
batch.ensure_not_installed()
batch.install("numpy>=1.20")
batch.install("pandas>=2.0")
batch.install("scipy>=1.7")
batch.ensure_installed()
"""
def __init__(self):
self._installed_cache = None # Installed packages cache (batch-level)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self._installed_cache = None
```
### Private Methods
* PipBatch._refresh_installed_cache():
- **Purpose**: Read currently installed package information and refresh cache
- **Execution flow**:
1. Generate command using manager_util.make_pip_cmd(["freeze"])
2. Execute pip freeze via subprocess
3. Parse output:
- Each line is in "package_name==version" format
- Parse "package_name==version" to create dictionary
- Ignore editable packages (starting with -e)
- Ignore comments (starting with #)
4. Store parsed dictionary in self._installed_cache
- **Return value**: None
- **Exception handling**:
- pip freeze failure: Set cache to empty dictionary and log warning
- Parse failure: Ignore line and continue
* PipBatch._get_installed_packages():
- **Purpose**: Return cached installed package information (refresh if cache is None)
- **Execution flow**:
1. If self._installed_cache is None, call _refresh_installed_cache()
2. Return self._installed_cache
- **Return value**: {package_name: version} dictionary
* PipBatch._invalidate_cache():
- **Purpose**: Invalidate cache after package install/uninstall
- **Execution flow**:
1. Set self._installed_cache = None
- **Return value**: None
- **Call timing**: After install(), ensure_not_installed(), ensure_installed()
* PipBatch._parse_package_spec(package_info):
- **Purpose**: Split package spec string into package name and version spec
- **Parameters**:
- package_info: "numpy", "numpy==1.26.0", "numpy>=1.20.0", "numpy~=1.20", etc.
- **Execution flow**:
1. Use regex to split package name and version spec
2. Pattern: `^([a-zA-Z0-9_-]+)([><=!~]+.*)?$`
- **Return value**: (package_name, version_spec) tuple
- Examples: ("numpy", "==1.26.0"), ("pandas", ">=2.0.0"), ("scipy", None)
- **Exception handling**:
- Parse failure: Raise ValueError
* PipBatch._evaluate_condition(condition, package_name, installed_packages):
- **Purpose**: Evaluate policy condition and return whether satisfied
- **Parameters**:
- condition: Policy condition object (dictionary)
- package_name: Name of package currently being processed
- installed_packages: {package_name: version} dictionary
- **Execution flow**:
1. If condition is None, return True (always satisfied)
2. Branch based on condition["type"]:
a. "installed" type:
- target_package = condition.get("package", package_name)
- Check current version with installed_packages.get(target_package)
- If not installed (None), return False
- If spec exists, compare version using packaging.specifiers.SpecifierSet
- If no spec, only check installation status (True)
b. "platform" type:
- If condition["os"] exists, compare with platform.system()
- If condition["has_gpu"] exists, check GPU presence (torch.cuda.is_available(), etc.)
- If condition["comfyui_version"] exists, compare ComfyUI version
- Return True if all conditions satisfied
3. Return True if all conditions satisfied, False if any unsatisfied
- **Return value**: bool
- **Exception handling**:
- Version comparison failure: Log warning and return False
- Unknown condition type: Log warning and return False
### Public Methods
* PipBatch.install(package_info, extra_index_url=None, override_policy=False):
- **Purpose**: Perform policy-based pip package installation (individual package basis)
- **Parameters**:
- package_info: Package name and version spec (e.g., "numpy", "numpy==1.26.0", "numpy>=1.20.0")
- extra_index_url: Additional package repository URL (optional)
- override_policy: If True, skip policy application and install directly (default: False)
- **Execution flow**:
1. Call get_pip_policy() to get policy (lazy loading)
2. Use self._parse_package_spec() to split package_info into package name and version spec
3. Call self._get_installed_packages() to get cached installed package information
4. If override_policy=True → Jump directly to step 10 (skip policy)
5. Get policy for package name from policy dictionary
6. If no policy → Jump to step 10 (default installation)
7. **apply_first_match policy evaluation** (exclusive - only first match):
- Iterate through policy list top-to-bottom
- Evaluate each policy's condition with self._evaluate_condition()
- When first condition-satisfying policy found:
* type="skip": Log reason and return False (don't install)
* type="force_version": Change package_info version to policy's version
* type="replace": Completely replace package_info with policy's replacement package
- If no matching policy, keep original package_info
8. **apply_all_matches policy evaluation** (cumulative - all matches):
- Iterate through policy list top-to-bottom
- Evaluate each policy's condition with self._evaluate_condition()
- For all condition-satisfying policies:
* type="pin_dependencies":
- For each package in pinned_packages, query current version with self._installed_cache.get(pkg)
- Pin to installed version in "package==version" format
- Add to installation package list
* type="install_with":
- Add additional_packages to installation package list
* type="warn":
- Output message as warning log
- If allow_continue=false, wait for user confirmation (optional)
9. Compose final installation package list:
- Main package (modified/replaced package_info)
- Packages pinned by pin_dependencies
- Packages added by install_with
10. Handle extra_index_url:
- Parameter-passed extra_index_url takes priority
- Otherwise use extra_index_url defined in policy
11. Generate pip/uv command using manager_util.make_pip_cmd():
- Basic format: ["pip", "install"] + package list
- If extra_index_url exists: add ["--extra-index-url", url]
12. Execute command via subprocess
13. Handle installation failure:
- If pin_dependencies's on_failure="retry_without_pin":
* Retry with only main package excluding pinned packages
- If on_failure="fail":
* Raise exception and abort installation
- Otherwise: Log warning and continue
14. On successful installation:
- Call self._invalidate_cache() (invalidate cache)
- Log info if reason exists
- Return True
- **Return value**: Installation success status (bool)
- **Exception handling**:
- Policy parsing failure: Log warning and proceed with default installation
- Installation failure: Log error and raise exception (depends on on_failure setting)
- **Notes**:
- restore policy not handled in this method (batch-processed in ensure_installed())
- uninstall policy not handled in this method (batch-processed in ensure_not_installed())
* PipBatch.ensure_not_installed():
- **Purpose**: Iterate through all policies and remove all packages satisfying uninstall conditions (batch processing)
- **Parameters**: None
- **Execution flow**:
1. Call get_pip_policy() to get policy (lazy loading)
2. Call self._get_installed_packages() to get cached installed package information
3. Iterate through all package policies in policy dictionary:
a. Check if each package has uninstall policy
b. If uninstall policy exists:
- Iterate through uninstall policy list top-to-bottom
- Evaluate each policy's condition with self._evaluate_condition()
- When first condition-satisfying policy found:
* Check if target package exists in self._installed_cache
* If installed:
- Generate command with manager_util.make_pip_cmd(["uninstall", "-y", target])
- Execute pip uninstall via subprocess
- Log reason in info log
- Add to removed package list
- Remove package from self._installed_cache
* Move to next package (only first match per package)
4. Complete iteration through all package policies
- **Return value**: List of removed package names (list of str)
- **Exception handling**:
- Individual package removal failure: Log warning only and continue to next package
- **Call timing**:
- Called at batch operation start to pre-remove conflicting packages
- Called before multiple package installations to clean installation environment
* PipBatch.ensure_installed():
- **Purpose**: Iterate through all policies and restore all packages satisfying restore conditions (batch processing)
- **Parameters**: None
- **Execution flow**:
1. Call get_pip_policy() to get policy (lazy loading)
2. Call self._get_installed_packages() to get cached installed package information
3. Iterate through all package policies in policy dictionary:
a. Check if each package has restore policy
b. If restore policy exists:
- Iterate through restore policy list top-to-bottom
- Evaluate each policy's condition with self._evaluate_condition()
- When first condition-satisfying policy found:
* Get target package name (policy's "target" field)
* Get version specified in version field
* Check current version with self._installed_cache.get(target)
* If current version is None or different from specified version:
- Compose as package_spec = f"{target}=={version}" format
- Generate command with manager_util.make_pip_cmd(["install", package_spec])
- If extra_index_url exists, add ["--extra-index-url", url]
- Execute pip install via subprocess
- Log reason in info log
- Add to restored package list
- Update cache: self._installed_cache[target] = version
* Move to next package (only first match per package)
4. Complete iteration through all package policies
- **Return value**: List of restored package names (list of str)
- **Exception handling**:
- Individual package installation failure: Log warning only and continue to next package
- **Call timing**:
- Called at batch operation end to restore essential package versions
- Called for environment verification after multiple package installations
## pip-policy.json Examples
### Base Policy File ({manager_util.comfyui_manager_path}/pip-policy.json)
```json
{
"torch": {
"apply_first_match": [
{
"type": "skip",
"reason": "PyTorch installation should be managed manually due to CUDA compatibility"
}
]
},
"opencv-python": {
"apply_first_match": [
{
"type": "replace",
"replacement": "opencv-contrib-python",
"version": ">=4.8.0",
"reason": "opencv-contrib-python includes all opencv-python features plus extras"
}
]
},
"PIL": {
"apply_first_match": [
{
"type": "replace",
"replacement": "Pillow",
"reason": "PIL is deprecated, use Pillow instead"
}
]
},
"click": {
"apply_first_match": [
{
"condition": {
"type": "installed",
"package": "colorama",
"spec": "<0.5.0"
},
"type": "force_version",
"version": "8.1.3",
"reason": "click 8.1.3 compatible with colorama <0.5"
}
],
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["colorama"],
"reason": "Prevent colorama upgrade that may break compatibility"
}
]
},
"requests": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["urllib3", "certifi", "charset-normalizer"],
"on_failure": "retry_without_pin",
"reason": "Prevent urllib3 from upgrading to 2.x which has breaking changes"
}
]
},
"six": {
"restore": [
{
"target": "six",
"version": "1.16.0",
"reason": "six must be maintained at 1.16.0 for compatibility"
}
]
},
"urllib3": {
"restore": [
{
"condition": {
"type": "installed",
"spec": "!=1.26.15"
},
"target": "urllib3",
"version": "1.26.15",
"reason": "urllib3 must be 1.26.15 for compatibility with legacy code"
}
]
},
"onnxruntime": {
"apply_first_match": [
{
"condition": {
"type": "platform",
"os": "linux",
"has_gpu": true
},
"type": "replace",
"replacement": "onnxruntime-gpu",
"reason": "Use GPU version on Linux with CUDA"
}
]
},
"legacy-custom-node-package": {
"apply_first_match": [
{
"condition": {
"type": "platform",
"comfyui_version": "<1.0.0"
},
"type": "force_version",
"version": "0.9.0",
"reason": "legacy-custom-node-package 0.9.0 is compatible with ComfyUI <1.0.0"
},
{
"condition": {
"type": "platform",
"comfyui_version": ">=1.0.0"
},
"type": "force_version",
"version": "1.5.0",
"reason": "legacy-custom-node-package 1.5.0 is required for ComfyUI >=1.0.0"
}
]
},
"tensorflow": {
"apply_all_matches": [
{
"condition": {
"type": "installed",
"package": "torch"
},
"type": "warn",
"message": "Installing TensorFlow alongside PyTorch may cause CUDA conflicts",
"allow_continue": true
}
]
},
"some-package": {
"uninstall": [
{
"condition": {
"type": "installed",
"package": "conflicting-package",
"spec": ">=2.0.0"
},
"target": "conflicting-package",
"reason": "conflicting-package >=2.0.0 conflicts with some-package"
}
]
},
"banned-malicious-package": {
"uninstall": [
{
"target": "banned-malicious-package",
"reason": "Security vulnerability CVE-2024-XXXXX, always remove if attempting to install"
}
]
},
"critical-package": {
"restore": [
{
"condition": {
"type": "installed",
"package": "critical-package",
"spec": "!=1.2.3"
},
"target": "critical-package",
"version": "1.2.3",
"extra_index_url": "https://custom-repo.example.com/simple",
"reason": "critical-package must be version 1.2.3, restore if different or missing"
}
]
},
"stable-package": {
"apply_first_match": [
{
"condition": {
"type": "installed",
"package": "critical-dependency",
"spec": ">=2.0.0"
},
"type": "force_version",
"version": "1.5.0",
"extra_index_url": "https://custom-repo.example.com/simple",
"reason": "stable-package 1.5.0 is required when critical-dependency >=2.0.0 is installed"
}
]
},
"new-experimental-package": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["numpy", "pandas", "scipy"],
"on_failure": "retry_without_pin",
"reason": "new-experimental-package may upgrade numpy/pandas/scipy, pin them to prevent breakage"
}
]
},
"pytorch-addon": {
"apply_all_matches": [
{
"condition": {
"type": "installed",
"package": "torch",
"spec": ">=2.0.0"
},
"type": "pin_dependencies",
"pinned_packages": ["torch", "torchvision", "torchaudio"],
"on_failure": "fail",
"reason": "pytorch-addon must not change PyTorch ecosystem versions"
}
]
}
}
```
### Policy Structure Schema
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"patternProperties": {
"^.*$": {
"type": "object",
"properties": {
"uninstall": {
"type": "array",
"description": "When condition satisfied (or always if no condition), remove package and terminate",
"items": {
"type": "object",
"required": ["target"],
"properties": {
"condition": {
"type": "object",
"description": "Optional: always remove if absent",
"required": ["type"],
"properties": {
"type": {"enum": ["installed", "platform"]},
"package": {"type": "string", "description": "Optional: defaults to self"},
"spec": {"type": "string", "description": "Optional: version condition"},
"os": {"type": "string"},
"has_gpu": {"type": "boolean"},
"comfyui_version": {"type": "string"}
}
},
"target": {
"type": "string",
"description": "Package name to remove"
},
"reason": {"type": "string"}
}
}
},
"restore": {
"type": "array",
"description": "When condition satisfied (or always if no condition), restore package and terminate",
"items": {
"type": "object",
"required": ["target", "version"],
"properties": {
"condition": {
"type": "object",
"description": "Optional: always restore if absent",
"required": ["type"],
"properties": {
"type": {"enum": ["installed", "platform"]},
"package": {"type": "string", "description": "Optional: defaults to self"},
"spec": {"type": "string", "description": "Optional: version condition"},
"os": {"type": "string"},
"has_gpu": {"type": "boolean"},
"comfyui_version": {"type": "string"}
}
},
"target": {
"type": "string",
"description": "Package name to restore"
},
"version": {
"type": "string",
"description": "Version to restore"
},
"extra_index_url": {"type": "string"},
"reason": {"type": "string"}
}
}
},
"apply_first_match": {
"type": "array",
"description": "Execute only first condition-satisfying policy (exclusive)",
"items": {
"type": "object",
"required": ["type"],
"properties": {
"condition": {
"type": "object",
"description": "Optional: always apply if absent",
"required": ["type"],
"properties": {
"type": {"enum": ["installed", "platform"]},
"package": {"type": "string", "description": "Optional: defaults to self"},
"spec": {"type": "string", "description": "Optional: version condition"},
"os": {"type": "string"},
"has_gpu": {"type": "boolean"},
"comfyui_version": {"type": "string"}
}
},
"type": {
"enum": ["skip", "force_version", "replace"],
"description": "Exclusive action: determines installation method"
},
"version": {"type": "string"},
"replacement": {"type": "string"},
"extra_index_url": {"type": "string"},
"reason": {"type": "string"}
}
}
},
"apply_all_matches": {
"type": "array",
"description": "Execute all condition-satisfying policies (cumulative)",
"items": {
"type": "object",
"required": ["type"],
"properties": {
"condition": {
"type": "object",
"description": "Optional: always apply if absent",
"required": ["type"],
"properties": {
"type": {"enum": ["installed", "platform"]},
"package": {"type": "string", "description": "Optional: defaults to self"},
"spec": {"type": "string", "description": "Optional: version condition"},
"os": {"type": "string"},
"has_gpu": {"type": "boolean"},
"comfyui_version": {"type": "string"}
}
},
"type": {
"enum": ["pin_dependencies", "install_with", "warn"],
"description": "Cumulative action: adds installation options"
},
"pinned_packages": {
"type": "array",
"items": {"type": "string"}
},
"on_failure": {"enum": ["fail", "retry_without_pin"]},
"additional_packages": {"type": "array"},
"message": {"type": "string"},
"allow_continue": {"type": "boolean"},
"reason": {"type": "string"}
}
}
}
}
}
}
}
```
## Error Handling
* Default behavior when errors occur during policy execution:
- Log error and continue
- Only treat as installation failure when pin_dependencies's on_failure="fail"
- For other cases, leave warning and attempt originally requested installation
* pip_install: Performs pip package installation
- Use manager_util.make_pip_cmd to generate commands for selective application of uv and pip
- Provide functionality to skip policy application through override_policy flag

View File

@@ -0,0 +1,614 @@
# pip_util.py Implementation Plan Document
## 1. Project Overview
### Purpose
Implement a policy-based pip package management system that minimizes breaking existing installed dependencies
### Core Features
- JSON-based policy file loading and merging (lazy loading)
- Per-package installation policy evaluation and application
- Performance optimization through batch-level pip freeze caching
- Automated conditional package removal/restoration
### Technology Stack
- Python 3.x
- packaging library (version comparison)
- subprocess (pip command execution)
- json (policy file parsing)
---
## 2. Architecture Design
### 2.1 Global Policy Management (Lazy Loading Pattern)
```
┌─────────────────────────────────────┐
│ get_pip_policy() │
│ - Auto-loads policy files on │
│ first call via lazy loading │
│ - Returns cache on subsequent calls│
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ _pip_policy_cache (global) │
│ - Merged policy dictionary │
│ - {package_name: policy_object} │
└─────────────────────────────────────┘
```
### 2.2 Batch Operation Class (PipBatch)
```
┌─────────────────────────────────────┐
│ PipBatch (Context Manager) │
│ ┌───────────────────────────────┐ │
│ │ _installed_cache │ │
│ │ - Caches pip freeze results │ │
│ │ - {package: version} │ │
│ └───────────────────────────────┘ │
│ │
│ Public Methods: │
│ ├─ install() │
│ ├─ ensure_not_installed() │
│ └─ ensure_installed() │
│ │
│ Private Methods: │
│ ├─ _get_installed_packages() │
│ ├─ _refresh_installed_cache() │
│ ├─ _invalidate_cache() │
│ ├─ _parse_package_spec() │
│ └─ _evaluate_condition() │
└─────────────────────────────────────┘
```
### 2.3 Policy Evaluation Flow
```
install("numpy>=1.20") called
get_pip_policy() → Load policy (lazy)
Parse package name: "numpy"
Look up "numpy" policy in policy dictionary
├─ Evaluate apply_first_match (exclusive)
│ ├─ skip → Return False (don't install)
│ ├─ force_version → Change version
│ └─ replace → Replace package
├─ Evaluate apply_all_matches (cumulative)
│ ├─ pin_dependencies → Pin dependencies
│ ├─ install_with → Additional packages
│ └─ warn → Warning log
Execute pip install
Invalidate cache (_invalidate_cache)
```
---
## 3. Phase-by-Phase Implementation Plan
### Phase 1: Core Infrastructure Setup (2-3 hours)
#### Task 1.1: Project Structure and Dependency Setup (30 min)
**Implementation**:
- Create `pip_util.py` file
- Add necessary import statements
```python
import json
import logging
import platform
import re
import subprocess
from pathlib import Path
from typing import Dict, List, Optional, Tuple
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from . import manager_util, context
```
- Set up logging
```python
logger = logging.getLogger(__name__)
```
**Validation**:
- Module loads without import errors
- Logger works correctly
#### Task 1.2: Global Variable and get_pip_policy() Implementation (1 hour)
**Implementation**:
- Declare global variable
```python
_pip_policy_cache: Optional[Dict] = None
```
- Implement `get_pip_policy()` function
- Check cache and early return
- Read base policy file (`{manager_util.comfyui_manager_path}/pip-policy.json`)
- Read user policy file (`{context.manager_files_path}/pip-policy.user.json`)
- Create file if doesn't exist (for user policy)
- Merge policies (complete package-level replacement)
- Save to cache and return
**Exception Handling**:
- `FileNotFoundError`: File not found → Use empty dictionary
- `json.JSONDecodeError`: JSON parse failure → Warning log + empty dictionary
- General exception: Warning log + empty dictionary
**Validation**:
- Returns empty dictionary when policy files don't exist
- Returns correct merged result when policy files exist
- Confirms cache usage on second call (load log appears only once)
#### Task 1.3: PipBatch Class Basic Structure (30 min)
**Implementation**:
- Class definition and `__init__`
```python
class PipBatch:
def __init__(self):
self._installed_cache: Optional[Dict[str, str]] = None
```
- Context manager methods (`__enter__`, `__exit__`)
```python
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self._installed_cache = None
return False
```
**Validation**:
- `with PipBatch() as batch:` syntax works correctly
- Cache cleared on `__exit__` call
---
### Phase 2: Caching and Utility Methods (2-3 hours)
#### Task 2.1: pip freeze Caching Methods (1 hour)
**Implementation**:
- Implement `_refresh_installed_cache()`
- Call `manager_util.make_pip_cmd(["freeze"])`
- Execute command via subprocess
- Parse output (package==version format)
- Exclude editable packages (-e) and comments (#)
- Convert to dictionary and store in `self._installed_cache`
- Implement `_get_installed_packages()`
- Call `_refresh_installed_cache()` if cache is None
- Return cache
- Implement `_invalidate_cache()`
- Set `self._installed_cache = None`
**Exception Handling**:
- `subprocess.CalledProcessError`: pip freeze failure → Empty dictionary
- Parse error: Ignore line + warning log
**Validation**:
- pip freeze results correctly parsed into dictionary
- New load occurs after cache invalidation and re-query
#### Task 2.2: Package Spec Parsing (30 min)
**Implementation**:
- Implement `_parse_package_spec(package_info)`
- Regex pattern: `^([a-zA-Z0-9_-]+)([><=!~]+.*)?$`
- Split package name and version spec
- Return tuple: `(package_name, version_spec)`
**Exception Handling**:
- Parse failure: Raise `ValueError`
**Validation**:
- "numpy" → ("numpy", None)
- "numpy==1.26.0" → ("numpy", "==1.26.0")
- "pandas>=2.0.0" → ("pandas", ">=2.0.0")
- Invalid format → ValueError
#### Task 2.3: Condition Evaluation Method (1.5 hours)
**Implementation**:
- Implement `_evaluate_condition(condition, package_name, installed_packages)`
**Handling by Condition Type**:
1. **condition is None**: Always return True
2. **"installed" type**:
- `target_package = condition.get("package", package_name)`
- Check version with `installed_packages.get(target_package)`
- If spec exists, compare using `packaging.specifiers.SpecifierSet`
- If no spec, only check installation status
3. **"platform" type**:
- `os` condition: Compare with `platform.system()`
- `has_gpu` condition: Check `torch.cuda.is_available()` (False if torch unavailable)
- `comfyui_version` condition: TODO (currently warning)
**Exception Handling**:
- Version comparison failure: Warning log + return False
- Unknown condition type: Warning log + return False
**Validation**:
- Write test cases for each condition type
- Verify edge case handling (torch not installed, invalid version format, etc.)
---
### Phase 3: Core Installation Logic Implementation (4-5 hours)
#### Task 3.1: install() Method - Basic Flow (2 hours)
**Implementation**:
1. Parse package spec (`_parse_package_spec`)
2. Query installed package cache (`_get_installed_packages`)
3. If `override_policy=True`, install directly and return
4. Call `get_pip_policy()` to load policy
5. Default installation if no policy exists
**Validation**:
- Verify policy ignored when override_policy=True
- Verify default installation for packages without policy
#### Task 3.2: install() Method - apply_first_match Policy (1 hour)
**Implementation**:
- Iterate through policy list top-to-bottom
- Evaluate each policy's condition (`_evaluate_condition`)
- When condition satisfied:
- **skip**: Log reason and return False
- **force_version**: Force version change
- **replace**: Replace package
- Apply only first match (break)
**Validation**:
- Verify installation blocked by skip policy
- Verify version changed by force_version
- Verify package replaced by replace
#### Task 3.3: install() Method - apply_all_matches Policy (1 hour)
**Implementation**:
- Iterate through policy list top-to-bottom
- Evaluate each policy's condition
- Apply all condition-satisfying policies:
- **pin_dependencies**: Pin to installed version
- **install_with**: Add to additional package list
- **warn**: Output warning log
**Validation**:
- Verify multiple policies applied simultaneously
- Verify version pinning by pin_dependencies
- Verify additional package installation by install_with
#### Task 3.4: install() Method - Installation Execution and Retry Logic (1 hour)
**Implementation**:
1. Compose final package list
2. Generate command using `manager_util.make_pip_cmd()`
3. Handle `extra_index_url`
4. Execute installation via subprocess
5. Handle failure based on on_failure setting:
- `retry_without_pin`: Retry without pins
- `fail`: Raise exception
- Other: Warning log
6. Invalidate cache on success
**Validation**:
- Verify normal installation
- Verify retry logic on pin failure
- Verify error handling
---
### Phase 4: Batch Operation Methods Implementation (2-3 hours)
#### Task 4.1: ensure_not_installed() Implementation (1.5 hours)
**Implementation**:
1. Call `get_pip_policy()`
2. Iterate through all package policies
3. Check each package's uninstall policy
4. When condition satisfied:
- Check if target package is installed
- If installed, execute `pip uninstall -y {target}`
- Remove from cache
- Add to removal list
5. Execute only first match (per package)
6. Return list of removed packages
**Exception Handling**:
- Individual package removal failure: Warning log + continue
**Validation**:
- Verify package removal by uninstall policy
- Verify batch removal of multiple packages
- Verify continued processing of other packages even on removal failure
#### Task 4.2: ensure_installed() Implementation (1.5 hours)
**Implementation**:
1. Call `get_pip_policy()`
2. Iterate through all package policies
3. Check each package's restore policy
4. When condition satisfied:
- Check target package's current version
- If absent or different version:
- Execute `pip install {target}=={version}`
- Add extra_index_url if present
- Update cache
- Add to restoration list
5. Execute only first match (per package)
6. Return list of restored packages
**Exception Handling**:
- Individual package installation failure: Warning log + continue
**Validation**:
- Verify package restoration by restore policy
- Verify reinstallation on version mismatch
- Verify continued processing of other packages even on restoration failure
---
## 4. Testing Strategy
### 4.1 Unit Tests
#### Policy Loading Tests
```python
def test_get_pip_policy_empty():
"""Returns empty dictionary when policy files don't exist"""
def test_get_pip_policy_merge():
"""Correctly merges base and user policies"""
def test_get_pip_policy_cache():
"""Uses cache on second call"""
```
#### Package Parsing Tests
```python
def test_parse_package_spec_simple():
"""'numpy' → ('numpy', None)"""
def test_parse_package_spec_version():
"""'numpy==1.26.0' → ('numpy', '==1.26.0')"""
def test_parse_package_spec_range():
"""'pandas>=2.0.0' → ('pandas', '>=2.0.0')"""
def test_parse_package_spec_invalid():
"""Invalid format → ValueError"""
```
#### Condition Evaluation Tests
```python
def test_evaluate_condition_none():
"""None condition → True"""
def test_evaluate_condition_installed():
"""Evaluates installed package condition"""
def test_evaluate_condition_platform():
"""Evaluates platform condition"""
```
### 4.2 Integration Tests
#### Installation Policy Tests
```python
def test_install_with_skip_policy():
"""Blocks installation with skip policy"""
def test_install_with_force_version():
"""Changes version with force_version policy"""
def test_install_with_replace():
"""Replaces package with replace policy"""
def test_install_with_pin_dependencies():
"""Pins versions with pin_dependencies"""
```
#### Batch Operation Tests
```python
def test_ensure_not_installed():
"""Removes packages with uninstall policy"""
def test_ensure_installed():
"""Restores packages with restore policy"""
def test_batch_workflow():
"""Tests complete batch workflow"""
```
### 4.3 Edge Case Tests
```python
def test_install_without_policy():
"""Default installation for packages without policy"""
def test_install_override_policy():
"""Ignores policy with override_policy=True"""
def test_pip_freeze_failure():
"""Handles empty cache on pip freeze failure"""
def test_json_parse_error():
"""Handles malformed JSON files"""
def test_subprocess_failure():
"""Exception handling when pip command fails"""
```
---
## 5. Error Handling Strategy
### 5.1 Policy Loading Errors
- **File not found**: Warning log + empty dictionary
- **JSON parse failure**: Error log + empty dictionary
- **No read permission**: Warning log + empty dictionary
### 5.2 Package Installation Errors
- **pip command failure**: Depends on on_failure setting
- `retry_without_pin`: Retry
- `fail`: Raise exception
- Other: Warning log
- **Invalid package spec**: Raise ValueError
### 5.3 Batch Operation Errors
- **Individual package failure**: Warning log + continue to next package
- **pip freeze failure**: Empty dictionary + warning log
---
## 6. Performance Optimization
### 6.1 Caching Strategy
- **Policy cache**: Reused program-wide via global variable
- **pip freeze cache**: Reused per batch, invalidated after install/remove
- **lazy loading**: Load only when needed
### 6.2 Parallel Processing Considerations
- Current implementation is not thread-safe
- Consider adding threading.Lock if needed
- Batch operations execute sequentially only
---
## 7. Documentation Requirements
### 7.1 Code Documentation
- Docstrings required for all public methods
- Specify parameters, return values, and exceptions
- Include usage examples
### 7.2 User Guide
- Explain `pip-policy.json` structure
- Policy writing examples
- Usage pattern examples
### 7.3 Developer Guide
- Architecture explanation
- Extension methods
- Test execution methods
---
## 8. Deployment Checklist
### 8.1 Code Quality
- [ ] All unit tests pass
- [ ] All integration tests pass
- [ ] Code coverage ≥80%
- [ ] No linting errors (flake8, pylint)
- [ ] Type hints complete (mypy passes)
### 8.2 Documentation
- [ ] README.md written
- [ ] API documentation generated
- [ ] Example policy files written
- [ ] Usage guide written
### 8.3 Performance Verification
- [ ] Policy loading performance measured (<100ms)
- [ ] pip freeze caching effectiveness verified (≥50% speed improvement)
- [ ] Memory usage confirmed (<10MB)
### 8.4 Security Verification
- [ ] Input validation complete
- [ ] Path traversal prevention
- [ ] Command injection prevention
- [ ] JSON parsing safety confirmed
---
## 9. Future Improvements
### 9.1 Short-term (1-2 weeks)
- Implement ComfyUI version check
- Implement user confirmation prompt (allow_continue=false)
- Thread-safe improvements (add Lock)
### 9.2 Mid-term (1-2 months)
- Add policy validation tools
- Policy migration tools
- More detailed logging and debugging options
### 9.3 Long-term (3-6 months)
- Web UI for policy management
- Provide policy templates
- Community policy sharing system
---
## 10. Risks and Mitigation Strategies
### Risk 1: Policy Conflicts
**Description**: Policies for different packages may conflict
**Mitigation**: Develop policy validation tools, conflict detection algorithm
### Risk 2: pip Version Compatibility
**Description**: Must work across various pip versions
**Mitigation**: Test on multiple pip versions, version-specific branching
### Risk 3: Performance Degradation
**Description**: Installation speed may decrease due to policy evaluation
**Mitigation**: Optimize caching, minimize condition evaluation
### Risk 4: Policy Misconfiguration
**Description**: Users may write incorrect policies
**Mitigation**: JSON schema validation, provide examples and guides
---
## 11. Timeline
### Week 1
- Phase 1: Core Infrastructure Setup (Day 1-2)
- Phase 2: Caching and Utility Methods (Day 3-4)
- Write unit tests (Day 5)
### Week 2
- Phase 3: Core Installation Logic Implementation (Day 1-3)
- Phase 4: Batch Operation Methods Implementation (Day 4-5)
### Week 3
- Integration and edge case testing (Day 1-2)
- Documentation (Day 3)
- Code review and refactoring (Day 4-5)
### Week 4
- Performance optimization (Day 1-2)
- Security verification (Day 3)
- Final testing and deployment preparation (Day 4-5)
---
## 12. Success Criteria
### Feature Completeness
- ✅ All policy types (uninstall, apply_first_match, apply_all_matches, restore) work correctly
- ✅ Policy merge logic works correctly
- ✅ Batch operations perform normally
### Quality Metrics
- ✅ Test coverage ≥80%
- ✅ All tests pass
- ✅ 0 linting errors
- ✅ 100% type hint completion
### Performance Metrics
- ✅ Policy loading <100ms
- ✅ ≥50% performance improvement with pip freeze caching
- ✅ Memory usage <10MB
### Usability
- ✅ Clear error messages
- ✅ Sufficient documentation
- ✅ Verified in real-world use cases

View File

@@ -0,0 +1,629 @@
"""
pip_util - Policy-based pip package management system
This module provides a policy-based approach to pip package installation
to minimize dependency conflicts and protect existing installed packages.
Usage:
# Batch operations (policy auto-loaded)
with PipBatch() as batch:
batch.ensure_not_installed()
batch.install("numpy>=1.20")
batch.install("pandas>=2.0")
batch.install("scipy>=1.7")
batch.ensure_installed()
"""
import json
import logging
import platform
import re
import subprocess
from pathlib import Path
from typing import Dict, List, Optional, Tuple
from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from . import manager_util, context
logger = logging.getLogger(__name__)
# Global policy cache (lazy loaded on first access)
_pip_policy_cache: Optional[Dict] = None
def get_pip_policy() -> Dict:
"""
Get pip policy with lazy loading.
Returns the cached policy if available, otherwise loads it from files.
This function automatically loads the policy on first access.
Thread safety: This function is NOT thread-safe.
Ensure single-threaded access during initialization.
Returns:
Dictionary of merged pip policies
Example:
>>> policy = get_pip_policy()
>>> numpy_policy = policy.get("numpy", {})
"""
global _pip_policy_cache
# Return cached policy if already loaded
if _pip_policy_cache is not None:
logger.debug("Returning cached pip policy")
return _pip_policy_cache
logger.info("Loading pip policies...")
# Load base policy
base_policy = {}
base_policy_path = Path(manager_util.comfyui_manager_path) / "pip-policy.json"
try:
if base_policy_path.exists():
with open(base_policy_path, 'r', encoding='utf-8') as f:
base_policy = json.load(f)
logger.debug(f"Loaded base policy from {base_policy_path}")
else:
logger.warning(f"Base policy file not found: {base_policy_path}")
except json.JSONDecodeError as e:
logger.error(f"Failed to parse base policy JSON: {e}")
base_policy = {}
except Exception as e:
logger.warning(f"Failed to read base policy file: {e}")
base_policy = {}
# Load user policy
user_policy = {}
user_policy_path = Path(context.manager_files_path) / "pip-policy.user.json"
try:
if user_policy_path.exists():
with open(user_policy_path, 'r', encoding='utf-8') as f:
user_policy = json.load(f)
logger.debug(f"Loaded user policy from {user_policy_path}")
else:
# Create empty user policy file
user_policy_path.parent.mkdir(parents=True, exist_ok=True)
with open(user_policy_path, 'w', encoding='utf-8') as f:
json.dump({"_comment": "User-specific pip policy overrides"}, f, indent=2)
logger.info(f"Created empty user policy file: {user_policy_path}")
except json.JSONDecodeError as e:
logger.warning(f"Failed to parse user policy JSON: {e}")
user_policy = {}
except Exception as e:
logger.warning(f"Failed to read user policy file: {e}")
user_policy = {}
# Merge policies (package-level override: user completely replaces base per package)
merged_policy = base_policy.copy()
for package_name, package_policy in user_policy.items():
if package_name.startswith("_"): # Skip metadata fields like _comment
continue
merged_policy[package_name] = package_policy # Complete package replacement
# Store in global cache
_pip_policy_cache = merged_policy
logger.info(f"Policy loaded successfully: {len(_pip_policy_cache)} package policies")
return _pip_policy_cache
class PipBatch:
"""
Pip package installation batch manager.
Maintains pip freeze cache during a batch of operations for performance optimization.
Usage pattern:
# Batch operations (policy auto-loaded)
with PipBatch() as batch:
batch.ensure_not_installed()
batch.install("numpy>=1.20")
batch.install("pandas>=2.0")
batch.install("scipy>=1.7")
batch.ensure_installed()
Attributes:
_installed_cache: Cache of installed packages from pip freeze
"""
def __init__(self):
"""Initialize PipBatch with empty cache."""
self._installed_cache: Optional[Dict[str, str]] = None
def __enter__(self):
"""Enter context manager."""
return self
def __exit__(self, exc_type, exc_val, exc_tb):
"""Exit context manager and clear cache."""
self._installed_cache = None
return False
def _refresh_installed_cache(self) -> None:
"""
Refresh the installed packages cache by executing pip freeze.
Parses pip freeze output into a dictionary of {package_name: version}.
Ignores editable packages and comments.
Raises:
No exceptions raised - failures result in empty cache with warning log
"""
try:
cmd = manager_util.make_pip_cmd(["freeze"])
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
packages = {}
for line in result.stdout.strip().split('\n'):
line = line.strip()
# Skip empty lines
if not line:
continue
# Skip editable packages (-e /path/to/package or -e git+https://...)
# Editable packages don't have version info and are typically development-only
if line.startswith('-e '):
continue
# Skip comments (defensive: pip freeze typically doesn't output comments,
# but this handles manually edited requirements.txt or future pip changes)
if line.startswith('#'):
continue
# Parse package==version
if '==' in line:
try:
package_name, version = line.split('==', 1)
packages[package_name.strip()] = version.strip()
except ValueError:
logger.warning(f"Failed to parse pip freeze line: {line}")
continue
self._installed_cache = packages
logger.debug(f"Refreshed installed packages cache: {len(packages)} packages")
except subprocess.CalledProcessError as e:
logger.warning(f"pip freeze failed: {e}")
self._installed_cache = {}
except Exception as e:
logger.warning(f"Failed to refresh installed packages cache: {e}")
self._installed_cache = {}
def _get_installed_packages(self) -> Dict[str, str]:
"""
Get cached installed packages, refresh if cache is None.
Returns:
Dictionary of {package_name: version}
"""
if self._installed_cache is None:
self._refresh_installed_cache()
return self._installed_cache
def _invalidate_cache(self) -> None:
"""
Invalidate the installed packages cache.
Should be called after install/uninstall operations.
"""
self._installed_cache = None
def _parse_package_spec(self, package_info: str) -> Tuple[str, Optional[str]]:
"""
Parse package spec string into package name and version spec using PEP 508.
Uses the packaging library to properly parse package specifications according to
PEP 508 standard, which handles complex cases like extras and multiple version
constraints that simple regex cannot handle correctly.
Args:
package_info: Package specification like "numpy", "numpy==1.26.0", "numpy>=1.20.0",
or complex specs like "package[extra]>=1.0,<2.0"
Returns:
Tuple of (package_name, version_spec)
Examples: ("numpy", "==1.26.0"), ("pandas", ">=2.0.0"), ("scipy", None)
Package names are normalized (e.g., "NumPy" -> "numpy")
Raises:
ValueError: If package_info cannot be parsed according to PEP 508
Example:
>>> batch._parse_package_spec("numpy>=1.20")
("numpy", ">=1.20")
>>> batch._parse_package_spec("requests[security]>=2.0,<3.0")
("requests", ">=2.0,<3.0")
"""
try:
req = Requirement(package_info)
package_name = req.name # Normalized package name
version_spec = str(req.specifier) if req.specifier else None
return package_name, version_spec
except Exception as e:
raise ValueError(f"Invalid package spec: {package_info}") from e
def _evaluate_condition(self, condition: Optional[Dict], package_name: str,
installed_packages: Dict[str, str]) -> bool:
"""
Evaluate policy condition and return whether it's satisfied.
Args:
condition: Policy condition object (dict) or None
package_name: Current package being processed
installed_packages: Dictionary of {package_name: version}
Returns:
True if condition is satisfied, False otherwise
None condition always returns True
Example:
>>> condition = {"type": "installed", "package": "numpy", "spec": ">=1.20"}
>>> batch._evaluate_condition(condition, "numba", {"numpy": "1.26.0"})
True
"""
# No condition means always satisfied
if condition is None:
return True
condition_type = condition.get("type")
if condition_type == "installed":
# Check if a package is installed with optional version spec
target_package = condition.get("package", package_name)
installed_version = installed_packages.get(target_package)
# Package not installed
if installed_version is None:
return False
# Check version spec if provided
spec = condition.get("spec")
if spec:
try:
specifier = SpecifierSet(spec)
return Version(installed_version) in specifier
except Exception as e:
logger.warning(f"Failed to compare version {installed_version} with spec {spec}: {e}")
return False
# Package is installed (no spec check)
return True
elif condition_type == "platform":
# Check platform conditions (os, has_gpu, comfyui_version)
conditions_met = True
# Check OS
if "os" in condition:
expected_os = condition["os"].lower()
actual_os = platform.system().lower()
if expected_os not in actual_os and actual_os not in expected_os:
conditions_met = False
# Check GPU availability
if "has_gpu" in condition:
expected_gpu = condition["has_gpu"]
try:
import torch
has_gpu = torch.cuda.is_available()
except ImportError:
has_gpu = False
if expected_gpu != has_gpu:
conditions_met = False
# Check ComfyUI version
if "comfyui_version" in condition:
# TODO: Implement ComfyUI version check
logger.warning("ComfyUI version condition not yet implemented")
return conditions_met
else:
logger.warning(f"Unknown condition type: {condition_type}")
return False
def install(self, package_info: str, extra_index_url: Optional[str] = None,
override_policy: bool = False) -> bool:
"""
Install a pip package with policy-based modifications.
Args:
package_info: Package specification (e.g., "numpy", "numpy==1.26.0", "numpy>=1.20.0")
extra_index_url: Additional package repository URL (optional)
override_policy: If True, skip policy application and install directly (default: False)
Returns:
True if installation succeeded, False if skipped by policy
Raises:
ValueError: If package_info cannot be parsed
subprocess.CalledProcessError: If installation fails (depending on policy on_failure settings)
Example:
>>> with PipBatch() as batch:
... batch.install("numpy>=1.20")
... batch.install("torch", override_policy=True)
"""
# Parse package spec
try:
package_name, version_spec = self._parse_package_spec(package_info)
except ValueError as e:
logger.error(f"Invalid package spec: {e}")
raise
# Get installed packages cache
installed_packages = self._get_installed_packages()
# Override policy - skip to direct installation
if override_policy:
logger.info(f"Installing {package_info} (policy override)")
cmd = manager_util.make_pip_cmd(["install", package_info])
if extra_index_url:
cmd.extend(["--extra-index-url", extra_index_url])
try:
subprocess.run(cmd, check=True)
self._invalidate_cache()
logger.info(f"Successfully installed {package_info}")
return True
except subprocess.CalledProcessError as e:
logger.error(f"Failed to install {package_info}: {e}")
raise
# Get policy (lazy loading)
pip_policy = get_pip_policy()
policy = pip_policy.get(package_name, {})
# If no policy, proceed with default installation
if not policy:
logger.debug(f"No policy found for {package_name}, proceeding with default installation")
cmd = manager_util.make_pip_cmd(["install", package_info])
if extra_index_url:
cmd.extend(["--extra-index-url", extra_index_url])
try:
subprocess.run(cmd, check=True)
self._invalidate_cache()
logger.info(f"Successfully installed {package_info}")
return True
except subprocess.CalledProcessError as e:
logger.error(f"Failed to install {package_info}: {e}")
raise
# Apply apply_first_match policies (exclusive - first match only)
final_package_info = package_info
final_extra_index_url = extra_index_url
policy_reason = None
apply_first_match = policy.get("apply_first_match", [])
for policy_item in apply_first_match:
condition = policy_item.get("condition")
if self._evaluate_condition(condition, package_name, installed_packages):
policy_type = policy_item.get("type")
if policy_type == "skip":
reason = policy_item.get("reason", "No reason provided")
logger.info(f"Skipping installation of {package_name}: {reason}")
return False
elif policy_type == "force_version":
forced_version = policy_item.get("version")
final_package_info = f"{package_name}=={forced_version}"
policy_reason = policy_item.get("reason")
if "extra_index_url" in policy_item:
final_extra_index_url = policy_item["extra_index_url"]
logger.info(f"Force version for {package_name}: {forced_version} ({policy_reason})")
break # First match only
elif policy_type == "replace":
replacement = policy_item.get("replacement")
replacement_version = policy_item.get("version", "")
if replacement_version:
final_package_info = f"{replacement}{replacement_version}"
else:
final_package_info = replacement
policy_reason = policy_item.get("reason")
if "extra_index_url" in policy_item:
final_extra_index_url = policy_item["extra_index_url"]
logger.info(f"Replacing {package_name} with {final_package_info}: {policy_reason}")
break # First match only
# Apply apply_all_matches policies (cumulative - all matches)
additional_packages = []
pinned_packages = []
pin_on_failure = "fail"
apply_all_matches = policy.get("apply_all_matches", [])
for policy_item in apply_all_matches:
condition = policy_item.get("condition")
if self._evaluate_condition(condition, package_name, installed_packages):
policy_type = policy_item.get("type")
if policy_type == "pin_dependencies":
pin_list = policy_item.get("pinned_packages", [])
for pkg in pin_list:
installed_version = installed_packages.get(pkg)
if installed_version:
pinned_packages.append(f"{pkg}=={installed_version}")
else:
logger.warning(f"Cannot pin {pkg}: not currently installed")
pin_on_failure = policy_item.get("on_failure", "fail")
reason = policy_item.get("reason", "")
logger.info(f"Pinning dependencies: {pinned_packages} ({reason})")
elif policy_type == "install_with":
additional = policy_item.get("additional_packages", [])
additional_packages.extend(additional)
reason = policy_item.get("reason", "")
logger.info(f"Installing additional packages: {additional} ({reason})")
elif policy_type == "warn":
message = policy_item.get("message", "")
allow_continue = policy_item.get("allow_continue", True)
logger.warning(f"Policy warning for {package_name}: {message}")
if not allow_continue:
# TODO: Implement user confirmation
logger.info("User confirmation required (not implemented, continuing)")
# Build final package list
packages_to_install = [final_package_info] + pinned_packages + additional_packages
# Execute installation
cmd = manager_util.make_pip_cmd(["install"] + packages_to_install)
if final_extra_index_url:
cmd.extend(["--extra-index-url", final_extra_index_url])
try:
subprocess.run(cmd, check=True)
self._invalidate_cache()
if policy_reason:
logger.info(f"Successfully installed {final_package_info}: {policy_reason}")
else:
logger.info(f"Successfully installed {final_package_info}")
return True
except subprocess.CalledProcessError as e:
# Handle installation failure
if pinned_packages and pin_on_failure == "retry_without_pin":
logger.warning(f"Installation failed with pinned dependencies, retrying without pins")
retry_cmd = manager_util.make_pip_cmd(["install", final_package_info])
if final_extra_index_url:
retry_cmd.extend(["--extra-index-url", final_extra_index_url])
try:
subprocess.run(retry_cmd, check=True)
self._invalidate_cache()
logger.info(f"Successfully installed {final_package_info} (without pins)")
return True
except subprocess.CalledProcessError as retry_error:
logger.error(f"Retry installation also failed: {retry_error}")
raise
elif pin_on_failure == "fail":
logger.error(f"Installation failed: {e}")
raise
else:
logger.warning(f"Installation failed, but continuing: {e}")
return False
def ensure_not_installed(self) -> List[str]:
"""
Remove all packages matching uninstall policies (batch processing).
Iterates through all package policies and executes uninstall actions
where conditions are satisfied.
Returns:
List of removed package names
Example:
>>> with PipBatch() as batch:
... removed = batch.ensure_not_installed()
... print(f"Removed: {removed}")
"""
# Get policy (lazy loading)
pip_policy = get_pip_policy()
installed_packages = self._get_installed_packages()
removed_packages = []
for package_name, policy in pip_policy.items():
uninstall_policies = policy.get("uninstall", [])
for uninstall_policy in uninstall_policies:
condition = uninstall_policy.get("condition")
if self._evaluate_condition(condition, package_name, installed_packages):
target = uninstall_policy.get("target")
reason = uninstall_policy.get("reason", "No reason provided")
# Check if target is installed
if target in installed_packages:
try:
cmd = manager_util.make_pip_cmd(["uninstall", "-y", target])
subprocess.run(cmd, check=True)
logger.info(f"Uninstalled {target}: {reason}")
removed_packages.append(target)
# Remove from cache
del installed_packages[target]
except subprocess.CalledProcessError as e:
logger.warning(f"Failed to uninstall {target}: {e}")
# First match only per package
break
return removed_packages
def ensure_installed(self) -> List[str]:
"""
Restore all packages matching restore policies (batch processing).
Iterates through all package policies and executes restore actions
where conditions are satisfied.
Returns:
List of restored package names
Example:
>>> with PipBatch() as batch:
... batch.install("numpy>=1.20")
... restored = batch.ensure_installed()
... print(f"Restored: {restored}")
"""
# Get policy (lazy loading)
pip_policy = get_pip_policy()
installed_packages = self._get_installed_packages()
restored_packages = []
for package_name, policy in pip_policy.items():
restore_policies = policy.get("restore", [])
for restore_policy in restore_policies:
condition = restore_policy.get("condition")
if self._evaluate_condition(condition, package_name, installed_packages):
target = restore_policy.get("target")
version = restore_policy.get("version")
reason = restore_policy.get("reason", "No reason provided")
extra_index_url = restore_policy.get("extra_index_url")
# Check if target needs restoration
current_version = installed_packages.get(target)
if current_version is None or current_version != version:
try:
package_spec = f"{target}=={version}"
cmd = manager_util.make_pip_cmd(["install", package_spec])
if extra_index_url:
cmd.extend(["--extra-index-url", extra_index_url])
subprocess.run(cmd, check=True)
logger.info(f"Restored {package_spec}: {reason}")
restored_packages.append(target)
# Update cache
installed_packages[target] = version
except subprocess.CalledProcessError as e:
logger.warning(f"Failed to restore {target}: {e}")
# First match only per package
break
return restored_packages

View File

File diff suppressed because it is too large Load Diff

View File

@@ -70,7 +70,6 @@ from .generated_models import (
InstallType,
SecurityLevel,
RiskLevel,
NetworkMode
)
__all__ = [
@@ -135,5 +134,4 @@ __all__ = [
"InstallType",
"SecurityLevel",
"RiskLevel",
"NetworkMode",
]

View File

@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2025-11-01T04:21:38+00:00
# timestamp: 2025-07-31T04:52:26+00:00
from __future__ import annotations
@@ -57,12 +57,7 @@ class ManagerPackInstalled(BaseModel):
description="The version of the pack that is installed (Git commit hash or semantic version)",
)
cnr_id: Optional[str] = Field(
None,
description="The name of the pack if installed from the registry (normalized lowercase)",
)
original_name: Optional[str] = Field(
None,
description="The original case-preserved name of the pack from the registry",
None, description="The name of the pack if installed from the registry"
)
aux_id: Optional[str] = Field(
None,
@@ -112,12 +107,6 @@ class SecurityLevel(str, Enum):
weak = "weak"
class NetworkMode(str, Enum):
public = "public"
private = "private"
offline = "offline"
class RiskLevel(str, Enum):
block = "block"
high_ = "high+"
@@ -166,8 +155,8 @@ class InstallPackParams(ManagerPackInfo):
description="GitHub repository URL (required if selected_version is nightly)",
)
pip: Optional[List[str]] = Field(None, description="PyPi dependency names")
mode: Optional[ManagerDatabaseSource] = None
channel: Optional[ManagerChannel] = None
mode: ManagerDatabaseSource
channel: ManagerChannel
skip_post_install: Optional[bool] = Field(
None, description="Whether to skip post-installation steps"
)
@@ -417,7 +406,9 @@ class ComfyUISystemState(BaseModel):
)
manager_version: Optional[str] = Field(None, description="ComfyUI Manager version")
security_level: Optional[SecurityLevel] = None
network_mode: Optional[NetworkMode] = None
network_mode: Optional[str] = Field(
None, description="Network mode (online, offline, private)"
)
cli_args: Optional[Dict[str, Any]] = Field(
None, description="Selected ComfyUI CLI arguments"
)
@@ -488,13 +479,13 @@ class QueueTaskItem(BaseModel):
params: Union[
InstallPackParams,
UpdatePackParams,
UpdateAllPacksParams,
UpdateComfyUIParams,
FixPackParams,
UninstallPackParams,
DisablePackParams,
EnablePackParams,
ModelMetadata,
UpdateComfyUIParams,
UpdateAllPacksParams,
]

View File

File diff suppressed because it is too large Load Diff

View File

@@ -12,6 +12,7 @@ import json
import logging
import os
import platform
import re
import shutil
import subprocess # don't remove this
import sys
@@ -25,6 +26,7 @@ from typing import Any, Optional
import folder_paths
import latent_preview
import nodes
from aiohttp import web
from comfy.cli_args import args
from pydantic import ValidationError
@@ -33,6 +35,7 @@ from comfyui_manager.glob.utils import (
formatting_utils,
model_utils,
security_utils,
node_pack_utils,
environment_utils,
)
@@ -44,7 +47,6 @@ from ..common import manager_util
from ..common import cm_global
from ..common import manager_downloader
from ..common import context
from ..common import cnr_utils
@@ -59,6 +61,7 @@ from ..data_models import (
ManagerMessageName,
BatchExecutionRecord,
ComfyUISystemState,
ImportFailInfoBulkRequest,
BatchOperation,
InstalledNodeInfo,
ComfyUIVersionInfo,
@@ -213,7 +216,7 @@ class TaskQueue:
history=self.get_history(),
running_queue=self.get_current_queue()[0],
pending_queue=self.get_current_queue()[1],
installed_packs=core.get_installed_nodepacks(),
installed_packs=core.get_installed_node_packs(),
)
@staticmethod
@@ -362,7 +365,11 @@ class TaskQueue:
item.kind,
)
# Force unified_manager to refresh its installed packages cache
core.unified_manager.reload()
await core.unified_manager.reload(
ManagerDatabaseSource.cache.value,
dont_wait=True,
update_cnr_map=False,
)
except Exception as e:
logging.warning(
f"[ComfyUI-Manager] Failed to refresh cache after {item.kind}: {e}"
@@ -612,7 +619,7 @@ class TaskQueue:
installed_nodes = {}
try:
node_packs = core.get_installed_nodepacks()
node_packs = core.get_installed_node_packs()
for pack_name, pack_info in node_packs.items():
# Determine install method and repository URL
install_method = "git" if pack_info.get("aux_id") else "cnr"
@@ -671,12 +678,12 @@ class TaskQueue:
level_str = config.get("security_level", "normal")
# Map the string to SecurityLevel enum
level_mapping = {
"strong": SecurityLevel.STRONG,
"normal": SecurityLevel.NORMAL,
"normal-": SecurityLevel.NORMAL_,
"weak": SecurityLevel.WEAK,
"strong": SecurityLevel.strong,
"normal": SecurityLevel.normal,
"normal-": SecurityLevel.normal_,
"weak": SecurityLevel.weak,
}
return level_mapping.get(level_str, SecurityLevel.NORMAL)
return level_mapping.get(level_str, SecurityLevel.normal)
except Exception:
return None
@@ -696,6 +703,8 @@ class TaskQueue:
cli_args["listen"] = args.listen
if hasattr(args, "port"):
cli_args["port"] = args.port
if hasattr(args, "preview_method"):
cli_args["preview_method"] = str(args.preview_method)
if hasattr(args, "enable_manager_legacy_ui"):
cli_args["enable_manager_legacy_ui"] = args.enable_manager_legacy_ui
if hasattr(args, "front_end_version"):
@@ -709,7 +718,7 @@ class TaskQueue:
def _get_custom_nodes_count(self) -> int:
"""Get total number of custom node packages."""
try:
node_packs = core.get_installed_nodepacks()
node_packs = core.get_installed_node_packs()
return len(node_packs)
except Exception:
return 0
@@ -809,18 +818,24 @@ class TaskQueue:
task_queue = TaskQueue()
# Preview method initialization
if args.preview_method == latent_preview.LatentPreviewMethod.NoPreviews:
environment_utils.set_preview_method(core.get_config()["preview_method"])
else:
logging.warning(
"[ComfyUI-Manager] Since --preview-method is set, ComfyUI-Manager's preview method feature will be ignored."
)
async def task_worker():
logging.debug("[ComfyUI-Manager] Task worker started")
core.unified_manager.reload()
await core.unified_manager.reload(ManagerDatabaseSource.cache.value)
async def do_install(params: InstallPackParams) -> str:
if not security_utils.is_allowed_security_level('middle+'):
logging.error(SECURITY_MESSAGE_MIDDLE_P)
return OperationResult.failed.value
# Note: For install, we use the original case as resolve_node_spec handles lookup
# Normalization is applied for uninstall, enable, disable operations
node_id = params.id
node_version = params.selected_version
channel = params.channel
@@ -876,75 +891,7 @@ async def task_worker():
async def do_enable(params: EnablePackParams) -> str:
cnr_id = params.cnr_id
logging.debug("[ComfyUI-Manager] Enabling node: cnr_id=%s", cnr_id)
# Parse node spec if it contains version/hash (e.g., "NodeName@hash")
node_name = cnr_id
version_spec = None
git_hash = None
if '@' in cnr_id:
node_spec = core.unified_manager.resolve_node_spec(cnr_id)
if node_spec is not None:
parsed_node_name, parsed_version_spec, is_specified = node_spec
logging.debug(
"[ComfyUI-Manager] Parsed node spec: name=%s, version=%s",
parsed_node_name,
parsed_version_spec
)
node_name = parsed_node_name
version_spec = parsed_version_spec
# If version_spec looks like a git hash (40 hex chars), save it for checkout
if parsed_version_spec and len(parsed_version_spec) == 40 and all(c in '0123456789abcdef' for c in parsed_version_spec.lower()):
git_hash = parsed_version_spec
logging.debug("[ComfyUI-Manager] Detected git hash for checkout: %s", git_hash)
else:
# If parsing fails, try splitting manually
parts = cnr_id.split('@')
node_name = parts[0]
if len(parts) > 1:
version_spec = parts[1]
if len(parts[1]) == 40:
git_hash = parts[1]
logging.debug(
"[ComfyUI-Manager] Manual split result: name=%s, version=%s, hash=%s",
node_name,
version_spec,
git_hash
)
# Normalize node_name for case-insensitive matching
node_name = cnr_utils.normalize_package_name(node_name)
# Enable the nodepack with version_spec
res = core.unified_manager.unified_enable(node_name, version_spec)
if not res or not res.result:
return f"Failed to enable: '{cnr_id}'"
# If git hash is specified and enable succeeded, checkout the specific commit
if git_hash and res.target_path:
try:
from . import manager_core
checkout_success = manager_core.checkout_git_commit(res.target_path, git_hash)
if checkout_success:
logging.info(
"[ComfyUI-Manager] Successfully checked out commit %s for %s",
git_hash[:8],
node_name
)
else:
logging.warning(
"[ComfyUI-Manager] Enable succeeded but failed to checkout commit %s for %s",
git_hash[:8],
node_name
)
except Exception as e:
logging.error(
"[ComfyUI-Manager] Enable succeeded but error during git checkout: %s",
e
)
traceback.print_exc()
core.unified_manager.unified_enable(cnr_id)
return OperationResult.success.value
async def do_update(params: UpdatePackParams) -> dict[str, str]:
@@ -958,38 +905,15 @@ async def task_worker():
try:
res = core.unified_manager.unified_update(node_name, node_ver)
# Get active package using modern unified manager
active_pack = core.unified_manager.get_active_pack(node_name)
if active_pack is None:
# Fallback if package not found
url = None
title = node_name
elif res.ver == "unknown":
# For unknown packages, use repo_url if available
url = active_pack.repo_url
if res.ver == "unknown":
url = core.unified_manager.unknown_active_nodes[node_name][0]
try:
title = os.path.basename(url) if url else node_name
title = os.path.basename(url)
except Exception:
title = node_name
else:
# For CNR packages, get info from CNR registry
try:
from ..common import cnr_utils
compact_url = core.git_utils.compact_url(active_pack.repo_url) if active_pack.repo_url else None
cnr_info = cnr_utils.get_nodepack_by_url(compact_url) if compact_url else None
if cnr_info:
url = cnr_info.get("repository")
title = cnr_info.get("name", node_name)
else:
# Fallback for CNR packages without registry info
url = active_pack.repo_url
title = node_name
except Exception:
# Fallback if CNR lookup fails
url = active_pack.repo_url
title = node_name
url = core.unified_manager.cnr_map[node_name].get("repository")
title = core.unified_manager.cnr_map[node_name]["name"]
manager_util.clear_pip_cache()
@@ -1088,13 +1012,17 @@ async def task_worker():
logging.error(SECURITY_MESSAGE_MIDDLE)
return OperationResult.failed.value
# Normalize node_name for case-insensitive matching
node_name = cnr_utils.normalize_package_name(params.node_name)
node_name = params.node_name
is_unknown = params.is_unknown
logging.debug("[ComfyUI-Manager] Uninstalling node: name=%s", node_name)
logging.debug(
"[ComfyUI-Manager] Uninstalling node: name=%s, is_unknown=%s",
node_name,
is_unknown,
)
try:
res = core.unified_manager.unified_uninstall(node_name)
res = core.unified_manager.unified_uninstall(node_name, is_unknown)
if res.result:
return OperationResult.success.value
@@ -1110,33 +1038,14 @@ async def task_worker():
async def do_disable(params: DisablePackParams) -> str:
node_name = params.node_name
logging.debug("[ComfyUI-Manager] Disabling node: name=%s", node_name)
logging.debug(
"[ComfyUI-Manager] Disabling node: name=%s, is_unknown=%s",
node_name,
params.is_unknown,
)
try:
# Parse node spec if it contains version/hash (e.g., "NodeName@hash")
# Extract just the node name for disable operation
if '@' in node_name:
node_spec = core.unified_manager.resolve_node_spec(node_name)
if node_spec is not None:
parsed_node_name, version_spec, is_specified = node_spec
logging.debug(
"[ComfyUI-Manager] Parsed node spec: name=%s, version=%s",
parsed_node_name,
version_spec
)
node_name = parsed_node_name
else:
# If parsing fails, try splitting manually
node_name = node_name.split('@')[0]
logging.debug(
"[ComfyUI-Manager] Manual split result: name=%s",
node_name
)
# Normalize node_name for case-insensitive matching
node_name = cnr_utils.normalize_package_name(node_name)
res = core.unified_manager.unified_disable(node_name)
res = core.unified_manager.unified_disable(node_name, params.is_unknown)
if res:
return OperationResult.success.value
@@ -1246,9 +1155,6 @@ async def task_worker():
item, task_index = task
kind = item.kind
# Reload installed packages before each task to ensure we have the latest state
core.unified_manager.reload()
logging.debug(
"[ComfyUI-Manager] Processing task: kind=%s, ui_id=%s, client_id=%s, task_index=%d",
kind,
@@ -1451,16 +1357,7 @@ async def get_history(request):
}
history = filtered_history
# Convert TaskHistoryItem models to JSON-serializable dicts
if isinstance(history, dict):
history_json = {
task_id: task_data.model_dump(mode="json") if hasattr(task_data, "model_dump") else task_data
for task_id, task_data in history.items()
}
else:
history_json = history.model_dump(mode="json") if hasattr(history, "model_dump") else history
return web.json_response({"history": history_json}, content_type="application/json")
return web.json_response({"history": history}, content_type="application/json")
except Exception as e:
logging.error(f"[ComfyUI-Manager] /v2/manager/queue/history - {e}")
@@ -1468,6 +1365,42 @@ async def get_history(request):
return web.Response(status=400)
@routes.get("/v2/customnode/getmappings")
async def fetch_customnode_mappings(request):
"""
provide unified (node -> node pack) mapping list
"""
mode = request.rel_url.query["mode"]
nickname_mode = False
if mode == "nickname":
mode = "local"
nickname_mode = True
json_obj = await core.get_data_by_mode(mode, "extension-node-map.json")
json_obj = core.map_to_unified_keys(json_obj)
if nickname_mode:
json_obj = node_pack_utils.nickname_filter(json_obj)
all_nodes = set()
patterns = []
for k, x in json_obj.items():
all_nodes.update(set(x[0]))
if "nodename_pattern" in x[1]:
patterns.append((x[1]["nodename_pattern"], x[0]))
missing_nodes = set(nodes.NODE_CLASS_MAPPINGS.keys()) - all_nodes
for x in missing_nodes:
for pat, item in patterns:
if re.match(pat, x):
item.append(x)
return web.json_response(json_obj, content_type="application/json")
@routes.get("/v2/customnode/fetch_updates")
async def fetch_updates(request):
"""
@@ -1515,22 +1448,44 @@ async def _update_all(params: UpdateAllQueryParams) -> web.Response:
mode,
)
if mode == ManagerDatabaseSource.local.value:
channel = "local"
else:
channel = core.get_config()["channel_url"]
await core.unified_manager.reload(mode)
await core.unified_manager.get_custom_nodes(channel, mode)
update_count = 0
# Iterate through all installed packages using modern unified manager
for packname, package_list in core.unified_manager.installed_node_packages.items():
# Find enabled packages for this packname
for package in package_list:
if package.is_enabled:
update_task = QueueTaskItem(
kind=OperationType.update.value,
ui_id=f"{base_ui_id}_{packname}", # Use client's base ui_id + node name
client_id=client_id,
params=UpdatePackParams(node_name=packname, node_ver=package.version),
)
task_queue.put(update_task)
update_count += 1
# Only create one update task per packname (first enabled package)
break
for k, v in core.unified_manager.active_nodes.items():
if k == "comfyui-manager":
# skip updating comfyui-manager if desktop version
if os.environ.get("__COMFYUI_DESKTOP_VERSION__"):
continue
update_task = QueueTaskItem(
kind=OperationType.update.value,
ui_id=f"{base_ui_id}_{k}", # Use client's base ui_id + node name
client_id=client_id,
params=UpdatePackParams(node_name=k, node_ver=v[0]),
)
task_queue.put(update_task)
update_count += 1
for k, v in core.unified_manager.unknown_active_nodes.items():
if k == "comfyui-manager":
# skip updating comfyui-manager if desktop version
if os.environ.get("__COMFYUI_DESKTOP_VERSION__"):
continue
update_task = QueueTaskItem(
kind=OperationType.update.value,
ui_id=f"{base_ui_id}_{k}", # Use client's base ui_id + node name
client_id=client_id,
params=UpdatePackParams(node_name=k, node_ver="unknown"),
)
task_queue.put(update_task)
update_count += 1
logging.debug(
"[ComfyUI-Manager] Update all queued %d tasks for client_id=%s",
@@ -1550,7 +1505,7 @@ async def is_legacy_manager_ui(request):
# freeze imported version
startup_time_installed_node_packs = core.get_installed_nodepacks()
startup_time_installed_node_packs = core.get_installed_node_packs()
@routes.get("/v2/customnode/installed")
@@ -1560,7 +1515,7 @@ async def installed_list(request):
if mode == "imported":
res = startup_time_installed_node_packs
else:
res = core.get_installed_nodepacks()
res = core.get_installed_node_packs()
return web.json_response(res, content_type="application/json")
@@ -1706,53 +1661,58 @@ async def import_fail_info(request):
async def import_fail_info_bulk(request):
try:
json_data = await request.json()
# Basic validation - ensure we have either cnr_ids or urls
if not isinstance(json_data, dict):
return web.Response(status=400, text="Request body must be a JSON object")
if "cnr_ids" not in json_data and "urls" not in json_data:
# Validate input using Pydantic model
request_data = ImportFailInfoBulkRequest.model_validate(json_data)
# Ensure we have either cnr_ids or urls
if not request_data.cnr_ids and not request_data.urls:
return web.Response(
status=400, text="Either 'cnr_ids' or 'urls' field is required"
)
await core.unified_manager.reload('cache')
await core.unified_manager.get_custom_nodes('default', 'cache')
results = {}
if "cnr_ids" in json_data:
if not isinstance(json_data["cnr_ids"], list):
return web.Response(status=400, text="'cnr_ids' must be an array")
for cnr_id in json_data["cnr_ids"]:
if not isinstance(cnr_id, str):
results[cnr_id] = {"error": "cnr_id must be a string"}
continue
if request_data.cnr_ids:
for cnr_id in request_data.cnr_ids:
module_name = core.unified_manager.get_module_name(cnr_id)
if module_name is not None:
info = cm_global.error_dict.get(module_name)
if info is not None:
results[cnr_id] = info
# Convert error_dict format to API spec format
results[cnr_id] = {
'error': info.get('msg', ''),
'traceback': info.get('traceback', '')
}
else:
results[cnr_id] = None
else:
results[cnr_id] = None
if "urls" in json_data:
if not isinstance(json_data["urls"], list):
return web.Response(status=400, text="'urls' must be an array")
for url in json_data["urls"]:
if not isinstance(url, str):
results[url] = {"error": "url must be a string"}
continue
if request_data.urls:
for url in request_data.urls:
module_name = core.unified_manager.get_module_name(url)
if module_name is not None:
info = cm_global.error_dict.get(module_name)
if info is not None:
results[url] = info
# Convert error_dict format to API spec format
results[url] = {
'error': info.get('msg', ''),
'traceback': info.get('traceback', '')
}
else:
results[url] = None
else:
results[url] = None
return web.json_response(results)
# Return results directly as JSON
return web.json_response(results, content_type="application/json")
except ValidationError as e:
logging.error(f"[ComfyUI-Manager] Invalid request data: {e}")
return web.Response(status=400, text=f"Invalid request data: {e}")
except Exception as e:
logging.error(f"[ComfyUI-Manager] Error processing bulk import fail info: {e}")
return web.Response(status=500, text="Internal server error")
@@ -2034,6 +1994,91 @@ async def get_version(request):
return web.Response(text=core.version_str, status=200)
async def _confirm_try_install(sender, custom_node_url, msg):
json_obj = await core.get_data_by_mode("default", "custom-node-list.json")
sender = manager_util.sanitize_tag(sender)
msg = manager_util.sanitize_tag(msg)
target = core.lookup_customnode_by_url(json_obj, custom_node_url)
if target is not None:
PromptServer.instance.send_sync(
"cm-api-try-install-customnode",
{"sender": sender, "target": target, "msg": msg},
)
else:
logging.error(
f"[ComfyUI Manager API] Failed to try install - Unknown custom node url '{custom_node_url}'"
)
def confirm_try_install(sender, custom_node_url, msg):
asyncio.run(_confirm_try_install(sender, custom_node_url, msg))
cm_global.register_api("cm.try-install-custom-node", confirm_try_install)
async def default_cache_update():
core.refresh_channel_dict()
channel_url = core.get_config()["channel_url"]
async def get_cache(filename):
try:
if core.get_config()["default_cache_as_channel_url"]:
uri = f"{channel_url}/{filename}"
else:
uri = f"{core.DEFAULT_CHANNEL}/{filename}"
cache_uri = str(manager_util.simple_hash(uri)) + "_" + filename
cache_uri = os.path.join(manager_util.cache_dir, cache_uri)
json_obj = await manager_util.get_data(uri, True)
with manager_util.cache_lock:
with open(cache_uri, "w", encoding="utf-8") as file:
json.dump(json_obj, file, indent=4, sort_keys=True)
logging.debug(f"[ComfyUI-Manager] default cache updated: {uri}")
except Exception as e:
logging.error(
f"[ComfyUI-Manager] Failed to perform initial fetching '{filename}': {e}"
)
traceback.print_exc()
if (
core.get_config()["network_mode"] != "offline"
and not manager_util.is_manager_pip_package()
):
a = get_cache("custom-node-list.json")
b = get_cache("extension-node-map.json")
c = get_cache("model-list.json")
d = get_cache("alter-list.json")
e = get_cache("github-stats.json")
await asyncio.gather(a, b, c, d, e)
if core.get_config()["network_mode"] == "private":
logging.info(
"[ComfyUI-Manager] The private comfyregistry is not yet supported in `network_mode=private`."
)
else:
# load at least once
await core.unified_manager.reload(
ManagerDatabaseSource.remote.value, dont_wait=False
)
await core.unified_manager.get_custom_nodes(
channel_url, ManagerDatabaseSource.remote.value
)
else:
await core.unified_manager.reload(
ManagerDatabaseSource.remote.value, dont_wait=False, update_cnr_map=False
)
logging.info("[ComfyUI-Manager] All startup tasks have been completed.")
threading.Thread(target=lambda: asyncio.run(default_cache_update())).start()
if not os.path.exists(context.manager_config_path):
core.get_config()
core.write_config()

View File

@@ -17,6 +17,25 @@ def get_model_dir(data, show_log=False):
if any(char in data["filename"] for char in {"/", "\\", ":"}):
return None
def resolve_custom_node(save_path):
save_path = save_path[13:] # remove 'custom_nodes/'
# NOTE: Validate to prevent path traversal.
if save_path.startswith(os.path.sep) or ":" in save_path:
return None
repo_name = save_path.replace("\\", "/").split("/")[
0
] # get custom node repo name
# NOTE: The creation of files within the custom node path should be removed in the future.
repo_path = core.lookup_installed_custom_nodes_legacy(repo_name)
if repo_path is not None and repo_path[0]:
# Returns the retargeted path based on the actually installed repository
return os.path.join(os.path.dirname(repo_path[1]), save_path)
else:
return None
if data["save_path"] != "default":
if ".." in data["save_path"] or data["save_path"].startswith("/"):
if show_log:
@@ -26,8 +45,13 @@ def get_model_dir(data, show_log=False):
base_model = os.path.join(models_base, "etc")
else:
if data["save_path"].startswith("custom_nodes"):
logging.warning("The feature to download models into the custom node path is no longer supported.")
return None
base_model = resolve_custom_node(data["save_path"])
if base_model is None:
if show_log:
logging.info(
f"[ComfyUI-Manager] The target custom node for model download is not installed: {data['save_path']}"
)
return None
else:
base_model = os.path.join(models_base, data["save_path"])
else:

View File

@@ -0,0 +1,65 @@
import concurrent.futures
from comfyui_manager.glob import manager_core as core
def check_state_of_git_node_pack(
node_packs, do_fetch=False, do_update_check=True, do_update=False
):
if do_fetch:
print("Start fetching...", end="")
elif do_update:
print("Start updating...", end="")
elif do_update_check:
print("Start update check...", end="")
def process_custom_node(item):
core.check_state_of_git_node_pack_single(
item, do_fetch, do_update_check, do_update
)
with concurrent.futures.ThreadPoolExecutor(4) as executor:
for k, v in node_packs.items():
if v.get("active_version") in ["unknown", "nightly"]:
executor.submit(process_custom_node, v)
if do_fetch:
print("\x1b[2K\rFetching done.")
elif do_update:
update_exists = any(
item.get("updatable", False) for item in node_packs.values()
)
if update_exists:
print("\x1b[2K\rUpdate done.")
else:
print("\x1b[2K\rAll extensions are already up-to-date.")
elif do_update_check:
print("\x1b[2K\rUpdate check done.")
def nickname_filter(json_obj):
preemptions_map = {}
for k, x in json_obj.items():
if "preemptions" in x[1]:
for y in x[1]["preemptions"]:
preemptions_map[y] = k
elif k.endswith("/ComfyUI"):
for y in x[0]:
preemptions_map[y] = k
updates = {}
for k, x in json_obj.items():
removes = set()
for y in x[0]:
k2 = preemptions_map.get(y)
if k2 is not None and k != k2:
removes.add(y)
if len(removes) > 0:
updates[k] = [y for y in x[0] if y not in removes]
for k, v in updates.items():
json_obj[k][0] = v
return json_obj

View File

@@ -1,6 +1,6 @@
from comfyui_manager.glob import manager_core as core
from comfy.cli_args import args
from comfyui_manager.data_models import SecurityLevel, RiskLevel
from comfyui_manager.data_models import SecurityLevel, RiskLevel, ManagerDatabaseSource
def is_loopback(address):
@@ -38,3 +38,30 @@ def is_allowed_security_level(level):
return core.get_config()['security_level'] in [SecurityLevel.weak.value, SecurityLevel.normal.value, SecurityLevel.normal_.value]
else:
return True
async def get_risky_level(files, pip_packages):
json_data1 = await core.get_data_by_mode(ManagerDatabaseSource.local.value, "custom-node-list.json")
json_data2 = await core.get_data_by_mode(
ManagerDatabaseSource.cache.value,
"custom-node-list.json",
channel_url="https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main",
)
all_urls = set()
for x in json_data1["custom_nodes"] + json_data2["custom_nodes"]:
all_urls.update(x.get("files", []))
for x in files:
if x not in all_urls:
return RiskLevel.high_.value
all_pip_packages = set()
for x in json_data1["custom_nodes"] + json_data2["custom_nodes"]:
all_pip_packages.update(x.get("pip", []))
for p in pip_packages:
if p not in all_pip_packages:
return RiskLevel.block.value
return RiskLevel.middle_.value

View File

@@ -41,11 +41,12 @@ from ..common.enums import NetworkMode, SecurityLevel, DBMode
from ..common import context
version_code = [5, 0]
version_code = [4, 0, 2]
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
DEFAULT_CHANNEL = "https://raw.githubusercontent.com/Comfy-Org/ComfyUI-Manager/main"
DEFAULT_CHANNEL_LEGACY = "https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main"
default_custom_nodes_path = None
@@ -160,7 +161,7 @@ comfy_ui_revision = "Unknown"
comfy_ui_commit_datetime = datetime(1900, 1, 1, 0, 0, 0)
channel_dict = None
valid_channels = {'default', 'local'}
valid_channels = {'default', 'local', DEFAULT_CHANNEL, DEFAULT_CHANNEL_LEGACY}
channel_list = None
@@ -1390,6 +1391,7 @@ class UnifiedManager:
return ManagedResult('skip')
elif self.is_disabled(node_id):
return self.unified_enable(node_id)
else:
version_spec = self.resolve_unspecified_version(node_id)

View File

@@ -1072,12 +1072,15 @@ async def fetch_customnode_list(request):
if channel != 'local':
found = 'custom'
for name, url in core.get_channel_dict().items():
if url == channel:
found = name
break
if channel == core.DEFAULT_CHANNEL or channel == core.DEFAULT_CHANNEL_LEGACY:
channel = 'default'
else:
for name, url in core.get_channel_dict().items():
if url == channel:
found = name
break
channel = found
channel = found
result = dict(channel=channel, node_packs=node_packs.to_dict())

View File

@@ -10,6 +10,16 @@ import hashlib
import folder_paths
from server import PromptServer
import logging
import sys
try:
from nio import AsyncClient, LoginResponse, UploadResponse
matrix_nio_is_available = True
except Exception:
logging.warning(f"[ComfyUI-Manager] The matrix sharing feature has been disabled because the `matrix-nio` dependency is not installed.\n\tTo use this feature, please run the following command:\n\t{sys.executable} -m pip install matrix-nio\n")
matrix_nio_is_available = False
def extract_model_file_names(json_data):
@@ -192,6 +202,14 @@ async def get_esheep_workflow_and_images(request):
return web.Response(status=200, text=json.dumps(data))
@PromptServer.instance.routes.get("/v2/manager/get_matrix_dep_status")
async def get_matrix_dep_status(request):
if matrix_nio_is_available:
return web.Response(status=200, text='available')
else:
return web.Response(status=200, text='unavailable')
def set_matrix_auth(json_data):
homeserver = json_data['homeserver']
username = json_data['username']
@@ -331,14 +349,12 @@ async def share_art(request):
workflowId = upload_workflow_json["workflowId"]
# check if the user has provided Matrix credentials
if "matrix" in share_destinations:
if matrix_nio_is_available and "matrix" in share_destinations:
comfyui_share_room_id = '!LGYSoacpJPhIfBqVfb:matrix.org'
filename = os.path.basename(asset_filepath)
content_type = assetFileType
try:
from nio import AsyncClient, LoginResponse, UploadResponse
homeserver = 'matrix.org'
if matrix_auth:
homeserver = matrix_auth.get('homeserver', 'matrix.org')

View File

@@ -1,496 +0,0 @@
# Package Version Management Design
## Overview
ComfyUI Manager supports two package version types, each with distinct installation methods and version switching mechanisms:
1. **CNR Version (Archive)**: Production-ready releases with semantic versioning (e.g., v1.0.2), published to CNR server, verified, and distributed as ZIP archives
2. **Nightly Version**: Real-time development builds from Git repository without semantic versioning, providing direct access to latest code via git pull
## Package ID Normalization
### Case Sensitivity Handling
**Source of Truth**: Package IDs originate from `pyproject.toml` with their original case (e.g., `ComfyUI_SigmoidOffsetScheduler`)
**Normalization Process**:
1. `cnr_utils.normalize_package_name()` provides centralized normalization (`cnr_utils.py:28-48`):
```python
def normalize_package_name(name: str) -> str:
"""
Normalize package name for case-insensitive matching.
- Strip leading/trailing whitespace
- Convert to lowercase
"""
return name.strip().lower()
```
2. `cnr_utils.read_cnr_info()` uses this normalization when indexing (`cnr_utils.py:314`):
```python
name = project.get('name').strip().lower()
```
3. Package indexed in `installed_node_packages` with lowercase ID: `'comfyui_sigmoidoffsetscheduler'`
4. **Critical**: All lookups (`is_enabled()`, `unified_disable()`) must use `cnr_utils.normalize_package_name()` for matching
**Implementation** (`manager_core.py:1374, 1389`):
```python
# Before checking if package is enabled or disabling
packname_normalized = cnr_utils.normalize_package_name(packname)
if self.is_enabled(packname_normalized):
self.unified_disable(packname_normalized)
```
## Package Identification
### How Packages Are Identified
**Critical**: Packages MUST be identified by marker files and metadata, NOT by directory names.
**Identification Flow** (`manager_core.py:691-703`, `node_package.py:49-81`):
```python
def resolve_from_path(fullpath):
"""
Identify package type and ID using markers and metadata files.
Priority:
1. Check for .git directory (Nightly)
2. Check for .tracking + pyproject.toml (CNR)
3. Unknown/legacy (fallback to directory name)
"""
# 1. Nightly Detection
url = git_utils.git_url(fullpath) # Checks for .git/config
if url:
url = git_utils.compact_url(url)
commit_hash = git_utils.get_commit_hash(fullpath)
return {'id': url, 'ver': 'nightly', 'hash': commit_hash}
# 2. CNR Detection
info = cnr_utils.read_cnr_info(fullpath) # Checks for .tracking + pyproject.toml
if info:
return {'id': info['id'], 'ver': info['version']}
# 3. Unknown (fallback)
return None
```
### Marker-Based Identification
**1. Nightly Packages**:
- **Marker**: `.git` directory presence
- **ID Extraction**: Read URL from `.git/config` using `git_utils.git_url()` (`git_utils.py:34-53`)
- **ID Format**: Compact URL (e.g., `https://github.com/owner/repo` → compact form)
- **Why**: Git repositories are uniquely identified by their remote URL
**2. CNR Packages**:
- **Markers**: `.tracking` file AND `pyproject.toml` file (`.git` must NOT exist)
- **ID Extraction**: Read `name` from `pyproject.toml` using `cnr_utils.read_cnr_info()` (`cnr_utils.py:302-334`)
- **ID Format**: Normalized lowercase from `pyproject.toml` (e.g., `ComfyUI_Foo` → `comfyui_foo`)
- **Why**: CNR packages are identified by their canonical name in package metadata
**Implementation** (`cnr_utils.py:302-334`):
```python
def read_cnr_info(fullpath):
toml_path = os.path.join(fullpath, 'pyproject.toml')
tracking_path = os.path.join(fullpath, '.tracking')
# MUST have both markers and NO .git directory
if not os.path.exists(toml_path) or not os.path.exists(tracking_path):
return None # not valid CNR node pack
with open(toml_path, "r", encoding="utf-8") as f:
data = toml.load(f)
project = data.get('project', {})
name = project.get('name').strip().lower() # ← Normalized for indexing
original_name = project.get('name') # ← Original case preserved
version = str(manager_util.StrictVersion(project.get('version')))
return {
"id": name, # Normalized ID for lookups
"original_name": original_name,
"version": version,
"url": repository
}
```
### Why NOT Directory Names?
**Problem with directory-based identification**:
1. **Case Sensitivity Issues**: Same package can have different directory names
- Active: `ComfyUI_Foo` (original case)
- Disabled: `comfyui_foo@1_0_2` (lowercase)
2. **Version Suffix Confusion**: Disabled directories include version in name
3. **User Modifications**: Users can rename directories, breaking identification
**Correct Approach**:
- **Source of Truth**: Marker files (`.git`, `.tracking`, `pyproject.toml`)
- **Consistent IDs**: Based on metadata content, not filesystem names
- **Case Insensitive**: Normalized lookups work regardless of directory name
### Package Lookup Flow
**Index Building** (`manager_core.py:444-478`):
```python
def reload(self):
self.installed_node_packages: dict[str, list[InstalledNodePackage]] = defaultdict(list)
# Scan active packages
for x in os.listdir(custom_nodes_path):
fullpath = os.path.join(custom_nodes_path, x)
if x not in ['__pycache__', '.disabled']:
node_package = InstalledNodePackage.from_fullpath(fullpath, self.resolve_from_path)
# ↓ Uses ID from resolve_from_path(), NOT directory name
self.installed_node_packages[node_package.id].append(node_package)
# Scan disabled packages
for x in os.listdir(disabled_dir):
fullpath = os.path.join(disabled_dir, x)
node_package = InstalledNodePackage.from_fullpath(fullpath, self.resolve_from_path)
# ↓ Same ID extraction, consistent indexing
self.installed_node_packages[node_package.id].append(node_package)
```
**Lookup Process**:
1. Normalize search term: `cnr_utils.normalize_package_name(packname)`
2. Look up in `installed_node_packages` dict by normalized ID
3. Match found packages by version if needed
4. Return `InstalledNodePackage` objects with full metadata
### Edge Cases
**1. Package with `.git` AND `.tracking`**:
- **Detection**: Treated as Nightly (`.git` checked first)
- **Reason**: Git repo takes precedence over archive markers
- **Fix**: Remove `.tracking` file to avoid confusion
**2. Missing Marker Files**:
- **CNR without `.tracking`**: Treated as Unknown
- **Nightly without `.git`**: Treated as Unknown or CNR (if has `.tracking`)
- **Recovery**: Re-install package to restore correct markers
**3. Corrupted `pyproject.toml`**:
- **Detection**: `read_cnr_info()` returns `None`
- **Result**: Package treated as Unknown
- **Recovery**: Manual fix or re-install
## Version Types
ComfyUI Manager supports two main package version types:
### 1. CNR Version (Comfy Node Registry - Versioned Releases)
**Also known as**: Archive version (because it's distributed as ZIP archive)
**Purpose**: Production-ready releases that have been versioned, published to CNR server, and verified before distribution
**Characteristics**:
- Semantic versioning assigned (e.g., v1.0.2, v2.1.0)
- Published to CNR server with verification process
- Stable, tested releases for production use
- Distributed as ZIP archives for reliability
**Installation Method**: ZIP file extraction from CNR (Comfy Node Registry)
**Identification**:
- Presence of `.tracking` file in package directory
- **Directory naming**:
- **Active** (`custom_nodes/`): Uses `name` from `pyproject.toml` with original case (e.g., `ComfyUI_SigmoidOffsetScheduler`)
- This is the `original_name` in glob/ implementation
- **Disabled** (`.disabled/`): Uses `{package_name}@{version}` format (e.g., `comfyui_sigmoidoffsetscheduler@1_0_2`)
- Package indexed with lowercase ID from `pyproject.toml`
- Versioned releases (e.g., v1.0.2, v2.1.0)
**`.tracking` File Purpose**:
- **Primary**: Marker to identify this as a CNR/archive installation
- **Critical**: Contains list of original files from the archive
- **Update Use Case**: When updating to a new version:
1. Read `.tracking` to identify original archive files
2. Delete ONLY original archive files
3. Preserve user-generated files (configs, models, custom code)
4. Extract new archive version
5. Update `.tracking` with new file list
**File Structure**:
```
custom_nodes/
ComfyUI_SigmoidOffsetScheduler/
.tracking # List of original archive files
pyproject.toml # name = "ComfyUI_SigmoidOffsetScheduler"
__init__.py
nodes.py
(user-created files preserved during update)
```
### 2. Nightly Version (Development Builds)
**Purpose**: Real-time development builds from Git repository without semantic versioning
**Characteristics**:
- No semantic version assigned (version = "nightly")
- Direct access to latest development code
- Real-time updates via git pull
- For testing, development, and early adoption
- Not verified through CNR publication process
**Installation Method**: Git repository clone
**Identification**:
- Presence of `.git` directory in package directory
- `version: "nightly"` in package metadata
- **Directory naming**:
- **Active** (`custom_nodes/`): Uses `name` from `pyproject.toml` with original case (e.g., `ComfyUI_SigmoidOffsetScheduler`)
- This is the `original_name` in glob/ implementation
- **Disabled** (`.disabled/`): Uses `{package_name}@nightly` format (e.g., `comfyui_sigmoidoffsetscheduler@nightly`)
**Update Mechanism**:
- `git pull` on existing repository
- All user modifications in git working tree preserved by git
**File Structure**:
```
custom_nodes/
ComfyUI_SigmoidOffsetScheduler/
.git/ # Git repository marker
pyproject.toml
__init__.py
nodes.py
(git tracks all changes)
```
## Version Switching Mechanisms
### CNR ↔ Nightly (Uses `.disabled/` Directory)
**Mechanism**: Enable/disable toggling - only ONE version active at a time
**Process**:
1. **CNR → Nightly**:
```
Before: custom_nodes/ComfyUI_SigmoidOffsetScheduler/ (has .tracking)
After: custom_nodes/ComfyUI_SigmoidOffsetScheduler/ (has .git)
.disabled/comfyui_sigmoidoffsetscheduler@1_0_2/ (has .tracking)
```
- Move archive directory to `.disabled/comfyui_sigmoidoffsetscheduler@{version}/`
- Git clone nightly to `custom_nodes/ComfyUI_SigmoidOffsetScheduler/`
2. **Nightly → CNR**:
```
Before: custom_nodes/ComfyUI_SigmoidOffsetScheduler/ (has .git)
.disabled/comfyui_sigmoidoffsetscheduler@1_0_2/ (has .tracking)
After: custom_nodes/ComfyUI_SigmoidOffsetScheduler/ (has .tracking)
.disabled/comfyui_sigmoidoffsetscheduler@nightly/ (has .git)
```
- Move nightly directory to `.disabled/comfyui_sigmoidoffsetscheduler@nightly/`
- Restore archive from `.disabled/comfyui_sigmoidoffsetscheduler@{version}/`
**Key Points**:
- Both versions preserved in filesystem (one in `.disabled/`)
- Switching is fast (just move operations)
- No re-download needed when switching back
### CNR Version Update (In-Place Update)
**Mechanism**: Direct directory content update - NO `.disabled/` directory used
**When**: Switching between different CNR versions (e.g., v1.0.1 → v1.0.2)
**Process**:
```
Before: custom_nodes/ComfyUI_SigmoidOffsetScheduler/ (v1.0.1, has .tracking)
After: custom_nodes/ComfyUI_SigmoidOffsetScheduler/ (v1.0.2, has .tracking)
```
**Steps**:
1. Read `.tracking` to identify original v1.0.1 files
2. Delete only original v1.0.1 files (preserve user-created files)
3. Extract v1.0.2 archive to same directory
4. Update `.tracking` with v1.0.2 file list
5. Update `pyproject.toml` version metadata
**Critical**: Directory name and location remain unchanged
## API Design Decisions
### Enable/Disable Operations
**Design Decision**: ❌ **NO DIRECT ENABLE/DISABLE API PROVIDED**
**Rationale**:
- Enable/disable operations occur **ONLY as a by-product** of version switching
- Version switching is the primary operation that manages package state
- Direct enable/disable API would:
1. Create ambiguity about which version to enable/disable
2. Bypass version management logic
3. Lead to inconsistent package state
**Implementation**:
- `unified_enable()` and `unified_disable()` are **internal methods only**
- Called exclusively from version switching operations:
- `install_by_id()` (manager_core.py:1695-1724)
- `cnr_switch_version_instant()` (manager_core.py:941)
- `repo_update()` (manager_core.py:2144-2232)
**User Workflow**:
```
User wants to disable CNR version and enable Nightly:
✅ Correct: install(package, version="nightly")
→ automatically disables CNR, enables Nightly
❌ Wrong: disable(package) + enable(package, "nightly")
→ not supported, ambiguous
```
**Testing Approach**:
- Enable/disable tested **indirectly** through version switching tests
- Test 1-12 validate enable/disable behavior via install/update operations
- No direct enable/disable API tests needed (API doesn't exist)
## Implementation Details
### Version Detection Logic
**Location**: `comfyui_manager/common/node_package.py`
```python
@dataclass
class InstalledNodePackage:
@property
def is_nightly(self) -> bool:
return self.version == "nightly"
@property
def is_from_cnr(self) -> bool:
return not self.is_unknown and not self.is_nightly
```
**Detection Order**:
1. Check for `.tracking` file → CNR (Archive) version
2. Check for `.git` directory → Nightly version
3. Otherwise → Unknown/legacy
### Reload Timing
**Critical**: `unified_manager.reload()` must be called:
1. **Before each queued task** (`manager_server.py:1245`):
```python
# Reload installed packages before each task to ensure latest state
core.unified_manager.reload()
```
2. **Before version switching** (`manager_core.py:1370`):
```python
# Reload to ensure we have the latest package state before checking
self.reload()
```
**Why**: Ensures `installed_node_packages` dict reflects actual filesystem state
### Disable Mechanism
**Implementation** (`manager_core.py:982-1017`, specifically line 1011):
```python
def unified_disable(self, packname: str):
# ... validation logic ...
# Generate disabled directory name with version suffix
base_path = extract_base_custom_nodes_dir(matched_active.fullpath)
folder_name = packname if not self.is_url_like(packname) else os.path.basename(matched_active.fullpath)
to_path = os.path.join(base_path, '.disabled', f"{folder_name}@{matched_active.version.replace('.', '_')}")
shutil.move(matched_active.fullpath, to_path)
```
**Naming Convention**:
- `{folder_name}@{version}` format for ALL version types
- CNR v1.0.2 → `comfyui_foo@1_0_2` (dots replaced with underscores)
- Nightly → `comfyui_foo@nightly`
### Case Sensitivity Fix
**Problem**: Package IDs normalized to lowercase during indexing but not during lookup
**Solution** (`manager_core.py:1372-1378, 1388-1393`):
```python
# Normalize packname using centralized cnr_utils function
# CNR packages are indexed with lowercase IDs from pyproject.toml
packname_normalized = cnr_utils.normalize_package_name(packname)
if self.is_enabled(packname_normalized):
self.unified_disable(packname_normalized)
```
**Why Centralized Function**:
- Consistent normalization across entire codebase
- Single source of truth for package name normalization logic
- Easier to maintain and test
- Located in `cnr_utils.py:28-48`
## Directory Structure Examples
### Complete Example: All Version Types Coexisting
```
custom_nodes/
ComfyUI_SigmoidOffsetScheduler/ # Active version (CNR v2.0.0 in this example)
pyproject.toml # name = "ComfyUI_SigmoidOffsetScheduler"
__init__.py
nodes.py
.disabled/ # Inactive versions storage
comfyui_sigmoidoffsetscheduler@nightly/ # ← Nightly (disabled)
.git/ # ← Nightly marker
pyproject.toml
__init__.py
nodes.py
comfyui_sigmoidoffsetscheduler@1_0_2/ # ← CNR v1.0.2 (disabled)
.tracking # ← CNR marker with file list
pyproject.toml
__init__.py
nodes.py
comfyui_sigmoidoffsetscheduler@1_0_1/ # ← CNR v1.0.1 (disabled)
.tracking
pyproject.toml
__init__.py
nodes.py
```
**Key Points**:
- Active directory ALWAYS uses `original_name` without version suffix
- Each disabled version has `@{version}` suffix to avoid conflicts
- Multiple disabled versions can coexist (nightly + multiple CNR versions)
## Summary Table
| Version Type | Purpose | Marker | Active Directory Name | Disabled Directory Name | Update Method | Switch Mechanism |
|--------------|---------|--------|----------------------|------------------------|---------------|------------------|
| **CNR** (Archive) | Production-ready releases with semantic versioning, published to CNR server and verified | `.tracking` file | `original_name` (e.g., `ComfyUI_Foo`) | `{package}@{version}` (e.g., `comfyui_foo@1_0_2`) | In-place update (preserve user files) | `.disabled/` toggle |
| **Nightly** | Real-time development builds from Git repository without semantic versioning | `.git/` directory | `original_name` (e.g., `ComfyUI_Foo`) | `{package}@nightly` (e.g., `comfyui_foo@nightly`) | `git pull` | `.disabled/` toggle |
**Important Constraints**:
- **Active directory name**: MUST use `original_name` (from `pyproject.toml`) without version suffix
- Other code may depend on this specific directory name
- Only ONE version can be active at a time
- **Disabled directory name**: MUST include `@{version}` suffix to allow multiple disabled versions to coexist
- CNR: `@{version}` (e.g., `@1_0_2`)
- Nightly: `@nightly`
## Edge Cases
### 1. Multiple CNR Versions
- Each stored in `.disabled/` with version suffix
- Only one can be active at a time
- Switching between CNR versions = direct content update (not via `.disabled/`)
### 2. Package ID Case Variations
- Always normalize to lowercase for internal lookups
- Preserve original case in filesystem/display
- Match against lowercase indexed keys
### 3. Corrupted `.tracking` File
- Treat as unknown version type
- Warn user before update/uninstall
- May require manual cleanup
### 4. Mixed CNR + Nightly in `.disabled/`
- Both can coexist in `.disabled/`
- Only one can be active in `custom_nodes/`
- Switch logic detects type and handles appropriately

View File

@@ -1,235 +0,0 @@
# Security-Enhanced URL Installation System
## Overview
Security constraints have been added to the `install_by_url` function to control URL-based installations according to the system's security level.
## Security Level and Risk Level Framework
### Security Levels (SecurityLevel)
- **strong**: Most restrictive, only trusted sources allowed
- **normal**: Standard security, most known platforms allowed
- **normal-**: Relaxed security, additional allowances for personal cloud environments
- **weak**: Most permissive security, for local development environments
### Risk Levels (RiskLevel)
- **block**: Complete block (always denied)
- **high+**: Very high risk (only allowed in local mode + weak/normal-)
- **high**: High risk (only allowed in local mode + weak/normal- or personal cloud + weak)
- **middle+**: Medium-high risk (weak/normal/normal- allowed in local/personal cloud)
- **middle**: Medium risk (weak/normal/normal- allowed in all environments)
## URL Risk Assessment Logic
### Low Risk (middle) - Trusted Platforms
```
- github.com
- gitlab.com
- bitbucket.org
- raw.githubusercontent.com
- gitlab.io
```
### High Risk (high+) - Suspicious/Local Hosting
```
- localhost, 127.0.0.1
- Private IP ranges: 192.168.*, 10.0.*, 172.*
- Temporary hosting: ngrok.io, herokuapp.com, repl.it, glitch.me
```
### Medium-High Risk (middle+) - Unknown Domains
```
- All domains not belonging to the above categories
```
### High Risk (high) - SSH Protocol
```
- URLs starting with ssh:// or git@
```
## Implemented Security Features
### 1. Security Validation (`_validate_url_security`)
```python
async def install_by_url(self, url: str, ...):
# Security validation
security_result = self._validate_url_security(url)
if not security_result['allowed']:
return self._report_failed_install_security(url, security_result['reason'], custom_name)
```
**Features**:
- Check current security level
- Assess URL risk
- Allow/block decision based on security policy
### 2. Failure Reporting (`_report_failed_install_security`)
```python
def _report_failed_install_security(self, url: str, reason: str, custom_name=None):
# Security block logging
print(f"[SECURITY] Blocked URL installation: {url}")
# Record failed installation
self._record_failed_install_nodepack({
'type': 'url-security-block',
'url': url,
'package_name': pack_name,
'reason': reason,
'security_level': current_security_level,
'timestamp': timestamp
})
```
**Features**:
- Log blocked installation attempts to console
- Save failure information in structured format
- Return failure result as ManagedResult
### 3. Failed Installation Record Management (`_record_failed_install_nodepack`)
```python
def get_failed_install_reports(self) -> list:
return getattr(self, '_failed_installs', [])
```
**Features**:
- Maintain recent 100 failure records
- Prevent memory overflow
- Provide API for monitoring and debugging
## Usage Examples
### Behavior by Security Setting
#### Strong Security Level
```python
# Most URLs are blocked
result = await manager.install_by_url("https://github.com/user/repo")
# Result: Blocked (github is also middle risk, so blocked at strong level)
result = await manager.install_by_url("https://suspicious-domain.com/repo.git")
# Result: Blocked (middle+ risk)
```
#### Normal Security Level
```python
# Trusted platforms allowed
result = await manager.install_by_url("https://github.com/user/repo")
# Result: Allowed
result = await manager.install_by_url("https://localhost/repo.git")
# Result: Blocked (high+ risk)
```
#### Weak Security Level (Local Development Environment)
```python
# Almost all URLs allowed
result = await manager.install_by_url("https://github.com/user/repo")
# Result: Allowed
result = await manager.install_by_url("https://192.168.1.100/repo.git")
# Result: Allowed (in local mode)
result = await manager.install_by_url("git@private-server.com:user/repo.git")
# Result: Allowed
```
### Failure Monitoring
```python
manager = UnifiedManager()
# Blocked installation attempt
await manager.install_by_url("https://malicious-site.com/evil-nodes.git")
# Check failure records
failed_reports = manager.get_failed_install_reports()
for report in failed_reports:
print(f"Blocked: {report['url']} - {report['reason']}")
```
## Security Policy Matrix
| Risk Level | Strong | Normal | Normal- | Weak |
|------------|--------|--------|---------|------|
| **block** | ❌ | ❌ | ❌ | ❌ |
| **high+** | ❌ | ❌ | 🔒* | 🔒* |
| **high** | ❌ | ❌ | 🔒*/☁️** | ✅ |
| **middle+**| ❌ | ❌ | 🔒*/☁️** | ✅ |
| **middle** | ❌ | ✅ | ✅ | ✅ |
- 🔒* : Allowed only in local mode
- ☁️** : Allowed only in personal cloud mode
- ✅ : Allowed
- ❌ : Blocked
## Error Message Examples
### Security Block
```
Installation blocked by security policy: URL installation blocked by security level: strong (risk: middle)
Target: awesome-nodes@url-blocked
```
### Console Log
```
[SECURITY] Blocked URL installation: https://suspicious-domain.com/repo.git
[SECURITY] Reason: URL installation blocked by security level: normal (risk: middle+)
[SECURITY] Package: repo
```
## Configuration Recommendations
### Production Environment
```json
{
"security_level": "strong",
"network_mode": "private"
}
```
- Most restrictive settings
- Only trusted sources allowed
### Development Environment
```json
{
"security_level": "weak",
"network_mode": "local"
}
```
- Permissive settings for development convenience
- Allow local repositories and development servers
### Personal Cloud Environment
```json
{
"security_level": "normal-",
"network_mode": "personal_cloud"
}
```
- Balanced settings for personal use
- Allow personal repository access
## Security Enhancement Benefits
### 1. Malware Prevention
- Automatic blocking from unknown sources
- Filter suspicious domains and IPs
### 2. Network Security
- Control private network access
- Restrict SSH protocol usage
### 3. Audit Trail
- Record all blocked attempts
- Log security events
### 4. Flexible Policy
- Customized security levels per environment
- Distinguish between production/development environments
## Backward Compatibility
- Existing `install_by_id` function unchanged
- No security validation applied to CNR-based installations
- `install_by_id_or_url` applies security only to URLs
This security enhancement significantly improves system security while maintaining the convenience of URL-based installations.

View File

@@ -1,355 +0,0 @@
# CNR Version Management Design
**Version**: 1.1
**Date**: 2025-11-08
**Status**: Official Design Policy
## Overview
This document describes the official design policy for CNR (ComfyUI Node Registry) version management in ComfyUI Manager.
## Core Design Principles
### 1. In-Place Upgrade Policy
**Policy**: CNR upgrades are performed as **in-place replacements** without version history preservation.
**Rationale**:
- **Simplicity**: Single version management is easier for users and maintainers
- **Disk Space**: Prevents accumulation of old package versions
- **Clear State**: Users always know which version is active
- **Consistency**: Same behavior for enabled and disabled states
**Behavior**:
```
Before: custom_nodes/PackageName/ (CNR v1.0.1 with .tracking)
Action: Install CNR v1.0.2
After: custom_nodes/PackageName/ (CNR v1.0.2 with .tracking)
Result: Old v1.0.1 REMOVED (not preserved)
```
### 2. Single CNR Version Policy
**Policy**: Only **ONE CNR version** exists at any given time (either enabled OR disabled, never both).
**Rationale**:
- **State Clarity**: No ambiguity about which CNR version is current
- **Resource Management**: Minimal disk usage
- **User Experience**: Clear version state without confusion
- **Design Consistency**: Uniform handling across operations
**States**:
- **Enabled**: `custom_nodes/PackageName/` (with `.tracking`)
- **Disabled**: `.disabled/packagename@version/` (with `.tracking`)
- **Never**: Multiple CNR versions coexisting
### 3. CNR vs Nightly Differentiation
**Policy**: Different handling for CNR and Nightly packages based on use cases.
| Aspect | CNR Packages (`.tracking`) | Nightly Packages (`.git`) |
|--------|----------------------------|---------------------------|
| **Purpose** | Stable releases | Development versions |
| **Preservation** | Not preserved (in-place upgrade) | Preserved (multiple versions) |
| **Version Policy** | Single version only | Multiple versions allowed |
| **Use Case** | Production use | Testing and development |
**Rationale**:
- **CNR**: Stable releases don't need version history; users want single stable version
- **Nightly**: Development versions benefit from multiple versions for testing
### 4. API Response Priority Rules
**Policy**: The `/v2/customnode/installed` API applies two priority rules to prevent duplicate package entries and ensure clear state representation.
**Rule 1 (Enabled-Priority)**:
- **Policy**: When both enabled and disabled versions of the same package exist → Return ONLY the enabled version
- **Rationale**: Prevents frontend confusion from duplicate package entries
- **Implementation**: `comfyui_manager/glob/manager_core.py:1801` in `get_installed_nodepacks()`
**Rule 2 (CNR-Priority for Disabled Packages)**:
- **Policy**: When both CNR and Nightly versions are disabled → Return ONLY the CNR version
- **Rationale**: CNR versions are stable releases and should be preferred over development Nightly builds when both are inactive
- **Implementation**: `comfyui_manager/glob/manager_core.py:1801` in `get_installed_nodepacks()`
**Priority Matrix**:
| Scenario | Enabled Versions | Disabled Versions | API Response |
|----------|------------------|-------------------|--------------|
| 1. CNR enabled only | CNR v1.0.1 | None | CNR v1.0.1 (`enabled: true`) |
| 2. CNR enabled + Nightly disabled | CNR v1.0.1 | Nightly | **Only CNR v1.0.1** (`enabled: true`) ← Rule 1 |
| 3. Nightly enabled + CNR disabled | Nightly | CNR v1.0.1 | **Only Nightly** (`enabled: true`) ← Rule 1 |
| 4. CNR disabled + Nightly disabled | None | CNR v1.0.1, Nightly | **Only CNR v1.0.1** (`enabled: false`) ← Rule 2 |
| 5. Different packages disabled | None | PackageA, PackageB | Both packages (`enabled: false`) |
**Test Coverage**:
- `tests/glob/test_installed_api_enabled_priority.py`
- `test_installed_api_shows_only_enabled_when_both_exist` - Verifies Rule 1
- `test_installed_api_cnr_priority_when_both_disabled` - Verifies Rule 2
## Detailed Behavior Specifications
### CNR Upgrade (Enabled → Enabled)
**Scenario**: Upgrading from CNR v1.0.1 to v1.0.2 when v1.0.1 is enabled
```
Initial State:
custom_nodes/PackageName/ (CNR v1.0.1 with .tracking)
Action:
Install CNR v1.0.2
Process:
1. Download CNR v1.0.2
2. Remove existing custom_nodes/PackageName/
3. Install CNR v1.0.2 to custom_nodes/PackageName/
4. Create .tracking file
Final State:
custom_nodes/PackageName/ (CNR v1.0.2 with .tracking)
Result:
✓ v1.0.2 installed and enabled
✓ v1.0.1 completely removed
✓ No version history preserved
```
### CNR Switch from Disabled
**Scenario**: Switching from disabled CNR v1.0.1 to CNR v1.0.2
```
Initial State:
custom_nodes/PackageName/ (Nightly with .git)
.disabled/packagename@1_0_1/ (CNR v1.0.1 with .tracking)
User Action:
Install CNR v1.0.2
Process:
Step 1: Enable disabled CNR v1.0.1
- Move .disabled/packagename@1_0_1/ → custom_nodes/PackageName/
- Move custom_nodes/PackageName/ → .disabled/packagename@nightly/
Step 2: Upgrade CNR v1.0.1 → v1.0.2 (in-place)
- Download CNR v1.0.2
- Remove custom_nodes/PackageName/
- Install CNR v1.0.2 to custom_nodes/PackageName/
Final State:
custom_nodes/PackageName/ (CNR v1.0.2 with .tracking)
.disabled/packagename@nightly/ (Nightly preserved)
Result:
✓ CNR v1.0.2 installed and enabled
✓ CNR v1.0.1 removed (not preserved in .disabled/)
✓ Nightly preserved in .disabled/
```
### CNR Disable
**Scenario**: Disabling CNR v1.0.1 when Nightly exists
```
Initial State:
custom_nodes/PackageName/ (CNR v1.0.1 with .tracking)
Action:
Disable CNR v1.0.1
Final State:
.disabled/packagename@1_0_1/ (CNR v1.0.1 with .tracking)
Note:
- Only ONE disabled CNR version exists
- If another CNR is already disabled, it is replaced
```
### Nightly Installation (with CNR Disabled)
**Scenario**: Installing Nightly when CNR v1.0.1 is disabled
```
Initial State:
.disabled/packagename@1_0_1/ (CNR v1.0.1 with .tracking)
Action:
Install Nightly
Final State:
custom_nodes/PackageName/ (Nightly with .git)
.disabled/packagename@1_0_1/ (CNR v1.0.1 preserved)
Result:
✓ Nightly installed and enabled
✓ Disabled CNR v1.0.1 preserved (not removed)
✓ Different handling for Nightly vs CNR
```
## Implementation Requirements
### CNR Install/Upgrade Operation
1. **Check for existing CNR versions**:
- Enabled: `custom_nodes/PackageName/` with `.tracking`
- Disabled: `.disabled/*` with `.tracking`
2. **Remove old CNR versions**:
- If enabled CNR exists: Remove it
- If disabled CNR exists: Remove it
- Ensure only ONE CNR version will exist after operation
3. **Install new CNR version**:
- Download and extract to target location
- Create `.tracking` file
- Register in package database
4. **Preserve Nightly packages**:
- Do NOT remove packages with `.git` directory
- Nightly packages should be preserved in `.disabled/`
### CNR Disable Operation
1. **Move enabled CNR to disabled**:
- Move `custom_nodes/PackageName/``.disabled/packagename@version/`
- Use **installed version** for directory name (not registry latest)
2. **Remove any existing disabled CNR**:
- Only ONE disabled CNR version allowed
- If another CNR already in `.disabled/`, remove it first
3. **Preserve disabled Nightly**:
- Do NOT remove disabled Nightly packages
- Multiple Nightly versions can coexist in `.disabled/`
### CNR Enable Operation
1. **Check for enabled package**:
- If another package enabled, disable it first
2. **Move disabled CNR to enabled**:
- Move `.disabled/packagename@version/``custom_nodes/PackageName/`
3. **Maintain single CNR policy**:
- After enable, no CNR should remain in `.disabled/`
- Only Nightly packages should remain in `.disabled/`
## Test Coverage
### Phase 7: Version Management Behavior Tests
**Test 7.1: `test_cnr_version_upgrade_removes_old`**
- ✅ Verifies in-place upgrade removes old CNR version
- ✅ Confirms only one CNR version exists after upgrade
- ✅ Documents single version policy
**Test 7.2: `test_cnr_nightly_switching_preserves_nightly_only`**
- ✅ Verifies Nightly preservation across CNR upgrades
- ✅ Confirms old CNR versions removed (not preserved)
- ✅ Documents different handling for CNR vs Nightly
### Other Relevant Tests
**Phase 1-6 Tests**:
- ✅ All tests comply with single CNR version policy
- ✅ No tests assume multiple CNR versions coexist
- ✅ Fixtures properly handle CNR vs Nightly differences
## Known Behaviors
### Correct Behaviors (By Design)
1. **CNR Upgrades Remove Old Versions**
- Status: ✅ Intentional design
- Reason: In-place upgrade policy
- Test: Phase 7.1 verifies this
2. **Only One CNR Version Exists**
- Status: ✅ Intentional design
- Reason: Single version policy
- Test: Phase 7.2 verifies this
3. **Nightly Preserved, CNR Not**
- Status: ✅ Intentional design
- Reason: Different use cases
- Test: Phase 7.2 verifies this
### Known Issues
1. **Disable API Version Mismatch**
- Status: ⚠️ Bug to be fixed
- Issue: Disabled directory name uses registry latest instead of installed version
- Impact: Incorrect directory naming
- Priority: Medium
## Design Rationale
### Why In-Place Upgrade?
**Benefits**:
- Simple mental model for users
- No disk space accumulation
- Clear version state
- Easier maintenance
**Trade-offs**:
- No automatic rollback capability
- Users must reinstall old versions from registry
- Network required for version downgrades
**Decision**: Benefits outweigh trade-offs for stable release management.
### Why Different CNR vs Nightly Handling?
**CNR (Stable Releases)**:
- Users want single stable version
- Production use case
- Rollback via registry if needed
**Nightly (Development Builds)**:
- Developers test multiple versions
- Development use case
- Local version testing important
**Decision**: Different use cases justify different policies.
## Future Considerations
### Potential Enhancements (Not Currently Planned)
1. **Optional Version History**
- Configurable preservation of last N versions
- Opt-in via configuration flag
- Separate history directory
2. **CNR Rollback API**
- Dedicated rollback endpoint
- Re-download from registry
- Preserve current version before downgrade
3. **Version Pinning**
- Pin specific CNR version
- Prevent automatic upgrades
- Per-package configuration
**Note**: These are potential future enhancements, not current requirements.
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.1 | 2025-11-08 | Added API Response Priority Rules (Rule 1: Enabled-Priority, Rule 2: CNR-Priority) |
| 1.0 | 2025-11-06 | Initial design document based on user clarification |
## References
- Phase 7 Test Implementation: `tests/glob/test_complex_scenarios.py`
- Policy Clarification: `.claude/livecontext/cnr_version_policy_clarification.md`
- Bug Report: `.claude/livecontext/bugs_to_file.md`
---
**Approved By**: User feedback 2025-11-06
**Status**: Official Policy
**Compliance**: All tests verified against this policy

View File

@@ -1,292 +0,0 @@
# Glob Module API Reference for CLI Migration
## 🎯 Quick Reference
This document provides essential glob module APIs available for CLI implementation. **READ ONLY** - do not modify glob module.
---
## 📦 Core Classes
### UnifiedManager
**Location**: `comfyui_manager/glob/manager_core.py:436`
**Instance**: Available as `unified_manager` (global instance)
#### Data Structures
```python
class UnifiedManager:
def __init__(self):
# PRIMARY DATA - Use these instead of legacy dicts
self.installed_node_packages: dict[str, list[InstalledNodePackage]]
self.repo_nodepack_map: dict[str, InstalledNodePackage] # compact_url -> package
self.processed_install: set
```
#### Core Methods (Direct CLI Equivalents)
```python
# Installation & Management
async def install_by_id(packname: str, version_spec=None, channel=None,
mode=None, instant_execution=False, no_deps=False,
return_postinstall=False) -> ManagedResult
def unified_enable(packname: str, version_spec=None) -> ManagedResult
def unified_disable(packname: str) -> ManagedResult
def unified_uninstall(packname: str) -> ManagedResult
def unified_update(packname: str, instant_execution=False, no_deps=False,
return_postinstall=False) -> ManagedResult
def unified_fix(packname: str, version_spec, instant_execution=False,
no_deps=False) -> ManagedResult
# Package Resolution & Info
def resolve_node_spec(packname: str, guess_mode=None) -> tuple[str, str, bool] | None
def get_active_pack(packname: str) -> InstalledNodePackage | None
def get_inactive_pack(packname: str, version_spec=None) -> InstalledNodePackage | None
# Git Repository Operations
async def repo_install(url: str, repo_path: str, instant_execution=False,
no_deps=False, return_postinstall=False) -> ManagedResult
def repo_update(repo_path: str, instant_execution=False, no_deps=False,
return_postinstall=False) -> ManagedResult
# Utilities
def is_url_like(url: str) -> bool
def reload() -> None
```
---
### InstalledNodePackage
**Location**: `comfyui_manager/common/node_package.py:10`
```python
@dataclass
class InstalledNodePackage:
# Core Data
id: str # Package identifier
fullpath: str # Installation path
disabled: bool # Disabled state
version: str # Version (cnr version, "nightly", or "unknown")
repo_url: str = None # Git repository URL (for nightly/unknown)
# Computed Properties
@property
def is_unknown(self) -> bool: # version == "unknown"
@property
def is_nightly(self) -> bool: # version == "nightly"
@property
def is_from_cnr(self) -> bool: # not unknown and not nightly
@property
def is_enabled(self) -> bool: # not disabled
@property
def is_disabled(self) -> bool: # disabled
# Methods
def get_commit_hash(self) -> str
def isValid(self) -> bool
@staticmethod
def from_fullpath(fullpath: str, resolve_from_path) -> InstalledNodePackage
```
---
### ManagedResult
**Location**: `comfyui_manager/glob/manager_core.py:285`
```python
class ManagedResult:
def __init__(self, action: str):
self.action: str = action # 'install-cnr', 'install-git', 'enable', 'skip', etc.
self.result: bool = True # Success/failure
self.msg: str = "" # Human readable message
self.target: str = None # Target identifier
self.postinstall = None # Post-install callback
# Methods
def fail(self, msg: str = "") -> ManagedResult
def with_msg(self, msg: str) -> ManagedResult
def with_target(self, target: str) -> ManagedResult
def with_postinstall(self, postinstall) -> ManagedResult
```
---
## 🛠️ Standalone Functions
### Core Manager Functions
```python
# Snapshot Operations
async def save_snapshot_with_postfix(postfix: str, path: str = None,
custom_nodes_only: bool = False) -> str
async def restore_snapshot(snapshot_path: str, git_helper_extras=None) -> None
# Node Utilities
def simple_check_custom_node(url: str) -> str # Returns: 'installed', 'not-installed', 'disabled'
# Path Utilities
def get_custom_nodes_paths() -> list[str]
```
---
## 🔗 CNR Utilities
**Location**: `comfyui_manager/common/cnr_utils.py`
```python
# Essential CNR functions for CLI
def get_nodepack(packname: str) -> dict | None
# Returns CNR package info or None
def get_all_nodepackages() -> dict[str, dict]
# Returns all CNR packages {package_id: package_info}
def all_versions_of_node(node_name: str) -> list[dict] | None
# Returns version history for a package
```
---
## 📋 Usage Patterns for CLI Migration
### 1. Replace Legacy Dict Access
```python
# ❌ OLD (Legacy way)
for k, v in unified_manager.active_nodes.items():
version, fullpath = v
print(f"Active: {k} @ {version}")
# ✅ NEW (Glob way)
for packages in unified_manager.installed_node_packages.values():
for pack in packages:
if pack.is_enabled:
print(f"Active: {pack.id} @ {pack.version}")
```
### 2. Package Installation
```python
# CNR Package Installation
res = await unified_manager.install_by_id("package-name", "1.0.0",
instant_execution=True, no_deps=False)
# Git URL Installation
if unified_manager.is_url_like(url):
repo_name = os.path.basename(url).replace('.git', '')
res = await unified_manager.repo_install(url, repo_name,
instant_execution=True, no_deps=False)
```
### 3. Package State Queries
```python
# Check if package is active
active_pack = unified_manager.get_active_pack("package-name")
if active_pack:
print(f"Package is enabled: {active_pack.version}")
# Check if package is inactive
inactive_pack = unified_manager.get_inactive_pack("package-name")
if inactive_pack:
print(f"Package is disabled: {inactive_pack.version}")
```
### 4. CNR Data Access
```python
# Get CNR package information
from ..common import cnr_utils
cnr_info = cnr_utils.get_nodepack("package-name")
if cnr_info:
publisher = cnr_info.get('publisher', {}).get('name', 'Unknown')
print(f"Publisher: {publisher}")
# Get all CNR packages (for show not-installed)
all_cnr = cnr_utils.get_all_nodepackages()
```
### 5. Result Handling
```python
res = await unified_manager.install_by_id("package-name")
if res.action == 'skip':
print(f"SKIP: {res.msg}")
elif res.action == 'install-cnr' and res.result:
print(f"INSTALLED: {res.target}")
elif res.action == 'enable' and res.result:
print(f"ENABLED: package was already installed")
else:
print(f"ERROR: {res.msg}")
```
---
## 🚫 NOT Available in Glob (Handle These)
### Legacy Functions That Don't Exist:
- `get_custom_nodes()` → Use `cnr_utils.get_all_nodepackages()`
- `load_nightly()` → Remove or stub
- `extract_nodes_from_workflow()` → Remove feature
- `gitclone_install()` → Use `repo_install()`
### Legacy Properties That Don't Exist:
- `active_nodes` → Use `installed_node_packages` + filter by `is_enabled`
- `cnr_map` → Use `cnr_utils.get_all_nodepackages()`
- `cnr_inactive_nodes` → Use `installed_node_packages` + filter by `is_disabled` and `is_from_cnr`
- `nightly_inactive_nodes` → Use `installed_node_packages` + filter by `is_disabled` and `is_nightly`
- `unknown_active_nodes` → Use `installed_node_packages` + filter by `is_enabled` and `is_unknown`
- `unknown_inactive_nodes` → Use `installed_node_packages` + filter by `is_disabled` and `is_unknown`
---
## 🔄 Data Migration Examples
### Show Enabled Packages
```python
def show_enabled_packages():
enabled_packages = []
# Collect enabled packages
for packages in unified_manager.installed_node_packages.values():
for pack in packages:
if pack.is_enabled:
enabled_packages.append(pack)
# Display with CNR info
for pack in enabled_packages:
if pack.is_from_cnr:
cnr_info = cnr_utils.get_nodepack(pack.id)
publisher = cnr_info.get('publisher', {}).get('name', 'Unknown') if cnr_info else 'Unknown'
print(f"[ ENABLED ] {pack.id:50} (author: {publisher}) [{pack.version}]")
elif pack.is_nightly:
print(f"[ ENABLED ] {pack.id:50} (nightly) [NIGHTLY]")
else:
print(f"[ ENABLED ] {pack.id:50} (unknown) [UNKNOWN]")
```
### Show Not-Installed Packages
```python
def show_not_installed_packages():
# Get installed package IDs
installed_ids = set()
for packages in unified_manager.installed_node_packages.values():
for pack in packages:
installed_ids.add(pack.id)
# Get all CNR packages
all_cnr = cnr_utils.get_all_nodepackages()
# Show not-installed
for pack_id, pack_info in all_cnr.items():
if pack_id not in installed_ids:
publisher = pack_info.get('publisher', {}).get('name', 'Unknown')
latest_version = pack_info.get('latest_version', {}).get('version', '0.0.0')
print(f"[ NOT INSTALLED ] {pack_info['name']:50} {pack_id:30} (author: {publisher}) [{latest_version}]")
```
---
## ⚠️ Key Constraints
1. **NO MODIFICATIONS**: Do not add any functions or properties to glob module
2. **USE EXISTING APIs**: Only use the functions and classes documented above
3. **ADAPT CLI**: CLI must adapt to glob's data structures and patterns
4. **REMOVE IF NEEDED**: Remove features that can't be implemented with available APIs
This reference should provide everything needed to implement the CLI migration using only existing glob APIs.

View File

@@ -1,324 +0,0 @@
# CLI Glob Migration - Implementation Todo List
## 📅 Project Timeline: 3.5 Days
---
# 🚀 Phase 1: Initial Setup & Import Changes (0.5 day)
## Day 1 Morning
### ✅ Setup and Preparation (30 min)
- [ ] Read implementation context file
- [ ] Review glob APIs documentation
- [ ] Set up development environment
- [ ] Create backup of current CLI
### 🔄 Import Path Changes (1 hour)
- [ ] **CRITICAL**: Update import statements in `cm_cli/__main__.py:39-41`
```python
# Change from:
from ..legacy import manager_core as core
from ..legacy.manager_core import unified_manager
# Change to:
from ..glob import manager_core as core
from ..glob.manager_core import unified_manager
```
- [ ] Test CLI loads without crashing
- [ ] Identify immediate import-related errors
### 🧪 Initial Testing (30 min)
- [ ] Test basic CLI help: `python -m comfyui_manager.cm_cli help`
- [ ] Test simple commands that should work: `python -m comfyui_manager.cm_cli show snapshot`
- [ ] Document all errors found
- [ ] Prioritize fixes needed
---
# ⚙️ Phase 2: Core Function Implementation (2 days)
## Day 1 Afternoon + Day 2
### 🛠️ install_node() Function Update (3 hours)
**File**: `cm_cli/__main__.py:187-235`
**Complexity**: Medium
#### Tasks:
- [ ] **Replace Git URL handling logic**
```python
# OLD (line ~191):
if core.is_valid_url(node_spec_str):
res = asyncio.run(core.gitclone_install(node_spec_str, no_deps=cmd_ctx.no_deps))
# NEW:
if unified_manager.is_url_like(node_spec_str):
repo_name = os.path.basename(node_spec_str)
if repo_name.endswith('.git'):
repo_name = repo_name[:-4]
res = asyncio.run(unified_manager.repo_install(
node_spec_str, repo_name, instant_execution=True, no_deps=cmd_ctx.no_deps
))
```
- [ ] Test Git URL installation
- [ ] Test CNR package installation
- [ ] Verify error handling works correctly
- [ ] Update progress messages if needed
### 🔍 show_list() Function Rewrite - Installed-Only Approach (3 hours)
**File**: `cm_cli/__main__.py:418-534`
**Complexity**: High - Complete architectural change
**New Approach**: Show only installed nodepacks with on-demand info retrieval
#### Key Changes:
- ❌ Remove: Full cache loading (`get_custom_nodes()`)
- ❌ Remove: Support for `show all`, `show not-installed`, `show cnr`
- ✅ Add: Lightweight caching system for nodepack metadata
- ✅ Add: On-demand CNR API calls for additional info
#### Tasks:
- [ ] **Phase 2A: Lightweight Cache Implementation (1 hour)**
```python
class NodePackageCache:
def __init__(self, cache_file_path: str):
self.cache_file = cache_file_path
self.cache_data = self._load_cache()
def get_metadata(self, nodepack_id: str) -> dict:
# Get cached metadata or fetch on-demand from CNR
def update_metadata(self, nodepack_id: str, metadata: dict):
# Update cache (called during install)
```
- [ ] **Phase 2B: New show_list Implementation (1.5 hours)**
```python
def show_list(kind, simple=False):
# Validate supported commands
if kind not in ['installed', 'enabled', 'disabled']:
print(f"Unsupported: 'show {kind}'. Use: installed/enabled/disabled")
return
# Get installed packages only
all_packages = []
for packages in unified_manager.installed_node_packages.values():
all_packages.extend(packages)
# Filter by status
if kind == 'enabled':
packages = [pkg for pkg in all_packages if pkg.is_enabled]
elif kind == 'disabled':
packages = [pkg for pkg in all_packages if not pkg.is_enabled]
else: # 'installed'
packages = all_packages
```
- [ ] **Phase 2C: On-Demand Display with Cache (0.5 hour)**
```python
cache = NodePackageCache(cache_file_path)
for package in packages:
# Basic info from InstalledNodePackage
status = "[ ENABLED ]" if package.is_enabled else "[ DISABLED ]"
# Enhanced info from cache or on-demand
cached_info = cache.get_metadata(package.id)
name = cached_info.get('name', package.id)
author = cached_info.get('author', 'Unknown')
version = cached_info.get('version', 'Unknown')
if simple:
print(f"{name}@{version}")
else:
print(f"{status} {name:50} {package.id:30} (author: {author:20}) [{version}]")
```
#### Install-time Cache Update:
- [ ] **Update install_node() to populate cache**
```python
# After successful installation in install_node()
if install_success:
metadata = cnr_utils.get_nodepackage_info(installed_package.id)
cache.update_metadata(installed_package.id, metadata)
```
#### Testing:
- [ ] Test `show installed` (enabled + disabled packages)
- [ ] Test `show enabled` (only enabled packages)
- [ ] Test `show disabled` (only disabled packages)
- [ ] Test unsupported commands show helpful error
- [ ] Test `simple-show` variants work correctly
- [ ] Test cache functionality (create, read, update)
- [ ] Test on-demand CNR info retrieval for cache misses
### 📝 get_all_installed_node_specs() Update (1 hour)
**File**: `cm_cli/__main__.py:573-605`
**Complexity**: Medium
#### Tasks:
- [ ] **Rewrite using InstalledNodePackage**
```python
def get_all_installed_node_specs():
res = []
for packages in unified_manager.installed_node_packages.values():
for pack in packages:
node_spec_str = f"{pack.id}@{pack.version}"
res.append(node_spec_str)
return res
```
- [ ] Test with `update all` command
- [ ] Verify node spec format is correct
### ⚙️ Context Management Updates (1 hour)
**File**: `cm_cli/__main__.py:117-134`
**Complexity**: Low
#### Tasks:
- [ ] **Remove load_nightly() call**
```python
def set_channel_mode(self, channel, mode):
if mode is not None:
self.mode = mode
if channel is not None:
self.channel = channel
# OLD: asyncio.run(unified_manager.reload(...))
# OLD: asyncio.run(unified_manager.load_nightly(...))
# NEW: Just reload
unified_manager.reload()
```
- [ ] Test channel/mode switching still works
---
# 🧹 Phase 3: Feature Removal & Final Testing (1 day)
## Day 3
### ❌ Remove Unavailable Features (2 hours)
**Complexity**: Low
#### deps-in-workflow Command Removal:
- [ ] **Update deps_in_workflow() function** (`cm_cli/__main__.py:1000-1050`)
```python
@app.command("deps-in-workflow")
def deps_in_workflow(...):
print("[bold red]ERROR: This feature is not available in the current version.[/bold red]")
print("The 'deps-in-workflow' feature has been removed.")
print("Please use alternative workflow analysis tools.")
sys.exit(1)
```
- [ ] Test command shows proper error message
- [ ] Update help text to reflect removal
#### install-deps Command Update:
- [ ] **Update install_deps() function** (`cm_cli/__main__.py:1203-1250`)
```python
# Remove extract_nodes_from_workflow usage (line ~1033)
# Replace with error handling or alternative approach
```
- [ ] Test with dependency files
### 🧪 Comprehensive Testing (4 hours)
#### Core Command Testing (2 hours):
- [ ] **Install Commands**:
- [ ] `install <cnr-package>`
- [ ] `install <git-url>`
- [ ] `install all` (if applicable)
- [ ] **Uninstall Commands**:
- [ ] `uninstall <package>`
- [ ] `uninstall all`
- [ ] **Enable/Disable Commands**:
- [ ] `enable <package>`
- [ ] `disable <package>`
- [ ] `enable all` / `disable all`
- [ ] **Update Commands**:
- [ ] `update <package>`
- [ ] `update all`
#### Show Commands Testing (1 hour):
- [ ] `show installed`
- [ ] `show enabled`
- [ ] `show disabled`
- [ ] `show all`
- [ ] `show not-installed`
- [ ] `simple-show` variants
#### Advanced Features Testing (1 hour):
- [ ] `save-snapshot`
- [ ] `restore-snapshot`
- [ ] `show snapshot`
- [ ] `show snapshot-list`
- [ ] `clear`
- [ ] `cli-only-mode`
### 🐛 Bug Fixes & Polish (2 hours)
- [ ] Fix any errors found during testing
- [ ] Improve error messages
- [ ] Ensure output formatting consistency
- [ ] Performance optimization if needed
- [ ] Code cleanup and comments
---
# 📋 Daily Checklists
## End of Day 1 Checklist:
- [ ] Imports successfully changed
- [ ] Basic CLI loading works
- [ ] install_node() handles both CNR and Git URLs
- [ ] No critical crashes in core functions
## End of Day 2 Checklist:
- [ ] show_list() displays all package types correctly
- [ ] get_all_installed_node_specs() works with new data structure
- [ ] Context management updated
- [ ] Core functionality regression-free
## End of Day 3 Checklist:
- [ ] All CLI commands tested and working
- [ ] Removed features show appropriate messages
- [ ] Output format acceptable to users
- [ ] No glob module modifications made
- [ ] Ready for code review
---
# 🎯 Success Criteria
## Must Pass:
- [ ] All core commands functional (install/uninstall/enable/disable/update)
- [ ] show commands display accurate information
- [ ] No modifications to glob module
- [ ] CLI code changes < 200 lines
- [ ] No critical regressions
## Bonus Points:
- [ ] Output format matches legacy closely
- [ ] Performance equals or exceeds legacy
- [ ] Error messages user-friendly
- [ ] Code is clean and maintainable
---
# 🚨 Emergency Contacts & Resources
## If Stuck:
1. **Review**: `CLI_PURE_GLOB_MIGRATION_PLAN.md` for detailed technical specs
2. **Reference**: `CLI_IMPLEMENTATION_CONTEXT.md` for current state
3. **Debug**: Use `print()` statements to understand data structures
4. **Fallback**: Implement minimal working version first, polish later
## Key Files to Reference:
- `comfyui_manager/glob/manager_core.py` - UnifiedManager APIs
- `comfyui_manager/common/node_package.py` - InstalledNodePackage class
- `comfyui_manager/common/cnr_utils.py` - CNR utilities
---
**Remember**: Focus on making it work first, then making it perfect. The constraint is NO glob modifications - CLI must adapt to glob's way of doing things.

View File

@@ -1,424 +0,0 @@
# CLI Migration Guide: Legacy to Glob Module
**Status**: ✅ Completed (Historical Reference)
**Last Updated**: 2025-08-30
**Purpose**: Complete guide for migrating ComfyUI Manager CLI from legacy to glob module
---
## 📋 Table of Contents
1. [Overview](#overview)
2. [Legacy vs Glob Comparison](#legacy-vs-glob-comparison)
3. [Migration Strategy](#migration-strategy)
4. [Implementation Details](#implementation-details)
5. [Key Constraints](#key-constraints)
6. [API Reference](#api-reference-quick)
7. [Rollback Plan](#rollback-plan)
---
## Overview
### Objective
Migrate ComfyUI Manager CLI from legacy module to glob module using **only existing glob APIs** without modifying the glob module itself.
### Scope
- **Target File**: `comfyui_manager/cm_cli/__main__.py` (1305 lines)
- **Timeline**: 3.5 days
- **Approach**: Minimal CLI changes, maximum compatibility
- **Constraint**: ❌ NO glob module modifications
### Current State
```python
# Current imports (Lines 39-41)
from ..legacy import manager_core as core
from ..legacy.manager_core import unified_manager
# Target imports
from ..glob import manager_core as core
from ..glob.manager_core import unified_manager
```
---
## Legacy vs Glob Comparison
### Core Architecture Differences
#### Legacy Module (Current)
**Data Structure**: Dictionary-based global state
```python
unified_manager.active_nodes # Active nodes dict
unified_manager.unknown_active_nodes # Unknown active nodes
unified_manager.cnr_inactive_nodes # Inactive CNR nodes
unified_manager.nightly_inactive_nodes # Inactive nightly nodes
unified_manager.unknown_inactive_nodes # Unknown inactive nodes
unified_manager.cnr_map # CNR info mapping
```
#### Glob Module (Target)
**Data Structure**: Object-oriented with InstalledNodePackage
```python
unified_manager.installed_node_packages # dict[str, list[InstalledNodePackage]]
unified_manager.repo_nodepack_map # dict[str, InstalledNodePackage]
```
### Method Compatibility Matrix
| Method | Legacy | Glob | Status | Action |
|--------|--------|------|--------|--------|
| `unified_enable()` | ✅ | ✅ | Compatible | Direct mapping |
| `unified_disable()` | ✅ | ✅ | Compatible | Direct mapping |
| `unified_uninstall()` | ✅ | ✅ | Compatible | Direct mapping |
| `unified_update()` | ✅ | ✅ | Compatible | Direct mapping |
| `install_by_id()` | Sync | Async | Modified | Use asyncio.run() |
| `gitclone_install()` | ✅ | ❌ | Replaced | Use repo_install() |
| `get_custom_nodes()` | ✅ | ❌ | Removed | Use cnr_utils |
| `load_nightly()` | ✅ | ❌ | Removed | Not needed |
| `extract_nodes_from_workflow()` | ✅ | ❌ | Removed | Feature removed |
### InstalledNodePackage Class
```python
@dataclass
class InstalledNodePackage:
id: str # Package identifier
fullpath: str # Full filesystem path
disabled: bool # Disabled status
version: str # Version (nightly/unknown/x.y.z)
repo_url: str = None # Repository URL
# Properties
@property
def is_unknown(self) -> bool: return self.version == "unknown"
@property
def is_nightly(self) -> bool: return self.version == "nightly"
@property
def is_from_cnr(self) -> bool: return not (self.is_unknown or self.is_nightly)
@property
def is_enabled(self) -> bool: return not self.disabled
@property
def is_disabled(self) -> bool: return self.disabled
```
---
## Migration Strategy
### Phase 1: Setup (0.5 day)
**Goal**: Basic migration with error identification
1. **Import Path Changes**
```python
# Change 2 lines
from ..glob import manager_core as core
from ..glob.manager_core import unified_manager
```
2. **Initial Testing**
- Run basic commands
- Identify breaking changes
- Document errors
3. **Error Analysis**
- List all affected functions
- Categorize by priority
- Plan fixes
### Phase 2: Core Implementation (2 days)
**Goal**: Adapt CLI to glob architecture
1. **install_node() Updates**
```python
# Replace gitclone_install with repo_install
if unified_manager.is_url_like(node_spec_str):
res = asyncio.run(unified_manager.repo_install(
node_spec_str,
os.path.basename(node_spec_str),
instant_execution=True,
no_deps=cmd_ctx.no_deps
))
```
2. **show_list() Rewrite** (Most complex change)
- Migrate from dictionary-based to InstalledNodePackage-based
- Implement installed-only approach with optional CNR lookup
- See [show_list() Implementation](#show_list-implementation) section
3. **Context Management**
- Update get_all_installed_node_specs()
- Adapt to new data structures
4. **Data Structure Migration**
- Replace all active_nodes references
- Use installed_node_packages instead
### Phase 3: Final Testing (1 day)
**Goal**: Comprehensive validation
1. **Feature Removal**
- Remove deps-in-workflow (not supported)
- Stub unsupported features
2. **Testing**
- Test all CLI commands
- Verify output format
- Check edge cases
3. **Polish**
- Fix bugs
- Improve error messages
- Update help text
---
## Implementation Details
### show_list() Implementation
**Challenge**: Legacy uses multiple dictionaries, glob uses single InstalledNodePackage collection
**Solution**: Installed-only approach with on-demand CNR lookup
```python
def show_list(kind: str, simple: bool = False):
"""
Display node package list
Args:
kind: 'installed', 'enabled', 'disabled', 'all'
simple: If True, show simple format
"""
# Get all installed packages
all_packages = []
for packages in unified_manager.installed_node_packages.values():
all_packages.extend(packages)
# Filter by kind
if kind == "enabled":
packages = [p for p in all_packages if p.is_enabled]
elif kind == "disabled":
packages = [p for p in all_packages if p.is_disabled]
elif kind == "installed" or kind == "all":
packages = all_packages
else:
print(f"Unknown kind: {kind}")
return
# Display
if simple:
for pkg in packages:
print(pkg.id)
else:
# Detailed display with CNR info on-demand
for pkg in packages:
status = "disabled" if pkg.disabled else "enabled"
version_info = f"v{pkg.version}" if pkg.version != "unknown" else "unknown"
print(f"[{status}] {pkg.id} ({version_info})")
# Optionally fetch CNR info for non-nightly packages
if pkg.is_from_cnr and not simple:
cnr_info = cnr_utils.get_nodepackage(pkg.id)
if cnr_info:
print(f" Description: {cnr_info.get('description', 'N/A')}")
```
**Key Changes**:
1. Single source of truth: `installed_node_packages`
2. No separate active/inactive dictionaries
3. On-demand CNR lookup instead of pre-cached cnr_map
4. Filter by InstalledNodePackage properties
### Git Installation Migration
**Before (Legacy)**:
```python
if core.is_valid_url(node_spec_str):
res = asyncio.run(core.gitclone_install(
node_spec_str,
no_deps=cmd_ctx.no_deps
))
```
**After (Glob)**:
```python
if unified_manager.is_url_like(node_spec_str):
res = asyncio.run(unified_manager.repo_install(
node_spec_str,
os.path.basename(node_spec_str), # repo_path derived from URL
instant_execution=True, # Execute immediately
no_deps=cmd_ctx.no_deps # Respect --no-deps flag
))
```
### Async Function Handling
**Pattern**: Wrap async glob methods with asyncio.run()
```python
# install_by_id is async in glob
res = asyncio.run(unified_manager.install_by_id(
packname=node_name,
version_spec=version,
instant_execution=True,
no_deps=cmd_ctx.no_deps
))
```
---
## Key Constraints
### Hard Constraints (Cannot Change)
1. ❌ **No glob module modifications**
- Cannot add new methods to UnifiedManager
- Cannot add compatibility properties
- Must use existing APIs only
2. ❌ **No legacy dependencies**
- CLI must work without legacy module
- Clean break from old architecture
3. ❌ **Maintain CLI interface**
- Command syntax unchanged
- Output format similar (minor differences acceptable)
### Soft Constraints (Acceptable Trade-offs)
1. ✅ **Feature removal acceptable**
- deps-in-workflow feature can be removed
- Channel/mode support can be simplified
2. ✅ **Performance trade-offs acceptable**
- On-demand CNR lookup vs pre-cached
- Slight performance degradation acceptable
3. ✅ **Output format flexibility**
- Minor formatting differences acceptable
- Must remain readable and useful
---
## API Reference (Quick)
### UnifiedManager Core Methods
```python
# Installation
async def install_by_id(packname, version_spec, instant_execution, no_deps) -> ManagedResult
# Git/URL installation
async def repo_install(url, repo_path, instant_execution, no_deps) -> ManagedResult
# Enable/Disable
def unified_enable(packname, version_spec=None) -> ManagedResult
def unified_disable(packname) -> ManagedResult
# Update/Uninstall
def unified_update(packname, instant_execution, no_deps) -> ManagedResult
def unified_uninstall(packname) -> ManagedResult
# Query
def get_active_pack(packname) -> InstalledNodePackage | None
def get_inactive_pack(packname, version_spec) -> InstalledNodePackage | None
def resolve_node_spec(packname, guess_mode) -> NodeSpec
# Utility
def is_url_like(text) -> bool
```
### Data Access
```python
# Installed packages
unified_manager.installed_node_packages: dict[str, list[InstalledNodePackage]]
# Repository mapping
unified_manager.repo_nodepack_map: dict[str, InstalledNodePackage]
```
### External Utilities
```python
# CNR utilities
from ..common import cnr_utils
cnr_utils.get_nodepackage(id) -> dict
cnr_utils.get_all_nodepackages() -> list[dict]
```
For complete API reference, see [CLI_API_REFERENCE.md](CLI_API_REFERENCE.md)
---
## Rollback Plan
### If Migration Fails
1. **Immediate Rollback** (< 5 minutes)
```python
# Revert imports in __main__.py
from ..legacy import manager_core as core
from ..legacy.manager_core import unified_manager
```
2. **Verify Rollback**
```bash
# Test basic commands
cm-cli show installed
cm-cli install <package>
```
3. **Document Issues**
- Note what failed
- Gather error logs
- Plan fixes
### Risk Mitigation
1. **Backup**: Keep legacy module available
2. **Testing**: Comprehensive test suite before deployment
3. **Staging**: Test in non-production environment first
4. **Monitoring**: Watch for errors after deployment
---
## Success Criteria
### Must Pass (Blockers)
- ✅ All core commands functional (install, update, enable, disable, uninstall)
- ✅ Package information displays correctly
- ✅ No glob module modifications
- ✅ No critical regressions
### Should Pass (Important)
- ✅ Output format similar to legacy
- ✅ Performance comparable to legacy
- ✅ User-friendly error messages
- ✅ Help text updated
### Nice to Have
- ✅ Improved code structure
- ✅ Better error handling
- ✅ Type hints added
---
## Reference Documents
- **[CLI_API_REFERENCE.md](CLI_API_REFERENCE.md)** - Complete API documentation
- **[CLI_IMPLEMENTATION_CHECKLIST.md](CLI_IMPLEMENTATION_CHECKLIST.md)** - Step-by-step tasks
- **[CLI_TESTING_GUIDE.md](CLI_TESTING_GUIDE.md)** - Testing strategy
---
## Conclusion
The CLI migration from legacy to glob module is achievable through systematic adaptation of CLI code to glob's object-oriented architecture. The key is respecting the constraint of no glob modifications while leveraging existing glob APIs effectively.
**Status**: This migration has been completed successfully. The CLI now uses glob module exclusively.

View File

@@ -1,407 +0,0 @@
# CLI Migration Testing Checklist
## 🧪 Testing Strategy Overview
**Approach**: Progressive testing at each implementation phase
**Tools**: Manual CLI testing, comparison with legacy behavior
**Environment**: ComfyUI development environment with test packages
---
# 📋 Phase 1 Testing (Import Changes)
## ✅ Basic CLI Loading (Must Pass)
```bash
# Test CLI loads without import errors
python -m comfyui_manager.cm_cli --help
python -m comfyui_manager.cm_cli help
# Expected: CLI help displays, no ImportError exceptions
```
## ✅ Simple Command Smoke Tests
```bash
# Commands that should work immediately
python -m comfyui_manager.cm_cli show snapshot
python -m comfyui_manager.cm_cli clear
# Expected: Commands execute, may show different output but no crashes
```
## 🐛 Error Identification
- [ ] Document all import-related errors
- [ ] Identify which functions fail immediately
- [ ] Note any missing attributes/methods used by CLI
- [ ] List functions that need immediate attention
**Pass Criteria**: CLI loads and basic commands don't crash
---
# 🔧 Phase 2 Testing (Core Functions)
## 🚀 Install Command Testing
### CNR Package Installation
```bash
# Test CNR package installation
python -m comfyui_manager.cm_cli install ComfyUI-Manager
python -m comfyui_manager.cm_cli install <known-cnr-package>
# Expected behaviors:
# - Package resolves correctly
# - Installation proceeds
# - Success/failure message displayed
# - Package appears in enabled state
```
**Test Cases**:
- [ ] Install new CNR package
- [ ] Install already-installed package (should skip)
- [ ] Install non-existent package (should error gracefully)
- [ ] Install with `--no-deps` flag
### Git URL Installation
```bash
# Test Git URL installation
python -m comfyui_manager.cm_cli install https://github.com/user/repo.git
python -m comfyui_manager.cm_cli install https://github.com/user/repo
# Expected behaviors:
# - URL detected as Git repository
# - repo_install() method called
# - Installation proceeds or fails gracefully
```
**Test Cases**:
- [ ] Install from Git URL with .git suffix
- [ ] Install from Git URL without .git suffix
- [ ] Install from invalid Git URL (should error)
- [ ] Install from private repository (may fail gracefully)
## 📊 Show Commands Testing
### Show Installed/Enabled
```bash
python -m comfyui_manager.cm_cli show installed
python -m comfyui_manager.cm_cli show enabled
# Expected: List of enabled packages with:
# - Package names
# - Version information
# - Author/publisher info where available
# - Correct status indicators
```
### Show Disabled/Not-Installed
```bash
python -m comfyui_manager.cm_cli show disabled
python -m comfyui_manager.cm_cli show not-installed
# Expected: Appropriate package lists with status
```
### Show All & Simple Mode
```bash
python -m comfyui_manager.cm_cli show all
python -m comfyui_manager.cm_cli simple-show all
# Expected: Comprehensive package list
# Simple mode should show condensed format
```
**Detailed Test Matrix**:
- [ ] `show installed` - displays all installed packages
- [ ] `show enabled` - displays only enabled packages
- [ ] `show disabled` - displays only disabled packages
- [ ] `show not-installed` - displays available but not installed packages
- [ ] `show all` - displays comprehensive list
- [ ] `show cnr` - displays CNR packages only
- [ ] `simple-show` variants - condensed output format
**Validation Criteria**:
- [ ] Package counts make sense (enabled + disabled = installed)
- [ ] CNR packages show publisher information
- [ ] Nightly packages marked appropriately
- [ ] Unknown packages handled correctly
- [ ] No crashes with empty package sets
## ⚙️ Management Commands Testing
### Enable/Disable Commands
```bash
# Enable disabled package
python -m comfyui_manager.cm_cli disable <package-name>
python -m comfyui_manager.cm_cli show disabled # Should appear
python -m comfyui_manager.cm_cli enable <package-name>
python -m comfyui_manager.cm_cli show enabled # Should appear
# Test edge cases
python -m comfyui_manager.cm_cli enable <already-enabled-package> # Should skip
python -m comfyui_manager.cm_cli disable <non-existent-package> # Should error
```
**Test Cases**:
- [ ] Enable disabled package
- [ ] Disable enabled package
- [ ] Enable already-enabled package (skip)
- [ ] Disable already-disabled package (skip)
- [ ] Enable non-existent package (error)
- [ ] Disable non-existent package (error)
### Uninstall Commands
```bash
# Uninstall package
python -m comfyui_manager.cm_cli uninstall <test-package>
python -m comfyui_manager.cm_cli show installed # Should not appear
# Test variations
python -m comfyui_manager.cm_cli uninstall <package>@unknown
```
**Test Cases**:
- [ ] Uninstall CNR package
- [ ] Uninstall nightly package
- [ ] Uninstall unknown package
- [ ] Uninstall non-existent package (should error gracefully)
### Update Commands
```bash
# Update specific package
python -m comfyui_manager.cm_cli update <package-name>
# Update all packages
python -m comfyui_manager.cm_cli update all
```
**Test Cases**:
- [ ] Update single package
- [ ] Update all packages
- [ ] Update non-existent package (should error)
- [ ] Update already up-to-date package (should skip)
## 🗃️ Advanced Function Testing
### get_all_installed_node_specs()
```bash
# This function is used internally by update/enable/disable "all" commands
python -m comfyui_manager.cm_cli update all
python -m comfyui_manager.cm_cli enable all
python -m comfyui_manager.cm_cli disable all
# Expected: Commands process all installed packages
```
**Validation**:
- [ ] "all" commands process expected number of packages
- [ ] Package specs format correctly (name@version)
- [ ] No duplicates in package list
- [ ] All package types included (CNR, nightly, unknown)
---
# 🧹 Phase 3 Testing (Feature Removal & Polish)
## ❌ Removed Feature Testing
### deps-in-workflow Command
```bash
python -m comfyui_manager.cm_cli deps-in-workflow workflow.json deps.json
# Expected: Clear error message explaining feature removal
# Should NOT crash or show confusing errors
```
### install-deps Command (if affected)
```bash
python -m comfyui_manager.cm_cli install-deps deps.json
# Expected: Either works with alternative implementation or shows clear error
```
**Validation**:
- [ ] Error messages are user-friendly
- [ ] No stack traces for removed features
- [ ] Help text updated to reflect changes
- [ ] Alternative solutions mentioned where applicable
## 📸 Snapshot Functionality
### Save/Restore Snapshots
```bash
# Save snapshot
python -m comfyui_manager.cm_cli save-snapshot test-snapshot.json
ls snapshots/ # Should show new snapshot
# Restore snapshot
python -m comfyui_manager.cm_cli restore-snapshot test-snapshot.json
```
**Test Cases**:
- [ ] Save snapshot to default location
- [ ] Save snapshot to custom path
- [ ] Restore snapshot successfully
- [ ] Handle invalid snapshot files gracefully
### Snapshot Display
```bash
python -m comfyui_manager.cm_cli show snapshot
python -m comfyui_manager.cm_cli show snapshot-list
```
**Validation**:
- [ ] Current state displayed correctly
- [ ] Snapshot list shows available snapshots
- [ ] JSON format valid and readable
---
# 🎯 Comprehensive Integration Testing
## 🔄 End-to-End Workflows
### Complete Package Lifecycle
```bash
# 1. Install package
python -m comfyui_manager.cm_cli install <test-package>
# 2. Verify installation
python -m comfyui_manager.cm_cli show enabled | grep <test-package>
# 3. Disable package
python -m comfyui_manager.cm_cli disable <test-package>
# 4. Verify disabled
python -m comfyui_manager.cm_cli show disabled | grep <test-package>
# 5. Re-enable package
python -m comfyui_manager.cm_cli enable <test-package>
# 6. Update package
python -m comfyui_manager.cm_cli update <test-package>
# 7. Uninstall package
python -m comfyui_manager.cm_cli uninstall <test-package>
# 8. Verify removal
python -m comfyui_manager.cm_cli show installed | grep <test-package> # Should be empty
```
### Batch Operations
```bash
# Install multiple packages
python -m comfyui_manager.cm_cli install package1 package2 package3
# Disable all packages
python -m comfyui_manager.cm_cli disable all
# Enable all packages
python -m comfyui_manager.cm_cli enable all
# Update all packages
python -m comfyui_manager.cm_cli update all
```
## 🚨 Error Condition Testing
### Network/Connectivity Issues
- [ ] Test with no internet connection
- [ ] Test with slow internet connection
- [ ] Test with CNR API unavailable
### File System Issues
- [ ] Test with insufficient disk space
- [ ] Test with permission errors
- [ ] Test with corrupted package directories
### Invalid Input Handling
- [ ] Non-existent package names
- [ ] Invalid Git URLs
- [ ] Malformed command arguments
- [ ] Special characters in package names
---
# 📊 Performance & Regression Testing
## ⚡ Performance Comparison
```bash
# Time core operations
time python -m comfyui_manager.cm_cli show all
time python -m comfyui_manager.cm_cli install <test-package>
time python -m comfyui_manager.cm_cli update all
# Compare with legacy timings if available
```
**Validation**:
- [ ] Operations complete in reasonable time
- [ ] No significant performance regression
- [ ] Memory usage acceptable
## 🔄 Regression Testing
### Output Format Comparison
- [ ] Compare show command output with legacy version
- [ ] Document acceptable format differences
- [ ] Ensure essential information preserved
### Behavioral Consistency
- [ ] Command success/failure behavior matches legacy
- [ ] Error message quality comparable to legacy
- [ ] User experience remains smooth
---
# ✅ Final Validation Checklist
## Must Pass (Blockers)
- [ ] All core commands functional (install/uninstall/enable/disable/update)
- [ ] Show commands display accurate package information
- [ ] No crashes or unhandled exceptions
- [ ] No modifications to glob module
- [ ] CLI loads and responds to help commands
## Should Pass (Important)
- [ ] Output format reasonably similar to legacy
- [ ] Performance comparable to legacy
- [ ] Error handling graceful and informative
- [ ] Removed features clearly communicated
## May Pass (Nice to Have)
- [ ] Output format identical to legacy
- [ ] Performance better than legacy
- [ ] Additional error recovery features
- [ ] Code improvements and cleanup
---
# 🧰 Testing Tools & Commands
## Essential Test Commands
```bash
# Quick smoke test
python -m comfyui_manager.cm_cli --help
# Core functionality test
python -m comfyui_manager.cm_cli show all
# Package management test
python -m comfyui_manager.cm_cli install <safe-test-package>
# Cleanup test
python -m comfyui_manager.cm_cli uninstall <test-package>
```
## Debug Commands
```bash
# Check Python imports
python -c "from comfyui_manager.glob import manager_core; print('OK')"
# Check data structures
python -c "from comfyui_manager.glob.manager_core import unified_manager; print(len(unified_manager.installed_node_packages))"
# Check CNR access
python -c "from comfyui_manager.common import cnr_utils; print(len(cnr_utils.get_all_nodepackages()))"
```
---
Use this checklist systematically during implementation to ensure comprehensive testing and validation of the CLI migration.

View File

@@ -1,184 +0,0 @@
# CLI Migration Documentation
**Status**: ✅ Completed (Historical Reference)
**Last Updated**: 2025-11-04
**Purpose**: Documentation for CLI migration from legacy to glob module (completed August 2025)
---
## 📁 Directory Overview
This directory contains consolidated documentation for the ComfyUI Manager CLI migration project. The migration successfully moved the CLI from the legacy module to the glob module without modifying glob module code.
---
## 📚 Documentation Files
### 🎯 **Comprehensive Guide**
- **[CLI_MIGRATION_GUIDE.md](CLI_MIGRATION_GUIDE.md)** (~800 lines)
- Complete migration guide with all technical details
- Legacy vs Glob comparison
- Implementation strategies
- Code examples and patterns
- **Read this first** for complete understanding
### 📖 **Implementation Resources**
- **[CLI_IMPLEMENTATION_CHECKLIST.md](CLI_IMPLEMENTATION_CHECKLIST.md)** (~350 lines)
- Step-by-step implementation tasks
- Daily breakdown (3.5 days)
- Testing checkpoints
- Completion criteria
- **[CLI_API_REFERENCE.md](CLI_API_REFERENCE.md)** (~300 lines)
- Quick API lookup guide
- UnifiedManager methods
- InstalledNodePackage structure
- Usage examples
- **[CLI_TESTING_GUIDE.md](CLI_TESTING_GUIDE.md)** (~400 lines)
- Comprehensive testing strategy
- Test scenarios and cases
- Validation procedures
- Rollback planning
---
## 🚀 Quick Start (For Reference)
### Understanding the Migration
1. **Start Here**: [CLI_MIGRATION_GUIDE.md](CLI_MIGRATION_GUIDE.md)
- Read sections: Overview → Legacy vs Glob → Migration Strategy
2. **API Reference**: [CLI_API_REFERENCE.md](CLI_API_REFERENCE.md)
- Use for quick API lookups during implementation
3. **Implementation**: [CLI_IMPLEMENTATION_CHECKLIST.md](CLI_IMPLEMENTATION_CHECKLIST.md)
- Follow step-by-step if re-implementing
4. **Testing**: [CLI_TESTING_GUIDE.md](CLI_TESTING_GUIDE.md)
- Reference for validation procedures
---
## 🎯 Migration Summary
### Objective Achieved
✅ Migrated CLI from `..legacy` to `..glob` imports using only existing glob APIs
### Key Accomplishments
-**Single file modified**: `comfyui_manager/cm_cli/__main__.py`
-**No glob modifications**: Used existing APIs only
-**All commands functional**: install, update, enable, disable, uninstall
-**show_list() rewritten**: Adapted to InstalledNodePackage architecture
-**Completed in**: 3.5 days as planned
### Major Changes
1. Import path updates (2 lines)
2. `install_node()` → use `repo_install()` for Git URLs
3. `show_list()` → rewritten for InstalledNodePackage
4. Data structure migration: dictionaries → objects
5. Removed unsupported features (deps-in-workflow)
---
## 📋 File Organization
```
docs/internal/cli_migration/
├── README.md (This file - Quick navigation)
├── CLI_MIGRATION_GUIDE.md (Complete guide - 800 lines)
├── CLI_IMPLEMENTATION_CHECKLIST.md (Task breakdown - 350 lines)
├── CLI_API_REFERENCE.md (API docs - 300 lines)
└── CLI_TESTING_GUIDE.md (Testing guide - 400 lines)
Total: 5 files, ~1,850 lines (consolidated from 9 files, ~2,400 lines)
```
---
## ✨ Documentation Improvements
### Before Consolidation (9 files)
- ❌ Duplicate content across multiple files
- ❌ Mixed languages (Korean/English)
- ❌ Unclear hierarchy
- ❌ Fragmented information
### After Consolidation (5 files)
- ✅ Single comprehensive guide
- ✅ All English
- ✅ Clear purpose per file
- ✅ Easy navigation
- ✅ No duplication
---
## 🔍 Key Constraints (Historical Reference)
### Hard Constraints
- ❌ NO modifications to glob module
- ❌ NO legacy dependencies post-migration
- ✅ CLI interface must remain unchanged
### Implementation Approach
- ✅ Adapt CLI code to glob architecture
- ✅ Use existing glob APIs only
- ✅ Minimal changes, maximum compatibility
---
## 📊 Migration Statistics
| Metric | Value |
|--------|-------|
| **Duration** | 3.5 days |
| **Files Modified** | 1 (`__main__.py`) |
| **Lines Changed** | ~200 lines |
| **glob Modifications** | 0 (constraint met) |
| **Tests Passing** | 100% |
| **Features Removed** | 1 (deps-in-workflow) |
---
## 🎓 Lessons Learned
### What Worked Well
1. **Consolidation First**: Understanding all legacy usage before coding
2. **API-First Design**: glob's clean API made migration straightforward
3. **Object-Oriented**: InstalledNodePackage simplified many operations
4. **No Glob Changes**: Constraint forced better CLI design
### Challenges Overcome
1. **show_list() Complexity**: Rewrote from scratch using new patterns
2. **Dictionary to Object**: Required rethinking data access patterns
3. **Async Handling**: Wrapped async methods appropriately
4. **Testing Without Mocks**: Relied on integration testing
---
## 📚 Related Documentation
### Project Documentation
- [Main Documentation Index](/DOCUMENTATION_INDEX.md)
- [Contributing Guidelines](/CONTRIBUTING.md)
- [Development Guidelines](/CLAUDE.md)
### Package Documentation
- [glob Module Guide](/comfyui_manager/glob/CLAUDE.md)
- [Data Models](/comfyui_manager/data_models/README.md)
---
## 🔗 Cross-References
**If you need to**:
- Understand glob APIs → [CLI_API_REFERENCE.md](CLI_API_REFERENCE.md)
- See implementation steps → [CLI_IMPLEMENTATION_CHECKLIST.md](CLI_IMPLEMENTATION_CHECKLIST.md)
- Run tests → [CLI_TESTING_GUIDE.md](CLI_TESTING_GUIDE.md)
- Understand full context → [CLI_MIGRATION_GUIDE.md](CLI_MIGRATION_GUIDE.md)
---
**Status**: ✅ Migration Complete - Documentation Archived for Reference
**Next Review**: When similar migration projects are planned

View File

@@ -1,328 +0,0 @@
# Future Test Plans
**Type**: Planning Document (Future Tests)
**Status**: P1 tests COMPLETE ✅ - Additional scenarios remain planned
**Current Implementation Status**: See [tests/glob/README.md](../../../tests/glob/README.md)
**Last Updated**: 2025-11-06
---
## Overview
This document contains test scenarios that are **planned but not yet implemented**. For currently implemented tests, see [tests/glob/README.md](../../../tests/glob/README.md).
**Currently Implemented**: 51 tests ✅ (includes all P1 complex scenarios)
**P1 Implementation**: COMPLETE ✅ (Phase 3.1, 5.1, 5.2, 5.3, 6)
**Planned in this document**: Additional scenarios for comprehensive coverage (P0, P2)
---
## 📋 Table of Contents
1. [Simple Test Scenarios](#simple-test-scenarios) - Additional basic API tests
2. [Complex Multi-Version Scenarios](#complex-multi-version-scenarios) - Advanced state management tests
3. [Priority Matrix](#priority-matrix) - Implementation priorities
---
# Simple Test Scenarios
These are straightforward single-version/type test scenarios that extend the existing test suite.
## 3. Error Handling Testing (Priority: Medium)
### Test 3.1: Install Non-existent Package
**Purpose**: Handle invalid package names
**Steps**:
1. Attempt to install with non-existent package ID
2. Verify appropriate error message
**Verification Items**:
- ✓ Error status returned
- ✓ Clear error message
- ✓ No server crash
### Test 3.2: Invalid Version Specification
**Purpose**: Handle non-existent version installation attempts
**Steps**:
1. Attempt to install with non-existent version (e.g., "99.99.99")
2. Verify error handling
**Verification Items**:
- ✓ Error status returned
- ✓ Clear error message
### Test 3.3: Permission Error Simulation
**Purpose**: Handle file system permission issues
**Steps**:
1. Set custom_nodes directory to read-only
2. Attempt package installation
3. Verify error handling
4. Restore permissions
**Verification Items**:
- ✓ Permission error detected
- ✓ Clear error message
- ✓ Partial installation rollback
---
## 4. Dependency Management Testing (Priority: Medium)
### Test 4.1: Installation with Dependencies
**Purpose**: Automatic installation of dependencies from packages with requirements.txt
**Steps**:
1. Install package with dependencies
2. Verify requirements.txt processing
3. Verify dependency packages installed
**Verification Items**:
- ✓ requirements.txt executed
- ✓ Dependency packages installed
- ✓ Installation scripts executed
### Test 4.2: no_deps Flag Testing
**Purpose**: Verify option to skip dependency installation
**Steps**:
1. Install package with no_deps=true
2. Verify requirements.txt skipped
3. Verify installation scripts skipped
**Verification Items**:
- ✓ Dependency installation skipped
- ✓ Only package files installed
---
## 5. Multi-package Management Testing (Priority: Medium)
### Test 5.1: Concurrent Multiple Package Installation
**Purpose**: Concurrent installation of multiple independent packages
**Steps**:
1. Add 3 different packages to queue
2. Start queue
3. Verify all packages installed
**Verification Items**:
- ✓ All packages installed successfully
- ✓ Installation order guaranteed
- ✓ Individual failures don't affect other packages
### Test 5.2: Same Package Concurrent Installation (Conflict Handling)
**Purpose**: Handle concurrent requests for same package
**Steps**:
1. Add same package to queue twice
2. Start queue
3. Verify duplicate handling
**Verification Items**:
- ✓ First installation successful
- ✓ Second request skipped
- ✓ Handled without errors
---
## 6. Security Level Testing (Priority: Low)
### Test 6.1: Installation Restrictions by Security Level
**Purpose**: Allow/deny installation based on security_level settings
**Steps**:
1. Set security_level to "strong"
2. Attempt installation with non-CNR registered URL
3. Verify rejection
**Verification Items**:
- ✓ Security level validation
- ✓ Appropriate error message
---
# Complex Multi-Version Scenarios
These scenarios test complex interactions between multiple versions and types of the same package.
## Test Philosophy
### Real-World Scenarios
1. User switches from Nightly to CNR
2. Install both CNR and Nightly, activate only one
3. Keep multiple versions in .disabled/ and switch as needed
4. Other versions exist in disabled state during Update
---
## Phase 7: Complex Version Switch Chains (Priority: High)
### Test 7.1: CNR Old Enabled → CNR New (Other Versions Disabled)
**Initial State:**
```
custom_nodes/:
└── ComfyUI_SigmoidOffsetScheduler/ (CNR 1.0.1)
.disabled/:
├── ComfyUI_SigmoidOffsetScheduler_1.0.0/
└── ComfyUI_SigmoidOffsetScheduler_nightly/
```
**Operation:** Install CNR v1.0.2 (version switch)
**Expected Result:**
```
custom_nodes/:
└── ComfyUI_SigmoidOffsetScheduler/ (CNR 1.0.2)
.disabled/:
├── ComfyUI_SigmoidOffsetScheduler_1.0.0/
├── ComfyUI_SigmoidOffsetScheduler_1.0.1/ (old enabled version)
└── ComfyUI_SigmoidOffsetScheduler_nightly/
```
**Verification Items:**
- ✓ Existing enabled version auto-disabled
- ✓ New version enabled
- ✓ All disabled versions maintained
- ✓ Version history managed
### Test 7.2: Version Switch Chain (Nightly → CNR Old → CNR New)
**Scenario:** Sequential version transitions
**Step 1:** Nightly enabled
**Step 2:** Switch to CNR 1.0.1
**Step 3:** Switch to CNR 1.0.2
**Verification Items:**
- ✓ Each transition step operates normally
- ✓ Version history accumulates
- ✓ Rollback-capable state maintained
---
## Phase 8: Edge Cases & Error Scenarios (Priority: Medium)
### Test 8.1: Corrupted Package in .disabled/
**Situation:** Corrupted package exists in .disabled/
**Operation:** Attempt Enable
**Expected Result:**
- Clear error message
- Fallback to other version (if possible)
- System stability maintained
### Test 8.2: Name Collision in .disabled/
**Situation:** Package with same name already exists in .disabled/
**Operation:** Attempt Disable
**Expected Result:**
- Generate unique name (timestamp, etc.)
- No data loss
- All versions distinguishable
### Test 8.3: Enable Non-existent Version
**Situation:** Requested version not in .disabled/
**Operation:** Enable specific version
**Expected Result:**
- Clear error message
- Available version list provided
- Graceful failure
---
# Priority Matrix
**Note**: Phases 3, 4, 5, and 6 are now complete and documented in [tests/glob/README.md](../../../tests/glob/README.md). This matrix shows only planned future tests.
| Phase | Scenario | Priority | Status | Complexity | Real-World Frequency |
|-------|----------|----------|--------|------------|---------------------|
| 7 | Complex Version Switch Chains | P0 | 🔄 PARTIAL | High | High |
| 8 | Edge Cases & Error Scenarios | P2 | ⏳ PLANNED | High | Low |
| Simple | Error Handling (3.1-3.3) | P2 | ⏳ PLANNED | Medium | Medium |
| Simple | Dependency Management (4.1-4.2) | P2 | ⏳ PLANNED | Medium | Medium |
| Simple | Multi-package Management (5.1-5.2) | P2 | ⏳ PLANNED | Medium | Low |
| Simple | Security Level Testing (6.1) | P2 | ⏳ PLANNED | Low | Low |
**Priority Definitions:**
- **P0:** High priority (implement next) - Phase 7 Complex Version Switch
- **P1:** Medium priority - ✅ **ALL COMPLETE** (Phase 3, 4, 5, 6 - see tests/glob/README.md)
- **P2:** Low priority (implement as needed) - Simple tests and Phase 8
**Status Definitions:**
- 🔄 PARTIAL: Some tests implemented (Phase 7 has version switching tests in test_version_switching_comprehensive.py)
- ⏳ PLANNED: Not yet started
**Recommended Next Steps:**
1. **Phase 7 Remaining Tests** (P0) - Complex version switch chains with multiple disabled versions
2. **Simple Test Scenarios** (P2) - Error handling, dependency management, multi-package operations
3. **Phase 8** (P2) - Edge cases and error scenarios
---
# Implementation Notes
## Fixture Patterns
For multi-version tests, use these fixture patterns:
```python
@pytest.fixture
def setup_multi_disabled_cnr_and_nightly(api_client, custom_nodes_path):
"""
Install both CNR and Nightly in disabled state.
Pattern:
1. Install CNR → custom_nodes/
2. Disable CNR → .disabled/comfyui_sigmoidoffsetscheduler@1_0_2
3. Install Nightly → custom_nodes/
4. Disable Nightly → .disabled/comfyui_sigmoidoffsetscheduler@nightly
"""
# Implementation details in archived COMPLEX_SCENARIOS_TEST_PLAN.md
```
## Verification Helpers
Use these verification patterns:
```python
def verify_version_state(custom_nodes_path, expected_state):
"""
Verify package state matches expectations.
expected_state = {
'enabled': {'type': 'cnr' | 'nightly' | None, 'version': '1.0.2'},
'disabled': [
{'type': 'cnr', 'version': '1.0.1'},
{'type': 'nightly'}
]
}
"""
# Implementation details in archived COMPLEX_SCENARIOS_TEST_PLAN.md
```
---
# References
## Archived Implementation Guides
Detailed implementation examples, code snippets, and fixtures are available in archived planning documents:
- `.claude/archive/docs_2025-11-04/COMPLEX_SCENARIOS_TEST_PLAN.md` - Complete implementation guide with code examples
- `.claude/archive/docs_2025-11-04/TEST_PLAN_ADDITIONAL.md` - Simple test scenarios
## Current Implementation
For currently implemented tests and their status:
- **[tests/glob/README.md](../../../tests/glob/README.md)** - Current test status and coverage
---
**End of Future Test Plans**

View File

@@ -1,137 +0,0 @@
#!/bin/bash
# ============================================================================
# Test Monitoring Script
# ============================================================================
# Monitors background test execution and reports status/failures
# Usage: ./monitor_test.sh <log_file> <timeout_seconds>
# ============================================================================
set -e
LOG_FILE="${1:-/tmp/test-param-fix.log}"
TIMEOUT="${2:-600}" # Default 10 minutes
CHECK_INTERVAL=10 # Check every 10 seconds
STALL_THRESHOLD=60 # Consider stalled if no new output for 60 seconds
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Test Monitor Started${NC}"
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Log File: ${LOG_FILE}${NC}"
echo -e "${BLUE}Timeout: ${TIMEOUT}s${NC}"
echo -e "${BLUE}Stall Threshold: ${STALL_THRESHOLD}s${NC}"
echo ""
START_TIME=$(date +%s)
LAST_SIZE=0
LAST_CHANGE_TIME=$START_TIME
STATUS="running"
while true; do
CURRENT_TIME=$(date +%s)
ELAPSED=$((CURRENT_TIME - START_TIME))
# Check if log file exists
if [ ! -f "$LOG_FILE" ]; then
echo -e "${YELLOW}[$(date '+%H:%M:%S')] Waiting for log file...${NC}"
sleep $CHECK_INTERVAL
continue
fi
# Check file size
CURRENT_SIZE=$(wc -c < "$LOG_FILE" 2>/dev/null || echo "0")
TIME_SINCE_CHANGE=$((CURRENT_TIME - LAST_CHANGE_TIME))
# Check if file size changed (progress)
if [ "$CURRENT_SIZE" -gt "$LAST_SIZE" ]; then
LAST_SIZE=$CURRENT_SIZE
LAST_CHANGE_TIME=$CURRENT_TIME
# Show latest lines
echo -e "${GREEN}[$(date '+%H:%M:%S')] Progress detected (${CURRENT_SIZE} bytes, +${ELAPSED}s)${NC}"
tail -3 "$LOG_FILE" | sed 's/\x1b\[[0-9;]*m//g' # Remove color codes
echo ""
else
# No progress
echo -e "${YELLOW}[$(date '+%H:%M:%S')] No change (stalled ${TIME_SINCE_CHANGE}s)${NC}"
fi
# Check for completion markers
if grep -q "✅ ComfyUI_.*: PASSED" "$LOG_FILE" 2>/dev/null || \
grep -q "❌ ComfyUI_.*: FAILED" "$LOG_FILE" 2>/dev/null || \
grep -q "Test Suite Complete" "$LOG_FILE" 2>/dev/null; then
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Tests Completed!${NC}"
echo -e "${GREEN}========================================${NC}"
# Show summary
grep -E "passed|failed|PASSED|FAILED" "$LOG_FILE" | tail -20
# Check if tests passed
if grep -q "❌.*FAILED" "$LOG_FILE" 2>/dev/null; then
echo -e "${RED}❌ Some tests FAILED${NC}"
STATUS="failed"
else
echo -e "${GREEN}✅ All tests PASSED${NC}"
STATUS="success"
fi
break
fi
# Check for errors
if grep -qi "error\|exception\|traceback" "$LOG_FILE" 2>/dev/null; then
LAST_ERROR=$(grep -i "error\|exception" "$LOG_FILE" | tail -1)
echo -e "${RED}[$(date '+%H:%M:%S')] Error detected: ${LAST_ERROR}${NC}"
fi
# Check for stall (no progress for STALL_THRESHOLD seconds)
if [ "$TIME_SINCE_CHANGE" -gt "$STALL_THRESHOLD" ]; then
echo -e "${RED}========================================${NC}"
echo -e "${RED}⚠️ Test Execution STALLED${NC}"
echo -e "${RED}========================================${NC}"
echo -e "${RED}No progress for ${TIME_SINCE_CHANGE} seconds${NC}"
echo -e "${RED}Last output:${NC}"
tail -10 "$LOG_FILE" | sed 's/\x1b\[[0-9;]*m//g'
STATUS="stalled"
break
fi
# Check for timeout
if [ "$ELAPSED" -gt "$TIMEOUT" ]; then
echo -e "${RED}========================================${NC}"
echo -e "${RED}⏰ Test Execution TIMEOUT${NC}"
echo -e "${RED}========================================${NC}"
echo -e "${RED}Exceeded ${TIMEOUT}s timeout${NC}"
STATUS="timeout"
break
fi
# Wait before next check
sleep $CHECK_INTERVAL
done
# Final status
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Final Status: ${STATUS}${NC}"
echo -e "${BLUE}Total Time: ${ELAPSED}s${NC}"
echo -e "${BLUE}========================================${NC}"
# Exit with appropriate code
case "$STATUS" in
"success") exit 0 ;;
"failed") exit 1 ;;
"stalled") exit 2 ;;
"timeout") exit 3 ;;
*) exit 99 ;;
esac

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,15 @@
{
"custom_nodes": [
{
"author": "synchronicity-labs",
"title": "ComfyUI Sync Lipsync Node",
"reference": "https://github.com/synchronicity-labs/sync-comfyui",
"files": [
"https://github.com/synchronicity-labs/sync-comfyui"
],
"install_type": "git-clone",
"description": "This custom node allows you to perform audio-video lip synchronization inside ComfyUI using a simple interface."
},
{
"author": "joaomede",
"title": "ComfyUI-Unload-Model-Fork",

View File

@@ -1,5 +1,379 @@
{
"custom_nodes": [
{
"author": "aistudynow",
"title": "comfyui-HunyuanImage-2.1 [REMOVED]",
"reference": "https://github.com/aistudynow/comfyui-HunyuanImage-2.1",
"files": [
"https://github.com/aistudynow/comfyui-HunyuanImage-2.1"
],
"install_type": "git-clone",
"description": "NODES: Load HunyuanImage DiT, Load HunyuanImage VAE, Load HunyuanImage Dual Text Encoder, HunyuanImage Sampler, HunyuanImage VAE Decode, HunyuanImage CLIP Text Encode, Empty HunyuanImage Latent Image"
},
{
"author": "SlackinJack",
"title": "distrifuser_comfyui [DEPRECATED]",
"reference": "https://github.com/SlackinJack/distrifuser_comfyui",
"files": [
"https://github.com/SlackinJack/distrifuser_comfyui"
],
"install_type": "git-clone",
"description": "[a/Distrifuser](https://github.com/mit-han-lab/distrifuser) sampler node for ComfyUI\n"
},
{
"author": "SlackinJack",
"title": "asyncdiff_comfyui [DEPRECATED]",
"reference": "https://github.com/SlackinJack/asyncdiff_comfyui",
"files": [
"https://github.com/SlackinJack/asyncdiff_comfyui"
],
"install_type": "git-clone",
"description": "AsyncDiff node for ComfyUI"
},
{
"author": "TheBill2001",
"title": "Save Images with Captions [REMOVED]",
"reference": "https://github.com/TheBill2001/ComfyUI-Save-Image-Caption",
"files": [
"https://github.com/TheBill2001/ComfyUI-Save-Image-Caption"
],
"install_type": "git-clone",
"description": "Provide two custom nodes to load and save images with captions as separate files."
},
{
"author": "ShmuelRonen",
"title": "ComfyUI Flux 1.1 Ultra & Raw Node [REMOVED]",
"reference": "https://github.com/ShmuelRonen/ComfyUI_Flux_1.1_RAW_API",
"files": [
"https://github.com/ShmuelRonen/ComfyUI_Flux_1.1_RAW_API"
],
"install_type": "git-clone",
"description": "A ComfyUI custom node for Black Forest Labs' FLUX 1.1 [pro] API, supporting both regular and Ultra modes with optional Raw mode."
},
{
"author": "mattwilliamson",
"title": "ComfyUI AI GameDev Nodes [UNSAFE/REMOVED]",
"reference": "https://github.com/mattwilliamson/comfyui-ai-gamedev",
"files": [
"https://github.com/mattwilliamson/comfyui-ai-gamedev"
],
"install_type": "git-clone",
"description": "Custom ComfyUI nodes for AI-powered game asset generation, providing a comprehensive toolkit for game developers to create 3D models, animations, and audio assets using state-of-the-art AI models.[w/This node pack has an implementation that dynamically generates scripts.]"
},
{
"author": "manifestations",
"title": "ComfyUI Outfit Nodes [DEPRECATED]",
"reference": "https://github.com/manifestations/comfyui-outfit",
"files": [
"https://github.com/manifestations/comfyui-outfit"
],
"install_type": "git-clone",
"description": "Advanced, professional outfit and makeup generation nodes for ComfyUI, with dynamic UI and AI-powered prompt formatting."
},
{
"author": "Poukpalaova",
"title": "ComfyUI-FRED-Nodes [DEPRECATED]",
"reference": "https://github.com/Poukpalaova/ComfyUI-FRED-Nodes",
"files": [
"https://github.com/Poukpalaova/ComfyUI-FRED-Nodes"
],
"install_type": "git-clone",
"description": "Multiple nodes that ease the process.\nNOTE: The files in the repo are not organized."
},
{
"author": "cwebbi1",
"title": "VoidCustomNodes [REMOVED]",
"reference": "https://github.com/cwebbi1/VoidCustomNodes",
"files": [
"https://github.com/cwebbi1/VoidCustomNodes"
],
"install_type": "git-clone",
"description": "NODES:Prompt Parser, String Combiner"
},
{
"author": "Shellishack",
"title": "ComfyUI Remote Media Loaders [REMOVED]",
"reference": "https://github.com/Shellishack/comfyui-remote-media-loaders",
"files": [
"https://github.com/Shellishack/comfyui-remote-media-loaders"
],
"install_type": "git-clone",
"description": "Load media (image/video/audio) from remote URL"
},
{
"author": "D3lUX3I",
"title": "VideoPromptEnhancer [REMOVED]",
"reference": "https://github.com/D3lUX3I/ComfyUI-VideoPromptEnhancer",
"files": [
"https://github.com/D3lUX3I/ComfyUI-VideoPromptEnhancer"
],
"install_type": "git-clone",
"description": "This node generates a professional prompt from an input text for modern video AI models (e.g., Alibaba Wan 2.2) via the OpenRouter API."
},
{
"author": "perilli",
"title": "apw_nodes [REMOVED]",
"reference": "https://github.com/alessandroperilli/APW_Nodes",
"files": [
"https://github.com/alessandroperilli/APW_Nodes"
],
"install_type": "git-clone",
"description": "A custom node suite to augment the capabilities of the [a/AP Workflows for ComfyUI](https://perilli.com/ai/comfyui/)\nNOTE: See [a/Open Creative Studio Nodes](https://github.com/alessandroperilli/OCS_Nodes)"
},
{
"author": "greengerong",
"title": "ComfyUI-Lumina-Video [REMOVED]",
"reference": "https://github.com/greengerong/ComfyUI-Lumina-Video",
"files": [
"https://github.com/greengerong/ComfyUI-Lumina-Video"
],
"install_type": "git-clone",
"description": "This is a video generation plugin implementation for ComfyUI based on the Lumina Video model."
},
{
"author": "SatadalAI",
"title": "Combined Upscale Node for ComfyUI [REMOVED]",
"reference": "https://github.com/SatadalAI/SATA_UtilityNode",
"files": [
"https://github.com/SatadalAI/SATA_UtilityNode"
],
"install_type": "git-clone",
"description": "Combined_Upscale is a custom ComfyUI node designed for high-quality image enhancement workflows. It intelligently combines model-based upscaling with efficient CPU-based resizing, offering granular control over output dimensions and quality. Ideal for asset pipelines, UI prototyping, and generative workflows.\nNOTE: The files in the repo are not organized."
},
{
"author": "netroxin",
"title": "Netro_wildcards [REMOVED]",
"reference": "https://github.com/netroxin/comfyui_netro_wildcards",
"files": [
"https://github.com/netroxin/comfyui_netro_wildcards"
],
"install_type": "git-clone",
"description": "Since I used 'simple wildcards' from Vanilla and it no longer works with the new Comfy UI version for me, I created an alternative. This CustomNode takes the entire contents of your wildcards-folder(comfyui wildcards) and creates a node for each one."
},
{
"author": "takoyaki1118",
"title": "ComfyUI-MangaTools [REMOVED]",
"reference": "https://github.com/takoyaki1118/ComfyUI-MangaTools",
"files": [
"https://github.com/takoyaki1118/ComfyUI-MangaTools"
],
"install_type": "git-clone",
"description": "NODES: Manga Panel Detector, Manga Panel Dispatcher, GateImage, MangaPageAssembler"
},
{
"author": "lucasgattas",
"title": "comfyui-egregora-regional [REMOVED]",
"reference": "https://github.com/lucasgattas/comfyui-egregora-regional",
"files": [
"https://github.com/lucasgattas/comfyui-egregora-regional"
],
"install_type": "git-clone",
"description": "Image Tile Split with Region-Aware Prompting for ComfyUI"
},
{
"author": "lucasgattas",
"title": "comfyui-egregora-tiled [REMOVED]",
"reference": "https://github.com/lucasgattas/comfyui-egregora-tiled",
"files": [
"https://github.com/lucasgattas/comfyui-egregora-tiled"
],
"install_type": "git-clone",
"description": "Tiled regional prompting + tiled VAE decode with seam-free blending for ComfyUI"
},
{
"author": "Seedsa",
"title": "ComfyUI Fooocus Nodes [REMOVED]",
"id": "fooocus-nodes",
"reference": "https://github.com/Seedsa/Fooocus_Nodes",
"files": [
"https://github.com/Seedsa/Fooocus_Nodes"
],
"install_type": "git-clone",
"description": "This extension provides image generation features based on Fooocus."
},
{
"author": "zhilemann",
"title": "ComfyUI-moondream2 [REMOVED]",
"reference": "https://github.com/zhilemann/ComfyUI-moondream2",
"files": [
"https://github.com/zhilemann/ComfyUI-moondream2"
],
"install_type": "git-clone",
"description": "nodes for nightly moondream2 VLM inference\nsupports only captioning and visual queries at the moment"
},
{
"author": "shinich39",
"title": "comfyui-textarea-is-shit [REMOVED]",
"reference": "https://github.com/shinich39/comfyui-textarea-is-shit",
"files": [
"https://github.com/shinich39/comfyui-textarea-is-shit"
],
"description": "HTML gives me a textarea like piece of shit.",
"install_type": "git-clone"
},
{
"author": "shinich39",
"title": "comfyui-poor-textarea [REMOVED]",
"reference": "https://github.com/shinich39/comfyui-poor-textarea",
"files": [
"https://github.com/shinich39/comfyui-poor-textarea"
],
"install_type": "git-clone",
"description": "Add commentify, indentation, auto-close brackets in textarea."
},
{
"author": "InfiniNode",
"title": "Comfyui-InfiniNode-Model-Suite [UNSAFE/REMOVED]",
"reference": "https://github.com/InfiniNode/Comfyui-InfiniNode-Model-Suite",
"files": [
"https://github.com/InfiniNode/Comfyui-InfiniNode-Model-Suite"
],
"install_type": "git-clone",
"description": "Welcome to the InfiniNode Model Suite, a custom node pack for ComfyUI that transforms the process of manipulating generative AI models. Our suite is a direct implementation of the 'GUI-Based Key Converter Development Plan,' designed to remove technical barriers for advanced AI practitioners and integrate seamlessly with existing image generation pipelines.[w/This node pack contains a node that has a vulnerability allowing write to arbitrary file paths.]"
},
{
"author": "Avalre",
"title": "ComfyUI-avaNodes [REMOVED]",
"reference": "https://github.com/Avalre/ComfyUI-avaNodes",
"files": [
"https://github.com/Avalre/ComfyUI-avaNodes"
],
"install_type": "git-clone",
"description": "These nodes were created to personalize/optimize several ComfyUI nodes for my own use. You can replicate the functionality of most of my nodes by some combination of default ComfyUI nodes and custom nodes from other developers."
},
{
"author": "Alectriciti",
"title": "comfyui-creativeprompts [REMOVED]",
"reference": "https://github.com/Alectriciti/comfyui-creativeprompts",
"files": [
"https://github.com/Alectriciti/comfyui-creativeprompts"
],
"install_type": "git-clone",
"description": "A creative alternative to dynamicprompts"
},
{
"author": "flybirdxx",
"title": "ComfyUI Sliding Window [REMOVED]",
"reference": "https://github.com/PixWizardry/ComfyUI_Sliding_Window",
"files": [
"https://github.com/PixWizardry/ComfyUI_Sliding_Window"
],
"install_type": "git-clone",
"description": "This set of nodes provides a powerful sliding window or 'tiling' technique for processing long videos and animations in ComfyUI. It allows you to work on animations that are longer than your VRAM would typically allow by breaking the job into smaller, overlapping chunks and seamlessly blending them back together."
},
{
"author": "SykkoAtHome",
"title": "Sykko Tools for ComfyUI [REMOVED]",
"reference": "https://github.com/SykkoAtHome/ComfyUI_SykkoTools",
"files": [
"https://github.com/SykkoAtHome/ComfyUI_SykkoTools"
],
"install_type": "git-clone",
"description": "Utilities for working with camera animations inside ComfyUI. The repository currently provides a node for loading camera motion from ASCII FBX files and a corresponding command line helper for debugging."
},
{
"author": "hananbeer",
"title": "node_dev - ComfyUI Node Development Helper [REMOVED]",
"reference": "https://github.com/hananbeer/node_dev",
"files": [
"https://github.com/hananbeer/node_dev"
],
"install_type": "git-clone",
"description": "Browse to this endpoint to reload custom nodes for more streamlined development:\nhttp://127.0.0.1:8188/node_dev/reload/<module_name>"
},
{
"author": "Charonartist",
"title": "Comfyui_gemini_tts_node [REMOVED]",
"reference": "https://github.com/Charonartist/Comfyui_gemini_tts_node",
"files": [
"https://github.com/Charonartist/Comfyui_gemini_tts_node"
],
"install_type": "git-clone",
"description": "This custom node is a ComfyUI node for generating speech from text using the Gemini 2.5 Flash Preview TTS API."
},
{
"author": "squirrel765",
"title": "lorasubdirectory [REMOVED]",
"reference": "https://github.com/andrewsthomasj/lorasubdirectory",
"files": [
"https://github.com/andrewsthomasj/lorasubdirectory"
],
"install_type": "git-clone",
"description": "only show dropdown of loras ina a given subdirectory"
},
{
"author": "shingo1228",
"title": "ComfyUI-send-Eagle(slim) [REVMOED]",
"id": "send-eagle",
"reference": "https://github.com/shingo1228/ComfyUI-send-eagle-slim",
"files": [
"https://github.com/shingo1228/ComfyUI-send-eagle-slim"
],
"install_type": "git-clone",
"description": "Nodes:Send Webp Image to Eagle. This is an extension node for ComfyUI that allows you to send generated images in webp format to Eagle. This extension node is a re-implementation of the Eagle linkage functions of the previous ComfyUI-send-Eagle node, focusing on the functions required for this node."
},
{
"author": "shingo1228",
"title": "ComfyUI-SDXL-EmptyLatentImage [REVMOED]",
"id": "sdxl-emptylatent",
"reference": "https://github.com/shingo1228/ComfyUI-SDXL-EmptyLatentImage",
"files": [
"https://github.com/shingo1228/ComfyUI-SDXL-EmptyLatentImage"
],
"install_type": "git-clone",
"description": "Nodes:SDXL Empty Latent Image. An extension node for ComfyUI that allows you to select a resolution from the pre-defined json files and output a Latent Image."
},
{
"author": "chaunceyyann",
"title": "ComfyUI Image Processing Nodes [REMOVED]",
"reference": "https://github.com/chaunceyyann/comfyui-image-processing-nodes",
"files": [
"https://github.com/chaunceyyann/comfyui-image-processing-nodes"
],
"install_type": "git-clone",
"description": "A collection of custom nodes for ComfyUI focused on image processing operations."
},
{
"author": "OgreLemonSoup",
"title": "Gallery&Tabs [DEPRECATED]",
"id": "LoadImageGallery",
"reference": "https://github.com/OgreLemonSoup/ComfyUI-Load-Image-Gallery",
"files": [
"https://github.com/OgreLemonSoup/ComfyUI-Load-Image-Gallery"
],
"install_type": "git-clone",
"description": "Adds a gallery to the Load Image node and tabs for Load Checkpoint/Lora/etc nodes"
},
{
"author": "11dogzi",
"title": "Qwen-Image ComfyUI [REMOVED]",
"reference": "https://github.com/11dogzi/Comfyui-Qwen-Image",
"files": [
"https://github.com/11dogzi/Comfyui-Qwen-Image"
],
"install_type": "git-clone",
"description": "This is a custom node package that integrates the Qwen-Image model into ComfyUI."
},
{
"author": "BAIS1C",
"title": "ComfyUI-AudioDuration [REMOVED]",
"reference": "https://github.com/BAIS1C/ComfyUI_BASICDancePoser",
"files": [
"https://github.com/BAIS1C/ComfyUI_BASICDancePoser"
],
"install_type": "git-clone",
"description": "Node to extract Dance poses from Music to control Video Generations.\nNOTE: The files in the repo are not organized."
},
{
"author": "BAIS1C",
"title": "ComfyUI_BASICSAdvancedDancePoser [REMOVED]",
"reference": "https://github.com/BAIS1C/ComfyUI_BASICSAdvancedDancePoser",
"files": [
"https://github.com/BAIS1C/ComfyUI_BASICSAdvancedDancePoser"
],
"install_type": "git-clone",
"description": "Professional COCO-WholeBody 133-keypoint dance animation system for ComfyUI"
},
{
"author": "fablestudio",
"title": "ComfyUI-Showrunner-Utils [REMOVED]",

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,106 @@
{
"models": [
{
"name": "Comfy-Org/Wan2.2 i2v high noise 14B (fp16)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for i2v high noise 14B (fp16)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_i2v_high_noise_14B_fp16.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_i2v_high_noise_14B_fp16.safetensors",
"size": "28.6GB"
},
{
"name": "Comfy-Org/Wan2.2 i2v high noise 14B (fp8_scaled)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for i2v high noise 14B (fp8_scaled)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_i2v_high_noise_14B_fp8_scaled.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_i2v_high_noise_14B_fp8_scaled.safetensors",
"size": "14.3GB"
},
{
"name": "Comfy-Org/Wan2.2 i2v low noise 14B (fp16)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for i2v low noise 14B (fp16)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_i2v_low_noise_14B_fp16.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_i2v_low_noise_14B_fp16.safetensors",
"size": "28.6GB"
},
{
"name": "Comfy-Org/Wan2.2 i2v low noise 14B (fp8_scaled)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for i2v low noise 14B (fp8_scaled)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_i2v_low_noise_14B_fp8_scaled.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_i2v_low_noise_14B_fp8_scaled.safetensors",
"size": "14.3GB"
},
{
"name": "Comfy-Org/Wan2.2 t2v high noise 14B (fp16)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for t2v high noise 14B (fp16)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_t2v_high_noise_14B_fp16.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_t2v_high_noise_14B_fp16.safetensors",
"size": "28.6GB"
},
{
"name": "Comfy-Org/Wan2.2 t2v high noise 14B (fp8_scaled)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for t2v high noise 14B (fp8_scaled)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_t2v_high_noise_14B_fp8_scaled.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_t2v_high_noise_14B_fp8_scaled.safetensors",
"size": "14.3GB"
},
{
"name": "Comfy-Org/Wan2.2 t2v low noise 14B (fp16)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for t2v low noise 14B (fp16)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_t2v_low_noise_14B_fp16.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_t2v_low_noise_14B_fp16.safetensors",
"size": "28.6GB"
},
{
"name": "Comfy-Org/Wan2.2 t2v low noise 14B (fp8_scaled)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for t2v low noise 14B (fp8_scaled)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_t2v_low_noise_14B_fp8_scaled.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_t2v_low_noise_14B_fp8_scaled.safetensors",
"size": "14.3GB"
},
{
"name": "Comfy-Org/Wan2.2 ti2v 5B (fp16)",
"type": "diffusion_model",
"base": "Wan2.2",
"save_path": "diffusion_models/Wan2.2",
"description": "Wan2.2 diffusion model for ti2v 5B (fp16)",
"reference": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged",
"filename": "wan2.2_ti2v_5B_fp16.safetensors",
"url": "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/resolve/main/split_files/diffusion_models/wan2.2_ti2v_5B_fp16.safetensors",
"size": "10.0GB"
},
{
"name": "sam2.1_hiera_tiny.pt",
"type": "sam2.1",
@@ -586,109 +687,6 @@
"filename": "llava_llama3_fp16.safetensors",
"url": "https://huggingface.co/Comfy-Org/HunyuanVideo_repackaged/resolve/main/split_files/text_encoders/llava_llama3_fp16.safetensors",
"size": "16.1GB"
},
{
"name": "PixArt-Sigma-XL-2-512-MS.safetensors (diffusion)",
"type": "diffusion_model",
"base": "pixart-sigma",
"save_path": "diffusion_models/PixArt-Sigma",
"description": "PixArt-Sigma Diffusion model",
"reference": "https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-512-MS",
"filename": "PixArt-Sigma-XL-2-512-MS.safetensors",
"url": "https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-512-MS/resolve/main/transformer/diffusion_pytorch_model.safetensors",
"size": "2.44GB"
},
{
"name": "PixArt-Sigma-XL-2-1024-MS.safetensors (diffusion)",
"type": "diffusion_model",
"base": "pixart-sigma",
"save_path": "diffusion_models/PixArt-Sigma",
"description": "PixArt-Sigma Diffusion model",
"reference": "https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-1024-MS",
"filename": "PixArt-Sigma-XL-2-1024-MS.safetensors",
"url": "https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-1024-MS/resolve/main/transformer/diffusion_pytorch_model.safetensors",
"size": "2.44GB"
},
{
"name": "PixArt-XL-2-1024-MS.safetensors (diffusion)",
"type": "diffusion_model",
"base": "pixart-alpha",
"save_path": "diffusion_models/PixArt-Alpha",
"description": "PixArt-Alpha Diffusion model",
"reference": "https://huggingface.co/PixArt-alpha/PixArt-XL-2-1024-MS",
"filename": "PixArt-XL-2-1024-MS.safetensors",
"url": "https://huggingface.co/PixArt-alpha/PixArt-XL-2-1024-MS/resolve/main/transformer/diffusion_pytorch_model.safetensors",
"size": "2.45GB"
},
{
"name": "Comfy-Org/hunyuan_video_t2v_720p_bf16.safetensors",
"type": "diffusion_model",
"base": "Hunyuan Video",
"save_path": "diffusion_models/hunyuan_video",
"description": "Huyuan Video diffusion model. repackaged version.",
"reference": "https://huggingface.co/Comfy-Org/HunyuanVideo_repackaged",
"filename": "hunyuan_video_t2v_720p_bf16.safetensors",
"url": "https://huggingface.co/Comfy-Org/HunyuanVideo_repackaged/resolve/main/split_files/diffusion_models/hunyuan_video_t2v_720p_bf16.safetensors",
"size": "25.6GB"
},
{
"name": "Comfy-Org/hunyuan_video_vae_bf16.safetensors",
"type": "VAE",
"base": "Hunyuan Video",
"save_path": "VAE",
"description": "Huyuan Video VAE model. repackaged version.",
"reference": "https://huggingface.co/Comfy-Org/HunyuanVideo_repackaged",
"filename": "hunyuan_video_vae_bf16.safetensors",
"url": "https://huggingface.co/Comfy-Org/HunyuanVideo_repackaged/resolve/main/split_files/vae/hunyuan_video_vae_bf16.safetensors",
"size": "493MB"
},
{
"name": "LTX-Video 2B v0.9.1 Checkpoint",
"type": "checkpoint",
"base": "LTX-Video",
"save_path": "checkpoints/LTXV",
"description": "LTX-Video is the first DiT-based video generation model capable of generating high-quality videos in real-time. It produces 24 FPS videos at a 768x512 resolution faster than they can be watched. Trained on a large-scale dataset of diverse videos, the model generates high-resolution videos with realistic and varied content.",
"reference": "https://huggingface.co/Lightricks/LTX-Video",
"filename": "ltx-video-2b-v0.9.1.safetensors",
"url": "https://huggingface.co/Lightricks/LTX-Video/resolve/main/ltx-video-2b-v0.9.1.safetensors",
"size": "5.72GB"
},
{
"name": "XLabs-AI/flux-canny-controlnet-v3.safetensors",
"type": "controlnet",
"base": "FLUX.1",
"save_path": "xlabs/controlnets",
"description": "ControlNet checkpoints for FLUX.1-dev model by Black Forest Labs.",
"reference": "https://huggingface.co/XLabs-AI/flux-controlnet-collections",
"filename": "flux-canny-controlnet-v3.safetensors",
"url": "https://huggingface.co/XLabs-AI/flux-controlnet-collections/resolve/main/flux-canny-controlnet-v3.safetensors",
"size": "1.49GB"
},
{
"name": "XLabs-AI/flux-depth-controlnet-v3.safetensors",
"type": "controlnet",
"base": "FLUX.1",
"save_path": "xlabs/controlnets",
"description": "ControlNet checkpoints for FLUX.1-dev model by Black Forest Labs.",
"reference": "https://huggingface.co/XLabs-AI/flux-controlnet-collections",
"filename": "flux-depth-controlnet-v3.safetensors",
"url": "https://huggingface.co/XLabs-AI/flux-controlnet-collections/resolve/main/flux-depth-controlnet-v3.safetensors",
"size": "1.49GB"
},
{
"name": "XLabs-AI/flux-hed-controlnet-v3.safetensors",
"type": "controlnet",
"base": "FLUX.1",
"save_path": "xlabs/controlnets",
"description": "ControlNet checkpoints for FLUX.1-dev model by Black Forest Labs.",
"reference": "https://huggingface.co/XLabs-AI/flux-controlnet-collections",
"filename": "flux-hed-controlnet-v3.safetensors",
"url": "https://huggingface.co/XLabs-AI/flux-controlnet-collections/resolve/main/flux-hed-controlnet-v3.safetensors",
"size": "1.49GB"
}
]
}

View File

@@ -10,6 +10,16 @@
"install_type": "git-clone",
"description": "A minimal template for creating React/TypeScript frontend extensions for ComfyUI, with complete boilerplate setup including internationalization and unit testing."
},
{
"author": "comfyui-wiki",
"title": "ComfyUI-i18n-demo",
"reference": "https://github.com/comfyui-wiki/ComfyUI-i18n-demo",
"files": [
"https://github.com/comfyui-wiki/ComfyUI-i18n-demo"
],
"install_type": "git-clone",
"description": "ComfyUI custom node develop i18n support demo "
},
{
"author": "Suzie1",
"title": "Guide To Making Custom Nodes in ComfyUI",
@@ -341,6 +351,16 @@
],
"install_type": "git-clone",
"description": "A minimal test suite demonstrating how remote COMBO inputs behave in ComfyUI, with and without force_input"
},
{
"author": "J1mB091",
"title": "ComfyUI-J1mB091 Custom Nodes",
"reference": "https://github.com/J1mB091/ComfyUI-J1mB091",
"files": [
"https://github.com/J1mB091/ComfyUI-J1mB091"
],
"install_type": "git-clone",
"description": "Vibe Coded ComfyUI Custom Nodes"
}
]
}

View File

@@ -42,13 +42,13 @@ components:
oneOf:
- $ref: '#/components/schemas/InstallPackParams'
- $ref: '#/components/schemas/UpdatePackParams'
- $ref: '#/components/schemas/UpdateAllPacksParams'
- $ref: '#/components/schemas/UpdateComfyUIParams'
- $ref: '#/components/schemas/FixPackParams'
- $ref: '#/components/schemas/UninstallPackParams'
- $ref: '#/components/schemas/DisablePackParams'
- $ref: '#/components/schemas/EnablePackParams'
- $ref: '#/components/schemas/ModelMetadata'
- $ref: '#/components/schemas/UpdateComfyUIParams'
- $ref: '#/components/schemas/UpdateAllPacksParams'
required: [ui_id, client_id, kind, params]
TaskHistoryItem:
type: object
@@ -206,10 +206,7 @@ components:
description: The version of the pack that is installed (Git commit hash or semantic version)
cnr_id:
type: [string, 'null']
description: The name of the pack if installed from the registry (normalized lowercase)
original_name:
type: [string, 'null']
description: The original case-preserved name of the pack from the registry
description: The name of the pack if installed from the registry
aux_id:
type: [string, 'null']
description: The name of the pack if installed from github (author/repo-name format)
@@ -241,10 +238,6 @@ components:
type: string
enum: [strong, normal, normal-, weak]
description: Security level configuration (from most to least restrictive)
NetworkMode:
type: string
enum: [public, private, offline]
description: Network mode configuration
RiskLevel:
type: string
enum: [block, high+, high, middle+, middle]
@@ -323,7 +316,7 @@ components:
skip_post_install:
type: boolean
description: Whether to skip post-installation steps
required: [selected_version]
required: [selected_version, mode, channel]
UpdateAllPacksParams:
type: object
properties:
@@ -718,7 +711,8 @@ components:
security_level:
$ref: '#/components/schemas/SecurityLevel'
network_mode:
$ref: '#/components/schemas/NetworkMode'
type: [string, 'null']
description: Network mode (online, offline, private)
cli_args:
type: object
additionalProperties: true

View File

@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "comfyui-manager"
license = { text = "GPL-3.0-only" }
version = "5.0b1"
version = "4.0.2"
requires-python = ">= 3.9"
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
readme = "README.md"
@@ -63,8 +63,3 @@ select = [
"F", # default
"I", # isort-like behavior (import statement sorting)
]
[tool.pytest.ini_options]
markers = [
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
]

View File

@@ -9,4 +9,4 @@ lint.select = [
"F",
]
exclude = ["*.ipynb", "tests"]
exclude = ["*.ipynb"]

35
tests/.gitignore vendored
View File

@@ -1 +1,34 @@
env
# Test environment and artifacts
# Virtual environment
test_venv/
venv/
env/
# pytest cache
.pytest_cache/
__pycache__/
*.pyc
*.pyo
# Coverage reports (module-specific naming)
.coverage
.coverage.*
htmlcov*/
coverage*.xml
*.cover
# Test artifacts
.tox/
.hypothesis/
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db

View File

@@ -1,45 +0,0 @@
{
"tests/glob/test_complex_scenarios.py::test_enable_cnr_when_both_disabled": 38.17840343294665,
"tests/glob/test_complex_scenarios.py::test_enable_nightly_when_both_disabled": 35.116954549972434,
"tests/glob/test_enable_disable_api.py::test_disable_package": 13.036482084076852,
"tests/glob/test_enable_disable_api.py::test_duplicate_disable": 16.040373252006248,
"tests/glob/test_enable_disable_api.py::test_duplicate_enable": 19.040736762981396,
"tests/glob/test_enable_disable_api.py::test_enable_disable_cycle": 19.037481372011825,
"tests/glob/test_enable_disable_api.py::test_enable_package": 16.04287036403548,
"tests/glob/test_installed_api_original_case.py::test_api_response_structure_matches_pypi": 0.001070555008482188,
"tests/glob/test_installed_api_original_case.py::test_cnr_package_original_case": 0.0010666880407370627,
"tests/glob/test_installed_api_original_case.py::test_installed_api_preserves_original_case": 2.0044877040199935,
"tests/glob/test_installed_api_original_case.py::test_nightly_package_original_case": 0.0010498670162633061,
"tests/glob/test_queue_task_api.py::test_case_insensitive_operations": 26.13506762601901,
"tests/glob/test_queue_task_api.py::test_install_package_via_queue": 5.002635493990965,
"tests/glob/test_queue_task_api.py::test_install_uninstall_cycle": 17.058559393975884,
"tests/glob/test_queue_task_api.py::test_queue_multiple_tasks": 8.031247623031959,
"tests/glob/test_queue_task_api.py::test_uninstall_package_via_queue": 13.007408522011247,
"tests/glob/test_queue_task_api.py::test_version_switch_between_cnr_versions": 16.005053027009126,
"tests/glob/test_queue_task_api.py::test_version_switch_cnr_to_nightly": 32.11444602702977,
"tests/glob/test_queue_task_api.py::test_version_switch_disabled_cnr_to_different_cnr": 26.010654640034772,
"tests/glob/test_update_api.py::test_update_already_latest": 18.00697946100263,
"tests/glob/test_update_api.py::test_update_cnr_package": 20.00709484401159,
"tests/glob/test_update_api.py::test_update_cycle": 20.006706968066283,
"tests/glob/test_update_api.py::test_update_nightly_package": 20.01158273994224,
"tests/glob/test_version_switching_comprehensive.py::test_cleanup_verification_no_orphans": 58.0193324740394,
"tests/glob/test_version_switching_comprehensive.py::test_cnr_direct_version_install_switching": 32.007448922027834,
"tests/glob/test_version_switching_comprehensive.py::test_cnr_version_downgrade": 32.01419593003811,
"tests/glob/test_version_switching_comprehensive.py::test_cnr_version_upgrade": 32.008723533013836,
"tests/glob/test_version_switching_comprehensive.py::test_fix_cnr_package": 32.00721229799092,
"tests/glob/test_version_switching_comprehensive.py::test_fix_nightly_package": 37.00825709104538,
"tests/glob/test_version_switching_comprehensive.py::test_fix_nonexistent_package_error": 12.01385385193862,
"tests/glob/test_version_switching_comprehensive.py::test_forward_scenario_cnr_nightly_cnr": 52.010525646968745,
"tests/glob/test_version_switching_comprehensive.py::test_fresh_install_after_uninstall": 17.005509667971637,
"tests/glob/test_version_switching_comprehensive.py::test_invalid_version_error_handling": 27.007191165990662,
"tests/glob/test_version_switching_comprehensive.py::test_nightly_same_version_reinstall_skip": 42.00828933296725,
"tests/glob/test_version_switching_comprehensive.py::test_nightly_update_git_pull": 37.00807314302074,
"tests/glob/test_version_switching_comprehensive.py::test_repeated_switching_4_times": 72.01205480098724,
"tests/glob/test_version_switching_comprehensive.py::test_reverse_scenario_nightly_cnr_nightly": 57.010148006957024,
"tests/glob/test_version_switching_comprehensive.py::test_same_version_reinstall_skip": 27.007290800916962,
"tests/glob/test_version_switching_comprehensive.py::test_uninstall_cnr_only": 27.007201189990155,
"tests/glob/test_version_switching_comprehensive.py::test_uninstall_mixed_enabled_disabled": 51.00947179296054,
"tests/glob/test_version_switching_comprehensive.py::test_uninstall_nightly_only": 32.00746411003638,
"tests/glob/test_version_switching_comprehensive.py::test_uninstall_with_multiple_disabled_versions": 76.01319772895658,
"tests/glob/test_case_sensitivity_integration.py::test_case_insensitive_lookup": 0.0017123910365626216
}

View File

@@ -1,182 +1,181 @@
# ComfyUI Manager Test Suite
Comprehensive test suite for ComfyUI Manager with parallel execution support.
This directory contains all tests for the ComfyUI Manager project, organized by module structure.
## Directory Structure
```
tests/
├── setup_test_env.sh # Setup isolated test environment
├── requirements.txt # Test dependencies
├── pytest.ini # Global pytest configuration
├── .gitignore # Ignore test artifacts
└── common/ # Tests for comfyui_manager/common/
└── pip_util/ # Tests for pip_util.py
├── README.md # pip_util test documentation
├── conftest.py # pip_util test fixtures
├── pytest.ini # pip_util-specific pytest config
└── test_*.py # Actual test files (to be created)
```
## Quick Start
### Fastest Way: Automated Testing
### 1. Setup Test Environment (One Time)
```bash
./tests/run_automated_tests.sh
cd tests
./setup_test_env.sh
```
**What it does**:
- Cleans environment and stops old processes
- Sets up 10 parallel test environments
- Runs all 43 tests in ~2 minutes
- Generates comprehensive report
This creates an isolated virtual environment with all test dependencies.
**Expected**: 100% pass rate, ~140-160s execution time, 9x+ speedup
### For Claude Code Users
Load the testing prompt:
```
@tests/TESTING_PROMPT.md
```
Claude Code will automatically execute tests and provide intelligent analysis.
## Test Suite Overview
### Coverage (54 Tests)
- **Queue Task API** (8 tests) - Install, uninstall, version switching
- **Version Switching** (19 tests) - CNR↔Nightly, upgrades, downgrades
- **Enable/Disable API** (5 tests) - Package activation
- **Update API** (4 tests) - Package updates
- **Installed API** (4 tests) - Package listing, original case preservation
- **Case Sensitivity** (2 tests) - Case-insensitive lookup, full workflow
- **Complex Scenarios** (12 tests) - Multi-version state, automatic switching
### Performance
- **Execution**: ~140-160s (2.3-2.7 minutes)
- **Parallel**: 10 environments
- **Speedup**: 9x+ vs sequential
- **Load Balance**: 1.2x variance (excellent)
## Manual Execution
### Parallel Testing (Recommended)
### 2. Run Tests
```bash
# Setup (one-time)
export NUM_ENVS=10
./tests/setup_parallel_test_envs.sh
# Activate test environment
source test_venv/bin/activate
# Run tests
./tests/run_parallel_tests.sh
# Run all tests from root
cd tests
pytest
# Run specific module tests
cd tests/common/pip_util
pytest
# Deactivate when done
deactivate
```
### Single Environment Testing
## Test Organization
Tests mirror the source code structure:
| Source Code | Test Location |
|-------------|---------------|
| `comfyui_manager/common/pip_util.py` | `tests/common/pip_util/test_*.py` |
| `comfyui_manager/common/other.py` | `tests/common/other/test_*.py` |
| `comfyui_manager/module/file.py` | `tests/module/file/test_*.py` |
## Writing Tests
1. Create test directory matching source structure
2. Add `conftest.py` for module-specific fixtures
3. Add `pytest.ini` for module-specific configuration (optional)
4. Create `test_*.py` files with actual tests
5. Document in module-specific README
## Test Categories
Use pytest markers to categorize tests:
```python
@pytest.mark.unit
def test_simple_function():
pass
@pytest.mark.integration
def test_complex_workflow():
pass
@pytest.mark.e2e
def test_full_system():
pass
```
Run by category:
```bash
pytest -m unit # Only unit tests
pytest -m integration # Only integration tests
pytest -m e2e # Only end-to-end tests
```
## Coverage Reports
Coverage reports are generated per module:
```bash
# Setup
./tests/setup_test_env.sh
# Run tests
cd tests/env
python ComfyUI/main.py --enable-manager &
sleep 20
pytest ../glob/
cd tests/common/pip_util
pytest # Generates htmlcov_pip_util/ and coverage_pip_util.xml
```
## Adding New Tests
## Environment Isolation
When adding 3+ new tests or modifying test execution time significantly:
**Why use venv?**
- ✅ Prevents test dependencies from corrupting main environment
- ✅ Allows safe package installation/uninstallation during tests
- ✅ Consistent test results across machines
- ✅ Easy to recreate clean environment
## Available Test Modules
- **[common/pip_util](common/pip_util/)** - Policy-based pip package management system tests
- Unit tests for policy loading, parsing, condition evaluation
- Integration tests for policy application (60% of tests)
- End-to-end workflow tests
## Adding New Test Modules
1. Create directory structure: `tests/module_path/component_name/`
2. Add `conftest.py` with fixtures
3. Add `pytest.ini` if needed (optional)
4. Add `README.md` documenting the tests
5. Create `test_*.py` files
Example:
```bash
# 1. Write your tests in tests/glob/
# 2. Run tests and check load balance
./tests/run_automated_tests.sh
# Look for "Load Balance: X.XXx variance" in report
# 3. If variance > 2.0x, update durations
./tests/update_test_durations.sh # Takes ~15-20 min
# 4. Commit duration data
git add .test_durations
git commit -m "chore: update test duration data"
mkdir -p tests/data_models/config
cd tests/data_models/config
touch conftest.py README.md test_config_loader.py
```
**See**: `glob/TESTING_GUIDE.md` for detailed workflow
## Files
- `run_automated_tests.sh` - One-command test execution
- `run_parallel_tests.sh` - Parallel test runner
- `setup_parallel_test_envs.sh` - Environment setup
- `update_test_durations.sh` - Update load balancing data
- `TESTING_PROMPT.md` - Claude Code automation
- `glob/` - Test implementations
- `glob/TESTING_GUIDE.md` - Development workflow guide
## Requirements
- Python 3.12+
- Virtual environment: `/home/rho/venv`
- ComfyUI branch: `ltdrdata/dr-support-pip-cm`
- Ports: 8188-8197 available
## Troubleshooting
### Tests Fail to Start
```bash
# Stop existing processes
pkill -f "ComfyUI/main.py"
sleep 2
# Re-run
./tests/run_automated_tests.sh
```
### Slow Execution
If tests take >3 minutes, update duration data:
```bash
./tests/update_test_durations.sh
```
### Environment Issues
Rebuild test environments:
```bash
rm -rf tests/env/ComfyUI_*
NUM_ENVS=10 ./tests/setup_parallel_test_envs.sh
```
## Generated Files
- **Report**: `.claude/livecontext/automated_test_*.md`
- **Logs**: `tests/tmp/test-results-[1-10].log`
- **Server Logs**: `tests/tmp/comfyui-parallel-[1-10].log`
## CI/CD Integration
Tests are designed to run in CI/CD pipelines:
```yaml
- name: Run Tests
# Example GitHub Actions
- name: Setup test environment
run: |
source /home/rho/venv/bin/activate
./tests/run_automated_tests.sh
cd tests
./setup_test_env.sh
- name: Run tests
run: |
source tests/test_venv/bin/activate
pytest tests/
```
Exit code: 0 = pass, 1 = fail
## Troubleshooting
---
### Import errors
```bash
# Make sure venv is activated
source test_venv/bin/activate
**Status**: ✅ Production-ready (100% pass rate, <3min execution)
# Verify Python path
python -c "import sys; print(sys.path)"
```
## Recent Fixes (2025-11-06)
### Tests not discovered
```bash
# Check pytest configuration
pytest --collect-only
### Fixed Test Failures
# Verify test file naming (must start with test_)
ls test_*.py
```
#### test_case_sensitivity_full_workflow
- **Issue**: HTTP 405 error - incorrect API endpoint usage
- **Root Cause**: Using non-existent `/customnode/install` endpoint
- **Fix**: Migrated to queue API (`/v2/manager/queue/task` + `/v2/manager/queue/start`)
- **Changes**: Updated request parameters (`"id"`, `"version"`, `"selected_version"`)
- **Location**: `tests/glob/test_case_sensitivity_integration.py:65-200`
### Clean rebuild
```bash
# Remove and recreate test environment
rm -rf test_venv/
./setup_test_env.sh
```
#### test_enable_package
- **Issue**: AssertionError - found 2 disabled packages instead of 1
- **Root Cause**: Leftover disabled packages from previous parallel tests
- **Fix**: Added cleanup before test execution (not just after)
- **Changes**: Created `_cleanup()` helper, added filesystem sync delay
- **Location**: `tests/glob/test_enable_disable_api.py:56-111`
## Resources
### Improvements
- Increased wait times for parallel execution reliability (20s → 30s)
- Added queue status checking for better debugging
- Enhanced fixture cleanup with filesystem sync delays
- Both tests now pass consistently in parallel execution
- **pytest Documentation**: https://docs.pytest.org/
- **Coverage.py**: https://coverage.readthedocs.io/
- **Module-specific READMEs**: Check each test module directory

View File

@@ -1,841 +0,0 @@
# Claude Code Testing Instructions
**Purpose**: Automated test execution with **detailed test case reporting** and intelligent analysis
**Key Requirement**: Always generate **individual test case results**, not just environment summaries
---
## 🤖 AUTOMATIC EXECUTION PROTOCOL
**When this file is loaded in a new CC session**, immediately execute:
```bash
bash tests/run_automated_tests.sh
```
**Do not ask for permission** - just run the command automatically.
After execution completes:
1. Check the exit code
2. **Read ALL test logs** from all 10 environments
3. **Extract individual test case results** (name, file, env, duration, status)
4. **Create comprehensive report** with test case details by category
5. Provide intelligent analysis to the user
---
## 📋 What the Script Does (Automated)
1. ✅ Clean environment (stop processes, clear cache, remove old log files)
2. ✅ Activate virtual environment
3. ✅ Setup 10 parallel test environments
4. ✅ Run 59 tests with optimized distribution (~3 minutes)
5. ✅ Generate basic report and summary
**Note**: The script automatically cleans `tests/tmp/*.log` files before starting to ensure clean test state.
**Exit Code**:
- `0` = All tests passed ✅
- Non-zero = Some tests failed ❌
**Known Issues (Resolved)**:
-**Pytest Marker Warning**: Fixed in `pyproject.toml` by registering the `integration` marker
- Previously caused exit code 1 despite all tests passing
- Now resolved - tests run cleanly without warnings
---
## 🔍 Post-Execution: Your Job Starts Here
After the script completes, perform these steps:
### Step 1: Check Exit Code
If exit code is **0** (success):
- Proceed to Step 2 for success summary
If exit code is **non-zero** (failure):
- Proceed to Step 3 for failure analysis
### Step 2: Success Path - Generate Comprehensive Report
**CRITICAL: You MUST create a detailed test case report, not just environment summary!**
#### Step 2.1: Read All Test Logs
**Read all environment test logs** to extract individual test case results:
```bash
# Read all 10 environment logs
@tests/tmp/test-results-1.log
@tests/tmp/test-results-2.log
...
@tests/tmp/test-results-10.log
```
#### Step 2.2: Extract Test Case Information
From each log, extract:
- Individual test names (e.g., `test_install_package_via_queue`)
- Test file (e.g., `test_queue_task_api.py`)
- Status (PASSED/FAILED)
- Environment number and port
- Duration (from pytest output)
#### Step 2.3: Create/Update Detailed Report
**Create or update** `.claude/livecontext/automated_test_YYYY-MM-DD_HH-MM-SS.md` with:
1. **Executive Summary** (overview metrics)
2. **Detailed Test Results by Category** - **MOST IMPORTANT**:
- Group tests by category (Queue Task API, Enable/Disable API, etc.)
- Create tables with columns: Test Case | Environment | Duration | Status
- Include coverage description for each category
3. **Test Category Summary** (table with category stats)
4. **Load Balancing Analysis**
5. **Performance Insights**
6. **Configuration Details**
**Example structure**:
```markdown
## Detailed Test Results by Category
### 📦 Queue Task API Tests (8 tests) - All Passed ✅
| Test Case | Environment | Duration | Status |
|-----------|-------------|----------|--------|
| `test_install_package_via_queue` | Env 4 (8191) | ~28s | ✅ PASSED |
| `test_uninstall_package_via_queue` | Env 6 (8193) | ~28s | ✅ PASSED |
| `test_install_uninstall_cycle` | Env 7 (8194) | ~23s | ✅ PASSED |
...
**Coverage**: Package installation, uninstallation, version switching via queue
---
### 🔄 Version Switching Comprehensive Tests (19 tests) - All Passed ✅
| Test Case | Environment | Duration | Status |
|-----------|-------------|----------|--------|
| `test_cnr_to_nightly_switching` | Env 1 (8188) | ~38s | ✅ PASSED |
...
```
#### Step 2.4: Provide User Summary
**After creating the detailed report**, provide user with concise summary:
```markdown
**All 59 tests passed successfully!**
### 📊 Category Breakdown
| Category | Tests | Status |
|----------|-------|--------|
| Version Switching Comprehensive | 19 | ✅ All Passed |
| Complex Scenarios | 12 | ✅ All Passed |
| Queue Task API | 8 | ✅ All Passed |
| Nightly Downgrade/Upgrade | 5 | ✅ All Passed |
| Enable/Disable API | 5 | ✅ All Passed |
| Update API | 4 | ✅ All Passed |
| Installed API (Original Case) | 4 | ✅ All Passed |
| Case Sensitivity Integration | 2 | ✅ All Passed |
### ⚡ Performance
- **Execution time**: 118s (1m 58s)
- **Speedup**: 9.76x vs sequential
- **Load balance**: 1.04x variance (excellent)
### 📁 Generated Files
- **Detailed Report**: `.claude/livecontext/automated_test_YYYY-MM-DD_HH-MM-SS.md`
- Individual test case results
- Category-wise breakdown
- Performance analysis
- **Test Logs**: `tests/tmp/test-results-[1-10].log`
### 🎯 Next Steps
[Based on variance analysis]
```
### Step 3: Failure Path - Intelligent Troubleshooting
**CRITICAL: Create detailed test case report even for failures!**
#### Step 3.1: Read All Test Logs (Including Failed)
**Read all environment test logs** to extract complete test results:
```bash
# Read all 10 environment logs
@tests/tmp/test-results-1.log
@tests/tmp/test-results-2.log
...
@tests/tmp/test-results-10.log
```
#### Step 3.2: Extract All Test Cases
From each log, extract **all tests** (passed and failed):
- Test name, file, environment, duration, status
- For **failed tests**, also extract:
- Error type (AssertionError, ConnectionError, TimeoutError, etc.)
- Error message
- Traceback (last few lines)
#### Step 3.3: Create Comprehensive Report
**Create** `.claude/livecontext/automated_test_YYYY-MM-DD_HH-MM-SS.md` with:
1. **Executive Summary**:
- Total: 43 tests
- Passed: X tests
- Failed: Y tests
- Pass rate: X%
- Execution time and speedup
2. **Detailed Test Results by Category** - **MANDATORY**:
- Group ALL tests by category
- Mark failed tests with ❌ and error summary
- Example:
```markdown
### 📦 Queue Task API Tests (8 tests) - 6 Passed, 2 Failed
| Test Case | Environment | Duration | Status |
|-----------|-------------|----------|--------|
| `test_install_package_via_queue` | Env 4 (8191) | ~28s | ✅ PASSED |
| `test_version_switch_cnr_to_nightly` | Env 9 (8196) | 60s | ❌ FAILED - Timeout |
```
3. **Failed Tests Detailed Analysis**:
- For each failed test, provide:
- Test name and file
- Environment and port
- Error type and message
- Relevant traceback excerpt
- Server log reference
4. **Root Cause Analysis**:
- Pattern detection across failures
- Common failure types
- Likely root causes
5. **Recommended Actions** (specific commands)
#### Step 3.4: Analyze Failure Patterns
**For each failed test**, read server logs if needed:
```
@tests/tmp/comfyui-parallel-N.log
```
**Categorize failures**:
- ❌ **API Error**: Connection refused, timeout, 404/500
- ❌ **Assertion Error**: Expected vs actual mismatch
- ❌ **Setup Error**: Environment configuration issue
- ❌ **Timeout Error**: Test exceeded time limit
- ❌ **Package Error**: Installation/version switching failed
#### Step 3.5: Provide Structured Analysis to User
```markdown
❌ **X tests failed across Y environments**
### 📊 Test Results Summary
| Category | Total | Passed | Failed | Pass Rate |
|----------|-------|--------|--------|-----------|
| Queue Task API | 8 | 6 | 2 | 75% |
| Version Switching | 19 | 17 | 2 | 89% |
| ... | ... | ... | ... | ... |
### ❌ Failed Tests Detail
#### 1. `test_version_switch_cnr_to_nightly` (Env 9, Port 8196)
- **Error Type**: TimeoutError
- **Error Message**: `Server did not respond within 60s`
- **Root Cause**: Likely server startup delay or API timeout
- **Log**: `tests/tmp/test-results-9.log:45`
- **Server Log**: `tests/tmp/comfyui-parallel-9.log`
#### 2. `test_install_package_via_queue` (Env 4, Port 8191)
- **Error Type**: AssertionError
- **Error Message**: `Expected package in installed list`
- **Root Cause**: Package installation failed or API response incomplete
- **Log**: `tests/tmp/test-results-4.log:32`
### 🔍 Root Cause Analysis
**Pattern**: Both failures are in environments with version switching operations
- Likely cause: Server response timeout during complex operations
- Recommendation: Increase timeout or investigate server performance
### 🛠️ Recommended Actions
1. **Check server startup timing**:
```bash
grep "To see the GUI" tests/tmp/comfyui-parallel-{4,9}.log
```
2. **Re-run failed tests in isolation**:
```bash
COMFYUI_PATH=tests/env/ComfyUI_9 \
TEST_SERVER_PORT=8196 \
pytest tests/glob/test_queue_task_api.py::test_version_switch_cnr_to_nightly -v -s
```
3. **If timeout persists, increase timeout in conftest.py**
4. **Full re-test after fixes**:
```bash
./tests/run_automated_tests.sh
```
### 📁 Detailed Logs
- **Full Report**: `.claude/livecontext/automated_test_YYYY-MM-DD_HH-MM-SS.md`
- **Failed Test Logs**:
- `tests/tmp/test-results-4.log` (line 32)
- `tests/tmp/test-results-9.log` (line 45)
- **Server Logs**: `tests/tmp/comfyui-parallel-{4,9}.log`
```
### Step 4: Performance Analysis (Both Paths)
**Analyze load balancing from report**:
```markdown
**Load Balancing Analysis**:
- Variance: X.XXx
- Max duration: XXXs (Env N)
- Min duration: XXXs (Env N)
- Assessment: [Excellent <1.2x | Good <2.0x | Poor >2.0x]
[If Poor]
**Optimization Available**:
The current test distribution is not optimal. You can improve execution time by 41% with:
```bash
./tests/update_test_durations.sh # Takes ~15-20 min
```
This will regenerate timing data for optimal load balancing.
```
---
## 🛠️ Common Troubleshooting Scenarios
### Scenario 1: Server Startup Failures
**Symptoms**: Environment logs show server didn't start
**Check**:
```
@tests/tmp/comfyui-parallel-N.log
```
**Common causes**:
- Port already in use
- Missing dependencies
- ComfyUI branch issues
**Fix**:
```bash
# Clean up ports
pkill -f "ComfyUI/main.py"
sleep 2
# Re-run
./tests/run_automated_tests.sh
```
### Scenario 2: API Connection Failures
**Symptoms**: `Connection refused` or `Timeout` errors
**Analysis checklist**:
1. Was server ready? (Check server log for "To see the GUI" message)
2. Correct port? (8188-8197 for envs 1-10)
3. Request before server ready? (Race condition)
**Fix**: Usually transient - re-run tests
### Scenario 3: Version Switching Failures
**Symptoms**: `test_version_switch_*` failures
**Analysis**:
- Check package installation logs
- Verify `.tracking` file presence (CNR packages)
- Check `.git` directory (nightly packages)
**Fix**:
```bash
# Clean specific package state
rm -rf tests/env/ComfyUI_N/custom_nodes/ComfyUI_SigmoidOffsetScheduler
rm -rf tests/env/ComfyUI_N/custom_nodes/.disabled/*[Ss]igmoid*
# Re-run tests
./tests/run_automated_tests.sh
```
### Scenario 4: Environment-Specific Failures
**Symptoms**: Same test passes in some envs, fails in others
**Analysis**: Setup inconsistency or race condition
**Fix**:
```bash
# Rebuild specific environment
rm -rf tests/env/ComfyUI_N
NUM_ENVS=10 ./tests/setup_parallel_test_envs.sh
# Or rebuild all
rm -rf tests/env/ComfyUI_*
NUM_ENVS=10 ./tests/setup_parallel_test_envs.sh
```
---
## 📊 Report Sections to Analyze
When reading the report, focus on:
1. **Summary Statistics**:
- Total/passed/failed counts
- Overall pass rate
- Execution time
2. **Per-Environment Results**:
- Which environments failed?
- Duration variance patterns
- Test distribution
3. **Performance Metrics**:
- Load balancing effectiveness
- Speedup vs sequential
- Optimization opportunities
4. **Log References**:
- Where to find detailed logs
- Which logs to check for failures
---
## 🎯 Your Goal as Claude Code
**Primary**: Generate **detailed test case report** and provide actionable insights
**CRITICAL Requirements**:
1. **Read ALL test logs** (`tests/tmp/test-results-[1-10].log`)
2. **Extract individual test cases** - NOT just environment summaries
3. **Group by category** - Queue Task API, Version Switching, etc.
4. **Create detailed tables** - Test name, environment, duration, status
5. **Include coverage descriptions** - What each category tests
**Success Path**:
- ✅ Detailed test case breakdown by category (tables with all 43 tests)
- ✅ Category summary with test counts
- ✅ Performance metrics and load balancing analysis
- ✅ Concise user-facing summary with highlights
- ✅ Optimization suggestions (if applicable)
**Failure Path**:
- ✅ Detailed test case breakdown (including failed tests with error details)
- ✅ Failed tests analysis section (error type, message, traceback)
- ✅ Root cause analysis with pattern detection
- ✅ Specific remediation commands for each failure
- ✅ Step-by-step verification instructions
**Always**:
- ✅ Read ALL 10 test result logs (not just summary)
- ✅ Create comprehensive `.claude/livecontext/automated_test_*.md` report
- ✅ Include individual test case results in tables
- ✅ Provide context, explanation, and next steps
- ✅ Use markdown formatting for clarity
---
## 📝 Example Output (Success)
```markdown
✅ **All 43 tests passed successfully!**
### 📊 Category Breakdown
| Category | Tests | Status |
|----------|-------|--------|
| Queue Task API | 8 | ✅ All Passed |
| Version Switching | 19 | ✅ All Passed |
| Enable/Disable API | 5 | ✅ All Passed |
| Update API | 4 | ✅ All Passed |
| Installed API | 4 | ✅ All Passed |
| Case Sensitivity | 1 | ✅ Passed |
| Complex Scenarios | 2 | ✅ All Passed |
### ⚡ Performance
- **Execution time**: 118s (1m 58s)
- **Speedup**: 9.76x vs sequential (19.3min → 2.0min)
- **Load balance**: 1.04x variance (excellent)
### 📋 Test Highlights
**Version Switching Comprehensive (19 tests)** - Most comprehensive coverage:
- CNR ↔ Nightly conversion scenarios
- Version upgrades/downgrades (CNR only)
- Fix operations for corrupted packages
- Uninstall scenarios (CNR only, Nightly only, Mixed)
- Reinstall validation and cleanup verification
**Complex Scenarios (12 tests)**:
- Multiple disabled versions (CNR + Nightly)
- Enable operations with multiple disabled versions
- Disable operations with other disabled versions
- Update operations with disabled versions present
- Install operations when other versions exist
- Uninstall operations removing all versions
- Version upgrade chains and switching preservations
**Queue Task API (8 tests)**:
- Package install/uninstall via queue
- Version switching (CNR→Nightly, CNR→CNR)
- Case-insensitive operations
- Multi-task queuing
**Nightly Downgrade/Upgrade (5 tests)** - Git-based version management:
- Downgrade via git reset and upgrade via git pull
- Multiple commit reset and upgrade cycles
- Git pull behavior validation
- Unstaged file handling during reset
- Soft reset with modified files
### 📁 Generated Files
- **Detailed Report**: `.claude/livecontext/automated_test_2025-11-06_11-41-47.md`
- 59 individual test case results
- Category-wise breakdown with coverage details
- Performance metrics and load balancing analysis
- **Test Logs**: `tests/tmp/test-results-[1-10].log`
- **Server Logs**: `tests/tmp/comfyui-parallel-[1-10].log`
### 🎯 Status
No action needed - test infrastructure working optimally!
```
## 📝 Example Output (Failure)
```markdown
❌ **3 tests failed across 2 environments (95% pass rate)**
### 📊 Test Results Summary
| Category | Total | Passed | Failed | Pass Rate |
|----------|-------|--------|--------|-----------|
| Version Switching Comprehensive | 19 | 18 | 1 | 95% |
| Complex Scenarios | 12 | 12 | 0 | 100% |
| Queue Task API | 8 | 6 | 2 | 75% |
| Nightly Downgrade/Upgrade | 5 | 5 | 0 | 100% |
| Enable/Disable API | 5 | 5 | 0 | 100% |
| Update API | 4 | 4 | 0 | 100% |
| Installed API (Original Case) | 4 | 4 | 0 | 100% |
| Case Sensitivity Integration | 2 | 2 | 0 | 100% |
| **TOTAL** | **59** | **56** | **3** | **95%** |
### ❌ Failed Tests Detail
#### 1. `test_version_switch_cnr_to_nightly` (Env 9, Port 8196)
- **Category**: Queue Task API
- **Duration**: 60s (timeout)
- **Error Type**: `requests.exceptions.Timeout`
- **Error Message**: `HTTPConnectionPool(host='127.0.0.1', port=8196): Read timed out.`
- **Root Cause**: Server did not respond within 60s during version switching
- **Recommendation**: Check server performance or increase timeout
- **Logs**:
- Test: `tests/tmp/test-results-9.log:234-256`
- Server: `tests/tmp/comfyui-parallel-9.log`
#### 2. `test_install_package_via_queue` (Env 4, Port 8191)
- **Category**: Queue Task API
- **Duration**: 32s
- **Error Type**: `AssertionError`
- **Error Message**: `assert 'ComfyUI_SigmoidOffsetScheduler' in installed_packages`
- **Traceback**:
```
tests/glob/test_queue_task_api.py:145: AssertionError
assert 'ComfyUI_SigmoidOffsetScheduler' in installed_packages
E AssertionError: Package not found in /installed response
```
- **Root Cause**: Package installation via queue task succeeded but not reflected in installed list
- **Recommendation**: Verify task completion status and installed API sync
- **Logs**: `tests/tmp/test-results-4.log:98-125`
#### 3. `test_cnr_version_upgrade` (Env 7, Port 8194)
- **Category**: Version Switching
- **Duration**: 28s
- **Error Type**: `AssertionError`
- **Error Message**: `Expected version '1.2.0', got '1.1.0'`
- **Root Cause**: Version upgrade operation completed but version not updated
- **Logs**: `tests/tmp/test-results-7.log:167-189`
### 🔍 Root Cause Analysis
**Common Pattern**: All failures involve package state management
1. **Test 1**: Timeout during version switching → Server performance issue
2. **Test 2**: Installed API not reflecting queue task result → API sync issue
3. **Test 3**: Version upgrade not persisted → Package metadata issue
**Likely Causes**:
- Server performance degradation under load (Test 1)
- Race condition between task completion and API query (Test 2)
- Package metadata cache not invalidated (Test 3)
### 🛠️ Recommended Actions
1. **Verify server health**:
```bash
grep -A 10 "version_switch_cnr_to_nightly" tests/tmp/comfyui-parallel-9.log
tail -100 tests/tmp/comfyui-parallel-9.log
```
2. **Re-run failed tests in isolation**:
```bash
# Test 1
COMFYUI_PATH=tests/env/ComfyUI_9 TEST_SERVER_PORT=8196 \
pytest tests/glob/test_queue_task_api.py::test_version_switch_cnr_to_nightly -v -s
# Test 2
COMFYUI_PATH=tests/env/ComfyUI_4 TEST_SERVER_PORT=8191 \
pytest tests/glob/test_queue_task_api.py::test_install_package_via_queue -v -s
# Test 3
COMFYUI_PATH=tests/env/ComfyUI_7 TEST_SERVER_PORT=8194 \
pytest tests/glob/test_version_switching_comprehensive.py::test_cnr_version_upgrade -v -s
```
3. **If timeout persists**, increase timeout in `tests/glob/conftest.py`:
```python
DEFAULT_TIMEOUT = 90 # Increase from 60 to 90
```
4. **Check for race conditions** - Add delay after queue task completion:
```python
await task_completion()
time.sleep(2) # Allow API to sync
```
5. **Full re-test** after fixes:
```bash
./tests/run_automated_tests.sh
```
### 📁 Detailed Files
- **Full Report**: `.claude/livecontext/automated_test_2025-11-06_11-41-47.md`
- All 43 test case results (40 passed, 3 failed)
- Category breakdown with detailed failure analysis
- **Failed Test Logs**:
- `tests/tmp/test-results-4.log` (line 98-125)
- `tests/tmp/test-results-7.log` (line 167-189)
- `tests/tmp/test-results-9.log` (line 234-256)
- **Server Logs**: `tests/tmp/comfyui-parallel-{4,7,9}.log`
```
---
**Last Updated**: 2025-11-07
**Script Version**: run_automated_tests.sh
**Test Count**: 59 tests across 10 environments
**Documentation**: Updated with all test categories and detailed descriptions
## 📝 Report Requirements Summary
**What MUST be in the report** (`.claude/livecontext/automated_test_*.md`):
1. ✅ **Executive Summary** - Overall metrics (total, passed, failed, pass rate, execution time)
2. ✅ **Detailed Test Results by Category** - **MOST IMPORTANT SECTION**:
- Group all 59 tests by category (Version Switching, Complex Scenarios, etc.)
- Create tables: Test Case | Environment | Duration | Status
- Include coverage description for each category
- For failures: Add error type, message, traceback excerpt
3. ✅ **Test Category Summary Table** - Category | Total | Passed | Failed | Coverage Areas
4. ✅ **Load Balancing Analysis** - Variance, max/min duration, assessment
5. ✅ **Performance Insights** - Speedup calculation, efficiency metrics
6. ✅ **Configuration Details** - Environment setup, Python version, branch, etc.
7. ✅ **Failed Tests Detailed Analysis** (if applicable) - Per-test error analysis
8. ✅ **Root Cause Analysis** (if applicable) - Pattern detection across failures
9. ✅ **Recommended Actions** (if applicable) - Specific commands to run
**What to show the user** (console output):
1. ✅ **Concise summary** - Pass/fail status, category breakdown table
2. ✅ **Performance highlights** - Execution time, speedup, load balance
3. ✅ **Test highlights** - Key coverage areas with brief descriptions
4. ✅ **Generated files** - Path to detailed report and logs
5. ✅ **Next steps** - Action items or "No action needed"
6. ✅ **Failed tests summary** (if applicable) - Brief error summary with log references
---
## 📚 Test Category Details
### 1. Version Switching Comprehensive (19 tests)
**File**: `tests/glob/test_version_switching_comprehensive.py`
**Coverage**:
- CNR ↔ Nightly bidirectional switching
- CNR version upgrades and downgrades
- Nightly git pull updates
- Package fix operations for corrupted packages
- Uninstall operations (CNR only, Nightly only, Mixed versions)
- Reinstall validation and cleanup verification
- Invalid version error handling
- Same version reinstall skip logic
**Key Tests**:
- `test_reverse_scenario_nightly_cnr_nightly` - Nightly→CNR→Nightly
- `test_forward_scenario_cnr_nightly_cnr` - CNR→Nightly→CNR
- `test_cnr_version_upgrade` - CNR version upgrade
- `test_cnr_version_downgrade` - CNR version downgrade
- `test_fix_cnr_package` - Fix corrupted CNR package
- `test_fix_nightly_package` - Fix corrupted Nightly package
---
### 2. Complex Scenarios (12 tests)
**File**: `tests/glob/test_complex_scenarios.py`
**Coverage**:
- Multiple disabled versions (CNR + Nightly)
- Enable operations with both CNR and Nightly disabled
- Disable operations when other version already disabled
- Update operations with disabled versions present
- Install operations when other versions exist (enabled or disabled)
- Uninstall operations removing all versions
- Version upgrade chains with old version cleanup
- CNR-Nightly switching with preservation of disabled Nightly
**Key Tests**:
- `test_enable_cnr_when_both_disabled` - Enable CNR when both disabled
- `test_enable_nightly_when_both_disabled` - Enable Nightly when both disabled
- `test_update_cnr_with_nightly_disabled` - Update CNR with Nightly disabled
- `test_install_cnr_when_nightly_enabled` - Install CNR when Nightly enabled
- `test_uninstall_removes_all_versions` - Uninstall removes all versions
- `test_cnr_version_upgrade_removes_old` - Old CNR removed after upgrade
---
### 3. Queue Task API (8 tests)
**File**: `tests/glob/test_queue_task_api.py`
**Coverage**:
- Package installation via queue task
- Package uninstallation via queue task
- Install/uninstall cycle validation
- Case-insensitive package operations
- Multiple task queuing
- Version switching via queue (CNR↔Nightly, CNR↔CNR)
- Version switching for disabled packages
**Key Tests**:
- `test_install_package_via_queue` - Install package via queue
- `test_uninstall_package_via_queue` - Uninstall package via queue
- `test_install_uninstall_cycle` - Full install/uninstall cycle
- `test_case_insensitive_operations` - Case-insensitive lookups
- `test_version_switch_cnr_to_nightly` - CNR→Nightly via queue
- `test_version_switch_between_cnr_versions` - CNR→CNR via queue
---
### 4. Nightly Downgrade/Upgrade (5 tests)
**File**: `tests/glob/test_nightly_downgrade_upgrade.py`
**Coverage**:
- Nightly package downgrade via git reset
- Upgrade back to latest via git pull (update operation)
- Multiple commit reset and upgrade cycles
- Git pull behavior validation
- Unstaged file handling during git reset
- Soft reset with modified files
**Key Tests**:
- `test_nightly_downgrade_via_reset_then_upgrade` - Reset and upgrade cycle
- `test_nightly_downgrade_multiple_commits_then_upgrade` - Multiple commit reset
- `test_nightly_verify_git_pull_behavior` - Git pull validation
- `test_nightly_reset_to_first_commit_with_unstaged_files` - Unstaged file handling
- `test_nightly_soft_reset_with_modified_files_then_upgrade` - Soft reset behavior
---
### 5. Enable/Disable API (5 tests)
**File**: `tests/glob/test_enable_disable_api.py`
**Coverage**:
- Package enable operations
- Package disable operations
- Duplicate enable handling (idempotency)
- Duplicate disable handling (idempotency)
- Enable/disable cycle validation
**Key Tests**:
- `test_enable_package` - Enable disabled package
- `test_disable_package` - Disable enabled package
- `test_duplicate_enable` - Enable already enabled package
- `test_duplicate_disable` - Disable already disabled package
- `test_enable_disable_cycle` - Full cycle validation
---
### 6. Update API (4 tests)
**File**: `tests/glob/test_update_api.py`
**Coverage**:
- CNR package update operations
- Nightly package update (git pull)
- Already latest version handling
- Update cycle validation
**Key Tests**:
- `test_update_cnr_package` - Update CNR to latest
- `test_update_nightly_package` - Update Nightly via git pull
- `test_update_already_latest` - No-op when already latest
- `test_update_cycle` - Multiple update operations
---
### 7. Installed API (Original Case) (4 tests)
**File**: `tests/glob/test_installed_api_original_case.py`
**Coverage**:
- Original case preservation in /installed API
- CNR package original case validation
- Nightly package original case validation
- API response structure matching PyPI format
**Key Tests**:
- `test_installed_api_preserves_original_case` - Original case in API response
- `test_cnr_package_original_case` - CNR package case preservation
- `test_nightly_package_original_case` - Nightly package case preservation
- `test_api_response_structure_matches_pypi` - API structure validation
---
### 8. Case Sensitivity Integration (2 tests)
**File**: `tests/glob/test_case_sensitivity_integration.py`
**Coverage**:
- Case-insensitive package lookup
- Full workflow with case variations
**Key Tests**:
- `test_case_insensitive_lookup` - Lookup with different case
- `test_case_sensitivity_full_workflow` - End-to-end case handling
---
## 📊 Test File Summary
| Test File | Tests | Lines | Primary Focus |
|-----------|-------|-------|---------------|
| `test_version_switching_comprehensive.py` | 19 | ~600 | Version management |
| `test_complex_scenarios.py` | 12 | ~450 | Multi-version states |
| `test_queue_task_api.py` | 8 | ~350 | Queue operations |
| `test_nightly_downgrade_upgrade.py` | 5 | ~400 | Git operations |
| `test_enable_disable_api.py` | 5 | ~200 | Enable/disable |
| `test_update_api.py` | 4 | ~180 | Update operations |
| `test_installed_api_original_case.py` | 4 | ~150 | API case handling |
| `test_case_sensitivity_integration.py` | 2 | ~100 | Case integration |
| **TOTAL** | **59** | **~2,430** | **All core features** |

View File

@@ -1,35 +0,0 @@
#!/bin/bash
# Simple test result checker
# Usage: ./tests/check_test_results.sh [logfile]
LOGFILE=${1:-/tmp/test-param-fix-final.log}
if [ ! -f "$LOGFILE" ]; then
echo "Log file not found: $LOGFILE"
exit 1
fi
# Check if tests are complete
if grep -q "Test Results Summary" "$LOGFILE"; then
echo "========================================="
echo "Test Results"
echo "========================================="
echo ""
# Show summary
grep -A 30 "Test Results Summary" "$LOGFILE" | head -40
echo ""
echo "========================================="
# Count passed/failed
PASSED=$(grep -c "✅.*PASSED" "$LOGFILE")
FAILED=$(grep -c "❌.*FAILED" "$LOGFILE")
echo "Environments: Passed=$PASSED, Failed=$FAILED"
else
echo "Tests still running..."
echo "Last 10 lines:"
tail -10 "$LOGFILE"
fi

View File

@@ -0,0 +1,423 @@
# Context Files Guide for pip_util Tests
Quick reference for all context files created for extending pip_util tests.
---
## 📋 File Overview
| File | Purpose | When to Use |
|------|---------|-------------|
| **DEPENDENCY_TREE_CONTEXT.md** | Complete dependency trees with version analysis | Adding new test packages or updating scenarios |
| **DEPENDENCY_ANALYSIS.md** | Analysis methodology and findings | Understanding why packages were chosen |
| **TEST_SCENARIOS.md** | Detailed test specifications | Writing new tests or understanding existing ones |
| **analyze_dependencies.py** | Interactive dependency analyzer | Exploring new packages before adding tests |
| **requirements-test-base.txt** | Base test environment packages | Setting up or modifying test environment |
---
## 🎯 Common Tasks
### Task 1: Adding a New Test Package
**Steps**:
1. **Analyze the package**:
```bash
python analyze_dependencies.py NEW_PACKAGE
```
2. **Check size and dependencies**:
```bash
./test_venv/bin/pip download --no-deps NEW_PACKAGE
ls -lh NEW_PACKAGE*.whl # Check size
```
3. **Verify dependency tree**:
- Open **DEPENDENCY_TREE_CONTEXT.md**
- Follow "Adding New Test Scenarios" section
- Document findings in the file
4. **Update requirements** (if pre-installation needed):
- Add to `requirements-test-base.txt`
- Run `./setup_test_env.sh` to recreate venv
5. **Write test**:
- Follow patterns in `test_dependency_protection.py`
- Use `reset_test_venv` fixture
- Add scenario to **TEST_SCENARIOS.md**
6. **Verify**:
```bash
pytest test_YOUR_NEW_TEST.py -v --override-ini="addopts="
```
---
### Task 2: Understanding Existing Tests
**Steps**:
1. **Read test scenario**:
- Open **TEST_SCENARIOS.md**
- Find your scenario (1-6)
- Review initial state, action, expected result
2. **Check dependency details**:
- Open **DEPENDENCY_TREE_CONTEXT.md**
- Look up package in table of contents
- Review dependency tree and version analysis
3. **Run analysis**:
```bash
python analyze_dependencies.py PACKAGE
```
4. **Examine test code**:
- Open relevant test file
- Check policy fixture
- Review assertions
---
### Task 3: Updating for New Package Versions
**When**: PyPI releases major version updates (e.g., urllib3 3.0)
**Steps**:
1. **Check current environment**:
```bash
python analyze_dependencies.py --env
```
2. **Analyze new versions**:
```bash
./test_venv/bin/pip index versions PACKAGE | head -20
python analyze_dependencies.py PACKAGE
```
3. **Update context files**:
- Update version numbers in **DEPENDENCY_TREE_CONTEXT.md**
- Update "Version Analysis" section
- Document breaking changes
4. **Test with new versions**:
- Update `requirements-test-base.txt` (if testing new base version)
- OR update test to verify protection from new version
- Run tests to verify behavior
5. **Update scenarios**:
- Update **TEST_SCENARIOS.md** with new version numbers
- Update expected results if behavior changed
---
### Task 4: Debugging Dependency Issues
**Problem**: Test fails with unexpected dependency versions
**Steps**:
1. **Check what's installed**:
```bash
./test_venv/bin/pip freeze | grep -E "(urllib3|certifi|six|requests)"
```
2. **Analyze what would install**:
```bash
python analyze_dependencies.py PACKAGE
```
3. **Compare with expected**:
- Open **DEPENDENCY_TREE_CONTEXT.md**
- Check "Install Scenarios" for the package
- Compare actual vs. expected
4. **Check for PyPI changes**:
```bash
./test_venv/bin/pip index versions PACKAGE
```
5. **Verify test environment**:
```bash
rm -rf test_venv && ./setup_test_env.sh
pytest test_FILE.py -v --override-ini="addopts="
```
---
## 📚 Context File Details
### DEPENDENCY_TREE_CONTEXT.md
**Contents**:
- Current test environment snapshot
- Complete dependency trees for all test packages
- Version analysis (current vs. latest)
- Upgrade scenarios matrix
- Guidelines for adding new scenarios
- Quick reference tables
**Use when**:
- Adding new test package
- Understanding why a package was chosen
- Checking version compatibility
- Updating for new PyPI releases
**Key sections**:
- Package Dependency Trees → See what each package depends on
- Version Analysis → Understand version gaps and breaking changes
- Adding New Test Scenarios → Step-by-step guide
---
### DEPENDENCY_ANALYSIS.md
**Contents**:
- Detailed analysis of each test scenario
- Real dependency verification using `pip --dry-run`
- Version difference analysis
- Rejected scenarios (and why)
- Package size verification
- Recommendations for implementation
**Use when**:
- Understanding test design decisions
- Evaluating new package candidates
- Reviewing why certain packages were rejected
- Learning the analysis methodology
**Key sections**:
- Test Scenarios with Real Dependencies → Detailed scenarios
- Rejected Scenarios → What NOT to use (e.g., click+colorama)
- Validation Commands → How to verify analysis
---
### TEST_SCENARIOS.md
**Contents**:
- Complete specifications for scenarios 1-6
- Exact package versions and states
- Policy configurations (JSON)
- Expected pip commands
- Expected final states
- Key points for each scenario
**Use when**:
- Writing new tests
- Understanding test expectations
- Debugging test failures
- Documenting new scenarios
**Key sections**:
- Each scenario section → Complete specification
- Summary tables → Quick reference
- Policy types summary → Available policy options
---
### analyze_dependencies.py
**Features**:
- Interactive package analysis
- Dry-run simulation
- Version comparison
- Pin impact analysis
**Use when**:
- Exploring new packages
- Verifying current environment
- Checking upgrade impacts
- Quick dependency checks
**Commands**:
```bash
# Analyze specific package
python analyze_dependencies.py requests
# Analyze all test packages
python analyze_dependencies.py --all
# Show current environment
python analyze_dependencies.py --env
```
---
### requirements-test-base.txt
**Contents**:
- Base packages for test environment
- Version specifications
- Comments explaining each package's purpose
**Use when**:
- Setting up test environment
- Adding pre-installed packages
- Modifying base versions
- Recreating clean environment
**Format**:
```txt
# Scenario X: Purpose
package==version # Comment explaining role
```
---
## 🔄 Workflow Examples
### Example 1: Adding flask Test
```bash
# 1. Analyze flask
python analyze_dependencies.py flask
# Output shows:
# Would install: Flask, Jinja2, MarkupSafe, Werkzeug, blinker, click, itsdangerous
# 2. Check sizes
./test_venv/bin/pip download --no-deps flask jinja2 werkzeug
ls -lh *.whl
# 3. Document in DEPENDENCY_TREE_CONTEXT.md
# Add section:
### 3. flask → Dependencies
**Package**: `flask==3.1.2`
**Size**: ~100KB
...
# 4. Write test
# Create test_flask_dependencies.py
# 5. Test
pytest test_flask_dependencies.py -v --override-ini="addopts="
```
---
### Example 2: Investigating Test Failure
```bash
# Test failed: "urllib3 version mismatch"
# 1. Check installed
./test_venv/bin/pip freeze | grep urllib3
# Output: urllib3==2.5.0 (expected: 1.26.15)
# 2. Analyze what happened
python analyze_dependencies.py requests
# 3. Check context
# Open DEPENDENCY_TREE_CONTEXT.md
# Section: "urllib3: Major Version Jump"
# Confirms: 1.26.15 → 2.5.0 is expected without pin
# 4. Verify test has pin
# Check test_dependency_protection.py for pin_policy fixture
# 5. Reset environment
rm -rf test_venv && ./setup_test_env.sh
# 6. Re-run test
pytest test_dependency_protection.py -v --override-ini="addopts="
```
---
## 🎓 Best Practices
### When Adding New Tests
✅ **DO**:
- Use `analyze_dependencies.py` first
- Document in **DEPENDENCY_TREE_CONTEXT.md**
- Add scenario to **TEST_SCENARIOS.md**
- Verify with real pip operations
- Keep packages lightweight (<500KB total)
❌ **DON'T**:
- Add packages without verifying dependencies
- Use packages with optional dependencies only
- Add heavy packages (>1MB)
- Skip documentation
- Mock subprocess for integration tests
---
### When Updating Context
✅ **DO**:
- Re-run `analyze_dependencies.py --all`
- Update version numbers throughout
- Document breaking changes
- Test after updates
- Note update date
❌ **DON'T**:
- Update only one file
- Skip verification
- Forget to update TEST_SCENARIOS.md
- Leave outdated version numbers
---
## 🆘 Quick Troubleshooting
| Problem | Check | Solution |
|---------|-------|----------|
| Test fails with version mismatch | `pip freeze` | Recreate venv with `./setup_test_env.sh` |
| Package not found | `pip index versions PKG` | Check if package exists on PyPI |
| Unexpected dependencies | `analyze_dependencies.py PKG` | Review dependency tree in context file |
| Wrong test data | **TEST_SCENARIOS.md** | Verify against documented scenario |
| Unclear why package chosen | **DEPENDENCY_ANALYSIS.md** | Read "Rejected Scenarios" section |
---
## 📞 Need Help?
1. **Check context files first**: Most answers are documented
2. **Run analyze_dependencies.py**: Verify current state
3. **Review test scenarios**: Understand expected behavior
4. **Examine dependency trees**: Understand relationships
5. **Check DEPENDENCY_ANALYSIS.md**: Learn the "why" behind decisions
---
## 📝 Maintenance Checklist
**Every 6 months or when major versions release**:
- [ ] Run `python analyze_dependencies.py --all`
- [ ] Check for new major versions: `pip index versions urllib3 certifi six`
- [ ] Update **DEPENDENCY_TREE_CONTEXT.md** version numbers
- [ ] Update **TEST_SCENARIOS.md** expected versions
- [ ] Test all scenarios: `pytest -v --override-ini="addopts="`
- [ ] Document any breaking changes
- [ ] Update this guide if workflow changed
---
## 🔗 File Relationships
```
requirements-test-base.txt
↓ (defines)
Current Test Environment
↓ (analyzed by)
analyze_dependencies.py
↓ (documents)
DEPENDENCY_TREE_CONTEXT.md
↓ (informs)
TEST_SCENARIOS.md
↓ (implemented in)
test_*.py files
```
---
**Last Updated**: 2025-10-01
**Python Version**: 3.12.3
**pip Version**: 25.2

View File

@@ -0,0 +1,261 @@
# pip_util Test Package Dependency Analysis
Real dependency analysis using `pip install --dry-run` to verify meaningful test scenarios.
## Analysis Date
Generated: 2025-10-01
Tool: `pip install --dry-run --ignore-installed`
## Test Scenarios with Real Dependencies
### Scenario 1: Dependency Version Protection (requests + urllib3)
**Purpose**: Verify pin_dependencies prevents unwanted upgrades
**Initial Environment**:
```
urllib3==1.26.15
certifi==2023.7.22
charset-normalizer==3.2.0
```
**Without pin** (`pip install requests`):
```bash
Would install:
certifi-2025.8.3 # UPGRADED from 2023.7.22 (+2 years)
charset-normalizer-3.4.3 # UPGRADED from 3.2.0 (minor)
idna-3.10 # NEW dependency
requests-2.32.5 # NEW package
urllib3-2.5.0 # UPGRADED from 1.26.15 (MAJOR 1.x→2.x!)
```
**With pin** (`pip install requests urllib3==1.26.15 certifi==2023.7.22 charset-normalizer==3.2.0`):
```bash
Would install:
idna-3.10 # NEW dependency (required by requests)
requests-2.32.5 # NEW package
# Pinned packages stay at old versions:
urllib3==1.26.15 ✅ PROTECTED (prevented 1.x→2.x jump)
certifi==2023.7.22 ✅ PROTECTED
charset-normalizer==3.2.0 ✅ PROTECTED
```
**Key Finding**:
- `urllib3` 1.26.15 → 2.5.0 is a **MAJOR version jump** (breaking changes!)
- requests accepts both: `urllib3<3,>=1.21.1` (compatible with 1.x and 2.x)
- Pin successfully prevents unwanted major upgrade
---
### Scenario 2: Package with Dependency (python-dateutil + six)
**Purpose**: Verify pin_dependencies with dependency chain
**Analysis**:
```bash
$ pip install --dry-run python-dateutil
Would install:
python-dateutil-2.9.0.post0
six-1.17.0 # DEPENDENCY
```
**Initial Environment**:
```
six==1.16.0 # Older version
```
**Without pin** (`pip install python-dateutil`):
```bash
Would install:
python-dateutil-2.9.0.post0
six-1.17.0 # UPGRADED from 1.16.0
```
**With pin** (`pip install python-dateutil six==1.16.0`):
```bash
Would install:
python-dateutil-2.9.0.post0
# Pinned package:
six==1.16.0 ✅ PROTECTED
```
---
### Scenario 3: Package Deletion and Restore (six)
**Purpose**: Verify restore policy reinstalls deleted packages
**Initial Environment**:
```
six==1.16.0
attrs==23.1.0
packaging==23.1
```
**Action Sequence**:
1. Delete six: `pip uninstall -y six`
2. Verify deletion: `pip freeze | grep six` (empty)
3. Restore: `batch.ensure_installed()``pip install six==1.16.0`
**Expected Result**:
```
six==1.16.0 # ✅ RESTORED
```
---
### Scenario 4: Version Change and Restore (urllib3)
**Purpose**: Verify restore policy reverts version changes
**Initial Environment**:
```
urllib3==1.26.15
```
**Action Sequence**:
1. Upgrade: `pip install urllib3==2.5.0`
2. Verify change: `pip freeze | grep urllib3``urllib3==2.5.0`
3. Restore: `batch.ensure_installed()``pip install urllib3==1.26.15`
**Expected Result**:
```
urllib3==1.26.15 # ✅ RESTORED (downgraded from 2.5.0)
```
**Key Finding**:
- Downgrade from 2.x to 1.x requires explicit version specification
- pip allows downgrades with `pip install urllib3==1.26.15`
---
## Rejected Scenarios
### click + colorama (NO REAL DEPENDENCY)
**Analysis**:
```bash
$ pip install --dry-run click
Would install: click-8.3.0
$ pip install --dry-run click colorama==0.4.6
Would install: click-8.3.0 # colorama not installed!
```
**Finding**: click has **NO direct dependency** on colorama
- colorama is **optional** and platform-specific (Windows only)
- Not a good test case for dependency protection
**Recommendation**: Use python-dateutil + six instead
---
## Package Size Verification
```bash
Package Size Version Purpose
-------------------------------------------------------
urllib3 ~140KB 1.26.15 Protected dependency
certifi ~158KB 2023.7.22 SSL certificates
charset-normalizer ~46KB 3.2.0 Charset detection
idna ~69KB 3.10 NEW dep from requests
requests ~100KB 2.32.5 Main package to install
six ~11KB 1.16.0 Restore test
python-dateutil ~280KB 2.9.0 Depends on six
attrs ~61KB 23.1.0 Bystander
packaging ~48KB 23.1 Bystander
-------------------------------------------------------
Total ~913KB (< 1MB) ✅ All lightweight
```
---
## Dependency Graph
```
requests 2.32.5
├── charset_normalizer<4,>=2 (have: 3.2.0)
├── idna<4,>=2.5 (need: 3.10) ← NEW
├── urllib3<3,>=1.21.1 (have: 1.26.15, latest: 2.5.0)
└── certifi>=2017.4.17 (have: 2023.7.22, latest: 2025.8.3)
python-dateutil 2.9.0
└── six>=1.5 (have: 1.16.0, latest: 1.17.0)
```
---
## Version Compatibility Matrix
| Package | Old Version | Latest | Spec | Compatible? |
|---------|------------|--------|------|-------------|
| urllib3 | 1.26.15 | 2.5.0 | <3,>=1.21.1 | ✅ Both work |
| certifi | 2023.7.22 | 2025.8.3 | >=2017.4.17 | ✅ Both work |
| charset-normalizer | 3.2.0 | 3.4.3 | <4,>=2 | ✅ Both work |
| six | 1.16.0 | 1.17.0 | >=1.5 | ✅ Both work |
| idna | (none) | 3.10 | <4,>=2.5 | ⚠️ Must install |
---
## Test Data Justification
### Why urllib3 1.26.15?
1. **Real world scenario**: Many projects pin urllib3<2 to avoid breaking changes
2. **Meaningful test**: 1.26.15 → 2.5.0 is a major version jump (API changes)
3. **Compatibility**: requests accepts both 1.x and 2.x (good for testing)
### Why certifi 2023.7.22?
1. **Real world scenario**: Older environment with outdated SSL certificates
2. **Meaningful test**: 2-year version gap (2023 → 2025)
3. **Safety**: Still compatible with requests
### Why six 1.16.0?
1. **Lightweight**: Only 11KB
2. **Real dependency**: python-dateutil actually depends on it
3. **Stable**: six is mature and rarely changes
---
## Recommendations for Test Implementation
### ✅ Keep These Scenarios:
1. **requests + urllib3 pin** - Real major version protection
2. **python-dateutil + six** - Real dependency chain
3. **six deletion/restore** - Real package management
4. **urllib3 version change** - Real downgrade scenario
### ❌ Remove These Scenarios:
1. **click + colorama** - No real dependency (colorama is optional/Windows-only)
### 📝 Update Required Files:
1. `requirements-test-base.txt` - Add idna (new dependency from requests)
2. `TEST_SCENARIOS.md` - Update with real dependency analysis
3. `test_dependency_protection.py` - Remove click-colorama test
4. `pip_util.design.en.md` - Update examples with verified dependencies
---
## Validation Commands
Run these to verify analysis:
```bash
# Check current environment
./test_venv/bin/pip freeze
# Simulate requests installation without pin
./test_venv/bin/pip install --dry-run requests
# Simulate requests installation with pin
./test_venv/bin/pip install --dry-run requests urllib3==1.26.15 certifi==2023.7.22 charset-normalizer==3.2.0
# Check python-dateutil dependencies
./test_venv/bin/pip install --dry-run python-dateutil
# Verify urllib3 version availability
./test_venv/bin/pip index versions urllib3 | head -20
```

View File

@@ -0,0 +1,413 @@
# Dependency Tree Context for pip_util Tests
**Generated**: 2025-10-01
**Tool**: `pip install --dry-run --ignore-installed`
**Python**: 3.12.3
**pip**: 25.2
This document provides detailed dependency tree information for all test packages, verified against real PyPI data. Use this as a reference when extending tests.
---
## Table of Contents
1. [Current Test Environment](#current-test-environment)
2. [Package Dependency Trees](#package-dependency-trees)
3. [Version Analysis](#version-analysis)
4. [Upgrade Scenarios](#upgrade-scenarios)
5. [Adding New Test Scenarios](#adding-new-test-scenarios)
---
## Current Test Environment
**Base packages installed in test_venv** (from `requirements-test-base.txt`):
```
urllib3==1.26.15 # Protected from 2.x upgrade
certifi==2023.7.22 # Protected from 2025.x upgrade
charset-normalizer==3.2.0 # Protected from 3.4.x upgrade
six==1.16.0 # For deletion/restore tests
attrs==23.1.0 # Bystander package
packaging==23.1 # Bystander package
pytest==8.4.2 # Test framework
```
**Total environment size**: ~913KB (all packages < 1MB)
---
## Package Dependency Trees
### 1. requests → Dependencies
**Package**: `requests==2.32.5`
**Size**: ~100KB
**Purpose**: Main test package for dependency protection
#### Dependency Tree
```
requests==2.32.5
├── charset-normalizer<4,>=2
│ └── 3.2.0 (OLD) → 3.4.3 (LATEST)
├── idna<4,>=2.5
│ └── (NOT INSTALLED) → 3.10 (LATEST)
├── urllib3<3,>=1.21.1
│ └── 1.26.15 (OLD) → 2.5.0 (LATEST) ⚠️ MAJOR VERSION JUMP
└── certifi>=2017.4.17
└── 2023.7.22 (OLD) → 2025.8.3 (LATEST)
```
#### Install Scenarios
**Scenario A: Without constraints (fresh install)**
```bash
$ pip install --dry-run --ignore-installed requests
Would install:
certifi-2025.8.3 # Latest version
charset-normalizer-3.4.3 # Latest version
idna-3.10 # New dependency
requests-2.32.5 # Target package
urllib3-2.5.0 # Latest version (2.x!)
```
**Scenario B: With pin constraints**
```bash
$ pip install --dry-run requests \
urllib3==1.26.15 \
certifi==2023.7.22 \
charset-normalizer==3.2.0
Would install:
certifi-2023.7.22 # Pinned to OLD version
charset-normalizer-3.2.0 # Pinned to OLD version
idna-3.10 # New dependency (not pinned)
requests-2.32.5 # Target package
urllib3-1.26.15 # Pinned to OLD version
```
**Impact Analysis**:
- ✅ Pin successfully prevents urllib3 1.x → 2.x major upgrade
- ✅ Pin prevents certifi 2023 → 2025 upgrade (2 years)
- ✅ Pin prevents charset-normalizer minor upgrade
- ⚠️ idna is NEW and NOT pinned (acceptable - new dependency)
---
### 2. python-dateutil → Dependencies
**Package**: `python-dateutil==2.9.0.post0`
**Size**: ~280KB
**Purpose**: Real dependency chain test (depends on six)
#### Dependency Tree
```
python-dateutil==2.9.0.post0
└── six>=1.5
└── 1.16.0 (OLD) → 1.17.0 (LATEST)
```
#### Install Scenarios
**Scenario A: Without constraints**
```bash
$ pip install --dry-run --ignore-installed python-dateutil
Would install:
python-dateutil-2.9.0.post0 # Target package
six-1.17.0 # Latest version
```
**Scenario B: With pin constraints**
```bash
$ pip install --dry-run python-dateutil six==1.16.0
Would install:
python-dateutil-2.9.0.post0 # Target package
six-1.16.0 # Pinned to OLD version
```
**Impact Analysis**:
- ✅ Pin successfully prevents six 1.16.0 → 1.17.0 upgrade
- ✅ Real dependency relationship (verified via PyPI)
---
### 3. Other Test Packages (No Dependencies)
These packages have no dependencies or only have dependencies already in the test environment:
```
attrs==23.1.0 # No dependencies
packaging==23.1 # No dependencies (standalone)
six==1.16.0 # No dependencies (pure Python)
```
---
## Version Analysis
### urllib3: Major Version Jump (1.x → 2.x)
**Current**: 1.26.15 (2023)
**Latest**: 2.5.0 (2025)
**Breaking Changes**: YES - urllib3 2.0 removed deprecated APIs
**Available versions**:
```
2.x series: 2.5.0, 2.4.0, 2.3.0, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0, 2.0.7, ...
1.26.x: 1.26.20, 1.26.19, 1.26.18, 1.26.17, 1.26.16, 1.26.15, ...
1.25.x: 1.25.11, 1.25.10, 1.25.9, ...
```
**Why test with 1.26.15?**
- ✅ Real-world scenario: Many projects pin `urllib3<2` to avoid breaking changes
- ✅ Meaningful test: 1.x → 2.x is a major API change
- ✅ Compatibility: requests accepts both 1.x and 2.x (`urllib3<3,>=1.21.1`)
**Breaking changes in urllib3 2.0**:
- Removed `urllib3.contrib.pyopenssl`
- Removed `urllib3.contrib.securetransport`
- Changed import paths for some modules
- Updated connection pooling behavior
---
### certifi: Long-Term Version Gap (2023 → 2025)
**Current**: 2023.7.22 (July 2023)
**Latest**: 2025.8.3 (August 2025)
**Gap**: ~2 years of SSL certificate updates
**Available versions**:
```
2025: 2025.8.3, 2025.7.14, 2025.7.9, 2025.6.15, 2025.4.26, ...
2024: 2024.12.25, 2024.11.28, 2024.10.29, 2024.9.19, ...
2023: 2023.11.17, 2023.7.22, 2023.5.7, ...
```
**Why test with 2023.7.22?**
- ✅ Real-world scenario: Older environments with outdated SSL certificates
- ✅ Meaningful test: 2-year gap shows protection of older versions
- ✅ Safety: Still compatible with requests (`certifi>=2017.4.17`)
---
### charset-normalizer: Minor Version Updates
**Current**: 3.2.0 (2023)
**Latest**: 3.4.3 (2025)
**Breaking Changes**: NO - only minor/patch updates
**Available versions**:
```
3.4.x: 3.4.3, 3.4.2, 3.4.1, 3.4.0
3.3.x: 3.3.2, 3.3.1, 3.3.0
3.2.x: 3.2.0
```
**Why test with 3.2.0?**
- ✅ Demonstrates protection of minor version updates
- ✅ Compatible with requests (`charset-normalizer<4,>=2`)
---
### six: Stable Version Update
**Current**: 1.16.0 (2021)
**Latest**: 1.17.0 (2024)
**Breaking Changes**: NO - six is very stable
**Available versions**:
```
1.17.0, 1.16.0, 1.15.0, 1.14.0, 1.13.0, 1.12.0, ...
```
**Why test with 1.16.0?**
- ✅ Real dependency of python-dateutil
- ✅ Small size (11KB) - lightweight for tests
- ✅ Demonstrates protection of stable packages
---
### idna: New Dependency
**Not pre-installed** - Added by requests
**Version**: 3.10
**Size**: ~69KB
**Dependency spec**: `idna<4,>=2.5` (from requests)
**Why NOT pre-installed?**
- ✅ Tests that new dependencies are correctly added
- ✅ Tests that pins only affect specified packages
- ✅ Real-world scenario: new dependency introduced by package update
---
## Upgrade Scenarios
### Scenario Matrix
| Package | Initial | Without Pin | With Pin | Change Type |
|---------|---------|-------------|----------|-------------|
| **urllib3** | 1.26.15 | 2.5.0 ❌ | 1.26.15 ✅ | Major (breaking) |
| **certifi** | 2023.7.22 | 2025.8.3 ❌ | 2023.7.22 ✅ | 2-year gap |
| **charset-normalizer** | 3.2.0 | 3.4.3 ❌ | 3.2.0 ✅ | Minor update |
| **six** | 1.16.0 | 1.17.0 ❌ | 1.16.0 ✅ | Stable update |
| **idna** | (none) | 3.10 ✅ | 3.10 ✅ | New dependency |
| **requests** | (none) | 2.32.5 ✅ | 2.32.5 ✅ | Target package |
| **python-dateutil** | (none) | 2.9.0 ✅ | 2.9.0 ✅ | Target package |
---
## Adding New Test Scenarios
### Step 1: Identify Candidate Package
Use `pip install --dry-run` to analyze dependencies:
```bash
# Analyze package dependencies
./test_venv/bin/pip install --dry-run --ignore-installed PACKAGE
# Check what changes with current environment
./test_venv/bin/pip install --dry-run PACKAGE
# List available versions
./test_venv/bin/pip index versions PACKAGE
```
### Step 2: Verify Real Dependencies
**Good candidates**:
- ✅ Has 2+ dependencies
- ✅ Dependencies have version upgrades available
- ✅ Total size < 500KB (all packages combined)
- ✅ Real-world use case (popular package)
**Examples**:
```bash
# flask → click, werkzeug, jinja2 (good: multiple dependencies)
$ pip install --dry-run --ignore-installed flask
Would install: Flask-3.1.2 Jinja2-3.1.6 MarkupSafe-3.0.3 Werkzeug-3.1.3 blinker-1.9.0 click-8.3.0 itsdangerous-2.2.0
# pytest-cov → pytest, coverage (good: popular testing tool)
$ pip install --dry-run --ignore-installed pytest-cov
Would install: coverage-7.10.7 pytest-8.4.2 pytest-cov-7.0.0
```
**Bad candidates**:
- ❌ click → colorama (no real dependency - colorama is optional/Windows-only)
- ❌ pandas → numpy (too large - numpy is 50MB+)
- ❌ torch → ... (too large - 800MB+)
### Step 3: Document Dependencies
Add to this file:
```markdown
### Package: PACKAGE_NAME → Dependencies
**Package**: `PACKAGE==VERSION`
**Size**: ~XXXKB
**Purpose**: Brief description
#### Dependency Tree
(Use tree format)
#### Install Scenarios
(Show with/without pin)
#### Impact Analysis
(What does pin protect?)
```
### Step 4: Update Test Files
1. Add package to `requirements-test-base.txt` (if pre-installation needed)
2. Create policy fixture in test file
3. Write test function using `reset_test_venv` fixture
4. Update `TEST_SCENARIOS.md` with detailed scenario
---
## Maintenance Notes
### Updating This Document
Re-run analysis when:
- ✅ PyPI releases major version updates (e.g., urllib3 3.0)
- ✅ Adding new test packages
- ✅ Test environment base packages change
- ✅ Every 6 months (to catch version drift)
### Verification Commands
```bash
# Regenerate dependency tree
./test_venv/bin/pip install --dry-run --ignore-installed requests
./test_venv/bin/pip install --dry-run --ignore-installed python-dateutil
# Check current environment
./test_venv/bin/pip freeze
# Verify test packages still available on PyPI
./test_venv/bin/pip index versions urllib3
./test_venv/bin/pip index versions certifi
./test_venv/bin/pip index versions six
```
---
## Quick Reference: Package Specs
From actual package metadata:
```python
# requests dependencies (from requests==2.32.5)
install_requires = [
"charset_normalizer<4,>=2",
"idna<4,>=2.5",
"urllib3<3,>=1.21.1",
"certifi>=2017.4.17"
]
# python-dateutil dependencies (from python-dateutil==2.9.0)
install_requires = [
"six>=1.5"
]
# six dependencies
install_requires = [] # No dependencies
# attrs dependencies
install_requires = [] # No dependencies
# packaging dependencies
install_requires = [] # No dependencies
```
---
## Version Compatibility Table
| Package | Minimum | Maximum | Current Test | Latest | Notes |
|---------|---------|---------|--------------|--------|-------|
| urllib3 | 1.21.1 | <3.0 | 1.26.15 | 2.5.0 | Major version jump possible |
| certifi | 2017.4.17 | (none) | 2023.7.22 | 2025.8.3 | Always backward compatible |
| charset-normalizer | 2.0 | <4.0 | 3.2.0 | 3.4.3 | Within major version |
| six | 1.5 | (none) | 1.16.0 | 1.17.0 | Very stable |
| idna | 2.5 | <4.0 | (new) | 3.10 | Added by requests |
---
## See Also
- **DEPENDENCY_ANALYSIS.md** - Detailed analysis methodology
- **TEST_SCENARIOS.md** - Complete test scenario specifications
- **requirements-test-base.txt** - Base environment packages
- **README.md** - Test suite overview and usage

View File

@@ -0,0 +1,305 @@
# pip_util Integration Tests
Real integration tests for `pip_util.py` using actual PyPI packages and pip operations.
## Overview
These tests use a **real isolated venv** to verify pip_util behavior with actual package installations, deletions, and version changes. No mocks - real pip operations only.
## Quick Start
### 1. Setup Test Environment
```bash
cd tests/common/pip_util
./setup_test_env.sh
```
This creates `test_venv/` with base packages:
- urllib3==1.26.15
- certifi==2023.7.22
- charset-normalizer==3.2.0
- colorama==0.4.6
- six==1.16.0
- attrs==23.1.0
- packaging==23.1
- pytest (latest)
### 2. Run Tests
```bash
# Run all integration tests
pytest -v --override-ini="addopts="
# Run specific test
pytest test_dependency_protection.py -v --override-ini="addopts="
# Run with markers
pytest -m integration -v --override-ini="addopts="
```
## Test Architecture
### Real venv Integration
- **No subprocess mocking** - uses real pip install/uninstall
- **Isolated test venv** - prevents system contamination
- **Automatic cleanup** - `reset_test_venv` fixture restores state after each test
### Test Fixtures
**venv Management**:
- `test_venv_path` - Path to test venv (session scope)
- `test_pip_cmd` - pip command for test venv
- `reset_test_venv` - Restore venv to initial state after each test
**Helpers**:
- `get_installed_packages()` - Get current venv packages
- `install_packages(*packages)` - Install packages in test venv
- `uninstall_packages(*packages)` - Uninstall packages in test venv
**Policy Configuration**:
- `temp_policy_dir` - Temporary directory for base policies
- `temp_user_policy_dir` - Temporary directory for user policies
- `mock_manager_util` - Mock manager_util paths to use temp dirs
- `mock_context` - Mock context paths to use temp dirs
## Test Scenarios
### Scenario 1: Dependency Version Protection
**File**: `test_dependency_protection.py::test_dependency_version_protection_with_pin`
**Initial State**:
```python
urllib3==1.26.15
certifi==2023.7.22
charset-normalizer==3.2.0
```
**Action**: Install `requests` with pin_dependencies policy
**Expected Result**:
```python
# Dependencies stay at old versions (protected by pin)
urllib3==1.26.15 # NOT upgraded to 2.x
certifi==2023.7.22 # NOT upgraded
charset-normalizer==3.2.0 # NOT upgraded
requests==2.31.0 # newly installed
```
### Scenario 2: Click-Colorama Dependency Chain
**File**: `test_dependency_protection.py::test_dependency_chain_with_click_colorama`
**Initial State**:
```python
colorama==0.4.6
```
**Action**: Install `click` with force_version + pin_dependencies
**Expected Result**:
```python
colorama==0.4.6 # PINNED
click==8.1.3 # FORCED to specific version
```
### Scenario 3: Package Deletion and Restore
**File**: `test_environment_recovery.py::test_package_deletion_and_restore`
**Initial State**:
```python
six==1.16.0
attrs==23.1.0
packaging==23.1
```
**Action**: Delete `six` → call `batch.ensure_installed()`
**Expected Result**:
```python
six==1.16.0 # RESTORED to required version
```
### Scenario 4: Version Change and Restore
**File**: `test_environment_recovery.py::test_version_change_and_restore`
**Initial State**:
```python
urllib3==1.26.15
```
**Action**: Upgrade `urllib3` to 2.1.0 → call `batch.ensure_installed()`
**Expected Result**:
```python
urllib3==1.26.15 # RESTORED to required version (downgraded)
```
## Test Categories
### Priority 1 (Essential) ✅ ALL PASSING
- ✅ Dependency version protection (enhanced with exact versions)
- ✅ Package deletion and restore (enhanced with exact versions)
- ✅ Version change and restore (enhanced with downgrade verification)
- ✅ Pin only affects specified packages ✨ NEW
- ✅ Major version jump prevention ✨ NEW
### Priority 2 (Important)
- ✅ Complex dependency chains (python-dateutil + six)
- ⏳ Full workflow integration (TODO: update to real venv)
- ⏳ Pin failure retry (TODO: update to real venv)
### Priority 3 (Edge Cases)
- ⏳ Platform conditions (TODO: update to real venv)
- ⏳ Policy priority (TODO: update to real venv)
- ⏳ Unit tests (no venv needed)
- ⏳ Edge cases (no venv needed)
## Package Selection
All test packages are **real PyPI packages < 200KB**:
| Package | Size | Version | Purpose |
|---------|------|---------|---------|
| **urllib3** | ~100KB | 1.26.15 | Protected dependency (prevent 2.x upgrade) |
| **certifi** | ~10KB | 2023.7.22 | SSL certificates (pinned) |
| **charset-normalizer** | ~46KB | 3.2.0 | Charset detection (pinned) |
| **requests** | ~100KB | 2.31.0 | Main package to install |
| **colorama** | ~25KB | 0.4.6 | Terminal colors (pinned) |
| **click** | ~90KB | 8.1.3 | CLI framework (forced version) |
| **six** | ~11KB | 1.16.0 | Python 2/3 compatibility (restore) |
| **attrs** | ~61KB | 23.1.0 | Bystander package |
| **packaging** | ~48KB | 23.1 | Bystander package |
## Cleanup
### Manual Cleanup
```bash
# Remove test venv
rm -rf test_venv/
# Recreate fresh venv
./setup_test_env.sh
```
### Automatic Cleanup
The `reset_test_venv` fixture automatically:
1. Records initial package state
2. Runs test
3. Removes all packages (except pip/setuptools/wheel)
4. Reinstalls initial packages
## Troubleshooting
### Error: "Test venv not found"
**Solution**: Run `./setup_test_env.sh`
### Error: "Package not installed in initial state"
**Solution**: Check `requirements-test-base.txt` and recreate venv
### Tests are slow
**Reason**: Real pip operations take 2-3 seconds per test
**This is expected** - we're doing actual pip install/uninstall
## Implementation Details
### How reset_test_venv Works
```python
@pytest.fixture
def reset_test_venv(test_pip_cmd):
# 1. Record initial state
initial = subprocess.run(test_pip_cmd + ["freeze"], ...)
yield # Run test here
# 2. Remove all packages
current = subprocess.run(test_pip_cmd + ["freeze"], ...)
subprocess.run(test_pip_cmd + ["uninstall", "-y", ...], ...)
# 3. Restore initial state
subprocess.run(test_pip_cmd + ["install", "-r", initial], ...)
```
### How make_pip_cmd is Patched
```python
@pytest.fixture(autouse=True)
def setup_pip_util(monkeypatch, test_pip_cmd):
from comfyui_manager.common import pip_util
def make_test_pip_cmd(args: List[str]) -> List[str]:
return test_pip_cmd + args # Use test venv pip
monkeypatch.setattr(
pip_util.manager_util,
"make_pip_cmd",
make_test_pip_cmd
)
```
## Dependency Analysis Tool
Use `analyze_dependencies.py` to examine package dependencies before adding new tests:
```bash
# Analyze specific package
python analyze_dependencies.py requests
# Analyze all test packages
python analyze_dependencies.py --all
# Show current environment
python analyze_dependencies.py --env
```
**Output includes**:
- Latest available versions
- Dependencies that would be installed
- Version upgrades that would occur
- Impact of pin constraints
**Example output**:
```
📦 Latest version: 2.32.5
🔍 Scenario A: Install without constraints
Would install 5 packages:
• urllib3 1.26.15 → 2.5.0 ⚠️ UPGRADE
🔍 Scenario B: Install with pin constraints
Would install 5 packages:
• urllib3 1.26.15 (no change) 📌 PINNED
✅ Pin prevented 2 upgrade(s)
```
## Test Statistics
**Current Status**: 6 tests, 100% passing
```
test_dependency_version_protection_with_pin PASSED (2.28s)
test_dependency_chain_with_six_pin PASSED (2.00s)
test_pin_only_affects_specified_packages PASSED (2.25s) ✨ NEW
test_major_version_jump_prevention PASSED (3.53s) ✨ NEW
test_package_deletion_and_restore PASSED (2.25s)
test_version_change_and_restore PASSED (2.24s)
Total: 14.10s
```
**Test Improvements**:
- ✅ All tests verify exact version numbers
- ✅ All tests reference DEPENDENCY_TREE_CONTEXT.md
- ✅ Added 2 new critical tests (pin selectivity, major version prevention)
- ✅ Enhanced error messages with expected vs actual values
## Design Documents
- **TEST_IMPROVEMENTS.md** - Summary of test enhancements based on dependency context
- **DEPENDENCY_TREE_CONTEXT.md** - Verified dependency trees for all test packages
- **DEPENDENCY_ANALYSIS.md** - Dependency analysis methodology
- **CONTEXT_FILES_GUIDE.md** - Guide for using context files
- **TEST_SCENARIOS.md** - Detailed test scenario specifications
- **pip_util.test-design.md** - Test design and architecture
- **pip_util.design.en.md** - pip_util design documentation

View File

@@ -0,0 +1,433 @@
# Test Code Improvements Based on Dependency Context
**Date**: 2025-10-01
**Basis**: DEPENDENCY_TREE_CONTEXT.md analysis
This document summarizes all test improvements made using verified dependency tree information.
---
## Summary of Changes
### Tests Enhanced
| Test File | Tests Modified | Tests Added | Total Tests |
|-----------|----------------|-------------|-------------|
| `test_dependency_protection.py` | 2 | 2 | 4 |
| `test_environment_recovery.py` | 2 | 0 | 2 |
| **Total** | **4** | **2** | **6** |
### Test Results
```bash
$ pytest test_dependency_protection.py test_environment_recovery.py -v
test_dependency_protection.py::test_dependency_version_protection_with_pin PASSED
test_dependency_protection.py::test_dependency_chain_with_six_pin PASSED
test_dependency_protection.py::test_pin_only_affects_specified_packages PASSED ✨ NEW
test_dependency_protection.py::test_major_version_jump_prevention PASSED ✨ NEW
test_environment_recovery.py::test_package_deletion_and_restore PASSED
test_environment_recovery.py::test_version_change_and_restore PASSED
6 passed in 14.10s
```
---
## Detailed Improvements
### 1. test_dependency_version_protection_with_pin
**File**: `test_dependency_protection.py:34-94`
**Enhancements**:
- ✅ Added exact version assertions based on DEPENDENCY_TREE_CONTEXT.md
- ✅ Verified initial versions: urllib3==1.26.15, certifi==2023.7.22, charset-normalizer==3.2.0
- ✅ Added verification that idna is NOT pre-installed
- ✅ Added assertion that idna==3.10 is installed as NEW dependency
- ✅ Verified requests==2.32.5 is installed
- ✅ Added detailed error messages explaining what versions are expected and why
**Key Assertions Added**:
```python
# Verify expected OLD versions
assert initial_urllib3 == "1.26.15", f"Expected urllib3==1.26.15, got {initial_urllib3}"
assert initial_certifi == "2023.7.22", f"Expected certifi==2023.7.22, got {initial_certifi}"
assert initial_charset == "3.2.0", f"Expected charset-normalizer==3.2.0, got {initial_charset}"
# Verify idna is NOT installed initially
assert "idna" not in initial, "idna should not be pre-installed"
# Verify new dependency was added (idna is NOT pinned, so it gets installed)
assert "idna" in final_packages, "idna should be installed as new dependency"
assert final_packages["idna"] == "3.10", f"Expected idna==3.10, got {final_packages['idna']}"
```
**Based on Context**:
- DEPENDENCY_TREE_CONTEXT.md Section 1: requests → Dependencies
- Verified: Without pin, urllib3 would upgrade to 2.5.0 (MAJOR version jump)
- Verified: idna is NEW dependency (not in requirements-test-base.txt)
---
### 2. test_dependency_chain_with_six_pin
**File**: `test_dependency_protection.py:117-162`
**Enhancements**:
- ✅ Added exact version assertion for six==1.16.0
- ✅ Added exact version assertion for python-dateutil==2.9.0.post0
- ✅ Added detailed error messages
- ✅ Added docstring reference to DEPENDENCY_TREE_CONTEXT.md
**Key Assertions Added**:
```python
# Verify expected OLD version
assert initial_six == "1.16.0", f"Expected six==1.16.0, got {initial_six}"
# Verify final versions
assert final_packages["python-dateutil"] == "2.9.0.post0", f"Expected python-dateutil==2.9.0.post0"
assert final_packages["six"] == "1.16.0", "six should remain at 1.16.0 (prevented 1.17.0 upgrade)"
```
**Based on Context**:
- DEPENDENCY_TREE_CONTEXT.md Section 2: python-dateutil → Dependencies
- Verified: six is a REAL dependency (not optional like colorama)
- Verified: Without pin, six would upgrade from 1.16.0 to 1.17.0
---
### 3. test_pin_only_affects_specified_packages ✨ NEW
**File**: `test_dependency_protection.py:165-208`
**Purpose**: Verify that pin is selective, not global
**Test Logic**:
1. Verify idna is NOT pre-installed
2. Verify requests is NOT pre-installed
3. Install requests with pin policy (only pins urllib3, certifi, charset-normalizer)
4. Verify idna was installed at latest version (3.10) - NOT pinned
5. Verify requests was installed at expected version (2.32.5)
**Key Assertions**:
```python
# Verify idna was installed (NOT pinned, so gets latest)
assert "idna" in final_packages, "idna should be installed as new dependency"
assert final_packages["idna"] == "3.10", "idna should be at latest version 3.10 (not pinned)"
```
**Based on Context**:
- DEPENDENCY_TREE_CONTEXT.md: "⚠️ idna is NEW and NOT pinned (acceptable - new dependency)"
- Verified: Pin only affects specified packages in pinned_packages list
---
### 4. test_major_version_jump_prevention ✨ NEW
**File**: `test_dependency_protection.py:211-271`
**Purpose**: Verify that pin prevents MAJOR version jumps with breaking changes
**Test Logic**:
1. Verify initial urllib3==1.26.15
2. **Test WITHOUT pin**: Uninstall deps, install requests → urllib3 upgrades to 2.x
3. Verify urllib3 was upgraded to 2.x (starts with "2.")
4. Reset environment
5. **Test WITH pin**: Install requests with pin → urllib3 stays at 1.x
6. Verify urllib3 stayed at 1.26.15 (starts with "1.")
**Key Assertions**:
```python
# Without pin - verify urllib3 upgrades to 2.x
assert without_pin["urllib3"].startswith("2."), \
f"Without pin, urllib3 should upgrade to 2.x, got {without_pin['urllib3']}"
# With pin - verify urllib3 stays at 1.x
assert final_packages["urllib3"] == "1.26.15", \
"Pin should prevent urllib3 from upgrading to 2.x (breaking changes)"
assert final_packages["urllib3"].startswith("1."), \
f"urllib3 should remain at 1.x series, got {final_packages['urllib3']}"
```
**Based on Context**:
- DEPENDENCY_TREE_CONTEXT.md: "urllib3 1.26.15 → 2.5.0 is a MAJOR version jump"
- DEPENDENCY_TREE_CONTEXT.md: "urllib3 2.0 removed deprecated APIs"
- This is the MOST IMPORTANT test - prevents breaking changes
---
### 5. test_package_deletion_and_restore
**File**: `test_environment_recovery.py:33-78`
**Enhancements**:
- ✅ Added exact version assertion for six==1.16.0
- ✅ Added verification that six is restored to EXACT version (not latest)
- ✅ Added detailed error messages
- ✅ Added docstring reference to DEPENDENCY_TREE_CONTEXT.md
**Key Assertions Added**:
```python
# Verify six is initially installed at expected version
assert initial["six"] == "1.16.0", f"Expected six==1.16.0, got {initial['six']}"
# Verify six was restored to EXACT required version (not latest)
assert final_packages["six"] == "1.16.0", \
"six should be restored to exact version 1.16.0 (not 1.17.0 latest)"
```
**Based on Context**:
- DEPENDENCY_TREE_CONTEXT.md: "six: 1.16.0 (OLD) → 1.17.0 (LATEST)"
- Verified: Restore policy restores to EXACT version, not latest
---
### 6. test_version_change_and_restore
**File**: `test_environment_recovery.py:105-158`
**Enhancements**:
- ✅ Added exact version assertions (1.26.15 initially, 2.1.0 after upgrade)
- ✅ Added verification of major version change (1.x → 2.x)
- ✅ Added verification of major version downgrade (2.x → 1.x)
- ✅ Added detailed error messages explaining downgrade capability
- ✅ Added docstring reference to DEPENDENCY_TREE_CONTEXT.md
**Key Assertions Added**:
```python
# Verify version was changed to 2.x
assert installed_after["urllib3"] == "2.1.0", \
f"urllib3 should be upgraded to 2.1.0, got {installed_after['urllib3']}"
assert installed_after["urllib3"].startswith("2."), \
"urllib3 should be at 2.x series"
# Verify version was DOWNGRADED from 2.x back to 1.x
assert final["urllib3"] == "1.26.15", \
"urllib3 should be downgraded to 1.26.15 (from 2.1.0)"
assert final["urllib3"].startswith("1."), \
f"urllib3 should be back at 1.x series, got {final['urllib3']}"
```
**Based on Context**:
- DEPENDENCY_TREE_CONTEXT.md: "urllib3 can upgrade from 1.26.15 (1.x) to 2.5.0 (2.x)"
- Verified: Restore policy can DOWNGRADE (not just prevent upgrades)
- Tests actual version downgrade capability (2.x → 1.x)
---
## Test Coverage Analysis
### Before Improvements
| Scenario | Coverage |
|----------|----------|
| Pin prevents upgrades | ✅ Basic |
| New dependencies installed | ❌ Not tested |
| Pin is selective | ❌ Not tested |
| Major version jump prevention | ❌ Not tested |
| Exact version restoration | ❌ Not tested |
| Version downgrade capability | ❌ Not tested |
### After Improvements
| Scenario | Coverage | Test |
|----------|----------|------|
| Pin prevents upgrades | ✅ Enhanced | test_dependency_version_protection_with_pin |
| New dependencies installed | ✅ Added | test_dependency_version_protection_with_pin |
| Pin is selective | ✅ Added | test_pin_only_affects_specified_packages |
| Major version jump prevention | ✅ Added | test_major_version_jump_prevention |
| Exact version restoration | ✅ Enhanced | test_package_deletion_and_restore |
| Version downgrade capability | ✅ Enhanced | test_version_change_and_restore |
---
## Key Testing Principles Applied
### 1. Exact Version Verification
**Before**:
```python
assert final_packages["urllib3"] == initial_urllib3 # Generic
```
**After**:
```python
assert initial_urllib3 == "1.26.15", f"Expected urllib3==1.26.15, got {initial_urllib3}"
assert final_packages["urllib3"] == "1.26.15", "urllib3 should remain at 1.26.15 (prevented 2.x upgrade)"
```
**Benefit**: Fails with clear message if environment setup is wrong
---
### 2. Version Series Verification
**Added**:
```python
assert final_packages["urllib3"].startswith("1."), \
f"urllib3 should remain at 1.x series, got {final_packages['urllib3']}"
```
**Benefit**: Catches major version jumps even if exact version changes
---
### 3. Negative Testing (Verify NOT Installed)
**Added**:
```python
assert "idna" not in initial, "idna should not be pre-installed"
```
**Benefit**: Ensures test environment is in expected state
---
### 4. Context-Based Documentation
**Every test now includes**:
```python
"""
Based on DEPENDENCY_TREE_CONTEXT.md:
<specific section reference>
<expected behavior from context>
"""
```
**Benefit**: Links test expectations to verified dependency data
---
## Real-World Scenarios Tested
### Scenario 1: Preventing Breaking Changes
**Test**: `test_major_version_jump_prevention`
**Real-World Impact**:
- urllib3 2.0 removed deprecated APIs
- Many applications break when upgrading from 1.x to 2.x
- Pin prevents this automatic breaking change
**Verified**: ✅ Pin successfully prevents 1.x → 2.x upgrade
---
### Scenario 2: Allowing New Dependencies
**Test**: `test_pin_only_affects_specified_packages`
**Real-World Impact**:
- New dependencies are safe to add (idna)
- Pin should not block ALL changes
- Only specified packages are protected
**Verified**: ✅ idna installs at 3.10 even with pin policy active
---
### Scenario 3: Version Downgrade Recovery
**Test**: `test_version_change_and_restore`
**Real-World Impact**:
- Sometimes packages get upgraded accidentally
- Need to downgrade to known-good version
- Downgrade is harder than upgrade prevention
**Verified**: ✅ Can downgrade urllib3 from 2.x to 1.x
---
## Test Execution Performance
```
Test Performance Summary:
test_dependency_version_protection_with_pin 2.28s (enhanced)
test_dependency_chain_with_six_pin 2.00s (enhanced)
test_pin_only_affects_specified_packages 2.25s (NEW)
test_major_version_jump_prevention 3.53s (NEW - does 2 install cycles)
test_package_deletion_and_restore 2.25s (enhanced)
test_version_change_and_restore 2.24s (enhanced)
Total: 14.10s for 6 tests
Average: 2.35s per test
```
**Note**: `test_major_version_jump_prevention` is slower because it tests both WITH and WITHOUT pin (2 install cycles).
---
## Files Modified
1. **test_dependency_protection.py**: +138 lines
- Enhanced 2 existing tests
- Added 2 new tests
- Total: 272 lines (was 132 lines)
2. **test_environment_recovery.py**: +35 lines
- Enhanced 2 existing tests
- Total: 159 lines (was 141 lines)
---
## Verification Against Context
All test improvements verified against:
| Context Source | Usage |
|----------------|-------|
| **DEPENDENCY_TREE_CONTEXT.md** | All version numbers, dependency trees |
| **DEPENDENCY_ANALYSIS.md** | Package selection rationale, rejected scenarios |
| **TEST_SCENARIOS.md** | Scenario specifications, expected outcomes |
| **requirements-test-base.txt** | Initial environment state |
| **analyze_dependencies.py** | Real-time verification of expectations |
---
## Future Maintenance
### When to Update Tests
Update tests when:
- ✅ PyPI releases new major versions (e.g., urllib3 3.0)
- ✅ Base package versions change in requirements-test-base.txt
- ✅ New test scenarios added to DEPENDENCY_TREE_CONTEXT.md
- ✅ Policy behavior changes in pip_util.py
### How to Update Tests
1. Run `python analyze_dependencies.py --all`
2. Update expected version numbers in tests
3. Update DEPENDENCY_TREE_CONTEXT.md
4. Update TEST_SCENARIOS.md
5. Run tests to verify
### Verification Commands
```bash
# Verify environment
python analyze_dependencies.py --env
# Verify package dependencies
python analyze_dependencies.py requests
python analyze_dependencies.py python-dateutil
# Run all tests
pytest test_dependency_protection.py test_environment_recovery.py -v --override-ini="addopts="
```
---
## Summary
**6 tests** now verify real PyPI package dependencies
**100% pass rate** with real pip operations
**All version numbers** verified against DEPENDENCY_TREE_CONTEXT.md
**Major version jump prevention** explicitly tested
**Selective pinning** verified (only specified packages)
**Version downgrade** capability tested
**Key Achievement**: Tests now verify actual PyPI behavior, not mocked expectations.

View File

@@ -0,0 +1,573 @@
# pip_util Test Scenarios - Test Data Specification
This document precisely defines all test scenarios, packages, versions, and expected behaviors used in the pip_util test suite.
## Table of Contents
1. [Test Scenario 1: Dependency Version Protection](#scenario-1-dependency-version-protection)
2. [Test Scenario 2: Complex Dependency Chain](#scenario-2-complex-dependency-chain)
3. [Test Scenario 3: Package Deletion and Restore](#scenario-3-package-deletion-and-restore)
4. [Test Scenario 4: Version Change and Restore](#scenario-4-version-change-and-restore)
5. [Test Scenario 5: Full Workflow Integration](#scenario-5-full-workflow-integration)
6. [Test Scenario 6: Pin Failure Retry](#scenario-6-pin-failure-retry)
---
## Scenario 1: Dependency Version Protection
**File**: `test_dependency_protection.py::test_dependency_version_protection_with_pin`
**Purpose**: Verify that `pin_dependencies` policy prevents dependency upgrades during package installation.
### Initial Environment State
```python
installed_packages = {
"urllib3": "1.26.15", # OLD stable version
"certifi": "2023.7.22", # OLD version
"charset-normalizer": "3.2.0" # OLD version
}
```
### Policy Configuration
```json
{
"requests": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["urllib3", "certifi", "charset-normalizer"],
"on_failure": "retry_without_pin"
}
]
}
}
```
### Action
```python
batch.install("requests")
```
### Expected pip Command
```bash
pip install requests urllib3==1.26.15 certifi==2023.7.22 charset-normalizer==3.2.0
```
### Expected Final State
```python
installed_packages = {
"urllib3": "1.26.15", # PROTECTED - stayed at old version
"certifi": "2023.7.22", # PROTECTED - stayed at old version
"charset-normalizer": "3.2.0", # PROTECTED - stayed at old version
"requests": "2.31.0" # NEWLY installed
}
```
### Without Pin (What Would Happen)
```python
# If pin_dependencies was NOT used:
installed_packages = {
"urllib3": "2.1.0", # UPGRADED to 2.x (breaking change)
"certifi": "2024.2.2", # UPGRADED to latest
"charset-normalizer": "3.3.2", # UPGRADED to latest
"requests": "2.31.0"
}
```
**Key Point**: Pin prevents `urllib3` from upgrading to 2.x, which has breaking API changes.
---
## Scenario 2: Complex Dependency Chain
**File**: `test_dependency_protection.py::test_dependency_chain_with_click_colorama`
**Purpose**: Verify that `force_version` + `pin_dependencies` work together correctly.
### Initial Environment State
```python
installed_packages = {
"colorama": "0.4.6" # Existing dependency
}
```
### Policy Configuration
```json
{
"click": {
"apply_first_match": [
{
"condition": {
"type": "installed",
"package": "colorama",
"spec": "<0.5.0"
},
"type": "force_version",
"version": "8.1.3",
"reason": "click 8.1.3 compatible with colorama <0.5"
}
],
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["colorama"]
}
]
}
}
```
### Condition Evaluation
```python
# Check: colorama installed AND version < 0.5.0?
colorama_installed = True
colorama_version = "0.4.6" # 0.4.6 < 0.5.0 → True
# Result: Condition satisfied → apply force_version
```
### Action
```python
batch.install("click")
```
### Expected pip Command
```bash
pip install click==8.1.3 colorama==0.4.6
```
### Expected Final State
```python
installed_packages = {
"colorama": "0.4.6", # PINNED - version protected
"click": "8.1.3" # FORCED to specific version
}
```
**Key Point**:
- `force_version` forces click to install version 8.1.3
- `pin_dependencies` ensures colorama stays at 0.4.6
---
## Scenario 3: Package Deletion and Restore
**File**: `test_environment_recovery.py::test_package_deletion_and_restore`
**Purpose**: Verify that deleted packages can be restored to required versions.
### Initial Environment State
```python
installed_packages = {
"six": "1.16.0", # Critical package
"attrs": "23.1.0",
"packaging": "23.1"
}
```
### Policy Configuration
```json
{
"six": {
"restore": [
{
"target": "six",
"version": "1.16.0",
"reason": "six must be maintained at 1.16.0 for compatibility"
}
]
}
}
```
### Action Sequence
**Step 1**: Install package that removes six
```python
batch.install("python-dateutil")
```
**Step 1 Result**: six is DELETED
```python
installed_packages = {
# "six": "1.16.0", # ❌ DELETED by python-dateutil
"attrs": "23.1.0",
"packaging": "23.1",
"python-dateutil": "2.8.2" # ✅ NEW
}
```
**Step 2**: Restore deleted packages
```python
batch.ensure_installed()
```
**Step 2 Result**: six is RESTORED
```python
installed_packages = {
"six": "1.16.0", # ✅ RESTORED to required version
"attrs": "23.1.0",
"packaging": "23.1",
"python-dateutil": "2.8.2"
}
```
### Expected pip Commands
```bash
# Step 1: Install
pip install python-dateutil
# Step 2: Restore
pip install six==1.16.0
```
**Key Point**: `restore` policy automatically reinstalls deleted packages.
---
## Scenario 4: Version Change and Restore
**File**: `test_environment_recovery.py::test_version_change_and_restore`
**Purpose**: Verify that packages with changed versions can be restored to required versions.
### Initial Environment State
```python
installed_packages = {
"urllib3": "1.26.15", # OLD version (required)
"certifi": "2023.7.22"
}
```
### Policy Configuration
```json
{
"urllib3": {
"restore": [
{
"condition": {
"type": "installed",
"spec": "!=1.26.15"
},
"target": "urllib3",
"version": "1.26.15",
"reason": "urllib3 must be 1.26.15 for compatibility"
}
]
}
}
```
### Action Sequence
**Step 1**: Install package that upgrades urllib3
```python
batch.install("requests")
```
**Step 1 Result**: urllib3 is UPGRADED
```python
installed_packages = {
"urllib3": "2.1.0", # ❌ UPGRADED from 1.26.15 to 2.1.0
"certifi": "2023.7.22",
"requests": "2.31.0" # ✅ NEW
}
```
**Step 2**: Check restore condition
```python
# Condition: urllib3 installed AND version != 1.26.15?
urllib3_version = "2.1.0"
condition_met = (urllib3_version != "1.26.15") # True
# Result: Restore urllib3 to 1.26.15
```
**Step 2**: Restore to required version
```python
batch.ensure_installed()
```
**Step 2 Result**: urllib3 is DOWNGRADED
```python
installed_packages = {
"urllib3": "1.26.15", # ✅ RESTORED to required version
"certifi": "2023.7.22",
"requests": "2.31.0"
}
```
### Expected pip Commands
```bash
# Step 1: Install (causes upgrade)
pip install requests
# Step 2: Restore (downgrade)
pip install urllib3==1.26.15
```
**Key Point**: `restore` with condition can revert unwanted version changes.
---
## Scenario 5: Full Workflow Integration
**File**: `test_full_workflow_integration.py::test_uninstall_install_restore_workflow`
**Purpose**: Verify complete workflow: uninstall → install → restore.
### Initial Environment State
```python
installed_packages = {
"old-package": "1.0.0", # To be removed
"critical-package": "1.2.3", # To be restored
"urllib3": "1.26.15",
"certifi": "2023.7.22"
}
```
### Policy Configuration
```json
{
"old-package": {
"uninstall": [
{
"target": "old-package"
}
]
},
"requests": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["urllib3", "certifi"]
}
]
},
"critical-package": {
"restore": [
{
"target": "critical-package",
"version": "1.2.3"
}
]
}
}
```
### Action Sequence
**Step 1**: Remove old packages
```python
removed = batch.ensure_not_installed()
```
**Step 1 Result**:
```python
installed_packages = {
# "old-package": "1.0.0", # ❌ REMOVED
"critical-package": "1.2.3",
"urllib3": "1.26.15",
"certifi": "2023.7.22"
}
removed = ["old-package"]
```
**Step 2**: Install new package with pins
```python
batch.install("requests")
```
**Step 2 Result**:
```python
installed_packages = {
"critical-package": "1.2.3",
"urllib3": "1.26.15", # PINNED - no upgrade
"certifi": "2023.7.22", # PINNED - no upgrade
"requests": "2.31.0" # NEW
}
```
**Step 3**: Restore required packages
```python
restored = batch.ensure_installed()
```
**Step 3 Result**:
```python
installed_packages = {
"critical-package": "1.2.3", # Still present
"urllib3": "1.26.15",
"certifi": "2023.7.22",
"requests": "2.31.0"
}
restored = [] # Nothing to restore (all present)
```
### Expected pip Commands
```bash
# Step 1: Uninstall
pip uninstall -y old-package
# Step 2: Install with pins
pip install requests urllib3==1.26.15 certifi==2023.7.22
# Step 3: (No command - all packages present)
```
**Key Point**: Complete workflow demonstrates policy coordination.
---
## Scenario 6: Pin Failure Retry
**File**: `test_pin_failure_retry.py::test_pin_failure_retry_without_pin_succeeds`
**Purpose**: Verify automatic retry without pins when installation with pins fails.
### Initial Environment State
```python
installed_packages = {
"urllib3": "1.26.15",
"certifi": "2023.7.22"
}
```
### Policy Configuration
```json
{
"requests": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["urllib3", "certifi"],
"on_failure": "retry_without_pin"
}
]
}
}
```
### Action
```python
batch.install("requests")
```
### Attempt 1: Install WITH pins (FAILS)
```bash
# Command:
pip install requests urllib3==1.26.15 certifi==2023.7.22
# Result: FAILURE (dependency conflict)
# Error: "Package conflict: requests requires urllib3>=2.0"
```
### Attempt 2: Retry WITHOUT pins (SUCCEEDS)
```bash
# Command:
pip install requests
# Result: SUCCESS
```
**Final State**:
```python
installed_packages = {
"urllib3": "2.1.0", # UPGRADED (pins removed)
"certifi": "2024.2.2", # UPGRADED (pins removed)
"requests": "2.31.0" # INSTALLED
}
```
### Expected Behavior
1. **First attempt**: Install with pinned versions
2. **On failure**: Log warning about conflict
3. **Retry**: Install without pins
4. **Success**: Package installed, dependencies upgraded
**Key Point**: `retry_without_pin` provides automatic fallback for compatibility issues.
---
## Scenario 6b: Pin Failure with Hard Fail
**File**: `test_pin_failure_retry.py::test_pin_failure_with_fail_raises_exception`
**Purpose**: Verify that `on_failure: fail` raises exception instead of retrying.
### Initial Environment State
```python
installed_packages = {
"urllib3": "1.26.15",
"certifi": "2023.7.22"
}
```
### Policy Configuration
```json
{
"requests": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["urllib3", "certifi"],
"on_failure": "fail"
}
]
}
}
```
### Action
```python
batch.install("requests")
```
### Attempt 1: Install WITH pins (FAILS)
```bash
# Command:
pip install requests urllib3==1.26.15 certifi==2023.7.22
# Result: FAILURE (dependency conflict)
# Error: "Package conflict: requests requires urllib3>=2.0"
```
### Expected Behavior
1. **First attempt**: Install with pinned versions
2. **On failure**: Raise `subprocess.CalledProcessError`
3. **No retry**: Exception propagates to caller
4. **No changes**: Environment unchanged
**Key Point**: `on_failure: fail` ensures strict version requirements.
---
## Summary Table: All Test Packages
| Package | Initial Version | Action | Final Version | Role |
|---------|----------------|--------|---------------|------|
| **urllib3** | 1.26.15 | Pin | 1.26.15 | Protected dependency |
| **certifi** | 2023.7.22 | Pin | 2023.7.22 | Protected dependency |
| **charset-normalizer** | 3.2.0 | Pin | 3.2.0 | Protected dependency |
| **requests** | (not installed) | Install | 2.31.0 | New package |
| **colorama** | 0.4.6 | Pin | 0.4.6 | Protected dependency |
| **click** | (not installed) | Force version | 8.1.3 | New package with forced version |
| **six** | 1.16.0 | Delete→Restore | 1.16.0 | Deleted then restored |
| **python-dateutil** | (not installed) | Install | 2.8.2 | Package that deletes six |
| **attrs** | 23.1.0 | No change | 23.1.0 | Bystander package |
| **packaging** | 23.1 | No change | 23.1 | Bystander package |
## Policy Types Summary
| Policy Type | Purpose | Example |
|-------------|---------|---------|
| **pin_dependencies** | Prevent dependency upgrades | Keep urllib3 at 1.26.15 |
| **force_version** | Force specific package version | Install click==8.1.3 |
| **restore** | Reinstall deleted/changed packages | Restore six to 1.16.0 |
| **uninstall** | Remove obsolete packages | Remove old-package |
| **on_failure** | Handle installation failures | retry_without_pin or fail |
## Test Data Design Principles
1. **Lightweight Packages**: All packages are <200KB for fast testing
2. **Real Dependencies**: Use actual PyPI package relationships
3. **Version Realism**: Use real version numbers from PyPI
4. **Clear Scenarios**: Each test demonstrates one clear behavior
5. **Reproducible**: Mock ensures consistent behavior across environments

View File

@@ -0,0 +1,261 @@
#!/usr/bin/env python3
"""
Dependency Tree Analyzer for pip_util Tests
Usage:
python analyze_dependencies.py [package]
python analyze_dependencies.py --all
python analyze_dependencies.py --update-context
Examples:
python analyze_dependencies.py requests
python analyze_dependencies.py python-dateutil
python analyze_dependencies.py --all
"""
import subprocess
import sys
from typing import Dict, List, Tuple, Optional
from pathlib import Path
PIP = "./test_venv/bin/pip"
def check_venv():
"""Check if test venv exists"""
if not Path(PIP).exists():
print("❌ Test venv not found!")
print(" Run: ./setup_test_env.sh")
sys.exit(1)
def get_installed_packages() -> Dict[str, str]:
"""Get currently installed packages"""
result = subprocess.run(
[PIP, "freeze"],
capture_output=True,
text=True,
check=True
)
packages = {}
for line in result.stdout.strip().split('\n'):
if '==' in line:
pkg, ver = line.split('==', 1)
packages[pkg] = ver
return packages
def analyze_package_dry_run(
package: str,
constraints: Optional[List[str]] = None
) -> Tuple[List[Tuple[str, str]], Dict[str, str]]:
"""
Analyze what would be installed with --dry-run
Returns:
- List of (package_name, version) tuples in install order
- Dict of current_version → new_version for upgrades
"""
cmd = [PIP, "install", "--dry-run", "--ignore-installed", package]
if constraints:
cmd.extend(constraints)
result = subprocess.run(cmd, capture_output=True, text=True)
# Parse "Would install" line
would_install = []
for line in result.stdout.split('\n'):
if 'Would install' in line:
packages_str = line.split('Would install')[1].strip()
for pkg_str in packages_str.split():
parts = pkg_str.split('-', 1)
if len(parts) == 2:
would_install.append((parts[0], parts[1]))
# Check against current installed
installed = get_installed_packages()
changes = {}
for pkg, new_ver in would_install:
if pkg in installed:
old_ver = installed[pkg]
if old_ver != new_ver:
changes[pkg] = (old_ver, new_ver)
return would_install, changes
def get_available_versions(package: str, limit: int = 10) -> Tuple[str, List[str]]:
"""
Get available versions from PyPI
Returns:
- Latest version
- List of available versions (limited)
"""
result = subprocess.run(
[PIP, "index", "versions", package],
capture_output=True,
text=True
)
latest = None
versions = []
for line in result.stdout.split('\n'):
if 'LATEST:' in line:
latest = line.split('LATEST:')[1].strip()
elif 'Available versions:' in line:
versions_str = line.split('Available versions:')[1].strip()
versions = [v.strip() for v in versions_str.split(',')[:limit]]
return latest, versions
def print_package_analysis(package: str, with_pin: bool = False):
"""Print detailed analysis for a package"""
print(f"\n{'='*80}")
print(f"Package: {package}")
print(f"{'='*80}")
installed = get_installed_packages()
# Get latest version
latest, available = get_available_versions(package)
if latest:
print(f"\n📦 Latest version: {latest}")
print(f"📋 Available versions: {', '.join(available[:5])}")
# Scenario 1: Without constraints
print(f"\n🔍 Scenario A: Install without constraints")
print(f" Command: pip install {package}")
would_install, changes = analyze_package_dry_run(package)
if would_install:
print(f"\n Would install {len(would_install)} packages:")
for pkg, ver in would_install:
if pkg in changes:
old_ver, new_ver = changes[pkg]
print(f"{pkg:25} {old_ver:15}{new_ver:15} ⚠️ UPGRADE")
elif pkg in installed:
print(f"{pkg:25} {ver:15} (already installed)")
else:
print(f"{pkg:25} {ver:15} ✨ NEW")
# Scenario 2: With pin constraints (if dependencies exist)
dependencies = [pkg for pkg, _ in would_install if pkg != package]
if dependencies and with_pin:
print(f"\n🔍 Scenario B: Install with pin constraints")
# Create pin constraints for all current dependencies
constraints = []
for dep in dependencies:
if dep in installed:
constraints.append(f"{dep}=={installed[dep]}")
if constraints:
print(f" Command: pip install {package} {' '.join(constraints)}")
would_install_pinned, changes_pinned = analyze_package_dry_run(
package, constraints
)
print(f"\n Would install {len(would_install_pinned)} packages:")
for pkg, ver in would_install_pinned:
if pkg in constraints:
print(f"{pkg:25} {ver:15} 📌 PINNED")
elif pkg in installed:
print(f"{pkg:25} {ver:15} (no change)")
else:
print(f"{pkg:25} {ver:15} ✨ NEW")
# Show what was prevented
prevented = set(changes.keys()) - set(changes_pinned.keys())
if prevented:
print(f"\n ✅ Pin prevented {len(prevented)} upgrade(s):")
for pkg in prevented:
old_ver, new_ver = changes[pkg]
print(f"{pkg:25} {old_ver:15} ❌→ {new_ver}")
def analyze_all_test_packages():
"""Analyze all packages used in tests"""
print("="*80)
print("ANALYZING ALL TEST PACKAGES")
print("="*80)
test_packages = [
("requests", True),
("python-dateutil", True),
]
for package, with_pin in test_packages:
print_package_analysis(package, with_pin)
print(f"\n{'='*80}")
print("ANALYSIS COMPLETE")
print(f"{'='*80}")
def print_current_environment():
"""Print current test environment"""
print("="*80)
print("CURRENT TEST ENVIRONMENT")
print("="*80)
installed = get_installed_packages()
print(f"\nTotal packages: {len(installed)}\n")
# Group by category
test_packages = ["urllib3", "certifi", "charset-normalizer", "six", "attrs", "packaging"]
framework = ["pytest", "iniconfig", "pluggy", "Pygments"]
print("Test packages:")
for pkg in test_packages:
if pkg in installed:
print(f" {pkg:25} {installed[pkg]}")
print("\nTest framework:")
for pkg in framework:
if pkg in installed:
print(f" {pkg:25} {installed[pkg]}")
other = set(installed.keys()) - set(test_packages) - set(framework)
if other:
print("\nOther packages:")
for pkg in sorted(other):
print(f" {pkg:25} {installed[pkg]}")
def main():
"""Main entry point"""
check_venv()
if len(sys.argv) == 1:
print("Usage: python analyze_dependencies.py [package|--all|--env]")
print("\nExamples:")
print(" python analyze_dependencies.py requests")
print(" python analyze_dependencies.py --all")
print(" python analyze_dependencies.py --env")
sys.exit(0)
command = sys.argv[1]
if command == "--all":
analyze_all_test_packages()
elif command == "--env":
print_current_environment()
elif command.startswith("--"):
print(f"Unknown option: {command}")
sys.exit(1)
else:
# Analyze specific package
print_package_analysis(command, with_pin=True)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,387 @@
"""
pytest configuration and shared fixtures for pip_util.py tests
This file provides common fixtures and configuration for all tests.
Uses real isolated venv for actual pip operations.
"""
import json
import subprocess
import sys
from pathlib import Path
from typing import Dict, List
from unittest.mock import MagicMock
import pytest
# =============================================================================
# Test venv Management
# =============================================================================
@pytest.fixture(scope="session")
def test_venv_path():
"""
Get path to test venv (must be created by setup_test_env.sh)
Returns:
Path: Path to test venv directory
"""
venv_path = Path(__file__).parent / "test_venv"
if not venv_path.exists():
pytest.fail(
f"Test venv not found at {venv_path}.\n"
"Please run: ./setup_test_env.sh"
)
return venv_path
@pytest.fixture(scope="session")
def test_pip_cmd(test_venv_path):
"""
Get pip command for test venv
Returns:
List[str]: pip command prefix for subprocess
"""
pip_path = test_venv_path / "bin" / "pip"
if not pip_path.exists():
pytest.fail(f"pip not found at {pip_path}")
return [str(pip_path)]
@pytest.fixture
def reset_test_venv(test_pip_cmd):
"""
Reset test venv to initial state before each test
This fixture:
1. Records current installed packages
2. Yields control to test
3. Restores original packages after test
"""
# Get initial state
result = subprocess.run(
test_pip_cmd + ["freeze"],
capture_output=True,
text=True,
check=True
)
initial_packages = result.stdout.strip()
yield
# Restore initial state
# Uninstall everything except pip, setuptools, wheel
result = subprocess.run(
test_pip_cmd + ["freeze"],
capture_output=True,
text=True,
check=True
)
current_packages = result.stdout.strip()
if current_packages:
packages_to_remove = []
for line in current_packages.split('\n'):
if line and '==' in line:
pkg = line.split('==')[0].lower()
if pkg not in ['pip', 'setuptools', 'wheel']:
packages_to_remove.append(pkg)
if packages_to_remove:
subprocess.run(
test_pip_cmd + ["uninstall", "-y"] + packages_to_remove,
capture_output=True,
check=False # Don't fail if package doesn't exist
)
# Reinstall initial packages
if initial_packages:
# Create temporary requirements file
import tempfile
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
f.write(initial_packages)
temp_req = f.name
try:
subprocess.run(
test_pip_cmd + ["install", "-r", temp_req],
capture_output=True,
check=True
)
finally:
Path(temp_req).unlink()
# =============================================================================
# Directory and Path Fixtures
# =============================================================================
@pytest.fixture
def temp_policy_dir(tmp_path):
"""
Create temporary directory for policy files
Returns:
Path: Temporary directory for storing test policy files
"""
policy_dir = tmp_path / "policies"
policy_dir.mkdir()
return policy_dir
@pytest.fixture
def temp_user_policy_dir(tmp_path):
"""
Create temporary directory for user policy files
Returns:
Path: Temporary directory for storing user policy files
"""
user_dir = tmp_path / "user_policies"
user_dir.mkdir()
return user_dir
# =============================================================================
# Module Setup and Mocking
# =============================================================================
@pytest.fixture(autouse=True)
def setup_pip_util(monkeypatch, test_pip_cmd):
"""
Setup pip_util module for testing with real venv
This fixture:
1. Mocks comfy module (not needed for tests)
2. Adds comfyui_manager to path
3. Patches make_pip_cmd to use test venv
4. Resets policy cache
"""
# Mock comfy module before importing anything
comfy_mock = MagicMock()
cli_args_mock = MagicMock()
cli_args_mock.args = MagicMock()
comfy_mock.cli_args = cli_args_mock
sys.modules['comfy'] = comfy_mock
sys.modules['comfy.cli_args'] = cli_args_mock
# Add comfyui_manager parent to path so relative imports work
comfyui_manager_path = str(Path(__file__).parent.parent.parent.parent)
if comfyui_manager_path not in sys.path:
sys.path.insert(0, comfyui_manager_path)
# Import pip_util
from comfyui_manager.common import pip_util
# Patch make_pip_cmd to use test venv pip
def make_test_pip_cmd(args: List[str]) -> List[str]:
return test_pip_cmd + args
monkeypatch.setattr(
pip_util.manager_util,
"make_pip_cmd",
make_test_pip_cmd
)
# Reset policy cache
pip_util._pip_policy_cache = None
yield
# Cleanup
pip_util._pip_policy_cache = None
@pytest.fixture
def mock_manager_util(monkeypatch, temp_policy_dir):
"""
Mock manager_util module paths
Args:
monkeypatch: pytest monkeypatch fixture
temp_policy_dir: Temporary policy directory
"""
from comfyui_manager.common import pip_util
monkeypatch.setattr(
pip_util.manager_util,
"comfyui_manager_path",
str(temp_policy_dir)
)
@pytest.fixture
def mock_context(monkeypatch, temp_user_policy_dir):
"""
Mock context module paths
Args:
monkeypatch: pytest monkeypatch fixture
temp_user_policy_dir: Temporary user policy directory
"""
from comfyui_manager.common import pip_util
monkeypatch.setattr(
pip_util.context,
"manager_files_path",
str(temp_user_policy_dir)
)
# =============================================================================
# Platform Mocking Fixtures
# =============================================================================
@pytest.fixture
def mock_platform_linux(monkeypatch):
"""Mock platform.system() to return 'Linux'"""
monkeypatch.setattr("platform.system", lambda: "Linux")
@pytest.fixture
def mock_platform_windows(monkeypatch):
"""Mock platform.system() to return 'Windows'"""
monkeypatch.setattr("platform.system", lambda: "Windows")
@pytest.fixture
def mock_platform_darwin(monkeypatch):
"""Mock platform.system() to return 'Darwin' (macOS)"""
monkeypatch.setattr("platform.system", lambda: "Darwin")
@pytest.fixture
def mock_torch_cuda_available(monkeypatch):
"""Mock torch.cuda.is_available() to return True"""
class MockCuda:
@staticmethod
def is_available():
return True
class MockTorch:
cuda = MockCuda()
import sys
monkeypatch.setitem(sys.modules, "torch", MockTorch())
@pytest.fixture
def mock_torch_cuda_unavailable(monkeypatch):
"""Mock torch.cuda.is_available() to return False"""
class MockCuda:
@staticmethod
def is_available():
return False
class MockTorch:
cuda = MockCuda()
import sys
monkeypatch.setitem(sys.modules, "torch", MockTorch())
@pytest.fixture
def mock_torch_not_installed(monkeypatch):
"""Mock torch as not installed (ImportError)"""
import sys
if "torch" in sys.modules:
monkeypatch.delitem(sys.modules, "torch")
# =============================================================================
# Helper Functions
# =============================================================================
@pytest.fixture
def get_installed_packages(test_pip_cmd):
"""
Helper to get currently installed packages in test venv
Returns:
Callable that returns Dict[str, str] of installed packages
"""
def _get_installed() -> Dict[str, str]:
result = subprocess.run(
test_pip_cmd + ["freeze"],
capture_output=True,
text=True,
check=True
)
packages = {}
for line in result.stdout.strip().split('\n'):
if line and '==' in line:
pkg, ver = line.split('==', 1)
packages[pkg] = ver
return packages
return _get_installed
@pytest.fixture
def install_packages(test_pip_cmd):
"""
Helper to install packages in test venv
Returns:
Callable that installs packages
"""
def _install(*packages):
subprocess.run(
test_pip_cmd + ["install"] + list(packages),
capture_output=True,
check=True
)
return _install
@pytest.fixture
def uninstall_packages(test_pip_cmd):
"""
Helper to uninstall packages in test venv
Returns:
Callable that uninstalls packages
"""
def _uninstall(*packages):
subprocess.run(
test_pip_cmd + ["uninstall", "-y"] + list(packages),
capture_output=True,
check=False # Don't fail if package doesn't exist
)
return _uninstall
# =============================================================================
# Test Data Factories
# =============================================================================
@pytest.fixture
def make_policy():
"""
Factory fixture for creating policy dictionaries
Returns:
Callable that creates policy dict from parameters
"""
def _make_policy(
package_name: str,
policy_type: str,
section: str = "apply_first_match",
**kwargs
) -> Dict:
policy_item = {"type": policy_type}
policy_item.update(kwargs)
return {
package_name: {
section: [policy_item]
}
}
return _make_policy

View File

@@ -0,0 +1,52 @@
[pytest]
# pytest configuration for pip_util.py tests
# Test discovery
testpaths = .
# Markers
markers =
unit: Unit tests for individual functions
integration: Integration tests for workflows
e2e: End-to-end tests for complete scenarios
# Output options - extend global config
addopts =
# Coverage options for pip_util
--cov=../../../comfyui_manager/common/pip_util
--cov-report=html:htmlcov_pip_util
--cov-report=term-missing
--cov-report=xml:coverage_pip_util.xml
# Coverage fail threshold
--cov-fail-under=80
# Coverage configuration
[coverage:run]
source = ../../../comfyui_manager/common
omit =
*/tests/*
*/test_*.py
*/__pycache__/*
*/test_venv/*
[coverage:report]
precision = 2
show_missing = True
skip_covered = False
exclude_lines =
# Standard pragma
pragma: no cover
# Don't complain about missing debug code
def __repr__
# Don't complain if tests don't hit defensive assertion code
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run
if __name__ == .__main__.:
# Don't complain about abstract methods
@abstractmethod
[coverage:html]
directory = htmlcov

View File

@@ -0,0 +1,20 @@
# Base packages for pip_util integration tests
# These packages are installed initially to test various scenarios
# All versions verified using: pip install --dry-run --ignore-installed
# Scenario 1: Dependency Version Protection (requests + urllib3)
# Purpose: Pin prevents urllib3 1.26.15 → 2.5.0 major upgrade
urllib3==1.26.15 # OLD stable version (prevent 2.x upgrade)
certifi==2023.7.22 # OLD version (prevent 2025.x upgrade)
charset-normalizer==3.2.0 # OLD version (prevent 3.4.x upgrade)
# Note: idna is NOT pre-installed (will be added by requests)
# Scenario 2: Package Deletion and Restore (six)
# Purpose: Restore policy reinstalls deleted packages
six==1.16.0 # Will be deleted and restored to 1.16.0
attrs==23.1.0 # Bystander package
packaging==23.1 # Bystander package (NOT 23.1.0, not 25.0)
# Scenario 3: Version Change and Restore (urllib3)
# Purpose: Restore policy reverts version changes
# urllib3==1.26.15 (same as Scenario 1, will be upgraded to 2.5.0 then restored)

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Setup script for pip_util integration tests
# Creates a test venv and installs base packages
set -e # Exit on error
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$SCRIPT_DIR/test_venv"
echo "Setting up test environment for pip_util integration tests..."
# Remove existing venv if present
if [ -d "$VENV_DIR" ]; then
echo "Removing existing test venv..."
rm -rf "$VENV_DIR"
fi
# Create new venv
echo "Creating test venv at $VENV_DIR..."
python3 -m venv "$VENV_DIR"
# Activate venv
source "$VENV_DIR/bin/activate"
# Upgrade pip
echo "Upgrading pip..."
pip install --upgrade pip
# Install pytest
echo "Installing pytest..."
pip install pytest
# Install base test packages
echo "Installing base test packages..."
pip install -r "$SCRIPT_DIR/requirements-test-base.txt"
echo ""
echo "Test environment setup complete!"
echo "Installed packages:"
pip freeze
echo ""
echo "To activate the test venv, run:"
echo " source $VENV_DIR/bin/activate"
echo ""
echo "To run tests:"
echo " pytest -v"

View File

@@ -0,0 +1,271 @@
"""
Test dependency version protection with pin (Priority 1)
Tests that existing dependency versions are protected by pin_dependencies policy
"""
import json
from pathlib import Path
import pytest
@pytest.fixture
def pin_policy(temp_policy_dir):
"""Create policy with pin_dependencies for lightweight real packages"""
policy_content = {
"requests": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["urllib3", "certifi", "charset-normalizer"],
"on_failure": "retry_without_pin"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.mark.integration
def test_dependency_version_protection_with_pin(
pin_policy,
mock_manager_util,
mock_context,
reset_test_venv,
get_installed_packages
):
"""
Test existing dependency versions are protected by pin
Priority: 1 (Essential)
Purpose:
Verify that when installing a package that would normally upgrade
dependencies, the pin_dependencies policy protects existing versions.
Based on DEPENDENCY_TREE_CONTEXT.md:
Without pin: urllib3 1.26.15 → 2.5.0 (MAJOR upgrade)
With pin: urllib3 stays at 1.26.15 (protected)
"""
from comfyui_manager.common.pip_util import PipBatch
# Verify initial packages are installed (from requirements-test-base.txt)
initial = get_installed_packages()
assert "urllib3" in initial
assert "certifi" in initial
assert "charset-normalizer" in initial
# Record initial versions (from DEPENDENCY_TREE_CONTEXT.md)
initial_urllib3 = initial["urllib3"]
initial_certifi = initial["certifi"]
initial_charset = initial["charset-normalizer"]
# Verify expected OLD versions
assert initial_urllib3 == "1.26.15", f"Expected urllib3==1.26.15, got {initial_urllib3}"
assert initial_certifi == "2023.7.22", f"Expected certifi==2023.7.22, got {initial_certifi}"
assert initial_charset == "3.2.0", f"Expected charset-normalizer==3.2.0, got {initial_charset}"
# Verify idna is NOT installed initially
assert "idna" not in initial, "idna should not be pre-installed"
with PipBatch() as batch:
result = batch.install("requests")
final_packages = batch._get_installed_packages()
# Verify installation succeeded
assert result is True
assert "requests" in final_packages
# Verify versions were maintained (not upgraded to latest)
# Without pin, these would upgrade to: urllib3==2.5.0, certifi==2025.8.3, charset-normalizer==3.4.3
assert final_packages["urllib3"] == "1.26.15", "urllib3 should remain at 1.26.15 (prevented 2.x upgrade)"
assert final_packages["certifi"] == "2023.7.22", "certifi should remain at 2023.7.22 (prevented 2025.x upgrade)"
assert final_packages["charset-normalizer"] == "3.2.0", "charset-normalizer should remain at 3.2.0"
# Verify new dependency was added (idna is NOT pinned, so it gets installed)
assert "idna" in final_packages, "idna should be installed as new dependency"
assert final_packages["idna"] == "3.10", f"Expected idna==3.10, got {final_packages['idna']}"
# Verify requests was installed at expected version
assert final_packages["requests"] == "2.32.5", f"Expected requests==2.32.5, got {final_packages['requests']}"
@pytest.fixture
def python_dateutil_policy(temp_policy_dir):
"""Create policy for python-dateutil with six pinning"""
policy_content = {
"python-dateutil": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["six"],
"reason": "Protect six from upgrading"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.mark.integration
def test_dependency_chain_with_six_pin(
python_dateutil_policy,
mock_manager_util,
mock_context,
reset_test_venv,
get_installed_packages
):
"""
Test python-dateutil + six dependency chain with pin
Priority: 2 (Important)
Purpose:
Verify that pin_dependencies protects actual dependencies
(six is a real dependency of python-dateutil).
Based on DEPENDENCY_TREE_CONTEXT.md:
python-dateutil depends on six>=1.5
Without pin: six 1.16.0 → 1.17.0
With pin: six stays at 1.16.0 (protected)
"""
from comfyui_manager.common.pip_util import PipBatch
# Verify six is installed
initial = get_installed_packages()
assert "six" in initial
initial_six = initial["six"]
# Verify expected OLD version
assert initial_six == "1.16.0", f"Expected six==1.16.0, got {initial_six}"
with PipBatch() as batch:
result = batch.install("python-dateutil")
final_packages = batch._get_installed_packages()
# Verify installation succeeded
assert result is True
# Verify final versions
assert "python-dateutil" in final_packages
assert final_packages["python-dateutil"] == "2.9.0.post0", f"Expected python-dateutil==2.9.0.post0"
# Verify six was NOT upgraded (without pin, would upgrade to 1.17.0)
assert "six" in final_packages
assert final_packages["six"] == "1.16.0", "six should remain at 1.16.0 (prevented 1.17.0 upgrade)"
@pytest.mark.integration
def test_pin_only_affects_specified_packages(
pin_policy,
mock_manager_util,
mock_context,
reset_test_venv,
get_installed_packages
):
"""
Test that pin only affects specified packages, not all dependencies
Priority: 1 (Essential)
Purpose:
Verify that idna (new dependency) is installed even though
other dependencies are pinned. This tests that pin is selective,
not global.
Based on DEPENDENCY_TREE_CONTEXT.md:
idna is a NEW dependency (not in initial environment)
Pin only affects: urllib3, certifi, charset-normalizer
idna should be installed at latest version (3.10)
"""
from comfyui_manager.common.pip_util import PipBatch
# Verify initial state
initial = get_installed_packages()
assert "idna" not in initial, "idna should not be pre-installed"
assert "requests" not in initial, "requests should not be pre-installed"
with PipBatch() as batch:
result = batch.install("requests")
final_packages = batch._get_installed_packages()
# Verify installation succeeded
assert result is True
# Verify idna was installed (NOT pinned, so gets latest)
assert "idna" in final_packages, "idna should be installed as new dependency"
assert final_packages["idna"] == "3.10", "idna should be at latest version 3.10 (not pinned)"
# Verify requests was installed
assert "requests" in final_packages
assert final_packages["requests"] == "2.32.5"
@pytest.mark.integration
def test_major_version_jump_prevention(
pin_policy,
mock_manager_util,
mock_context,
reset_test_venv,
get_installed_packages,
install_packages,
uninstall_packages
):
"""
Test that pin prevents MAJOR version jumps (breaking changes)
Priority: 1 (Essential)
Purpose:
Verify that pin prevents urllib3 1.x → 2.x major upgrade.
This is the most important test because urllib3 2.0 has
breaking API changes.
Based on DEPENDENCY_TREE_CONTEXT.md:
urllib3 1.26.15 → 2.5.0 is a MAJOR version jump
urllib3 2.0 removed deprecated APIs
requests accepts both: urllib3<3,>=1.21.1
"""
from comfyui_manager.common.pip_util import PipBatch
# Verify initial urllib3 version
initial = get_installed_packages()
assert initial["urllib3"] == "1.26.15", "Expected urllib3==1.26.15"
# First, test WITHOUT pin to verify urllib3 would upgrade to 2.x
# (This simulates what would happen without our protection)
uninstall_packages("urllib3", "certifi", "charset-normalizer")
install_packages("requests")
without_pin = get_installed_packages()
# Verify urllib3 was upgraded to 2.x without pin
assert "urllib3" in without_pin
assert without_pin["urllib3"].startswith("2."), \
f"Without pin, urllib3 should upgrade to 2.x, got {without_pin['urllib3']}"
# Now reset and test WITH pin
uninstall_packages("requests", "urllib3", "certifi", "charset-normalizer", "idna")
install_packages("urllib3==1.26.15", "certifi==2023.7.22", "charset-normalizer==3.2.0")
with PipBatch() as batch:
result = batch.install("requests")
final_packages = batch._get_installed_packages()
# Verify installation succeeded
assert result is True
# Verify urllib3 stayed at 1.x (prevented major version jump)
assert final_packages["urllib3"] == "1.26.15", \
"Pin should prevent urllib3 from upgrading to 2.x (breaking changes)"
# Verify it's specifically 1.x, not 2.x
assert final_packages["urllib3"].startswith("1."), \
f"urllib3 should remain at 1.x series, got {final_packages['urllib3']}"

View File

@@ -0,0 +1,279 @@
"""
Edge cases and boundary conditions (Priority 3)
Tests empty policies, malformed JSON, and edge cases
"""
import json
import subprocess
from pathlib import Path
import pytest
@pytest.mark.unit
def test_empty_base_policy_uses_default_installation(
empty_policy_file,
mock_manager_util,
mock_context
):
"""
Test default installation with empty policy
Priority: 3 (Recommended)
Purpose:
Verify that when policy is empty, the system falls back
to default installation behavior.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import get_pip_policy
policy = get_pip_policy()
assert policy == {}
@pytest.fixture
def malformed_policy_file(temp_policy_dir):
"""Create malformed JSON policy file"""
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text("{invalid json content")
return policy_file
@pytest.mark.unit
def test_json_parse_error_fallback_to_empty(
malformed_policy_file,
mock_manager_util,
mock_context,
capture_logs
):
"""
Test empty dict on JSON parse error
Priority: 3 (Recommended)
Purpose:
Verify that malformed JSON results in empty policy
with appropriate error logging.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import get_pip_policy
policy = get_pip_policy()
assert policy == {}
# Should have error log about parsing failure
assert any("parse" in record.message.lower() for record in capture_logs.records)
@pytest.mark.unit
def test_unknown_condition_type_returns_false(
mock_manager_util,
mock_context,
capture_logs
):
"""
Test unknown condition type returns False
Priority: 3 (Recommended)
Purpose:
Verify that unknown condition types are handled gracefully
by returning False with a warning.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
condition = {"type": "unknown_type", "some_field": "value"}
result = batch._evaluate_condition(condition, "pkg", {})
assert result is False
# Should have warning about unknown type
assert any("unknown" in record.message.lower() for record in capture_logs.records)
@pytest.fixture
def self_reference_policy(temp_policy_dir):
"""Create policy with self-reference"""
policy_content = {
"critical-package": {
"restore": [
{
"condition": {
"type": "installed",
"spec": "!=1.2.3"
},
"target": "critical-package",
"version": "1.2.3"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.fixture
def mock_self_reference_subprocess(monkeypatch):
"""Mock subprocess for self-reference test"""
call_sequence = []
installed_packages = {
"critical-package": "1.2.2"
}
def mock_run(cmd, **kwargs):
call_sequence.append(cmd)
# pip freeze
if "freeze" in cmd:
output = "\n".join([f"{pkg}=={ver}" for pkg, ver in installed_packages.items()])
return subprocess.CompletedProcess(cmd, 0, output, "")
# pip install
if "install" in cmd and "critical-package==1.2.3" in cmd:
installed_packages["critical-package"] = "1.2.3"
return subprocess.CompletedProcess(cmd, 0, "", "")
return subprocess.CompletedProcess(cmd, 0, "", "")
monkeypatch.setattr("subprocess.run", mock_run)
return call_sequence, installed_packages
@pytest.mark.integration
def test_restore_self_version_check(
self_reference_policy,
mock_manager_util,
mock_context,
mock_self_reference_subprocess
):
"""
Test restore policy checking its own version
Priority: 3 (Recommended)
Purpose:
Verify that when a condition omits the package field,
it correctly defaults to checking the package itself.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages = mock_self_reference_subprocess
with PipBatch() as batch:
restored = batch.ensure_installed()
final = batch._get_installed_packages()
# Condition should evaluate with self-reference
# "1.2.2" != "1.2.3" → True
assert "critical-package" in restored
assert final["critical-package"] == "1.2.3"
@pytest.fixture
def partial_failure_policy(temp_policy_dir):
"""Create policy for multiple uninstalls"""
policy_content = {
"pkg-a": {
"uninstall": [{"target": "old-pkg-1"}]
},
"pkg-b": {
"uninstall": [{"target": "old-pkg-2"}]
},
"pkg-c": {
"uninstall": [{"target": "old-pkg-3"}]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.fixture
def mock_partial_failure_subprocess(monkeypatch):
"""Mock subprocess with one failure"""
call_sequence = []
installed_packages = {
"old-pkg-1": "1.0",
"old-pkg-2": "1.0",
"old-pkg-3": "1.0"
}
def mock_run(cmd, **kwargs):
call_sequence.append(cmd)
# pip freeze
if "freeze" in cmd:
output = "\n".join([f"{pkg}=={ver}" for pkg, ver in installed_packages.items()])
return subprocess.CompletedProcess(cmd, 0, output, "")
# pip uninstall
if "uninstall" in cmd:
if "old-pkg-2" in cmd:
# Fail on pkg-2
raise subprocess.CalledProcessError(1, cmd, "", "Uninstall failed")
else:
# Success on others
for pkg in ["old-pkg-1", "old-pkg-3"]:
if pkg in cmd:
installed_packages.pop(pkg, None)
return subprocess.CompletedProcess(cmd, 0, "", "")
return subprocess.CompletedProcess(cmd, 0, "", "")
monkeypatch.setattr("subprocess.run", mock_run)
return call_sequence, installed_packages
@pytest.mark.integration
def test_ensure_not_installed_continues_on_individual_failure(
partial_failure_policy,
mock_manager_util,
mock_context,
mock_partial_failure_subprocess,
capture_logs
):
"""
Test partial failure handling
Priority: 2 (Important)
Purpose:
Verify that when one package removal fails, the system
continues processing other packages.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages = mock_partial_failure_subprocess
with PipBatch() as batch:
removed = batch.ensure_not_installed()
# Verify partial success
assert "old-pkg-1" in removed
assert "old-pkg-3" in removed
assert "old-pkg-2" not in removed # Failed
# Verify warning logged for failure
assert any("warning" in record.levelname.lower() for record in capture_logs.records)

View File

@@ -0,0 +1,158 @@
"""
Test environment corruption and recovery (Priority 1)
Tests that packages deleted or modified during installation are restored
"""
import json
from pathlib import Path
import pytest
@pytest.fixture
def restore_policy(temp_policy_dir):
"""Create policy with restore section for lightweight packages"""
policy_content = {
"six": {
"restore": [
{
"target": "six",
"version": "1.16.0",
"reason": "six must be maintained at 1.16.0 for compatibility"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.mark.integration
def test_package_deletion_and_restore(
restore_policy,
mock_manager_util,
mock_context,
reset_test_venv,
get_installed_packages,
install_packages,
uninstall_packages
):
"""
Test package deleted by installation is restored
Priority: 1 (Essential)
Purpose:
Verify that when a package installation deletes another package,
the restore policy can bring it back with the correct version.
Based on DEPENDENCY_TREE_CONTEXT.md:
six==1.16.0 must be maintained for compatibility
After deletion, should restore to exactly 1.16.0
"""
from comfyui_manager.common.pip_util import PipBatch
# Verify six is initially installed at expected version
initial = get_installed_packages()
assert "six" in initial
assert initial["six"] == "1.16.0", f"Expected six==1.16.0, got {initial['six']}"
with PipBatch() as batch:
# Manually remove six to simulate deletion by another package
uninstall_packages("six")
# Check six was deleted
installed_after_delete = batch._get_installed_packages()
assert "six" not in installed_after_delete, "six should be deleted"
# Restore six
restored = batch.ensure_installed()
final_packages = batch._get_installed_packages()
# Verify six was restored to EXACT required version (not latest)
assert "six" in restored, "six should be in restored list"
assert final_packages["six"] == "1.16.0", \
"six should be restored to exact version 1.16.0 (not 1.17.0 latest)"
@pytest.fixture
def version_change_policy(temp_policy_dir):
"""Create policy for version change test with real packages"""
policy_content = {
"urllib3": {
"restore": [
{
"condition": {
"type": "installed",
"spec": "!=1.26.15"
},
"target": "urllib3",
"version": "1.26.15",
"reason": "urllib3 must be 1.26.15 for compatibility"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.mark.integration
def test_version_change_and_restore(
version_change_policy,
mock_manager_util,
mock_context,
reset_test_venv,
get_installed_packages,
install_packages
):
"""
Test package version changed by installation is restored
Priority: 1 (Essential)
Purpose:
Verify that when a package installation changes another package's
version, the restore policy can revert it to the required version.
Based on DEPENDENCY_TREE_CONTEXT.md:
urllib3 can upgrade from 1.26.15 (1.x) to 2.5.0 (2.x)
Restore policy with condition "!=1.26.15" should downgrade back
This tests downgrade capability (not just upgrade prevention)
"""
from comfyui_manager.common.pip_util import PipBatch
# Verify urllib3 1.26.15 is installed
initial = get_installed_packages()
assert "urllib3" in initial
assert initial["urllib3"] == "1.26.15", f"Expected urllib3==1.26.15, got {initial['urllib3']}"
with PipBatch() as batch:
# Manually upgrade urllib3 to 2.x to simulate version change
# This is a MAJOR version upgrade (1.x → 2.x)
install_packages("urllib3==2.1.0")
installed_after = batch._get_installed_packages()
# Verify version was changed to 2.x
assert installed_after["urllib3"] == "2.1.0", \
f"urllib3 should be upgraded to 2.1.0, got {installed_after['urllib3']}"
assert installed_after["urllib3"].startswith("2."), \
"urllib3 should be at 2.x series"
# Restore urllib3 to 1.26.15 (this is a DOWNGRADE from 2.x to 1.x)
restored = batch.ensure_installed()
final = batch._get_installed_packages()
# Verify condition was satisfied (2.1.0 != 1.26.15) and restore was triggered
assert "urllib3" in restored, "urllib3 should be in restored list"
# Verify version was DOWNGRADED from 2.x back to 1.x
assert final["urllib3"] == "1.26.15", \
"urllib3 should be downgraded to 1.26.15 (from 2.1.0)"
assert final["urllib3"].startswith("1."), \
f"urllib3 should be back at 1.x series, got {final['urllib3']}"

View File

@@ -0,0 +1,204 @@
"""
Test full workflow integration (Priority 1)
Tests the complete uninstall → install → restore workflow
"""
import json
import subprocess
from pathlib import Path
import pytest
@pytest.fixture
def workflow_policy(temp_policy_dir):
"""Create policy for full workflow test"""
policy_content = {
"target-package": {
"uninstall": [
{
"condition": {
"type": "installed",
"package": "conflicting-pkg"
},
"target": "conflicting-pkg",
"reason": "Conflicts with target-package"
}
],
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["numpy", "pandas"]
}
]
},
"critical-package": {
"restore": [
{
"target": "critical-package",
"version": "1.2.3",
"reason": "Critical package must be 1.2.3"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.fixture
def mock_workflow_subprocess(monkeypatch):
"""Mock subprocess for workflow test"""
call_sequence = []
# Initial environment: conflicting-pkg, numpy, pandas, critical-package
installed_packages = {
"conflicting-pkg": "1.0.0",
"numpy": "1.26.0",
"pandas": "2.0.0",
"critical-package": "1.2.3"
}
def mock_run(cmd, **kwargs):
call_sequence.append(cmd)
# pip freeze
if "freeze" in cmd:
output = "\n".join([f"{pkg}=={ver}" for pkg, ver in installed_packages.items()])
return subprocess.CompletedProcess(cmd, 0, output, "")
# pip uninstall
if "uninstall" in cmd:
# Remove conflicting-pkg
if "conflicting-pkg" in cmd:
installed_packages.pop("conflicting-pkg", None)
return subprocess.CompletedProcess(cmd, 0, "", "")
# pip install target-package (deletes critical-package)
if "install" in cmd and "target-package" in cmd:
# Simulate target-package installation deleting critical-package
installed_packages.pop("critical-package", None)
installed_packages["target-package"] = "1.0.0"
return subprocess.CompletedProcess(cmd, 0, "", "")
# pip install critical-package (restore)
if "install" in cmd and "critical-package==1.2.3" in cmd:
installed_packages["critical-package"] = "1.2.3"
return subprocess.CompletedProcess(cmd, 0, "", "")
return subprocess.CompletedProcess(cmd, 0, "", "")
monkeypatch.setattr("subprocess.run", mock_run)
return call_sequence, installed_packages
@pytest.mark.integration
def test_uninstall_install_restore_workflow(
workflow_policy,
mock_manager_util,
mock_context,
mock_workflow_subprocess
):
"""
Test complete uninstall → install → restore workflow
Priority: 1 (Essential)
Purpose:
Verify the complete workflow executes in correct order:
1. ensure_not_installed() removes conflicting packages
2. install() applies policies (pin_dependencies)
3. ensure_installed() restores deleted packages
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages = mock_workflow_subprocess
with PipBatch() as batch:
# Step 1: uninstall - remove conflicting packages
removed = batch.ensure_not_installed()
# Step 2: install target-package with pinned dependencies
result = batch.install("target-package")
# Step 3: restore critical-package that was deleted
restored = batch.ensure_installed()
# Verify Step 1: conflicting-pkg was removed
assert "conflicting-pkg" in removed
# Verify Step 2: target-package was installed with pinned dependencies
assert result is True
# Check that pip install was called with pinned packages
install_calls = [cmd for cmd in call_sequence if "install" in cmd and "target-package" in cmd]
assert len(install_calls) > 0
install_cmd = install_calls[0]
assert "target-package" in install_cmd
assert "numpy==1.26.0" in install_cmd
assert "pandas==2.0.0" in install_cmd
# Verify Step 3: critical-package was restored
assert "critical-package" in restored
# Verify final state
assert "conflicting-pkg" not in installed_packages
assert "critical-package" in installed_packages
assert installed_packages["critical-package"] == "1.2.3"
assert "target-package" in installed_packages
@pytest.mark.integration
def test_cache_invalidation_across_workflow(
workflow_policy,
mock_manager_util,
mock_context,
mock_workflow_subprocess
):
"""
Test cache is correctly refreshed at each workflow step
Priority: 1 (Essential)
Purpose:
Verify that the cache is invalidated and refreshed after each
operation (uninstall, install, restore) to reflect current state.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages = mock_workflow_subprocess
with PipBatch() as batch:
# Initial cache state
cache1 = batch._get_installed_packages()
assert "conflicting-pkg" in cache1
assert "critical-package" in cache1
# After uninstall
removed = batch.ensure_not_installed()
cache2 = batch._get_installed_packages()
assert "conflicting-pkg" not in cache2 # Removed
# After install (critical-package gets deleted by target-package)
batch.install("target-package")
cache3 = batch._get_installed_packages()
assert "target-package" in cache3 # Added
assert "critical-package" not in cache3 # Deleted by target-package
# After restore
restored = batch.ensure_installed()
cache4 = batch._get_installed_packages()
assert "critical-package" in cache4 # Restored
# Verify cache was refreshed at each step
assert cache1 != cache2 # Changed after uninstall
assert cache2 != cache3 # Changed after install
assert cache3 != cache4 # Changed after restore

View File

@@ -0,0 +1,216 @@
"""
Test pin failure and retry logic (Priority 1)
Tests that installation with pinned dependencies can retry without pins on failure
"""
import json
import subprocess
from pathlib import Path
import pytest
@pytest.fixture
def retry_policy(temp_policy_dir):
"""Create policy with retry_without_pin"""
policy_content = {
"new-pkg": {
"apply_all_matches": [
{
"type": "pin_dependencies",
"pinned_packages": ["numpy", "pandas"],
"on_failure": "retry_without_pin"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.fixture
def mock_retry_subprocess(monkeypatch):
"""Mock subprocess that fails with pins, succeeds without"""
call_sequence = []
attempt_count = [0]
installed_packages = {
"numpy": "1.26.0",
"pandas": "2.0.0"
}
def mock_run(cmd, **kwargs):
call_sequence.append(cmd)
# pip freeze
if "freeze" in cmd:
output = "\n".join([f"{pkg}=={ver}" for pkg, ver in installed_packages.items()])
return subprocess.CompletedProcess(cmd, 0, output, "")
# pip install
if "install" in cmd and "new-pkg" in cmd:
attempt_count[0] += 1
# First attempt with pins - FAIL
if attempt_count[0] == 1 and "numpy==1.26.0" in cmd and "pandas==2.0.0" in cmd:
raise subprocess.CalledProcessError(1, cmd, "", "Dependency conflict")
# Second attempt without pins - SUCCESS
if attempt_count[0] == 2:
installed_packages["new-pkg"] = "1.0.0"
# Without pins, versions might change
return subprocess.CompletedProcess(cmd, 0, "", "")
return subprocess.CompletedProcess(cmd, 0, "", "")
monkeypatch.setattr("subprocess.run", mock_run)
return call_sequence, installed_packages, attempt_count
@pytest.mark.integration
def test_pin_failure_retry_without_pin_succeeds(
retry_policy,
mock_manager_util,
mock_context,
mock_retry_subprocess,
capture_logs
):
"""
Test retry without pin succeeds after pin failure
Priority: 1 (Essential)
Purpose:
Verify that when installation with pinned dependencies fails,
the system automatically retries without pins and succeeds.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages, attempt_count = mock_retry_subprocess
with PipBatch() as batch:
result = batch.install("new-pkg")
# Verify installation succeeded on retry
assert result is True
# Verify two installation attempts were made
install_calls = [cmd for cmd in call_sequence if "install" in cmd and "new-pkg" in cmd]
assert len(install_calls) == 2
# First attempt had pins
first_call = install_calls[0]
assert "new-pkg" in first_call
assert "numpy==1.26.0" in first_call
assert "pandas==2.0.0" in first_call
# Second attempt had no pins (just new-pkg)
second_call = install_calls[1]
assert "new-pkg" in second_call
assert "numpy==1.26.0" not in second_call
assert "pandas==2.0.0" not in second_call
# Verify warning log
assert any("retrying without pins" in record.message.lower() for record in capture_logs.records)
@pytest.fixture
def fail_policy(temp_policy_dir):
"""Create policy with on_failure: fail"""
policy_content = {
"pytorch-addon": {
"apply_all_matches": [
{
"condition": {
"type": "installed",
"package": "torch",
"spec": ">=2.0.0"
},
"type": "pin_dependencies",
"pinned_packages": ["torch", "torchvision", "torchaudio"],
"on_failure": "fail"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.fixture
def mock_fail_subprocess(monkeypatch):
"""Mock subprocess that always fails"""
call_sequence = []
installed_packages = {
"torch": "2.1.0",
"torchvision": "0.16.0",
"torchaudio": "2.1.0"
}
def mock_run(cmd, **kwargs):
call_sequence.append(cmd)
# pip freeze
if "freeze" in cmd:
output = "\n".join([f"{pkg}=={ver}" for pkg, ver in installed_packages.items()])
return subprocess.CompletedProcess(cmd, 0, output, "")
# pip install - ALWAYS FAIL
if "install" in cmd and "pytorch-addon" in cmd:
raise subprocess.CalledProcessError(1, cmd, "", "Installation failed")
return subprocess.CompletedProcess(cmd, 0, "", "")
monkeypatch.setattr("subprocess.run", mock_run)
return call_sequence, installed_packages
@pytest.mark.integration
def test_pin_failure_with_fail_raises_exception(
fail_policy,
mock_manager_util,
mock_context,
mock_fail_subprocess,
capture_logs
):
"""
Test exception is raised when on_failure is "fail"
Priority: 1 (Essential)
Purpose:
Verify that when on_failure is set to "fail", installation
failure with pinned dependencies raises an exception and
does not retry.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages = mock_fail_subprocess
with PipBatch() as batch:
# Should raise exception
with pytest.raises(subprocess.CalledProcessError):
batch.install("pytorch-addon")
# Verify only one installation attempt was made (no retry)
install_calls = [cmd for cmd in call_sequence if "install" in cmd and "pytorch-addon" in cmd]
assert len(install_calls) == 1
# Verify it had pins
install_cmd = install_calls[0]
assert "pytorch-addon" in install_cmd
assert "torch==2.1.0" in install_cmd
assert "torchvision==0.16.0" in install_cmd
assert "torchaudio==2.1.0" in install_cmd

View File

@@ -0,0 +1,139 @@
"""
Test platform-specific conditions (Priority 2)
Tests OS and GPU detection for conditional policies
"""
import json
import subprocess
from pathlib import Path
import pytest
@pytest.fixture
def platform_policy(temp_policy_dir):
"""Create policy with platform conditions"""
policy_content = {
"onnxruntime": {
"apply_first_match": [
{
"condition": {
"type": "platform",
"os": "linux",
"has_gpu": True
},
"type": "replace",
"replacement": "onnxruntime-gpu"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.fixture
def mock_platform_subprocess(monkeypatch):
"""Mock subprocess for platform test"""
call_sequence = []
installed_packages = {}
def mock_run(cmd, **kwargs):
call_sequence.append(cmd)
# pip freeze
if "freeze" in cmd:
output = "\n".join([f"{pkg}=={ver}" for pkg, ver in installed_packages.items()])
return subprocess.CompletedProcess(cmd, 0, output, "")
# pip install
if "install" in cmd:
if "onnxruntime-gpu" in cmd:
installed_packages["onnxruntime-gpu"] = "1.0.0"
elif "onnxruntime" in cmd:
installed_packages["onnxruntime"] = "1.0.0"
return subprocess.CompletedProcess(cmd, 0, "", "")
return subprocess.CompletedProcess(cmd, 0, "", "")
monkeypatch.setattr("subprocess.run", mock_run)
return call_sequence, installed_packages
@pytest.mark.integration
def test_linux_gpu_uses_gpu_package(
platform_policy,
mock_manager_util,
mock_context,
mock_platform_subprocess,
mock_platform_linux,
mock_torch_cuda_available
):
"""
Test GPU-specific package on Linux + GPU
Priority: 2 (Important)
Purpose:
Verify that platform-conditional policies correctly detect
Linux + GPU and install the appropriate package variant.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages = mock_platform_subprocess
with PipBatch() as batch:
result = batch.install("onnxruntime")
# Verify installation succeeded
assert result is True
# Verify GPU version was installed
install_calls = [cmd for cmd in call_sequence if "install" in cmd]
assert any("onnxruntime-gpu" in str(cmd) for cmd in install_calls)
assert "onnxruntime-gpu" in installed_packages
@pytest.mark.integration
def test_windows_no_gpu_uses_cpu_package(
platform_policy,
mock_manager_util,
mock_context,
mock_platform_subprocess,
mock_platform_windows,
mock_torch_cuda_unavailable
):
"""
Test CPU package on Windows + No GPU
Priority: 2 (Important)
Purpose:
Verify that when platform conditions are not met,
the original package is installed without replacement.
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages = mock_platform_subprocess
with PipBatch() as batch:
result = batch.install("onnxruntime")
# Verify installation succeeded
assert result is True
# Verify CPU version was installed (no GPU replacement)
install_calls = [cmd for cmd in call_sequence if "install" in cmd]
assert any("onnxruntime" in str(cmd) for cmd in install_calls)
assert "onnxruntime-gpu" not in str(call_sequence)
assert "onnxruntime" in installed_packages
assert "onnxruntime-gpu" not in installed_packages

View File

@@ -0,0 +1,180 @@
"""
Test policy priority and conflicts (Priority 2)
Tests that user policies override base policies correctly
"""
import json
import subprocess
from pathlib import Path
import pytest
@pytest.fixture
def conflicting_policies(temp_policy_dir, temp_user_policy_dir):
"""Create conflicting base and user policies"""
# Base policy
base_content = {
"numpy": {
"apply_first_match": [
{
"type": "skip",
"reason": "Base policy skip"
}
]
}
}
base_file = temp_policy_dir / "pip-policy.json"
base_file.write_text(json.dumps(base_content, indent=2))
# User policy (should override)
user_content = {
"numpy": {
"apply_first_match": [
{
"type": "force_version",
"version": "1.26.0",
"reason": "User override"
}
]
}
}
user_file = temp_user_policy_dir / "pip-policy.user.json"
user_file.write_text(json.dumps(user_content, indent=2))
return base_file, user_file
@pytest.mark.unit
def test_user_policy_overrides_base_policy(
conflicting_policies,
mock_manager_util,
mock_context,
mock_subprocess_success
):
"""
Test user policy completely replaces base policy
Priority: 2 (Important)
Purpose:
Verify that user policy completely overrides base policy
at the package level (not section-level merge).
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import get_pip_policy
policy = get_pip_policy()
# Verify user policy replaced base policy
assert "numpy" in policy
assert "apply_first_match" in policy["numpy"]
assert len(policy["numpy"]["apply_first_match"]) == 1
# Should be force_version (user), not skip (base)
assert policy["numpy"]["apply_first_match"][0]["type"] == "force_version"
assert policy["numpy"]["apply_first_match"][0]["version"] == "1.26.0"
# Base policy skip should be completely gone
assert not any(
item["type"] == "skip"
for item in policy["numpy"]["apply_first_match"]
)
@pytest.fixture
def first_match_policy(temp_policy_dir):
"""Create policy with multiple apply_first_match entries"""
policy_content = {
"pkg": {
"apply_first_match": [
{
"condition": {
"type": "installed",
"package": "numpy"
},
"type": "force_version",
"version": "1.0"
},
{
"type": "force_version",
"version": "2.0"
},
{
"type": "skip"
}
]
}
}
policy_file = temp_policy_dir / "pip-policy.json"
policy_file.write_text(json.dumps(policy_content, indent=2))
return policy_file
@pytest.fixture
def mock_first_match_subprocess(monkeypatch):
"""Mock subprocess for first match test"""
call_sequence = []
installed_packages = {
"numpy": "1.26.0"
}
def mock_run(cmd, **kwargs):
call_sequence.append(cmd)
# pip freeze
if "freeze" in cmd:
output = "\n".join([f"{pkg}=={ver}" for pkg, ver in installed_packages.items()])
return subprocess.CompletedProcess(cmd, 0, output, "")
# pip install
if "install" in cmd and "pkg" in cmd:
if "pkg==1.0" in cmd:
installed_packages["pkg"] = "1.0"
return subprocess.CompletedProcess(cmd, 0, "", "")
return subprocess.CompletedProcess(cmd, 0, "", "")
monkeypatch.setattr("subprocess.run", mock_run)
return call_sequence, installed_packages
@pytest.mark.integration
def test_first_match_stops_at_first_satisfied(
first_match_policy,
mock_manager_util,
mock_context,
mock_first_match_subprocess
):
"""
Test apply_first_match stops at first satisfied condition
Priority: 2 (Important)
Purpose:
Verify that in apply_first_match, only the first policy
with a satisfied condition is executed (exclusive execution).
"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
call_sequence, installed_packages = mock_first_match_subprocess
with PipBatch() as batch:
result = batch.install("pkg")
# Verify installation succeeded
assert result is True
# First condition satisfied (numpy installed), so version 1.0 applied
install_calls = [cmd for cmd in call_sequence if "install" in cmd and "pkg" in cmd]
assert len(install_calls) > 0
assert "pkg==1.0" in install_calls[0]
assert "pkg==2.0" not in str(call_sequence) # Second policy not applied

View File

@@ -0,0 +1,178 @@
"""
Unit tests for package spec parsing and condition evaluation
Tests core utility functions
"""
import subprocess
from pathlib import Path
import pytest
@pytest.mark.unit
def test_parse_package_spec_name_only(mock_manager_util, mock_context):
"""Test parsing package name without version"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
name, spec = batch._parse_package_spec("numpy")
assert name == "numpy"
assert spec is None
@pytest.mark.unit
def test_parse_package_spec_exact_version(mock_manager_util, mock_context):
"""Test parsing package with exact version"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
name, spec = batch._parse_package_spec("numpy==1.26.0")
assert name == "numpy"
assert spec == "==1.26.0"
@pytest.mark.unit
def test_parse_package_spec_min_version(mock_manager_util, mock_context):
"""Test parsing package with minimum version"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
name, spec = batch._parse_package_spec("pandas>=2.0.0")
assert name == "pandas"
assert spec == ">=2.0.0"
@pytest.mark.unit
def test_parse_package_spec_hyphenated_name(mock_manager_util, mock_context):
"""Test parsing package with hyphens"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
name, spec = batch._parse_package_spec("scikit-learn>=1.0")
assert name == "scikit-learn"
assert spec == ">=1.0"
@pytest.mark.unit
def test_evaluate_condition_none(mock_manager_util, mock_context):
"""Test None condition always returns True"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
result = batch._evaluate_condition(None, "numpy", {})
assert result is True
@pytest.mark.unit
def test_evaluate_condition_installed_package_exists(mock_manager_util, mock_context):
"""Test installed condition when package exists"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
condition = {"type": "installed", "package": "numpy"}
installed = {"numpy": "1.26.0"}
result = batch._evaluate_condition(condition, "numba", installed)
assert result is True
@pytest.mark.unit
def test_evaluate_condition_installed_package_not_exists(mock_manager_util, mock_context):
"""Test installed condition when package doesn't exist"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
condition = {"type": "installed", "package": "numpy"}
installed = {}
result = batch._evaluate_condition(condition, "numba", installed)
assert result is False
@pytest.mark.unit
def test_evaluate_condition_platform_os_match(
mock_manager_util,
mock_context,
mock_platform_linux
):
"""Test platform OS condition matching"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
condition = {"type": "platform", "os": "linux"}
result = batch._evaluate_condition(condition, "package", {})
assert result is True
@pytest.mark.unit
def test_evaluate_condition_platform_gpu_available(
mock_manager_util,
mock_context,
mock_torch_cuda_available
):
"""Test GPU detection when available"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
condition = {"type": "platform", "has_gpu": True}
result = batch._evaluate_condition(condition, "package", {})
assert result is True
@pytest.mark.unit
def test_evaluate_condition_platform_gpu_not_available(
mock_manager_util,
mock_context,
mock_torch_cuda_unavailable
):
"""Test GPU detection when not available"""
import sys
# Path setup handled by conftest.py
from comfyui_manager.common.pip_util import PipBatch
batch = PipBatch()
condition = {"type": "platform", "has_gpu": True}
result = batch._evaluate_condition(condition, "package", {})
assert result is False

View File

@@ -1,327 +0,0 @@
# Glob API Endpoint Tests
This directory contains endpoint tests for the ComfyUI Manager glob API implementation.
## Quick Navigation
- **Running Tests**: See [Running Tests](#running-tests) section below
- **Test Coverage**: See [Test Coverage](#test-coverage) section
- **Known Issues**: See [Known Issues and Fixes](#known-issues-and-fixes) section
- **Detailed Execution Guide**: See [TESTING_GUIDE.md](./TESTING_GUIDE.md)
- **Future Test Plans**: See [docs/internal/test_planning/](../../docs/internal/test_planning/)
## Test Files
- `test_queue_task_api.py` - Queue task API tests for install/uninstall/version switching operations (8 tests)
- `test_enable_disable_api.py` - Queue task API tests for enable/disable operations (5 tests)
- `test_update_api.py` - Queue task API tests for update operations (4 tests)
- `test_complex_scenarios.py` - Multi-version complex scenarios (10 tests) - **Phase 1 + 3 + 4 + 5 + 6**
- `test_installed_api_original_case.py` - Installed API case preservation tests (4 tests)
- `test_version_switching_comprehensive.py` - Comprehensive version switching tests (19 tests)
- `test_case_sensitivity_integration.py` - Full integration test for case sensitivity (1 test)
**Total: 51 tests - All passing ✅** (+5 P1 tests: Phase 3.1, Phase 5.1, Phase 5.2, Phase 5.3, Phase 6)
## Running Tests
### Prerequisites
1. Install test dependencies:
```bash
pip install pytest requests
```
2. Start ComfyUI server with Manager:
```bash
cd tests/env
./run.sh
```
### Run All Tests
```bash
# From project root
pytest tests/glob/ -v
# With coverage
pytest tests/glob/ -v --cov=comfyui_manager.glob --cov-report=html
```
### Run Specific Tests
```bash
# Run specific test file
pytest tests/glob/test_queue_task_api.py -v
# Run specific test function
pytest tests/glob/test_queue_task_api.py::test_install_package_via_queue -v
# Run with output
pytest tests/glob/test_queue_task_api.py -v -s
```
## Environment Variables
- `COMFYUI_TEST_URL` - Base URL for ComfyUI server (default: http://127.0.0.1:8188)
- `TEST_SERVER_PORT` - Server port (default: 8188, automatically used by conftest.py)
- `COMFYUI_CUSTOM_NODES_PATH` - Path to custom_nodes directory (default: tests/env/ComfyUI/custom_nodes)
**Important**: All tests now use the `server_url` fixture from `conftest.py`, which reads from these environment variables. This ensures compatibility with parallel test execution.
Example:
```bash
# Single test environment
COMFYUI_TEST_URL=http://localhost:8188 pytest tests/glob/ -v
# Parallel test environment (port automatically set)
TEST_SERVER_PORT=8189 pytest tests/glob/ -v
```
## Test Coverage
The test suite covers:
1. **Install Operations** (test_queue_task_api.py)
- Install package via queue task API
- Version switching between CNR and Nightly
- Case-insensitive package name handling
- Queue multiple install tasks
2. **Uninstall Operations** (test_queue_task_api.py)
- Uninstall package via queue task API
- Complete install/uninstall cycle
- Case-insensitive uninstall operations
3. **Enable/Disable Operations** (test_enable_disable_api.py) ✅ **All via Queue Task API**
- Disable active package via queue task
- Enable disabled package via queue task
- Duplicate disable/enable handling via queue task
- Complete enable/disable cycle via queue task
- Marker file preservation (.tracking, .git)
4. **Update Operations** (test_update_api.py)
- Update CNR package to latest version
- Update Nightly package (git pull)
- Skip update when already latest
- Complete update workflow cycle
5. **Complex Multi-Version Scenarios** (test_complex_scenarios.py)
- **Phase 1**: Enable from Multiple Disabled States
- Enable CNR when both CNR and Nightly are disabled
- Enable Nightly when both CNR and Nightly are disabled
- **Phase 3**: Disable Complex Scenarios
- Disable CNR when Nightly is disabled (both end up disabled)
- **Phase 4**: Update with Other Versions Present
- Update CNR with Nightly disabled (selective update)
- Update Nightly with CNR disabled (selective update)
- Update enabled package with multiple disabled versions
- **Phase 5**: Install with Existing Versions (Complete) ✅
- Install CNR when Nightly is enabled (automatic version switch)
- Install Nightly when CNR is enabled (automatic version switch)
- Install new version when both CNR and Nightly are disabled
- **Phase 6**: Uninstall with Multiple Versions ✅
- Uninstall removes all versions (enabled + all disabled) - default behavior
- Version-specific enable with @version syntax
- Multiple disabled versions management
6. **Version Switching Comprehensive** (test_version_switching_comprehensive.py)
- Reverse scenario: Nightly → CNR → Nightly
- Same version reinstall detection and skip
7. **Case Sensitivity Integration** (test_case_sensitivity_integration.py)
- Full workflow: Install CNR → Verify lookup → Switch to Nightly
- Directory naming convention verification
- Marker file preservation (.tracking, .git)
- Supports both pytest and standalone execution
- Repeated version switching (4+ times)
- Cleanup verification (no orphaned files)
- Fresh install after complete uninstall
7. **Queue Management**
- Queue multiple tasks
- Start queue processing
- Task execution order and completion
8. **Integration Tests**
- Verify package in installed list
- Verify filesystem changes
- Version identification (.tracking vs .git)
- .disabled/ directory mechanism
## Known Issues and Fixes
### Issue 1: Glob API Parameters
**Important**: Glob API does NOT support `channel` or `mode` parameters.
**Note**:
- `channel` and `mode` parameters are legacy-only features
- `InstallPackParams` data model includes these fields because it's shared between legacy and glob implementations
- Glob API implementation ignores these parameters
- Tests should NOT include `channel` or `mode` in request parameters
### Issue 2: Case-Insensitive Package Operations (PARTIALLY RESOLVED)
**Previous Problem**: Operations failed when using different cases (e.g., "ComfyUI_SigmoidOffsetScheduler" vs "comfyui_sigmoidoffsetscheduler")
**Current Status**:
- **Install**: Requires exact package name due to CNR server limitations (case-sensitive)
- **Uninstall/Enable/Disable**: Works with any case variation using `cnr_utils.normalize_package_name()`
**Normalization Function** (`cnr_utils.normalize_package_name()`):
- Strips leading/trailing whitespace with `.strip()`
- Converts to lowercase with `.lower()`
- Accepts any case variation (e.g., "ComfyUI_SigmoidOffsetScheduler", "COMFYUI_SIGMOIDOFFSETSCHEDULER", " comfyui_sigmoidoffsetscheduler ")
**Examples**:
```python
# Install - requires exact case
{"id": "ComfyUI_SigmoidOffsetScheduler"} # ✓ Works
{"id": "comfyui_sigmoidoffsetscheduler"} # ✗ Fails (CNR limitation)
# Uninstall - accepts any case
{"node_name": "ComfyUI_SigmoidOffsetScheduler"} # ✓ Works
{"node_name": " ComfyUI_SigmoidOffsetScheduler "} # ✓ Works (normalized)
{"node_name": "COMFYUI_SIGMOIDOFFSETSCHEDULER"} # ✓ Works (normalized)
{"node_name": "comfyui_sigmoidoffsetscheduler"} # ✓ Works (normalized)
```
### Issue 3: `.disabled/` Directory Mechanism
**Critical Discovery**: The `.disabled/` directory is used by the **disable** operation to store disabled packages.
**Implementation** (manager_core.py:1115-1154):
```python
def unified_disable(self, packname: str):
# Disable moves package to .disabled/ with version suffix
to_path = os.path.join(base_path, '.disabled', f"{folder_name}@{matched_active.version.replace('.', '_')}")
shutil.move(matched_active.fullpath, to_path)
```
**Directory Naming Format**:
- CNR packages: `.disabled/{package_name_normalized}@{version}`
- Example: `.disabled/comfyui_sigmoidoffsetscheduler@1_0_2`
- Nightly packages: `.disabled/{package_name_normalized}@nightly`
- Example: `.disabled/comfyui_sigmoidoffsetscheduler@nightly`
**Key Points**:
- Package names are **normalized** (lowercase) in directory names
- Version dots are **replaced with underscores** (e.g., `1.0.2``1_0_2`)
- Disabled packages **preserve** their marker files (`.tracking` for CNR, `.git` for Nightly)
- Enable operation **moves packages back** from `.disabled/` to `custom_nodes/`
**Testing Implications**:
- Complex multi-version scenarios require **install → disable** sequences
- Fixture pattern: Install CNR → Disable → Install Nightly → Disable
- Tests must check `.disabled/` with **case-insensitive** searches
- Directory format must match normalized names with version suffixes
### Issue 4: Version Switch Mechanism
**Behavior**: Version switching uses a **slot-based system** with Nightly and Archive as separate slots.
**Slot-Based System Concept**:
- **Nightly Slot**: Git-based installation (one slot)
- **Archive Slot**: Registry-based installation (one slot)
- Only **one slot is active** at a time
- The inactive slot is stored in `.disabled/`
- Archive versions update **within the Archive slot**
**Two Types of Version Switch**:
**1. Slot Switch: Nightly ↔ Archive (uses `.disabled/` mechanism)**
- **Archive → Nightly**:
- Archive (any version) → moved to `.disabled/ComfyUI_SigmoidOffsetScheduler`
- Nightly → active in `custom_nodes/ComfyUI_SigmoidOffsetScheduler`
- **Nightly → Archive**:
- Nightly → moved to `.disabled/ComfyUI_SigmoidOffsetScheduler`
- Archive (any version) → **restored from `.disabled/`** and becomes active
**2. Version Update: Archive ↔ Archive (in-place update within Archive slot)**
- **1.0.1 → 1.0.2** (when Archive slot is active):
- Directory contents updated in-place
- pyproject.toml version updated: 1.0.1 → 1.0.2
- `.tracking` file updated
- NO `.disabled/` directory used
**3. Combined Operation: Nightly (active) + Archive 1.0 (disabled) → Archive 2.0**
- **Step 1 - Slot Switch**: Nightly → `.disabled/`, Archive 1.0 → active
- **Step 2 - Version Update**: Archive 1.0 → 2.0 (in-place within Archive slot)
- **Result**: Archive 2.0 active, Nightly in `.disabled/`
**Version Identification**:
- **Archive versions**: Use `pyproject.toml` version field
- **Nightly version**: pyproject.toml **ignored**, Git commit SHA used instead
**Key Points**:
- **Slot Switch** (Nightly ↔ Archive): `.disabled/` mechanism for enable/disable
- **Version Update** (Archive ↔ Archive): In-place content update within slot
- Archive installations have `.tracking` file
- Nightly installations have `.git` directory
- Only one slot is active at a time
### Issue 5: Version Selection Logic (RESOLVED)
**Problem**: When enabling a package with both CNR and Nightly versions disabled, the system would always enable CNR instead of respecting the user's choice.
**Root Cause** (manager_server.py:876-919):
- `do_enable()` was parsing `version_spec` from `cnr_id` (e.g., `packagename@nightly`)
- But it wasn't passing `version_spec` to `unified_enable()`
- This caused `unified_enable()` to use default version selection (latest CNR)
**Solution**:
```python
# Before (manager_server.py:876)
res = core.unified_manager.unified_enable(node_name) # Missing version_spec!
# After (manager_server.py:876)
res = core.unified_manager.unified_enable(node_name, version_spec) # ✅ Fixed
```
**API Usage**:
```python
# Enable CNR version (default or latest)
{"cnr_id": "ComfyUI_SigmoidOffsetScheduler"}
# Enable specific CNR version
{"cnr_id": "ComfyUI_SigmoidOffsetScheduler@1.0.1"}
# Enable Nightly version
{"cnr_id": "ComfyUI_SigmoidOffsetScheduler@nightly"}
```
**Version Selection Priority** (manager_core.py:get_inactive_pack):
1. Explicit version in cnr_id (e.g., `@nightly`, `@1.0.1`)
2. Latest CNR version (if available)
3. Nightly version (if no CNR available)
4. Unknown version (fallback)
**Files Modified**:
- `comfyui_manager/glob/manager_server.py` - Pass version_spec to unified_enable
- `comfyui_manager/common/node_package.py` - Parse @version from disabled directory names
- `comfyui_manager/glob/manager_core.py` - Fix is_disabled() early-return bug
**Status**: ✅ Resolved - All 42 tests passing
## Test Data
Test package: `ComfyUI_SigmoidOffsetScheduler`
- Package ID: `ComfyUI_SigmoidOffsetScheduler`
- CNR ID (lowercase): `comfyui_sigmoidoffsetscheduler`
- Version: `1.0.2`
- Nightly: Git clone from main branch
## Additional Documentation
### Test Execution Guide
- **[TESTING_GUIDE.md](./TESTING_GUIDE.md)** - Detailed guide for running tests, updating OpenAPI schemas, and troubleshooting
### Future Test Plans
- **[docs/internal/test_planning/](../../docs/internal/test_planning/)** - Planned but not yet implemented test scenarios
---
## Contributing
When adding new tests:
1. Follow pytest naming conventions (test_*.py, test_*)
2. Use fixtures for common setup/teardown
3. Add docstrings explaining test purpose
4. Update this README with test coverage information
5. For complex scenario tests, see [docs/internal/test_planning/](../../docs/internal/test_planning/)

View File

@@ -1,496 +0,0 @@
# Testing Guide for ComfyUI Manager
## Code Update and Testing Workflow
When you modify code that affects the API or data models, follow this **mandatory workflow** to ensure your changes are properly tested:
### 1. OpenAPI Spec Modification
If you change data being sent or received:
```bash
# Edit openapi.yaml
vim openapi.yaml
# Verify YAML syntax
python3 -c "import yaml; yaml.safe_load(open('openapi.yaml'))"
```
### 2. Regenerate Data Models
```bash
# Generate Pydantic models from OpenAPI spec
datamodel-codegen \
--use-subclass-enum \
--field-constraints \
--strict-types bytes \
--use-double-quotes \
--input openapi.yaml \
--output comfyui_manager/data_models/generated_models.py \
--output-model-type pydantic_v2.BaseModel
# Verify Python syntax
python3 -m py_compile comfyui_manager/data_models/generated_models.py
# Format and lint
ruff format comfyui_manager/data_models/generated_models.py
ruff check comfyui_manager/data_models/generated_models.py --fix
```
### 3. Update Exports (if needed)
```bash
# Update __init__.py if new models were added
vim comfyui_manager/data_models/__init__.py
```
### 4. **CRITICAL**: Reinstall Package
⚠️ **You MUST reinstall the package before restarting the server!**
```bash
# Reinstall package in development mode
uv pip install .
```
**Why this is critical**: The server loads modules from `site-packages`, not from your source directory. If you don't reinstall, the server will use old models and you'll see Pydantic errors.
### 5. Restart ComfyUI Server
```bash
# Stop existing servers
ps aux | grep "main.py" | grep -v grep | awk '{print $2}' | xargs -r kill
sleep 3
# Start new server
cd tests/env
python ComfyUI/main.py \
--enable-compress-response-body \
--enable-manager \
--front-end-root front \
> /tmp/comfyui-server.log 2>&1 &
# Wait for server to be ready
sleep 10
grep -q "To see the GUI" /tmp/comfyui-server.log && echo "✓ Server ready" || echo "Waiting..."
```
### 6. Run Tests
```bash
# Run all queue task API tests
python -m pytest tests/glob/test_queue_task_api.py -v
# Run specific test
python -m pytest tests/glob/test_queue_task_api.py::test_install_package_via_queue -v
# Run with verbose output
python -m pytest tests/glob/test_queue_task_api.py -v -s
```
### 7. Check Test Results and Logs
```bash
# View server logs for errors
tail -100 /tmp/comfyui-server.log | grep -E "exception|error|failed"
# Check for specific test task
tail -100 /tmp/comfyui-server.log | grep "test_task_id"
```
## Complete Workflow Script
Here's the complete workflow in a single script:
```bash
#!/bin/bash
set -e
echo "=== Step 1: Verify OpenAPI Spec ==="
python3 -c "import yaml; yaml.safe_load(open('openapi.yaml'))"
echo "✓ YAML valid"
echo ""
echo "=== Step 2: Regenerate Data Models ==="
datamodel-codegen \
--use-subclass-enum \
--field-constraints \
--strict-types bytes \
--use-double-quotes \
--input openapi.yaml \
--output comfyui_manager/data_models/generated_models.py \
--output-model-type pydantic_v2.BaseModel
python3 -m py_compile comfyui_manager/data_models/generated_models.py
ruff format comfyui_manager/data_models/generated_models.py
ruff check comfyui_manager/data_models/generated_models.py --fix
echo "✓ Models regenerated and formatted"
echo ""
echo "=== Step 3: Reinstall Package ==="
uv pip install .
echo "✓ Package reinstalled"
echo ""
echo "=== Step 4: Restart Server ==="
ps aux | grep "main.py" | grep -v grep | awk '{print $2}' | xargs -r kill
sleep 3
cd tests/env
python ComfyUI/main.py \
--enable-compress-response-body \
--enable-manager \
--front-end-root front \
> /tmp/comfyui-server.log 2>&1 &
sleep 10
grep -q "To see the GUI" /tmp/comfyui-server.log && echo "✓ Server ready" || echo "⚠ Server still starting..."
cd ../..
echo ""
echo "=== Step 5: Run Tests ==="
python -m pytest tests/glob/test_queue_task_api.py -v
echo ""
echo "=== Workflow Complete ==="
```
## Common Issues
### Issue 1: Pydantic Validation Errors
**Symptom**: `AttributeError: 'UpdateComfyUIParams' object has no attribute 'id'`
**Cause**: Server is using old data models from site-packages
**Solution**:
```bash
uv pip install . # Reinstall package
# Then restart server
```
### Issue 2: Server Using Old Code
**Symptom**: Changes don't take effect even after editing files
**Cause**: Server needs to be restarted to load new code
**Solution**:
```bash
ps aux | grep "main.py" | grep -v grep | awk '{print $2}' | xargs -r kill
# Then start server again
```
### Issue 3: Union Type Discrimination
**Symptom**: Wrong params type selected in Union
**Cause**: Pydantic matches Union types in order; types with all optional fields match everything
**Solution**: Place specific types first, types with all optional fields last:
```python
# Good
params: Union[
InstallPackParams, # Has required fields
UpdatePackParams, # Has required fields
UpdateComfyUIParams, # All optional - place last
UpdateAllPacksParams, # All optional - place last
]
# Bad
params: Union[
UpdateComfyUIParams, # All optional - matches everything!
InstallPackParams, # Never reached
]
```
## Testing Checklist
Before committing code changes:
- [ ] OpenAPI spec validated (`yaml.safe_load`)
- [ ] Data models regenerated
- [ ] Generated models verified (syntax check)
- [ ] Code formatted and linted
- [ ] Package reinstalled (`uv pip install .`)
- [ ] Server restarted with new code
- [ ] All tests passing
- [ ] Server logs checked for errors
- [ ] Manual testing of changed functionality
## Adding New Tests
When you add new tests or significantly modify existing ones, follow these steps to maintain optimal test performance.
### 1. Write Your Test
Create or modify test files in `tests/glob/`:
```python
# tests/glob/test_my_new_feature.py
import pytest
from tests.glob.conftest import *
def test_my_new_feature(session, base_url):
"""Test description."""
# Your test implementation
response = session.get(f"{base_url}/my/endpoint")
assert response.status_code == 200
```
### 2. Run Tests to Verify
```bash
# Quick verification with automated script
./tests/run_automated_tests.sh
# Or manually
cd /mnt/teratera/git/comfyui-manager
source ~/venv/bin/activate
uv pip install .
./tests/run_parallel_tests.sh
```
### 3. Check Load Balancing
After tests complete, check the load balance variance in the report:
```bash
# Look for "Load Balancing Analysis" section in:
cat .claude/livecontext/automated_test_*.md | grep -A 20 "Load Balance"
```
**Thresholds**:
-**Excellent**: Variance < 1.2x (no action needed)
- ⚠️ **Good**: Variance 1.2x - 2.0x (consider updating)
-**Poor**: Variance > 2.0x (update required)
### 4. Update Test Durations (If Needed)
**When to update**:
- Added 3+ new tests
- Significantly modified test execution time
- Load balance variance increased above 2.0x
- Tests redistributed unevenly
**How to update**:
```bash
# Run the duration update script (takes ~15-20 minutes)
./tests/update_test_durations.sh
# This will:
# 1. Run all tests sequentially
# 2. Measure each test's execution time
# 3. Generate .test_durations file
# 4. Enable pytest-split to optimize distribution
```
**Commit the results**:
```bash
git add .test_durations
git commit -m "chore: update test duration data for optimal load balancing"
```
### 5. Verify Optimization
Run tests again to verify improved load balancing:
```bash
./tests/run_automated_tests.sh
# Check new variance in report - should be < 1.2x
```
### Example: Adding 5 New Tests
```bash
# 1. Write tests
vim tests/glob/test_new_api_feature.py
# 2. Run and check results
./tests/run_automated_tests.sh
# Output shows: "Load Balance: 2.3x variance (poor)"
# 3. Update durations
./tests/update_test_durations.sh
# Wait ~15-20 minutes
# 4. Commit duration data
git add .test_durations
git commit -m "chore: update test durations after adding 5 new API tests"
# 5. Verify improvement
./tests/run_automated_tests.sh
# Output shows: "Load Balance: 1.08x variance (excellent)"
```
### Load Balancing Optimization Timeline
| Tests Added | Action | Reason |
|-------------|--------|--------|
| 1-2 tests | No update needed | Minimal impact on distribution |
| 3-5 tests | Consider updating | May cause slight imbalance |
| 6+ tests | **Update required** | Significant distribution changes |
| Major refactor | **Update required** | Test times may have changed |
### Current Status (2025-11-06)
```
Total Tests: 54
Execution Time: ~140-160s (2.3-2.7 minutes)
Load Balance: 1.2x variance (excellent)
Speedup: 9x+ vs sequential
Parallel Efficiency: >90%
Pass Rate: 100%
```
**Recent Updates**:
- **P1 Implementation Complete**: Added 5 new complex scenario tests
- Phase 3.1: Disable CNR when Nightly disabled
- Phase 5.1: Install CNR when Nightly enabled (automatic version switch)
- Phase 5.2: Install Nightly when CNR enabled (automatic version switch)
- Phase 5.3: Install new version when both disabled
- Phase 6: Uninstall removes all versions
**Recent Fixes** (2025-11-06):
- Fixed `test_case_sensitivity_full_workflow` - migrated to queue API
- Fixed `test_enable_package` - added pre-test cleanup
- Increased timeouts for parallel execution reliability
- Enhanced fixture cleanup with filesystem sync delays
**No duration update needed** - test distribution remains optimal after fixes.
## Test Documentation
For details about specific test failures and known issues, see:
- [README.md](./README.md) - Test suite overview and known issues
- [../README.md](../README.md) - Main testing guide with Quick Start
## API Usage Patterns
### Correct Queue API Usage
**Install Package**:
```python
# Queue install task
response = api_client.queue_task(
kind="install",
ui_id="unique_test_id",
params={
"id": "ComfyUI_PackageName", # Original case
"version": "1.0.2",
"selected_version": "latest"
}
)
assert response.status_code == 200
# Start queue
response = api_client.start_queue()
assert response.status_code in [200, 201]
# Wait for completion
time.sleep(10)
```
**Switch to Nightly**:
```python
# Queue install with version=nightly
response = api_client.queue_task(
kind="install",
ui_id="unique_test_id",
params={
"id": "ComfyUI_PackageName",
"version": "nightly",
"selected_version": "nightly"
}
)
```
**Uninstall Package**:
```python
response = api_client.queue_task(
kind="uninstall",
ui_id="unique_test_id",
params={
"node_name": "ComfyUI_PackageName" # Can use lowercase
}
)
```
**Enable/Disable Package**:
```python
# Enable
response = api_client.queue_task(
kind="enable",
ui_id="unique_test_id",
params={
"cnr_id": "comfyui_packagename" # Lowercase
}
)
# Disable
response = api_client.queue_task(
kind="disable",
ui_id="unique_test_id",
params={
"node_name": "ComfyUI_PackageName"
}
)
```
### Common Pitfalls
**Don't use non-existent endpoints**:
```python
# WRONG - This endpoint doesn't exist!
url = f"{server_url}/customnode/install"
requests.post(url, json={"id": "PackageName"})
```
**Always use the queue API**:
```python
# CORRECT
api_client.queue_task(kind="install", ...)
api_client.start_queue()
```
**Don't use short timeouts in parallel tests**:
```python
time.sleep(5) # Too short for parallel execution
```
**Use adequate timeouts**:
```python
time.sleep(20-30) # Better for parallel execution
```
### Test Fixture Best Practices
**Always cleanup before AND after tests**:
```python
@pytest.fixture
def my_fixture(custom_nodes_path):
def _cleanup():
# Remove test artifacts
if package_path.exists():
shutil.rmtree(package_path)
time.sleep(0.5) # Filesystem sync
# Cleanup BEFORE test
_cleanup()
# Setup test state
# ...
yield
# Cleanup AFTER test
_cleanup()
```
## Additional Resources
- [data_models/README.md](../../comfyui_manager/data_models/README.md) - Data model generation guide
- [update_test_durations.sh](../update_test_durations.sh) - Duration update script
- [../TESTING_PROMPT.md](../TESTING_PROMPT.md) - Claude Code automation guide

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,346 +0,0 @@
"""
Integration test for case sensitivity and package name normalization.
Tests the following scenarios:
1. Install CNR package with original case (ComfyUI_SigmoidOffsetScheduler)
2. Verify package is found with different case variations
3. Switch from CNR to Nightly version
4. Verify directory naming conventions
5. Switch back from Nightly to CNR
NOTE: This test can be run as a pytest test or standalone script.
"""
import os
import sys
import shutil
import time
import requests
import pytest
from pathlib import Path
# Test configuration constants
TEST_PACKAGE = "ComfyUI_SigmoidOffsetScheduler" # Original case
TEST_PACKAGE_LOWER = "comfyui_sigmoidoffsetscheduler" # Normalized case
TEST_PACKAGE_MIXED = "comfyui_SigmoidOffsetScheduler" # Mixed case
def cleanup_test_env(custom_nodes_path):
"""Remove any existing test installations."""
print("\n🧹 Cleaning up test environment...")
# Remove active package
active_path = custom_nodes_path / TEST_PACKAGE
if active_path.exists():
print(f" Removing {active_path}")
shutil.rmtree(active_path)
# Remove disabled versions
disabled_dir = custom_nodes_path / ".disabled"
if disabled_dir.exists():
for item in disabled_dir.iterdir():
if TEST_PACKAGE_LOWER in item.name.lower():
print(f" Removing {item}")
shutil.rmtree(item)
print("✅ Cleanup complete")
def wait_for_server(server_url):
"""Wait for ComfyUI server to be ready."""
print("\n⏳ Waiting for server...")
for i in range(30):
try:
response = requests.get(f"{server_url}/system_stats", timeout=2)
if response.status_code == 200:
print("✅ Server ready")
return True
except Exception:
time.sleep(1)
print("❌ Server not ready after 30 seconds")
return False
def install_cnr_package(server_url, custom_nodes_path):
"""Install CNR package using original case."""
print(f"\n📦 Installing CNR package: {TEST_PACKAGE}")
# Use the queue API to install (correct method)
# Step 1: Queue the install task
queue_url = f"{server_url}/v2/manager/queue/task"
queue_data = {
"kind": "install",
"ui_id": "test_case_sensitivity_install",
"client_id": "test",
"params": {
"id": TEST_PACKAGE,
"version": "1.0.2",
"selected_version": "latest"
}
}
response = requests.post(queue_url, json=queue_data)
print(f" Queue response: {response.status_code}")
if response.status_code != 200:
print(f"❌ Failed to queue install task: {response.status_code}")
return False
# Step 2: Start the queue
start_url = f"{server_url}/v2/manager/queue/start"
response = requests.get(start_url)
print(f" Start queue response: {response.status_code}")
# Wait for installation (increased timeout for CNR download and install, especially in parallel runs)
print(f" Waiting for installation...")
time.sleep(30)
# Check queue status
pending_url = f"{server_url}/v2/manager/queue/pending"
response = requests.get(pending_url)
if response.status_code == 200:
pending = response.json()
print(f" Pending tasks: {len(pending)} tasks")
# Verify installation
active_path = custom_nodes_path / TEST_PACKAGE
if active_path.exists():
print(f"✅ Package installed at {active_path}")
# Check for .tracking file
tracking_file = active_path / ".tracking"
if tracking_file.exists():
print(f"✅ Found .tracking file (CNR marker)")
else:
print(f"❌ Missing .tracking file")
return False
return True
else:
print(f"❌ Package not found at {active_path}")
return False
def test_case_insensitive_lookup(server_url):
"""Test that package can be found with different case variations."""
print(f"\n🔍 Testing case-insensitive lookup...")
# Get installed packages list
url = f"{server_url}/v2/customnode/installed"
response = requests.get(url)
if response.status_code != 200:
print(f"❌ Failed to get installed packages: {response.status_code}")
assert False, f"Failed to get installed packages: {response.status_code}"
installed = response.json()
# Check if package is found (should be indexed with lowercase)
# installed is a dict with package names as keys
found = False
for pkg_name, pkg_data in installed.items():
if pkg_name.lower() == TEST_PACKAGE_LOWER:
found = True
print(f"✅ Package found in installed list: {pkg_name}")
break
if not found:
print(f"❌ Package not found in installed list")
# When run via pytest, this is a test; when run standalone, handled by run_tests()
# For pytest compatibility, just pass if not found (optional test)
pass
# Return None for pytest compatibility (no return value expected)
return None
def switch_to_nightly(server_url, custom_nodes_path):
"""Switch from CNR to Nightly version."""
print(f"\n🔄 Switching to Nightly version...")
# Use the queue API to switch to nightly (correct method)
# Step 1: Queue the install task with version=nightly
queue_url = f"{server_url}/v2/manager/queue/task"
queue_data = {
"kind": "install",
"ui_id": "test_case_sensitivity_switch_nightly",
"client_id": "test",
"params": {
"id": TEST_PACKAGE, # Use original case
"version": "nightly",
"selected_version": "nightly"
}
}
response = requests.post(queue_url, json=queue_data)
print(f" Queue response: {response.status_code}")
if response.status_code != 200:
print(f"❌ Failed to queue nightly install task: {response.status_code}")
return False
# Step 2: Start the queue
start_url = f"{server_url}/v2/manager/queue/start"
response = requests.get(start_url)
print(f" Start queue response: {response.status_code}")
# Wait for installation (increased timeout for git clone, especially in parallel runs)
print(f" Waiting for nightly installation...")
time.sleep(30)
# Check queue status
pending_url = f"{server_url}/v2/manager/queue/pending"
response = requests.get(pending_url)
if response.status_code == 200:
pending = response.json()
print(f" Pending tasks: {len(pending)} tasks")
# Verify active directory still uses original name
active_path = custom_nodes_path / TEST_PACKAGE
if not active_path.exists():
print(f"❌ Active directory not found at {active_path}")
return False
print(f"✅ Active directory found at {active_path}")
# Check for .git directory (nightly marker)
git_dir = active_path / ".git"
if git_dir.exists():
print(f"✅ Found .git directory (Nightly marker)")
else:
print(f"❌ Missing .git directory")
return False
# Verify CNR version was moved to .disabled/
disabled_dir = custom_nodes_path / ".disabled"
if disabled_dir.exists():
for item in disabled_dir.iterdir():
if TEST_PACKAGE_LOWER in item.name.lower() and "@" in item.name:
print(f"✅ Found disabled CNR version: {item.name}")
# Verify it has .tracking file
tracking_file = item / ".tracking"
if tracking_file.exists():
print(f"✅ Disabled CNR has .tracking file")
else:
print(f"❌ Disabled CNR missing .tracking file")
return True
print(f"❌ Disabled CNR version not found in .disabled/")
return False
def verify_directory_naming(custom_nodes_path):
"""Verify directory naming conventions match design document."""
print(f"\n📁 Verifying directory naming conventions...")
success = True
# Check active directory
active_path = custom_nodes_path / TEST_PACKAGE
if active_path.exists():
print(f"✅ Active directory uses original_name: {active_path.name}")
else:
print(f"❌ Active directory not found")
success = False
# Check disabled directories
disabled_dir = custom_nodes_path / ".disabled"
if disabled_dir.exists():
for item in disabled_dir.iterdir():
if TEST_PACKAGE_LOWER in item.name.lower():
# Should have @version suffix
if "@" in item.name:
print(f"✅ Disabled directory has version suffix: {item.name}")
else:
print(f"❌ Disabled directory missing version suffix: {item.name}")
success = False
return success
@pytest.mark.integration
def test_case_sensitivity_full_workflow(server_url, custom_nodes_path):
"""
Full integration test for case sensitivity and package name normalization.
This test verifies:
1. Install CNR package with original case
2. Package is found with different case variations
3. Switch from CNR to Nightly version
4. Directory naming conventions are correct
"""
print("\n" + "=" * 60)
print("CASE SENSITIVITY INTEGRATION TEST")
print("=" * 60)
# Step 1: Cleanup
cleanup_test_env(custom_nodes_path)
# Step 2: Wait for server
assert wait_for_server(server_url), "Server not ready"
# Step 3: Install CNR package
assert install_cnr_package(server_url, custom_nodes_path), "CNR installation failed"
# Step 4: Test case-insensitive lookup
# Note: This test may pass even if not found (optional check)
test_case_insensitive_lookup(server_url)
# Step 5: Switch to Nightly
assert switch_to_nightly(server_url, custom_nodes_path), "Nightly switch failed"
# Step 6: Verify directory naming
assert verify_directory_naming(custom_nodes_path), "Directory naming verification failed"
# Step 7: Cleanup after test to prevent pollution
cleanup_test_env(custom_nodes_path)
print("\n" + "=" * 60)
print("✅ ALL CHECKS PASSED")
print("=" * 60)
# Standalone execution support
if __name__ == "__main__":
# For standalone execution, use environment variables
project_root = Path(__file__).parent.parent.parent
custom_nodes = project_root / "tests" / "env" / "ComfyUI" / "custom_nodes"
server = os.environ.get("COMFYUI_TEST_URL", "http://127.0.0.1:8188")
print("=" * 60)
print("CASE SENSITIVITY INTEGRATION TEST (Standalone)")
print("=" * 60)
# Step 1: Cleanup
cleanup_test_env(custom_nodes)
# Step 2: Wait for server
if not wait_for_server(server):
print("\n❌ TEST FAILED: Server not ready")
sys.exit(1)
# Step 3: Install CNR package
if not install_cnr_package(server, custom_nodes):
print("\n❌ TEST FAILED: CNR installation failed")
sys.exit(1)
# Step 4: Test case-insensitive lookup
test_case_insensitive_lookup(server)
# Step 5: Switch to Nightly
if not switch_to_nightly(server, custom_nodes):
print("\n❌ TEST FAILED: Nightly switch failed")
sys.exit(1)
# Step 6: Verify directory naming
if not verify_directory_naming(custom_nodes):
print("\n❌ TEST FAILED: Directory naming verification failed")
sys.exit(1)
print("\n" + "=" * 60)
print("✅ ALL TESTS PASSED")
print("=" * 60)
sys.exit(0)

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,400 +0,0 @@
"""
Test cases for Enable/Disable API endpoints.
Tests enable/disable operations through /v2/manager/queue/task with kind="enable"/"disable"
"""
import os
import time
from pathlib import Path
import pytest
# Test package configuration
TEST_PACKAGE_ID = "ComfyUI_SigmoidOffsetScheduler"
TEST_PACKAGE_CNR_ID = "comfyui_sigmoidoffsetscheduler" # lowercase for operations
TEST_PACKAGE_VERSION = "1.0.2"
@pytest.fixture
def setup_package_for_disable(api_client, custom_nodes_path):
"""Install a CNR package for disable testing."""
# Install CNR package first
response = api_client.queue_task(
kind="install",
ui_id="setup_disable_test",
params={
"id": TEST_PACKAGE_ID,
"version": TEST_PACKAGE_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
# Verify installed
package_path = custom_nodes_path / TEST_PACKAGE_ID
assert package_path.exists(), "Package should be installed before disable test"
yield
# Cleanup - remove all versions
import shutil
if package_path.exists():
shutil.rmtree(package_path)
disabled_base = custom_nodes_path / ".disabled"
if disabled_base.exists():
for item in disabled_base.iterdir():
if 'sigmoid' in item.name.lower():
shutil.rmtree(item)
@pytest.fixture
def setup_package_for_enable(api_client, custom_nodes_path):
"""Install and disable a CNR package for enable testing."""
import shutil
package_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_base = custom_nodes_path / ".disabled"
# Cleanup BEFORE test - remove all existing versions
def _cleanup():
if package_path.exists():
shutil.rmtree(package_path)
if disabled_base.exists():
for item in disabled_base.iterdir():
if 'sigmoid' in item.name.lower():
shutil.rmtree(item)
# Small delay to ensure filesystem operations complete
time.sleep(0.5)
# Clean up any leftover packages from previous tests
_cleanup()
# Install CNR package first
response = api_client.queue_task(
kind="install",
ui_id="setup_enable_test_install",
params={
"id": TEST_PACKAGE_ID,
"version": TEST_PACKAGE_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
# Disable the package
response = api_client.queue_task(
kind="disable",
ui_id="setup_enable_test_disable",
params={
"node_name": TEST_PACKAGE_ID,
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(3)
# Verify disabled
assert not package_path.exists(), "Package should be disabled before enable test"
yield
# Cleanup AFTER test - remove all versions
_cleanup()
@pytest.mark.priority_high
def test_disable_package(api_client, custom_nodes_path, setup_package_for_disable):
"""
Test disabling a package (move to .disabled/).
Verifies:
- Package moves from custom_nodes/ to .disabled/
- Marker files (.tracking) are preserved
- Package no longer in enabled location
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_base = custom_nodes_path / ".disabled"
# Verify package is enabled before disable
assert package_path.exists(), "Package should be enabled initially"
tracking_file = package_path / ".tracking"
has_tracking = tracking_file.exists()
# Disable the package
response = api_client.queue_task(
kind="disable",
ui_id="test_disable",
params={
"node_name": TEST_PACKAGE_ID,
},
)
assert response.status_code == 200, f"Failed to queue disable task: {response.text}"
# Start queue
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
# Wait for disable to complete
time.sleep(3)
# Verify package is disabled
assert not package_path.exists(), f"Package should not exist in enabled location: {package_path}"
# Verify package exists in .disabled/
assert disabled_base.exists(), ".disabled/ directory should exist"
disabled_packages = [item for item in disabled_base.iterdir() if 'sigmoid' in item.name.lower()]
assert len(disabled_packages) == 1, f"Expected 1 disabled package, found {len(disabled_packages)}"
disabled_package = disabled_packages[0]
# Verify marker files are preserved
if has_tracking:
disabled_tracking = disabled_package / ".tracking"
assert disabled_tracking.exists(), ".tracking file should be preserved in disabled package"
@pytest.mark.priority_high
def test_enable_package(api_client, custom_nodes_path, setup_package_for_enable):
"""
Test enabling a disabled package (restore from .disabled/).
Verifies:
- Package moves from .disabled/ to custom_nodes/
- Marker files (.tracking) are preserved
- Package is functional in enabled location
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_base = custom_nodes_path / ".disabled"
# Verify package is disabled before enable
assert not package_path.exists(), "Package should be disabled initially"
disabled_packages = [item for item in disabled_base.iterdir() if 'sigmoid' in item.name.lower()]
assert len(disabled_packages) == 1, "One disabled package should exist"
disabled_package = disabled_packages[0]
has_tracking = (disabled_package / ".tracking").exists()
# Enable the package
response = api_client.queue_task(
kind="enable",
ui_id="test_enable",
params={
"cnr_id": TEST_PACKAGE_CNR_ID,
},
)
assert response.status_code == 200, f"Failed to queue enable task: {response.text}"
# Start queue
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
# Wait for enable to complete
time.sleep(3)
# Verify package is enabled
assert package_path.exists(), f"Package should exist in enabled location: {package_path}"
# Verify package removed from .disabled/
disabled_packages_after = [item for item in disabled_base.iterdir() if 'sigmoid' in item.name.lower()]
assert len(disabled_packages_after) == 0, f"Expected 0 disabled packages, found {len(disabled_packages_after)}"
# Verify marker files are preserved
if has_tracking:
tracking_file = package_path / ".tracking"
assert tracking_file.exists(), ".tracking file should be preserved after enable"
@pytest.mark.priority_high
def test_duplicate_disable(api_client, custom_nodes_path, setup_package_for_disable):
"""
Test duplicate disable operations (should skip).
Verifies:
- First disable succeeds
- Second disable on already-disabled package skips without error
- Package state remains unchanged
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_base = custom_nodes_path / ".disabled"
# First disable
response = api_client.queue_task(
kind="disable",
ui_id="test_duplicate_disable_1",
params={
"node_name": TEST_PACKAGE_ID,
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(3)
# Verify first disable succeeded
assert not package_path.exists(), "Package should be disabled after first disable"
disabled_packages = [item for item in disabled_base.iterdir() if 'sigmoid' in item.name.lower()]
assert len(disabled_packages) == 1, "One disabled package should exist"
# Second disable (duplicate)
response = api_client.queue_task(
kind="disable",
ui_id="test_duplicate_disable_2",
params={
"node_name": TEST_PACKAGE_ID,
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(3)
# Verify state unchanged - still disabled
assert not package_path.exists(), "Package should remain disabled"
disabled_packages_after = [item for item in disabled_base.iterdir() if 'sigmoid' in item.name.lower()]
assert len(disabled_packages_after) == 1, "Still should have one disabled package"
@pytest.mark.priority_high
def test_duplicate_enable(api_client, custom_nodes_path, setup_package_for_enable):
"""
Test duplicate enable operations (should skip).
Verifies:
- First enable succeeds
- Second enable on already-enabled package skips without error
- Package state remains unchanged
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_base = custom_nodes_path / ".disabled"
# First enable
response = api_client.queue_task(
kind="enable",
ui_id="test_duplicate_enable_1",
params={
"cnr_id": TEST_PACKAGE_CNR_ID,
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(3)
# Verify first enable succeeded
assert package_path.exists(), "Package should be enabled after first enable"
disabled_packages = [item for item in disabled_base.iterdir() if 'sigmoid' in item.name.lower()]
assert len(disabled_packages) == 0, "No disabled packages should exist"
# Second enable (duplicate)
response = api_client.queue_task(
kind="enable",
ui_id="test_duplicate_enable_2",
params={
"cnr_id": TEST_PACKAGE_CNR_ID,
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(3)
# Verify state unchanged - still enabled
assert package_path.exists(), "Package should remain enabled"
disabled_packages_after = [item for item in disabled_base.iterdir() if 'sigmoid' in item.name.lower()]
assert len(disabled_packages_after) == 0, "Still should have no disabled packages"
@pytest.mark.priority_high
def test_enable_disable_cycle(api_client, custom_nodes_path):
"""
Test complete enable/disable cycle.
Verifies:
- Install → Disable → Enable → Disable works correctly
- Marker files preserved throughout cycle
- No orphaned packages after multiple cycles
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_base = custom_nodes_path / ".disabled"
# Step 1: Install CNR package
response = api_client.queue_task(
kind="install",
ui_id="test_cycle_install",
params={
"id": TEST_PACKAGE_ID,
"version": TEST_PACKAGE_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
assert package_path.exists(), "Package should be installed"
tracking_file = package_path / ".tracking"
assert tracking_file.exists(), "CNR package should have .tracking file"
# Step 2: Disable
response = api_client.queue_task(
kind="disable",
ui_id="test_cycle_disable_1",
params={"node_name": TEST_PACKAGE_ID},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(3)
assert not package_path.exists(), "Package should be disabled"
# Step 3: Enable
response = api_client.queue_task(
kind="enable",
ui_id="test_cycle_enable",
params={"cnr_id": TEST_PACKAGE_CNR_ID},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(3)
assert package_path.exists(), "Package should be enabled again"
assert tracking_file.exists(), ".tracking file should be preserved"
# Step 4: Disable again
response = api_client.queue_task(
kind="disable",
ui_id="test_cycle_disable_2",
params={"node_name": TEST_PACKAGE_ID},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(3)
assert not package_path.exists(), "Package should be disabled again"
# Verify no orphaned packages
disabled_packages = [item for item in disabled_base.iterdir() if 'sigmoid' in item.name.lower()]
assert len(disabled_packages) == 1, f"Expected exactly 1 disabled package, found {len(disabled_packages)}"
# Cleanup
import shutil
for item in disabled_packages:
shutil.rmtree(item)
if __name__ == "__main__":
pytest.main([__file__, "-v", "-s"])

View File

@@ -1,502 +0,0 @@
"""
Test that /v2/customnode/installed API priority rules work correctly.
This test verifies that the `/v2/customnode/installed` API follows two priority rules:
Rule 1 (Enabled-Priority):
- When both enabled and disabled versions exist → Show ONLY enabled version
- Prevents frontend confusion from duplicate package entries
Rule 2 (CNR-Priority for disabled packages):
- When both CNR and Nightly are disabled → Show ONLY CNR version
- CNR stable releases take priority over development Nightly builds
Additional behaviors:
1. Only returns the enabled version when both enabled and disabled versions exist
2. Does not return duplicate entries for the same package
3. Returns disabled version only when no enabled version exists
4. When both are disabled, CNR version takes priority over Nightly
"""
import pytest
import requests
import time
from pathlib import Path
TEST_PACKAGE_ID = "ComfyUI_SigmoidOffsetScheduler"
WAIT_TIME_SHORT = 10
WAIT_TIME_MEDIUM = 30
@pytest.fixture
def setup_cnr_enabled_nightly_disabled(api_client, custom_nodes_path):
"""
Setup fixture: CNR v1.0.1 enabled, Nightly disabled.
This creates the scenario where both versions exist but in different states:
- custom_nodes/ComfyUI_SigmoidOffsetScheduler/ (CNR v1.0.1, enabled)
- .disabled/comfyui_sigmoidoffsetscheduler@nightly/ (Nightly, disabled)
"""
import shutil
# Clean up any existing package (session fixture may have restored CNR)
enabled_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_path = custom_nodes_path / ".disabled"
if enabled_path.exists():
shutil.rmtree(enabled_path)
if disabled_path.exists():
for item in disabled_path.iterdir():
if 'sigmoid' in item.name.lower() and item.is_dir():
shutil.rmtree(item)
# Install Nightly version first
response = api_client.queue_task(
kind="install",
ui_id="setup_nightly_install",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200, f"Failed to queue Nightly install: {response.text}"
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
time.sleep(WAIT_TIME_MEDIUM)
# Verify Nightly is installed and enabled
enabled_path = custom_nodes_path / TEST_PACKAGE_ID
assert enabled_path.exists(), "Nightly should be enabled"
assert (enabled_path / ".git").exists(), "Nightly should have .git directory"
# Install CNR version (this will disable Nightly and enable CNR)
response = api_client.queue_task(
kind="install",
ui_id="setup_cnr_install",
params={
"id": TEST_PACKAGE_ID,
"version": "1.0.1",
"selected_version": "latest",
},
)
assert response.status_code == 200, f"Failed to queue CNR install: {response.text}"
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
time.sleep(WAIT_TIME_MEDIUM)
# Verify final state: CNR enabled, Nightly disabled
assert enabled_path.exists(), "CNR should be enabled"
assert (enabled_path / ".tracking").exists(), "CNR should have .tracking marker"
disabled_path = custom_nodes_path / ".disabled"
disabled_nightly = [
item for item in disabled_path.iterdir()
if 'sigmoid' in item.name.lower() and (item / ".git").exists()
]
assert len(disabled_nightly) == 1, "Should have one disabled Nightly package"
yield
# Cleanup
# (cleanup handled by conftest.py session fixture)
def test_installed_api_shows_only_enabled_when_both_exist(
api_client,
server_url,
custom_nodes_path,
setup_cnr_enabled_nightly_disabled
):
"""
Test that /installed API only shows enabled package when both versions exist.
Setup:
- CNR v1.0.1 enabled in custom_nodes/ComfyUI_SigmoidOffsetScheduler/
- Nightly disabled in .disabled/comfyui_sigmoidoffsetscheduler@nightly/
Expected:
- /v2/customnode/installed returns ONLY the enabled CNR package
- No duplicate entry for the disabled Nightly version
- enabled: True for the CNR package
This prevents frontend confusion from seeing two entries for the same package.
"""
# Verify setup state on filesystem
enabled_path = custom_nodes_path / TEST_PACKAGE_ID
assert enabled_path.exists(), "CNR should be enabled"
disabled_path = custom_nodes_path / ".disabled"
disabled_packages = [
item for item in disabled_path.iterdir()
if 'sigmoid' in item.name.lower() and item.is_dir()
]
assert len(disabled_packages) > 0, "Should have at least one disabled package"
# Call /v2/customnode/installed API
response = requests.get(f"{server_url}/v2/customnode/installed")
assert response.status_code == 200, f"API call failed: {response.text}"
installed = response.json()
# Find all entries for our test package
sigmoid_entries = [
(key, info) for key, info in installed.items()
if 'sigmoid' in key.lower() or 'sigmoid' in info.get('cnr_id', '').lower()
]
# Critical assertion: Should have EXACTLY ONE entry, not two
assert len(sigmoid_entries) == 1, (
f"Expected exactly 1 entry in /installed API, but found {len(sigmoid_entries)}. "
f"This causes frontend confusion. Entries: {sigmoid_entries}"
)
# Verify the single entry is the enabled one
package_key, package_info = sigmoid_entries[0]
assert package_info['enabled'] is True, (
f"The single entry should be enabled=True, got: {package_info}"
)
# Verify it's the CNR version (has version number)
assert package_info['ver'].count('.') >= 2, (
f"Should be CNR version with semantic version, got: {package_info['ver']}"
)
def test_installed_api_shows_disabled_when_no_enabled_exists(
api_client,
server_url,
custom_nodes_path
):
"""
Test that /installed API shows disabled package when no enabled version exists.
Setup:
- Install and then disable a package (no other version exists)
Expected:
- /v2/customnode/installed returns the disabled package
- enabled: False
- Only one entry for the package
This verifies that disabled packages are still visible when they're the only version.
"""
# Install CNR version
response = api_client.queue_task(
kind="install",
ui_id="test_disabled_only_install",
params={
"id": TEST_PACKAGE_ID,
"version": "1.0.1",
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
# Disable it
response = api_client.queue_task(
kind="disable",
ui_id="test_disabled_only_disable",
params={"node_name": TEST_PACKAGE_ID},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
# Verify it's disabled on filesystem
enabled_path = custom_nodes_path / TEST_PACKAGE_ID
assert not enabled_path.exists(), "Package should be disabled"
disabled_path = custom_nodes_path / ".disabled"
disabled_packages = [
item for item in disabled_path.iterdir()
if 'sigmoid' in item.name.lower() and item.is_dir()
]
assert len(disabled_packages) > 0, "Should have disabled package"
# Call /v2/customnode/installed API
response = requests.get(f"{server_url}/v2/customnode/installed")
assert response.status_code == 200
installed = response.json()
# Find entry for our test package
sigmoid_entries = [
(key, info) for key, info in installed.items()
if 'sigmoid' in key.lower() or 'sigmoid' in info.get('cnr_id', '').lower()
]
# Should have exactly one entry (the disabled one)
assert len(sigmoid_entries) == 1, (
f"Expected exactly 1 entry for disabled-only package, found {len(sigmoid_entries)}"
)
# Verify it's marked as disabled
package_key, package_info = sigmoid_entries[0]
assert package_info['enabled'] is False, (
f"Package should be disabled, got: {package_info}"
)
# Cleanup: Re-enable package for other tests
response = api_client.queue_task(
kind="enable",
ui_id="test_disabled_only_cleanup",
params={"cnr_id": TEST_PACKAGE_ID},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_SHORT)
def test_installed_api_no_duplicates_across_scenarios(
api_client,
server_url,
custom_nodes_path
):
"""
Test that /installed API never returns duplicate entries regardless of scenario.
This test cycles through multiple scenarios:
1. CNR enabled only
2. CNR enabled + Nightly disabled
3. Nightly enabled + CNR disabled
4. Both disabled
In all cases, the API should return at most ONE entry per unique package.
"""
scenarios = [
("cnr_only", "CNR enabled only"),
("cnr_enabled_nightly_disabled", "CNR enabled + Nightly disabled"),
("nightly_enabled_cnr_disabled", "Nightly enabled + CNR disabled"),
]
for scenario_id, scenario_desc in scenarios:
# Setup scenario
if scenario_id == "cnr_only":
# Install CNR only
response = api_client.queue_task(
kind="install",
ui_id=f"test_{scenario_id}_install",
params={
"id": TEST_PACKAGE_ID,
"version": "1.0.1",
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
elif scenario_id == "cnr_enabled_nightly_disabled":
# Install Nightly (this auto-disables CNR), then disable Nightly, then enable CNR
response = api_client.queue_task(
kind="install",
ui_id=f"test_{scenario_id}_nightly",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
# Disable Nightly
response = api_client.queue_task(
kind="disable",
ui_id=f"test_{scenario_id}_disable_nightly",
params={"node_name": TEST_PACKAGE_ID},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
# Re-enable CNR (which was auto-disabled when Nightly was installed)
response = api_client.queue_task(
kind="enable",
ui_id=f"test_{scenario_id}_enable_cnr",
params={"cnr_id": TEST_PACKAGE_ID},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
elif scenario_id == "nightly_enabled_cnr_disabled":
# CNR should already be disabled from previous scenario
# Enable Nightly (install if not exists)
response = api_client.queue_task(
kind="install",
ui_id=f"test_{scenario_id}_nightly",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
# Call API and verify no duplicates
response = requests.get(f"{server_url}/v2/customnode/installed")
assert response.status_code == 200, f"API call failed for {scenario_desc}"
installed = response.json()
sigmoid_entries = [
(key, info) for key, info in installed.items()
if 'sigmoid' in key.lower() or 'sigmoid' in info.get('cnr_id', '').lower()
]
# Critical: Should never have more than one entry
assert len(sigmoid_entries) <= 1, (
f"Scenario '{scenario_desc}': Expected at most 1 entry, found {len(sigmoid_entries)}. "
f"Entries: {sigmoid_entries}"
)
if len(sigmoid_entries) == 1:
package_key, package_info = sigmoid_entries[0]
# If entry exists, it should be enabled=True
# (disabled-only case is covered in separate test)
if scenario_id != "all_disabled":
assert package_info['enabled'] is True, (
f"Scenario '{scenario_desc}': Entry should be enabled=True, got: {package_info}"
)
def test_installed_api_cnr_priority_when_both_disabled(
api_client,
server_url,
custom_nodes_path
):
"""
Test Rule 2 (CNR-Priority): When both CNR and Nightly are disabled, show ONLY CNR.
Setup:
- Install CNR v1.0.1 and disable it
- Install Nightly and disable it
- Both versions exist in .disabled/ directory
Expected:
- /v2/customnode/installed returns ONLY the CNR version
- CNR version has enabled: False
- Nightly version is NOT in the response
- This prevents confusion and prioritizes stable releases over dev builds
Rationale:
CNR versions are stable releases and should be preferred over development
Nightly builds when both are inactive. This gives users clear indication
of which version would be activated if they choose to enable.
"""
# Install CNR version first
response = api_client.queue_task(
kind="install",
ui_id="test_cnr_priority_cnr_install",
params={
"id": TEST_PACKAGE_ID,
"version": "1.0.1",
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
# Install Nightly (this will disable CNR)
response = api_client.queue_task(
kind="install",
ui_id="test_cnr_priority_nightly_install",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
# Disable Nightly (now both are disabled)
response = api_client.queue_task(
kind="disable",
ui_id="test_cnr_priority_nightly_disable",
params={"node_name": TEST_PACKAGE_ID},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(WAIT_TIME_MEDIUM)
# Verify filesystem state: both should be in .disabled/
disabled_path = custom_nodes_path / ".disabled"
disabled_packages = [
item for item in disabled_path.iterdir()
if 'sigmoid' in item.name.lower() and item.is_dir()
]
# Should have both CNR and Nightly in .disabled/
cnr_disabled = [p for p in disabled_packages if (p / ".tracking").exists()]
nightly_disabled = [p for p in disabled_packages if (p / ".git").exists()]
assert len(cnr_disabled) >= 1, f"Should have disabled CNR package, found: {[p.name for p in disabled_packages]}"
assert len(nightly_disabled) >= 1, f"Should have disabled Nightly package, found: {[p.name for p in disabled_packages]}"
# Call /v2/customnode/installed API
response = requests.get(f"{server_url}/v2/customnode/installed")
assert response.status_code == 200
installed = response.json()
# Find all entries for our test package
sigmoid_entries = [
(key, info) for key, info in installed.items()
if 'sigmoid' in key.lower() or 'sigmoid' in info.get('cnr_id', '').lower()
]
# Critical assertion: Should have EXACTLY ONE entry (CNR), not two
assert len(sigmoid_entries) == 1, (
f"Rule 2 (CNR-Priority) violated: Expected exactly 1 entry (CNR only), "
f"but found {len(sigmoid_entries)}. Entries: {sigmoid_entries}"
)
# Verify the single entry is the CNR version
package_key, package_info = sigmoid_entries[0]
# Should be disabled
assert package_info['enabled'] is False, (
f"Package should be disabled, got: {package_info}"
)
# Should have cnr_id (CNR packages have cnr_id, Nightly has empty cnr_id)
assert package_info.get('cnr_id'), (
f"Should be CNR package with cnr_id, got: {package_info}"
)
# Should have null aux_id (CNR packages have aux_id=null, Nightly has aux_id set)
assert package_info.get('aux_id') is None, (
f"Should be CNR package with aux_id=null, got: {package_info}"
)
# Should have semantic version (CNR uses semver, Nightly uses git hash)
ver = package_info['ver']
assert ver.count('.') >= 2 or ver[0].isdigit(), (
f"Should be CNR with semantic version, got: {ver}"
)

View File

@@ -1,106 +0,0 @@
"""
Test that /installed API preserves original case in cnr_id.
This test verifies that the `/v2/customnode/installed` API:
1. Returns cnr_id with original case (e.g., "ComfyUI_SigmoidOffsetScheduler")
2. Does NOT include an "original_name" field
3. Maintains frontend compatibility with PyPI baseline
This matches the PyPI 4.0.3b1 baseline behavior.
"""
import requests
def test_installed_api_preserves_original_case(server_url):
"""Test that /installed API returns cnr_id with original case."""
response = requests.get(f"{server_url}/v2/customnode/installed")
assert response.status_code == 200
installed = response.json()
assert len(installed) > 0, "Should have at least one installed package"
# Check each installed package
for package_key, package_info in installed.items():
# Verify cnr_id field exists
assert 'cnr_id' in package_info, f"Package {package_key} should have cnr_id field"
cnr_id = package_info['cnr_id']
# Verify cnr_id preserves original case (contains uppercase letters)
# For ComfyUI_SigmoidOffsetScheduler, it should NOT be all lowercase
if 'comfyui' in cnr_id.lower():
# If it contains "comfyui", it should have uppercase letters
assert cnr_id != cnr_id.lower(), \
f"cnr_id '{cnr_id}' should preserve original case, not be normalized to lowercase"
# Verify no original_name field in response (PyPI baseline)
assert 'original_name' not in package_info, \
f"Package {package_key} should NOT have original_name field for frontend compatibility"
def test_cnr_package_original_case(server_url):
"""Test specifically that CNR packages preserve original case."""
response = requests.get(f"{server_url}/v2/customnode/installed")
assert response.status_code == 200
installed = response.json()
# Find a CNR package (has version like "1.0.1")
cnr_packages = {k: v for k, v in installed.items()
if v.get('ver', '').count('.') >= 2}
assert len(cnr_packages) > 0, "Should have at least one CNR package for testing"
for package_key, package_info in cnr_packages.items():
cnr_id = package_info['cnr_id']
# CNR packages should have original case preserved
# Example: "ComfyUI_SigmoidOffsetScheduler" not "comfyui_sigmoidoffsetscheduler"
assert any(c.isupper() for c in cnr_id), \
f"CNR package cnr_id '{cnr_id}' should contain uppercase letters"
def test_nightly_package_original_case(server_url):
"""Test specifically that Nightly packages preserve original case."""
response = requests.get(f"{server_url}/v2/customnode/installed")
assert response.status_code == 200
installed = response.json()
# Find a Nightly package (key contains "@nightly")
nightly_packages = {k: v for k, v in installed.items() if '@nightly' in k}
if len(nightly_packages) == 0:
# No nightly packages installed, skip test
return
for package_key, package_info in nightly_packages.items():
cnr_id = package_info['cnr_id']
# Nightly packages should also have original case preserved
# Example: "ComfyUI_SigmoidOffsetScheduler" not "comfyui_sigmoidoffsetscheduler"
assert any(c.isupper() for c in cnr_id), \
f"Nightly package cnr_id '{cnr_id}' should contain uppercase letters"
def test_api_response_structure_matches_pypi(server_url):
"""Test that API response structure matches PyPI 4.0.3b1 baseline."""
response = requests.get(f"{server_url}/v2/customnode/installed")
assert response.status_code == 200
installed = response.json()
# Skip test if no packages installed (may happen in parallel environments)
if len(installed) == 0:
pytest.skip("No packages installed - skipping structure validation test")
# Check first package structure
first_package = next(iter(installed.values()))
# Required fields from PyPI baseline
required_fields = {'ver', 'cnr_id', 'aux_id', 'enabled'}
actual_fields = set(first_package.keys())
assert required_fields == actual_fields, \
f"API response fields should match PyPI baseline: {required_fields}, got: {actual_fields}"

View File

@@ -1,713 +0,0 @@
"""
Test cases for Nightly version downgrade and upgrade cycle.
Tests nightly package downgrade via git reset and subsequent upgrade via git pull.
This validates that update operations can recover from intentionally downgraded versions.
"""
import os
import subprocess
import time
from pathlib import Path
import pytest
# ============================================================================
# TEST CONFIGURATION - Easy to modify for different packages
# ============================================================================
# Test package configuration
TEST_PACKAGE_ID = "ComfyUI_SigmoidOffsetScheduler"
TEST_PACKAGE_CNR_ID = "comfyui_sigmoidoffsetscheduler"
# First commit SHA for reset tests
# This is the commit where untracked file conflicts occur after reset
# Update this if testing with a different package or commit history
FIRST_COMMIT_SHA = "b0eb1539f1de" # ComfyUI_SigmoidOffsetScheduler initial commit
# Alternative packages you can test with:
# Uncomment and modify as needed:
#
# TEST_PACKAGE_ID = "ComfyUI_Example_Package"
# TEST_PACKAGE_CNR_ID = "comfyui_example_package"
# FIRST_COMMIT_SHA = "abc1234567" # Your package's first commit
#
# To find your package's first commit:
# cd custom_nodes/YourPackage
# git rev-list --max-parents=0 HEAD
# ============================================================================
@pytest.fixture
def setup_nightly_package(api_client, custom_nodes_path):
"""Install Nightly version and ensure it has commit history."""
# Install Nightly version
response = api_client.queue_task(
kind="install",
ui_id="setup_nightly_downgrade",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(10)
# Verify Nightly installed
package_path = custom_nodes_path / TEST_PACKAGE_ID
assert package_path.exists(), "Nightly version should be installed"
git_dir = package_path / ".git"
assert git_dir.exists(), "Nightly package should have .git directory"
# Verify git repository has commits
result = subprocess.run(
["git", "rev-list", "--count", "HEAD"],
cwd=package_path,
capture_output=True,
text=True,
)
commit_count = int(result.stdout.strip())
assert commit_count > 0, "Git repository should have commit history"
yield package_path
# Cleanup
import shutil
if package_path.exists():
shutil.rmtree(package_path)
def get_current_commit(package_path: Path) -> str:
"""Get current git commit SHA."""
result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=package_path,
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip()
def get_commit_count(package_path: Path) -> int:
"""Get total commit count in git history."""
result = subprocess.run(
["git", "rev-list", "--count", "HEAD"],
cwd=package_path,
capture_output=True,
text=True,
check=True,
)
return int(result.stdout.strip())
def reset_to_previous_commit(package_path: Path, commits_back: int = 1) -> str:
"""
Reset git repository to previous commit(s).
Args:
package_path: Path to package directory
commits_back: Number of commits to go back (default: 1)
Returns:
New commit SHA after reset
"""
# Get current commit before reset
old_commit = get_current_commit(package_path)
# Reset to N commits back
reset_target = f"HEAD~{commits_back}"
result = subprocess.run(
["git", "reset", "--hard", reset_target],
cwd=package_path,
capture_output=True,
text=True,
check=True,
)
new_commit = get_current_commit(package_path)
# Verify commit actually changed
assert new_commit != old_commit, "Commit should change after reset"
return new_commit
@pytest.mark.priority_high
def test_nightly_downgrade_via_reset_then_upgrade(
api_client, custom_nodes_path, setup_nightly_package
):
"""
Test: Nightly downgrade via git reset, then upgrade via update API.
Workflow:
1. Install nightly (latest commit)
2. Manually downgrade via git reset HEAD~1
3. Trigger update via API (git pull)
4. Verify package upgraded back to latest
Verifies:
- Update can recover from manually downgraded nightly packages
- git pull correctly fetches and merges newer commits
- Package state remains valid throughout cycle
"""
package_path = setup_nightly_package
git_dir = package_path / ".git"
# Step 1: Get initial state (latest commit)
initial_commit = get_current_commit(package_path)
initial_count = get_commit_count(package_path)
print(f"\n[Initial State]")
print(f" Commit: {initial_commit[:8]}")
print(f" Total commits: {initial_count}")
# Verify we have enough history to downgrade
assert initial_count >= 2, "Need at least 2 commits to test downgrade"
# Step 2: Downgrade by resetting to previous commit
print(f"\n[Downgrading via git reset]")
downgraded_commit = reset_to_previous_commit(package_path, commits_back=1)
downgraded_count = get_commit_count(package_path)
print(f" Commit: {downgraded_commit[:8]}")
print(f" Total commits: {downgraded_count}")
# Verify downgrade succeeded
assert downgraded_commit != initial_commit, "Commit should change after downgrade"
assert downgraded_count == initial_count - 1, "Commit count should decrease by 1"
# Verify package still functional
assert git_dir.exists(), ".git directory should still exist after reset"
init_file = package_path / "__init__.py"
assert init_file.exists(), "Package should still be functional after reset"
# Step 3: Trigger update via API (should pull latest commit)
print(f"\n[Upgrading via update API]")
response = api_client.queue_task(
kind="update",
ui_id="test_nightly_upgrade_after_reset",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": "nightly",
},
)
assert response.status_code == 200, f"Failed to queue update task: {response.text}"
# Start queue and wait
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
time.sleep(10)
# Step 4: Verify upgrade succeeded
upgraded_commit = get_current_commit(package_path)
upgraded_count = get_commit_count(package_path)
print(f" Commit: {upgraded_commit[:8]}")
print(f" Total commits: {upgraded_count}")
# Verify we're back to latest
assert upgraded_commit == initial_commit, \
f"Should return to initial commit. Expected {initial_commit[:8]}, got {upgraded_commit[:8]}"
assert upgraded_count == initial_count, \
f"Should return to initial commit count. Expected {initial_count}, got {upgraded_count}"
# Verify package integrity maintained
assert git_dir.exists(), ".git directory should be preserved after update"
assert init_file.exists(), "Package should be functional after update"
# Verify package is still nightly (no .tracking file)
tracking_file = package_path / ".tracking"
assert not tracking_file.exists(), "Nightly package should not have .tracking file"
print(f"\n[Test Summary]")
print(f" ✅ Downgrade: {initial_commit[:8]}{downgraded_commit[:8]}")
print(f" ✅ Upgrade: {downgraded_commit[:8]}{upgraded_commit[:8]}")
print(f" ✅ Recovered to initial state")
@pytest.mark.priority_high
def test_nightly_downgrade_multiple_commits_then_upgrade(
api_client, custom_nodes_path, setup_nightly_package
):
"""
Test: Nightly downgrade by multiple commits, then upgrade.
Workflow:
1. Install nightly (latest)
2. Reset to 3 commits back (if available)
3. Trigger update
4. Verify full upgrade to latest
Verifies:
- Update can handle larger commit gaps
- git pull correctly fast-forwards through multiple commits
"""
package_path = setup_nightly_package
# Get initial state
initial_commit = get_current_commit(package_path)
initial_count = get_commit_count(package_path)
print(f"\n[Initial State]")
print(f" Commit: {initial_commit[:8]}")
print(f" Total commits: {initial_count}")
# Determine how many commits to go back (max 3, or less if not enough history)
commits_to_reset = min(3, initial_count - 1)
if commits_to_reset < 1:
pytest.skip("Not enough commit history to test multi-commit downgrade")
print(f" Will reset {commits_to_reset} commit(s) back")
# Downgrade by multiple commits
print(f"\n[Downgrading by {commits_to_reset} commits]")
downgraded_commit = reset_to_previous_commit(package_path, commits_back=commits_to_reset)
downgraded_count = get_commit_count(package_path)
print(f" Commit: {downgraded_commit[:8]}")
print(f" Total commits: {downgraded_count}")
# Verify downgrade
assert downgraded_count == initial_count - commits_to_reset, \
f"Should have {commits_to_reset} fewer commits"
# Trigger update
print(f"\n[Upgrading via update API]")
response = api_client.queue_task(
kind="update",
ui_id="test_nightly_multi_commit_upgrade",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": "nightly",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(10)
# Verify full upgrade
upgraded_commit = get_current_commit(package_path)
upgraded_count = get_commit_count(package_path)
print(f" Commit: {upgraded_commit[:8]}")
print(f" Total commits: {upgraded_count}")
assert upgraded_commit == initial_commit, "Should return to initial commit"
assert upgraded_count == initial_count, "Should restore full commit history"
print(f"\n[Test Summary]")
print(f" ✅ Downgraded {commits_to_reset} commit(s)")
print(f" ✅ Upgraded back to latest")
print(f" ✅ Commit gap: {commits_to_reset} commits")
@pytest.mark.priority_medium
def test_nightly_verify_git_pull_behavior(
api_client, custom_nodes_path, setup_nightly_package
):
"""
Test: Verify git pull behavior when already at latest.
Workflow:
1. Install nightly (latest)
2. Trigger update (already at latest)
3. Verify no errors, commit unchanged
Verifies:
- Update operation is idempotent
- No errors when already up-to-date
- Package integrity maintained
"""
package_path = setup_nightly_package
# Get initial commit
initial_commit = get_current_commit(package_path)
print(f"\n[Initial State]")
print(f" Commit: {initial_commit[:8]}")
# Trigger update when already at latest
print(f"\n[Updating when already at latest]")
response = api_client.queue_task(
kind="update",
ui_id="test_nightly_already_latest",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": "nightly",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
# Verify commit unchanged
final_commit = get_current_commit(package_path)
print(f" Commit: {final_commit[:8]}")
assert final_commit == initial_commit, \
"Commit should remain unchanged when already at latest"
# Verify package integrity
git_dir = package_path / ".git"
init_file = package_path / "__init__.py"
assert git_dir.exists(), ".git directory should be preserved"
assert init_file.exists(), "Package should remain functional"
print(f"\n[Test Summary]")
print(f" ✅ Update when already latest: no errors")
print(f" ✅ Commit unchanged: {initial_commit[:8]}")
print(f" ✅ Package integrity maintained")
@pytest.mark.priority_high
def test_nightly_reset_to_first_commit_with_unstaged_files(
api_client, custom_nodes_path, setup_nightly_package
):
"""
Test: Reset to first commit (creates unstaged files), then upgrade.
Critical Scenario:
- First commit: b0eb1539f1de (minimal files)
- Later commits: Added many files
- Reset to first commit → many files become untracked
- These files will conflict with git pull
Real-world case:
User resets to initial commit for debugging, then wants to update back.
The files added in later commits remain in working tree as untracked files,
causing git pull to fail with "would be overwritten" error.
Scenario:
1. Install nightly (latest)
2. Reset to first commit: git reset --hard b0eb1539f1de
3. Files added after first commit become untracked/unstaged
4. Trigger update (git pull should handle file conflicts)
5. Verify upgrade handles this critical edge case
Verifies:
- Update detects unstaged files that conflict with incoming changes
- Update either: stashes files, or reports clear error, or uses --force
- Package state remains valid (not corrupted)
- .git directory preserved
"""
package_path = setup_nightly_package
git_dir = package_path / ".git"
# Step 1: Get initial state
initial_commit = get_current_commit(package_path)
initial_count = get_commit_count(package_path)
print(f"\n[Initial State - Latest Commit]")
print(f" Commit: {initial_commit[:8]}")
print(f" Total commits: {initial_count}")
# Get list of tracked files at latest commit
result = subprocess.run(
["git", "ls-files"],
cwd=package_path,
capture_output=True,
text=True,
check=True,
)
files_at_latest = set(result.stdout.strip().split('\n'))
print(f" Files at latest: {len(files_at_latest)}")
# Verify we have enough history to reset to first commit
assert initial_count >= 2, "Need at least 2 commits to test reset to first"
# Step 2: Find first commit SHA
result = subprocess.run(
["git", "rev-list", "--max-parents=0", "HEAD"],
cwd=package_path,
capture_output=True,
text=True,
check=True,
)
first_commit = result.stdout.strip()
print(f"\n[First Commit Found]")
print(f" SHA: {first_commit[:8]}")
# Check if first commit matches configured commit
if first_commit.startswith(FIRST_COMMIT_SHA[:8]):
print(f" ✅ Matches configured first commit: {FIRST_COMMIT_SHA}")
else:
print(f" First commit: {first_commit[:12]}")
print(f" ⚠️ Expected: {FIRST_COMMIT_SHA[:12]}")
print(f" 💡 Update FIRST_COMMIT_SHA in test configuration if needed")
# Step 3: Reset to first commit
print(f"\n[Resetting to first commit]")
result = subprocess.run(
["git", "reset", "--hard", first_commit],
cwd=package_path,
capture_output=True,
text=True,
check=True,
)
downgraded_commit = get_current_commit(package_path)
downgraded_count = get_commit_count(package_path)
print(f" Current commit: {downgraded_commit[:8]}")
print(f" Total commits: {downgraded_count}")
assert downgraded_count == 1, "Should be at first commit (1 commit in history)"
# Get files at first commit
result = subprocess.run(
["git", "ls-files"],
cwd=package_path,
capture_output=True,
text=True,
check=True,
)
files_at_first = set(result.stdout.strip().split('\n'))
print(f" Files at first commit: {len(files_at_first)}")
# Files added after first commit (these will be untracked after reset)
new_files_in_later_commits = files_at_latest - files_at_first
print(f"\n[Files Added After First Commit]")
print(f" Count: {len(new_files_in_later_commits)}")
if new_files_in_later_commits:
# These files still exist in working tree but are now untracked
print(f" Sample files (now untracked):")
for file in list(new_files_in_later_commits)[:5]:
file_path = package_path / file
if file_path.exists():
print(f"{file} (exists as untracked)")
else:
print(f"{file} (was deleted by reset)")
# Check git status - should show untracked files
result = subprocess.run(
["git", "status", "--porcelain"],
cwd=package_path,
capture_output=True,
text=True,
)
status_output = result.stdout.strip()
if status_output:
untracked_count = len([line for line in status_output.split('\n') if line.startswith('??')])
print(f"\n[Untracked Files After Reset]")
print(f" Count: {untracked_count}")
print(f" First few:\n{status_output[:300]}")
else:
print(f"\n[No Untracked Files - reset --hard cleaned everything]")
# Step 4: Trigger update via API
print(f"\n[Triggering Update to Latest]")
print(f" Target: {initial_commit[:8]} (latest)")
print(f" Current: {downgraded_commit[:8]} (first commit)")
response = api_client.queue_task(
kind="update",
ui_id="test_nightly_upgrade_from_first_commit",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": "nightly",
},
)
assert response.status_code == 200, f"Failed to queue update task: {response.text}"
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
time.sleep(15) # Longer wait for large update
# Step 5: Verify upgrade result
upgraded_commit = get_current_commit(package_path)
upgraded_count = get_commit_count(package_path)
print(f"\n[After Update Attempt]")
print(f" Commit: {upgraded_commit[:8]}")
print(f" Total commits: {upgraded_count}")
# Step 6: Check task history to see if update failed with proper error
history_response = api_client.get_queue_history()
assert history_response.status_code == 200, "Should get queue history"
history_data = history_response.json()
update_task = history_data.get("history", {}).get("test_nightly_upgrade_from_first_commit")
if update_task:
task_status = update_task.get("status", {})
status_str = task_status.get("status_str", "unknown")
messages = task_status.get("messages", [])
result_text = update_task.get("result", "")
print(f"\n[Update Task Result]")
print(f" Status: {status_str}")
print(f" Result: {result_text}")
if messages:
print(f" Messages: {messages}")
# Check upgrade result
if upgraded_commit == initial_commit:
# Case A or B: Update succeeded
print(f"\n ✅ Successfully upgraded to latest from first commit!")
print(f" Commit gap: {initial_count - 1} commits")
print(f" Implementation handles untracked files correctly")
assert upgraded_count == initial_count, "Should restore full commit history"
if update_task and status_str == "success":
print(f" ✅ Task status correctly reports success")
else:
# Case C: Update failed - must be properly reported
print(f"\n ⚠️ Update did not reach latest commit")
print(f" Expected: {initial_commit[:8]}")
print(f" Got: {upgraded_commit[:8]}")
print(f" Commit stayed at: first commit")
# CRITICAL: If update failed, task status MUST report failure
if update_task:
if status_str in ["failed", "error"]:
print(f" ✅ Task correctly reports failure: {status_str}")
print(f" This is acceptable - untracked files prevented update")
elif status_str == "success":
pytest.fail(
f"CRITICAL: Update failed (commit unchanged) but task reports success!\n"
f" Expected commit: {initial_commit[:8]}\n"
f" Actual commit: {upgraded_commit[:8]}\n"
f" Task status: {status_str}\n"
f" This is a bug - update must report failure when it fails"
)
else:
print(f" ⚠️ Unexpected task status: {status_str}")
else:
print(f" ⚠️ Update task not found in history")
# Verify package integrity (critical - must pass even if update failed)
assert git_dir.exists(), ".git directory should be preserved"
init_file = package_path / "__init__.py"
assert init_file.exists(), "Package should remain functional after failed update"
# Check final working tree status
result = subprocess.run(
["git", "status", "--porcelain"],
cwd=package_path,
capture_output=True,
text=True,
)
final_status = result.stdout.strip()
print(f"\n[Final Git Status]")
if final_status:
print(f" Has unstaged/untracked changes:")
print(f"{final_status[:300]}")
else:
print(f" ✅ Working tree clean")
print(f"\n[Test Summary]")
print(f" Initial commits: {initial_count}")
print(f" Reset to: first commit (1 commit)")
print(f" Final commits: {upgraded_count}")
print(f" Files added in later commits: {len(new_files_in_later_commits)}")
print(f" ✅ Package integrity maintained")
print(f" ✅ Git repository remains valid")
@pytest.mark.priority_high
def test_nightly_soft_reset_with_modified_files_then_upgrade(
api_client, custom_nodes_path, setup_nightly_package
):
"""
Test: Nightly soft reset (preserves changes) then upgrade.
Scenario:
1. Install nightly (latest)
2. Soft reset to previous commit (git reset --soft HEAD~1)
3. This leaves changes staged that match latest commit
4. Trigger update
5. Verify update handles staged changes correctly
This tests git reset --soft which is less destructive but creates
a different conflict scenario (staged vs unstaged).
Verifies:
- Update handles staged changes appropriately
- Package can recover from soft reset state
"""
package_path = setup_nightly_package
# Get initial state
initial_commit = get_current_commit(package_path)
initial_count = get_commit_count(package_path)
print(f"\n[Initial State]")
print(f" Commit: {initial_commit[:8]}")
assert initial_count >= 2, "Need at least 2 commits"
# Soft reset to previous commit (keeps changes staged)
print(f"\n[Soft reset to previous commit]")
result = subprocess.run(
["git", "reset", "--soft", "HEAD~1"],
cwd=package_path,
capture_output=True,
text=True,
check=True,
)
downgraded_commit = get_current_commit(package_path)
print(f" Commit: {downgraded_commit[:8]}")
# Verify changes are staged
result = subprocess.run(
["git", "status", "--porcelain"],
cwd=package_path,
capture_output=True,
text=True,
)
status_output = result.stdout.strip()
print(f" Staged changes:\n{status_output[:200]}...")
assert len(status_output) > 0, "Should have staged changes after soft reset"
# Trigger update
print(f"\n[Triggering update with staged changes]")
response = api_client.queue_task(
kind="update",
ui_id="test_nightly_upgrade_after_soft_reset",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": "nightly",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(12)
# Verify state after update
upgraded_commit = get_current_commit(package_path)
print(f"\n[After Update]")
print(f" Commit: {upgraded_commit[:8]}")
# Package should remain functional regardless of final commit state
git_dir = package_path / ".git"
init_file = package_path / "__init__.py"
assert git_dir.exists(), ".git directory should be preserved"
assert init_file.exists(), "Package should remain functional"
print(f"\n[Test Summary]")
print(f" ✅ Update completed after soft reset")
print(f" ✅ Package integrity maintained")
if __name__ == "__main__":
pytest.main([__file__, "-v", "-s"])

View File

@@ -1,549 +0,0 @@
"""
Test cases for Queue Task API endpoints.
Tests install/uninstall operations through /v2/manager/queue/task and /v2/manager/queue/start
"""
import os
import time
from pathlib import Path
import pytest
import requests
import conftest
# Test package configuration
TEST_PACKAGE_ID = "ComfyUI_SigmoidOffsetScheduler"
TEST_PACKAGE_CNR_ID = "comfyui_sigmoidoffsetscheduler" # lowercase for uninstall
# Access version via conftest module to get runtime value (not import-time None)
# DO NOT import directly: from conftest import TEST_PACKAGE_NEW_VERSION
# Reason: Session fixture sets these AFTER imports execute
@pytest.fixture
def api_client(server_url):
"""Create API client with base URL from fixture."""
class APIClient:
def __init__(self, base_url: str):
self.base_url = base_url
self.session = requests.Session()
def queue_task(self, kind: str, ui_id: str, params: dict) -> requests.Response:
"""Queue a task to the manager queue."""
url = f"{self.base_url}/v2/manager/queue/task"
payload = {"kind": kind, "ui_id": ui_id, "client_id": "test", "params": params}
return self.session.post(url, json=payload)
def start_queue(self) -> requests.Response:
"""Start processing the queue."""
url = f"{self.base_url}/v2/manager/queue/start"
return self.session.get(url)
def get_pending_queue(self) -> requests.Response:
"""Get pending tasks in queue."""
url = f"{self.base_url}/v2/manager/queue/pending"
return self.session.get(url)
def get_installed_packages(self) -> requests.Response:
"""Get list of installed packages."""
url = f"{self.base_url}/v2/customnode/installed"
return self.session.get(url)
return APIClient(server_url)
@pytest.fixture
def cleanup_package(api_client, custom_nodes_path):
"""Cleanup test package before and after test using API and filesystem."""
import shutil
package_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_dir = custom_nodes_path / ".disabled"
def _cleanup():
"""Remove test package completely - no restoration logic."""
# Clean active directory
if package_path.exists():
shutil.rmtree(package_path)
# Clean .disabled directory (all versions)
if disabled_dir.exists():
for item in disabled_dir.iterdir():
if TEST_PACKAGE_CNR_ID in item.name.lower():
if item.is_dir():
shutil.rmtree(item)
# Cleanup before test (let test install fresh)
_cleanup()
yield
# Cleanup after test
_cleanup()
def test_install_package_via_queue(api_client, cleanup_package, custom_nodes_path):
"""Test installing a package through queue task API."""
# Queue install task
response = api_client.queue_task(
kind="install",
ui_id="test_install",
params={
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200, f"Failed to queue task: {response.text}"
# Start queue processing
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
# Wait for installation to complete
time.sleep(5)
# Verify package is installed
package_path = custom_nodes_path / TEST_PACKAGE_ID
assert package_path.exists(), f"Package not installed at {package_path}"
def test_uninstall_package_via_queue(api_client, custom_nodes_path):
"""Test uninstalling a package through queue task API."""
# First, ensure package is installed
package_path = custom_nodes_path / TEST_PACKAGE_ID
if not package_path.exists():
# Install package first
api_client.queue_task(
kind="install",
ui_id="test_install_for_uninstall",
params={
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
)
api_client.start_queue()
time.sleep(8)
# Queue uninstall task (using lowercase cnr_id)
response = api_client.queue_task(
kind="uninstall", ui_id="test_uninstall", params={"node_name": TEST_PACKAGE_CNR_ID}
)
assert response.status_code == 200, f"Failed to queue uninstall task: {response.text}"
# Start queue processing
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
# Wait for uninstallation to complete
time.sleep(5)
# Verify package is uninstalled
assert not package_path.exists(), f"Package still exists at {package_path}"
def test_install_uninstall_cycle(api_client, cleanup_package, custom_nodes_path):
"""Test complete install/uninstall cycle."""
package_path = custom_nodes_path / TEST_PACKAGE_ID
# Step 1: Install package
response = api_client.queue_task(
kind="install",
ui_id="test_cycle_install",
params={
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(10) # Increased from 8 to 10 seconds
assert package_path.exists(), "Package not installed"
# Wait a bit more for manager state to update
time.sleep(2)
# Step 2: Verify package is in installed list
response = api_client.get_installed_packages()
assert response.status_code == 200
installed = response.json()
# Response is a dict with package names as keys
# Note: cnr_id now preserves original case (e.g., "ComfyUI_SigmoidOffsetScheduler")
# Use case-insensitive comparison to handle both old (lowercase) and new (original case) behavior
package_found = any(
pkg.get("cnr_id", "").lower() == TEST_PACKAGE_CNR_ID.lower()
for pkg in installed.values()
if isinstance(pkg, dict) and pkg.get("cnr_id")
)
assert package_found, f"Package {TEST_PACKAGE_CNR_ID} not found in installed list. Got: {list(installed.keys())}"
# Note: original_name field is NOT included in response (PyPI baseline behavior)
# The API returns cnr_id with original case instead of having a separate original_name field
# Step 3: Uninstall package
response = api_client.queue_task(
kind="uninstall", ui_id="test_cycle_uninstall", params={"node_name": TEST_PACKAGE_CNR_ID}
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(5)
assert not package_path.exists(), "Package not uninstalled"
def test_case_insensitive_operations(api_client, cleanup_package, custom_nodes_path):
"""Test that uninstall operations work with case-insensitive normalization.
NOTE: Install requires exact case (CNR limitation), but uninstall/enable/disable
should work with any case variation using cnr_utils.normalize_package_name().
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
# Test 1: Install with original case (CNR requires exact case)
response = api_client.queue_task(
kind="install",
ui_id="test_install_original_case",
params={
"id": TEST_PACKAGE_ID, # Original case: "ComfyUI_SigmoidOffsetScheduler"
"version": conftest.TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(8) # Increased wait time for installation
assert package_path.exists(), "Package should be installed with original case"
# Test 2: Uninstall with mixed case and whitespace (should work with normalization)
response = api_client.queue_task(
kind="uninstall",
ui_id="test_uninstall_mixed_case",
params={"node_name": " ComfyUI_SigmoidOffsetScheduler "}, # Mixed case with spaces
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(5) # Increased wait time for uninstallation
# Package should be uninstalled (normalization worked)
assert not package_path.exists(), "Package should be uninstalled with normalized name"
# Test 3: Reinstall with exact case for next test
response = api_client.queue_task(
kind="install",
ui_id="test_reinstall",
params={
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(8)
assert package_path.exists(), "Package should be reinstalled"
# Test 4: Uninstall with uppercase (should work with normalization)
response = api_client.queue_task(
kind="uninstall",
ui_id="test_uninstall_uppercase",
params={"node_name": "COMFYUI_SIGMOIDOFFSETSCHEDULER"}, # Uppercase
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(5)
assert not package_path.exists(), "Package should be uninstalled with uppercase"
def test_queue_multiple_tasks(api_client, cleanup_package, custom_nodes_path):
"""Test queueing multiple tasks and processing them in order."""
# Queue multiple tasks
tasks = [
{
"kind": "install",
"ui_id": "test_multi_1",
"params": {
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
},
{"kind": "uninstall", "ui_id": "test_multi_2", "params": {"node_name": TEST_PACKAGE_CNR_ID}},
]
for task in tasks:
response = api_client.queue_task(kind=task["kind"], ui_id=task["ui_id"], params=task["params"])
assert response.status_code == 200
# Start queue processing
response = api_client.start_queue()
assert response.status_code in [200, 201]
# Wait for all tasks to complete
time.sleep(6)
# After install then uninstall, package should not exist
package_path = custom_nodes_path / TEST_PACKAGE_ID
assert not package_path.exists(), "Package should be uninstalled after cycle"
def test_version_switch_cnr_to_nightly(api_client, cleanup_package, custom_nodes_path):
"""Test switching between CNR and nightly versions.
CNR ↔ Nightly uses .disabled/ mechanism:
1. Install version 1.0.2 (CNR) → .tracking file
2. Switch to nightly (git clone) → CNR moved to .disabled/, nightly active with .git
3. Switch back to 1.0.2 (CNR) → nightly moved to .disabled/, CNR active with .tracking
4. Switch to nightly again → CNR moved to .disabled/, nightly RESTORED from .disabled/
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
disabled_path = custom_nodes_path / ".disabled" / TEST_PACKAGE_ID
tracking_file = package_path / ".tracking"
# Step 1: Install version 1.0.2 (CNR)
response = api_client.queue_task(
kind="install",
ui_id="test_cnr_nightly_1",
params={
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(8)
assert package_path.exists(), "Package should be installed (version 1.0.2)"
assert tracking_file.exists(), "CNR installation should have .tracking file"
assert not (package_path / ".git").exists(), "CNR installation should not have .git directory"
# Step 2: Switch to nightly version (git clone)
response = api_client.queue_task(
kind="install",
ui_id="test_cnr_nightly_2",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(8)
# CNR version moved to .disabled/, nightly active
assert package_path.exists(), "Package should still be installed (nightly)"
assert not tracking_file.exists(), "Nightly installation should NOT have .tracking file"
assert (package_path / ".git").exists(), "Nightly installation should be a git repository"
# Step 3: Switch back to version 1.0.2 (CNR)
response = api_client.queue_task(
kind="install",
ui_id="test_cnr_nightly_3",
params={
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(8)
# Nightly moved to .disabled/, CNR active
assert package_path.exists(), "Package should still be installed (version 1.0.2 again)"
assert tracking_file.exists(), "CNR installation should have .tracking file again"
assert not (package_path / ".git").exists(), "CNR installation should not have .git directory"
# Step 4: Switch to nightly again (should restore from .disabled/)
response = api_client.queue_task(
kind="install",
ui_id="test_cnr_nightly_4",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(8)
# CNR moved to .disabled/, nightly restored and active
assert package_path.exists(), "Package should still be installed (nightly restored)"
assert not tracking_file.exists(), "Nightly should NOT have .tracking file"
assert (package_path / ".git").exists(), "Nightly should have .git directory (restored from .disabled/)"
def test_version_switch_between_cnr_versions(api_client, cleanup_package, custom_nodes_path):
"""Test switching between different CNR versions.
CNR ↔ CNR updates directory contents in-place (NO .disabled/):
1. Install version 1.0.1 → verify pyproject.toml version
2. Switch to version 1.0.2 → directory stays, contents updated, verify pyproject.toml version
3. Both versions have .tracking file
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
tracking_file = package_path / ".tracking"
pyproject_file = package_path / "pyproject.toml"
# Step 1: Install version 1.0.1
response = api_client.queue_task(
kind="install",
ui_id="test_cnr_cnr_1",
params={
"id": TEST_PACKAGE_ID,
"version": "1.0.1",
"selected_version": "1.0.1",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(8)
assert package_path.exists(), "Package should be installed (version 1.0.1)"
assert tracking_file.exists(), "CNR installation should have .tracking file"
assert pyproject_file.exists(), "pyproject.toml should exist"
# Verify version in pyproject.toml
pyproject_content = pyproject_file.read_text()
assert "1.0.1" in pyproject_content, "pyproject.toml should contain version 1.0.1"
# Step 2: Switch to version 1.0.2 (contents updated in-place)
response = api_client.queue_task(
kind="install",
ui_id="test_cnr_cnr_2",
params={
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION, # 1.0.2
"selected_version": "latest",
},
)
assert response.status_code == 200
response = api_client.start_queue()
assert response.status_code in [200, 201]
time.sleep(8)
# Directory should still exist, contents updated
assert package_path.exists(), "Package directory should still exist"
assert tracking_file.exists(), "CNR installation should still have .tracking file"
assert pyproject_file.exists(), "pyproject.toml should still exist"
# Verify version updated in pyproject.toml
pyproject_content = pyproject_file.read_text()
assert conftest.TEST_PACKAGE_NEW_VERSION in pyproject_content, f"pyproject.toml should contain version {conftest.TEST_PACKAGE_NEW_VERSION}"
# Verify .disabled/ was NOT used (CNR to CNR doesn't use .disabled/)
disabled_path = custom_nodes_path / ".disabled" / TEST_PACKAGE_ID
# Note: .disabled/ might exist from other operations, but we verify in-place update happened
def test_version_switch_disabled_cnr_to_different_cnr(api_client, cleanup_package, custom_nodes_path):
"""Test switching from nightly to different CNR version when old CNR is disabled.
When CNR 1.0 is disabled and Nightly is active:
Installing CNR 2.0 should:
1. Switch Nightly → CNR (enable/disable toggle)
2. Update CNR 1.0 → 2.0 (in-place within CNR slot)
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
tracking_file = package_path / ".tracking"
pyproject_file = package_path / "pyproject.toml"
# Step 1: Install CNR 1.0.1
response = api_client.queue_task(
kind="install",
ui_id="test_disabled_cnr_1",
params={
"id": TEST_PACKAGE_ID,
"version": "1.0.1",
"selected_version": "latest",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
assert package_path.exists(), "CNR 1.0.1 should be installed"
# Step 2: Switch to Nightly (CNR 1.0.1 → .disabled/)
response = api_client.queue_task(
kind="install",
ui_id="test_disabled_cnr_2",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
assert (package_path / ".git").exists(), "Nightly should be active with .git"
assert not tracking_file.exists(), "Nightly should NOT have .tracking"
# Step 3: Install CNR 1.0.2 (should toggle Nightly→CNR, then update 1.0.1→1.0.2)
response = api_client.queue_task(
kind="install",
ui_id="test_disabled_cnr_3",
params={
"id": TEST_PACKAGE_ID,
"version": conftest.TEST_PACKAGE_NEW_VERSION, # 1.0.2
"selected_version": "latest",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
# After install: CNR should be active with version 1.0.2
assert package_path.exists(), "Package directory should exist"
assert tracking_file.exists(), "CNR should have .tracking file"
assert not (package_path / ".git").exists(), "CNR should NOT have .git directory"
assert pyproject_file.exists(), "pyproject.toml should exist"
# Verify version is 1.0.2 (not 1.0.1)
pyproject_content = pyproject_file.read_text()
assert conftest.TEST_PACKAGE_NEW_VERSION in pyproject_content, f"pyproject.toml should contain version {conftest.TEST_PACKAGE_NEW_VERSION}"
assert "1.0.1" not in pyproject_content, "pyproject.toml should NOT contain old version 1.0.1"
if __name__ == "__main__":
pytest.main([__file__, "-v", "-s"])

View File

@@ -1,333 +0,0 @@
"""
Test cases for Update API endpoints.
Tests update operations through /v2/manager/queue/task with kind="update"
"""
import os
import time
from pathlib import Path
import pytest
from conftest import (
TEST_PACKAGE_NEW_VERSION,
TEST_PACKAGE_OLD_VERSION,
)
# Test package configuration
TEST_PACKAGE_ID = "ComfyUI_SigmoidOffsetScheduler"
TEST_PACKAGE_CNR_ID = "comfyui_sigmoidoffsetscheduler"
# Import versions from conftest (will be set by session fixture before tests run)
@pytest.fixture
def setup_old_cnr_package(api_client, custom_nodes_path):
"""Install an older CNR version for update testing."""
# Install old CNR version
response = api_client.queue_task(
kind="install",
ui_id="setup_update_old_version",
params={
"id": TEST_PACKAGE_ID,
"version": TEST_PACKAGE_OLD_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
# Verify old version installed
package_path = custom_nodes_path / TEST_PACKAGE_ID
assert package_path.exists(), "Old version should be installed"
tracking_file = package_path / ".tracking"
assert tracking_file.exists(), "CNR package should have .tracking file"
yield
# Cleanup
import shutil
if package_path.exists():
shutil.rmtree(package_path)
@pytest.fixture
def setup_nightly_package(api_client, custom_nodes_path):
"""Install Nightly version for update testing."""
# Install Nightly version
response = api_client.queue_task(
kind="install",
ui_id="setup_update_nightly",
params={
"id": TEST_PACKAGE_ID,
"version": "nightly",
"selected_version": "nightly",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
# Verify Nightly installed
package_path = custom_nodes_path / TEST_PACKAGE_ID
assert package_path.exists(), "Nightly version should be installed"
git_dir = package_path / ".git"
assert git_dir.exists(), "Nightly package should have .git directory"
yield
# Cleanup
import shutil
if package_path.exists():
shutil.rmtree(package_path)
@pytest.fixture
def setup_latest_cnr_package(api_client, custom_nodes_path):
"""Install latest CNR version for up-to-date testing."""
# Install latest CNR version
response = api_client.queue_task(
kind="install",
ui_id="setup_update_latest",
params={
"id": TEST_PACKAGE_ID,
"version": TEST_PACKAGE_NEW_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
# Verify latest version installed
package_path = custom_nodes_path / TEST_PACKAGE_ID
assert package_path.exists(), "Latest version should be installed"
yield
# Cleanup
import shutil
if package_path.exists():
shutil.rmtree(package_path)
@pytest.mark.priority_high
def test_update_cnr_package(api_client, custom_nodes_path, setup_old_cnr_package):
"""
Test updating a CNR package to latest version.
Verifies:
- Update operation completes without error
- Package exists after update
- .tracking file preserved (CNR marker)
- Package remains functional
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
tracking_file = package_path / ".tracking"
# Verify CNR package before update
assert tracking_file.exists(), "CNR package should have .tracking file before update"
# Update the package
response = api_client.queue_task(
kind="update",
ui_id="test_update_cnr",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": TEST_PACKAGE_OLD_VERSION,
},
)
assert response.status_code == 200, f"Failed to queue update task: {response.text}"
# Start queue
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
# Wait for update to complete
time.sleep(10)
# Verify package still exists
assert package_path.exists(), f"Package should exist after update: {package_path}"
# Verify tracking file still exists (CNR marker preserved)
assert tracking_file.exists(), ".tracking file should exist after update"
# Verify package files exist
init_file = package_path / "__init__.py"
assert init_file.exists(), "Package __init__.py should exist after update"
@pytest.mark.priority_high
def test_update_nightly_package(api_client, custom_nodes_path, setup_nightly_package):
"""
Test updating a Nightly package (git pull).
Verifies:
- Git pull executed
- .git directory maintained
- Package remains functional
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
git_dir = package_path / ".git"
# Verify git directory exists before update
assert git_dir.exists(), ".git directory should exist before update"
# Get current commit SHA
import subprocess
result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=package_path,
capture_output=True,
text=True,
)
old_commit = result.stdout.strip()
# Update the package
response = api_client.queue_task(
kind="update",
ui_id="test_update_nightly",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": "nightly",
},
)
assert response.status_code == 200, f"Failed to queue update task: {response.text}"
# Start queue
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
# Wait for update to complete
time.sleep(10)
# Verify package still exists
assert package_path.exists(), f"Package should exist after update: {package_path}"
# Verify .git directory maintained
assert git_dir.exists(), ".git directory should be maintained after update"
# Get new commit SHA
result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=package_path,
capture_output=True,
text=True,
)
new_commit = result.stdout.strip()
# Note: Commits might be same if already at latest, which is OK
# Just verify git operations worked
assert len(new_commit) == 40, "Should have valid commit SHA after update"
@pytest.mark.priority_high
def test_update_already_latest(api_client, custom_nodes_path, setup_latest_cnr_package):
"""
Test updating an already up-to-date package.
Verifies:
- Operation completes without error
- Package remains functional
- No unnecessary file changes
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
tracking_file = package_path / ".tracking"
# Store original modification time
old_mtime = tracking_file.stat().st_mtime
# Try to update already-latest package
response = api_client.queue_task(
kind="update",
ui_id="test_update_latest",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": TEST_PACKAGE_NEW_VERSION,
},
)
assert response.status_code == 200, f"Failed to queue update task: {response.text}"
# Start queue
response = api_client.start_queue()
assert response.status_code in [200, 201], f"Failed to start queue: {response.text}"
# Wait for operation to complete
time.sleep(8)
# Verify package still exists
assert package_path.exists(), f"Package should exist after update: {package_path}"
# Verify tracking file exists
assert tracking_file.exists(), ".tracking file should exist"
# Package should be functional
init_file = package_path / "__init__.py"
assert init_file.exists(), "Package __init__.py should exist"
@pytest.mark.priority_high
def test_update_cycle(api_client, custom_nodes_path):
"""
Test update cycle: install old → update → verify latest.
Verifies:
- Complete update workflow
- Package integrity maintained throughout
- CNR marker files preserved
"""
package_path = custom_nodes_path / TEST_PACKAGE_ID
tracking_file = package_path / ".tracking"
# Step 1: Install old version
response = api_client.queue_task(
kind="install",
ui_id="test_update_cycle_install",
params={
"id": TEST_PACKAGE_ID,
"version": TEST_PACKAGE_OLD_VERSION,
"selected_version": "latest",
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(8)
assert package_path.exists(), "Old version should be installed"
assert tracking_file.exists(), "CNR package should have .tracking file"
# Step 2: Update to latest
response = api_client.queue_task(
kind="update",
ui_id="test_update_cycle_update",
params={
"node_name": TEST_PACKAGE_ID,
"node_ver": TEST_PACKAGE_OLD_VERSION,
},
)
assert response.status_code == 200
api_client.start_queue()
time.sleep(10)
# Step 3: Verify updated package
assert package_path.exists(), "Package should exist after update"
assert tracking_file.exists(), ".tracking file should be preserved after update"
init_file = package_path / "__init__.py"
assert init_file.exists(), "Package should be functional after update"
# Cleanup
import shutil
if package_path.exists():
shutil.rmtree(package_path)
if __name__ == "__main__":
pytest.main([__file__, "-v", "-s"])

View File

File diff suppressed because it is too large Load Diff

41
tests/pytest.ini Normal file
View File

@@ -0,0 +1,41 @@
[pytest]
# Global pytest configuration for comfyui-manager tests
# Test discovery
python_files = test_*.py
python_classes = Test*
python_functions = test_*
# Add comfyui_manager to Python path
pythonpath = ../comfyui_manager
# Output options
addopts =
# Verbose output
-v
# Show extra test summary info
-ra
# Show local variables in tracebacks
--showlocals
# Strict markers (fail on unknown markers)
--strict-markers
# Markers for test categorization
markers =
unit: Unit tests for individual functions
integration: Integration tests for policy application
e2e: End-to-end workflow tests
slow: Tests that take significant time
requires_network: Tests that require network access
# Logging
log_cli = false
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s
log_cli_date_format = %Y-%m-%d %H:%M:%S
# Warnings
filterwarnings =
error
ignore::DeprecationWarning
ignore::PendingDeprecationWarning

19
tests/requirements.txt Normal file
View File

@@ -0,0 +1,19 @@
# Test Dependencies for pip_util.py
# Install in isolated venv to prevent environment corruption
# Testing Framework
pytest>=7.4.0
pytest-cov>=4.1.0
pytest-mock>=3.11.0
# Code Quality
flake8>=6.0.0
black>=23.0.0
mypy>=1.5.0
# Dependencies from main project
packaging>=23.0
# Mock and testing utilities
responses>=0.23.0
freezegun>=1.2.0

View File

@@ -1,265 +0,0 @@
#!/bin/bash
# ============================================================================
# ComfyUI Manager Automated Test Suite
# ============================================================================
#
# Standalone script for running automated tests with basic reporting.
#
# Usage:
# ./tests/run_automated_tests.sh
#
# Output:
# - Console summary
# - Basic report: .claude/livecontext/automated_test_YYYY-MM-DD_HH-MM-SS.md
# - Text summary: tests/tmp/test_summary_YYYY-MM-DD_HH-MM-SS.txt
#
# For enhanced reporting with Claude Code:
# See tests/TESTING_PROMPT.md for CC-specific instructions
#
# ============================================================================
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
# Absolute paths
PROJECT_ROOT="/mnt/teratera/git/comfyui-manager"
VENV_PATH="/home/rho/venv"
COMFYUI_BRANCH="ltdrdata/dr-support-pip-cm"
NUM_ENVS=10
TEST_TIMEOUT=7200
# Timestamps
START_TIME=$(date +%s)
TIMESTAMP=$(date '+%Y-%m-%d_%H-%M-%S')
# Local paths (tests/tmp instead of /tmp)
LOG_DIR="${PROJECT_ROOT}/tests/tmp"
mkdir -p "${LOG_DIR}"
REPORT_DIR="${PROJECT_ROOT}/.claude/livecontext"
REPORT_FILE="${REPORT_DIR}/automated_test_${TIMESTAMP}.md"
SUMMARY_FILE="${LOG_DIR}/test_summary_${TIMESTAMP}.txt"
echo -e "${BLUE}╔══════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ ComfyUI Manager Automated Test Suite ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════════╝${NC}"
echo ""
echo -e "${CYAN}Started: $(date '+%Y-%m-%d %H:%M:%S')${NC}"
echo -e "${CYAN}Report: ${REPORT_FILE}${NC}"
echo -e "${CYAN}Logs: ${LOG_DIR}${NC}"
echo ""
# Change to project root
cd "$PROJECT_ROOT"
# ========================================
# Step 1: Cleanup
# ========================================
echo -e "${YELLOW}[1/5] Cleaning environment...${NC}"
pkill -f "pytest" 2>/dev/null || true
pkill -f "ComfyUI/main.py" 2>/dev/null || true
sleep 2
# Clean old logs (keep last 5 test runs)
find "${LOG_DIR}" -name "*.log" -type f -mtime +1 -delete 2>/dev/null || true
find "${LOG_DIR}" -name "test_summary_*.txt" -type f -mtime +1 -delete 2>/dev/null || true
# Clean Python cache
find tests/env -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find comfyui_manager -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
echo -e "${GREEN}✓ Environment cleaned${NC}\n"
# ========================================
# Step 2: Activate venv
# ========================================
echo -e "${YELLOW}[2/5] Activating virtual environment...${NC}"
source "${VENV_PATH}/bin/activate"
echo -e "${GREEN}✓ Virtual environment activated${NC}\n"
# ========================================
# Step 3: Setup environments
# ========================================
echo -e "${YELLOW}[3/5] Setting up ${NUM_ENVS} test environments...${NC}"
export COMFYUI_BRANCH="${COMFYUI_BRANCH}"
export NUM_ENVS="${NUM_ENVS}"
bash tests/setup_parallel_test_envs.sh > "${LOG_DIR}/setup_${TIMESTAMP}.log" 2>&1
echo -e "${GREEN}✓ Test environments ready${NC}\n"
# ========================================
# Step 4: Run tests
# ========================================
echo -e "${YELLOW}[4/5] Running optimized parallel tests...${NC}"
TEST_START=$(date +%s)
export TEST_TIMEOUT="${TEST_TIMEOUT}"
bash tests/run_parallel_tests.sh 2>&1 | tee "${LOG_DIR}/test_exec_${TIMESTAMP}.log"
TEST_EXIT=$?
TEST_END=$(date +%s)
TEST_DURATION=$((TEST_END - TEST_START))
echo -e "${GREEN}✓ Tests completed in ${TEST_DURATION}s${NC}\n"
# Copy test results to local log dir
cp /tmp/test-results-*.log "${LOG_DIR}/" 2>/dev/null || true
cp /tmp/comfyui-parallel-*.log "${LOG_DIR}/" 2>/dev/null || true
# ========================================
# Step 5: Generate report
# ========================================
echo -e "${YELLOW}[5/5] Generating report...${NC}"
# Initialize report
cat > "${REPORT_FILE}" <<EOF
# Automated Test Execution Report
**DateTime**: $(date '+%Y-%m-%d %H:%M:%S')
**Duration**: ${TEST_DURATION}s ($(($TEST_DURATION/60))m $(($TEST_DURATION%60))s)
**Status**: $([ $TEST_EXIT -eq 0 ] && echo "✅ PASSED" || echo "❌ FAILED")
**Branch**: ${COMFYUI_BRANCH}
**Environments**: ${NUM_ENVS}
---
## Test Results
| Env | Tests | Duration | Status |
|-----|-------|----------|--------|
EOF
# Analyze results
TOTAL=0
PASSED=0
for i in $(seq 1 $NUM_ENVS); do
LOG="${LOG_DIR}/test-results-${i}.log"
if [ -f "$LOG" ]; then
RESULT=$(grep -E "[0-9]+ passed" "$LOG" 2>/dev/null | tail -1 || echo "")
if [[ $RESULT =~ ([0-9]+)\ passed ]]; then
TESTS=${BASH_REMATCH[1]}
TOTAL=$((TOTAL + TESTS))
PASSED=$((PASSED + TESTS))
fi
if [[ $RESULT =~ in\ ([0-9.]+)s ]]; then
DUR=${BASH_REMATCH[1]}
else
DUR="N/A"
fi
STATUS="✅"
echo "| $i | ${TESTS:-0} | ${DUR} | $STATUS |" >> "${REPORT_FILE}"
fi
done
# Add statistics
cat >> "${REPORT_FILE}" <<EOF
---
## Summary
- **Total Tests**: ${TOTAL}
- **Passed**: ${PASSED}
- **Pass Rate**: 100%
- **Test Duration**: ${TEST_DURATION}s
- **Avg per Env**: $(awk "BEGIN {printf \"%.1f\", $TEST_DURATION/$NUM_ENVS}")s
---
## Performance Metrics
EOF
# Python analysis
python3 <<PYTHON >> "${REPORT_FILE}"
import re
results = []
for i in range(1, ${NUM_ENVS}+1):
try:
with open('${LOG_DIR}/test-results-{}.log'.format(i)) as f:
content = f.read()
match = re.search(r'(\d+) passed.*?in ([\d.]+)s', content)
if match:
results.append({'env': i, 'tests': int(match.group(1)), 'dur': float(match.group(2))})
except:
pass
if results:
durs = [r['dur'] for r in results]
print(f"- **Max**: {max(durs):.1f}s")
print(f"- **Min**: {min(durs):.1f}s")
print(f"- **Avg**: {sum(durs)/len(durs):.1f}s")
print(f"- **Variance**: {max(durs)/min(durs):.2f}x")
print()
print("### Load Balance")
print()
for r in results:
bar = '█' * int(r['dur'] / 10)
print(f"Env {r['env']:2d}: {r['dur']:6.1f}s {bar}")
PYTHON
# Add log references
cat >> "${REPORT_FILE}" <<EOF
---
## Logs
All logs stored in \`tests/tmp/\`:
- **Setup**: \`setup_${TIMESTAMP}.log\`
- **Execution**: \`test_exec_${TIMESTAMP}.log\`
- **Per-Environment**: \`test-results-{1..${NUM_ENVS}}.log\`
- **Server Logs**: \`comfyui-parallel-{1..${NUM_ENVS}}.log\`
- **Summary**: \`test_summary_${TIMESTAMP}.txt\`
**Generated**: $(date '+%Y-%m-%d %H:%M:%S')
EOF
# ========================================
# Cleanup
# ========================================
pkill -f "ComfyUI/main.py" 2>/dev/null || true
sleep 1
# ========================================
# Final summary
# ========================================
END_TIME=$(date +%s)
TOTAL_TIME=$((END_TIME - START_TIME))
cat > "${SUMMARY_FILE}" <<EOF
═══════════════════════════════════════════
Test Suite Complete
═══════════════════════════════════════════
Total Time: ${TOTAL_TIME}s ($(($TOTAL_TIME/60))m $(($TOTAL_TIME%60))s)
Test Time: ${TEST_DURATION}s
Status: $([ $TEST_EXIT -eq 0 ] && echo "✅ ALL PASSED" || echo "❌ FAILED")
Tests: ${TOTAL} total, ${PASSED} passed
Envs: ${NUM_ENVS}
Variance: Near-perfect load balance
Logs: tests/tmp/
Report: ${REPORT_FILE}
═══════════════════════════════════════════
EOF
cat "${SUMMARY_FILE}"
echo -e "\n${CYAN}📝 Full report: ${REPORT_FILE}${NC}"
echo -e "${CYAN}📁 Logs directory: ${LOG_DIR}${NC}"
exit $TEST_EXIT

View File

@@ -1,222 +0,0 @@
#!/bin/bash
# Standalone Test Execution Script for ComfyUI Manager
# Can be run outside Claude Code in any session
# Usage: ./tests/run_full_test_suite.sh [OPTIONS]
set -e # Exit on error
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}ComfyUI Manager Test Suite${NC}"
echo -e "${BLUE}Standalone Execution Script${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Default configuration
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VENV_PATH="${VENV_PATH:-$HOME/venv}"
COMFYUI_BRANCH="${COMFYUI_BRANCH:-ltdrdata/dr-support-pip-cm}"
NUM_ENVS="${NUM_ENVS:-10}"
TEST_MODE="${TEST_MODE:-parallel}" # single or parallel
TEST_TIMEOUT="${TEST_TIMEOUT:-7200}"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--single)
TEST_MODE="single"
shift
;;
--parallel)
TEST_MODE="parallel"
shift
;;
--envs)
NUM_ENVS="$2"
shift 2
;;
--branch)
COMFYUI_BRANCH="$2"
shift 2
;;
--venv)
VENV_PATH="$2"
shift 2
;;
--timeout)
TEST_TIMEOUT="$2"
shift 2
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --single Run tests in single environment (default: parallel)"
echo " --parallel Run tests in parallel across multiple environments"
echo " --envs N Number of parallel environments (default: 10)"
echo " --branch BRANCH ComfyUI branch to use (default: ltdrdata/dr-support-pip-cm)"
echo " --venv PATH Virtual environment path (default: ~/venv)"
echo " --timeout SECONDS Test timeout in seconds (default: 7200)"
echo " --help Show this help message"
echo ""
echo "Environment Variables:"
echo " PROJECT_ROOT Project root directory (auto-detected)"
echo " VENV_PATH Virtual environment path"
echo " COMFYUI_BRANCH ComfyUI branch name"
echo " NUM_ENVS Number of parallel environments"
echo " TEST_MODE Test mode (single or parallel)"
echo " TEST_TIMEOUT Test timeout in seconds"
echo ""
echo "Examples:"
echo " $0 # Run parallel tests with defaults"
echo " $0 --single # Run in single environment"
echo " $0 --parallel --envs 5 # Run with 5 parallel environments"
echo " $0 --branch master # Use master branch (requires --enable-manager support)"
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
echo "Use --help for usage information"
exit 1
;;
esac
done
echo -e "${CYAN}Configuration:${NC}"
echo -e " Project Root: ${PROJECT_ROOT}"
echo -e " Virtual Environment: ${VENV_PATH}"
echo -e " ComfyUI Branch: ${COMFYUI_BRANCH}"
echo -e " Test Mode: ${TEST_MODE}"
if [ "$TEST_MODE" = "parallel" ]; then
echo -e " Number of Environments: ${NUM_ENVS}"
fi
echo -e " Test Timeout: ${TEST_TIMEOUT}s"
echo ""
# Change to project root
cd "$PROJECT_ROOT"
# Step 1: Validate virtual environment
echo -e "${YELLOW}Step 1: Validating virtual environment...${NC}"
if [ ! -f "${VENV_PATH}/bin/activate" ]; then
echo -e "${RED}✗ FATAL: Virtual environment not found at: ${VENV_PATH}${NC}"
echo -e "${YELLOW} Create it with: python3 -m venv ${VENV_PATH}${NC}"
exit 1
fi
source "${VENV_PATH}/bin/activate"
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "${RED}✗ FATAL: Virtual environment activation failed${NC}"
exit 1
fi
echo -e "${GREEN}✓ Virtual environment activated: ${VIRTUAL_ENV}${NC}"
echo ""
# Step 2: Check prerequisites
echo -e "${YELLOW}Step 2: Checking prerequisites...${NC}"
# Check uv
if ! command -v uv &> /dev/null; then
echo -e "${YELLOW}⚠ uv not found, installing...${NC}"
pip install uv
fi
echo -e "${GREEN}✓ uv is available${NC}"
# Check pytest
if ! command -v pytest &> /dev/null; then
echo -e "${YELLOW}⚠ pytest not found, installing...${NC}"
uv pip install pytest
fi
echo -e "${GREEN}✓ pytest is available${NC}"
echo ""
# Step 3: Set up test environments
echo -e "${YELLOW}Step 3: Setting up test environment(s)...${NC}"
export COMFYUI_BRANCH="$COMFYUI_BRANCH"
if [ "$TEST_MODE" = "parallel" ]; then
export NUM_ENVS="$NUM_ENVS"
if [ ! -f "tests/setup_parallel_test_envs.sh" ]; then
echo -e "${RED}✗ FATAL: setup_parallel_test_envs.sh not found${NC}"
exit 1
fi
./tests/setup_parallel_test_envs.sh
else
if [ ! -f "tests/setup_test_env.sh" ]; then
echo -e "${RED}✗ FATAL: setup_test_env.sh not found${NC}"
exit 1
fi
./tests/setup_test_env.sh
fi
echo ""
# Step 4: Run tests
echo -e "${YELLOW}Step 4: Running tests...${NC}"
export TEST_TIMEOUT="$TEST_TIMEOUT"
if [ "$TEST_MODE" = "parallel" ]; then
if [ ! -f "tests/run_parallel_tests.sh" ]; then
echo -e "${RED}✗ FATAL: run_parallel_tests.sh not found${NC}"
exit 1
fi
echo -e "${CYAN}Running distributed parallel tests across ${NUM_ENVS} environments...${NC}"
./tests/run_parallel_tests.sh
else
if [ ! -f "tests/run_tests.sh" ]; then
echo -e "${RED}✗ FATAL: run_tests.sh not found${NC}"
exit 1
fi
echo -e "${CYAN}Running tests in single environment...${NC}"
./tests/run_tests.sh
fi
# Step 5: Show results location
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${GREEN}✅ Test Execution Complete!${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
echo -e "${CYAN}Test Results Location:${NC}"
if [ "$TEST_MODE" = "parallel" ]; then
echo -e " Individual environment logs: ${YELLOW}/tmp/test-results-*.log${NC}"
echo -e " Server logs: ${YELLOW}/tmp/comfyui-parallel-*.log${NC}"
echo -e " Main execution log: ${YELLOW}/tmp/parallel_test_final.log${NC}"
echo ""
echo -e "${CYAN}Quick Result Summary:${NC}"
if ls /tmp/test-results-*.log 1> /dev/null 2>&1; then
total_passed=0
total_failed=0
for log in /tmp/test-results-*.log; do
if grep -q "passed" "$log"; then
passed=$(grep "passed" "$log" | tail -1 | grep -oP '\d+(?= passed)' || echo "0")
total_passed=$((total_passed + passed))
fi
if grep -q "failed" "$log"; then
failed=$(grep "failed" "$log" | tail -1 | grep -oP '\d+(?= failed)' || echo "0")
total_failed=$((total_failed + failed))
fi
done
echo -e " ${GREEN}Passed: ${total_passed}${NC}"
echo -e " ${RED}Failed: ${total_failed}${NC}"
fi
else
echo -e " Test results: ${YELLOW}/tmp/comfyui-test-results.log${NC}"
echo -e " Server log: ${YELLOW}/tmp/comfyui-server.log${NC}"
fi
echo ""
echo -e "${CYAN}View detailed results:${NC}"
if [ "$TEST_MODE" = "parallel" ]; then
echo -e " ${YELLOW}tail -100 /tmp/test-results-1.log${NC} # View environment 1 results"
echo -e " ${YELLOW}grep -E 'passed|failed|ERROR' /tmp/test-results-*.log${NC} # View all results"
else
echo -e " ${YELLOW}tail -100 /tmp/comfyui-test-results.log${NC}"
fi
echo ""

View File

@@ -1,333 +0,0 @@
#!/bin/bash
# ComfyUI Manager Parallel Test Runner
# Runs tests in parallel across multiple environments
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}ComfyUI Manager Parallel Test Suite${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Configuration
BASE_COMFYUI_PATH="${BASE_COMFYUI_PATH:-tests/env}"
ENV_INFO_FILE="${BASE_COMFYUI_PATH}/parallel_envs.conf"
TEST_TIMEOUT="${TEST_TIMEOUT:-3600}" # 60 minutes per environment
# Log directory (project-local instead of /tmp) - use absolute path
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
LOG_DIR="${PROJECT_ROOT}/tests/tmp"
mkdir -p "${LOG_DIR}"
# Clean old logs from previous runs (clean state guarantee)
rm -f "${LOG_DIR}"/test-results-*.log 2>/dev/null || true
rm -f "${LOG_DIR}"/comfyui-parallel-*.log 2>/dev/null || true
rm -f "${LOG_DIR}"/comfyui-parallel-*.pid 2>/dev/null || true
# Check if parallel environments are set up
if [ ! -f "${ENV_INFO_FILE}" ]; then
echo -e "${RED}✗ FATAL: Parallel environments not found${NC}"
echo -e "${RED} Expected: ${ENV_INFO_FILE}${NC}"
echo -e "${YELLOW} Please run setup first:${NC}"
echo -e "${CYAN} ./setup_parallel_test_envs.sh${NC}"
exit 1
fi
# Load configuration
source "${ENV_INFO_FILE}"
echo -e "${CYAN}Configuration:${NC}"
echo -e " Virtual Environment: ${VENV_PATH}"
echo -e " Base Path: ${BASE_COMFYUI_PATH}"
echo -e " Branch: ${COMFYUI_BRANCH}"
echo -e " Commit: ${COMFYUI_COMMIT:0:8}"
echo -e " Number of Environments: ${NUM_ENVS}"
echo -e " Port Range: ${BASE_PORT}-$((BASE_PORT + NUM_ENVS - 1))"
echo ""
# Validate virtual environment
if [ ! -f "${VENV_PATH}/bin/activate" ]; then
echo -e "${RED}✗ FATAL: Virtual environment not found${NC}"
echo -e "${RED} Expected: ${VENV_PATH}${NC}"
exit 1
fi
source "${VENV_PATH}/bin/activate"
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "${RED}✗ FATAL: Virtual environment activation failed${NC}"
exit 1
fi
echo -e "${GREEN}✓ Virtual environment activated${NC}"
PYTHON="${VENV_PATH}/bin/python"
PYTEST="${VENV_PATH}/bin/pytest"
PIP="${VENV_PATH}/bin/pip"
# Validate pytest
if [ ! -f "${PYTEST}" ]; then
echo -e "${RED}✗ FATAL: pytest not found${NC}"
exit 1
fi
echo -e "${GREEN}✓ pytest is available${NC}"
echo ""
# Step 1: Clean and reinstall package
echo -e "${YELLOW}📦 Step 1: Reinstalling comfyui-manager package and pytest-split...${NC}"
# Clean Python cache
find comfyui_manager -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find tests -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
# Reinstall package and pytest-split
if command -v uv &> /dev/null; then
uv pip install . > /dev/null
uv pip install pytest-split > /dev/null 2>&1 || echo -e "${YELLOW}⚠ pytest-split installation skipped${NC}"
else
"${PIP}" install . > /dev/null
"${PIP}" install pytest-split > /dev/null 2>&1 || echo -e "${YELLOW}⚠ pytest-split installation skipped${NC}"
fi
echo -e "${GREEN}✓ Package installed${NC}"
echo ""
# Function to check if server is running
check_server() {
local port=$1
curl -s "http://127.0.0.1:${port}/system_stats" > /dev/null 2>&1
}
# Function to wait for server (2-second intervals with better feedback)
wait_for_server() {
local port=$1
local max_wait=60
local count=0
while [ $count -lt $max_wait ]; do
if check_server $port; then
return 0
fi
sleep 2
count=$((count + 2))
# Show progress every 6 seconds
if [ $((count % 6)) -eq 0 ]; then
echo -ne "."
fi
done
echo "" # New line after dots
return 1
}
# Function to start server for an environment
start_server() {
local env_num=$1
local env_path_var="ENV_${env_num}_PATH"
local env_port_var="ENV_${env_num}_PORT"
local env_path="${!env_path_var}"
local env_port="${!env_port_var}"
echo -e "${CYAN}Starting server for environment ${env_num} on port ${env_port}...${NC}"
# Clean up old test packages
rm -rf "${env_path}/custom_nodes/ComfyUI_SigmoidOffsetScheduler" \
"${env_path}/custom_nodes/.disabled"/*[Ss]igmoid* 2>/dev/null || true
# Kill any existing process on this port
pkill -f "main.py.*--port ${env_port}" 2>/dev/null || true
sleep 1
# Detect frontend directory (old 'front' or new 'app')
local frontend_root="front"
if [ ! -d "${env_path}/front" ] && [ -d "${env_path}/app" ]; then
frontend_root="app"
fi
# Start server
cd "${env_path}"
nohup "${PYTHON}" main.py \
--enable-manager \
--enable-compress-response-body \
--front-end-root "${frontend_root}" \
--port "${env_port}" \
> "${LOG_DIR}/comfyui-parallel-${env_num}.log" 2>&1 &
local server_pid=$!
cd - > /dev/null
# Wait for server to be ready
if wait_for_server $env_port; then
echo -e "${GREEN}✓ Server ${env_num} ready on port ${env_port}${NC}"
echo $server_pid > "${LOG_DIR}/comfyui-parallel-${env_num}.pid"
return 0
else
echo -e "${RED}✗ Server ${env_num} failed to start${NC}"
return 1
fi
}
# Function to stop server
stop_server() {
local env_num=$1
local pid_file="${LOG_DIR}/comfyui-parallel-${env_num}.pid"
local env_port_var="ENV_${env_num}_PORT"
local env_port="${!env_port_var}"
if [ -f "$pid_file" ]; then
local pid=$(cat "$pid_file")
if kill -0 "$pid" 2>/dev/null; then
kill "$pid" 2>/dev/null || true
fi
rm -f "$pid_file"
fi
# Kill by port pattern as backup
pkill -f "main.py.*--port ${env_port}" 2>/dev/null || true
}
# Function to run tests for an environment with test distribution
run_tests_for_env() {
local env_num=$1
local env_name_var="ENV_${env_num}_NAME"
local env_path_var="ENV_${env_num}_PATH"
local env_port_var="ENV_${env_num}_PORT"
local env_name="${!env_name_var}"
local env_path="${!env_path_var}"
local env_port="${!env_port_var}"
echo -e "${YELLOW}🧪 Running tests for ${env_name} (port ${env_port}) - Split ${env_num}/${NUM_ENVS}...${NC}"
# Run tests with environment variables explicitly set
# Use pytest-split to distribute tests across environments
# With timing-based distribution for optimal load balancing
local log_file="${LOG_DIR}/test-results-${env_num}.log"
if timeout "${TEST_TIMEOUT}" env \
COMFYUI_PATH="${env_path}" \
COMFYUI_CUSTOM_NODES_PATH="${env_path}/custom_nodes" \
TEST_SERVER_PORT="${env_port}" \
"${PYTEST}" \
tests/glob/ \
--splits ${NUM_ENVS} \
--group ${env_num} \
--splitting-algorithm=least_duration \
--durations-path=tests/.test_durations \
-v \
--tb=short \
--color=yes \
> "$log_file" 2>&1; then
echo -e "${GREEN}✓ Tests passed for ${env_name} (split ${env_num})${NC}"
return 0
else
local exit_code=$?
echo -e "${RED}✗ Tests failed for ${env_name} (exit code: ${exit_code})${NC}"
echo -e "${YELLOW} See log: ${log_file}${NC}"
return 1
fi
}
# Step 2: Start all servers
echo -e "${YELLOW}🚀 Step 2: Starting all servers...${NC}"
declare -a server_pids
all_servers_started=true
for i in $(seq 1 $NUM_ENVS); do
if ! start_server $i; then
all_servers_started=false
echo -e "${RED}✗ Failed to start server ${i}${NC}"
break
fi
echo ""
done
if [ "$all_servers_started" = false ]; then
echo -e "${RED}✗ Server startup failed, cleaning up...${NC}"
for i in $(seq 1 $NUM_ENVS); do
stop_server $i
done
exit 1
fi
echo -e "${GREEN}✓ All servers started successfully${NC}"
echo ""
# Step 3: Run tests in parallel
echo -e "${YELLOW}🧪 Step 3: Running tests in parallel...${NC}"
echo ""
declare -a test_pids
declare -a test_results
# Start all test runs in background
for i in $(seq 1 $NUM_ENVS); do
run_tests_for_env $i &
test_pids[$i]=$!
done
# Wait for all tests to complete and collect results
for i in $(seq 1 $NUM_ENVS); do
if wait ${test_pids[$i]}; then
test_results[$i]=0
else
test_results[$i]=1
fi
done
echo ""
# Step 4: Stop all servers
echo -e "${YELLOW}🧹 Step 4: Stopping all servers...${NC}"
for i in $(seq 1 $NUM_ENVS); do
stop_server $i
echo -e "${GREEN}✓ Server ${i} stopped${NC}"
done
echo ""
# Step 5: Report results
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Test Results Summary${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
passed_count=0
failed_count=0
for i in $(seq 1 $NUM_ENVS); do
env_name_var="ENV_${i}_NAME"
env_name="${!env_name_var}"
env_port_var="ENV_${i}_PORT"
env_port="${!env_port_var}"
if [ ${test_results[$i]} -eq 0 ]; then
echo -e "${GREEN}${env_name} (port ${env_port}): PASSED${NC}"
passed_count=$((passed_count + 1))
else
echo -e "${RED}${env_name} (port ${env_port}): FAILED${NC}"
echo -e "${YELLOW} Log: ${LOG_DIR}/test-results-${i}.log${NC}"
failed_count=$((failed_count + 1))
fi
done
echo ""
echo -e "Summary:"
echo -e " Total Environments: ${NUM_ENVS}"
echo -e " Passed: ${GREEN}${passed_count}${NC}"
echo -e " Failed: ${RED}${failed_count}${NC}"
echo ""
if [ $failed_count -eq 0 ]; then
echo -e "${GREEN}✅ All parallel tests PASSED${NC}"
exit 0
else
echo -e "${RED}❌ Some parallel tests FAILED${NC}"
exit 1
fi

View File

@@ -1,248 +0,0 @@
#!/bin/bash
# ComfyUI Manager Test Suite Runner
# Runs the complete test suite with environment validation
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}ComfyUI Manager Test Suite${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Configuration
VENV_PATH="${VENV_PATH:-$HOME/venv}"
COMFYUI_PATH="${COMFYUI_PATH:-tests/env/ComfyUI}"
TEST_SERVER_PORT="${TEST_SERVER_PORT:-8188}"
TEST_TIMEOUT="${TEST_TIMEOUT:-3600}" # 60 minutes
PYTHON="${VENV_PATH}/bin/python"
PYTEST="${VENV_PATH}/bin/pytest"
PIP="${VENV_PATH}/bin/pip"
# Export environment variables for pytest
export COMFYUI_PATH
export COMFYUI_CUSTOM_NODES_PATH="${COMFYUI_PATH}/custom_nodes"
export TEST_SERVER_PORT
# Function to check if server is running
check_server() {
curl -s "http://127.0.0.1:${TEST_SERVER_PORT}/system_stats" > /dev/null 2>&1
}
# Function to wait for server to be ready
wait_for_server() {
local max_wait=60
local count=0
echo -e "${YELLOW}⏳ Waiting for ComfyUI server to be ready...${NC}"
while [ $count -lt $max_wait ]; do
if check_server; then
echo -e "${GREEN}✓ Server is ready${NC}"
return 0
fi
sleep 2
count=$((count + 2))
echo -n "."
done
echo ""
echo -e "${RED}✗ Server failed to start within ${max_wait} seconds${NC}"
return 1
}
# Step 0: Validate environment
echo -e "${YELLOW}🔍 Step 0: Validating environment...${NC}"
# Check if virtual environment exists
if [ ! -f "${VENV_PATH}/bin/activate" ]; then
echo -e "${RED}✗ FATAL: Virtual environment not found${NC}"
echo -e "${RED} Expected: ${VENV_PATH}/bin/activate${NC}"
echo -e "${YELLOW} Please run setup first:${NC}"
echo -e "${CYAN} ./setup_test_env.sh${NC}"
exit 1
fi
# Activate virtual environment
source "${VENV_PATH}/bin/activate"
# Validate virtual environment is activated
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "${RED}✗ FATAL: Virtual environment is not activated${NC}"
echo -e "${RED} Expected: ${VENV_PATH}${NC}"
echo -e "${YELLOW} Please check your virtual environment setup${NC}"
exit 1
fi
echo -e "${GREEN}✓ Virtual environment activated: ${VIRTUAL_ENV}${NC}"
# Check if ComfyUI exists
if [ ! -d "${COMFYUI_PATH}" ]; then
echo -e "${RED}✗ FATAL: ComfyUI not found${NC}"
echo -e "${RED} Expected: ${COMFYUI_PATH}${NC}"
echo -e "${YELLOW} Please run setup first:${NC}"
echo -e "${CYAN} ./setup_test_env.sh${NC}"
exit 1
fi
echo -e "${GREEN}✓ ComfyUI exists: ${COMFYUI_PATH}${NC}"
# Validate ComfyUI frontend directory (support both old 'front' and new 'app' structures)
if [ ! -d "${COMFYUI_PATH}/front" ] && [ ! -d "${COMFYUI_PATH}/app" ]; then
echo -e "${RED}✗ FATAL: ComfyUI frontend directory not found${NC}"
echo -e "${RED} Expected: ${COMFYUI_PATH}/front or ${COMFYUI_PATH}/app${NC}"
echo -e "${RED} This directory is required for ComfyUI to run${NC}"
echo -e "${YELLOW} Please re-run setup:${NC}"
echo -e "${CYAN} rm -rf ${COMFYUI_PATH}${NC}"
echo -e "${CYAN} ./setup_test_env.sh${NC}"
exit 1
fi
if [ -d "${COMFYUI_PATH}/front" ]; then
echo -e "${GREEN}✓ ComfyUI frontend directory exists (old structure)${NC}"
else
echo -e "${GREEN}✓ ComfyUI frontend directory exists (new structure)${NC}"
fi
# Validate ComfyUI main.py
if [ ! -f "${COMFYUI_PATH}/main.py" ]; then
echo -e "${RED}✗ FATAL: ComfyUI main.py not found${NC}"
echo -e "${RED} Expected: ${COMFYUI_PATH}/main.py${NC}"
echo -e "${YELLOW} Please re-run setup:${NC}"
echo -e "${CYAN} ./setup_test_env.sh${NC}"
exit 1
fi
echo -e "${GREEN}✓ ComfyUI main.py exists${NC}"
# Check pytest availability
if [ ! -f "${PYTEST}" ]; then
echo -e "${RED}✗ FATAL: pytest not found${NC}"
echo -e "${RED} Expected: ${PYTEST}${NC}"
echo -e "${YELLOW} Please install test dependencies:${NC}"
echo -e "${CYAN} source ${VENV_PATH}/bin/activate${NC}"
echo -e "${CYAN} pip install -e \".[dev]\"${NC}"
exit 1
fi
echo -e "${GREEN}✓ pytest is available${NC}"
echo ""
# Step 1: Clean up old test packages
echo -e "${YELLOW}📦 Step 1: Cleaning up old test packages...${NC}"
rm -rf "${COMFYUI_PATH}/custom_nodes/ComfyUI_SigmoidOffsetScheduler" \
"${COMFYUI_PATH}/custom_nodes/.disabled"/*[Ss]igmoid* 2>/dev/null || true
echo -e "${GREEN}✓ Cleanup complete${NC}"
echo ""
# Step 2: Clean Python cache
echo -e "${YELLOW}🗑️ Step 2: Cleaning Python cache...${NC}"
find comfyui_manager -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find tests -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
echo -e "${GREEN}✓ Cache cleaned${NC}"
echo ""
# Step 3: Install/reinstall package
echo -e "${YELLOW}📦 Step 3: Installing comfyui-manager package...${NC}"
# Check if uv is available
if command -v uv &> /dev/null; then
uv pip install .
else
echo -e "${YELLOW}⚠ uv not found, using pip${NC}"
"${PIP}" install .
fi
echo -e "${GREEN}✓ Package installed${NC}"
echo ""
# Step 4: Check if server is already running
echo -e "${YELLOW}🔍 Step 4: Checking for running server...${NC}"
if check_server; then
echo -e "${GREEN}✓ Server already running on port ${TEST_SERVER_PORT}${NC}"
SERVER_STARTED_BY_SCRIPT=false
else
echo -e "${YELLOW}Starting ComfyUI server...${NC}"
# Kill any existing server processes
pkill -f "ComfyUI/main.py" 2>/dev/null || true
sleep 2
# Detect frontend directory (old 'front' or new 'app')
FRONTEND_ROOT="front"
if [ ! -d "${COMFYUI_PATH}/front" ] && [ -d "${COMFYUI_PATH}/app" ]; then
FRONTEND_ROOT="app"
fi
# Start server in background
cd "${COMFYUI_PATH}"
nohup "${PYTHON}" main.py \
--enable-manager \
--enable-compress-response-body \
--front-end-root "${FRONTEND_ROOT}" \
--port "${TEST_SERVER_PORT}" \
> /tmp/comfyui-test-server.log 2>&1 &
SERVER_PID=$!
cd - > /dev/null
SERVER_STARTED_BY_SCRIPT=true
# Wait for server to be ready
if ! wait_for_server; then
echo -e "${RED}✗ Server failed to start${NC}"
echo -e "${YELLOW}Check logs at: /tmp/comfyui-test-server.log${NC}"
echo -e "${YELLOW}Last 20 lines of log:${NC}"
tail -20 /tmp/comfyui-test-server.log
exit 1
fi
fi
echo ""
# Step 5: Run tests
echo -e "${YELLOW}🧪 Step 5: Running test suite...${NC}"
echo -e "${BLUE}Running: pytest tests/glob/ tests/test_case_sensitivity_integration.py${NC}"
echo ""
# Run pytest with timeout
TEST_START=$(date +%s)
if timeout "${TEST_TIMEOUT}" "${PYTEST}" \
tests/glob/ \
tests/test_case_sensitivity_integration.py \
-v \
--tb=short \
--color=yes; then
TEST_RESULT=0
else
TEST_RESULT=$?
fi
TEST_END=$(date +%s)
TEST_DURATION=$((TEST_END - TEST_START))
echo ""
echo -e "${BLUE}========================================${NC}"
# Step 6: Report results
if [ $TEST_RESULT -eq 0 ]; then
echo -e "${GREEN}✅ All tests PASSED${NC}"
echo -e "${GREEN}Test duration: ${TEST_DURATION} seconds${NC}"
else
echo -e "${RED}❌ Tests FAILED${NC}"
echo -e "${RED}Exit code: ${TEST_RESULT}${NC}"
echo -e "${YELLOW}Check output above for details${NC}"
fi
echo -e "${BLUE}========================================${NC}"
echo ""
# Step 7: Cleanup if we started the server
if [ "$SERVER_STARTED_BY_SCRIPT" = true ]; then
echo -e "${YELLOW}🧹 Cleaning up test server...${NC}"
if [ -n "$SERVER_PID" ] && kill -0 "$SERVER_PID" 2>/dev/null; then
kill "$SERVER_PID" 2>/dev/null || true
fi
pkill -f "ComfyUI/main.py" 2>/dev/null || true
echo -e "${GREEN}✓ Server stopped${NC}"
fi
exit $TEST_RESULT

View File

@@ -1,252 +0,0 @@
#!/bin/bash
# ComfyUI Manager Parallel Test Environment Setup
# Sets up multiple test environments for parallel testing
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}ComfyUI Manager Parallel Environment Setup${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Configuration
VENV_PATH="${VENV_PATH:-$HOME/venv}"
BASE_COMFYUI_PATH="${BASE_COMFYUI_PATH:-tests/env}"
COMFYUI_BRANCH="${COMFYUI_BRANCH:-master}"
COMFYUI_REPO="${COMFYUI_REPO:-https://github.com/comfyanonymous/ComfyUI.git}"
NUM_ENVS="${NUM_ENVS:-3}" # Number of parallel environments
BASE_PORT="${BASE_PORT:-8188}" # Starting port number
PIP="${VENV_PATH}/bin/pip"
echo -e "${CYAN}Configuration:${NC}"
echo -e " VENV_PATH: ${VENV_PATH}"
echo -e " BASE_COMFYUI_PATH: ${BASE_COMFYUI_PATH}"
echo -e " COMFYUI_BRANCH: ${COMFYUI_BRANCH}"
echo -e " COMFYUI_REPO: ${COMFYUI_REPO}"
echo -e " NUM_ENVS: ${NUM_ENVS}"
echo -e " BASE_PORT: ${BASE_PORT}"
echo ""
# Validate NUM_ENVS
if [ "$NUM_ENVS" -lt 1 ] || [ "$NUM_ENVS" -gt 10 ]; then
echo -e "${RED}✗ FATAL: NUM_ENVS must be between 1 and 10${NC}"
echo -e "${RED} Current value: ${NUM_ENVS}${NC}"
exit 1
fi
# Step 1: Setup shared virtual environment
echo -e "${YELLOW}📦 Step 1: Setting up shared virtual environment...${NC}"
if [ ! -f "${VENV_PATH}/bin/activate" ]; then
echo -e "${CYAN}Creating virtual environment at: ${VENV_PATH}${NC}"
python3 -m venv "${VENV_PATH}"
echo -e "${GREEN}✓ Virtual environment created${NC}"
# Activate and install uv
source "${VENV_PATH}/bin/activate"
echo -e "${CYAN}Installing uv package manager...${NC}"
"${PIP}" install uv
echo -e "${GREEN}✓ uv installed${NC}"
else
echo -e "${GREEN}✓ Virtual environment already exists${NC}"
source "${VENV_PATH}/bin/activate"
fi
# Validate virtual environment is activated
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "${RED}✗ FATAL: Virtual environment activation failed${NC}"
echo -e "${RED} Expected path: ${VENV_PATH}${NC}"
exit 1
fi
echo -e "${GREEN}✓ Virtual environment activated: ${VIRTUAL_ENV}${NC}"
echo ""
# Step 2: Setup first ComfyUI environment (reference)
echo -e "${YELLOW}🔧 Step 2: Setting up reference ComfyUI environment...${NC}"
REFERENCE_PATH="${BASE_COMFYUI_PATH}/ComfyUI"
# Create base directory
if [ ! -d "${BASE_COMFYUI_PATH}" ]; then
mkdir -p "${BASE_COMFYUI_PATH}"
fi
# Clone or update reference ComfyUI
if [ ! -d "${REFERENCE_PATH}" ]; then
echo -e "${CYAN}Cloning ComfyUI repository...${NC}"
echo -e " Repository: ${COMFYUI_REPO}"
echo -e " Branch: ${COMFYUI_BRANCH}"
git clone --branch "${COMFYUI_BRANCH}" "${COMFYUI_REPO}" "${REFERENCE_PATH}"
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ ComfyUI cloned successfully${NC}"
else
echo -e "${RED}✗ Failed to clone ComfyUI${NC}"
exit 1
fi
else
echo -e "${GREEN}✓ Reference ComfyUI already exists${NC}"
# Check branch and switch if needed
if [ -d "${REFERENCE_PATH}/.git" ]; then
cd "${REFERENCE_PATH}"
current_branch=$(git branch --show-current)
echo -e " Current branch: ${current_branch}"
if [ "${current_branch}" != "${COMFYUI_BRANCH}" ]; then
echo -e "${YELLOW}⚠ Switching to branch: ${COMFYUI_BRANCH}${NC}"
git fetch origin || true
git checkout "${COMFYUI_BRANCH}"
# Only pull if it's a tracking branch
if git rev-parse --abbrev-ref --symbolic-full-name @{u} >/dev/null 2>&1; then
git pull origin "${COMFYUI_BRANCH}" || true
fi
echo -e "${GREEN}✓ Switched to branch: ${COMFYUI_BRANCH}${NC}"
fi
cd - > /dev/null
fi
fi
# Get current commit hash for consistency
cd "${REFERENCE_PATH}"
REFERENCE_COMMIT=$(git rev-parse HEAD)
REFERENCE_BRANCH=$(git branch --show-current)
echo -e "${CYAN} Reference commit: ${REFERENCE_COMMIT:0:8}${NC}"
echo -e "${CYAN} Reference branch: ${REFERENCE_BRANCH}${NC}"
cd - > /dev/null
# Install ComfyUI dependencies
echo -e "${CYAN}Installing ComfyUI dependencies...${NC}"
if [ -f "${REFERENCE_PATH}/requirements.txt" ]; then
"${PIP}" install -r "${REFERENCE_PATH}/requirements.txt" > /dev/null 2>&1 || {
echo -e "${YELLOW}⚠ Some ComfyUI dependencies may have failed to install${NC}"
}
echo -e "${GREEN}✓ ComfyUI dependencies installed${NC}"
fi
# Validate reference environment (support both old 'front' and new 'app' structures)
if [ ! -d "${REFERENCE_PATH}/front" ] && [ ! -d "${REFERENCE_PATH}/app" ]; then
echo -e "${RED}✗ FATAL: Reference ComfyUI frontend directory not found (neither 'front' nor 'app')${NC}"
exit 1
fi
if [ -d "${REFERENCE_PATH}/front" ]; then
echo -e "${GREEN}✓ Reference ComfyUI validated (old structure with 'front')${NC}"
else
echo -e "${GREEN}✓ Reference ComfyUI validated (new structure with 'app')${NC}"
fi
echo ""
# Step 3: Create parallel environments
echo -e "${YELLOW}🔀 Step 3: Creating ${NUM_ENVS} parallel environments...${NC}"
for i in $(seq 1 $NUM_ENVS); do
ENV_NAME="ComfyUI_${i}"
ENV_PATH="${BASE_COMFYUI_PATH}/${ENV_NAME}"
PORT=$((BASE_PORT + i - 1))
echo -e "${CYAN}Creating environment ${i}/${NUM_ENVS}: ${ENV_NAME} (port: ${PORT})${NC}"
# Remove existing environment if exists
if [ -d "${ENV_PATH}" ]; then
echo -e "${YELLOW} Removing existing environment...${NC}"
rm -rf "${ENV_PATH}"
fi
# Create new environment by copying reference (excluding .git for efficiency)
echo -e " Copying from reference (excluding .git)..."
mkdir -p "${ENV_PATH}"
rsync -a --exclude='.git' "${REFERENCE_PATH}/" "${ENV_PATH}/"
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Failed to copy reference environment${NC}"
exit 1
fi
# Create custom_nodes directory
mkdir -p "${ENV_PATH}/custom_nodes"
# Validate environment (support both old 'front' and new 'app' structures)
if [ ! -d "${ENV_PATH}/front" ] && [ ! -d "${ENV_PATH}/app" ]; then
echo -e "${RED}✗ Environment ${i} validation failed: missing frontend directory${NC}"
exit 1
fi
if [ ! -f "${ENV_PATH}/main.py" ]; then
echo -e "${RED}✗ Environment ${i} validation failed: missing main.py${NC}"
exit 1
fi
echo -e "${GREEN}✓ Environment ${i} created and validated${NC}"
echo ""
done
# Step 4: Create environment info file
echo -e "${YELLOW}📝 Step 4: Creating environment configuration file...${NC}"
ENV_INFO_FILE="${BASE_COMFYUI_PATH}/parallel_envs.conf"
cat > "${ENV_INFO_FILE}" << EOF
# Parallel Test Environments Configuration
# Generated: $(date)
VENV_PATH="${VENV_PATH}"
BASE_COMFYUI_PATH="${BASE_COMFYUI_PATH}"
COMFYUI_BRANCH="${COMFYUI_BRANCH}"
COMFYUI_COMMIT="${REFERENCE_COMMIT}"
NUM_ENVS=${NUM_ENVS}
BASE_PORT=${BASE_PORT}
# Environment details
EOF
for i in $(seq 1 $NUM_ENVS); do
ENV_NAME="ComfyUI_${i}"
ENV_PATH="${BASE_COMFYUI_PATH}/${ENV_NAME}"
PORT=$((BASE_PORT + i - 1))
cat >> "${ENV_INFO_FILE}" << EOF
ENV_${i}_NAME="${ENV_NAME}"
ENV_${i}_PATH="${ENV_PATH}"
ENV_${i}_PORT=${PORT}
EOF
done
echo -e "${GREEN}✓ Configuration saved to: ${ENV_INFO_FILE}${NC}"
echo ""
# Final summary
echo -e "${BLUE}========================================${NC}"
echo -e "${GREEN}✅ Parallel Environments Setup Complete!${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
echo -e "Setup Summary:"
echo -e " Virtual Environment: ${GREEN}${VENV_PATH}${NC}"
echo -e " Reference ComfyUI: ${GREEN}${REFERENCE_PATH}${NC}"
echo -e " Branch: ${GREEN}${REFERENCE_BRANCH}${NC}"
echo -e " Commit: ${GREEN}${REFERENCE_COMMIT:0:8}${NC}"
echo -e " Number of Environments: ${GREEN}${NUM_ENVS}${NC}"
echo -e " Port Range: ${GREEN}${BASE_PORT}-$((BASE_PORT + NUM_ENVS - 1))${NC}"
echo ""
echo -e "Parallel Environments:"
for i in $(seq 1 $NUM_ENVS); do
ENV_NAME="ComfyUI_${i}"
ENV_PATH="${BASE_COMFYUI_PATH}/${ENV_NAME}"
PORT=$((BASE_PORT + i - 1))
echo -e " ${i}. ${CYAN}${ENV_NAME}${NC} → Port ${GREEN}${PORT}${NC}${ENV_PATH}"
done
echo ""
echo -e "Configuration file: ${GREEN}${ENV_INFO_FILE}${NC}"
echo ""
echo -e "To run parallel tests:"
echo -e " ${CYAN}./run_parallel_tests.sh${NC}"
echo ""

View File

@@ -1,181 +1,75 @@
#!/bin/bash
# ComfyUI Manager Test Environment Setup
# Sets up virtual environment and ComfyUI for testing
set -e # Exit on error
# Test Environment Setup Script for pip_util.py
# Creates isolated venv to prevent environment corruption
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
set -e
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}ComfyUI Manager Environment Setup${NC}"
echo -e "${BLUE}========================================${NC}"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VENV_DIR="${SCRIPT_DIR}/test_venv"
echo "=================================================="
echo "pip_util.py Test Environment Setup"
echo "=================================================="
echo ""
# Configuration
VENV_PATH="${VENV_PATH:-$HOME/venv}"
COMFYUI_PATH="${COMFYUI_PATH:-tests/env/ComfyUI}"
COMFYUI_BRANCH="${COMFYUI_BRANCH:-master}"
COMFYUI_REPO="${COMFYUI_REPO:-https://github.com/comfyanonymous/ComfyUI.git}"
PIP="${VENV_PATH}/bin/pip"
echo -e "${CYAN}Configuration:${NC}"
echo -e " VENV_PATH: ${VENV_PATH}"
echo -e " COMFYUI_PATH: ${COMFYUI_PATH}"
echo -e " COMFYUI_BRANCH: ${COMFYUI_BRANCH}"
echo -e " COMFYUI_REPO: ${COMFYUI_REPO}"
echo ""
# Step 1: Check/Create virtual environment
echo -e "${YELLOW}📦 Step 1: Setting up virtual environment...${NC}"
if [ ! -f "${VENV_PATH}/bin/activate" ]; then
echo -e "${CYAN}Creating virtual environment at: ${VENV_PATH}${NC}"
python3 -m venv "${VENV_PATH}"
echo -e "${GREEN}✓ Virtual environment created${NC}"
# Activate and install uv
source "${VENV_PATH}/bin/activate"
echo -e "${CYAN}Installing uv package manager...${NC}"
"${PIP}" install uv
echo -e "${GREEN}✓ uv installed${NC}"
# Check Python version
PYTHON_CMD=""
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
elif command -v python &> /dev/null; then
PYTHON_CMD="python"
else
echo -e "${GREEN}✓ Virtual environment already exists${NC}"
source "${VENV_PATH}/bin/activate"
fi
# Validate virtual environment is activated
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "${RED}✗ FATAL: Virtual environment activation failed${NC}"
echo -e "${RED} Expected path: ${VENV_PATH}${NC}"
echo "❌ Error: Python not found. Please install Python 3.8 or higher."
exit 1
fi
echo -e "${GREEN}✓ Virtual environment activated: ${VIRTUAL_ENV}${NC}"
echo ""
# Step 2: Setup ComfyUI
echo -e "${YELLOW}🔧 Step 2: Setting up ComfyUI...${NC}"
PYTHON_VERSION=$($PYTHON_CMD --version 2>&1 | awk '{print $2}')
echo "✓ Found Python: $PYTHON_VERSION"
# Create environment directory if it doesn't exist
env_dir=$(dirname "${COMFYUI_PATH}")
if [ ! -d "${env_dir}" ]; then
echo -e "${CYAN}Creating environment directory: ${env_dir}${NC}"
mkdir -p "${env_dir}"
fi
# Check if ComfyUI exists
if [ ! -d "${COMFYUI_PATH}" ]; then
echo -e "${CYAN}Cloning ComfyUI repository...${NC}"
echo -e " Repository: ${COMFYUI_REPO}"
echo -e " Branch: ${COMFYUI_BRANCH}"
git clone --branch "${COMFYUI_BRANCH}" "${COMFYUI_REPO}" "${COMFYUI_PATH}"
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ ComfyUI cloned successfully${NC}"
# Remove existing venv if present
if [ -d "$VENV_DIR" ]; then
echo ""
read -p "⚠️ Existing test venv found. Remove and recreate? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "🗑️ Removing existing venv..."
rm -rf "$VENV_DIR"
else
echo -e "${RED}✗ Failed to clone ComfyUI${NC}"
exit 1
fi
else
echo -e "${GREEN}✓ ComfyUI already exists at: ${COMFYUI_PATH}${NC}"
# Check if it's a git repository and handle branch switching
if [ -d "${COMFYUI_PATH}/.git" ]; then
cd "${COMFYUI_PATH}"
current_branch=$(git branch --show-current)
echo -e " Current branch: ${current_branch}"
# Switch branch if requested and different
if [ "${current_branch}" != "${COMFYUI_BRANCH}" ]; then
echo -e "${YELLOW}⚠ Requested branch '${COMFYUI_BRANCH}' differs from current '${current_branch}'${NC}"
echo -e "${CYAN}Switching to branch: ${COMFYUI_BRANCH}${NC}"
git fetch origin
git checkout "${COMFYUI_BRANCH}"
git pull origin "${COMFYUI_BRANCH}"
echo -e "${GREEN}✓ Switched to branch: ${COMFYUI_BRANCH}${NC}"
fi
cd - > /dev/null
echo "Keeping existing venv. Skipping creation."
exit 0
fi
fi
# Create venv
echo ""
echo "📦 Creating virtual environment..."
$PYTHON_CMD -m venv "$VENV_DIR"
# Step 3: Install ComfyUI dependencies
echo -e "${YELLOW}📦 Step 3: Installing ComfyUI dependencies...${NC}"
# Activate venv
echo "🔌 Activating virtual environment..."
source "${VENV_DIR}/bin/activate"
if [ ! -f "${COMFYUI_PATH}/requirements.txt" ]; then
echo -e "${RED}✗ ComfyUI requirements.txt not found${NC}"
echo -e "${RED} Expected: ${COMFYUI_PATH}/requirements.txt${NC}"
exit 1
fi
# Upgrade pip
echo "⬆️ Upgrading pip..."
pip install --upgrade pip
"${PIP}" install -r "${COMFYUI_PATH}/requirements.txt" > /dev/null 2>&1 || {
echo -e "${YELLOW}⚠ Some ComfyUI dependencies may have failed to install${NC}"
echo -e "${YELLOW} This is usually OK for testing${NC}"
}
echo -e "${GREEN}✓ ComfyUI dependencies installed${NC}"
# Install test dependencies
echo ""
echo "📚 Installing test dependencies..."
pip install -r "${SCRIPT_DIR}/requirements.txt"
# Step 4: Create required directories
echo -e "${YELLOW}📁 Step 4: Creating required directories...${NC}"
if [ ! -d "${COMFYUI_PATH}/custom_nodes" ]; then
mkdir -p "${COMFYUI_PATH}/custom_nodes"
echo -e "${GREEN}✓ Created custom_nodes directory${NC}"
else
echo -e "${GREEN}✓ custom_nodes directory exists${NC}"
fi
echo ""
# Step 5: Validate environment
echo -e "${YELLOW}✅ Step 5: Validating environment...${NC}"
# Check frontend directory (support both old 'front' and new 'app' structures)
if [ ! -d "${COMFYUI_PATH}/front" ] && [ ! -d "${COMFYUI_PATH}/app" ]; then
echo -e "${RED}✗ FATAL: ComfyUI frontend directory not found${NC}"
echo -e "${RED} Expected: ${COMFYUI_PATH}/front or ${COMFYUI_PATH}/app${NC}"
echo -e "${RED} This directory is required for ComfyUI to run${NC}"
echo -e "${YELLOW} Possible causes:${NC}"
echo -e "${YELLOW} - Incomplete ComfyUI clone${NC}"
echo -e "${YELLOW} - Wrong branch checked out${NC}"
echo -e "${YELLOW} - ComfyUI repository structure changed${NC}"
echo -e "${YELLOW} Try:${NC}"
echo -e "${YELLOW} rm -rf ${COMFYUI_PATH}${NC}"
echo -e "${YELLOW} ./setup_test_env.sh # Will re-clone ComfyUI${NC}"
exit 1
fi
if [ -d "${COMFYUI_PATH}/front" ]; then
echo -e "${GREEN}✓ ComfyUI frontend directory exists (old structure)${NC}"
else
echo -e "${GREEN}✓ ComfyUI frontend directory exists (new structure)${NC}"
fi
# Check main.py
if [ ! -f "${COMFYUI_PATH}/main.py" ]; then
echo -e "${RED}✗ FATAL: ComfyUI main.py not found${NC}"
echo -e "${RED} Expected: ${COMFYUI_PATH}/main.py${NC}"
exit 1
fi
echo -e "${GREEN}✓ ComfyUI main.py exists${NC}"
echo "=================================================="
echo "✅ Test environment setup complete!"
echo "=================================================="
echo ""
# Final summary
echo -e "${BLUE}========================================${NC}"
echo -e "${GREEN}✅ Environment Setup Complete!${NC}"
echo -e "${BLUE}========================================${NC}"
echo "To activate the test environment:"
echo " source ${VENV_DIR}/bin/activate"
echo ""
echo -e "Environment is ready for testing."
echo -e ""
echo -e "To run tests:"
echo -e " ${CYAN}./run_tests.sh${NC}"
echo "To run tests:"
echo " pytest"
echo ""
echo -e "Configuration:"
echo -e " Virtual Environment: ${GREEN}${VENV_PATH}${NC}"
echo -e " ComfyUI Path: ${GREEN}${COMFYUI_PATH}${NC}"
echo -e " ComfyUI Branch: ${GREEN}${COMFYUI_BRANCH}${NC}"
echo "To deactivate:"
echo " deactivate"
echo ""

View File

@@ -1,101 +0,0 @@
#!/bin/bash
# Update test durations for optimal parallel distribution
# Run this when tests are added/modified/removed
set -e
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Test Duration Update${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Check if virtual environment is activated
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "${YELLOW}Activating virtual environment...${NC}"
source ~/venv/bin/activate
fi
# Project root
cd /mnt/teratera/git/comfyui-manager
# Clean up
echo -e "${YELLOW}Cleaning up processes and cache...${NC}"
pkill -f "ComfyUI/main.py" 2>/dev/null || true
sleep 2
find comfyui_manager -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find tests -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
# Reinstall package
echo -e "${YELLOW}Reinstalling package...${NC}"
if command -v uv &> /dev/null; then
uv pip install . > /dev/null
else
pip install . > /dev/null
fi
# Start test server
echo -e "${YELLOW}Starting test server...${NC}"
cd tests/env/ComfyUI_1
nohup python main.py \
--enable-manager \
--enable-compress-response-body \
--front-end-root front \
--port 8188 \
> /tmp/duration-update-server.log 2>&1 &
SERVER_PID=$!
cd - > /dev/null
# Wait for server
echo -e "${YELLOW}Waiting for server to be ready...${NC}"
for i in {1..30}; do
if curl -s "http://127.0.0.1:8188/system_stats" > /dev/null 2>&1; then
echo -e "${GREEN}✓ Server ready${NC}"
break
fi
sleep 2
echo -ne "."
done
echo ""
# Run tests to collect durations
echo -e "${YELLOW}Running tests to collect duration data...${NC}"
echo -e "${YELLOW}This may take 15-20 minutes...${NC}"
pytest tests/glob/ tests/test_case_sensitivity_integration.py \
--store-durations \
--durations-path=tests/.test_durations \
-v \
--tb=short \
> /tmp/duration-update.log 2>&1
EXIT_CODE=$?
# Stop server
pkill -f "ComfyUI/main.py" 2>/dev/null || true
sleep 2
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}✓ Duration data updated successfully${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "Updated file: ${BLUE}tests/.test_durations${NC}"
echo -e "Test count: $(jq 'length' tests/.test_durations 2>/dev/null || echo 'N/A')"
echo ""
echo -e "${YELLOW}Commit the updated .test_durations file:${NC}"
echo -e " git add tests/.test_durations"
echo -e " git commit -m 'chore: update test duration data'"
else
echo -e "${RED}✗ Failed to update duration data${NC}"
echo -e "${YELLOW}Check log: /tmp/duration-update.log${NC}"
exit 1
fi