fix(web): solve p0 mapping, nested validation, and add health checks
这个提交包含在:
+85
-1
@@ -84,6 +84,30 @@ def test_validation():
|
||||
assert issues[0]['algo'] == "Clean"
|
||||
print("Scheduler validation flow passed.")
|
||||
|
||||
def test_nested_validation():
|
||||
from src.validator import FlowValidator
|
||||
from src.models import WaterSoundData
|
||||
|
||||
wsd = WaterSoundData()
|
||||
wsd.sea_env = {"modeling": {"freq_hz": 100}}
|
||||
|
||||
# 1. 存在性校验
|
||||
ok, msg, _ = FlowValidator.check_field_existence(wsd, "sea_env.modeling.freq_hz")
|
||||
assert ok, f"Nested existence failed: {msg}"
|
||||
|
||||
ok, _, _ = FlowValidator.check_field_existence(wsd, "sea_env.modeling.non_existent")
|
||||
assert not ok, "Nested non-existence should fail"
|
||||
|
||||
# 2. 类型校验
|
||||
ok, msg, _ = FlowValidator.check_data_type(wsd, "sea_env.modeling.freq_hz", "int")
|
||||
assert ok, f"Nested type check failed: {msg}"
|
||||
|
||||
# 3. 嵌套写入仿真
|
||||
FlowValidator._set_nested_field(wsd, "vis_data.tl_matrix.values", np.array([1, 2, 3]))
|
||||
assert wsd.vis_data["tl_matrix"]["values"][1] == 2
|
||||
|
||||
print("Nested validation test passed.")
|
||||
|
||||
def test_sea_trial_pipeline():
|
||||
print("Starting sea-trial pipeline test...")
|
||||
from src.sample_algorithms import dc_removal_and_bandpass, quality_check, snr_estimation
|
||||
@@ -113,6 +137,7 @@ def test_sea_trial_pipeline():
|
||||
def test_cpp_bridge():
|
||||
print("Starting C++ bridge test...")
|
||||
from src.bridges import CppBridge
|
||||
from src.integrity import sha256_file
|
||||
|
||||
lib_path = "src/sample_algos_cpp/simple_ops.so"
|
||||
if not os.path.exists(lib_path):
|
||||
@@ -127,7 +152,8 @@ def test_cpp_bridge():
|
||||
lib_path,
|
||||
"multiply_by_factor_cpp",
|
||||
{"in_data": "clean_data"},
|
||||
{"0": "final_result"}
|
||||
{"0": "final_result"},
|
||||
expected_sha256=sha256_file(lib_path),
|
||||
)
|
||||
|
||||
scheduler = CoreScheduler()
|
||||
@@ -143,6 +169,60 @@ def test_cpp_bridge():
|
||||
assert np.allclose(result.final_result, raw * 1.5)
|
||||
print("C++ bridge test passed.")
|
||||
|
||||
def test_cpp_bridge_isolated():
|
||||
print("Starting C++ bridge isolated test...")
|
||||
from src.bridges import CppBridge
|
||||
from src.integrity import sha256_file
|
||||
|
||||
lib_path = "src/sample_algos_cpp/simple_ops.so"
|
||||
if not os.path.exists(lib_path):
|
||||
print("C++ library not found, skipping isolated CPP test.")
|
||||
return
|
||||
|
||||
raw = np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype=np.float64)
|
||||
wsd = WaterSoundData(clean_data=raw)
|
||||
|
||||
cpp_bridge = CppBridge(
|
||||
"GainCPP(Isolated)",
|
||||
lib_path,
|
||||
"multiply_by_factor_cpp",
|
||||
{"in_data": "clean_data"},
|
||||
{"0": "final_result"},
|
||||
expected_sha256=sha256_file(lib_path),
|
||||
isolate=True,
|
||||
)
|
||||
|
||||
scheduler = CoreScheduler()
|
||||
scheduler.set_flow([cpp_bridge])
|
||||
result = scheduler.execute(wsd)
|
||||
|
||||
if result.status != "finished":
|
||||
print(f"C++ Bridge Isolated Execution Failed: {result.error_info}")
|
||||
for l in result.log:
|
||||
print(f" Log: {l}")
|
||||
|
||||
assert result.status == "finished"
|
||||
assert np.allclose(result.final_result, raw * 1.5)
|
||||
print("C++ bridge isolated test passed.")
|
||||
|
||||
def test_python_loader_sha256():
|
||||
print("Starting Python loader SHA256 test...")
|
||||
from src.algo_loader import load_algo_func
|
||||
from src.integrity import sha256_file
|
||||
|
||||
module_file = "src/sample_algorithms.py"
|
||||
good_hash = sha256_file(module_file)
|
||||
func = load_algo_func("src.sample_algorithms", "snr_estimation", expected_sha256=good_hash)
|
||||
assert callable(func)
|
||||
|
||||
bad_hash = "0" * 64
|
||||
try:
|
||||
load_algo_func("src.sample_algorithms", "snr_estimation", expected_sha256=bad_hash)
|
||||
assert False, "expected SHA256 mismatch to raise"
|
||||
except Exception as e:
|
||||
assert "SHA256" in str(e)
|
||||
print("Python loader SHA256 test passed.")
|
||||
|
||||
def test_matlab_bridge_fallback():
|
||||
print("Starting MATLAB bridge fallback test...")
|
||||
from src.bridges import MatlabBridge
|
||||
@@ -171,4 +251,8 @@ if __name__ == "__main__":
|
||||
test_validation()
|
||||
test_sea_trial_pipeline()
|
||||
test_cpp_bridge()
|
||||
test_cpp_bridge_isolated()
|
||||
test_python_loader_sha256()
|
||||
test_matlab_bridge_fallback()
|
||||
test_nested_validation()
|
||||
print("\nAll Tests Passed Successfully! 🚀")
|
||||
|
||||
在新工单中引用
屏蔽一个用户