test(freeze): 增长冻结改盯耦合,行数降为粗护栏
Home() useState/useRef 与 JyotishAPIHandler 类方法/__new__ 不得增长。行数改为开工实测基线加余量。产品授权删除参数式 hook 零 React hook 规则。
This commit is contained in:
@@ -1,30 +1,81 @@
|
||||
"""Freeze scripts/jyotish_api_server.py growth.
|
||||
"""Freeze coupling in scripts/jyotish_api_server.py.
|
||||
|
||||
New endpoints and features must live in new modules and be thinly registered
|
||||
from the main file. This cap is the live line count at freeze (11063 on
|
||||
2026-09-02, via `wc -l`) plus 300 lines of bugfix slack.
|
||||
from the main file. Line count is only a coarse guardrail; the live gates are
|
||||
JyotishAPIHandler method count and JyotishAPIHandler.__new__ forgery sites.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
API_SERVER = ROOT / "scripts" / "jyotish_api_server.py"
|
||||
AGENTS = ROOT / "AGENTS.md"
|
||||
|
||||
# Live `wc -l scripts/jyotish_api_server.py` at freeze. New features must not
|
||||
# consume this budget; open a module instead.
|
||||
JYOTISH_API_SERVER_LINE_COUNT_BASELINE = 11063
|
||||
# Live `wc -l scripts/jyotish_api_server.py` equivalent:
|
||||
# Path.read_bytes().count(b"\n"), measured 2026-09-16 on origin/staging @ 51a65d92.
|
||||
# New features must not consume this budget; open a module instead.
|
||||
JYOTISH_API_SERVER_LINE_COUNT_BASELINE = 11291
|
||||
JYOTISH_API_SERVER_LINE_COUNT_CAP = JYOTISH_API_SERVER_LINE_COUNT_BASELINE + 300
|
||||
|
||||
# Whole-file indent match `^ (?:async )?def \w+`, same count as
|
||||
# TASK-freeze-metric-change-20260915 §1. Measured 2026-09-16 @ 51a65d92.
|
||||
JYOTISH_API_HANDLER_METHOD_COUNT_BASELINE = 225
|
||||
|
||||
# `JyotishAPIHandler.__new__` in scripts/ and tests/ `*.py`, excluding this file.
|
||||
# Measured 2026-09-16 @ 51a65d92: scripts/ production forgeries = 4, tests/ = 29.
|
||||
JYOTISH_API_HANDLER_NEW_COUNT_BASELINE = 33
|
||||
|
||||
HANDLER_METHOD_RE = re.compile(r"^ (?:async )?def \w+", re.MULTILINE)
|
||||
NEW_MARKER = "JyotishAPIHandler.__new__"
|
||||
|
||||
|
||||
def _handler_method_count(source: str) -> int:
|
||||
return len(HANDLER_METHOD_RE.findall(source))
|
||||
|
||||
|
||||
def _new_hits() -> Counter[str]:
|
||||
hits: Counter[str] = Counter()
|
||||
skip = Path(__file__).resolve()
|
||||
for folder in (ROOT / "scripts", ROOT / "tests"):
|
||||
for path in sorted(folder.rglob("*.py")):
|
||||
if path.resolve() == skip:
|
||||
continue
|
||||
count = path.read_text(encoding="utf-8").count(NEW_MARKER)
|
||||
if count:
|
||||
hits[path.relative_to(ROOT).as_posix()] = count
|
||||
return hits
|
||||
|
||||
|
||||
def test_jyotish_api_handler_method_count_must_not_grow() -> None:
|
||||
source = API_SERVER.read_text(encoding="utf-8")
|
||||
count = _handler_method_count(source)
|
||||
assert count <= JYOTISH_API_HANDLER_METHOD_COUNT_BASELINE, (
|
||||
f"{API_SERVER.as_posix()} has {count} four-space def methods; "
|
||||
f"cap is {JYOTISH_API_HANDLER_METHOD_COUNT_BASELINE}. Move behaviour "
|
||||
"into a dedicated module; thinly registered from this file."
|
||||
)
|
||||
|
||||
|
||||
def test_jyotish_api_handler_new_count_must_not_grow() -> None:
|
||||
hits = _new_hits()
|
||||
total = sum(hits.values())
|
||||
listed = ", ".join(f"{path}:{count}" for path, count in sorted(hits.items()))
|
||||
assert total <= JYOTISH_API_HANDLER_NEW_COUNT_BASELINE, (
|
||||
f"{NEW_MARKER} appears {total} times under scripts/ and tests/; "
|
||||
f"cap is {JYOTISH_API_HANDLER_NEW_COUNT_BASELINE}. Hits: {listed}"
|
||||
)
|
||||
|
||||
|
||||
def test_jyotish_api_server_must_not_grow_beyond_bugfix_slack() -> None:
|
||||
line_count = API_SERVER.read_bytes().count(b"\n")
|
||||
assert line_count <= JYOTISH_API_SERVER_LINE_COUNT_CAP, (
|
||||
f"{API_SERVER.as_posix()} has {line_count} lines; cap is "
|
||||
f"{JYOTISH_API_SERVER_LINE_COUNT_CAP} ({JYOTISH_API_SERVER_LINE_COUNT_BASELINE} "
|
||||
"baseline + 300 bugfix slack). New endpoints and features must be new "
|
||||
"baseline + 300 coarse guardrail). New endpoints and features must be new "
|
||||
"modules, thinly registered from this file."
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user