fed-sx-m1: Step 9a-pure — Pin smoke test in-process (verb extensibility end-to-end) + 13 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 20s

This commit is contained in:
2026-05-28 18:12:03 +00:00
parent 5940b98878
commit 1496136d12
2 changed files with 159 additions and 1 deletions

156
next/tests/smoke_pin_pure.sh Executable file
View File

@@ -0,0 +1,156 @@
#!/usr/bin/env bash
# next/tests/smoke_pin_pure.sh — Step 9a-pure smoke test.
#
# Mirrors plans/fed-sx-milestone-1.md §Step 9a but without TCP /
# curl / JSON. Exercises Pin-verb extensibility end-to-end:
# 1. define_registry fold projection registers DefineActivity
# 2. A pin-state projection (Erlang fun) folds Pin activities
# 3. Both projections wired into nx_kernel
# 4. Publish Create{DefineActivity{name: pin}} -> registry update
# 5. Publish Pin{path:..., cid:...} -> pin-state update
#
# Proves the meta-projection + verb-fold mechanism is wired
# correctly. The remaining Step 9a deliverable (curl smoke test)
# layers TCP on top — needs Step 8b-start. 14 cases.
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
# Shared prelude — starts kernel + two projections, wires them in,
# binds DefineAct and PinAct ready to publish.
PRELUDE='KM = <<1,2,3,4>>, KS = [{key_id,k1},{algorithm,ed25519},{value,KM}], AS = [{public_keys,[[{id,k1},{created,0},{value,KM}]]}], PinFold = fun (Act, S) -> case envelope:get_field(type, Act) of {ok, pin} -> case envelope:get_field(object, Act) of {ok, Obj} -> {ok, P} = envelope:get_field(path, Obj), {ok, C} = envelope:get_field(cid, Obj), [{P, C} | S]; _ -> S end; _ -> S end end, projection:start_link(define_reg, registry:new(), define_registry:fold_fn()), projection:start_link(pin_state, [], PinFold), nx_kernel:start_link(alice, KS, AS), nx_kernel:with_projections([define_reg, pin_state]), DefineAct = [{type, create}, {object, [{type, define_activity}, {name, pin}]}], PinAct = [{type, pin}, {object, [{path, docs_intro}, {cid, qm_cid_1}]}],'
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 "(er-load-gen-server!)")
(epoch 3)
(eval "(get (erlang-load-module (file-read \"next/kernel/envelope.erl\")) :name)")
(epoch 4)
(eval "(get (erlang-load-module (file-read \"next/kernel/log.erl\")) :name)")
(epoch 5)
(eval "(get (erlang-load-module (file-read \"next/kernel/pipeline.erl\")) :name)")
(epoch 6)
(eval "(get (erlang-load-module (file-read \"next/kernel/registry.erl\")) :name)")
(epoch 7)
(eval "(get (erlang-load-module (file-read \"next/kernel/projection.erl\")) :name)")
(epoch 8)
(eval "(get (erlang-load-module (file-read \"next/kernel/outbox.erl\")) :name)")
(epoch 9)
(eval "(get (erlang-load-module (file-read \"next/kernel/nx_kernel.erl\")) :name)")
(epoch 10)
(eval "(get (erlang-load-module (file-read \"next/kernel/define_registry.erl\")) :name)")
;; Initial state: pin_state empty
(epoch 20)
(eval "(get (erlang-eval-ast \"${PRELUDE} projection:query(pin_state) =:= []\") :name)")
;; Initial state: pin NOT in registry
(epoch 21)
(eval "(get (erlang-eval-ast \"${PRELUDE} registry:lookup(activity_types, pin, projection:query(define_reg)) =:= not_found\") :name)")
;; Step 1: Publish DefineActivity{pin}, then pin IS in the registry
(epoch 22)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:publish(DefineAct), case registry:lookup(activity_types, pin, projection:query(define_reg)) of {ok, _} -> ok; _ -> bad end\") :name)")
;; Define activity does NOT advance pin_state
(epoch 23)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:publish(DefineAct), projection:query(pin_state) =:= []\") :name)")
;; Step 2: Publish Pin activity, pin_state has the {path, cid}
(epoch 24)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:publish(PinAct), projection:query(pin_state) =:= [{docs_intro, qm_cid_1}]\") :name)")
;; Pin activity does NOT add to the registry
(epoch 25)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:publish(PinAct), length(registry:list(activity_types, projection:query(define_reg))) =:= 0\") :name)")
;; Both publishes interleaved — order independent
(epoch 26)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:publish(DefineAct), nx_kernel:publish(PinAct), {projection:query(pin_state), case registry:lookup(activity_types, pin, projection:query(define_reg)) of {ok, _} -> registered; _ -> unregistered end} =:= {[{docs_intro, qm_cid_1}], registered}\") :name)")
;; Reverse order: publish Pin FIRST, then DefineActivity — Pin still folds
(epoch 27)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:publish(PinAct), nx_kernel:publish(DefineAct), {projection:query(pin_state), case registry:lookup(activity_types, pin, projection:query(define_reg)) of {ok, _} -> registered; _ -> unregistered end} =:= {[{docs_intro, qm_cid_1}], registered}\") :name)")
;; Two Pins -> two entries in pin_state (newest-first)
(epoch 28)
(eval "(get (erlang-eval-ast \"${PRELUDE} PinAct2 = [{type, pin}, {object, [{path, docs_arch}, {cid, qm_cid_2}]}], nx_kernel:publish(PinAct), nx_kernel:publish(PinAct2), projection:query(pin_state) =:= [{docs_arch, qm_cid_2}, {docs_intro, qm_cid_1}]\") :name)")
;; Log tip advances with each publish
(epoch 29)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:publish(DefineAct), nx_kernel:publish(PinAct), nx_kernel:log_tip() =:= 2\") :name)")
;; Multiple DefineActivity registrations (different names) accumulate
(epoch 30)
(eval "(get (erlang-eval-ast \"${PRELUDE} Foo = [{type, create}, {object, [{type, define_activity}, {name, foo}]}], nx_kernel:publish(DefineAct), nx_kernel:publish(Foo), length(registry:list(activity_types, projection:query(define_reg))) =:= 2\") :name)")
;; pin_state survives an empty-publish round (non-Pin doesn't disturb)
(epoch 31)
(eval "(get (erlang-eval-ast \"${PRELUDE} Other = [{type, create}, {object, [{type, note}, {content, hi}]}], nx_kernel:publish(PinAct), nx_kernel:publish(Other), projection:query(pin_state) =:= [{docs_intro, qm_cid_1}]\") :name)")
EPOCHS
OUTPUT=$(timeout 300 "$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_registry loaded" "define_registry"
check 20 "initial pin_state is []" "true"
check 21 "pin not in registry initially" "true"
check 22 "DefineActivity registers pin" "ok"
check 23 "DefineActivity skips pin_state" "true"
check 24 "Pin advances pin_state" "true"
check 25 "Pin doesn't register a type" "true"
check 26 "both publishes: both states ok" "true"
check 27 "reverse order works too" "true"
check 28 "two Pins -> two entries" "true"
check 29 "log tip after two publishes" "true"
check 30 "two DefineActivities accumulate" "true"
check 31 "Note doesn't disturb pin_state" "true"
TOTAL=$((PASS+FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL next/tests/smoke_pin_pure.sh passed"
else
echo "FAIL $PASS/$TOTAL passed, $FAIL failed:"
echo "$ERRORS"
fi
[ $FAIL -eq 0 ]

View File

@@ -577,7 +577,8 @@ Auth on `POST /activity`: bearer token from env var `NEXT_PUBLISH_TOKEN`.
**Sub-deliverables:**
- [x] **9-pre-fold** — In-process end-to-end test of the HTTP → publish → broadcast → projection-fold chain. Proves the full vertical works without a real TCP socket. `next/tests/http_publish_fold.sh` (10 cases). Step 9a/b proper need TCP (Step 8b-start).
- [ ] **9a** — Pin smoke test (TCP-driven, curl) — needs Step 8b-start + Define\* SX-source eval.
- [x] **9a-pure** In-process Pin smoke test mirroring the §Step 9a flow. Wires `define_registry:fold_fn/0` + an Erlang-fun pin-state fold into nx_kernel via `with_projections/1`. Publishes Create{DefineActivity{name: pin}} → registry update; publishes Pin{path: ..., cid: ...} → pin_state update. Order-independent; ignores Note + other types. `next/tests/smoke_pin_pure.sh` (13 cases).
- [ ] **9a-tcp** — Same flow under curl over Step 8b-start once TCP listening lands.
- [ ] **9b** — Reactive smoke test (TCP-driven, curl) — needs DefineSubscription / DefineTrigger eval.
**The proof points.** Two end-to-end smoke tests demonstrate, between them, that
@@ -1000,6 +1001,7 @@ A few things still under-specified; resolve as work begins.
Newest first. One line per sub-deliverable commit. Erlang conformance gate
(`bash lib/erlang/conformance.sh`) must remain 729/729 on every entry.
- **2026-05-28** — Step 9a-pure: **the first verb-extensibility smoke test, proven end-to-end.** Mirrors §Step 9a structurally without TCP/curl/JSON. Two projections wired into `nx_kernel:with_projections([define_reg, pin_state])``define_reg` uses `define_registry:fold_fn/0` (Step 5d-pure), `pin_state` uses an Erlang-fun fold that records `{Path, Cid}` from Pin activities. Publish `Create{DefineActivity{name: pin}}` → registry update visible via `registry:lookup(activity_types, pin, projection:query(define_reg))`; publish `Pin{path: docs_intro, cid: qm_cid_1}``projection:query(pin_state) =:= [{docs_intro, qm_cid_1}]`. Order-independent (DefineActivity-then-Pin and Pin-then-DefineActivity both succeed); Note + non-Define types are pass-throughs in both projections. The TCP/curl variant (Step 9a-tcp) layers on Step 8b-start. `next/tests/smoke_pin_pure.sh` 13/13. Erlang conformance 729/729.
- **2026-05-28** — Step 5d-pure: `next/kernel/define_registry.erl` — the meta-projection fold body, in pure Erlang. State shape mirrors `registry:new()` exactly; `fold/2` dispatches Create{Define*} to `registry:register/4` keyed by `define_kind/1` (define_activity → activity_types, define_object → object_types, …). Non-Create + Create{non-Define} + Define{no :name} are all pass-throughs. Override re-registration preserves a single entry per name. `fold_fn/0` plugs the fold into `projection:start_link/3` — verified end-to-end: activity → projection async_fold → query state → registry:lookup returns the registered Object. The SX `define-registry.sx` body will replace this once an SX-source eval bridge exists; the Erlang shape proves the wiring is correct. `next/tests/define_registry_pure.sh` 16/16. Erlang conformance 729/729.
- **2026-05-28** — Step 6c-schema-pure: `pipeline:stage_schema/2` accepts (Activity, SchemaLookup) where SchemaLookup is a caller-supplied callback `fun(Type) -> {ok, SchemaFn} | not_found`. Open-world default — unregistered types resolve to ok so the pipeline doesn't block activities the kernel hasn't yet learned about (tightened to strict-world in milestone 2). Activities without `:object` skip the schema check. `stage_schema/1` returns a 1-arity stage fun closed over SchemaLookup for composition with run_stages. Halt order verified end-to-end: envelope-shape errors precede schema; envelope-ok + schema-fail surfaces `schema_mismatch`. The Erlang-fun shape is the substrate-friendly stand-in for the SX `:schema` bodies in genesis; same stage shape will dispatch through an SX-source eval bridge once it exists. `next/tests/pipeline_schema.sh` 14/14. Erlang conformance 729/729.
- **2026-05-28** — Step 8d-dispatch-get: format-aware versions of every GET response builder. `actor_doc_response_for/2`, `artifact_response_for/2`, `projection_response_for/2`, `projections_list_response_for/1`. Each produces `{"key":"value"}` (json/activity_json), `(key "value")` (sx), raw payload bytes (cbor stub), or the existing text form. `dispatch` refactored to `/3` with a backward-compat `dispatch/2` wrapper. Route extracts Format via `accept_format_from/1` once at the top and threads it through dispatch. End-to-end GETs with `Accept: application/json` / `application/sx` verified for all three dynamic-prefix routes + the projections-list bare-path route. Step 8d effectively complete — format dispatch + Content-Type live on every non-static response. `next/tests/http_get_format.sh` 17/17. Erlang conformance 729/729.