From 4d5dcb2b4e9dd177b77aac424e09d22f1393466d Mon Sep 17 00:00:00 2001 From: Srinivasa Consultants <78673153+dinakarjs@users.noreply.github.com> Date: Mon, 26 Oct 2026 14:00:28 +0530 Subject: [PATCH] test: add shared Python and TypeScript projection boundary corpus Signed-off-by: Srinivasa Dinakar Jainti --- conformance/parity/README.md | 5 + conformance/parity/projection-boundaries.json | 123 ++++++++++++++++++ .../typescript/test/projection-parity.test.ts | 30 +++++ tests/test_projection_parity_corpus.py | 35 +++++ 4 files changed, 193 insertions(+) create mode 100644 conformance/parity/README.md create mode 100644 conformance/parity/projection-boundaries.json create mode 100644 packages/typescript/test/projection-parity.test.ts create mode 100644 tests/test_projection_parity_corpus.py diff --git a/conformance/parity/README.md b/conformance/parity/README.md new file mode 100644 index 0000000..62e26fe --- /dev/null +++ b/conformance/parity/README.md @@ -0,0 +1,5 @@ +# Projection boundary corpus + +Both SDK test suites consume projection-boundaries.json. This slice covers six canonical timestamps, thirteen noncanonical spellings, and five scalar projection cases. Nonfinite values use local special-value tags because they have no JSON representation. These projection inputs are not assertions that arbitrary event fields pass the event schema. + +This companion is based on telemetry #119. Other adapter timestamp/duration and EventFactory corrections remain in #116–120; it neither replaces those fixes nor claims their acceptance. The 20-digit tuple is an explicit positive boundary; logs, delivery, collector behavior and hardware are separate. diff --git a/conformance/parity/projection-boundaries.json b/conformance/parity/projection-boundaries.json new file mode 100644 index 0000000..37f09c6 --- /dev/null +++ b/conformance/parity/projection-boundaries.json @@ -0,0 +1,123 @@ +{ + "timestamps": [ + { + "input": "0", + "tuple": [ + 0, + 0 + ] + }, + { + "input": "1", + "tuple": [ + 0, + 1 + ] + }, + { + "input": "999999999", + "tuple": [ + 0, + 999999999 + ] + }, + { + "input": "1000000000", + "tuple": [ + 1, + 0 + ] + }, + { + "input": "1000000001", + "tuple": [ + 1, + 1 + ] + }, + { + "input": "99999999999999999999", + "tuple": [ + 99999999999, + 999999999 + ] + } + ], + "invalid_timestamps": [ + "", + " ", + "-1", + "+1", + "01", + "0x10", + "1.0", + "1e9", + "1\n", + "1\r", + "1
", + "١", + "111111111111111111111" + ], + "projections": [ + { + "id": "finite-scalars", + "event": { + "run_id": "run-1", + "task_id": 0, + "decision": false + }, + "expected": { + "agentrust.run.id": "run-1", + "agentrust.task.id": 0, + "agentrust.policy.decision": false + } + }, + { + "id": "structured-and-null-omit", + "event": { + "run_id": "run-1", + "task_id": null, + "workflow_id": [], + "agent_id": {} + }, + "expected": { + "agentrust.run.id": "run-1" + } + }, + { + "id": "unmapped-payload-omit", + "event": { + "run_id": "run-1", + "payload": "synthetic" + }, + "expected": { + "agentrust.run.id": "run-1" + } + }, + { + "id": "nonfinite-omit", + "event": { + "run_id": "run-1" + }, + "special": { + "task_id": "nan", + "workflow_id": "positive_infinity", + "agent_id": "negative_infinity" + }, + "expected": { + "agentrust.run.id": "run-1" + } + }, + { + "id": "fractional-scalar", + "event": { + "run_id": "run-1", + "task_id": 1.5 + }, + "expected": { + "agentrust.run.id": "run-1", + "agentrust.task.id": 1.5 + } + } + ] +} diff --git a/packages/typescript/test/projection-parity.test.ts b/packages/typescript/test/projection-parity.test.ts new file mode 100644 index 0000000..78238ee --- /dev/null +++ b/packages/typescript/test/projection-parity.test.ts @@ -0,0 +1,30 @@ +import assert from "node:assert/strict"; +import {readFileSync} from "node:fs"; +import test from "node:test"; +import {hrTime, spanAttributes} from "../src/projection.js"; +import type {NormalizedEvent} from "../src/types.js"; + +const corpus = JSON.parse(readFileSync( + new URL("../../../conformance/parity/projection-boundaries.json", import.meta.url), "utf8", +)); +for (const row of corpus.timestamps) { + test("shared timestamp " + row.input, () => assert.deepEqual(hrTime(row.input), row.tuple)); +} +for (const value of corpus.invalid_timestamps) { + test("shared noncanonical timestamp " + JSON.stringify(value), () => { + assert.throws(() => hrTime(value)); + }); +} +const special: Record = { + nan: Number.NaN, positive_infinity: Number.POSITIVE_INFINITY, + negative_infinity: Number.NEGATIVE_INFINITY, +}; +for (const row of corpus.projections) { + test("shared scalar projection " + row.id, () => { + const event = {...row.event}; + for (const [key, value] of Object.entries(row.special ?? {})) { + event[key] = special[value as string]; + } + assert.deepEqual(spanAttributes(event as NormalizedEvent), row.expected); + }); +} diff --git a/tests/test_projection_parity_corpus.py b/tests/test_projection_parity_corpus.py new file mode 100644 index 0000000..430c972 --- /dev/null +++ b/tests/test_projection_parity_corpus.py @@ -0,0 +1,35 @@ +"""Shared Python/TypeScript normalization and projection cases, not schema acceptance.""" +import json +import math +import unittest +from pathlib import Path + +from agentrust_telemetry.adapters.base import _unix_nano +from agentrust_telemetry.projection import span_attributes + +CORPUS = json.loads( + (Path(__file__).resolve().parents[1] / "conformance/parity/projection-boundaries.json") + .read_text(encoding="utf-8") +) + + +class TestProjectionParityCorpus(unittest.TestCase): + def test_timestamp_normalization(self): + for case in CORPUS["timestamps"]: + with self.subTest(value=case["input"]): + normalized = _unix_nano(case["input"]) + self.assertEqual(normalized, case["input"]) + self.assertEqual(list(divmod(int(normalized), 1_000_000_000)), case["tuple"]) + + def test_noncanonical_timestamps(self): + for value in CORPUS["invalid_timestamps"]: + with self.subTest(value=value), self.assertRaises((ValueError, TypeError)): + _unix_nano(value) + + def test_scalar_projection(self): + special = {"nan": math.nan, "positive_infinity": math.inf, "negative_infinity": -math.inf} + for case in CORPUS["projections"]: + with self.subTest(case=case["id"]): + event = dict(case["event"]) + event.update({key: special[value] for key, value in case.get("special", {}).items()}) + self.assertEqual(span_attributes(event), case["expected"])