Files
Pulse/scripts/tests/test_telemetry_schema_parity.py
rcourtman c5b6d05107 feat(telemetry): add schema v26 map topology API/CLI/MCP telemetry
I added Schema v26 content-free Infrastructure Map topology read telemetry for external live GET /api/agent/topology requests (total read days, CLI days, MCP days, anonymized days, and an explicit availability flag) alongside hardened opt-out zero-write boundaries, credential-binding checks, and read-only SQLite/config guards.

Key changes:
- Added a dedicated root-scoped daily tally store (infrastructure_map_topology_tally.json) with strict schema validation, fail-closed degraded sidecar accounting, and strict zero-write guarantees when telemetry is disabled by settings or PULSE_TELEMETRY=false.
- Added X-Pulse-Agent-Surface attribution for pulse-cli and MCP clients while filtering out first-party browser traffic, mock-mode snapshots, and unverified monitor states.
- Updated Settings payload preview, localization copy, shipped PRIVACY.md disclosure, integration specs, and schema parity tooling for Schema v26.
- Hardened host/agent token hash binding, self-uninstall live authority and durable hash-scoped tombstones, Patrol investigation replay-floor provenance, bounded non-blocking regular-file config reads, and cold read-only legacy SQLite history queries.
2026-12-02 01:41:25 +00:00

83 lines
2.7 KiB
Python

import importlib.util
from pathlib import Path
import unittest
SCRIPT_PATH = Path(__file__).resolve().parents[1] / "check_telemetry_schema_parity.py"
SPEC = importlib.util.spec_from_file_location("check_telemetry_schema_parity", SCRIPT_PATH)
MODULE = importlib.util.module_from_spec(SPEC)
assert SPEC.loader is not None
SPEC.loader.exec_module(MODULE)
class TelemetrySchemaParityTest(unittest.TestCase):
def test_repository_preview_matches_public_payload(self):
# Fixture-only parser tests cannot catch drift in the shipped interface.
# Check every sender field and type without needing the private repo.
root = SCRIPT_PATH.parents[1]
public = MODULE.json_fields(
(root / "internal/telemetry/telemetry.go").read_text(), "type Ping struct"
)
frontend = MODULE.typescript_fields(
(root / "frontend-modern/src/api/settings.ts").read_text(),
"export interface TelemetryPingPreview",
)
self.assertEqual(public, frontend)
def test_matching_contract(self):
public = '''
type Ping struct {
SchemaVersion int `json:"schema_version"`
Active bool `json:"active"`
}
'''
receiver = '''
type telemetryPingBody struct {
SchemaVersion int `json:"schema_version"`
Active bool `json:"active"`
LicenseTier string `json:"license_tier"`
APITokens int `json:"api_tokens"`
}
'''
frontend = '''
export interface TelemetryPingPreview {
schema_version: number;
active: boolean;
}
'''
self.assertEqual(MODULE.parity_errors(public, receiver, frontend), [])
def test_missing_and_mismatched_fields_fail(self):
public = '''
type Ping struct {
SchemaVersion int `json:"schema_version"`
Active bool `json:"active"`
Count int `json:"count"`
}
'''
receiver = '''
var ping struct {
SchemaVersion string `json:"schema_version"`
Active int `json:"active"`
Extra bool `json:"extra"`
}
'''
frontend = '''
export interface TelemetryPingPreview {
schema_version: string;
active: boolean;
unexpected: number;
}
'''
errors = MODULE.parity_errors(public, receiver, frontend)
self.assertTrue(any("count" in error for error in errors))
self.assertTrue(any("extra" in error for error in errors))
self.assertTrue(any("schema_version" in error and "active" in error for error in errors))
self.assertTrue(any("frontend preview missing" in error and "count" in error for error in errors))
self.assertTrue(any("frontend preview fields absent" in error and "unexpected" in error for error in errors))
self.assertTrue(any("frontend field type mismatches" in error and "schema_version" in error for error in errors))
if __name__ == "__main__":
unittest.main()