Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.
JavaScript agent-skillsai-agentsbrowser-agentbrowser-automationdecision-modeldeep-researchinstagramjevlinkedinlocal-firstopen-sourceosintresearch-agentsocaisocial-listeningsocial-mediasocial-media-researchsocmintsystem-onetiktok
feat: add privacy-safe benchmark row schema (#46)
Asklv5151170465c4
diff --git a/benchmark/README.md b/benchmark/README.mdnew file mode 100644index 0000000..da445bc--- /dev/null+++ b/benchmark/README.md@@ -0,0 +1,31 @@+# Benchmark row contract++`schema.js` validates one privacy-safe row for the reproducible live benchmark proposed in [#32](https://github.com/socai-io/jev-social/issues/32). It does not run a browser, call Jev, or collect live measurements.++```js+import { validateBenchmarkRow } from "jev-social/benchmark/schema";++const row = validateBenchmarkRow(JSON.parse(input));+```++The contract records pinned runtime metadata, per-step Jev latency, aggregate browser and media time, evidence counts, and an explicit outcome. Run and task IDs must be generated UUIDv4 values. Model values are identifiers such as `typesafe/jev-1.13-20260917`, not paths or URLs. The validator rejects unknown fields, inconsistent totals, and credential-, account-, browser-, path-, or content-bearing field names at any depth.++Measure `started_at` and `ended_at` with the wall clock. Measure every `timing_ms` field with a monotonic clock; `total` is end-to-end latency, and media time may overlap browser time. Jev decisions and browser operations are sequential, so their combined time must fit `total` within the one-second clock tolerance. `jev_total` must equal the sum of `jev_step_latency_ms`, with one entry per attempted decision. The array may be empty for a preflight failure and may contain up to `max_steps + 1` entries: one routing decision plus the bounded action decisions.++Successful rows require at least one evidence record. Download counts and bytes must be zero together or positive together, and downloaded media is valid only for TikTok rows.++Use these stable terminal mappings:++| Stop reason | Failure category |+| --- | --- |+| `login_required`, `challenge_required`, `rate_limited` | `access_gate` |+| `capability_unavailable`, `browser_unavailable`, `media_unavailable` | `unavailable` |+| `decision_failed`, `cli_failed`, `network_error`, `report_failed` | `execution_error` |+| `step_limit` | `step_limit` |+| `empty_results` | `empty_results` |+| `interrupted` | `interrupted` |+| `unknown` | `unknown` |++Successful rows use `goal_satisfied` with a null failure category.++Use `fixtures/valid-row.json` only as synthetic test data. Live collection, aggregation, the coverage rubric, and publication of benchmark results remain tracked in #32.diff --git a/benchmark/fixtures/valid-row.json b/benchmark/fixtures/valid-row.jsonnew file mode 100644index 0000000..76db3d6--- /dev/null+++ b/benchmark/fixtures/valid-row.json@@ -0,0 +1,32 @@+{+ "schema_version": 1,+ "run_id": "00000000-0000-4000-8000-000000000001",+ "task_id": "00000000-0000-4000-8000-000000000002",+ "started_at": "2026-09-25T00:00:00.000Z",+ "ended_at": "2026-09-25T00:00:12.000Z",+ "platform": "instagram",+ "outcome": "success",+ "jev_model": "typesafe/jev-1.13-20260917",+ "socai_version": "0.6.0",+ "socai_commit": "0123456789abcdef0123456789abcdef01234567",+ "result_limit": 4,+ "max_steps": 12,+ "profile_mode": "existing",+ "region": "synthetic-us",+ "condition": "warm",+ "jev_step_latency_ms": [350, 450],+ "timing_ms": {+ "jev_total": 800,+ "socai_browser": 9000,+ "media": 1200,+ "total": 12000+ },+ "evidence": {+ "records": 4,+ "comments": 12,+ "downloaded_media_count": 0,+ "downloaded_media_bytes": 0+ },+ "stop_reason": "goal_satisfied",+ "failure_category": null+}diff --git a/benchmark/schema.js b/benchmark/schema.jsnew file mode 100644index 0000000..250aec8--- /dev/null+++ b/benchmark/schema.js@@ -0,0 +1,339 @@+const TOP_LEVEL_FIELDS = new Set([+ "schema_version",+ "run_id",+ "task_id",+ "started_at",+ "ended_at",+ "platform",+ "outcome",+ "jev_model",+ "socai_version",+ "socai_commit",+ "result_limit",+ "max_steps",+ "profile_mode",+ "region",+ "condition",+ "jev_step_latency_ms",+ "timing_ms",+ "evidence",+ "stop_reason",+ "failure_category",+]);++const TIMING_FIELDS = new Set(["jev_total", "socai_browser", "media", "total"]);+const EVIDENCE_FIELDS = new Set([+ "records",+ "comments",+ "downloaded_media_count",+ "downloaded_media_bytes",+]);++const DENYLISTED_FIELDS = new Set([+ "cookie",+ "authorization",+ "api_key",+ "token",+ "websocket_url",+ "cdp_endpoint",+ "account_id",+ "username",+ "local_path",+ "post_text",+]);++export const BENCHMARK_PLATFORMS = Object.freeze(["instagram", "tiktok", "linkedin"]);+export const BENCHMARK_OUTCOMES = Object.freeze(["success", "partial", "failed"]);+export const BENCHMARK_PROFILE_MODES = Object.freeze(["existing", "isolated"]);+export const BENCHMARK_CONDITIONS = Object.freeze(["cold", "warm"]);+export const BENCHMARK_STOP_REASONS = Object.freeze([+ "goal_satisfied",+ "step_limit",+ "login_required",+ "challenge_required",+ "rate_limited",+ "empty_results",+ "capability_unavailable",+ "browser_unavailable",+ "media_unavailable",+ "decision_failed",+ "cli_failed",+ "network_error",+ "report_failed",+ "interrupted",+ "unknown",+]);+export const BENCHMARK_FAILURE_CATEGORIES = Object.freeze([+ "access_gate",+ "unavailable",+ "execution_error",+ "interrupted",+ "step_limit",+ "empty_results",+ "unknown",+]);++const FAILURE_CATEGORY_BY_STOP_REASON = Object.freeze({+ step_limit: "step_limit",+ login_required: "access_gate",+ challenge_required: "access_gate",+ rate_limited: "access_gate",+ empty_results: "empty_results",+ capability_unavailable: "unavailable",+ browser_unavailable: "unavailable",+ media_unavailable: "unavailable",+ decision_failed: "execution_error",+ cli_failed: "execution_error",+ network_error: "execution_error",+ report_failed: "execution_error",+ interrupted: "interrupted",+ unknown: "unknown",+});++export class BenchmarkRowValidationError extends TypeError {+ constructor(path, message) {+ super(`${path}: ${message}`);+ this.name = "BenchmarkRowValidationError";+ this.path = path;+ }+}++const fail = (path, message) => {+ throw new BenchmarkRowValidationError(path, message);+};++const isRecord = (value) =>+ value !== null &&+ typeof value === "object" &&+ !Array.isArray(value) &&+ (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);++const rejectDenylistedFields = (value, path = "row") => {+ if (Array.isArray(value)) {+ value.forEach((item, index) => rejectDenylistedFields(item, `${path}[${index}]`));+ return;+ }+ if (!isRecord(value)) return;++ for (const [key, nested] of Object.entries(value)) {+ const nestedPath = `${path}.${key}`;+ if (DENYLISTED_FIELDS.has(key.toLowerCase())) fail(nestedPath, "field is not publishable");+ rejectDenylistedFields(nested, nestedPath);+ }+};++const strictRecord = (value, allowed, path) => {+ if (!isRecord(value)) fail(path, "must be an object");+ for (const key of Object.keys(value)) {+ if (!allowed.has(key)) fail(path === "row" ? key : `${path}.${key}`, "unknown field");+ }+ for (const key of allowed) {+ if (!Object.hasOwn(value, key)) {+ fail(path === "row" ? key : `${path}.${key}`, "field is required");+ }+ }+};++const cleanString = (value, path, { max = 200, pattern } = {}) => {+ if (typeof value !== "string") fail(path, "must be a string");+ const cleaned = value.trim();+ if (!cleaned) fail(path, "must not be empty");+ if (cleaned.length > max) fail(path, `must be at most ${max} characters`);+ if (/[\u0000-\u001f\u007f]/.test(cleaned)) fail(path, "must not contain control characters");+ if (pattern && !pattern.test(cleaned)) fail(path, "has an invalid format");+ return cleaned;+};++const enumValue = (value, choices, path) => {+ if (!choices.includes(value)) fail(path, `must be one of: ${choices.join(", ")}`);+ return value;+};++const integer = (value, path, { min = 0, max = Number.MAX_SAFE_INTEGER } = {}) => {+ if (!Number.isSafeInteger(value) || value < min || value > max) {+ fail(path, `must be an integer from ${min} to ${max}`);+ }+ return value;+};++const timestamp = (value, path) => {+ const cleaned = cleanString(value, path, { max: 30 });+ if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/.test(cleaned)) {+ fail(path, "must be an ISO 8601 UTC timestamp");+ }+ const date = new Date(cleaned);+ if (!Number.isFinite(date.getTime())) fail(path, "must be a valid timestamp");+ const canonical = cleaned.includes(".") ? cleaned : cleaned.replace(/Z$/, ".000Z");+ if (date.toISOString() !== canonical) fail(path, "must be a real calendar timestamp");+ return date.toISOString();+};++const opaqueId = (value, path) => {+ const cleaned = cleanString(value, path, {+ max: 36,+ pattern: /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,+ });+ return cleaned.toLowerCase();+};++const normalizeTiming = (value) => {+ strictRecord(value, TIMING_FIELDS, "timing_ms");+ return {+ jev_total: integer(value.jev_total, "timing_ms.jev_total"),+ socai_browser: integer(value.socai_browser, "timing_ms.socai_browser"),+ media: integer(value.media, "timing_ms.media"),+ total: integer(value.total, "timing_ms.total"),+ };+};++const normalizeEvidence = (value) => {+ strictRecord(value, EVIDENCE_FIELDS, "evidence");+ return {+ records: integer(value.records, "evidence.records"),+ comments: integer(value.comments, "evidence.comments"),+ downloaded_media_count: integer(+ value.downloaded_media_count,+ "evidence.downloaded_media_count",+ ),+ downloaded_media_bytes: integer(+ value.downloaded_media_bytes,+ "evidence.downloaded_media_bytes",+ ),+ };+};++export const validateBenchmarkRow = (value) => {+ rejectDenylistedFields(value);+ strictRecord(value, TOP_LEVEL_FIELDS, "row");++ const startedAt = timestamp(value.started_at, "started_at");+ const endedAt = timestamp(value.ended_at, "ended_at");+ const startedMs = Date.parse(startedAt);+ const endedMs = Date.parse(endedAt);+ if (endedMs < startedMs) fail("ended_at", "must not be earlier than started_at");++ if (!Array.isArray(value.jev_step_latency_ms)) {+ fail("jev_step_latency_ms", "must be an array");+ }+ const maxSteps = integer(value.max_steps, "max_steps", { min: 1, max: 30 });+ const jevStepLatency = value.jev_step_latency_ms.map((duration, index) =>+ integer(duration, `jev_step_latency_ms[${index}]`),+ );+ if (jevStepLatency.length > maxSteps + 1) {+ fail("jev_step_latency_ms", "must not contain more entries than route plus max_steps");+ }+ const timing = normalizeTiming(value.timing_ms);+ const evidence = normalizeEvidence(value.evidence);+ const platform = enumValue(value.platform, BENCHMARK_PLATFORMS, "platform");++ const measuredJevTotal = jevStepLatency.reduce((total, duration) => total + duration, 0);+ if (measuredJevTotal !== timing.jev_total) {+ fail("timing_ms.jev_total", "must equal the sum of jev_step_latency_ms");+ }+ for (const component of ["jev_total", "socai_browser", "media"]) {+ if (timing[component] > timing.total) {+ fail(`timing_ms.${component}`, "must not exceed timing_ms.total");+ }+ }+ if (timing.jev_total + timing.socai_browser > timing.total + 1_000) {+ fail("timing_ms.total", "must cover sequential Jev and browser time within 1000 ms");+ }+ if (Math.abs(endedMs - startedMs - timing.total) > 1_000) {+ fail("timing_ms.total", "must be within 1000 ms of the wall-clock duration");+ }++ const hasDownloadedMedia = evidence.downloaded_media_count > 0;+ const hasDownloadedMediaBytes = evidence.downloaded_media_bytes > 0;+ if (hasDownloadedMedia !== hasDownloadedMediaBytes) {+ fail(+ "evidence.downloaded_media_bytes",+ "downloaded media count and byte total must both be zero or both be positive",+ );+ }+ if (hasDownloadedMedia && platform !== "tiktok") {+ fail("evidence.downloaded_media_count", "downloaded media is supported only for TikTok");+ }+ if (evidence.downloaded_media_count > evidence.records) {+ fail("evidence.downloaded_media_count", "must not exceed evidence.records");+ }++ const outcome = enumValue(value.outcome, BENCHMARK_OUTCOMES, "outcome");+ const stopReason = enumValue(value.stop_reason, BENCHMARK_STOP_REASONS, "stop_reason");+ let failureCategory = null;+ if (value.failure_category !== null) {+ failureCategory = enumValue(+ value.failure_category,+ BENCHMARK_FAILURE_CATEGORIES,+ "failure_category",+ );+ }+ if (outcome === "success" && (failureCategory !== null || stopReason !== "goal_satisfied")) {+ fail("failure_category", "successful rows must end with goal_satisfied and no failure");+ }+ if (outcome === "success" && evidence.records === 0) {+ fail("evidence.records", "successful rows require captured evidence");+ }+ if (outcome === "success" && jevStepLatency.length === 0) {+ fail("jev_step_latency_ms", "successful rows require at least one Jev decision");+ }+ if (outcome !== "success" && failureCategory === null) {+ fail("failure_category", "partial and failed rows require a failure category");+ }+ if (outcome !== "success" && stopReason === "goal_satisfied") {+ fail("stop_reason", "partial and failed rows cannot report goal_satisfied");+ }+ if (+ outcome !== "success" &&+ failureCategory !== FAILURE_CATEGORY_BY_STOP_REASON[stopReason]+ ) {+ fail("failure_category", `must be ${FAILURE_CATEGORY_BY_STOP_REASON[stopReason]} for ${stopReason}`);+ }+ if (+ stopReason === "empty_results" &&+ (evidence.records !== 0 ||+ evidence.comments !== 0 ||+ evidence.downloaded_media_count !== 0 ||+ evidence.downloaded_media_bytes !== 0)+ ) {+ fail("evidence", "empty_results rows cannot contain captured evidence");+ }++ const socaiVersion = cleanString(value.socai_version, "socai_version", {+ max: 64,+ pattern: /^v?\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/,+ }).replace(/^v/, "");+ const socaiCommit = cleanString(value.socai_commit, "socai_commit", {+ max: 40,+ pattern: /^[a-f0-9]{7,40}$/i,+ }).toLowerCase();++ return {+ schema_version: integer(value.schema_version, "schema_version", { min: 1, max: 1 }),+ run_id: opaqueId(value.run_id, "run_id"),+ task_id: opaqueId(value.task_id, "task_id"),+ started_at: startedAt,+ ended_at: endedAt,+ platform,+ outcome,+ jev_model: cleanString(value.jev_model, "jev_model", {+ max: 128,+ pattern:+ /^~?[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*){0,3}(?::[A-Za-z0-9][A-Za-z0-9._-]*)?$/,+ }),+ socai_version: socaiVersion,+ socai_commit: socaiCommit,+ result_limit: integer(value.result_limit, "result_limit", { min: 1, max: 100 }),+ max_steps: maxSteps,+ profile_mode: enumValue(value.profile_mode, BENCHMARK_PROFILE_MODES, "profile_mode"),+ region: cleanString(value.region, "region", {+ max: 64,+ pattern: /^[A-Za-z0-9][A-Za-z0-9._-]*$/,+ }),+ condition: enumValue(value.condition, BENCHMARK_CONDITIONS, "condition"),+ jev_step_latency_ms: jevStepLatency,+ timing_ms: timing,+ evidence,+ stop_reason: stopReason,+ failure_category: failureCategory,+ };+};diff --git a/package.json b/package.jsonindex 9c0aea3..0fc7b13 100644--- a/package.json+++ b/package.json@@ -7,7 +7,8 @@"jev-social": "bin/jev-social.js"},"exports": {- ".": "./src/index.js"+ ".": "./src/index.js",+ "./benchmark/schema": "./benchmark/schema.js"},"repository": {"type": "git",@@ -18,6 +19,9 @@"url": "https://github.com/socai-io/jev-social/issues"},"files": [+ "benchmark/schema.js",+ "benchmark/README.md",+ "benchmark/fixtures/valid-row.json","bin","docs/troubleshooting.md","public",@@ -29,7 +33,7 @@"scripts": {"start": "node ./bin/jev-social.js","dev": "node --watch ./bin/jev-social.js serve --no-open",- "check": "node --check ./bin/jev-social.js && node --check ./src/server.js && node --check ./src/decision-provider.js && node --check ./src/evidence.js && node --check ./src/report.js && node --check ./public/app.js && node --check ./public/evidence-preview.js && node --check ./public/run-route.js && node --check ./public/report-download.js && node --check ./public/report-stream.js && node --check ./public/prompts.js && node --check ./public/status.js",+ "check": "node --check ./bin/jev-social.js && node --check ./benchmark/schema.js && node --check ./src/server.js && node --check ./src/decision-provider.js && node --check ./src/evidence.js && node --check ./src/report.js && node --check ./public/app.js && node --check ./public/evidence-preview.js && node --check ./public/run-route.js && node --check ./public/report-download.js && node --check ./public/report-stream.js && node --check ./public/prompts.js && node --check ./public/status.js","test": "node --test"},"engines": {diff --git a/test/benchmark-schema.test.js b/test/benchmark-schema.test.jsnew file mode 100644index 0000000..73ec4a0--- /dev/null+++ b/test/benchmark-schema.test.js@@ -0,0 +1,332 @@+import assert from "node:assert/strict";+import { execFileSync } from "node:child_process";+import { mkdtempSync, readFileSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import test from "node:test";+import {+ BenchmarkRowValidationError,+ validateBenchmarkRow,+} from "../benchmark/schema.js";++const fixture = JSON.parse(+ readFileSync(new URL("../benchmark/fixtures/valid-row.json", import.meta.url), "utf8"),+);++const clone = (value = fixture) => structuredClone(value);++test("accepts and normalizes the documented synthetic row", () => {+ const row = clone();+ row.region = " synthetic-us ";++ const normalized = validateBenchmarkRow(row);++ assert.notEqual(normalized, row);+ assert.equal(normalized.region, "synthetic-us");+ assert.equal(normalized.started_at, "2026-09-25T00:00:00.000Z");+ assert.equal(normalized.ended_at, "2026-09-25T00:00:12.000Z");+ assert.deepEqual(normalized, { ...fixture, region: "synthetic-us" });+});++test("rejects missing required fields and unknown enum values", () => {+ const missing = clone();+ delete missing.run_id;+ assert.throws(() => validateBenchmarkRow(missing), BenchmarkRowValidationError);++ for (const [field, value] of [+ ["platform", "youtube"],+ ["outcome", "mostly-success"],+ ["condition", "sometimes-warm"],+ ["profile_mode", "personal-account"],+ ]) {+ const row = clone();+ row[field] = value;+ assert.throws(+ () => validateBenchmarkRow(row),+ (error) => error instanceof BenchmarkRowValidationError && error.path === field,+ `${field} should reject ${value}`,+ );+ }+});++test("rejects invalid timestamps and inconsistent timing totals", () => {+ for (const mutate of [+ (row) => {+ row.started_at = "2026-09-25 00:00:00";+ },+ (row) => {+ row.ended_at = "2026-09-24T23:59:59.000Z";+ },+ (row) => {+ row.started_at = "2026-02-30T00:00:00.000Z";+ row.ended_at = "2026-02-30T00:00:12.000Z";+ },+ (row) => {+ row.timing_ms.jev_total = 999;+ },+ (row) => {+ row.timing_ms.total = 10_999;+ },+ (row) => {+ row.timing_ms.socai_browser = 12_001;+ },+ ]) {+ const row = clone();+ mutate(row);+ assert.throws(() => validateBenchmarkRow(row), BenchmarkRowValidationError);+ }+});++test("allows overlapping component timers and one-second wall-clock tolerance", () => {+ const row = clone();+ row.timing_ms.socai_browser = 12_000;+ row.timing_ms.media = 12_000;+ row.timing_ms.total = 12_001;+ assert.equal(validateBenchmarkRow(row).timing_ms.total, 12_001);++ row.timing_ms.total = 13_001;+ assert.throws(() => validateBenchmarkRow(row), BenchmarkRowValidationError);+});++test("requires sequential Jev and browser time to fit the end-to-end total", () => {+ const row = clone();+ row.jev_step_latency_ms = [3_000, 3_000];+ row.timing_ms.jev_total = 6_000;+ row.timing_ms.socai_browser = 7_001;+ assert.throws(() => validateBenchmarkRow(row), BenchmarkRowValidationError);+});++test("rejects negative durations and evidence counts", () => {+ for (const path of [+ ["jev_step_latency_ms", 0],+ ["timing_ms", "media"],+ ["evidence", "records"],+ ["evidence", "downloaded_media_bytes"],+ ]) {+ const row = clone();+ if (Array.isArray(row[path[0]])) row[path[0]][path[1]] = -1;+ else row[path[0]][path[1]] = -1;+ assert.throws(() => validateBenchmarkRow(row), BenchmarkRowValidationError);+ }+});++test("rejects unknown fields and recursively denylisted names", () => {+ const unknown = clone();+ unknown.notes = "looks harmless";+ assert.throws(+ () => validateBenchmarkRow(unknown),+ (error) => error instanceof BenchmarkRowValidationError && error.path === "notes",+ );++ for (const [name, value] of [+ ["cookie", "secret"],+ ["authorization", "secret"],+ ["api_key", "secret"],+ ["token", "secret"],+ ["websocket_url", "ws://127.0.0.1"],+ ["cdp_endpoint", "http://127.0.0.1"],+ ["account_id", "123"],+ ["username", "person"],+ ["local_path", "/tmp/private"],+ ["post_text", "private content"],+ ]) {+ const row = clone();+ row.evidence.extra = { [name]: value };+ assert.throws(+ () => validateBenchmarkRow(row),+ (error) =>+ error instanceof BenchmarkRowValidationError && error.path.endsWith(name),+ `${name} should be rejected at any depth`,+ );+ }+});++test("requires opaque IDs and pinned socai metadata", () => {+ for (const [field, value] of [+ ["run_id", "https://example.com/run/1"],+ ["run_id", "/Users/example/run-1"],+ ["run_id", "real_account_username"],+ ["task_id", "@creator"],+ ]) {+ const row = clone();+ row[field] = value;+ assert.throws(+ () => validateBenchmarkRow(row),+ (error) => error instanceof BenchmarkRowValidationError && error.path === field,+ );+ }++ const commit = clone();+ commit.socai_commit = "main";+ assert.throws(+ () => validateBenchmarkRow(commit),+ (error) => error instanceof BenchmarkRowValidationError && error.path === "socai_commit",+ );++ for (const value of [+ "/Users/alice/jev-model",+ "https://example.com/jev",+ "typesafe/jev?token=secret",+ "@account/model",+ ]) {+ const row = clone();+ row.jev_model = value;+ assert.throws(+ () => validateBenchmarkRow(row),+ (error) => error instanceof BenchmarkRowValidationError && error.path === "jev_model",+ );+ }++ const canonical = clone();+ canonical.socai_version = "v0.6.0-beta.1+sha.abcdef";+ canonical.socai_commit = canonical.socai_commit.toUpperCase();+ canonical.jev_model = "typesafe/jev-latest:free";+ const normalized = validateBenchmarkRow(canonical);+ assert.equal(normalized.socai_version, "0.6.0-beta.1+sha.abcdef");+ assert.equal(normalized.socai_commit, canonical.socai_commit.toLowerCase());+ assert.equal(normalized.jev_model, canonical.jev_model);++ const nestedModel = clone();+ nestedModel.jev_model = "org/team/jev";+ assert.equal(validateBenchmarkRow(nestedModel).jev_model, nestedModel.jev_model);+});++test("keeps outcome and stop state consistent", () => {+ const success = clone();+ success.failure_category = "rate_limited";+ assert.throws(() => validateBenchmarkRow(success), BenchmarkRowValidationError);++ const partial = clone();+ partial.outcome = "partial";+ partial.stop_reason = "rate_limited";+ partial.failure_category = null;+ assert.throws(() => validateBenchmarkRow(partial), BenchmarkRowValidationError);++ const stateMatrix = [+ ["step_limit", "step_limit"],+ ["login_required", "access_gate"],+ ["challenge_required", "access_gate"],+ ["rate_limited", "access_gate"],+ ["empty_results", "empty_results"],+ ["capability_unavailable", "unavailable"],+ ["browser_unavailable", "unavailable"],+ ["media_unavailable", "unavailable"],+ ["decision_failed", "execution_error"],+ ["cli_failed", "execution_error"],+ ["network_error", "execution_error"],+ ["report_failed", "execution_error"],+ ["interrupted", "interrupted"],+ ["unknown", "unknown"],+ ];+ for (const [stopReason, failureCategory] of stateMatrix) {+ const failed = clone();+ failed.outcome = "failed";+ failed.stop_reason = stopReason;+ failed.failure_category = failureCategory;+ if (stopReason === "empty_results") {+ failed.evidence.records = 0;+ failed.evidence.comments = 0;+ failed.evidence.downloaded_media_count = 0;+ failed.evidence.downloaded_media_bytes = 0;+ }+ assert.equal(validateBenchmarkRow(failed).stop_reason, stopReason);++ failed.failure_category = failureCategory === "unknown" ? "execution_error" : "unknown";+ assert.throws(() => validateBenchmarkRow(failed), BenchmarkRowValidationError);+ }++ const contradictory = clone();+ contradictory.outcome = "failed";+ contradictory.stop_reason = "goal_satisfied";+ contradictory.failure_category = "unknown";+ assert.throws(() => validateBenchmarkRow(contradictory), BenchmarkRowValidationError);++ const successWithoutEvidence = clone();+ successWithoutEvidence.evidence.records = 0;+ successWithoutEvidence.evidence.comments = 0;+ successWithoutEvidence.evidence.downloaded_media_count = 0;+ successWithoutEvidence.evidence.downloaded_media_bytes = 0;+ assert.throws(() => validateBenchmarkRow(successWithoutEvidence), BenchmarkRowValidationError);++ const nonemptyEmptyResult = clone();+ nonemptyEmptyResult.outcome = "failed";+ nonemptyEmptyResult.stop_reason = "empty_results";+ nonemptyEmptyResult.failure_category = "empty_results";+ assert.throws(() => validateBenchmarkRow(nonemptyEmptyResult), BenchmarkRowValidationError);+});++test("allows zero preflight decisions and bounds route plus action decisions", () => {+ const preflight = clone();+ preflight.outcome = "failed";+ preflight.stop_reason = "capability_unavailable";+ preflight.failure_category = "unavailable";+ preflight.jev_step_latency_ms = [];+ preflight.timing_ms.jev_total = 0;+ preflight.evidence.records = 0;+ preflight.evidence.comments = 0;+ preflight.evidence.downloaded_media_count = 0;+ preflight.evidence.downloaded_media_bytes = 0;+ assert.equal(validateBenchmarkRow(preflight).jev_step_latency_ms.length, 0);++ const fullBudget = clone();+ fullBudget.max_steps = 1;+ assert.equal(validateBenchmarkRow(fullBudget).jev_step_latency_ms.length, 2);++ const tooMany = clone();+ tooMany.max_steps = 1;+ tooMany.jev_step_latency_ms.push(1);+ tooMany.timing_ms.jev_total += 1;+ assert.throws(() => validateBenchmarkRow(tooMany), BenchmarkRowValidationError);+});++test("keeps downloaded media counts possible and TikTok-only", () => {+ const zeroCountWithBytes = clone();+ zeroCountWithBytes.evidence.downloaded_media_bytes = 4_096;+ assert.throws(() => validateBenchmarkRow(zeroCountWithBytes), BenchmarkRowValidationError);++ const countWithZeroBytes = clone();+ countWithZeroBytes.evidence.downloaded_media_count = 1;+ assert.throws(() => validateBenchmarkRow(countWithZeroBytes), BenchmarkRowValidationError);++ const instagramDownload = clone();+ instagramDownload.evidence.downloaded_media_count = 1;+ instagramDownload.evidence.downloaded_media_bytes = 4_096;+ assert.throws(() => validateBenchmarkRow(instagramDownload), BenchmarkRowValidationError);++ const tiktokDownload = clone();+ tiktokDownload.platform = "tiktok";+ tiktokDownload.evidence.downloaded_media_count = 1;+ tiktokDownload.evidence.downloaded_media_bytes = 4_096;+ assert.equal(validateBenchmarkRow(tiktokDownload).evidence.downloaded_media_count, 1);+});++test("the packaged benchmark schema has an explicit import path", async () => {+ const packaged = await import("jev-social/benchmark/schema");+ assert.equal(packaged.validateBenchmarkRow, validateBenchmarkRow);+});++test("the package contains only the intended benchmark artifacts", () => {+ const cache = mkdtempSync(join(tmpdir(), "jev-social-npm-cache-"));+ try {+ const npmArgs = ["pack", "--dry-run", "--ignore-scripts", "--json", "--cache", cache];+ const output = process.env.npm_execpath+ ? execFileSync(process.execPath, [process.env.npm_execpath, ...npmArgs], {+ cwd: new URL("..", import.meta.url),+ encoding: "utf8",+ })+ : execFileSync(process.platform === "win32" ? "npm.cmd" : "npm", npmArgs, {+ cwd: new URL("..", import.meta.url),+ encoding: "utf8",+ });+ const files = JSON.parse(output)[0].files+ .map(({ path }) => path)+ .filter((path) => path.startsWith("benchmark/"));+ assert.deepEqual(files, [+ "benchmark/fixtures/valid-row.json",+ "benchmark/README.md",+ "benchmark/schema.js",+ ]);+ } finally {+ rmSync(cache, { recursive: true, force: true });+ }+});