From 7621c6565be5ba04af2b970d8e557a84f23f1f40 Mon Sep 17 00:00:00 2001 From: Noah Gardner Date: Mon, 16 Nov 2026 11:12:22 -0500 Subject: [PATCH 1/4] build: ez 1.16.0, bolt 1.65.0 Pin bolt v1.65.0 in [tools.bolt]. ez 1.16.0's mkLint runs `bolt check` for a bolt at 1.65 or later, which this repo is. Co-Authored-By: Claude Opus 5.5 --- ez.lock.toml | 6 +++--- ez.toml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ez.lock.toml b/ez.lock.toml index 44654f7..88fb604 100644 --- a/ez.lock.toml +++ b/ez.lock.toml @@ -125,8 +125,8 @@ LICENSE = "309f5aae946e4db157750e002fb179a74ed0fe27fce09a7be68a6977b14f205f" [tools] [tools.bolt] git = "https://github.com/Emerging-Patterns/bolt" -rev = "9700daf3a447089a8795d311912014382a74a2a9" -tag = "v1.27.0" +rev = "dfb06d0e5d6362739231b90bb090535af493b8f0" +tag = "v1.65.0" root = "." -narHash = "sha256-0S48j2dongVcvP5Oms5a+s5I12sIy91KAgwW0bP7pxM=" +narHash = "sha256-39sCydxFW7dWmf69CTJOXuC+j884fEhHWFKctdWCkAg=" entry = "main.bend" diff --git a/ez.toml b/ez.toml index baf8042..47f0721 100644 --- a/ez.toml +++ b/ez.toml @@ -28,8 +28,8 @@ entry = "main.bend" [tools] [tools.bolt] git = "https://github.com/Emerging-Patterns/bolt" -rev = "9700daf3a447089a8795d311912014382a74a2a9" -tag = "v1.27.0" +rev = "dfb06d0e5d6362739231b90bb090535af493b8f0" +tag = "v1.65.0" root = "." -narHash = "sha256-0S48j2dongVcvP5Oms5a+s5I12sIy91KAgwW0bP7pxM=" +narHash = "sha256-39sCydxFW7dWmf69CTJOXuC+j884fEhHWFKctdWCkAg=" entry = "main.bend" From acc259bd97baaf57ccb6c0abb0df12796ab99d09 Mon Sep 17 00:00:00 2001 From: Noah Gardner Date: Mon, 16 Nov 2026 11:17:24 -0500 Subject: [PATCH 2/4] fix(lint): clear bolt 1.65's errors and the pick/concat/prefix findings bolt 1.65 reports 23 errors on ez; all are fixed, behaviour unchanged: - S013 (12): `U32.to_nat()` written as the Nat literal `n`. - U020 (4): unused imports dropped (fetch/world, pub/run, share/cap, tests/fetch). - S009 (3): lock/plan `step.pick` takes the popped walk as one `Walk`; lock/up `dep.hub` takes the checkout it lands on as a new `Moved`; pkg `visit.put` takes the file it opened as a new `Opened` and splits into `visit.keep` / `visit.halt`. The laws and proofs over them are restated over the bundled value, same guarantees. - S010 (2): ez/line `spec` builds init/add/lock/tool from helpers (the three tool targets share one); ez/app `dispatch` hands add and lock to helpers. - S008 (2): ws/joint `source.eq` names its sides left/right; tests/hub names the two packages lib/mid. The six warnings bolt.bend held at "warn" are fixed and the overrides are gone, so pick, concat and prefix are back at their groups' level: - C003 (3): ws/joint `text.at`, ws/workspace `nested` and `twice` match the test first and recurse only past a miss. - U004 (2): io/file `slurp` gathers chunks newest first and joins once. check/serve's request reader reads the head as before, then counts the body by bytes once a byte of it has come, and joins once at the end. - U017 (1): tool/run `line.abs` is `String.starts_with`. Also deletes two defs nothing calls (check/kit `eq_u32`, share/say `stuck`). Co-Authored-By: Claude Opus 5.5 --- bolt.bend | 15 --- laws/LicenseGoesAlong.bend | 2 +- laws/NoLicenseAsBefore.bend | 2 +- proofs/LicenseAsked.bend | 2 +- proofs/NamedImportIsHubDependency.bend | 10 +- proofs/lemmas/DistinctWalkSteps.bend | 4 +- proofs/lemmas/LockPlannerFacts.bend | 22 ++-- proofs/lemmas/UpgradeKeeps.bend | 2 +- proofs/lemmas/UpgradeKeepsNames.bend | 2 +- proofs/lemmas/UpgradeMoves.bend | 10 +- src/add/run.bend | 2 +- src/check/framing.bend | 2 +- src/check/kit.bend | 4 - src/check/oracle.bend | 2 +- src/check/serve.bend | 163 +++++++++++++++---------- src/doctor/run.bend | 2 +- src/ez/app.bend | 24 ++-- src/ez/line.bend | 106 ++++++++-------- src/fetch/run.bend | 2 +- src/fetch/world.bend | 1 - src/io/file.bend | 30 +++-- src/lock/plan.bend | 15 ++- src/lock/run.bend | 2 +- src/lock/up.bend | 20 ++- src/pkg/bench/scan.bend | 2 +- src/pkg/pkg.bend | 66 +++++++--- src/pub/run.bend | 3 +- src/share/cap.bend | 1 - src/share/say.bend | 5 - src/tool/run.bend | 4 +- src/ws/joint.bend | 21 ++-- src/ws/workspace.bend | 22 +++- tests/fetch.bend | 1 - tests/hub.bend | 10 +- 34 files changed, 328 insertions(+), 253 deletions(-) diff --git a/bolt.bend b/bolt.bend index bae9863..946edac 100644 --- a/bolt.bend +++ b/bolt.bend @@ -32,18 +32,3 @@ def coverage() -> String: # law claims one computed case and no guarantee, and nothing exempts one. def closed() -> String: "error" - -# Rules bolt 1.23 to 1.27 added or widened, which fire on code that predates -# them: `pick` (C003, a search bound above its pick: src/ws/joint.bend, -# src/ws/workspace.bend), `concat` (U004, an append passed through a -# continuation: src/check/serve.bend, src/io/file.bend) and `prefix` (U017, a -# take compared to a literal: src/tool/run.bend). They are advice until those -# six findings are fixed, and go back to their groups' level then. -def pick() -> String: - "warn" - -def concat() -> String: - "warn" - -def prefix() -> String: - "warn" diff --git a/laws/LicenseGoesAlong.bend b/laws/LicenseGoesAlong.bend index 4e3632c..3d147f2 100644 --- a/laws/LicenseGoesAlong.bend +++ b/laws/LicenseGoesAlong.bend @@ -22,7 +22,7 @@ law license_goes_along: for rest: List<&2, K.Task> for lic: String for here: {K.Here{lic} == K.find(tree, K.beside(file)) : K.Look} - {K.visit.put(K.Going{}, tree, sc, text, file, ns, eb, seen, out, rest) + {K.visit.put(K.Going{}, tree, K.Opened{file, ns, text, sc}, eb, seen, out, rest) == K.State{file <> seen, K.Hit{K.raw_of(ns, eb), text} <> K.Hit{K.beside(K.raw_of(ns, eb)), lic} <> List.append(&2, K.Hit, diff --git a/laws/NoLicenseAsBefore.bend b/laws/NoLicenseAsBefore.bend index 7b94e20..b45dc9e 100644 --- a/laws/NoLicenseAsBefore.bend +++ b/laws/NoLicenseAsBefore.bend @@ -15,7 +15,7 @@ law no_license_as_before: for out: List<&2, K.Hit> for rest: List<&2, K.Task> for none: {K.Absent{} == K.find(tree, K.beside(file)) : K.Look} - {K.visit.put(K.Going{}, tree, sc, text, file, ns, eb, seen, out, rest) + {K.visit.put(K.Going{}, tree, K.Opened{file, ns, text, sc}, eb, seen, out, rest) == K.State{file <> seen, K.Hit{K.raw_of(ns, eb), text} <> List.append(&2, K.Hit, K.foreigns(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(sc)), out), diff --git a/proofs/LicenseAsked.bend b/proofs/LicenseAsked.bend index f1be794..12183b0 100644 --- a/proofs/LicenseAsked.bend +++ b/proofs/LicenseAsked.bend @@ -8,7 +8,7 @@ def Laws.license_asked(tree, text, file, ns, eb, seen, out, rest, unasked): %unasked : {K.visit.put(K.asked(_, K.beside(file), _u => K.named.check(K.unnamed(K.scan.mods(K.scan(text))), _v => K.foreign.check(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(K.scan(text))))), - tree, K.scan(text), text, file, ns, eb, seen, out, rest) + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Asking{K.beside(file)}, K.Task{file, ns} <> rest} : K.State} {==} diff --git a/proofs/NamedImportIsHubDependency.bend b/proofs/NamedImportIsHubDependency.bend index 4745c2b..441f39a 100644 --- a/proofs/NamedImportIsHubDependency.bend +++ b/proofs/NamedImportIsHubDependency.bend @@ -44,7 +44,7 @@ law unnamed_at: {K.visit.put(K.asked(l, K.beside(file), _u => K.named.check(K.unnamed(K.scan.mods(K.scan(text))), _v => K.foreign.check(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(K.scan(text))))), - tree, K.scan(text), text, file, ns, eb, seen, out, rest) + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Unnamed{K.unnamed(K.scan.mods(K.scan(text)))}, K.Task{file, ns} <> rest} : K.State} @@ -53,20 +53,20 @@ def unnamed_at(l, tree, text, file, ns, eb, seen, out, rest, g, n): case K.Here{_x}: %n : {K.visit.put(K.named.check.at(_, K.unnamed(K.scan.mods(K.scan(text))), _v => K.foreign.check(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(K.scan(text)))), - tree, K.scan(text), text, file, ns, eb, seen, out, rest) + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Unnamed{K.unnamed(K.scan.mods(K.scan(text)))}, K.Task{file, ns} <> rest} : K.State} {==} case K.Absent{}: %n : {K.visit.put(K.named.check.at(_, K.unnamed(K.scan.mods(K.scan(text))), _v => K.foreign.check(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(K.scan(text)))), - tree, K.scan(text), text, file, ns, eb, seen, out, rest) + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Unnamed{K.unnamed(K.scan.mods(K.scan(text)))}, K.Task{file, ns} <> rest} : K.State} {==} case K.Unasked{}: - Eq.bit.absurd2(&2, {K.visit.put(K.Asking{K.beside(file)}, tree, K.scan(text), text, file, ns, - eb, seen, out, rest) + Eq.bit.absurd2(&2, {K.visit.put(K.Asking{K.beside(file)}, + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Unnamed{K.unnamed(K.scan.mods(K.scan(text)))}, K.Task{file, ns} <> rest} : K.State}, g) diff --git a/proofs/lemmas/DistinctWalkSteps.bend b/proofs/lemmas/DistinctWalkSteps.bend index fd35eab..f731e8f 100644 --- a/proofs/lemmas/DistinctWalkSteps.bend +++ b/proofs/lemmas/DistinctWalkSteps.bend @@ -119,8 +119,8 @@ law pick_distinct: for bad: String for e: {D1.packs.distinct(packs) == True{} : Bool} for hs: {Bool.or(L.has(packs, hash), L.seen.holds(asks, hash)) == seen : Bool} - {D1.packs.distinct(P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, rest, packs, - asks, bad))) == True{} : Bool} + {D1.packs.distinct(P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, + P.Walk{rest, packs, asks, bad}))) == True{} : Bool} def pick_distinct(ns, seen, orgs, js, hash, rest, packs, asks, bad, e, hs): match seen: diff --git a/proofs/lemmas/LockPlannerFacts.bend b/proofs/lemmas/LockPlannerFacts.bend index 10a7437..2815650 100644 --- a/proofs/lemmas/LockPlannerFacts.bend +++ b/proofs/lemmas/LockPlannerFacts.bend @@ -987,9 +987,9 @@ law pick_pins: for asks: List<&2, String> for bad: String for e: {D1.pinned.all(orgs, packs) == packs : List<&2, L.Pack>} - {D1.pinned.all(orgs, P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, rest, - packs, asks, bad))) - == P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, rest, packs, asks, bad)) + {D1.pinned.all(orgs, P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, + P.Walk{rest, packs, asks, bad}))) + == P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, P.Walk{rest, packs, asks, bad})) : List<&2, L.Pack>} def pick_pins(ns, seen, orgs, js, hash, rest, packs, asks, bad, e): @@ -1501,7 +1501,7 @@ law mv.fine_hub: for +man: String for srcs: List<&2, String> for +br: String - {mv.fine(Up.dep.hub(hb, M.Dep{hn, hh, he, src}, hash, r, root2, nar2, man, srcs, br), hn) + {mv.fine(Up.dep.hub(hb, M.Dep{hn, hh, he, src}, hash, Up.Moved{r, root2, nar2, man, srcs}, br), hn) == (hn, True{}) : String & Bool} def mv.fine_hub(hb, _hn, _hh, _he, src, _hash, _r, _root2, _nar2, _man, _srcs, _br): @@ -2167,12 +2167,12 @@ law a.hub: for ea: {U.aim(True{}, M.Git{url, r0, tg, rt0, nr0, vd}) == am : U.Aim} for et: {up.tip(am, rs, url) == Up.At{tip, tag, br} : Up.Tip} for eco: {Up.checkout(rs, Up.Tree{url, tip, he}) == Up.Co{nar1, root1, man1, srcs1} : Up.Co} - {again(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), tip, root1, nar1, man1, - srcs1, br), g, rs, only, hub) - == M1.still(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), tip, root1, nar1, - man1, srcs1, br), - fsays(again(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), tip, root1, - nar1, man1, srcs1, br), g, rs, only, hub))) : Up.Fate} + {again(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), + Up.Moved{tip, root1, nar1, man1, srcs1}, br), g, rs, only, hub) + == M1.still(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), + Up.Moved{tip, root1, nar1, man1, srcs1}, br), + fsays(again(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), + Up.Moved{tip, root1, nar1, man1, srcs1}, br), g, rs, only, hub))) : Up.Fate} def a.hub( hb, @@ -2684,7 +2684,7 @@ law hub_back: for manifest: String for srcs: List<&2, String> for +branch: String - {M1.back(Up.dep.hub(hubbed, dep, hash, rev, root, nar, manifest, srcs, branch), dep) == dep : M.Dep} + {M1.back(Up.dep.hub(hubbed, dep, hash, Up.Moved{rev, root, nar, manifest, srcs}, branch), dep) == dep : M.Dep} def hub_back(hubbed, dep, hash, rev, root, nar, manifest, srcs, branch): match hubbed: diff --git a/proofs/lemmas/UpgradeKeeps.bend b/proofs/lemmas/UpgradeKeeps.bend index 7957819..e76bc02 100644 --- a/proofs/lemmas/UpgradeKeeps.bend +++ b/proofs/lemmas/UpgradeKeeps.bend @@ -86,7 +86,7 @@ law st.hub: for +man: String for srcs: List<&2, String> for +br: String - st.fate(Up.dep.hub(hb, M.Dep{hn, hh, he, src}, hash, r, root2, nar2, man, srcs, br), + st.fate(Up.dep.hub(hb, M.Dep{hn, hh, he, src}, hash, Up.Moved{r, root2, nar2, man, srcs}, br), M.Dep{hn, hh, he, src}) def st.hub(hb, _hn, _hh, _he, src, _hash, _r, _root2, _nar2, _man, _srcs, _br): diff --git a/proofs/lemmas/UpgradeKeepsNames.bend b/proofs/lemmas/UpgradeKeepsNames.bend index de2fe17..d87c8eb 100644 --- a/proofs/lemmas/UpgradeKeepsNames.bend +++ b/proofs/lemmas/UpgradeKeepsNames.bend @@ -63,7 +63,7 @@ law hub_name: for manifest: String for srcs: List<&2, String> for +branch: String - {fate.name(Up.dep.hub(hubbed, dep, hash, rev, root, nar, manifest, srcs, branch), M.dep.name(dep)) + {fate.name(Up.dep.hub(hubbed, dep, hash, Up.Moved{rev, root, nar, manifest, srcs}, branch), M.dep.name(dep)) == M.dep.name(dep) : String} def hub_name(hubbed, dep, hash, rev, root, nar, manifest, srcs, branch): diff --git a/proofs/lemmas/UpgradeMoves.bend b/proofs/lemmas/UpgradeMoves.bend index d874363..474e3bf 100644 --- a/proofs/lemmas/UpgradeMoves.bend +++ b/proofs/lemmas/UpgradeMoves.bend @@ -148,8 +148,9 @@ law mv.ok_hub: for +man: String for srcs: List<&2, String> for e: {Up.onward(rs, Up.Above{url, rev, r}) == Up.Asc{True{}} : Up.Asc} - {mv.ok(Up.dep.hub(hb, mv.git(hn, hh, he, url, rev, tag, root, nar, vend), hash, r, root2, - nar2, man, srcs, br), Up.At{r, tg, br}, rs, mv.git(hn, hh, he, url, rev, tag, root, nar, vend)) + {mv.ok(Up.dep.hub(hb, mv.git(hn, hh, he, url, rev, tag, root, nar, vend), hash, + Up.Moved{r, root2, nar2, man, srcs}, br), Up.At{r, tg, br}, rs, + mv.git(hn, hh, he, url, rev, tag, root, nar, vend)) == True{} : Bool} def mv.ok_hub( @@ -1192,8 +1193,9 @@ law mv.live_hub: for +nar2: String for +man: String for srcs: List<&2, String> - {mv.live(Up.dep.hub(hb, mv.git(hn, hh, he, url, rev, tag, root, nar, vend), hash, tip, root2, - nar2, man, srcs, br), tip, mv.git(hn, hh, he, url, rev, tag, root, nar, vend)) == True{} : Bool} + {mv.live(Up.dep.hub(hb, mv.git(hn, hh, he, url, rev, tag, root, nar, vend), hash, + Up.Moved{tip, root2, nar2, man, srcs}, br), tip, + mv.git(hn, hh, he, url, rev, tag, root, nar, vend)) == True{} : Bool} def mv.live_hub( hb, diff --git a/src/add/run.bend b/src/add/run.bend index 1ab0f39..4ddb82f 100644 --- a/src/add/run.bend +++ b/src/add/run.bend @@ -63,7 +63,7 @@ def loop.step(st: AR.Next, +lib: String, world: AR.World, go: AR.World -> IO(Uni # import graph, as `ez lock` does (`Run.rounds`). This is only a guard against # a planner that keeps asking, and running out of it dies loudly. def rounds() -> Nat: - U32.to_nat(100000) + 100000n # the loop, under fuel. Every round adds an answer, since the planner never # asks what the World answers already, so the fuel is only a guard. diff --git a/src/check/framing.bend b/src/check/framing.bend index b5934e3..b51ab0a 100644 --- a/src/check/framing.bend +++ b/src/check/framing.bend @@ -160,7 +160,7 @@ def loop.on(state: Run, rest: Listener -> IO(Unit)) -> IO(Unit): # Bend has no unbounded loop, so "forever" is a count no test run will reach, a # thousand runs of a thousand connections; a server has no input to size it by. def thousand() -> Nat: - U32.to_nat(1000) + 1000n # connections served for as long as the fuel lasts. Bend has no unbounded loop, # so "forever" is a count no test run will reach: a thousand runs of a thousand diff --git a/src/check/kit.bend b/src/check/kit.bend index 26abbb2..f7cbd27 100644 --- a/src/check/kit.bend +++ b/src/check/kit.bend @@ -13,7 +13,3 @@ def say(ok: Bool, name: String, got: String, want: String) -> IO(Unit): # passes when two strings are equal def eq_str(name: String, +got: String, +want: String) -> IO(Unit): say(String.eq(got, want), name, got, want) - -# passes when two U32 are equal -def eq_u32(name: String, got: U32, want: U32) -> IO(Unit): - eq_str(name, U32.show(got), U32.show(want)) diff --git a/src/check/oracle.bend b/src/check/oracle.bend index f19c258..4c02722 100644 --- a/src/check/oracle.bend +++ b/src/check/oracle.bend @@ -692,7 +692,7 @@ def loop.on(state: Run, dir: String, rest: String -> Listener -> IO(Unit)) -> IO # Bend has no unbounded loop, so "forever" is a count no test run will reach, a # thousand runs of a thousand connections; a server has no input to size it by. def thousand() -> Nat: - U32.to_nat(1000) + 1000n # connections served for as long as the fuel lasts. Bend has no unbounded loop, # so "forever" is a count no test run will reach: a thousand runs of a thousand diff --git a/src/check/serve.bend b/src/check/serve.bend index 7a42c52..bf0576e 100644 --- a/src/check/serve.bend +++ b/src/check/serve.bend @@ -111,19 +111,6 @@ def clen(hs: List<&2, String>) -> U32: case h <> t: clen.at(h, clen(t)) -# whether a request has arrived whole -def complete.of(message: Msg) -> Bool: - match message: - case MPartial{}: - False{} - case MFull{head, body}: - U32.is_ge(size(body), clen(head)) - -# whether what has been read so far is the whole request: its head has ended and -# its body is as long as the head said it would be -def complete(text: String) -> Bool: - complete.of(msg.of(text)) - # an answer's bytes, framed by its length. Every one of them states that length # and says the connection closes, because bend, curl and nix's fetcher all read # a body to the length they were promised and then expect the socket to shut. @@ -187,85 +174,135 @@ def pieces(sock: Socket, width: Nat, +text: String) -> IO(Unit): sock2 : Socket <- piece.go(String.length(text), width, sock, text) Socket.close(sock2) +# what has been read so far, the chunks newest first, put back in order +def recv.text(parts: List<&2, String>) -> String: + String.concat(List.reverse(&2, String, parts)) + # an empty chunk means the client stopped writing, whole request or not -def recv.chunk( - chunk: String, - sock: Socket, - acc: String, - rest: Socket -> String -> IO(Socket & String) -) -> IO(Socket & String): - match chunk: +def recv.chunk(text: String) -> Maybe<&1, String>: + match text: case SNil{}: - IO.pure(Socket & String, (sock, acc)) + None{} case SCon{c, t}: - rest(sock, acc ++ SCon{c, t}) + Some{SCon{c, t}} -# None is the peer done sending. Some is the bytes, and an empty chunk is -# the same end. -def recv.taken( - chunk: Maybe<&1, String>, - sock: Socket, - acc: String, - rest: Socket -> String -> IO(Socket & String) -) -> IO(Socket & String): - match chunk: - case None{}: - recv.chunk("", sock, acc, rest) - case Some{text}: - recv.chunk(text, sock, acc, rest) - -# a failed read ends the request as surely as a closed peer -def recv.got( - received: Result<&1, &1, U32 & String, Maybe<&1, String>>, - sock: Socket, - acc: String, - rest: Socket -> String -> IO(Socket & String) -) -> IO(Socket & String): +# what one read gave: a chunk, or None when the peer is done sending, the +# read failed or the chunk was empty, all of which end the request +def recv.got(received: Result<&1, &1, U32 & String, Maybe<&1, String>>) -> Maybe<&1, String>: match received: case Fail{_e}: - IO.pure(Socket & String, (sock, acc)) + None{} case Done{chunk}: - recv.taken(chunk, sock, acc, rest) + Maybe.bind(&1, String, String, chunk, recv.chunk) # the socket comes back paired with what it read -def recv.next( - got: Socket & Result<&1, &1, U32 & String, Maybe<&1, String>>, - acc: String, - rest: Socket -> String -> IO(Socket & String) -) -> IO(Socket & String): +def recv.one.of( + got: Socket & Result<&1, &1, U32 & String, Maybe<&1, String>> +) -> IO(Socket & Maybe<&1, String>): (sock, r) = got - recv.got(r, sock, acc, rest) + IO.pure(Socket & Maybe<&1, String>, (sock, recv.got(r))) + +# one read off the socket, and the socket back +def recv.one(sock: Socket) -> IO(Socket & Maybe<&1, String>): + do IO>: + got : Socket & Result<&1, &1, U32 & String, Maybe<&1, String>> <- TCP.recv(sock, 65536) + recv.one.of(got) + +# a chunk taken into the parts and the walk gone on, or the request as it +# stands once the reads have ended +def recv.then( + read: Socket & Maybe<&1, String>, + parts: List<&2, String>, + rest: Socket -> String -> List<&2, String> -> IO(Socket & String) +) -> IO(Socket & String): + (sock, chunk) = read + match chunk: + case None{}: + IO.pure(Socket & String, (sock, recv.text(parts))) + case Some{+text}: + rest(sock, text, text <> parts) -# nothing more is asked for once the whole request is in hand +# a request that is whole is done; one that is not reads one more chunk and +# goes on with it def recv.more( done: Bool, sock: Socket, - acc: String, - rest: Socket -> String -> IO(Socket & String) + parts: List<&2, String>, + rest: Socket -> String -> List<&2, String> -> IO(Socket & String) ) -> IO(Socket & String): match done: case True{}: - IO.pure(Socket & String, (sock, acc)) + IO.pure(Socket & String, (sock, recv.text(parts))) case False{}: do IO: - got : Socket & Result<&1, &1, U32 & String, Maybe<&1, String>> <- TCP.recv(sock, 65536) - recv.next(got, acc, rest) + read : Socket & Maybe<&1, String> <- recv.one(sock) + recv.then(read, parts, rest) + +# the body, once the head is settled: each chunk is counted as it comes, so +# the request is put together once, when the body is as long as `need` +def recv.body( + fuel: Nat, + sock: Socket, + parts: List<&2, String>, + +have: U32, + +need: U32 +) -> IO(Socket & String): + match fuel: + case 0n: + IO.pure(Socket & String, (sock, recv.text(parts))) + case 1n+f: + recv.more(U32.is_ge(have, need), sock, parts, + s => c => ps => recv.body(f, s, ps, U32.add(have, size(c)), need)) + +# a head that has ended. While nothing of the body has come, the next chunk +# may still move where the head ends, so the head is looked at again. Once a +# byte of the body has come, the head is settled and every later chunk is +# body, so the body goes on by count. +def recv.head.full( + empty: Bool, + +have: U32, + +need: U32, + fuel: Nat, + sock: Socket, + parts: List<&2, String>, + again: Socket -> String -> List<&2, String> -> IO(Socket & String) +) -> IO(Socket & String): + match empty: + case True{}: + recv.more(U32.is_ge(have, need), sock, parts, again) + case False{}: + recv.more(U32.is_ge(have, need), sock, parts, + s => c => ps => recv.body(fuel, s, ps, U32.add(have, size(c)), need)) + +# the head not yet whole: one more chunk read. Whole: on to the body +def recv.head.at( + message: Msg, + fuel: Nat, + sock: Socket, + parts: List<&2, String>, + again: Socket -> String -> List<&2, String> -> IO(Socket & String) +) -> IO(Socket & String): + match message: + case MPartial{}: + recv.more(False{}, sock, parts, again) + case MFull{head, +body}: + recv.head.full(String.is_empty(body), size(body), clen(head), fuel, sock, parts, again) # a whole request read off a socket, one chunk at a time until the head has # ended and the body is as long as Content-Length promised -def recv.go(fuel: Nat, sock: Socket, +acc: String) -> IO(Socket & String): +def recv.head(fuel: Nat, sock: Socket, +parts: List<&2, String>) -> IO(Socket & String): match fuel: case 0n: - IO.pure(Socket & String, (sock, acc)) - case 1n+f: - recv.more(complete(acc), sock, acc, s => a => recv.go(f, s, a)) + IO.pure(Socket & String, (sock, recv.text(parts))) + case 1n+(+f): + recv.head.at(msg.of(recv.text(parts)), f, sock, parts, s => _c => ps => recv.head(f, s, ps)) # the reads a request may take, 64 KiB at most each: 256 MiB, past any request # a test sends. How long a request is is not known until its head has arrived, # so the reads cannot be counted up front. def reads() -> Nat: - U32.to_nat(4096) + 4096n # a whole request read off a socket, and the socket it came on def request(sock: Socket) -> IO(Socket & String): - recv.go(reads(), sock, "") + recv.head(reads(), sock, []) diff --git a/src/doctor/run.bend b/src/doctor/run.bend index 5c68a8c..83d48ee 100644 --- a/src/doctor/run.bend +++ b/src/doctor/run.bend @@ -112,7 +112,7 @@ def loop.step(st: DP.Step, +lib: String, world: DW.World, go: DW.World -> IO(Uni # has answered, so this is a guard against a planner that keeps asking, not # a limit on a project: running out of it dies loudly. def rounds() -> Nat: - U32.to_nat(100000) + 100000n # the loop, under fuel. Every round adds at least one answer, since the # planner never asks what the World answers already, and the lock check asks diff --git a/src/ez/app.bend b/src/ez/app.bend index 1b37839..d20773b 100644 --- a/src/ez/app.bend +++ b/src/ez/app.bend @@ -30,6 +30,20 @@ import ../io/file.bend as F import ../ez/line.bend as L import ../ws/run.bend as WsRun +# `ez add`: the target, ref, entry and rename the line bound, in the member +def dispatch.add(+matched: Shake.Matched) -> IO(Unit): + +target = L.get(matched, "target") + +ref = L.get(matched, "ref") + +entry = L.get(matched, "entry") + +rename = L.get(matched, "rename") + WsRun.in.member(_u => Cmd.add(target, ref, entry, rename)) + +# `ez lock`: `--upgrade` and the package it is limited to, at the root +def dispatch.lock(+matched: Shake.Matched) -> IO(Unit): + +up = Shake.on(matched, "upgrade") + +only = L.get(matched, "package") + WsRun.at.root(_u => Cmd.lock(up, only)) + # what a subcommand runs. `L.line` never runs `CHelp`, which names no # command; it is here so the match is whole, and it writes the help a bare # `ez` would. The directories `ez check` and `ez build` write into are made @@ -41,18 +55,12 @@ def dispatch(sub: L.Sub, +matched: Shake.Matched, +as: List<&2, String>) -> IO(U Cmd.init(L.get(matched, "name"), L.get(matched, "entry"), L.get(matched, "description")) case L.CAdd{}: - +target = L.get(matched, "target") - +ref = L.get(matched, "ref") - +entry = L.get(matched, "entry") - +rename = L.get(matched, "rename") - WsRun.in.member(_u => Cmd.add(target, ref, entry, rename)) + dispatch.add(matched) case L.CRemove{}: +name = L.get(matched, "name") WsRun.in.member(_u => Cmd.remove(name)) case L.CLock{}: - +up = Shake.on(matched, "upgrade") - +only = L.get(matched, "package") - WsRun.at.root(_u => Cmd.lock(up, only)) + dispatch.lock(matched) case L.CFetch{}: WsRun.at.root(_u => Cmd.fetch()) case L.CCheck{}: diff --git a/src/ez/line.bend b/src/ez/line.bend index 7761b90..ef74730 100644 --- a/src/ez/line.bend +++ b/src/ez/line.bend @@ -43,39 +43,71 @@ type Sub is Data: CToolUpgrade{} CHelp{} +# `ez init`: a name, an entry and the one-line description +def spec.init() -> Shake.Sub: + Shake.sub("init", "scaffold a project: ez.toml, ignore, entry, src/", + [ + Shake.pos("name", "package name", False{}, None{}, []), + Shake.pos("entry", "entry file", False{}, None{}, []), + Shake.opt("description", None{}, Some{"description"}, + "one line: the entry's first line, which the hub shows", False{}, None{}, []) + ], []) + +# `ez add`: a target, its ref and entry, and the name to record it under +def spec.add() -> Shake.Sub: + Shake.sub("add", "record a git or hub package", + [ + Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, + []), + Shake.pos("ref", "commit, tag or branch", False{}, None{}, []), + Shake.pos("entry", "entry file", False{}, None{}, []), + Shake.opt("rename", None{}, Some{"rename"}, + "record it under this name, ahead of its own (a TOML bare key)", + False{}, None{}, []) + ], []) + +# `ez lock`: `--upgrade` and the one package it may be limited to +def spec.lock() -> Shake.Sub: + Shake.sub("lock", "resolve every import, write ez.lock.toml", + [ + Shake.flag("upgrade", None{}, Some{"upgrade"}, + "re-pin git deps and tools that moved, then write the lock"), + Shake.opt("package", None{}, Some{"package"}, + "with --upgrade, only this dependency or tool", False{}, None{}, []) + ], []) + +# a `tool` subcommand that names a target and may name the entry to build +def spec.tool.target(+name: String, +about: String) -> Shake.Sub: + Shake.sub(name, about, + [ + Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, + []), + Shake.opt("entry", None{}, Some{"entry"}, + "build this file of the checkout, not the one it names", False{}, None{}, []) + ], []) + +# `ez tool`: the group, with `sync` and the three that take a target +def spec.tool() -> Shake.Sub: + Shake.sub("tool", "build or run another project's binary", [], [ + Shake.sub("sync", "build and link every pinned tool at its lock rev", + [], []), + spec.tool.target("run", "fetch, build and run the binary a repo declares"), + spec.tool.target("install", "build the binary and link it on PATH"), + spec.tool.target("upgrade", "rebuild when the commit moved, and refresh the link") + ]) + # the program: every command, and the flags and positionals it binds def spec() -> Shake.Cli: Shake.app("ez", "dependency tracking and builds for Bend 2", None{}, [], [ - Shake.sub("init", "scaffold a project: ez.toml, ignore, entry, src/", - [ - Shake.pos("name", "package name", False{}, None{}, []), - Shake.pos("entry", "entry file", False{}, None{}, []), - Shake.opt("description", None{}, Some{"description"}, - "one line: the entry's first line, which the hub shows", False{}, None{}, []) - ], []), - Shake.sub("add", "record a git or hub package", - [ - Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, - []), - Shake.pos("ref", "commit, tag or branch", False{}, None{}, []), - Shake.pos("entry", "entry file", False{}, None{}, []), - Shake.opt("rename", None{}, Some{"rename"}, - "record it under this name, ahead of its own (a TOML bare key)", - False{}, None{}, []) - ], []), + spec.init(), + spec.add(), Shake.sub("remove", "drop a package from the ledger", [ Shake.pos("name", "package name", True{}, None{}, []) ], []), - Shake.sub("lock", "resolve every import, write ez.lock.toml", - [ - Shake.flag("upgrade", None{}, Some{"upgrade"}, - "re-pin git deps and tools that moved, then write the lock"), - Shake.opt("package", None{}, Some{"package"}, - "with --upgrade, only this dependency or tool", False{}, None{}, []) - ], []), + spec.lock(), Shake.sub("fetch", "fill BEND_LIB from the lock", [], []), Shake.sub("check", "check the entry, without running it", [], []), Shake.sub("build", "build the entry to a native binary", @@ -83,31 +115,7 @@ def spec() -> Shake.Cli: Shake.pos("out", "output path", False{}, None{}, []) ], []), Shake.sub("run", "check and run the entry", [], []), - Shake.sub("tool", "build or run another project's binary", [], [ - Shake.sub("sync", "build and link every pinned tool at its lock rev", - [], []), - Shake.sub("run", "fetch, build and run the binary a repo declares", - [ - Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, - []), - Shake.opt("entry", None{}, Some{"entry"}, - "build this file of the checkout, not the one it names", False{}, None{}, []) - ], []), - Shake.sub("install", "build the binary and link it on PATH", - [ - Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, - []), - Shake.opt("entry", None{}, Some{"entry"}, - "build this file of the checkout, not the one it names", False{}, None{}, []) - ], []), - Shake.sub("upgrade", "rebuild when the commit moved, and refresh the link", - [ - Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, - []), - Shake.opt("entry", None{}, Some{"entry"}, - "build this file of the checkout, not the one it names", False{}, None{}, []) - ], []) - ]), + spec.tool(), Shake.sub("publish", "send the entry to the hub, under ez's 0x name", [], []), Shake.sub("test", "run every */tests/*.bend against its trailer", [], []), diff --git a/src/fetch/run.bend b/src/fetch/run.bend index b98f45c..4dd85e9 100644 --- a/src/fetch/run.bend +++ b/src/fetch/run.bend @@ -95,7 +95,7 @@ def loop.step(st: FP.Step, +lib: String, world: FW.World, go: FW.World -> IO(Uni # once, so this is only a guard against a planner that keeps asking, and # running out of it dies loudly. def rounds() -> Nat: - U32.to_nat(10) + 10n # the loop, under fuel. A package asks at most twice, for its tree under # BEND_LIB and for its fetch, and every round answers what it asked, so the diff --git a/src/fetch/world.bend b/src/fetch/world.bend index f67ed98..5575afc 100644 --- a/src/fetch/world.bend +++ b/src/fetch/world.bend @@ -25,7 +25,6 @@ # them itself. import Base import ../toml/toml.bend as T -import ../lock/lock.bend as L import ../lock/world.bend as W import ../lock/up.bend as Up diff --git a/src/io/file.bend b/src/io/file.bend index be87689..c7798a6 100644 --- a/src/io/file.bend +++ b/src/io/file.bend @@ -2,26 +2,32 @@ # and chunked reads; this is the loop over them. import Base -# the handle closed, and whatever was gathered -def slurp.end(file: File, acc: String) -> IO(String): +# the handle closed, and whatever was gathered. The chunks are gathered +# newest first, so each read is one prepend, and put in order once here. +def slurp.end(file: File, acc: List<&2, String>) -> IO(String): do IO: File.close(file) - return acc + return String.concat(List.reverse(&2, String, acc)) # an empty chunk means the end of the file -def slurp.cut(chunk: String, file: File, acc: String, rest: File -> String -> IO(String)) -> IO(String): +def slurp.cut( + chunk: String, + file: File, + acc: List<&2, String>, + rest: File -> List<&2, String> -> IO(String) +) -> IO(String): match chunk: case SNil{}: slurp.end(file, acc) case SCon{c, t}: - rest(file, acc ++ SCon{c, t}) + rest(file, SCon{c, t} <> acc) # a failed read ends the file as surely as an empty one def slurp.more( res: Result<&1, &1, U32 & String, String>, file: File, - acc: String, - rest: File -> String -> IO(String) + acc: List<&2, String>, + rest: File -> List<&2, String> -> IO(String) ) -> IO(String): match res: case Fail{_e}: @@ -32,14 +38,14 @@ def slurp.more( # the handle comes back paired with what it read def slurp.next( got: File & Result<&1, &1, U32 & String, String>, - acc: String, - rest: File -> String -> IO(String) + acc: List<&2, String>, + rest: File -> List<&2, String> -> IO(String) ) -> IO(String): (file, r) = got slurp.more(r, file, acc, rest) # the whole file, read in chunks until one is empty, or the fuel is -def slurp(fuel: Nat, file: File, acc: String) -> IO(String): +def slurp(fuel: Nat, file: File, acc: List<&2, String>) -> IO(String): match fuel: case 0n: slurp.end(file, acc) @@ -52,7 +58,7 @@ def slurp(fuel: Nat, file: File, acc: String) -> IO(String): # /proc file reports 0 bytes and a file past 4 GiB fails to report, so these # are read until they end, up to 100000 reads of 64 KiB, past any file ez reads def unsized() -> Nat: - U32.to_nat(100000) + 100000n # a size of 0 is no size to go by; any other is read to def reads.given(none: Bool, bytes: U32) -> Nat: @@ -78,7 +84,7 @@ def reads.of(res: Result<&1, &1, U32 & String, U32>) -> Nat: # a file read whole, with fuel enough for the size it reported def read.sized(got: File & Result<&1, &1, U32 & String, U32>) -> IO(String): (file, r) = got - slurp(reads.of(r), file, "") + slurp(reads.of(r), file, []) # what an opened file holds, or nothing when it would not open def read.opened(res: Result<&1, &1, U32 & String, File>) -> IO(Maybe<&2, String>): diff --git a/src/lock/plan.bend b/src/lock/plan.bend index ef7f944..812f4de 100644 --- a/src/lock/plan.bend +++ b/src/lock/plan.bend @@ -113,22 +113,21 @@ def step.look( case Found{v}: step.verdict(v, ns, src, hash, rest, packs, asks, bad) -# a hash already resolved, or already asked about, is passed over +# a hash already resolved, or already asked about, is passed over. `wk` is +# the walk with the hash popped off its queue. def step.pick( seen: Bool, +orgs: List<&2, L.Origin>, +ns: List<&2, L.Name>, +js: List<&2, W.Judged>, +hash: String, - rest: List<&2, String>, - packs: List<&2, L.Pack>, - asks: List<&2, String>, - bad: String + wk: Walk ) -> Walk: match seen: case True{}: - Walk{rest, packs, asks, bad} + wk case False{}: + Walk{rest, packs, asks, bad} = wk step.look(look(js, hash), ns, L.origin(orgs, hash), hash, rest, packs, asks, bad) # the next hash of the queue, or the walk as it is when the queue is empty @@ -145,8 +144,8 @@ def step.pop( case []: Walk{[], packs, asks, bad} case +h <> t: - step.pick(Bool.or(L.has(packs, h), L.seen.holds(asks, h)), orgs, ns, js, h, t, - packs, asks, bad) + step.pick(Bool.or(L.has(packs, h), L.seen.holds(asks, h)), orgs, ns, js, h, + Walk{t, packs, asks, bad}) # one step of the walk def walk.step(+orgs: List<&2, L.Origin>, +ns: List<&2, L.Name>, +js: List<&2, W.Judged>, wk: Walk) -> Walk: diff --git a/src/lock/run.bend b/src/lock/run.bend index ee1795a..48e2f57 100644 --- a/src/lock/run.bend +++ b/src/lock/run.bend @@ -691,7 +691,7 @@ def loop.step(st: Plan.Step, +lib: String, back: WsUp.Back, world: W.World, go: # it dies loudly. The walk inside each round takes its fuel from its inputs # (`Plan.walk.fuel`). def rounds() -> Nat: - U32.to_nat(100000) + 100000n # the loop, under fuel. Every round adds at least one answer, since the # planner never asks what the World answers already. diff --git a/src/lock/up.bend b/src/lock/up.bend index e249723..952ed81 100644 --- a/src/lock/up.bend +++ b/src/lock/up.bend @@ -648,20 +648,16 @@ def dep.moved( line.if(Bool.not(String.is_empty(drop)), name ++ ": vendored .ez/lib/" ++ hash)), [Laid{hash, nar, manifest, srcs}]} +# the checkout a moved pin lands on: the rev it advances to, and the root, +# NAR hash, manifest and sources the checkout at that rev has +type Moved is Data: + Moved{rev: String, root: String, nar: String, manifest: String, srcs: List<&2, String>} + # the hub's word on the new hash -def dep.hub( - hubbed: Hubbed, - +dep: M.Dep, - +hash: String, - +rev: String, - +root: String, - +nar: String, - manifest: String, - srcs: List<&2, String>, - +branch: String -) -> Fate: +def dep.hub(hubbed: Hubbed, +dep: M.Dep, +hash: String, moved: Moved, +branch: String) -> Fate: match hubbed: case Clear{}: + Moved{rev, root, nar, manifest, srcs} = moved dep.moved(dep, hash, rev, root, nar, manifest, srcs, branch) case Clash{}: Halts{"ez: " ++ M.dep.name(dep) ++ ": hub digest does not match " ++ hash} @@ -676,7 +672,7 @@ def dep.advance(co: Co, +rs: List<&2, Reply>, +hub: String, +dep: M.Dep, +rev: S match co: case Co{nar, root, +manifest, srcs}: +hash = hash.of(manifest) - dep.hub(hubbed(rs, HubHas{hub, hash}), dep, hash, rev, root, nar, manifest, srcs, + dep.hub(hubbed(rs, HubHas{hub, hash}), dep, hash, Moved{rev, root, nar, manifest, srcs}, branch) case CoWait{ask}: Waits{[ask]} diff --git a/src/pkg/bench/scan.bend b/src/pkg/bench/scan.bend index 3076f5a..7907f10 100644 --- a/src/pkg/bench/scan.bend +++ b/src/pkg/bench/scan.bend @@ -160,7 +160,7 @@ def at(xs: List<&2, String>, index: Nat) -> String: def start(as: List<&2, String>) -> IO(Unit): match as: case Nil{}: - IO.print(run("new", U32.to_nat(200000))) + IO.print(run("new", 200000n)) case Con{h, t}: IO.print(run(h, U32.to_nat(Maybe.default(&2, U32, U32.read(at(t, 0n)), 200000)))) diff --git a/src/pkg/pkg.bend b/src/pkg/pkg.bend index 2d8a06d..ffe2c56 100644 --- a/src/pkg/pkg.bend +++ b/src/pkg/pkg.bend @@ -795,6 +795,11 @@ type Stop is Data: Spent{} Unnamed{nv: String} +# a file the walk opened: its path, the name it was reached through, its +# text and that text's scan +type Opened is Data: + Opened{file: String, ns: String, text: String, sc: Scan} + # the walk so far: the files already visited, what was found, whether it has # stopped, and the files still to visit type State is Data: @@ -959,6 +964,38 @@ def foreign.check(+tree: Tree, +dir: String, +nd: String, ats: List<&2, String>) foreign.judge(outside(at), tree, at, P.join(nd, h), _u => foreign.check(tree, dir, nd, t)) +# a file kept: itself, the LICENSE beside it and its foreign bodies found, +# and the modules it imports queued first +def visit.keep( + +tree: Tree, + opened: Opened, + eb: String, + seen: List<&2, String>, + out: List<&2, Hit>, + rest: List<&2, Task> +) -> State: + Opened{+file, +ns, text, +sc} = opened + +d = P.dir(file) + +nd = nsdir(ns) + +raw = raw_of(ns, eb) + State{file <> seen, + Hit{raw, text} <> List.append(&2, Hit, + license.put(find(tree, beside(file)), beside(raw)), + List.append(&2, Hit, foreigns(tree, d, nd, scan.foreign(sc)), out)), + Going{}, + List.append(&2, Task, tasks(d, nd, scan.mods(sc)), rest)} + +# a file whose walk stopped stays queued, to be visited again +def visit.halt( + stop: Stop, + opened: Opened, + seen: List<&2, String>, + out: List<&2, Hit>, + rest: List<&2, Task> +) -> State: + Opened{file, ns, _text, _sc} = opened + State{seen, out, stop, Task{file, ns} <> rest} + # a file whose LICENSE and foreign bodies are all settled: itself, the # LICENSE beside it and its foreign bodies found, and the modules it imports # put at the front of the queue, so the walk goes depth first the way bend's @@ -967,10 +1004,7 @@ def foreign.check(+tree: Tree, +dir: String, +nd: String, ats: List<&2, String>) def visit.put( fstop: Stop, +tree: Tree, - +sc: Scan, - +text: String, - +file: String, - +ns: String, + opened: Opened, eb: String, seen: List<&2, String>, out: List<&2, Hit>, @@ -978,25 +1012,17 @@ def visit.put( ) -> State: match fstop: case Going{}: - +d = P.dir(file) - +nd = nsdir(ns) - +raw = raw_of(ns, eb) - State{file <> seen, - Hit{raw, text} <> List.append(&2, Hit, - license.put(find(tree, beside(file)), beside(raw)), - List.append(&2, Hit, foreigns(tree, d, nd, scan.foreign(sc)), out)), - Going{}, - List.append(&2, Task, tasks(d, nd, scan.mods(sc)), rest)} + visit.keep(tree, opened, eb, seen, out, rest) case Missing{at}: - State{seen, out, Missing{at}, Task{file, ns} <> rest} + visit.halt(Missing{at}, opened, seen, out, rest) case Climbs{at}: - State{seen, out, Climbs{at}, Task{file, ns} <> rest} + visit.halt(Climbs{at}, opened, seen, out, rest) case Asking{at}: - State{seen, out, Asking{at}, Task{file, ns} <> rest} + visit.halt(Asking{at}, opened, seen, out, rest) case Spent{}: - State{seen, out, Spent{}, Task{file, ns} <> rest} + visit.halt(Spent{}, opened, seen, out, rest) case Unnamed{nv}: - State{seen, out, Unnamed{nv}, Task{file, ns} <> rest} + visit.halt(Unnamed{nv}, opened, seen, out, rest) # a file that imports a name the hub rules out stops the walk, naming it, as # bend refuses to load it; any other goes on to its foreign bodies @@ -1026,7 +1052,7 @@ def visit.found( visit.put(asked(find(tree, beside(file)), beside(file), _u => named.check(unnamed(scan.mods(sc)), _v => foreign.check(tree, P.dir(file), nsdir(ns), scan.foreign(sc)))), - tree, sc, text, file, ns, eb, seen, out, rest) + tree, Opened{file, ns, text, sc}, eb, seen, out, rest) # a module that is imported and not there stops the walk, since a package # missing a file is not the package bend would publish. One the walk was not @@ -1560,7 +1586,7 @@ def resumed.fuel(+tree: Tree, +st: State) -> Nat: # is a guard against a walk that keeps asking, not a limit on a package: a # package of more files than this is refused, never hashed short. def asks() -> Nat: - U32.to_nat(100000) + 100000n # the walk over what has been read so far, and each file it asks for read # and handed back, until it no longer asks diff --git a/src/pub/run.bend b/src/pub/run.bend index c13c95f..55f69d0 100644 --- a/src/pub/run.bend +++ b/src/pub/run.bend @@ -25,7 +25,6 @@ import ../io/file.bend as F import ../lock/run.bend as Run import ../tool/run.bend as ToolRun import ../tool/world.bend as TW -import ../hub/hub.bend as Web import ../hub/get.bend as Net import ../share/env.bend as Env import ./world.bend as PW @@ -94,7 +93,7 @@ def loop.step(st: PP.Step, +lib: String, world: PW.World, go: PW.World -> IO(Uni # against a planner that keeps asking, not a limit on a package: running out # of it dies loudly. def rounds() -> Nat: - U32.to_nat(100000) + 100000n # the loop, under fuel. The walk asks for one file a round, so the fuel is a # guard against a planner that keeps asking, not a limit on a package. diff --git a/src/share/cap.bend b/src/share/cap.bend index e0124c0..de62d32 100644 --- a/src/share/cap.bend +++ b/src/share/cap.bend @@ -9,7 +9,6 @@ import Base import snap@1.4.0.0/main.bend as R import ./env.bend as Env -import ./args.bend as Args # how many gigabytes one `bend` may have. 8 is what fits beside the rest of # this machine; a project whose closure costs more says so in EZ_CAP. diff --git a/src/share/say.bend b/src/share/say.bend index a629d87..46439e7 100644 --- a/src/share/say.bend +++ b/src/share/say.bend @@ -149,11 +149,6 @@ def drift(+name: String, +tag: String, +rev: String, +old: String, +new: String) old ++ " on the pin, " ++ new ++ " in the tree). `ez lock --upgrade` cannot fix a drifted pin. Update the dependency hash, re-add the package, or check the tag." -# a drift judged before the tree was weighed, so there are not two hashes to show -def stuck(+name: String) -> String: - "ez: " ++ name ++ - ": the pin drifted. `ez lock --upgrade` cannot fix a drifted pin. Update the dependency hash, re-add the package, or check the tag." - # a `[tools.` section in the ledger text. The parser is not asked: a ledger # that does not parse can still have named the command. def has.tools(+text: String) -> Bool: diff --git a/src/tool/run.bend b/src/tool/run.bend index 9383543..2d60722 100644 --- a/src/tool/run.bend +++ b/src/tool/run.bend @@ -68,7 +68,7 @@ def said.rev(ls: List<&2, String>) -> String: # a line that is an absolute path, as `rev-parse --show-toplevel` prints one def line.abs(+line: String) -> Bool: - String.eq(String.take(line, 1n), "/") + String.starts_with(line, "/") # the first line that is an absolute path, or "" def said.abs(ls: List<&2, String>) -> String: @@ -278,7 +278,7 @@ def loop.step(st: TP.Step, world: TW.World, go: TW.World -> IO(Unit)) -> IO(Unit # is only a guard against a planner that keeps asking, and running out of it # dies loudly. def rounds() -> Nat: - U32.to_nat(100) + 100n # the loop, under fuel. Every round adds an answer, since the planner never # asks what the World answers already, and it asks at most five rounds, so diff --git a/src/ws/joint.bend b/src/ws/joint.bend index 2a62f25..9f366f8 100644 --- a/src/ws/joint.bend +++ b/src/ws/joint.bend @@ -160,10 +160,10 @@ def bit.eq(aa: Bool, bb: Bool) -> Bool: Bool.not(bb) # whether two sources are one -def source.eq(aa: M.Source, bb: M.Source) -> Bool: - match aa: +def source.eq(left: M.Source, right: M.Source) -> Bool: + match left: case M.Hub{an}: - match bb: + match right: case M.Hub{bn}: String.eq(an, bn) case M.Git{_u, _r, _t, _o, _n, _v}: @@ -171,7 +171,7 @@ def source.eq(aa: M.Source, bb: M.Source) -> Bool: case M.Member{_p, _m}: False{} case M.Git{au, ar, at, ao, an, av}: - match bb: + match right: case M.Hub{_bn}: False{} case M.Git{bu, br, bt, bo, bn, bv}: @@ -181,7 +181,7 @@ def source.eq(aa: M.Source, bb: M.Source) -> Bool: case M.Member{_p, _m}: False{} case M.Member{ap, am}: - match bb: + match right: case M.Hub{_bn}: False{} case M.Git{_u, _r, _t, _o, _n, _v}: @@ -682,14 +682,21 @@ def resolve(+root: M.Manifest, ms: List<&2, Member>, +files: List<&2, K.Source>) # --------------------------------------------------------------------------- # the answers the lock reads a member's package from +# the text of the file at the path, or the search gone on past it +def text.at.hit(hit: Bool, ft: String, rest: Unit -> String) -> String: + match hit: + case True{}: + ft + case False{}: + rest(Unit{}) + # a file's text in a walk's files, "" when it holds none at that path def text.at(fs: List<&2, K.Source>, +at: String) -> String: match fs: case []: "" case K.Source{+fa, ft} <> tl: - rest = text.at(tl, at) - Bool.pick(String, String.eq(fa, at), ft, rest) + text.at.hit(String.eq(fa, at), ft, _u => text.at(tl, at)) # the texts of a walk's files, in its manifest's order def texts(sums: List<&2, K.Item>, +fs: List<&2, K.Source>) -> List<&2, String>: diff --git a/src/ws/workspace.bend b/src/ws/workspace.bend index b4b0d8f..84336ad 100644 --- a/src/ws/workspace.bend +++ b/src/ws/workspace.bend @@ -301,14 +301,21 @@ def unnested(ls: List<&2, Ledger>) -> Bool: rest = unnested(tl) Bool.and(Bool.not(ledger.nested(hd)), rest) +# the member whose ledger has a `[workspace]` table, or the search gone on +def nested.hit(hit: Bool, hd: Ledger, rest: Unit -> String) -> String: + match hit: + case True{}: + segs.text(ledger.dir(hd)) + case False{}: + rest(Unit{}) + # the first member whose ledger has a `[workspace]` table, "" for none def nested(ls: List<&2, Ledger>) -> String: match ls: case []: "" case +hd <> tl: - rest = nested(tl) - Bool.pick(String, ledger.nested(hd), segs.text(ledger.dir(hd)), rest) + nested.hit(ledger.nested(hd), hd, _u => nested(tl)) # the package name of every ledger, in order def names.of(ls: List<&2, Ledger>) -> List<&2, String>: @@ -344,14 +351,21 @@ def distinct(ns: List<&2, String>) -> Bool: rest = distinct(tl) Bool.and(Bool.not(named(tl, hd)), rest) +# the name that is in the list again, or the search gone on +def twice.hit(hit: Bool, hd: String, rest: Unit -> String) -> String: + match hit: + case True{}: + hd + case False{}: + rest(Unit{}) + # the first name in the list twice, "" for none def twice(ns: List<&2, String>) -> String: match ns: case []: "" case +hd <> +tl: - rest = twice(tl) - Bool.pick(String, named(tl, hd), hd, rest) + twice.hit(named(tl, hd), hd, _u => twice(tl)) # whether the root is a member def root.member(root: Root) -> Bool: diff --git a/tests/fetch.bend b/tests/fetch.bend index e8d8c90..0ab9feb 100644 --- a/tests/fetch.bend +++ b/tests/fetch.bend @@ -5,7 +5,6 @@ # It is under tests/ rather than hub/tests/ because it drives a socket, and the # unit tests beside the code are about what can be said without one. import Base -import ../src/hub/hub.bend as Hub import ../src/hub/get.bend as Net import snap@1.4.0.0/main.bend as R import ../src/check/kit.bend as Check diff --git a/tests/hub.bend b/tests/hub.bend index 9738b51..3b709b3 100644 --- a/tests/hub.bend +++ b/tests/hub.bend @@ -76,15 +76,15 @@ def go(+repo: String, +root: String, +port: String) -> IO(Unit): do IO: W.mkdir(root ++ "/app") W.mkdir(root ++ "/empty") - +a : String <- publish(root ++ "/hub", "src/lib.bend", + +lib : String <- publish(root ++ "/hub", "src/lib.bend", "import Base\n\n# double the number\ndef double(+x: U32) -> U32:\n" ++ " (x * 2 : U32)\n") - +b : String <- publish(root ++ "/hub", "src/mid.bend", - "import Base\nimport " ++ a ++ "/src/lib.bend as A\n\n" ++ + +mid : String <- publish(root ++ "/hub", "src/mid.bend", + "import Base\nimport " ++ lib ++ "/src/lib.bend as A\n\n" ++ "# four times the number\ndef quad(+x: U32) -> U32:\n" ++ " A.double(A.double(x))\n") _w : Bool <- F.write(root ++ "/app/main.bend", - "import Base\nimport " ++ b ++ "/src/mid.bend as B\n\n" ++ + "import Base\nimport " ++ mid ++ "/src/mid.bend as B\n\n" ++ "def main() -> U32:\n B.quad(11)\n") +pid : String <- W.spawn(W.inside(root ++ "/hub", ["python3", "-m", "http.server", port, "--bind", "127.0.0.1"])) @@ -97,7 +97,7 @@ def go(+repo: String, +root: String, +port: String) -> IO(Unit): hs : List<&2, String> <- named(at) Check.eq_str("the lock names both packages, the direct one and its own " ++ "dependency", String.join(hs, "\n"), - String.join(List.sort(~String, ~String.is_le, [a, b]), "\n")) + String.join(List.sort(~String, ~String.is_le, [lib, mid]), "\n")) restore(repo, root ++ "/app", "http://127.0.0.1:" ++ port) W.stop(pid) +good : String <- build(root ++ "/app", root ++ "/app/.ez/lib") From f75f5f270e52ea2038472015127803d0ee87857e Mon Sep 17 00:00:00 2001 From: Noah Gardner Date: Mon, 16 Nov 2026 11:34:07 -0500 Subject: [PATCH 3/4] fix(lint): coverage at error Every def and type bolt's coverage rule (L001) flagged is now reached by a quantified law or says on its def line why no law can reach it, so `laws` and `coverage` are errors in bolt.bend again. - 25 new guarantee files under laws/, each proved by its namesake under proofs/: NarBuildsTree, NarHashForm, NarListingRows, CommandLineWords, CappedRunWords, EnvFallsBack, ProgressNamesBriefly, ServeSpeaksHttp, FramingAnswersRoutes, ServerArgsAfterName, LiarHidesAnswerWhenMute, TestOutputPicksLines, OracleReadsPublishBody, ProofPassesOnVerdictLine, TestTallyCounts, TestBudgetOnlyWhenSet, RefusalReasonShown, PlaceShownOnOneLine, PackagePrintedWithHash, RunOutputFiltered, SortKeepsEveryString, LineNeverRunsHelp, BenchScanAnswersMode, RepliesJoinTheWorld, StepRunsThePlan; NonTrailerLineSkipped gains `trailer_skips`. All state internal behavior. - Pure decisions that lived in modules that run programs move beside their pure siblings so a law can import them: src/share/capped.bend (from share/cap), src/ez/verdict.bend (from ez/prove and ez/test), src/check/body.bend and argv.bend (from check/oracle, check/framing), src/check/out.bend (from check/world), each command's `more` into its world/relock module, and lock/run's `said`, `gots`, `place` into lock/world and lock/plan. Behaviour is unchanged. - Dead or duplicated defs deleted: lock/plan `needed`, `answered`; add/plan `answered`; add/hub `names`; tool/world `here`; pub/world `lockfile`; hub/hub `show`; sha/dump `printed` (snap's R.text); lock/run `nonempty` and ws/run `lines` (Args.nonempty). - IO drivers, their fuel constants, and message wording carry `# noqa: L001 ` per the fleet convention (162 defs). Co-Authored-By: Claude Opus 5.5 --- LAWS.bend | 25 ++ PROOF.bend | 25 ++ bolt.bend | 13 +- laws/BenchScanAnswersMode.bend | 52 +++ laws/CappedRunWords.bend | 50 +++ laws/CommandLineWords.bend | 51 +++ laws/EnvFallsBack.bend | 17 + laws/FramingAnswersRoutes.bend | 59 +++ laws/LiarHidesAnswerWhenMute.bend | 51 +++ laws/LineNeverRunsHelp.bend | 40 ++ laws/NarBuildsTree.bend | 74 ++++ laws/NarHashForm.bend | 49 +++ laws/NarListingRows.bend | 27 ++ laws/NonTrailerLineSkipped.bend | 10 + laws/OracleReadsPublishBody.bend | 71 ++++ laws/PackagePrintedWithHash.bend | 36 ++ laws/PlaceShownOnOneLine.bend | 22 ++ laws/ProgressNamesBriefly.bend | 36 ++ laws/ProofPassesOnVerdictLine.bend | 53 +++ laws/RefusalReasonShown.bend | 16 + laws/RepliesJoinTheWorld.bend | 141 +++++++ laws/RunOutputFiltered.bend | 43 +++ laws/ServeSpeaksHttp.bend | 94 +++++ laws/ServerArgsAfterName.bend | 24 ++ laws/SortKeepsEveryString.bend | 19 + laws/StepRunsThePlan.bend | 112 ++++++ laws/TestBudgetOnlyWhenSet.bend | 24 ++ laws/TestOutputPicksLines.bend | 126 ++++++ laws/TestTallyCounts.bend | 19 + main.bend | 2 +- proofs/BenchScanAnswersMode.bend | 36 ++ proofs/CappedRunWords.bend | 22 ++ proofs/CommandLineWords.bend | 30 ++ proofs/EnvFallsBack.bend | 12 + proofs/FramingAnswersRoutes.bend | 40 ++ proofs/LiarHidesAnswerWhenMute.bend | 22 ++ proofs/LineNeverRunsHelp.bend | 74 ++++ proofs/NarBuildsTree.bend | 29 ++ proofs/NarHashForm.bend | 37 ++ proofs/NarListingRows.bend | 10 + proofs/NonTrailerLineSkipped.bend | 6 + proofs/OracleReadsPublishBody.bend | 41 ++ proofs/PackagePrintedWithHash.bend | 15 + proofs/PlaceShownOnOneLine.bend | 12 + proofs/ProgressNamesBriefly.bend | 22 ++ proofs/ProofPassesOnVerdictLine.bend | 33 ++ proofs/RefusalReasonShown.bend | 9 + proofs/RepliesJoinTheWorld.bend | 46 +++ proofs/RunOutputFiltered.bend | 39 ++ proofs/ServeSpeaksHttp.bend | 58 +++ proofs/ServerArgsAfterName.bend | 12 + proofs/SortKeepsEveryString.bend | 39 ++ proofs/StepRunsThePlan.bend | 250 ++++++++++++ proofs/TestBudgetOnlyWhenSet.bend | 29 ++ proofs/TestOutputPicksLines.bend | 60 +++ proofs/TestTallyCounts.bend | 9 + src/add/hub.bend | 17 - src/add/plan.bend | 4 - src/add/relock.bend | 15 + src/add/run.bend | 39 +- src/add/world.bend | 10 + src/check/argv.bend | 22 ++ src/check/body.bend | 493 ++++++++++++++++++++++++ src/check/framing.bend | 21 +- src/check/kit.bend | 4 +- src/check/liar.bend | 21 +- src/check/oracle.bend | 555 ++------------------------- src/check/out.bend | 114 ++++++ src/check/serve.bend | 8 +- src/check/world.bend | 138 +------ src/doctor/run.bend | 27 +- src/doctor/world.bend | 5 + src/ez/app.bend | 6 +- src/ez/cache.bend | 2 +- src/ez/cmd.bend | 31 +- src/ez/prove.bend | 71 +--- src/ez/start.bend | 6 +- src/ez/test.bend | 70 ++-- src/ez/timer.bend | 8 +- src/ez/verdict.bend | 75 ++++ src/fetch/run.bend | 27 +- src/fetch/world.bend | 5 + src/git/exec.bend | 14 +- src/git/git.bend | 2 +- src/hub/get.bend | 4 +- src/hub/hub.bend | 8 - src/init/run.bend | 2 +- src/io/file.bend | 4 +- src/lock/plan.bend | 19 +- src/lock/run.bend | 95 ++--- src/lock/world.bend | 27 ++ src/pkg/pkg.bend | 17 +- src/pub/run.bend | 20 +- src/pub/world.bend | 9 +- src/remove/relock.bend | 5 + src/remove/run.bend | 16 +- src/run/bend.bend | 2 +- src/sha/dump.bend | 29 +- src/share/args.bend | 2 +- src/share/cap.bend | 42 +- src/share/capped.bend | 36 ++ src/share/env.bend | 4 +- src/share/exec.bend | 4 +- src/share/pass.bend | 2 +- src/share/say.bend | 20 +- src/share/spin.bend | 12 +- src/tool/run.bend | 47 +-- src/tool/world.bend | 11 +- src/ws/run.bend | 38 +- tests/cli.bend | 35 +- tests/git.bend | 27 +- tests/hub.bend | 13 +- tests/init.bend | 21 +- tests/nix.bend | 11 +- tests/publish.bend | 7 +- tests/publishing.bend | 13 +- tests/relock.bend | 13 +- 117 files changed, 3590 insertions(+), 1208 deletions(-) create mode 100644 laws/BenchScanAnswersMode.bend create mode 100644 laws/CappedRunWords.bend create mode 100644 laws/CommandLineWords.bend create mode 100644 laws/EnvFallsBack.bend create mode 100644 laws/FramingAnswersRoutes.bend create mode 100644 laws/LiarHidesAnswerWhenMute.bend create mode 100644 laws/LineNeverRunsHelp.bend create mode 100644 laws/NarBuildsTree.bend create mode 100644 laws/NarHashForm.bend create mode 100644 laws/NarListingRows.bend create mode 100644 laws/OracleReadsPublishBody.bend create mode 100644 laws/PackagePrintedWithHash.bend create mode 100644 laws/PlaceShownOnOneLine.bend create mode 100644 laws/ProgressNamesBriefly.bend create mode 100644 laws/ProofPassesOnVerdictLine.bend create mode 100644 laws/RefusalReasonShown.bend create mode 100644 laws/RepliesJoinTheWorld.bend create mode 100644 laws/RunOutputFiltered.bend create mode 100644 laws/ServeSpeaksHttp.bend create mode 100644 laws/ServerArgsAfterName.bend create mode 100644 laws/SortKeepsEveryString.bend create mode 100644 laws/StepRunsThePlan.bend create mode 100644 laws/TestBudgetOnlyWhenSet.bend create mode 100644 laws/TestOutputPicksLines.bend create mode 100644 laws/TestTallyCounts.bend create mode 100644 proofs/BenchScanAnswersMode.bend create mode 100644 proofs/CappedRunWords.bend create mode 100644 proofs/CommandLineWords.bend create mode 100644 proofs/EnvFallsBack.bend create mode 100644 proofs/FramingAnswersRoutes.bend create mode 100644 proofs/LiarHidesAnswerWhenMute.bend create mode 100644 proofs/LineNeverRunsHelp.bend create mode 100644 proofs/NarBuildsTree.bend create mode 100644 proofs/NarHashForm.bend create mode 100644 proofs/NarListingRows.bend create mode 100644 proofs/OracleReadsPublishBody.bend create mode 100644 proofs/PackagePrintedWithHash.bend create mode 100644 proofs/PlaceShownOnOneLine.bend create mode 100644 proofs/ProgressNamesBriefly.bend create mode 100644 proofs/ProofPassesOnVerdictLine.bend create mode 100644 proofs/RefusalReasonShown.bend create mode 100644 proofs/RepliesJoinTheWorld.bend create mode 100644 proofs/RunOutputFiltered.bend create mode 100644 proofs/ServeSpeaksHttp.bend create mode 100644 proofs/ServerArgsAfterName.bend create mode 100644 proofs/SortKeepsEveryString.bend create mode 100644 proofs/StepRunsThePlan.bend create mode 100644 proofs/TestBudgetOnlyWhenSet.bend create mode 100644 proofs/TestOutputPicksLines.bend create mode 100644 proofs/TestTallyCounts.bend create mode 100644 src/check/argv.bend create mode 100644 src/check/body.bend create mode 100644 src/check/out.bend create mode 100644 src/ez/verdict.bend create mode 100644 src/share/capped.bend diff --git a/LAWS.bend b/LAWS.bend index 6008bc1..7325cea 100644 --- a/LAWS.bend +++ b/LAWS.bend @@ -36,14 +36,17 @@ import ./laws/AddEntryChosen.bend as AddEntryChosen import ./laws/AddNotesUnlockedPackage.bend as AddNotesUnlockedPackage import ./laws/AddPinsChosenRef.bend as AddPinsChosenRef import ./laws/AddRemoveRelock.bend as AddRemoveRelock +import ./laws/BenchScanAnswersMode.bend as BenchScanAnswersMode import ./laws/BodyLineEndsHeader.bend as BodyLineEndsHeader import ./laws/BuildMakesBin.bend as BuildMakesBin import ./laws/BuildWithOutMakesNothing.bend as BuildWithOutMakesNothing +import ./laws/CappedRunWords.bend as CappedRunWords import ./laws/CheckMakesEzDir.bend as CheckMakesEzDir import ./laws/ClimbCancelsComponent.bend as ClimbCancelsComponent import ./laws/ClimbOfZeroNormalizes.bend as ClimbOfZeroNormalizes import ./laws/ClimbedAbsolutePathStaysAbsolute.bend as ClimbedAbsolutePathStaysAbsolute import ./laws/ClimbsStack.bend as ClimbsStack +import ./laws/CommandLineWords.bend as CommandLineWords import ./laws/CommandsNeedLedger.bend as CommandsNeedLedger import ./laws/DepOpensItsSection.bend as DepOpensItsSection import ./laws/DependenciesRenderInOrder.bend as DependenciesRenderInOrder @@ -63,6 +66,7 @@ import ./laws/EmptyLedgerClashesWithNone.bend as EmptyLedgerClashesWithNone import ./laws/EmptyLedgerTakesSourceName.bend as EmptyLedgerTakesSourceName import ./laws/EmptyLockWithDepsFails.bend as EmptyLockWithDepsFails import ./laws/EmptyValueWritesNoLine.bend as EmptyValueWritesNoLine +import ./laws/EnvFallsBack.bend as EnvFallsBack import ./laws/EqualsInPathNamed.bend as EqualsInPathNamed import ./laws/EqualsInPathUnlockable.bend as EqualsInPathUnlockable import ./laws/EscapingImportRefused.bend as EscapingImportRefused @@ -77,6 +81,7 @@ import ./laws/FirstSectionWins.bend as FirstSectionWins import ./laws/ForeignBodyGatheredAnywhere.bend as ForeignBodyGatheredAnywhere import ./laws/ForeignLicenseGoesAlong.bend as ForeignLicenseGoesAlong import ./laws/FoundFileIsPublished.bend as FoundFileIsPublished +import ./laws/FramingAnswersRoutes.bend as FramingAnswersRoutes import ./laws/FullToolPinCopied.bend as FullToolPinCopied import ./laws/GitNamedWithoutLicense.bend as GitNamedWithoutLicense import ./laws/GitNamedWithoutReadme.bend as GitNamedWithoutReadme @@ -106,11 +111,13 @@ import ./laws/LedgerNamesFirst.bend as LedgerNamesFirst import ./laws/LedgerRemoveIdempotent.bend as LedgerRemoveIdempotent import ./laws/LedgerTextOpensWithPackage.bend as LedgerTextOpensWithPackage import ./laws/LedgerWithoutDepsNeedsNoLock.bend as LedgerWithoutDepsNeedsNoLock +import ./laws/LiarHidesAnswerWhenMute.bend as LiarHidesAnswerWhenMute import ./laws/LibJudgedAsClone.bend as LibJudgedAsClone import ./laws/LicenseAsked.bend as LicenseAsked import ./laws/LicenseDirNamed.bend as LicenseDirNamed import ./laws/LicenseDirRefused.bend as LicenseDirRefused import ./laws/LicenseGoesAlong.bend as LicenseGoesAlong +import ./laws/LineNeverRunsHelp.bend as LineNeverRunsHelp import ./laws/LockIdempotent.bend as LockIdempotent import ./laws/LockIgnoresWalkOrder.bend as LockIgnoresWalkOrder import ./laws/LockLaysItsNames.bend as LockLaysItsNames @@ -126,7 +133,10 @@ import ./laws/MissingNarHashRefused.bend as MissingNarHashRefused import ./laws/MissingRootIsCheckoutTop.bend as MissingRootIsCheckoutTop import ./laws/NameFilesLaid.bend as NameFilesLaid import ./laws/NamedImportIsHubDependency.bend as NamedImportIsHubDependency +import ./laws/NarBuildsTree.bend as NarBuildsTree +import ./laws/NarHashForm.bend as NarHashForm import ./laws/NarIgnoresEntryOrder.bend as NarIgnoresEntryOrder +import ./laws/NarListingRows.bend as NarListingRows import ./laws/NarReadsNamesVerbatim.bend as NarReadsNamesVerbatim import ./laws/NarlessToolPinRefused.bend as NarlessToolPinRefused import ./laws/NoLicenseAsBefore.bend as NoLicenseAsBefore @@ -139,15 +149,18 @@ import ./laws/NormKeepsRootFlag.bend as NormKeepsRootFlag import ./laws/OldNameKeepsOtherFiles.bend as OldNameKeepsOtherFiles import ./laws/OldNameLeavesLicenseOut.bend as OldNameLeavesLicenseOut import ./laws/OldNameLeavesReadmeOut.bend as OldNameLeavesReadmeOut +import ./laws/OracleReadsPublishBody.bend as OracleReadsPublishBody import ./laws/OtherCommandsMakeNoDir.bend as OtherCommandsMakeNoDir import ./laws/OtherGitSourceLendsNoName.bend as OtherGitSourceLendsNoName import ./laws/OtherNameIsNoClash.bend as OtherNameIsNoClash import ./laws/OtherNarHashRefused.bend as OtherNarHashRefused import ./laws/OtherTargetRunsGitPlanner.bend as OtherTargetRunsGitPlanner import ./laws/PackageInsertedInHashOrder.bend as PackageInsertedInHashOrder +import ./laws/PackagePrintedWithHash.bend as PackagePrintedWithHash import ./laws/ParseReadsTheSections.bend as ParseReadsTheSections import ./laws/PathBaseIsLastComponent.bend as PathBaseIsLastComponent import ./laws/PathTargetRecordedAsGiven.bend as PathTargetRecordedAsGiven +import ./laws/PlaceShownOnOneLine.bend as PlaceShownOnOneLine import ./laws/PlainComponentKept.bend as PlainComponentKept import ./laws/PlainLockAsksNoUpgrade.bend as PlainLockAsksNoUpgrade import ./laws/PlainLockKeepsLedger.bend as PlainLockKeepsLedger @@ -155,6 +168,8 @@ import ./laws/PlainLockLeavesLedger.bend as PlainLockLeavesLedger import ./laws/PlainLockWritesOnlyLock.bend as PlainLockWritesOnlyLock import ./laws/PlainPathHasNoClimbs.bend as PlainPathHasNoClimbs import ./laws/PopulatedLockPasses.bend as PopulatedLockPasses +import ./laws/ProgressNamesBriefly.bend as ProgressNamesBriefly +import ./laws/ProofPassesOnVerdictLine.bend as ProofPassesOnVerdictLine import ./laws/PublishAgreesWithBend.bend as PublishAgreesWithBend import ./laws/PublishNeedsCleanTree.bend as PublishNeedsCleanTree import ./laws/PublishNeedsDepsOnHub.bend as PublishNeedsDepsOnHub @@ -170,12 +185,14 @@ import ./laws/ReadmeGoesAlong.bend as ReadmeGoesAlong import ./laws/ReadmeOverRefused.bend as ReadmeOverRefused import ./laws/ReadmelessKeepsOtherFiles.bend as ReadmelessKeepsOtherFiles import ./laws/RecordedPackageIsNamed.bend as RecordedPackageIsNamed +import ./laws/RefusalReasonShown.bend as RefusalReasonShown import ./laws/RefusalWritesNothing.bend as RefusalWritesNothing import ./laws/RefusedWalkRefusesAdd.bend as RefusedWalkRefusesAdd import ./laws/RemoveDependencyIdempotent.bend as RemoveDependencyIdempotent import ./laws/RemoveRefusesAbsent.bend as RemoveRefusesAbsent import ./laws/RenderKeepsPackagesWithoutTools.bend as RenderKeepsPackagesWithoutTools import ./laws/RepeatedFileKeptOnce.bend as RepeatedFileKeptOnce +import ./laws/RepliesJoinTheWorld.bend as RepliesJoinTheWorld import ./laws/RepolessSectionIsHub.bend as RepolessSectionIsHub import ./laws/ResolvedMembersJoin.bend as ResolvedMembersJoin import ./laws/ResolvedNotAsked.bend as ResolvedNotAsked @@ -186,8 +203,11 @@ import ./laws/RewriteKeepsOtherLines.bend as RewriteKeepsOtherLines import ./laws/RootAtEntryDepth.bend as RootAtEntryDepth import ./laws/RootOneAboveEntry.bend as RootOneAboveEntry import ./laws/RunDeadlineIsAbsolute.bend as RunDeadlineIsAbsolute +import ./laws/RunOutputFiltered.bend as RunOutputFiltered import ./laws/RunPassesWords.bend as RunPassesWords import ./laws/SectionKeepsItsName.bend as SectionKeepsItsName +import ./laws/ServerArgsAfterName.bend as ServerArgsAfterName +import ./laws/ServeSpeaksHttp.bend as ServeSpeaksHttp import ./laws/ShowBadIsMarked.bend as ShowBadIsMarked import ./laws/ShowGoodOpensWithName.bend as ShowGoodOpensWithName import ./laws/SkippedComponentChangesNothing.bend as SkippedComponentChangesNothing @@ -196,13 +216,18 @@ import ./laws/SlashlessPathIsItsOwnBase.bend as SlashlessPathIsItsOwnBase import ./laws/SlashlessPathSplitsToItself.bend as SlashlessPathSplitsToItself import ./laws/SlashlessTailIsWholePath.bend as SlashlessTailIsWholePath import ./laws/SortIgnoresFileOrder.bend as SortIgnoresFileOrder +import ./laws/SortKeepsEveryString.bend as SortKeepsEveryString import ./laws/SoundDocumentBuilds.bend as SoundDocumentBuilds import ./laws/SourceOmitsAbsentTag.bend as SourceOmitsAbsentTag +import ./laws/StepRunsThePlan.bend as StepRunsThePlan import ./laws/StoppedWalkTakesNoReadme.bend as StoppedWalkTakesNoReadme import ./laws/SyntaxErrorReportedFirst.bend as SyntaxErrorReportedFirst import ./laws/TagOfNamesTheTag.bend as TagOfNamesTheTag import ./laws/TailOfOneIsBase.bend as TailOfOneIsBase import ./laws/TargetClassified.bend as TargetClassified +import ./laws/TestBudgetOnlyWhenSet.bend as TestBudgetOnlyWhenSet +import ./laws/TestOutputPicksLines.bend as TestOutputPicksLines +import ./laws/TestTallyCounts.bend as TestTallyCounts import ./laws/TildeExpandsUnderHome.bend as TildeExpandsUnderHome import ./laws/ToolBinDirChosen.bend as ToolBinDirChosen import ./laws/ToolBuiltFileChosen.bend as ToolBuiltFileChosen diff --git a/PROOF.bend b/PROOF.bend index 1f4d6c7..9eda849 100644 --- a/PROOF.bend +++ b/PROOF.bend @@ -12,14 +12,17 @@ import ./proofs/AddEntryChosen.bend as PAddEntryChosen import ./proofs/AddNotesUnlockedPackage.bend as PAddNotesUnlockedPackage import ./proofs/AddPinsChosenRef.bend as PAddPinsChosenRef import ./proofs/AddRemoveRelock.bend as PAddRemoveRelock +import ./proofs/BenchScanAnswersMode.bend as PBenchScanAnswersMode import ./proofs/BodyLineEndsHeader.bend as PBodyLineEndsHeader import ./proofs/BuildMakesBin.bend as PBuildMakesBin import ./proofs/BuildWithOutMakesNothing.bend as PBuildWithOutMakesNothing +import ./proofs/CappedRunWords.bend as PCappedRunWords import ./proofs/CheckMakesEzDir.bend as PCheckMakesEzDir import ./proofs/ClimbCancelsComponent.bend as PClimbCancelsComponent import ./proofs/ClimbOfZeroNormalizes.bend as PClimbOfZeroNormalizes import ./proofs/ClimbedAbsolutePathStaysAbsolute.bend as PClimbedAbsolutePathStaysAbsolute import ./proofs/ClimbsStack.bend as PClimbsStack +import ./proofs/CommandLineWords.bend as PCommandLineWords import ./proofs/CommandsNeedLedger.bend as PCommandsNeedLedger import ./proofs/DepOpensItsSection.bend as PDepOpensItsSection import ./proofs/DependenciesRenderInOrder.bend as PDependenciesRenderInOrder @@ -39,6 +42,7 @@ import ./proofs/EmptyLedgerClashesWithNone.bend as PEmptyLedgerClashesWithNone import ./proofs/EmptyLedgerTakesSourceName.bend as PEmptyLedgerTakesSourceName import ./proofs/EmptyLockWithDepsFails.bend as PEmptyLockWithDepsFails import ./proofs/EmptyValueWritesNoLine.bend as PEmptyValueWritesNoLine +import ./proofs/EnvFallsBack.bend as PEnvFallsBack import ./proofs/EqualsInPathNamed.bend as PEqualsInPathNamed import ./proofs/EqualsInPathUnlockable.bend as PEqualsInPathUnlockable import ./proofs/EscapingImportRefused.bend as PEscapingImportRefused @@ -53,6 +57,7 @@ import ./proofs/FirstSectionWins.bend as PFirstSectionWins import ./proofs/ForeignBodyGatheredAnywhere.bend as PForeignBodyGatheredAnywhere import ./proofs/ForeignLicenseGoesAlong.bend as PForeignLicenseGoesAlong import ./proofs/FoundFileIsPublished.bend as PFoundFileIsPublished +import ./proofs/FramingAnswersRoutes.bend as PFramingAnswersRoutes import ./proofs/FullToolPinCopied.bend as PFullToolPinCopied import ./proofs/GitNamedWithoutLicense.bend as PGitNamedWithoutLicense import ./proofs/GitNamedWithoutReadme.bend as PGitNamedWithoutReadme @@ -82,11 +87,13 @@ import ./proofs/LedgerNamesFirst.bend as PLedgerNamesFirst import ./proofs/LedgerRemoveIdempotent.bend as PLedgerRemoveIdempotent import ./proofs/LedgerTextOpensWithPackage.bend as PLedgerTextOpensWithPackage import ./proofs/LedgerWithoutDepsNeedsNoLock.bend as PLedgerWithoutDepsNeedsNoLock +import ./proofs/LiarHidesAnswerWhenMute.bend as PLiarHidesAnswerWhenMute import ./proofs/LibJudgedAsClone.bend as PLibJudgedAsClone import ./proofs/LicenseAsked.bend as PLicenseAsked import ./proofs/LicenseDirNamed.bend as PLicenseDirNamed import ./proofs/LicenseDirRefused.bend as PLicenseDirRefused import ./proofs/LicenseGoesAlong.bend as PLicenseGoesAlong +import ./proofs/LineNeverRunsHelp.bend as PLineNeverRunsHelp import ./proofs/LockIdempotent.bend as PLockIdempotent import ./proofs/LockIgnoresWalkOrder.bend as PLockIgnoresWalkOrder import ./proofs/LockLaysItsNames.bend as PLockLaysItsNames @@ -102,7 +109,10 @@ import ./proofs/MissingNarHashRefused.bend as PMissingNarHashRefused import ./proofs/MissingRootIsCheckoutTop.bend as PMissingRootIsCheckoutTop import ./proofs/NameFilesLaid.bend as PNameFilesLaid import ./proofs/NamedImportIsHubDependency.bend as PNamedImportIsHubDependency +import ./proofs/NarBuildsTree.bend as PNarBuildsTree +import ./proofs/NarHashForm.bend as PNarHashForm import ./proofs/NarIgnoresEntryOrder.bend as PNarIgnoresEntryOrder +import ./proofs/NarListingRows.bend as PNarListingRows import ./proofs/NarReadsNamesVerbatim.bend as PNarReadsNamesVerbatim import ./proofs/NarlessToolPinRefused.bend as PNarlessToolPinRefused import ./proofs/NoLicenseAsBefore.bend as PNoLicenseAsBefore @@ -115,15 +125,18 @@ import ./proofs/NormKeepsRootFlag.bend as PNormKeepsRootFlag import ./proofs/OldNameKeepsOtherFiles.bend as POldNameKeepsOtherFiles import ./proofs/OldNameLeavesLicenseOut.bend as POldNameLeavesLicenseOut import ./proofs/OldNameLeavesReadmeOut.bend as POldNameLeavesReadmeOut +import ./proofs/OracleReadsPublishBody.bend as POracleReadsPublishBody import ./proofs/OtherCommandsMakeNoDir.bend as POtherCommandsMakeNoDir import ./proofs/OtherGitSourceLendsNoName.bend as POtherGitSourceLendsNoName import ./proofs/OtherNameIsNoClash.bend as POtherNameIsNoClash import ./proofs/OtherNarHashRefused.bend as POtherNarHashRefused import ./proofs/OtherTargetRunsGitPlanner.bend as POtherTargetRunsGitPlanner import ./proofs/PackageInsertedInHashOrder.bend as PPackageInsertedInHashOrder +import ./proofs/PackagePrintedWithHash.bend as PPackagePrintedWithHash import ./proofs/ParseReadsTheSections.bend as PParseReadsTheSections import ./proofs/PathBaseIsLastComponent.bend as PPathBaseIsLastComponent import ./proofs/PathTargetRecordedAsGiven.bend as PPathTargetRecordedAsGiven +import ./proofs/PlaceShownOnOneLine.bend as PPlaceShownOnOneLine import ./proofs/PlainComponentKept.bend as PPlainComponentKept import ./proofs/PlainLockAsksNoUpgrade.bend as PPlainLockAsksNoUpgrade import ./proofs/PlainLockKeepsLedger.bend as PPlainLockKeepsLedger @@ -131,6 +144,8 @@ import ./proofs/PlainLockLeavesLedger.bend as PPlainLockLeavesLedger import ./proofs/PlainLockWritesOnlyLock.bend as PPlainLockWritesOnlyLock import ./proofs/PlainPathHasNoClimbs.bend as PPlainPathHasNoClimbs import ./proofs/PopulatedLockPasses.bend as PPopulatedLockPasses +import ./proofs/ProgressNamesBriefly.bend as PProgressNamesBriefly +import ./proofs/ProofPassesOnVerdictLine.bend as PProofPassesOnVerdictLine import ./proofs/PublishAgreesWithBend.bend as PPublishAgreesWithBend import ./proofs/PublishNeedsCleanTree.bend as PPublishNeedsCleanTree import ./proofs/PublishNeedsDepsOnHub.bend as PPublishNeedsDepsOnHub @@ -146,12 +161,14 @@ import ./proofs/ReadmeGoesAlong.bend as PReadmeGoesAlong import ./proofs/ReadmeOverRefused.bend as PReadmeOverRefused import ./proofs/ReadmelessKeepsOtherFiles.bend as PReadmelessKeepsOtherFiles import ./proofs/RecordedPackageIsNamed.bend as PRecordedPackageIsNamed +import ./proofs/RefusalReasonShown.bend as PRefusalReasonShown import ./proofs/RefusalWritesNothing.bend as PRefusalWritesNothing import ./proofs/RefusedWalkRefusesAdd.bend as PRefusedWalkRefusesAdd import ./proofs/RemoveDependencyIdempotent.bend as PRemoveDependencyIdempotent import ./proofs/RemoveRefusesAbsent.bend as PRemoveRefusesAbsent import ./proofs/RenderKeepsPackagesWithoutTools.bend as PRenderKeepsPackagesWithoutTools import ./proofs/RepeatedFileKeptOnce.bend as PRepeatedFileKeptOnce +import ./proofs/RepliesJoinTheWorld.bend as PRepliesJoinTheWorld import ./proofs/RepolessSectionIsHub.bend as PRepolessSectionIsHub import ./proofs/ResolvedMembersJoin.bend as PResolvedMembersJoin import ./proofs/ResolvedNotAsked.bend as PResolvedNotAsked @@ -162,8 +179,11 @@ import ./proofs/RewriteKeepsOtherLines.bend as PRewriteKeepsOtherLines import ./proofs/RootAtEntryDepth.bend as PRootAtEntryDepth import ./proofs/RootOneAboveEntry.bend as PRootOneAboveEntry import ./proofs/RunDeadlineIsAbsolute.bend as PRunDeadlineIsAbsolute +import ./proofs/RunOutputFiltered.bend as PRunOutputFiltered import ./proofs/RunPassesWords.bend as PRunPassesWords import ./proofs/SectionKeepsItsName.bend as PSectionKeepsItsName +import ./proofs/ServerArgsAfterName.bend as PServerArgsAfterName +import ./proofs/ServeSpeaksHttp.bend as PServeSpeaksHttp import ./proofs/ShowBadIsMarked.bend as PShowBadIsMarked import ./proofs/ShowGoodOpensWithName.bend as PShowGoodOpensWithName import ./proofs/SkippedComponentChangesNothing.bend as PSkippedComponentChangesNothing @@ -172,13 +192,18 @@ import ./proofs/SlashlessPathIsItsOwnBase.bend as PSlashlessPathIsItsOwnBase import ./proofs/SlashlessPathSplitsToItself.bend as PSlashlessPathSplitsToItself import ./proofs/SlashlessTailIsWholePath.bend as PSlashlessTailIsWholePath import ./proofs/SortIgnoresFileOrder.bend as PSortIgnoresFileOrder +import ./proofs/SortKeepsEveryString.bend as PSortKeepsEveryString import ./proofs/SoundDocumentBuilds.bend as PSoundDocumentBuilds import ./proofs/SourceOmitsAbsentTag.bend as PSourceOmitsAbsentTag +import ./proofs/StepRunsThePlan.bend as PStepRunsThePlan import ./proofs/StoppedWalkTakesNoReadme.bend as PStoppedWalkTakesNoReadme import ./proofs/SyntaxErrorReportedFirst.bend as PSyntaxErrorReportedFirst import ./proofs/TagOfNamesTheTag.bend as PTagOfNamesTheTag import ./proofs/TailOfOneIsBase.bend as PTailOfOneIsBase import ./proofs/TargetClassified.bend as PTargetClassified +import ./proofs/TestBudgetOnlyWhenSet.bend as PTestBudgetOnlyWhenSet +import ./proofs/TestOutputPicksLines.bend as PTestOutputPicksLines +import ./proofs/TestTallyCounts.bend as PTestTallyCounts import ./proofs/TildeExpandsUnderHome.bend as PTildeExpandsUnderHome import ./proofs/ToolBinDirChosen.bend as PToolBinDirChosen import ./proofs/ToolBuiltFileChosen.bend as PToolBuiltFileChosen diff --git a/bolt.bend b/bolt.bend index 946edac..64e7e24 100644 --- a/bolt.bend +++ b/bolt.bend @@ -17,16 +17,15 @@ def suspicious() -> String: def style() -> String: "error" -# the law rules: `coverage` (a def no law names) and `closed`. The group is -# advice because of `coverage`, which the RFC's later phases grow; it goes -# back to an error as the laws land. A rule set by name wins over its group. +# the law rules: `coverage` (a def no law reaches) and `closed`, both errors. def laws() -> String: - "warn" + "error" -# a def no law names. Since bolt 1.26 the rule is off unless bolt.bend names -# it, so it is named here to keep ez's coverage gate on, at the group's level. +# a def no law reaches. Since bolt 1.26 the rule is off unless bolt.bend +# names it, so it is named here to keep ez's coverage gate on. A def no law +# can reach, an IO driver, says why on its def line (`# noqa: L001 `). def coverage() -> String: - "warn" + "error" # a law in a law file with no `for`/`exs` binder, equality or not. A closed # law claims one computed case and no guarantee, and nothing exempts one. diff --git a/laws/BenchScanAnswersMode.bend b/laws/BenchScanAnswersMode.bend new file mode 100644 index 0000000..954d172 --- /dev/null +++ b/laws/BenchScanAnswersMode.bend @@ -0,0 +1,52 @@ +# What the scan benchmark (src/pkg/bench/scan.bend) answers: the mode named +# on its command line picks the classifier, `old` the one before the rewrite +# and anything else the one pkg/pkg.bend has now, each counted over the same +# lines; the program's own name is not an argument, every argument after it +# is kept, and an argument past the end reads as nothing. This is internal: +# the benchmark is a developer's tool the gate does not run. +import Base +import ../src/pkg/bench/scan.bend as B + +# LAW: `old` counts with the classifier before the rewrite +law run_old: + for mode: String + for size: Nat + for e: {True{} == String.eq(mode, "old") : Bool} + {B.run(mode, size) == "old " ++ Nat.show(B.count.old(B.lines(size))) : String} + +# LAW: and any other mode with the classifier as it is now +law run_new: + for mode: String + for size: Nat + for e: {False{} == String.eq(mode, "old") : Bool} + {B.run(mode, size) == "new " ++ Nat.show(B.count.new(B.lines(size))) : String} + +# LAW: the program's own name is dropped and the rest kept +law args_drop_name: + for h: String + for t: List<&1, String> + {B.args(Con{h, t}) == B.copy(t) : List<&2, String>} + +# LAW: and copying keeps every argument +law copy_keeps_length: + for xs: List<&1, String> + {List.length(&2, String, B.copy(xs)) == List.length(&1, String, xs) : Nat} + +# LAW: the first argument is the head +law at_first: + for h: String + for t: List<&2, String> + {B.at(h <> t, 0n) == h : String} + +# LAW: a later one is found in the rest +law at_later: + for h: String + for t: List<&2, String> + for p: Nat + {B.at(h <> t, 1n+p) == B.at(t, p) : String} + +# LAW: and one past the end is nothing +law at_past_end: + for index: Nat + {B.at([], index) == "" : String} + diff --git a/laws/CappedRunWords.bend b/laws/CappedRunWords.bend new file mode 100644 index 0000000..0c42bef --- /dev/null +++ b/laws/CappedRunWords.bend @@ -0,0 +1,50 @@ +# The words of a `bend` ez runs under the memory cap, and what is said of +# one the cap killed. This is internal: it holds src/share/capped.bend in +# place, under `ez build`, `ez prove` and `ez tool`. +# +# An uncapped run is `env BEND_LIB=` followed by the program's words, +# unchanged. A capped run is the cap's scope (systemd-run with the memory +# limit) followed by exactly those same words, so the variable is set inside +# the cgroup and the program's own words are never touched. A run that ended +# with status 137 was killed for memory, and is said to have been, naming the +# cap; any run that was not killed has nothing said of it here. That 137 is +# what the kernel leaves on a process it killed for memory is trusted in +# src/share/cap.bend. +import Base +import ../src/share/capped.bend as Capped + +# LAW: an uncapped run is BEND_LIB set in front of the program's words +law uncapped_words: + for gigs: String + for at: String + for args: List<&2, String> + {Capped.argv(False{}, gigs, at, args) == "env" <> (String.append("BEND_LIB=", at) <> args) + : List<&2, String>} + +# LAW: a capped run is the cap's scope in front of those same words +law capped_words: + for gigs: String + for at: String + for args: List<&2, String> + {Capped.argv(True{}, gigs, at, args) + == List.append(&2, String, Capped.scope(gigs), "env" <> (String.append("BEND_LIB=", at) <> args)) + : List<&2, String>} + +# LAW: a run that ended with status 137 was killed for memory +law status_137_killed: + for text: String + {Capped.killed(String.append("137\n", text)) == True{} : Bool} + +# LAW: and is said to have been, naming the cap it ran under +law killed_names_cap: + for text: String + for gigs: String + {Capped.why(String.append("137\n", text), gigs) + == String.append("killed for memory at ", String.append(gigs, "G: raise EZ_CAP\n")) : String} + +# LAW: a run that was not killed has nothing said of it +law unkilled_says_nothing: + for out: String + for gigs: String + for alive: {Capped.killed(out) == False{} : Bool} + {Capped.why(out, gigs) == "" : String} diff --git a/laws/CommandLineWords.bend b/laws/CommandLineWords.bend new file mode 100644 index 0000000..8f1101c --- /dev/null +++ b/laws/CommandLineWords.bend @@ -0,0 +1,51 @@ +# How ez reads the words it was started with. This is internal: it holds +# src/share/args.bend in place, under the commands that read their words. +# +# The words are every word after the program's own name, in order and +# unchanged. The nth word is the word at that place, counted from zero, and a +# place past the last word reads as no word, the empty string. A line split +# into its first word and the rest gives exactly those two. An environment +# variable that is set reads as its value, and one that is not reads as the +# empty string. What `IO.args` hands ez is trusted in src/share/args.bend. +import Base +import ../src/share/args.bend as Args + +# LAW: the words ez reads are the ones after the program's name, in order +law words_after_program: + for prog: String + for ws: List<&1, String> + {Args.rest(Args.copy(Con{prog, ws})) == Args.copy(ws) : List<&2, String>} + +# LAW: the first word is at place zero +law word_at_zero: + for h: String + for t: List<&2, String> + {Args.at(h <> t, 0n) == h : String} + +# LAW: and every later place is a place of the words after it +law word_at_later: + for h: String + for t: List<&2, String> + for n: Nat + {Args.at(h <> t, 1n+n) == Args.at(t, n) : String} + +# LAW: a place past the last word reads as no word +law word_past_end: + for n: Nat + {Args.at([], n) == "" : String} + +# LAW: a line split is its first word and the words after it +law split_first: + for h: String + for t: List<&2, String> + {Args.split(h <> t) == (h, t) : String & List<&2, String>} + +# LAW: a variable that is set reads as its value +law env_set_reads: + for value: String + {Args.text_of(Done{value}) == value : String} + +# LAW: a variable that is not set reads as the empty string +law env_unset_empty: + for e: U32 & String + {Args.text_of(Fail{e}) == "" : String} diff --git a/laws/EnvFallsBack.bend b/laws/EnvFallsBack.bend new file mode 100644 index 0000000..57126e9 --- /dev/null +++ b/laws/EnvFallsBack.bend @@ -0,0 +1,17 @@ +# A variable ez reads with a default reads as its value when it holds one, +# and as the default when it is unset or empty. This is internal: it holds +# src/share/env.bend's fallback in place, under BEND_LIB and EZ_CAP. +import Base +import ../src/share/env.bend as Env + +# LAW: a value that is there is read as it is +law value_kept: + for +value: String + for alt: String + for full: {String.is_empty(value) == False{} : Bool} + {Env.or_else(value, alt) == value : String} + +# LAW: an empty value reads as the default +law empty_falls_back: + for alt: String + {Env.or_else("", alt) == alt : String} diff --git a/laws/FramingAnswersRoutes.bend b/laws/FramingAnswersRoutes.bend new file mode 100644 index 0000000..4a6eaef --- /dev/null +++ b/laws/FramingAnswersRoutes.bend @@ -0,0 +1,59 @@ +# What the framing test server (src/check/framing.bend) answers, which is what +# tests/fetch.bend drives ezhttp's client against. This is internal: the +# server is a test fixture, not part of ez, and these laws hold its routes in +# place so a failing fetch test is about the client. +# +# Exactly four answers, by the request's path: `/plain` is the plain body +# framed by its length, `/chunked` is the chunked body framed in chunks, `/` +# is `ok` so a test can wait on the server, and any other path is a 404 with +# no body. A chunk states its length in lower-case hex, one digit below 16. +# also rests on: laws/ServeSpeaksHttp.bend +import Base +import ../src/check/serve.bend as S +import ../src/check/framing.bend as F + +# LAW: `/plain` is the plain body, framed by its length +law reply_plain: + for +path: String + for is_plain: {True{} == String.eq(path, "/plain") : Bool} + {F.reply(path) == S.response("200 OK", F.plain()) : String} + +# LAW: `/chunked` is the chunked body +law reply_chunked: + for +path: String + for not_plain: {False{} == String.eq(path, "/plain") : Bool} + for is_chunked: {True{} == String.eq(path, "/chunked") : Bool} + {F.reply(path) == F.chunked() : String} + +# LAW: `/` is `ok` +law reply_root: + for +path: String + for not_plain: {False{} == String.eq(path, "/plain") : Bool} + for not_chunked: {False{} == String.eq(path, "/chunked") : Bool} + for is_root: {True{} == String.eq(path, "/") : Bool} + {F.reply(path) == S.response("200 OK", "ok") : String} + +# LAW: and every other path is a 404 with no body +law reply_unknown: + for +path: String + for not_plain: {False{} == String.eq(path, "/plain") : Bool} + for not_chunked: {False{} == String.eq(path, "/chunked") : Bool} + for not_root: {False{} == String.eq(path, "/") : Bool} + {F.reply(path) == S.response("404 Not Found", "") : String} + +# LAW: a chunk is its length in hex, its bytes, each ended by a CRLF +law chunk_frames: + for +text: String + {F.chunk(text) == F.hex.show(S.size(text)) ++ "\r\n" ++ text ++ "\r\n" : String} + +# LAW: a length below 16 is one hex digit +law hex_one_digit: + for +len: U32 + for small: {True{} == U32.is_lt(len, 16) : Bool} + {F.hex.show(len) == F.hex.digit(len) : String} + +# LAW: a longer one is its sixteens and then its ones +law hex_two_digits: + for +len: U32 + for big: {False{} == U32.is_lt(len, 16) : Bool} + {F.hex.show(len) == F.hex.digit(U32.div(len, 16)) ++ F.hex.digit(U32.mod(len, 16)) : String} diff --git a/laws/LiarHidesAnswerWhenMute.bend b/laws/LiarHidesAnswerWhenMute.bend new file mode 100644 index 0000000..c6f80df --- /dev/null +++ b/laws/LiarHidesAnswerWhenMute.bend @@ -0,0 +1,51 @@ +# What the lying `bend` (src/check/liar.bend) prints, which tests/publish.bend +# puts in front of the real one to drive `ez publish`'s disagreement path. +# This is internal: the liar is a test fixture, not part of ez. +# +# It prints the two lines the real bend prints around its answer, each +# holding a `0x` name mid-line, and, exactly when it is not mute, the answer +# itself: a line that is a `0x` name on its own. So a pattern anchored at the +# start of a line finds a name exactly when the liar is not mute, and the name +# it finds is never one a package walk arrives at. An unset EZ_LIAR reads as +# "", so the liar is mute only when it is asked to be. +import Base +import ../src/check/liar.bend as Liar + +# whether a line is a `0x` name on its own, which is what an anchored pattern +# finds +def bare(+line: String) -> Bool: + String.starts_with(line, "0x") + +# whether any of the lines is one +def has_bare(ls: List<&2, String>) -> Bool: + match ls: + case []: + False{} + case h <> t: + Bool.or(bare(h), has_bare(t)) + +# LAW: the liar prints a bare name exactly when it is not mute +law bare_unless_mute: + for mute: Bool + {has_bare(Liar.lines(mute)) == Bool.not(mute) : Bool} + +# LAW: the line it prints while it mines holds the name mid-line, never at +# the start +law mining_not_bare: + for +hash: String + {bare(Liar.mining(hash)) == False{} : Bool} + +# LAW: and so does the import line it prints last +law importing_not_bare: + for +hash: String + {bare(Liar.importing(hash)) == False{} : Bool} + +# LAW: an EZ_LIAR that could not be read is "" +law unset_is_empty: + for err: U32 & String + {Liar.text_of(Fail{err}) == "" : String} + +# LAW: and one that could is its text +law set_is_text: + for text: String + {Liar.text_of(Done{text}) == text : String} diff --git a/laws/LineNeverRunsHelp.bend b/laws/LineNeverRunsHelp.bend new file mode 100644 index 0000000..54fb5cd --- /dev/null +++ b/laws/LineNeverRunsHelp.bend @@ -0,0 +1,40 @@ +# Every line `ez` is given ends one of three ways (ez/line.bend): a command +# runs, help is shown, or the line is misused. The one subcommand that names +# no command, the help a bare `ez` shows, is never the command a line runs: +# a line that names no command shows help or is refused. And a command reads +# what the line bound for a name, or nothing when it bound none. This is +# internal: it fixes ez/line.bend's reading of shake's parse, whose own +# correctness is shake's (cited in ez/line.bend's header). +import Base +import shake@0.6.0.0/main.bend as Shake +import ../src/ez/line.bend as L + +# whether a line's end runs the help subcommand +def runs.help(how: L.Line) -> Bool: + match how: + case L.Runs{sub, _m}: + L.is.help(sub) + case L.Shows{_t}: + False{} + case L.Misuse{_t}: + False{} + +# LAW: no line ez is given runs the help subcommand +law never_runs_help: + for argv: List<&2, String> + {runs.help(L.line(L.spec(), Shake.parse(L.spec(), argv))) == False{} : Bool} + +# LAW: a name the line bound reads as what it bound +law get_bound: + for found: Shake.Matched + for +name: String + for v: String + for e: {Some{v} == Shake.get(found, name) : Maybe<&2, String>} + {L.get(found, name) == v : String} + +# LAW: and a name it did not bind reads as nothing +law get_unbound: + for found: Shake.Matched + for +name: String + for e: {None{} == Shake.get(found, name) : Maybe<&2, String>} + {L.get(found, name) == "" : String} diff --git a/laws/NarBuildsTree.bend b/laws/NarBuildsTree.bend new file mode 100644 index 0000000..6e89f95 --- /dev/null +++ b/laws/NarBuildsTree.bend @@ -0,0 +1,74 @@ +# The NAR walk builds the node nix's dumper would write for a tree, from the +# paths of its listing in the order `find` prints them, top first. This is +# internal: it holds src/sha/nar.bend's build in place, not an interface. +# +# A listing whose top is a file is that file's regular node, executable when +# its owner may execute it; one whose top is a symlink is a symlink node of +# its target; a directory with nothing in it is the empty directory's node; +# and a file listed inside the top directory is that directory's one entry, +# under its name, holding the file's node. When a directory closes, its node +# becomes an entry of the directory around it, under its name, and the walk +# goes on in that directory with the paths still to place. What this proves +# is the build over listings of those shapes and the close of a nested +# directory; that a deeper listing builds the tree nix's dumper would write +# rests on the same steps and is trusted in src/sha/nar.bend. +# also rests on: laws/NarIgnoresEntryOrder.bend +import Base +import ../src/pkg/pkg.bend as K +import ../src/sha/nar.bend as Nar + +# LAW: a listing that is one regular file is that file's node +law nar_lone_file: + for ex: Bool + for name: String + for at: String + for body: String + {Nar.tree([Nar.Ent{"f", ex, name, at, body}]) == Some{Nar.regular(ex, body)} + : Maybe<&2, String>} + +# LAW: a listing that is one symlink is a symlink node of its target +law nar_lone_symlink: + for ex: Bool + for name: String + for at: String + for target: String + {Nar.tree([Nar.Ent{"l", ex, name, at, target}]) == Some{Nar.symlink(target)} + : Maybe<&2, String>} + +# LAW: a directory with nothing under it is the empty directory's node +law nar_lone_directory: + for ex: Bool + for name: String + for at: String + for body: String + {Nar.tree([Nar.Ent{"d", ex, name, at, body}]) == Some{Nar.empty()} + : Maybe<&2, String>} + +# LAW: a file listed inside the top directory is that directory's one entry, +# under its name, holding the file's node +law nar_file_in_directory: + for dex: Bool + for dname: String + for dat: String + for dbody: String + for ex: Bool + for +name: String + for body: String + {Nar.tree([Nar.Ent{"d", dex, dname, dat, dbody}, Nar.Ent{"f", ex, name, name, body}]) + == Some{Nar.dir([K.Item{name, Nar.regular(ex, body)}])} : Maybe<&2, String>} + +# LAW: a directory that closes inside another becomes an entry of it, under +# its name, holding its node, and the walk goes on there with the paths still +# to place +law nar_close_nested: + for at: String + for name: String + for kids: List<&2, K.Item> + for pat: String + for pname: String + for pkids: List<&2, K.Item> + for up: List<&2, Nar.Frame> + for es: List<&2, Nar.Ent> + {Nar.close(Nar.Frame{at, name, kids}, Nar.Frame{pat, pname, pkids} <> up, es) + == Nar.Next{Nar.State{es, Nar.Frame{pat, pname, K.Item{name, Nar.dir(kids)} <> pkids}, up}} + : Nar.Move} diff --git a/laws/NarHashForm.bend b/laws/NarHashForm.bend new file mode 100644 index 0000000..9ce7db6 --- /dev/null +++ b/laws/NarHashForm.bend @@ -0,0 +1,49 @@ +# The form ez writes a NAR hash in, which is the form fetchgit records as +# narHash. This is internal: it holds src/sha/nar.bend's encoding in place. +# +# A tree's NAR is the magic string `nix-archive-1`, as a NAR string, followed +# by the tree's root node. A NAR hash is `sha256-` followed by the standard +# base64 of the digest. Base64 turns every three bytes into four characters, +# group by group from the front, and pads a last group of one or two bytes +# with `=` to four characters, so a digest's base64 is never cut short. That +# the digest is SHA-256 is share/sha's, proved there. +import Base +import ../src/sha/nar.bend as Nar + +# LAW: a NAR is the magic string followed by the root node +law nar_archive_magic: + for node: String + {Nar.archive(node) == String.append(Nar.str("nix-archive-1"), node) : String} + +# LAW: every NAR hash ez writes starts `sha256-` +law sri_names_sha256: + for bytes: String + {String.starts_with(Nar.sri(bytes), "sha256-") == True{} : Bool} + +# LAW: base64 encodes three bytes at a time from the front, each group on its +# own +law b64_by_groups_of_three: + for a: Char + for b: Char + for c: Char + for rest: String + {Nar.b64(SCon{a, SCon{b, SCon{c, rest}}}) + == String.append(Nar.b64(SCon{a, SCon{b, SCon{c, SNil{}}}}), Nar.b64(rest)) : String} + +# LAW: a last group of one byte is padded to four characters +law b64_pads_one: + for a: Char + {String.length(Nar.b64(SCon{a, SNil{}})) == 4n : Nat} + +# LAW: and a last group of two bytes is too +law b64_pads_two: + for a: Char + for b: Char + {String.length(Nar.b64(SCon{a, SCon{b, SNil{}}})) == 4n : Nat} + +# LAW: a whole group of three bytes is four characters +law b64_three_is_four: + for a: Char + for b: Char + for c: Char + {String.length(Nar.b64(SCon{a, SCon{b, SCon{c, SNil{}}}})) == 4n : Nat} diff --git a/laws/NarListingRows.bend b/laws/NarListingRows.bend new file mode 100644 index 0000000..dabe7e3 --- /dev/null +++ b/laws/NarListingRows.bend @@ -0,0 +1,27 @@ +# The NAR walk reads its listing five fields to a path: the type, the mode, +# the name, the path from the top and a symlink's target, in that order, and +# a path the listing cut short is not read at all. This is internal: it holds +# src/sha/nar.bend's reading of `find`'s output in place. +# also rests on: laws/NarReadsNamesVerbatim.bend +import Base +import ../src/sha/nar.bend as Nar + +# LAW: five fields make one path, in the order `find` prints them, and the +# rest of the listing is read the same way +law rows_by_five: + for kind: String + for mode: String + for name: String + for at: String + for target: String + for rest: List<&2, String> + {Nar.rows(kind <> (mode <> (name <> (at <> (target <> rest))))) + == Nar.Row{kind, mode, name, at, target} <> Nar.rows(rest) : List<&2, Nar.Row>} + +# LAW: a path the listing cut short, four fields with no fifth, is not read +law rows_cut_short: + for kind: String + for mode: String + for name: String + for at: String + {Nar.rows([kind, mode, name, at]) == [] : List<&2, Nar.Row>} diff --git a/laws/NonTrailerLineSkipped.bend b/laws/NonTrailerLineSkipped.bend index bb102ab..7db8a75 100644 --- a/laws/NonTrailerLineSkipped.bend +++ b/laws/NonTrailerLineSkipped.bend @@ -9,3 +9,13 @@ law want_skips: for +t: List<&2, String> for e: {False{} == String.starts_with(h, "#|") : Bool} {G.want(h <> t) == G.want(t) : List<&2, String>} + +# LAW: so a file whose first line is not a trailer line states the trailer +# its other lines state +law trailer_skips: + for text: String + for +h: String + for t: List<&2, String> + for e: {h <> t == String.lines(text) : List<&2, String>} + for ne: {False{} == String.starts_with(h, "#|") : Bool} + {G.trailer(text) == String.join(G.want(t), "\n") : String} diff --git a/laws/OracleReadsPublishBody.bend b/laws/OracleReadsPublishBody.bend new file mode 100644 index 0000000..de1f0d0 --- /dev/null +++ b/laws/OracleReadsPublishBody.bend @@ -0,0 +1,71 @@ +# How the test hub (src/check/body.bend, for check/oracle.bend) reads the body +# of a publish. This is internal: the oracle stands in for the hub in +# tests/publish.bend and is not part of ez; these laws hold its reading in +# place so a failing publish test is about ez. +# +# Whitespace before a token is skipped and nothing else is. A character that +# must head the text is consumed when it does and refused when it does not. A +# string's span is decoded one character at a time: a character that is not a +# backslash stands for itself, and an empty span decodes to "". A body that +# does not open with `{`, after whitespace, is refused as not an object, and +# nothing of it is read. One file is already in manifest order. +# +# Partly proved: the escapes a backslash introduces, and the reading of the +# `files` object past its brace, are held by the oracle's own refusals (an +# escape or a shape it does not know is refused, never passed through) and by +# tests/publish.bend, not by a law yet. +import Base +import ../src/check/body.bend as B + +# LAW: a leading space is skipped +law ws_skips: + for +ch: Char + for tail: String + for space: {True{} == Char.is_space(ch) : Bool} + {B.ws(SCon{ch, tail}) == B.ws(tail) : String} + +# LAW: and the first character that is not one stops the skip, kept +law ws_stops: + for +ch: Char + for +tail: String + for solid: {False{} == Char.is_space(ch) : Bool} + {B.ws(SCon{ch, tail}) == SCon{ch, tail} : String} + +# LAW: a character that heads the text is consumed +law eat_hit: + for +text: String + for +ch: Char + for heads: {True{} == String.starts_with(text, Char.show(ch)) : Bool} + {B.eat(text, ch) == Some{String.drop(text, 1n)} : Maybe<&2, String>} + +# LAW: one that does not is refused +law eat_miss: + for +text: String + for +ch: Char + for absent: {False{} == String.starts_with(text, Char.show(ch)) : Bool} + {B.eat(text, ch) == None{} : Maybe<&2, String>} + +# LAW: an empty span decodes to "", whatever the fuel +law unesc_empty: + for fuel: Nat + {B.unesc(fuel, "") == B.UOk{""} : B.Uns} + +# LAW: a character that is not a backslash stands for itself, in front of the +# rest of the span decoded +law unesc_plain: + for fuel: Nat + for +ch: Char + for +tail: String + for plain: {False{} == Char.is_eq(ch, '\\') : Bool} + {B.unesc(1n+fuel, SCon{ch, tail}) == B.uns.push(ch, B.unesc(fuel, tail)) : B.Uns} + +# LAW: a body that does not open with a brace is refused as not an object +law parse_not_object: + for +body: String + for open: {None{} == B.eat(B.ws(body), '{') : Maybe<&2, String>} + {B.parse(body) == B.OBad{"a body that is not an object"} : B.Obj} + +# LAW: one file is in manifest order as it is +law sorted_one: + for entry: B.Ent + {B.sorted([entry]) == [entry] : List<&2, B.Ent>} diff --git a/laws/PackagePrintedWithHash.bend b/laws/PackagePrintedWithHash.bend new file mode 100644 index 0000000..5ae9195 --- /dev/null +++ b/laws/PackagePrintedWithHash.bend @@ -0,0 +1,36 @@ +# What `src/pkg/print.bend` prints for a package: its hash on the first +# line, the directory its paths are written from on the second, then its +# manifest, so what `bend --publish` would upload can be read without +# uploading it. An unset EZ_ENTRY reads as no entry. A walk that stopped to +# ask for a file is taken up again with everything it had found and still +# had queued, going on. This is internal: the printer is a developer's tool, +# and the walk's resumption is the disk walk's (src/pkg/pkg.bend). +import Base +import ../src/pkg/pkg.bend as K +import ../src/pkg/print.bend as Print + +# LAW: a package prints as its hash, its root and its manifest, a line each +law show_package: + for h: String + for root: String + for fs: List<&2, K.Item> + {Print.show(K.Pkg{h, root, fs}) == h ++ "\n" ++ root ++ "\n" ++ K.manifest_of(fs) : String} + +# LAW: an environment variable that was set reads as its text +law text_of_set: + for s: String + {Print.text_of(Done{s}) == s : String} + +# LAW: and one that was not reads as nothing +law text_of_unset: + for e: U32 & String + {Print.text_of(Fail{e}) == "" : String} + +# LAW: a walk taken up again keeps what it saw, found and had queued, and +# goes on, whatever had stopped it +law resume_goes_on: + for seen: List<&2, String> + for out: List<&2, K.Hit> + for stop: K.Stop + for queue: List<&2, K.Task> + {K.resume(K.State{seen, out, stop, queue}) == K.State{seen, out, K.Going{}, queue} : K.State} diff --git a/laws/PlaceShownOnOneLine.bend b/laws/PlaceShownOnOneLine.bend new file mode 100644 index 0000000..6707114 --- /dev/null +++ b/laws/PlaceShownOnOneLine.bend @@ -0,0 +1,22 @@ +# A place `ez add` resolved a target to, shown on one line: its kind first, +# `bad`, `local` or `remote`, then what it holds, a remote's url and slug in +# that order, each after one space. This is internal: it fixes the form a +# place is read back in by whoever compares one. +import Base +import ../src/ez/target.bend as T + +# LAW: a bad target shows its reason +law show_bad: + for why: String + {T.show(T.Bad{why}) == "bad " ++ why : String} + +# LAW: a local target shows its path +law show_local: + for path: String + {T.show(T.Local{path}) == "local " ++ path : String} + +# LAW: a remote target shows its url, then its slug +law show_remote: + for url: String + for slug: String + {T.show(T.Remote{url, slug}) == "remote " ++ url ++ " " ++ slug : String} diff --git a/laws/ProgressNamesBriefly.bend b/laws/ProgressNamesBriefly.bend new file mode 100644 index 0000000..f630081 --- /dev/null +++ b/laws/ProgressNamesBriefly.bend @@ -0,0 +1,36 @@ +# How a progress line names a commit and a package. This is internal: it +# holds src/share/say.bend's naming in place; the rest of a line's words are +# wording, which nothing should rely on. +# +# A commit is named by its first twelve characters, and one of twelve or +# fewer is named whole. A package is named by its entry's file name without +# the directory or the `.bend`, and by its hash when that leaves nothing. +import Base +import ../src/pkg/path.bend as P +import ../src/share/say.bend as Say + +# LAW: a commit of twelve characters or fewer is named whole +law short_rev_whole: + for +rev: String + for short: {Nat.is_le(String.length(rev), 12n) == True{} : Bool} + {Say.brief(rev) == rev : String} + +# LAW: a longer one is named by its first twelve +law long_rev_cut: + for +rev: String + for long: {Nat.is_le(String.length(rev), 12n) == False{} : Bool} + {Say.brief(rev) == String.take(rev, 12n) : String} + +# LAW: a package whose entry has a name is called by it +law label_names_entry: + for hash: String + for +entry: String + for named: {String.is_empty(P.unbend(P.base(entry))) == False{} : Bool} + {Say.label(hash, entry) == P.unbend(P.base(entry)) : String} + +# LAW: and one whose entry leaves no name is called by its hash +law label_falls_to_hash: + for hash: String + for +entry: String + for blank: {String.is_empty(P.unbend(P.base(entry))) == True{} : Bool} + {Say.label(hash, entry) == hash : String} diff --git a/laws/ProofPassesOnVerdictLine.bend b/laws/ProofPassesOnVerdictLine.bend new file mode 100644 index 0000000..009b7ed --- /dev/null +++ b/laws/ProofPassesOnVerdictLine.bend @@ -0,0 +1,53 @@ +# `ez prove` passes a proof exactly when the first line its run printed is +# `ALL PROOFS CHECK`, and counts one more pass for each proof that passed and +# none for one that did not. A run that printed anything else first fails, +# whatever it printed after. What a failed run printed is shown indented, one +# line of it per line. This is internal: it fixes how ez/verdict.bend reads +# a run, which ez/prove.bend trusts; that the runner hands it what bend +# printed is trusted in ez/prove.bend. Each file the runners found gets one +# `bend` run, in the order they found them. +import Base +import ../src/ez/verdict.bend as V + +# LAW: a run whose first line is the verdict passes +law passes_on_verdict: + for text: String + for t: List<&2, String> + for e: {"ALL PROOFS CHECK" <> t == String.lines(text) : List<&2, String>} + {V.passed(text) == True{} : Bool} + +# LAW: and a run whose first line is anything else fails +law fails_otherwise: + for text: String + for +h: String + for t: List<&2, String> + for e: {h <> t == String.lines(text) : List<&2, String>} + for ne: {False{} == String.eq(h, V.verdict()) : Bool} + {V.passed(text) == False{} : Bool} + +# LAW: a pass counts one more +law count_pass: + for +n: Nat + {V.count(True{}, n) == (1n + n : Nat) : Nat} + +# LAW: and a failure counts none +law count_fail: + for +n: Nat + {V.count(False{}, n) == n : Nat} + +# LAW: what a failed run printed is shown a line at a time, each indented +law indent_lines: + for text: String + for +h: String + for t: List<&2, String> + for e: {h <> t == String.lines(text) : List<&2, String>} + {V.indent(text) == String.append(" " ++ h ++ "\n", String.concat(V.indent.go(t))) + : String} + +# LAW: the runners start one `bend` for every file they found +law one_run_per_file: + for ps: List<&2, String> + for +cap: Bool + for +gigs: String + for +at: String + {List.length(&2, List<&2, String>, V.cmds(ps, cap, gigs, at)) == List.length(&2, String, ps) : Nat} diff --git a/laws/RefusalReasonShown.bend b/laws/RefusalReasonShown.bend new file mode 100644 index 0000000..a70a81a --- /dev/null +++ b/laws/RefusalReasonShown.bend @@ -0,0 +1,16 @@ +# What `ez check`, `ez build` and `ez run` say they refused for: the reason a +# refusal carries, exactly, and nothing for a command that started bend. +# This is internal: it fixes what ez/start.bend hands the interpreter to +# print. +import Base +import ../src/ez/start.bend as S + +# LAW: a refusal says its own reason +law why_refused: + for w: String + {S.why(S.Refused{w}) == w : String} + +# LAW: and a command that started bend says nothing +law why_started: + for l: List<&2, String> + {S.why(S.Starts{l}) == "" : String} diff --git a/laws/RepliesJoinTheWorld.bend b/laws/RepliesJoinTheWorld.bend new file mode 100644 index 0000000..400883b --- /dev/null +++ b/laws/RepliesJoinTheWorld.bend @@ -0,0 +1,141 @@ +# Each round of a command's interpreter adds the answers it got to the World +# the planner reads, and nothing else: the new answers go after the ones the +# World held, in the order they came, and every other field is the World's +# own. So the planner, which never asks what its World answers already, sees +# each answer once and loses none, whatever the round. +# +# Internal, not interface: this holds the interpreters' bookkeeping in place. +# That the answers are what the other program printed is trusted in +# src/ez/app.bend. +import Base +import ../src/lock/world.bend as W +import ../src/lock/up.bend as Up +import ../src/fetch/world.bend as F +import ../src/doctor/world.bend as DW +import ../src/pub/world.bend as PW +import ../src/tool/world.bend as TW +import ../src/add/world.bend as A +import ../src/add/relock.bend as AR +import ../src/remove/relock.bend as RR +import ../src/remove/plan.bend as RP + +# LAW: `ez lock` and `ez lock --upgrade` add the hub's and git's answers after +# the ones the World held, each to its own list +law lock_replies_join: + for args: W.Args + for ledger: Maybe<&2, String> + for listing: W.Listing + for replies: List<&2, W.Reply> + for ups: List<&2, Up.Reply> + for rs: List<&2, W.Reply> + for us: List<&2, Up.Reply> + {W.more(W.World{args, ledger, listing, replies, ups}, rs, us) + == W.World{args, ledger, listing, List.append(&2, W.Reply, replies, rs), + List.append(&2, Up.Reply, ups, us)} : W.World} + +# LAW: `ez fetch` adds its answers after the ones the World held +law fetch_replies_join: + for here: String + for ledger: Bool + for lock: Maybe<&2, String> + for replies: List<&2, F.Reply> + for rs: List<&2, F.Reply> + {F.more(F.World{here, ledger, lock, replies}, rs) + == F.World{here, ledger, lock, List.append(&2, F.Reply, replies, rs)} : F.World} + +# LAW: `ez doctor` adds its answers after the ones the World held +law doctor_replies_join: + for cc: String + for lib: String + for ledger: Maybe<&2, String> + for lock: Maybe<&2, String> + for replies: List<&2, DW.Reply> + for rs: List<&2, DW.Reply> + {DW.more(DW.World{cc, lib, ledger, lock, replies}, rs) + == DW.World{cc, lib, ledger, lock, List.append(&2, DW.Reply, replies, rs)} : DW.World} + +# LAW: `ez publish` adds its answers after the ones the World held +law publish_replies_join: + for here: String + for ledger: Maybe<&2, String> + for replies: List<&2, PW.Reply> + for rs: List<&2, PW.Reply> + {PW.more(PW.World{here, ledger, replies}, rs) + == PW.World{here, ledger, List.append(&2, PW.Reply, replies, rs)} : PW.World} + +# LAW: `ez tool` adds its own answers and git's after the ones the World +# held, each to its own list +law tool_replies_join: + for act: TW.Act + for target: String + for want: String + for here: String + for env: TW.Env + for bend: String + for ledger: Maybe<&2, String> + for lock: Maybe<&2, String> + for replies: List<&2, TW.Reply> + for ups: List<&2, Up.Reply> + for rs: List<&2, TW.Reply> + for us: List<&2, Up.Reply> + {TW.more(TW.World{act, target, want, here, env, bend, ledger, lock, replies, ups}, rs, us) + == TW.World{act, target, want, here, env, bend, ledger, lock, + List.append(&2, TW.Reply, replies, rs), List.append(&2, Up.Reply, ups, us)} : TW.World} + +# LAW: `ez add` adds git's answers after the ones the add's World held +law add_replies_join: + for args: A.Args + for here: String + for home: String + for ledger: Maybe<&2, String> + for ignore: String + for replies: List<&2, Up.Reply> + for hubs: List<&2, W.Reply> + for rs: List<&2, Up.Reply> + {A.more(A.World{args, here, home, ledger, ignore, replies, hubs}, rs) + == A.World{args, here, home, ledger, ignore, List.append(&2, Up.Reply, replies, rs), hubs} + : A.World} + +# LAW: and the hub's after the hub's +law add_hub_replies_join: + for args: A.Args + for here: String + for home: String + for ledger: Maybe<&2, String> + for ignore: String + for replies: List<&2, Up.Reply> + for hubs: List<&2, W.Reply> + for rs: List<&2, W.Reply> + {A.more.hub(A.World{args, here, home, ledger, ignore, replies, hubs}, rs) + == A.World{args, here, home, ledger, ignore, replies, List.append(&2, W.Reply, hubs, rs)} + : A.World} + +# LAW: the add's relock World passes both on to the add's World, leaving its +# own listing and answers as they were +law add_relock_replies_join: + for a: A.World + for listing: W.Listing + for locks: List<&2, W.Reply> + for rs: List<&2, Up.Reply> + for hs: List<&2, W.Reply> + {AR.more.hub(AR.more(AR.World{a, listing, locks}, rs), hs) + == AR.World{A.more.hub(A.more(a, rs), hs), listing, locks} : AR.World} + +# LAW: and the relock's after the relock's, leaving the add's World as it was +law add_lock_replies_join: + for a: A.World + for listing: W.Listing + for locks: List<&2, W.Reply> + for rs: List<&2, W.Reply> + {AR.more.lock(AR.World{a, listing, locks}, rs) + == AR.World{a, listing, List.append(&2, W.Reply, locks, rs)} : AR.World} + +# LAW: `ez remove` adds the relock's answers after the ones the World held +law remove_replies_join: + for r: RP.World + for here: String + for listing: W.Listing + for locks: List<&2, W.Reply> + for rs: List<&2, W.Reply> + {RR.more(RR.World{r, here, listing, locks}, rs) + == RR.World{r, here, listing, List.append(&2, W.Reply, locks, rs)} : RR.World} diff --git a/laws/RunOutputFiltered.bend b/laws/RunOutputFiltered.bend new file mode 100644 index 0000000..ba8d7ab --- /dev/null +++ b/laws/RunOutputFiltered.bend @@ -0,0 +1,43 @@ +# What `ez test` compares with a test's trailer is the run's output with +# bend's update nag dropped wherever it appears, every other line kept in +# order, and the blank lines at its end dropped, the way a shell's `$(...)` +# drops a trailing newline. This is internal: it fixes ez/quiet.bend, which +# ez/test.bend trusts to hand it only what the program printed. +# also rests on: laws/UpdateNagAnchoredAtFront.bend +import Base +import ../src/ez/quiet.bend as Q + +# LAW: the nag is dropped +law nag_dropped: + for +h: String + for t: List<&2, String> + for e: {True{} == Q.is_nag(h) : Bool} + {Q.go(h <> t) == Q.go(t) : List<&2, String>} + +# LAW: and every other line is kept, in its place +law line_kept: + for +h: String + for t: List<&2, String> + for e: {False{} == Q.is_nag(h) : Bool} + {Q.go(h <> t) == h <> Q.go(t) : List<&2, String>} + +# LAW: a blank line at the end changes nothing the fold collects +law blank_tail_dropped: + for ls: List<&2, String> + {Q.tail.walk(List.append(&2, String, ls, [""])) == Q.tail.walk(ls) : Q.Tail} + +# LAW: so the text compared is the same with a blank line at its end +law chomp_blank_tail: + for text: String + for ls: List<&2, String> + for e: {List.append(&2, String, ls, [""]) == String.lines(text) : List<&2, String>} + {Q.chomp(text) == String.join(Q.chomp.lines(ls), "\n") : String} + +# LAW: and a run that opens with the nag is compared without it +law filter_drops_nag: + for text: String + for +h: String + for t: List<&2, String> + for e: {h <> t == String.lines(text) : List<&2, String>} + for nag: {True{} == Q.is_nag(h) : Bool} + {Q.filter(text) == String.join(Q.chomp.lines(Q.go(t)), "\n") : String} diff --git a/laws/ServeSpeaksHttp.bend b/laws/ServeSpeaksHttp.bend new file mode 100644 index 0000000..3827945 --- /dev/null +++ b/laws/ServeSpeaksHttp.bend @@ -0,0 +1,94 @@ +# The plaintext HTTP ez's test servers speak (src/check/serve.bend), which +# check/framing.bend and check/oracle.bend answer through. This is internal: +# the test servers are not part of ez, and these laws hold their reading and +# framing in place so a test fails on ez and not on its own server. +# +# A request's head ends at its first blank line, a line that is empty or is a +# lone `\r`; the head lines before it are kept in order, and the body is +# everything after it, joined back with the newlines it was split on. A head +# that came out empty has not arrived. The body's length is the head's +# Content-Length, read from the first line that starts with it, whatever its +# case; a head with none says zero. An answer states its body's length in the +# bytes it goes over the wire as, an ASCII character being one byte, and says +# the connection closes. A list of words is indexed from zero, and an index +# past the end is "". +import Base +import ../src/check/serve.bend as S + +# LAW: an ASCII character takes one byte on the wire +law width_ascii: + for +code: U32 + for e: {True{} == U32.is_lt(code, 128) : Bool} + {S.width(code) == 1 : U32} + +# LAW: so a string headed by an ASCII character is one byte longer than its tail +law size_ascii: + for +ch: Char + for tail: String + for e: {True{} == U32.is_lt(Char.to_u32(ch), 128) : Bool} + {S.size(SCon{ch, tail}) == U32.add(1, S.size(tail)) : U32} + +# LAW: the word at index zero is the first +law at_first: + for word: String + for rest: List<&2, String> + {S.at(word <> rest, 0n) == word : String} + +# LAW: the word at the next index is the one at that index of the rest +law at_next: + for word: String + for rest: List<&2, String> + for index: Nat + {S.at(word <> rest, 1n+index) == S.at(rest, index) : String} + +# LAW: an index past the end of the words is "" +law at_past: + for index: Nat + {S.at([], index) == "" : String} + +# LAW: an empty line ends the head, and the lines after it are the body +law cut_blank: + for lines: List<&2, String> + {S.cut("" <> lines) == S.MFull{[], String.join(lines, "\n")} : S.Msg} + +# LAW: and so does a lone `\r`, which is how a CRLF blank line splits +law cut_cr: + for lines: List<&2, String> + {S.cut("\r" <> lines) == S.MFull{[], String.join(lines, "\n")} : S.Msg} + +# LAW: any other line is a head line, kept in front of the head the rest gives +law cut_line: + for +line: String + for lines: List<&2, String> + for e: {False{} == Bool.or(String.is_empty(line), String.eq(line, "\r")) : Bool} + {S.cut(line <> lines) == S.cut.put(line, S.cut(lines)) : S.Msg} + +# LAW: a head that came out empty is a request that has not arrived +law empty_head_partial: + for body: String + {S.msg.at(S.MFull{[], body}) == S.MPartial{} : S.Msg} + +# LAW: a head line that does not state the Content-Length is passed over +law clen_skip: + for +line: String + for lines: List<&2, String> + for e: {False{} == String.starts_with(String.to_lower(line), "content-length:") : Bool} + {S.clen(line <> lines) == S.clen(lines) : U32} + +# LAW: the first one that does gives the length it states, zero when it states +# no number +law clen_read: + for +line: String + for lines: List<&2, String> + for e: {True{} == String.starts_with(String.to_lower(line), "content-length:") : Bool} + {S.clen(line <> lines) + == Maybe.default(&2, U32, U32.read(String.trim(String.drop(line, 15n))), 0) : U32} + +# LAW: an answer is its status, its body's length in bytes, the close, and the +# body +law response_frames: + for status: String + for +body: String + {S.response(status, body) + == "HTTP/1.1 " ++ status ++ "\r\nContent-Length: " ++ U32.show(S.size(body)) ++ + "\r\nConnection: close\r\n\r\n" ++ body : String} diff --git a/laws/ServerArgsAfterName.bend b/laws/ServerArgsAfterName.bend new file mode 100644 index 0000000..53d384e --- /dev/null +++ b/laws/ServerArgsAfterName.bend @@ -0,0 +1,24 @@ +# How a test server reads its command line (src/check/argv.bend). This is +# internal to the test servers. `IO.args()` answers the program's own name +# first, as C's argv does, and then its arguments; a server's arguments are +# the ones after the name, in order, every one kept. +import Base +import ../src/check/argv.bend as A + +# LAW: the program's name is dropped and its first argument comes first +law args_after_name: + for name: String + for first: String + for rest: List<&1, String> + {A.args(Con{name, Con{first, rest}}) == first <> A.copy(rest) : List<&2, String>} + +# LAW: a command line that is only the name has no arguments +law args_name_only: + for name: String + {A.args(Con{name, Nil{}}) == [] : List<&2, String>} + +# LAW: the copy keeps every argument, in order +law copy_keeps: + for first: String + for rest: List<&1, String> + {A.copy(Con{first, rest}) == first <> A.copy(rest) : List<&2, String>} diff --git a/laws/SortKeepsEveryString.bend b/laws/SortKeepsEveryString.bend new file mode 100644 index 0000000..bfe3130 --- /dev/null +++ b/laws/SortKeepsEveryString.bend @@ -0,0 +1,19 @@ +# ez/sorted.bend's sort puts a list of strings in order and drops none of +# them: what it returns is as long as what it was given, and one string +# dropped into a list makes it one longer. This is internal: the runners sort +# the files they find so a report reads the same twice over, and a sort that +# lost a file would run fewer proofs than the tree holds. That the result is +# in order is not proved. +import Base +import ../src/ez/sorted.bend as Sort + +# LAW: a string dropped into a list makes it one longer +law ins_adds_one: + for +item: String + for ss: List<&2, String> + {List.length(&2, String, Sort.sort.ins(item, ss)) == 1n+List.length(&2, String, ss) : Nat} + +# LAW: sorting keeps the list's length +law sort_keeps_length: + for ss: List<&2, String> + {List.length(&2, String, Sort.sort(ss)) == List.length(&2, String, ss) : Nat} diff --git a/laws/StepRunsThePlan.bend b/laws/StepRunsThePlan.bend new file mode 100644 index 0000000..c535b1b --- /dev/null +++ b/laws/StepRunsThePlan.bend @@ -0,0 +1,112 @@ +# What a command's interpreter is told to do next agrees with its planner. +# When the step for a World runs a plan, that plan is exactly the command's +# plan of the same World, so the plan the laws are stated over is the one that +# runs. For `ez fetch` and `ez doctor`, when the step asks, it asks exactly +# the questions the World still leaves open (`wants`), and it runs only once +# there are none. The workspace doctor runs its own plan and asks exactly +# what the doctor asks. Holds for `ez fetch`, `ez doctor` (alone and in a +# workspace), `ez publish` and `ez tool run`, `install` and `upgrade`. +# +# Internal, not interface: this ties each `step` to the `plan` and `wants` +# the command's other laws are stated over. +import Base +import ../src/lock/plan.bend as P +import ../src/fetch/world.bend as F +import ../src/fetch/plan.bend as FP +import ../src/doctor/world.bend as DW +import ../src/doctor/plan.bend as DP +import ../src/ws/doctor.bend as WD +import ../src/pub/world.bend as PW +import ../src/pub/plan.bend as PP +import ../src/tool/world.bend as TW +import ../src/tool/plan.bend as TP + +# the plan a fetch step runs, or `other` when it asks instead +def ran.fetch(st: FP.Step, other: P.Plan) -> P.Plan: + match st: + case FP.Asking{_asks}: + other + case FP.Run{pl}: + pl + +# the questions a fetch step asks, none when it runs a plan +def asked.fetch(st: FP.Step) -> List<&2, F.Ask>: + match st: + case FP.Asking{asks}: + asks + case FP.Run{_pl}: + [] + +# the plan a doctor step runs, or `other` when it asks instead +def ran.doctor(st: DP.Step, other: P.Plan) -> P.Plan: + match st: + case DP.Asking{_asks}: + other + case DP.Run{pl}: + pl + +# the questions a doctor step asks, none when it runs a plan +def asked.doctor(st: DP.Step) -> List<&2, DW.Ask>: + match st: + case DP.Asking{asks}: + asks + case DP.Run{_pl}: + [] + +# the plan a publish step runs, or `other` when it asks instead +def ran.publish(st: PP.Step, other: P.Plan) -> P.Plan: + match st: + case PP.Asking{_asks}: + other + case PP.Run{pl}: + pl + +# the plan a tool step runs, or `other` when it asks instead +def ran.tool(st: TP.Step, other: TP.Plan) -> TP.Plan: + match st: + case TP.Asking{_asks, _ups}: + other + case TP.Run{pl}: + pl + +# LAW: a fetch step that runs a plan runs the fetch's plan of that World +law fetch_step_runs_plan: + for +world: F.World + {ran.fetch(FP.step(world), FP.plan(world)) == FP.plan(world) : P.Plan} + +# LAW: and one that asks asks exactly what the World leaves open +law fetch_step_asks_wants: + for +world: F.World + {asked.fetch(FP.step(world)) == FP.wants(world) : List<&2, F.Ask>} + +# LAW: a doctor step that runs a plan runs the doctor's plan of that World +law doctor_step_runs_plan: + for +world: DW.World + {ran.doctor(DP.step(world), DP.plan(world)) == DP.plan(world) : P.Plan} + +# LAW: and one that asks asks exactly what the World leaves open +law doctor_step_asks_wants: + for +world: DW.World + {asked.doctor(DP.step(world)) == DP.wants(world) : List<&2, DW.Ask>} + +# LAW: the workspace doctor runs its own plan of the World +law workspace_doctor_step_runs_plan: + for back: WD.Back + for +world: DW.World + {ran.doctor(WD.step(back, world), WD.plan(back, world)) == WD.plan(back, world) : P.Plan} + +# LAW: and asks exactly what the doctor asks +law workspace_doctor_step_asks: + for back: WD.Back + for +world: DW.World + {asked.doctor(WD.step(back, world)) == asked.doctor(DP.step(world)) : List<&2, DW.Ask>} + +# LAW: a publish step that runs a plan runs the publish's plan of that World +law publish_step_runs_plan: + for +world: PW.World + {ran.publish(PP.step(world), PP.plan(world)) == PP.plan(world) : P.Plan} + +# LAW: a tool step that runs a plan runs the tool command's plan of that World +law tool_step_runs_plan: + for +world: TW.World + {ran.tool(TP.step(world), TP.plan(world)) == TP.plan(world) : TP.Plan} diff --git a/laws/TestBudgetOnlyWhenSet.bend b/laws/TestBudgetOnlyWhenSet.bend new file mode 100644 index 0000000..b705cdf --- /dev/null +++ b/laws/TestBudgetOnlyWhenSet.bend @@ -0,0 +1,24 @@ +# `ez test` keeps a wall-clock budget exactly when one was given: an empty +# budget, or one of `0`, keeps none, and any other keeps one. This is +# internal: it fixes the choice ez/clock.bend makes for ez/test.bend. +import Base +import ../src/ez/clock.bend as Clock + +# LAW: an empty budget keeps none +law off_when_empty: + for +secs: String + for e: {True{} == String.is_empty(secs) : Bool} + {Clock.on(secs) == False{} : Bool} + +# LAW: and a budget of `0` keeps none +law off_when_zero: + for +secs: String + for e: {True{} == String.eq(secs, "0") : Bool} + {Clock.on(secs) == False{} : Bool} + +# LAW: and any other budget is kept +law on_otherwise: + for +secs: String + for e0: {False{} == String.is_empty(secs) : Bool} + for e1: {False{} == String.eq(secs, "0") : Bool} + {Clock.on(secs) == True{} : Bool} diff --git a/laws/TestOutputPicksLines.bend b/laws/TestOutputPicksLines.bend new file mode 100644 index 0000000..2a249a0 --- /dev/null +++ b/laws/TestOutputPicksLines.bend @@ -0,0 +1,126 @@ +# How an end-to-end test reads a program's answer and builds the command lines +# it runs (src/check/out.bend). This is internal: the tests are host checks, +# never evidence for a guarantee, and these laws only hold their reading in +# place so a test that fails is about ez. +# +# A snap answer is a status line and then what the program printed. A test's +# one-line answer is the first line printed, and a program that reports as it +# goes answers with its last. Empty lines are dropped where a test counts what +# a program listed, and every other line kept in order. A search for a line +# that starts with, or holds, a text gives the first line that does, or "". A +# `key = "value"` line's value is what stands between its first two quotes. +# Every command a test runs inside a project runs there through `env -C` with +# BEND_LIB taken away, and `ez` is the repo's own built binary. +import Base +import snap@1.4.0.0/src/answer.bend as A +import ../src/check/out.bend as O + +# LAW: an empty line is dropped +law nonblank_drops: + for +line: String + for rest: List<&2, String> + for empty: {True{} == String.is_empty(line) : Bool} + {O.nonblank(line <> rest) == O.nonblank(rest) : List<&2, String>} + +# LAW: any other line is kept, in front of what the rest keeps +law nonblank_keeps: + for +line: String + for rest: List<&2, String> + for full: {False{} == String.is_empty(line) : Bool} + {O.nonblank(line <> rest) == line <> O.nonblank(rest) : List<&2, String>} + +# LAW: the first of the lines is the first +law first_line: + for line: String + for rest: List<&2, String> + {O.first(line <> rest) == line : String} + +# LAW: a one-line answer is the first line the program printed +law line_is_first: + for +out: String + {O.line(out) == O.first(String.lines(A.text(out))) : String} + +# LAW: the last of one line is that line +law last_one: + for line: String + {O.last([line]) == line : String} + +# LAW: the last of more lines is the last of the ones after the first +law last_more: + for line: String + for next: String + for rest: List<&2, String> + {O.last(line <> (next <> rest)) == O.last(next <> rest) : String} + +# LAW: a reported answer is the last line the program printed +law tail_is_last: + for +out: String + {O.tail(out) == O.last(String.lines(A.text(out))) : String} + +# LAW: the line at index zero is the first +law nth_first: + for line: String + for rest: List<&2, String> + {O.nth(line <> rest, 0n) == line : String} + +# LAW: the line at the next index is the one at that index of the rest +law nth_next: + for line: String + for rest: List<&2, String> + for index: Nat + {O.nth(line <> rest, 1n+index) == O.nth(rest, index) : String} + +# LAW: a line that starts with the text is the one found +law starting_hit: + for +line: String + for rest: List<&2, String> + for +pre: String + for hit: {True{} == String.starts_with(line, pre) : Bool} + {O.starting(line <> rest, pre) == line : String} + +# LAW: one that does not is passed over +law starting_miss: + for +line: String + for rest: List<&2, String> + for +pre: String + for miss: {False{} == String.starts_with(line, pre) : Bool} + {O.starting(line <> rest, pre) == O.starting(rest, pre) : String} + +# LAW: a line that holds the text is the one found +law containing_hit: + for +line: String + for rest: List<&2, String> + for +sub: String + for hit: {True{} == String.contains(line, sub) : Bool} + {O.containing(line <> rest, sub) == line : String} + +# LAW: one that does not is passed over +law containing_miss: + for +line: String + for rest: List<&2, String> + for +sub: String + for miss: {False{} == String.contains(line, sub) : Bool} + {O.containing(line <> rest, sub) == O.containing(rest, sub) : String} + +# LAW: a key's value is read off the first line that starts with the key, as +# what stands between its first two quotes +law value_reads: + for +text: String + for +key: String + {O.value(text, key) == O.nth(String.split(O.starting(String.lines(text), key), '"'), 1n) + : String} + +# LAW: a command runs in its directory with BEND_LIB taken away, its words +# after that as they were given +law inside_env: + for at: String + for args: List<&2, String> + {O.inside(at, args) == "env" <> ("-C" <> (at <> ("-u" <> ("BEND_LIB" <> args)))) + : List<&2, String>} + +# LAW: `ez` in a project is the repo's own binary, run inside it +law ez_runs_bin: + for +repo: String + for +app: String + for args: List<&2, String> + {O.ez(repo, app, args) == O.inside(app, (repo ++ "/bin/ez.bin") <> args) : List<&2, String>} diff --git a/laws/TestTallyCounts.bend b/laws/TestTallyCounts.bend new file mode 100644 index 0000000..3700ef1 --- /dev/null +++ b/laws/TestTallyCounts.bend @@ -0,0 +1,19 @@ +# `ez test` counts every comparison of a run with its trailer, and passes +# exactly the ones that held: a comparison that held adds one to both the +# passes and the total, and one that did not adds one to the total alone. +# This is internal: it fixes how ez/verdict.bend keeps the score that +# ez/test.bend reports and exits on. +import Base +import ../src/ez/verdict.bend as V + +# LAW: a comparison that held counts as a pass and as one more comparison +law tally_held: + for +p: Nat + for +n: Nat + {V.tally(True{}, V.Tally{p, n}) == V.Tally{(1n + p : Nat), (1n + n : Nat)} : V.Tally} + +# LAW: and one that did not leaves the passes as they were +law tally_failed: + for +p: Nat + for +n: Nat + {V.tally(False{}, V.Tally{p, n}) == V.Tally{p, (1n + n : Nat)} : V.Tally} diff --git a/main.bend b/main.bend index e1cdd98..6561424 100644 --- a/main.bend +++ b/main.bend @@ -12,5 +12,5 @@ import ./src/ez/app.bend as App # the ez command line: read the words, run the command they name, and exit # as it ends -def main() -> IO(Unit): +def main() -> IO(Unit): # noqa: L001 IO entry point App.main() diff --git a/proofs/BenchScanAnswersMode.bend b/proofs/BenchScanAnswersMode.bend new file mode 100644 index 0000000..8076771 --- /dev/null +++ b/proofs/BenchScanAnswersMode.bend @@ -0,0 +1,36 @@ +# proofs of laws/BenchScanAnswersMode.bend +import Base +import ../src/pkg/bench/scan.bend as B +import ../laws/BenchScanAnswersMode.bend as Laws + +def Laws.run_old(_mode, size, e): + %e : {B.run.at(_, size) == "old " ++ Nat.show(B.count.old(B.lines(size))) : String} + {==} + +def Laws.run_new(_mode, size, e): + %e : {B.run.at(_, size) == "new " ++ Nat.show(B.count.new(B.lines(size))) : String} + {==} + +def Laws.args_drop_name(_h, _t): + {==} + +def Laws.copy_keeps_length(xs): + match xs: + case Nil{}: + {==} + case Con{h, t}: + %Laws.copy_keeps_length(t) : {1n+List.length(&2, String, B.copy(t)) == 1n+_ : Nat} + {==} + +def Laws.at_first(_h, _t): + {==} + +def Laws.at_later(_h, _t, _p): + {==} + +def Laws.at_past_end(index): + match index: + case 0n: + {==} + case 1n+_p: + {==} diff --git a/proofs/CappedRunWords.bend b/proofs/CappedRunWords.bend new file mode 100644 index 0000000..b58c5c0 --- /dev/null +++ b/proofs/CappedRunWords.bend @@ -0,0 +1,22 @@ +# proofs of laws/CappedRunWords.bend +import Base +import ../src/share/capped.bend as Capped +import ../laws/CappedRunWords.bend as Laws + +def Laws.uncapped_words(_gigs, _at, _args): + {==} + +def Laws.capped_words(_gigs, _at, _args): + {==} + +def Laws.status_137_killed(_text): + {==} + +def Laws.killed_names_cap(_text, _gigs): + {==} + +# the pick reads the premise's answer +def Laws.unkilled_says_nothing(out, gigs, alive): + Equal.cong(Bool, String, + b => Bool.pick(String, b, "killed for memory at " ++ gigs ++ "G: raise EZ_CAP\n", ""), + Capped.killed(out), False{}, alive) diff --git a/proofs/CommandLineWords.bend b/proofs/CommandLineWords.bend new file mode 100644 index 0000000..c95e182 --- /dev/null +++ b/proofs/CommandLineWords.bend @@ -0,0 +1,30 @@ +# proofs of laws/CommandLineWords.bend +import Base +import ../src/share/args.bend as Args +import ../laws/CommandLineWords.bend as Laws + +def Laws.words_after_program(_prog, _ws): + {==} + +def Laws.word_at_zero(_h, _t): + {==} + +def Laws.word_at_later(_h, _t, _n): + {==} + +# the empty list reads as no word at any place +def Laws.word_past_end(n): + match n: + case 0n: + {==} + case 1n+p: + {==} + +def Laws.split_first(_h, _t): + {==} + +def Laws.env_set_reads(_value): + {==} + +def Laws.env_unset_empty(_e): + {==} diff --git a/proofs/EnvFallsBack.bend b/proofs/EnvFallsBack.bend new file mode 100644 index 0000000..2a9676c --- /dev/null +++ b/proofs/EnvFallsBack.bend @@ -0,0 +1,12 @@ +# proofs of laws/EnvFallsBack.bend +import Base +import ../src/share/env.bend as Env +import ../laws/EnvFallsBack.bend as Laws + +# the pick reads the premise's answer +def Laws.value_kept(value, alt, full): + Equal.cong(Bool, String, b => Bool.pick(String, b, alt, value), + String.is_empty(value), False{}, full) + +def Laws.empty_falls_back(_alt): + {==} diff --git a/proofs/FramingAnswersRoutes.bend b/proofs/FramingAnswersRoutes.bend new file mode 100644 index 0000000..3b2ebcf --- /dev/null +++ b/proofs/FramingAnswersRoutes.bend @@ -0,0 +1,40 @@ +# proofs of laws/FramingAnswersRoutes.bend +import Base +import ../src/check/serve.bend as S +import ../src/check/framing.bend as F +import ../laws/FramingAnswersRoutes.bend as Laws + +def Laws.reply_plain(path, is_plain): + %is_plain : {F.reply.plain(_, path) == S.response("200 OK", F.plain()) : String} + {==} + +def Laws.reply_chunked(path, not_plain, is_chunked): + %not_plain : {F.reply.plain(_, path) == F.chunked() : String} + %is_chunked : {F.reply.chunked(_, path) == F.chunked() : String} + {==} + +def Laws.reply_root(path, not_plain, not_chunked, is_root): + %not_plain : {F.reply.plain(_, path) == S.response("200 OK", "ok") : String} + %not_chunked : {F.reply.chunked(_, path) == S.response("200 OK", "ok") : String} + %is_root : {F.reply.root(_) == S.response("200 OK", "ok") : String} + {==} + +def Laws.reply_unknown(path, not_plain, not_chunked, not_root): + %not_plain : {F.reply.plain(_, path) == S.response("404 Not Found", "") : String} + %not_chunked : {F.reply.chunked(_, path) == S.response("404 Not Found", "") : String} + %not_root : {F.reply.root(_) == S.response("404 Not Found", "") : String} + {==} + +def Laws.chunk_frames(_text): + {==} + +def Laws.hex_one_digit(len, small): + %small : {Bool.pick(String, _, F.hex.digit(len), + F.hex.digit(U32.div(len, 16)) ++ F.hex.digit(U32.mod(len, 16))) == F.hex.digit(len) : String} + {==} + +def Laws.hex_two_digits(len, big): + %big : {Bool.pick(String, _, F.hex.digit(len), + F.hex.digit(U32.div(len, 16)) ++ F.hex.digit(U32.mod(len, 16))) + == F.hex.digit(U32.div(len, 16)) ++ F.hex.digit(U32.mod(len, 16)) : String} + {==} diff --git a/proofs/LiarHidesAnswerWhenMute.bend b/proofs/LiarHidesAnswerWhenMute.bend new file mode 100644 index 0000000..d393e76 --- /dev/null +++ b/proofs/LiarHidesAnswerWhenMute.bend @@ -0,0 +1,22 @@ +# proofs of laws/LiarHidesAnswerWhenMute.bend +import Base +import ../laws/LiarHidesAnswerWhenMute.bend as Laws + +def Laws.bare_unless_mute(mute): + match mute: + case True{}: + {==} + case False{}: + {==} + +def Laws.mining_not_bare(_hash): + {==} + +def Laws.importing_not_bare(_hash): + {==} + +def Laws.unset_is_empty(_err): + {==} + +def Laws.set_is_text(_text): + {==} diff --git a/proofs/LineNeverRunsHelp.bend b/proofs/LineNeverRunsHelp.bend new file mode 100644 index 0000000..36d6ef0 --- /dev/null +++ b/proofs/LineNeverRunsHelp.bend @@ -0,0 +1,74 @@ +# proofs of laws/LineNeverRunsHelp.bend +import Base +import shake@0.6.0.0/main.bend as Shake +import ../src/ez/line.bend as L +import ../laws/LineNeverRunsHelp.bend as Laws + +# LAW: a line Shake refused shows help or is misused, whatever help it named +law err_runs_none: + for help: Maybe<&2, List<&2, String>> + for +app: Shake.Cli + for err: Shake.ParseErr + {Laws.runs.help(L.line.err(help, app, err)) == False{} : Bool} + +def err_runs_none(help, _app, _err): + match help: + case Some{_p}: + {==} + case None{}: + {==} + +# LAW: a group shows help or is misused, bare or not +law group_runs_none: + for bare: Bool + for +app: Shake.Cli + for +matched: Shake.Matched + {Laws.runs.help(L.line.group(bare, app, matched)) == False{} : Bool} + +def group_runs_none(bare, _app, _matched): + match bare: + case True{}: + {==} + case False{}: + {==} + +# LAW: a parsed line runs its command only when that command is not help +law run_runs_none: + for help: Bool + for sub: L.Sub + for +app: Shake.Cli + for +matched: Shake.Matched + for e: {help == L.is.help(sub) : Bool} + {Laws.runs.help(L.line.run(help, sub, app, matched)) == False{} : Bool} + +def run_runs_none(help, _sub, app, matched, e): + match help: + case True{}: + group_runs_none(String.is_empty(L.path(matched)), app, matched) + case False{}: + %e : {_ == False{} : Bool} + {==} + +# LAW: whatever Shake made of a line, it does not run the help subcommand +law line_runs_none: + for +app: Shake.Cli + for parsed: Result<&2, &2, Shake.ParseErr, Shake.Matched> + {Laws.runs.help(L.line(app, parsed)) == False{} : Bool} + +def line_runs_none(app, parsed): + match parsed: + case Fail{+e}: + err_runs_none(Shake.help_path(e), app, e) + case Done{+m}: + run_runs_none(L.is.help(L.command(L.path(m))), L.command(L.path(m)), app, m, {==}) + +def Laws.never_runs_help(argv): + line_runs_none(L.spec(), Shake.parse(L.spec(), argv)) + +def Laws.get_bound(_found, _name, v, e): + %e : {Maybe.default(&2, String, _, "") == v : String} + {==} + +def Laws.get_unbound(_found, _name, e): + %e : {Maybe.default(&2, String, _, "") == "" : String} + {==} diff --git a/proofs/NarBuildsTree.bend b/proofs/NarBuildsTree.bend new file mode 100644 index 0000000..76ca3ab --- /dev/null +++ b/proofs/NarBuildsTree.bend @@ -0,0 +1,29 @@ +# proofs of laws/NarBuildsTree.bend +import Base +import ../src/check/eq.bend as Eq +import ../src/pkg/pkg.bend as K +import ../src/sha/nar.bend as Nar +import ../laws/NarBuildsTree.bend as Laws + +# the type of the top decides, and each leaf is its own node +def Laws.nar_lone_file(_ex, _name, _at, _body): + {==} + +def Laws.nar_lone_symlink(_ex, _name, _at, _target): + {==} + +# the build of no paths closes the top at once +def Laws.nar_lone_directory(_ex, _name, _at, _body): + {==} + +# the file is inside the top because its path is its name under the top's +# empty path, and a string equals itself +def Laws.nar_file_in_directory(_dex, _dname, _dat, _dbody, ex, name, body): + Equal.cong(Bool, Maybe<&2, String>, + b => Nar.build.go(3n, Nar.step.ent(b, Nar.Ent{"f", ex, name, name, body}, [], + Nar.Frame{"", "", []}, [])), + String.eq(name, name), True{}, Eq.string_eq_self(name)) + +# a close with a directory around it is one step of the definition +def Laws.nar_close_nested(_at, _name, _kids, _pat, _pname, _pkids, _up, _es): + {==} diff --git a/proofs/NarHashForm.bend b/proofs/NarHashForm.bend new file mode 100644 index 0000000..18b08e3 --- /dev/null +++ b/proofs/NarHashForm.bend @@ -0,0 +1,37 @@ +# proofs of laws/NarHashForm.bend +import Base +import ../src/check/eq.bend as Eq +import ../src/sha/nar.bend as Nar +import ../src/share/sha.bend as Sha +import ../laws/NarHashForm.bend as Laws + +def Laws.nar_archive_magic(_node): + {==} + +# the SRI is `sha256-` appended to the base64, so it is a prefix +def Laws.sri_names_sha256(bytes): + Eq.starts_append("sha256-", Nar.b64(Nar.hex.bytes(Sha.raw(bytes)))) + +# the group's own encoding, with the empty rest it ends on taken off +def Laws.b64_by_groups_of_three(a, b, c, rest): + Equal.cong(String, String, x => String.append(x, Nar.b64(rest)), + Nar.b64.triple(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c)), + String.append(Nar.b64.triple(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c)), ""), + Equal.sym(String, + String.append(Nar.b64.triple(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c)), ""), + Nar.b64.triple(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c)), + Eq.append_nil(Nar.b64.triple(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c))))) + +# each padded group is four characters built one by one +def Laws.b64_pads_one(_a): + {==} + +def Laws.b64_pads_two(_a, _b): + {==} + +# a triple is four characters, and the empty rest adds none +def Laws.b64_three_is_four(a, b, c): + Equal.cong(String, Nat, x => String.length(x), + String.append(Nar.b64.triple(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c)), ""), + Nar.b64.triple(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c)), + Eq.append_nil(Nar.b64.triple(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c)))) diff --git a/proofs/NarListingRows.bend b/proofs/NarListingRows.bend new file mode 100644 index 0000000..494c9ec --- /dev/null +++ b/proofs/NarListingRows.bend @@ -0,0 +1,10 @@ +# proofs of laws/NarListingRows.bend +import Base +import ../src/sha/nar.bend as Nar +import ../laws/NarListingRows.bend as Laws + +def Laws.rows_by_five(_kind, _mode, _name, _at, _target, _rest): + {==} + +def Laws.rows_cut_short(_kind, _mode, _name, _at): + {==} diff --git a/proofs/NonTrailerLineSkipped.bend b/proofs/NonTrailerLineSkipped.bend index 8059999..51634bb 100644 --- a/proofs/NonTrailerLineSkipped.bend +++ b/proofs/NonTrailerLineSkipped.bend @@ -6,3 +6,9 @@ import ../laws/NonTrailerLineSkipped.bend as Laws def Laws.want_skips(h, t, e): %e : {G.want.put(_, h, G.want(t)) == G.want(t) : List<&2, String>} {==} + +def Laws.trailer_skips(_text, h, t, e, ne): + %e : {String.join(G.want(_), "\n") == String.join(G.want(t), "\n") : String} + %Equal.sym(List<&2, String>, G.want(h <> t), G.want(t), Laws.want_skips(h, t, ne)) + : {String.join(_, "\n") == String.join(G.want(t), "\n") : String} + {==} diff --git a/proofs/OracleReadsPublishBody.bend b/proofs/OracleReadsPublishBody.bend new file mode 100644 index 0000000..5e0b90d --- /dev/null +++ b/proofs/OracleReadsPublishBody.bend @@ -0,0 +1,41 @@ +# proofs of laws/OracleReadsPublishBody.bend +import Base +import ../src/check/serve.bend as S +import ../src/check/body.bend as B +import ../laws/OracleReadsPublishBody.bend as Laws + +def Laws.ws_skips(ch, tail, space): + %space : {B.ws.step(_, ch, tail, _u => B.ws(tail)) == B.ws(tail) : String} + {==} + +def Laws.ws_stops(ch, tail, solid): + %solid : {B.ws.step(_, ch, tail, _u => B.ws(tail)) == SCon{ch, tail} : String} + {==} + +def Laws.eat_hit(text, _ch, heads): + %heads : {B.eat.at(_, String.drop(text, 1n)) == Some{String.drop(text, 1n)} : Maybe<&2, String>} + {==} + +def Laws.eat_miss(text, _ch, absent): + %absent : {B.eat.at(_, String.drop(text, 1n)) == None{} : Maybe<&2, String>} + {==} + +def Laws.unesc_empty(fuel): + match fuel: + case 0n: + {==} + case 1n+_f: + {==} + +def Laws.unesc_plain(fuel, ch, tail, plain): + %plain : {B.uns.put(B.uns.step(_, ch, tail), B.unesc(fuel, B.uns.rest(B.uns.step(_, ch, tail)))) + == B.uns.push(ch, B.unesc(fuel, tail)) : B.Uns} + {==} + +def Laws.parse_not_object(body, open): + %open : {B.parse.open(U32.to_nat(U32.add(U32.div(S.size(body), 6), 8)), _) + == B.OBad{"a body that is not an object"} : B.Obj} + {==} + +def Laws.sorted_one(_entry): + {==} diff --git a/proofs/PackagePrintedWithHash.bend b/proofs/PackagePrintedWithHash.bend new file mode 100644 index 0000000..1c9b84e --- /dev/null +++ b/proofs/PackagePrintedWithHash.bend @@ -0,0 +1,15 @@ +# proofs of laws/PackagePrintedWithHash.bend +import Base +import ../laws/PackagePrintedWithHash.bend as Laws + +def Laws.show_package(_h, _root, _fs): + {==} + +def Laws.text_of_set(_s): + {==} + +def Laws.text_of_unset(_e): + {==} + +def Laws.resume_goes_on(_seen, _out, _stop, _queue): + {==} diff --git a/proofs/PlaceShownOnOneLine.bend b/proofs/PlaceShownOnOneLine.bend new file mode 100644 index 0000000..751e216 --- /dev/null +++ b/proofs/PlaceShownOnOneLine.bend @@ -0,0 +1,12 @@ +# proofs of laws/PlaceShownOnOneLine.bend +import Base +import ../laws/PlaceShownOnOneLine.bend as Laws + +def Laws.show_bad(_why): + {==} + +def Laws.show_local(_path): + {==} + +def Laws.show_remote(_url, _slug): + {==} diff --git a/proofs/ProgressNamesBriefly.bend b/proofs/ProgressNamesBriefly.bend new file mode 100644 index 0000000..5ff0c27 --- /dev/null +++ b/proofs/ProgressNamesBriefly.bend @@ -0,0 +1,22 @@ +# proofs of laws/ProgressNamesBriefly.bend +import Base +import ../src/pkg/path.bend as P +import ../src/share/say.bend as Say +import ../laws/ProgressNamesBriefly.bend as Laws + +# each is the branch its premise picks +def Laws.short_rev_whole(rev, short): + Equal.cong(Bool, String, b => Say.brief.go(b, rev), + Nat.is_le(String.length(rev), 12n), True{}, short) + +def Laws.long_rev_cut(rev, long): + Equal.cong(Bool, String, b => Say.brief.go(b, rev), + Nat.is_le(String.length(rev), 12n), False{}, long) + +def Laws.label_names_entry(hash, entry, named): + Equal.cong(Bool, String, b => Say.label.go(b, hash, P.unbend(P.base(entry))), + String.is_empty(P.unbend(P.base(entry))), False{}, named) + +def Laws.label_falls_to_hash(hash, entry, blank): + Equal.cong(Bool, String, b => Say.label.go(b, hash, P.unbend(P.base(entry))), + String.is_empty(P.unbend(P.base(entry))), True{}, blank) diff --git a/proofs/ProofPassesOnVerdictLine.bend b/proofs/ProofPassesOnVerdictLine.bend new file mode 100644 index 0000000..7939e87 --- /dev/null +++ b/proofs/ProofPassesOnVerdictLine.bend @@ -0,0 +1,33 @@ +# proofs of laws/ProofPassesOnVerdictLine.bend +import Base +import ../src/ez/verdict.bend as V +import ../laws/ProofPassesOnVerdictLine.bend as Laws + +def Laws.passes_on_verdict(_text, _t, e): + %e : {String.eq(V.head.of(_), V.verdict()) == True{} : Bool} + {==} + +def Laws.fails_otherwise(_text, _h, _t, e, ne): + %e : {String.eq(V.head.of(_), V.verdict()) == False{} : Bool} + %ne : {_ == False{} : Bool} + {==} + +def Laws.count_pass(_n): + {==} + +def Laws.count_fail(_n): + {==} + +def Laws.indent_lines(_text, h, t, e): + %e : {String.concat(V.indent.go(_)) + == String.append(" " ++ h ++ "\n", String.concat(V.indent.go(t))) : String} + {==} + +def Laws.one_run_per_file(ps, cap, gigs, at): + match ps: + case []: + {==} + case +h <> t: + %Laws.one_run_per_file(t, cap, gigs, at) + : {1n+List.length(&2, List<&2, String>, V.cmds(t, cap, gigs, at)) == 1n+_ : Nat} + {==} diff --git a/proofs/RefusalReasonShown.bend b/proofs/RefusalReasonShown.bend new file mode 100644 index 0000000..ffaeb5a --- /dev/null +++ b/proofs/RefusalReasonShown.bend @@ -0,0 +1,9 @@ +# proofs of laws/RefusalReasonShown.bend +import Base +import ../laws/RefusalReasonShown.bend as Laws + +def Laws.why_refused(_w): + {==} + +def Laws.why_started(_l): + {==} diff --git a/proofs/RepliesJoinTheWorld.bend b/proofs/RepliesJoinTheWorld.bend new file mode 100644 index 0000000..58deac1 --- /dev/null +++ b/proofs/RepliesJoinTheWorld.bend @@ -0,0 +1,46 @@ +# proofs of laws/RepliesJoinTheWorld.bend +import Base +import ../laws/RepliesJoinTheWorld.bend as Laws + +def Laws.lock_replies_join(_args, _ledger, _listing, _replies, _ups, _rs, _us): + {==} + +def Laws.fetch_replies_join(_here, _ledger, _lock, _replies, _rs): + {==} + +def Laws.doctor_replies_join(_cc, _lib, _ledger, _lock, _replies, _rs): + {==} + +def Laws.publish_replies_join(_here, _ledger, _replies, _rs): + {==} + +def Laws.tool_replies_join( + _act, + _target, + _want, + _here, + _env, + _bend, + _ledger, + _lock, + _replies, + _ups, + _rs, + _us +): + {==} + +def Laws.add_replies_join(_args, _here, _home, _ledger, _ignore, _replies, _hubs, _rs): + {==} + +def Laws.add_hub_replies_join(_args, _here, _home, _ledger, _ignore, _replies, _hubs, _rs): + {==} + +def Laws.add_relock_replies_join(_a, _listing, _locks, _rs, _hs): + {==} + +def Laws.add_lock_replies_join(_a, _listing, _locks, _rs): + {==} + +def Laws.remove_replies_join(_r, _here, _listing, _locks, _rs): + {==} diff --git a/proofs/RunOutputFiltered.bend b/proofs/RunOutputFiltered.bend new file mode 100644 index 0000000..1347fdf --- /dev/null +++ b/proofs/RunOutputFiltered.bend @@ -0,0 +1,39 @@ +# proofs of laws/RunOutputFiltered.bend +import Base +import ../src/ez/quiet.bend as Q +import ../laws/RunOutputFiltered.bend as Laws + +def Laws.nag_dropped(h, t, e): + %e : {Q.put(_, h, Q.go(t)) == Q.go(t) : List<&2, String>} + {==} + +def Laws.line_kept(h, t, e): + %e : {Q.put(_, h, Q.go(t)) == h <> Q.go(t) : List<&2, String>} + {==} + +# by induction on the lines: the blank is the last step of the fold, and a +# blank offered to a fold that has kept nothing yet is dropped +def Laws.blank_tail_dropped(ls): + match ls: + case []: + {==} + case h <> t: + %Equal.sym(Q.Tail, Q.tail.walk(List.append(&2, String, t, [""])), Q.tail.walk(t), + Laws.blank_tail_dropped(t)) + : {Q.tail.step(h, _) == Q.tail.step(h, Q.tail.walk(t)) : Q.Tail} + {==} + +def Laws.chomp_blank_tail(_text, ls, e): + %e : {String.join(Q.tail.out(Q.tail.walk(_)), "\n") + == String.join(Q.tail.out(Q.tail.walk(ls)), "\n") : String} + %Equal.sym(Q.Tail, Q.tail.walk(List.append(&2, String, ls, [""])), Q.tail.walk(ls), + Laws.blank_tail_dropped(ls)) + : {String.join(Q.tail.out(_), "\n") == String.join(Q.tail.out(Q.tail.walk(ls)), "\n") : String} + {==} + +def Laws.filter_drops_nag(_text, h, t, e, nag): + %e : {String.join(Q.chomp.lines(Q.go(_)), "\n") + == String.join(Q.chomp.lines(Q.go(t)), "\n") : String} + %Equal.sym(List<&2, String>, Q.go(h <> t), Q.go(t), Laws.nag_dropped(h, t, nag)) + : {String.join(Q.chomp.lines(_), "\n") == String.join(Q.chomp.lines(Q.go(t)), "\n") : String} + {==} diff --git a/proofs/ServeSpeaksHttp.bend b/proofs/ServeSpeaksHttp.bend new file mode 100644 index 0000000..8870d49 --- /dev/null +++ b/proofs/ServeSpeaksHttp.bend @@ -0,0 +1,58 @@ +# proofs of laws/ServeSpeaksHttp.bend +import Base +import ../src/check/serve.bend as S +import ../laws/ServeSpeaksHttp.bend as Laws + +def Laws.width_ascii(code, e): + %e : {Bool.pick(U32, _, 1, + Bool.pick(U32, U32.is_lt(code, 2048), 2, + Bool.pick(U32, U32.is_lt(code, 65536), 3, 4))) == 1 : U32} + {==} + +def Laws.size_ascii(ch, tail, e): + %Equal.sym(U32, S.width(Char.to_u32(ch)), 1, Laws.width_ascii(Char.to_u32(ch), e)) + : {U32.add(_, S.size(tail)) == U32.add(1, S.size(tail)) : U32} + {==} + +def Laws.at_first(_word, _rest): + {==} + +def Laws.at_next(_word, _rest, _index): + {==} + +def Laws.at_past(index): + match index: + case 0n: + {==} + case 1n+_p: + {==} + +def Laws.cut_blank(_lines): + {==} + +def Laws.cut_cr(_lines): + {==} + +def Laws.cut_line(line, lines, e): + %e : {S.cut.step(_, lines, _u => S.cut.put(line, S.cut(lines))) + == S.cut.put(line, S.cut(lines)) : S.Msg} + {==} + +def Laws.empty_head_partial(_body): + {==} + +def Laws.clen_skip(line, lines, e): + %e : {Bool.pick(U32, _, + Maybe.default(&2, U32, U32.read(String.trim(String.drop(line, 15n))), 0), + S.clen(lines)) == S.clen(lines) : U32} + {==} + +def Laws.clen_read(line, lines, e): + %e : {Bool.pick(U32, _, + Maybe.default(&2, U32, U32.read(String.trim(String.drop(line, 15n))), 0), + S.clen(lines)) + == Maybe.default(&2, U32, U32.read(String.trim(String.drop(line, 15n))), 0) : U32} + {==} + +def Laws.response_frames(_status, _body): + {==} diff --git a/proofs/ServerArgsAfterName.bend b/proofs/ServerArgsAfterName.bend new file mode 100644 index 0000000..429bda6 --- /dev/null +++ b/proofs/ServerArgsAfterName.bend @@ -0,0 +1,12 @@ +# proofs of laws/ServerArgsAfterName.bend +import Base +import ../laws/ServerArgsAfterName.bend as Laws + +def Laws.args_after_name(_name, _first, _rest): + {==} + +def Laws.args_name_only(_name): + {==} + +def Laws.copy_keeps(_first, _rest): + {==} diff --git a/proofs/SortKeepsEveryString.bend b/proofs/SortKeepsEveryString.bend new file mode 100644 index 0000000..4011370 --- /dev/null +++ b/proofs/SortKeepsEveryString.bend @@ -0,0 +1,39 @@ +# proofs of laws/SortKeepsEveryString.bend +import Base +import ../src/ez/sorted.bend as Sort +import ../laws/SortKeepsEveryString.bend as Laws + +# LAW: the choice an insertion makes keeps the count, whichever it is +law put_adds_one: + for le: Bool + for +item: String + for +h: String + for t: List<&2, String> + for ih: {List.length(&2, String, Sort.sort.ins(item, t)) == 1n+List.length(&2, String, t) : Nat} + {List.length(&2, String, Sort.sort.ins.put(le, item, h, t, Sort.sort.ins(item, t))) + == 1n+1n+List.length(&2, String, t) : Nat} + +def put_adds_one(le, item, _h, t, ih): + match le: + case True{}: + {==} + case False{}: + %Equal.sym(Nat, List.length(&2, String, Sort.sort.ins(item, t)), 1n+List.length(&2, String, t), ih) + : {1n+_ == 1n+1n+List.length(&2, String, t) : Nat} + {==} + +def Laws.ins_adds_one(item, ss): + match ss: + case []: + {==} + case +h <> +t: + put_adds_one(String.is_le(item, h), item, h, t, Laws.ins_adds_one(item, t)) + +def Laws.sort_keeps_length(ss): + match ss: + case []: + {==} + case +h <> +t: + %Laws.sort_keeps_length(t) + : {List.length(&2, String, Sort.sort.ins(h, Sort.sort(t))) == 1n+_ : Nat} + Laws.ins_adds_one(h, Sort.sort(t)) diff --git a/proofs/StepRunsThePlan.bend b/proofs/StepRunsThePlan.bend new file mode 100644 index 0000000..f73d21d --- /dev/null +++ b/proofs/StepRunsThePlan.bend @@ -0,0 +1,250 @@ +# proofs of laws/StepRunsThePlan.bend +import Base +import ../src/lock/plan.bend as P +import ../src/fetch/world.bend as F +import ../src/fetch/plan.bend as FP +import ../src/doctor/world.bend as DW +import ../src/doctor/plan.bend as DP +import ../src/ws/doctor.bend as WD +import ../src/pub/world.bend as PW +import ../src/pub/plan.bend as PP +import ../src/tool/world.bend as TW +import ../src/tool/plan.bend as TP +import ../src/ledger/manifest.bend as M +import ../src/lock/lock.bend as L +import ../laws/StepRunsThePlan.bend as Laws + +# `ez fetch`. The step and the plan take the ledger and the lock apart the +# same way, so each lemma follows one of them a level down. + +# LAW: the questions decide whether the parts' plan runs, and nothing else +law fetch_asks_ran: + for asks: List<&2, F.Ask> + for ps: List<&2, FP.Pt> + for +ms: List<&2, FP.Nm> + {Laws.ran.fetch(FP.step.asks(asks, ps, ms), FP.parts.plan(ps, ms)) == FP.parts.plan(ps, ms) + : P.Plan} + +def fetch_asks_ran(asks, _ps, _ms): + match asks: + case []: + {==} + case _h <> _t: + {==} + +# LAW: and the step asks the questions it was given +law fetch_asks_asked: + for asks: List<&2, F.Ask> + for ps: List<&2, FP.Pt> + for +ms: List<&2, FP.Nm> + {Laws.asked.fetch(FP.step.asks(asks, ps, ms)) == asks : List<&2, F.Ask>} + +def fetch_asks_asked(asks, _ps, _ms): + match asks: + case []: + {==} + case _h <> _t: + {==} + +# LAW: with the ledger there, the lock decides +law fetch_lock_ran: + for got: Maybe<&2, String> + for +world: F.World + {Laws.ran.fetch(FP.step.lock(got, world), FP.plan.lock(got, world)) == FP.plan.lock(got, world) + : P.Plan} + +def fetch_lock_ran(got, world): + match got: + case None{}: + {==} + case Some{_text}: + fetch_asks_ran( + List.append(&2, F.Ask, + FP.asks.of(FP.parts.of(F.sects(world), world), F.here(world), L.lock.hub(F.sects(world))), + FP.names.asks(FP.name.parts.of(F.sects(world), world))), + FP.parts.of(F.sects(world), world), FP.name.parts.of(F.sects(world), world)) + +# LAW: and the asks a lock leaves are what the step asks +law fetch_lock_asked: + for got: Maybe<&2, String> + for +world: F.World + {Laws.asked.fetch(FP.step.lock(got, world)) == FP.wants.lock(got, world) : List<&2, F.Ask>} + +def fetch_lock_asked(got, world): + match got: + case None{}: + {==} + case Some{_text}: + fetch_asks_asked( + List.append(&2, F.Ask, + FP.asks.of(FP.parts.of(F.sects(world), world), F.here(world), L.lock.hub(F.sects(world))), + FP.names.asks(FP.name.parts.of(F.sects(world), world))), + FP.parts.of(F.sects(world), world), FP.name.parts.of(F.sects(world), world)) + +# LAW: and before that the ledger +law fetch_led_ran: + for led: Bool + for got: Maybe<&2, String> + for +world: F.World + {Laws.ran.fetch(FP.step.led(led, got, world), FP.plan.led(led, got, world)) + == FP.plan.led(led, got, world) : P.Plan} + +def fetch_led_ran(led, got, world): + match led: + case False{}: + {==} + case True{}: + fetch_lock_ran(got, world) + +# LAW: likewise for the questions +law fetch_led_asked: + for led: Bool + for got: Maybe<&2, String> + for +world: F.World + {Laws.asked.fetch(FP.step.led(led, got, world)) == FP.wants.led(led, got, world) + : List<&2, F.Ask>} + +def fetch_led_asked(led, got, world): + match led: + case False{}: + {==} + case True{}: + fetch_lock_asked(got, world) + +def Laws.fetch_step_runs_plan(world): + fetch_led_ran(F.ledger(world), F.lock(world), world) + +def Laws.fetch_step_asks_wants(world): + fetch_led_asked(F.ledger(world), F.lock(world), world) + +# `ez doctor`: the step and the plan read the same fields of the World + +# LAW: the doctor's questions decide whether its plan runs, and nothing else +law doctor_asks_ran: + for asks: List<&2, DW.Ask> + for +ledger: M.Read + for +cc: String + for +lib: String + for lock: Maybe<&2, String> + for +rs: List<&2, DW.Reply> + for cs: List<&2, DP.Note> + {Laws.ran.doctor(DP.step.asks(asks, ledger, cc, lib, lock, rs, cs), + DP.plan.of(ledger, cc, lib, lock, rs, cs)) == DP.plan.of(ledger, cc, lib, lock, rs, cs) : P.Plan} + +def doctor_asks_ran(asks, _ledger, _cc, _lib, _lock, _rs, _cs): + match asks: + case []: + {==} + case _h <> _t: + {==} + +# LAW: and the step asks the questions it was given +law doctor_asks_asked: + for asks: List<&2, DW.Ask> + for +ledger: M.Read + for +cc: String + for +lib: String + for lock: Maybe<&2, String> + for +rs: List<&2, DW.Reply> + for cs: List<&2, DP.Note> + {Laws.asked.doctor(DP.step.asks(asks, ledger, cc, lib, lock, rs, cs)) == asks : List<&2, DW.Ask>} + +def doctor_asks_asked(asks, _ledger, _cc, _lib, _lock, _rs, _cs): + match asks: + case []: + {==} + case _h <> _t: + {==} + +def Laws.doctor_step_runs_plan(world): + doctor_asks_ran( + DP.open(List.append(&2, DW.Ask, + DP.asks.of(DP.ledger.seen(DW.read(world)), DW.cc(world), DW.lib(world), DW.lock(world)), + DP.trees.of(DW.ledger(world), DW.lock(world), DW.lock(world), DW.replies(world))), + DW.replies(world)), + DP.ledger.seen(DW.read(world)), DW.cc(world), DW.lib(world), DW.lock(world), DW.replies(world), + DP.checked(world)) + +def Laws.doctor_step_asks_wants(world): + doctor_asks_asked( + DP.open(List.append(&2, DW.Ask, + DP.asks.of(DP.ledger.seen(DW.read(world)), DW.cc(world), DW.lib(world), DW.lock(world)), + DP.trees.of(DW.ledger(world), DW.lock(world), DW.lock(world), DW.replies(world))), + DW.replies(world)), + DP.ledger.seen(DW.read(world)), DW.cc(world), DW.lib(world), DW.lock(world), DW.replies(world), + DP.checked(world)) + +# the workspace doctor passes the doctor's step on + +# LAW: whatever the doctor's step, the workspace's runs the workspace's plan +law workspace_of_ran: + for st: DP.Step + for back: WD.Back + for +world: DW.World + {Laws.ran.doctor(WD.step.of(st, back, world), WD.plan(back, world)) == WD.plan(back, world) + : P.Plan} + +def workspace_of_ran(st, _back, _world): + match st: + case DP.Asking{_asks}: + {==} + case DP.Run{_pl}: + {==} + +# LAW: and asks what the doctor's asks +law workspace_of_asked: + for st: DP.Step + for back: WD.Back + for +world: DW.World + {Laws.asked.doctor(WD.step.of(st, back, world)) == Laws.asked.doctor(st) : List<&2, DW.Ask>} + +def workspace_of_asked(st, _back, _world): + match st: + case DP.Asking{_asks}: + {==} + case DP.Run{_pl}: + {==} + +def Laws.workspace_doctor_step_runs_plan(back, world): + workspace_of_ran(DP.step(world), back, world) + +def Laws.workspace_doctor_step_asks(back, world): + workspace_of_asked(DP.step(world), back, world) + +# `ez publish` and `ez tool`: the step and the plan read one verdict + +# LAW: whatever the publish's verdict, a step that runs runs its plan +law publish_v_ran: + for v: PP.Verdict + for +world: PW.World + {Laws.ran.publish(PP.step.v(v, world), PP.plan.v(v, world)) == PP.plan.v(v, world) : P.Plan} + +def publish_v_ran(v, _world): + match v: + case PP.Go{}: + {==} + case PP.Pending{_asks}: + {==} + case PP.Stop{_why}: + {==} + +def Laws.publish_step_runs_plan(world): + publish_v_ran(PP.decide(world), world) + +# LAW: whatever the tool command's verdict, a step that runs runs its plan +law tool_v_ran: + for v: TP.Verdict + for +world: TW.World + {Laws.ran.tool(TP.step.v(v, world), TP.plan.v(v, world)) == TP.plan.v(v, world) : TP.Plan} + +def tool_v_ran(v, _world): + match v: + case TP.Go{}: + {==} + case TP.Pending{_as, _us}: + {==} + case TP.Stop{_why}: + {==} + +def Laws.tool_step_runs_plan(world): + tool_v_ran(TP.decide(world), world) diff --git a/proofs/TestBudgetOnlyWhenSet.bend b/proofs/TestBudgetOnlyWhenSet.bend new file mode 100644 index 0000000..340d2b7 --- /dev/null +++ b/proofs/TestBudgetOnlyWhenSet.bend @@ -0,0 +1,29 @@ +# proofs of laws/TestBudgetOnlyWhenSet.bend +import Base +import ../src/ez/clock.bend as Clock +import ../laws/TestBudgetOnlyWhenSet.bend as Laws + +def Laws.off_when_empty(secs, e): + %e : {Bool.not(Bool.or(_, String.eq(secs, "0"))) == False{} : Bool} + {==} + +# LAW: a bit or'd with True is True, whatever the bit +law or_true: + for b: Bool + {Bool.not(Bool.or(b, True{})) == False{} : Bool} + +def or_true(b): + match b: + case True{}: + {==} + case False{}: + {==} + +def Laws.off_when_zero(secs, e): + %e : {Bool.not(Bool.or(String.is_empty(secs), _)) == False{} : Bool} + or_true(String.is_empty(secs)) + +def Laws.on_otherwise(secs, e0, e1): + %e0 : {Bool.not(Bool.or(_, String.eq(secs, "0"))) == True{} : Bool} + %e1 : {Bool.not(Bool.or(False{}, _)) == True{} : Bool} + {==} diff --git a/proofs/TestOutputPicksLines.bend b/proofs/TestOutputPicksLines.bend new file mode 100644 index 0000000..269ac96 --- /dev/null +++ b/proofs/TestOutputPicksLines.bend @@ -0,0 +1,60 @@ +# proofs of laws/TestOutputPicksLines.bend +import Base +import ../src/check/out.bend as O +import ../laws/TestOutputPicksLines.bend as Laws + +def Laws.nonblank_drops(line, rest, empty): + %empty : {Bool.pick(List<&2, String>, _, O.nonblank(rest), line <> O.nonblank(rest)) + == O.nonblank(rest) : List<&2, String>} + {==} + +def Laws.nonblank_keeps(line, rest, full): + %full : {Bool.pick(List<&2, String>, _, O.nonblank(rest), line <> O.nonblank(rest)) + == line <> O.nonblank(rest) : List<&2, String>} + {==} + +def Laws.first_line(_line, _rest): + {==} + +def Laws.line_is_first(_out): + {==} + +def Laws.last_one(_line): + {==} + +def Laws.last_more(_line, _next, _rest): + {==} + +def Laws.tail_is_last(_out): + {==} + +def Laws.nth_first(_line, _rest): + {==} + +def Laws.nth_next(_line, _rest, _index): + {==} + +def Laws.starting_hit(line, rest, pre, hit): + %hit : {O.first.step(_, line, _u => O.starting(rest, pre)) == line : String} + {==} + +def Laws.starting_miss(line, rest, pre, miss): + %miss : {O.first.step(_, line, _u => O.starting(rest, pre)) == O.starting(rest, pre) : String} + {==} + +def Laws.containing_hit(line, rest, sub, hit): + %hit : {O.first.step(_, line, _u => O.containing(rest, sub)) == line : String} + {==} + +def Laws.containing_miss(line, rest, sub, miss): + %miss : {O.first.step(_, line, _u => O.containing(rest, sub)) == O.containing(rest, sub) : String} + {==} + +def Laws.value_reads(_text, _key): + {==} + +def Laws.inside_env(_at, _args): + {==} + +def Laws.ez_runs_bin(_repo, _app, _args): + {==} diff --git a/proofs/TestTallyCounts.bend b/proofs/TestTallyCounts.bend new file mode 100644 index 0000000..b5b372d --- /dev/null +++ b/proofs/TestTallyCounts.bend @@ -0,0 +1,9 @@ +# proofs of laws/TestTallyCounts.bend +import Base +import ../laws/TestTallyCounts.bend as Laws + +def Laws.tally_held(_p, _n): + {==} + +def Laws.tally_failed(_p, _n): + {==} diff --git a/src/add/hub.bend b/src/add/hub.bend index ccc697c..550cc55 100644 --- a/src/add/hub.bend +++ b/src/add/hub.bend @@ -425,23 +425,6 @@ def asks.hub(as: List<&2, W.Ask>, +hub: String) -> Bool: +rest = asks.hub(t, hub) Bool.and(String.eq(ask.hub(h), hub), rest) -# whether a question asks the hub what a name names -def names.one(ask: W.Ask) -> Bool: - match ask: - case W.Name{_nv, _hub}: - True{} - case _: - False{} - -# whether any question does -def names(as: List<&2, W.Ask>) -> Bool: - match as: - case []: - False{} - case h <> t: - +rest = names(t) - Bool.or(names.one(h), rest) - # the last of some lines, `prev` when there are none after it def last.go(ls: List<&2, String>, +prev: String) -> String: match ls: diff --git a/src/add/plan.bend b/src/add/plan.bend index 06b8441..3da56cc 100644 --- a/src/add/plan.bend +++ b/src/add/plan.bend @@ -648,10 +648,6 @@ def qs.v(verdict: Verdict) -> List<&2, Q>: def wants(+world: A.World) -> List<&2, Up.Ask>: asks.of(qs.v(decide(world)), A.from(world)) -# whether every answer the planner needs is in -def answered(+world: A.World) -> Bool: - List.is_empty(&2, Up.Ask, wants(world)) - # the questions still open, or the plan once there are none type Step is Data: Asking{asks: List<&2, Up.Ask>} diff --git a/src/add/relock.bend b/src/add/relock.bend index bc693e6..0109d9c 100644 --- a/src/add/relock.bend +++ b/src/add/relock.bend @@ -226,3 +226,18 @@ def next.add(nx: AP.Next, +world: World) -> Next: # what the interpreter does next on a World def next(+world: World) -> Next: next.add(AP.next(add(world)), world) + +# the World with more of git's answers in the add's World +def more(world: World, rs: List<&2, Up.Reply>) -> World: + World{a, listing, locks} = world + World{A.more(a, rs), listing, locks} + +# the World with more of the hub's answers in the add's World +def more.hub(world: World, rs: List<&2, W.Reply>) -> World: + World{a, listing, locks} = world + World{A.more.hub(a, rs), listing, locks} + +# the World with more of the lock's answers in it +def more.lock(world: World, rs: List<&2, W.Reply>) -> World: + World{a, listing, locks} = world + World{a, listing, List.append(&2, W.Reply, locks, rs)} diff --git a/src/add/run.bend b/src/add/run.bend index 4ddb82f..461ae8f 100644 --- a/src/add/run.bend +++ b/src/add/run.bend @@ -22,23 +22,6 @@ import ../ws/run.bend as WsRun import ./relock.bend as AR import ../ws/relock.bend as Rel -# the World with more answers in it -def more(world: AR.World, rs: List<&2, Up.Reply>) -> AR.World: - AR.World{A.World{args, here, home, ledger, ignore, replies, hubs}, listing, locks} = world - AR.World{A.World{args, here, home, ledger, ignore, List.append(&2, Up.Reply, replies, rs), hubs}, - listing, locks} - -# the World with more of the hub's answers in it -def more.hub(world: AR.World, rs: List<&2, W.Reply>) -> AR.World: - AR.World{A.World{args, here, home, ledger, ignore, replies, hubs}, listing, locks} = world - AR.World{A.World{args, here, home, ledger, ignore, replies, List.append(&2, W.Reply, hubs, rs)}, - listing, locks} - -# the World with more of the lock's answers in it -def more.lock(world: AR.World, rs: List<&2, W.Reply>) -> AR.World: - AR.World{a, listing, locks} = world - AR.World{a, listing, List.append(&2, W.Reply, locks, rs)} - # the planner's step: its questions answered and the loop gone round again, # or its plan run def loop.step(st: AR.Next, +lib: String, world: AR.World, go: AR.World -> IO(Unit)) -> IO(Unit): @@ -46,15 +29,15 @@ def loop.step(st: AR.Next, +lib: String, world: AR.World, go: AR.World -> IO(Uni case AR.AskGit{asks}: do IO: rs : List<&2, Up.Reply> <- Run.answer.ups(lib, asks) - go(more(world, rs)) + go(AR.more(world, rs)) case AR.AskHub{asks}: do IO: rs : List<&2, W.Reply> <- Run.answer.all(lib, asks) - go(more.hub(world, rs)) + go(AR.more.hub(world, rs)) case AR.AskLock{asks}: do IO: rs : List<&2, W.Reply> <- Run.answer.all(lib, asks) - go(more.lock(world, rs)) + go(AR.more.lock(world, rs)) case AR.Planned{pl}: Run.exec.plan(lib, pl) @@ -62,12 +45,17 @@ def loop.step(st: AR.Next, +lib: String, world: AR.World, go: AR.World -> IO(Uni # target and two for a name; the lock after it asks a round per level of the # import graph, as `ez lock` does (`Run.rounds`). This is only a guard against # a planner that keeps asking, and running out of it dies loudly. -def rounds() -> Nat: +def rounds() -> Nat: # noqa: L001 the IO loop's fuel 100000n # the loop, under fuel. Every round adds an answer, since the planner never # asks what the World answers already, so the fuel is only a guard. -def loop(fuel: Nat, +lib: String, +ws: Rel.Ws, +world: AR.World) -> IO(Unit): +def loop( # noqa: L001 IO driver: the interpreter's loop + fuel: Nat, + +lib: String, + +ws: Rel.Ws, + +world: AR.World +) -> IO(Unit): match fuel: case 0n: IO.die(Unit, 1, "ez: ez add kept asking questions") @@ -75,7 +63,12 @@ def loop(fuel: Nat, +lib: String, +ws: Rel.Ws, +world: AR.World) -> IO(Unit): loop.step(Rel.add.next(ws, world), lib, world, w => loop(f, lib, ws, w)) # `ez add [ref] [entry.bend] [--rename NAME]` -def run(+target: String, +ref: String, +entry: String, +rename: String) -> IO(Unit): +def run( # noqa: L001 IO entry of the command + +target: String, + +ref: String, + +entry: String, + +rename: String +) -> IO(Unit): do IO: lib : String <- Run.bend.lib() +pwd : String <- R.exec(["pwd"]) diff --git a/src/add/world.bend b/src/add/world.bend index 6c347e1..fc2f2d0 100644 --- a/src/add/world.bend +++ b/src/add/world.bend @@ -179,3 +179,13 @@ def named(world: World) -> Bool: # the hub the ledger names, which a name and its package are asked of def hub(world: World) -> String: M.hub_of(read(world)) + +# the World with more of git's answers in it +def more(world: World, rs: List<&2, Up.Reply>) -> World: + World{args, here, home, ledger, ignore, replies, hubs} = world + World{args, here, home, ledger, ignore, List.append(&2, Up.Reply, replies, rs), hubs} + +# the World with more of the hub's answers in it +def more.hub(world: World, rs: List<&2, W.Reply>) -> World: + World{args, here, home, ledger, ignore, replies, hubs} = world + World{args, here, home, ledger, ignore, replies, List.append(&2, W.Reply, hubs, rs)} diff --git a/src/check/argv.bend b/src/check/argv.bend new file mode 100644 index 0000000..85847db --- /dev/null +++ b/src/check/argv.bend @@ -0,0 +1,22 @@ +# check/argv: a test server's command line. `IO.args()` answers a `&1` list, +# which can be read once, with the program's own name first; the servers read +# their arguments more than once, so they take a `&2` copy of the ones after +# the name. Shared by check/framing.bend and check/oracle.bend. +import Base + +# a &1 list copied into a &2 one +def copy(xs: List<&1, String>) -> List<&2, String>: + match xs: + case Nil{}: + Nil{} + case Con{h, t}: + h <> copy(t) + +# the arguments after the program's own name. Since bend 2.0.32 `IO.args()` +# starts with the program as it was invoked, as C's argv does. +def args(xs: List<&1, String>) -> List<&2, String>: + match xs: + case Nil{}: + Nil{} + case Con{_h, t}: + copy(t) diff --git a/src/check/body.bend b/src/check/body.bend new file mode 100644 index 0000000..53d6fe2 --- /dev/null +++ b/src/check/body.bend @@ -0,0 +1,493 @@ +# check/body: the body of a publish read the way the hub reads it, for +# check/oracle.bend. bend sends `{"files": {..}, "nonce": N}`; this is the +# reading of that object into the files it carries, their order, their +# manifest and the `0x` name it gives them. It is pure, so a law reaches it +# without the oracle's sockets, and nothing here is part of ez: it is the +# test hub's own reading, and a body it only half understands is refused. +import Base +import ../share/sha.bend as Sha +import ./serve.bend as S + +# a list with its last element gone, the head held back one step so the walk can +# see whether it is looking at the last one. The list comes first because a +# self-call must shrink an argument before it changes one. +def init.put(rest: List<&2, String>, held: String) -> List<&2, String>: + match rest: + case []: + [] + case h2 <> t2: + held <> init.put(t2, h2) + +# every element but the last +def init.of(xs: List<&2, String>) -> List<&2, String>: + match xs: + case []: + [] + case h <> t: + init.put(t, h) + +# the directory a path lies in +def parent.of(path: String) -> String: + String.join(init.of(String.split(path, '/')), "/") + +# one step of the skip, with the head's answer in hand. A recursive call in an +# arm of a `Bool.pick` is not an arm: `Bool.pick` is an ordinary function and +# builds both before it picks one, so the first non-space still cost a walk of +# everything after it. The rest arrives as a thunk and only the arm that wants +# it applies it. +def ws.step(space: Bool, ch: Char, tail: String, rest: Unit -> String) -> String: + match space: + case True{}: + rest(Unit{}) + case False{}: + SCon{ch, tail} + +# the text with its leading whitespace gone +def ws(text: String) -> String: + match text: + case SNil{}: + SNil{} + case SCon{+c, +t}: + ws.step(Char.is_space(c), c, t, _u => ws(t)) + +# a character that had to be there, either consumed or refused +def eat.at(ok: Bool, rest: String) -> Maybe<&2, String>: + match ok: + case True{}: + Some{rest} + case False{}: + None{} + +# the text after a character that must head it, or nothing when it does not +def eat(+text: String, ch: Char) -> Maybe<&2, String>: + eat.at(String.starts_with(text, Char.show(ch)), String.drop(text, 1n)) + +# a hex digit's value, or nothing when the character is not one +def hex.val(+ch: Char) -> Maybe<&2, U32>: + +x = Char.to_u32(ch) + Bool.pick(Maybe<&2, U32>, Char.is_digit(ch), Some{U32.sub(x, 48)}, + Bool.pick(Maybe<&2, U32>, Bool.and(U32.is_ge(x, 97), U32.is_le(x, 102)), + Some{U32.sub(x, 87)}, + Bool.pick(Maybe<&2, U32>, Bool.and(U32.is_ge(x, 65), U32.is_le(x, 70)), + Some{U32.sub(x, 55)}, + None{}))) + +# a code point this oracle will put in a file. A Bend source file is ASCII, and +# a guess at what a higher code point should become would corrupt the file +# rather than fail, so nothing above 0x7f is accepted. +def hex.small(+code: U32) -> Maybe<&2, U32>: + Bool.pick(Maybe<&2, U32>, U32.is_lt(code, 128), Some{code}, None{}) + +# two digit values as one byte +def hex.join(high: Maybe<&2, U32>, low: Maybe<&2, U32>) -> Maybe<&2, U32>: + match high low: + case Some{x} Some{y}: + Some{U32.add(U32.mul(x, 16), y)} + case Some{x} None{}: + None{} + case None{} _m: + None{} + +# the byte two hex characters spell +def hex.pair(high: Maybe<&2, Char>, low: Maybe<&2, Char>) -> Maybe<&2, U32>: + match high low: + case Some{x} Some{y}: + hex.join(hex.val(x), hex.val(y)) + case Some{x} None{}: + None{} + case None{} _m: + None{} + +# two bytes as one code point, the high one first, refused when it is not ASCII +def hex.wide(high: Maybe<&2, U32>, low: Maybe<&2, U32>) -> Maybe<&2, U32>: + match high low: + case Some{x} Some{y}: + hex.small(U32.add(U32.mul(x, 256), y)) + case Some{x} None{}: + None{} + case None{} _m: + None{} + +# one character of a string, decoded from the escape that spelled it, and what +# follows it +type Esc is Data: + EBad{why: String} + EOk{c: Char, rest: String} + +# a `\uXXXX` escape's verdict +def esc.u.fin(code: Maybe<&2, U32>, rest: String) -> Esc: + match code: + case None{}: + EBad{"a unicode escape that is not four hex digits below 0080"} + case Some{x}: + EOk{Chr{x}, rest} + +# the character a `\uXXXX` escape names, read from just after the `u` +def esc.u(+text: String) -> Esc: + esc.u.fin( + hex.wide(hex.pair(String.get(text, 0n), String.get(text, 1n)), + hex.pair(String.get(text, 2n), String.get(text, 3n))), + String.drop(text, 4n)) + +# the character a backslash introduces, read from just after it. An escape this +# oracle does not know is refused, never passed through: a body half understood +# would write a file that is not the one that was published. +def esc.of(text: String) -> Esc: + match text: + case SNil{}: + EBad{"a backslash at the end of the body"} + case SCon{+c, +t}: + Bool.pick(Esc, Char.is_eq(c, '"'), EOk{'"', t}, + Bool.pick(Esc, Char.is_eq(c, '\\'), EOk{'\\', t}, + Bool.pick(Esc, Char.is_eq(c, '/'), EOk{'/', t}, + Bool.pick(Esc, Char.is_eq(c, 'n'), EOk{'\n', t}, + Bool.pick(Esc, Char.is_eq(c, 't'), EOk{'\t', t}, + Bool.pick(Esc, Char.is_eq(c, 'r'), EOk{'\r', t}, + Bool.pick(Esc, Char.is_eq(c, 'b'), EOk{Chr{8}, t}, + Bool.pick(Esc, Char.is_eq(c, 'f'), EOk{Chr{12}, t}, + Bool.pick(Esc, Char.is_eq(c, 'u'), esc.u(t), + EBad{"an escape this oracle does not know"}))))))))) + +# a span of a body with its escapes decoded, or the reason one could not be +type Uns is Data: + UBad{why: String} + UOk{text: String} + +# the next character of a span, whether a backslash spelled it or it stood for +# itself. Both are decided here so the walk below has one recursive call and not +# two, which would make it read the rest of the span twice over at every step. +def uns.step(esc: Bool, ch: Char, tail: String) -> Esc: + match esc: + case True{}: + esc.of(tail) + case False{}: + EOk{ch, tail} + +# what is left of a span after one character of it +def uns.rest(step: Esc) -> String: + match step: + case EBad{_why}: + SNil{} + case EOk{_c, r}: + r + +# a character put in front of what came after it +def uns.push(ch: Char, acc: Uns) -> Uns: + match acc: + case UBad{why}: + UBad{why} + case UOk{text}: + UOk{SCon{ch, text}} + +# one decoded character joined to the rest, an escape that failed carrying its +# reason out past everything after it +def uns.put(step: Esc, acc: Uns) -> Uns: + match step: + case EBad{why}: + UBad{why} + case EOk{c, _rest}: + uns.push(c, acc) + +# a span of a body decoded. The fuel is the span's own length: every step eats +# at least one character, so it cannot run out early, and the walk needs it +# because an escape makes the step shorter than the string it left behind. +def unesc(fuel: Nat, span: String) -> Uns: + match fuel span: + case 0n SNil{}: + UOk{""} + case 0n SCon{_c, _t}: + UBad{"a span longer than the length it was cut to"} + case 1n+f SNil{}: + UOk{""} + case 1n+f SCon{+c, t}: + +e = uns.step(Char.is_eq(c, '\\'), c, t) + uns.put(e, unesc(f, uns.rest(e))) + +# a string literal read out of a body: its text, and what follows its closing +# quote +type Str is Data: + SBad{why: String} + SOk{text: String, rest: String} + +# one step of the measure, with the answer to "does this quote close it" in +# hand. Under a `Bool.pick` the closing quote still cost a walk of the rest of +# the body, and a `Succ` built over every character of it. +def str.end.step(shut: Bool, rest: Unit -> Nat) -> Nat: + match shut: + case True{}: + 0n + case False{}: + rest(Unit{}) + +# how many characters lie before the quote that closes a string literal, or the +# whole length when none does. `esc` says a backslash stood before this +# character, so this one cannot close the literal and cannot escape the next. +def str.end(text: String, +esc: Bool) -> Nat: + match text: + case SNil{}: + 0n + case SCon{+c, t}: + str.end.step(Bool.and(Bool.not(esc), Char.is_eq(c, '"')), + _u => Succ{str.end(t, Bool.and(Bool.not(esc), Char.is_eq(c, '\\')))}) + +# a literal whose span decoded, or the escape that stopped it +def str.done(unescaped: Uns, rest: String) -> Str: + match unescaped: + case UBad{why}: + SBad{why} + case UOk{text}: + SOk{text, rest} + +# a literal that ran off the end of the body is refused rather than taken for +# whatever was left +def str.fin(closed: Bool, unescaped: Uns, rest: String) -> Str: + match closed: + case False{}: + SBad{"a string in the body has no closing quote"} + case True{}: + str.done(unescaped, rest) + +# the span up to the closing quote decoded, and the body past that quote +def str.cut(+len: Nat, +text: String) -> Str: + str.fin(Maybe.is_some(&2, Char, String.get(text, len)), + unesc(len, String.take(text, len)), String.drop(text, Succ{len})) + +# a string literal read from just after its opening quote +def str.of(+text: String) -> Str: + str.cut(str.end(text, False{}), text) + +# one file of a package: where it sits in the package, and what is in it +type Ent is Data: + Ent{path: String, text: String} + +# where a file sits +def ent.path(entry: Ent) -> String: + Ent{p, _t} = entry + p + +# the order the manifest lists files in, which is ascending by path +def ent.le(left: Ent, right: Ent) -> Bool: + String.is_le(ent.path(left), ent.path(right)) + +# the files in the order a manifest names them +def sorted(es: List<&2, Ent>) -> List<&2, Ent>: + List.sort(~Ent, ~ent.le, es) + +# a manifest line: a file's digest, a space, its path +def line.of(entry: Ent) -> String: + Ent{p, t} = entry + Sha.hex(t) ++ " " ++ p ++ "\n" + +# the manifest: a line for each file, in the order they were given +def manifest.of(es: List<&2, Ent>) -> String: + match es: + case []: + "" + case h <> t: + line.of(h) ++ manifest.of(t) + +# the `0x` name a manifest gives its package: the first 32 hex characters of the +# manifest's digest +def hash.of(content: String) -> String: + "0x" ++ String.take(Sha.hex(content), 32n) + +# one `"path": "contents"` pair of the files object, or the end of that object +type Mem is Data: + MBad{why: String} + MEnd{} + MOne{path: String, text: String, more: Bool, rest: String} + +# a comma means another pair follows, a brace ends the object +def mem.tail.at(+path: String, +text: String, +sep: String, +rest: String) -> Mem: + Bool.pick(Mem, String.eq(sep, ","), MOne{path, text, True{}, rest}, + Bool.pick(Mem, String.eq(sep, "}"), MOne{path, text, False{}, rest}, + MBad{"a files entry followed by neither a comma nor a brace"})) + +# what stands after a pair +def mem.tail(path: String, text: String, +after: String) -> Mem: + mem.tail.at(path, text, String.take(after, 1n), String.drop(after, 1n)) + +# a pair whose value has been read +def mem.val(path: String, value: Str) -> Mem: + match value: + case SBad{why}: + MBad{why} + case SOk{text, rest}: + mem.tail(path, text, ws(rest)) + +# a value that is not a string is refused: the files object holds file contents +# and nothing else +def mem.quote.at(path: String, ok: Bool, rest: String) -> Mem: + match ok: + case False{}: + MBad{"a files entry whose value is not a string"} + case True{}: + mem.val(path, str.of(rest)) + +# the quote that opens a value +def mem.quote(path: String, +text: String) -> Mem: + mem.quote.at(path, String.starts_with(text, "\""), String.drop(text, 1n)) + +# the colon between a key and its value +def mem.colon(path: String, after: Maybe<&2, String>) -> Mem: + match after: + case None{}: + MBad{"a files entry with no colon after its key"} + case Some{t}: + mem.quote(path, ws(t)) + +# a pair whose key has been read +def mem.key(key: Str) -> Mem: + match key: + case SBad{why}: + MBad{why} + case SOk{path, rest}: + mem.colon(path, eat(ws(rest), ':')) + +# the quote that opens a key +def mem.one.key(ok: Bool, rest: String) -> Mem: + match ok: + case False{}: + MBad{"a files entry that does not begin with a key"} + case True{}: + mem.key(str.of(rest)) + +# the end of the object, decided. The pair reader hangs off the other arm +# rather than sitting in an argument, so an object that has ended does not +# read a pair out of what follows it. +def mem.one.shut(end: Bool, +text: String) -> Mem: + match end: + case True{}: + MEnd{} + case False{}: + mem.one.key(String.starts_with(text, "\""), String.drop(text, 1n)) + +# either the brace that ends the object or the pair that continues it +def mem.one.at(+text: String) -> Mem: + mem.one.shut(String.starts_with(text, "}"), text) + +# the next pair of the files object, read from wherever the last one left off +def mem.one(text: String) -> Mem: + mem.one.at(ws(text)) + +# every file a body carried, or the reason the body could not be read +type Obj is Data: + OBad{why: String} + OOk{items: List<&2, Ent>} + +# a pair the object goes on past, or the end of it +def obj.rest.if(more: Bool, rest: String) -> String: + match more: + case True{}: + rest + case False{}: + SNil{} + +# where the walk picks up after a pair +def obj.rest(member: Mem) -> String: + match member: + case MBad{_why}: + SNil{} + case MEnd{}: + SNil{} + case MOne{_p, _t, more, rest}: + obj.rest.if(more, rest) + +# one file joined to the ones after it +def obj.cons(entry: Ent, tail: Obj) -> Obj: + match tail: + case OBad{why}: + OBad{why} + case OOk{items}: + OOk{entry <> items} + +# the last pair of an object closes it, and what the walk found past it is not +# part of the body +def obj.put.if(more: Bool, entry: Ent, tail: Obj) -> Obj: + match more: + case True{}: + obj.cons(entry, tail) + case False{}: + OOk{[entry]} + +# a pair joined to whatever the rest of the object gave +def obj.put(member: Mem, tail: Obj) -> Obj: + match member: + case MBad{why}: + OBad{why} + case MEnd{}: + OOk{[]} + case MOne{p, t, more, _rest}: + obj.put.if(more, Ent{p, t}, tail) + +# every pair of the files object. The fuel is the body's length, which no object +# can hold more pairs than. +def obj.go(fuel: Nat, text: String) -> Obj: + match fuel: + case 0n: + OBad{"a files object that never ends"} + case 1n+f: + +m = mem.one(text) + obj.put(m, obj.go(f, obj.rest(m))) + +# the files object itself +def parse.body(fuel: Nat, after: Maybe<&2, String>) -> Obj: + match after: + case None{}: + OBad{"a files key whose value is not an object"} + case Some{t}: + obj.go(fuel, t) + +# the colon after the files key +def parse.colon(fuel: Nat, after: Maybe<&2, String>) -> Obj: + match after: + case None{}: + OBad{"no colon after the files key"} + case Some{t}: + parse.body(fuel, eat(ws(t), '{')) + +# bend sends `{"files": {..}, "nonce": N}` and this oracle reads exactly that. +# A body in another shape is refused rather than searched, because a body it +# only half understood would publish a package that is not the one that was sent. +def parse.name.if(fuel: Nat, ok: Bool, text: String) -> Obj: + match ok: + case False{}: + OBad{"a body whose first key is not files"} + case True{}: + parse.colon(fuel, eat(text, ':')) + +# the body's first key +def parse.name(fuel: Nat, key: Str) -> Obj: + match key: + case SBad{why}: + OBad{why} + case SOk{name, rest}: + parse.name.if(fuel, String.eq(name, "files"), ws(rest)) + +# the quote that opens the body's first key +def parse.quote.at(fuel: Nat, ok: Bool, rest: String) -> Obj: + match ok: + case False{}: + OBad{"a body with no key"} + case True{}: + parse.name(fuel, str.of(rest)) + +# the key that follows the body's opening brace +def parse.quote(fuel: Nat, +text: String) -> Obj: + parse.quote.at(fuel, String.starts_with(text, "\""), String.drop(text, 1n)) + +# the body's opening brace +def parse.open(fuel: Nat, after: Maybe<&2, String>) -> Obj: + match after: + case None{}: + OBad{"a body that is not an object"} + case Some{t}: + parse.quote(fuel, ws(t)) + +# the files a request body carries, as (path, contents) pairs. The fuel counts +# the pairs the body could hold at most: the shortest one a body can spell is +# `"":"",` and no count of them is ever reached, but the walk below reads both +# arms of its choice, so a fuel of the body's whole length would be a walk of +# the body's whole length past its end. +def parse(+body: String) -> Obj: + parse.open(U32.to_nat(U32.add(U32.div(S.size(body), 6), 8)), eat(ws(body), '{')) diff --git a/src/check/framing.bend b/src/check/framing.bend index b51ab0a..f1c6497 100644 --- a/src/check/framing.bend +++ b/src/check/framing.bend @@ -15,6 +15,7 @@ # here is the routes, the chunking, and the accept loop that holds them. import Base import ./serve.bend as S +import ./argv.bend as Argv # the body framed by its length def plain() -> String: @@ -197,24 +198,6 @@ def begin(+port: U32) -> IO(Unit): r : Result<&1, &1, U32 & String, Listener> <- TCP.listen("127.0.0.1", port) begin.at(r, port) -# a &1 list copied into a &2 one. `IO.args()` answers a `&1` list, which can be -# read once, and the argument is read twice here. -def copy(xs: List<&1, String>) -> List<&2, String>: - match xs: - case Nil{}: - Nil{} - case Con{h, t}: - h <> copy(t) - -# the arguments after the program's own name. Since bend 2.0.32 `IO.args()` -# starts with the program as it was invoked, as C's argv does. -def args(xs: List<&1, String>) -> List<&2, String>: - match xs: - case Nil{}: - Nil{} - case Con{_h, t}: - copy(t) - # the command line: a port to serve on def start(as: List<&2, String>) -> IO(Unit): begin(Maybe.default(&2, U32, U32.read(S.at(as, 0n)), 0)) @@ -222,4 +205,4 @@ def start(as: List<&2, String>) -> IO(Unit): def main() -> IO(Unit): do IO: xs : List<&1, String> <- IO.args() - start(args(xs)) + start(Argv.args(xs)) diff --git a/src/check/kit.bend b/src/check/kit.bend index f7cbd27..7d351bc 100644 --- a/src/check/kit.bend +++ b/src/check/kit.bend @@ -3,7 +3,7 @@ import Base # the line a check prints, pass or fail -def say(ok: Bool, name: String, got: String, want: String) -> IO(Unit): +def say(ok: Bool, name: String, got: String, want: String) -> IO(Unit): # noqa: L001 IO: prints a test verdict match ok: case True{}: IO.print("ok " ++ name) @@ -11,5 +11,5 @@ def say(ok: Bool, name: String, got: String, want: String) -> IO(Unit): IO.print("FAIL " ++ name ++ ": got " ++ got ++ ", want " ++ want) # passes when two strings are equal -def eq_str(name: String, +got: String, +want: String) -> IO(Unit): +def eq_str(name: String, +got: String, +want: String) -> IO(Unit): # noqa: L001 IO: prints a test verdict say(String.eq(got, want), name, got, want) diff --git a/src/check/liar.bend b/src/check/liar.bend index 2860208..d6b0d0f 100644 --- a/src/check/liar.bend +++ b/src/check/liar.bend @@ -36,19 +36,24 @@ def text_of(res: Result<&1, &1, U32 & String, String>) -> String: # what the liar says: everything the real bend says, or everything but the one # line that is an answer -def go(mute: Bool) -> IO(Unit): +def lines(mute: Bool) -> List<&2, String>: match mute: case True{}: - do IO: - IO.print(mining(other())) - IO.print(importing(other())) + [mining(other()), importing(other())] case False{}: + [mining(other()), other(), importing(other())] + +# every line said, in order +def say(ls: List<&2, String>) -> IO(Unit): + match ls: + case []: + IO.pure(Unit, Unit{}) + case h <> t: do IO: - IO.print(mining(other())) - IO.print(other()) - IO.print(importing(other())) + IO.print(h) + say(t) def main() -> IO(Unit): do IO: r : Result<&1, &1, U32 & String, String> <- IO.get_env("EZ_LIAR") - go(String.eq(String.trim(text_of(r)), "mute")) + say(lines(String.eq(String.trim(text_of(r)), "mute"))) diff --git a/src/check/oracle.bend b/src/check/oracle.bend index 4c02722..70c0e18 100644 --- a/src/check/oracle.bend +++ b/src/check/oracle.bend @@ -7,8 +7,8 @@ # # bend check/oracle.bend # -# What is here is the hub: the reading of a body is pure and sits above, the -# sockets and the writing are below, and nothing in the upper half touches IO. +# What is here is the hub's sockets and writing. The reading of a body is pure +# and is check/body.bend, where a law can reach it without the sockets. # Reading a request off a socket and writing an answer back are check/serve.bend, # shared with check/framing.bend. Plaintext HTTP only; bend speaks TLS to the # real hub, and check/serve.bend says why a Bend binary cannot. @@ -18,499 +18,16 @@ # One connection is served at a time, each answer states its length and closes # the socket, and the oracle stops of its own accord after a million of them. import Base -import ../share/sha.bend as Sha import ../io/file.bend as F import snap@1.4.0.0/main.bend as R import ./serve.bend as S - -# a list with its last element gone, the head held back one step so the walk can -# see whether it is looking at the last one. The list comes first because a -# self-call must shrink an argument before it changes one. -def init.put(rest: List<&2, String>, held: String) -> List<&2, String>: - match rest: - case []: - [] - case h2 <> t2: - held <> init.put(t2, h2) - -# every element but the last -def init.of(xs: List<&2, String>) -> List<&2, String>: - match xs: - case []: - [] - case h <> t: - init.put(t, h) - -# the directory a path lies in -def parent.of(path: String) -> String: - String.join(init.of(String.split(path, '/')), "/") - -# one step of the skip, with the head's answer in hand. A recursive call in an -# arm of a `Bool.pick` is not an arm: `Bool.pick` is an ordinary function and -# builds both before it picks one, so the first non-space still cost a walk of -# everything after it. The rest arrives as a thunk and only the arm that wants -# it applies it. -def ws.step(space: Bool, ch: Char, tail: String, rest: Unit -> String) -> String: - match space: - case True{}: - rest(Unit{}) - case False{}: - SCon{ch, tail} - -# the text with its leading whitespace gone -def ws(text: String) -> String: - match text: - case SNil{}: - SNil{} - case SCon{+c, +t}: - ws.step(Char.is_space(c), c, t, _u => ws(t)) - -# a character that had to be there, either consumed or refused -def eat.at(ok: Bool, rest: String) -> Maybe<&2, String>: - match ok: - case True{}: - Some{rest} - case False{}: - None{} - -# the text after a character that must head it, or nothing when it does not -def eat(+text: String, ch: Char) -> Maybe<&2, String>: - eat.at(String.starts_with(text, Char.show(ch)), String.drop(text, 1n)) - -# a hex digit's value, or nothing when the character is not one -def hex.val(+ch: Char) -> Maybe<&2, U32>: - +x = Char.to_u32(ch) - Bool.pick(Maybe<&2, U32>, Char.is_digit(ch), Some{U32.sub(x, 48)}, - Bool.pick(Maybe<&2, U32>, Bool.and(U32.is_ge(x, 97), U32.is_le(x, 102)), - Some{U32.sub(x, 87)}, - Bool.pick(Maybe<&2, U32>, Bool.and(U32.is_ge(x, 65), U32.is_le(x, 70)), - Some{U32.sub(x, 55)}, - None{}))) - -# a code point this oracle will put in a file. A Bend source file is ASCII, and -# a guess at what a higher code point should become would corrupt the file -# rather than fail, so nothing above 0x7f is accepted. -def hex.small(+code: U32) -> Maybe<&2, U32>: - Bool.pick(Maybe<&2, U32>, U32.is_lt(code, 128), Some{code}, None{}) - -# two digit values as one byte -def hex.join(high: Maybe<&2, U32>, low: Maybe<&2, U32>) -> Maybe<&2, U32>: - match high low: - case Some{x} Some{y}: - Some{U32.add(U32.mul(x, 16), y)} - case Some{x} None{}: - None{} - case None{} _m: - None{} - -# the byte two hex characters spell -def hex.pair(high: Maybe<&2, Char>, low: Maybe<&2, Char>) -> Maybe<&2, U32>: - match high low: - case Some{x} Some{y}: - hex.join(hex.val(x), hex.val(y)) - case Some{x} None{}: - None{} - case None{} _m: - None{} - -# two bytes as one code point, the high one first, refused when it is not ASCII -def hex.wide(high: Maybe<&2, U32>, low: Maybe<&2, U32>) -> Maybe<&2, U32>: - match high low: - case Some{x} Some{y}: - hex.small(U32.add(U32.mul(x, 256), y)) - case Some{x} None{}: - None{} - case None{} _m: - None{} - -# one character of a string, decoded from the escape that spelled it, and what -# follows it -type Esc is Data: - EBad{why: String} - EOk{c: Char, rest: String} - -# a `\uXXXX` escape's verdict -def esc.u.fin(code: Maybe<&2, U32>, rest: String) -> Esc: - match code: - case None{}: - EBad{"a unicode escape that is not four hex digits below 0080"} - case Some{x}: - EOk{Chr{x}, rest} - -# the character a `\uXXXX` escape names, read from just after the `u` -def esc.u(+text: String) -> Esc: - esc.u.fin( - hex.wide(hex.pair(String.get(text, 0n), String.get(text, 1n)), - hex.pair(String.get(text, 2n), String.get(text, 3n))), - String.drop(text, 4n)) - -# the character a backslash introduces, read from just after it. An escape this -# oracle does not know is refused, never passed through: a body half understood -# would write a file that is not the one that was published. -def esc.of(text: String) -> Esc: - match text: - case SNil{}: - EBad{"a backslash at the end of the body"} - case SCon{+c, +t}: - Bool.pick(Esc, Char.is_eq(c, '"'), EOk{'"', t}, - Bool.pick(Esc, Char.is_eq(c, '\\'), EOk{'\\', t}, - Bool.pick(Esc, Char.is_eq(c, '/'), EOk{'/', t}, - Bool.pick(Esc, Char.is_eq(c, 'n'), EOk{'\n', t}, - Bool.pick(Esc, Char.is_eq(c, 't'), EOk{'\t', t}, - Bool.pick(Esc, Char.is_eq(c, 'r'), EOk{'\r', t}, - Bool.pick(Esc, Char.is_eq(c, 'b'), EOk{Chr{8}, t}, - Bool.pick(Esc, Char.is_eq(c, 'f'), EOk{Chr{12}, t}, - Bool.pick(Esc, Char.is_eq(c, 'u'), esc.u(t), - EBad{"an escape this oracle does not know"}))))))))) - -# a span of a body with its escapes decoded, or the reason one could not be -type Uns is Data: - UBad{why: String} - UOk{text: String} - -# the next character of a span, whether a backslash spelled it or it stood for -# itself. Both are decided here so the walk below has one recursive call and not -# two, which would make it read the rest of the span twice over at every step. -def uns.step(esc: Bool, ch: Char, tail: String) -> Esc: - match esc: - case True{}: - esc.of(tail) - case False{}: - EOk{ch, tail} - -# what is left of a span after one character of it -def uns.rest(step: Esc) -> String: - match step: - case EBad{_why}: - SNil{} - case EOk{_c, r}: - r - -# a character put in front of what came after it -def uns.push(ch: Char, acc: Uns) -> Uns: - match acc: - case UBad{why}: - UBad{why} - case UOk{text}: - UOk{SCon{ch, text}} - -# one decoded character joined to the rest, an escape that failed carrying its -# reason out past everything after it -def uns.put(step: Esc, acc: Uns) -> Uns: - match step: - case EBad{why}: - UBad{why} - case EOk{c, _rest}: - uns.push(c, acc) - -# a span of a body decoded. The fuel is the span's own length: every step eats -# at least one character, so it cannot run out early, and the walk needs it -# because an escape makes the step shorter than the string it left behind. -def unesc(fuel: Nat, span: String) -> Uns: - match fuel span: - case 0n SNil{}: - UOk{""} - case 0n SCon{_c, _t}: - UBad{"a span longer than the length it was cut to"} - case 1n+f SNil{}: - UOk{""} - case 1n+f SCon{+c, t}: - +e = uns.step(Char.is_eq(c, '\\'), c, t) - uns.put(e, unesc(f, uns.rest(e))) - -# a string literal read out of a body: its text, and what follows its closing -# quote -type Str is Data: - SBad{why: String} - SOk{text: String, rest: String} - -# one step of the measure, with the answer to "does this quote close it" in -# hand. Under a `Bool.pick` the closing quote still cost a walk of the rest of -# the body, and a `Succ` built over every character of it. -def str.end.step(shut: Bool, rest: Unit -> Nat) -> Nat: - match shut: - case True{}: - 0n - case False{}: - rest(Unit{}) - -# how many characters lie before the quote that closes a string literal, or the -# whole length when none does. `esc` says a backslash stood before this -# character, so this one cannot close the literal and cannot escape the next. -def str.end(text: String, +esc: Bool) -> Nat: - match text: - case SNil{}: - 0n - case SCon{+c, t}: - str.end.step(Bool.and(Bool.not(esc), Char.is_eq(c, '"')), - _u => Succ{str.end(t, Bool.and(Bool.not(esc), Char.is_eq(c, '\\')))}) - -# a literal whose span decoded, or the escape that stopped it -def str.done(unescaped: Uns, rest: String) -> Str: - match unescaped: - case UBad{why}: - SBad{why} - case UOk{text}: - SOk{text, rest} - -# a literal that ran off the end of the body is refused rather than taken for -# whatever was left -def str.fin(closed: Bool, unescaped: Uns, rest: String) -> Str: - match closed: - case False{}: - SBad{"a string in the body has no closing quote"} - case True{}: - str.done(unescaped, rest) - -# the span up to the closing quote decoded, and the body past that quote -def str.cut(+len: Nat, +text: String) -> Str: - str.fin(Maybe.is_some(&2, Char, String.get(text, len)), - unesc(len, String.take(text, len)), String.drop(text, Succ{len})) - -# a string literal read from just after its opening quote -def str.of(+text: String) -> Str: - str.cut(str.end(text, False{}), text) - -# one file of a package: where it sits in the package, and what is in it -type Ent is Data: - Ent{path: String, text: String} - -# where a file sits -def ent.path(entry: Ent) -> String: - Ent{p, _t} = entry - p - -# the order the manifest lists files in, which is ascending by path -def ent.le(left: Ent, right: Ent) -> Bool: - String.is_le(ent.path(left), ent.path(right)) - -# the files in the order a manifest names them -def sorted(es: List<&2, Ent>) -> List<&2, Ent>: - List.sort(~Ent, ~ent.le, es) - -# a manifest line: a file's digest, a space, its path -def line.of(entry: Ent) -> String: - Ent{p, t} = entry - Sha.hex(t) ++ " " ++ p ++ "\n" - -# the manifest: a line for each file, in the order they were given -def manifest.of(es: List<&2, Ent>) -> String: - match es: - case []: - "" - case h <> t: - line.of(h) ++ manifest.of(t) - -# the `0x` name a manifest gives its package: the first 32 hex characters of the -# manifest's digest -def hash.of(content: String) -> String: - "0x" ++ String.take(Sha.hex(content), 32n) - -# one `"path": "contents"` pair of the files object, or the end of that object -type Mem is Data: - MBad{why: String} - MEnd{} - MOne{path: String, text: String, more: Bool, rest: String} - -# a comma means another pair follows, a brace ends the object -def mem.tail.at(+path: String, +text: String, +sep: String, +rest: String) -> Mem: - Bool.pick(Mem, String.eq(sep, ","), MOne{path, text, True{}, rest}, - Bool.pick(Mem, String.eq(sep, "}"), MOne{path, text, False{}, rest}, - MBad{"a files entry followed by neither a comma nor a brace"})) - -# what stands after a pair -def mem.tail(path: String, text: String, +after: String) -> Mem: - mem.tail.at(path, text, String.take(after, 1n), String.drop(after, 1n)) - -# a pair whose value has been read -def mem.val(path: String, value: Str) -> Mem: - match value: - case SBad{why}: - MBad{why} - case SOk{text, rest}: - mem.tail(path, text, ws(rest)) - -# a value that is not a string is refused: the files object holds file contents -# and nothing else -def mem.quote.at(path: String, ok: Bool, rest: String) -> Mem: - match ok: - case False{}: - MBad{"a files entry whose value is not a string"} - case True{}: - mem.val(path, str.of(rest)) - -# the quote that opens a value -def mem.quote(path: String, +text: String) -> Mem: - mem.quote.at(path, String.starts_with(text, "\""), String.drop(text, 1n)) - -# the colon between a key and its value -def mem.colon(path: String, after: Maybe<&2, String>) -> Mem: - match after: - case None{}: - MBad{"a files entry with no colon after its key"} - case Some{t}: - mem.quote(path, ws(t)) - -# a pair whose key has been read -def mem.key(key: Str) -> Mem: - match key: - case SBad{why}: - MBad{why} - case SOk{path, rest}: - mem.colon(path, eat(ws(rest), ':')) - -# the quote that opens a key -def mem.one.key(ok: Bool, rest: String) -> Mem: - match ok: - case False{}: - MBad{"a files entry that does not begin with a key"} - case True{}: - mem.key(str.of(rest)) - -# the end of the object, decided. The pair reader hangs off the other arm -# rather than sitting in an argument, so an object that has ended does not -# read a pair out of what follows it. -def mem.one.shut(end: Bool, +text: String) -> Mem: - match end: - case True{}: - MEnd{} - case False{}: - mem.one.key(String.starts_with(text, "\""), String.drop(text, 1n)) - -# either the brace that ends the object or the pair that continues it -def mem.one.at(+text: String) -> Mem: - mem.one.shut(String.starts_with(text, "}"), text) - -# the next pair of the files object, read from wherever the last one left off -def mem.one(text: String) -> Mem: - mem.one.at(ws(text)) - -# every file a body carried, or the reason the body could not be read -type Obj is Data: - OBad{why: String} - OOk{items: List<&2, Ent>} - -# a pair the object goes on past, or the end of it -def obj.rest.if(more: Bool, rest: String) -> String: - match more: - case True{}: - rest - case False{}: - SNil{} - -# where the walk picks up after a pair -def obj.rest(member: Mem) -> String: - match member: - case MBad{_why}: - SNil{} - case MEnd{}: - SNil{} - case MOne{_p, _t, more, rest}: - obj.rest.if(more, rest) - -# one file joined to the ones after it -def obj.cons(entry: Ent, tail: Obj) -> Obj: - match tail: - case OBad{why}: - OBad{why} - case OOk{items}: - OOk{entry <> items} - -# the last pair of an object closes it, and what the walk found past it is not -# part of the body -def obj.put.if(more: Bool, entry: Ent, tail: Obj) -> Obj: - match more: - case True{}: - obj.cons(entry, tail) - case False{}: - OOk{[entry]} - -# a pair joined to whatever the rest of the object gave -def obj.put(member: Mem, tail: Obj) -> Obj: - match member: - case MBad{why}: - OBad{why} - case MEnd{}: - OOk{[]} - case MOne{p, t, more, _rest}: - obj.put.if(more, Ent{p, t}, tail) - -# every pair of the files object. The fuel is the body's length, which no object -# can hold more pairs than. -def obj.go(fuel: Nat, text: String) -> Obj: - match fuel: - case 0n: - OBad{"a files object that never ends"} - case 1n+f: - +m = mem.one(text) - obj.put(m, obj.go(f, obj.rest(m))) - -# the files object itself -def parse.body(fuel: Nat, after: Maybe<&2, String>) -> Obj: - match after: - case None{}: - OBad{"a files key whose value is not an object"} - case Some{t}: - obj.go(fuel, t) - -# the colon after the files key -def parse.colon(fuel: Nat, after: Maybe<&2, String>) -> Obj: - match after: - case None{}: - OBad{"no colon after the files key"} - case Some{t}: - parse.body(fuel, eat(ws(t), '{')) - -# bend sends `{"files": {..}, "nonce": N}` and this oracle reads exactly that. -# A body in another shape is refused rather than searched, because a body it -# only half understood would publish a package that is not the one that was sent. -def parse.name.if(fuel: Nat, ok: Bool, text: String) -> Obj: - match ok: - case False{}: - OBad{"a body whose first key is not files"} - case True{}: - parse.colon(fuel, eat(text, ':')) - -# the body's first key -def parse.name(fuel: Nat, key: Str) -> Obj: - match key: - case SBad{why}: - OBad{why} - case SOk{name, rest}: - parse.name.if(fuel, String.eq(name, "files"), ws(rest)) - -# the quote that opens the body's first key -def parse.quote.at(fuel: Nat, ok: Bool, rest: String) -> Obj: - match ok: - case False{}: - OBad{"a body with no key"} - case True{}: - parse.name(fuel, str.of(rest)) - -# the key that follows the body's opening brace -def parse.quote(fuel: Nat, +text: String) -> Obj: - parse.quote.at(fuel, String.starts_with(text, "\""), String.drop(text, 1n)) - -# the body's opening brace -def parse.open(fuel: Nat, after: Maybe<&2, String>) -> Obj: - match after: - case None{}: - OBad{"a body that is not an object"} - case Some{t}: - parse.quote(fuel, ws(t)) - -# the files a request body carries, as (path, contents) pairs. The fuel counts -# the pairs the body could hold at most: the shortest one a body can spell is -# `"":"",` and no count of them is ever reached, but the walk below reads both -# arms of its choice, so a fuel of the body's whole length would be a walk of -# the body's whole length past its end. -def parse(+body: String) -> Obj: - parse.open(U32.to_nat(U32.add(U32.div(S.size(body), 6), 8)), eat(ws(body), '{')) +import ./body.bend as B +import ./argv.bend as Argv # one answer written and the connection closed. Every answer states its length # and says the connection closes, because bend, curl and nix's fetcher all read # a body to the length they were promised and then expect the socket to shut. -def answer(sock: Socket, status: String, body: String) -> IO(Unit): +def answer(sock: Socket, status: String, body: String) -> IO(Unit): # noqa: L001 IO: test server socket write S.answer(sock, S.response(status, body)) # a file that was there, or the 404 for one that was not @@ -556,16 +73,16 @@ def write.after(out: String, at: String, text: String) -> IO(Bool): # so a program is run for it. def write.file(+at: String, text: String) -> IO(Bool): do IO: - out : String <- R.exec(["mkdir", "-p", parent.of(at)]) + out : String <- R.exec(["mkdir", "-p", B.parent.of(at)]) write.after(out, at, text) # one file of a package written under the package's directory -def write.ent(dir: String, entry: Ent) -> IO(Bool): - Ent{p, t} = entry +def write.ent(dir: String, entry: B.Ent) -> IO(Bool): + B.Ent{p, t} = entry write.file(dir ++ "/" ++ p, t) # every file of a package written -def write.all(+dir: String, es: List<&2, Ent>) -> IO(Bool): +def write.all(+dir: String, es: List<&2, B.Ent>) -> IO(Bool): match es: case []: IO.pure(Bool, True{}) @@ -585,7 +102,7 @@ def post.said(sock: Socket, ok: Bool, digest: String) -> IO(Unit): answer(sock, "500 Internal Server Error", "the package could not be written") # the package written out under its hash, then that hash answered -def post.at(sock: Socket, +at: String, digest: String, listing: String, es: List<&2, Ent>) -> IO(Unit): +def post.at(sock: Socket, +at: String, digest: String, listing: String, es: List<&2, B.Ent>) -> IO(Unit): do IO: a : Bool <- write.all(at, es) b : Bool <- write.file(at ++ "/manifest", listing) @@ -593,24 +110,24 @@ def post.at(sock: Socket, +at: String, digest: String, listing: String, es: List # a package's manifest and name, computed from its files the way cli_publish # computes them -def post.write(sock: Socket, dir: String, +es: List<&2, Ent>) -> IO(Unit): - +m = manifest.of(es) - +h = hash.of(m) +def post.write(sock: Socket, dir: String, +es: List<&2, B.Ent>) -> IO(Unit): + +m = B.manifest.of(es) + +h = B.hash.of(m) post.at(sock, dir ++ "/" ++ h, h, m, es) # a POST answered: the package it carried, or the reason its body was refused -def post.go(sock: Socket, dir: String, parsed: Obj) -> IO(Unit): +def post.go(sock: Socket, dir: String, parsed: B.Obj) -> IO(Unit): match parsed: - case OBad{why}: + case B.OBad{why}: answer(sock, "400 Bad Request", why) - case OOk{items}: - post.write(sock, dir, sorted(items)) + case B.OOk{items}: + post.write(sock, dir, B.sorted(items)) # a POST publishes, anything else fetches def serve.pick(post: Bool, sock: Socket, dir: String, +path: String, body: String) -> IO(Unit): match post: case True{}: - post.go(sock, dir, parse(body)) + post.go(sock, dir, B.parse(body)) case False{}: get.pow(String.eq(path, "/pow.json"), sock, dir, path) @@ -633,13 +150,13 @@ def once.at(got: Socket & String, dir: String) -> IO(Unit): serve.msg(sock, dir, S.msg.of(text)) # one connection, read and answered and shut -def once(sock: Socket, dir: String) -> IO(Unit): +def once(sock: Socket, dir: String) -> IO(Unit): # noqa: L001 IO: test server connection do IO: got : Socket & String <- S.request(sock) once.at(got, dir) # a listener with connections left in it, or one that has stopped accepting -type Run is Type: +type Run is Type: # noqa: L001 holds a Listener, which no law reaches RStop{} RGo{l: Listener} @@ -671,7 +188,7 @@ def turn.at( # a run of connections served one at a time, the listener handed back when the # run is up so another can have it -def turn(fuel: Nat, dir: String, listener: Listener) -> IO(Run): +def turn(fuel: Nat, dir: String, listener: Listener) -> IO(Run): # noqa: L001 IO: test server accept loop match fuel: case 0n: IO.pure(Run, RGo{listener}) @@ -691,7 +208,7 @@ def loop.on(state: Run, dir: String, rest: String -> Listener -> IO(Unit)) -> IO # a thousand: the runs the server takes, and the connections each run serves. # Bend has no unbounded loop, so "forever" is a count no test run will reach, a # thousand runs of a thousand connections; a server has no input to size it by. -def thousand() -> Nat: +def thousand() -> Nat: # noqa: L001 fuel for the accept loop, an IO driver 1000n # connections served for as long as the fuel lasts. Bend has no unbounded loop, @@ -699,7 +216,7 @@ def thousand() -> Nat: # connections. The count is nested rather than written out because a Nat is # unary, and the interpreted lane builds the whole of it before it serves # anything. -def loop(fuel: Nat, +dir: String, listener: Listener) -> IO(Unit): +def loop(fuel: Nat, +dir: String, listener: Listener) -> IO(Unit): # noqa: L001 IO: test server accept loop match fuel: case 0n: Listener.close(listener) @@ -726,34 +243,16 @@ def begin.at(bound: Result<&1, &1, U32 & String, Listener>, +dir: String, port: loop(thousand(), dir, l) # the oracle, on a directory and a port -def begin(dir: String, +port: U32) -> IO(Unit): +def begin(dir: String, +port: U32) -> IO(Unit): # noqa: L001 IO: test server listen do IO: r : Result<&1, &1, U32 & String, Listener> <- TCP.listen("127.0.0.1", port) begin.at(r, dir, port) -# a &1 list copied into a &2 one. `IO.args()` answers a `&1` list, which can be -# read once, and the arguments are read twice here. -def copy(xs: List<&1, String>) -> List<&2, String>: - match xs: - case Nil{}: - Nil{} - case Con{h, t}: - h <> copy(t) - -# the arguments after the program's own name. Since bend 2.0.32 `IO.args()` -# starts with the program as it was invoked, as C's argv does. -def args(xs: List<&1, String>) -> List<&2, String>: - match xs: - case Nil{}: - Nil{} - case Con{_h, t}: - copy(t) - # the command line: a directory to serve, and a port to serve it on -def start(+as: List<&2, String>) -> IO(Unit): +def start(+as: List<&2, String>) -> IO(Unit): # noqa: L001 IO driver: the command line begin(S.at(as, 0n), Maybe.default(&2, U32, U32.read(S.at(as, 1n)), 0)) -def main() -> IO(Unit): +def main() -> IO(Unit): # noqa: L001 IO entry point do IO: xs : List<&1, String> <- IO.args() - start(args(xs)) + start(Argv.args(xs)) diff --git a/src/check/out.bend b/src/check/out.bend new file mode 100644 index 0000000..50a871d --- /dev/null +++ b/src/check/out.bend @@ -0,0 +1,114 @@ +# check/out: what an end-to-end test reads out of a program's answer, and the +# command lines it builds. A snap answer is a status line and then what the +# program printed; these pick lines out of the printed part and values out of +# `key = "value"` lines. They are pure, so a law reaches them without the +# programs check/world.bend runs. +import Base +import snap@1.4.0.0/src/answer.bend as A + +# the non-empty strings, which is what a program's output amounts to once its +# trailing newline has been counted as a line +def nonblank(ss: List<&2, String>) -> List<&2, String>: + match ss: + case Nil{}: + Nil{} + case Con{+h, t}: + +more = nonblank(t) + Bool.pick(List<&2, String>, String.is_empty(h), more, h <> more) + +# the first line of a list of them +def first(ls: List<&2, String>) -> String: + match ls: + case []: + "" + case h <> t: + h + +# a one-line answer, without the newline the program ended it with +def line(+out: String) -> String: + first(String.lines(A.text(out))) + +# the last line of a list of them +def last(ls: List<&2, String>) -> String: + match ls: + case []: + "" + case Con{h, Nil{}}: + h + case Con{_h, t}: + last(t) + +# the last thing a program said, which for one that reports as it goes is its +# answer +def tail(+out: String) -> String: + last(String.lines(A.text(out))) + +# the nth of a list of strings, or "" when there is no such one. The list and +# the count are scrutinised together, so the walk needs no helper to branch. +def nth(ls: List<&2, String>, index: Nat) -> String: + match ls index: + case Nil{} _m: + "" + case Con{h, _t} 0n: + h + case Con{_h, t} 1n+p: + nth(t, p) + +# one step of a search for the first line that answers. Both searches here +# want it, so it is stated once. +# +# A recursive call in an arm of a `Bool.pick` is not an arm: `Bool.pick` is an +# ordinary function, so both arms are built before it picks one and the line +# found first still costs a walk of every line after it. The rest of the +# search arrives as a thunk, which is a value, and only the arm that wants it +# applies it. +def first.step(here: Bool, text: String, rest: Unit -> String) -> String: + match here: + case True{}: + text + case False{}: + rest(Unit{}) + +# the first line that starts with this, or "" when none does +def starting(ls: List<&2, String>, +pre: String) -> String: + match ls: + case []: + "" + case +h <> t: + first.step(String.starts_with(h, pre), h, _u => starting(t, pre)) + +# the first line that holds this anywhere in it, or "" when none does +def containing(ls: List<&2, String>, +sub: String) -> String: + match ls: + case []: + "" + case +h <> t: + first.step(String.contains(h, sub), h, _u => containing(t, sub)) + +# the last line that starts with this, or "" when none does. A build's answer +# is the last thing it says, because its log arrives on the same stream. +def starting.last(ls: List<&2, String>, +pre: String, got: String) -> String: + match ls: + case []: + got + case +h <> t: + starting.last(t, pre, Bool.pick(String, String.starts_with(h, pre), h, got)) + +# what a `key = "value"` line holds, which is all ez's own files ever hold +def quoted(+row: String) -> String: + nth(String.split(row, '"'), 1n) + +# the value a text gives a key, over its `key = "value"` lines +def value(+text: String, +key: String) -> String: + quoted(starting(String.lines(text), key)) + +# a command run in a directory, with the gate's BEND_LIB taken away. Base has +# no chdir, so the directory is `env`'s business; and a test that is about +# where packages come from must not inherit the one the gate set for itself. +def inside(at: String, args: List<&2, String>) -> List<&2, String>: + List.append(&2, String, ["env", "-C", at, "-u", "BEND_LIB"], args) + +# `ez` run in a project directory. The binary is the whole of ez, so it is +# started with nothing in front of it but the directory it runs in. +def ez(+repo: String, +app: String, args: List<&2, String>) -> List<&2, String>: + inside(app, List.append(&2, String, [repo ++ "/bin/ez.bin"], args)) diff --git a/src/check/serve.bend b/src/check/serve.bend index bf0576e..bd462a7 100644 --- a/src/check/serve.bend +++ b/src/check/serve.bend @@ -124,7 +124,7 @@ def send.done(sr: Socket & Result<&1, &1, (U32 & String) & List<&2, U32>, Unit>) Socket.close(sock) # one answer written in one go and the connection closed -def answer(sock: Socket, text: String) -> IO(Unit): +def answer(sock: Socket, text: String) -> IO(Unit): # noqa: L001 IO: test server socket write do IO: sr : Socket & Result<&1, &1, (U32 & String) & List<&2, U32>, Unit> <- TCP.send(sock, text) send.done(sr) @@ -169,7 +169,7 @@ def piece.go(fuel: Nat, +width: Nat, sock: Socket, +text: String) -> IO(Socket): # one answer written in pieces of n characters and the connection closed. The # fuel is one piece per character, which no answer can outrun. -def pieces(sock: Socket, width: Nat, +text: String) -> IO(Unit): +def pieces(sock: Socket, width: Nat, +text: String) -> IO(Unit): # noqa: L001 IO: test server socket write do IO: sock2 : Socket <- piece.go(String.length(text), width, sock, text) Socket.close(sock2) @@ -300,9 +300,9 @@ def recv.head(fuel: Nat, sock: Socket, +parts: List<&2, String>) -> IO(Socket & # the reads a request may take, 64 KiB at most each: 256 MiB, past any request # a test sends. How long a request is is not known until its head has arrived, # so the reads cannot be counted up front. -def reads() -> Nat: +def reads() -> Nat: # noqa: L001 fuel for the request read loop, an IO driver 4096n # a whole request read off a socket, and the socket it came on -def request(sock: Socket) -> IO(Socket & String): +def request(sock: Socket) -> IO(Socket & String): # noqa: L001 IO: test server socket read recv.head(reads(), sock, []) diff --git a/src/check/world.bend b/src/check/world.bend index a5c6e48..2e74332 100644 --- a/src/check/world.bend +++ b/src/check/world.bend @@ -7,123 +7,28 @@ # its own. Nothing here goes through a shell. import Base import snap@1.4.0.0/main.bend as R - -# the non-empty strings, which is what a program's output amounts to once its -# trailing newline has been counted as a line -def nonblank(ss: List<&2, String>) -> List<&2, String>: - match ss: - case Nil{}: - Nil{} - case Con{+h, t}: - +more = nonblank(t) - Bool.pick(List<&2, String>, String.is_empty(h), more, h <> more) - -# the first line of a list of them -def first(ls: List<&2, String>) -> String: - match ls: - case []: - "" - case h <> t: - h - -# a one-line answer, without the newline the program ended it with -def line(+out: String) -> String: - first(String.lines(R.text(out))) - -# the last line of a list of them -def last(ls: List<&2, String>) -> String: - match ls: - case []: - "" - case Con{h, Nil{}}: - h - case Con{_h, t}: - last(t) - -# the last thing a program said, which for one that reports as it goes is its -# answer -def tail(+out: String) -> String: - last(String.lines(R.text(out))) - -# the nth of a list of strings, or "" when there is no such one. The list and -# the count are scrutinised together, so the walk needs no helper to branch. -def nth(ls: List<&2, String>, index: Nat) -> String: - match ls index: - case Nil{} _m: - "" - case Con{h, _t} 0n: - h - case Con{_h, t} 1n+p: - nth(t, p) - -# one step of a search for the first line that answers. Both searches here -# want it, so it is stated once. -# -# A recursive call in an arm of a `Bool.pick` is not an arm: `Bool.pick` is an -# ordinary function, so both arms are built before it picks one and the line -# found first still costs a walk of every line after it. The rest of the -# search arrives as a thunk, which is a value, and only the arm that wants it -# applies it. -def first.step(here: Bool, text: String, rest: Unit -> String) -> String: - match here: - case True{}: - text - case False{}: - rest(Unit{}) - -# the first line that starts with this, or "" when none does -def starting(ls: List<&2, String>, +pre: String) -> String: - match ls: - case []: - "" - case +h <> t: - first.step(String.starts_with(h, pre), h, _u => starting(t, pre)) - -# the first line that holds this anywhere in it, or "" when none does -def containing(ls: List<&2, String>, +sub: String) -> String: - match ls: - case []: - "" - case +h <> t: - first.step(String.contains(h, sub), h, _u => containing(t, sub)) - -# the last line that starts with this, or "" when none does. A build's answer -# is the last thing it says, because its log arrives on the same stream. -def starting.last(ls: List<&2, String>, +pre: String, got: String) -> String: - match ls: - case []: - got - case +h <> t: - starting.last(t, pre, Bool.pick(String, String.starts_with(h, pre), h, got)) - -# what a `key = "value"` line holds, which is all ez's own files ever hold -def quoted(+row: String) -> String: - nth(String.split(row, '"'), 1n) - -# the value a text gives a key, over its `key = "value"` lines -def value(+text: String, +key: String) -> String: - quoted(starting(String.lines(text), key)) +import ./out.bend as O # the directory the test is running in, which is the repo `ez test` was run from -def here() -> IO(String): +def here() -> IO(String): # noqa: L001 IO: runs pwd do IO: +out : String <- R.exec(["pwd"]) - return line(out) + return O.line(out) # a fresh empty directory, removed when the test is done with it -def tmp() -> IO(String): +def tmp() -> IO(String): # noqa: L001 IO: runs mktemp do IO: +out : String <- R.exec(["mktemp", "-d"]) - return line(out) + return O.line(out) # a directory, and every directory above it -def mkdir(at: String) -> IO(Unit): +def mkdir(at: String) -> IO(Unit): # noqa: L001 IO: runs mkdir do IO: _o : String <- R.exec(["mkdir", "-p", at]) return Unit{} # a directory and everything under it, gone -def rm(at: String) -> IO(Unit): +def rm(at: String) -> IO(Unit): # noqa: L001 IO: runs rm do IO: _o : String <- R.exec(["rm", "-rf", at]) return Unit{} @@ -131,49 +36,38 @@ def rm(at: String) -> IO(Unit): # a project's files, tracked by a repository of its own. `ez lock` starts from # the `.bend` files git tracks, so a project a test writes is one it has to # add before it locks; staged is enough, since `git ls-files` reads the index. -def track(+at: String) -> IO(Unit): +def track(+at: String) -> IO(Unit): # noqa: L001 IO: runs git do IO: _i : String <- R.exec(["git", "-C", at, "init", "-q"]) _a : String <- R.exec(["git", "-C", at, "add", "-A"]) return Unit{} -# a command run in a directory, with the gate's BEND_LIB taken away. Base has -# no chdir, so the directory is `env`'s business; and a test that is about -# where packages come from must not inherit the one the gate set for itself. -def inside(at: String, args: List<&2, String>) -> List<&2, String>: - List.append(&2, String, ["env", "-C", at, "-u", "BEND_LIB"], args) - -# `ez` run in a project directory. The binary is the whole of ez, so it is -# started with nothing in front of it but the directory it runs in. -def ez(+repo: String, +app: String, args: List<&2, String>) -> List<&2, String>: - inside(app, List.append(&2, String, [repo ++ "/bin/ez.bin"], args)) - # the one file a pattern names, or "" when it names none. The lock's name is # ez's business and not a test's, so a test looks for it rather than spelling # it out. -def only(+at: String, +pat: String) -> IO(String): +def only(+at: String, +pat: String) -> IO(String): # noqa: L001 IO: runs find do IO: +out : String <- R.exec(["find", at, "-maxdepth", "1", "-name", pat]) - return first(nonblank(String.lines(R.text(out)))) + return O.first(O.nonblank(String.lines(R.text(out)))) # a TCP port nothing is listening on, so a stray server elsewhere can never # answer for the one this test started -def port() -> IO(String): +def port() -> IO(String): # noqa: L001 IO: asks the host for a port do IO: +out : String <- R.exec(["python3", "-c", "import socket; s=socket.socket(); s.bind((\"127.0.0.1\", 0)); " ++ "print(s.getsockname()[1]); s.close()"]) - return line(out) + return O.line(out) # a program started and left running, and the pid it was given. `R.exec` waits # for what it runs and reads it to the end, which a server never reaches, so # this is the other effect. -def spawn(args: List<&2, String>) -> IO(String): +def spawn(args: List<&2, String>) -> IO(String): # noqa: L001 IO: starts a program R.start(args) # a started program stopped again, by the pid it was started with, so a test # can never stop anything but what it started -def stop(pid: String) -> IO(Unit): +def stop(pid: String) -> IO(Unit): # noqa: L001 IO: runs kill do IO: _o : String <- R.exec(["kill", pid]) return Unit{} @@ -182,7 +76,7 @@ def stop(pid: String) -> IO(Unit): # the server it just started. A Bend server started on the interpreted lane # takes tens of seconds to reach its first accept, so the count is generous. The verdict and the count are scrutinised # together, so one def covers both endings and nothing recurses mutually. -def until(+args: List<&2, String>, tries: Nat, ok: Bool) -> IO(Bool): +def until(+args: List<&2, String>, tries: Nat, ok: Bool) -> IO(Bool): # noqa: L001 IO: retries a program match tries ok: case _k True{}: IO.pure(Bool, True{}) @@ -195,5 +89,5 @@ def until(+args: List<&2, String>, tries: Nat, ok: Bool) -> IO(Bool): until(args, m, R.ok(out)) # a server answered before the test went on without it -def ready(args: List<&2, String>) -> IO(Bool): +def ready(args: List<&2, String>) -> IO(Bool): # noqa: L001 IO: waits on a program until(args, 600n, False{}) diff --git a/src/doctor/run.bend b/src/doctor/run.bend index 83d48ee..249ba27 100644 --- a/src/doctor/run.bend +++ b/src/doctor/run.bend @@ -53,13 +53,16 @@ def tree.seen(got: Maybe<&2, String>, +dir: String) -> IO(DW.Answer): IO.pure(DW.Answer, DW.Away{}) # a package's tree under the library directory -def tree(+dir: String) -> IO(DW.Answer): +def tree(+dir: String) -> IO(DW.Answer): # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) do IO: m : Maybe<&2, String> <- F.read(dir ++ "/manifest") tree.seen(m, dir) # one question, answered. `lib` is the library directory the planner names. -def answer(+lib: String, ask: DW.Ask) -> IO(DW.Answer): +def answer( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + +lib: String, + ask: DW.Ask +) -> IO(DW.Answer): match ask: case DW.Probe{+name}: do IO: @@ -91,11 +94,6 @@ def answer.all(+lib: String, asks: List<&2, DW.Ask>) -> IO(List<&2, DW.Reply>): rest : List<&2, DW.Reply> <- answer.all(lib, t) return DW.Reply{h, a} <> rest -# the World with more answers in it -def more(world: DW.World, rs: List<&2, DW.Reply>) -> DW.World: - DW.World{cc, lib, ledger, lock, replies} = world - DW.World{cc, lib, ledger, lock, List.append(&2, DW.Reply, replies, rs)} - # the planner's step: its questions answered and the loop gone round again, # or its plan run def loop.step(st: DP.Step, +lib: String, world: DW.World, go: DW.World -> IO(Unit)) -> IO(Unit): @@ -103,7 +101,7 @@ def loop.step(st: DP.Step, +lib: String, world: DW.World, go: DW.World -> IO(Uni case DP.Asking{asks}: do IO: rs : List<&2, DW.Reply> <- answer.all(lib, asks) - go(more(world, rs)) + go(DW.more(world, rs)) case DP.Run{pl}: Run.exec.plan("", pl) @@ -111,13 +109,18 @@ def loop.step(st: DP.Step, +lib: String, world: DW.World, go: DW.World -> IO(Uni # and each other, and the packages they reach are not known until BEND_LIB # has answered, so this is a guard against a planner that keeps asking, not # a limit on a project: running out of it dies loudly. -def rounds() -> Nat: +def rounds() -> Nat: # noqa: L001 the IO loop's fuel 100000n # the loop, under fuel. Every round adds at least one answer, since the # planner never asks what the World answers already, and the lock check asks # about each package at most once. -def loop(fuel: Nat, +lib: String, +back: WsDoc.Back, +world: DW.World) -> IO(Unit): +def loop( # noqa: L001 IO driver: the interpreter's loop + fuel: Nat, + +lib: String, + +back: WsDoc.Back, + +world: DW.World +) -> IO(Unit): match fuel: case 0n: IO.die(Unit, 1, "ez: ez doctor kept asking questions") @@ -125,7 +128,7 @@ def loop(fuel: Nat, +lib: String, +back: WsDoc.Back, +world: DW.World) -> IO(Uni loop.step(WsDoc.step(back, world), lib, world, w => loop(f, lib, back, w)) # a variable's text, "" when it is unset -def var(name: String) -> IO(String): +def var(name: String) -> IO(String): # noqa: L001 IO: reads an environment variable do IO: r : Result<&1, &1, U32 & String, String> <- IO.get_env(name) return Args.text_of(r) @@ -136,7 +139,7 @@ def run.doctored(dd: WsDoc.Doctored, +cc: String, +lib: String, lk: Maybe<&2, St loop(rounds(), DP.lib.at(lib), back, DW.World{cc, lib, led, lk, []}) # `ez doctor`: the toolchain and the project, reported on -def run() -> IO(Unit): +def run() -> IO(Unit): # noqa: L001 IO entry of the command do IO: cc : String <- var("CC") +lib : String <- var("BEND_LIB") diff --git a/src/doctor/world.bend b/src/doctor/world.bend index 3501bd2..9656a34 100644 --- a/src/doctor/world.bend +++ b/src/doctor/world.bend @@ -136,3 +136,8 @@ def heard(rs: List<&2, Reply>, ask: Ask) -> Heard: # the answer the sources question has had on a World, or none yet def sources(world: World) -> Heard: heard(replies(world), Sources{}) + +# the World with more answers in it +def more(world: World, rs: List<&2, Reply>) -> World: + World{cc, lib, ledger, lock, replies} = world + World{cc, lib, ledger, lock, List.append(&2, Reply, replies, rs)} diff --git a/src/ez/app.bend b/src/ez/app.bend index d20773b..75842fa 100644 --- a/src/ez/app.bend +++ b/src/ez/app.bend @@ -49,7 +49,7 @@ def dispatch.lock(+matched: Shake.Matched) -> IO(Unit): # `ez` would. The directories `ez check` and `ez build` write into are made # by those commands once they know they will start bend (`Env.dirs`), so a # refused one leaves the directory as it found it. -def dispatch(sub: L.Sub, +matched: Shake.Matched, +as: List<&2, String>) -> IO(Unit): +def dispatch(sub: L.Sub, +matched: Shake.Matched, +as: List<&2, String>) -> IO(Unit): # noqa: L001 IO driver match sub: case L.CInit{}: Cmd.init(L.get(matched, "name"), L.get(matched, "entry"), @@ -138,10 +138,10 @@ def go.line(+how: L.Line, +as: List<&2, String>) -> IO(Unit): go.end(L.status(how)) # the line taken apart -def go(+app: Shake.Cli, +as: List<&2, String>) -> IO(Unit): +def go(+app: Shake.Cli, +as: List<&2, String>) -> IO(Unit): # noqa: L001 IO driver go.line(L.line(app, Shake.parse(app, Args.argv.of(as))), as) -def main() -> IO(Unit): +def main() -> IO(Unit): # noqa: L001 IO entry point do IO: as : List<&2, String> <- Args.all() go(L.spec(), as) diff --git a/src/ez/cache.bend b/src/ez/cache.bend index 1da64e6..84f6cf2 100644 --- a/src/ez/cache.bend +++ b/src/ez/cache.bend @@ -8,7 +8,7 @@ import ../run/bend.bend as Bend import ../share/env.bend as Env # the toolchain: bend's version and the C compiler it would hand its C to -def tool() -> IO(String): +def tool() -> IO(String): # noqa: L001 IO driver do IO: +out : String <- Bend.version() +cc : String <- Env.var("CC", "cc") diff --git a/src/ez/cmd.bend b/src/ez/cmd.bend index 7233823..c38e714 100644 --- a/src/ez/cmd.bend +++ b/src/ez/cmd.bend @@ -10,6 +10,7 @@ import ../lock/plan.bend as P import ../share/env.bend as Env import ../share/exec.bend as Exec import ../share/cap.bend as Cap +import ../share/capped.bend as Capped import ../share/args.bend as Args import ../ez/ends.bend as E import ../ez/start.bend as S @@ -20,20 +21,16 @@ import ../add/run.bend as AddRun import ../fetch/run.bend as FetchRun import ../pub/run.bend as PubRun -# the ledger's path, which is fixed -def toml() -> String: - "ez.toml" - # what `ez check`, `ez build` or `ez run` does, decided from ez.toml as it is # on disk (`S.start`): a missing or unreadable ledger is refused before # anything is started or made -def started(+ask: S.Ask) -> IO(S.Start): +def started(+ask: S.Ask) -> IO(S.Start): # noqa: L001 IO driver do IO: - t : Maybe<&2, String> <- F.read(toml()) + t : Maybe<&2, String> <- F.read(S.toml()) return S.start(ask, t) # a refusal said, and the command ended on it with exit 1 -def refused(+why: String) -> IO(Unit): +def refused(+why: String) -> IO(Unit): # noqa: L001 IO driver Run.end(P.Refused{why}) # a build's output, printed with a word in front of it for a run the kernel @@ -80,7 +77,7 @@ def check.go(start: S.Start) -> IO(Unit): Run.end(E.checked(out)) # `ez check` -def check() -> IO(Unit): +def check() -> IO(Unit): # noqa: L001 IO driver do IO: start : S.Start <- started(S.Check{}) check.go(start) @@ -99,10 +96,10 @@ def build.go(start: S.Start, +out: String) -> IO(Unit): Cap.warn(cap) +g : String <- Cap.gb() +bin : String <- Cap.run(cap, line) - report.capped(Cap.why(bin, g), bin) + report.capped(Capped.why(bin, g), bin) # `ez build [out]` -def build(+out: String) -> IO(Unit): +def build(+out: String) -> IO(Unit): # noqa: L001 IO driver do IO: start : S.Start <- started(S.Build{out}) build.go(start, out) @@ -128,7 +125,7 @@ def run.go(+start: S.Start) -> IO(Unit): # `ez run [args..]`: the entry run by bend, which checks it first, with every # word after `run`, as `cargo run` runs a project's binary -def run(as: List<&2, String>) -> IO(Unit): +def run(as: List<&2, String>) -> IO(Unit): # noqa: L001 IO driver do IO: +start : S.Start <- started(S.Run{as}) run.go(start) @@ -137,7 +134,7 @@ def run(as: List<&2, String>) -> IO(Unit): # the hub once the tree is clean and git tracks every file of the package, # and bend's answer checked against the `0x` name ez computed. A ledger that # is missing or does not parse is refused, and nothing is sent. -def publish() -> IO(Unit): +def publish() -> IO(Unit): # noqa: L001 IO driver PubRun.run() # `ez lock`, plain or `--upgrade`, is the planner's @@ -157,17 +154,17 @@ def lock.go(flags: P.Outcome, up: Bool, +name: String) -> IO(Unit): Run.end(P.Refused{why}) # `ez lock` and `ez lock --upgrade [--package NAME]` -def lock(+up: Bool, +name: String) -> IO(Unit): +def lock(+up: Bool, +name: String) -> IO(Unit): # noqa: L001 IO driver lock.go(E.lock.flags(up, name), up, name) # `ez fetch`, planned by fetch/plan.bend: BEND_LIB filled from the lock, with # nothing re-resolved, and nothing laid unless every package checks -def fetch() -> IO(Unit): +def fetch() -> IO(Unit): # noqa: L001 IO driver FetchRun.run() # `ez init [name] [entry.bend] [--description TEXT]`: a new project, planned # by init/plan.bend -def init(+asked: String, +file: String, +desc: String) -> IO(Unit): +def init(+asked: String, +file: String, +desc: String) -> IO(Unit): # noqa: L001 IO driver InitRun.run(asked, file, desc) # `ez add [rev|tag|branch] [entry.bend] [--rename NAME]`, planned by @@ -175,9 +172,9 @@ def init(+asked: String, +file: String, +desc: String) -> IO(Unit): # shapes `ez tool run` takes, or a hub package's `@` # (add/hub.bend). A missing ref is resolved, and a missing entry is read from # the checkout, or from the package the hub serves. -def add(+target: String, +ref: String, +entry: String, +rename: String) -> IO(Unit): +def add(+target: String, +ref: String, +entry: String, +rename: String) -> IO(Unit): # noqa: L001 IO driver AddRun.run(target, ref, entry, rename) # `ez remove `, planned by remove/plan.bend -def remove(+name: String) -> IO(Unit): +def remove(+name: String) -> IO(Unit): # noqa: L001 IO driver RemoveRun.run(name) diff --git a/src/ez/prove.bend b/src/ez/prove.bend index 7d4936f..59f2cc8 100644 --- a/src/ez/prove.bend +++ b/src/ez/prove.bend @@ -19,8 +19,10 @@ import snap@1.4.0.0/main.bend as R import ../share/args.bend as Args import ../share/env.bend as Env import ../share/cap.bend as Cap +import ../share/capped.bend as Capped import ./quiet.bend as Q import ./sorted.bend as Sort +import ./verdict.bend as V import ../ez/ends.bend as E import ../lock/run.bend as Run @@ -43,7 +45,7 @@ def find.proofs() -> IO(List<&2, String>): # means the effect works it out: cores, but never more of them than the memory # cap divides the machine into, since each one of these may claim the whole # cap. EZ_JOBS overrides it for a machine that knows better. -def width() -> IO(String): +def width() -> IO(String): # noqa: L001 IO driver Env.var("EZ_JOBS", "") # a directory emptied and made again, so nothing a run reads was written by the @@ -58,74 +60,29 @@ def fresh.dir(+at: String) -> IO(Unit): def out.at() -> String: ".ez/run/prove" -# the first line of a run's output -def head.of(ls: List<&2, String>) -> String: - match ls: - case []: - "" - case h <> _t: - h - -# the first line of some text -def head(text: String) -> String: - head.of(String.lines(text)) - -# the one line a proof passes on -def verdict() -> String: - "ALL PROOFS CHECK" - -# every line of a block, indented under the line that introduces it -def indent.go(ls: List<&2, String>) -> List<&2, String>: - match ls: - case []: - [] - case h <> t: - (" " ++ h ++ "\n") <> indent.go(t) - -# a block of text, indented -def indent(text: String) -> String: - String.concat(indent.go(String.lines(text))) - -# a `bend` on one file, inside the memory cap and with this project's BEND_LIB -# set for it -def cmd(cap: Bool, +gigs: String, +at: String, +path: String) -> List<&2, String>: - Cap.argv(cap, gigs, at, ["bend", path]) - -# every file's command, in the tree's order -def cmds(ps: List<&2, String>, +cap: Bool, +gigs: String, +at: String) -> List<&2, List<&2, String>>: - match ps: - case Nil{}: - Nil{} - case Con{+h, t}: - cmd(cap, gigs, at, h) <> cmds(t, cap, gigs, at) - # one proof's line. A proof that held says so in one line; one that did not # names itself and then prints what bend said, since that is where the law # that failed is named. -def say(ok: Bool, +path: String, +text: String) -> IO(Unit): +def say(ok: Bool, +path: String, +text: String) -> IO(Unit): # noqa: L001 IO driver match ok: case True{}: IO.print("ok: " ++ path) case False{}: - IO.write("FAIL: " ++ path ++ "\n" ++ indent(text)) - -# one more proof counted, and one more pass when it held -def count(ok: Bool, +passed: Nat) -> Nat: - Bool.pick(Nat, ok, (1n + passed : Nat), passed) + IO.write("FAIL: " ++ path ++ "\n" ++ V.indent(text)) # one proof against its answer: the run's first line, with a memory kill turned # into a sentence in front of what it printed -def one(+path: String, +gigs: String, +output: String, +passed: Nat) -> IO(Nat): +def one(+path: String, +gigs: String, +output: String, +passed: Nat) -> IO(Nat): # noqa: L001 IO driver do IO: +text : String <- IO.pure(String, R.text(output)) - +ok : Bool <- IO.pure(Bool, String.eq(head(text), verdict())) - say(ok, path, Cap.why(output, gigs) ++ Q.chomp(text)) - return count(ok, passed) + +ok : Bool <- IO.pure(Bool, V.passed(text)) + say(ok, path, Capped.why(output, gigs) ++ Q.chomp(text)) + return V.count(ok, passed) # every proof the answers ran out before. The two lists are the same length by # construction and this should never have one to report, but the alternative # to saying so is a green count over fewer proofs than the tree holds. -def short(ps: List<&2, String>) -> IO(Unit): +def short(ps: List<&2, String>) -> IO(Unit): # noqa: L001 IO driver match ps: case Nil{}: IO.pure(Unit, Unit{}) @@ -135,7 +92,7 @@ def short(ps: List<&2, String>) -> IO(Unit): short(t) # every proof, in the tree's order however the run happened to interleave -def report(ps: List<&2, String>, as: List<&2, String>, +gigs: String, +passed: Nat) -> IO(Nat): +def report(ps: List<&2, String>, as: List<&2, String>, +gigs: String, +passed: Nat) -> IO(Nat): # noqa: L001 IO driver match ps as: case Con{+h, pt} Con{+x, xt}: do IO: @@ -149,7 +106,7 @@ def report(ps: List<&2, String>, as: List<&2, String>, +gigs: String, +passed: N # the count, and the exit status it implies. A run's last line is its verdict, # and anything that failed fails the command (`E.counted`), or a script around # it learns nothing. -def done(+passed: Nat, +total: Nat) -> IO(Unit): +def done(+passed: Nat, +total: Nat) -> IO(Unit): # noqa: L001 IO driver do IO: IO.print("PASS: " ++ Nat.show(passed) ++ " / " ++ Nat.show(total)) Run.end(E.counted(passed, total)) @@ -157,7 +114,7 @@ def done(+passed: Nat, +total: Nat) -> IO(Unit): # `ez prove`: every PROOF.bend in the tree, run at once and reported in the # tree's order. There is no budget: a proof that takes long is still a proof, # and one that never finishes is stopped by whatever runs the gate. -def run() -> IO(Unit): +def run() -> IO(Unit): # noqa: L001 IO driver do IO: +cap : Bool <- Cap.ok() Cap.warn(cap) @@ -166,6 +123,6 @@ def run() -> IO(Unit): +jobs : String <- width() +ps : List<&2, String> <- find.proofs() fresh.dir(out.at()) - as : List<&2, String> <- R.par(cmds(ps, cap, g, at), jobs, g, out.at(), "0") + as : List<&2, String> <- R.par(V.cmds(ps, cap, g, at), jobs, g, out.at(), "0") +passed : Nat <- report(ps, as, g, 0n) done(passed, List.length(&2, String, ps)) diff --git a/src/ez/start.bend b/src/ez/start.bend index f7bcc4f..71af8e2 100644 --- a/src/ez/start.bend +++ b/src/ez/start.bend @@ -32,9 +32,13 @@ def does(ask: Ask) -> String: case Run{_as}: "ez run runs a project's entry" +# the ledger's path, which is fixed +def toml() -> String: + "ez.toml" + # why a directory with no ez.toml is refused def none(ask: Ask) -> String: - "ez: no ez.toml here; " ++ does(ask) ++ ", and ez init makes one" + "ez: no " ++ toml() ++ " here; " ++ does(ask) ++ ", and ez init makes one" # the entry file a ledger names, or "main.bend" when it names none def entry.or(+file: String) -> String: diff --git a/src/ez/test.bend b/src/ez/test.bend index 5f30bcb..f5e33e3 100644 --- a/src/ez/test.bend +++ b/src/ez/test.bend @@ -16,46 +16,30 @@ import ./quiet.bend as Q import ./clock.bend as Clock import ./timer.bend as Timer import ./prove.bend as P +import ./verdict.bend as V import ../ez/ends.bend as E import ../lock/run.bend as Run -# how many comparisons were made, and how many of them held -type Tally is Data: - Tally{pass: Nat, total: Nat} - # a comparison that held says nothing. One that did not prints both sides in # full: a diff is real work in Bend, and for a handful of short lines the pair # reads better than one would. -def say(ok: Bool, name: String, want: String, got: String) -> IO(Unit): +def say(ok: Bool, name: String, want: String, got: String) -> IO(Unit): # noqa: L001 IO driver match ok: case True{}: IO.pure(Unit, Unit{}) case False{}: - IO.write("FAIL: " ++ name ++ "\n expected:\n" ++ P.indent(want) ++ - " observed:\n" ++ P.indent(got)) - -# one more comparison, and one more pass when it held -def tally.go(ok: Bool, passed: Nat, total: Nat) -> Tally: - match ok: - case True{}: - Tally{(1n + passed : Nat), (1n + total : Nat)} - case False{}: - Tally{passed, (1n + total : Nat)} - -# the tally with this comparison's verdict in it -def tally(ok: Bool, score: Tally) -> Tally: - Tally{p, n} = score - tally.go(ok, p, n) + IO.write("FAIL: " ++ name ++ "\n expected:\n" ++ V.indent(want) ++ + " observed:\n" ++ V.indent(got)) # what was wanted against what happened, reported and counted -def check(name: String, +wanted: String, +got: String, score: Tally) -> IO(Tally): - do IO: +def check(name: String, +wanted: String, +got: String, score: V.Tally) -> IO(V.Tally): # noqa: L001 IO driver + do IO: say(String.eq(wanted, got), name, wanted, got) - return tally(String.eq(wanted, got), score) + return V.tally(String.eq(wanted, got), score) # one test against its own trailer -def one(+path: String, +output: String, score: Tally) -> IO(Tally): - do IO: +def one(+path: String, +output: String, score: V.Tally) -> IO(V.Tally): # noqa: L001 IO driver + do IO: src : Maybe<&2, String> <- F.read(path) check(path, G.trailer(F.text_of(src)), Q.filter(R.text(output)), score) @@ -63,27 +47,27 @@ def one(+path: String, +output: String, score: Tally) -> IO(Tally): # construction and this should never have one to report, but the alternative to # saying so is a green count over fewer tests than the tree holds, which is the # worst answer a gate can give. -def short(ts: List<&2, String>, score: Tally) -> IO(Tally): +def short(ts: List<&2, String>, score: V.Tally) -> IO(V.Tally): # noqa: L001 IO driver match ts: case Nil{}: - IO.pure(Tally, score) + IO.pure(V.Tally, score) case Con{_h, rest}: - do IO: + do IO: IO.write("FAIL: the run planned a test it never got an answer for\n") - short(rest, tally(False{}, score)) + short(rest, V.tally(False{}, score)) # every test, in the tree's order however the run happened to interleave -def report(ts: List<&2, String>, as: List<&2, String>, score: Tally) -> IO(Tally): +def report(ts: List<&2, String>, as: List<&2, String>, score: V.Tally) -> IO(V.Tally): # noqa: L001 IO driver match ts as: case Con{+h, tt} Con{+x, xt}: - do IO: - next : Tally <- one(h, x, score) + do IO: + next : V.Tally <- one(h, x, score) report(tt, xt, next) case rest _x: short(rest, score) # every test file -def find() -> IO(List<&2, String>): +def find() -> IO(List<&2, String>): # noqa: L001 IO driver P.find.at("*/tests/*.bend", "-path") # the count, and the exit status it implies. The reminder sits above the count @@ -95,8 +79,8 @@ def done.go(+passed: Nat, +total: Nat) -> IO(Unit): Run.end(E.counted(passed, total)) # what a whole run amounts to -def done(score: Tally) -> IO(Unit): - Tally{p, n} = score +def done(score: V.Tally) -> IO(Unit): # noqa: L001 IO driver + V.Tally{p, n} = score done.go(p, n) # where the jobs of a run write what they print @@ -106,22 +90,22 @@ def out.at() -> String: # the budget checked the way every other thing here is checked. A run that # overran is a run that failed, and it says so in the count rather than merely # taking a long time. -def budget(late: Bool, +secs: String, score: Tally) -> IO(Tally): +def budget(late: Bool, +secs: String, score: V.Tally) -> IO(V.Tally): # noqa: L001 IO driver match late: case False{}: - IO.pure(Tally, score) + IO.pure(V.Tally, score) case True{}: - do IO: + do IO: IO.write("FAIL: the gate took longer than its " ++ secs ++ " second " ++ "budget\n set EZ_DEADLINE higher if this tree honestly needs " ++ "longer, or to 0 to stop asking\n") - return tally(False{}, score) + return V.tally(False{}, score) # `ez test`: every test in the tree, all of them at once. Nothing here is # ordered against anything else, since each test has its own scratch directory # and port, and the report is still walked in the tree's order whatever order # the jobs finished in. -def run() -> IO(Unit): +def run() -> IO(Unit): # noqa: L001 IO driver do IO: +cap : Bool <- Cap.ok() Cap.warn(cap) @@ -133,8 +117,8 @@ def run() -> IO(Unit): +ts : List<&2, String> <- find() P.fresh.dir(out.at()) +by : String <- IO.pure(String, Clock.by.effect(deadline)) - as : List<&2, String> <- R.par(P.cmds(ts, cap, g, at), jobs, g, out.at(), by) - every : Tally <- report(ts, as, Tally{0n, 0n}) + as : List<&2, String> <- R.par(V.cmds(ts, cap, g, at), jobs, g, out.at(), by) + every : V.Tally <- report(ts, as, V.Tally{0n, 0n}) +late : Bool <- Timer.over(deadline) - kept : Tally <- budget(late, secs, every) + kept : V.Tally <- budget(late, secs, every) done(kept) diff --git a/src/ez/timer.bend b/src/ez/timer.bend index 9cf987d..9df1f8a 100644 --- a/src/ez/timer.bend +++ b/src/ez/timer.bend @@ -11,12 +11,12 @@ import ./clock.bend as Clock # how many seconds a whole run may take. Five minutes is what the gate is held # to; a tree that honestly needs longer says so in EZ_DEADLINE, and "0" turns # the budget off for someone bisecting with the cache cold. -def seconds() -> IO(String): +def seconds() -> IO(String): # noqa: L001 IO driver Env.var("EZ_DEADLINE", "300") # the second the run must be finished by, worked out once at the start so that # nothing later has to add anything up -def by(+secs: String) -> IO(String): +def by(+secs: String) -> IO(String): # noqa: L001 IO driver do IO: +out : String <- R.exec(["date", "-d", "+" ++ secs ++ " seconds", "+%s"]) return String.trim(R.text(out)) @@ -30,7 +30,7 @@ def start.go(keep: Bool, +secs: String) -> IO(String): by(secs) # the deadline, or "" when there is none -def start(+secs: String) -> IO(String): +def start(+secs: String) -> IO(String): # noqa: L001 IO driver start.go(Clock.on(secs), secs) # whether the deadline has gone by @@ -51,5 +51,5 @@ def over.go(none: Bool, +deadline: String) -> IO(Bool): # whether the run has outstayed its budget, which a run with no budget never # has -def over(+deadline: String) -> IO(Bool): +def over(+deadline: String) -> IO(Bool): # noqa: L001 IO driver over.go(String.is_empty(deadline), deadline) diff --git a/src/ez/verdict.bend b/src/ez/verdict.bend new file mode 100644 index 0000000..b741374 --- /dev/null +++ b/src/ez/verdict.bend @@ -0,0 +1,75 @@ +# ez/verdict: what the two runners read off a run. `ez prove` passes a proof +# whose first line is exactly `ALL PROOFS CHECK` and counts it; `ez test` +# tallies each comparison of a run with its trailer. Both runners print what +# failed indented under the line that names it. All of it is pure, so what a +# run is judged and counted as is a law (laws/ProofPassesOnVerdictLine.bend, +# laws/TestTallyCounts.bend); running `bend` and reading its output is the +# runners' (ez/prove.bend, ez/test.bend). +import Base +import ../share/capped.bend as Capped + +# the first line of a run's output +def head.of(ls: List<&2, String>) -> String: + match ls: + case []: + "" + case h <> _t: + h + +# the first line of some text +def head(text: String) -> String: + head.of(String.lines(text)) + +# the one line a proof passes on +def verdict() -> String: + "ALL PROOFS CHECK" + +# every line of a block, indented under the line that introduces it +def indent.go(ls: List<&2, String>) -> List<&2, String>: + match ls: + case []: + [] + case h <> t: + (" " ++ h ++ "\n") <> indent.go(t) + +# a block of text, indented +def indent(text: String) -> String: + String.concat(indent.go(String.lines(text))) + +# whether a run passed the proof gate: its first line is the verdict, exactly +def passed(text: String) -> Bool: + String.eq(head(text), verdict()) + +# one more proof counted, and one more pass when it held +def count(ok: Bool, +passed: Nat) -> Nat: + Bool.pick(Nat, ok, (1n + passed : Nat), passed) + +# how many comparisons were made, and how many of them held +type Tally is Data: + Tally{pass: Nat, total: Nat} + +# one more comparison, and one more pass when it held +def tally.go(ok: Bool, passed: Nat, total: Nat) -> Tally: + match ok: + case True{}: + Tally{(1n + passed : Nat), (1n + total : Nat)} + case False{}: + Tally{passed, (1n + total : Nat)} + +# the tally with this comparison's verdict in it +def tally(ok: Bool, score: Tally) -> Tally: + Tally{p, n} = score + tally.go(ok, p, n) + +# a `bend` on one file, inside the memory cap and with this project's BEND_LIB +# set for it +def cmd(cap: Bool, +gigs: String, +at: String, +path: String) -> List<&2, String>: + Capped.argv(cap, gigs, at, ["bend", path]) + +# every file's command, in the tree's order +def cmds(ps: List<&2, String>, +cap: Bool, +gigs: String, +at: String) -> List<&2, List<&2, String>>: + match ps: + case Nil{}: + Nil{} + case Con{+h, t}: + cmd(cap, gigs, at, h) <> cmds(t, cap, gigs, at) diff --git a/src/fetch/run.bend b/src/fetch/run.bend index 4dd85e9..063b8dd 100644 --- a/src/fetch/run.bend +++ b/src/fetch/run.bend @@ -33,14 +33,20 @@ def laid.seen(got: Maybe<&2, String>, +dir: String) -> IO(W.Answer): # the tree under BEND_LIB for a hash, as its manifest names it, or a miss # when there is none -def laid(+lib: String, +hash: String) -> IO(W.Answer): +def laid( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + +lib: String, + +hash: String +) -> IO(W.Answer): +dir = lib ++ "/" ++ hash do IO: m : Maybe<&2, String> <- F.read(dir ++ "/manifest") laid.seen(m, dir) # one question, answered -def answer(+lib: String, ask: FW.Ask) -> IO(FW.Answer): +def answer( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + +lib: String, + ask: FW.Ask +) -> IO(FW.Answer): match ask: case FW.Laid{hash}: do IO: @@ -74,11 +80,6 @@ def answer.all(+lib: String, asks: List<&2, FW.Ask>) -> IO(List<&2, FW.Reply>): rest : List<&2, FW.Reply> <- answer.all(lib, t) return FW.Reply{h, a} <> rest -# the World with more answers in it -def more(world: FW.World, rs: List<&2, FW.Reply>) -> FW.World: - FW.World{here, ledger, lock, replies} = world - FW.World{here, ledger, lock, List.append(&2, FW.Reply, replies, rs)} - # the planner's step: its questions answered and the loop gone round again, # or its plan run def loop.step(st: FP.Step, +lib: String, world: FW.World, go: FW.World -> IO(Unit)) -> IO(Unit): @@ -86,7 +87,7 @@ def loop.step(st: FP.Step, +lib: String, world: FW.World, go: FW.World -> IO(Uni case FP.Asking{asks}: do IO: rs : List<&2, FW.Reply> <- answer.all(lib, asks) - go(more(world, rs)) + go(FW.more(world, rs)) case FP.Run{pl}: Run.exec.plan(lib, pl) @@ -94,13 +95,13 @@ def loop.step(st: FP.Step, +lib: String, world: FW.World, go: FW.World -> IO(Uni # under BEND_LIB and for its fetch, and a round asks for every package at # once, so this is only a guard against a planner that keeps asking, and # running out of it dies loudly. -def rounds() -> Nat: +def rounds() -> Nat: # noqa: L001 the IO loop's fuel 10n # the loop, under fuel. A package asks at most twice, for its tree under # BEND_LIB and for its fetch, and every round answers what it asked, so the # fuel is only a guard. -def loop(fuel: Nat, +lib: String, +world: FW.World) -> IO(Unit): +def loop(fuel: Nat, +lib: String, +world: FW.World) -> IO(Unit): # noqa: L001 IO driver: the interpreter's loop match fuel: case 0n: IO.die(Unit, 1, "ez: ez fetch kept asking questions") @@ -108,20 +109,20 @@ def loop(fuel: Nat, +lib: String, +world: FW.World) -> IO(Unit): loop.step(FP.step(world), lib, world, w => loop(f, lib, w)) # a file of the project, read -def at(+here: String, +file: String) -> String: +def at(+here: String, +file: String) -> String: # noqa: L001 the IO driver's read path here ++ "/" ++ file # BEND_LIB `lib` filled from the lock of the project in `here`, which is # where every relative path in the lock is read from. `ez tool` fills a # tool's cache from its checkout's lock this way. -def fill(+here: String, +lib: String) -> IO(Unit): +def fill(+here: String, +lib: String) -> IO(Unit): # noqa: L001 IO entry of the command do IO: led : Maybe<&2, String> <- F.read(at(here, FW.toml())) lk : Maybe<&2, String> <- F.read(at(here, FW.lockfile())) loop(rounds(), lib, FW.World{here, Maybe.is_some(&2, String, led), lk, []}) # `ez fetch`: BEND_LIB filled from the lock of the project ez runs in -def run() -> IO(Unit): +def run() -> IO(Unit): # noqa: L001 IO entry of the command do IO: lib : String <- Run.bend.lib() +pwd : String <- R.exec(["pwd"]) diff --git a/src/fetch/world.bend b/src/fetch/world.bend index 5575afc..f13da0d 100644 --- a/src/fetch/world.bend +++ b/src/fetch/world.bend @@ -144,3 +144,8 @@ def look(rs: List<&2, Reply>, +want: String) -> Heard: # the answer to a question, or none yet def heard(rs: List<&2, Reply>, ask: Ask) -> Heard: look(rs, key(ask)) + +# the World with more answers in it +def more(world: World, rs: List<&2, Reply>) -> World: + World{here, ledger, lock, replies} = world + World{here, ledger, lock, List.append(&2, Reply, replies, rs)} diff --git a/src/git/exec.bend b/src/git/exec.bend index 468e582..33af763 100644 --- a/src/git/exec.bend +++ b/src/git/exec.bend @@ -13,7 +13,7 @@ import ../share/spin.bend as Spin import ./git.bend as G # a git command that failed stops the command, with whatever git said -def ran(ok: Bool, what: String, text: String) -> IO(Unit): +def ran(ok: Bool, what: String, text: String) -> IO(Unit): # noqa: L001 IO: runs git match ok: case True{}: IO.pure(Unit, Unit{}) @@ -21,7 +21,7 @@ def ran(ok: Bool, what: String, text: String) -> IO(Unit): IO.die(Unit, 1, "ez: git " ++ what ++ ": " ++ text) # one git command -def run(what: String, args: List<&2, String>) -> IO(Unit): +def run(what: String, args: List<&2, String>) -> IO(Unit): # noqa: L001 IO: runs git do IO: +out : String <- R.exec(args) ran(R.ok(out), what, R.text(out)) @@ -32,7 +32,7 @@ def run(what: String, args: List<&2, String>) -> IO(Unit): # else: a fetch from inside its work directory, and `ls-remote` from the top # of any repository around it. Every git command here that is handed a source # is handed this instead. -def anchored(+url: String) -> IO(String): +def anchored(+url: String) -> IO(String): # noqa: L001 IO: runs git do IO: +here : String <- R.exec(["pwd"]) return P.anchor(String.trim(R.text(here)), url) @@ -50,18 +50,18 @@ def clone.say(+work: String, +url: String, +rev: String, +msg: String) -> IO(Uni Spin.done(s) # a shallow clone of one commit into `work`, with a line saying what it fetches -def clone(+work: String, +url: String, +rev: String) -> IO(Unit): +def clone(+work: String, +url: String, +rev: String) -> IO(Unit): # noqa: L001 IO: runs git clone.say(work, url, rev, Say.git.fetch(url)) # the NAR hash nix rebuilds the checkout by. `fetchgit` hashes the working # tree with its `.git` taken off, so that is what is weighed here and the # caller strips `.git` before asking. Computed in Bend; nix is not required. -def nar(+work: String) -> IO(String): +def nar(+work: String) -> IO(String): # noqa: L001 IO: runs git Dump.path(work) # the NAR hash of one commit. The checkout is weighed the way `fetchgit` # weighs it, then removed. Nothing is laid under BEND_LIB. -def weigh(+url: String, +rev: String) -> IO(String): +def weigh(+url: String, +rev: String) -> IO(String): # noqa: L001 IO: runs git +work = ".ez/weigh-" ++ rev do IO: _rm : String <- R.exec(["rm", "-rf", work]) @@ -93,7 +93,7 @@ def remote.said(ok: Bool, +url: String, +text: String) -> IO(G.Tip): # HEAD on the remote: the commit the default branch tips, and that branch's # name. `--symref` is what puts the branch on the line in front of the commit. -def remote(+url: String) -> IO(G.Tip): +def remote(+url: String) -> IO(G.Tip): # noqa: L001 IO: runs git do IO: +from : String <- anchored(url) +out : String <- R.exec(["git", "ls-remote", "--symref", from, "HEAD"]) diff --git a/src/git/git.bend b/src/git/git.bend index a2b3826..a4e0450 100644 --- a/src/git/git.bend +++ b/src/git/git.bend @@ -161,7 +161,7 @@ def exact(+rs: List<&2, Row>, +ref: String) -> String: or_else(named(rs, "refs/tags/" ++ ref), named(rs, "refs/heads/" ++ ref))) # that commit is the tip of -type Tip is Data: +type Tip is Data: # noqa: L001 git/exec's IO remote answers it; no pure def makes one Tip{rev: String, branch: String} # the rest of the scan only when this row said nothing. A recursive call diff --git a/src/hub/get.bend b/src/hub/get.bend index 1676c0f..fb9f497 100644 --- a/src/hub/get.bend +++ b/src/hub/get.bend @@ -62,11 +62,11 @@ def get.loc(loc: Url.Loc, url: String) -> IO(String): get.scheme(String.eq(scheme, "file"), url, path) # the body at a url: "0" and the body, or a status and the reason -def get(+url: String) -> IO(String): +def get(+url: String) -> IO(String): # noqa: L001 IO: fetches over HTTP get.loc(Http.parse_url(url), url) # the file at a url, accepted only when it hashes to `want` -def fetch(+url: String, want: String) -> IO(Hub.Got): +def fetch(+url: String, want: String) -> IO(Hub.Got): # noqa: L001 IO: fetches over HTTP do IO: +out : String <- get(url) return Hub.judge(R.ok(out), Hub.matches(want, R.text(out)), url, R.text(out)) diff --git a/src/hub/hub.bend b/src/hub/hub.bend index 2adfadd..cf9d0e2 100644 --- a/src/hub/hub.bend +++ b/src/hub/hub.bend @@ -55,11 +55,3 @@ def judge(ok: Bool, good: Bool, url: String, body: String) -> Got: Miss{url ++ ": " ++ body} case True{}: judge.hash(good, url, body) - -# a fetch's outcome on one line -def show(got: Got) -> String: - match got: - case Miss{why}: - "miss " ++ why - case Have{body}: - "have " ++ body diff --git a/src/init/run.bend b/src/init/run.bend index b5e7d00..ebca4f4 100644 --- a/src/init/run.bend +++ b/src/init/run.bend @@ -10,7 +10,7 @@ import ../lock/run.bend as Run import ./plan.bend as IP # `ez init [name] [entry.bend] [--description TEXT]` -def run(+name: String, +file: String, +desc: String) -> IO(Unit): +def run(+name: String, +file: String, +desc: String) -> IO(Unit): # noqa: L001 IO entry of the command do IO: lib : String <- Run.bend.lib() led : Maybe<&2, String> <- F.read(IP.toml()) diff --git a/src/io/file.bend b/src/io/file.bend index c7798a6..5cdcac0 100644 --- a/src/io/file.bend +++ b/src/io/file.bend @@ -98,7 +98,7 @@ def read.opened(res: Result<&1, &1, U32 & String, File>) -> IO(Maybe<&2, String> return Some{text} # a file's text, or None when it cannot be opened -def read(path: String) -> IO(Maybe<&2, String>): +def read(path: String) -> IO(Maybe<&2, String>): # noqa: L001 IO: the file effect do IO>: r : Result<&1, &1, U32 & String, File> <- File.open(path, "r") read.opened(r) @@ -129,7 +129,7 @@ def write.opened(res: Result<&1, &1, U32 & String, File>, text: String) -> IO(Bo write.done(w) # a file replaced with this text; False when it could not be written -def write(path: String, text: String) -> IO(Bool): +def write(path: String, text: String) -> IO(Bool): # noqa: L001 IO: the file effect do IO: r : Result<&1, &1, U32 & String, File> <- File.open(path, "w") write.opened(r, text) diff --git a/src/lock/plan.bend b/src/lock/plan.bend index 812f4de..63bf0b6 100644 --- a/src/lock/plan.bend +++ b/src/lock/plan.bend @@ -301,11 +301,6 @@ def packs.named(+js: List<&2, W.Judged>, ps: List<&2, L.Pack>) -> List<&2, Strin List.append(&2, String, L.kids.named(pack.srcs(look(js, L.pack.hash(h)))), packs.named(js, t)) -# every name a lock needs resolved: those the committed sources import, then -# those the packages it reaches import -def needed(listing: W.Listing, +js: List<&2, W.Judged>, ps: List<&2, L.Pack>) -> List<&2, String>: - List.append(&2, String, roots.named(listing.files(listing)), packs.named(js, ps)) - # why a plain lock cannot copy the ledger's tool pins, or "" when it can. A # ledger that does not parse is refused here too. def need.why(ledger: M.Read) -> String: @@ -1220,10 +1215,6 @@ def wants.up(world: W.World) -> List<&2, Up.Ask>: W.World{args, +ledger, _listing, _replies, ups} = world Up.next.asks(W.next(args, ledger, ups)) -# whether the upgrade has every answer it needs -def answered(world: W.World) -> Bool: - List.is_empty(&2, Up.Ask, wants.up(world)) - # each of the upgrade's questions, with the question git is asked for it def queries(+here: String, as: List<&2, Up.Ask>) -> List<&2, Query>: match as: @@ -1411,3 +1402,13 @@ def step(world: W.World) -> Step: W.World{+args, +ledger, +listing, +replies, ups} = world +nx = W.next(args, ledger, ups) step.ups(Up.next.asks(nx), W.here.of(args), nx, listing, replies) + +# where a place is +def place.dir(+lib: String, pl: Place) -> String: + match pl: + case Committed{}: + ".ez/lib" + case Cache{}: + lib + case Under{dir}: + dir ++ "/.ez/lib" diff --git a/src/lock/run.bend b/src/lock/run.bend index 48e2f57..3e78541 100644 --- a/src/lock/run.bend +++ b/src/lock/run.bend @@ -21,6 +21,7 @@ import ../git/git.bend as Git import ../git/exec.bend as GX import ../pkg/pkg.bend as K import ../pkg/path.bend as P +import ../share/args.bend as Args import ../share/say.bend as Say import ../share/spin.bend as Spin import ./lock.bend as L @@ -52,15 +53,6 @@ def bend.lib() -> IO(String): r : Result<&1, &1, U32 & String, String> <- IO.get_env("BEND_LIB") return lib.or(String.trim(env.text(r))) -# the non-empty lines -def nonempty(ss: List<&2, String>) -> List<&2, String>: - match ss: - case []: - [] - case +h <> t: - +more = nonempty(t) - Bool.pick(List<&2, String>, String.is_empty(h), more, h <> more) - # the ledger's text, or None when there is no ez.toml def read.ledger() -> IO(Maybe<&2, String>): F.read("ez.toml") @@ -77,11 +69,14 @@ def read.all(ps: List<&2, String>) -> IO(List<&2, W.Source>): return W.Source{h, F.text_of(m)} <> rest # what git listed, or why it could not -def listed(ok: Bool, +text: String) -> IO(W.Listing): +def listed( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + ok: Bool, + +text: String +) -> IO(W.Listing): match ok: case True{}: do IO: - fs : List<&2, W.Source> <- read.all(nonempty(String.lines(text))) + fs : List<&2, W.Source> <- read.all(Args.nonempty(String.lines(text))) return W.Listed{fs} case False{}: IO.pure(W.Listing, W.Unlisted{ @@ -99,18 +94,6 @@ def read.listing() -> IO(W.Listing): # --------------------------------------------------------------------------- # answering one question -# every text a fetch answered, or the first miss -def gots(+how: W.How, +manifest: String, gs: List<&2, Web.Got>, acc: List<&2, String>) -> W.Answer: - match gs: - case []: - W.Got{how, manifest, List.reverse(&2, String, acc)} - case g <> t: - match g: - case Web.Miss{why}: - W.Miss{"ez: " ++ why} - case Web.Have{body}: - gots(how, manifest, t, body <> acc) - # every file of a hub package, fetched and checked against its sum def hub.all(+hub: String, +hash: String, fs: List<&2, K.Item>) -> IO(List<&2, Web.Got>): match fs: @@ -130,7 +113,7 @@ def hub.got(got: Web.Got, +hub: String, +hash: String) -> IO(W.Answer): case Web.Have{+body}: do IO: gs : List<&2, Web.Got> <- hub.all(hub, hash, L.manifest.files(String.lines(body))) - return gots(W.Served{}, body, gs, []) + return W.got.all(W.Served{}, body, gs, []) # a hub package: its manifest, then every file it names def answer.hub(+hub: String, +hash: String) -> IO(W.Answer): @@ -256,22 +239,13 @@ def answer.pkg(+lib: String, +hash: String, src: L.Src, +hub: String) -> IO(W.An case L.Member{path, _entry}: IO.pure(W.Answer, W.Miss{"ez: the workspace member at " ++ path ++ " was not walked"}) -# what the hub says a name names, as it said it; the planner reads the hash -# out of it -def said(got: Web.Got) -> W.Answer: - match got: - case Web.Miss{why}: - W.Miss{"ez: " ++ why} - case Web.Have{body}: - W.Said{body} - # a name, asked of the hub once: `GET /name/` def answer.name(+hub: String, +nv: String) -> IO(W.Answer): do IO: +s : Say.Spin <- Spin.hold(Say.dep.hub(nv)) g : Web.Got <- Net.fetch(hub ++ "/name/" ++ nv, "") Spin.done(s) - return said(g) + return W.got.said(g) # the lock being rewritten, "" when there is none def answer.lock() -> IO(W.Answer): @@ -280,7 +254,10 @@ def answer.lock() -> IO(W.Answer): return W.Locked{F.text_of(m)} # one question, answered -def answer(+lib: String, ask: W.Ask) -> IO(W.Answer): +def answer( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + +lib: String, + ask: W.Ask +) -> IO(W.Answer): match ask: case W.Pkg{+hash, src, +hub}: answer.pkg(lib, hash, src, hub) @@ -418,7 +395,7 @@ def found.all(ps: List<&2, String>) -> IO(Up.Answer): def found.listed(ok: Bool, +text: String) -> IO(Up.Answer): match ok: case True{}: - found.all(nonempty(String.lines(text))) + found.all(Args.nonempty(String.lines(text))) case False{}: IO.pure(Up.Answer, Up.Miss{"ez: could not list sources: " ++ String.trim(text)}) @@ -483,7 +460,7 @@ def whole.listed(ok: Bool, +work: String, +nar: String, +text: String) -> IO(Up. match ok: case True{}: do IO: - fs : List<&2, K.Source> <- whole.read(work, nonempty(String.lines(text))) + fs : List<&2, K.Source> <- whole.read(work, Args.nonempty(String.lines(text))) _rm : String <- R.exec(["rm", "-rf", work]) return Up.Cloned{nar, fs} case False{}: @@ -572,17 +549,11 @@ def answer.queries(+lib: String, qs: List<&2, Plan.Query>) -> IO(List<&2, Up.Rep rest : List<&2, Up.Reply> <- answer.queries(lib, t) return Up.Reply{ask, a} <> rest -# the World with more answers in it -def more(world: W.World, rs: List<&2, W.Reply>, us: List<&2, Up.Reply>) -> W.World: - W.World{args, ledger, listing, replies, ups} = world - W.World{args, ledger, listing, List.append(&2, W.Reply, replies, rs), - List.append(&2, Up.Reply, ups, us)} - # --------------------------------------------------------------------------- # executing a plan # a write that did not happen stops the command -def wrote(ok: Bool, +at: String) -> IO(Unit): +def wrote(ok: Bool, +at: String) -> IO(Unit): # noqa: L001 IO: runs the plan (trusted in src/ez/app.bend) match ok: case True{}: IO.pure(Unit, Unit{}) @@ -590,7 +561,7 @@ def wrote(ok: Bool, +at: String) -> IO(Unit): IO.die(Unit, 1, "ez: " ++ at ++ " could not be written") # one file written, with the directory it goes in made first -def write(+at: String, text: String) -> IO(Unit): +def write(+at: String, text: String) -> IO(Unit): # noqa: L001 IO: runs the plan (trusted in src/ez/app.bend) do IO: _mk : String <- R.exec(["mkdir", "-p", P.dir(at)]) ok : Bool <- F.write(at, text) @@ -606,23 +577,13 @@ def lay.all(+dir: String, fs: List<&2, W.Source>) -> IO(Unit): write(dir ++ "/" ++ at, text) lay.all(dir, t) -# where a place is -def place(+lib: String, pl: Plan.Place) -> String: - match pl: - case Plan.Committed{}: - ".ez/lib" - case Plan.Cache{}: - lib - case Plan.Under{dir}: - dir ++ "/.ez/lib" - # one effect -def exec(+lib: String, effect: Plan.Effect) -> IO(Unit): +def exec(+lib: String, effect: Plan.Effect) -> IO(Unit): # noqa: L001 IO: runs the plan (trusted in src/ez/app.bend) match effect: case Plan.Write{at, text}: write(at, text) case Plan.Lay{pl, hash, fs}: - +dir = place(lib, pl) ++ "/" ++ hash + +dir = Plan.place.dir(lib, pl) ++ "/" ++ hash do IO: _rm : String <- R.exec(["rm", "-rf", dir]) lay.all(dir, fs) @@ -657,7 +618,7 @@ def end.at(zero: Bool, +code: U32, +why: String) -> IO(Unit): # how the command ends: with the status the planner gave its outcome # (`Plan.status`, laws/ExitStatusSaysFailure.bend), and the reason when it # refused -def end(+outcome: Plan.Outcome) -> IO(Unit): +def end(+outcome: Plan.Outcome) -> IO(Unit): # noqa: L001 IO: runs the plan (trusted in src/ez/app.bend) +code = Plan.status(outcome) end.at(U32.is_eq(code, 0), code, Plan.why(outcome)) @@ -680,7 +641,7 @@ def loop.step(st: Plan.Step, +lib: String, back: WsUp.Back, world: W.World, go: rs : List<&2, W.Reply> <- answer.all(lib, asks) us : List<&2, Up.Reply> <- answer.queries(lib, ups) ns : List<&2, W.Reply> <- answer.all(lib, names) - go(more(world, List.append(&2, W.Reply, rs, ns), us)) + go(W.more(world, List.append(&2, W.Reply, rs, ns), us)) case Plan.Run{_pl}: exec.plan(lib, WsUp.plan(back, world)) @@ -690,12 +651,17 @@ def loop.step(st: Plan.Step, +lib: String, back: WsUp.Back, world: W.World, go: # against a planner that keeps asking, not a limit on a lock: running out of # it dies loudly. The walk inside each round takes its fuel from its inputs # (`Plan.walk.fuel`). -def rounds() -> Nat: +def rounds() -> Nat: # noqa: L001 the IO loop's fuel 100000n # the loop, under fuel. Every round adds at least one answer, since the # planner never asks what the World answers already. -def loop(fuel: Nat, +lib: String, +back: WsUp.Back, +world: W.World) -> IO(Unit): +def loop( # noqa: L001 IO driver: the interpreter's loop + fuel: Nat, + +lib: String, + +back: WsUp.Back, + +world: W.World +) -> IO(Unit): match fuel: case 0n: IO.die(Unit, 1, "ez: the lock kept asking questions") @@ -723,7 +689,10 @@ def settle.one(rp: W.Reply, +lib: String) -> IO(W.Reply): settle.seen(got, ask, answer, lib, hash) # every member's package, so -def settle(rs: List<&2, W.Reply>, +lib: String) -> IO(List<&2, W.Reply>): +def settle( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + rs: List<&2, W.Reply>, + +lib: String +) -> IO(List<&2, W.Reply>): match rs: case []: IO.pure(List<&2, W.Reply>, []) @@ -744,7 +713,7 @@ def run.planned(pd: WsRun.Planned, +lib: String, up: Bool, only: String, here: S # `ez lock` and `ez lock --upgrade [--package only]`: the directory it runs # in, the ledger and the listing read, every question answered, and the plan # run -def run(up: Bool, +only: String) -> IO(Unit): +def run(up: Bool, +only: String) -> IO(Unit): # noqa: L001 IO entry of the command do IO: IO.print_err(Say.resolving()) lib : String <- bend.lib() diff --git a/src/lock/world.bend b/src/lock/world.bend index 9f10efa..10598b8 100644 --- a/src/lock/world.bend +++ b/src/lock/world.bend @@ -591,3 +591,30 @@ def reclone(world: World) -> World: World{+args, +ledger, listing, replies, +ups} = world World{args, ledger, listing, reclone.all(next.origins(next(args, ledger, ups)), replies), ups} + +# the World with more answers in it +def more(world: World, rs: List<&2, Reply>, us: List<&2, Up.Reply>) -> World: + World{args, ledger, listing, replies, ups} = world + World{args, ledger, listing, List.append(&2, Reply, replies, rs), + List.append(&2, Up.Reply, ups, us)} + +# what the hub says a name names, as it said it; the planner reads the hash +# out of it +def got.said(got: Web.Got) -> Answer: + match got: + case Web.Miss{why}: + Miss{"ez: " ++ why} + case Web.Have{body}: + Said{body} + +# every text a fetch answered, or the first miss +def got.all(+how: How, +manifest: String, gs: List<&2, Web.Got>, acc: List<&2, String>) -> Answer: + match gs: + case []: + Got{how, manifest, List.reverse(&2, String, acc)} + case g <> t: + match g: + case Web.Miss{why}: + Miss{"ez: " ++ why} + case Web.Have{body}: + got.all(how, manifest, t, body <> acc) diff --git a/src/pkg/pkg.bend b/src/pkg/pkg.bend index ffe2c56..71a26be 100644 --- a/src/pkg/pkg.bend +++ b/src/pkg/pkg.bend @@ -1581,13 +1581,6 @@ def resumed.fuel(+tree: Tree, +st: State) -> Nat: State{_seen, _out, _stop, queue} = st (List.length(&2, Task, queue) + walk.fuel(fs) : Nat) -# how many files the walk from disk may ask for. It asks for one file a round -# and cannot know how many the checkout holds until it has read them, so this -# is a guard against a walk that keeps asking, not a limit on a package: a -# package of more files than this is refused, never hashed short. -def asks() -> Nat: - 100000n - # the walk over what has been read so far, and each file it asks for read # and handed back, until it no longer asks def pkg.ask(fuel: Nat, +top: String, +entry: String, +eb: String, +tree: Tree, +st: State) -> IO(Pkg): @@ -1602,12 +1595,16 @@ def pkg.ask(fuel: Nat, +top: String, +entry: String, +eb: String, +tree: Tree, + # the package an entry would be published as, walked over its checkout: the # entry and every file the walk reaches are paths from `top`, read from disk # as the walk asks for them. An import that climbs above `top` is refused. +# The walk may ask for 100000 files. It asks for one file a round and cannot +# know how many the checkout holds until it has read them, so that is a guard +# against a walk that keeps asking, not a limit on a package: a package of +# more files than this is refused, never hashed short. def walk.io(+top: String, +entry: String) -> IO(Pkg): - pkg.ask(asks(), top, entry, P.base(entry), Tree{False{}, [], []}, + pkg.ask(100000n, top, entry, P.base(entry), Tree{False{}, [], []}, start(entry)) # the package an entry of a checkout would be published as -def pkg_in(+top: String, +entry: String) -> IO(Pkg): +def pkg_in(+top: String, +entry: String) -> IO(Pkg): # noqa: L001 IO driver walk.io(top, P.norm(entry)) # an entry named from the working directory is walked over the working @@ -1623,7 +1620,7 @@ def pkg.from(abs: Bool, +entry: String) -> IO(Pkg): # every foreign body beside them, and the hash over their manifest. A relative # entry's checkout is the working directory, which is the project a command # runs in. -def pkg_of(+entry: String) -> IO(Pkg): +def pkg_of(+entry: String) -> IO(Pkg): # noqa: L001 IO driver pkg.from(String.starts_with(entry, "/"), entry) # the hash that names a package diff --git a/src/pub/run.bend b/src/pub/run.bend index 55f69d0..9076ef2 100644 --- a/src/pub/run.bend +++ b/src/pub/run.bend @@ -32,11 +32,14 @@ import ./plan.bend as PP import ../ws/run.bend as WsRun # what a program printed, and whether it exited 0 -def ran(+out: String) -> PW.Answer: +def ran(+out: String) -> PW.Answer: # noqa: L001 reads snap's exec output, which no law can import PW.Ran{R.ok(out), R.text(out)} # one question, answered -def answer(+lib: String, ask: PW.Ask) -> IO(PW.Answer): +def answer( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + +lib: String, + ask: PW.Ask +) -> IO(PW.Answer): match ask: case PW.ToolAsk{q}: do IO: @@ -72,11 +75,6 @@ def answer.all(+lib: String, asks: List<&2, PW.Ask>) -> IO(List<&2, PW.Reply>): rest : List<&2, PW.Reply> <- answer.all(lib, t) return PW.Reply{h, a} <> rest -# the World with more answers in it -def more(world: PW.World, rs: List<&2, PW.Reply>) -> PW.World: - PW.World{here, ledger, replies} = world - PW.World{here, ledger, List.append(&2, PW.Reply, replies, rs)} - # the planner's step: its questions answered and the loop gone round again, # or its plan run def loop.step(st: PP.Step, +lib: String, world: PW.World, go: PW.World -> IO(Unit)) -> IO(Unit): @@ -84,7 +82,7 @@ def loop.step(st: PP.Step, +lib: String, world: PW.World, go: PW.World -> IO(Uni case PP.Asking{asks}: do IO: rs : List<&2, PW.Reply> <- answer.all(lib, asks) - go(more(world, rs)) + go(PW.more(world, rs)) case PP.Run{pl}: Run.exec.plan(lib, pl) @@ -92,12 +90,12 @@ def loop.step(st: PP.Step, +lib: String, world: PW.World, go: PW.World -> IO(Uni # know how many the package holds until it has read them, so this is a guard # against a planner that keeps asking, not a limit on a package: running out # of it dies loudly. -def rounds() -> Nat: +def rounds() -> Nat: # noqa: L001 the IO loop's fuel 100000n # the loop, under fuel. The walk asks for one file a round, so the fuel is a # guard against a planner that keeps asking, not a limit on a package. -def loop(fuel: Nat, +lib: String, +world: PW.World) -> IO(Unit): +def loop(fuel: Nat, +lib: String, +world: PW.World) -> IO(Unit): # noqa: L001 IO driver: the interpreter's loop match fuel: case 0n: IO.die(Unit, 1, "ez: ez publish kept asking questions") @@ -106,7 +104,7 @@ def loop(fuel: Nat, +lib: String, +world: PW.World) -> IO(Unit): # `ez publish`: the package the project's ledger names, checked, sent, and # the hash bend answered checked against ez's own -def run() -> IO(Unit): +def run() -> IO(Unit): # noqa: L001 IO entry of the command do IO: lib : String <- Env.lib() +pwd : String <- R.exec(["pwd"]) diff --git a/src/pub/world.bend b/src/pub/world.bend index 09bcbe7..1806aa4 100644 --- a/src/pub/world.bend +++ b/src/pub/world.bend @@ -43,10 +43,6 @@ type World is Data: def toml() -> String: "ez.toml" -# the lock's path, which is fixed -def lockfile() -> String: - "ez.lock.toml" - # the directory the project is in def here(world: World) -> String: World{h, _ledger, _replies} = world @@ -104,3 +100,8 @@ def look(rs: List<&2, Reply>, +want: String) -> Heard: # the answer to a question, or none yet def heard(+world: World, ask: Ask) -> Heard: look(replies(world), key(ask)) + +# the World with more answers in it +def more(world: World, rs: List<&2, Reply>) -> World: + World{here, ledger, replies} = world + World{here, ledger, List.append(&2, Reply, replies, rs)} diff --git a/src/remove/relock.bend b/src/remove/relock.bend index 1b574b5..0a24d6f 100644 --- a/src/remove/relock.bend +++ b/src/remove/relock.bend @@ -77,3 +77,8 @@ def next.made(refused: Bool, +world: World) -> Next: # what the interpreter does next on a World def next(+world: World) -> Next: next.made(R.refuses(RP.plan(remove(world))), world) + +# the World with more of the lock's answers in it +def more(world: World, rs: List<&2, W.Reply>) -> World: + World{r, here, listing, locks} = world + World{r, here, listing, List.append(&2, W.Reply, locks, rs)} diff --git a/src/remove/run.bend b/src/remove/run.bend index b7ad6cd..7de201d 100644 --- a/src/remove/run.bend +++ b/src/remove/run.bend @@ -17,11 +17,6 @@ import ./relock.bend as RR import ../ws/relock.bend as Rel import ../ws/run.bend as WsRun -# the World with more of the lock's answers in it -def more(world: RR.World, rs: List<&2, W.Reply>) -> RR.World: - RR.World{r, here, listing, locks} = world - RR.World{r, here, listing, List.append(&2, W.Reply, locks, rs)} - # the planner's step: its questions answered and the loop gone round again, # or its plan run def loop.step(st: RR.Next, +lib: String, world: RR.World, go: RR.World -> IO(Unit)) -> IO(Unit): @@ -29,13 +24,18 @@ def loop.step(st: RR.Next, +lib: String, world: RR.World, go: RR.World -> IO(Uni case RR.AskLock{asks}: do IO: rs : List<&2, W.Reply> <- Run.answer.all(lib, asks) - go(more(world, rs)) + go(RR.more(world, rs)) case RR.Planned{pl}: Run.exec.plan(lib, pl) # the loop, under fuel. Every round adds an answer, since the lock never asks # what the World answers already, so the fuel (`Run.rounds`) is only a guard. -def loop(fuel: Nat, +lib: String, +ws: Rel.Ws, +world: RR.World) -> IO(Unit): +def loop( # noqa: L001 IO driver: the interpreter's loop + fuel: Nat, + +lib: String, + +ws: Rel.Ws, + +world: RR.World +) -> IO(Unit): match fuel: case 0n: IO.die(Unit, 1, "ez: ez remove kept asking questions") @@ -43,7 +43,7 @@ def loop(fuel: Nat, +lib: String, +ws: Rel.Ws, +world: RR.World) -> IO(Unit): loop.step(Rel.remove.next(ws, world), lib, world, w => loop(f, lib, ws, w)) # `ez remove ` -def run(+name: String) -> IO(Unit): +def run(+name: String) -> IO(Unit): # noqa: L001 IO entry of the command do IO: lib : String <- Run.bend.lib() +pwd : String <- R.exec(["pwd"]) diff --git a/src/run/bend.bend b/src/run/bend.bend index 68e3921..d2fe59e 100644 --- a/src/run/bend.bend +++ b/src/run/bend.bend @@ -22,7 +22,7 @@ def version.older(ok: Bool, out: String) -> IO(String): # `bend` asked which bend it is, as a run's answer: the status line, then the # banner. A bend that is not on the PATH fails both spellings, so the status # an absent bend answers with is still the one the caller sees. -def version() -> IO(String): +def version() -> IO(String): # noqa: L001 IO: runs bend do IO: +out : String <- R.exec(["bend", "version"]) version.older(R.ok(out), out) diff --git a/src/sha/dump.bend b/src/sha/dump.bend index f9def9e..e984fcc 100644 --- a/src/sha/dump.bend +++ b/src/sha/dump.bend @@ -9,30 +9,13 @@ import ../io/file.bend as F import ./nar.bend as Nar # a command's output as it printed it, or the walk stopped with why it failed -def said(ok: Bool, +why: String, +text: String) -> IO(String): +def said(ok: Bool, +why: String, +text: String) -> IO(String): # noqa: L001 IO: reads the tree off the disk match ok: case False{}: IO.die(String, 1, "ez: nar hash: " ++ why ++ text) case True{}: IO.pure(String, text) -# what a program printed, with the status line in front of it taken off and -# nothing else touched -def printed.at(ends: Bool, tail: String, rest: Unit -> String) -> String: - match ends: - case True{}: - tail - case False{}: - rest(Unit{}) - -# the output after its first newline -def printed(out: String) -> String: - match out: - case SNil{}: - "" - case SCon{c, +t}: - printed.at(Char.is_eq(c, '\n'), t, _u => printed(t)) - # a path of the tree, as the file effect is to open it def under.top(+top: String, +at: String) -> String: Bool.pick(String, String.is_empty(at), top, top ++ "/" ++ at) @@ -91,7 +74,7 @@ def ent.of(+top: String, row: Nar.Row) -> IO(Nar.Ent): ent.read(String.eq(kind, "f"), kind, mode, name, at, target, under.top(top, at)) # every path of the listing, read -def ents(+top: String, rs: List<&2, Nar.Row>) -> IO(List<&2, Nar.Ent>): +def ents(+top: String, rs: List<&2, Nar.Row>) -> IO(List<&2, Nar.Ent>): # noqa: L001 IO: reads the tree off the disk match rs: case []: IO.pure(List<&2, Nar.Ent>, []) @@ -102,7 +85,7 @@ def ents(+top: String, rs: List<&2, Nar.Row>) -> IO(List<&2, Nar.Ent>): return e <> rest # the tree's node, or the walk stopped when the listing made none -def built(got: Maybe<&2, String>, +path: String) -> IO(String): +def built(got: Maybe<&2, String>, +path: String) -> IO(String): # noqa: L001 IO: reads the tree off the disk match got: case None{}: IO.die(String, 1, "ez: nar hash: " ++ path ++ ": the listing does not make a tree") @@ -110,15 +93,15 @@ def built(got: Maybe<&2, String>, +path: String) -> IO(String): IO.pure(String, node) # the NAR serial of one path -def dump(+path: String) -> IO(String): +def dump(+path: String) -> IO(String): # noqa: L001 IO: reads the tree off the disk do IO: +out : String <- R.exec(Nar.listing.argv(path)) - text : String <- said(R.ok(out), path ++ ": ", printed(out)) + text : String <- said(R.ok(out), path ++ ": ", R.text(out)) es : List<&2, Nar.Ent> <- ents(path, Nar.rows(Nar.cut(text))) built(Nar.tree(es), path) # the SRI narHash of a path, the same string `nix hash path --sri` prints -def path(+work: String) -> IO(String): +def path(+work: String) -> IO(String): # noqa: L001 IO: reads the tree off the disk do IO: node : String <- dump(work) return Nar.sri(Nar.archive(node)) diff --git a/src/share/args.bend b/src/share/args.bend index 827470a..fbfc212 100644 --- a/src/share/args.bend +++ b/src/share/args.bend @@ -79,7 +79,7 @@ def rest(as: List<&2, String>) -> List<&2, String>: t # every argument after the program's own name, each one readable twice -def all() -> IO(List<&2, String>): +def all() -> IO(List<&2, String>): # noqa: L001 IO: reads the process's words do IO>: xs : List<&1, String> <- IO.args() return rest(copy(xs)) diff --git a/src/share/cap.bend b/src/share/cap.bend index de62d32..0ff47b3 100644 --- a/src/share/cap.bend +++ b/src/share/cap.bend @@ -9,6 +9,7 @@ import Base import snap@1.4.0.0/main.bend as R import ./env.bend as Env +import ./capped.bend as Capped # how many gigabytes one `bend` may have. 8 is what fits beside the rest of # this machine; a project whose closure costs more says so in EZ_CAP. @@ -19,61 +20,32 @@ import ./env.bend as Env # the dearest aggregate here peaks at 3.3G, and at the 8G cap that is a width # of 4 where 11 would fit. Lower EZ_CAP, or set EZ_JOBS outright, for a tree # you have measured. -def gb() -> IO(String): +def gb() -> IO(String): # noqa: L001 IO: runs under the cap Env.var("EZ_CAP", "8") # whether a `bend` can be capped. The cap is `systemd-run --user`. That # fails when the program is absent, and it fails when the program is present # and the user bus is not. Either failure is no cap. A probe that would # wait on a password fails closed instead. -def ok() -> IO(Bool): +def ok() -> IO(Bool): # noqa: L001 IO: runs under the cap do IO: +out : String <- R.exec(["systemd-run", "--user", "--scope", "-q", "--collect", "--no-ask-password", "true"]) return R.ok(out) -# the cgroup a capped run gets. `MemorySwapMax=0` matters: without it the -# cgroup spills into swap and the cap stops meaning anything. -def scope(+gigs: String) -> List<&2, String>: - ["systemd-run", "--user", "--scope", "-q", "-p", "MemoryMax=" ++ gigs ++ "G", - "-p", "MemorySwapMax=0", "nice"] - -# the words a capped run is prefixed with, or none when nothing can cap it -def pre(on: Bool, +gigs: String) -> List<&2, String>: - match on: - case True{}: - scope(gigs) - case False{}: - [] - -# a program's arguments dressed the way the cap wants them, for a caller that -# is not going to run it here. The cap goes outside `env`, so the variable is -# set inside the cgroup. -def argv(on: Bool, +gigs: String, +at: String, args: List<&2, String>) -> List<&2, String>: - List.append(&2, String, pre(on, gigs), Env.line(at, args)) - # a program run under the cap, with this project's BEND_LIB set for it -def run(on: Bool, args: List<&2, String>) -> IO(String): +def run(on: Bool, args: List<&2, String>) -> IO(String): # noqa: L001 IO: runs under the cap do IO: +g : String <- gb() at : String <- Env.lib() - R.exec(argv(on, g, at, args)) - -# the status the kernel leaves on a process it killed for memory -def killed(+out: String) -> Bool: - String.eq(R.code(out), "137") - -# what to say when a run died for memory rather than for being wrong -def why(+out: String, +gigs: String) -> String: - Bool.pick(String, killed(out), - "killed for memory at " ++ gigs ++ "G: raise EZ_CAP\n", "") + R.exec(Capped.argv(on, g, at, args)) # what is said when nothing is capping the jobs -def warning() -> String: +def warning() -> String: # noqa: L001 the text share/cap prints: wording, not behavior "warning: systemd-run --user cannot cap `bend`, so no `bend` is capped" # a warning printed once when nothing is capping the jobs -def warn(on: Bool) -> IO(Unit): +def warn(on: Bool) -> IO(Unit): # noqa: L001 IO: runs under the cap match on: case True{}: IO.pure(Unit, Unit{}) diff --git a/src/share/capped.bend b/src/share/capped.bend new file mode 100644 index 0000000..e374088 --- /dev/null +++ b/src/share/capped.bend @@ -0,0 +1,36 @@ +# share/capped: the words of a run under the memory cap share/cap sets, and +# what is said of a run the cap killed. They are apart from share/cap, which +# runs programs through snap's foreign effect, so that a law may import them +# (laws/CappedRunWords.bend). +import Base +import snap@1.4.0.0/src/answer.bend as R +import ./env.bend as Env + +# the cgroup a capped run gets. `MemorySwapMax=0` matters: without it the +# cgroup spills into swap and the cap stops meaning anything. +def scope(+gigs: String) -> List<&2, String>: + ["systemd-run", "--user", "--scope", "-q", "-p", "MemoryMax=" ++ gigs ++ "G", + "-p", "MemorySwapMax=0", "nice"] + +# the words a capped run is prefixed with, or none when nothing can cap it +def pre(on: Bool, +gigs: String) -> List<&2, String>: + match on: + case True{}: + scope(gigs) + case False{}: + [] + +# a program's arguments dressed the way the cap wants them, for a caller that +# is not going to run it here. The cap goes outside `env`, so the variable is +# set inside the cgroup. +def argv(on: Bool, +gigs: String, +at: String, args: List<&2, String>) -> List<&2, String>: + List.append(&2, String, pre(on, gigs), Env.line(at, args)) + +# the status the kernel leaves on a process it killed for memory +def killed(+out: String) -> Bool: + String.eq(R.code(out), "137") + +# what to say when a run died for memory rather than for being wrong +def why(+out: String, +gigs: String) -> String: + Bool.pick(String, killed(out), + "killed for memory at " ++ gigs ++ "G: raise EZ_CAP\n", "") diff --git a/src/share/env.bend b/src/share/env.bend index dbde824..1538a62 100644 --- a/src/share/env.bend +++ b/src/share/env.bend @@ -12,13 +12,13 @@ def or_else(+value: String, +alt: String) -> String: Bool.pick(String, String.is_empty(value), alt, value) # what a variable holds, with a default for when it holds nothing -def var(name: String, +alt: String) -> IO(String): +def var(name: String, +alt: String) -> IO(String): # noqa: L001 IO: reads the environment do IO: r : Result<&1, &1, U32 & String, String> <- IO.get_env(name) return or_else(Args.text_of(r), alt) # where this project's packages live -def lib() -> IO(String): +def lib() -> IO(String): # noqa: L001 IO: reads the environment var("BEND_LIB", ".ez/lib") # the command with the project's BEND_LIB in front of it diff --git a/src/share/exec.bend b/src/share/exec.bend index c0b1149..4584bcf 100644 --- a/src/share/exec.bend +++ b/src/share/exec.bend @@ -8,14 +8,14 @@ import snap@1.4.0.0/main.bend as R import ./env.bend as Env # a program run with this project's BEND_LIB set for it -def exec(args: List<&2, String>) -> IO(String): +def exec(args: List<&2, String>) -> IO(String): # noqa: L001 IO: runs a program do IO: at : String <- Env.lib() R.exec(Env.line(at, args)) # those directories made. Base has no mkdir, so this is coreutils, and no # directory means no run at all. -def make(ds: List<&2, String>) -> IO(Unit): +def make(ds: List<&2, String>) -> IO(Unit): # noqa: L001 IO: runs a program match ds: case []: IO.pure(Unit, Unit{}) diff --git a/src/share/pass.bend b/src/share/pass.bend index 0d5acf8..cdf73f9 100644 --- a/src/share/pass.bend +++ b/src/share/pass.bend @@ -16,5 +16,5 @@ def ezpass.run(cmd: String) -> IO(U32): import "./pass.js" # a program run with its arguments, on ez's own stdio -def run(argv: List<&2, String>) -> IO(U32): +def run(argv: List<&2, String>) -> IO(U32): # noqa: L001 IO: runs a program ezpass.run(R.cmd(argv)) diff --git a/src/share/say.bend b/src/share/say.bend index 46439e7..a6c5656 100644 --- a/src/share/say.bend +++ b/src/share/say.bend @@ -19,7 +19,7 @@ import ../pkg/path.bend as P # a spinner that is running, or none. An empty pid means the line was already # printed and nothing has to be stopped. `msg` is what the terminal is owed # when the mark is cleared. -type Spin is Data: +type Spin is Data: # noqa: L001 the spinner share/spin's IO starts and stops Spin{dev: String, pid: String, msg: String} # the first twelve characters of a commit, which is enough to tell one from @@ -58,11 +58,11 @@ def dep.hub(+name: String) -> String: "dep " ++ name ++ ": hub fetch" # a binary already built for this commit -def reused(+name: String) -> String: +def reused(+name: String) -> String: # noqa: L001 a progress line an IO driver prints: wording, not behavior name ++ ": cached" # the lock resolving every dependency -def resolving() -> String: +def resolving() -> String: # noqa: L001 a progress line an IO driver prints: wording, not behavior "resolving deps" def resolving.at(+name: String) -> String: @@ -72,11 +72,11 @@ def git.fetch(+url: String) -> String: "git fetch (" ++ url ++ ")" # a binary being built -def building(+name: String) -> String: +def building(+name: String) -> String: # noqa: L001 a progress line an IO driver prints: wording, not behavior "building " ++ name # a binary being linked into place -def linking(+at: String) -> String: +def linking(+at: String) -> String: # noqa: L001 a progress line an IO driver prints: wording, not behavior "linking " ++ at # a binary built and linked @@ -88,7 +88,7 @@ def linked(+name: String, +at: String) -> String: "linked " ++ name ++ " -> " ++ at # a commit's tree being weighed for its NAR hash -def hashing(+rev: String) -> String: +def hashing(+rev: String) -> String: # noqa: L001 a progress line an IO driver prints: wording, not behavior "hashing " ++ brief(rev) # a device path that is a terminal. A pipe and `/dev/null` are not. @@ -156,7 +156,7 @@ def has.tools(+text: String) -> Bool: # `ez sync` is not a command. A ledger that pins tools already has the one # that builds them; a ledger that does not is pointed at lock and install. -def hint(tools: Bool) -> String: +def hint(tools: Bool) -> String: # noqa: L001 the hint ez/app's IO prints: wording, not behavior match tools: case True{}: "hint: `sync` is not a command; use `ez tool sync`" @@ -165,15 +165,15 @@ def hint(tools: Bool) -> String: # the parent's fd, by number. The child cannot look at its own: that one was # replaced with a pipe before this ran. `$1` is the number. -def probe() -> String: +def probe() -> String: # noqa: L001 a shell script share/spin runs "ppid=; while read -r k v; do case $k in PPid:) ppid=$v;; esac; done < /proc/self/status; readlink /proc/$ppid/fd/$1 2>/dev/null" # a mark on the terminal while the parent is alive. `$1` is the terminal, # `$2` the line. The mark walks ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏. An empty parent # id exits rather than spinning on `/proc`. -def frames() -> String: +def frames() -> String: # noqa: L001 a shell script share/spin runs "ppid=; while read -r k v; do case $k in PPid:) ppid=$v;; esac; done < /proc/self/status; [ -n \"$ppid\" ] || exit 0; while [ -d /proc/$ppid ]; do printf '\\r%s %s' '⠋' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠙' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠹' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠸' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠼' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠴' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠦' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠧' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠇' \"$2\" >\"$1\"; sleep 0.08; [ -d /proc/$ppid ] || break; printf '\\r%s %s' '⠏' \"$2\" >\"$1\"; sleep 0.08; done" # the mark wiped, and the line left in its place -def settle() -> String: +def settle() -> String: # noqa: L001 a shell script share/spin runs "printf '\\r\\033[K%s\\n' \"$2\" >\"$1\"" diff --git a/src/share/spin.bend b/src/share/spin.bend index 110dce0..fab1783 100644 --- a/src/share/spin.bend +++ b/src/share/spin.bend @@ -9,20 +9,20 @@ import snap@1.4.0.0/main.bend as R import ./say.bend as Say # one fd of this process, as a path. A failure is not a terminal. -def link(+fd: String) -> IO(String): +def link(+fd: String) -> IO(String): # noqa: L001 IO: the spinner do IO: +out : String <- R.exec(["sh", "-c", Say.probe(), "sh", fd]) return String.trim(R.text(out)) # the terminal this process writes to, stderr's first, or empty for none -def dev() -> IO(String): +def dev() -> IO(String): # noqa: L001 IO: the spinner do IO: +err : String <- link("2") +out : String <- link("1") return Say.tty.pick(err, out) # the mark, when there is a terminal to draw it on -def start(on: Bool, +dev: String, +msg: String) -> IO(Say.Spin): +def start(on: Bool, +dev: String, +msg: String) -> IO(Say.Spin): # noqa: L001 IO: the spinner match on: case False{}: IO.pure(Say.Spin, Say.Spin{"", "", ""}) @@ -42,14 +42,14 @@ def hold.at(plain: Bool, +dev: String, +msg: String) -> IO(Say.Spin): # the line, then the mark when a terminal will show it moving. A pipe gets # the line and nothing else. -def hold(+msg: String) -> IO(Say.Spin): +def hold(+msg: String) -> IO(Say.Spin): # noqa: L001 IO: the spinner do IO: +tty : String <- dev() hold.at(String.is_empty(tty), tty, msg) # a spinner that never started still owes its line, unless the plain path # already printed it and left the message empty -def owed(empty: Bool, +msg: String) -> IO(Unit): +def owed(empty: Bool, +msg: String) -> IO(Unit): # noqa: L001 IO: the spinner match empty: case True{}: IO.pure(Unit, Unit{}) @@ -71,6 +71,6 @@ def done.bad(bad: Bool, +dev: String, +pid: String, +msg: String) -> IO(Unit): done.live(dev, pid, msg) # the step finished: the mark stopped and the line left, or the line owed -def done(spin: Say.Spin) -> IO(Unit): +def done(spin: Say.Spin) -> IO(Unit): # noqa: L001 IO: the spinner Say.Spin{+term, +pid, +msg} = spin done.bad(Bool.or(String.is_empty(pid), String.eq(pid, "0")), term, pid, msg) diff --git a/src/tool/run.bend b/src/tool/run.bend index 2d60722..e3c9f5f 100644 --- a/src/tool/run.bend +++ b/src/tool/run.bend @@ -29,6 +29,7 @@ import ../fetch/run.bend as FetchRun import ../pkg/path.bend as P import ../run/bend.bend as Bend import ../share/cap.bend as Cap +import ../share/capped.bend as Capped import ../share/say.bend as Say import ../share/spin.bend as Spin import ../share/pass.bend as Pass @@ -39,7 +40,7 @@ import ./plan.bend as TP # answering # the first line, or nothing -def line0(ls: List<&2, String>) -> String: +def line0(ls: List<&2, String>) -> String: # noqa: L001 reads bend's banner for the IO driver match ls: case []: "" @@ -97,7 +98,9 @@ def said.top(+out: String) -> String: # what git says of a path that has a real path: the top of its checkout, # HEAD, and what `git status` names, untracked files included whatever the # repository's own settings hide -def located(+abs: String) -> IO(TW.Answer): +def located( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + +abs: String +) -> IO(TW.Answer): do IO: +top : String <- R.exec(["git", "-C", abs, "rev-parse", "--show-toplevel"]) +head : String <- R.exec(["git", "-C", abs, "rev-parse", "HEAD"]) @@ -115,13 +118,15 @@ def locate.real(ok: Bool, +path: String, +text: String) -> IO(TW.Answer): located(String.trim(text)) # a local path, made real, and what git says of it -def locate(+path: String) -> IO(TW.Answer): +def locate( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + +path: String +) -> IO(TW.Answer): do IO: +out : String <- R.exec(["realpath", path]) locate.real(R.ok(out), path, R.text(out)) # one question answered -def answer(ask: TW.Ask) -> IO(TW.Answer): +def answer(ask: TW.Ask) -> IO(TW.Answer): # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) match ask: case TW.Read{path}: do IO: @@ -145,12 +150,6 @@ def answer.all(asks: List<&2, TW.Ask>) -> IO(List<&2, TW.Reply>): rest : List<&2, TW.Reply> <- answer.all(t) return TW.Reply{h, a} <> rest -# the World with more answers in it -def more(world: TW.World, rs: List<&2, TW.Reply>, us: List<&2, Up.Reply>) -> TW.World: - TW.World{a, t, want, here, env, bend, ledger, lock, replies, ups} = world - TW.World{a, t, want, here, env, bend, ledger, lock, List.append(&2, TW.Reply, replies, rs), - List.append(&2, Up.Reply, ups, us)} - # --------------------------------------------------------------------------- # executing @@ -177,14 +176,18 @@ def compile.said(ok: Bool, +why: String, +text: String) -> IO(Unit): IO.die(Unit, 1, "") # `bend -o ` under the memory cap, with the checkout's library -def compile(+lib: String, +file: String, +out: String) -> IO(Unit): +def compile( # noqa: L001 IO: runs the plan (trusted in src/ez/app.bend) + +lib: String, + +file: String, + +out: String +) -> IO(Unit): do IO: +on : Bool <- Cap.ok() Cap.warn.err(on) +g : String <- Cap.gb() _mk : String <- R.exec(["mkdir", "-p", P.dir(out)]) - +bin : String <- R.exec(Cap.argv(on, g, lib, ["bend", file, "-o", out])) - compile.said(R.ok(bin), Cap.why(bin, g), R.text(bin)) + +bin : String <- R.exec(Capped.argv(on, g, lib, ["bend", file, "-o", out])) + compile.said(R.ok(bin), Capped.why(bin, g), R.text(bin)) # the library a build reads: an ez project's lock fetched into it as `ez # fetch` fetches one, with every relative path in it read from the @@ -215,7 +218,7 @@ def exec.make(making: TP.Make) -> IO(Unit): Run.write(at, key) # the lines a person is told, each on stderr -def tell(ls: List<&2, String>) -> IO(Unit): +def tell(ls: List<&2, String>) -> IO(Unit): # noqa: L001 IO: runs the plan (trusted in src/ez/app.bend) match ls: case []: IO.pure(Unit, Unit{}) @@ -270,20 +273,20 @@ def loop.step(st: TP.Step, world: TW.World, go: TW.World -> IO(Unit)) -> IO(Unit do IO: rs : List<&2, TW.Reply> <- answer.all(asks) us : List<&2, Up.Reply> <- Run.answer.ups("", ups) - go(more(world, rs, us)) + go(TW.more(world, rs, us)) case TP.Run{pl}: exec.plan(pl) # the rounds the loop may take. The planner asks at most five rounds, so this # is only a guard against a planner that keeps asking, and running out of it # dies loudly. -def rounds() -> Nat: +def rounds() -> Nat: # noqa: L001 the IO loop's fuel 100n # the loop, under fuel. Every round adds an answer, since the planner never # asks what the World answers already, and it asks at most five rounds, so # the fuel is only a guard. -def loop(fuel: Nat, +world: TW.World) -> IO(Unit): +def loop(fuel: Nat, +world: TW.World) -> IO(Unit): # noqa: L001 IO driver: the interpreter's loop match fuel: case 0n: IO.die(Unit, 1, "ez: ez tool kept asking questions") @@ -291,7 +294,7 @@ def loop(fuel: Nat, +world: TW.World) -> IO(Unit): loop.step(TP.step(world), world, w => loop(f, w)) # a variable, "" when it is unset -def var(name: String) -> IO(String): +def var(name: String) -> IO(String): # noqa: L001 IO: reads an environment variable do IO: r : Result<&1, &1, U32 & String, String> <- IO.get_env(name) return Run.env.text(r) @@ -304,7 +307,7 @@ def bend.is() -> IO(String): return Bool.pick(String, R.ok(out), line0(String.lines(String.trim(R.text(out)))), "") # the variables the tool commands read -def env() -> IO(TW.Env): +def env() -> IO(TW.Env): # noqa: L001 IO: reads the environment do IO: +b : String <- var("EZ_TOOL_BIN") +x : String <- var("XDG_BIN_HOME") @@ -315,7 +318,7 @@ def env() -> IO(TW.Env): # one target, run, installed or upgraded, over the project's ledger and lock, # building the file `want` names when it names one -def go( +def go( # noqa: L001 IO driver act: TW.Act, +target: String, +want: String, @@ -328,7 +331,7 @@ def go( loop(rounds(), TW.World{act, target, want, here, vars, bend, led, lock, [], []}) # `ez tool run [--entry ] [-- args…]`, `install` and `upgrade` -def run(act: TW.Act, +target: String, +want: String) -> IO(Unit): +def run(act: TW.Act, +target: String, +want: String) -> IO(Unit): # noqa: L001 IO entry of the command do IO: +pwd : String <- R.exec(["pwd"]) +vars : TW.Env <- env() @@ -369,7 +372,7 @@ def sync.go( Run.end(TP.sync.outcome(synced)) # `ez tool sync`: every pin the ledger names, installed at its lock rev -def sync() -> IO(Unit): +def sync() -> IO(Unit): # noqa: L001 IO entry of the command do IO: +pwd : String <- R.exec(["pwd"]) +vars : TW.Env <- env() diff --git a/src/tool/world.bend b/src/tool/world.bend index 0a49971..a8beae4 100644 --- a/src/tool/world.bend +++ b/src/tool/world.bend @@ -71,11 +71,6 @@ def want(world: World) -> String: World{_a, _t, w, _here, _env, _bend, _ledger, _lock, _rs, _ups} = world w -# the directory ez runs in -def here(world: World) -> String: - World{_a, _t, _want, h, _env, _bend, _ledger, _lock, _rs, _ups} = world - h - # the variables def env(world: World) -> Env: World{_a, _t, _want, _here, e, _bend, _ledger, _lock, _rs, _ups} = world @@ -230,3 +225,9 @@ def look(rs: List<&2, Reply>, +want: String) -> Heard: # the answer to a question, or none yet def heard(+world: World, ask: Ask) -> Heard: look(replies(world), key(ask)) + +# the World with more answers in it +def more(world: World, rs: List<&2, Reply>, us: List<&2, Up.Reply>) -> World: + World{a, t, want, here, env, bend, ledger, lock, replies, ups} = world + World{a, t, want, here, env, bend, ledger, lock, List.append(&2, Reply, replies, rs), + List.append(&2, Up.Reply, ups, us)} diff --git a/src/ws/run.bend b/src/ws/run.bend index ef11852..64bfbc5 100644 --- a/src/ws/run.bend +++ b/src/ws/run.bend @@ -25,7 +25,7 @@ import ./doctor.bend as Doc import ./relock.bend as Rel # what the search found, and the top of the checkout it searched from -type Searched is Data: +type Searched is Data: # noqa: L001 carried between the IO driver's steps Searched{top: String, found: R.Found} # a directory's ez.toml, from the top of the checkout @@ -63,14 +63,14 @@ def here.git(ok: Bool, +text: String) -> Maybe<&2, List<&2, String>>: None{} # the search for the root, from where ez runs up to the top of its checkout -def search() -> IO(Searched): +def search() -> IO(Searched): # noqa: L001 IO: searches up for the workspace root do IO: +pre : String <- Sn.exec(["git", "rev-parse", "--show-prefix"]) +top : String <- Sn.exec(["git", "rev-parse", "--show-toplevel"]) search.at(here.git(Bool.and(Sn.ok(pre), Sn.ok(top)), Sn.text(pre)), String.trim(Sn.text(top))) # the program's own name, and every word after it -def argv() -> IO(List<&2, String>): +def argv() -> IO(List<&2, String>): # noqa: L001 IO: reads argv do IO>: xs : List<&1, String> <- IO.args() return Args.copy(xs) @@ -136,18 +136,9 @@ def read.found(ps: List<&2, String>) -> IO(List<&2, J.Found>): rest : List<&2, J.Found> <- read.found(tl) return J.Found{hd, F.text_of(mm)} <> rest -# the non-empty lines -def lines(ss: List<&2, String>) -> List<&2, String>: - match ss: - case []: - [] - case +hd <> tl: - +more = lines(tl) - Bool.pick(List<&2, String>, String.is_empty(hd), more, hd <> more) - # the ledger `ez lock` is planned from, what an upgrade needs to write its # pins back, and the answers the lock reads the workspace's members from -type Planned is Data: +type Planned is Data: # noqa: L001 carried between the IO driver's steps Planned{ledger: Maybe<&2, String>, back: U.Back, seeds: List<&2, LW.Reply>} # the joint ledger, as the lock reads it, or the refusal that leaves none @@ -179,7 +170,7 @@ def joint.listed( match ok: case True{}: do IO: - +fs : List<&2, J.Found> <- read.found(lines(String.lines(out))) + +fs : List<&2, J.Found> <- read.found(Args.nonempty(String.lines(out))) lk : Maybe<&2, String> <- F.read("ez.lock.toml") joint.at(J.joint(text, fs, files), text, spec, fs, files, F.text_of(lk)) case False{}: @@ -208,7 +199,10 @@ def joint.read(rd: W.Read, +text: String, +files: List<&2, K.Source>) -> IO(Plan # the ledger `ez lock` is planned from: ez.toml as it is, or, at a workspace # root, the joint ledger of the root and every member. `files` are the # committed `.bend` files, which a member's package is walked over. -def ledger(led: Maybe<&2, String>, +files: List<&2, K.Source>) -> IO(Planned): +def ledger( # noqa: L001 IO: answers the planner's questions (trusted in src/ez/app.bend) + led: Maybe<&2, String>, + +files: List<&2, K.Source> +) -> IO(Planned): match led: case None{}: IO.pure(Planned, Planned{None{}, U.Alone{}, []}) @@ -304,9 +298,9 @@ def pins.at(+dir: String) -> IO(List<&2, M.Dep>): mm : Maybe<&2, String> <- F.read(dir ++ "/ez.toml") +out : String <- Sn.exec(["git", "-C", dir, "-c", "core.quotepath=off", "ls-files", "--", ":(glob)**/ez.toml"]) - fs : List<&2, J.Found> <- read.under(dir, lines(String.lines(Sn.text(out)))) + fs : List<&2, J.Found> <- read.under(dir, Args.nonempty(String.lines(Sn.text(out)))) +bend : String <- Sn.exec(["git", "-C", dir, "-c", "core.quotepath=off", "ls-files", "--", "*.bend"]) - files : List<&2, K.Source> <- files.under(dir, lines(String.lines(Sn.text(bend)))) + files : List<&2, K.Source> <- files.under(dir, Args.nonempty(String.lines(Sn.text(bend)))) return pins.joint(J.joint(F.text_of(mm), fs, files)) # the ref, once the workspace's pins are known @@ -358,7 +352,7 @@ def listing.listed(ok: Bool, +dir: String, +out: String) -> IO(LW.Listing): match ok: case True{}: do IO: - fs : List<&2, LW.Source> <- sources.under(dir, lines(String.lines(out))) + fs : List<&2, LW.Source> <- sources.under(dir, Args.nonempty(String.lines(out))) return LW.Listed{fs} case False{}: IO.pure(LW.Listing, LW.Unlisted{ @@ -373,12 +367,12 @@ def listing.at(+dir: String) -> IO(LW.Listing): # what a command run at `rel` from the root at `at` reads of the root: its # ledger, every ez.toml and `.bend` file git lists under it, and its lock -def rooted(+at: String, rel: List<&2, String>) -> IO(Rel.Rooted): +def rooted(+at: String, rel: List<&2, String>) -> IO(Rel.Rooted): # noqa: L001 IO: reads the workspace do IO: mm : Maybe<&2, String> <- F.read(at ++ "/ez.toml") +out : String <- Sn.exec(["git", "-C", at, "-c", "core.quotepath=off", "ls-files", "--", ":(glob)**/ez.toml"]) - fs : List<&2, J.Found> <- read.under(at, lines(String.lines(Sn.text(out)))) + fs : List<&2, J.Found> <- read.under(at, Args.nonempty(String.lines(Sn.text(out)))) ls : LW.Listing <- listing.at(at) lk : Maybe<&2, String> <- F.read(at ++ "/ez.lock.toml") return Rel.Rooted{at, rel, F.text_of(mm), fs, ls, F.text_of(lk)} @@ -424,9 +418,9 @@ def lock.path() -> IO(String): def doctor.root(+text: String) -> IO(Doc.Doctored): do IO: +out : String <- Sn.exec(["git", "-c", "core.quotepath=off", "ls-files", "--", ":(glob)**/ez.toml"]) - +fs : List<&2, J.Found> <- read.found(lines(String.lines(Sn.text(out)))) + +fs : List<&2, J.Found> <- read.found(Args.nonempty(String.lines(Sn.text(out)))) +bend : String <- Sn.exec(["git", "-c", "core.quotepath=off", "ls-files", "--", "*.bend"]) - files : List<&2, K.Source> <- files.under(".", lines(String.lines(Sn.text(bend)))) + files : List<&2, K.Source> <- files.under(".", Args.nonempty(String.lines(Sn.text(bend)))) return Doc.joint(J.joint(text, fs, files), text, fs) # what one ledger's text says, for the doctor diff --git a/tests/cli.bend b/tests/cli.bend index 017edea..548d54f 100644 --- a/tests/cli.bend +++ b/tests/cli.bend @@ -8,6 +8,7 @@ import ../src/io/file.bend as F import ../src/ez/quiet.bend as Q import ../src/check/kit.bend as Check import ../src/check/world.bend as W +import ../src/check/out.bend as O # a check whose answer is a yes or a no def yes(name: String, ok: Bool) -> IO(Unit): @@ -39,7 +40,7 @@ def stanza(+text: String, +head: String) -> String: # what a program answered, with bend's update nag taken out of it, since a # run's output and bend's own lines arrive on the same stream def answer(+out: String) -> String: - W.last(String.lines(Q.filter(R.text(out)))) + O.last(String.lines(Q.filter(R.text(out)))) # the upstream package: a repo with one file, committed and never published def upstream(+at: String) -> IO(String): @@ -53,7 +54,7 @@ def upstream(+at: String) -> IO(String): _c : String <- R.exec(["git", "-C", at, "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-q", "-m", "init"]) +rev : String <- R.exec(["git", "-C", at, "rev-parse", "HEAD"]) - return W.line(rev) + return O.line(rev) # that repo served the way a real remote is, so `ez add` reaches it over the # protocol and not over the file system @@ -75,7 +76,7 @@ def serve(+at: String, +port: String) -> IO(String): # the ledger, the lock and the vendored tree, each asked what it holds def ledger(+repo: String, +app: String, +url: String, +rev: String) -> IO(String): do IO: - _i : String <- R.exec(W.ez(repo, app, ["init", "myapp", "main.bend"])) + _i : String <- R.exec(O.ez(repo, app, ["init", "myapp", "main.bend"])) t : Maybe<&2, String> <- F.read(app ++ "/ez.toml") Check.eq_str("init writes a ledger", Q.chomp(F.text_of(t)), "[package]\nname = \"myapp\"\nentry = \"main.bend\"") @@ -84,10 +85,10 @@ def ledger(+repo: String, +app: String, +url: String, +rev: String) -> IO(String Q.chomp(F.text_of(e)), "# myapp: TODO describe myapp\nimport Base\nimport ./src/lib.bend as Lib\n\n" ++ "def main() -> IO(Unit):\n IO.print(Lib.greeting())") - _a : String <- R.exec(W.ez(repo, app, ["add", url, rev, "src/lib.bend"])) + _a : String <- R.exec(O.ez(repo, app, ["add", url, rev, "src/lib.bend"])) +t2 : Maybe<&2, String> <- F.read(app ++ "/ez.toml") - +hash : String <- IO.pure(String, W.value(F.text_of(t2), "hash")) - +nar : String <- IO.pure(String, W.value(F.text_of(t2), "narHash")) + +hash : String <- IO.pure(String, O.value(F.text_of(t2), "hash")) + +nar : String <- IO.pure(String, O.value(F.text_of(t2), "narHash")) Check.eq_str("add records the package under its name", stanza(F.text_of(t2), "[deps.upstream]"), "[deps.upstream]\nhash = \"" ++ hash ++ "\"\ngit = \"" ++ url ++ @@ -105,14 +106,14 @@ def project(+repo: String, +app: String, +hash: String, +rev: String) -> IO(Unit "import Base\nimport " ++ hash ++ "/lib.bend as L\n\n" ++ "def main() -> U32:\n L.double(21)\n") W.track(app) - _l : String <- R.exec(W.ez(repo, app, ["lock"])) + _l : String <- R.exec(O.ez(repo, app, ["lock"])) +at : String <- W.only(app, "ez.lock.*") +lock : Maybe<&2, String> <- F.read(at) yes("lock records the git source", Bool.and(String.contains(F.text_of(lock), "git"), String.contains(F.text_of(lock), rev))) W.rm(app ++ "/.ez/lib") - _f : String <- R.exec(W.ez(repo, app, ["fetch"])) + _f : String <- R.exec(O.ez(repo, app, ["fetch"])) +got : String <- R.exec(["test", "-f", app ++ "/.ez/lib/" ++ hash ++ "/lib.bend"]) yes("fetch fills BEND_LIB from the lock alone", R.ok(got)) @@ -120,9 +121,9 @@ def project(+repo: String, +app: String, +hash: String, +rev: String) -> IO(Unit # what `ez` says once there is no remote left to ask def offline(+repo: String, +app: String) -> IO(Unit): do IO: - +ck : String <- R.exec(W.ez(repo, app, ["check"])) + +ck : String <- R.exec(O.ez(repo, app, ["check"])) yes("check passes with the git remote gone", R.ok(ck)) - +rn : String <- R.exec(W.ez(repo, app, ["run"])) + +rn : String <- R.exec(O.ez(repo, app, ["run"])) Check.eq_str("run gives the program's answer", answer(rn), "42") # the test runner, on a file that prints its trailer and then on one that does @@ -132,12 +133,12 @@ def runner(+repo: String, +app: String) -> IO(Unit): W.mkdir(app ++ "/src/tests") _w : Bool <- F.write(app ++ "/src/tests/ok.bend", "import Base\n\ndef main() -> IO(Unit):\n IO.print(\"ok one\")\n\n#|ok one\n") - +good : String <- R.exec(W.ez(repo, app, ["test"])) + +good : String <- R.exec(O.ez(repo, app, ["test"])) Check.eq_str("test passes a file that prints its trailer", answer(good), "PASS: 1 / 1") _b : Bool <- F.write(app ++ "/src/tests/bad.bend", "import Base\n\ndef main() -> IO(Unit):\n IO.print(\"ok one\")\n\n#|ok two\n") - +bad : String <- R.exec(W.ez(repo, app, ["test"])) + +bad : String <- R.exec(O.ez(repo, app, ["test"])) yes("test fails a file that does not", Bool.not(R.ok(bad))) W.rm(app ++ "/src/tests/bad.bend") @@ -145,19 +146,19 @@ def runner(+repo: String, +app: String) -> IO(Unit): # the package is dropped from the ledger while the import line stays def drifted(+repo: String, +app: String, +hash: String) -> IO(Unit): do IO: - +ok : String <- R.exec(W.ez(repo, app, ["doctor"])) + +ok : String <- R.exec(O.ez(repo, app, ["doctor"])) yes("doctor passes a project with nothing wrong", R.ok(ok)) - _r : String <- R.exec(W.ez(repo, app, ["remove", "upstream"])) + _r : String <- R.exec(O.ez(repo, app, ["remove", "upstream"])) +t : Maybe<&2, String> <- F.read(app ++ "/ez.toml") yes("remove drops it from the ledger", Bool.not(String.contains(F.text_of(t), "deps.upstream"))) Check.eq_str("and leaves the package stanza alone", - W.value(F.text_of(t), "name"), "myapp") - +bad : String <- R.exec(W.ez(repo, app, ["doctor"])) + O.value(F.text_of(t), "name"), "myapp") + +bad : String <- R.exec(O.ez(repo, app, ["doctor"])) yes("doctor reports a hash the ledger no longer names", String.contains(R.text(bad), "drift: " ++ hash ++ " is imported")) yes("and that drift fails the command", Bool.not(R.ok(bad))) - +no : String <- R.exec(W.ez(repo, app, ["nonsense"])) + +no : String <- R.exec(O.ez(repo, app, ["nonsense"])) yes("an unknown subcommand fails", Bool.not(R.ok(no))) # everything, once the scratch directory, the port and the binary are known diff --git a/tests/git.bend b/tests/git.bend index a7d713b..6b7542f 100644 --- a/tests/git.bend +++ b/tests/git.bend @@ -9,6 +9,7 @@ import ../src/io/file.bend as F import ../src/ez/quiet.bend as Q import ../src/check/kit.bend as Check import ../src/check/world.bend as W +import ../src/check/out.bend as O # a check whose answer is a yes or a no def yes(name: String, ok: Bool) -> IO(Unit): @@ -16,7 +17,7 @@ def yes(name: String, ok: Bool) -> IO(Unit): # what a program answered, with bend's update nag taken out of it def answer(+out: String) -> String: - W.last(String.lines(Q.filter(R.text(out)))) + O.last(String.lines(Q.filter(R.text(out)))) # the upstream repo: two files, one importing the other, committed, tagged and # never published @@ -37,7 +38,7 @@ def upstream(+at: String) -> IO(String): _g : String <- R.exec(["git", "-C", at, "-c", "user.email=t@t", "-c", "user.name=t", "tag", "-a", "v1.0", "-m", "v1.0"]) +rev : String <- R.exec(["git", "-C", at, "rev-parse", "HEAD"]) - return W.line(rev) + return O.line(rev) # that repo served over the protocol, so the nix sandbox can reach it too. The # annotated tag is pushed as well, since the peeled `^{}` row is the one that @@ -67,18 +68,18 @@ def serve(+at: String, +port: String) -> IO(String): # file rather than one of them overwriting the other. def vendor(+repo: String, +app: String, +url: String, +rev: String) -> IO(String): do IO: - _i : String <- R.exec(W.ez(repo, app, ["init", "myapp", "main.bend"])) - +out : String <- R.exec(W.ez(repo, app, ["add", url, rev, "src/lib.bend"])) + _i : String <- R.exec(O.ez(repo, app, ["init", "myapp", "main.bend"])) + +out : String <- R.exec(O.ez(repo, app, ["add", url, rev, "src/lib.bend"])) +led : Maybe<&2, String> <- F.read(app ++ "/ez.toml") - +hash : String <- IO.pure(String, W.value(F.text_of(led), "hash")) + +hash : String <- IO.pure(String, O.value(F.text_of(led), "hash")) Check.eq_str("add says the import line the package is reachable by", - W.containing(String.lines(R.text(out)), "import "), + O.containing(String.lines(R.text(out)), "import "), "import " ++ hash ++ "/lib.bend as Lib") - +tag : String <- R.exec(W.inside(app, ["env", + +tag : String <- R.exec(O.inside(app, ["env", "BEND_LIB=" ++ app ++ "/.ez/tag", repo ++ "/bin/ez.bin", "add", url, "v1.0", "src/lib.bend"])) Check.eq_str("the tag it resolved through is written down", - W.containing(String.lines(R.text(tag)), " is "), "v1.0 is " ++ rev) + O.containing(String.lines(R.text(tag)), " is "), "v1.0 is " ++ rev) +same : String <- R.exec(["diff", "-r", app ++ "/.ez/lib/" ++ hash, app ++ "/.ez/tag/" ++ hash]) yes("a tag vendors the same package as its commit", R.ok(same)) @@ -92,18 +93,18 @@ def local(+repo: String, +app: String, +hash: String, +rev: String) -> IO(Unit): "import Base\nimport " ++ hash ++ "/lib.bend as Lib\n\n" ++ "def main() -> U32:\n Lib.quad(11)\n") W.track(app) - +out : String <- R.exec(W.inside(app, ["env", "BEND_HUB=http://127.0.0.1:1", + +out : String <- R.exec(O.inside(app, ["env", "BEND_HUB=http://127.0.0.1:1", "BEND_LIB=" ++ app ++ "/.ez/lib", "bend", "main.bend"])) Check.eq_str("the vendored package builds, with no hub at all", answer(out), "44") - _lk : String <- R.exec(W.ez(repo, app, ["lock"])) + _lk : String <- R.exec(O.ez(repo, app, ["lock"])) +at : String <- W.only(app, "ez.lock.*") +txt : Maybe<&2, String> <- F.read(at) yes("the lock records the git rev, not the hub", Bool.and(String.contains(F.text_of(txt), "git"), String.contains(F.text_of(txt), rev))) Check.eq_str("the lock keeps the tag beside the rev", - W.value(F.text_of(txt), "tag"), "v1.0") + O.value(F.text_of(txt), "tag"), "v1.0") # nix rebuilding the package from the rev alone. The store path is the last # line of the build that names one, since the build's log shares the stream. @@ -115,11 +116,11 @@ def rebuild(+repo: String, +app: String, +hash: String) -> IO(Unit): "/nix/bend-lib.nix { } " ++ lock ++ "\n") +out : String <- R.exec(["nix-build", "--no-out-link", app ++ "/build.nix"]) +at : String <- IO.pure(String, - W.starting.last(String.lines(R.text(out)), "/nix/store/", "")) + O.starting.last(String.lines(R.text(out)), "/nix/store/", "")) +same : String <- R.exec(["diff", "-r", app ++ "/.ez/lib/" ++ hash, at ++ "/" ++ hash]) yes("nix rebuilds the package byte for byte", R.ok(same)) - +ran : String <- R.exec(W.inside(app, ["env", "BEND_HUB=http://127.0.0.1:1", + +ran : String <- R.exec(O.inside(app, ["env", "BEND_HUB=http://127.0.0.1:1", "BEND_LIB=" ++ at, "bend", "main.bend"])) Check.eq_str("the nix tree builds with no hub", answer(ran), "44") diff --git a/tests/hub.bend b/tests/hub.bend index 3b709b3..fb1bdac 100644 --- a/tests/hub.bend +++ b/tests/hub.bend @@ -10,6 +10,7 @@ import ../src/doctor/plan.bend as DP import ../src/ez/quiet.bend as Q import ../src/check/kit.bend as Check import ../src/check/world.bend as W +import ../src/check/out.bend as O # a check whose answer is a yes or a no def yes(name: String, ok: Bool) -> IO(Unit): @@ -17,7 +18,7 @@ def yes(name: String, ok: Bool) -> IO(Unit): # what a program answered, with bend's update nag taken out of it def answer(+out: String) -> String: - W.last(String.lines(Q.filter(R.text(out)))) + O.last(String.lines(Q.filter(R.text(out)))) # a package's manifest: one ` ` line per file, in path order. # Every package here holds one file, which is all this test needs. @@ -45,7 +46,7 @@ def named(+at: String) -> IO(List<&2, String>): do IO>: +out : String <- R.exec(["grep", "-ohE", "0x[0-9a-f]{32}", at]) return DP.once(List.sort(~String, ~String.is_le, - W.nonblank(String.lines(R.text(out))))) + O.nonblank(String.lines(R.text(out))))) # the entry, locked against the hub that is serving the two packages. The hub # is the one the ledger names, since `ez lock` reads no environment for it. @@ -54,21 +55,21 @@ def lock(+repo: String, +app: String, +hub: String) -> IO(Unit): _t : Bool <- F.write(app ++ "/ez.toml", "[package]\nname = \"app\"\nhub = \"" ++ hub ++ "\"\n") W.track(app) - _o : String <- R.exec(W.ez(repo, app, ["lock"])) + _o : String <- R.exec(O.ez(repo, app, ["lock"])) return Unit{} # BEND_LIB filled from the lock and nothing else, which is what the nix # derivation does and what a checkout without a network needs def restore(+repo: String, +app: String, +hub: String) -> IO(Unit): do IO: - _o : String <- R.exec(W.inside(app, ["env", "BEND_HUB=" ++ hub, + _o : String <- R.exec(O.inside(app, ["env", "BEND_HUB=" ++ hub, repo ++ "/bin/ez.bin", "fetch"])) return Unit{} # the entry built against a BEND_LIB, with the hub pointed at a dead port so a # fallback to the network cannot be what made it work def build(+app: String, +lib: String) -> IO(String): - R.exec(W.inside(app, ["env", "BEND_HUB=http://127.0.0.1:1", + R.exec(O.inside(app, ["env", "BEND_HUB=http://127.0.0.1:1", "BEND_LIB=" ++ lib, "bend", "main.bend"])) # everything, once the scratch directory and the port are known @@ -86,7 +87,7 @@ def go(+repo: String, +root: String, +port: String) -> IO(Unit): _w : Bool <- F.write(root ++ "/app/main.bend", "import Base\nimport " ++ mid ++ "/src/mid.bend as B\n\n" ++ "def main() -> U32:\n B.quad(11)\n") - +pid : String <- W.spawn(W.inside(root ++ "/hub", ["python3", "-m", + +pid : String <- W.spawn(O.inside(root ++ "/hub", ["python3", "-m", "http.server", port, "--bind", "127.0.0.1"])) up : Bool <- W.ready(["curl", "-fsS", "--max-time", "5", "http://127.0.0.1:" ++ port ++ "/"]) diff --git a/tests/init.bend b/tests/init.bend index c5bca21..d983623 100644 --- a/tests/init.bend +++ b/tests/init.bend @@ -7,6 +7,7 @@ import ../src/io/file.bend as F import ../src/ez/quiet.bend as Q import ../src/check/kit.bend as Check import ../src/check/world.bend as W +import ../src/check/out.bend as O # a check whose answer is a yes or a no def yes(name: String, ok: Bool) -> IO(Unit): @@ -30,7 +31,7 @@ def alone(+head: String) -> String: def fresh(+repo: String, +app: String) -> IO(Unit): do IO: W.mkdir(app) - +out : String <- R.exec(W.ez(repo, app, ["init"])) + +out : String <- R.exec(O.ez(repo, app, ["init"])) yes("init succeeds with no arguments", R.ok(out)) t : Maybe<&2, String> <- F.read(app ++ "/ez.toml") Check.eq_str("and writes a ledger for app at main.bend", @@ -46,7 +47,7 @@ def fresh(+repo: String, +app: String) -> IO(Unit): l : Maybe<&2, String> <- F.read(app ++ "/src/lib.bend") Check.eq_str("and the library under src/ it imports", Q.chomp(F.text_of(l)), lib()) - +ck : String <- R.exec(W.ez(repo, app, ["check"])) + +ck : String <- R.exec(O.ez(repo, app, ["check"])) Check.eq_str("and that entry checks", Q.chomp(R.text(ck)), "ok main.bend") # a second init is refused, and leaves the ledger and the program it found @@ -54,7 +55,7 @@ def kept(+repo: String, +app: String) -> IO(Unit): do IO: _w : Bool <- F.write(app ++ "/main.bend", "import Base\n\ndef main() -> U32:\n 7\n") - +again : String <- R.exec(W.ez(repo, app, ["init", "other"])) + +again : String <- R.exec(O.ez(repo, app, ["init", "other"])) yes("a second init is refused", Bool.not(R.ok(again))) t : Maybe<&2, String> <- F.read(app ++ "/ez.toml") Check.eq_str("and leaves the ledger it found", @@ -72,7 +73,7 @@ def kept(+repo: String, +app: String) -> IO(Unit): def nested(+repo: String, +app: String) -> IO(Unit): do IO: W.mkdir(app) - +out : String <- R.exec(W.ez(repo, app, ["init", "myapp", "src/main.bend"])) + +out : String <- R.exec(O.ez(repo, app, ["init", "myapp", "src/main.bend"])) yes("init succeeds with a nested entry", R.ok(out)) e : Maybe<&2, String> <- F.read(app ++ "/src/main.bend") Check.eq_str("and writes the entry under the directories it needs", @@ -81,7 +82,7 @@ def nested(+repo: String, +app: String) -> IO(Unit): Check.eq_str("and names that entry in the ledger", Q.chomp(F.text_of(t)), "[package]\nname = \"myapp\"\nentry = \"src/main.bend\"") - +ck : String <- R.exec(W.ez(repo, app, ["check"])) + +ck : String <- R.exec(O.ez(repo, app, ["check"])) Check.eq_str("and that nested entry checks", Q.chomp(R.text(ck)), "ok src/main.bend") @@ -91,7 +92,7 @@ def existing(+repo: String, +app: String) -> IO(Unit): W.mkdir(app ++ "/src") _w : Bool <- F.write(app ++ "/src/lib.bend", "import Base\n\ndef double(+x: U32) -> U32:\n (x * 2 : U32)\n") - _i : String <- R.exec(W.ez(repo, app, ["init", "myapp", "src/lib.bend"])) + _i : String <- R.exec(O.ez(repo, app, ["init", "myapp", "src/lib.bend"])) e : Maybe<&2, String> <- F.read(app ++ "/src/lib.bend") Check.eq_str("init does not overwrite an entry that is already there", Q.chomp(F.text_of(e)), @@ -102,13 +103,13 @@ def existing(+repo: String, +app: String) -> IO(Unit): def described(+repo: String, +app: String) -> IO(Unit): do IO: W.mkdir(app) - +out : String <- R.exec(W.ez(repo, app, ["init", "demo", "--description", "a demo"])) + +out : String <- R.exec(O.ez(repo, app, ["init", "demo", "--description", "a demo"])) yes("init takes a description", R.ok(out)) e : Maybe<&2, String> <- F.read(app ++ "/main.bend") Check.eq_str("and opens the entry with it", Q.chomp(F.text_of(e)), stub("# demo: a demo")) - +run : String <- R.exec(W.ez(repo, app, ["run"])) - Check.eq_str("and the new project runs", W.last(String.lines(Q.filter(R.text(run)))), "hello") + +run : String <- R.exec(O.ez(repo, app, ["run"])) + Check.eq_str("and the new project runs", O.last(String.lines(Q.filter(R.text(run)))), "hello") # a library that is already there is left alone, and the stub then imports # nothing @@ -116,7 +117,7 @@ def library(+repo: String, +app: String) -> IO(Unit): do IO: W.mkdir(app ++ "/src") _w : Bool <- F.write(app ++ "/src/lib.bend", "import Base\n\ndef mine() -> U32:\n 1\n") - _i : String <- R.exec(W.ez(repo, app, ["init", "demo"])) + _i : String <- R.exec(O.ez(repo, app, ["init", "demo"])) l : Maybe<&2, String> <- F.read(app ++ "/src/lib.bend") Check.eq_str("init does not overwrite a src/lib.bend that is already there", Q.chomp(F.text_of(l)), "import Base\n\ndef mine() -> U32:\n 1") diff --git a/tests/nix.bend b/tests/nix.bend index e21a486..a10f744 100644 --- a/tests/nix.bend +++ b/tests/nix.bend @@ -9,6 +9,7 @@ import ../src/share/sha.bend as Sha import ../src/ez/quiet.bend as Q import ../src/check/kit.bend as Check import ../src/check/world.bend as W +import ../src/check/out.bend as O # a check whose answer is a yes or a no def yes(name: String, ok: Bool) -> IO(Unit): @@ -16,7 +17,7 @@ def yes(name: String, ok: Bool) -> IO(Unit): # what a program answered, with bend's update nag taken out of it def answer(+out: String) -> String: - W.last(String.lines(Q.filter(R.text(out)))) + O.last(String.lines(Q.filter(R.text(out)))) # a one-file package written into a hub directory, under the name its own # manifest's digest gives it @@ -36,7 +37,7 @@ def lock(+repo: String, +app: String, +hub: String) -> IO(String): _t : Bool <- F.write(app ++ "/ez.toml", "[package]\nname = \"app\"\nhub = \"" ++ hub ++ "\"\n") W.track(app) - _o : String <- R.exec(W.ez(repo, app, ["lock"])) + _o : String <- R.exec(O.ez(repo, app, ["lock"])) +at : String <- W.only(app, "ez.lock.*") yes("the lock was written", Bool.not(String.is_empty(at))) return at @@ -50,10 +51,10 @@ def sandbox(+repo: String, +app: String, +hash: String, +lock: String) -> IO(Uni "/nix/bend-lib.nix { } " ++ lock ++ "\n") +out : String <- R.exec(["nix-build", "--no-out-link", app ++ "/build.nix"]) +at : String <- IO.pure(String, - W.starting.last(String.lines(R.text(out)), "/nix/store/", "")) + O.starting.last(String.lines(R.text(out)), "/nix/store/", "")) +got : String <- R.exec(["test", "-f", at ++ "/" ++ hash ++ "/src/lib.bend"]) yes("nix fetched the package through the lock", R.ok(got)) - +ran : String <- R.exec(W.inside(app, ["env", "BEND_HUB=http://127.0.0.1:1", + +ran : String <- R.exec(O.inside(app, ["env", "BEND_HUB=http://127.0.0.1:1", "BEND_LIB=" ++ at, "bend", "main.bend"])) Check.eq_str("the store path builds with the hub unreachable", answer(ran), "42") @@ -68,7 +69,7 @@ def go(+repo: String, +root: String, +port: String) -> IO(Unit): _w : Bool <- F.write(root ++ "/app/main.bend", "import Base\nimport " ++ a ++ "/src/lib.bend as A\n\n" ++ "def main() -> U32:\n A.double(21)\n") - +pid : String <- W.spawn(W.inside(root ++ "/hub", ["python3", "-m", + +pid : String <- W.spawn(O.inside(root ++ "/hub", ["python3", "-m", "http.server", port, "--bind", "127.0.0.1"])) up : Bool <- W.ready(["curl", "-fsS", "--max-time", "5", "http://127.0.0.1:" ++ port ++ "/"]) diff --git a/tests/publish.bend b/tests/publish.bend index cf9e8c0..f997dcf 100644 --- a/tests/publish.bend +++ b/tests/publish.bend @@ -11,6 +11,7 @@ import ../src/io/file.bend as F import ../src/ez/quiet.bend as Q import ../src/check/kit.bend as Check import ../src/check/world.bend as W +import ../src/check/out.bend as O # the repo being published: a nested layout with an import across it, which is # the shape that makes the file walk worth checking. One comment is not ASCII, @@ -58,10 +59,10 @@ def ours(+here: String, +entry: String) -> IO(String): # package: the proof of work reports as it goes, on the same stream. def theirs(+repo: String, +port: String) -> IO(String): do IO: - +out : String <- R.exec(W.inside(repo, ["env", + +out : String <- R.exec(O.inside(repo, ["env", "BEND_HUB=http://127.0.0.1:" ++ port, "bend", "src/lib.bend", "--publish"])) - return W.starting(String.lines(R.text(out)), "0x") + return O.starting(String.lines(R.text(out)), "0x") # the two hashes, and then the two manifests the hashes are taken over. The # manifests are compared with their trailing blank dropped from both sides: @@ -74,7 +75,7 @@ def compare(+here: String, +root: String, +port: String) -> IO(Unit): +out : String <- ours(here, root ++ "/repo/src/lib.bend") +said : List<&2, String> <- IO.pure(List<&2, String>, String.lines(Q.filter(R.text(out)))) - Check.eq_str("ez computes the hash bend publishes", W.nth(said, 0n), got) + Check.eq_str("ez computes the hash bend publishes", O.nth(said, 0n), got) +man : Maybe<&2, String> <- F.read(root ++ "/hub/" ++ got ++ "/manifest") Check.eq_str("ez computes the manifest bend publishes", Q.chomp(String.join(List.drop(&2, String, said, 2n), "\n")), diff --git a/tests/publishing.bend b/tests/publishing.bend index 55facfe..4538c56 100644 --- a/tests/publishing.bend +++ b/tests/publishing.bend @@ -14,6 +14,7 @@ import ../src/ez/quiet.bend as Q import ../src/pub/plan.bend as P import ../src/check/kit.bend as Check import ../src/check/world.bend as W +import ../src/check/out.bend as O # a check whose answer is a yes or a no def yes(name: String, ok: Bool) -> IO(Unit): @@ -56,7 +57,7 @@ def path() -> IO(String): # assignments before the command, and `W.inside` has already put an `env` # there. def ez(+repo: String, +app: String, vars: List<&2, String>, args: List<&2, String>) -> List<&2, String>: - W.inside(app, List.append(&2, String, vars, + O.inside(app, List.append(&2, String, vars, List.append(&2, String, [repo ++ "/bin/ez.bin"], args))) # the project being published: the nested layout `tests/publish.bend` uses, so @@ -120,11 +121,11 @@ def consumer(+root: String, +hub: String, +hash: String) -> IO(Unit): _w : Bool <- F.write(root ++ "/consumer/main.bend", "import Base\nimport " ++ hash ++ "/lib.bend as Lib\n\n" ++ "def main() -> U32:\n Lib.quad(11)\n") - +out : String <- R.exec(W.inside(root ++ "/consumer", + +out : String <- R.exec(O.inside(root ++ "/consumer", ["env", "BEND_HUB=" ++ hub, "BEND_LIB=" ++ root ++ "/consumer/lib", "bend", "main.bend"])) Check.eq_str("a consumer's import of that name resolves and runs", - W.last(said(out)), "44") + O.last(said(out)), "44") # the tree clean, the hub up, and the package sent. Two lines come back: the # name ez computed, and the import line a consumer would write. Before the @@ -137,11 +138,11 @@ def publishes(+repo: String, +app: String, +root: String, +hub: String) -> IO(St yes("publish sends from a tree whose only extra files are ignored", R.ok(out)) +ls : List<&2, String> <- IO.pure(List<&2, String>, reported(out)) - +hash : String <- IO.pure(String, W.nth(ls, 0n)) + +hash : String <- IO.pure(String, O.nth(ls, 0n)) yes("and reports a 0x name and nothing else on its first line", P.is_name(hash)) Check.eq_str("and then the import line a consumer would write", - W.nth(ls, 1n), "import " ++ hash ++ "/lib.bend as Lib") + O.nth(ls, 1n), "import " ++ hash ++ "/lib.bend as Lib") yes("and says, on stderr, the line the hub describes it by", String.contains(R.text(out), "hub description: import Base")) m : Maybe<&2, String> <- F.read(root ++ "/hub/" ++ hash ++ "/manifest") @@ -208,7 +209,7 @@ def go(+repo: String, +root: String, +port: String) -> IO(Unit): +hub = "http://127.0.0.1:" ++ port do IO: project(app) - _i : String <- R.exec(W.ez(repo, app, ["init", "myapp", "src/lib.bend"])) + _i : String <- R.exec(O.ez(repo, app, ["init", "myapp", "src/lib.bend"])) refuses.dirty(repo, app, hub) commit(app) ignored(app) diff --git a/tests/relock.bend b/tests/relock.bend index a550e88..413519e 100644 --- a/tests/relock.bend +++ b/tests/relock.bend @@ -12,6 +12,7 @@ import ../src/io/file.bend as F import ../src/ez/quiet.bend as Q import ../src/check/kit.bend as Check import ../src/check/world.bend as W +import ../src/check/out.bend as O # a check whose answer is a yes or a no def yes(name: String, ok: Bool) -> IO(Unit): @@ -31,21 +32,21 @@ def upstream(+at: String) -> IO(String): _p : String <- R.exec(["git", "-C", at, "config", "uploadpack.allowAnySHA1InWant", "true"]) +rev : String <- R.exec(["git", "-C", at, "rev-parse", "HEAD"]) - return W.line(rev) + return O.line(rev) # a project that depends on that repo, locked once with everything in place def built(+repo: String, +app: String, +url: String, +rev: String) -> IO(String): do IO: - _i : String <- R.exec(W.ez(repo, app, ["init", "myapp", "main.bend"])) - +out : String <- R.exec(W.ez(repo, app, ["add", url, rev, "src/lib.bend"])) + _i : String <- R.exec(O.ez(repo, app, ["init", "myapp", "main.bend"])) + +out : String <- R.exec(O.ez(repo, app, ["add", url, rev, "src/lib.bend"])) yes("add vendors a package from a repo", R.ok(out)) +t : Maybe<&2, String> <- F.read(app ++ "/ez.toml") - +hash : String <- IO.pure(String, W.value(F.text_of(t), "hash")) + +hash : String <- IO.pure(String, O.value(F.text_of(t), "hash")) _w : Bool <- F.write(app ++ "/main.bend", "import Base\nimport " ++ hash ++ "/lib.bend as L\n\n" ++ "def main() -> U32:\n L.double(21)\n") W.track(app) - +l : String <- R.exec(W.ez(repo, app, ["lock"])) + +l : String <- R.exec(O.ez(repo, app, ["lock"])) yes("lock writes a lock with the cache in place", R.ok(l)) return hash @@ -57,7 +58,7 @@ def again(+repo: String, +app: String, +was: String) -> IO(Unit): W.rm(app ++ "/.ez/lib") +gone : String <- R.exec(["test", "-e", app ++ "/.ez/origins.toml"]) yes("the cache is gone", Bool.not(R.ok(gone))) - +l : String <- R.exec(W.ez(repo, app, ["lock"])) + +l : String <- R.exec(O.ez(repo, app, ["lock"])) yes("lock succeeds from the ledger alone", R.ok(l)) +now : Maybe<&2, String> <- F.read(app ++ "/ez.lock.toml") Check.eq_str("and writes the same lock, to the byte", From db74fc010d0746e9808faa4a0288880ea8e94be4 Mon Sep 17 00:00:00 2001 From: Noah Gardner Date: Mon, 16 Nov 2026 12:05:24 -0500 Subject: [PATCH 4/4] build: bolt 1.66.0; macOS only for C/JS or toolchain changes [tools.bolt] v1.66.0 (bolt#398: a list-literal data table isn't measured by S010). ci.yml at actions 4ea982d: macOS runs outside the required check (actions#16), and only when C/JS effect code, the flake or ez's lock changes (actions#17). Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 2 +- ez.lock.toml | 6 +++--- ez.toml | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51d91c4..71951eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: jobs: check: - uses: Emerging-Patterns/actions/.github/workflows/nix-flake-check.yml@feaa011dafd85fecb67aa058fbcf6424cf605e86 + uses: Emerging-Patterns/actions/.github/workflows/nix-flake-check.yml@4ea982dc3e7839b05bc0bd65a3e4a2868d44e1a1 # The README's install, followed without nix on a fresh checkout: bend, # `sh bootstrap.sh`, the build, then the proof gate with the built ez. diff --git a/ez.lock.toml b/ez.lock.toml index 88fb604..e3ffb93 100644 --- a/ez.lock.toml +++ b/ez.lock.toml @@ -125,8 +125,8 @@ LICENSE = "309f5aae946e4db157750e002fb179a74ed0fe27fce09a7be68a6977b14f205f" [tools] [tools.bolt] git = "https://github.com/Emerging-Patterns/bolt" -rev = "dfb06d0e5d6362739231b90bb090535af493b8f0" -tag = "v1.65.0" +rev = "26391508a28b69077aaf59b75a80f774a455bca5" +tag = "v1.66.0" root = "." -narHash = "sha256-39sCydxFW7dWmf69CTJOXuC+j884fEhHWFKctdWCkAg=" +narHash = "sha256-gldg9U4c/Rq1W/9sdhxSPCbujQ8LpHR8edQwbM3tNXM=" entry = "main.bend" diff --git a/ez.toml b/ez.toml index 47f0721..c7e3548 100644 --- a/ez.toml +++ b/ez.toml @@ -28,8 +28,8 @@ entry = "main.bend" [tools] [tools.bolt] git = "https://github.com/Emerging-Patterns/bolt" -rev = "dfb06d0e5d6362739231b90bb090535af493b8f0" -tag = "v1.65.0" +rev = "26391508a28b69077aaf59b75a80f774a455bca5" +tag = "v1.66.0" root = "." -narHash = "sha256-39sCydxFW7dWmf69CTJOXuC+j884fEhHWFKctdWCkAg=" +narHash = "sha256-gldg9U4c/Rq1W/9sdhxSPCbujQ8LpHR8edQwbM3tNXM=" entry = "main.bend"