interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / store / tests / expect_served.py
| 1 | #!/usr/bin/env python3 |
| 2 | # ORACLE: host test helper, not product code. |
| 3 | # store/tests/expect_served.py ROOT: the projects the store-reading build is expected to serve from |
| 4 | # the store at ROOT, one name a line, in catalog order; with --count only their number. Written apart |
| 5 | # from the forge (store/repos.om) and from infra/spark/forged-public.sh store_names, so a test that |
| 6 | # compares the forge's explore list with this does not compare a rule with itself. |
| 7 | # The rule (Drake, 2026-11-14: the store build serves every public catalog line): every line of |
| 8 | # ROOT/catalog.tsv whose fifth field is "public", less the deny list of server/repos.om fdeny |
| 9 | # (the names omega-pearl and aien-crypto, and the old id rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ read from |
| 10 | # the "alias" line of projects/NAME/records/1), less a line whose old id an earlier kept line already |
| 11 | # has, less lines past FAMAX (256). A store the forge refuses as a whole (store/repos.om) is not |
| 12 | # modelled here: the tests use stores that verify. |
| 13 | import sys |
| 14 | |
| 15 | DENY_NAMES = {"omega-pearl", "aien-crypto"} |
| 16 | DENY_IDS = {"z2ft64NFLsKzWttCXw6NWNbRQLggQ"} |
| 17 | FAMAX = 256 |
| 18 | |
| 19 | |
| 20 | def alias(root, name): |
| 21 | try: |
| 22 | with open(f"{root}/projects/{name}/records/1", "rb") as f: |
| 23 | for line in f.read().decode("ascii", "replace").split("\n"): |
| 24 | if line.startswith("alias "): |
| 25 | a = line[len("alias "):] |
| 26 | return a[4:] if a.startswith("rad:") else "" |
| 27 | except OSError: |
| 28 | pass |
| 29 | return "" |
| 30 | |
| 31 | |
| 32 | def served(root): |
| 33 | out, seen, pub = [], set(), 0 |
| 34 | with open(f"{root}/catalog.tsv", encoding="ascii") as f: |
| 35 | for line in f: |
| 36 | p = line.rstrip("\n").split("\t") |
| 37 | if len(p) != 5 or p[4] != "public": |
| 38 | continue |
| 39 | pub += 1 |
| 40 | if pub > FAMAX: # the table takes the first FAMAX public lines, then the deny list |
| 41 | break |
| 42 | name, a = p[0], alias(root, p[0]) |
| 43 | if name in DENY_NAMES or a in DENY_IDS: |
| 44 | continue |
| 45 | if a and a in seen: |
| 46 | continue |
| 47 | if a: |
| 48 | seen.add(a) |
| 49 | out.append(name) |
| 50 | return out |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | args = [a for a in sys.argv[1:] if a != "--count"] |
| 55 | if len(args) != 1: |
| 56 | sys.exit("usage: expect_served.py [--count] ROOT") |
| 57 | s = served(args[0].rstrip("/")) |
| 58 | print(len(s) if "--count" in sys.argv else "\n".join(s)) |