Files
wild-pc/wildpc-api/tests/test_programs_git.py
Paul Payne 05b28cb584 Rename Castle -> Wild PC across the repo
Repo-side rename only (Phases 1-3 of the migration plan); the live box
(~/.castle, systemd units, /data/castle, domains) is a separate cutover.

- Slug `castle` -> `wildpc`: CLI command, module names (wildpc_core/cli/api),
  dist names, entry point `wildpc = wildpc_cli.main:main`.
- Identifiers: CastleConfig/NATSClient/DirError/MDNS -> Wildpc*.
- Env/constants: CASTLE_* -> WILDPC_*; ~/.castle -> ~/.wildpc, castle.yaml ->
  wildpc.yaml, /data/castle -> /data/wildpc.
- Systemd UNIT_PREFIX castle- -> wildpc-; own programs castle-api/gateway/etc.
- Display prose "Castle" -> "Wild PC" in docs, agent-guide files, README, frontend.
- Package dirs and bootstrap yaml renamed via git mv; lockfiles regenerated;
  redundant nested uv.lock files dropped (workspace root lock is authoritative).

Tests: core 273, cli 47, wildpc-api 120 all pass. Frontend type-checks + builds.
Fixed a stale test fixture (secret_env_path kind arg) broken pre-rename.
2026-07-18 22:55:08 -07:00

80 lines
2.7 KiB
Python

"""Tests for the program git-status / sync endpoints."""
import os
import subprocess
from pathlib import Path
from fastapi.testclient import TestClient
_ENV = {
"GIT_AUTHOR_NAME": "t",
"GIT_AUTHOR_EMAIL": "t@t",
"GIT_COMMITTER_NAME": "t",
"GIT_COMMITTER_EMAIL": "t@t",
"GIT_CONFIG_GLOBAL": "/dev/null",
"GIT_CONFIG_SYSTEM": "/dev/null",
}
def _git(cwd: Path, *args: str) -> None:
subprocess.run(
["git", "-C", str(cwd), *args],
check=True,
capture_output=True,
text=True,
env={**os.environ, **_ENV},
)
def _commit(cwd: Path, fname: str) -> None:
(cwd / fname).write_text(fname)
_git(cwd, "add", fname)
_git(cwd, "commit", "-m", f"add {fname}")
def _setup_git_program(work: Path) -> None:
"""Make `work` a git clone tracking an `-upstream` repo with one commit."""
upstream = work.parent / f"{work.name}-upstream"
upstream.mkdir()
_git(upstream, "init", "-q", "-b", "main")
_commit(upstream, "a.txt")
_git(work.parent, "clone", "-q", str(upstream), str(work))
class TestProgramGit:
def test_non_git_source_is_benign(self, client: TestClient) -> None:
"""A program whose source isn't a git repo returns is_repo:false, not 500."""
resp = client.get("/programs/test-tool/git")
assert resp.status_code == 200
assert resp.json()["is_repo"] is False
def test_status_behind_then_sync_pulls(
self, client: TestClient, wildpc_root: Path
) -> None:
work = wildpc_root / "wired-in" # source: "wired-in" → <root>/wired-in
_setup_git_program(work)
_commit(work.parent / "wired-in-upstream", "b.txt") # advance the remote
status = client.get("/programs/wired-in/git")
assert status.status_code == 200
body = status.json()
assert body["is_repo"] is True and body["branch"] == "main"
assert body["behind"] == 1 and body["ahead"] == 0
synced = client.post("/programs/wired-in/sync")
assert synced.status_code == 200
s = synced.json()
assert s["status"] == "ok" and s["pulled"] is True
assert "wired-in" in s["deployments"] # affected deployment surfaced
assert (work / "b.txt").exists()
# A second sync is a no-op: nothing pulled, no affected deployments.
again = client.post("/programs/wired-in/sync").json()
assert again["pulled"] is False and again["deployments"] == []
def test_sync_unknown_program_404(self, client: TestClient) -> None:
assert client.post("/programs/nope/sync").status_code == 404
def test_sync_non_git_source_400(self, client: TestClient) -> None:
assert client.post("/programs/test-tool/sync").status_code == 400