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

@ -25,7 +25,7 @@ describe.each([
it("serves the specification through its family and docs index", () => {
expect(familyOfSpec(slug)?.slug).toBe(family);
expect(listDocs()).toContainEqual(expect.objectContaining({ slug, title: name }));
expect(readDoc(slug)).toMatch(/Status: \*{0,2}0\.1/);
expect(readDoc(slug)).toMatch(/Status: \*{0,2}0\.\d/);
});
it("includes a reachable docs URL and the full contract in the LLM feeds", async () => {

View file

@ -121,7 +121,7 @@ export const FAMILIES: Family[] = [
"The lifecycle for building software when agents work in parallel and CI is the only gate, the requirement document an agent can execute, the settlement and proof layer under a peer-to-peer swarm, a lossless byte-stream envelope, the five nouns a shared ontology needs, the record an agent session carries about who spawned it and under what ceiling, the one script that puts an application into service on the box it runs on, the signed package format a command-line tool is installed and updated from, and the errand file an agent runs on a website with no API while handing every legal, identity and mail step to a person.",
specs: [
s("asdlc", "ASDLC", "The Agentic Software Development Lifecycle: nine phases, four conformance levels and the ratchet rule"),
s("openabtest", "OpenABTest", "Portable experiments with sticky assignments, distinct exposure and conversion events, and reconciled profit accounting", { landing: undefined, status: "draft" }),
s("openabtest", "OpenABTest", "Portable experiments with sticky assignments, distinct exposure and conversion events, goal or purchase conversions, and reconciled profit accounting", { landing: undefined, status: "draft" }),
s("openprd", "OpenPRD", "A product requirement document an agent can execute and a person can read"),
s("openswarm", "OpenSwarm", "Settlement and proof of work done under a peer-to-peer swarm"),
s("openstream", "OpenStream", "A lossless byte-stream relay envelope, with benchmark reports per release", { landing: undefined }),

View file

@ -280,11 +280,11 @@
},
"packages/schemas": {
"name": "@logicsrc/schemas",
"version": "0.4.0",
"version": "0.5.0",
},
"packages/sdk": {
"name": "@logicsrc/sdk",
"version": "0.3.0",
"version": "0.4.0",
"devDependencies": {
"vitest": "^4.0.8",
},
@ -303,7 +303,7 @@
},
"packages/validators": {
"name": "@logicsrc/validators",
"version": "0.4.0",
"version": "0.5.0",
"bin": {
"logicsrc-validate": "dist/cli.js",
},

View file

@ -2,7 +2,7 @@
OpenABTest is a portable experiment manifest and private event contract for comparing product offers across services without confusing assignment, exposure, purchases, or profit.
Status: **0.1 draft proposal**, September 13, 2026. This release supplies JSON Schemas, semantic validators, SDK document constructors and examples. It does not ship an assignment service, analytics warehouse, statistical decision engine, payment executor, or registered AT Protocol extension. No external standards body has accepted this draft.
Status: **0.2 draft proposal**, October 17, 2026 (0.1: September 13, 2026). 0.2 adds goal conversions and is backward compatible: every valid 0.1 document stays valid. This release supplies JSON Schemas, semantic validators, SDK document constructors and examples. It does not ship an assignment service of its own (a hosted reference implementation runs at [w3bs.org/ab-testing](https://w3bs.org/ab-testing)), analytics warehouse, statistical decision engine, payment executor, or registered AT Protocol extension. No external standards body has accepted this draft.
Slug: `openabtest`
@ -12,15 +12,15 @@ A manifest names one experiment, its versioned variants, eligibility rule, rando
- Manifest schema: `@logicsrc/schemas/openabtest-manifest`.
- Event schema: `@logicsrc/schemas/openabtest-event`.
- Validation: `validate("openabtest-manifest", document)` and `validate("openabtest-event", document)` from `@logicsrc/validators` 0.3.0 or newer.
- SDK: `OpenABTestManifest`, `OpenABTestEvent`, `createOpenABTestManifest` and `createOpenABTestEvent` from `@logicsrc/sdk` 0.3.0 or newer. Constructors add the draft discriminator; they do not validate, assign people, authenticate events or initiate payment.
- Validation: `validate("openabtest-manifest", document)` and `validate("openabtest-event", document)` from `@logicsrc/validators` 0.3.0 or newer (0.5.0 or newer for 0.2 goal conversions).
- SDK: `OpenABTestManifest`, `OpenABTestEvent`, `createOpenABTestManifest` and `createOpenABTestEvent` from `@logicsrc/sdk` 0.3.0 or newer (0.4.0 or newer for 0.2). Constructors add the draft discriminator; they do not validate, assign people, authenticate events or initiate payment.
- Complete examples: [manifest](https://github.com/profullstack/logicsrc/blob/master/packages/schemas/fixtures/openabtest/chovy-manifest.json) and [event fixtures](https://github.com/profullstack/logicsrc/tree/master/packages/schemas/fixtures/openabtest).
Schema `$id` values name the contracts; they do not imply that a schema-hosting endpoint or universal discovery API has been deployed. A service may link a public, redacted manifest from its documentation. Participant events and settlement evidence MUST remain private.
## Manifest and versioned assignment
Required fields are `openabtest: "0.1-draft"`, `id`, positive integer `revision`, `name`, `state`, `cohort`, `assignment`, `variants`, `window`, `metrics`, and `guardrails`. `economics` is optional for experiments that do not change prices. IDs are issuer-scoped opaque strings, at most 128 characters. Variant IDs must be unique within the manifest; weights are positive safe integers with a safe-integer sum. The share of newly assigned eligible participants is `weight / sum(weights)`, not a promise of an exact observed sample split.
Required fields are `openabtest` (`"0.1-draft"`, or `"0.2-draft"` for a document that uses goal conversions), `id`, positive integer `revision`, `name`, `state`, `cohort`, `assignment`, `variants`, `window`, `metrics`, and `guardrails`. `economics` is optional for experiments that do not change prices. IDs are issuer-scoped opaque strings, at most 128 characters. Variant IDs must be unique within the manifest; weights are positive safe integers with a safe-integer sum. The share of newly assigned eligible participants is `weight / sum(weights)`, not a promise of an exact observed sample split.
`cohort` contains a stable `id`, an explicit `eligibilityRule`, and `purchaseScope`. Rules must state the product, tenant, referral validity, exclusions, geography or other restrictions when applicable. They are prose for the implementing service, not executable expressions. The Chovy scope is **all-referred-purchases**. Other products may select `all-eligible-purchases`, `first-eligible-purchase`, or `custom` with a complete rule. Overlapping experiments must declare their interaction policy in the eligibility rule; do not silently stack price discounts.
@ -80,7 +80,7 @@ Every event has `openabtest`, unique `id`, `producerId`, `manifestId`, `manifest
| eligibility | `cohortId`, `eligible: true`; the server verified entry into the cohort. Repeated visits do not add people to the denominator |
| assignment | `cohortId`, `assignmentId`, `variantId`; a durable choice exists. This does not assert that the customer saw it |
| exposure | `assignmentId`, `variantId`, `offerId`, `surface`; the offer was actually shown on the named surface. Rendering failure is not an exposure |
| conversion | `assignmentId`, `variantId`, unique `conversionId`, immutable `price`; an authenticated purchase confirmation, not a checkout click or a client success redirect |
| conversion | `assignmentId`, `variantId`, unique `conversionId`, and exactly one of an immutable `price` (an authenticated purchase confirmation, not a checkout click or a client success redirect) or, in 0.2, a `goal` (see Goal conversions) |
| adjustment | Assignment and conversion IDs, unique `adjustmentId`, currency, signed `amountMinor`, reason and evidence references; a refund, chargeback or accounting correction |
| reconciliation | Assignment and conversion IDs, increasing `accountingRevision`, currency, recognized revenue/refunds, actual costs/fees, affiliate allocation, retained profit, floor, state, payout status and evidence references |
@ -92,6 +92,43 @@ Deduplicate events by `(producerId, id)` and immutable payload binding. An ident
Consumers verify manifest revision and variant existence, participant/assignment ownership, currency, original conversion attribution, event order and accounting revision against the private ledger. Out-of-order events can be buffered and reconciled; never invent missing eligibility or exposure. An authenticated conversion can exist without an observed exposure due to instrumentation loss; report that discrepancy. Standalone schema validation cannot establish these cross-record facts or event authority.
## Goal conversions (0.2)
Most experiments are not about price. A button label, an onboarding step or a landing page is judged by whether people sign up, finish a task or come back. In 0.1 a conversion is a purchase with a price, so those experiments had nothing conformant to report. 0.2 adds a goal conversion.
A goal experiment declares `openabtest: "0.2-draft"`, `metrics.conversion: "unique-participants-with-goal"` and `metrics.goal`, an opaque goal id such as `signup-completed`. The primary metric must be `conversion-rate`. If there is no money in the experiment, `metrics.profit` is `"none"`; `economics` is then omitted.
```json
{
"openabtest": "0.2-draft",
"id": "signup-cta-v1",
"variants": [
{ "id": "control", "weight": 1, "parameters": { "cta": "Sign up" } },
{ "id": "free", "weight": 1, "parameters": { "cta": "Start free" } }
],
"metrics": {
"primary": "conversion-rate",
"conversion": "unique-participants-with-goal",
"goal": "signup-completed",
"profit": "none"
}
}
```
This is an excerpt; use the [full fixture](https://github.com/profullstack/logicsrc/blob/master/packages/schemas/fixtures/openabtest/goal-manifest.json) for validation.
A goal conversion event carries `goal` instead of `price`, with an optional observed `value` of `{ currency, amountMinor }` (a non-negative integer). A conversion carries exactly one of `price` or `goal`; a document using `goal` must say `0.2-draft`. The same rules as purchases apply. The goal must be confirmed by the server that owns it (an account actually created, not a button clicked). Deduplicate by `conversionId`. A conversion without an observed exposure is reported as such, never dropped.
```json
{
"openabtest": "0.2-draft",
"kind": "conversion",
"payload": { "assignmentId": "assignment-42", "variantId": "free", "conversionId": "signup-42", "goal": "signup-completed" }
}
```
For a goal experiment, the conversion rate counts unique assigned participants with at least one confirmed goal conversion, over the same eligible-participant denominator. `value` totals may be reported per currency beside it. They are observed amounts, not reconciled profit, and must not be labelled as profit.
## Reconciliation, refunds and payment references
A pending reconciliation has unknown affiliate/retained amounts (`null`) and `payoutStatus: "withheld"`; actual costs and fees may also be `null`. A reconciled record requires all those numbers and private proof references. Its equality is:

View file

@ -40,7 +40,7 @@
"test": "vitest run src"
},
"dependencies": {
"@logicsrc/validators": "^0.4.0",
"@logicsrc/validators": "^0.5.0",
"commander": "^14.0.2"
},
"devDependencies": {

View file

@ -0,0 +1,16 @@
{
"openabtest": "0.2-draft",
"producerId": "chovy-server",
"manifestId": "signup-cta-v1",
"manifestRevision": 1,
"participantId": "participant-opaque-7d12",
"at": "2026-09-15T12:00:00Z",
"id": "event-goal-42",
"kind": "conversion",
"payload": {
"assignmentId": "assignment-42",
"variantId": "free",
"conversionId": "signup-42",
"goal": "signup-completed"
}
}

View file

@ -0,0 +1,55 @@
{
"openabtest": "0.2-draft",
"id": "signup-cta-v1",
"revision": 1,
"name": "Sign-up button copy",
"state": "draft",
"cohort": {
"id": "landing-visitors",
"eligibilityRule": "Signed-out visitors who load the landing page; staff and bots excluded.",
"purchaseScope": "custom"
},
"assignment": {
"unit": "device",
"authority": "server",
"keyVersion": "1",
"algorithm": "hmac-sha256-persisted-v1",
"persistence": "sticky"
},
"variants": [
{
"id": "control",
"weight": 1,
"parameters": {
"cta": "Sign up"
}
},
{
"id": "free",
"weight": 1,
"parameters": {
"cta": "Start free"
}
}
],
"window": {
"startsAt": "2026-09-14T00:00:00Z",
"endsAt": "2026-10-14T00:00:00Z"
},
"metrics": {
"primary": "conversion-rate",
"denominator": "unique-eligible-participants",
"conversion": "unique-participants-with-goal",
"profit": "none",
"minimumEligiblePerVariant": 100,
"minimumObservationSeconds": 604800,
"winnerPolicy": "manual-review",
"goal": "signup-completed"
},
"guardrails": {
"preserveAcceptedOffers": true,
"preserveAccruedCommissions": true,
"requireReconciledCostsForPayout": true,
"onBreach": "pause-new-assignments"
}
}

View file

@ -1,6 +1,6 @@
{
"name": "@logicsrc/schemas",
"version": "0.4.0",
"version": "0.5.0",
"description": "LogicSRC JSON schemas for tasks, agents, runs, events, plugins, the AgentAd ad standard, the OpenOntology knowledge contracts, the OpenContext context plane, the OpenCreds credential vault, OpenRental membership and rental offers, and the OpenWall messaging proposal. Includes the OpenABTest draft experiment and event contracts.",
"license": "MIT",
"type": "module",

View file

@ -17,7 +17,10 @@
],
"properties": {
"openabtest": {
"const": "0.1-draft"
"enum": [
"0.1-draft",
"0.2-draft"
]
},
"id": {
"type": "string",
@ -182,8 +185,7 @@
"required": [
"assignmentId",
"variantId",
"conversionId",
"price"
"conversionId"
],
"properties": {
"assignmentId": {
@ -254,8 +256,49 @@
"maximum": 9007199254740991
}
}
},
"goal": {
"type": "string",
"pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
},
"value": {
"type": "object",
"additionalProperties": false,
"required": [
"currency",
"amountMinor"
],
"properties": {
"currency": {
"type": "string",
"pattern": "^[A-Z]{3}$"
},
"amountMinor": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
}
}
}
},
"oneOf": [
{
"required": [
"price"
],
"properties": {
"price": true
}
},
{
"required": [
"goal"
],
"properties": {
"goal": true
}
}
]
}
}
}

View file

@ -19,7 +19,10 @@
],
"properties": {
"openabtest": {
"const": "0.1-draft"
"enum": [
"0.1-draft",
"0.2-draft"
]
},
"id": {
"type": "string",
@ -198,10 +201,16 @@
"const": "unique-eligible-participants"
},
"conversion": {
"const": "unique-participants-with-confirmed-purchase"
"enum": [
"unique-participants-with-confirmed-purchase",
"unique-participants-with-goal"
]
},
"profit": {
"const": "reconciled-net-retained-profit"
"enum": [
"reconciled-net-retained-profit",
"none"
]
},
"minimumEligiblePerVariant": {
"type": "integer",
@ -215,6 +224,10 @@
},
"winnerPolicy": {
"const": "manual-review"
},
"goal": {
"type": "string",
"pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
}
}
},

View file

@ -37,7 +37,7 @@ MIT © Profullstack, Inc.
Version 0.3.0 adds `OpenABTestManifest`, `OpenABTestEvent`,
`createOpenABTestManifest` and `createOpenABTestEvent`. The constructors set
`openabtest: "0.1-draft"`; validate their result with `@logicsrc/validators`
`openabtest: "0.1-draft"`, or `"0.2-draft"` when the document uses a goal conversion; validate their result with `@logicsrc/validators`
using `openabtest-manifest` or `openabtest-event` before storing it. They do not
assign participants, authenticate events or initiate payments. See the
[OpenABTest specification](https://logicsrc.com/docs/openabtest) and its complete

View file

@ -1,6 +1,6 @@
{
"name": "@logicsrc/sdk",
"version": "0.3.0",
"version": "0.4.0",
"description": "LogicSRC SDK contract types and client interface.",
"type": "module",
"main": "./dist/index.js",

View file

@ -1,6 +1,7 @@
/** Draft private contracts; constructors do not assign users, authorize events or pay money. */
export type OpenABTestVersion = "0.1-draft" | "0.2-draft";
export interface OpenABTestManifest {
openabtest: "0.1-draft";
openabtest: OpenABTestVersion;
id: string;
revision: number;
name: string;
@ -12,8 +13,10 @@ export interface OpenABTestManifest {
metrics: {
primary: "conversion-rate" | "retained-profit-per-eligible-visitor";
denominator: "unique-eligible-participants";
conversion: "unique-participants-with-confirmed-purchase";
profit: "reconciled-net-retained-profit";
/** 0.2: unique-participants-with-goal counts participants who reached metrics.goal. */
conversion: "unique-participants-with-confirmed-purchase" | "unique-participants-with-goal";
profit: "reconciled-net-retained-profit" | "none";
goal?: string;
minimumEligiblePerVariant: number;
minimumObservationSeconds: number;
winnerPolicy: "manual-review";
@ -55,12 +58,12 @@ type EventDetail =
| { kind: "eligibility"; payload: { cohortId: string; eligible: true } }
| { kind: "assignment"; payload: Assigned & { cohortId: string } }
| { kind: "exposure"; payload: Assigned & { offerId: string; surface: string } }
| { kind: "conversion"; payload: Converted & { price: OpenABTestPrice } }
| { kind: "conversion"; payload: Converted & ({ price: OpenABTestPrice; goal?: never } | { goal: string; price?: never; value?: { currency: string; amountMinor: number } }) }
| { kind: "adjustment"; payload: Converted & { adjustmentId: string; currency: string; amountMinor: number; reason: "refund" | "chargeback" | "correction"; proofRefs: string[] } }
| { kind: "reconciliation"; payload: OpenABTestReconciliation };
export type OpenABTestEvent = {
openabtest: "0.1-draft";
openabtest: OpenABTestVersion;
id: string;
producerId: string;
manifestId: string;
@ -71,11 +74,13 @@ export type OpenABTestEvent = {
/** Validate with @logicsrc/validators before storing or using the document. */
export function createOpenABTestManifest(input: Omit<OpenABTestManifest, "openabtest">): OpenABTestManifest {
return { ...input, openabtest: "0.1-draft" };
const goal = input.metrics.conversion === "unique-participants-with-goal" || input.metrics.profit === "none";
return { ...input, openabtest: goal ? "0.2-draft" : "0.1-draft" };
}
type EventInput = Omit<OpenABTestEvent, "openabtest" | "kind" | "payload"> & EventDetail;
/** The caller supplies authenticated context and durable IDs; this helper creates neither. */
export function createOpenABTestEvent(input: EventInput): OpenABTestEvent {
return { ...input, openabtest: "0.1-draft" };
const goal = input.kind === "conversion" && "goal" in input.payload && input.payload.goal !== undefined;
return { ...input, openabtest: goal ? "0.2-draft" : "0.1-draft" } as OpenABTestEvent;
}

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;