mirror of
https://github.com/piabrota/mu.git
synced 2026-11-11 17:38:13 -10:00
This repo was a copy of Ouroboric's umbrella. It becomes piabrota's company umbrella, ready for pirsig to manage it. - DOGMA.md holds ten invariants, and AGENTS.md follows it. - PIABROTA.md indexes the org's public repos, rendered by minijinja-cli from scripts/piabrota/repos.toml. - docs/DECISION_MODELS.md tracks decision models and where routines run. - brain/ and pirsig.toml seed PARA, smart notes and the decision track record. - The org, the bot name, the charter, the roadmap, the budget, the legal page and the palette change. - Ouroboric's logos go. Its licences stay, with credit in NOTICE.md. Dated records keep their text. - The Go component template becomes a Rust one, rendered by minijinja-cli. - Every plot is drawn with archify, pinned in forks/archify. Mermaid, D2 and diagrams.sh go. Co-Authored-By: Claude Opus 5.5 <[email protected]>
73 lines
3.1 KiB
Python
73 lines
3.1 KiB
Python
# Fake GitHub API for the script tests. Logs each request to LOG as one JSON line.
|
|
# python3 -I fake-github.py LOG PORTFILE
|
|
# FAKE_PEM: the key the manifest conversion returns. FAKE_GIT_ROOT: where a created repo gets its
|
|
# bare git repo, so a test can push to file://$FAKE_GIT_ROOT/<org>/<repo>.git. FAKE_USER: the login
|
|
# that GET /user returns, and the account that POST /user/repos creates in (default acme).
|
|
import json
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
|
|
log, portfile = sys.argv[1:3]
|
|
repos = set() # (org, name) of the repos created; "taken" exists in every org
|
|
|
|
|
|
def repo_routes(method, path, body):
|
|
if method == "GET" and (m := re.fullmatch(r"/repos/([^/]+)/([^/]+)", path)):
|
|
org, name = m.groups()
|
|
return (200, {"name": name}) if name == "taken" or (org, name) in repos else None
|
|
if method == "GET" and path == "/user":
|
|
return 200, {"login": os.environ.get("FAKE_USER", "acme")}
|
|
if method == "POST" and (m := re.fullmatch(r"/orgs/([^/]+)/repos|/user/repos", path)):
|
|
org = m.group(1) or os.environ.get("FAKE_USER", "acme")
|
|
name = json.loads(body)["name"]
|
|
if name == "taken" or (org, name) in repos:
|
|
return 422, {"message": "Repository creation failed."}
|
|
repos.add((org, name))
|
|
subprocess.run(["git", "init", "-q", "--bare", "-b", "main",
|
|
os.path.join(os.environ["FAKE_GIT_ROOT"], org, name + ".git")], check=True)
|
|
return 201, {"name": name}
|
|
return None
|
|
|
|
|
|
def routes():
|
|
return {
|
|
("GET", "/orgs/piabrota/installation"): (200, {"id": 42}),
|
|
("POST", "/app/installations/42/access_tokens"):
|
|
(201, {"token": "ghs_FAKE", "expires_at": "2099-01-01T00:00:00Z"}),
|
|
("POST", "/app-manifests/good-code/conversions"):
|
|
(201, {"id": 7, "slug": "piabrota-pr-bot", "client_id": "Iv1.test",
|
|
"client_secret": "SECRET_CS", "webhook_secret": None,
|
|
"pem": open(os.environ["FAKE_PEM"]).read() if "FAKE_PEM" in os.environ else ""}),
|
|
}
|
|
|
|
|
|
class Handler(BaseHTTPRequestHandler):
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
def handle_any(self):
|
|
n = int(self.headers.get("Content-Length") or 0)
|
|
body = self.rfile.read(n).decode() if n else ""
|
|
with open(log, "a") as f:
|
|
f.write(json.dumps({"method": self.command, "path": self.path,
|
|
"auth": self.headers.get("Authorization", ""), "body": body}) + "\n")
|
|
code, obj = repo_routes(self.command, self.path, body) \
|
|
or routes().get((self.command, self.path), (404, {"message": "Not Found"}))
|
|
data = json.dumps(obj).encode()
|
|
self.send_response(code)
|
|
self.send_header("Content-Type", "application/json")
|
|
self.send_header("Content-Length", str(len(data)))
|
|
self.end_headers()
|
|
self.wfile.write(data)
|
|
|
|
do_GET = do_POST = handle_any
|
|
|
|
|
|
server = HTTPServer(("127.0.0.1", 0), Handler)
|
|
with open(portfile, "w") as f:
|
|
f.write(str(server.server_address[1]))
|
|
server.serve_forever()
|