Simplify Athena operator architecture
This commit is contained in:
@@ -70,6 +70,32 @@ class OperatorTests(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
self.module.execute({"ticket": proposal["ticket"], "confirmation": proposal["required_confirmation"]})
|
||||
|
||||
def test_direct_change_applies_authorized_work_without_ticket(self):
|
||||
before = self.module.sha((self.repo / "docs" / "test.md").read_bytes())
|
||||
result = self.module.change({
|
||||
"operation": "patch_update",
|
||||
"payload": {"files": [{
|
||||
"path": "docs/test.md", "expected_sha256": before,
|
||||
"patch": "@@ -1 +1 @@\n-before\n+after\n",
|
||||
}]},
|
||||
})
|
||||
self.assertEqual(result["operation"], "patch_update")
|
||||
self.assertEqual((self.repo / "docs" / "test.md").read_text(), "after\n")
|
||||
self.assertEqual((self.stack / "docs" / "test.md").read_text(), "after\n")
|
||||
|
||||
def test_single_worktree_is_written_only_once(self):
|
||||
self.module.STACK = self.repo
|
||||
before = self.module.sha((self.repo / "docs" / "test.md").read_bytes())
|
||||
result = self.module.change({
|
||||
"operation": "patch_update",
|
||||
"payload": {"files": [{
|
||||
"path": "docs/test.md", "expected_sha256": before,
|
||||
"patch": "@@ -1 +1 @@\n-before\n+after\n",
|
||||
}]},
|
||||
})
|
||||
self.assertEqual(result["operation"], "patch_update")
|
||||
self.assertEqual((self.repo / "docs" / "test.md").read_text(), "after\n")
|
||||
|
||||
def test_wrong_confirmation_and_expired_ticket_are_rejected(self):
|
||||
proposal = self.prepare_file()
|
||||
with self.assertRaises(PermissionError):
|
||||
|
||||
@@ -6,13 +6,10 @@ import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def load_module(root: Path, docs: Path, runtime: Path, state: Path):
|
||||
def load_module(root: Path, runtime: Path):
|
||||
os.environ.update({
|
||||
"ATHENA_REPO_ROOT": str(root),
|
||||
"ATHENA_DOCS_ROOT": str(docs),
|
||||
"ATHENA_RUNTIME_FILE": str(runtime),
|
||||
"ATHENA_CONTEXT_STATE": str(state),
|
||||
"ATHENA_DOC_WRITE_MODE": "enabled",
|
||||
})
|
||||
source = Path(__file__).parents[1] / "platform/mcp/platform_context_mcp.py"
|
||||
spec = importlib.util.spec_from_file_location("platform_context_mcp_test", source)
|
||||
@@ -24,47 +21,33 @@ def load_module(root: Path, docs: Path, runtime: Path, state: Path):
|
||||
|
||||
def main():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
base = Path(tmp)
|
||||
repo = base / "repo"
|
||||
docs = base / "docs"
|
||||
state = base / "state"
|
||||
runtime = base / "runtime.json"
|
||||
(repo / "docs").mkdir(parents=True)
|
||||
(repo / "config").mkdir(parents=True)
|
||||
docs.mkdir()
|
||||
(repo / "docs/PLATFORM_OVERVIEW.md").write_text("# Athena\nRouter and recovery.\n")
|
||||
(repo / "docs/OPERATIONS.md").write_text("# Operations\nUse bounded tools.\n")
|
||||
(docs / "PLATFORM_OVERVIEW.md").write_text("# Athena\nRouter and recovery.\n")
|
||||
(repo / "config/service-catalog.json").write_text(json.dumps({
|
||||
"version": 1,
|
||||
"services": [{"id": "test", "name": "Test", "address": "127.0.0.1", "port": 9, "protocol": "tcp", "probe": "tcp"}],
|
||||
root = Path(tmp) / "repo"
|
||||
runtime = Path(tmp) / "runtime.json"
|
||||
(root / "docs").mkdir(parents=True)
|
||||
(root / "config").mkdir(parents=True)
|
||||
(root / "ATHENA.md").write_text("# Athena\nOne short source of truth.\n")
|
||||
(root / "docs/OPERATIONS.md").write_text("# Operations\nRecovery detail.\n")
|
||||
(root / "config/service-catalog.json").write_text(json.dumps({
|
||||
"services": [{"id": "test", "name": "Test", "address": "127.0.0.1", "port": 9, "protocol": "tcp"}],
|
||||
}))
|
||||
runtime.write_text(json.dumps({"generated_unix": 4102444800, "generated_at": "2100-01-01T00:00:00Z", "source_commit": "abc", "containers": []}))
|
||||
m = load_module(repo, docs, runtime, state)
|
||||
runtime.write_text(json.dumps({
|
||||
"generated_at": "2100-01-01T00:00:00Z", "source_commit": "abc",
|
||||
"containers": [{"name": "mike-ai-test", "status": "Up"}],
|
||||
"active_inference_profiles": ["fast"], "gpus": [],
|
||||
}))
|
||||
m = load_module(root, runtime)
|
||||
|
||||
assert len(m.TOOLS) == 10
|
||||
assert m.overview()["source"] == "docs/PLATFORM_OVERVIEW.md"
|
||||
assert m.current_state()["available"] is True
|
||||
assert len(m.TOOLS) == 5
|
||||
assert m.overview()["source"] == "ATHENA.md"
|
||||
assert m.current_state()["active_inference_profiles"] == ["fast"]
|
||||
assert m.external_services()["services"][0]["id"] == "test"
|
||||
assert m.search_knowledge({"query": "recovery", "max_results": 3})["count"] >= 1
|
||||
assert "Operations" in m.read_source({"path": "docs/OPERATIONS.md"})["content"]
|
||||
try:
|
||||
m.safe_repo_path("config/secret.env")
|
||||
raise AssertionError("secret path was accepted")
|
||||
except ValueError:
|
||||
pass
|
||||
assert m.search_reference({"query": "Recovery"})["matches"]
|
||||
assert "Operations" in m.read_reference({"path": "docs/OPERATIONS.md"})["content"]
|
||||
|
||||
proposal = m.prepare_update({
|
||||
"summary": "Update overview test",
|
||||
"evidence": "Verified synthetic test state",
|
||||
"updates": [{"path": "docs/PLATFORM_OVERVIEW.md", "content": "# Athena\nUpdated safely.\n"}],
|
||||
})
|
||||
assert (docs / "PLATFORM_OVERVIEW.md").read_text().endswith("recovery.\n")
|
||||
result = m.apply_update({"proposal_id": proposal["proposal_id"], "confirmation": proposal["required_confirmation"]})
|
||||
assert result["documentation_applied"] is True
|
||||
assert result["git_commit_complete"] is False
|
||||
assert (docs / "PLATFORM_OVERVIEW.md").read_text().endswith("safely.\n")
|
||||
assert m.maintenance_status()["latest_applied_documentation_change"]
|
||||
missing = m.read_reference({"path": "docs/MISSING.md"})
|
||||
assert missing["ok"] is False and missing["retry"] is False
|
||||
blocked = m.read_reference({"path": "config/secret.env"})
|
||||
assert blocked["ok"] is False and blocked["retry"] is False
|
||||
|
||||
for tool in m.TOOLS:
|
||||
for prop in tool["inputSchema"].get("properties", {}).values():
|
||||
|
||||
Reference in New Issue
Block a user