vomebook commited on
Commit ·
a5c30a5
1
Parent(s): 6db4908
Repair isolated release tests for download and chapter progress
Browse filesFiles changed (3)
423 unmodified lines4244254264274284294304314324334344354364374384394404414428 unmodified lines451452453454455456457423 unmodified linesroot = Path(directory)for name in ('backend', 'quality', 'scripts/coverage-anchors'):shutil.copytree(live / name, root / name)# Exercise both path-map and transition-only overlaps, plus a plain destination.changed = ('backend/app.py', 'backend/search/domain/ordering.py','backend/search/application/requests.py', 'backend/search/http/schemas.py','backend/catalog/application/metadata.py')for name in changed:source = root / namedata = source.read_bytes()if name == 'backend/app.py':data = data.replace(b'from backend.search.domain.ordering import ',b'from backend.search.domain.ordering import ')self.assertNotIn(b'from backend.search.domain.ordering import ', data)source.write_bytes(b'# Live comment shifts line numbers.\n' + data)self.assertTrue(transport_layout(root))self.assertEqual(transport_baseline(root, debt), expected)for name in changed[:-1]:with self.subTest(strict_source=name), self.assertRaisesRegex(ValueError, 'exact current source'):8 unmodified lineswith tempfile.TemporaryDirectory() as fixture_directory:history = build_coverage_history(root, Path(fixture_directory))frozen = frozen_refactor_sources(live)for name in changed[1:]:self.assertEqual((history / name).read_bytes(), frozen[name])self.assertEqual((history / 'backend/app.py').read_bytes(),(live / 'scripts/coverage-anchors/transport-parent-app.py.snapshot').read_bytes())423 unmodified lines4244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544558 unmodified lines464465466467468469470423 unmodified linesroot = Path(directory)for name in ('backend', 'quality', 'scripts/coverage-anchors'):shutil.copytree(live / name, root / name)# Unlike ordinary no-debt destinations, the audited app must match# the exact successor even when the historical proof uses frozen bytes.app = root / 'backend/app.py'original = app.read_bytes()marker = b'from backend.search.domain.ordering import 'data = original.replace(marker, b'from backend.search.domain.ordering import ')self.assertNotIn(marker, data)app.write_bytes(b'# Live comment shifts line numbers.\n' + data)self.assertTrue(transport_layout(root)) # The path map still identifies the layout.for validate in (lambda: transport_baseline(root, debt),lambda: reviewed_source(root, 'backend/app.py'),lambda: validate_migration(root)):with self.assertRaisesRegex(ValueError, r'exact current source: backend/app\.py'):validate()app.unlink()with self.assertRaises(FileNotFoundError) as error:transport_baseline(root, debt)self.assertEqual(error.exception.filename, str(app))app.write_bytes(original)# Exercise both path-map and transition-only overlaps, plus a plain destination.changed = ('backend/search/domain/ordering.py', 'backend/search/application/requests.py','backend/search/http/schemas.py', 'backend/catalog/application/metadata.py')for name in changed:source = root / namesource.write_bytes(b'# Live comment shifts line numbers.\n' + source.read_bytes())self.assertEqual(transport_baseline(root, debt), expected)for name in changed[:-1]:with self.subTest(strict_source=name), self.assertRaisesRegex(ValueError, 'exact current source'):8 unmodified lineswith tempfile.TemporaryDirectory() as fixture_directory:history = build_coverage_history(root, Path(fixture_directory))frozen = frozen_refactor_sources(live)for name in changed:self.assertEqual((history / name).read_bytes(), frozen[name])self.assertEqual((history / 'backend/app.py').read_bytes(),(live / 'scripts/coverage-anchors/transport-parent-app.py.snapshot').read_bytes())
61 unmodified lines6263646566673368 unmodified lines343634373438343934403441344234433444344534463447344853 unmodified lines350235033504350535063507350835093510351135123513351439 unmodified lines355435553556355735583559356035613562356335643565356650 unmodified lines361736183619362036213622362336243625362636273628362942 unmodified lines367236733674367536763677367836793680368136823683368435 unmodified lines372037213722372337243725372637273728372937303731373265 unmodified lines379837993800380138023803380438053806380738083809381061 unmodified lines(self.root / "scripts/check_python_static.py").write_bytes((ROOT / "scripts/check_python_static.py").read_bytes())(self.root / "scripts/sample.py").write_text("print('ok')\n")def run_check(self, *command, timeout=30, tap_stdout=False):# Replay only stdout: a Node warning on stderr is not TAP input.return subprocess.run(command, cwd=self.root, text=True, stdout=subprocess.PIPE,3368 unmodified linesself.assert_check(self.run_check(*check), False, "TS2769")def test_reader_chapter_exact_gate_checks_original_bounds_invariant(self):config = self.root / "jsconfig.reader-exact.json"original = load_type_config("jsconfig.reader-exact.json")config.write_text(json.dumps(original))for name in original["files"]:target = self.root / nametarget.parent.mkdir(parents=True, exist_ok=True)shutil.copyfile(ROOT / name, target)check = ["node", ROOT / "node_modules/typescript/bin/tsc", "--project", config]self.assert_check(self.run_check(*check), True, "")module = self.root / "static/reader/formats/reader-chapter-repository.js"53 unmodified linesadapter = self.root / "static/reader/pdf/pdf-first-page-worker-adapter.mjs"adapter.parent.mkdir(parents=True, exist_ok=True)original = (ROOT / "static/reader/pdf/pdf-first-page-worker-adapter.mjs").read_text()local_config = self.root / "jsconfig.reader-exact.json"project = load_type_config("jsconfig.reader-exact.json")for name in project["files"]:target = self.root / nametarget.parent.mkdir(parents=True, exist_ok=True)shutil.copyfile(ROOT / name, target)local_config.write_text(json.dumps(project))production_check = ["node", ROOT / "node_modules/typescript/bin/tsc", "--project", local_config]self.assert_check(self.run_check(*production_check), True, "")for annotation in [39 unmodified lineswith self.subTest(expression=expression):source.write_text(prefix + expression + '\n')self.assert_check(self.run_check(*check), False, diagnostic)project = load_type_config('jsconfig.reader-exact.json')for name in project['files']:target = self.root / nametarget.parent.mkdir(parents=True, exist_ok=True)shutil.copyfile(ROOT / name, target)local_config = self.root / 'jsconfig.reader-exact.json'local_config.write_text(json.dumps(project))production_check = ['node', ROOT / 'node_modules/typescript/bin/tsc', '--project', local_config]self.assert_check(self.run_check(*production_check), True, '')local = self.root / 'static/reader/search/reader-pdf-book-search.mjs'50 unmodified lineswith self.subTest(expression=expression):source.write_text(prefix + expression + '\n')self.assert_check(self.run_check(*check), False, diagnostic)project = load_type_config('jsconfig.reader-exact.json')for name in project['files']:target = self.root / nametarget.parent.mkdir(parents=True, exist_ok=True)shutil.copyfile(ROOT / name, target)local_config = self.root / 'jsconfig.reader-exact.json'local_config.write_text(json.dumps(project))production_check = ['node', ROOT / 'node_modules/typescript/bin/tsc', '--project', local_config]self.assert_check(self.run_check(*production_check), True, '')local = self.root / 'static/reader/formats/reader-text-format.mjs'42 unmodified lineswith self.subTest(expression=expression):source.write_text(prefix + expression + '\n')self.assert_check(self.run_check(*check), False, diagnostic)project = load_type_config('jsconfig.reader-exact.json')for name in project['files']:target = self.root / nametarget.parent.mkdir(parents=True, exist_ok=True)shutil.copyfile(ROOT / name, target)local_config = self.root / 'jsconfig.reader-exact.json'local_config.write_text(json.dumps(project))production_check = ['node', ROOT / 'node_modules/typescript/bin/tsc', '--project', local_config]self.assert_check(self.run_check(*production_check), True, '')local = self.root / 'static/reader/formats/reader-media-format.mjs'35 unmodified lineswith self.subTest(expression=expression):source.write_text(prefix + expression + "\n")self.assert_check(self.run_check(*check), False, diagnostic)local_config = self.root / "jsconfig.reader-exact.json"project = load_type_config("jsconfig.reader-exact.json")for name in project["files"]:target = self.root / nametarget.parent.mkdir(parents=True, exist_ok=True)shutil.copyfile(ROOT / name, target)local_config.write_text(json.dumps(project))production_check = ["node", ROOT / "node_modules/typescript/bin/tsc", "--project", local_config]self.assert_check(self.run_check(*production_check), True, "")lifecycle = self.root / "static/reader/core/reader-lifecycle.mjs"65 unmodified linesself.assert_check(self.run_check(*check), False, "TS2375")configure({**options, "exactOptionalPropertyTypes": False})self.assert_check(self.run_check(*check), True, "")local_config = self.root / "jsconfig.reader-exact.json"local_config.write_text(json.dumps(original))for name in [*original["files"], "typings/reader-security-strict.d.ts", "typings/reader-store-strict.d.ts","typings/reader-contract-strict.d.ts", "typings/reader-toc-strict.d.ts"]:target = self.root / nametarget.parent.mkdir(parents=True, exist_ok=True)shutil.copyfile(ROOT / name, target)production_check = ["node", ROOT / "node_modules/typescript/bin/tsc", "--project", local_config]self.assert_check(self.run_check(*production_check), True, "")# Block scope keeps the probes independent even in classic scripts.61 unmodified lines626364656667686970717273747576777879803368 unmodified lines344934503451345234533454345553 unmodified lines350935103511351235133514351539 unmodified lines355535563557355835593560356150 unmodified lines361236133614361536163617361842 unmodified lines366136623663366436653666366735 unmodified lines370337043705370637073708370965 unmodified lines377537763777377837793780378161 unmodified lines(self.root / "scripts/check_python_static.py").write_bytes((ROOT / "scripts/check_python_static.py").read_bytes())(self.root / "scripts/sample.py").write_text("print('ok')\n")def materialize_reader_exact_project(self, project):# Chapter progress imports ChapterLoader, whose declarations reach the# search core's SearchResult through reader-chapter-search-strict.d.ts.# Copy this transitive dependency without changing the config's root files.dependency = "static/reader/search/reader-chapter-search-core.mjs"for name in [*project["files"], dependency]:target = self.root / nametarget.parent.mkdir(parents=True, exist_ok=True)shutil.copyfile(ROOT / name, target)config = self.root / "jsconfig.reader-exact.json"config.write_text(json.dumps(project))return configdef run_check(self, *command, timeout=30, tap_stdout=False):# Replay only stdout: a Node warning on stderr is not TAP input.return subprocess.run(command, cwd=self.root, text=True, stdout=subprocess.PIPE,3368 unmodified linesself.assert_check(self.run_check(*check), False, "TS2769")def test_reader_chapter_exact_gate_checks_original_bounds_invariant(self):config = self.materialize_reader_exact_project(load_type_config("jsconfig.reader-exact.json"))check = ["node", ROOT / "node_modules/typescript/bin/tsc", "--project", config]self.assert_check(self.run_check(*check), True, "")module = self.root / "static/reader/formats/reader-chapter-repository.js"53 unmodified linesadapter = self.root / "static/reader/pdf/pdf-first-page-worker-adapter.mjs"adapter.parent.mkdir(parents=True, exist_ok=True)original = (ROOT / "static/reader/pdf/pdf-first-page-worker-adapter.mjs").read_text()local_config = self.materialize_reader_exact_project(load_type_config("jsconfig.reader-exact.json"))production_check = ["node", ROOT / "node_modules/typescript/bin/tsc", "--project", local_config]self.assert_check(self.run_check(*production_check), True, "")for annotation in [39 unmodified lineswith self.subTest(expression=expression):source.write_text(prefix + expression + '\n')self.assert_check(self.run_check(*check), False, diagnostic)local_config = self.materialize_reader_exact_project(load_type_config('jsconfig.reader-exact.json'))production_check = ['node', ROOT / 'node_modules/typescript/bin/tsc', '--project', local_config]self.assert_check(self.run_check(*production_check), True, '')local = self.root / 'static/reader/search/reader-pdf-book-search.mjs'50 unmodified lineswith self.subTest(expression=expression):source.write_text(prefix + expression + '\n')self.assert_check(self.run_check(*check), False, diagnostic)local_config = self.materialize_reader_exact_project(load_type_config('jsconfig.reader-exact.json'))production_check = ['node', ROOT / 'node_modules/typescript/bin/tsc', '--project', local_config]self.assert_check(self.run_check(*production_check), True, '')local = self.root / 'static/reader/formats/reader-text-format.mjs'42 unmodified lineswith self.subTest(expression=expression):source.write_text(prefix + expression + '\n')self.assert_check(self.run_check(*check), False, diagnostic)local_config = self.materialize_reader_exact_project(load_type_config('jsconfig.reader-exact.json'))production_check = ['node', ROOT / 'node_modules/typescript/bin/tsc', '--project', local_config]self.assert_check(self.run_check(*production_check), True, '')local = self.root / 'static/reader/formats/reader-media-format.mjs'35 unmodified lineswith self.subTest(expression=expression):source.write_text(prefix + expression + "\n")self.assert_check(self.run_check(*check), False, diagnostic)local_config = self.materialize_reader_exact_project(load_type_config("jsconfig.reader-exact.json"))production_check = ["node", ROOT / "node_modules/typescript/bin/tsc", "--project", local_config]self.assert_check(self.run_check(*production_check), True, "")lifecycle = self.root / "static/reader/core/reader-lifecycle.mjs"65 unmodified linesself.assert_check(self.run_check(*check), False, "TS2375")configure({**options, "exactOptionalPropertyTypes": False})self.assert_check(self.run_check(*check), True, "")local_config = self.materialize_reader_exact_project(original)production_check = ["node", ROOT / "node_modules/typescript/bin/tsc", "--project", local_config]self.assert_check(self.run_check(*production_check), True, "")# Block scope keeps the probes independent even in classic scripts.
1088 unmodified lines1089109010911092109310941095109610971098109911001101110211031104110511061107110811094 unmodified lines11141115111611171118111911201121112211231124112511262 unmodified lines112911301131113211331134113511361137113811391140114111422 unmodified lines11451146114711481149115014 unmodified lines1165116611671168116911701 unmodified line117211731174117511761177117811791180118111821 unmodified line11841185118611871188118911901191119211931194119511961088 unmodified lines}''')self.assertTrue(result)def test_watchdog_late_back_preserves_reader_forward_and_foreign_state(self):self.page.locator('#search-input').focus()before = self.page.evaluate('''() => {history.replaceState({...history.state, foreignSearch:{keep:1}}, '', location.href);return {url:location.href, state:history.state, rows:STATE.results.map(getResultStableId)};}''')self.page.evaluate('''() => {const path=new URL(document.querySelector('script[src*="search/reader-host/application/navigation.js"]').src).pathname.replace('search/reader-host/application/navigation.js','reader.html');navigateToReader(path+'?ext=txt&title=Delayed');history.replaceState({...history.state, foreignReader:{keep:2}}, '', location.href);}''')self.page.frame_locator('.reader-overlay').locator('body').wait_for()# The iframe's initial navigation can itself change the joint history length.opened = self.page.evaluate('({url:location.href,state:history.state,length:history.length})')self.page.evaluate('''() => {const back=history.back.bind(history);window.__releaseBack=()=>{history.back=back;back();};4 unmodified lineshistory[name]=(...args)=>{__historyWrites++;return original(...args);};}window.__returnSnapshot=readerReturnSnapshot;handleReaderMessage({origin:location.origin,source:readerHost.overlay.contentWindow,data:{type:'voice-reader-close'}});}''')recovery = self.page.get_by_role('link', name='直接打开搜索页')recovery.wait_for(state='visible', timeout=3000)self.assertEqual(self.page.evaluate('({url:location.href,state:history.state,length:history.length})'), opened)self.assertEqual(self.page.evaluate('[__backCalls,__historyWrites]'), [1, 0])self.assertTrue(self.page.evaluate('readerClosing && readerReturnSnapshot === __returnSnapshot'))# Release the sole requested traversal only after the watchdog has run.self.page.evaluate('__releaseBack()')self.page.locator('.reader-overlay').wait_for(state='detached')2 unmodified linesself.assertEqual(self.page.evaluate('STATE.results.map(getResultStableId)'), before['rows'])self.assertEqual(self.page.evaluate('document.activeElement.id'), 'search-input')self.assertEqual(self.page.locator('.reader-overlay-opening').count(), 0)self.page.evaluate('history.forward()')self.page.frame_locator('.reader-overlay').locator('body').wait_for()self.assertEqual(self.page.evaluate('({url:location.href,state:history.state,length:history.length})'), opened)self.assertEqual(self.page.evaluate('readerHost.overlay.src'), opened['state']['readerUrl'])self.assertFalse(self.page.evaluate('readerClosing'))self.assertEqual(self.page.locator('.reader-overlay-opening a').count(), 0)def test_pending_watchdog_late_frame_and_back_preserve_history(self):held = []self.page.unroute('**/static/reader.html?**')self.page.route('**/static/reader.html?**', lambda route: held.append(route))2 unmodified lineshistory.replaceState({...history.state, foreignSearch:{keep:1}}, '', location.href);return {url:location.href, state:history.state, rows:STATE.results.map(getResultStableId)};}''')with self.page.expect_request('**/static/reader.html?**'):self.page.evaluate('''() => {const path=new URL(document.querySelector('script[src*="search/reader-host/application/navigation.js"]').src)14 unmodified linesopening.wait_for(state='visible')self.assertEqual(len(held), 1)pending = self.page.evaluate('({url:location.href,state:history.state})')opening.locator('button').click()recovery = self.page.get_by_role('link', name='直接打开搜索页')recovery.wait_for(state='visible', timeout=3000)1 unmodified lineself.assertEqual(self.page.evaluate('[__backCalls,__historyWrites]'), [1, 0])self.assertTrue(self.page.evaluate('readerClosing && readerReturnSnapshot === __returnSnapshot'))self.assertEqual(self.page.evaluate('({url:location.href,state:history.state})'), pending)self._deliver_late_reader_shell(held.pop(), recovery)self.assertEqual(self.page.evaluate('[__backCalls,__historyWrites]'), [1, 0])self.assertTrue(self.page.evaluate('readerClosing && readerReturnSnapshot === __returnSnapshot'))opened = self.page.evaluate('({url:location.href,state:history.state,length:history.length})')self.assertEqual({k: opened[k] for k in pending}, pending)self.page.evaluate('__releaseBack()')self.page.locator('.reader-overlay').wait_for(state='detached')self.assertEqual(self.page.url, before['url'])1 unmodified lineself.assertEqual(self.page.evaluate('STATE.results.map(getResultStableId)'), before['rows'])self.assertEqual(self.page.evaluate('document.activeElement.id'), 'search-input')self.assertEqual(self.page.locator('.reader-overlay-opening').count(), 0)self.page.unroute('**/static/reader.html?**')self.page.route('**/static/reader.html?**', lambda route: route.fulfill(content_type='text/html', body='<body>reader</body>'))self.page.evaluate('history.forward()')self.page.frame_locator('.reader-overlay').locator('body').wait_for()self.assertEqual(self.page.evaluate('({url:location.href,state:history.state,length:history.length})'), opened)self.assertEqual(self.page.evaluate('readerHost.overlay.src'), opened['state']['readerUrl'])self.assertFalse(self.page.evaluate('readerClosing'))self.assertEqual(self.page.locator('.reader-overlay-opening a').count(), 0)1088 unmodified lines108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311444 unmodified lines11491150115111521153115411551156115711581159116011611162116311642 unmodified lines11671168116911701171117211731174117511761177117811791180118111821183118411852 unmodified lines118811891190119111921193119414 unmodified lines120912101211121212131214121512161 unmodified line1218121912201221122212231224122512261227122812291 unmodified line123112321233123412351236123712381239124012411242124312441245124612471088 unmodified lines}''')self.assertTrue(result)def _watchdog_history_probe(self):# Chromium can cache a stale renderer history.length after opening the# iframe, even after it loads. Check the browser's actual entry IDs,# URLs and position; Firefox uses length plus the real traversals.context = self.fixture.contextcdp = context.new_cdp_session(self.page) if self.fixture.browser.browser_type.name == 'chromium' else Nonedef snapshot():if cdp is None:return {'length': self.page.evaluate('history.length')}history = cdp.send('Page.getNavigationHistory')return {'length': len(history['entries']), 'index': history['currentIndex'],'entries': [(entry['id'], entry['url']) for entry in history['entries']]}return snapshotdef _assert_reader_added_one_entry(self, search, reader, reader_url):self.assertEqual(reader['length'], search['length'] + 1)if 'entries' in reader:self.assertEqual(reader['index'], search['index'] + 1)self.assertEqual(reader['entries'][:-1], search['entries'])self.assertEqual(reader['entries'][reader['index']][1], reader_url)def _assert_reader_back_history(self, snapshot, search, reader):expected = dict(reader)if 'index' in search:expected['index'] = search['index']self.assertEqual(snapshot(), expected)def _assert_reader_frame_identity(self, url):self.assertEqual(self.page.evaluate('[readerHost.overlay.src, readerHost.overlay.contentDocument.URL]'), [url, url])def test_watchdog_late_back_preserves_reader_forward_and_foreign_state(self):history_snapshot = self._watchdog_history_probe()self.page.locator('#search-input').focus()before = self.page.evaluate('''() => {history.replaceState({...history.state, foreignSearch:{keep:1}}, '', location.href);return {url:location.href, state:history.state, rows:STATE.results.map(getResultStableId)};}''')search_history = history_snapshot()self.page.evaluate('''() => {const path=new URL(document.querySelector('script[src*="search/reader-host/application/navigation.js"]').src).pathname.replace('search/reader-host/application/navigation.js','reader.html');navigateToReader(path+'?ext=txt&title=Delayed');history.replaceState({...history.state, foreignReader:{keep:2}}, '', location.href);}''')self.page.frame_locator('.reader-overlay').locator('body', has_text='reader').wait_for()opened = self.page.evaluate('({url:location.href,state:history.state})')reader_history = history_snapshot()self._assert_reader_added_one_entry(search_history, reader_history, opened['url'])self.page.evaluate('''() => {const back=history.back.bind(history);window.__releaseBack=()=>{history.back=back;back();};4 unmodified lineshistory[name]=(...args)=>{__historyWrites++;return original(...args);};}window.__returnSnapshot=readerReturnSnapshot;window.__closingFrame=readerHost.overlay;handleReaderMessage({origin:location.origin,source:readerHost.overlay.contentWindow,data:{type:'voice-reader-close'}});}''')recovery = self.page.get_by_role('link', name='直接打开搜索页')recovery.wait_for(state='visible', timeout=3000)self.assertEqual(self.page.evaluate('({url:location.href,state:history.state})'), opened)self.assertEqual(history_snapshot(), reader_history)self.assertEqual(self.page.evaluate('[__backCalls,__historyWrites]'), [1, 0])self.assertTrue(self.page.evaluate('readerClosing && readerReturnSnapshot === __returnSnapshot'))self.assertTrue(self.page.evaluate('readerHost.overlay === __closingFrame && __closingFrame.isConnected'))# Release the sole requested traversal only after the watchdog has run.self.page.evaluate('__releaseBack()')self.page.locator('.reader-overlay').wait_for(state='detached')2 unmodified linesself.assertEqual(self.page.evaluate('STATE.results.map(getResultStableId)'), before['rows'])self.assertEqual(self.page.evaluate('document.activeElement.id'), 'search-input')self.assertEqual(self.page.locator('.reader-overlay-opening').count(), 0)self._assert_reader_back_history(history_snapshot, search_history, reader_history)writes_before_forward = self.page.evaluate('__historyWrites')self.page.evaluate('history.forward()')self.page.frame_locator('.reader-overlay').locator('body', has_text='reader').wait_for()self.assertEqual(self.page.evaluate('({url:location.href,state:history.state})'), opened)self.assertEqual(history_snapshot(), reader_history)self.assertEqual(self.page.evaluate('__historyWrites'), writes_before_forward)self._assert_reader_frame_identity(opened['state']['readerUrl'])self.assertFalse(self.page.evaluate('readerClosing'))self.assertEqual(self.page.locator('.reader-overlay-opening a').count(), 0)def test_pending_watchdog_late_frame_and_back_preserve_history(self):history_snapshot = self._watchdog_history_probe()held = []self.page.unroute('**/static/reader.html?**')self.page.route('**/static/reader.html?**', lambda route: held.append(route))2 unmodified lineshistory.replaceState({...history.state, foreignSearch:{keep:1}}, '', location.href);return {url:location.href, state:history.state, rows:STATE.results.map(getResultStableId)};}''')search_history = history_snapshot()with self.page.expect_request('**/static/reader.html?**'):self.page.evaluate('''() => {const path=new URL(document.querySelector('script[src*="search/reader-host/application/navigation.js"]').src)14 unmodified linesopening.wait_for(state='visible')self.assertEqual(len(held), 1)pending = self.page.evaluate('({url:location.href,state:history.state})')reader_history = history_snapshot()self._assert_reader_added_one_entry(search_history, reader_history, pending['url'])opening.locator('button').click()recovery = self.page.get_by_role('link', name='直接打开搜索页')recovery.wait_for(state='visible', timeout=3000)1 unmodified lineself.assertEqual(self.page.evaluate('[__backCalls,__historyWrites]'), [1, 0])self.assertTrue(self.page.evaluate('readerClosing && readerReturnSnapshot === __returnSnapshot'))self.assertEqual(self.page.evaluate('({url:location.href,state:history.state})'), pending)self.assertEqual(history_snapshot(), reader_history)self._deliver_late_reader_shell(held.pop(), recovery)self.assertEqual(self.page.evaluate('[__backCalls,__historyWrites]'), [1, 0])self.assertTrue(self.page.evaluate('readerClosing && readerReturnSnapshot === __returnSnapshot'))self.assertEqual(self.page.evaluate('({url:location.href,state:history.state})'), pending)self.assertEqual(history_snapshot(), reader_history)self.page.evaluate('__releaseBack()')self.page.locator('.reader-overlay').wait_for(state='detached')self.assertEqual(self.page.url, before['url'])1 unmodified lineself.assertEqual(self.page.evaluate('STATE.results.map(getResultStableId)'), before['rows'])self.assertEqual(self.page.evaluate('document.activeElement.id'), 'search-input')self.assertEqual(self.page.locator('.reader-overlay-opening').count(), 0)self._assert_reader_back_history(history_snapshot, search_history, reader_history)self.page.unroute('**/static/reader.html?**')self.page.route('**/static/reader.html?**', lambda route: route.fulfill(content_type='text/html', body='<body>reader</body>'))writes_before_forward = self.page.evaluate('__historyWrites')self.page.evaluate('history.forward()')self.page.frame_locator('.reader-overlay').locator('body', has_text='reader').wait_for()self.assertEqual(self.page.evaluate('({url:location.href,state:history.state})'), pending)self.assertEqual(history_snapshot(), reader_history)self.assertEqual(self.page.evaluate('__historyWrites'), writes_before_forward)self._assert_reader_frame_identity(pending['state']['readerUrl'])self.assertFalse(self.page.evaluate('readerClosing'))self.assertEqual(self.page.locator('.reader-overlay-opening a').count(), 0)
tests/gates/test_lifespan_coverage_slice.py+24-11
tests/gates/test_static_checks.py+20-49
tests/reader/browser/test_reader_navigation_host.py+63-12