{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/proptastic/proptastic/main/contract/schemas/events/v1.json",
  "title": "proptastic events, v1",
  "description": "One event, a JSON object on a line of its own, keyed on its `reason`. The library writes each property's last event to `events/<name>.json`, <name> made from the property's id as the contract's `names` says, in its directory (PROPTASTIC_DIR, else proptastic's directory in the build's output), replacing the one before: `property-passed` or `property-failed`. The CLI's `run --format=jsonl` writes `run-started`, then each property's event as the library wrote it, then `run-finished`; under `--format=agent` or `jsonl` the CLI writes `run-failed` as the last line instead when it can't run or finish. Within v1, events only gain fields, reasons and enum values: read what you know, and ignore a field or an event you don't.",
  "type": "object",
  "required": ["schema", "reason"],
  "properties": {
    "schema": { "$ref": "#/$defs/schema" },
    "edition": { "$ref": "#/$defs/edition" },
    "reason": {
      "type": "string",
      "description": "What the event is: `property-passed` or `property-failed` from the library; `run-started`, `run-finished` and `run-failed` from the CLI. Ignore an event whose reason you don't know: a later v1 may add one."
    }
  },
  "allOf": [
    {
      "if": { "properties": { "reason": { "const": "property-passed" } }, "required": ["reason"] },
      "then": { "$ref": "#/$defs/propertyPassed" }
    },
    {
      "if": { "properties": { "reason": { "const": "property-failed" } }, "required": ["reason"] },
      "then": { "$ref": "#/$defs/propertyFailed" }
    },
    {
      "if": { "properties": { "reason": { "const": "run-failed" } }, "required": ["reason"] },
      "then": { "$ref": "#/$defs/runFailed" }
    },
    {
      "if": { "properties": { "reason": { "const": "run-started" } }, "required": ["reason"] },
      "then": { "$ref": "#/$defs/runStarted" }
    },
    {
      "if": { "properties": { "reason": { "const": "run-finished" } }, "required": ["reason"] },
      "then": { "$ref": "#/$defs/runFinished" }
    }
  ],
  "$defs": {
    "schema": {
      "const": "proptastic.events/v1",
      "description": "The format and its major version. A change that would break a reader comes as v2, with a schema of its own."
    },
    "edition": {
      "enum": ["java", "rust", "swift"],
      "description": "Which edition wrote the event, or which the CLI ran: every `property-passed` and `property-failed` has it, and a `run-failed` once the CLI has chosen an edition (decision 68)."
    },
    "property": {
      "type": "string",
      "description": "The property as a failure's header names it, after its test's class or module: `SortTest#sortKeepsSize`. Its exact id is the manifest's `id`."
    },
    "seed": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{1,16}$",
      "description": "The seed, `0x` and hex digits, as a failure prints it."
    },
    "run": {
      "type": "string",
      "pattern": "^[0-9a-f]{16}$",
      "description": "The run's stamp: 16 hex digits the test process draws once, the same in every event it writes, so a reader can tell which properties ran together (decision 61)."
    },
    "started": {
      "type": "string",
      "format": "date-time",
      "description": "When the property started, in UTC to the millisecond: `2026-12-02T21:24:13.120Z`. The CLI reads an event as its run's when it started at or after the CLI started the host, so it needn't trust a file's time (decision 61)."
    },
    "statistics": {
      "type": "object",
      "description": "What `classify` counted: each label, and the tries it held on.",
      "additionalProperties": { "type": "integer", "minimum": 0 }
    },
    "sizes": {
      "type": "object",
      "description": "The sizes the counted tries drew (decision 100): each sized draw by its name, or each kind of sized value inside one, `strings in xs`, and the 50th, 90th and 99th percentiles, by nearest rank, of every such value's size; absent when no sized value was drawn.",
      "additionalProperties": {
        "type": "object",
        "required": ["p50", "p90", "p99"],
        "properties": {
          "p50": { "type": "integer", "minimum": 0 },
          "p90": { "type": "integer", "minimum": 0 },
          "p99": { "type": "integer", "minimum": 0 }
        }
      }
    },
    "durationMs": {
      "type": "integer",
      "minimum": 0,
      "description": "How long the property ran, in milliseconds."
    },
    "counterexample": {
      "type": "object",
      "description": "The input that failed, smallest first when shrunk.",
      "required": ["text", "values"],
      "properties": {
        "text": {
          "type": "string",
          "description": "The input as the failure prints it: `xs = [0, 0]`, or a stateful test's steps, a line each."
        },
        "values": {
          "type": "array",
          "description": "Each draw's value, in order.",
          "items": {
            "type": "object",
            "required": ["name", "text"],
            "properties": {
              "name": {
                "type": ["string", "null"],
                "description": "The draw's name, where the edition knows it (decision 31), else `null`."
              },
              "text": { "type": "string", "description": "The value as the counterexample shows it." }
            }
          }
        }
      }
    },
    "location": {
      "type": "object",
      "description": "A place in the test's source.",
      "required": ["path", "line"],
      "properties": {
        "path": {
          "type": "string",
          "description": "The file, as the edition's `identity` binding (E2) gives a manifest's `at`: Java `com/example/SortTest.java`."
        },
        "line": { "type": "integer", "minimum": 1 }
      }
    },
    "propertyPassed": {
      "type": "object",
      "description": "The property passed: its examples, its saved counterexample and corpus, then its random tries.",
      "required": ["schema", "edition", "reason", "property", "run", "started", "tries", "discarded", "seed", "corpus", "profile", "statistics", "durationMs"],
      "properties": {
        "schema": { "$ref": "#/$defs/schema" },
        "edition": { "$ref": "#/$defs/edition" },
        "reason": { "const": "property-passed" },
        "property": { "$ref": "#/$defs/property" },
        "run": { "$ref": "#/$defs/run" },
        "started": { "$ref": "#/$defs/started" },
        "tries": {
          "type": "integer",
          "minimum": 0,
          "description": "The tries it passed, corpus entries among them, examples not."
        },
        "discarded": {
          "type": "integer",
          "minimum": 0,
          "description": "Tries a filter or `assume` threw away."
        },
        "seed": { "$ref": "#/$defs/seed" },
        "corpus": {
          "type": "integer",
          "minimum": 0,
          "description": "Corpus entries it ran."
        },
        "profile": { "enum": ["local", "pr", "nightly"] },
        "budget": {
          "type": "string",
          "description": "The time budget, as said (`2s`), when it ran out before the tries did; absent otherwise."
        },
        "statistics": { "$ref": "#/$defs/statistics" },
        "sizes": { "$ref": "#/$defs/sizes" },
        "targets": {
          "type": "object",
          "additionalProperties": { "type": "number" },
          "description": "Each `target` label's best score, `\"\"` for a score with no label (decision 62); absent when no try scored."
        },
        "durationMs": { "$ref": "#/$defs/durationMs" },
        "howSure": {
          "type": "object",
          "description": "The numbers the `how sure:` line and its long form are worked from (decision 41), so `explain` says what the library would; absent when no try was drawn at random, as with examples alone, tries 0 or `.exhaustively()`.",
          "required": ["passed", "unit", "bound"],
          "properties": {
            "passed": {
              "type": "integer",
              "minimum": 1,
              "description": "The tries or runs drawn at random, none failing: examples and corpus entries were chosen, so aren't counted."
            },
            "unit": {
              "enum": ["tries", "runs", "threadedRuns"],
              "description": "What was counted: a property's `tries`, a stateful test's `runs`, or `threadedRuns`, runs of steps on threads, whose schedules are searched, not drawn."
            },
            "bound": {
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 1,
              "description": "The share of what's drawn this way that may fail, at 95% confidence: `1 - 0.05^(1/passed)`, unrounded."
            }
          }
        },
        "incomplete": {
          "type": "array",
          "description": "Each `require` label the tries couldn't tell at 64 times those asked (decision 107), in the order they were asked for; absent when every label was told, and from an edition before decision 107.",
          "items": {
            "type": "object",
            "required": ["label", "held", "tries", "needs", "leans", "chance", "certainty"],
            "properties": {
              "label": { "type": "string" },
              "held": { "type": "integer", "minimum": 0, "description": "The tries the label held on." },
              "tries": { "type": "integer", "minimum": 1, "description": "The tries it was judged on." },
              "needs": { "type": "number", "exclusiveMinimum": 0, "maximum": 100, "description": "The percent `require` asked for." },
              "leans": {
                "enum": ["tooRare", "enough", "neither"],
                "description": "Which side of the line, nine tenths of what was asked, the share is on; `neither` when a call that way would be wrong more often than not."
              },
              "chance": {
                "type": "number",
                "minimum": 0,
                "maximum": 1,
                "description": "The most chance the lean is wrong, as the certainty counts it: Chernoff and Hoeffding's bound times the run's 7 looks, at most 1."
              },
              "certainty": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 0.05,
                "description": "The chance a call needed, `PROPTASTIC_CERTAINTY`."
              }
            }
          }
        },
        "model": {
          "type": "object",
          "description": "The model or spec the property followed, as its pass names it; absent when it followed none.",
          "required": ["name", "version", "kind", "proved"],
          "properties": {
            "name": { "type": "string", "description": "The model's name: `Trading.reserve`, or a spec's, `Reserve`." },
            "version": {
              "type": ["string", "null"],
              "description": "Its version, the model's own or `sha256:` and 8 hex digits of its sources, or `null` when it has none."
            },
            "kind": {
              "type": "string",
              "description": "What kind of model it is, as the pass's line says: `Lean`, `command`, or `TLA+` for a spec."
            },
            "proved": {
              "type": "array",
              "items": { "type": "string" },
              "description": "The theorems the model says it proved, in its order; empty when none."
            }
          }
        },
        "outcomes": {
          "type": "array",
          "description": "Each of the model's outcomes, or a spec's actions, in the model's order, with what the tries reached; absent when it followed none.",
          "items": {
            "type": "object",
            "required": ["name", "about", "count"],
            "properties": {
              "name": { "type": "string" },
              "about": {
                "type": ["string", "null"],
                "description": "What the outcome means, as the model says, or `null` where it doesn't, as a spec's actions don't."
              },
              "count": {
                "type": "integer",
                "minimum": 0,
                "description": "The tries it was the model's answer on, or the steps a spec's action took."
              },
              "unreachable": {
                "type": "string",
                "description": "Why the draws can't reach it, as `.unreachable` said; absent unless it said."
              },
              "smallest": {
                "type": "string",
                "description": "The smallest input that reached a model's outcome, as `explain PROPERTY OUTCOME` shows it: each value shown a comma apart, the shortest first, then the first in order; absent for a spec's actions and for an outcome no try reached."
              }
            }
          }
        }
      }
    },
    "propertyFailed": {
      "type": "object",
      "description": "The property failed: on a pinned example, with `example`, or on an input it found, with the tries, the seed and the pin line.",
      "required": ["schema", "edition", "reason", "property", "run", "started", "shrunk", "flaky", "counterexample", "assertion", "rendered"],
      "anyOf": [
        { "required": ["example"] },
        { "required": ["id", "tries", "discarded", "shrinkSteps", "fromCorpus", "seed", "pin", "failsForAny", "rerun", "location", "statistics", "durationMs"] }
      ],
      "properties": {
        "schema": { "$ref": "#/$defs/schema" },
        "edition": { "$ref": "#/$defs/edition" },
        "reason": { "const": "property-failed" },
        "property": { "$ref": "#/$defs/property" },
        "run": { "$ref": "#/$defs/run" },
        "started": { "$ref": "#/$defs/started" },
        "id": {
          "type": "string",
          "pattern": "^c[0-9a-f]{8}$",
          "description": "The counterexample's id, `c` and 8 hex digits: the first 8 of the SHA-256 of the property's id (the manifest's `id`), a newline, and the choices as the counterexample file writes them (decision 52). The counterexample file holds it too, as `id=`; `example ID` names it."
        },
        "example": {
          "type": "integer",
          "minimum": 1,
          "description": "Which pinned example failed, counting from 1."
        },
        "tries": {
          "type": "integer",
          "minimum": 0,
          "description": "The tries it made up to the failing one, that one included; 0 for a saved counterexample that failed again."
        },
        "discarded": { "type": "integer", "minimum": 0 },
        "shrinkSteps": {
          "type": "integer",
          "minimum": 0,
          "description": "The smaller inputs shrinking found on its way."
        },
        "fromCorpus": {
          "type": "boolean",
          "description": "Whether the failing input was a corpus entry."
        },
        "seed": { "$ref": "#/$defs/seed" },
        "shrunk": { "type": "boolean", "description": "Whether shrinking made the input smaller." },
        "flaky": {
          "type": "boolean",
          "description": "Whether the input passed when it ran again (decision 18)."
        },
        "counterexample": { "$ref": "#/$defs/counterexample" },
        "pin": {
          "type": ["string", "null"],
          "description": "The `pin it:` line, as source, or `null` where there's none."
        },
        "failsForAny": {
          "type": "array",
          "items": { "type": "string" },
          "description": "The draws whose values didn't matter, as the `fails for any:` fact names them: by draw name where the edition has them, else `value <n>`, or `the value` for one draw. Empty when none, or when the edition didn't look."
        },
        "rerun": {
          "type": ["string", "null"],
          "description": "The `rerun:` line: the CLI's, `proptastic run --only='<id>' --seed=0x…`, when `PROPTASTIC_COMMANDS=proptastic` (decision 63), else the host's own; `null` where proptastic doesn't know the host's command, or the chain fixes the seed."
        },
        "assertion": {
          "type": ["string", "null"],
          "description": "The check's own message, untouched, or `null` when it had none."
        },
        "location": {
          "oneOf": [{ "$ref": "#/$defs/location" }, { "type": "null" }],
          "description": "Where the check failed, in the test's own source, or `null` where that isn't known."
        },
        "statistics": { "$ref": "#/$defs/statistics" },
        "sizes": { "$ref": "#/$defs/sizes" },
        "durationMs": { "$ref": "#/$defs/durationMs" },
        "rendered": {
          "type": "string",
          "description": "proptastic's report, as the failure prints it after the check's message."
        }
      }
    },
    "runFailed": {
      "type": "object",
      "description": "The CLI couldn't do what it was asked, and exits with `exitCode`: the last line of its output under `--format=agent` or `jsonl`, with the same words as the error on stderr (decision 59).",
      "required": ["schema", "reason", "code", "message", "help", "exitCode", "rendered"],
      "properties": {
        "schema": { "$ref": "#/$defs/schema" },
        "edition": {
          "$ref": "#/$defs/edition",
          "description": "The edition the CLI chose for the project, by `--edition` or from what it found there. Absent when the CLI failed before it chose one, as for a mistake in the command or no project found: then no edition was involved (decision 68)."
        },
        "reason": { "const": "run-failed" },
        "code": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]*$",
          "description": "The kind of failure, one of the contract's `errors`, such as `unknown-option` or `ci-refused`. A later v1 may add a code: treat one you don't know as `other`."
        },
        "message": {
          "type": "string",
          "description": "The error's first line, without `proptastic: `."
        },
        "help": {
          "type": "array",
          "description": "The commands the error ends in, in its order. Empty when it offers none.",
          "items": {
            "type": "object",
            "required": ["command", "applicability"],
            "properties": {
              "command": { "type": "string" },
              "applicability": {
                "enum": ["exact", "placeholders", "maybe"],
                "description": "`exact`: it runs as it is. `placeholders`: a part in `<…>` is to be filled in first. `maybe`: a close name, to check before running it."
              }
            }
          }
        },
        "exitCode": { "type": "integer", "minimum": 1 },
        "rendered": {
          "type": "string",
          "description": "The error as stderr has it, every line, `proptastic: ` first."
        }
      }
    },
    "runStarted": {
      "type": "object",
      "description": "The CLI started the host's test runner: the first line of `run --format=jsonl` (decision 73).",
      "required": ["schema", "reason", "edition", "project", "host", "command", "chosen"],
      "properties": {
        "schema": { "$ref": "#/$defs/schema" },
        "edition": { "$ref": "#/$defs/edition" },
        "reason": { "const": "run-started" },
        "project": {
          "type": "string",
          "description": "The project's directory, absolute."
        },
        "host": {
          "enum": ["gradle", "maven"],
          "description": "The build tool whose test runner runs the properties, as the edition's `hosts` binding (E19) names it. Within v1 a host may be added."
        },
        "command": {
          "type": "string",
          "description": "The command the CLI ran, as a person would type it from where the CLI was run."
        },
        "chosen": {
          "type": ["array", "null"],
          "items": { "type": "string" },
          "description": "The properties chosen, by the manifest's ids; `null` on a first run, which runs every test to register the properties (decision 50)."
        }
      }
    },
    "runFinished": {
      "type": "object",
      "description": "The run finished, and the CLI exits with `exitCode`: the last line of `run --format=jsonl` when nothing stopped it (decision 73).",
      "required": ["schema", "reason", "edition", "passed", "failed", "missing", "registered", "overridden", "warnings", "durationMs", "exitCode"],
      "properties": {
        "schema": { "$ref": "#/$defs/schema" },
        "edition": { "$ref": "#/$defs/edition" },
        "reason": { "const": "run-finished" },
        "passed": { "type": "integer", "minimum": 0, "description": "The properties that passed." },
        "failed": { "type": "integer", "minimum": 0, "description": "The properties that failed." },
        "missing": {
          "type": "array",
          "items": { "type": "string" },
          "description": "The properties chosen that wrote no event, by the manifest's ids: they didn't run."
        },
        "registered": {
          "type": ["integer", "null"],
          "minimum": 0,
          "description": "On a first run, how many properties the manifests have now; `null` on a later run."
        },
        "overridden": {
          "type": "array",
          "description": "Each setting asked for that the properties ran without, as the human formats' `!` lines say it (decision 49).",
          "items": {
            "type": "object",
            "required": ["setting", "option", "asked", "ran", "by", "properties"],
            "properties": {
              "setting": { "enum": ["seed", "tries", "profile"], "description": "The setting, as its variable's name ends." },
              "option": { "type": "string", "description": "The option as typed: `--tries=50`, or `--replay`." },
              "asked": { "type": "string", "description": "What the option asked for." },
              "ran": { "type": "string", "description": "What the properties ran with instead." },
              "by": {
                "enum": ["build", "chain"],
                "description": "`build`: the build's own setting won (Java's system property, E1); `chain`: the property's chain fixes it, as `.seed(…)` does."
              },
              "properties": {
                "type": "array",
                "items": { "type": "string" },
                "description": "The properties that ran with it, by the manifest's ids."
              }
            }
          }
        },
        "warnings": {
          "type": "array",
          "items": { "type": "string" },
          "description": "What else the person should know, as the human formats' `!` lines say it: a class that calls `forAll` and that the host doesn't run, as Surefire doesn't run a `*Properties` class by default."
        },
        "reports": {
          "type": "array",
          "items": { "type": "string" },
          "description": "The reports the run wrote (decision 76), each file as typed from where the CLI was run; empty with `--report=none`. Absent from a CLI before decision 76."
        },
        "incomplete": {
          "type": "array",
          "items": { "type": "string" },
          "description": "The properties that passed with a `require` label their tries couldn't tell (decision 107), by the manifest's ids; absent when there are none, and from a CLI before decision 107."
        },
        "durationMs": { "$ref": "#/$defs/durationMs" },
        "exitCode": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1,
          "description": "0 every property passed, 1 one failed: the CLI's exit. A run that can't finish ends in `run-failed` instead."
        }
      }
    }
  }
}
