From 199c9f742cefbc790c5a0c4bcb6901c6ac0420c4 Mon Sep 17 00:00:00 2001 From: Will Miao Date: Sun, 8 Feb 2026 08:30:57 +0800 Subject: [PATCH] feat(docs): update AGENTS.md with improved testing and development instructions - Simplify pytest coverage command by consolidating --cov flags - Remove redundant JSON coverage report - Reorganize frontend section into "Frontend Development (Standalone Web UI)" and "Vue Widget Development" - Add npm commands for Vue widget development (dev, build, typecheck, tests) - Consolidate Python code style sections (imports, formatting, naming, error handling, async) - Update architecture overview with clearer service descriptions - Fix truncated line in API endpoints note - Improve readability and remove redundant information --- AGENTS.md | 181 ++++++++++++++--------------------- CLAUDE.md | 276 +++++++++++++++++++++++++----------------------------- 2 files changed, 197 insertions(+), 260 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ae651b90..2609695f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -25,168 +25,127 @@ pytest tests/test_recipes.py::test_function_name # Run backend tests with coverage COVERAGE_FILE=coverage/backend/.coverage pytest \ - --cov=py \ - --cov=standalone \ + --cov=py --cov=standalone \ --cov-report=term-missing \ --cov-report=html:coverage/backend/html \ - --cov-report=xml:coverage/backend/coverage.xml \ - --cov-report=json:coverage/backend/coverage.json + --cov-report=xml:coverage/backend/coverage.xml ``` -### Frontend Development +### Frontend Development (Standalone Web UI) ```bash -# Install frontend dependencies npm install +npm test # Run all tests (JS + Vue) +npm run test:js # Run JS tests only +npm run test:watch # Watch mode +npm run test:coverage # Generate coverage report +``` -# Run frontend tests -npm test +### Vue Widget Development -# Run frontend tests in watch mode -npm run test:watch - -# Run frontend tests with coverage -npm run test:coverage +```bash +cd vue-widgets +npm install +npm run dev # Build in watch mode +npm run build # Build production bundle +npm run typecheck # Run TypeScript type checking +npm test # Run Vue widget tests +npm run test:watch # Watch mode +npm run test:coverage # Generate coverage report ``` ## Python Code Style -### Imports +### Imports & Formatting -- Use `from __future__ import annotations` for forward references in type hints -- Group imports: standard library, third-party, local (separated by blank lines) -- Use absolute imports within `py/` package: `from ..services import X` -- Mock ComfyUI dependencies in tests using `tests/conftest.py` patterns - -### Formatting & Types - -- PEP 8 with 4-space indentation -- Type hints required for function signatures and class attributes -- Use `TYPE_CHECKING` guard for type-checking-only imports -- Prefer dataclasses for simple data containers -- Use `Optional[T]` for nullable types, `Union[T, None]` only when necessary +- Use `from __future__ import annotations` for forward references +- Group imports: standard library, third-party, local (blank line separated) +- Absolute imports within `py/`: `from ..services import X` +- PEP 8 with 4-space indentation, type hints required ### Naming Conventions -- Files: `snake_case.py` (e.g., `model_scanner.py`, `lora_service.py`) -- Classes: `PascalCase` (e.g., `ModelScanner`, `LoraService`) -- Functions/variables: `snake_case` (e.g., `get_instance`, `model_type`) -- Constants: `UPPER_SNAKE_CASE` (e.g., `VALID_LORA_TYPES`) -- Private members: `_single_underscore` (protected), `__double_underscore` (name-mangled) +- Files: `snake_case.py`, Classes: `PascalCase`, Functions/vars: `snake_case` +- Constants: `UPPER_SNAKE_CASE`, Private: `_protected`, `__mangled` -### Error Handling +### Error Handling & Async -- Use `logging.getLogger(__name__)` for module-level loggers -- Define custom exceptions in `py/services/errors.py` -- Use `asyncio.Lock` for thread-safe singleton patterns -- Raise specific exceptions with descriptive messages -- Log errors at appropriate levels (DEBUG, INFO, WARNING, ERROR, CRITICAL) +- Use `logging.getLogger(__name__)`, define custom exceptions in `py/services/errors.py` +- `async def` for I/O, `@pytest.mark.asyncio` for async tests +- Singleton with `asyncio.Lock`: see `ModelScanner.get_instance()` +- Return `aiohttp.web.json_response` or `web.Response` -### Async Patterns +### Testing -- Use `async def` for I/O-bound operations -- Mark async tests with `@pytest.mark.asyncio` -- Use `async with` for context managers -- Singleton pattern with class-level locks: see `ModelScanner.get_instance()` -- Use `aiohttp.web.Response` for HTTP responses +- `pytest` with `--import-mode=importlib` +- Fixtures in `tests/conftest.py`, use `tmp_path_factory` for isolation +- Mark tests needing real paths: `@pytest.mark.no_settings_dir_isolation` +- Mock ComfyUI dependencies via conftest patterns -### Testing Patterns - -- Use `pytest` with `--import-mode=importlib` -- Fixtures in `tests/conftest.py` handle ComfyUI mocking -- Use `@pytest.mark.no_settings_dir_isolation` for tests needing real paths -- Test files: `tests/test_*.py` -- Use `tmp_path_factory` for temporary directory isolation - -## JavaScript Code Style +## JavaScript/TypeScript Code Style ### Imports & Modules -- ES modules with `import`/`export` -- Use `import { app } from "../../scripts/app.js"` for ComfyUI integration -- Export named functions/classes: `export function foo() {}` -- Widget files use `*_widget.js` suffix +- ES modules: `import { app } from "../../scripts/app.js"` for ComfyUI +- Vue: `import { ref, computed } from 'vue'`, type imports: `import type { Foo }` +- Export named functions: `export function foo() {}` ### Naming & Formatting -- camelCase for functions, variables, object properties -- PascalCase for classes/constructors -- Constants: `UPPER_SNAKE_CASE` (e.g., `CONVERTED_TYPE`) -- Files: `snake_case.js` or `kebab-case.js` +- camelCase for functions/vars/props, PascalCase for classes +- Constants: `UPPER_SNAKE_CASE`, Files: `snake_case.js` or `kebab-case.js` - 2-space indentation preferred (follow existing file conventions) +- Vue Single File Components: `