@kernlang/test 3.4.0 → 3.4.1

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/README.md CHANGED
@@ -33,7 +33,7 @@ kern test path/to/tests --pass-with-no-tests
33
33
  kern test path/to/tests --fail-on-warn
34
34
  ```
35
35
 
36
- `kern-test` is the standalone binary shipped by `@kernlang/test`. `kern test` is the integrated command from `@kernlang/cli`; it supports the same native runner flags plus `--watch` and the legacy MCP Jest generator fallback. Single-file `kern test <file.kern>` inputs keep that legacy generator behavior when the file has no native `test` nodes. Directory inputs discover `.kern` files that contain native `test` nodes and run them as one aggregate suite. This repo's `examples/native-test` directory includes machine, MCP safety, permission-gated tool, runtime-function, and language-surface smoke tests for arrays, classes, and functions.
36
+ `kern-test` is the standalone binary shipped by `@kernlang/test`. `kern test` is the integrated command from `@kernlang/cli`; it supports the same native runner flags plus `--watch` and the legacy MCP Jest generator fallback. Single-file `kern test <file.kern>` inputs keep that legacy generator behavior when the file has no native `test` nodes. Directory inputs discover `.kern` files that contain native `test` nodes and run them as one aggregate suite. This repo's `examples/native-test` directory includes machine, MCP safety, permission-gated tool, runtime-function, language-surface, array conformance, class/function conformance, collection/destructure conformance, advanced data conformance, control-flow conformance, effect recovery conformance, and route workflow conformance tests.
37
37
 
38
38
  ## KERN Syntax
39
39
 
@@ -70,6 +70,14 @@ test name="Order invariants" target="./order.kern"
70
70
  expect fn=addTax args={{[orderSubtotal(paidOrder), taxRate]}} equals=54
71
71
  expect derive=total equals=54
72
72
 
73
+ it name="route workflow is stable"
74
+ expect route="GET /api/users" with={{({ query: { role: "admin" } })}} returns={{adminUsers}}
75
+ expect route="GET /api/users/:id" with={{({ params: { id: "missing" } })}} returns={{({ status: 404 })}}
76
+
77
+ it name="effect recovery is stable"
78
+ expect effect=fetchUsers returns={{users}}
79
+ expect effect=loadFallback recovers=true fallback={{[]}}
80
+
73
81
  it name="suite covers target surface"
74
82
  expect preset=coverage
75
83
  ```
@@ -92,15 +100,19 @@ Use `expect node=<type>` for KERN-native shape assertions over the target IR. Ad
92
100
 
93
101
  Use `no=nonExhaustiveGuards` to scan target-side variant guards that declare `covers=...`, `over=<Union>`, or `union=<Union>`. This is useful when Guard/Sight should catch a newly-added union variant before any backend compiler runs. Use `no=emptyRoutes` when route declarations must carry executable behavior through `handler`, `respond`, `derive`, `fmt`, `branch`, `each`, `collect`, or `effect`.
94
102
 
95
- Use `expect expr={{...}}` for small runtime assertions over referenced target-side `const`, `derive`, `let`, and pure `fn` bindings. Runtime `fn` handlers may use local statements, `if`, `return`, `throw`, and `async=true`/`await` over sandboxed values. Without a comparator, the expression must evaluate truthy. Add `equals=...` for deep equality, `matches="..."` for string/regex checks, or `throws=ErrorName` for expected exceptions.
103
+ Use `expect expr={{...}}` for small runtime assertions over referenced target-side `const`, `derive`, `let`, pure `fn`, constrained `class`, `mapLit`, `setLit`, structured `destructure`, and safe native array/data bindings such as `filter`, `map`, `find`, `reduce`, `slice`, `flatMap`, `sort`, `join`, `compact`, `pluck`, `unique`, `uniqueBy`, `groupBy`, `partition`, `indexBy`, `countBy`, `chunk`, `zip`, `range`, `take`, `drop`, `min`, `max`, `minBy`, `maxBy`, `sum`, `avg`, `sumBy`, `intersect`, and `collect`. Runtime branch bindings execute matching `path` children and return the first `respond` payload when present. Runtime `each` nodes execute eagerly so iteration-scoped `let`/`derive` children can prove loop behavior before codegen. Runtime `fn` handlers may use local statements, `if`, `return`, `throw`, and `async=true`/`await` over sandboxed values. Runtime `class` support covers fields, constructors, methods, and getters/setters with the same sandbox restrictions. Without a comparator, the expression must evaluate truthy. Add `equals=...` for deep equality, `matches="..."` for string/regex checks, or `throws=ErrorName` for expected exceptions.
96
104
 
