release: Евномия, новая версия, линейка юристов
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
"""Headed Chromium QA for the focused atomic graph; does not modify product code."""
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = 'http://127.0.0.1:18765/'
|
||||
OUT = Path(__file__).resolve().parents[1] / 'qa/atomic'
|
||||
NODE = 'doc:legal-corpus:code:gpk-rf:article:131'
|
||||
RUNTIME = """() => {
|
||||
const e = document.querySelector('.p-force-canvas');
|
||||
if (!e) throw Error('force canvas missing');
|
||||
let f = e[Object.keys(e).find(k => k.startsWith('__reactFiber$'))];
|
||||
for (; f; f = f.return) {
|
||||
let h = f.memoizedState, graph = null, data = null;
|
||||
while (h) {
|
||||
const v = h.memoizedState?.current, m = h.memoizedState;
|
||||
if (v && (typeof v.zoom === 'function' || typeof v.camera === 'function')) graph = v;
|
||||
if (Array.isArray(m) && m[0]?.nodes && m[0]?.links) data = m[0];
|
||||
h = h.next;
|
||||
}
|
||||
if (graph && data) return {graph, data};
|
||||
}
|
||||
throw Error('graph refs not found in React runtime');
|
||||
}"""
|
||||
|
||||
|
||||
def main():
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
errors, console_errors, failed = [], [], []
|
||||
report = {}
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=False, args=['--use-angle=metal'])
|
||||
page = browser.new_page(viewport={'width': 1440, 'height': 1000})
|
||||
page.on('pageerror', lambda error: errors.append(str(error)))
|
||||
page.on('console', lambda message: console_errors.append(message.text) if message.type == 'error' else None)
|
||||
page.on('requestfailed', lambda request: failed.append(f'{request.url}: {request.failure}'))
|
||||
page.on('response', lambda response: failed.append(f'{response.status} {response.url}') if response.status >= 400 else None)
|
||||
url = BASE + '#view=graph&level=atoms&resource_id=legal-corpus%3Acode%3Agpk-rf&fragment=' + NODE.replace(':', '%3A')
|
||||
page.goto(url, wait_until='networkidle', timeout=60000)
|
||||
page.get_by_role('button', name='Оживить', exact=True).wait_for(timeout=30000)
|
||||
page.wait_for_timeout(1200)
|
||||
page.evaluate('window.qaGraph = ' + RUNTIME)
|
||||
data = page.evaluate('qaGraph().data')
|
||||
assert any(node['id'] == NODE for node in data['nodes']), 'article 131 is absent from focused graph'
|
||||
initial_missing = page.evaluate("performance.getEntriesByType('resource').map(e => e.name).filter(n => n.endsWith('/favicon.ico'))")
|
||||
report['focus'] = {'node': NODE, 'nodes': len(data['nodes']), 'links': len(data['links'])}
|
||||
canvas = page.locator('.p-force-canvas canvas')
|
||||
box = canvas.bounding_box()
|
||||
assert box and box['width'] > 300 and box['height'] > 300
|
||||
before = page.evaluate('qaGraph().graph.zoom()')
|
||||
page.get_by_role('button', name='Приблизить карту').click()
|
||||
page.wait_for_timeout(800)
|
||||
after = page.evaluate('qaGraph().graph.zoom()')
|
||||
assert after > before, (before, after)
|
||||
report['2d_zoom'] = {'before': before, 'after': after}
|
||||
node = page.evaluate("""(id) => {
|
||||
const {graph, data} = qaGraph(); const n = data.nodes.find(x => x.id === id);
|
||||
const s = graph.graph2ScreenCoords(n.x, n.y); return {id, x:n.x, y:n.y, sx:s.x, sy:s.y};
|
||||
}""", NODE)
|
||||
x, y = box['x'] + node['sx'], box['y'] + node['sy']
|
||||
page.mouse.move(x, y); page.wait_for_timeout(100); page.mouse.down()
|
||||
page.mouse.move(x + 48, y + 24, steps=12); page.mouse.up(); page.wait_for_timeout(500)
|
||||
moved = page.evaluate('(id) => { const n=qaGraph().data.nodes.find(x=>x.id===id); return {x:n.x,y:n.y}; }', NODE)
|
||||
assert math.hypot(moved['x'] - node['x'], moved['y'] - node['y']) > 2, (node, moved)
|
||||
report['2d_drag'] = {'before': node, 'after': moved}
|
||||
page.get_by_role('button', name='3D', exact=True).click()
|
||||
page.wait_for_function("() => { try { return typeof qaGraph().graph.camera === 'function'; } catch { return false; } }", timeout=30000)
|
||||
page.wait_for_timeout(1000)
|
||||
box = page.locator('.p-force-canvas canvas').bounding_box(); assert box
|
||||
before = page.evaluate('() => { const p=qaGraph().graph.camera().position; return [p.x,p.y,p.z]; }')
|
||||
page.mouse.move(box['x'] + box['width']*.8, box['y'] + box['height']*.25)
|
||||
page.mouse.down(); page.mouse.move(box['x'] + box['width']*.6, box['y'] + box['height']*.4, steps=8); page.mouse.up()
|
||||
page.wait_for_timeout(1000)
|
||||
after = page.evaluate('() => { const p=qaGraph().graph.camera().position; return [p.x,p.y,p.z]; }')
|
||||
assert math.dist(before, after) > 1, (before, after)
|
||||
report['3d_orbit'] = {'before': before, 'after': after}
|
||||
before = page.evaluate('() => qaGraph().graph.camera().position.length()')
|
||||
page.get_by_role('button', name='Приблизить карту').click(); page.wait_for_timeout(1000)
|
||||
after = page.evaluate('() => qaGraph().graph.camera().position.length()')
|
||||
assert after < before, (before, after)
|
||||
report['3d_zoom'] = {'before': before, 'after': after}
|
||||
page.emulate_media(reduced_motion='reduce'); page.reload(wait_until='networkidle', timeout=60000)
|
||||
page.get_by_role('button', name='Оживить', exact=True).wait_for(timeout=30000)
|
||||
page.wait_for_timeout(1000); page.evaluate('window.qaGraph = ' + RUNTIME)
|
||||
before = page.evaluate('qaGraph().data.nodes.map(n => [n.x,n.y])'); page.wait_for_timeout(700)
|
||||
after = page.evaluate('qaGraph().data.nodes.map(n => [n.x,n.y])')
|
||||
assert before == after, 'reduced-motion graph kept moving'
|
||||
report['reduced_motion_stable'] = len(after)
|
||||
missing = sorted(set(initial_missing + page.evaluate("performance.getEntriesByType('resource').map(e => e.name).filter(n => n.endsWith('/favicon.ico'))")))
|
||||
report['javascript_errors'] = errors; report['console_errors'] = console_errors
|
||||
report['request_failures'] = failed; report['known_missing_assets'] = missing
|
||||
page.screenshot(path=str(OUT / 'runtime-atomic-131.png'), full_page=True)
|
||||
browser.close()
|
||||
(OUT / 'runtime-atomic-131.json').write_text(json.dumps(report, ensure_ascii=False, indent=2) + '\n')
|
||||
unexpected_console = [message for message in console_errors if 'Failed to load resource' not in message]
|
||||
assert not errors and not unexpected_console and not failed and len(missing) == 1, report
|
||||
print(json.dumps(report, ensure_ascii=False, indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user