eval-quality 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +355 -0
- package/corpus/dev/README.md +36 -0
- package/corpus/dev/compile-seal-example/brief.json +1 -0
- package/corpus/dev/compile-seal-example/contract.json +1 -0
- package/corpus/dev/contracts/absent-collection-locations.json +1 -0
- package/corpus/dev/contracts/absent-sibling-groups.json +1 -0
- package/corpus/dev/contracts/absent-success-indicator.json +1 -0
- package/corpus/dev/contracts/empty-channel-roles.json +1 -0
- package/corpus/dev/contracts/empty-collection-locations.json +1 -0
- package/corpus/dev/contracts/empty-request-shapes.json +1 -0
- package/corpus/dev/contracts/empty-sibling-groups.json +1 -0
- package/corpus/dev/contracts/no-collection-quantifier.json +1 -0
- package/corpus/dev/contracts/no-operation-inventory.json +1 -0
- package/corpus/dev/contracts/no-read-back-relation.json +1 -0
- package/corpus/dev/contracts/no-state-change-marker.json +1 -0
- package/corpus/dev/contracts/no-type-violating-step.json +1 -0
- package/corpus/dev/contracts/per-key-split-oracles.json +1 -0
- package/corpus/dev/contracts/satisfied-declarations.json +1 -0
- package/corpus/dev/contracts/single-required-response-key.json +1 -0
- package/corpus/dev/contracts/split-indicator-oracle.json +1 -0
- package/corpus/dev/contracts/unaddressed-parameter-sibling.json +1 -0
- package/corpus/dev/contracts/unnamed-reference-set.json +1 -0
- package/corpus/dev/contracts/wrong-cardinality-form.json +1 -0
- package/corpus/dev/index.json +1 -0
- package/dist/adapters/index.d.ts +12 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/local-corpus-adapter.d.ts +7 -0
- package/dist/adapters/local-corpus-adapter.js +78 -0
- package/dist/adapters/node-file-system-adapter.d.ts +7 -0
- package/dist/adapters/node-file-system-adapter.js +39 -0
- package/dist/adapters/port-boundary.d.ts +18 -0
- package/dist/adapters/port-boundary.js +83 -0
- package/dist/adapters/system-clock-adapter.d.ts +10 -0
- package/dist/adapters/system-clock-adapter.js +18 -0
- package/dist/application/compile.d.ts +4 -0
- package/dist/application/compile.js +24 -0
- package/dist/application/diagnostics.d.ts +22 -0
- package/dist/application/diagnostics.js +18 -0
- package/dist/application/index.d.ts +23 -0
- package/dist/application/index.js +17 -0
- package/dist/application/invoke-port.d.ts +2 -0
- package/dist/application/invoke-port.js +45 -0
- package/dist/application/preflight.d.ts +27 -0
- package/dist/application/preflight.js +131 -0
- package/dist/application/seal.d.ts +4 -0
- package/dist/application/seal.js +28 -0
- package/dist/application/serialize.d.ts +6 -0
- package/dist/application/serialize.js +9 -0
- package/dist/cli/arguments.d.ts +28 -0
- package/dist/cli/arguments.js +167 -0
- package/dist/cli/exit-codes.d.ts +36 -0
- package/dist/cli/exit-codes.js +39 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +143 -0
- package/dist/cli/render.d.ts +26 -0
- package/dist/cli/render.js +53 -0
- package/dist/cli/run.d.ts +41 -0
- package/dist/cli/run.js +203 -0
- package/dist/core/canonical/canonicalize.d.ts +1 -0
- package/dist/core/canonical/canonicalize.js +113 -0
- package/dist/core/canonical/digest.d.ts +7 -0
- package/dist/core/canonical/digest.js +81 -0
- package/dist/core/canonical/scan-json.d.ts +1 -0
- package/dist/core/canonical/scan-json.js +298 -0
- package/dist/core/canonical/value-domain.d.ts +4 -0
- package/dist/core/canonical/value-domain.js +113 -0
- package/dist/core/compile/compile.d.ts +24 -0
- package/dist/core/compile/compile.js +67 -0
- package/dist/core/compile/declarations.d.ts +5 -0
- package/dist/core/compile/declarations.js +22 -0
- package/dist/core/compile/expression-legality.d.ts +14 -0
- package/dist/core/compile/expression-legality.js +346 -0
- package/dist/core/compile/forbidden-inputs.d.ts +5 -0
- package/dist/core/compile/forbidden-inputs.js +19 -0
- package/dist/core/compile/interface-inventory.d.ts +10 -0
- package/dist/core/compile/interface-inventory.js +55 -0
- package/dist/core/compile/oracle-alignment.d.ts +14 -0
- package/dist/core/compile/oracle-alignment.js +93 -0
- package/dist/core/compile/reachability.d.ts +17 -0
- package/dist/core/compile/reachability.js +177 -0
- package/dist/core/compile/rubrics.d.ts +55 -0
- package/dist/core/compile/rubrics.js +198 -0
- package/dist/core/compile/scripting-bound.d.ts +5 -0
- package/dist/core/compile/scripting-bound.js +151 -0
- package/dist/core/compile/sensitivity-witness.d.ts +73 -0
- package/dist/core/compile/sensitivity-witness.js +232 -0
- package/dist/core/compile/waivers.d.ts +3 -0
- package/dist/core/compile/waivers.js +21 -0
- package/dist/core/coverage/coverage.d.ts +18 -0
- package/dist/core/coverage/coverage.js +47 -0
- package/dist/core/coverage/relevance.d.ts +75 -0
- package/dist/core/coverage/relevance.js +186 -0
- package/dist/core/coverage/rules.d.ts +7 -0
- package/dist/core/coverage/rules.js +18 -0
- package/dist/core/coverage/satisfaction.d.ts +107 -0
- package/dist/core/coverage/satisfaction.js +415 -0
- package/dist/core/coverage/table.d.ts +26 -0
- package/dist/core/coverage/table.js +222 -0
- package/dist/core/declared-inputs.d.ts +16 -0
- package/dist/core/declared-inputs.js +18 -0
- package/dist/core/evaluate/evidence-resolution.d.ts +54 -0
- package/dist/core/evaluate/evidence-resolution.js +153 -0
- package/dist/core/evaluate/operators.d.ts +87 -0
- package/dist/core/evaluate/operators.js +350 -0
- package/dist/core/evaluate/resolution.d.ts +40 -0
- package/dist/core/evaluate/resolution.js +336 -0
- package/dist/core/evaluate/resolved-value.d.ts +9 -0
- package/dist/core/evaluate/resolved-value.js +6 -0
- package/dist/core/failure-codes.d.ts +18 -0
- package/dist/core/failure-codes.js +50 -0
- package/dist/core/lineage/chain.d.ts +49 -0
- package/dist/core/lineage/chain.js +210 -0
- package/dist/core/lineage/freeze.d.ts +12 -0
- package/dist/core/lineage/freeze.js +35 -0
- package/dist/core/lineage/stage-table.d.ts +43 -0
- package/dist/core/lineage/stage-table.js +106 -0
- package/dist/core/preflight/plan.d.ts +67 -0
- package/dist/core/preflight/plan.js +313 -0
- package/dist/core/preflight/projection.d.ts +40 -0
- package/dist/core/preflight/projection.js +96 -0
- package/dist/core/preflight/reduce.d.ts +8 -0
- package/dist/core/preflight/reduce.js +180 -0
- package/dist/core/preflight/witness-evidence.d.ts +42 -0
- package/dist/core/preflight/witness-evidence.js +88 -0
- package/dist/core/probe/target-policy.d.ts +63 -0
- package/dist/core/probe/target-policy.js +328 -0
- package/dist/core/schemas/artifact-reference.d.ts +19 -0
- package/dist/core/schemas/artifact-reference.js +30 -0
- package/dist/core/schemas/artifact.d.ts +1153 -0
- package/dist/core/schemas/artifact.js +84 -0
- package/dist/core/schemas/constraint-ledger.d.ts +57 -0
- package/dist/core/schemas/constraint-ledger.js +143 -0
- package/dist/core/schemas/eval-contract.d.ts +402 -0
- package/dist/core/schemas/eval-contract.js +147 -0
- package/dist/core/schemas/evaluator-configuration.d.ts +37 -0
- package/dist/core/schemas/evaluator-configuration.js +43 -0
- package/dist/core/schemas/evidence-artifact.d.ts +471 -0
- package/dist/core/schemas/evidence-artifact.js +232 -0
- package/dist/core/schemas/expression.d.ts +197 -0
- package/dist/core/schemas/expression.js +284 -0
- package/dist/core/schemas/faults.d.ts +9 -0
- package/dist/core/schemas/faults.js +32 -0
- package/dist/core/schemas/interface.d.ts +417 -0
- package/dist/core/schemas/interface.js +115 -0
- package/dist/core/schemas/isolation-manifest.d.ts +136 -0
- package/dist/core/schemas/isolation-manifest.js +92 -0
- package/dist/core/schemas/lineage.d.ts +21 -0
- package/dist/core/schemas/lineage.js +28 -0
- package/dist/core/schemas/oracle.d.ts +72 -0
- package/dist/core/schemas/oracle.js +35 -0
- package/dist/core/schemas/plan.d.ts +115 -0
- package/dist/core/schemas/plan.js +58 -0
- package/dist/core/schemas/pointer.d.ts +63 -0
- package/dist/core/schemas/pointer.js +94 -0
- package/dist/core/schemas/port-messages.d.ts +103 -0
- package/dist/core/schemas/port-messages.js +90 -0
- package/dist/core/schemas/preflight-verdict.d.ts +60 -0
- package/dist/core/schemas/preflight-verdict.js +38 -0
- package/dist/core/schemas/primitives.d.ts +78 -0
- package/dist/core/schemas/primitives.js +121 -0
- package/dist/core/schemas/private-artifact-manifest.d.ts +56 -0
- package/dist/core/schemas/private-artifact-manifest.js +46 -0
- package/dist/core/schemas/probe-body.d.ts +25 -0
- package/dist/core/schemas/probe-body.js +23 -0
- package/dist/core/schemas/probe-policy.d.ts +76 -0
- package/dist/core/schemas/probe-policy.js +33 -0
- package/dist/core/schemas/probe.d.ts +189 -0
- package/dist/core/schemas/probe.js +82 -0
- package/dist/core/schemas/publish.d.ts +30 -0
- package/dist/core/schemas/publish.js +135 -0
- package/dist/core/schemas/reference-set.d.ts +18 -0
- package/dist/core/schemas/reference-set.js +27 -0
- package/dist/core/schemas/rubric.d.ts +62 -0
- package/dist/core/schemas/rubric.js +68 -0
- package/dist/core/schemas/scoring-policy.d.ts +28 -0
- package/dist/core/schemas/scoring-policy.js +51 -0
- package/dist/core/schemas/sealed-evaluator-brief.d.ts +80 -0
- package/dist/core/schemas/sealed-evaluator-brief.js +59 -0
- package/dist/core/schemas/sealed-run-record.d.ts +382 -0
- package/dist/core/schemas/sealed-run-record.js +215 -0
- package/dist/core/schemas/sensitivity-witness.d.ts +138 -0
- package/dist/core/schemas/sensitivity-witness.js +86 -0
- package/dist/core/schemas/verdict.d.ts +25 -0
- package/dist/core/schemas/verdict.js +20 -0
- package/dist/core/schemas/waiver.d.ts +17 -0
- package/dist/core/schemas/waiver.js +24 -0
- package/dist/core/seal/derived-reference.d.ts +36 -0
- package/dist/core/seal/derived-reference.js +383 -0
- package/dist/core/seal/direction-prose.d.ts +13 -0
- package/dist/core/seal/direction-prose.js +120 -0
- package/dist/core/seal/plan-index.d.ts +63 -0
- package/dist/core/seal/plan-index.js +155 -0
- package/dist/core/seal/scripting-audit.d.ts +15 -0
- package/dist/core/seal/scripting-audit.js +51 -0
- package/dist/core/seal/seal.d.ts +18 -0
- package/dist/core/seal/seal.js +155 -0
- package/dist/core/stage-contracts.d.ts +30 -0
- package/dist/core/stage-contracts.js +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +22 -0
- package/dist/ports/clock-port.d.ts +13 -0
- package/dist/ports/clock-port.js +7 -0
- package/dist/ports/corpus-port.d.ts +16 -0
- package/dist/ports/corpus-port.js +7 -0
- package/dist/ports/environment-probe-port.d.ts +76 -0
- package/dist/ports/environment-probe-port.js +32 -0
- package/dist/ports/file-system-port.d.ts +27 -0
- package/dist/ports/file-system-port.js +11 -0
- package/dist/ports/port.d.ts +33 -0
- package/dist/ports/port.js +14 -0
- package/dist/testing/conformance.d.ts +88 -0
- package/dist/testing/conformance.js +281 -0
- package/dist/testing/index.d.ts +26 -0
- package/dist/testing/index.js +18 -0
- package/dist/testing/probe-conformance.d.ts +45 -0
- package/dist/testing/probe-conformance.js +186 -0
- package/package.json +130 -0
- package/schemas/artifact-reference.schema.json +64 -0
- package/schemas/eval-contract.schema.json +2145 -0
- package/schemas/evaluator-configuration.schema.json +199 -0
- package/schemas/evidence-artifact.schema.json +1229 -0
- package/schemas/isolation-manifest.schema.json +394 -0
- package/schemas/preflight-verdict.schema.json +114 -0
- package/schemas/private-artifact-manifest.schema.json +103 -0
- package/schemas/probe.schema.json +1151 -0
- package/schemas/rubric.schema.json +148 -0
- package/schemas/scoring-policy.schema.json +90 -0
- package/schemas/sealed-evaluator-brief.schema.json +268 -0
- package/schemas/sealed-run-record.schema.json +875 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/** the operand union and the recursive check expression tree. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { EvidencePointer } from './pointer.js';
|
|
4
|
+
import { Identifier, JsonValue, KeyedShapeDescriptor, KeyName, } from './primitives.js';
|
|
5
|
+
// AD-26: each operand form is a single-keyed object, and the reference-set
|
|
6
|
+
// form carries nothing else. Enforced structurally: a two-key spelling would
|
|
7
|
+
// validate against more than one operand form.
|
|
8
|
+
export const PointerOperand = z.strictObject({ pointer: EvidencePointer });
|
|
9
|
+
export const LiteralOperand = z.strictObject({ literal: JsonValue });
|
|
10
|
+
export const ReferenceSetOperand = z.strictObject({
|
|
11
|
+
referenceSet: Identifier.describe("A plain identifier. Deliberately not an enum of the contract's declared reference sets and deliberately not refined against them: an identifier the contract does not declare is `unresolved-reference-set`, a coded compile-time error, and a schema that rejected it would convert that code into an anonymous parse fault."),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Every tuple position takes this full union. Per-position operand legality is
|
|
15
|
+
* the compiler's: AD-26 makes a reference-set operand outside its three legal
|
|
16
|
+
* positions fire `malformed-operator-expression`, which only stays fireable if
|
|
17
|
+
* the other positions admit it.
|
|
18
|
+
*/
|
|
19
|
+
export const Operand = z
|
|
20
|
+
.union([PointerOperand, LiteralOperand, ReferenceSetOperand])
|
|
21
|
+
.meta({
|
|
22
|
+
id: 'Operand',
|
|
23
|
+
description: "One of the three operand forms, each a single-keyed object. Named so the published schema carries it once as a shared definition rather than inlining it at seventeen use sites. Which forms are legal in which position is declared on each operator's own `operands`, never narrowed here.",
|
|
24
|
+
});
|
|
25
|
+
// Coin flip (b), settled: AD-26 restricts only the *reference-set* operand's
|
|
26
|
+
// legal positions and is silent on literals, and Gate C's state oracle needs
|
|
27
|
+
// the four-value enum ["queued","running","succeeded","failed"], which has no
|
|
28
|
+
// business being a declared reference set.
|
|
29
|
+
export const LiteralSetOperand = z.strictObject({
|
|
30
|
+
literal: z
|
|
31
|
+
.array(JsonValue)
|
|
32
|
+
.min(1)
|
|
33
|
+
.describe('Coin flip (b), settled: a literal set operand is admitted alongside the reference-set form, and is constrained to a non-empty array because `set-membership` against an empty set is unfalsifiable authoring rather than an observation about the world. This is the one deliberately narrowed operand position in the grammar; the cost is that `{ "literal": [] }` and a `{ "pointer" }` in this position are schema rejections rather than `malformed-operator-expression`.'),
|
|
34
|
+
});
|
|
35
|
+
export const SetOperand = z.union([ReferenceSetOperand, LiteralSetOperand]);
|
|
36
|
+
/** AD-33: one polarity per check, and one on the direction it must align with. */
|
|
37
|
+
export const Polarity = z.enum(['expects-hold', 'expects-violation']);
|
|
38
|
+
export const SortOrder = z.enum(['ascending', 'descending']);
|
|
39
|
+
/** AD-4's eleven operators. */
|
|
40
|
+
export const OPERATOR_NAMES = [
|
|
41
|
+
'equality',
|
|
42
|
+
'deep-equality',
|
|
43
|
+
'containment',
|
|
44
|
+
'existence',
|
|
45
|
+
'absence',
|
|
46
|
+
'regex',
|
|
47
|
+
'set-membership',
|
|
48
|
+
'ordering',
|
|
49
|
+
'count-tolerance',
|
|
50
|
+
'shape',
|
|
51
|
+
'covers-by-key',
|
|
52
|
+
];
|
|
53
|
+
/** AD-4's three connectives. */
|
|
54
|
+
export const CONNECTIVE_NAMES = ['all', 'any', 'not'];
|
|
55
|
+
/** AD-4's two collection quantifiers. */
|
|
56
|
+
export const QUANTIFIER_NAMES = ['for-all', 'for-any'];
|
|
57
|
+
/**
|
|
58
|
+
* The sixteen-member vocabulary a direction's relation is drawn from. AD-3
|
|
59
|
+
* fixes it as "AD-4's operator set", read as all sixteen: seven of the eight
|
|
60
|
+
* Gate C oracles declare `all`, `not`, or `for-all` as their relation (only
|
|
61
|
+
* O-001 is a bare operator, `deep-equality`), so narrowing this to the eleven
|
|
62
|
+
* operators alone would fail the primary accept fixture on seven of eight.
|
|
63
|
+
*/
|
|
64
|
+
export const RELATION_VOCABULARY = [
|
|
65
|
+
...OPERATOR_NAMES,
|
|
66
|
+
...CONNECTIVE_NAMES,
|
|
67
|
+
...QUANTIFIER_NAMES,
|
|
68
|
+
];
|
|
69
|
+
export const Relation = z.enum(RELATION_VOCABULARY);
|
|
70
|
+
// AD-4 calls the regex dialect "always fully anchored" and codes only
|
|
71
|
+
// backreferences and lookbehind, so anchoring is the schema's half; the
|
|
72
|
+
// rejected constructs are the compiler's. See `AnchoredPattern`'s
|
|
73
|
+
// description for the verified false-accept and false-reject cases this
|
|
74
|
+
// positional check produces.
|
|
75
|
+
export const ANCHORING_RESIDUAL = 'positional check: admits an unanchored alternation, rejects an anchored pattern wrapped in a group';
|
|
76
|
+
export const ANCHORED_PATTERN_FORM = /^\^[\s\S]*\$$/;
|
|
77
|
+
export const AnchoredPattern = z
|
|
78
|
+
.string()
|
|
79
|
+
.regex(ANCHORED_PATTERN_FORM)
|
|
80
|
+
.describe('An ECMA-262 pattern, fully anchored: it begins with "^" and ends with "$". A named field rather than a `{ literal }` operand, so the compiler\'s backreference and lookbehind check has one place to look instead of a JsonValue that may hold anything. The check is positional and is wrong in both directions. It admits patterns that are not anchored, such as the alternation "^a|b$" or a trailing "$" that is escaped; those are the compiler\'s, alongside backreferences and lookbehind. It also rejects patterns that are anchored but wrapped in a group, such as "(^a$)" — write "^(?:a|b)$" rather than "(?:^a$|^b$)" and the form accepts it. Deciding anchoring properly requires parsing the pattern, which no JSON Schema keyword can express.');
|
|
81
|
+
/**
|
|
82
|
+
* The minimum operand count for `all` and `any`, settled here because AD-4
|
|
83
|
+
* leaves connective arity unstated. Zero would certify vacuously, the
|
|
84
|
+
* fail-open shape AD-4's three-valued resolution guards against; one is the
|
|
85
|
+
* identity; and two spellings of one tree would defeat the structural
|
|
86
|
+
* containment AD-3's alignment predicate computes, hence a floor of two.
|
|
87
|
+
*/
|
|
88
|
+
export const CONNECTIVE_MINIMUM_ARITY = 2;
|
|
89
|
+
/**
|
|
90
|
+
* Every expression form whose operands are a fixed-length tuple, with its
|
|
91
|
+
* arity. `not` is here because its one operand is a nested `Expression`, not
|
|
92
|
+
* the `Operand` union; `all`, `any`, `for-all`, and `for-any` are excluded
|
|
93
|
+
* because their operand counts are variable or their operands are named
|
|
94
|
+
* fields.
|
|
95
|
+
*
|
|
96
|
+
* The constraint ledger is built from this table so the two cannot drift; a
|
|
97
|
+
* test asserts each entry against what the schema actually rejects.
|
|
98
|
+
*/
|
|
99
|
+
export const TUPLE_ARITY = {
|
|
100
|
+
equality: 2,
|
|
101
|
+
'deep-equality': 2,
|
|
102
|
+
containment: 2,
|
|
103
|
+
existence: 1,
|
|
104
|
+
absence: 1,
|
|
105
|
+
regex: 1,
|
|
106
|
+
'set-membership': 2,
|
|
107
|
+
ordering: 1,
|
|
108
|
+
'count-tolerance': 1,
|
|
109
|
+
shape: 1,
|
|
110
|
+
'covers-by-key': 2,
|
|
111
|
+
not: 1,
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* `check` is a recursive discriminated union on `op`. Arity is enforced as
|
|
115
|
+
* fixed-length tuples, the one deliberate exception to the admit-rule (AD-13
|
|
116
|
+
* verified constraint injection specifically for arity), so
|
|
117
|
+
* `malformed-operator-expression`'s arity limb is schema-covered in v0; its
|
|
118
|
+
* live limbs are the rejected regex constructs and the operand-type
|
|
119
|
+
* violations the schema deliberately does not narrow.
|
|
120
|
+
*
|
|
121
|
+
* Carries `.meta({ id })` for the same reason `JsonValue` does: without it
|
|
122
|
+
* the tree exports as a generated `$defs.__schema0`, pinning a positional
|
|
123
|
+
* name into the published-schema drift check and leaving the ledger's twelve
|
|
124
|
+
* arity entries with no stable address.
|
|
125
|
+
*/
|
|
126
|
+
export const Expression = z
|
|
127
|
+
.lazy(() => z.discriminatedUnion('op', [
|
|
128
|
+
Equality,
|
|
129
|
+
DeepEquality,
|
|
130
|
+
Containment,
|
|
131
|
+
Existence,
|
|
132
|
+
Absence,
|
|
133
|
+
RegexMatch,
|
|
134
|
+
SetMembership,
|
|
135
|
+
Ordering,
|
|
136
|
+
CountTolerance,
|
|
137
|
+
Shape,
|
|
138
|
+
CoversByKey,
|
|
139
|
+
Not,
|
|
140
|
+
All,
|
|
141
|
+
Any,
|
|
142
|
+
ForAll,
|
|
143
|
+
ForAny,
|
|
144
|
+
]))
|
|
145
|
+
.meta({
|
|
146
|
+
id: 'Expression',
|
|
147
|
+
description: "A `check` expression tree over AD-4's closed vocabulary, discriminated on `op`. Exports as a `oneOf` of sixteen branches, each identified by its `op` const; a constraint ledger entry names a branch by that const rather than by position.",
|
|
148
|
+
});
|
|
149
|
+
// AD-4 requires each operator to declare "a fixed arity and operand types in
|
|
150
|
+
// the published schema". Arity is structural, as fixed-length tuples; operand
|
|
151
|
+
// types cannot be, since narrowing a position would delete
|
|
152
|
+
// `malformed-operator-expression`'s operand-type limb. The types are
|
|
153
|
+
// therefore declared here in text that survives the export, and the compiler
|
|
154
|
+
// enforces what the text says. AD-36's numeric domain gets the same
|
|
155
|
+
// treatment on `JsonValue`: a note in an internal document does not satisfy
|
|
156
|
+
// a requirement to express something in the published schema.
|
|
157
|
+
const ADMIT_RULE = "Every position admits the full operand union on purpose. AD-26 makes a reference-set operand outside its three legal positions — `covers-by-key`'s expected operand, and the set operand of `set-membership` or `containment` — fail compilation under `malformed-operator-expression`, which only stays fireable if the other positions admit it. Compilation enforces the legality stated here; the schema does not narrow it.";
|
|
158
|
+
const operandTypes = (statement) => `${statement} ${ADMIT_RULE}`;
|
|
159
|
+
const Equality = z.strictObject({
|
|
160
|
+
op: z.literal('equality'),
|
|
161
|
+
operands: z
|
|
162
|
+
.tuple([Operand, Operand])
|
|
163
|
+
.describe(operandTypes('Two operands, each legally a pointer or a literal.')),
|
|
164
|
+
});
|
|
165
|
+
const DeepEquality = z.strictObject({
|
|
166
|
+
op: z.literal('deep-equality'),
|
|
167
|
+
operands: z
|
|
168
|
+
.tuple([Operand, Operand])
|
|
169
|
+
.describe(operandTypes('Two operands, each legally a pointer or a literal.')),
|
|
170
|
+
});
|
|
171
|
+
const Containment = z.strictObject({
|
|
172
|
+
op: z.literal('containment'),
|
|
173
|
+
operands: z
|
|
174
|
+
.tuple([Operand, Operand])
|
|
175
|
+
.describe(operandTypes('Two operands: the container is legally a pointer, and the set is legally a pointer, a literal, or a reference set.')),
|
|
176
|
+
});
|
|
177
|
+
const Existence = z.strictObject({
|
|
178
|
+
op: z.literal('existence'),
|
|
179
|
+
operands: z
|
|
180
|
+
.tuple([Operand])
|
|
181
|
+
.describe(operandTypes('One operand, legally a pointer.')),
|
|
182
|
+
});
|
|
183
|
+
const Absence = z.strictObject({
|
|
184
|
+
op: z.literal('absence'),
|
|
185
|
+
operands: z
|
|
186
|
+
.tuple([Operand])
|
|
187
|
+
.describe(operandTypes('One operand, legally a pointer.')),
|
|
188
|
+
});
|
|
189
|
+
const RegexMatch = z.strictObject({
|
|
190
|
+
op: z.literal('regex'),
|
|
191
|
+
operands: z
|
|
192
|
+
.tuple([Operand])
|
|
193
|
+
.describe(operandTypes('One operand, legally a pointer.')),
|
|
194
|
+
pattern: AnchoredPattern,
|
|
195
|
+
});
|
|
196
|
+
const SetMembership = z.strictObject({
|
|
197
|
+
op: z.literal('set-membership'),
|
|
198
|
+
operands: z
|
|
199
|
+
.tuple([Operand, SetOperand])
|
|
200
|
+
.describe(operandTypes('Two operands: the value is legally a pointer, and the set is a reference set or a non-empty literal array. The set position is the one place the schema does narrow, and coin flip (b) records what that costs.')),
|
|
201
|
+
});
|
|
202
|
+
// Arity settled here: a collection pointer plus a named key and a named
|
|
203
|
+
// order. A pairwise reading (pointer a precedes pointer b) was considered and
|
|
204
|
+
// rejected: it cannot express "this page is sorted by capturedAt," the only
|
|
205
|
+
// thing AD-4 says `ordering` is for, and `core/evaluate` inherits that
|
|
206
|
+
// semantics.
|
|
207
|
+
const Ordering = z.strictObject({
|
|
208
|
+
op: z.literal('ordering'),
|
|
209
|
+
operands: z
|
|
210
|
+
.tuple([Operand])
|
|
211
|
+
.describe(operandTypes('One operand, legally a pointer to a collection.')),
|
|
212
|
+
key: KeyName,
|
|
213
|
+
order: SortOrder,
|
|
214
|
+
});
|
|
215
|
+
const CountTolerance = z.strictObject({
|
|
216
|
+
op: z.literal('count-tolerance'),
|
|
217
|
+
operands: z
|
|
218
|
+
.tuple([Operand])
|
|
219
|
+
.describe(operandTypes('One operand, legally a pointer to a collection.')),
|
|
220
|
+
expected: z
|
|
221
|
+
.int()
|
|
222
|
+
.min(0)
|
|
223
|
+
.describe('The expected element count. Non-negative: a negative count is not a count, and no AD-5 code fires on one, so the schema is the enforcement point.'),
|
|
224
|
+
tolerance: z
|
|
225
|
+
.int()
|
|
226
|
+
.min(0)
|
|
227
|
+
.describe('The permitted deviation from `expected`, non-negative for the same reason. When `relative` is declared the tolerance is read as whole percentage points, which is stated because AD-4 supplies no value space for the magnitude and any reader that resolves this check inherits the semantics. An integer therefore cannot express a fractional relative tolerance such as 2.5 percent; widening the value space later is an additive `schemaVersion` bump under AD-11, and was not taken here because it would export as a bare `type: "number"` and cost a constraint ledger entry for a case no declaration needs yet.'),
|
|
228
|
+
relative: z
|
|
229
|
+
.boolean()
|
|
230
|
+
.describe('AD-4: the tolerance is absolute unless this flag is declared. Required and explicit rather than defaulted, because a Zod default diverges input and output mode and drops the key from the exported `required` list.'),
|
|
231
|
+
});
|
|
232
|
+
const Shape = z.strictObject({
|
|
233
|
+
op: z.literal('shape'),
|
|
234
|
+
operands: z
|
|
235
|
+
.tuple([Operand])
|
|
236
|
+
.describe(operandTypes('One operand, legally a pointer.')),
|
|
237
|
+
descriptor: KeyedShapeDescriptor.describe('AD-4: a closed descriptor, never an embedded JSON Schema. Typing it as a named field is what makes that structural, and it is a deliberate divergence from the Gate C fixture\'s `{ "literal": { … } }` spelling, where any JSON could sit.'),
|
|
238
|
+
});
|
|
239
|
+
const CoversByKey = z.strictObject({
|
|
240
|
+
op: z.literal('covers-by-key'),
|
|
241
|
+
operands: z
|
|
242
|
+
.tuple([Operand, Operand])
|
|
243
|
+
.describe(operandTypes('Two operands: `expected` is legally a reference set, and `actual` is legally a pointer to a collection.')),
|
|
244
|
+
expectedKey: KeyName,
|
|
245
|
+
actualKey: KeyName,
|
|
246
|
+
});
|
|
247
|
+
const Not = z.strictObject({
|
|
248
|
+
op: z.literal('not'),
|
|
249
|
+
operands: z
|
|
250
|
+
.tuple([Expression])
|
|
251
|
+
.describe('One nested expression rather than an operand. A connective composes the tree; it never addresses evidence itself.'),
|
|
252
|
+
});
|
|
253
|
+
const All = z.strictObject({
|
|
254
|
+
op: z.literal('all'),
|
|
255
|
+
operands: z
|
|
256
|
+
.array(Expression)
|
|
257
|
+
.min(CONNECTIVE_MINIMUM_ARITY)
|
|
258
|
+
.describe('Two or more nested expressions rather than operands. The minimum is settled here because AD-4 leaves connective arity unstated: zero operands would certify vacuously and one is the identity.'),
|
|
259
|
+
});
|
|
260
|
+
const Any = z.strictObject({
|
|
261
|
+
op: z.literal('any'),
|
|
262
|
+
operands: z
|
|
263
|
+
.array(Expression)
|
|
264
|
+
.min(CONNECTIVE_MINIMUM_ARITY)
|
|
265
|
+
.describe('Two or more nested expressions rather than operands, for the same reason `all` carries the same minimum.'),
|
|
266
|
+
});
|
|
267
|
+
// A quantifier inside a quantifier, and `covers-by-key` inside one, are both
|
|
268
|
+
// structurally admitted on purpose. A quantifier-free predicate type would be
|
|
269
|
+
// elegant and would delete `quantifier-nesting-exceeded` from the compiler
|
|
270
|
+
// along with its fixture.
|
|
271
|
+
const ForAll = z
|
|
272
|
+
.strictObject({
|
|
273
|
+
op: z.literal('for-all'),
|
|
274
|
+
collection: Operand,
|
|
275
|
+
predicate: Expression,
|
|
276
|
+
})
|
|
277
|
+
.describe(operandTypes('`collection` is legally a pointer to a collection, and `predicate` is the expression each bound element is tested against, addressed by the `@/` pointer spelling. A quantifier inside the predicate is structurally admitted so `quantifier-nesting-exceeded` keeps a shape to fire on.'));
|
|
278
|
+
const ForAny = z
|
|
279
|
+
.strictObject({
|
|
280
|
+
op: z.literal('for-any'),
|
|
281
|
+
collection: Operand,
|
|
282
|
+
predicate: Expression,
|
|
283
|
+
})
|
|
284
|
+
.describe(operandTypes('`collection` is legally a pointer to a collection, and `predicate` is the expression each bound element is tested against, addressed by the `@/` pointer spelling.'));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const RUNTIME_FAULT_CODES: readonly ['schema-parse-failure', 'schema-version-mismatch', 'non-canonicalizable-value', 'digest-mismatch', 'budget-exhausted', 'port-failure', 'port-contract-violation', 'forbidden-target', 'aborted', 'operator-cannot-accept-operand'];
|
|
2
|
+
export type RuntimeFaultCode = (typeof RUNTIME_FAULT_CODES)[number];
|
|
3
|
+
export declare class RuntimeFault extends Error {
|
|
4
|
+
readonly code: RuntimeFaultCode;
|
|
5
|
+
readonly artifactPath: string;
|
|
6
|
+
constructor(code: RuntimeFaultCode, artifactPath: string, detail: string, options?: {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Runtime fault registry (AD-28): thrown, typed errors carrying a stable
|
|
2
|
+
// machine code and the artifact path that produced them. Disjoint from AD-5's
|
|
3
|
+
// compile-time registry; they share only this base shape, never a code table.
|
|
4
|
+
//
|
|
5
|
+
// The complete normative ten-code AD-28 table, in the spine's exact order.
|
|
6
|
+
// `scripts/check-ad28-registry.ts` asserts this tuple stays set- and order-
|
|
7
|
+
// equal to that table under `npm run validate` (mirroring
|
|
8
|
+
// `scripts/check-ad5-registry.ts` for `FAILURE_CODES`). A code with no
|
|
9
|
+
// thrower yet is not a defect: AD-28 fixes the registry independently of
|
|
10
|
+
// implementation order, exactly as AD-5 does for `FAILURE_CODES`.
|
|
11
|
+
export const RUNTIME_FAULT_CODES = [
|
|
12
|
+
'schema-parse-failure',
|
|
13
|
+
'schema-version-mismatch',
|
|
14
|
+
'non-canonicalizable-value',
|
|
15
|
+
'digest-mismatch',
|
|
16
|
+
'budget-exhausted',
|
|
17
|
+
'port-failure',
|
|
18
|
+
'port-contract-violation',
|
|
19
|
+
'forbidden-target',
|
|
20
|
+
'aborted',
|
|
21
|
+
'operator-cannot-accept-operand',
|
|
22
|
+
];
|
|
23
|
+
export class RuntimeFault extends Error {
|
|
24
|
+
code;
|
|
25
|
+
artifactPath;
|
|
26
|
+
constructor(code, artifactPath, detail, options) {
|
|
27
|
+
super(`${code} in ${artifactPath}: ${detail}`, options);
|
|
28
|
+
this.name = 'RuntimeFault';
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.artifactPath = artifactPath;
|
|
31
|
+
}
|
|
32
|
+
}
|