GraphTest

The checks of a test or a replay. Each check is about what happened right after what the check before it was about, so a test reads as the path of the run:

CheckWhat happened next
expectNode("check")the node check finished
expectNodes("model", "tools", "model")these nodes finished, one after another
expectStep("search", "summarize")a step ran these nodes, at the same time and in any order
expectInterruptBefore("pay")the run paused, and pay runs when it is resumed
expectFinished()the run completed
expectFailure()the run failed

After a pause, resumeWith continues the run, and the checks go on with what the run does next. Each check takes a function that gets the state at that point, for the assertions of the test, and also returns that state.

The run until its next pause or its end happens before the first check, so a check sees what the run did, and what a scripted model was asked, up to that pause or end. Retries, progress and the events inside a subgraph are not checked here: collect them with record.

Every check that does not hold throws an AssertionError that says what happened instead and the path of the run so far. After the last check, the test fails if the run did more: every node that finished, and the pause or end of the run, has to be checked.

Functions

Link copied to clipboard
fun expectFailure(check: (Exception) -> Unit = {}): Exception

Checks that the run failed next, and passes what it threw to check: usually a NodeExecutionException, whose cause is what the node threw.

Link copied to clipboard
fun expectFinished(check: (State) -> Unit = {}): State

Checks that the run completed next, and passes its last state to check.

Link copied to clipboard
fun expectInterruptBefore(node: String, check: (State) -> Unit = {}): State

Checks that the run paused next, and that node runs when it is resumed: the run paused before node because of GraphConfig.interruptBefore, after the node before it because of GraphConfig.interruptAfter, or in node because it called interrupt. check gets the state of the paused run.

Link copied to clipboard
fun expectNode(node: String, check: (State) -> Unit = {}): State

Checks that node finished next, and passes the state it returned to check. In a step that ran several nodes this is the node's own result: expectStep has the state of the step.

Link copied to clipboard
fun expectNodes(vararg nodes: String)

Checks that nodes finished next, one after another in this order. For a graph whose nodes run one at a time, this is the path of the run.

Link copied to clipboard
fun expectStep(vararg nodes: String, check: (State) -> Unit = {}): State

Checks that the next step ran nodes, all of them and no other, and passes the state after the step, with the results of its nodes combined, to check. The nodes of a step run at the same time and finish in any order, so this check, not expectNode, is the one for parallel branches.

Link copied to clipboard
suspend fun resumeWith(update: suspend (State) -> State = { it })

Continues the paused run, with the state that update returns, as CompiledGraph.resume does: for example with the decision of the person the run waited for. The checks after this one are about what the run does from there.