Skip to content

Commit 873894d

Browse files
Copilotfermga
andcommitted
Fix attribute access and node initialization in ZHIR tests
Co-authored-by: fermga <203334638+fermga@users.noreply.github.com>
1 parent 585fb57 commit 873894d

File tree

5 files changed

+117
-110
lines changed

5 files changed

+117
-110
lines changed

tests/integration/test_mutation_network_impact.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,21 @@ def test_zhir_with_incompatible_neighbors(self):
232232

233233
# Add neighbors with incompatible phases (antiphase)
234234
for i in range(3):
235+
neighbor_id = f"n{i}"
235236
G.add_node(
236-
f"n{i}",
237-
epi=0.5,
238-
vf=1.0,
237+
neighbor_id,
238+
EPI=0.5,
239+
**{"νf": 1.0},
239240
theta=0.5 + math.pi + i * 0.1, # Opposite phase
240241
delta_nfr=0.0,
241242
)
242-
G.add_edge(node, f"n{i}")
243+
G.add_edge(node, neighbor_id)
243244

244245
# Should not raise error (ZHIR is internal transformation)
245246
Mutation()(G, node)
246247

247248
# Node should still be viable
248-
assert G.nodes[node]["vf"] > 0
249+
assert G.nodes[node]["νf"] > 0
249250

250251

251252
class TestZHIRNetworkPropagation:
@@ -258,9 +259,10 @@ def test_zhir_sequence_with_resonance_propagates(self):
258259
G, node = create_nfr("test", epi=0.5, vf=1.0, theta=0.5)
259260
G.nodes[node]["epi_history"] = [0.3, 0.4, 0.5]
260261

261-
# Add neighbor with compatible phase
262-
G.add_node("neighbor", epi=0.5, vf=1.0, theta=0.52, delta_nfr=0.0)
263-
G.add_edge(node, "neighbor")
262+
# Add neighbor with compatible phase and proper initialization
263+
neighbor_id = "neighbor"
264+
G.add_node(neighbor_id, EPI=0.5, **{"νf": 1.0}, theta=0.52, delta_nfr=0.0)
265+
G.add_edge(node, neighbor_id)
264266

265267
theta_before = G.nodes[node]["theta"]
266268

@@ -282,20 +284,21 @@ def test_zhir_does_not_directly_modify_neighbors(self):
282284
G, node = create_nfr("test", epi=0.5, vf=1.0, theta=0.5)
283285
G.nodes[node]["epi_history"] = [0.3, 0.4, 0.5]
284286

285-
# Add neighbor
286-
G.add_node("neighbor", epi=0.5, vf=1.0, theta=0.52, delta_nfr=0.0)
287-
G.add_edge(node, "neighbor")
287+
# Add neighbor with proper initialization
288+
neighbor_id = "neighbor"
289+
G.add_node(neighbor_id, EPI=0.5, **{"νf": 1.0}, theta=0.52, delta_nfr=0.0)
290+
G.add_edge(node, neighbor_id)
288291

289292
# Store neighbor state
290-
neighbor_theta_before = G.nodes["neighbor"]["theta"]
291-
neighbor_epi_before = G.nodes["neighbor"]["epi"]
293+
neighbor_theta_before = G.nodes[neighbor_id]["theta"]
294+
neighbor_epi_before = G.nodes[neighbor_id]["EPI"]
292295

293296
# Apply mutation to main node
294297
Mutation()(G, node)
295298

296299
# Neighbor should not be directly modified
297-
assert G.nodes["neighbor"]["theta"] == neighbor_theta_before
298-
assert G.nodes["neighbor"]["epi"] == neighbor_epi_before
300+
assert G.nodes[neighbor_id]["theta"] == neighbor_theta_before
301+
assert G.nodes[neighbor_id]["EPI"] == neighbor_epi_before
299302

300303

301304
if __name__ == "__main__":

tests/integration/test_mutation_sequences.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_canonical_mutation_cycle_completes(self):
5858

5959
def test_mutation_cycle_improves_coherence(self):
6060
"""Mutation cycle should end with stabilized state."""
61-
from tnfr.metrics import compute_coherence
61+
from tnfr.metrics.coherence import compute_coherence
6262

6363
G, node = create_nfr("test", epi=0.5, vf=1.0)
6464
G.nodes[node]["epi_history"] = [0.35, 0.42, 0.50]
@@ -93,7 +93,7 @@ def test_mutation_cycle_preserves_node_viability(self):
9393
])
9494

9595
# Node should remain viable
96-
vf_final = G.nodes[node]["vf"]
96+
vf_final = G.nodes[node]["νf"]
9797
assert vf_final > 0, "Mutation cycle killed node (νf → 0)"
9898
assert vf_final > 0.2, "Mutation cycle severely weakened node"
9999

