4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
"""Tests for canonical investigation loop analytics metrics."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from config.constants.investigation import MAX_INVESTIGATION_LOOPS
|
|
from platform.analytics.investigation_loop import (
|
|
begin_investigation_loop_metrics_scope,
|
|
bind_investigation_loop_metrics_from_state,
|
|
bound_loop_metrics,
|
|
investigation_iteration_cap_from_state,
|
|
investigation_loop_count_from_state,
|
|
loop_metrics_from_state,
|
|
loop_properties,
|
|
merge_loop_properties,
|
|
publish_loop_metrics_from_stream_failure,
|
|
reset_investigation_loop_metrics,
|
|
)
|
|
|
|
|
|
def test_loop_properties_from_state() -> None:
|
|
count, cap = loop_metrics_from_state(
|
|
{
|
|
"investigation_loop_count": 7,
|
|
"investigation_iteration_cap": 20,
|
|
}
|
|
)
|
|
assert count == 7
|
|
assert cap == 20
|
|
assert loop_properties(loop_count=count, iteration_cap=cap) == {
|
|
"investigation_loop_count": 7,
|
|
"investigation_iteration_cap": 20,
|
|
}
|
|
|
|
|
|
def test_loop_count_defaults_to_zero_without_state() -> None:
|
|
assert investigation_loop_count_from_state(None) == 0
|
|
assert investigation_iteration_cap_from_state(None) == MAX_INVESTIGATION_LOOPS
|
|
|
|
|
|
def test_merge_loop_properties_preserves_existing_fields() -> None:
|
|
merged = merge_loop_properties(
|
|
{"investigation_id": "inv-1", "status": "completed"},
|
|
loop_count=3,
|
|
iteration_cap=20,
|
|
)
|
|
assert merged["investigation_id"] == "inv-1"
|
|
assert merged["investigation_loop_count"] == 3
|
|
assert merged["investigation_iteration_cap"] == 20
|
|
|
|
|
|
def test_reset_investigation_loop_metrics_restores_prior_binding() -> None:
|
|
outer_token = begin_investigation_loop_metrics_scope()
|
|
bind_investigation_loop_metrics_from_state(
|
|
{"investigation_loop_count": 4, "investigation_iteration_cap": 20}
|
|
)
|
|
assert bound_loop_metrics() == (4, 20)
|
|
reset_investigation_loop_metrics(outer_token)
|
|
assert bound_loop_metrics() is None
|
|
|
|
|
|
def test_publish_loop_metrics_from_stream_failure_binds_on_caller_thread() -> None:
|
|
from tools.investigation.streaming import InvestigationPipelineStreamError
|
|
|
|
outer_token = begin_investigation_loop_metrics_scope()
|
|
wrapped = InvestigationPipelineStreamError(
|
|
cause=RuntimeError("boom"),
|
|
loop_count=3,
|
|
iteration_cap=20,
|
|
)
|
|
unwrapped = publish_loop_metrics_from_stream_failure(wrapped)
|
|
try:
|
|
assert isinstance(unwrapped, RuntimeError)
|
|
assert bound_loop_metrics() == (3, 20)
|
|
finally:
|
|
reset_investigation_loop_metrics(outer_token)
|