feat: duration seconds; required fields; type-validated insertions/updates/retrievals
CI / publish (push) Successful in 9s
CI / test (push) Successful in 19s

- Duration literals now accept s/m/h/d/w (was m/h/d/w): 'BEHAVES { ttl 30s }'
  is 30s, and 'within 30s' temporal expressions parse.
- Definition fields are REQUIRED by default ('field: type'); 'field: type?'
  marks a field optional. addNode enforces presence on insert, getSchema
  exposes per-field requiredness, and updateNodeData still validates the
  provided fields' types.
- Provider-returned edges are validated against the fact's declared typing:
  a value-carrying fact must return { value, possibility } with a value of the
  declared type (bare-number shorthand is rejected); a non-value fact must not
  carry a value; and every possibility must lie in [0, 1]. Violations throw a
  clear provider-authoring error instead of silently injecting malformed edges.

Tests: DSLRuntimeTyping (duration units, required-field enforcement, schema
requiredness, value-type + shape + possibility validation).
This commit is contained in:
John Dvorak
2026-08-03 16:00:49 -07:00
parent aa38fbfd8c
commit 9111c4b20d
8 changed files with 856 additions and 707 deletions
+8 -8
View File
@@ -20,9 +20,9 @@ import { Arbiter } from '@arbiter/core';
import { DSLRuntime } from '../src/runtime/DSLRuntime.js';
const BASE_DSL = `
definition Employee { id: string level: number active: boolean }
definition Group { id: string }
definition Doc { id: string }
definition Employee { id: string? level: number? active: boolean? }
definition Group { id: string? }
definition Doc { id: string? }
fact member_of(user: Employee, group: Group)
fact *owns(user: Employee, doc: Doc)
fact *user_score(user: Employee, value: number)
@@ -164,8 +164,8 @@ describe('DSLRuntime', () => {
it('derives transitive required facts through evidence composition', async () => {
const dsl = `
definition Employee { id: string }
definition Doc { id: string }
definition Employee { id: string? }
definition Doc { id: string? }
fact *owns(user: Employee, doc: Doc)
fact *banned(user: Employee)
evidence can_read(user: Employee, doc: Doc) { owns(user, doc) }
@@ -191,9 +191,9 @@ describe('DSLRuntime', () => {
it('derives transitive required facts through a condition-step chain', () => {
const dsl = `
definition Employee { id: string }
definition Group { id: string }
definition Doc { id: string }
definition Employee { id: string? }
definition Group { id: string? }
definition Doc { id: string? }
fact *member_of(user: Employee, group: Group)
fact *can_view(group: Group, doc: Doc)
fact *banned(group: Group)