From 669dfacd0422877a1ccaa601cbbccb83a83df71b Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Mon, 15 Mar 2021 14:04:04 +1000 Subject: [PATCH] demo: add demo/testing agent for hook libraries --- pkg/arvo/app/demo-pull-hook.hoon | 58 +++++++++++ pkg/arvo/app/demo-push-hook.hoon | 65 ++++++++++++ pkg/arvo/app/demo-store.hoon | 100 ++++++++++++++++++ pkg/arvo/app/demo/pull-hook.hoon | 0 pkg/arvo/app/demo/push-hook.hoon | 0 pkg/arvo/gen/demo/add.hoon | 8 ++ pkg/arvo/gen/demo/ini.hoon | 8 ++ pkg/arvo/gen/demo/run.hoon | 8 ++ pkg/arvo/gen/demo/sub.hoon | 8 ++ pkg/arvo/mar/demo/update-0.hoon | 15 +++ pkg/arvo/mar/demo/update-1.hoon | 15 +++ pkg/arvo/mar/demo/update.hoon | 0 pkg/arvo/sur/demo.hoon | 10 ++ sh/test-hook | 172 +++++++++++++++++++++++++++++++ 14 files changed, 467 insertions(+) create mode 100644 pkg/arvo/app/demo-pull-hook.hoon create mode 100644 pkg/arvo/app/demo-push-hook.hoon create mode 100644 pkg/arvo/app/demo-store.hoon create mode 100644 pkg/arvo/app/demo/pull-hook.hoon create mode 100644 pkg/arvo/app/demo/push-hook.hoon create mode 100644 pkg/arvo/gen/demo/add.hoon create mode 100644 pkg/arvo/gen/demo/ini.hoon create mode 100644 pkg/arvo/gen/demo/run.hoon create mode 100644 pkg/arvo/gen/demo/sub.hoon create mode 100644 pkg/arvo/mar/demo/update-0.hoon create mode 100644 pkg/arvo/mar/demo/update-1.hoon create mode 100644 pkg/arvo/mar/demo/update.hoon create mode 100644 pkg/arvo/sur/demo.hoon create mode 100755 sh/test-hook diff --git a/pkg/arvo/app/demo-pull-hook.hoon b/pkg/arvo/app/demo-pull-hook.hoon new file mode 100644 index 000000000..f9317942a --- /dev/null +++ b/pkg/arvo/app/demo-pull-hook.hoon @@ -0,0 +1,58 @@ +/- store=demo +/+ default-agent, verb, dbug, pull-hook, agentio, resource +~% %demo-pull-hook-top ..part ~ +|% ++$ card card:agent:gall +:: +++ config + ^- config:pull-hook + :* %demo-store + update:store + %demo-update + %demo-push-hook + :: do not change spacing, required by tests + 0 + 0 + %.n + == +:: +-- +:: +:: +%- agent:dbug +%+ verb | +^- agent:gall +%- (agent:pull-hook config) +^- (pull-hook:pull-hook config) +|_ =bowl:gall ++* this . + def ~(. (default-agent this %|) bowl) + dep ~(. (default:pull-hook this config) bowl) +:: +++ on-init on-init:def +++ on-save !>(~) +++ on-load on-load:def +++ on-poke on-poke:def +++ on-agent on-agent:def +++ on-watch on-watch:def +++ on-leave on-leave:def +++ on-peek on-peek:def +++ on-arvo on-arvo:def +++ on-fail on-fail:def +++ on-pull-nack + |= [=resource =tang] + ^- (quip card _this) + `this +:: +++ on-pull-kick + |= =resource + ^- (unit path) + ~& "{}: kicked" + `/ +:: +++ resource-for-update + |= =vase + =+ !<(=update:store vase) + ~[p.update] +-- + diff --git a/pkg/arvo/app/demo-push-hook.hoon b/pkg/arvo/app/demo-push-hook.hoon new file mode 100644 index 000000000..4dcd47737 --- /dev/null +++ b/pkg/arvo/app/demo-push-hook.hoon @@ -0,0 +1,65 @@ +/- store=demo +/+ default-agent, verb, dbug, push-hook, resource, agentio +|% ++$ card card:agent:gall +:: +++ config + ^- config:push-hook + :* %demo-store + /updates + update:store + %demo-update + %demo-pull-hook + :: + 0 + 0 + == +:: ++$ agent (push-hook:push-hook config) +-- +:: +:: +%- agent:dbug +%+ verb | +^- agent:gall +%- (agent:push-hook config) +^- agent +|_ =bowl:gall ++* this . + def ~(. (default-agent this %|) bowl) + grp ~(. grpl bowl) + io ~(. agentio bowl) +:: +++ on-init on-init:def +++ on-save !>(~) +++ on-load on-load:def +++ on-poke on-poke:def +++ on-agent on-agent:def +++ on-watch on-watch:def +++ on-leave on-leave:def +++ on-peek on-peek:def +++ on-arvo on-arvo:def +++ on-fail on-fail:def +:: +++ transform-proxy-update + |= vas=vase + ^- (unit vase) + `vas +:: +++ resource-for-update + |= =vase + =+ !<(=update:store vase) + ~[p.update] +:: +++ take-update + |= =vase + ^- [(list card) agent] + `this +:: +++ initial-watch + |= [=path rid=resource] + ^- vase + =+ .^(=update:store %gx (scry:io %demo-store (snoc `^path`log+(en-path:resource rid) %noun))) + !>(update) +:: +-- diff --git a/pkg/arvo/app/demo-store.hoon b/pkg/arvo/app/demo-store.hoon new file mode 100644 index 000000000..705a68863 --- /dev/null +++ b/pkg/arvo/app/demo-store.hoon @@ -0,0 +1,100 @@ +/- store=demo +/+ default-agent, verb, dbug, resource, agentio +|% ++$ card card:agent:gall ++$ state-0 + [%0 log=(jar resource update:store) counters=(map resource @ud)] +-- +=| state-0 +=* state - +:: +%- agent:dbug +%+ verb | +^- agent:gall +|_ =bowl:gall ++* this . + def ~(. (default-agent this %|) bowl) + io ~(. agentio bowl) +++ on-init + `this +:: +++ on-save + !>(state) +:: +++ on-load + |= =vase + =+ !<(old=state-0 vase) + `this(state old) +:: +++ on-poke + |= [=mark =vase] + ^- (quip card _this) + ?. =(%demo-update-0 mark) + (on-poke:def mark vase) + ~& mark + =+ !<(=update:store vase) + |^ + =. log + (~(add ja log) p.update update) + =^ cards state + (upd update) + [cards this] + :: + ++ upd + |= up=update:store + ^- (quip card _state) + ?- -.up + %ini (upd-ini +.up) + %add (upd-add +.up) + %sub (upd-sub +.up) + %run (upd-run +.up) + == + :: + ++ upd-ini + |= [rid=resource ~] + :- (fact:io mark^!>([%ini +<]) /updates ~)^~ + state(counters (~(put by counters) rid 0)) + :: + ++ upd-add + |= [rid=resource count=@ud] + :- (fact:io mark^!>([%add +<]) /updates ~)^~ + state(counters (~(jab by counters) rid (cury add count))) + :: + ++ upd-sub + |= [rid=resource count=@ud] + :- (fact:io mark^!>([%sub +<]) /updates ~)^~ + state(counters (~(jab by counters) rid (cury sub count))) + :: + ++ upd-run + =| cards=(list card) + |= [rid=resource =(list update:store)] + ?~ list [cards state] + =^ caz state + (upd i.list) + $(list t.list, cards (weld cards caz)) + -- +:: +++ on-watch + |= =path + ?. ?=([%updates ~] path) + (on-watch:def path) + `this +:: +++ on-peek + |= =path + ?. ?=([%x %log @ @ @ ~] path) + (on-peek:def path) + =/ rid=resource + (de-path:resource t.t.path) + =/ =update:store + [%run rid (flop (~(get ja log) rid))] + ``noun+!>(update) +:: +++ on-agent on-agent:def +:: +++ on-arvo on-arvo:def +:: +++ on-leave on-leave:def +:: +++ on-fail on-fail:def +-- diff --git a/pkg/arvo/app/demo/pull-hook.hoon b/pkg/arvo/app/demo/pull-hook.hoon new file mode 100644 index 000000000..e69de29bb diff --git a/pkg/arvo/app/demo/push-hook.hoon b/pkg/arvo/app/demo/push-hook.hoon new file mode 100644 index 000000000..e69de29bb diff --git a/pkg/arvo/gen/demo/add.hoon b/pkg/arvo/gen/demo/add.hoon new file mode 100644 index 000000000..fe70ae11c --- /dev/null +++ b/pkg/arvo/gen/demo/add.hoon @@ -0,0 +1,8 @@ +/- *demo +:- %say +|= $: [now=@da eny=@uvJ =beak] + [[ver=@ud =term count=@ud ~] ~] + == +:- (cat 3 %demo-update- (scot %ud ver)) +^- update +[%add [p.beak term] count] diff --git a/pkg/arvo/gen/demo/ini.hoon b/pkg/arvo/gen/demo/ini.hoon new file mode 100644 index 000000000..79389bb07 --- /dev/null +++ b/pkg/arvo/gen/demo/ini.hoon @@ -0,0 +1,8 @@ +/- *demo +:- %say +|= $: [now=@da eny=@uvJ =beak] + [[=term ~] ~] + == +:- %demo-update-0 +^- update +[%ini [p.beak term] ~] diff --git a/pkg/arvo/gen/demo/run.hoon b/pkg/arvo/gen/demo/run.hoon new file mode 100644 index 000000000..0512598d4 --- /dev/null +++ b/pkg/arvo/gen/demo/run.hoon @@ -0,0 +1,8 @@ +/- *demo +:- %say +|= $: [now=@da eny=@uvJ =beak] + [[=term lst=(list action) ~] ~] + == +:- %demo-update-0 +^- action +[%run [p.beak term] lst] diff --git a/pkg/arvo/gen/demo/sub.hoon b/pkg/arvo/gen/demo/sub.hoon new file mode 100644 index 000000000..c360d1993 --- /dev/null +++ b/pkg/arvo/gen/demo/sub.hoon @@ -0,0 +1,8 @@ +/- *demo +:- %say +|= $: [now=@da eny=@uvJ =beak] + [[=term count=@ud ~] ~] + == +:- %demo-update-0 +^- update +[%sub [p.beak term] count] diff --git a/pkg/arvo/mar/demo/update-0.hoon b/pkg/arvo/mar/demo/update-0.hoon new file mode 100644 index 000000000..5f378bf69 --- /dev/null +++ b/pkg/arvo/mar/demo/update-0.hoon @@ -0,0 +1,15 @@ +/- *demo +:: +|_ upd=update +++ grad %noun +++ grow + |% + ++ noun upd + ++ demo-update-1 upd + -- +:: +++ grab + |% + ++ noun update + -- +-- diff --git a/pkg/arvo/mar/demo/update-1.hoon b/pkg/arvo/mar/demo/update-1.hoon new file mode 100644 index 000000000..b495a4051 --- /dev/null +++ b/pkg/arvo/mar/demo/update-1.hoon @@ -0,0 +1,15 @@ +/- *demo +:: +|_ upd=update +++ grad %noun +++ grow + |% + ++ noun upd + ++ demo-update-0 upd + -- +:: +++ grab + |% + ++ noun update + -- +-- diff --git a/pkg/arvo/mar/demo/update.hoon b/pkg/arvo/mar/demo/update.hoon new file mode 100644 index 000000000..e69de29bb diff --git a/pkg/arvo/sur/demo.hoon b/pkg/arvo/sur/demo.hoon new file mode 100644 index 000000000..47592fbfe --- /dev/null +++ b/pkg/arvo/sur/demo.hoon @@ -0,0 +1,10 @@ +/+ resource +|% ++$ update + $~ [%add *resource 0] + $% [%add p=resource q=@ud] + [%sub p=resource q=@ud] + [%ini p=resource ~] + [%run p=resource q=(list update)] + == +-- diff --git a/sh/test-hook b/sh/test-hook new file mode 100755 index 000000000..090f17248 --- /dev/null +++ b/sh/test-hook @@ -0,0 +1,172 @@ +#!/usr/bin/env bash +reset_ship() { + ship=$1 + pier=../../$ship + + downgrade $ship + + herb ./$pier -p hood -d "+hood/fade %demo-store" + herb ./$pier -p hood -d "+hood/fade %demo-pull-hook" + herb ./$pier -p hood -d "+hood/fade %demo-push-hook" + + herb ./$pier -p hood -d "+hood/start %demo-store" + herb ./$pier -p hood -d "+hood/start %demo-pull-hook" + herb ./$pier -p hood -d "+hood/start %demo-push-hook" + + #herb ./$pier -p demo-store -d "+verb" + #herb ./$pier -p demo-push-hook -d "+verb" + #herb ./$pier -p demo-pull-hook -d "+verb" + +} + +start() { + ship=$1 + pier=../../$ship + + herb ./$pier -p demo-store -d "+demo/ini %foo" + herb ./$pier -p demo-push-hook -d "+push/add %foo" + herb ./$pier -p demo-store -d "+demo/add 0 %foo 3" +} + +poke_store() { + ship=$1 + num=$2 + ver=$3 + pier=../../$ship + herb ./$pier -p demo-store -d "+demo/add $ver %foo $num" +} +sub() { + us=$1 + them=$2 + + pier=../../$us + + herb ./$pier -p demo-pull-hook -d "+pull/add ~$them %foo" +} + +print() { + ship=$1 + pier=../../$ship + + herb ./$pier -p demo-store -d "+dbug" + herb ./$pier -p demo-push-hook -d "+dbug" + herb ./$pier -p demo-pull-hook -d "+dbug" +} + + + +upgrade() { + ship=$1 + pier=../../$ship + desk=$pier/home + gsed --in-place "s/demo-update-0/demo-update-1/g" $desk/app/demo-store.hoon + gsed --in-place "14s/.*/1/" $desk/app/demo-pull-hook.hoon + gsed --in-place "14s/.*/1/" $desk/app/demo-push-hook.hoon + herb ./$pier -p hood -d "+hood/commit %home" +} + +upgrade_incompat() { + ship=$1 + pier=../../$ship + desk=$pier/home + gsed --in-place "s/demo-update-0/demo-update-1/g" $desk/app/demo-store.hoon + gsed --in-place "14s/.*/1/" $desk/app/demo-pull-hook.hoon + gsed --in-place "15s/.*/1/" $desk/app/demo-pull-hook.hoon + gsed --in-place "14s/.*/1/" $desk/app/demo-push-hook.hoon + gsed --in-place "15s/.*/1/" $desk/app/demo-push-hook.hoon + herb ./$pier -p hood -d "+hood/commit %home" +} + +downgrade() { + ship=$1 + pier=../../$ship + desk=$pier/home + gsed --in-place "s/demo-update-1/demo-update-0/g" $desk/app/demo-store.hoon + gsed --in-place "14s/.*/0/" $desk/app/demo-pull-hook.hoon + gsed --in-place "15s/.*/0/" $desk/app/demo-pull-hook.hoon + gsed --in-place "14s/.*/0/" $desk/app/demo-push-hook.hoon + gsed --in-place "15s/.*/0/" $desk/app/demo-push-hook.hoon + herb ./$pier -p hood -d "+hood/commit %home" +} + + +sub_ahead() { + echo "subscriber ahead" + reset_ship "zod" + reset_ship "bus" + start "zod" + sub "bus" "zod" + sleep 2 + print "zod" + print "bus" + sleep 2 + upgrade "zod" + sleep 1 + poke_store "zod" 5 1 + sleep 2 + print "zod" + print "bus" +} + + +sub_ahead_incompat() { + echo "subscriber ahead, incompatible" + reset_ship "zod" + reset_ship "bus" + start "zod" + sub "bus" "zod" + sleep 2 + print "zod" + print "bus" + sleep 2 + upgrade_incompat "bus" + sleep 1 + print "bus" + poke_store "zod" 5 0 + sleep 2 + upgrade_incompat "zod" + sleep 3 + print "zod" + print "bus" +} + +pub_ahead() { + echo "publisher ahead" + reset_ship "zod" + reset_ship "bus" + start "zod" + sub "bus" "zod" + sleep 2 + print "zod" + print "bus" + sleep 2 + upgrade "zod" + sleep 1 + poke_store "zod" 5 1 + sleep 2 + print "zod" + print "bus" +} + + +pub_ahead_incompat() { + echo "publisher ahead, incompatible" + reset_ship "zod" + reset_ship "bus" + start "zod" + sub "bus" "zod" + sleep 2 + print "zod" + print "bus" + sleep 2 + upgrade_incompat "zod" + sleep 1 + poke_store "zod" 5 1 + sleep 2 + upgrade_incompat "bus" + sleep 3 + print "zod" + print "bus" +} + +pub_ahead_incompat