jetstream v2 in zig stream.waow.tech
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127#!/usr/bin/env python3"""Run Stream through the pinned upstream Jetstream V2 oracle offline.
The Go test lives in this repository, but is overlaid into upstream's``internal/oracle`` package for compilation. That deliberately reuses thepinned simulator, JSS reader, event-log normalizer, final-state model, publicclient, and comparison code instead of growing a second interpretation here."""
import jsonimport osfrom pathlib import Pathimport platformimport subprocessimport tempfile
PIN = "289b0328c2e1a0ccf8c870cb45de0b2397de19fb"ROOT = Path(__file__).resolve().parents[1]UPSTREAM = Path( os.environ.get( "STREAM_UPSTREAM_REPO", Path.home() / "github.com/bluesky-social/jetstream", )).resolve()SOURCE = ROOT / "tests/upstream_oracle/stream_differential_test.go"FAULT_SOURCE = ROOT / "tests/upstream_oracle/stream_fault_differential_test.go"RESTART_SOURCE = ROOT / "tests/upstream_oracle/stream_restart_predicate_test.go"RESYNC_CAPACITY_SOURCE = ROOT / "tests/upstream_oracle/stream_resync_capacity_test.go"STREAM_BIN = (ROOT / "zig-out/bin/stream").resolve()
def output(*args: str, cwd: Path) -> str: return subprocess.check_output(args, cwd=cwd, text=True).strip()
def go_binary() -> str: explicit = os.environ.get("STREAM_GO") if explicit: return explicit if "go1.26.5 " in output("go", "version", cwd=ROOT): return "go" modcache = Path(output("go", "env", "GOMODCACHE", cwd=ROOT)) goos = {"Darwin": "darwin", "Linux": "linux"}.get(platform.system()) machine = {"arm64": "arm64", "aarch64": "arm64", "x86_64": "amd64"}.get( platform.machine() ) if goos is None or machine is None: raise SystemExit(f"unsupported cached Go toolchain platform: {platform.platform()}") cached = ( modcache / f"golang.org/toolchain@v0.0.1-go1.26.5.{goos}-{machine}" / "bin/go" ) if not cached.is_file(): raise SystemExit( "Go 1.26.5 is not available offline; install or cache it before this contract" ) return str(cached)
def main() -> None: if not STREAM_BIN.is_file(): raise SystemExit("missing zig-out/bin/stream; run `zig build -Doptimize=ReleaseSafe`") if not (UPSTREAM / "go.mod").is_file(): raise SystemExit(f"pinned upstream checkout not found at {UPSTREAM}")
head = output("git", "rev-parse", "HEAD", cwd=UPSTREAM) if head != PIN: raise SystemExit(f"upstream pin mismatch: want {PIN}, got {head}") go = go_binary() run_pattern = os.environ.get( "STREAM_ORACLE_RUN", "^TestStream(Differential|ReplayFault|FrameFault|Adversarial|ResyncCapacity|BootstrapControls|BackfillWorkerControls)Oracle$", )
# -overlay can add a test file to an existing Go package. Compiling it as # part of internal/oracle means Go's internal-package rule remains intact, # while the authoritative source and every committed edit stay in Stream. virtual = UPSTREAM / "internal/oracle/stream_differential_test.go" fault_virtual = UPSTREAM / "internal/oracle/stream_fault_differential_test.go" restart_virtual = UPSTREAM / "internal/oracle/stream_restart_predicate_test.go" resync_capacity_virtual = UPSTREAM / "internal/oracle/stream_resync_capacity_test.go" with tempfile.TemporaryDirectory(prefix="stream-differential-oracle-") as tmp: overlay = Path(tmp) / "overlay.json" overlay.write_text( json.dumps( { "Replace": { str(virtual): str(SOURCE.resolve()), str(fault_virtual): str(FAULT_SOURCE.resolve()), str(restart_virtual): str(RESTART_SOURCE.resolve()), str(resync_capacity_virtual): str(RESYNC_CAPACITY_SOURCE.resolve()), } } ), encoding="utf-8", ) env = os.environ.copy() env.update( { "GOPROXY": "off", "GOSUMDB": "off", "GOTOOLCHAIN": "local", "STREAM_ORACLE_BIN": str(STREAM_BIN), "STREAM_ORACLE_EXPECTED_PIN": PIN, } ) subprocess.run( [ go, "test", f"-overlay={overlay}", "-count=1", f"-run={run_pattern}", "-v", "./internal/oracle", ], cwd=UPSTREAM, env=env, check=True, )
if __name__ == "__main__": main()