HEL-822: land HEL-821 A1+A2 source onto PR#4 base (db571ba)

- 13 modified / 8 added / 1 deleted per CHANGES.json (author package 76bc120b)
- docs/requirements v1.10 + prototypes/hel-799 + PROVENANCE from bundle, verified byte-identical to 63799f0
- AGENTS.md + scripts/check_requirements.py restored from governance commit 63799f0

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
白栖知
2026-10-24 06:10:53 +08:00
co-authored by multica-agent
parent db571ba204
commit 003d8c2cae
78 changed files with 11055 additions and 433 deletions
+75 -62
View File
@@ -1,4 +1,4 @@
"""HEL-783 foreground Chromium checks. Only temporary SQLite + controlled LLM.
"""HEL-783 foreground Chromium checks (chat parts moved to the HEL-821 stage/reader). Only temporary SQLite + controlled LLM.
PYTHONPATH=src <python with playwright> web/tests/rework_browser_check.py
No deployed service or user data is read or written. Every server/context closes.
@@ -69,6 +69,18 @@ def send(page, text):
click(page, '发送')
# HEL-821 stage: lines are keyed by turn/position. A shown line must never change its text, and her ink-in plays
# at most once per line (re-presenting, status changes and the growing stream never replay it).
TRACK = """() => { const seen = window.lineSeen = {}, inked = window.lineInked = {}; window.lineChanged = [];
const note = n => { if (!(n instanceof HTMLElement) || !n.matches('.line')) return; const k = n.dataset.key, t = n.querySelector('p').textContent;
if (k in seen && seen[k] !== t) window.lineChanged.push([k, seen[k], t]); seen[k] = t;
if (n.querySelector('p.ink')) inked[k] = (inked[k] || 0) + 1; };
document.querySelectorAll('.stage .line').forEach(note);
new MutationObserver(list => list.forEach(r => r.addedNodes.forEach(note))).observe(document.querySelector('.stage'), {childList: true}); }"""
STILL = "() => [...document.querySelectorAll('.stage .line:not(.leaving)')].every(n => n.getAnimations().length === 0)"
CURRENT = '.stage .line.is-current:not(.leaving)'
try:
with tempfile.TemporaryDirectory(prefix='cg-rework-') as directory, sync_playwright() as pw:
provider = ReworkLLM()
@@ -84,12 +96,6 @@ try:
if(key === 'cybergril.demo.v1' && !location.search.includes('demo=1')) throw new Error('real read demo');
return get.call(this, key);
};
window.motionStarts = [];
const animate = Element.prototype.animate;
Element.prototype.animate = function(...args) {
if (this.matches('.her .current-text')) window.motionStarts.push({text:this.textContent, duration:args[1].duration});
return animate.apply(this, args);
};
"""
)
page.goto(url)
@@ -109,39 +115,36 @@ try:
nav(page, '交谈')
provider.mode = 'long'
before = page.evaluate('motionStarts.length')
page.evaluate(TRACK)
send(page, USER)
expect(page.locator('.her .current-text')).to_contain_text('开头:')
page.evaluate("window.streamNode = document.querySelector('.her .current-text')")
# Pause the actual animation and inspect deterministic frames, then resume.
frames = []
for time in (0, 80, 200):
values = page.evaluate("""t => {const el=window.streamNode;const a=el.getAnimations()[0];if(a){a.pause();a.currentTime=t;}const s=getComputedStyle(el);return {time:t,opacity:s.opacity,transform:s.transform};}""", time)
frames.append(values)
shot(page, f'motion-enter-{time}')
page.evaluate('window.streamNode.getAnimations().forEach(a=>a.play())')
expect(page.get_by_role('button', name='取消本轮回复')).not_to_be_visible()
expect(page.locator('.her .current-text')).to_have_text(LONG)
assert page.evaluate("window.streamNode === document.querySelector('.her .current-text')")
assert page.evaluate('motionStarts.length') - before == 1
assert float(frames[0]['opacity']) < float(frames[1]['opacity']) < float(frames[2]['opacity'])
report['motion']['entry_frames'] = frames
expect(page.locator('.you .current-text')).to_have_text(USER)
passed('Long Chinese stream: entire user/reply retained; final keeps same DOM; one entrance across all chunks and final')
# Replace a completed sentence; retain its exit DOM until the animation ends.
send(page, '再讲一次')
outgoing = page.locator('.her .outgoing-text')
expect(outgoing).to_have_count(1)
assert outgoing.text_content() == LONG
exit_frames = page.evaluate("""() => {const el=document.querySelector('.her .outgoing-text');const a=el.getAnimations()[0];a.pause();return [0,80,159].map(t=>{a.currentTime=t;return {time:t,opacity:getComputedStyle(el).opacity,retained:el.isConnected}});} """)
assert float(exit_frames[0]['opacity']) > float(exit_frames[-1]['opacity'])
report['motion']['exit_frames'] = exit_frames
page.evaluate("document.querySelector('.her .outgoing-text').getAnimations().forEach(a=>a.play())")
expect(outgoing).to_have_count(0)
expect(page.get_by_role('button', name='取消本轮回复')).not_to_be_visible()
passed('Old sentence stays mounted during a visible 160ms fade-out, then leaves')
# The turn starts at your line, then her reply flows on by itself one or two lines at a time.
expect(page.locator(CURRENT)).to_have_attribute('data-role', 'user')
expect(page.locator(CURRENT + '[data-role="companion"]')).to_contain_text('开头:', timeout=10000)
expect(page.get_by_role('button', name='停止回复')).not_to_be_visible(timeout=15000)
# Pause, then review: keyboard lands at once (no slide, no replayed ink), "back to where I was" returns.
click(page, '暂停')
page.evaluate('document.activeElement.blur()')
before = page.locator(CURRENT).get_attribute('data-key')
page.keyboard.press('ArrowLeft')
expect(page.locator(CURRENT)).not_to_have_attribute('data-key', before)
assert page.evaluate(STILL)
page.keyboard.press('ArrowRight')
expect(page.locator(CURRENT)).to_have_attribute('data-key', before)
assert page.evaluate(STILL)
click(page, '上一句')
page.locator('.reader-bar .latest').click()
expect(page.locator(CURRENT)).to_have_attribute('data-key', before)
assert page.evaluate('window.lineChanged') == [], page.evaluate('window.lineChanged')
assert max(page.evaluate('Object.values(window.lineInked)') or [1]) == 1
report['motion']['inked_lines'] = page.evaluate('window.lineInked')
click(page, '完整记录')
for part in ('长句开头', '用户长句末尾', '开头:', '第5段。', '故事没有被截掉'):
expect(page.locator('.log-panel')).to_contain_text(part)
click(page, '关闭记录')
click(page, '继续')
passed('Long Chinese stream: shown lines never change or re-key, ink plays once per line; pause/keyboard review is instant; record keeps everything')
click(page, '暂停')
for width, height in [(1440, 900), (360, 640), (390, 700), (390, 844), (390, 420), (844, 390)]:
page.set_viewport_size({'width': width, 'height': height})
for theme, label in [('moon', '靛蓝月光'), ('fog', '蓝紫雾光')]:
@@ -149,42 +152,49 @@ try:
expect(page.locator('html')).to_have_attribute('data-theme', theme)
page.get_by_role('textbox', name='想和她说的话').focus()
metrics = page.evaluate("""() => {
const box=s=>{const b=document.querySelector(s).getBoundingClientRect();return {top:b.top,bottom:b.bottom,height:b.height}};
const scroll=document.querySelector('.dialog-scroll');return {dialog:box('.dialog'),composer:box('.composer'),nav:box('.nav'),stage:box('.portal'),scrollHeight:scroll.scrollHeight,clientHeight:scroll.clientHeight,width:innerWidth,overflow:document.documentElement.scrollWidth>innerWidth};
const box=el=>{const b=el.getBoundingClientRect();return {top:b.top,bottom:b.bottom,left:b.left,right:b.right,height:b.height}};
const q=s=>box(document.querySelector(s));
return {stage:q('.stage'),reader:q('.reader-bar'),composer:q('.composer'),nav:q('.nav'),
lines:[...document.querySelectorAll('.stage .line:not(.leaving) p')].filter(p=>p.offsetParent).map(box),
width:innerWidth,height:innerHeight,overflow:document.documentElement.scrollWidth>innerWidth};
}""")
assert not metrics['overflow'], metrics
assert metrics['stage']['bottom'] <= metrics['dialog']['top'] + 1, metrics
assert metrics['dialog']['bottom'] <= metrics['composer']['top'] + 1, metrics
assert metrics['lines'], metrics
for line in metrics['lines']:
assert line['left'] >= 0 and line['right'] <= metrics['width'] + .5, metrics
assert line['bottom'] <= metrics['reader']['top'] + 1, metrics
assert metrics['stage']['bottom'] <= metrics['reader']['top'] + 1, metrics
assert metrics['reader']['bottom'] <= metrics['composer']['top'] + 1, metrics
assert metrics['composer']['bottom'] < metrics['nav']['top'], metrics
assert metrics['clientHeight'] >= 60, metrics
assert metrics['scrollHeight'] > metrics['clientHeight'], metrics
report['viewports'].append({'width': width, 'height': height, 'theme': theme, **metrics})
page.locator('.dialog-scroll').evaluate('el=>el.scrollTop=0')
expect(page.locator('.you .current-text')).to_have_text('再讲一次')
if width in (360, 390) and height in (640, 420, 844): shot(page, f'long-start-{width}-{height}-{theme}')
page.locator('.dialog-scroll').evaluate('el=>el.scrollTop=el.scrollHeight')
if width in (360, 390) and height in (640, 420, 844): shot(page, f'long-end-{width}-{height}-{theme}')
if width in (360, 390) and height in (640, 420, 844): shot(page, f'long-line-{width}-{height}-{theme}')
click(page, '全文')
expect(page.locator('.record.full')).to_be_visible()
page.keyboard.press('Escape')
expect(page.locator('.record.full')).to_have_count(0)
expect(page.get_by_role('button', name='全文', exact=True)).to_be_focused()
click(page, '完整记录')
expect(page.locator('.log-panel')).to_contain_text('长句开头')
expect(page.locator('.log-panel')).to_contain_text('故事没有被截掉')
if width == 390 and height == 844: shot(page, f'full-history-{theme}')
click(page, '关闭记录')
passed('12 viewport/theme combinations: long text scrolls, stage/dialog/composer/navigation never overlap; full history reachable')
click(page, '继续')
passed('12 viewport/theme combinations: lines stay inside the stage, stage/reader/composer/navigation never overlap; Esc closes full text with focus back; full history reachable')
page.set_viewport_size({'width': 390, 'height': 700})
provider.mode = 'slow'; send(page, '取消并重发')
expect(page.locator('.her .current-text')).to_have_text('答')
click(page, '取消本轮回复')
expect(page.get_by_role('button', name='停止回复')).to_be_visible()
click(page, '停止回复')
provider.mode = 'normal'; send(page, '新轮')
expect(page.get_by_role('button', name='取消本轮回复')).not_to_be_visible()
expect(page.locator('.her .current-text')).to_have_text('答复')
expect(page.get_by_role('button', name='停止回复')).not_to_be_visible()
expect(page.locator(CURRENT + '[data-role="companion"]')).to_have_text('答复', timeout=8000)
provider.mode = 'error'; send(page, '失败再试')
expect(page.locator('.dialog .failed')).to_be_visible()
expect(page.locator('.talk-status .retry')).to_be_visible()
expect(page.get_by_role('textbox', name='想和她说的话')).to_have_value('失败再试')
count = app.state.store.query_one('SELECT count(*) n FROM chat_message')['n']
provider.mode = 'normal'; page.locator('.dialog .retry').click()
expect(page.locator('.dialog .failed')).not_to_be_visible()
expect(page.get_by_role('button', name='取消本轮回复')).not_to_be_visible()
provider.mode = 'normal'; page.locator('.talk-status .retry').click()
expect(page.locator('.talk-status .retry')).not_to_be_visible()
expect(page.get_by_role('button', name='停止回复')).not_to_be_visible()
assert app.state.store.query_one('SELECT count(*) n FROM chat_message')['n'] == count + 1
passed('Cancel then immediate new turn, model error and same-turn retry preserve roles and avoid duplicate user messages')
@@ -228,11 +238,14 @@ try:
page.reload(); nav(page, '交谈')
assert page.locator('html').evaluate("el=>el.classList.contains('reduced')")
provider.mode = 'normal'; send(page, '减少动效检查')
expect(page.get_by_role('button', name='取消本轮回复')).not_to_be_visible()
assert page.evaluate('motionStarts.at(-1).duration') == 120
expect(page.get_by_role('button', name='停止回复')).not_to_be_visible()
expect(page.locator(CURRENT + '[data-role="companion"]')).to_have_text('答复', timeout=8000)
assert page.evaluate(STILL) and page.locator('.stage p.ink').count() == 0
reduced = browser.new_context(viewport={'width': 390, 'height': 700}, reduced_motion='reduce')
rp = reduced.new_page(); rp.goto(url); nav(rp, '交谈'); send(rp, '系统减少动效')
expect(rp.get_by_role('button', name='取消本轮回复')).not_to_be_visible()
expect(rp.get_by_role('button', name='停止回复')).not_to_be_visible()
expect(rp.locator(CURRENT + '[data-role="companion"]')).to_have_text('答复', timeout=8000)
assert rp.evaluate(STILL) and rp.locator('.stage p.ink').count() == 0
reduced.close()
passed('Escape navigation; browser display preference survives reload; settings/system reduced motion uses gentle opacity')
@@ -247,7 +260,7 @@ try:
dp.get_by_role('checkbox').check(); click(dp, '确认创建'); click(dp, '去看看她')
nav(dp, '交谈'); click(dp, '开始模拟语音'); click(dp, '开始模拟')
expect(dp.get_by_role('button', name='结束语音')).to_be_visible()
assert dp.locator('.voicebar').bounding_box()['y'] > dp.locator('.dialog').bounding_box()['y']
assert dp.locator('.voice-row').bounding_box()['y'] + dp.locator('.voice-row').bounding_box()['height'] <= dp.locator('.composer').bounding_box()['y'] + 1
shot(dp, 'demo-voice-390')
click(dp, '结束语音')
dp.locator('.demo > button').click(); click(dp, '载入三天记录')