Skip to content

Commit 3473e5b

Browse files
authored
refactor(operator-trend): collapse tier-rollup summary renderers onto a parametrized base (T3-2 phase 6f) (#88)
Collapse the rebuild / restore / rerererestore reset-reentry summary renderers onto one `_tier_summary_base` + `_TierSummarySpec` + per-tier specs. The three were structural clones differing only in the status key they read, the per-tier status tokens, and reworded prose; the shared status-string render skeleton was triplicated, the same drift risk that produced the phase-5 floor/freshness fixes. Proven byte-identical two ways: an exhaustive branch differential (168 cases per tier, spanning every status branch, hotspot fallback, blocked-reason presence, and label / hotspot-label combination) and the composer golden contract (zero diff). Public signatures unchanged; the prose templates were extracted from the source AST, never hand-typed.
1 parent b07409d commit 3473e5b

1 file changed

Lines changed: 126 additions & 128 deletions

File tree

src/operator_trend_closure_forecast_reset_controls.py

Lines changed: 126 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,56 +1656,137 @@ def closure_forecast_reset_reentry_refresh_recovery_summary(
16561656
return "No reset re-entry rebuild attempt is active enough yet to re-earn stronger restored posture."
16571657

16581658

1659-
def closure_forecast_reset_reentry_rebuild_summary(
1659+
class _TierSummarySpec(NamedTuple):
1660+
"""Tier-specific literals for the reset-reentry tier-rollup summary renderer.
1661+
1662+
The rebuild / restore / rerererestore rollup summaries share one
1663+
status-string-driven render algorithm (proven byte-identical by the composer
1664+
golden plus an exhaustive branch differential) and differ only in the status
1665+
key they read, the per-tier status tokens, and the reworded prose. The
1666+
``*_text`` fields are ``str.format`` templates over ``{label}`` and
1667+
``{hotspot_label}``.
1668+
"""
1669+
1670+
status_key: str
1671+
reason_key: str
1672+
pending_confirmation_status: str
1673+
pending_clearance_status: str
1674+
settled_confirmation_status: str
1675+
settled_clearance_status: str
1676+
pending_confirmation_text: str
1677+
pending_clearance_text: str
1678+
settled_confirmation_text: str
1679+
settled_clearance_text: str
1680+
blocked_reason_default: str
1681+
recovering_confirmation_text: str
1682+
recovering_clearance_text: str
1683+
default_text: str
1684+
1685+
1686+
def _tier_summary_base(
16601687
primary_target: dict[str, Any],
16611688
recovering_confirmation_hotspots: list[dict[str, Any]],
16621689
recovering_clearance_hotspots: list[dict[str, Any]],
16631690
*,
1691+
spec: _TierSummarySpec,
16641692
target_label: Callable[[dict[str, Any]], str],
16651693
) -> str:
16661694
label = target_label(primary_target) or "The current target"
1667-
status = str(primary_target.get("closure_forecast_reset_reentry_rebuild_status", "none"))
1668-
if status == "pending-confirmation-rebuild":
1669-
return (
1670-
f"Fresh confirmation-side evidence is returning after reset re-entry softened or reset for {label}, "
1671-
"but stronger reset re-entry still needs more fresh follow-through before it is rebuilt."
1672-
)
1673-
if status == "pending-clearance-rebuild":
1674-
return (
1675-
f"Fresh clearance-side evidence is returning after reset re-entry softened or reset for {label}, "
1676-
"but stronger reset re-entry still needs more fresh follow-through before it is rebuilt."
1677-
)
1678-
if status == "rebuilt-confirmation-reentry":
1679-
return (
1680-
f"Fresh confirmation-side follow-through for {label} has rebuilt stronger "
1681-
"confirmation-side reset re-entry."
1682-
)
1683-
if status == "rebuilt-clearance-reentry":
1684-
return (
1685-
f"Fresh clearance-side pressure for {label} has rebuilt stronger clearance-side "
1686-
"reset re-entry."
1687-
)
1695+
status = str(primary_target.get(spec.status_key, "none"))
1696+
if status == spec.pending_confirmation_status:
1697+
return spec.pending_confirmation_text.format(label=label)
1698+
if status == spec.pending_clearance_status:
1699+
return spec.pending_clearance_text.format(label=label)
1700+
if status == spec.settled_confirmation_status:
1701+
return spec.settled_confirmation_text.format(label=label)
1702+
if status == spec.settled_clearance_status:
1703+
return spec.settled_clearance_text.format(label=label)
16881704
if status == "blocked":
16891705
return str(
16901706
primary_target.get(
1691-
"closure_forecast_reset_reentry_rebuild_reason",
1692-
f"Local target instability is still preventing positive confirmation-side "
1693-
f"reset re-entry rebuild for {label}.",
1707+
spec.reason_key,
1708+
spec.blocked_reason_default.format(label=label),
16941709
)
16951710
)
16961711
if recovering_confirmation_hotspots:
16971712
hotspot = recovering_confirmation_hotspots[0]
1698-
return (
1699-
f"Confirmation-side reset re-entry rebuild is closest around {hotspot.get('label', 'recent hotspots')}, "
1700-
"but it still needs one more layer of fresh confirmation follow-through."
1713+
return spec.recovering_confirmation_text.format(
1714+
hotspot_label=hotspot.get("label", "recent hotspots")
17011715
)
17021716
if recovering_clearance_hotspots:
17031717
hotspot = recovering_clearance_hotspots[0]
1704-
return (
1705-
f"Clearance-side reset re-entry rebuild is closest around {hotspot.get('label', 'recent hotspots')}, "
1706-
"but it still needs one more layer of fresh clearance follow-through."
1707-
)
1708-
return "No reset re-entry rebuild is changing the current restored closure-forecast posture right now."
1718+
return spec.recovering_clearance_text.format(
1719+
hotspot_label=hotspot.get("label", "recent hotspots")
1720+
)
1721+
return spec.default_text
1722+
1723+
1724+
_REBUILD_SUMMARY_SPEC = _TierSummarySpec(
1725+
status_key='closure_forecast_reset_reentry_rebuild_status',
1726+
reason_key='closure_forecast_reset_reentry_rebuild_reason',
1727+
pending_confirmation_status='pending-confirmation-rebuild',
1728+
pending_clearance_status='pending-clearance-rebuild',
1729+
settled_confirmation_status='rebuilt-confirmation-reentry',
1730+
settled_clearance_status='rebuilt-clearance-reentry',
1731+
pending_confirmation_text='Fresh confirmation-side evidence is returning after reset re-entry softened or reset for {label}, but stronger reset re-entry still needs more fresh follow-through before it is rebuilt.',
1732+
pending_clearance_text='Fresh clearance-side evidence is returning after reset re-entry softened or reset for {label}, but stronger reset re-entry still needs more fresh follow-through before it is rebuilt.',
1733+
settled_confirmation_text='Fresh confirmation-side follow-through for {label} has rebuilt stronger confirmation-side reset re-entry.',
1734+
settled_clearance_text='Fresh clearance-side pressure for {label} has rebuilt stronger clearance-side reset re-entry.',
1735+
blocked_reason_default='Local target instability is still preventing positive confirmation-side reset re-entry rebuild for {label}.',
1736+
recovering_confirmation_text='Confirmation-side reset re-entry rebuild is closest around {hotspot_label}, but it still needs one more layer of fresh confirmation follow-through.',
1737+
recovering_clearance_text='Clearance-side reset re-entry rebuild is closest around {hotspot_label}, but it still needs one more layer of fresh clearance follow-through.',
1738+
default_text='No reset re-entry rebuild is changing the current restored closure-forecast posture right now.',
1739+
)
1740+
1741+
_RESTORE_SUMMARY_SPEC = _TierSummarySpec(
1742+
status_key='closure_forecast_reset_reentry_rebuild_reentry_restore_status',
1743+
reason_key='closure_forecast_reset_reentry_rebuild_reentry_restore_reason',
1744+
pending_confirmation_status='pending-confirmation-rebuild-reentry-restore',
1745+
pending_clearance_status='pending-clearance-rebuild-reentry-restore',
1746+
settled_confirmation_status='restored-confirmation-rebuild-reentry',
1747+
settled_clearance_status='restored-clearance-rebuild-reentry',
1748+
pending_confirmation_text='Fresh confirmation-side evidence is returning after rebuilt re-entry softened or reset for {label}, but stronger rebuilt re-entry posture still needs more fresh follow-through before it is restored.',
1749+
pending_clearance_text='Fresh clearance-side evidence is returning after rebuilt re-entry softened or reset for {label}, but stronger rebuilt re-entry posture still needs more fresh follow-through before it is restored.',
1750+
settled_confirmation_text='Fresh confirmation-side follow-through for {label} has restored stronger rebuilt re-entry posture.',
1751+
settled_clearance_text='Fresh clearance-side pressure for {label} has restored stronger rebuilt re-entry posture.',
1752+
blocked_reason_default='Local target instability is still preventing positive confirmation-side rebuilt re-entry restore for {label}.',
1753+
recovering_confirmation_text='Confirmation-side rebuilt re-entry is closest to being restored around {hotspot_label}, but it still needs one more layer of fresh confirmation follow-through.',
1754+
recovering_clearance_text='Clearance-side rebuilt re-entry is closest to being restored around {hotspot_label}, but it still needs one more layer of fresh clearance follow-through.',
1755+
default_text='No rebuilt re-entry restore control is changing the current closure-forecast posture right now.',
1756+
)
1757+
1758+
_RERERERESTORE_SUMMARY_SPEC = _TierSummarySpec(
1759+
status_key='closure_forecast_reset_reentry_rebuild_reentry_restore_rerererestore_status',
1760+
reason_key='closure_forecast_reset_reentry_rebuild_reentry_restore_rerererestore_reason',
1761+
pending_confirmation_status='pending-confirmation-rebuild-reentry-rerererestore',
1762+
pending_clearance_status='pending-clearance-rebuild-reentry-rerererestore',
1763+
settled_confirmation_status='rerererestored-confirmation-rebuild-reentry',
1764+
settled_clearance_status='rerererestored-clearance-rebuild-reentry',
1765+
pending_confirmation_text='Fresh confirmation-side evidence is returning after re-re-restored rebuilt re-entry softened or reset for {label}, but stronger re-re-restored posture still needs more fresh follow-through before it is re-re-re-restored.',
1766+
pending_clearance_text='Fresh clearance-side evidence is returning after re-re-restored rebuilt re-entry softened or reset for {label}, but stronger re-re-restored posture still needs more fresh follow-through before it is re-re-re-restored.',
1767+
settled_confirmation_text='Fresh confirmation-side follow-through for {label} has re-re-re-restored stronger re-re-restored rebuilt re-entry posture.',
1768+
settled_clearance_text='Fresh clearance-side pressure for {label} has re-re-re-restored stronger re-re-restored rebuilt re-entry posture.',
1769+
blocked_reason_default='Local target instability is still preventing positive confirmation-side re-re-restored rebuilt re-entry re-re-re-restore for {label}.',
1770+
recovering_confirmation_text='Confirmation-side re-re-restored rebuilt re-entry is closest to being re-re-re-restored around {hotspot_label}, but it still needs one more layer of fresh confirmation follow-through.',
1771+
recovering_clearance_text='Clearance-side re-re-restored rebuilt re-entry is closest to being re-re-re-restored around {hotspot_label}, but it still needs one more layer of fresh clearance follow-through.',
1772+
default_text='No re-re-restored rebuilt re-entry re-re-re-restore control is changing the current closure-forecast posture right now.',
1773+
)
1774+
1775+
1776+
def closure_forecast_reset_reentry_rebuild_summary(
1777+
primary_target: dict[str, Any],
1778+
recovering_confirmation_hotspots: list[dict[str, Any]],
1779+
recovering_clearance_hotspots: list[dict[str, Any]],
1780+
*,
1781+
target_label: Callable[[dict[str, Any]], str],
1782+
) -> str:
1783+
return _tier_summary_base(
1784+
primary_target,
1785+
recovering_confirmation_hotspots,
1786+
recovering_clearance_hotspots,
1787+
spec=_REBUILD_SUMMARY_SPEC,
1788+
target_label=target_label,
1789+
)
17091790

17101791

17111792
def _reset_reentry_rebuild_event_is_confirmation_like(
@@ -4297,46 +4378,13 @@ def closure_forecast_reset_reentry_rebuild_reentry_restore_summary(
42974378
*,
42984379
target_label: Callable[[dict[str, Any]], str],
42994380
) -> str:
4300-
label = target_label(primary_target) or "The current target"
4301-
status = str(
4302-
primary_target.get("closure_forecast_reset_reentry_rebuild_reentry_restore_status", "none")
4381+
return _tier_summary_base(
4382+
primary_target,
4383+
recovering_confirmation_hotspots,
4384+
recovering_clearance_hotspots,
4385+
spec=_RESTORE_SUMMARY_SPEC,
4386+
target_label=target_label,
43034387
)
4304-
if status == "pending-confirmation-rebuild-reentry-restore":
4305-
return (
4306-
f"Fresh confirmation-side evidence is returning after rebuilt re-entry softened or "
4307-
f"reset for {label}, but stronger rebuilt re-entry posture still needs more fresh "
4308-
"follow-through before it is restored."
4309-
)
4310-
if status == "pending-clearance-rebuild-reentry-restore":
4311-
return (
4312-
f"Fresh clearance-side evidence is returning after rebuilt re-entry softened or reset "
4313-
f"for {label}, but stronger rebuilt re-entry posture still needs more fresh "
4314-
"follow-through before it is restored."
4315-
)
4316-
if status == "restored-confirmation-rebuild-reentry":
4317-
return f"Fresh confirmation-side follow-through for {label} has restored stronger rebuilt re-entry posture."
4318-
if status == "restored-clearance-rebuild-reentry":
4319-
return f"Fresh clearance-side pressure for {label} has restored stronger rebuilt re-entry posture."
4320-
if status == "blocked":
4321-
return str(
4322-
primary_target.get(
4323-
"closure_forecast_reset_reentry_rebuild_reentry_restore_reason",
4324-
f"Local target instability is still preventing positive confirmation-side rebuilt re-entry restore for {label}.",
4325-
)
4326-
)
4327-
if recovering_confirmation_hotspots:
4328-
hotspot = recovering_confirmation_hotspots[0]
4329-
return (
4330-
f"Confirmation-side rebuilt re-entry is closest to being restored around {hotspot.get('label', 'recent hotspots')}, "
4331-
"but it still needs one more layer of fresh confirmation follow-through."
4332-
)
4333-
if recovering_clearance_hotspots:
4334-
hotspot = recovering_clearance_hotspots[0]
4335-
return (
4336-
f"Clearance-side rebuilt re-entry is closest to being restored around {hotspot.get('label', 'recent hotspots')}, "
4337-
"but it still needs one more layer of fresh clearance follow-through."
4338-
)
4339-
return "No rebuilt re-entry restore control is changing the current closure-forecast posture right now."
43404388

43414389

43424390
def apply_reset_reentry_rebuild_reentry_refresh_recovery_and_restore(
@@ -7103,62 +7151,12 @@ def closure_forecast_reset_reentry_rebuild_reentry_restore_rerererestore_summary
71037151
*,
71047152
target_label: Callable[[dict[str, Any]], str],
71057153
) -> str:
7106-
label = target_label(primary_target) or "The current target"
7107-
status = str(
7108-
primary_target.get(
7109-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerererestore_status",
7110-
"none",
7111-
)
7112-
)
7113-
if status == "pending-confirmation-rebuild-reentry-rerererestore":
7114-
return (
7115-
f"Fresh confirmation-side evidence is returning after re-re-restored "
7116-
f"rebuilt re-entry softened or reset for {label}, but stronger "
7117-
"re-re-restored posture still needs more fresh follow-through before it is "
7118-
"re-re-re-restored."
7119-
)
7120-
if status == "pending-clearance-rebuild-reentry-rerererestore":
7121-
return (
7122-
f"Fresh clearance-side evidence is returning after re-re-restored rebuilt "
7123-
f"re-entry softened or reset for {label}, but stronger re-re-restored "
7124-
"posture still needs more fresh follow-through before it is "
7125-
"re-re-re-restored."
7126-
)
7127-
if status == "rerererestored-confirmation-rebuild-reentry":
7128-
return (
7129-
f"Fresh confirmation-side follow-through for {label} has re-re-re-restored "
7130-
"stronger re-re-restored rebuilt re-entry posture."
7131-
)
7132-
if status == "rerererestored-clearance-rebuild-reentry":
7133-
return (
7134-
f"Fresh clearance-side pressure for {label} has re-re-re-restored "
7135-
"stronger re-re-restored rebuilt re-entry posture."
7136-
)
7137-
if status == "blocked":
7138-
return str(
7139-
primary_target.get(
7140-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerererestore_reason",
7141-
"Local target instability is still preventing positive "
7142-
f"confirmation-side re-re-restored rebuilt re-entry re-re-re-restore for {label}.",
7143-
)
7144-
)
7145-
if recovering_confirmation_hotspots:
7146-
hotspot = recovering_confirmation_hotspots[0]
7147-
return (
7148-
"Confirmation-side re-re-restored rebuilt re-entry is closest to being "
7149-
f"re-re-re-restored around {hotspot.get('label', 'recent hotspots')}, but "
7150-
"it still needs one more layer of fresh confirmation follow-through."
7151-
)
7152-
if recovering_clearance_hotspots:
7153-
hotspot = recovering_clearance_hotspots[0]
7154-
return (
7155-
"Clearance-side re-re-restored rebuilt re-entry is closest to being "
7156-
f"re-re-re-restored around {hotspot.get('label', 'recent hotspots')}, but "
7157-
"it still needs one more layer of fresh clearance follow-through."
7158-
)
7159-
return (
7160-
"No re-re-restored rebuilt re-entry re-re-re-restore control is changing the "
7161-
"current closure-forecast posture right now."
7154+
return _tier_summary_base(
7155+
primary_target,
7156+
recovering_confirmation_hotspots,
7157+
recovering_clearance_hotspots,
7158+
spec=_RERERERESTORE_SUMMARY_SPEC,
7159+
target_label=target_label,
71627160
)
71637161

71647162

0 commit comments

Comments
 (0)