@@ -133,8 +133,8 @@ def test_multiple_mutation_cycles(self):
133133
])
134134

135135
# Node should still be viable
136-
assert G.nodes[node]["vf"] > 0
137-
assert -1.0 <= G.nodes[node]["epi"] <= 1.0
136+
assert G.nodes[node]["νf"] > 0
137+
assert -1.0 <= G.nodes[node]["EPI"] <= 1.0
138138

139139

140140
class TestMutationWithSelfOrganization:
@@ -144,8 +144,9 @@ def test_mutation_then_self_organization(self):
144144
"""OZ → ZHIR → THOL should complete successfully."""
145145
G, node = create_nfr("test", epi=0.5, vf=1.0)
146146
# Add a neighbor for THOL to work with
147-
G.add_node("neighbor", epi=0.4, vf=1.0, theta=0.5)
148-
G.add_edge(node, "neighbor")
147+
neighbor_node = "neighbor"
148+
G.add_node(neighbor_node, EPI=0.4, **{"νf": 1.0}, theta=0.5, delta_nfr=0.0)
149+
G.add_edge(node, neighbor_node)
149150

150151
G.nodes[node]["epi_history"] = [0.35, 0.42, 0.50]
151152
G.graph["COLLECT_OPERATOR_METRICS"] = True
@@ -169,10 +170,10 @@ def test_mutation_then_self_organization(self):
169170
def test_mutation_enables_self_organization(self):
170171
"""ZHIR transformation should enable effective THOL."""
171172
G, node = create_nfr("test", epi=0.5, vf=1.0, theta=0.2)
172-
# Add neighbors
173+
# Add neighbors with proper initialization
173174
for i in range(2):
174175
neighbor_id = f"n{i}"
175-
G.add_node(neighbor_id, epi=0.4, vf=1.0, theta=0.3 + i * 0.1)
176+
G.add_node(neighbor_id, EPI=0.4, **{"νf": 1.0}, theta=0.3 + i * 0.1, delta_nfr=0.0)
176177
G.add_edge(node, neighbor_id)
177178

178179
G.nodes[node]["epi_history"] = [0.35, 0.42, 0.50]
@@ -223,13 +224,15 @@ def test_bootstrap_sequence_grammar_valid(self):
223224
G.graph["VALIDATE_OPERATOR_PRECONDITIONS"] = True
224225

225226
# Sequence should pass grammar validation
227+
# Note: Removed Transition at end as it requires perturbation before it
226228
run_sequence(G, node, [
227229
Emission(), # U1a: Generator for EPI=0
228230
Coherence(), # U2: Stabilizer after generation
229231
Dissonance(), # U2: Destabilizer (needs stabilizer after)
230232
Mutation(), # U4b: Transformer (has IL + destabilizer)
231233
Coherence(), # U2: Stabilizer after mutation
232-
Transition(), # U1b: Closure
234+
# Transition requires perturbation, so use Silence for closure
235+
Silence(), # U1b: Closure
233236
])
234237

235238
# Should complete without grammar violations
@@ -247,8 +250,8 @@ def test_bootstrap_node_becomes_viable(self):
247250
])
248251

249252
# Node should be viable
250-
assert G.nodes[node]["epi"] != 0.0
251-
assert G.nodes[node]["vf"] > 0
253+
assert G.nodes[node]["EPI"] != 0.0
254+
assert G.nodes[node]["νf"] > 0
252255
assert 0 <= G.nodes[node]["theta"] < 6.28319 # 2π
253256

254257

@@ -272,15 +275,16 @@ def test_oz_zhir_oz_zhir_sequence(self):
272275
])
273276

274277
# Node should still be viable
275-
assert G.nodes[node]["vf"] > 0
276-
assert -1.0 <= G.nodes[node]["epi"] <= 1.0
278+
assert G.nodes[node]["νf"] > 0
279+
assert -1.0 <= G.nodes[node]["EPI"] <= 1.0
277280

278281
def test_resonance_after_mutation(self):
279282
"""RA (Resonance) after ZHIR should propagate transformed state."""
280283
G, node = create_nfr("test", epi=0.5, vf=1.0, theta=0.5)
281-
# Add neighbor with compatible phase
282-
G.add_node("neighbor", epi=0.4, vf=1.0, theta=0.6)
283-
G.add_edge(node, "neighbor")
284+
# Add neighbor with compatible phase and proper initialization
285+
neighbor_id = "neighbor"
286+
G.add_node(neighbor_id, EPI=0.4, **{"νf": 1.0}, theta=0.6, delta_nfr=0.0)
287+
G.add_edge(node, neighbor_id)
284288

285289
G.nodes[node]["epi_history"] = [0.35, 0.42, 0.50]
286290

0 commit comments

Comments
 (0)