FETCHERS allow-list only catches from argus_cortex.net import fetch-style imports
The finding
The FETCHERS check only runs for an ast.ImportFrom whose module is exactly argus_cortex.net and whose imported names intersect FETCH_NAMES. Several common import forms reach the same fetch function without triggering it:
- from argus_cortex import net followed by net.fetch(...) (module is argus_cortex).
- import argus_cortex.net followed by argus_cortex.net.fetch(...) (an ast.Import, which never checks FETCHERS).
- from argus_cortex.net import * (the alias name is *, not in FETCH_NAMES).
- from argus_cortex.net import fetch as f. This one is still caught, because a.name is the original name.
As a result, any module outside the Prometheus client and status poller can make network calls through cortex while this test stays green. That defeats the guard on scout's 'reads telemetry through PromQL only, never acts' invariant.
1| from __future__ import annotations
2|
3| import ast
4| import functools
5| import json
6| import math
7| from datetime import UTC, datetime, timedelta
8| from pathlib import Path
9| from urllib.parse import parse_qs, urlsplit
10|
11| import httpx
12| import pytest
13| from argus_cortex.net import Reply, UrlRefused, afetch
14|
15| from argus_scout.prometheus import (
16| PrometheusClient,
17| PrometheusQueryError,
18| PrometheusResponseError,
19| PrometheusUnavailable,
20| parse_matrix,
21| parse_vector,
22| )
23| The work pack
Recommendation. Flag every import that resolves to argus_cortex.net, including:
- ast.Import aliases named argus_cortex.net.
- ImportFrom with module argus_cortex that imports net.
- Star imports.
Also scan for ast.Attribute nodes whose .attr is in FETCH_NAMES.
In all of these cases, assert rel in FETCHERS.
Acceptance criteria
- Address: FETCHERS allow-list only catches
from argus_cortex.net import fetch-style imports - Keep the change scoped to the cited file/symbols unless impact requires otherwise
- Flag every import that resolves to
argus_cortex.net, including: -ast.Importaliases namedargus_cortex.net. -ImportFromwith moduleargus_cortexthat importsnet. - Star imports. Also scan forast.Attributenodes whose `.att - Re-check
tests/test_prometheus.pyafter the fix
Status
- claimed
- resolved
The fix
3c79645a2a test: the network-access check covers every import form and fetch attribute. This commit closes 2 packs.
@@ -252,28 +252,82 @@ RAW_SOCKET_USERS = {"channels/snapcast.py"} WEBSOCKET_USERS = {"channels/mask.py"} +def network_violations(rel: str, source: str) -> list[str]:+ """How the module at ``rel`` (relative to ``src/argus_scout``) would reach the network beyond what it may.++ Every import form counts: ``import x.y``, ``from x import y`` (checked as ``x`` and ``x.y``, so+ ``from urllib import request`` is ``urllib.request``), ``argus_cortex.net`` reached as ``import argus_cortex.net``,+ ``from argus_cortex import net`` or ``from argus_cortex.net import *``, and any ``.fetch`` / ``.afetch``+ attribute."""+ found: list[str] = []+ tree = ast.parse(source)+ for node in ast.walk(tree):+ fetches = False+ if isinstance(node, ast.Import):+ names = {a.name for a in node.names}+ fetches = any(n == "argus_cortex.net" or n.startswith("argus_cortex.net.") for n in names)+ elif isinstance(node, ast.ImportFrom):+ module = node.module or ""+ aliases = {a.name for a in node.names}+ names = {module} | {f"{module}.{a}" for a in aliases}+ fetches = (module == "argus_cortex.net" and bool(aliases & (FETCH_NAMES | {"*"}))) or (+ module == "argus_cortex" and bool(aliases & {"net", "*"})+ )+ elif isinstance(node, ast.Attribute):+ names = set()+ fetches = node.attr in FETCH_NAMES+ else:+ continue+ if fetches and rel not in FETCHERS:+ found.append(f"{rel}:{node.lineno} fetches over the network")+ bad = {n for n in names if n in NETWORK_MODULES or n.split(".")[0] in {"httpx", "requests", "aiohttp"}}+ if bad:+ found.append(f"{rel}:{node.lineno} imports {sorted(bad)}")+ if rel not in WEBSOCKET_USERS and {n for n in names if n.split(".")[0] == "websockets"}:+ found.append(f"{rel}:{node.lineno} opens WebSockets")+ if rel not in RAW_SOCKET_USERS:+ calls = {n.attr for n in ast.walk(tree) if isinstance(n, ast.Attribute) and n.attr in RAW_SOCKET_CALLS} | {+ n.id for n in ast.walk(tree) if isinstance(n, ast.Name) and n.id in RAW_SOCKET_CALLS+ }+ if calls:+ found.append(f"{rel} opens raw sockets: {sorted(calls)}")+ return found++ def test_no_module_contacts_hosts_directly(): """Scout reads telemetry through PromQL only: no module opens sockets or HTTP clients of its own, and only the Prometheus client and the status poller use argus_cortex.net's fetch."""+ found = [] for path in SRC.rglob("*.py"):- rel = path.relative_to(SRC).as_posix()- tree = ast.parse(path.read_text())- for node in ast.walk(tree):- if isinstance(node, ast.Import):- names = {a.name for a in node.names}- elif isinstance(node, ast.ImportFrom):- names = {node.module or ""}- if node.module == "argus_cortex.net" and {a.name for a in node.names} & FETCH_NAMES:- assert rel in FETCHERS, f"{rel} fetches over the network"- else:- continue- bad = {n for n in names if n in NETWORK_MODULES or n.split(".")[0] in {"httpx", "requests", "aiohttp"}}- assert not bad, f"{rel} imports {bad}"- if rel not in WEBSOCKET_USERS:- ws = {n for n in names if n.split(".")[0] == "websockets"}- assert not ws, f"{rel} opens WebSockets: {ws}"- if rel not in RAW_SOCKET_USERS:- calls = {n.attr for n in ast.walk(tree) if isinstance(n, ast.Attribute) and n.attr in RAW_SOCKET_CALLS} | {- n.id for n in ast.walk(tree) if isinstance(n, ast.Name) and n.id in RAW_SOCKET_CALLS- }- assert not calls, f"{rel} opens raw sockets: {calls}"+ found += network_violations(path.relative_to(SRC).as_posix(), path.read_text())+ assert found == []+++@pytest.mark.parametrize(+ "source",+ [+ "from argus_cortex.net import fetch",+ "from argus_cortex.net import afetch as get",+ "from argus_cortex.net import *",+ "from argus_cortex import net",+ "import argus_cortex.net",+ "client.afetch(url)",+ "from urllib import request",+ "from http import client",+ "import urllib.request",+ "from httpx import AsyncClient",+ "import socket",+ "from websockets import client",+ "await asyncio.open_connection(host, 1705)",+ ],+)+def test_network_check_catches_every_import_form(source):+ assert network_violations("narrative.py", source), source+++def test_network_check_allows_what_it_should():+ assert (+ network_violations("narrative.py", "from urllib.parse import urlsplit\nfrom argus_cortex.net import check_url")+ == []+ )+ assert network_violations("prometheus.py", "from argus_cortex.net import afetch\nawait afetch(url)") == []How it was judged
Waiver evidence waived: Test-only finding: the fix strengthens a test, so the same test runs on both trees and passes on dev's source. Verified locally by mutation: the strengthened test fails when the guarded behaviour is b
Judged 24 Nov 2026, 04:55 UTC against dev at d0c0f66.
This fix strengthens a test. The stronger test passes on dev's code as well, so there is no failure on dev for it to show. It resolved on a written waiver of at least twenty characters, recorded with the pack:
Test-only finding: the fix strengthens a test, so the same test runs on both trees and passes on dev's source. Verified locally by mutation: the strengthened test fails when the guarded behaviour is broken, where the old one passed.