Files
computer-playbook/roles/web-app-homeassistant/files/python/probe_mcp_token.py
kevinveenbirkenbachandClaude Opus 5 dfe7a7fdd4 refactor(roles): sort role scripts into per-language folders
The merged branch moved every role-local script out of files/ into a folder
named for its language (files/python/, files/php/, files/shell/), but the
moves lost their staging and never landed. HEAD still carried the old paths
while the worktree had the new ones.

Move the 24 remaining scripts and update the six places that resolve them:
the mcp-adapter instance/isolation/probe tasks, the litellm key task, the
adapter README and the endpoint-path lint. Every changed line in those
files is a path.

Also drop roles/sys-svc-compose/files/swarm/stack_ready.sh, a stale
duplicate of the copy already tracked under files/shell/swarm/.

The added comments are the branch's own `nocheck: mirrored-unit-test`
directives, which state why a script whose measurement only exists inside
its container cannot have a mirrored unit test.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 12:00:59 +02:00

29 lines
1.0 KiB
Python

# nocheck: mirrored-unit-test - the whole module is one authenticated GET against the
# running hub, issued at import from the container's own environment; there is no
# callable unit below it
"""Report whether the stored Home Assistant token still authenticates.
Environment:
HA_PORT: the hub's internal port.
HA_TOKEN: the token to present.
"""
import os
import urllib.error
import urllib.request
TRANSIENT_STATUS = frozenset({429, 502, 503, 504})
req = urllib.request.Request(
"http://localhost:" + os.environ["HA_PORT"] + "/api/",
headers={"Authorization": "Bearer " + os.environ["HA_TOKEN"]},
)
try:
with urllib.request.urlopen(req, timeout=30) as response: # noqa: S310 - fixed http://localhost loopback of the hub
print("ACCEPTED", response.status)
except urllib.error.HTTPError as err:
marker = "PENDING" if err.code in TRANSIENT_STATUS else "REJECTED"
raise SystemExit(f"{marker} {err.code}") from err
except OSError as err:
raise SystemExit(f"PENDING unreachable: {err}") from err