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,198 @@
|
|
|
1
|
+
"""Test Harness Engine for Isolated Scratch Execution, Concurrency Fuzzing, and Resource Profiling.
|
|
2
|
+
|
|
3
|
+
Provides subprocess isolation, timeout enforcement, thread-safety fuzzing, and memory profiling.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import tempfile
|
|
12
|
+
import textwrap
|
|
13
|
+
import time
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestHarnessEngine:
|
|
18
|
+
"""Engine for executing isolated test scripts, concurrency fuzzing, and performance profiling."""
|
|
19
|
+
|
|
20
|
+
def run_scratch_test(self, code: str, timeout_sec: float = 3.0) -> dict[str, Any]:
|
|
21
|
+
"""Write script to tempfile, execute via sys.executable, enforce strict timeout,
|
|
22
|
+
|
|
23
|
+
and capture stdout, stderr, returncode, duration_ms.
|
|
24
|
+
"""
|
|
25
|
+
temp_fd, temp_path = tempfile.mkstemp(suffix=".py", text=True)
|
|
26
|
+
try:
|
|
27
|
+
with os.fdopen(temp_fd, "w", encoding="utf-8") as f:
|
|
28
|
+
f.write(code)
|
|
29
|
+
|
|
30
|
+
t0 = time.perf_counter()
|
|
31
|
+
try:
|
|
32
|
+
proc = subprocess.run(
|
|
33
|
+
[sys.executable, temp_path],
|
|
34
|
+
capture_output=True,
|
|
35
|
+
text=True,
|
|
36
|
+
timeout=timeout_sec,
|
|
37
|
+
)
|
|
38
|
+
duration_ms = (time.perf_counter() - t0) * 1000.0
|
|
39
|
+
return {
|
|
40
|
+
"stdout": proc.stdout,
|
|
41
|
+
"stderr": proc.stderr,
|
|
42
|
+
"returncode": proc.returncode,
|
|
43
|
+
"duration_ms": round(duration_ms, 2),
|
|
44
|
+
"timed_out": False,
|
|
45
|
+
"success": proc.returncode == 0,
|
|
46
|
+
}
|
|
47
|
+
except subprocess.TimeoutExpired as exc:
|
|
48
|
+
duration_ms = (time.perf_counter() - t0) * 1000.0
|
|
49
|
+
stdout = exc.stdout if isinstance(exc.stdout, str) else (exc.stdout.decode() if exc.stdout else "")
|
|
50
|
+
stderr = exc.stderr if isinstance(exc.stderr, str) else (exc.stderr.decode() if exc.stderr else "")
|
|
51
|
+
return {
|
|
52
|
+
"stdout": stdout,
|
|
53
|
+
"stderr": (stderr + "\nExecution timed out").strip(),
|
|
54
|
+
"returncode": -1,
|
|
55
|
+
"duration_ms": round(duration_ms, 2),
|
|
56
|
+
"timed_out": True,
|
|
57
|
+
"success": False,
|
|
58
|
+
}
|
|
59
|
+
finally:
|
|
60
|
+
try:
|
|
61
|
+
if os.path.exists(temp_path):
|
|
62
|
+
os.remove(temp_path)
|
|
63
|
+
except OSError:
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
def concurrency_fuzz(self, func_code: str, threads: int = 4, iterations: int = 50) -> dict[str, Any]:
|
|
67
|
+
"""Execute multithreaded stress loop to detect race conditions or exceptions."""
|
|
68
|
+
if "def target_fn" in func_code or "def run" in func_code:
|
|
69
|
+
code_body = func_code
|
|
70
|
+
else:
|
|
71
|
+
# Wrap script body into target_fn
|
|
72
|
+
indented = textwrap.indent(func_code.strip(), " ")
|
|
73
|
+
code_body = f"def target_fn():\n{indented}\n"
|
|
74
|
+
|
|
75
|
+
driver = f"""
|
|
76
|
+
import json
|
|
77
|
+
import threading
|
|
78
|
+
import traceback
|
|
79
|
+
import sys
|
|
80
|
+
|
|
81
|
+
{code_body}
|
|
82
|
+
|
|
83
|
+
exceptions = []
|
|
84
|
+
lock = threading.Lock()
|
|
85
|
+
|
|
86
|
+
def worker(worker_id):
|
|
87
|
+
for i in range({iterations}):
|
|
88
|
+
try:
|
|
89
|
+
if "target_fn" in globals():
|
|
90
|
+
target_fn()
|
|
91
|
+
elif "run" in globals():
|
|
92
|
+
run()
|
|
93
|
+
except Exception as e:
|
|
94
|
+
with lock:
|
|
95
|
+
exceptions.append(f"{{type(e).__name__}}: {{e}}")
|
|
96
|
+
break
|
|
97
|
+
|
|
98
|
+
thread_pool = []
|
|
99
|
+
for t_id in range({threads}):
|
|
100
|
+
t = threading.Thread(target=worker, args=(t_id,))
|
|
101
|
+
thread_pool.append(t)
|
|
102
|
+
t.start()
|
|
103
|
+
|
|
104
|
+
for t in thread_pool:
|
|
105
|
+
t.join()
|
|
106
|
+
|
|
107
|
+
output = {{
|
|
108
|
+
"exceptions": exceptions,
|
|
109
|
+
"race_conditions_detected": len(exceptions) > 0,
|
|
110
|
+
}}
|
|
111
|
+
print("__CONCURRENCY_OUTPUT__" + json.dumps(output))
|
|
112
|
+
"""
|
|
113
|
+
res = self.run_scratch_test(driver, timeout_sec=max(5.0, threads * 1.5))
|
|
114
|
+
if not res["success"]:
|
|
115
|
+
return {
|
|
116
|
+
"threads": threads,
|
|
117
|
+
"iterations": iterations,
|
|
118
|
+
"race_conditions_detected": True,
|
|
119
|
+
"exceptions": [res["stderr"] or "Process terminated abnormally"],
|
|
120
|
+
"duration_ms": res["duration_ms"],
|
|
121
|
+
"success": False,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
# Parse output
|
|
125
|
+
stdout = res["stdout"]
|
|
126
|
+
marker = "__CONCURRENCY_OUTPUT__"
|
|
127
|
+
if marker in stdout:
|
|
128
|
+
payload_str = stdout.split(marker, 1)[1].strip()
|
|
129
|
+
try:
|
|
130
|
+
data = json.loads(payload_str)
|
|
131
|
+
return {
|
|
132
|
+
"threads": threads,
|
|
133
|
+
"iterations": iterations,
|
|
134
|
+
"race_conditions_detected": data.get("race_conditions_detected", False),
|
|
135
|
+
"exceptions": data.get("exceptions", []),
|
|
136
|
+
"duration_ms": res["duration_ms"],
|
|
137
|
+
"success": len(data.get("exceptions", [])) == 0,
|
|
138
|
+
}
|
|
139
|
+
except json.JSONDecodeError:
|
|
140
|
+
pass
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
"threads": threads,
|
|
144
|
+
"iterations": iterations,
|
|
145
|
+
"race_conditions_detected": False,
|
|
146
|
+
"exceptions": [],
|
|
147
|
+
"duration_ms": res["duration_ms"],
|
|
148
|
+
"success": True,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
def profile_memory_and_cpu(self, code: str) -> dict[str, Any]:
|
|
152
|
+
"""Run code and return execution duration and estimated heap delta."""
|
|
153
|
+
indented = textwrap.indent(code.strip(), " ")
|
|
154
|
+
driver = f"""
|
|
155
|
+
import tracemalloc
|
|
156
|
+
import time
|
|
157
|
+
import json
|
|
158
|
+
import sys
|
|
159
|
+
|
|
160
|
+
tracemalloc.start()
|
|
161
|
+
t0 = time.perf_counter()
|
|
162
|
+
err_str = None
|
|
163
|
+
|
|
164
|
+
try:
|
|
165
|
+
{indented}
|
|
166
|
+
except Exception as e:
|
|
167
|
+
err_str = f"{{type(e).__name__}}: {{e}}"
|
|
168
|
+
|
|
169
|
+
t1 = time.perf_counter()
|
|
170
|
+
current, peak = tracemalloc.get_traced_memory()
|
|
171
|
+
tracemalloc.stop()
|
|
172
|
+
|
|
173
|
+
result = {{
|
|
174
|
+
"duration_ms": round((t1 - t0) * 1000.0, 3),
|
|
175
|
+
"peak_memory_bytes": peak,
|
|
176
|
+
"memory_delta_bytes": current,
|
|
177
|
+
"error": err_str,
|
|
178
|
+
}}
|
|
179
|
+
print("__PROFILE_OUTPUT__" + json.dumps(result))
|
|
180
|
+
"""
|
|
181
|
+
res = self.run_scratch_test(driver, timeout_sec=5.0)
|
|
182
|
+
marker = "__PROFILE_OUTPUT__"
|
|
183
|
+
if res["success"] and marker in res["stdout"]:
|
|
184
|
+
payload_str = res["stdout"].split(marker, 1)[1].strip()
|
|
185
|
+
try:
|
|
186
|
+
data = json.loads(payload_str)
|
|
187
|
+
data["success"] = data.get("error") is None
|
|
188
|
+
return data
|
|
189
|
+
except json.JSONDecodeError:
|
|
190
|
+
pass
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
"duration_ms": res["duration_ms"],
|
|
194
|
+
"peak_memory_bytes": 0,
|
|
195
|
+
"memory_delta_bytes": 0,
|
|
196
|
+
"success": False,
|
|
197
|
+
"error": res["stderr"] or "Profiling execution failed",
|
|
198
|
+
}
|