Contents

Evaluation contract tests

Canonical contract: sdk-specs 9a5395c.

The tests below cover all 62 published scenarios through the JS public API. Mocked service responses test SDK behavior; they do not establish backend conformance. The transport suite also uses a real localhost HTTP server to check redirect handling. The shared SDK acceptance harness still needs management API bindings; these tests do not claim harness readiness.

python-parity.json was generated by executing Python SDK request/declaration code at revision 2936009887d4b23c9eb4156f77e06734e9513e78, the spec reference revision. Its evaluation implementation matches Python main a5b93eed7125a1ef7a9c9a442ec75487027f1f59. The fixture covers every management method, retry policy, declarations, and an upload. It does not require Python at JS test runtime.

python-composite-parity.json adds composite management, validation, declarations, and uploads from revision a39cdd7a4e5824c2df020481276e2bbc12a9db06 (Python PR). Regenerate it with the same script plus --composites-only, then format it with the AI package's formatter settings.

The composite suites follow sdk-specs#213: pinned metadata and versions, read-scoped validation, calculation declarations, legacy compatibility, stored outcomes, dependency grouping at count/UTF-8 boundaries, overlapping spans, rejection before I/O, and exact failed-group replay. The backend remains responsible for formula execution, permissions, status propagation, and billing; mocked acknowledgments do not establish backend conformance.

The portableDeclarations fixtures retain exact JSON strings that Python restored without changing their values. Tests compare toJSONString() output directly with those strings, including large positive and negative integers in scores and nested item payloads. Parsing both sides into JavaScript numbers before comparison would hide the precision regression.

Regenerate deliberately with the Python checkout environment:

 1/path/to/posthog-python/.venv/bin/python packages/ai/tests/evaluations/generate-python-parity.py /path/to/posthog-python
 2pnpm exec oxfmt --config .oxfmtrc.json --write packages/ai/tests/evaluations/python-parity.json

Run through the repository Turbo graph (builds prerequisites):

 1pnpm turbo run test:unit --filter=@posthog/ai

After prerequisites are built, the focused suite is:

 1pnpm --filter=@posthog/ai exec vitest run tests/evaluations --coverage.enabled=false

Additional JS cases cover immutable snapshots and option mutation during I/O, safe integer/bigint handling, full int64 counters, UTF-16 versus code-point ordering, exact UTF-8 limits, unsupported JSON objects, prototype-shaped keys, sparse arrays, microsecond timestamps, cancellation/backoff, serialized handle operations, and reusable pending chunks. The module-load check verifies ESM/CommonJS consumers with no provider dependencies and type-checks both declaration consumers.

Intentional native adaptations: a single async client, camelCase SDK options, timeoutMs, AbortSignal, async iteration, and bigint for exact large numeric inputs. Persisted item/result declarations retain Python wire keys. Returned timestamp strings normalize to UTC without discarding fractional precision.

Capability Scenario Test file
offline-evaluations Success is an acknowledgment transport.test.ts
offline-evaluations Invalid client options do not send requests transport.test.ts
offline-evaluations An ingestion host maps to the management host transport.test.ts
offline-evaluations Redirects cannot forward the secret transport.test.ts
offline-evaluations Creation can be replayed after an uncertain response transport.test.ts
offline-evaluations Resume does not discover or create a run uploads.test.ts
offline-evaluations Saved declarations survive process reconstruction declarations.test.ts
offline-evaluations Missing and null payload values differ declarations.test.ts
offline-evaluations Invalid payloads fail locally declarations.test.ts
offline-evaluations A false score is still a successful evaluator outcome declarations.test.ts
offline-evaluations A non-ok outcome cannot carry a score declarations.test.ts
offline-evaluations Numeric score precision cannot be silently lost declarations.test.ts
offline-evaluations Multiple scorers share one item declaration uploads.test.ts
offline-evaluations Exact replay is observable without duplication uploads.test.ts
offline-evaluations Missing acknowledgments remain uncertain uploads.test.ts
offline-evaluations Count boundaries preserve independently replayable declarations uploads.test.ts
offline-evaluations UTF-8 request size includes the envelope uploads.test.ts
offline-evaluations Invalid bulk input sends no partial work uploads.test.ts
offline-evaluations The second chunk fails after the first is acknowledged uploads.test.ts
offline-evaluations Count mismatch leaves the experiment open uploads.test.ts
offline-evaluations Failure is explicit and repeatable uploads.test.ts
offline-evaluations Closed experiments permit exact replay but reject new data uploads.test.ts
offline-evaluations Retry preserves the exact upload transport.test.ts
offline-evaluations A long Retry-After is not shortened transport.test.ts
offline-evaluations A rejection after a lost response cannot erase uncertainty transport.test.ts
offline-evaluations Error messages do not expose evaluation content transport.test.ts
offline-evaluations Experiment tags can change after completion uploads.test.ts
offline-evaluations Context exit does not finish an experiment transport.test.ts
offline-evaluations Cancellation propagates without cleanup writes transport.test.ts
offline-evaluations One pinned dataset execution is scored twice management.test.ts
offline-evaluations An item outside the pinned dataset revision is rejected management.test.ts
ai-datasets Metadata changes preserve revision state management.test.ts
ai-datasets Duplicate dataset names surface the server rejection management.test.ts
ai-datasets JSON values retain their types management.test.ts
ai-datasets Incomplete provenance fails before a write management.test.ts
ai-datasets Updating an item preserves its historical version management.test.ts
ai-datasets Identical content does not create history management.test.ts
ai-datasets A concurrent update is not overwritten management.test.ts
ai-datasets Restore copies history into a new version management.test.ts
ai-datasets Restoring a dataset preserves archived items management.test.ts
ai-datasets A keyed item create can recover a lost acknowledgment management.test.ts
ai-datasets An unkeyed item create is not replayed management.test.ts
ai-datasets Pagination preserves the original request scope management.test.ts
ai-datasets Invalid continuation is observable management.test.ts
ai-datasets Dataset changes do not move a snapshot management.test.ts
ai-datasets Historical resolution survives concurrent writes management.test.ts
ai-datasets Empty history differs from an empty revision management.test.ts
ai-datasets A partial read remains a failure management.test.ts
ai-datasets A newer item cannot enter a pinned read management.test.ts
ai-datasets Source data does not become a new execution's output management.test.ts
ai-scorers Same-name scorers remain independent management.test.ts
ai-scorers Failure polarity does not invert an uploaded value management.test.ts
ai-scorers A zero numeric threshold and null bounds survive management management.test.ts
ai-scorers An empty multiple-selection passing set is preserved management.test.ts
ai-scorers Restoring and clearing metadata preserves the version management.test.ts
ai-scorers A new version does not alter an existing result's configuration management.test.ts
ai-scorers Identical configuration can intentionally create a version management.test.ts
ai-scorers A stale version creation remains a conflict management.test.ts
ai-scorers A lost version acknowledgment does not create another version management.test.ts
ai-scorers Scorer listing retains its filters management.test.ts
ai-scorers Version history continues by cursor management.test.ts
ai-scorers A malformed success is not an acknowledgment management.test.ts