1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/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 the
pinned simulator, JSS reader, event-log normalizer, final-state model, public
client, and comparison code instead of growing a second interpretation here.
"""
import json
import os
from pathlib import Path
import platform
import subprocess
import 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()