Merge origin/main into feat/plugin-catalog

Python plugin CLI/loader/web/tui files taken from main wholesale; the
catalog layer is re-ported onto main's decomposed shapes in the
following commits. plugin_index.py removed (catalog is the sole
discovery system).
This commit is contained in:
Teknium
2026-09-09 04:15:27 -07:00
5636 changed files with 754596 additions and 780439 deletions
+118
View File
@@ -0,0 +1,118 @@
"""Wrappers for scripts/check-case-collisions.py.
Same pattern as tests/scripts/test_windows_footguns_full_repo_scan.py: run
the real checker and assert its outcomes, so a normal pytest run catches a
regression — someone committing a case-colliding pair — without anyone
having to remember to run the script by hand.
The collision cases are built with ``git update-index --cacheinfo`` (index
only, never touching the working tree), so they exercise the same index the
checker reads and work even on a case-insensitive filesystem, where the two
spellings cannot coexist on disk.
"""
from __future__ import annotations
import hashlib
import subprocess
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
SCRIPT = REPO_ROOT / "scripts" / "check-case-collisions.py"
def _git_blob_sha(data: bytes) -> str:
"""The git object hash for a blob with ``data`` as its content."""
header = f"blob {len(data)}\0".encode("ascii")
return hashlib.sha1(header + data).hexdigest()
def _run_check(*args, root=None):
cmd = [sys.executable, str(SCRIPT)] + list(args)
if root is not None:
cmd.append(str(root))
return subprocess.run(
cmd,
capture_output=True,
text=True,
timeout=60,
stdin=subprocess.DEVNULL,
cwd=REPO_ROOT,
)
def _git_init(tmp_path) -> Path:
repo = tmp_path / "repo"
repo.mkdir()
subprocess.run(["git", "init", "-q"], cwd=repo, check=True)
return repo
def test_full_repo_has_no_case_colliding_paths():
"""The real checker against the whole tracked tree must exit clean."""
result = _run_check()
assert result.returncode == 0, (
f"Case-collision check failed:\n{result.stdout}\n{result.stderr}"
)
def test_detects_case_colliding_paths(tmp_path):
"""Same-directory Foo.txt + foo.txt must fail, naming both paths."""
repo = _git_init(tmp_path)
subprocess.run(
[
"git", "update-index", "--add", "--cacheinfo",
f"100644,{_git_blob_sha(b'a')},Foo.txt",
],
cwd=repo, check=True,
)
subprocess.run(
[
"git", "update-index", "--add", "--cacheinfo",
f"100644,{_git_blob_sha(b'b')},foo.txt",
],
cwd=repo, check=True,
)
result = _run_check(root=repo)
assert result.returncode == 1, f"expected failure, got:\n{result.stdout}"
assert "Foo.txt" in result.stdout
assert "foo.txt" in result.stdout
def test_detects_directory_case_collisions(tmp_path):
"""The comparison is on the FULL path — dir/Foo.txt vs DIR/foo.txt too."""
repo = _git_init(tmp_path)
subprocess.run(
[
"git", "update-index", "--add", "--cacheinfo",
f"100644,{_git_blob_sha(b'a')},src/Helper.py",
],
cwd=repo, check=True,
)
subprocess.run(
[
"git", "update-index", "--add", "--cacheinfo",
f"100644,{_git_blob_sha(b'b')},SRC/helper.py",
],
cwd=repo, check=True,
)
result = _run_check(root=repo)
assert result.returncode == 1, f"expected failure, got:\n{result.stdout}"
assert "src/Helper.py" in result.stdout
assert "SRC/helper.py" in result.stdout
def test_same_name_in_different_dirs_is_not_a_collision(tmp_path):
"""a/Readme.txt and b/readme.txt share a basename but not a path."""
repo = _git_init(tmp_path)
(repo / "a").mkdir()
(repo / "b").mkdir()
(repo / "a" / "Readme.txt").write_text("a", encoding="utf-8")
(repo / "b" / "readme.txt").write_text("b", encoding="utf-8")
subprocess.run(["git", "add", "-A"], cwd=repo, check=True)
result = _run_check(root=repo)
assert result.returncode == 0, f"expected clean, got:\n{result.stdout}"
@@ -0,0 +1,57 @@
"""Behavioral tests for the profile archive CI guard."""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
SCRIPT = (
Path(__file__).resolve().parents[2]
/ "scripts"
/ "ci"
/ "check_profile_archive_boundary.py"
)
def _run(root: Path) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[sys.executable, str(SCRIPT), "--root", str(root)],
capture_output=True,
text=True,
check=False,
)
def test_clean_root_passes(tmp_path):
result = _run(tmp_path)
assert result.returncode == 0
assert "No profile export archives" in result.stdout
def test_root_profile_archive_fails_without_printing_contents(tmp_path):
default_archive = tmp_path / "default.tar.gz"
alternate_archive = tmp_path / "backup.TGZ"
default_archive.write_bytes(b"profile webhook secret must never be printed")
alternate_archive.write_bytes(b"another archive")
result = _run(tmp_path)
assert result.returncode == 1
assert "default.tar.gz" in result.stdout
assert "backup.TGZ" in result.stdout
assert "profile webhook secret" not in result.stdout
assert "another archive" not in result.stdout
def test_nested_profile_archive_is_also_rejected(tmp_path):
nested = tmp_path / "fixtures"
nested.mkdir()
(nested / "fixture.tar.gz").write_bytes(b"test fixture")
result = _run(tmp_path)
assert result.returncode == 1
assert "fixtures/fixture.tar.gz" in result.stdout
@@ -0,0 +1,91 @@
"""scripts/ci/check_public_surface.py detects silently dropped public names, methods and test defs.
Replayed against the Sep 2026 refactor PR at open it reports 1,703 public names dropped in 341 modules
(the figure reviewers had to find ~30 of by hand); here the contract is pinned on a throwaway repo.
"""
import importlib.util
import subprocess
import textwrap
from pathlib import Path
SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "ci" / "check_public_surface.py"
def _load():
spec = importlib.util.spec_from_file_location("check_public_surface", SCRIPT)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
def _git(repo, *args):
subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True,
env={"GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t", "GIT_COMMITTER_NAME": "t",
"GIT_COMMITTER_EMAIL": "t@t", "PATH": "/usr/bin:/bin:/usr/local/bin"})
def test_dropped_public_names_methods_and_test_defs_are_reported_and_moves_are_not(tmp_path, monkeypatch):
repo = tmp_path
(repo / "agent").mkdir(); (repo / "tests").mkdir(); (repo / "docs").mkdir()
(repo / "agent" / "mod.py").write_text(textwrap.dedent('''
import os
from json import loads as parse
LIMIT = 3
def keep(): ...
def gone(): ...
def _private(): ...
class K:
def pub(self): ...
def __len__(self): return 0
def _hidden(self): ...
class Big:
def stays(self): ...
def extracted(self): ...
'''), encoding="utf-8")
(repo / "agent" / "moved.py").write_text("def relocated(): ...\n", encoding="utf-8")
(repo / "tests" / "test_x.py").write_text("def test_a(): ...\ndef test_b(): ...\nasync def test_c(): ...\n", encoding="utf-8")
(repo / "docs" / "notes.py").write_text("def doc_helper(): ...\n", encoding="utf-8")
_git(repo, "init", "-q", "-b", "main"); _git(repo, "add", "."); _git(repo, "commit", "-qm", "base")
# HEAD: drop `gone`, `parse`, `K.pub`, `K.__len__`; drop `_private`/`K._hidden` (private: fine);
# move `relocated` into mod with a re-export left behind (fine); lose one test def; change a
# non-source module (ignored).
(repo / "agent" / "mod.py").write_text(textwrap.dedent('''
import os
from agent.moved import relocated # re-export
LIMIT = 3
def keep(): ...
class K: ...
class _BigMixin:
def extracted(self): ... # moved into an in-module base: still reachable on Big
class Big(_BigMixin):
def stays(self): ...
'''), encoding="utf-8")
(repo / "agent" / "moved.py").write_text("def relocated(): ...\ndef relocated2(): ...\n", encoding="utf-8")
(repo / "tests" / "test_x.py").write_text("def test_a(): ...\nasync def test_c(): ...\n", encoding="utf-8")
(repo / "docs" / "notes.py").write_text("def other(): ...\n", encoding="utf-8")
_git(repo, "add", "."); _git(repo, "commit", "-qm", "head")
monkeypatch.chdir(repo)
mod = _load()
report = mod.diff_surface("HEAD~1", "HEAD")
assert report["dropped_names"] == {"agent/mod.py": ["gone", "parse"]}
assert report["dropped_methods"] == {"agent/mod.py": ["K.__len__", "K.pub"]}
assert report["test_drops"] == {"tests/test_x.py": (3, 2)}
assert mod.main(["--base", "HEAD~1", "--head", "HEAD"]) == 0 # advisory
assert mod.main(["--base", "HEAD~1", "--head", "HEAD", "--strict"]) == 1
assert mod.main(["--base", "HEAD", "--head", "HEAD", "--strict"]) == 0 # nothing dropped
def test_unresolvable_refs_are_an_error_not_a_clean_report(tmp_path, monkeypatch):
"""Independent-review witness: a nonexistent base ref under --strict reported zero drops and exited 0,
which would make a mis-fetched CI job look clean."""
repo = tmp_path
(repo / "a.py").write_text("x = 1\n", encoding="utf-8")
_git(repo, "init", "-q", "-b", "main"); _git(repo, "add", "."); _git(repo, "commit", "-qm", "base")
monkeypatch.chdir(repo)
mod = _load()
assert mod.main(["--base", "origin/does-not-exist", "--head", "HEAD", "--strict"]) == 2
assert mod.main(["--base", "origin/does-not-exist", "--head", "HEAD"]) == 2
+63
View File
@@ -116,3 +116,66 @@ def test_cli_entrypoint_end_to_end(tmp_path):
assert proc.returncode == 0, proc.stderr
out = (tmp_path / "contributors" / "emails" / "cli@example.com").read_text(encoding="utf-8")
assert out.splitlines()[0] == "cliperson"
# ── case-insensitive filename collisions ──────────────────────────────
#
# The mapping key IS the filename, so two emails differing only in case are the
# same file on Windows and on default macOS. When both exist, git writes one and
# then reports the other as modified in a FRESH clone, permanently: the repo can
# never be checked out clean on those platforms.
#
# The historical agent@Agents-Mac-mini.local / agent@agents-Mac-mini.local pair
# was removed from the tree (fcdae2cf0b), so there is no allowlist: any pair
# is a regression. scripts/check-case-collisions.py enforces the same
# invariant repo-wide in CI; this test keeps it visible next to the writer.
EMAILS_DIR = REPO_ROOT / "contributors" / "emails"
def test_no_case_insensitive_mapping_collisions():
groups: dict[str, set[str]] = {}
for entry in EMAILS_DIR.iterdir():
if entry.is_file():
groups.setdefault(entry.name.casefold(), set()).add(entry.name)
collisions = {frozenset(names) for names in groups.values() if len(names) > 1}
assert not collisions, (
"contributor mappings differing only in case cannot coexist on "
"case-insensitive filesystems (Windows, default macOS) — a fresh clone "
f"there is permanently dirty: {sorted(sorted(c) for c in collisions)}"
)
def test_add_contributor_refuses_a_case_collision(tmp_path, monkeypatch):
d = tmp_path / "emails"
d.mkdir()
(d / "agent@Example-Host.local").write_text("someone\n")
import add_contributor as mod
monkeypatch.setattr(mod, "EMAILS_DIR", d)
assert mod.add_contributor("agent@example-host.local", "otherperson") == 1
assert not (d / "agent@example-host.local").exists()
def test_add_contributor_refuses_case_collision_even_for_same_login(emails_dir, capsys):
# Same login, different spelling: still refused — the problem is the
# filename pair, not the login. The exact spelling is what's "present".
emails_dir.mkdir(parents=True)
(emails_dir / "Foo@Example.com").write_text("foouser\n")
assert add_contributor("foo@example.com", "foouser") == 1
assert "Foo@Example.com" in capsys.readouterr().err
assert sorted(p.name for p in emails_dir.iterdir()) == ["Foo@Example.com"]
# Exact-case re-add is the ordinary idempotent path.
assert add_contributor("Foo@Example.com", "foouser") == 0
def test_case_collision_uses_casefold(emails_dir):
# casefold, not lower: matches how macOS/Windows fold non-ASCII (ß ~ ss).
emails_dir.mkdir(parents=True)
(emails_dir / "strasse@example.com").write_text("someone\n")
assert add_contributor("STRASSE@example.com", "someone") == 1
assert add_contributor("straße@example.com", "someone") == 1