41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from idea187_autopoiesis_verifiable_service import (
|
|
ServiceGenome,
|
|
CapabilityVector,
|
|
ResourceEnvelope,
|
|
SafetyInvariants,
|
|
MutationOperator,
|
|
TestContract,
|
|
generate_ems,
|
|
)
|
|
|
|
|
|
def build_base() -> ServiceGenome:
|
|
return ServiceGenome(
|
|
name="svc",
|
|
version="0.1",
|
|
image_ref="ghcr.io/example/svc:0.1",
|
|
capabilities=CapabilityVector(network=["https://internal"], db_access=["sqlite"], actuators=[]),
|
|
resource_envelope=ResourceEnvelope(cpu_millicores=100, memory_mib=128, bandwidth_mbps=5, cost_usd_per_hour=0.01, max_replicas=1),
|
|
safety_invariants=SafetyInvariants(max_exposure=5, read_only_scopes=[], denied_endpoints=[]),
|
|
mutation_operators=[MutationOperator(name="safe-fork", kind="fork")],
|
|
test_contracts=[TestContract(name="t1", seed=1, input_fingerprint="a", expected_output_hash=__import__("hashlib").sha256("1:a".encode()).hexdigest())],
|
|
)
|
|
|
|
|
|
def test_generate_ems_detects_added_network_and_resource_increase():
|
|
before = build_base()
|
|
after = before.model_copy(update={
|
|
"capabilities": before.capabilities.model_copy(update={"network": before.capabilities.network + ["https://exfil.example"]}),
|
|
"resource_envelope": before.resource_envelope.model_copy(update={"cpu_millicores": 200, "max_replicas": 2}),
|
|
})
|
|
|
|
ems = generate_ems(before, after)
|
|
assert "https://exfil.example" in ems.capability_delta.added_network
|
|
assert ems.resource_delta.cpu_millicores == 100
|
|
assert ems.resource_delta.max_replicas == 1
|
|
# safety risk should reflect the new network exposure
|
|
assert ems.safety_risk_delta >= 0
|
|
assert isinstance(ems.counterfactual_sample.get("seed"), int)
|