package main // Exhibit 8's upkeep. zoo-broken shows a refused manifest only until someone pushes it a valid one // (any change to its page does), so every night the job `nightly` reads zoo-broken's manifest fact for // this zoo's environment (the live zoo looks after `main`, the staging zoo after `staging`) and, if a // valid manifest has replaced the typo, puts it back: one commit on top of that branch's head that // adds `chanels = updates`, pushed as zoo-broken's creator. Root refuses the push, as it must, the // branch stays where it was, and the error is back in zoo-broken's facts. // // The key: zoo-broken's creator is the zoo's robot, `zoo-robot`, a robot creator whose only app it is, // so its key can push nothing but zoo-broken (creator.odin). Without the capability this says so and // pushes nothing. import "core:encoding/json" import "core:fmt" import "core:strings" import "ratcloud:rc" BROKEN_APP :: "zoo-broken" BROKEN_TYPO :: "chanels = updates" // `channels`, misspelt: root refuses a key it does not know Broken :: struct { result: string `json:"result"`, // still refused, put back, no key, failed, ACCEPTED branch: string `json:"branch"`, detail: string `json:"detail"`, commit: string `json:"commit,omitempty"`, output: string `json:"output,omitempty"`, at: i64 `json:"at"`, } // zoo-broken's manifest fact for this environment, as zoo-broken itself publishes it over HTTPS. broken_fact :: proc() -> json.Value { r := get(new_browser(), cat(rc.app_url(BROKEN_APP), "/manifest.json")) if r.status != 200 do return nil _, isobj := r.j.(json.Object) return r.j if isobj else nil } // Put the typo back if it is gone. broken_reassert :: proc() -> Broken { branch := "main" if env().env == "live" else "staging" m := broken_fact() if m == nil do return {result = "failed", branch = branch, detail = "zoo-broken's /manifest.json did not load"} if ok, isb := jget(m, "ok").(json.Boolean); isb && !ok { return {result = "still refused", branch = branch, detail = fmt.tprintf("its typo is still refused (commit %s, %s); nothing to do", short(jstr(m, "commit"), 7), jstr(m, "at"))} } dir := "broken" creator_git({op = "rm", dir = dir}) // a clone left behind by a run that was killed goes first defer creator_git({op = "rm", dir = dir}) r := creator_git({op = "clone", repo = BROKEN_APP, branch = branch, dir = dir}) if r.code == -1 && strings.has_prefix(r.out, "refused") do return {result = "no key", branch = branch, detail = cat("a valid manifest replaced the typo, and this zoo may not run git as ", CREATOR, " (", r.out, ")")} if r.code != 0 do return {result = "failed", branch = branch, detail = fmt.tprintf("could not clone zoo-broken's %s: %s", branch, r.out)} conf := creator_git({op = "read", dir = dir, path = "ratcloud.conf"}) if conf.code != 0 do return {result = "failed", branch = branch, detail = cat("could not read its ratcloud.conf: ", conf.out)} for line in strings.split_lines(conf.out) { if strings.has_prefix(strings.trim_space(line), "chanels") do return {result = "ACCEPTED", branch = branch, detail = fmt.tprintf("zoo-broken's %s already holds the typo, yet its manifest fact says ok: root took a manifest it must refuse", branch)} } if w := creator_git({op = "write", dir = dir, path = "ratcloud.conf", data = cat(strings.trim_right(conf.out, "\n"), "\n", BROKEN_TYPO, "\n")}); w.code != 0 do return {result = "failed", branch = branch, detail = cat("could not write the typo: ", w.out)} if c := creator_git({op = "commit", dir = dir, all = true, message = "zoo-broken: the deliberate typo again (exhibit 8), put back by the zoo's nightly job"}); c.code != 0 do return {result = "failed", branch = branch, detail = cat("could not commit the typo: ", c.out)} commit := creator_git({op = "rev-parse", dir = dir, rev = "HEAD"}).out p := creator_git({op = "push", dir = dir, branch = branch}) out := unremote(p.out) if p.code == 0 do return {result = "ACCEPTED", branch = branch, commit = commit, output = out, detail = "root ACCEPTED a push whose ratcloud.conf has an unknown key"} m = broken_fact() if ok, isb := jget(m, "ok").(json.Boolean); !isb || ok || jstr(m, "commit") != commit { return {result = "failed", branch = branch, commit = commit, output = out, detail = cat("the push was refused, but not for its manifest: ", clip(out, 200))} } return {result = "put back", branch = branch, commit = commit, output = out, detail = fmt.tprintf("a valid manifest had replaced the typo; put it back on top of %s as %s and root refused it: %s", branch, short(commit, 7), jstr(m, "error"))} }