CLI db binding fix + true two-process satellite setup e2e

cmd_satellite constructs its own Kanta bound to the global db object on
the resolved path — the lifecycle module's import-time binding would
follow the wrong directory if CWD changed after import. The new e2e runs
'paskia satellite <url>' as a real subprocess against the live upstream:
own database created, link key material identical on both sides, pushed
domain stored as remote.
This commit is contained in:
LeoVasanko committed 2026-10-01 06:46:36 +00:00
1 parent fa0d03729b
commit 6d49b59cec
2 files changed
+58 -1

No files matched your search

+52
View File
@@ -20,6 +20,8 @@ a mocked forward_request.
import asyncio
import os
import socket
import subprocess
import sys
import time
from datetime import UTC, datetime, timedelta
from types import SimpleNamespace
@@ -30,10 +32,12 @@ import msgspec.structs
import pytest
import pytest_asyncio
import uvicorn
from kanta import Kanta
import paskia.db.operations as ops_db
from paskia import domains, satellite
from paskia.db.structs import (
DB,
Config,
Credential,
DomainConfig,
@@ -226,6 +230,54 @@ async def test_live_registration_rejections(live_server):
assert not live_server.db.satellite_links
@pytest.mark.asyncio
async def test_cli_satellite_command(live_server, tmp_path):
"""The whole satellite-only setup, two processes: the CLI registers
against the live upstream (creating its own database on the way) and
stores the link and the pushed domains — 'paskia' then serves them."""
live = live_server
ops_db.create_domain(
REMOTE_DOMAIN,
DomainConfig(
rp_name="Example",
origins={
f"**.{REMOTE_DOMAIN}": True,
f"auth.{REMOTE_DOMAIN}": OriginEntry(auth_host=True),
},
),
)
offer_url = sync.create_offer([REMOTE_DOMAIN], live.url)
proc = await asyncio.to_thread(
subprocess.run,
[sys.executable, "-m", "paskia", "satellite", offer_url],
cwd=tmp_path,
capture_output=True,
text=True,
env={k: v for k, v in os.environ.items() if not k.startswith("PASKIA_")},
timeout=60,
)
assert proc.returncode == 0, proc.stderr
assert REMOTE_DOMAIN in proc.stdout
# The satellite's own database holds the uplink and the pushed domain,
# and both sides hold the same key material for the link.
sat_db_path = tmp_path / "paskia.kantadb"
kanta = Kanta(str(sat_db_path), DB())
await kanta.open(readonly=True)
try:
sat_domains = dict(kanta.data.config.domains)
uplinks = dict(kanta.data.uplinks)
finally:
await kanta.close()
domain = sat_domains[REMOTE_DOMAIN]
assert domain.remote is not None
assert domain.rp_name == "Example"
((link_id, uplink),) = uplinks.items()
assert uplink.url == live.url
assert live.db.satellite_links[link_id].key == uplink.key
assert live.db.satellite_links[link_id].rp_ids == [REMOTE_DOMAIN]
# -------------------------------------------------------------------------
# Established link: sync behavior
# -------------------------------------------------------------------------