Skip to content

Commit caebb82

Browse files
committed
ci(search): verify locked Git engine and matching native bridge
1 parent be3246f commit caebb82

1 file changed

Lines changed: 62 additions & 21 deletions

File tree

‎.github/workflows/search_note_annotations.yml‎

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
OTZARIA_REQUIRE_SEARCH_ENGINE: '1'
3838
# Replace only with the independently reviewed engine notes commit.
3939
NOTE_ENGINE_COMMIT: f0235013e0ffc6a0e1f263d9a4767620fb4d016b
40-
LEGACY_ENGINE_SHA256: 1101a8048ca9076d0e8714c68ae3f9a44b82d2c2fe2075a8c8eb13e9a938cd8b
40+
LEGACY_ENGINE_COMMIT: b78d36eaffcb2a5fa679d34a52133512ee55c084
4141

4242
steps:
4343
- name: Checkout app
@@ -95,7 +95,8 @@ jobs:
9595
dart run tool/generate_search_index.dart
9696
dart run tool/generate_settings_l10n.dart
9797
98-
- name: Verify engine revision and the locked legacy package
98+
- name: Verify engine revision and the locked Git baseline
99+
id: legacy_package
99100
run: |
100101
set -euo pipefail
101102
python3 - <<'PY'
@@ -124,20 +125,30 @@ jobs:
124125
package_root = Path(unquote(parsed.path)).resolve(strict=True)
125126
version = re.search(r'^version:\s*(\S+)\s*$', (package_root / 'pubspec.yaml').read_text(), re.M)
126127
if version is None or version.group(1) != '7.0.1' or package_root == engine:
127-
raise SystemExit('The legacy phase requires the locked, hosted engine package 7.0.1')
128+
raise SystemExit('The baseline requires the locked Git package 7.0.1')
128129
lock = Path('pubspec.lock').read_text()
129130
entry = re.search(r'^ otzaria_search_engine:\n(.*?)(?=^ \S|\Z)', lock, re.M | re.S)
130-
if entry is None or not re.search(r'^ source: hosted$', entry.group(1), re.M):
131-
raise SystemExit('The legacy engine must resolve from the hosted lockfile entry')
131+
if entry is None or not re.search(r'^ source: git$', entry.group(1), re.M):
132+
raise SystemExit('The baseline engine must resolve from the locked Git entry')
132133
if not re.search(r'^ version: "7\.0\.1"$', entry.group(1), re.M):
133-
raise SystemExit('The legacy lockfile version must be exactly 7.0.1')
134+
raise SystemExit('The baseline lockfile version must be exactly 7.0.1')
135+
for key in ['ref', 'resolved-ref']:
136+
expected_git_field = f' {key}: "{os.environ["LEGACY_ENGINE_COMMIT"]}"'
137+
if expected_git_field.strip() not in entry.group(1):
138+
raise SystemExit(f'Git lockfile {key} must match the reviewed baseline')
139+
if 'https://github.com/Otzaria/otzaria_search_engine' not in entry.group(1):
140+
raise SystemExit('The baseline Git repository URL is unexpected')
134141
bridges = sorted((package_root / 'lib/src/rust').rglob('*.dart'))
135142
if len(bridges) != 8:
136143
raise SystemExit(f'Unexpected legacy bridge file count: {len(bridges)}')
137144
bridge_hash = re.search(r'int get rustContentHash => (-?\d+);',
138145
(package_root / 'lib/src/rust/frb_generated.dart').read_text())
139-
if bridge_hash is None or int(bridge_hash.group(1)) != -1026649565:
140-
raise SystemExit('The legacy Dart bridge does not match package 7.0.1')
146+
rust_hash = re.search(r'FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = (-?\d+);',
147+
(package_root / 'rust/src/frb_generated.rs').read_text())
148+
if bridge_hash is None or rust_hash is None or bridge_hash.group(1) != rust_hash.group(1):
149+
raise SystemExit('The baseline Dart and Rust bridge hashes disagree')
150+
if int(bridge_hash.group(1)) != 1526607425:
151+
raise SystemExit('The baseline bridge is not the pinned Git revision')
141152
evidence = Path('build/note-annotations')
142153
original = json.loads((evidence / 'original-manifests.json').read_text())
143154
for name, digest in original.items():
@@ -152,27 +163,52 @@ jobs:
152163
'original_manifests_sha256': original,
153164
'pubspec_lock_sha256': original['pubspec.lock'],
154165
'legacy_package_version': version.group(1),
166+
'legacy_package_source': 'git',
167+
'legacy_engine_commit': os.environ['LEGACY_ENGINE_COMMIT'],
155168
'legacy_package_root': str(package_root),
156169
'legacy_package_config_sha256': hashlib.sha256(config_path.read_bytes()).hexdigest(),
157170
'legacy_bridge_sha256': {str(p.relative_to(package_root)): hashlib.sha256(p.read_bytes()).hexdigest() for p in bridges},
158171
'legacy_rust_content_hash': int(bridge_hash.group(1)),
159-
'legacy_release': 'precompiled_1040c89b1c5fdf1ee19ca1cb00468d4c',
160-
'legacy_sha256': os.environ['LEGACY_ENGINE_SHA256'],
172+
'legacy_features': ['sqlite-host', 'semantic'],
161173
}
162174
(evidence / 'provenance.json').write_text(json.dumps(provenance, indent=2) + '\n')
175+
with Path(os.environ['GITHUB_OUTPUT']).open('a') as output:
176+
output.write(f'root={package_root}\n')
163177
PY
164178
rustc -Vv > build/note-annotations/rust-toolchain.txt
165179
cargo -V >> build/note-annotations/rust-toolchain.txt
166180
167-
# This control fails closed if the locked package is upgraded from 7.0.1.
168-
- name: Download and verify legacy engine
181+
# Build the native library from the exact Git package pinned by the app.
182+
# Its generated FRB bridge is different from the old hosted release.
183+
- name: Build locked Git baseline with app native features
184+
id: legacy
169185
run: |
170186
set -euo pipefail
187+
package_root="${{ steps.legacy_package.outputs.root }}"
188+
test -f "$package_root/rust/Cargo.lock"
189+
cargo build --manifest-path "$package_root/rust/Cargo.toml" \
190+
--locked --release --lib --jobs 2 --no-default-features \
191+
--features sqlite-host,semantic \
192+
--target-dir "$RUNNER_TEMP/note-annotations-cargo"
171193
mkdir -p "$RUNNER_TEMP/note-annotation-binaries/legacy"
172194
library="$RUNNER_TEMP/note-annotation-binaries/legacy/libsearch_engine.so"
173-
curl -fSL --retry 3 --retry-delay 5 -o "$library" \
174-
https://github.com/Otzaria/otzaria_search_engine/releases/download/precompiled_1040c89b1c5fdf1ee19ca1cb00468d4c/x86_64-unknown-linux-gnu_libsearch_engine.so
175-
printf '%s %s\n' "$LEGACY_ENGINE_SHA256" "$library" | sha256sum -c -
195+
cp "$RUNNER_TEMP/note-annotations-cargo/release/libsearch_engine.so" "$library"
196+
sha256="$(sha256sum "$library" | cut -d ' ' -f1)"
197+
echo "sha256=$sha256" >> "$GITHUB_OUTPUT"
198+
python3 - <<'PY'
199+
import hashlib
200+
import json
201+
import os
202+
from pathlib import Path
203+
204+
library = Path(os.environ['RUNNER_TEMP']) / 'note-annotation-binaries/legacy/libsearch_engine.so'
205+
digest = hashlib.sha256(library.read_bytes()).hexdigest()
206+
evidence = Path('build/note-annotations/provenance.json')
207+
provenance = json.loads(evidence.read_text())
208+
provenance.update(legacy_library=str(library), legacy_sha256=digest)
209+
evidence.write_text(json.dumps(provenance, indent=2) + '\n')
210+
print(f'Locked Git baseline SHA-256: {digest}')
211+
PY
176212
177213
- name: Build candidate with the app native features
178214
run: |
@@ -208,7 +244,7 @@ jobs:
208244
env:
209245
OTZARIA_EXPECT_NOTE_ANNOTATIONS: '0'
210246
OTZARIA_SEARCH_ENGINE_LIBRARY_PATH: ${{ runner.temp }}/note-annotation-binaries/legacy/libsearch_engine.so
211-
OTZARIA_EXPECTED_SEARCH_ENGINE_SHA256: ${{ env.LEGACY_ENGINE_SHA256 }}
247+
OTZARIA_EXPECTED_SEARCH_ENGINE_SHA256: ${{ steps.legacy.outputs.sha256 }}
212248
run: |
213249
flutter test --no-pub -j 2 --reporter expanded \
214250
--file-reporter json:build/note-annotations/legacy-tests.json \
@@ -364,7 +400,7 @@ jobs:
364400
from collections import Counter
365401
from pathlib import Path
366402
367-
expected = {
403+
minimum = {
368404
'snippet_note_annotations_test.dart': 26,
369405
'snippet_note_annotations_engine_test.dart': 4,
370406
'snippet_builder_test.dart': 27,
@@ -375,6 +411,7 @@ jobs:
375411
'text_book_search_engine_route_test.dart': 41,
376412
}
377413
summaries = []
414+
baseline_counts = None
378415
for mode in ['legacy', 'candidate']:
379416
events = [json.loads(line) for line in Path(f'build/note-annotations/{mode}-tests.json').read_text().splitlines() if line.strip()]
380417
suites = {e['suite']['id']: Path(e['suite']['path']).name for e in events if e['type'] == 'suite'}
@@ -388,11 +425,15 @@ jobs:
388425
if any(e.get('skipped', False) or e.get('result') != 'success'
389426
for e in events if e['type'] == 'testDone'):
390427
raise SystemExit(f'{mode}: failed or skipped tests')
391-
if len(done) != 169 or len({e['testID'] for e in done}) != 169:
392-
raise SystemExit(f'{mode}: expected 169 distinct completed tests')
428+
if len(done) < 169 or len({e['testID'] for e in done}) != len(done):
429+
raise SystemExit(f'{mode}: expected at least 169 unique completed tests')
393430
counts = Counter(suites[tests[e['testID']]['suiteID']] for e in done)
394-
if dict(counts) != expected:
395-
raise SystemExit(f'{mode}: unexpected test suite coverage: {dict(counts)}')
431+
if set(counts) != set(minimum) or any(counts[k] < minimum[k] for k in minimum):
432+
raise SystemExit(f'{mode}: required suite missing or below coverage minimum: {dict(counts)}')
433+
if baseline_counts is None:
434+
baseline_counts = counts
435+
elif counts != baseline_counts:
436+
raise SystemExit(f'{mode}: suite coverage differs between the locked and candidate engines')
396437
summaries.append({'mode': mode, 'passed': len(done), 'skipped': 0, 'suites': dict(counts)})
397438
Path('build/note-annotations/summary.json').write_text(json.dumps(summaries, indent=2) + '\n')
398439
print(json.dumps(summaries, indent=2))

0 commit comments

Comments
 (0)