Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/store/tests/compare.py # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / store / tests / compare.py` 488 lines ยท 22710 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # ORACLE: host test helper for store/tests/compare.sh (outside tool, not product code). 3 # sample CATALOG PROJECTS FIXTURE the sampled project names, one per line (rule in compare.sh) 4 # fetch PORT DIR LISTFILE every page of LISTFILE; HTML-like pages also with the JSON Accept 5 # key PATH KIND the file name fetch gives PATH (KIND html or json) 6 # same A B every page of fetch dir A equals B (status, type, bytes) 7 # radicle A B B equals A apart from the rules listed in RULES: the Radicle id 8 # replaced by the store id, the forge-nav row without "Open builds" 9 # (server/noopen.om ohnav), the footer, the developer rows, the 10 # clone panel and the JSON clone object. A STORE line must be 11 # exactly what its rule makes of the MAIN line; any other difference 12 # is printed as BAD with its page and line, and the exit is 1 13 # replay LISTING the same rules over a kept `radicle` listing, offline (no pages) 14 # manylines CATALOG N N well-formed public lines (names many-NNN) 15 # signin PORT KEY / star PORT SESSION REPO / stars PORT REPO social helpers (forge sign-in) 16 # env (radicle, replay): COMPARE_FIXTURES, the names of the fixture projects compare.sh signs with its 17 # KEY (space-separated), and COMPARE_FIXTURE_KEY, the SHA256 fingerprint of that key. The owner key of a 18 # fixture page must be exactly COMPARE_FIXTURE_KEY, and fixtures keep their own one-to-one table 19 # ("owner key of fixtures"): KEY need not be the store's owner key (the store's own projects keep the 20 # "owner key" table, one key for the owner name over all of them). 21 import base64, difflib, hashlib, http.client, json, os, re, subprocess, sys, urllib.parse 22 23 OWNER = "drakestapleton" 24 JSON = "application/json" 25 SEAM = 'Open builds' 26 PLAIN = re.compile(r"/(raw|archive)/|\.(patch|diff|json)$|\.json\?") 27 FIXTURES = set(os.environ.get("COMPARE_FIXTURES", "").split()) 28 FIXKEY = os.environ.get("COMPARE_FIXTURE_KEY", "") 29 30 31 def owner_pair(name, delegate, fp): 32 # the owner-key pair of a page: fixtures are signed with compare.sh's KEY, which must be exactly 33 # COMPARE_FIXTURE_KEY; the store's own projects pair the owner name with one key over the run 34 if name in FIXTURES: 35 return ("owner key of fixtures", delegate, fp) if fp == FIXKEY else None 36 return ("owner key", delegate, fp) 37 38 39 def key(path, kind): 40 return hashlib.sha256((kind + " " + path).encode()).hexdigest()[:32] 41 42 43 def get(port, path, headers=None): 44 c = http.client.HTTPConnection("127.0.0.1", port, timeout=900) 45 c.request("GET", path, headers=headers or {}) 46 r = c.getresponse() 47 body = r.read() 48 out = (r.status, r.getheader("Content-Type", ""), r.getheader("Location", ""), body, r.getheaders()) 49 c.close() 50 return out 51 52 53 def fetch(port, d, listfile): 54 paths = [l.rstrip("\n") for l in open(listfile, encoding="utf-8") if l.strip()] 55 idx = [] 56 for p in paths: 57 kinds = ["html"] if PLAIN.search(p) else ["html", "json"] 58 for k in kinds: 59 st, ct, loc, body, _ = get(port, p, {"Accept": JSON} if k == "json" else {}) 60 name = key(p, k) 61 open(os.path.join(d, name), "wb").write(body) 62 idx.append("\t".join([name, k, p, str(st), ct, loc.replace(str(port), "PORT"), str(len(body)), 63 hashlib.sha256(body).hexdigest()])) 64 open(os.path.join(d, "index.tsv"), "w", encoding="utf-8").write("\n".join(idx) + "\n") 65 66 67 def index(d): 68 rows = {} 69 for l in open(os.path.join(d, "index.tsv"), encoding="utf-8"): 70 f = l.rstrip("\n").split("\t") 71 rows[f[0]] = f 72 return rows 73 74 75 def same(a, b): 76 A, B = index(a), index(b) 77 bad = 0 78 for k, ra in A.items(): 79 rb = B.get(k) 80 if rb is None or ra[3:] != rb[3:]: 81 bad += 1 82 print("DIFFER %s %s: %s / %s" % (ra[1], ra[2], ra[3:7], rb[3:7] if rb else None)) 83 print("pages=%d identical=%d differ=%d" % (len(A), len(A) - bad, bad)) 84 return 1 if bad or len(A) != len(B) else 0 85 86 87 # radicle A B: the only differences STORE may show against MAIN. Every rule is a form that the kept 88 # listing of the run at `babf1706` shows (differing-lines-`babf1706080e75dff2f8dd412e0d62ecbc538d44`.txt), 89 # and a STORE line is accepted only when it is exactly what the rule makes of the MAIN line or lines 90 # it replaces. No line passes for merely naming an id. A rule gets the MAIN lines, the STORE lines and 91 # the project name of the page; it returns None, or the (table, MAIN value, STORE value) pairs that 92 # must stay one to one over the whole run (a Radicle id and its store id, an owner and its key). 93 # ids: rad:z... (the Radicle build before the Radicle-text removal), a bare z... in a "rid" value (after it, 94 # `c1f107df`: the old id without its prefix), git:<64 hex> (the store build) 95 IDS = re.compile(r'rad:z[0-9A-Za-z]+|git:[0-9a-f]{64}|(?<="rid":")z[0-9A-Za-z]+') 96 RIDF = r'((?:)?z[0-9A-Za-z]+(?:)?)' # a Radicle id as an HTML page prints it 97 CODE = '' 98 FOOT = ('

