"""DGR-037 structural guardrails for the standalone llama.cpp worker. The real GGUF lane is opt-in and needs a mounted artifact; these tests keep the default suite model-download-free while guarding the integration shape that a later real-model harness exercises. """ from pathlib import Path ROOT = Path(__file__).resolve().parents[1] WORKER = ROOT / "packages/node/native/worker" def test_worker_uses_the_private_llama_shardengine_not_the_fixture_engine(): service_header = (WORKER / "shard_service.h").read_text(encoding="utf-8") service = (WORKER / "shard_service.cpp").read_text(encoding="utf-8") engine = (WORKER / "llama_shard_engine.cpp").read_text(encoding="utf-8") assert '#include "llama_shard_engine.h"' in service_header assert "FakeShardEngine" not in service_header assert "engine_.Execute(" in service assert "llama_model_load_from_file" in engine assert "llama_model_meshnet_range_report" in engine def test_worker_configuration_and_death_hook_are_explicit_and_opt_in(): main = (WORKER / "shard_worker_main.cpp").read_text(encoding="utf-8") for name in ( "MESHNET_MODEL_ARTIFACT", "MESHNET_MODEL_ARTIFACT_DIGEST", "MESHNET_RUNTIME_RECIPE_DIGEST", "MESHNET_SHARD_START_LAYER", "MESHNET_SHARD_END_LAYER", "MESHNET_INJECT_PROCESS_DEATH_AFTER_EXECUTIONS", ): assert name in main assert "engine->Shutdown()" in main def test_identity_is_loaded_not_stream_supplied_and_health_reports_it(): source = (WORKER / "shard_service.cpp").read_text(encoding="utf-8") assert "r.start_layer() == engine_.identity().start_layer" in source assert "r.end_layer() == engine_.identity().end_layer" in source assert "model artifact or runtime recipe digest does not match" in source assert "resident_bytes" in source assert '" range=["' in source def test_hot_kv_is_bounded_and_keyed_by_route_session_and_epoch(): engine = (WORKER / "llama_shard_engine.cpp").read_text(encoding="utf-8") header = (WORKER / "llama_shard_engine.h").read_text(encoding="utf-8") service = (WORKER / "shard_service.cpp").read_text(encoding="utf-8") main = (WORKER / "shard_worker_main.cpp").read_text(encoding="utf-8") assert "struct SessionKey" in engine assert "uint64_t route_epoch" in engine assert "llama_init_from_model" in engine assert "llama_memory_seq_rm" in engine assert "EvictExpiredLocked" in engine assert "EvictLruLocked" in engine assert "HotKvStatus::kCacheMiss" in service assert "ERROR_CODE_CACHE_MISS" in service assert "MESHNET_HOT_KV_BUDGET_TOKENS" in main assert "HotKvStep" in header