from pathlib import Path import yaml from infospace_bench import load_infospace from markitect_tool.memory.graph import ( compile_memory_graph_selection_to_context_package, load_memory_graph_file, load_memory_graph_selection_file, load_memory_profile_file, validate_memory_graph, validate_memory_profile, ) ROOT = Path("infospaces/agentic-memory-profile-pilot") def test_agentic_memory_profile_pilot_is_loadable() -> None: infospace = load_infospace(ROOT) artifact_ids = {artifact.id for artifact in infospace.artifacts} assert infospace.config.slug == "agentic-memory-profile-pilot" assert "source/memory-pilot-brief.md" in artifact_ids assert "generated/memory-profile.yaml" in artifact_ids assert "generated/memory-graph.yaml" in artifact_ids assert "generated/restart-context-selection.yaml" in artifact_ids assert "generated/context-package-evaluation.yaml" in artifact_ids def test_memory_profile_and_graph_validate_with_markitect_contracts() -> None: profile = load_memory_profile_file(ROOT / "output" / "memory" / "memory-profile.yaml") graph = load_memory_graph_file(ROOT / "output" / "memory" / "memory-graph.yaml") profile_result = validate_memory_profile(profile) graph_result = validate_memory_graph(graph) assert profile_result.valid, [item.to_dict() for item in profile_result.diagnostics] assert graph_result.valid, [item.to_dict() for item in graph_result.diagnostics] assert profile_result.metadata["memory_kinds"] == [ "reasoning", "conversation", "knowledge", "package", ] assert graph_result.metadata == {"nodes": 15, "edges": 14, "events": 4} def test_restart_context_selection_compiles_to_expected_package_shape() -> None: profile = load_memory_profile_file(ROOT / "output" / "memory" / "memory-profile.yaml") graph = load_memory_graph_file(ROOT / "output" / "memory" / "memory-graph.yaml") selection = load_memory_graph_selection_file( ROOT / "output" / "memory" / "restart-context-selection.yaml" ) expected = yaml.safe_load( (ROOT / "output" / "memory" / "restart-context-package.expected.yaml").read_text( encoding="utf-8" ) ) package = compile_memory_graph_selection_to_context_package( graph, selection, profile, ) memory_graph = package.metadata["memory_graph"] assert package.id == expected["package_id"] assert package.title == expected["title"] assert len(package.items) == expected["expected_item_count"] assert package.budget.to_dict() == expected["budget"] assert package.token_estimate <= expected["acceptance"]["max_token_estimate"] assert memory_graph["selected_nodes"] == expected["expected_selected_nodes"] assert memory_graph["selected_edges"] == expected["expected_selected_edges"] assert memory_graph["selected_events"] == expected["expected_selected_events"] assert all(item.source.path for item in package.items) def test_agentic_memory_pilot_docs_route_lower_layer_feedback() -> None: text = Path("docs/agentic-memory-profile-pilot.md").read_text(encoding="utf-8") evaluation = yaml.safe_load( (ROOT / "output" / "memory" / "context-package-evaluation.yaml").read_text( encoding="utf-8" ) ) assert "markitect.memory.profile.v1" in text assert "kontextual-engine" in text assert "Do not store credentials" in text assert evaluation["recommended_contract_changes"]["markitect-tool"] assert evaluation["recommended_contract_changes"]["kontextual-engine"] assert evaluation["metrics"]["live_llm_required"] is False