package main // Exhibit 19. Every card's "how" link opens the exhibit's source, the files the zoo is running. Each // is embedded in the program when the zoo is compiled (#load), so /how/ shows exactly the bytes the // running build was made from; with page.odin's switch on, the links open them on apps instead, at the // commit this zoo runs (root's mirror of the zoo's repo; `source = public` lets anyone read it there). // The check fetches every one of those files over HTTPS, from wherever the links point, and compares // it byte for byte with the file the zoo was built from. import "core:fmt" import "ratcloud:rc" e19 :: proc() -> Exhibit { return { n = 19, wing = "Building", title = "Show me how", promise = "Every exhibit shows the code that makes it work.", block = "An app's code is plain files in its repo; apps shows any commit of it, and the zoo links each exhibit to the files it was built from, so what you read is what runs.", src = {"e19_show_me_how.odin", #load("e19_show_me_how.odin", string)}, files = srcs({"page.odin", #load("page.odin", string)}, {"zoo.odin", #load("zoo.odin", string)}), show = proc(me: ^rc.User) -> string { where_ := "the actual file this program was built from, with its sha256" if how_on_apps() do where_ = fmt.tprintf(`on apps, at commit %s, the one running here`, h(how_apps_url("files", "")), h(short(how_commit(), 10))) e10, _ := exhibit(10) e9, _ := exhibit(9) return fmt.tprintf(`

Every card has a how link. Try the counter's or the doors': %s.

`, h(how_url(e10)), h(how_url(e9)), where_) }, check = proc() -> Check { b := new_browser() // a visitor: no sign-in n := 0 apps := how_on_apps() if apps && how_commit() == "" do return fail("the fact deploy.json names no commit for this zoo, so there is nothing to link to on apps") for &e in exhibits() { for f in how_files(&e) { url := how_apps_url("raw", f.path) if apps else self_url(fmt.tprintf("/how/%d?raw=%s", e.n, rc.percent_encode(f.path))) r := get(b, url) if r.status != 200 do return fail(fmt.tprintf("how for exhibit %d (%s) answered %d at %s", e.n, f.path, r.status, url)) if r.body != f.text do return fail(fmt.tprintf("how for exhibit %d shows a %s that differs from the running one (%s)", e.n, f.path, url)) n += 1 } } return pass(fmt.tprintf("%d files fetched over HTTPS from %s each identical to the file the running build was made from", n, cat("apps, at commit ", short(how_commit(), 10), ",") if apps else "the zoo's own how pages,")) }, } }