fable-engine 1.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fable_compressor.py +356 -0
- fable_engine/__init__.py +1 -0
- fable_engine/actions/__init__.py +291 -0
- fable_engine/actions/cas.py +182 -0
- fable_engine/actions/deliberation.py +523 -0
- fable_engine/actions/fleet.py +807 -0
- fable_engine/actions/lifecycle.py +298 -0
- fable_engine/actions/scrapers.py +116 -0
- fable_engine/actions/system3.py +815 -0
- fable_engine/browser.py +824 -0
- fable_engine/cas.py +974 -0
- fable_engine/fable_session.json +510 -0
- fable_engine/guards.py +283 -0
- fable_engine/schema.py +714 -0
- fable_engine/scrapers/__init__.py +32 -0
- fable_engine/scrapers/arxiv.py +115 -0
- fable_engine/scrapers/base.py +386 -0
- fable_engine/scrapers/github.py +129 -0
- fable_engine/scrapers/reddit.py +154 -0
- fable_engine/scrapers/web.py +120 -0
- fable_engine/scrapers/x.py +125 -0
- fable_engine/scrapers/youtube.py +132 -0
- fable_engine/server.py +414 -0
- fable_engine/session.py +1819 -0
- fable_engine/test_server.py +1362 -0
- fable_engine/updater.py +541 -0
- fable_engine-1.3.1.dist-info/LICENSE +22 -0
- fable_engine-1.3.1.dist-info/METADATA +173 -0
- fable_engine-1.3.1.dist-info/RECORD +104 -0
- fable_engine-1.3.1.dist-info/WHEEL +5 -0
- fable_engine-1.3.1.dist-info/entry_points.txt +5 -0
- fable_engine-1.3.1.dist-info/top_level.txt +6 -0
- fable_mode/__init__.py +3 -0
- fable_mode/__main__.py +4 -0
- fable_mode/adapters.py +1014 -0
- fable_mode/installer.py +553 -0
- fable_mode/launcher.py +437 -0
- fable_mode/manifest.py +142 -0
- fable_mode/resources.json +114 -0
- fable_mode/safety.py +103 -0
- fable_mode_entry.py +10 -0
- fable_v2/__init__.py +146 -0
- fable_v2/adapters.py +151 -0
- fable_v2/coder_fleet/__init__.py +100 -0
- fable_v2/coder_fleet/ast_tools.py +158 -0
- fable_v2/coder_fleet/compute.py +199 -0
- fable_v2/coder_fleet/design_engine.py +1316 -0
- fable_v2/coder_fleet/diagnostics.py +293 -0
- fable_v2/coder_fleet/fleet_dispatcher.py +214 -0
- fable_v2/coder_fleet/mock_auditor.py +306 -0
- fable_v2/coder_fleet/mutation.py +216 -0
- fable_v2/coder_fleet/property_oracle.py +260 -0
- fable_v2/coder_fleet/receipt_attestor.py +122 -0
- fable_v2/coder_fleet/red_team_swarm.py +908 -0
- fable_v2/coder_fleet/test_harness.py +198 -0
- fable_v2/coder_fleet/vector_engine.py +1287 -0
- fable_v2/coder_fleet/visual.py +357 -0
- fable_v2/coder_fleet/workspace.py +153 -0
- fable_v2/cortical/__init__.py +20 -0
- fable_v2/cortical/plasticity_engine.py +992 -0
- fable_v2/execution_broker.py +811 -0
- fable_v2/proof_engine.py +1141 -0
- fable_v2/protocol.py +485 -0
- fable_v2/runtime.py +1010 -0
- fable_v2/system3/__init__.py +204 -0
- fable_v2/system3/causal.py +558 -0
- fable_v2/system3/dialectical.py +577 -0
- fable_v2/system3/evolution.py +503 -0
- fable_v2/system3/executive.py +338 -0
- fable_v2/system3/free_energy.py +479 -0
- fable_v2/system3/hyperbolic.py +555 -0
- fable_v2/system3/induction.py +336 -0
- fable_v2/system3/kripke.py +548 -0
- fable_v2/system3/oracle.py +745 -0
- fable_v2/verifiers.py +72 -0
- tests/__init__.py +1 -0
- tests/test_anti_loop_circuit_breaker.py +64 -0
- tests/test_auto_updater.py +407 -0
- tests/test_coder_fleet.py +535 -0
- tests/test_delegation_compiler.py +54 -0
- tests/test_descriptor_boundaries.py +126 -0
- tests/test_design_engine.py +603 -0
- tests/test_epistemic_evidence_validator.py +66 -0
- tests/test_execution_broker.py +233 -0
- tests/test_fable_v2.py +406 -0
- tests/test_fleet_transitions.py +116 -0
- tests/test_fsm_redteam_evolution.py +406 -0
- tests/test_goal_rubric_and_pipeline.py +367 -0
- tests/test_hebbian_plasticity.py +585 -0
- tests/test_packaging_runtime.py +194 -0
- tests/test_proof_engine.py +259 -0
- tests/test_red_team_swarm.py +645 -0
- tests/test_redteam_remediation.py +169 -0
- tests/test_registration_transaction.py +375 -0
- tests/test_requested_regressions.py +467 -0
- tests/test_scrapers.py +370 -0
- tests/test_server_actions.py +93 -0
- tests/test_server_frontier_actions.py +269 -0
- tests/test_server_protocol.py +88 -0
- tests/test_stealth_browser.py +970 -0
- tests/test_system3.py +381 -0
- tests/test_system3_deep_integration.py +385 -0
- tests/test_system3_frontier.py +436 -0
- tests/test_vector_engine.py +608 -0
tests/test_system3.py
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"""Comprehensive Unit Tests for System 3 Meta-Cognitive Deliberation & Dialectical Architecture."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import unittest
|
|
6
|
+
import math
|
|
7
|
+
|
|
8
|
+
from fable_v2.system3 import (
|
|
9
|
+
CausalDAG,
|
|
10
|
+
CausalNode,
|
|
11
|
+
CausalEdge,
|
|
12
|
+
CausalNodeType,
|
|
13
|
+
CausalCycleError,
|
|
14
|
+
CausalNodeNotFoundError,
|
|
15
|
+
BrittlenessReport,
|
|
16
|
+
InterventionResult,
|
|
17
|
+
ThesisCandidate,
|
|
18
|
+
AntithesisCritique,
|
|
19
|
+
Contradiction,
|
|
20
|
+
TRIZPrinciple,
|
|
21
|
+
TRIZContradictionResolver,
|
|
22
|
+
TRIZ_PRINCIPLES_CATALOG,
|
|
23
|
+
DialecticalSynthesizer,
|
|
24
|
+
EmergentSynthesis,
|
|
25
|
+
CognitiveGenome,
|
|
26
|
+
CognitiveGenePool,
|
|
27
|
+
PARETO_DIMENSIONS,
|
|
28
|
+
create_random_genome,
|
|
29
|
+
NeuroSymbolicAxiom,
|
|
30
|
+
AxiomProvenance,
|
|
31
|
+
AxiomStatus,
|
|
32
|
+
MetaProofInducer,
|
|
33
|
+
CognitiveGear,
|
|
34
|
+
CognitiveBiasType,
|
|
35
|
+
CognitiveBiasFinding,
|
|
36
|
+
CognitiveBiasDetector,
|
|
37
|
+
DynamicSearchHeuristicRewriter,
|
|
38
|
+
SearchHeuristicConfig,
|
|
39
|
+
TriLevelArbitrator,
|
|
40
|
+
System3Executive,
|
|
41
|
+
)
|
|
42
|
+
from fable_v2.protocol import ToolReceipt, Evidence, canonical_hash
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TestSystem3CausalDAG(unittest.TestCase):
|
|
46
|
+
"""Unit tests for Causal DAG, Pearl's Do-Calculus, and Brittleness Analysis."""
|
|
47
|
+
|
|
48
|
+
def test_dag_creation_and_topological_sort(self):
|
|
49
|
+
dag = CausalDAG(name="ThroughputLatencyModel")
|
|
50
|
+
n1 = dag.add_node("threads", "Worker Threads", CausalNodeType.EXOGENOUS, value=4.0)
|
|
51
|
+
n2 = dag.add_node("contention", "Lock Contention", CausalNodeType.ENDOGENOUS, value=0.0)
|
|
52
|
+
n3 = dag.add_node("throughput", "System Throughput", CausalNodeType.METRIC, value=0.0)
|
|
53
|
+
|
|
54
|
+
dag.add_edge("threads", "contention", weight=0.5)
|
|
55
|
+
dag.add_edge("threads", "throughput", weight=2.0)
|
|
56
|
+
dag.add_edge("contention", "throughput", weight=-1.5)
|
|
57
|
+
|
|
58
|
+
is_acyclic, cycle = dag.check_acyclicity()
|
|
59
|
+
self.assertTrue(is_acyclic)
|
|
60
|
+
self.assertEqual(len(cycle), 0)
|
|
61
|
+
|
|
62
|
+
order = dag.topological_sort()
|
|
63
|
+
self.assertEqual(order[0], "threads")
|
|
64
|
+
self.assertIn("contention", order[1:])
|
|
65
|
+
self.assertEqual(order[-1], "throughput")
|
|
66
|
+
|
|
67
|
+
def test_cycle_detection_and_rejection(self):
|
|
68
|
+
dag = CausalDAG(name="CycleTest")
|
|
69
|
+
dag.add_node("A", value=1.0)
|
|
70
|
+
dag.add_node("B", value=2.0)
|
|
71
|
+
dag.add_node("C", value=3.0)
|
|
72
|
+
|
|
73
|
+
dag.add_edge("A", "B")
|
|
74
|
+
dag.add_edge("B", "C")
|
|
75
|
+
|
|
76
|
+
# Attempting to add C -> A should raise CausalCycleError and rollback
|
|
77
|
+
with self.assertRaises(CausalCycleError):
|
|
78
|
+
dag.add_edge("C", "A")
|
|
79
|
+
|
|
80
|
+
# Verify DAG remains valid after rejected edge
|
|
81
|
+
is_dag, _ = dag.check_acyclicity()
|
|
82
|
+
self.assertTrue(is_dag)
|
|
83
|
+
self.assertEqual(len(dag.edges), 2)
|
|
84
|
+
|
|
85
|
+
def test_self_loop_rejection(self):
|
|
86
|
+
dag = CausalDAG(name="SelfLoopTest")
|
|
87
|
+
dag.add_node("A", value=1.0)
|
|
88
|
+
with self.assertRaises(CausalCycleError):
|
|
89
|
+
dag.add_edge("A", "A")
|
|
90
|
+
|
|
91
|
+
def test_pearl_do_calculus_intervention(self):
|
|
92
|
+
"""Verify Pearl's do-operator severs incoming edges and calculates counterfactual deltas."""
|
|
93
|
+
dag = CausalDAG(name="InterventionTest")
|
|
94
|
+
dag.add_node("workers", value=2.0)
|
|
95
|
+
dag.add_node("cache_hits", value=100.0)
|
|
96
|
+
dag.add_node("latency", value=0.0)
|
|
97
|
+
|
|
98
|
+
dag.add_edge("workers", "cache_hits", weight=-10.0)
|
|
99
|
+
dag.add_edge("cache_hits", "latency", weight=-0.5)
|
|
100
|
+
|
|
101
|
+
# Baseline factual computation
|
|
102
|
+
f_vals = dag.compute_forward()
|
|
103
|
+
self.assertEqual(f_vals["workers"], 2.0)
|
|
104
|
+
self.assertEqual(f_vals["cache_hits"], -20.0)
|
|
105
|
+
self.assertEqual(f_vals["latency"], 10.0)
|
|
106
|
+
|
|
107
|
+
# Apply do(cache_hits = 50.0) -> graph surgery cuts workers -> cache_hits edge
|
|
108
|
+
res = dag.do_intervention({"cache_hits": 50.0})
|
|
109
|
+
self.assertEqual(res.counterfactual_values["cache_hits"], 50.0)
|
|
110
|
+
self.assertEqual(res.counterfactual_values["latency"], -25.0)
|
|
111
|
+
self.assertEqual(res.deltas["latency"], -35.0)
|
|
112
|
+
self.assertIn(("workers", "cache_hits"), res.severed_edges)
|
|
113
|
+
|
|
114
|
+
def test_structural_brittleness_evaluation(self):
|
|
115
|
+
dag = CausalDAG(name="BrittlenessTest")
|
|
116
|
+
dag.add_node("gateway", value=1.0)
|
|
117
|
+
dag.add_node("auth_service", value=1.0)
|
|
118
|
+
dag.add_node("api_latency", value=0.0)
|
|
119
|
+
|
|
120
|
+
dag.add_edge("gateway", "auth_service", weight=2.0)
|
|
121
|
+
dag.add_edge("auth_service", "api_latency", weight=3.0)
|
|
122
|
+
|
|
123
|
+
report = dag.evaluate_brittleness("api_latency", critical_sensitivity_threshold=1.5)
|
|
124
|
+
self.assertIsInstance(report, BrittlenessReport)
|
|
125
|
+
self.assertGreater(report.overall_brittleness_score, 0.0)
|
|
126
|
+
self.assertIn("auth_service", report.single_points_of_failure)
|
|
127
|
+
self.assertIn("gateway", report.single_points_of_failure)
|
|
128
|
+
self.assertTrue(len(report.critical_paths) > 0)
|
|
129
|
+
|
|
130
|
+
def test_custom_evaluator_and_serialization(self):
|
|
131
|
+
dag = CausalDAG(name="CustomEval")
|
|
132
|
+
dag.add_node("x", value=3.0)
|
|
133
|
+
dag.add_node("y", value=4.0)
|
|
134
|
+
dag.add_node("hypotenuse", value=0.0)
|
|
135
|
+
|
|
136
|
+
dag.add_edge("x", "hypotenuse")
|
|
137
|
+
dag.add_edge("y", "hypotenuse")
|
|
138
|
+
dag.register_evaluator("hypotenuse", lambda vals: math.sqrt(vals["x"]**2 + vals["y"]**2))
|
|
139
|
+
|
|
140
|
+
vals = dag.compute_forward()
|
|
141
|
+
self.assertAlmostEqual(vals["hypotenuse"], 5.0)
|
|
142
|
+
|
|
143
|
+
# Test dictionary roundtrip
|
|
144
|
+
d = dag.to_dict()
|
|
145
|
+
restored = CausalDAG.from_dict(d)
|
|
146
|
+
self.assertEqual(restored.name, "CustomEval")
|
|
147
|
+
self.assertEqual(len(restored.nodes), 3)
|
|
148
|
+
self.assertEqual(len(restored.edges), 2)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class TestSystem3DialecticalSynthesis(unittest.TestCase):
|
|
152
|
+
"""Unit tests for TRIZ Contradiction Matrix and Dialectical Synthesizer."""
|
|
153
|
+
|
|
154
|
+
def test_triz_catalog_completeness(self):
|
|
155
|
+
self.assertEqual(len(TRIZ_PRINCIPLES_CATALOG), 40)
|
|
156
|
+
p1 = TRIZ_PRINCIPLES_CATALOG[1]
|
|
157
|
+
self.assertEqual(p1.name, "Segmentation")
|
|
158
|
+
self.assertTrue(len(p1.software_analogs) > 0)
|
|
159
|
+
|
|
160
|
+
def test_triz_contradiction_resolver(self):
|
|
161
|
+
resolver = TRIZContradictionResolver()
|
|
162
|
+
contra = Contradiction(
|
|
163
|
+
contradiction_id="c1",
|
|
164
|
+
improving_parameter="throughput",
|
|
165
|
+
worsening_parameter="latency",
|
|
166
|
+
description="Batching increases throughput but adds pipeline latency",
|
|
167
|
+
severity=0.85,
|
|
168
|
+
)
|
|
169
|
+
recs = resolver.resolve_contradiction(contra)
|
|
170
|
+
self.assertTrue(len(recs) > 0)
|
|
171
|
+
principle_numbers = [r.principle.number for r in recs]
|
|
172
|
+
# Should include Segmentation (1), Dynamics (15), Prior Action (10), or Intermediary (24)
|
|
173
|
+
self.assertTrue(any(p in [1, 15, 10, 24, 21] for p in principle_numbers))
|
|
174
|
+
|
|
175
|
+
def test_dialectical_synthesizer_monotonic_convergence(self):
|
|
176
|
+
thesis = ThesisCandidate(
|
|
177
|
+
thesis_id="th_1",
|
|
178
|
+
title="Monolithic In-Memory Cache",
|
|
179
|
+
description="Fast direct access but high single-point-of-failure risk",
|
|
180
|
+
metrics={"throughput": 0.9, "safety": 0.3},
|
|
181
|
+
)
|
|
182
|
+
critique = AntithesisCritique(
|
|
183
|
+
critique_id="cr_1",
|
|
184
|
+
thesis_id="th_1",
|
|
185
|
+
title="Red-Team Memory Corruptibility",
|
|
186
|
+
contradictions=[
|
|
187
|
+
Contradiction(
|
|
188
|
+
contradiction_id="c_01",
|
|
189
|
+
improving_parameter="speed",
|
|
190
|
+
worsening_parameter="memory",
|
|
191
|
+
description="Unbounded cache causes OOM risk",
|
|
192
|
+
severity=0.8,
|
|
193
|
+
)
|
|
194
|
+
],
|
|
195
|
+
failure_modes=["Process crash loses all uncommitted writes"],
|
|
196
|
+
severity_score=0.75,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
synthesizer = DialecticalSynthesizer()
|
|
200
|
+
synthesis = synthesizer.synthesize(thesis, critique, max_debate_rounds=3, target_residual_threshold=0.20)
|
|
201
|
+
|
|
202
|
+
self.assertIsInstance(synthesis, EmergentSynthesis)
|
|
203
|
+
self.assertLess(synthesis.residual_contradiction_score, synthesis.initial_contradiction_score)
|
|
204
|
+
self.assertTrue(synthesis.convergence_achieved)
|
|
205
|
+
self.assertTrue(len(synthesis.transcended_principles) > 0)
|
|
206
|
+
|
|
207
|
+
# Check serialization
|
|
208
|
+
d = synthesis.to_dict()
|
|
209
|
+
restored = EmergentSynthesis.from_dict(d)
|
|
210
|
+
self.assertEqual(restored.synthesis_id, synthesis.synthesis_id)
|
|
211
|
+
self.assertEqual(restored.residual_contradiction_score, synthesis.residual_contradiction_score)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class TestSystem3EvolutionaryEngine(unittest.TestCase):
|
|
215
|
+
"""Unit tests for CognitiveGenome, NSGA-II 10D Pareto optimization, and GenePool."""
|
|
216
|
+
|
|
217
|
+
def test_genome_pareto_dominance(self):
|
|
218
|
+
g1 = CognitiveGenome(
|
|
219
|
+
genome_id="g1",
|
|
220
|
+
paradigm_name="Candidate 1",
|
|
221
|
+
fitness_scores={dim: 0.8 for dim in PARETO_DIMENSIONS},
|
|
222
|
+
)
|
|
223
|
+
g2 = CognitiveGenome(
|
|
224
|
+
genome_id="g2",
|
|
225
|
+
paradigm_name="Candidate 2",
|
|
226
|
+
fitness_scores={dim: 0.7 for dim in PARETO_DIMENSIONS},
|
|
227
|
+
)
|
|
228
|
+
# g1 strictly dominates g2
|
|
229
|
+
self.assertTrue(g1.dominates(g2))
|
|
230
|
+
self.assertFalse(g2.dominates(g1))
|
|
231
|
+
|
|
232
|
+
# Incomparable genomes (trade-off)
|
|
233
|
+
g3 = CognitiveGenome(
|
|
234
|
+
genome_id="g3",
|
|
235
|
+
paradigm_name="Candidate 3",
|
|
236
|
+
fitness_scores={dim: 0.8 for dim in PARETO_DIMENSIONS},
|
|
237
|
+
)
|
|
238
|
+
g3.fitness_scores["latency"] = 0.95
|
|
239
|
+
g3.fitness_scores["simplicity"] = 0.60
|
|
240
|
+
self.assertFalse(g1.dominates(g3))
|
|
241
|
+
self.assertFalse(g3.dominates(g1))
|
|
242
|
+
|
|
243
|
+
def test_gene_pool_evolution_generations(self):
|
|
244
|
+
pool = CognitiveGenePool(population_size=10, mutation_rate=0.2, crossover_rate=0.8, random_seed=123)
|
|
245
|
+
pool.initialize_population()
|
|
246
|
+
self.assertEqual(len(pool.population), 10)
|
|
247
|
+
|
|
248
|
+
frontier_gen0 = pool.get_pareto_frontier()
|
|
249
|
+
self.assertTrue(len(frontier_gen0) > 0)
|
|
250
|
+
|
|
251
|
+
# Evolve 3 generations
|
|
252
|
+
for _ in range(3):
|
|
253
|
+
pool.evolve_generation()
|
|
254
|
+
|
|
255
|
+
self.assertEqual(pool.generation_count, 3)
|
|
256
|
+
self.assertEqual(len(pool.population), 10)
|
|
257
|
+
best = pool.get_best_genome()
|
|
258
|
+
self.assertIsInstance(best, CognitiveGenome)
|
|
259
|
+
self.assertGreaterEqual(best.compute_scalar_fitness(), 0.5)
|
|
260
|
+
|
|
261
|
+
# Check serialization round-trip
|
|
262
|
+
d = pool.to_dict()
|
|
263
|
+
restored = CognitiveGenePool.from_dict(d)
|
|
264
|
+
self.assertEqual(restored.generation_count, 3)
|
|
265
|
+
self.assertEqual(len(restored.population), 10)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
class TestSystem3NeuroSymbolicInduction(unittest.TestCase):
|
|
269
|
+
"""Unit tests for Neuro-Symbolic Axiom Induction and empirical verification."""
|
|
270
|
+
|
|
271
|
+
def test_axiom_evaluation_and_verification(self):
|
|
272
|
+
prov = AxiomProvenance(provenance_id="prov_test", empirical_samples=5, falsification_attempts=5)
|
|
273
|
+
axiom = NeuroSymbolicAxiom(
|
|
274
|
+
axiom_id="AXIOM-TEST-001",
|
|
275
|
+
name="Token Ratio Boundedness",
|
|
276
|
+
symbolic_expression="forall data: TokenRatio(data) <= 0.003",
|
|
277
|
+
natural_language="Token ratio must not exceed 0.003 for large payloads",
|
|
278
|
+
domain="performance",
|
|
279
|
+
provenance=prov,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
test_cases_pass = [
|
|
283
|
+
{"token_ratio": 0.0025, "raw_chars": 15000},
|
|
284
|
+
{"token_ratio": 0.0018, "raw_chars": 20000},
|
|
285
|
+
{"token_ratio": 0.0029, "raw_chars": 12000},
|
|
286
|
+
]
|
|
287
|
+
inducer = MetaProofInducer()
|
|
288
|
+
success, ratio, failures = inducer.verify_axiom_empirically(axiom, test_cases_pass)
|
|
289
|
+
self.assertTrue(success)
|
|
290
|
+
self.assertEqual(ratio, 1.0)
|
|
291
|
+
self.assertEqual(len(failures), 0)
|
|
292
|
+
self.assertEqual(axiom.status, AxiomStatus.PROVEN)
|
|
293
|
+
|
|
294
|
+
# Test falsification
|
|
295
|
+
test_cases_fail = [
|
|
296
|
+
{"token_ratio": 0.0080, "raw_chars": 15000},
|
|
297
|
+
]
|
|
298
|
+
success_fail, ratio_fail, failures_fail = inducer.verify_axiom_empirically(axiom, test_cases_fail)
|
|
299
|
+
self.assertFalse(success_fail)
|
|
300
|
+
self.assertEqual(axiom.status, AxiomStatus.FALSIFIED)
|
|
301
|
+
self.assertEqual(len(failures_fail), 1)
|
|
302
|
+
|
|
303
|
+
def test_axiom_induction_from_session(self):
|
|
304
|
+
inducer = MetaProofInducer()
|
|
305
|
+
axioms = inducer.induce_axioms_from_session(
|
|
306
|
+
receipts=[],
|
|
307
|
+
evidence=[],
|
|
308
|
+
session_telemetry={"active_phase": "Phase 1", "phase_history": [{"phase": "Phase 1"}]},
|
|
309
|
+
)
|
|
310
|
+
self.assertTrue(len(axioms) >= 3)
|
|
311
|
+
names = [a.name for a in axioms]
|
|
312
|
+
self.assertIn("Content-Addressed Immutability & Determinism", names)
|
|
313
|
+
self.assertIn("Token Compaction Ratio Upper Bound", names)
|
|
314
|
+
self.assertIn("Immutable Authority Pacing Lockout", names)
|
|
315
|
+
|
|
316
|
+
# Check proof sketch formatting
|
|
317
|
+
sketch = inducer.formalize_to_proof_sketch(axioms[0])
|
|
318
|
+
self.assertIn("Formal Neuro-Symbolic Proof Sketch", sketch)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class TestSystem3ExecutiveAndArbitration(unittest.TestCase):
|
|
322
|
+
"""Unit tests for CognitiveBiasDetector, TriLevelArbitrator, and System3Executive."""
|
|
323
|
+
|
|
324
|
+
def test_cognitive_bias_detector(self):
|
|
325
|
+
detector = CognitiveBiasDetector()
|
|
326
|
+
|
|
327
|
+
# State with confirmation bias: 4 hypotheses, 0 proven, 0 unknown
|
|
328
|
+
session_biased = {
|
|
329
|
+
"epistemic_ledger": [
|
|
330
|
+
{"id": "e1", "tag": "HYPOTHESIS", "claim": "H1"},
|
|
331
|
+
{"id": "e2", "tag": "HYPOTHESIS", "claim": "H2"},
|
|
332
|
+
{"id": "e3", "tag": "HYPOTHESIS", "claim": "H3"},
|
|
333
|
+
{"id": "e4", "tag": "HYPOTHESIS", "claim": "H4"},
|
|
334
|
+
],
|
|
335
|
+
"refinement_cycles": [],
|
|
336
|
+
"invariants": [],
|
|
337
|
+
"active_phase": "Phase 1: Epistemic Grounding & Live Research",
|
|
338
|
+
}
|
|
339
|
+
findings = detector.audit_session(session_biased)
|
|
340
|
+
self.assertTrue(any(f.bias_type == CognitiveBiasType.CONFIRMATION_BIAS for f in findings))
|
|
341
|
+
|
|
342
|
+
def test_tri_level_arbitrator(self):
|
|
343
|
+
arbitrator = TriLevelArbitrator()
|
|
344
|
+
|
|
345
|
+
# High complexity & high contradiction density -> SYSTEM_3
|
|
346
|
+
res_s3 = arbitrator.arbitrate(task_complexity=0.9, contradiction_density=0.85, failure_count=2)
|
|
347
|
+
self.assertEqual(res_s3["recommended_gear"], CognitiveGear.SYSTEM_3_META_COGNITIVE.value)
|
|
348
|
+
self.assertTrue(len(res_s3["directives"]) >= 3)
|
|
349
|
+
|
|
350
|
+
# Low complexity -> SYSTEM_1
|
|
351
|
+
res_s1 = arbitrator.arbitrate(task_complexity=0.2, contradiction_density=0.1, failure_count=0, epistemic_uncertainty=0.1)
|
|
352
|
+
self.assertEqual(res_s1["recommended_gear"], CognitiveGear.SYSTEM_1_INTUITIVE.value)
|
|
353
|
+
|
|
354
|
+
def test_dynamic_heuristic_rewriting(self):
|
|
355
|
+
rewriter = DynamicSearchHeuristicRewriter()
|
|
356
|
+
base_config = SearchHeuristicConfig(exploration_temperature=0.7)
|
|
357
|
+
|
|
358
|
+
# Rewriting under high contradiction density increases temperature
|
|
359
|
+
updated = rewriter.rewrite_heuristics(base_config, contradiction_density=0.85, bias_findings=[])
|
|
360
|
+
self.assertGreater(updated.exploration_temperature, base_config.exploration_temperature)
|
|
361
|
+
|
|
362
|
+
def test_system3_executive_meta_reflection(self):
|
|
363
|
+
executive = System3Executive()
|
|
364
|
+
session_data = {
|
|
365
|
+
"session_name": "test_exec_session",
|
|
366
|
+
"epistemic_ledger": [
|
|
367
|
+
{"id": "e1", "tag": "PROVEN", "claim": "Verified file exists", "evidence": "server.py:10"},
|
|
368
|
+
{"id": "e2", "tag": "HYPOTHESIS", "claim": "Cache will improve latency"},
|
|
369
|
+
],
|
|
370
|
+
"refinement_cycles": [],
|
|
371
|
+
"invariants": [],
|
|
372
|
+
"active_phase": "Phase 3: Adversarial Red-Teaming & Falsification",
|
|
373
|
+
}
|
|
374
|
+
report = executive.meta_reflect(session_data)
|
|
375
|
+
self.assertIn("cognitive_gear", report)
|
|
376
|
+
self.assertIn("updated_search_heuristics", report)
|
|
377
|
+
self.assertIn("directives", report)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
if __name__ == "__main__":
|
|
381
|
+
unittest.main()
|