Skip to content

Commit e04bd24

Browse files
committed
refactor(operator-trend): collapse _side_from_status clones onto _resolve_side
Seventeen reset/reentry/rebuild/restore side classifiers each hand-spelled a confirmation member set plus its clearance mirror (the same strings with the side word swapped), cloning identical control flow seventeen ways. Replace them with a shared _resolve_side(status, *confirmation_members) helper that derives the clearance mirror once (cached); each classifier is now a one-line delegator. Proven byte-identical by the restore-tier golden contract + full suite. Second scalar-primitive slice of the operator_resolution_trend fractal collapse.
1 parent 7e71c85 commit e04bd24

1 file changed

Lines changed: 79 additions & 139 deletions

File tree

src/operator_resolution_trend.py

Lines changed: 79 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from functools import lru_cache
4+
35
from src.operator_trend_apply_chain import (
46
run_resolution_trend_apply_chain as _run_resolution_trend_apply_chain_helper,
57
)
@@ -5857,20 +5859,42 @@ def _apply_reacquisition_reset_refresh_recovery_and_reentry(
58575859
}
58585860

58595861

5860-
def _closure_forecast_reset_reentry_side_from_status(status: str) -> str:
5861-
if status in {"pending-confirmation-reentry", "reentered-confirmation"}:
5862+
@lru_cache(maxsize=None)
5863+
def _side_sets(confirmation_members: tuple[str, ...]) -> tuple[frozenset[str], frozenset[str]]:
5864+
return (
5865+
frozenset(confirmation_members),
5866+
frozenset(member.replace("confirmation", "clearance") for member in confirmation_members),
5867+
)
5868+
5869+
5870+
def _resolve_side(status: str, *confirmation_members: str) -> str:
5871+
# Shared side classifier for the reset/reentry/rebuild/restore status families. The
5872+
# clearance-side set is the confirmation-side set with "confirmation" swapped for
5873+
# "clearance"; confirmation membership wins, so a confirmation-only token (e.g.
5874+
# "just-rererestored") resolves to confirmation even though the swap also lands it
5875+
# in clearance. Returns "none" for anything unrecognized.
5876+
confirmation, clearance = _side_sets(confirmation_members)
5877+
if status in confirmation:
58625878
return "confirmation"
5863-
if status in {"pending-clearance-reentry", "reentered-clearance"}:
5879+
if status in clearance:
58645880
return "clearance"
58655881
return "none"
58665882

58675883

5884+
def _closure_forecast_reset_reentry_side_from_status(status: str) -> str:
5885+
return _resolve_side(
5886+
status,
5887+
"pending-confirmation-reentry",
5888+
"reentered-confirmation",
5889+
)
5890+
5891+
58685892
def _closure_forecast_reset_reentry_side_from_recovery_status(status: str) -> str:
5869-
if status in {"recovering-confirmation-reset", "reentering-confirmation"}:
5870-
return "confirmation"
5871-
if status in {"recovering-clearance-reset", "reentering-clearance"}:
5872-
return "clearance"
5873-
return "none"
5893+
return _resolve_side(
5894+
status,
5895+
"recovering-confirmation-reset",
5896+
"reentering-confirmation",
5897+
)
58745898

58755899

