Private
Public Access
0
0
Files
manual_slop/scripts/tier2/apply_t1_1_edits.py
T
ed 5351389fc0 refactor(ai_client): rename send_result to send (the impl, TDD red moment)
The TDD red moment. The implementation is renamed but the call sites
in src/, tests/, and docs still use send_result. Subsequent commits
rename the call sites and progressively move the test suite back to
green.

10 references renamed in src/ai_client.py:
- 4 'Called by: send_result' docstring tags in private provider helpers
- 1 function definition (def send_result -> def send)
- 1 [C: ...] SDM tag referencing test function names
- 2 monitor component names (start_component / end_component)
- 2 error source strings (CONFIG + INTERNAL)

Also adds scripts/tier2/apply_t1_1_edits.py - the helper script that
applied the 10 edits. Kept in scripts/tier2/ as a record of the
mechanical change pattern.

Refs: conductor/tracks/send_result_to_send_20260616/
2026-06-17 00:23:16 -04:00

86 lines
3.0 KiB
Python

"""Apply the 10 send_result -> send edits to src/ai_client.py.
This is a one-shot script for Task 1.1. Idempotent: re-running is a no-op
if the rename is already complete.
"""
from __future__ import annotations
import sys
from pathlib import Path
FILE = Path("src/ai_client.py")
EDITS: list[tuple[str, str]] = [
(
" Immediate-Mode DAG / Thread Context:\n Called by: send_result\n Calls: _ensure_grok_client",
" Immediate-Mode DAG / Thread Context:\n Called by: send\n Calls: _ensure_grok_client",
),
(
" Immediate-Mode DAG / Thread Context:\n Called by: send_result\n Calls: _ensure_minimax_client",
" Immediate-Mode DAG / Thread Context:\n Called by: send\n Calls: _ensure_minimax_client",
),
(
" Immediate-Mode DAG / Thread Context:\n Called by: send_result\n Calls: _ensure_qwen_client",
" Immediate-Mode DAG / Thread Context:\n Called by: send\n Calls: _ensure_qwen_client",
),
(
" Immediate-Mode DAG / Thread Context:\n Called by: send_result\n Calls: _send_llama_native",
" Immediate-Mode DAG / Thread Context:\n Called by: send\n Calls: _send_llama_native",
),
(
"def send_result(\n md_content: str,",
"def send(\n md_content: str,",
),
(
"[C: tests/test_ai_client_result.py:test_send_result_public_api_returns_result, tests/test_ai_client_result.py:test_send_result_preserves_errors, tests/test_deprecation_warnings.py:test_send_result_does_not_emit_deprecation]",
"[C: tests/test_ai_client_result.py:test_send_public_api_returns_result, tests/test_ai_client_result.py:test_send_preserves_errors, tests/test_deprecation_warnings.py:test_send_does_not_emit_deprecation]",
),
(
'if monitor.enabled: monitor.start_component("ai_client.send_result")',
'if monitor.enabled: monitor.start_component("ai_client.send")',
),
(
'source="ai_client.send_result")])',
'source="ai_client.send")])',
),
(
'source="ai_client.send_result", original=exc)',
'source="ai_client.send", original=exc)',
),
(
'if monitor.enabled: monitor.end_component("ai_client.send_result")',
'if monitor.enabled: monitor.end_component("ai_client.send")',
),
]
def main() -> int:
with FILE.open("r", encoding="utf-8", newline="") as f:
content = f.read()
has_crlf = "\r\n" in content
nl = "\r\n" if has_crlf else "\n"
normalized_edits = [
(old.replace("\n", nl), new.replace("\n", nl)) for old, new in EDITS
]
new_content = content
applied = 0
for old, new in normalized_edits:
if old in new_content:
new_content = new_content.replace(old, new, 1)
applied += 1
else:
print(f"NOT FOUND: {old[:80]!r}", file=sys.stderr)
if applied != len(EDITS):
print(f"Only applied {applied}/{len(EDITS)} edits. ABORTING.", file=sys.stderr)
return 1
with FILE.open("w", encoding="utf-8", newline="") as f:
f.write(new_content)
remaining = new_content.count("send_result")
print(f"Applied {applied}/{len(EDITS)} edits. Remaining send_result: {remaining}")
print(f"Line endings: {'CRLF' if has_crlf else 'LF'}")
return 0
if __name__ == "__main__":
raise SystemExit(main())