Skip to main content

Running Scripts

Run predefined REPL command sequences from coco.nut:

coco lab run <script-name>

coco lab init

Loads and compiles the logic from the manifest already configured in coco.nut, and registers the default_user. The project must already be initialized (use coco nut init to create a new coco.nut).

Defining Scripts

In coco.nut:

[lab.scripts]
test-toggle = ["engines", "users", "logics"]
my-test = ["compile MyLogic", "deploy MyLogic.Init()", "invoke MyLogic.Run()"]

Scripts created by default with coco nut init.

Persistence

State persists across separate coco lab run invocations that share the same storage location: each run restores the latest snapshot before executing and saves a new one afterward. Use --new-session to ignore the prior snapshot, or --no-persist for a hermetic run (point --storage-path at a fresh directory to fully isolate it).

Bash Verification Scripts

The [scripts] section defines bash commands that can run lab scripts and verify output:

[scripts]
test = '''
PASS=0
FAIL=0
TEST_RESULTS=$(coco lab run my-test 2>&1)

echo "$TEST_RESULTS" | grep -q 'expected_output' \
&& { echo 'PASS: test name'; PASS=$((PASS+1)); } \
|| { echo 'FAIL: test name'; FAIL=$((FAIL+1)); }

echo "Results: $PASS passed, $FAIL failed out of $((PASS+FAIL)) tests"
if [ "$FAIL" -gt 0 ]; then exit 1; fi
'''

Run with: coco nut run test

CLI Flags

FlagDescription
-c, --configConfig name from [lab.config.name]
-e, --envEnvironment (default: main)
-o, --osOverride target OS
-s, --suppressSuppress output
-x, --no-exitDon't exit the REPL after the script runs
--debugPrint each lab command before execution
--no-persistDisable session persistence (state is discarded on exit)
--new-sessionStart a fresh session (ignore persisted state) but keep saving
--storageStorage backend type (default: file; overrides coco.nut)
--storage-pathBackend-specific location, e.g. a folder path (overrides coco.nut)
coco lab run test-toggle -s