Files
rose-ash/next/tests/define_trigger.sh
giles fc6a47ad62
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
fed-sx-types Phase 6: DefineTrigger verb + trigger_registry
The trigger declaration layer (fed-sx-triggers-loop.md Phase 1): bind an
activity-type to a durable flow so an arriving activity can fan out into
a business flow.

- next/genesis/activity-types/define_trigger.sx — the DefineTrigger verb
  (DefineActivity form, nested-get schema). :object carries
  :activity-type, :flow-name, optional :guard / :actor-scope.
- next/kernel/trigger_registry.erl — pure core + registered gen_server,
  mirroring peer_actors/peer_types. Keyed by activity-type, multiple
  specs per type fire independently. Spec = {TriggerCid, FlowName,
  Guard, ActorScope}. Hydrates on start from a fold over DefineTrigger
  activities (restart-safe, same content-addressing as define_registry).

Manifest activity-types 7->8 (total bundle 38->39); the four bootstrap
count suites + genesis_parse bumped, and bootstrap_load's internal
timeout raised (the larger bundle's double cid:to_string was truncating).

Tests: define_trigger.sh (6), trigger_registry.sh (17). lib/erlang
771/771 + next/flow 34/34 untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-30 18:18:22 +00:00

100 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# next/tests/define_trigger.sh — fed-sx triggers Phase 1 (verb).
#
# The DefineTrigger genesis verb
# (next/genesis/activity-types/define_trigger.sx) binds an activity-type
# to a flow. This suite confirms it parses with the expected
# DefineActivity head + :name, that its :schema accepts a well-formed
# binding and rejects malformed ones, and that a DefineTrigger envelope
# round-trips through term_codec.
set -uo pipefail
cd "$(git rev-parse --show-toplevel)"
SX_SERVER="${SX_SERVER:-hosts/ocaml/_build/default/bin/sx_server.exe}"
if [ ! -x "$SX_SERVER" ]; then
SX_SERVER="/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe"
fi
if [ ! -x "$SX_SERVER" ]; then
echo "ERROR: sx_server.exe not found." >&2
exit 1
fi
VERBOSE="${1:-}"
PASS=0; FAIL=0; ERRORS=""
TMPFILE=$(mktemp); trap "rm -f $TMPFILE" EXIT
SCH='(eval-expr (get (apply dict (rest (parse (file-read \"next/genesis/activity-types/define_trigger.sx\")))) :schema))'
cat > "$TMPFILE" <<EPOCHS
(epoch 1)
(load "lib/erlang/tokenizer.sx")
(load "lib/erlang/parser.sx")
(load "lib/erlang/parser-core.sx")
(load "lib/erlang/parser-expr.sx")
(load "lib/erlang/parser-module.sx")
(load "lib/erlang/transpile.sx")
(load "lib/erlang/runtime.sx")
(load "lib/erlang/vm/dispatcher.sx")
(epoch 2)
(eval "(get (erlang-load-module (file-read \"next/kernel/term_codec.erl\")) :name)")
;; ── parse / shape ──────────────────────────────────────────
(epoch 10)
(eval "(first (parse (file-read \"next/genesis/activity-types/define_trigger.sx\")))")
(epoch 11)
(eval "(get (apply dict (rest (parse (file-read \"next/genesis/activity-types/define_trigger.sx\")))) :name)")
;; ── schema accept / reject ─────────────────────────────────
;; valid binding: string :activity-type + :flow-name -> true
(epoch 20)
(eval "(define sch ${SCH}) (sch (dict :object (dict :activity-type \"Create\" :flow-name \"blog-publish-digest\")))")
;; reject: missing :activity-type -> false
(epoch 21)
(eval "(define sch ${SCH}) (sch (dict :object (dict :flow-name \"f\")))")
;; reject: missing :flow-name -> false
(epoch 22)
(eval "(define sch ${SCH}) (sch (dict :object (dict :activity-type \"Create\")))")
;; ── envelope round-trip through term_codec ─────────────────
(epoch 30)
(eval "(get (erlang-eval-ast \"A = [{type, define_trigger}, {actor, alice}, {object, [{activity_type, create}, {flow_name, blog_publish_digest}]}], {ok, D, _} = term_codec:decode(term_codec:encode(A)), D =:= A\") :name)")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
check() {
local epoch="$1" desc="$2" expected="$3"
local actual
actual=$(echo "$OUTPUT" | awk -v e="$epoch" '
$0 ~ "^\\(ok-len " e " " { getline; print; exit }
$0 ~ "^\\(ok " e " " { print; exit }
$0 ~ "^\\(error " e " " { print; exit }
')
[ -z "$actual" ] && actual="<no output for epoch $epoch>"
if echo "$actual" | grep -qF -- "$expected"; then
PASS=$((PASS+1))
[ "$VERBOSE" = "-v" ] && echo " ok $desc"
else
FAIL=$((FAIL+1))
ERRORS+=" FAIL [$desc] (epoch $epoch) expected: $expected | actual: $actual
"
fi
}
check 10 "define_trigger.sx head form" "DefineActivity"
check 11 "define_trigger.sx name" "DefineTrigger"
check 20 "schema accepts valid binding" "true"
check 21 "schema rejects missing type" "false"
check 22 "schema rejects missing flow-name" "false"
check 30 "DefineTrigger envelope round-trips" "true"
TOTAL=$((PASS+FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL next/tests/define_trigger.sh passed"
else
echo "FAIL $PASS/$TOTAL passed, $FAIL failed:"
echo "$ERRORS"
fi
[ $FAIL -eq 0 ]