Files
computer-playbook/tests/unit/python/plugins/lookup/test_network_siblings.py
T
kevinveenbirkenbachandClaude Opus 5.5 e2beab9f1c test(domains): read the primary domain from default.env in every test
The hardcoded-primary-domain lint exempted tests/ and scripts/tests/, so test
fixtures kept their own copy of the domain and would drift from
INFINITO_DOMAIN the moment it changes. The lint now scans both trees, and a
unit test pins its scope: only default.env, Markdown, inventories/, .claude/
and build/ may name the domain.

Python tests take the value from default_domain_primary(), and the workspace
helper builds its dashboard and Matomo URLs from INFINITO_DOMAIN once the repo
.env is loaded.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 22:53:54 +02:00

70 lines
2.4 KiB
Python

"""Contract of ``lookup('network_siblings')``: every logical domain renders
once per network its app is served on, and exactly once overall."""
from __future__ import annotations
import unittest
from plugins.lookup.network_siblings import served_siblings
from utils.domains.default_primary import default_domain_primary
ONION = "abc123def456ghij789klmno000pqrstuvwx111yz222abc333def444gh.onion"
PRIMARY = default_domain_primary()
class TestServedSiblings(unittest.TestCase):
def test_multi_app_renders_both_networks_from_the_canonical_domain(self) -> None:
domains = {"web-app-x": [f"x.{PRIMARY}", f"x.{ONION}"]}
self.assertEqual(
served_siblings(f"x.{PRIMARY}", domains, PRIMARY, ONION),
[f"x.{PRIMARY}", f"x.{ONION}"],
)
def test_multi_app_skips_the_non_canonical_sibling(self) -> None:
domains = {"web-app-x": [f"x.{PRIMARY}", f"x.{ONION}"]}
self.assertEqual(served_siblings(f"x.{ONION}", domains, PRIMARY, ONION), [])
def test_tor_only_app_maps_a_raw_clearnet_domain_to_its_onion(self) -> None:
domains = {"web-app-x": [f"x.{ONION}"]}
self.assertEqual(
served_siblings(f"x.{PRIMARY}", domains, PRIMARY, ONION), [f"x.{ONION}"]
)
def test_clearnet_only_app_renders_one_vhost(self) -> None:
domains = {"web-app-x": [f"x.{PRIMARY}"]}
self.assertEqual(
served_siblings(f"x.{PRIMARY}", domains, PRIMARY, ONION),
[f"x.{PRIMARY}"],
)
def test_named_canonicals_fan_out_per_key(self) -> None:
domains = {
"web-app-x": {
"api": f"api.{PRIMARY}",
"web": f"web.{PRIMARY}",
"api_onion": f"api.{ONION}",
"web_onion": f"web.{ONION}",
}
}
self.assertEqual(
served_siblings(f"web.{PRIMARY}", domains, PRIMARY, ONION),
[f"web.{PRIMARY}", f"web.{ONION}"],
)
def test_unknown_domain_renders_as_given(self) -> None:
self.assertEqual(
served_siblings("elsewhere.example", {}, PRIMARY, ONION),
["elsewhere.example"],
)
def test_node_without_tor_renders_as_given(self) -> None:
domains = {"web-app-x": [f"x.{PRIMARY}"]}
self.assertEqual(
served_siblings(f"x.{PRIMARY}", domains, PRIMARY, ""),
[f"x.{PRIMARY}"],
)
if __name__ == "__main__":
unittest.main()