forked from enderofwings/NexusOS
Reconciles 17 commits of this session's work (self-alteration tools, vendored Curry, slash-command dispatch, Windows toolchain/gate fixes) against origin/main's v1.2.0 sync (Projects/RAG scoping, a new modules/ system for mail and network, in-app updates, the standalone memory microservice folded into an in-process curator, KDE desktop theme overhaul). Nine real conflicts, each resolved by hand after reading both sides' actual diffs rather than picking one side wholesale: - synapse/tools.py, tests/test_tools.py: origin/main's diff here was small and clean (read_file/list_files, two new tests) despite git's diff3 flagging the whole file as one conflict blob -- reset to this branch's version and hand-spliced their addition in at the same points they used, rather than trying to reconcile a false 800-line conflict. Found and fixed a real bug while verifying: _list_files returned backslash-separated paths on Windows, which don't match the forward-slash glob patterns the tool's own schema documents. - synapse/main.py: kept this branch's cue-based standing advertisement of render_preview/run_snippet (independent of any playbook granting them) AND adopted origin/main's fix for routed reference playbooks not bringing their own tools along -- dropping either would have been a real regression, not just a style difference. Also: the standalone memory service (port 8001) is gone upstream, so its dead CORS/kill- target entries were removed; NEXUS_BACKEND_PORT parameterization and the manage_ollama-conditional kill logic (this branch's remote-Ollama support) were kept over origin/main's hardcoded equivalents. - synapse/memory/store.py: kept this branch's _delete_message_vectors helper (already reused elsewhere, batches to stay under SQLite's variable limit) over origin/main's inline duplicate of the same fix. - synapse/nexus_config.py, nexusos_cli/ncp.py: dropped the now-dead memory-service port/service entries; kept NEXUS_BACKEND_PORT env override and the manage_ollama-conditional kill-target list. - CLAUDE.md, README.md: merged both sides' additions, no real conflict. Found and fixed three more issues while independently verifying the merged tree, none of them mine or origin/main's alone -- only visible once both sides actually ran together: - modules/ (the new mail+network package) was never added to pyproject.toml's wheel `packages` list OR the sdist's `include` allowlist, so `from modules.registry import ROUTERS` in main.py would ImportError on any wheel install. Fixed both; bin/check.sh's packaging gate now asserts modules/ actually ships. tests/ test_packaging_deps.py's FIRST_PARTY/SHIPPED_PACKAGES sets were updated to recognize the new package. - tests/test_mail_creds.py's 0600-mode assertions are POSIX-only -- NTFS has no equivalent permission bits, so os.open(path, 0o600) on Windows just creates a normal file and stat.S_IMODE reports 0o666 regardless. Made the assertions platform-aware rather than skip real coverage (the temp-file-cleanup and password round-trip checks in the same test still run on Windows) or paper over a genuine OS limitation with a fake pass. - tests/test_kde_theme.py used bare Path.read_text() in fifteen places; Windows' default locale encoding (cp1252, not UTF-8) can't decode a real UTF-8 byte in the QML it reads, and did fail on one of the fifteen. Fixed all fifteen, not just the one that happened to trip today, since the other fourteen were equally fragile. Verified: full bin/check.sh reports OK end-to-end on this Windows checkout -- pytest (tests + management): 295 passed, 0 failed, 9 skipped; eslint clean; frontend node:test 57/57; PowerShell/shell parse clean; wheel + sdist pass twine check and now correctly carry modules/ (60 files, up from 52 pre-merge). synapse.main:app builds with 74 routes (up from 54 pre-merge, matching the new Projects/mail/ network endpoints).
146 lines
5.7 KiB
Python
146 lines
5.7 KiB
Python
"""Guard the wheel's dependency list against drift.
|
|
|
|
There are now two dependency declarations: requirements-base.txt (what the
|
|
desktop installers pip -r) and pyproject.toml (what the wheel ships). They will
|
|
drift. What actually breaks a user is narrower than "they differ", though: it
|
|
is an import that no declared distribution provides, so that is what this pins.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import ast
|
|
import sys
|
|
import tomllib
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SHIPPED_PACKAGES = ("synapse", "nexusos_cli", "modules")
|
|
|
|
# Import name -> distribution name, where PyPI disagrees with the module.
|
|
DISTRIBUTION_OF = {
|
|
"docx": "python-docx",
|
|
"dotenv": "python-dotenv",
|
|
"faster_whisper": "faster-whisper",
|
|
"imap_tools": "imap-tools",
|
|
"sqlite_vec": "sqlite-vec",
|
|
"yaml": "pyyaml",
|
|
"PIL": "pillow",
|
|
}
|
|
|
|
# Provided by another declared distribution rather than named directly.
|
|
# rich: Textual depends on it, so the tui extra already pulls it in.
|
|
TRANSITIVE = {"starlette", "socketio", "engineio", "rich"}
|
|
|
|
# Modules that ship inside this repo.
|
|
FIRST_PARTY = {"synapse", "nexusos_cli", "management", "bin", "tests", "modules"}
|
|
|
|
|
|
def _pyproject() -> dict:
|
|
return tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
|
|
|
|
|
|
def _requirement_name(spec: str) -> str:
|
|
"""'pypdf>=5,<7' -> 'pypdf'; strips extras and environment markers."""
|
|
head = spec.split(";", 1)[0].strip()
|
|
for sep in ("[", "=", ">", "<", "!", "~", " "):
|
|
head = head.split(sep, 1)[0]
|
|
return head.strip().lower().replace("_", "-")
|
|
|
|
|
|
def _declared() -> set[str]:
|
|
project = _pyproject()["project"]
|
|
specs = list(project.get("dependencies", []))
|
|
for extra in project.get("optional-dependencies", {}).values():
|
|
specs.extend(extra)
|
|
return {_requirement_name(s) for s in specs}
|
|
|
|
|
|
def _imported_modules() -> set[str]:
|
|
"""Top-level module names imported anywhere in the shipped packages."""
|
|
found: set[str] = set()
|
|
for package in SHIPPED_PACKAGES:
|
|
for path in (ROOT / package).rglob("*.py"):
|
|
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Import):
|
|
found.update(alias.name.split(".")[0] for alias in node.names)
|
|
elif isinstance(node, ast.ImportFrom):
|
|
# level > 0 is a relative (first-party) import.
|
|
if node.level == 0 and node.module:
|
|
found.add(node.module.split(".")[0])
|
|
return found
|
|
|
|
|
|
def _third_party() -> set[str]:
|
|
return {
|
|
module for module in _imported_modules()
|
|
if module not in sys.stdlib_module_names
|
|
and module not in FIRST_PARTY
|
|
and module not in TRANSITIVE
|
|
and not module.startswith("_")
|
|
}
|
|
|
|
|
|
def test_every_third_party_import_is_a_declared_dependency():
|
|
declared = _declared()
|
|
missing = sorted(
|
|
module for module in _third_party()
|
|
if DISTRIBUTION_OF.get(module, module).lower().replace("_", "-") not in declared
|
|
)
|
|
assert not missing, (
|
|
"synapse/nexusos_cli import these, but pyproject.toml declares no "
|
|
f"distribution for them: {missing}. Add them to [project] dependencies "
|
|
"or an extra (and to DISTRIBUTION_OF here if the names differ)."
|
|
)
|
|
|
|
|
|
def test_all_extra_is_the_union_of_the_capability_extras():
|
|
extras = _pyproject()["project"]["optional-dependencies"]
|
|
combined: set[str] = set()
|
|
for name, specs in extras.items():
|
|
if name in ("all", "dev", "standard"):
|
|
continue
|
|
combined.update(_requirement_name(s) for s in specs)
|
|
everything = {_requirement_name(s) for s in extras["all"]}
|
|
assert combined == everything, (
|
|
"the 'all' extra drifted from the capability extras; "
|
|
f"missing={sorted(combined - everything)} extra={sorted(everything - combined)}"
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("name", ["fastapi", "uvicorn", "httpx", "pydantic", "pyyaml"])
|
|
def test_core_runtime_is_a_hard_dependency_not_an_extra(name):
|
|
"""These are imported at module scope, so the base install must carry them."""
|
|
base = {_requirement_name(s) for s in _pyproject()["project"]["dependencies"]}
|
|
assert name in base
|
|
|
|
|
|
def test_optional_imports_are_lazy():
|
|
"""Anything only in an extra must not be imported at module scope.
|
|
|
|
A base `pip install nexusos-ai` has none of the extras, so a top-level
|
|
`import psutil` in synapse would make the backend unimportable.
|
|
"""
|
|
base = {_requirement_name(s) for s in _pyproject()["project"]["dependencies"]}
|
|
offenders: list[str] = []
|
|
for package in SHIPPED_PACKAGES:
|
|
for path in (ROOT / package).rglob("*.py"):
|
|
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
|
for node in tree.body: # module scope only
|
|
names: list[str] = []
|
|
if isinstance(node, ast.Import):
|
|
names = [a.name.split(".")[0] for a in node.names]
|
|
elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module:
|
|
names = [node.module.split(".")[0]]
|
|
for module in names:
|
|
if module in sys.stdlib_module_names or module in FIRST_PARTY:
|
|
continue
|
|
dist = DISTRIBUTION_OF.get(module, module).lower().replace("_", "-")
|
|
if dist not in base and module not in TRANSITIVE:
|
|
offenders.append(f"{path.relative_to(ROOT)}: {module}")
|
|
assert not offenders, (
|
|
"optional dependencies imported at module scope (wrap in try/ImportError "
|
|
f"or import inside the function): {offenders}"
|
|
)
|