6.3 KiB
Testing Rules
- Status: Canonical
- Last reviewed: 2026-07-05
- Update when: Test structure, coverage expectations, fixture policy, or regression-test rules change.
This document defines repository-wide testing rules for ComfyUI-LLM-Session.
Use it together with domain-specific test requirements in documents such as
model-specific-parameter-flow.md and advanced-simple-config-notes.md.
Core Principles
- Behavior preservation is the first testing priority.
- Tests should lock user-visible behavior and compatibility-critical surfaces.
- Service boundaries should have direct tests, not only indirect node-level coverage.
- Refactors should be supported by existing tests or small additive tests in the same step.
When Tests Are Required
Add or update tests when a change affects any of the following:
services/*.pyclasses, request objects, dependency wiring, or orchestration behavior.- Cache, history, session, KV state, model unload, transcript, or filesystem side effects.
- Model-family detection, model-specific parameter flow, chat handler kwargs, or backend fallback.
- UI input defaults, enum/choice labels, sentinel strings, or Simple-node defaults.
- Bug fixes, especially when the broken condition can regress silently.
For service-layer changes, prefer a direct test in tests/services/ even when a
higher-level node test already exercises the path.
Test Placement
- Put
core/tests undertests/core/. - Put
services/tests undertests/services/. - Put
infra/tests undertests/infra/. - Keep
llm_session_nodes.pyUI/default/import/node-wrapper tests in focused top-leveltests/test_*.pyfiles. - For model-specific parameter behavior, also follow the Required Tests section
in
model-specific-parameter-flow.md. - For advanced Simple config behavior, also follow the documentation and test
requirements in
advanced-simple-config-notes.md.
Side Effects
Side-effecting behavior should cover both success and failure paths when practical.
Examples include:
- History save, backup, restore, quarantine, and schema migration.
- KV state save, restore, invalidation, and cache mismatch handling.
- Runtime cache configuration and invalidation.
- Model unload and runtime container cleanup.
- Transcript append and output file writes.
When a failure is intentionally tolerated, assert the returned status, recorded error, log output, or preserved state that makes the tolerance observable.
Fixtures And Helpers
- Do not copy the same test helper across many files.
- If the same helper, stub, or import setup is needed in three or more test
files, move it to
tests/conftest.pyor a focused test helper module. - Keep
folder_pathsstubs,llm_session_nodesreload setup, and runtime container stubs centralized when they are shared. - Large dependency dictionaries should use a default builder plus explicit overrides instead of repeating full dictionaries in each test.
- Test helpers should keep defaults boring and make the behavior under test obvious at the call site.
Parametrized Tests
Use pytest.mark.parametrize when the same assertion shape covers three or more
cases.
Good candidates include:
- Model family aliases and variant names.
- UI input defaults and option lists.
- Language-specific continue-rewrite behavior.
- Supported and unsupported media/input shapes.
- Error-message or backend-fallback cases with the same expected outcome.
Do not force a regression test into a parameter table when a named standalone test better explains the broken condition.
Large Test Files
Avoid growing already-large test files by default.
- When a test file is roughly 500 lines or larger, consider placing new tests in a focused sibling file.
- Split new turn-execution coverage by concern when possible: preflight, generation, persistence, KV state, node execution, or timing/logging.
- Existing large files do not need immediate mechanical splitting. Prefer incremental extraction when new tests or helper cleanup make the boundary clear.
Testing Private Helpers
Prefer public functions, service methods, and request/dependency contracts as the main test surface.
Direct private-helper tests are acceptable when one of these applies:
- The helper handles path safety, media conversion, model alias detection, config/default normalization, or backend compatibility fallback.
- The helper has many boundary conditions that would be noisy to reach through a higher-level API.
- The higher-level API would require heavy mocks or unrelated setup that hides the behavior being tested.
Regression Test Names
Regression tests should name the condition that used to fail.
Prefer names like:
test_load_history_reads_backup_when_primary_invalidtest_restore_state_invalidates_cache_on_state_data_mismatchtest_simple_config_override_preserves_model_specific_default
Avoid vague names like test_history_fix or test_kv_state_works.
Pytest Configuration
Keep pytest configuration strict enough to catch stale test metadata.
Recommended defaults:
- Use
--strict-config. - Use
--strict-markers. - Register any marker before using it.
- Introduce coverage measurement before introducing a hard coverage threshold.
- Raise coverage thresholds gradually after currently-thin service areas are covered directly.
Checklist
Before finishing a code change, check:
- Did service-layer behavior get a direct test?
- Did side-effect behavior cover success and failure paths where practical?
- Did repeated cases use parametrization where appropriate?
- Did new helpers avoid copy-paste across test files?
- Did regression tests describe the broken condition in the test name?
- Did domain-specific docs add any extra test requirements for this change?
Related Documents
refactoring-rules.md- Refactoring safety-net and split criteria.model-specific-parameter-flow.md- Required tests for model-specific parameter changes.advanced-simple-config-notes.md- Advanced Simple config implementation and test requirements.change-documentation-guidelines.md- Documentation, changelog, and release-note placement rules.