TestCell<C extends Cell> class
Testing & Validation
The central validation gate for a Cell – it decides what's allowed.
Every reactive node has a TestCell that governs four kinds of actions:
- State changes (the core validation)
- Function execution (TestActionRule)
- Linking (TestLinkRule)
- Pulse processing (TestPulseRule)
You compose individual rules into a single policy using the + operator.
When to use
Most of the time you don't need to build a TestCell from scratch. Start with one of the predefined policies:
To define your own, use the constructor with a simple validation function, then compose with others:
final isPositive = TestCell<int>((value, {host, arguments, user}) => value > 0);
final hasPermission = TestCell<Cell>((_, {host, ...}) => host.context.hasRole('admin'));
final policy = isPositive + hasPermission;
Use TestCell whenever you need to enforce business rules, security boundaries, or data integrity on a cell. The framework uses it internally for every validation, but you can supply your own when creating a cell:
final cell = Cell(testRule: myPolicy);
How it works
- The TestCell is attached to a cell at creation time.
- Every operation (state change, action, link, pulse) passes through the TestCell's validation pipeline.
- The pipeline is a chain of rules; each rule returns
trueto allow orfalseto block. - Rules can be synchronous or asynchronous (FutureOr<bool>).
- The
+operator composes rules into a single TestCell that evaluates them in sequence (short‑circuiting onfalse).
Non‑obvious
- A deputy (created via Cell.deputy) gets its own TestCell, layered on top of the principal's rule. You can narrow permissions, never widen.
- If a rule throws an exception, the framework treats it as a
true(pass) when the host is ungoverned, orfalse(fail) when governed. - The TestCell is a flyweight – many cells can share the same policy instance without extra memory.
Example: A complete policy
final rangeRule = TestCell<int>((value, ...) => value >= 0 && value <= 100);
final actionRule = TestActionRule<Cell>((action, ...) => action is ReadAction);
final linkRule = TestLinkRule<Cell>((link, ...) => link.context.domains == host.context.domains);
final pulseRule = TestPulseRule<Cell>((pulse, ...) => pulse.priority > 50);
final policy = rangeRule + actionRule + linkRule + pulseRule;
See also:
- TestActionRule for action‑specific validation.
- TestLinkRule for link‑specific validation.
- TestPulseRule for pulse‑specific validation.
- TestRule for the base validation contract.
- HowTo: See
guide/HowTo-TestCell.mdfor a guide on implementing custom validation policies and integrity gates.
- Inheritance
- Implemented types
-
- TestActionRule<
C> - TestLinkRule<
C> - TestPulseRule<
C>
- TestActionRule<
- Implementers
Constructors
-
TestCell(FutureOr<
bool> rule(dynamic object, {dynamic arguments, C? host, dynamic user}), {TestCell<C> ? parent, dynamic user}) -
Creates an TestCell with a single validation rule.
const
-
TestCell.chain(Iterable<
TestRule< rules, {TestCell<C> >C> ? parent, dynamic user, FutureOr<bool> strategy(dynamic object, {dynamic arguments, C? host, dynamic user})?}) -
Synthesizes a Composite Validation Pipeline by aggregating multiple
specialized rules into a single, unified Integrity Gate.
const
- TestCell.fromRecord(dynamic record)
-
Creates a TestCell instance directly from a raw Record blueprint.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
action(
Function action, {required C host, Arguments? arguments}) → FutureOr< bool> -
Validates the execution of a functional
actionand its associatedargumentson thehostcell, supporting Hybrid Convergence (Sync/Async).override -
call(
dynamic object, {C? host, dynamic arguments}) → FutureOr< bool> -
The primary entry point for the Integrity Gate, executing the
validation pipeline for a specific
objector state mutation.override -
link(
covariant Cell link, {required C host}) → FutureOr< bool> -
Validates the establishment of a reactive
linkfrom a candidate Cell to thehostcell, supporting Hybrid Convergence (Sync/Async).override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pulse(
covariant Pulse pulse, {required C host}) → FutureOr< bool> -
Validates an incoming
pulseintended for processing by thehostcell, supporting Hybrid Convergence (Sync/Async).override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator +(
covariant TestRule< C> other) → TestCell<C> -
Composes this Integrity Gate (TestCell) with another validation rule
using the Compositional Algebra of the framework.
override
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- allowAll → const TestPasses
- A policy that allows everything – the default.
- readOnly → const _TestCellReadOnly
- A policy that blocks all mutations – read‑only.