generated from coulomb/repo-seed
Implement first knowledge engine runtime slice
This commit is contained in:
75
tests/test_artifacts.py
Normal file
75
tests/test_artifacts.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from kontextual_engine import (
|
||||
Artifact,
|
||||
ArtifactMetadata,
|
||||
ArtifactReference,
|
||||
ArtifactType,
|
||||
Collection,
|
||||
Relationship,
|
||||
RelationshipGraph,
|
||||
RelationshipType,
|
||||
content_digest,
|
||||
)
|
||||
|
||||
|
||||
def test_artifact_create_updates_digest_and_roundtrips() -> None:
|
||||
artifact = Artifact.create(
|
||||
"collection-1",
|
||||
"brief",
|
||||
"first version",
|
||||
artifact_type=ArtifactType.DOCUMENT,
|
||||
metadata=ArtifactMetadata(tags=["example"], media_type="text/plain"),
|
||||
)
|
||||
|
||||
assert artifact.content_digest == content_digest("first version")
|
||||
assert artifact.content_size == len("first version".encode("utf-8"))
|
||||
|
||||
artifact.update_content("second version")
|
||||
assert artifact.content_digest == content_digest("second version")
|
||||
|
||||
restored = Artifact.from_dict(artifact.to_dict())
|
||||
assert restored.id == artifact.id
|
||||
assert restored.metadata.tags == ["example"]
|
||||
assert restored.artifact_type == ArtifactType.DOCUMENT
|
||||
|
||||
|
||||
def test_artifact_reference_parse_formats() -> None:
|
||||
assert ArtifactReference.parse("name") == ArtifactReference(name="name")
|
||||
assert ArtifactReference.parse("space:name") == ArtifactReference(
|
||||
name="name",
|
||||
collection_id="space",
|
||||
)
|
||||
assert str(ArtifactReference.parse("space:name@v1")) == "space:name@v1"
|
||||
|
||||
|
||||
def test_collection_and_relationship_roundtrip() -> None:
|
||||
collection = Collection.create("project", domain="markitect")
|
||||
restored_collection = Collection.from_dict(collection.to_dict())
|
||||
assert restored_collection.name == "project"
|
||||
assert restored_collection.domain == "markitect"
|
||||
|
||||
relationship = Relationship.create(
|
||||
"a",
|
||||
"b",
|
||||
"depends on",
|
||||
relationship_type=RelationshipType.DEPENDS_ON,
|
||||
evidence="test evidence",
|
||||
)
|
||||
assert relationship.edge() == ("a", "b", "depends on")
|
||||
restored_relationship = Relationship.from_dict(relationship.to_dict())
|
||||
assert restored_relationship.relationship_type == RelationshipType.DEPENDS_ON
|
||||
assert restored_relationship.evidence == "test evidence"
|
||||
|
||||
|
||||
def test_relationship_graph_detects_cycles_and_orders_dependencies() -> None:
|
||||
edge_ab = Relationship.create("A", "B", "depends on")
|
||||
edge_bc = Relationship.create("B", "C", "depends on")
|
||||
graph = RelationshipGraph.from_relationships([edge_ab, edge_bc])
|
||||
|
||||
assert graph.successors("A") == {"B"}
|
||||
assert graph.predecessors("C") == {"B"}
|
||||
assert graph.detect_cycles() == []
|
||||
assert graph.topological_sort().index("C") < graph.topological_sort().index("A")
|
||||
|
||||
graph.add(Relationship.create("C", "A", "depends on"))
|
||||
assert graph.detect_cycles()
|
||||
|
||||
Reference in New Issue
Block a user