Close the validated pre-public review findings with import-safe capability checks, safer retrieval and image-tagging behavior, CI/release hygiene, and regression coverage for the confirmed defects.
123 lines
3.5 KiB
Python
123 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Minimal package verifier for comfyui-tag-rag.
|
|
|
|
Runs compile checks, import tests, and (by default) the pytest suite.
|
|
Use ``--skip-tests`` for a fast local compile-only check.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import importlib
|
|
|
|
# Ensure the repo root is on sys.path so that nodes/ and tag_rag/ are importable.
|
|
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
_REPO_ROOT = os.path.abspath(os.path.join(_SCRIPT_DIR, ".."))
|
|
if _REPO_ROOT not in sys.path:
|
|
sys.path.insert(0, _REPO_ROOT)
|
|
|
|
|
|
def check_compile():
|
|
"""Verify all .py files compile without syntax errors."""
|
|
print("=== Compile check ===")
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"compileall",
|
|
".",
|
|
"-q",
|
|
],
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
if result.returncode == 0:
|
|
print("OK - all scaffold files compile.")
|
|
else:
|
|
print("FAIL - compile errors:")
|
|
print(result.stderr[:2000] if result.stderr else result.stdout[:2000])
|
|
return result.returncode
|
|
|
|
|
|
def check_imports():
|
|
"""Verify key modules import without errors."""
|
|
print("\n=== Import check ===")
|
|
modules = [
|
|
"nodes.index_node",
|
|
"nodes.prompt_node",
|
|
"nodes.chat_node",
|
|
"nodes.image_node",
|
|
"tag_rag.paths",
|
|
"tag_rag.csv_io",
|
|
"tag_rag.tag_catalog",
|
|
"tag_rag.lexical_search",
|
|
"tag_rag.faiss_store",
|
|
"tag_rag.embeddings",
|
|
"tag_rag.llama_server",
|
|
"tag_rag.llama_cpp_backend",
|
|
"tag_rag.generation",
|
|
"tag_rag.prompt_builder",
|
|
"tag_rag.conversation",
|
|
"tag_rag.capabilities",
|
|
"tag_rag.image_tagger",
|
|
"tag_rag.json_io",
|
|
"tag_rag.pipeline",
|
|
"tag_rag.catalog_cache",
|
|
"tag_rag._http",
|
|
"tag_rag._redact",
|
|
]
|
|
failures = []
|
|
for mod_name in modules:
|
|
try:
|
|
importlib.import_module(mod_name)
|
|
print(f" OK {mod_name}")
|
|
except Exception as exc:
|
|
print(f" FAIL {mod_name}: {exc}")
|
|
failures.append(mod_name)
|
|
if failures:
|
|
print(f"\n{len(failures)} module(s) failed to import.")
|
|
return 1
|
|
print("\nAll modules imported successfully.")
|
|
return 0
|
|
|
|
|
|
def check_pytest(skip_tests: bool = False) -> int:
|
|
"""Run the pytest suite; return 0 on success, 1 on failure."""
|
|
if skip_tests:
|
|
print("\n=== Test check skipped (--skip-tests) ===")
|
|
return 0
|
|
print("\n=== Test check ===")
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "pytest", "tests/", "-v", "--tb=short"],
|
|
capture_output=True,
|
|
text=True,
|
|
cwd=_REPO_ROOT,
|
|
)
|
|
output = (result.stdout or "") + (result.stderr or "")
|
|
if result.returncode == 0:
|
|
print("OK - all tests pass.")
|
|
else:
|
|
print("FAIL - test failures:")
|
|
print(output[-4000:])
|
|
return result.returncode
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(description="comfyui-tag-rag verifier")
|
|
parser.add_argument("--skip-tests", action="store_true", help="Skip pytest; only run compile + import checks.")
|
|
args = parser.parse_args(argv)
|
|
|
|
compile_ok = check_compile()
|
|
imports_ok = check_imports()
|
|
tests_ok = check_pytest(skip_tests=args.skip_tests)
|
|
if compile_ok == 0 and imports_ok == 0 and tests_ok == 0:
|
|
print("\n=== Verification passed ===")
|
|
return 0
|
|
print("\n=== Verification FAILED ===")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|