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
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"""Unit and Integration Tests for Deep System 3 Integration in Fable Mode."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
import unittest
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
12
|
+
|
|
13
|
+
from fable_v2.protocol import (
|
|
14
|
+
Candidate,
|
|
15
|
+
Evidence,
|
|
16
|
+
TaskSpec,
|
|
17
|
+
ToolReceipt,
|
|
18
|
+
VerificationPolicy,
|
|
19
|
+
VerificationResult,
|
|
20
|
+
canonical_hash,
|
|
21
|
+
)
|
|
22
|
+
from fable_v2.runtime import FableRun, RunState, new_run
|
|
23
|
+
from fable_v2.adapters import HostCapabilities
|
|
24
|
+
from fable_v2.execution_broker import ExecutionBroker, BrokerPolicy
|
|
25
|
+
from fable_engine.server import (
|
|
26
|
+
DelegationContractCompiler,
|
|
27
|
+
FableSession,
|
|
28
|
+
handle_fable_session,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class MockFailingVerifier:
|
|
33
|
+
name = "mock_failing_verifier"
|
|
34
|
+
verifier_class = "deterministic"
|
|
35
|
+
independent = False
|
|
36
|
+
trust_boundary = "in_process"
|
|
37
|
+
|
|
38
|
+
def verify(self, candidate: Candidate) -> VerificationResult:
|
|
39
|
+
return VerificationResult(
|
|
40
|
+
verification_id=f"v_fail_{candidate.candidate_id}",
|
|
41
|
+
session_id=candidate.session_id,
|
|
42
|
+
candidate_id=candidate.candidate_id,
|
|
43
|
+
verifier="mock_failing_verifier",
|
|
44
|
+
passed=False,
|
|
45
|
+
reasons=("AssertionError: expected 42 but got 0", "Timeout in unit test"),
|
|
46
|
+
trust_boundary="in_process",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class MockPassingVerifier:
|
|
51
|
+
name = "mock_passing_verifier"
|
|
52
|
+
verifier_class = "deterministic"
|
|
53
|
+
independent = False
|
|
54
|
+
trust_boundary = "in_process"
|
|
55
|
+
|
|
56
|
+
def verify(self, candidate: Candidate) -> VerificationResult:
|
|
57
|
+
return VerificationResult(
|
|
58
|
+
verification_id=f"v_pass_{candidate.candidate_id}",
|
|
59
|
+
session_id=candidate.session_id,
|
|
60
|
+
candidate_id=candidate.candidate_id,
|
|
61
|
+
verifier="mock_passing_verifier",
|
|
62
|
+
passed=True,
|
|
63
|
+
reasons=(),
|
|
64
|
+
trust_boundary="in_process",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class TestSystem3RuntimeDeepIntegration(unittest.TestCase):
|
|
69
|
+
"""Test System 3 integration in fable_v2/runtime.py."""
|
|
70
|
+
|
|
71
|
+
def setUp(self):
|
|
72
|
+
self.task = TaskSpec(
|
|
73
|
+
task_id="task_deep_sys3_001",
|
|
74
|
+
objective="Implement System 3 deep integration with mathematical bounds",
|
|
75
|
+
required_capabilities=("read_file", "write_file"),
|
|
76
|
+
required_evidence=("file_check",),
|
|
77
|
+
definition_of_done=("Pass all unit tests", "Zero invariant violations"),
|
|
78
|
+
verification_policy=VerificationPolicy(
|
|
79
|
+
required_verifier_classes=("deterministic",),
|
|
80
|
+
minimum_passing_verifiers=1,
|
|
81
|
+
),
|
|
82
|
+
)
|
|
83
|
+
self.run = new_run(session_id="session_sys3_test", task=self.task)
|
|
84
|
+
|
|
85
|
+
def test_candidate_registration_evaluates_system3(self):
|
|
86
|
+
"""Candidate registration must evaluate Free Energy F, Kripke AG(safe), and Hyperbolic embeddings."""
|
|
87
|
+
r1 = ToolReceipt.from_result(
|
|
88
|
+
receipt_id="rec_1",
|
|
89
|
+
session_id="session_sys3_test",
|
|
90
|
+
capability="read_file",
|
|
91
|
+
tool_name="read_file",
|
|
92
|
+
tool_input={"path": "test.txt"},
|
|
93
|
+
tool_output="content",
|
|
94
|
+
success=True,
|
|
95
|
+
)
|
|
96
|
+
r2 = ToolReceipt.from_result(
|
|
97
|
+
receipt_id="rec_2",
|
|
98
|
+
session_id="session_sys3_test",
|
|
99
|
+
capability="write_file",
|
|
100
|
+
tool_name="write_file",
|
|
101
|
+
tool_input={"path": "out.txt"},
|
|
102
|
+
tool_output="ok",
|
|
103
|
+
success=True,
|
|
104
|
+
)
|
|
105
|
+
self.run.record_receipt(r1)
|
|
106
|
+
self.run.record_receipt(r2)
|
|
107
|
+
|
|
108
|
+
ev = Evidence.from_receipt(
|
|
109
|
+
receipt=r1,
|
|
110
|
+
evidence_id="ev_1",
|
|
111
|
+
claim="File content matches expectation",
|
|
112
|
+
kind="file_check",
|
|
113
|
+
source="test_runner",
|
|
114
|
+
)
|
|
115
|
+
self.run.attach_evidence(ev)
|
|
116
|
+
|
|
117
|
+
cand = Candidate(
|
|
118
|
+
candidate_id="cand_sys3_01",
|
|
119
|
+
session_id="session_sys3_test",
|
|
120
|
+
approach="system3_pareto_architecture",
|
|
121
|
+
artifact={"title": "System 3 Core Implementation", "version": "1.0"},
|
|
122
|
+
receipt_ids=("rec_1", "rec_2"),
|
|
123
|
+
evidence_ids=("ev_1",),
|
|
124
|
+
)
|
|
125
|
+
self.run.register_candidate(cand)
|
|
126
|
+
|
|
127
|
+
stored = self.run.candidates["cand_sys3_01"]
|
|
128
|
+
# Check Free Energy F
|
|
129
|
+
self.assertIn("system3_free_energy", stored.metadata)
|
|
130
|
+
fe = stored.metadata["system3_free_energy"]
|
|
131
|
+
self.assertIn("variational_free_energy_f", fe)
|
|
132
|
+
self.assertIn("complexity_kl", fe)
|
|
133
|
+
self.assertIn("accuracy_log_likelihood", fe)
|
|
134
|
+
|
|
135
|
+
# Check Kripke Invariants
|
|
136
|
+
self.assertIn("system3_kripke", stored.metadata)
|
|
137
|
+
kripke = stored.metadata["system3_kripke"]
|
|
138
|
+
self.assertEqual(kripke["formula"], "AG(safe)")
|
|
139
|
+
self.assertTrue(kripke["is_satisfied"])
|
|
140
|
+
|
|
141
|
+
# Check Hyperbolic Tree Embedding
|
|
142
|
+
self.assertIn("system3_hyperbolic", stored.metadata)
|
|
143
|
+
hyp = stored.metadata["system3_hyperbolic"]
|
|
144
|
+
self.assertEqual(hyp["root_id"], "cand_sys3_01")
|
|
145
|
+
self.assertGreater(hyp["total_nodes"], 0)
|
|
146
|
+
|
|
147
|
+
def test_verification_failure_triggers_triz_repair(self):
|
|
148
|
+
"""Verifier failure must automatically synthesize TRIZ repair recommendations and attach to candidate."""
|
|
149
|
+
r1 = ToolReceipt.from_result(
|
|
150
|
+
receipt_id="rec_1",
|
|
151
|
+
session_id="session_sys3_test",
|
|
152
|
+
capability="read_file",
|
|
153
|
+
tool_name="read_file",
|
|
154
|
+
tool_input={"path": "test.txt"},
|
|
155
|
+
tool_output="content",
|
|
156
|
+
success=True,
|
|
157
|
+
)
|
|
158
|
+
self.run.record_receipt(r1)
|
|
159
|
+
ev = Evidence.from_receipt(
|
|
160
|
+
receipt=r1,
|
|
161
|
+
evidence_id="ev_1",
|
|
162
|
+
claim="File test ok",
|
|
163
|
+
kind="file_check",
|
|
164
|
+
source="test_runner",
|
|
165
|
+
)
|
|
166
|
+
self.run.attach_evidence(ev)
|
|
167
|
+
|
|
168
|
+
cand = Candidate(
|
|
169
|
+
candidate_id="cand_failing_01",
|
|
170
|
+
session_id="session_sys3_test",
|
|
171
|
+
approach="failing_architecture_candidate",
|
|
172
|
+
artifact={"title": "Failing Microservice"},
|
|
173
|
+
receipt_ids=("rec_1",),
|
|
174
|
+
evidence_ids=("ev_1",),
|
|
175
|
+
)
|
|
176
|
+
self.run.register_candidate(cand)
|
|
177
|
+
|
|
178
|
+
verifier = MockFailingVerifier()
|
|
179
|
+
result = self.run.execute_verifier(verifier, "cand_failing_01")
|
|
180
|
+
self.assertFalse(result.passed)
|
|
181
|
+
|
|
182
|
+
# Verify TRIZ recommendations were generated and stored
|
|
183
|
+
stored = self.run.candidates["cand_failing_01"]
|
|
184
|
+
self.assertIn("triz_repair_recommendation", stored.metadata)
|
|
185
|
+
triz_rec = stored.metadata["triz_repair_recommendation"]
|
|
186
|
+
self.assertEqual(triz_rec["candidate_id"], "cand_failing_01")
|
|
187
|
+
self.assertIn("synthesized_architecture", triz_rec)
|
|
188
|
+
self.assertIn("recommendations", triz_rec)
|
|
189
|
+
self.assertGreater(len(triz_rec["recommendations"]), 0)
|
|
190
|
+
self.assertEqual(len(self.run.triz_repair_recommendations), 1)
|
|
191
|
+
|
|
192
|
+
def test_run_system3_meta_cycle(self):
|
|
193
|
+
"""run_system3_meta_cycle must execute full reflection and return structured dictionary."""
|
|
194
|
+
r1 = ToolReceipt.from_result(
|
|
195
|
+
receipt_id="rec_1",
|
|
196
|
+
session_id="session_sys3_test",
|
|
197
|
+
capability="read_file",
|
|
198
|
+
tool_name="read_file",
|
|
199
|
+
tool_input={"path": "test.txt"},
|
|
200
|
+
tool_output="content",
|
|
201
|
+
success=True,
|
|
202
|
+
)
|
|
203
|
+
self.run.record_receipt(r1)
|
|
204
|
+
cand = Candidate(
|
|
205
|
+
candidate_id="cand_meta_01",
|
|
206
|
+
session_id="session_sys3_test",
|
|
207
|
+
approach="meta_cycle_candidate",
|
|
208
|
+
artifact={"title": "Meta Cycle Candidate"},
|
|
209
|
+
receipt_ids=("rec_1",),
|
|
210
|
+
evidence_ids=(),
|
|
211
|
+
)
|
|
212
|
+
self.run.register_candidate(cand)
|
|
213
|
+
|
|
214
|
+
meta_report = self.run.run_system3_meta_cycle("cand_meta_01")
|
|
215
|
+
self.assertIn("free_energy", meta_report)
|
|
216
|
+
self.assertIn("kripke_invariants", meta_report)
|
|
217
|
+
self.assertIn("hyperbolic_embedding", meta_report)
|
|
218
|
+
self.assertIn("bias_findings", meta_report)
|
|
219
|
+
self.assertIn("arbitration", meta_report)
|
|
220
|
+
self.assertIn("dialectical_synthesis", meta_report)
|
|
221
|
+
self.assertEqual(len(self.run.system3_meta_cycles), 1)
|
|
222
|
+
|
|
223
|
+
def test_serialization_roundtrip_preserves_system3_fields(self):
|
|
224
|
+
"""to_dict and from_dict must preserve all System 3 state fields without loss."""
|
|
225
|
+
r1 = ToolReceipt.from_result(
|
|
226
|
+
receipt_id="rec_1",
|
|
227
|
+
session_id="session_sys3_test",
|
|
228
|
+
capability="read_file",
|
|
229
|
+
tool_name="read_file",
|
|
230
|
+
tool_input={"path": "test.txt"},
|
|
231
|
+
tool_output="content",
|
|
232
|
+
success=True,
|
|
233
|
+
)
|
|
234
|
+
self.run.record_receipt(r1)
|
|
235
|
+
cand = Candidate(
|
|
236
|
+
candidate_id="cand_serial_01",
|
|
237
|
+
session_id="session_sys3_test",
|
|
238
|
+
approach="serial_candidate",
|
|
239
|
+
artifact={"title": "Serial Candidate"},
|
|
240
|
+
receipt_ids=("rec_1",),
|
|
241
|
+
evidence_ids=(),
|
|
242
|
+
)
|
|
243
|
+
self.run.register_candidate(cand)
|
|
244
|
+
self.run.run_system3_meta_cycle("cand_serial_01")
|
|
245
|
+
|
|
246
|
+
data = self.run.to_dict()
|
|
247
|
+
self.assertIn("system3_free_energy", data)
|
|
248
|
+
self.assertIn("system3_kripke_invariants", data)
|
|
249
|
+
self.assertIn("system3_hyperbolic_embeddings", data)
|
|
250
|
+
self.assertIn("system3_meta_cycles", data)
|
|
251
|
+
self.assertIn("triz_repair_recommendations", data)
|
|
252
|
+
|
|
253
|
+
restored = FableRun.from_dict(data)
|
|
254
|
+
self.assertEqual(len(restored.system3_meta_cycles), 1)
|
|
255
|
+
self.assertEqual(len(restored.system3_free_energy), 1)
|
|
256
|
+
self.assertEqual(restored.system3_meta_cycles[0]["candidate_id"], "cand_serial_01")
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class TestSystem3ServerDeepIntegration(unittest.TestCase):
|
|
260
|
+
"""Test System 3 integration in fable_engine/server.py."""
|
|
261
|
+
|
|
262
|
+
def setUp(self):
|
|
263
|
+
self.session = FableSession(
|
|
264
|
+
session_name="test_sys3_session",
|
|
265
|
+
objective="Evaluate System 3 Server Integration",
|
|
266
|
+
time_budget_minutes=30.0,
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
def test_advance_phase_runs_system3_bias_and_free_energy(self):
|
|
270
|
+
"""advance_phase must run bias detection, update active Free Energy and Kripke safety."""
|
|
271
|
+
tel = self.session.advance_phase("Phase 2: Invariant Specification & Blueprint", "Explored 3 archetypes")
|
|
272
|
+
self.assertIn("system3_cognitive_state", tel)
|
|
273
|
+
cog = tel["system3_cognitive_state"]
|
|
274
|
+
self.assertIn("free_energy_f", cog)
|
|
275
|
+
self.assertIn("kripke_safety_invariant", cog)
|
|
276
|
+
self.assertIn("active_biases_count", cog)
|
|
277
|
+
self.assertTrue(cog["kripke_safety_verified"])
|
|
278
|
+
self.assertEqual(len(self.session.system3_active_inferences), 1)
|
|
279
|
+
|
|
280
|
+
def test_log_refinement_cycle_updates_causal_dag_and_free_energy(self):
|
|
281
|
+
"""log_refinement_cycle must update active Free Energy and causal DAG nodes."""
|
|
282
|
+
entry = self.session.log_refinement_cycle(
|
|
283
|
+
refinement_type="architectural",
|
|
284
|
+
focus_area="Memory Model",
|
|
285
|
+
critique_or_bottleneck="Contention on spinlock",
|
|
286
|
+
architectural_refinement="Converted to ticket lock",
|
|
287
|
+
terminal_probe_results="Benchmark: 15% latency reduction PASS",
|
|
288
|
+
)
|
|
289
|
+
self.assertEqual(entry["cycle_number"], 1)
|
|
290
|
+
self.assertIsNotNone(self.session.active_free_energy)
|
|
291
|
+
self.assertEqual(len(self.session.system3_causal_graphs), 1)
|
|
292
|
+
dag_dict = self.session.system3_causal_graphs[0]
|
|
293
|
+
self.assertTrue(any(n["node_id"] == "refine_cycle_1" for n in dag_dict["nodes"]))
|
|
294
|
+
|
|
295
|
+
def test_delegation_contract_compiler_injects_micro_scaffolds(self):
|
|
296
|
+
"""DelegationContractCompiler must inject formal mathematical micro-scaffolds for weak models."""
|
|
297
|
+
compiler = DelegationContractCompiler()
|
|
298
|
+
prompt = """
|
|
299
|
+
TargetFile: src/pipeline.py
|
|
300
|
+
InterfaceContract: def process_data(records: list[dict]) -> tuple[int, int]: ...
|
|
301
|
+
StrictConstraints: Zero-alloc in hot path; thread-safe under GIL.
|
|
302
|
+
VerificationCommand: pytest tests/test_pipeline.py -v
|
|
303
|
+
"""
|
|
304
|
+
is_valid, errors, parsed = compiler.compile_and_validate(prompt)
|
|
305
|
+
self.assertTrue(is_valid)
|
|
306
|
+
self.assertEqual(len(errors), 0)
|
|
307
|
+
self.assertIn("system3_micro_scaffold", parsed)
|
|
308
|
+
scaffold = parsed["system3_micro_scaffold"]
|
|
309
|
+
self.assertIn("SYSTEM 3 MICRO-SCAFFOLD", scaffold)
|
|
310
|
+
self.assertIn("AG(\\text{safe})", scaffold)
|
|
311
|
+
self.assertIn("do(\\cdot)", scaffold)
|
|
312
|
+
self.assertIn("TRIZ Transcendent Resolution", scaffold)
|
|
313
|
+
self.assertIn("Structured Output Regex Acceptance Constraint", scaffold)
|
|
314
|
+
|
|
315
|
+
def test_handle_fable_session_advance_and_compile(self):
|
|
316
|
+
"""handle_fable_session must return rich System 3 telemetry in advance_phase and compile_delegation_contract."""
|
|
317
|
+
init_res = handle_fable_session({
|
|
318
|
+
"action": "create_session",
|
|
319
|
+
"session_name": "sys3_rpc_session",
|
|
320
|
+
"objective": "Test RPC Integration",
|
|
321
|
+
"time_budget_minutes": 20.0,
|
|
322
|
+
})
|
|
323
|
+
self.assertIn("Fable Cognitive Session Initialized", init_res)
|
|
324
|
+
|
|
325
|
+
adv_res = handle_fable_session({
|
|
326
|
+
"action": "advance_phase",
|
|
327
|
+
"session_name": "sys3_rpc_session",
|
|
328
|
+
"next_phase": "Phase 2: Invariant Specification & Blueprint",
|
|
329
|
+
"phase_summary": "Synthesized 3 distinct paradigms",
|
|
330
|
+
})
|
|
331
|
+
self.assertIn("System 3 Meta-Cognitive Advisory", adv_res)
|
|
332
|
+
self.assertIn("Live Free Energy", adv_res)
|
|
333
|
+
|
|
334
|
+
compile_res = handle_fable_session({
|
|
335
|
+
"action": "compile_delegation_contract",
|
|
336
|
+
"subagent_prompt": """
|
|
337
|
+
TargetFile: src/core.py
|
|
338
|
+
InterfaceContract: class CoreEngine: def run(self) -> bool: ...
|
|
339
|
+
StrictConstraints: Safe execution bounds
|
|
340
|
+
VerificationCommand: python -m unittest
|
|
341
|
+
""",
|
|
342
|
+
})
|
|
343
|
+
self.assertIn("System 3 Micro-Scaffolds", compile_res)
|
|
344
|
+
self.assertIn("INJECTED", compile_res)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
class TestSystem3BrokerAndAdapters(unittest.TestCase):
|
|
348
|
+
"""Test System 3 checks in execution broker and host adapters."""
|
|
349
|
+
|
|
350
|
+
def test_host_capabilities_system3_methods(self):
|
|
351
|
+
caps = HostCapabilities(
|
|
352
|
+
host="gemini-cli",
|
|
353
|
+
capabilities=frozenset({"run_command", "view_file", "write_to_file"}),
|
|
354
|
+
)
|
|
355
|
+
# Temporal invariant check
|
|
356
|
+
k_res = caps.verify_temporal_capability_invariants("AG(capable)")
|
|
357
|
+
self.assertIn("is_satisfied", k_res)
|
|
358
|
+
|
|
359
|
+
# Causal capability contract validation
|
|
360
|
+
c_res = caps.validate_causal_capability_contract(["run_command", "view_file"])
|
|
361
|
+
self.assertTrue(c_res["is_valid"])
|
|
362
|
+
self.assertEqual(len(c_res["missing"]), 0)
|
|
363
|
+
|
|
364
|
+
c_missing = caps.validate_causal_capability_contract(["run_command", "gpu_compute"])
|
|
365
|
+
self.assertFalse(c_missing["is_valid"])
|
|
366
|
+
self.assertIn("gpu_compute", c_missing["missing"])
|
|
367
|
+
|
|
368
|
+
def test_execution_broker_system3_pre_checks(self):
|
|
369
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
370
|
+
policy = BrokerPolicy(
|
|
371
|
+
workspace=Path(tmpdir),
|
|
372
|
+
allowed_executables=("python",),
|
|
373
|
+
)
|
|
374
|
+
broker = ExecutionBroker(policy)
|
|
375
|
+
k_res = broker.check_kripke_pre_execution_invariants(["python", "-c", "print(1)"])
|
|
376
|
+
self.assertTrue(k_res["is_satisfied"])
|
|
377
|
+
self.assertEqual(k_res["formula"], "AG(safe_execution)")
|
|
378
|
+
|
|
379
|
+
c_res = broker.validate_causal_boundaries(["python", "-c", "print(1)"])
|
|
380
|
+
self.assertTrue(c_res["is_valid"])
|
|
381
|
+
self.assertIn("dag", c_res)
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
if __name__ == "__main__":
|
|
385
|
+
unittest.main()
|