Commit Graph
15 Commits
Author SHA1 Message Date
WildAi ec9640f34b chore(docs): point the tracked references at the local .dev/docs tree
The audit artifacts and the plan moved to the local .dev/docs tree, so the
references in the code, the tools and the tests follow them there. The
license file names the tool that produces the record instead of a path.
2026-10-24 22:44:06 +03:00
WildAi 93ae504df5 plan(P4): address review findings
Two review findings of the P4 phase, both fixed at their root:

1. (medium) Structure guard (g) did not scan the node layer. Its file set
   came from the import closure of tools/scan_compat.py (the three src/
   entry points) plus src/** - the node layer (nodes/**) and the root
   __init__.py were invisible, although guard (h) of the same phase scans
   them. A torch.cuda.empty_cache() added to the shipped node code passed
   the guard silently.
   tests/test_structure.py: new PACKAGE_OWN_SOURCE_ROOTS (the pack's own
   code without the vendored tree), _package_files() takes the trees to
   walk (the default is unchanged, so guards (d) and (h) are untouched),
   and guard (g) now scans the own code (13 files) plus the vendored
   modules/deps closure (139 files - the vendored part stays
   closure-scoped as the plan and D8 require). Two new self-tests cover
   the node layer and the entry point.
   Proof (old guard vs new guard on the same injected copy):
     OLD guard (HEAD)  -> []
     NEW guard (fixed) -> ['__init__.py: 1 occurrence(s) of
       torch.cuda.empty_cache() (allowlisted: 0)', 'nodes/
       keep_process_image_sequence.py: 1 occurrence(s) of
       torch.cuda.empty_cache() (allowlisted: 0)']

2. (low) The P4.5 "CPU-mode variant" residency test was vacuous: the
   conftest mock already answers torch.device("cpu") for
   get_torch_device(), so the monkeypatch was a no-op and the variant
   exercised the default path.
   tests/test_keep_model_loader.py: the test now runs a GPU leg and a CPU
   leg - both must produce the same residency calls (load_models_gpu,
   unload_all_models, soft_empty_cache, once each) and the patched device
   must really reach the pack.
   Proof (mutation probes against the production code):
     mutation A (the pack hardcodes the cpu device and ignores ComfyUI):
       the old test (from HEAD) passes (10 passed), the new test fails
       (assert device(type='cpu') == device(type='cuda')).
     mutation B (the pack skips load_models_gpu on a cpu device): the new
       test fails (the two legs no longer match).

Docs: the plan's P4 progress row, the guard table of the P4 audit and the
P4 working state are current; the round is recorded in
docs/2026-10-23-p4-review-findings.md.

Verification (run in this round):
  python_embeded/python.exe -m pytest -q -m "unit or mock_integration"
      -> 189 passed, 1 skipped, 5 deselected, 2 xfailed
         (baseline before the round: 187 passed)
  COMFYUI_ROOT=... python_embeded/python.exe -m pytest -q -m headless
      -> 5 passed, 192 deselected
  ruff check . -> All checks passed!
2026-10-23 22:29:47 +03:00
WildAi 03fd97cf95 plan(P4.7): remove the dead video path and the dead imports 2026-10-23 21:51:09 +03:00
WildAi 88734109b1 plan(P4.6): release the VRAM through ComfyUI instead of torch.cuda 2026-10-23 21:37:07 +03:00
WildAi 7d84b9f879 plan(P4.4): switch the package entry point to V3 only 2026-10-23 21:09:44 +03:00
WildAi fcbfcce3a6 plan(P3): address review findings
Five review findings of the P3 phase, each fixed at its root:

1. (medium) The P3.7 metadata test imported `tomllib` at module level: the
   **3.10 CI job** (the declared `requires-python >=3.10` minimum) died
   during collection, so the registry-metadata assertions never ran on 3.10.
   The parser import is now guarded (`tomllib` -> `tomli`, the package the
   3.10 job installs); without any parser the module *skips* instead of
   dying. `pyproject.toml` gained the test extra
   `tomli>=2.0; python_version < '3.11'`.
   Proof: a 3.10 simulation (the stdlib `tomllib` refused for the test
   module, `tomli` on sys.path) -> 6 passed; the control without `tomli`
   -> 6 skipped (no collection error).

2. (medium) The P3.5 "primary-root-first multi-root" resolution was not
   wired into the production load path: `resolve_model_file` (the only
   `get_full_path_or_raise` caller) was used by tests only, so a weight in
   a secondary model root was downloaded into the primary root again.
   `src/keep_paths.py` now has `find_model_file()` (the multi-root lookup
   through `folder_paths.get_full_path_or_raise`) and `resolve_model_root()`
   (the root the weights really live in); `load_file_from_url_comfy()` - the
   production path of `src/keep_model_loader.py:107` - uses the lookup, and
   the facelib root follows the weights (the facelib helper builds its
   paths from a single root). New tests prove that the production path
   uses a weight of an extra model root and that the primary root wins.
   The `models_dir` grep guard is no longer a blanket exemption: only the
   registration in `src/keep_paths.py` may use the attribute.

3. (low) `[tool.comfy].Icon` was an empty string and the test only checked
   that the key exists. The preview asset **is** committed
   (`git cat-file -s HEAD:assets/keep-preview.png` -> 93279 bytes); only the
   working copy was missing (an uncommitted local deletion, restored from
   HEAD - no asset change is in this commit). The key now points at
   `assets/keep-preview.png` and the test asserts that the value is not
   empty and names a file that is really in the repository.

4. (low) `tests/test_package_entrypoint.py` hard-coded the V1 state and
   would have gone red (not xfail) when P4.4 flips the root `__init__.py`
   to `comfy_entrypoint`. The assertions now follow the entry point that is
   really there: exactly **one** mapping style (V1 XOR V3). The mocked
   smoke test of `tests/test_package_import.py` got the same treatment; the
   headless variant is P4.4's job (its test list names it).

5. (low) The plan's §3 rule ("`comfy.*` imports inside `src/` are lazy
   (function-level) so the pack imports without a ComfyUI server") was
   violated and unguarded. The `comfy` imports of `src/keep_model_loader.py`
   and `src/keep_processor.py` are function-level now; the vendored facelib
   helper (which imports `comfy` itself) is imported lazily through a module
   `__getattr__` (PEP 562), so `loader.FaceRestoreHelper` still resolves to
   the vendored class. Structure **guard (f)** (`tests/test_structure.py`)
   forbids a module-level `comfy`/`comfy_api` import in `src/**` (with the
   self-test the guards file demands), and the new
   `tests/test_lazy_imports.py` proves at runtime that the engines import
   while every `comfy` import is blocked.

Gate after the commit:
  python.exe -m pytest -q tests -m "unit or mock_integration"
    -> 153 passed, 1 skipped, 5 deselected, 3 xfailed
  COMFYUI_ROOT=C:/_Dev/ComfyUI_dev/ComfyUI-source/ComfyUI python.exe
    -m pytest -q tests -m "unit or mock_integration or headless"
    -> 158 passed, 1 skipped, 3 xfailed

Details: docs/2026-10-23-p3-review-findings.md
2026-10-23 20:34:51 +03:00
WildAi c81a0f5f9e plan(P3.4): make the package entry point minimal and move the logger to src/keep_logger.py 2026-10-23 19:03:35 +03:00
WildAi a07cc8ee87 plan(P3.2): move the engines into src/ and lift the logger constraint 2026-10-23 18:57:32 +03:00
WildAi 94d379584f plan(P3.1): move the node classes into nodes/ (one file per node) 2026-10-23 18:41:53 +03:00
WildAi 4c44a8e275 plan(P2): address review findings
Five review findings of the P2 phase, each fixed at its root:

1. (medium) The P2.6 guard could not see an undeclared third-party import:
   the closure's imports were filtered through a hard-coded 10-name map, so
   every module outside it was dropped silently (a module-level `import av`
   in a copy of the repo still gave "1 passed"). The map is now a *rename*
   map (cv2 -> opencv-python, PIL -> Pillow, yaml -> pyyaml); every other
   module is mapped to its own name, so an unknown module shows up as an
   undeclared dependency. The guard is split by import time: every
   third-party module imported at import time must be a declared
   distribution, every lazy (function-level) one must be allowlisted with a
   reason (dlib, gdown, mc, wandb - all unreachable from the node).
2. (low) The P2.1 (c) progression test was vacuous: it returned before its
   assertions and probed a second, top-level copy of the vendored tree
   (`sys.path.insert(modules/deps)`). It now imports the packaged
   architecture, asserts that FeedForward / AdaLayerNorm come from the
   vendored _diffusers_compat and that no top-level `basicsr` shadows an
   installed one.
3. (low) Two swallow-and-stub fallbacks remained in the vendored tree
   (facelib/detection, facelib/parsing - their stubs called an unimported
   `urlparse` and would have raised NameError). Both now import the vendored
   symbol directly; a guard forbids a fallback stub in the vendored tree.
4. (low) `basicsr/utils/file_client.py` still appended to `sys.path` (the
   optional `sys_path` of MemcachedBackend), which the plan's §3 rule
   forbids anywhere in the package. The mutation and the parameter are gone
   and guard (d) now covers the whole package (the vendored tree included).
5. (low) The unreachable body of `KEEPFaceProcessor.process_video` still
   called the deleted VideoReader / VideoWriter. The 141 dead lines are
   removed; an AST guard keeps the references out.

Found while fixing the findings: the CI job did not install `requests`,
which the vendored `basicsr/utils/download_util.py` imports at module level
(P2.6 added it to requirements.txt but not to the workflow) - a clean CI
runner died with "No module named 'requests'". The install list is now
completed and a test derives it from requirements.txt.

Gate: pytest -m "unit or mock_integration" -> 109 passed, 1 skipped,
4 xfailed; plan's local gate (+ headless) -> 109 passed, 3 skipped,
4 xfailed; tools/scan_compat.py -> finding_count 0 (exit 0); ruff check . ->
All checks passed. A mutation check re-introduces six defects into a copy of
the repository: the matching guard fails in 6/6 cases.
2026-10-23 18:29:04 +03:00
WildAi e3f141c6ee plan(P2.5): package-ize the vendored deps and drop the sys.path mutation 2026-10-23 17:33:50 +03:00
WildAi 7e6d9ffc71 plan(P2.4): prune the vendored tree to the runtime closure with explicit import lists 2026-10-23 17:25:27 +03:00
WildAi fc05d4fb49 plan(P2.1): strip the debug, breakage and pip-shim lines from the vendored closure 2026-10-23 16:53:44 +03:00
WildAi e7c08682d8 plan(P1): address review findings
Seven review findings of the P1 phase, each fixed at its root:

1. (high) The CI install list omitted PyYAML, but the vendored tree imports
   yaml eagerly (modules/deps/basicsr/utils/options.py:5), so the CI job
   failed on its first run. pyyaml is now installed and asserted by
   tests/test_ci_workflow.py.
2. (medium) tests/test_ci_workflow.py skipped the whole module without
   PyYAML. The module never skips now: a minimal indentation parser is the
   fallback, and it is cross-checked against the PyYAML parse.
3. (medium) Guard (e)'s self-test asserted that the tree still contains
   breakage (it would break exactly at P2.1). It now proves the guard
   instead; P2.1's work list is the scanner output and
   test_guard_e_flip_owner_covers_every_current_finding keeps plan and tree
   in sync.
4. (medium) The mock-fidelity tripwire skipped the comfy_api.latest
   symbols. Every mocked symbol is now checked against the real source
   (re-export / definition / instance attribute), including io.ComfyNode,
   ComfyExtension, ComfyAPI and ComfyAPISync, plus the reverse check that
   the mock invents nothing.
5. (low) The phase review listed committed work as outstanding and
   misstated the ruff ignore list; both are corrected.
6. (low) The reported whole-suite count was impossible; the phase review
   now carries the measured numbers.
7. (low) The root conftest installed the mocks unconditionally. The
   KEEP_NO_COMFY_MOCKS=1 opt-out lets the headless tier import the real
   comfy/comfy_api modules in-process.

tools/ci_env_sim.py runs the gate in an environment without the packages
the CI install list omits.
2026-10-23 16:34:37 +03:00
WildAi f47d9e6123 plan(P1.3): add the source-text structure guards
tests/test_structure.py implements the five plan guards as pure functions over
a repository root, each xfail(strict=False) with the step that flips it
strict in the reason:
  (a) nodes/ classes exported by nodes/__init__.py  -> P3.1
  (b) no io.Schema(/define_schema in src/           -> P3.2
  (c) __init__.py exposes exactly comfy_entrypoint  -> P4.4
  (d) no sys.path mutation outside modules/deps/    -> P2.5
  (e) no pdb/profiler/pip in the vendored closure   -> P2.1
The self-tests copy the repository into tmp_path and prove that each guard
fails on a deliberately violating file.
2026-10-23 15:48:52 +03:00