WP-0004: ecosystem integration complete
Add Helix Forge correlation (HELIX_SESSION_UID env, metrics correlate), artifact-store publish (metrics publish), activity-core ActivityDefinition references, integration patterns docs, and canon/knowledge design artifacts.
This commit is contained in:
161
tests/test_helix_correlation.py
Normal file
161
tests/test_helix_correlation.py
Normal file
@@ -0,0 +1,161 @@
|
||||
"""Tests for Helix Forge correlation (WP-0004 Part 1)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
from kaizen_agentic.cli import cli
|
||||
from kaizen_agentic.integrations.helix import (
|
||||
HelixCorrelationAdapter,
|
||||
enrich_helix_correlation,
|
||||
)
|
||||
|
||||
|
||||
def test_enrich_helix_correlation_from_env(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setenv("HELIX_SESSION_UID", "claude:test-uid")
|
||||
monkeypatch.setenv("HELIX_REPO", "kaizen-agentic")
|
||||
monkeypatch.setenv("HELIX_FLAVOR", "claude")
|
||||
monkeypatch.setenv("HELIX_TOKENS", "9900")
|
||||
monkeypatch.setenv("HELIX_INFRA_OVERHEAD_SHARE", "0.15")
|
||||
|
||||
result = enrich_helix_correlation({"success": True})
|
||||
|
||||
assert result["helix_session_uid"] == "claude:test-uid"
|
||||
assert result["repo"] == "kaizen-agentic"
|
||||
assert result["flavor"] == "claude"
|
||||
assert result["tokens"] == 9900
|
||||
assert result["infra_overhead_share"] == 0.15
|
||||
|
||||
|
||||
def test_enrich_does_not_override_existing_fields():
|
||||
record = {
|
||||
"success": True,
|
||||
"helix_session_uid": "grok:existing",
|
||||
"repo": "other-repo",
|
||||
}
|
||||
result = enrich_helix_correlation(record)
|
||||
assert result["helix_session_uid"] == "grok:existing"
|
||||
assert result["repo"] == "other-repo"
|
||||
|
||||
|
||||
def test_adapter_stub_when_store_unconfigured():
|
||||
adapter = HelixCorrelationAdapter(store_db=None)
|
||||
summary = adapter.lookup("claude:missing")
|
||||
assert summary["adapter"] == "stub"
|
||||
assert summary["status"] == "not_configured"
|
||||
|
||||
|
||||
def test_adapter_sqlite_lookup(tmp_path: Path):
|
||||
db_path = tmp_path / "store.db"
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.execute(
|
||||
"CREATE TABLE digests (session_uid TEXT PRIMARY KEY, json TEXT NOT NULL)"
|
||||
)
|
||||
conn.execute(
|
||||
"CREATE TABLE sessions (session_uid TEXT PRIMARY KEY, json TEXT NOT NULL)"
|
||||
)
|
||||
digest = {
|
||||
"outcome": "success",
|
||||
"cost": {"input_tokens": 800, "output_tokens": 200, "wall_clock_s": 3600},
|
||||
"tool_histogram": {"mcp__state-hub__x": 3, "Bash": 7},
|
||||
"markers": {"errors": 0, "retries": 1},
|
||||
}
|
||||
session = {"repo": "demo-app", "flavor": "claude"}
|
||||
conn.execute(
|
||||
"INSERT INTO digests VALUES (?, ?)",
|
||||
("claude:abc", json.dumps(digest)),
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT INTO sessions VALUES (?, ?)",
|
||||
("claude:abc", json.dumps(session)),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
adapter = HelixCorrelationAdapter(store_db=db_path)
|
||||
summary = adapter.lookup("claude:abc")
|
||||
|
||||
assert summary["adapter"] == "helix-sqlite"
|
||||
assert summary["repo"] == "demo-app"
|
||||
assert summary["flavor"] == "claude"
|
||||
assert summary["fleet_outcome"] == "success"
|
||||
assert summary["tokens"] == 1000
|
||||
assert summary["wall_clock_s"] == 3600
|
||||
assert summary["infra_overhead_share"] == 0.3
|
||||
|
||||
|
||||
class TestHelixCorrelationCli:
|
||||
def test_record_populates_helix_uid_from_env(
|
||||
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
):
|
||||
monkeypatch.setenv("HELIX_SESSION_UID", "claude:session-42")
|
||||
monkeypatch.setenv("HELIX_REPO", "kaizen-agentic")
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"metrics",
|
||||
"record",
|
||||
"tdd-workflow",
|
||||
"--target",
|
||||
str(tmp_path),
|
||||
"--success",
|
||||
"--time",
|
||||
"10",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
|
||||
show = runner.invoke(
|
||||
cli,
|
||||
["metrics", "show", "tdd-workflow", "--target", str(tmp_path)],
|
||||
)
|
||||
assert "claude:session-42" in show.output
|
||||
assert "kaizen-agentic" in show.output
|
||||
|
||||
def test_correlate_stub_output(self):
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["metrics", "correlate", "claude:stub-uid"])
|
||||
assert result.exit_code == 0
|
||||
payload = json.loads(result.output)
|
||||
assert payload["helix_session_uid"] == "claude:stub-uid"
|
||||
assert payload["adapter"] == "stub"
|
||||
|
||||
def test_brief_works_with_correlated_metrics(
|
||||
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
):
|
||||
memory_dir = tmp_path / ".kaizen" / "agents" / "tdd-workflow"
|
||||
memory_dir.mkdir(parents=True)
|
||||
(memory_dir / "memory.md").write_text(
|
||||
"---\nagent: tdd-workflow\nproject: demo\nsession_count: 1\n---\n\n## Session Log\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setenv("HELIX_SESSION_UID", "claude:brief-test")
|
||||
|
||||
runner = CliRunner()
|
||||
runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"metrics",
|
||||
"record",
|
||||
"tdd-workflow",
|
||||
"--target",
|
||||
str(tmp_path),
|
||||
"--success",
|
||||
"--quality",
|
||||
"0.9",
|
||||
],
|
||||
)
|
||||
brief = runner.invoke(
|
||||
cli,
|
||||
["memory", "brief", "tdd-workflow", "--target", str(tmp_path)],
|
||||
)
|
||||
assert brief.exit_code == 0
|
||||
assert "## Performance Summary" in brief.output
|
||||
Reference in New Issue
Block a user