97
105
  Use `fixture name=<id> value={{...}}` or `fixture name=<id> expr={{...}}` to define scoped runtime data inside `test`, `describe`, or `it`. Fixtures are visible to descendant assertions and do not leak into sibling cases.
98
106
 
99
107
  Use `expect fn=<name>` when the target KERN `fn` itself is the behavior under test. Add `with=<fixture-or-expression>` to pass one argument, or `args={{[...]}}` to spread an argument array into the function. Use `expect derive=<name>` to execute a target-side `derive` binding through the same runtime evaluator. Behavioral assertions support the same `equals=...`, `matches="..."`, and `throws=ErrorName` comparators as `expect expr={{...}}`. Failed behavior assertions report the generated call expression and fixture names so CI output points back to the KERN-native setup.
100
108
 
109
+ Use `expect route="METHOD /path"` to execute portable KERN route workflows before Express/FastAPI generation. Add `with={{...}}` (or `input={{...}}`) to provide `{ params, query, body, headers }`. Route workflow assertions currently execute target-side `derive`, `guard`, `branch`, `collect`, `each`, `destructure`, `partition`, deterministic `effect`/`recover`, and `respond` nodes. Use `returns={{...}}` for deep equality, or the same `equals=...`, `matches="..."`, and `throws=ErrorName` comparators as other runtime assertions. Handler blocks and non-expression effects remain backend/runtime-test territory until dedicated native mocks land.
110
+
111
+ Use `expect effect=<name>` for deterministic portable effects with `trigger expr={{...}}`. A successful trigger can be checked with `returns={{...}}`; recovery can be checked with `recovers=true fallback={{...}}`. Route workflow assertions execute the same deterministic effect/recover subset, including `effectName.result` references. Non-expression triggers such as `query=`, `url=`, and `call=` are intentionally not executed by the native runner yet.
112
+
101
113
  Runtime assertions intentionally do not execute arbitrary application code. Multi-statement expressions and unsafe globals such as `process`, `require`, `eval`, `Function`, `fetch`, timers, and `WebSocket` are rejected before execution.
102
114
 
103
- Use `preset=coverage` when Guard/Sight need a native signal for untested KERN surface. Machine transition coverage is driven by explicit `via=...` reachability assertions. Guard coverage passes when guards have explicit `expect guard=<name> exhaustive=true` assertions or a guard-wide assertion such as `expect preset=guard`.
115
+ Use `preset=coverage` when Guard/Sight need a native signal for untested KERN surface. Machine transition coverage is driven by explicit `via=...` reachability assertions. Guard coverage passes when guards have explicit `expect guard=<name> exhaustive=true` assertions, a guard-wide assertion such as `expect preset=guard`, or passing route/tool workflow assertions that execute those guard nodes. Route and tool assertions also count the nested effects they actually execute, including mocked effect boundaries, so workflow-level tests cover the source-level guard and effect surface they exercise.
104
116
 
105
117
  Native effect checks follow same-file helper `fn` calls before classifying dangerous work, so a route/tool that calls `readSecret()` still gets flagged when `readSecret()` performs filesystem, database, network, shell, or email effects. They also recognize inline CLI permission gates shaped like a `checkPermission` function returning a `PermissionDecision` and returned from a tool factory. That lets KERN test AGON-style tool factories without forcing every permission check into a separate `guard` node.
106
118
 
package/dist/index.d.ts CHANGED
@@ -22,6 +22,9 @@ export interface NativeKernTestCoverageTarget {
22
22
  file: string;
23
23
  transitions: NativeKernTestCoverageMetric;
24
24
  guards: NativeKernTestCoverageMetric;
25
+ routes: NativeKernTestCoverageMetric;
26
+ tools: NativeKernTestCoverageMetric;
27
+ effects: NativeKernTestCoverageMetric;
25
28
  }
26
29
  export interface NativeKernTestCoverageSummary {
27
30
  total: number;
@@ -29,6 +32,9 @@ export interface NativeKernTestCoverageSummary {
29
32
  percent: number;
30
33
  transitions: NativeKernTestCoverageMetric;
31
34
  guards: NativeKernTestCoverageMetric;
35
+ routes: NativeKernTestCoverageMetric;
36
+ tools: NativeKernTestCoverageMetric;
37
+ effects: NativeKernTestCoverageMetric;
32
38
  targets: NativeKernTestCoverageTarget[];
33
39
  }
34
40
  export interface NativeKernTestSummary {