mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-23 23:12:04 +03:00
demo: add demo/testing agent for hook libraries
This commit is contained in:
parent
fb502ae519
commit
669dfacd04
58
pkg/arvo/app/demo-pull-hook.hoon
Normal file
58
pkg/arvo/app/demo-pull-hook.hoon
Normal file
@ -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)
|
||||
~& "{<resource>}: kicked"
|
||||
`/
|
||||
::
|
||||
++ resource-for-update
|
||||
|= =vase
|
||||
=+ !<(=update:store vase)
|
||||
~[p.update]
|
||||
--
|
||||
|
65
pkg/arvo/app/demo-push-hook.hoon
Normal file
65
pkg/arvo/app/demo-push-hook.hoon
Normal file
@ -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)
|
||||
::
|
||||
--
|
100
pkg/arvo/app/demo-store.hoon
Normal file
100
pkg/arvo/app/demo-store.hoon
Normal file
@ -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
|
||||
--
|
0
pkg/arvo/app/demo/pull-hook.hoon
Normal file
0
pkg/arvo/app/demo/pull-hook.hoon
Normal file
0
pkg/arvo/app/demo/push-hook.hoon
Normal file
0
pkg/arvo/app/demo/push-hook.hoon
Normal file
8
pkg/arvo/gen/demo/add.hoon
Normal file
8
pkg/arvo/gen/demo/add.hoon
Normal file
@ -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]
|
8
pkg/arvo/gen/demo/ini.hoon
Normal file
8
pkg/arvo/gen/demo/ini.hoon
Normal file
@ -0,0 +1,8 @@
|
||||
/- *demo
|
||||
:- %say
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=term ~] ~]
|
||||
==
|
||||
:- %demo-update-0
|
||||
^- update
|
||||
[%ini [p.beak term] ~]
|
8
pkg/arvo/gen/demo/run.hoon
Normal file
8
pkg/arvo/gen/demo/run.hoon
Normal file
@ -0,0 +1,8 @@
|
||||
/- *demo
|
||||
:- %say
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=term lst=(list action) ~] ~]
|
||||
==
|
||||
:- %demo-update-0
|
||||
^- action
|
||||
[%run [p.beak term] lst]
|
8
pkg/arvo/gen/demo/sub.hoon
Normal file
8
pkg/arvo/gen/demo/sub.hoon
Normal file
@ -0,0 +1,8 @@
|
||||
/- *demo
|
||||
:- %say
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
[[=term count=@ud ~] ~]
|
||||
==
|
||||
:- %demo-update-0
|
||||
^- update
|
||||
[%sub [p.beak term] count]
|
15
pkg/arvo/mar/demo/update-0.hoon
Normal file
15
pkg/arvo/mar/demo/update-0.hoon
Normal file
@ -0,0 +1,15 @@
|
||||
/- *demo
|
||||
::
|
||||
|_ upd=update
|
||||
++ grad %noun
|
||||
++ grow
|
||||
|%
|
||||
++ noun upd
|
||||
++ demo-update-1 upd
|
||||
--
|
||||
::
|
||||
++ grab
|
||||
|%
|
||||
++ noun update
|
||||
--
|
||||
--
|
15
pkg/arvo/mar/demo/update-1.hoon
Normal file
15
pkg/arvo/mar/demo/update-1.hoon
Normal file
@ -0,0 +1,15 @@
|
||||
/- *demo
|
||||
::
|
||||
|_ upd=update
|
||||
++ grad %noun
|
||||
++ grow
|
||||
|%
|
||||
++ noun upd
|
||||
++ demo-update-0 upd
|
||||
--
|
||||
::
|
||||
++ grab
|
||||
|%
|
||||
++ noun update
|
||||
--
|
||||
--
|
0
pkg/arvo/mar/demo/update.hoon
Normal file
0
pkg/arvo/mar/demo/update.hoon
Normal file
10
pkg/arvo/sur/demo.hoon
Normal file
10
pkg/arvo/sur/demo.hoon
Normal file
@ -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)]
|
||||
==
|
||||
--
|
172
sh/test-hook
Executable file
172
sh/test-hook
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user