The best way to control Claude Code, Codex and more from any computer or phone

main
sh 69 lines 3.43 KB
Raw
1 #!/bin/bash
2 set -euo pipefail
3 module_dir=$(cd "$(dirname "$0")/.." && pwd)
4 sdk=$(xcrun --sdk macosx --show-sdk-path)
5 compiler=$(xcrun --find swiftc)
6 output=$(mktemp -d)
7 trap 'rm -rf "$output"' EXIT
8 # Keep the real content view and helpers; the Expo bridge is not needed by this harness.
9 python3 - "$module_dir" "$output/main.swift" <<'PYTHON'
10 import sys
11 from pathlib import Path
12 module = Path(sys.argv[1])
13 source = (module / "ios/T3ReviewDiffView.swift").read_text()
14 source = source.replace("import ExpoModulesCore\n", "")
15 # Count entry into the real decoder without replacing the production queue or lifecycle.
16 row_decode = "try JSONDecoder().decode([ReviewDiffNativeRow].self, from: data)"
17 assert source.count(row_decode) == 1
18 source = source.replace(row_decode, "try decodeRowsForTest(data)")
19 # Instrument the real full-token decoder and accepted publication only.
20 start = source.index(" let decodedTokens = try JSONDecoder().decode(")
21 end = source.index(" DispatchQueue.main.async", start)
22 decode = source[start:end]
23 source = source[:start] + decode.replace("try JSONDecoder().decode(", "try decodeTokensForTest(") + source[end:]
24 publish = " self.contentView.tokensByRowId = decodedTokens"
25 assert source.count(publish) == 1
26 source = source.replace(publish, publish + "\n tokenDecodeProbe.publish()")
27 # Include the accepted malformed-current fallback in publication counts.
28 start = source.index(" func setTokensJson(")
29 end = source.index(" func setTokensPatchJson(", start)
30 method = source[start:end]
31 fallback = " self.contentView.tokensByRowId = [:]"
32 assert method.count(fallback) == 1
33 source = source[:start] + method.replace(fallback, fallback + "\n tokenDecodeProbe.publish()") + source[end:]
34 # Count the actual lookup's row visits only in the compiled test copy.
35 needle = """ private func resolvedFileId(for row: ReviewDiffNativeRow) -> String {
36 row.resolvedFileId
37 }"""
38 if source.count(needle) != 1:
39 raise RuntimeError("Header lookup instrumentation seam changed")
40 source = source.replace(needle, """ private func resolvedFileId(for row: ReviewDiffNativeRow) -> String {
41 HeaderLookupReads.record(row)
42 return row.resolvedFileId
43 }""")
44 stubs = """
45 public final class AppContext {}
46 open class ExpoView: UIView {
47 public required init(appContext: AppContext? = nil) { super.init(frame: .zero) }
48 @available(*, unavailable)
49 public required init?(coder: NSCoder) { fatalError("init(coder:) is unused") }
50 }
51 final class EventDispatcher {
52 var onEvent: (([String: Any]) -> Void)?
53 func callAsFunction(_ payload: [String: Any]) { onEvent?(payload) }
54 }
55 """
56 # Expo alone is stubbed; keep the real scroll container as well as the content view.
57 Path(sys.argv[2]).write_text(source + "\n" + stubs + "\n"
58 + (module / "tests/ios/main.swift").read_text() + "\n"
59 + (module / "tests/ios/anchor.swift").read_text() + "\n"
60 + (module / "tests/ios/row-decode.swift").read_text() + "\n"
61 + (module / "tests/ios/token-decode.swift").read_text() + "\n"
62 + (module / "tests/ios/geometry.swift").read_text())
63 PYTHON
64 "$compiler" -O -target "$(uname -m)-apple-ios16.1-macabi" -sdk "$sdk" \
65 -module-cache-path "$output/module-cache" \
66 -F "$sdk/System/iOSSupport/System/Library/Frameworks" \
67 "$module_dir/ios/ReviewDiffCodeLayout.swift" "$output/main.swift" \
68 -o "$output/layout-tests"
69 "$output/layout-tests"