58765900
def _closure_forecast_reset_reentry_side_from_event(event: dict) -> str:
@@ -6993,17 +7017,11 @@ def _apply_reset_reentry_persistence_and_churn(
69937017

69947018

69957019
def _closure_forecast_reset_reentry_side_from_persistence_status(status: str) -> str:
6996-
if status in {
7020+
return _resolve_side(
7021+
status,
69977022
"holding-confirmation-reentry",
69987023
"sustained-confirmation-reentry",
6999-
}:
7000-
return "confirmation"
7001-
if status in {
7002-
"holding-clearance-reentry",
7003-
"sustained-clearance-reentry",
7004-
}:
7005-
return "clearance"
7006-
return "none"
7024+
)
70077025

70087026

70097027
def _closure_forecast_reset_reentry_memory_side_from_event(event: dict) -> str:
@@ -7424,25 +7442,19 @@ def _apply_reset_reentry_freshness_and_reset(
74247442

74257443

74267444
def _closure_forecast_reset_reentry_rebuild_side_from_status(status: str) -> str:
7427-
if status in {"pending-confirmation-rebuild", "rebuilt-confirmation-reentry"}:
7428-
return "confirmation"
7429-
if status in {"pending-clearance-rebuild", "rebuilt-clearance-reentry"}:
7430-
return "clearance"
7431-
return "none"
7445+
return _resolve_side(
7446+
status,
7447+
"pending-confirmation-rebuild",
7448+
"rebuilt-confirmation-reentry",
7449+
)
74327450

74337451

74347452
def _closure_forecast_reset_reentry_rebuild_side_from_recovery_status(status: str) -> str:
7435-
if status in {
7453+
return _resolve_side(
7454+
status,
74367455
"recovering-confirmation-reentry-reset",
74377456
"rebuilding-confirmation-reentry",
7438-
}:
7439-
return "confirmation"
7440-
if status in {
7441-
"recovering-clearance-reentry-reset",
7442-
"rebuilding-clearance-reentry",
7443-
}:
7444-
return "clearance"
7445-
return "none"
7457+
)
74467458

74477459

74487460
def _closure_forecast_reset_reentry_refresh_path_label(event: dict) -> str:
@@ -7754,17 +7766,11 @@ def _apply_reset_reentry_refresh_recovery_and_rebuild(
77547766

77557767

77567768
def _closure_forecast_reset_reentry_rebuild_side_from_persistence_status(status: str) -> str:
7757-
if status in {
7769+
return _resolve_side(
7770+
status,
77587771
"holding-confirmation-rebuild",
77597772
"sustained-confirmation-rebuild",
7760-
}:
7761-
return "confirmation"
7762-
if status in {
7763-
"holding-clearance-rebuild",
7764-
"sustained-clearance-rebuild",
7765-
}:
7766-
return "clearance"
7767-
return "none"
7773+
)
77687774

77697775

77707776
def _closure_forecast_reset_reentry_rebuild_side_from_event(event: dict) -> str:
@@ -8272,31 +8278,19 @@ def _apply_reset_reentry_rebuild_freshness_and_reset(
82728278
def _closure_forecast_reset_reentry_rebuild_side_from_refresh_recovery_status(
82738279
status: str,
82748280
) -> str:
8275-
if status in {
8281+
return _resolve_side(
8282+
status,
82768283
"recovering-confirmation-rebuild-reset",
82778284
"reentering-confirmation-rebuild",
8278-
}:
8279-
return "confirmation"
8280-
if status in {
8281-
"recovering-clearance-rebuild-reset",
8282-
"reentering-clearance-rebuild",
8283-
}:
8284-
return "clearance"
8285-
return "none"
8285+
)
82868286

82878287

82888288
def _closure_forecast_reset_reentry_rebuild_side_from_reentry_status(status: str) -> str:
8289-
if status in {
8289+
return _resolve_side(
8290+
status,
82908291
"pending-confirmation-rebuild-reentry",
82918292
"reentered-confirmation-rebuild",
8292-
}:
8293-
return "confirmation"
8294-
if status in {
8295-
"pending-clearance-rebuild-reentry",
8296-
"reentered-clearance-rebuild",
8297-
}:
8298-
return "clearance"
8299-
return "none"
8293+
)
83008294

83018295

83028296
def _closure_forecast_reset_reentry_rebuild_refresh_path_label(event: dict) -> str:
@@ -9139,17 +9133,11 @@ def _apply_reset_reentry_rebuild_refresh_recovery_and_reentry(
91399133
def _closure_forecast_reset_reentry_rebuild_reentry_side_from_persistence_status(
91409134
status: str,
91419135
) -> str:
9142-
if status in {
9136+
return _resolve_side(
9137+
status,
91439138
"holding-confirmation-rebuild-reentry",
91449139
"sustained-confirmation-rebuild-reentry",
9145-
}:
9146-
return "confirmation"
9147-
if status in {
9148-
"holding-clearance-rebuild-reentry",
9149-
"sustained-clearance-rebuild-reentry",
9150-
}:
9151-
return "clearance"
9152-
return "none"
9140+
)
91539141

91549142

91559143
def _closure_forecast_reset_reentry_rebuild_reentry_side_from_event(event: dict) -> str:
@@ -10934,49 +10922,31 @@ def _apply_reset_reentry_rebuild_reentry_freshness_and_reset(
1093410922
def _closure_forecast_reset_reentry_rebuild_reentry_side_from_refresh_recovery_status(
1093510923
status: str,
1093610924
) -> str:
10937-
if status in {
10925+
return _resolve_side(
10926+
status,
1093810927
"recovering-confirmation-rebuild-reentry-reset",
1093910928
"restoring-confirmation-rebuild-reentry",
10940-
}:
10941-
return "confirmation"
10942-
if status in {
10943-
"recovering-clearance-rebuild-reentry-reset",
10944-
"restoring-clearance-rebuild-reentry",
10945-
}:
10946-
return "clearance"
10947-
return "none"
10929+
)
1094810930

1094910931

1095010932
def _closure_forecast_reset_reentry_rebuild_reentry_side_from_restore_status(
1095110933
status: str,
1095210934
) -> str:
10953-
if status in {
10935+
return _resolve_side(
10936+
status,
1095410937
"pending-confirmation-rebuild-reentry-restore",
1095510938
"restored-confirmation-rebuild-reentry",
10956-
}:
10957-
return "confirmation"
10958-
if status in {
10959-
"pending-clearance-rebuild-reentry-restore",
10960-
"restored-clearance-rebuild-reentry",
10961-
}:
10962-
return "clearance"
10963-
return "none"
10939+
)
1096410940

1096510941

1096610942
def _closure_forecast_reset_reentry_rebuild_reentry_side_from_restore_persistence_status(
1096710943
status: str,
1096810944
) -> str:
10969-
if status in {
10945+
return _resolve_side(
10946+
status,
1097010947
"holding-confirmation-rebuild-reentry-restore",
1097110948
"sustained-confirmation-rebuild-reentry-restore",
10972-
}:
10973-
return "confirmation"
10974-
if status in {
10975-
"holding-clearance-rebuild-reentry-restore",
10976-
"sustained-clearance-rebuild-reentry-restore",
10977-
}:
10978-
return "clearance"
10979-
return "none"
10949+
)
1098010950

1098110951

1098210952
def _closure_forecast_reset_reentry_rebuild_reentry_refresh_path_label(event: dict) -> str:
@@ -14039,33 +14009,21 @@ def _apply_reset_reentry_rebuild_reentry_restore_refresh_recovery_and_rerestore(
1403914009
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_side_from_status(
1404014010
status: str,
1404114011
) -> str:
14042-
if status in {
14012+
return _resolve_side(
14013+
status,
1404314014
"pending-confirmation-rebuild-reentry-rerestore",
1404414015
"rerestored-confirmation-rebuild-reentry",
14045-
}:
14046-
return "confirmation"
14047-
if status in {
14048-
"pending-clearance-rebuild-reentry-rerestore",
14049-
"rerestored-clearance-rebuild-reentry",
14050-
}:
14051-
return "clearance"
14052-
return "none"
14016+
)
1405314017

1405414018

1405514019
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_side_from_persistence_status(
1405614020
status: str,
1405714021
) -> str:
14058-
if status in {
14022+
return _resolve_side(
14023+
status,
1405914024
"holding-confirmation-rebuild-reentry-rerestore",
1406014025
"sustained-confirmation-rebuild-reentry-rerestore",
14061-
}:
14062-
return "confirmation"
14063-
if status in {
14064-
"holding-clearance-rebuild-reentry-rerestore",
14065-
"sustained-clearance-rebuild-reentry-rerestore",
14066-
}:
14067-
return "clearance"
14068-
return "none"
14026+
)
1406914027

1407014028

1407114029
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_side_from_event(
@@ -16140,33 +16098,21 @@ def _apply_reset_reentry_rebuild_reentry_restore_rerestore_freshness_and_reset(
1614016098
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rererestore_side_from_status(
1614116099
status: str,
1614216100
) -> str:
16143-
if status in {
16101+
return _resolve_side(
16102+
status,
1614416103
"pending-confirmation-rebuild-reentry-rererestore",
1614516104
"rererestored-confirmation-rebuild-reentry",
16146-
}:
16147-
return "confirmation"
16148-
if status in {
16149-
"pending-clearance-rebuild-reentry-rererestore",
16150-
"rererestored-clearance-rebuild-reentry",
16151-
}:
16152-
return "clearance"
16153-
return "none"
16105+
)
1615416106

1615516107

1615616108
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_side_from_refresh_recovery_status(
1615716109
status: str,
1615816110
) -> str:
16159-
if status in {
16111+
return _resolve_side(
16112+
status,
1616016113
"recovering-confirmation-rebuild-reentry-rerestore-reset",
1616116114
"rererestoring-confirmation-rebuild-reentry",
16162-
}:
16163-
return "confirmation"
16164-
if status in {
16165-
"recovering-clearance-rebuild-reentry-rerestore-reset",
16166-
"rererestoring-clearance-rebuild-reentry",
16167-
}:
16168-
return "clearance"
16169-
return "none"
16115+
)
1617016116

1617116117

1617216118
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_path_label(
@@ -17169,18 +17115,12 @@ def _apply_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_and_
1716917115
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rererestore_side_from_persistence_status(
1717017116
status: str,
1717117117
) -> str:
17172-
if status in {
17118+
return _resolve_side(
17119+
status,
1717317120
"just-rererestored",
1717417121
"holding-confirmation-rebuild-reentry-rererestore",
1717517122
"sustained-confirmation-rebuild-reentry-rererestore",
17176-
}:
17177-
return "confirmation"
17178-
if status in {
17179-
"holding-clearance-rebuild-reentry-rererestore",
17180-
"sustained-clearance-rebuild-reentry-rererestore",
17181-
}:
17182-
return "clearance"
17183-
return "none"
17123+
)
1718417124

1718517125

1718617126
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rererestore_side_from_event(

0 commit comments

Comments
 (0)