Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

131 lines
4.1 KiB
Python

from __future__ import annotations
import pytest
from platform.analytics.source import (
INVESTIGATION_EVENT_SCHEMA_VERSION,
EntrypointSource,
TriggerMode,
build_source_properties,
is_test_run,
resolve_environment_tag,
)
def test_is_test_run_true_for_explicit_source_override(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("OPENSRE_INVESTIGATION_SOURCE", "test")
monkeypatch.delenv("OPENSRE_IS_TEST", raising=False)
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.delenv("CI", raising=False)
assert is_test_run() is True
def test_is_test_run_true_for_explicit_boolean_flag(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("OPENSRE_INVESTIGATION_SOURCE", raising=False)
monkeypatch.setenv("OPENSRE_IS_TEST", "1")
assert is_test_run() is True
@pytest.mark.parametrize(
("env_name", "env_value"),
[
("PYTEST_CURRENT_TEST", "tests/suite.py::test_case"),
("GITHUB_ACTIONS", "true"),
("CI", "true"),
],
)
def test_is_test_run_true_for_auto_detected_env(
monkeypatch: pytest.MonkeyPatch,
env_name: str,
env_value: str,
) -> None:
monkeypatch.delenv("OPENSRE_INVESTIGATION_SOURCE", raising=False)
monkeypatch.delenv("OPENSRE_IS_TEST", raising=False)
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.delenv("CI", raising=False)
monkeypatch.setenv(env_name, env_value)
assert is_test_run() is True
def test_is_test_run_false_without_signals(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("OPENSRE_INVESTIGATION_SOURCE", raising=False)
monkeypatch.delenv("OPENSRE_IS_TEST", raising=False)
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.delenv("CI", raising=False)
assert is_test_run() is False
@pytest.mark.parametrize(
("env_value", "expected"),
[
("production", "prod"),
("prod", "prod"),
("staging", "staging"),
("stage", "staging"),
("development", "dev"),
("dev", "dev"),
("local", "dev"),
("preview", "unknown"),
],
)
def test_resolve_environment_tag_maps_known_values(
monkeypatch: pytest.MonkeyPatch,
env_value: str,
expected: str,
) -> None:
monkeypatch.delenv("OPENSRE_ANALYTICS_ENV", raising=False)
monkeypatch.setenv("ENV", env_value)
assert resolve_environment_tag() == expected
def test_build_source_properties_for_api_source(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("OPENSRE_INVESTIGATION_SOURCE", raising=False)
monkeypatch.delenv("OPENSRE_IS_TEST", raising=False)
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.delenv("CI", raising=False)
monkeypatch.setenv("ENV", "production")
properties = build_source_properties(
entrypoint=EntrypointSource.SDK,
trigger_mode=TriggerMode.SERVICE_RUNTIME,
investigation_id="inv-123",
)
assert properties == {
"source": "sdk",
"entrypoint_source": "sdk",
"category": "api",
"trigger_mode": "service_runtime",
"is_test": False,
"environment": "prod",
"investigation_id": "inv-123",
"investigation_event_schema_version": INVESTIGATION_EVENT_SCHEMA_VERSION,
}
def test_build_source_properties_for_test_override(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("OPENSRE_INVESTIGATION_SOURCE", "test")
monkeypatch.setenv("ENV", "development")
properties = build_source_properties(
entrypoint=EntrypointSource.CLI_PASTE,
trigger_mode=TriggerMode.PASTE,
investigation_id="inv-abc",
)
assert properties["source"] == "test"
assert properties["entrypoint_source"] == "cli_paste"
assert properties["category"] == "test"
assert properties["is_test"] is True
assert properties["trigger_mode"] == "paste"
assert properties["environment"] == "dev"