urbit/app/ph.hoon

354 lines
8.3 KiB
Plaintext
Raw Normal View History

2019-02-12 02:25:25 +03:00
:: Test the pH of your aquarium. See if it's safe to put in real fish.
2019-02-06 05:21:41 +03:00
::
:: usage:
:: :aqua [%run-test %test-add]
::
:: TODO:
:: - Restore a fleet
:: - Compose tests
::
/- aquarium
/+ ph
=, aquarium
=, ph
=> $~ |%
2019-03-06 23:22:37 +03:00
+$ move (pair bone card)
+$ card
2019-03-08 08:15:42 +03:00
$% [%poke wire dock poke-type]
2019-02-09 00:34:24 +03:00
[%peer wire dock path]
[%pull wire dock ~]
2019-03-08 08:15:42 +03:00
[%diff diff-type]
2019-02-06 05:21:41 +03:00
==
::
2019-03-08 08:15:42 +03:00
+$ poke-type
2019-03-07 10:31:14 +03:00
$% [%aqua-events (list aqua-event)]
[%drum-start term term]
2019-03-08 08:15:42 +03:00
[%aqua-vane-control ?(%subscribe %unsubscribe)]
==
::
+$ diff-type
$% [%aqua-effects aqua-effects]
2019-03-07 10:31:14 +03:00
==
::
2019-03-06 23:22:37 +03:00
+$ state
2019-02-06 05:21:41 +03:00
$: %0
2019-03-07 10:31:14 +03:00
raw-test-cores=(map term raw-test-core)
2019-03-06 23:22:37 +03:00
test-cores=(map term test-core-state)
2019-02-06 05:21:41 +03:00
other-state
==
2019-03-06 23:22:37 +03:00
::
+$ test-core-state
$: hers=(list ship)
2019-03-07 10:31:14 +03:00
cor=raw-test-core
effect-log=(list [who=ship uf=unix-effect])
2019-03-06 23:22:37 +03:00
==
::
+$ other-state
2019-02-06 05:21:41 +03:00
$~
--
=, gall
|_ $: hid=bowl
state
==
++ this .
2019-02-12 05:46:36 +03:00
++ test-lib ~(. ^test-lib our.hid)
2019-02-06 05:21:41 +03:00
++ install-tests
^+ this
2019-02-09 00:34:24 +03:00
=. raw-test-cores
2019-02-12 05:46:36 +03:00
~& jael=.^(noun %j /(scot %p our.hid)/code/(scot %da now.hid)/(scot %p our.hid))
=, test-lib
2019-02-06 05:21:41 +03:00
%- malt
2019-03-07 10:31:14 +03:00
^- (list (pair term raw-test-core))
2019-02-06 05:21:41 +03:00
:~
2019-02-09 00:34:24 +03:00
:- %add
2019-03-07 10:31:14 +03:00
^- raw-test-core
2019-02-09 00:34:24 +03:00
=+ num=5
2019-02-13 03:11:19 +03:00
|%
2019-02-12 05:46:36 +03:00
++ label %add
2019-02-12 02:25:25 +03:00
++ ships ~[~bud]
2019-02-06 05:21:41 +03:00
++ start
2019-02-12 05:46:36 +03:00
|= now=@da
2019-02-12 02:25:25 +03:00
^- (pair (list ph-event) _..start)
2019-02-09 00:34:24 +03:00
=. num +(num)
2019-02-12 02:25:25 +03:00
:_ ..start
%- zing
2019-03-06 23:22:37 +03:00
:~ (init ~bud ~)
2019-02-12 02:25:25 +03:00
(dojo ~bud "[%test-result (add 2 3)]")
==
2019-02-06 05:21:41 +03:00
::
++ route
2019-03-07 10:31:14 +03:00
|= [now=@da who=ship uf=unix-effect]
^- [? (quip ph-event _..start)]
2019-02-09 00:34:24 +03:00
~& [%num num]
2019-03-08 08:15:42 +03:00
:- &
2019-02-12 02:25:25 +03:00
:_ ..start
2019-03-07 10:31:14 +03:00
(expect-dojo-output ~bud who uf "[%test-result 5]")
2019-02-06 05:21:41 +03:00
--
::
2019-02-09 00:34:24 +03:00
:- %hi
2019-03-07 10:31:14 +03:00
^- raw-test-core
2019-02-13 03:11:19 +03:00
|%
2019-02-12 05:46:36 +03:00
++ label %hi
2019-02-12 02:53:23 +03:00
++ ships ~[~bud ~dev]
2019-02-06 05:21:41 +03:00
++ start
2019-02-12 05:46:36 +03:00
|= now=@da
2019-02-12 02:25:25 +03:00
^- (pair (list ph-event) _..start)
:_ ..start
%- zing
2019-03-06 23:22:37 +03:00
:~ (init ~bud ~)
(init ~dev ~)
2019-02-12 02:25:25 +03:00
(dojo ~bud "|hi ~dev")
==
2019-02-06 05:21:41 +03:00
::
++ route
2019-03-07 10:31:14 +03:00
|= [now=@da who=ship uf=unix-effect]
^- [? (quip ph-event _..start)]
2019-03-08 08:15:42 +03:00
:- &
2019-02-12 02:25:25 +03:00
:_ ..start
2019-03-07 10:31:14 +03:00
(expect-dojo-output ~bud who uf "hi ~dev successful")
2019-02-06 05:21:41 +03:00
--
2019-02-12 02:25:25 +03:00
::
2019-02-12 05:46:36 +03:00
[%headstart-bud (galaxy ~bud)]
2019-02-12 02:25:25 +03:00
::
2019-02-12 02:53:23 +03:00
:- %composed-child-boot
2019-02-12 05:46:36 +03:00
%+ compose-tests (planet ~linnup-torsyx)
2019-03-08 08:15:42 +03:00
%+ porcelain-test %composed-child-boot
2019-02-13 03:11:19 +03:00
|%
2019-02-12 02:25:25 +03:00
++ start
2019-02-12 05:46:36 +03:00
|= now=@da
2019-02-12 02:53:23 +03:00
[(dojo ~linnup-torsyx "|hi ~bud") ..start]
2019-02-12 02:25:25 +03:00
::
++ route
2019-03-07 10:31:14 +03:00
|= [now=@da who=ship uf=unix-effect]
2019-02-12 02:25:25 +03:00
^- (quip ph-event _..start)
:_ ..start
2019-02-12 02:53:23 +03:00
%- on-dojo-output
2019-03-07 10:31:14 +03:00
:^ ~linnup-torsyx who uf
2019-02-12 02:53:23 +03:00
:- "hi ~bud successful"
|= ~
[%test-done &]~
2019-02-12 02:25:25 +03:00
--
2019-02-12 05:46:36 +03:00
::
:- %composed-child-boot-2
2019-02-12 22:26:48 +03:00
%+ compose-tests
%+ compose-tests (planet ~mitnep-todsut)
(planet ~haplun-todtus)
2019-03-07 10:31:14 +03:00
%+ porcelain-test
%composed-child-boot-2
2019-02-13 03:11:19 +03:00
|%
2019-02-12 05:46:36 +03:00
++ start
|= now=@da
[(dojo ~haplun-todtus "|hi ~bud") ..start]
::
++ route
2019-03-07 10:31:14 +03:00
|= [now=@da who=ship uf=unix-effect]
2019-02-12 05:46:36 +03:00
^- (quip ph-event _..start)
:_ ..start
%- on-dojo-output
2019-03-07 10:31:14 +03:00
:^ ~haplun-todtus who uf
2019-02-12 05:46:36 +03:00
:- "hi ~bud successful"
|= ~
[%test-done &]~
--
2019-02-09 02:21:40 +03:00
::
2019-02-15 04:18:04 +03:00
:- %change-file
%+ compose-tests (galaxy ~bud)
2019-02-23 02:52:18 +03:00
(touch-file ~bud %home)
::
:- %child-sync
%+ compose-tests
2019-02-23 02:52:18 +03:00
%+ compose-tests
(star ~marbud)
(touch-file ~bud %base)
(check-file-touched ~marbud %home)
2019-03-06 23:22:37 +03:00
::
:- %boot-azimuth
%+ compose-tests
%+ compose-tests
(raw-ship ~bud `(dawn:azimuth ~bud))
(touch-file ~bud %home)
:: %- assert-happens
:: :~
:: ==
2019-03-07 10:31:14 +03:00
*raw-test-core
2019-02-09 00:34:24 +03:00
::
:- %individual-breach
2019-03-07 10:31:14 +03:00
*raw-test-core
2019-02-09 00:34:24 +03:00
::
:: (init ~zod)
:: (init ~marzod)
:: wait for sync to finish
:: cycle ~zod keys
:: verify it sunk
:: kill ~zod
:: (init ~zod) w/new keys
:: change file on ~zod
:: wait for sync to finish
2019-02-09 02:21:40 +03:00
:: verify file has changed on ~marzod
2019-02-09 00:34:24 +03:00
::
2019-02-06 05:21:41 +03:00
==
this
::
++ prep
|= old=(unit [@ tests=* rest=*])
2019-02-09 00:34:24 +03:00
^- (quip move _this)
2019-02-06 05:21:41 +03:00
=. this install-tests
?~ old
`this
=/ new ((soft other-state) rest.u.old)
?~ new
`this
2019-02-09 00:34:24 +03:00
`this(+<+>+> u.new)
2019-02-06 05:21:41 +03:00
::
2019-03-07 10:31:14 +03:00
++ publish-aqua-effects
|= afs=aqua-effects
^- (list move)
%+ murn ~(tap by sup.hid)
|= [b=bone her=ship pax=path]
^- (unit move)
?. ?=([%effects ~] pax)
~
2019-03-08 08:15:42 +03:00
`[ost.hid %diff %aqua-effects afs]
2019-03-07 10:31:14 +03:00
::
2019-02-06 05:21:41 +03:00
++ run-events
2019-02-09 00:34:24 +03:00
|= [lab=term what=(list ph-event)]
^- (quip move _this)
2019-02-06 05:21:41 +03:00
?: =(~ what)
`this
=/ res
|- ^- (each (list aqua-event) $~)
?~ what
[%& ~]
?: ?=(%test-done -.i.what)
~& ?~(p.i.what "test successful" "test failed")
[%| ~]
=/ nex $(what t.what)
?: ?=(%| -.nex)
nex
[%& `aqua-event`i.what p.nex]
?: ?=(%| -.res)
2019-02-09 00:34:24 +03:00
(cancel-test lab)
2019-02-06 05:21:41 +03:00
[[ost.hid %poke /running [our.hid %aqua] %aqua-events p.res]~ this]
::
2019-02-09 00:34:24 +03:00
:: Cancel subscriptions to ships
::
++ cancel-test
|= lab=term
^- (quip move _this)
=/ test (~(get by test-cores) lab)
?~ test
`this
=. test-cores (~(del by test-cores) lab)
:_ this
%- zing
%+ turn hers.u.test
|= her=ship
^- (list move)
:~ [ost.hid %pull /[lab]/(scot %p her) [our.hid %aqua] ~]
:* ost.hid
%poke
/cancelling
[our.hid %aqua]
%aqua-events
[%pause-events her]~
==
==
::
2019-02-06 05:21:41 +03:00
:: Should check whether we're already subscribed
::
++ subscribe-to-effects
|= [lab=@tas hers=(list ship)]
:_ this
%+ turn hers
|= her=ship
^- move
:* ost.hid
%peer
/[lab]/(scot %p her)
[our.hid %aqua]
/effects/(scot %p her)
==
::
++ poke-noun
|= arg=*
2019-02-08 05:03:46 +03:00
~& %herm
2019-02-06 05:21:41 +03:00
^- (quip move _this)
?+ arg ~|(%bad-noun-arg !!)
2019-03-07 10:31:14 +03:00
%init
:_ this
%- zing ^- (list (list move))
%+ turn
^- (list term)
~[%aqua-ames %aqua-behn %aqua-dill %aqua-eyre]
|= vane-app=term
:~ [ost.hid %poke /start [our.hid %hood] %drum-start %home vane-app]
[ost.hid %poke /init [our.hid vane-app] %aqua-vane-control %subscribe]
==
::
2019-02-06 05:21:41 +03:00
[%run-test lab=@tas]
2019-03-07 10:31:14 +03:00
=/ res=[events=(list ph-event) new-state=raw-test-core]
2019-02-12 05:46:36 +03:00
(start:(~(got by raw-test-cores) lab.arg) now.hid)
2019-03-06 23:22:37 +03:00
=. test-cores (~(put by test-cores) lab.arg [ships . ~]:new-state.res)
2019-02-12 02:25:25 +03:00
=^ moves-1 this (subscribe-to-effects lab.arg ships.new-state.res)
2019-02-09 00:34:24 +03:00
=^ moves-2 this (run-events lab.arg events.res)
2019-02-06 05:21:41 +03:00
[(weld moves-1 moves-2) this]
2019-03-06 23:22:37 +03:00
::
[%print lab=@tas]
=/ log effect-log:(~(got by test-cores) lab.arg)
~& lent=(lent log)
~& %+ roll log
2019-03-07 10:31:14 +03:00
|= [[who=ship uf=unix-effect] ~]
?: ?=(?(%blit %doze) -.q.uf)
2019-03-06 23:22:37 +03:00
~
2019-03-07 10:31:14 +03:00
?: ?=(%ergo -.q.uf)
~& [who [- +<]:uf %omitted-by-ph]
2019-03-06 23:22:37 +03:00
~
2019-03-07 10:31:14 +03:00
~& [who uf]
2019-03-06 23:22:37 +03:00
~
`this
2019-02-06 05:21:41 +03:00
==
::
2019-02-08 05:03:46 +03:00
++ diff-aqua-effects
2019-03-07 10:31:14 +03:00
|= [way=wire afs=aqua-effects]
2019-02-06 05:21:41 +03:00
^- (quip move _this)
2019-03-08 08:15:42 +03:00
:: ~& [%diff-aqua-effect way who.afs]
2019-02-09 00:34:24 +03:00
?> ?=([@tas @ ~] way)
2019-02-06 05:21:41 +03:00
=/ lab i.way
2019-02-12 00:42:54 +03:00
=/ test-cor (~(get by test-cores) lab)
?~ test-cor
~& [%ph-dropping lab]
`this
2019-03-08 08:15:42 +03:00
=+ |- ^- $: thru-effects=(list unix-effect)
events=(list ph-event)
2019-03-07 10:31:14 +03:00
cor=_u.test-cor
==
2019-03-08 08:15:42 +03:00
?~ ufs.afs
2019-03-07 10:31:14 +03:00
[~ ~ u.test-cor]
=. effect-log.u.test-cor
2019-03-08 08:15:42 +03:00
[[who i.ufs]:afs effect-log.u.test-cor]
=+ ^- [thru=? events-1=(list ph-event) cor=_cor.u.test-cor]
(route:cor.u.test-cor now.hid who.afs i.ufs.afs)
2019-03-07 10:31:14 +03:00
=. cor.u.test-cor cor
2019-03-08 08:15:42 +03:00
=+ $(ufs.afs t.ufs.afs)
2019-03-07 10:31:14 +03:00
:+ ?: thru
2019-03-08 08:15:42 +03:00
[i.ufs.afs thru-effects]
thru-effects
2019-03-07 10:31:14 +03:00
(weld events-1 events)
cor
2019-03-08 08:15:42 +03:00
=. u.test-cor cor
2019-02-12 02:25:25 +03:00
=. test-cores (~(put by test-cores) lab u.test-cor)
2019-03-08 08:15:42 +03:00
=/ moves-1 (publish-aqua-effects who.afs thru-effects)
=^ moves-2 this (run-events lab events)
[(weld moves-1 moves-2) this]
2019-03-07 10:31:14 +03:00
::
:: Subscribe to effects
::
++ peer-effects
|= pax=path
^- (quip move _this)
?. ?=(~ pax)
~& [%ph-bad-peer-effects pax]
`this
`this
2019-02-06 05:21:41 +03:00
--