INTERPLANE Forge: agents express intent; the forge retains authority. %s' 99 " served by forged, a seeded-Omega web server, with no JavaScript.

") 100 FOOT_A = FOOT % "Built on Radicle (Heartwood): repositories are Radicle projects" 101 FOOT_A2 = FOOT % "Repositories are" # the footer after the Radicle-text removal (`c1f107df`) 102 FOOT_B = FOOT % "Repositories are plain Git kept in Interplane's own signed store," 103 PATCH = "
Patch
A proposed change, %s The list is under " 104 PATCH_A = PATCH % "sent over Radicle and reviewed before it is merged." 105 PATCH_B = PATCH % "reviewed before it is merged. This forge does not show proposed changes from its own store yet." 106 PANEL = '

Get this repository

' 107 PANEL_A = re.compile(PANEL + "
Radicle
" + CODE + "rad clone rad:" + RIDF + "
" 108 "(
Git over HTTPS
" + CODE + r"git clone )https://www\.aienos\.com/rad/\1\.git" 109 "(
Source archive of .*)", re.S) 110 OBJECT_A = re.compile(r'"clone":\{"rad":"rad:(z[0-9A-Za-z]+)","rad_clone":"rad clone rad:\1",' 111 r'"git_https":"https://www\.aienos\.com/rad/\1\.git"(.*)', re.S) 112 STORE_GIT = "https://interplane.io/projects/%s/repo.git" 113 DEV_RID = re.compile(r"
RID
The Radicle ID: the project's permanent name on Radicle, the open network" 114 r" that stores and signs it\. This one is " + CODE + "rad:" + RIDF + r"\.
") 115 DEV_DELEGATE = re.compile(r"
Delegate
A key that may sign the project's official versions\. This forge" 116 r" lists the project under ([^;<]+); " + CODE + "rad inspect rad:" + RIDF + 117 r" --delegates prints the project's own list\.
") 118 DEV_SEED = ("
Seed
A Radicle node that keeps a copy of the project and serves it to others. The count" 119 " below is read from this node's routing table.
") 120 DEV_ID = (r"
ID
The project's permanent id on Interplane: the SHA-256 of its first signed record\." 121 " This one is " + CODE + r'git:([0-9a-f]{64})\. Its old Radicle ID,' 122 " kept only so that old links still work: " + CODE + r"rad:%s\.
") 123 DEV_OWNER = (r"
Owner
The key that signs every record of the project\. This forge lists the project" 124 " under %s; its key is " + CODE + r"(SHA256:[A-Za-z0-9+/]{43})\.
") 125 126 127 def project(path): 128 f = path.split("?")[0].split("/") 129 n = f[2] if len(f) > 2 else "" 130 return n[:-5] if len(f) == 3 and n.endswith(".json") else n 131 132 133 def r_ids(a, b, name): 134 # the same line with a Radicle id where STORE has the store id; ids equal on both sides stay as they are 135 if IDS.split(a[0]) != IDS.split(b[0]): 136 return None 137 d = [(x, y) for x, y in zip(IDS.findall(a[0]), IDS.findall(b[0])) if x != y] 138 if not d or not all(x.startswith(("rad:", "z")) and y.startswith("git:") for x, y in d): 139 return None 140 # a bare old id (MAIN after `c1f107df`) is the same id as rad:: one name for the one-to-one check 141 return [("id", x if x.startswith("rad:") else "rad:" + x, y) for x, y in d] 142 143 144 def r_nav(a, b, name): 145 return [] if SEAM in a[0] and '