OpenABTest 0.2-draft: goal conversions (#239)

* OpenABTest 0.2-draft: goal conversions

0.1 conversions are purchases with a price, so button, onboarding and
landing-page experiments had nothing conformant to report. 0.2 adds a goal
conversion: metrics.conversion "unique-participants-with-goal" with
metrics.goal, metrics.profit "none", and conversion events carrying exactly
one of price or goal (optional observed value). Backward compatible: every
0.1 document stays valid; goal forms require "0.2-draft". The reference
implementation is w3bs.org/ab-testing.

@logicsrc/schemas and @logicsrc/validators 0.5.0, @logicsrc/sdk 0.4.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* contract: accept any 0.x draft status (OpenABTest is 0.2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-10-17 04:58:40 -07:00 • committed by GitHub
parent 0d0a2583b1
commit ef35139f04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 257 additions and 33 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@logicsrc/validators",
"version": "0.4.0",
"version": "0.5.0",
"description": "LogicSRC schema validation helpers.",
"type": "module",
"main": "./dist/index.js",
@ -11,10 +11,10 @@
"scripts": {
"build": "tsc -p tsconfig.json",
"test": "vitest run src",
"validate:fixtures": "node dist/cli.js task ../schemas/fixtures/task.yaml && node dist/cli.js agent ../schemas/fixtures/agent.yaml && node dist/cli.js agentad-ad ../schemas/fixtures/agentad-ad.yaml && node dist/cli.js agentad-placement ../schemas/fixtures/agentad-placement.yaml && node dist/cli.js repo ../schemas/fixtures/repo.yaml && node dist/cli.js pull-request ../schemas/fixtures/pull-request.yaml && node dist/cli.js openontology-manifest ../schemas/fixtures/openontology/valid/manifest.json && node dist/cli.js openontology-claim ../schemas/fixtures/openontology/valid/claim-relationship.json && node dist/cli.js openontology-changeset ../schemas/fixtures/openontology/valid/changeset.json && node dist/cli.js opencontext-manifest ../schemas/fixtures/opencontext/valid/manifest.json && node dist/cli.js opencontext-object ../schemas/fixtures/opencontext/valid/object-policy.json && node dist/cli.js opencontext-bundle ../schemas/fixtures/opencontext/valid/bundle.json && node dist/cli.js opencontext-decision ../schemas/fixtures/opencontext/valid/decision.json && node dist/cli.js opencontext-role ../schemas/fixtures/opencontext/valid/role.json && node dist/cli.js opencontext-provenance ../schemas/fixtures/opencontext/valid/provenance.json && node dist/cli.js opencontext-diagnostic ../schemas/fixtures/opencontext/valid/diagnostic.json && node dist/cli.js opencontext-audit-event ../schemas/fixtures/opencontext/valid/audit-event.json && node dist/cli.js openrental ../schemas/fixtures/openrental/mixed.json && node dist/cli.js openerrand ../schemas/fixtures/openerrand/ftb-register-business.json && node dist/cli.js openerrand-index ../schemas/fixtures/openerrand/index.json && node dist/cli.js openwall-message ../schemas/fixtures/openwall/broadcast.json && node dist/cli.js openwall-message ../schemas/fixtures/openwall/direct.json && node dist/cli.js openwall-message ../schemas/fixtures/openwall/announcement.json && node dist/cli.js openwall-receipt ../schemas/fixtures/openwall/receipt-accepted.json && node dist/cli.js openwall-receipt ../schemas/fixtures/openwall/receipt-retrying.json && node dist/cli.js openabtest-manifest ../schemas/fixtures/openabtest/chovy-manifest.json && node dist/cli.js openabtest-event ../schemas/fixtures/openabtest/reconciliation.json"
"validate:fixtures": "node dist/cli.js task ../schemas/fixtures/task.yaml && node dist/cli.js agent ../schemas/fixtures/agent.yaml && node dist/cli.js agentad-ad ../schemas/fixtures/agentad-ad.yaml && node dist/cli.js agentad-placement ../schemas/fixtures/agentad-placement.yaml && node dist/cli.js repo ../schemas/fixtures/repo.yaml && node dist/cli.js pull-request ../schemas/fixtures/pull-request.yaml && node dist/cli.js openontology-manifest ../schemas/fixtures/openontology/valid/manifest.json && node dist/cli.js openontology-claim ../schemas/fixtures/openontology/valid/claim-relationship.json && node dist/cli.js openontology-changeset ../schemas/fixtures/openontology/valid/changeset.json && node dist/cli.js opencontext-manifest ../schemas/fixtures/opencontext/valid/manifest.json && node dist/cli.js opencontext-object ../schemas/fixtures/opencontext/valid/object-policy.json && node dist/cli.js opencontext-bundle ../schemas/fixtures/opencontext/valid/bundle.json && node dist/cli.js opencontext-decision ../schemas/fixtures/opencontext/valid/decision.json && node dist/cli.js opencontext-role ../schemas/fixtures/opencontext/valid/role.json && node dist/cli.js opencontext-provenance ../schemas/fixtures/opencontext/valid/provenance.json && node dist/cli.js opencontext-diagnostic ../schemas/fixtures/opencontext/valid/diagnostic.json && node dist/cli.js opencontext-audit-event ../schemas/fixtures/opencontext/valid/audit-event.json && node dist/cli.js openrental ../schemas/fixtures/openrental/mixed.json && node dist/cli.js openerrand ../schemas/fixtures/openerrand/ftb-register-business.json && node dist/cli.js openerrand-index ../schemas/fixtures/openerrand/index.json && node dist/cli.js openwall-message ../schemas/fixtures/openwall/broadcast.json && node dist/cli.js openwall-message ../schemas/fixtures/openwall/direct.json && node dist/cli.js openwall-message ../schemas/fixtures/openwall/announcement.json && node dist/cli.js openwall-receipt ../schemas/fixtures/openwall/receipt-accepted.json && node dist/cli.js openwall-receipt ../schemas/fixtures/openwall/receipt-retrying.json && node dist/cli.js openabtest-manifest ../schemas/fixtures/openabtest/chovy-manifest.json && node dist/cli.js openabtest-event ../schemas/fixtures/openabtest/reconciliation.json && node dist/cli.js openabtest-manifest ../schemas/fixtures/openabtest/goal-manifest.json && node dist/cli.js openabtest-event ../schemas/fixtures/openabtest/goal-conversion.json"
},
"dependencies": {
"@logicsrc/schemas": "^0.4.0",
"@logicsrc/schemas": "^0.5.0",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"yaml": "^2.8.1"

View file

@ -93,6 +93,46 @@ describe("OpenABTest draft contracts", () => {
Object.assign(event.payload, { affiliateMinor: 0, actualCostMinor: 36000, retainedProfitMinor: -1000, payoutStatus: "withheld" });
expect(validate("openabtest-event", event).ok).toBe(true);
});
it("accepts 0.2 goal experiments and goal conversions", () => {
expect(validate("openabtest-manifest", fixture("goal-manifest")).ok).toBe(true);
expect(validate("openabtest-event", fixture("goal-conversion")).ok).toBe(true);
const valued = fixture("goal-conversion");
valued.payload.value = { currency: "USD", amountMinor: 4900 };
expect(validate("openabtest-event", valued).ok).toBe(true);
valued.payload.value.amountMinor = -1;
expect(validate("openabtest-event", valued).ok).toBe(false);
});
it("keeps 0.1 documents valid and gates goal forms behind 0.2-draft", () => {
const old = fixture("chovy-manifest");
old.openabtest = "0.2-draft";
expect(validate("openabtest-manifest", old).ok).toBe(true);
const manifest = fixture("goal-manifest");
manifest.openabtest = "0.1-draft";
expect(validate("openabtest-manifest", manifest).ok).toBe(false);
const event = fixture("goal-conversion");
event.openabtest = "0.1-draft";
expect(validate("openabtest-event", event).ok).toBe(false);
});
it("requires a named goal and a conversion-rate primary for goal experiments", () => {
const manifest = fixture("goal-manifest");
delete manifest.metrics.goal;
expect(validate("openabtest-manifest", manifest).ok).toBe(false);
const profit = fixture("goal-manifest");
profit.metrics.primary = "retained-profit-per-eligible-visitor";
expect(validate("openabtest-manifest", profit).ok).toBe(false);
const stray = fixture("chovy-manifest");
stray.metrics.goal = "signup-completed";
expect(validate("openabtest-manifest", stray).ok).toBe(false);
});
it("takes exactly one of price or goal on a conversion", () => {
const both = fixture("conversion");
both.openabtest = "0.2-draft";
both.payload.goal = "signup-completed";
expect(validate("openabtest-event", both).ok).toBe(false);
const neither = fixture("goal-conversion");
delete neither.payload.goal;
expect(validate("openabtest-event", neither).ok).toBe(false);
});
it("requires reconciliation evidence without bearer URLs", () => {
const event = fixture("reconciliation");
event.payload.proofRefs = [];

View file

@ -1,7 +1,7 @@
import type { ErrorObject } from "ajv";
type AccountingEvent =
| { kind: "conversion"; at: string; payload: { price: { listUnitPriceMinor: number; discountBps: number; quantityMilliUnits: number; chargedUnitPriceMinor: number; totalMinor: number; acceptedAt: string } } }
| { openabtest: string; kind: "conversion"; at: string; payload: { goal?: string; price?: { listUnitPriceMinor: number; discountBps: number; quantityMilliUnits: number; chargedUnitPriceMinor: number; totalMinor: number; acceptedAt: string } } }
| { kind: "adjustment"; payload: { reason: string; amountMinor: number } }
| { kind: "reconciliation"; payload: { revenueMinor: number; refundsMinor: number; actualCostMinor: number | null; feesMinor: number | null; affiliateMinor: number | null; retainedProfitMinor: number | null; minimumRetainedProfitMinor: number; state: string; payoutStatus: string; proofRefs: string[] } };
@ -14,9 +14,21 @@ export function validateOpenABTest(kind: string, data: unknown): ErrorObject[] {
}
if (kind === "openabtest-manifest") {
const manifest = data as {
openabtest: string;
variants: Array<{ id: string; weight: number; parameters: Record<string, unknown> }>;
window: { startsAt: string; endsAt: string };
metrics: { primary: string; conversion: string; profit: string; goal?: string };
};
// 0.2 goal conversions: a named goal instead of a purchase, and no profit metric.
const goalConversion = manifest.metrics.conversion === "unique-participants-with-goal";
if ((goalConversion || manifest.metrics.profit === "none") && manifest.openabtest !== "0.2-draft") {
report("/openabtest", "goal conversions and profit \"none\" require 0.2-draft");
}
if (goalConversion && manifest.metrics.goal === undefined) report("/metrics/goal", "is required for goal conversions");
if (!goalConversion && manifest.metrics.goal !== undefined) report("/metrics/goal", "applies only to unique-participants-with-goal");
if (manifest.metrics.profit === "none" && manifest.metrics.primary !== "conversion-rate") {
report("/metrics/profit", "\"none\" requires the conversion-rate primary metric");
}
const seen = new Set<string>();
let total = 0n;
manifest.variants.forEach((variant, index) => {
@ -34,7 +46,10 @@ export function validateOpenABTest(kind: string, data: unknown): ErrorObject[] {
}
} else {
const event = data as AccountingEvent;
if (event.kind === "conversion") {
if (event.kind === "conversion" && event.payload.goal !== undefined && event.openabtest !== "0.2-draft") {
report("/payload/goal", "goal conversions require 0.2-draft");
}
if (event.kind === "conversion" && event.payload.price) {
const price = event.payload.price;
const unit = (BigInt(price.listUnitPriceMinor) * BigInt(10000 - price.discountBps) + 5000n) / 10000n;
const total = (unit * BigInt(price.quantityMilliUnits) + 500n) / 1000n;