Coverage for astrocyte/_validation.py: 100%
7 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-04 05:24 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-04 05:24 +0000
1"""Shared validation helpers — used by _astrocyte.py and _policy.py."""
3from __future__ import annotations
5import re
7from astrocyte.errors import ConfigError
9_BANK_ID_RE = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9._:@\-]{0,254}$")
12def validate_bank_id(bank_id: str) -> None:
13 """Validate bank_id format: 1–255 chars, alphanumeric start, safe characters only."""
14 if not bank_id or not _BANK_ID_RE.match(bank_id):
15 raise ConfigError(
16 f"Invalid bank_id {bank_id!r}: must be 1–255 characters, "
17 "start with alphanumeric, and contain only [a-zA-Z0-9._:@-]"
18 )