view: preserve disclosure state and release CLI 2.7.1

This commit is contained in:
cflmy committed 2026-11-11 00:44:32 +08:00
1 parent c0dc18433b
commit eac6921524
21 files changed
+976 -228

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
// Reproduce user activation followed by real layout/observer and live DOM updates.
const assert=require('node:assert/strict');
const {chromium}=require(process.env.MARQDO_PLAYWRIGHT_MODULE||'playwright');
let browser;
(async()=>{
browser=await chromium.launch({headless:true,args:['--no-sandbox']});
const page=await browser.newPage({viewport:{width:1100,height:1000}});
const errors=[];page.on('pageerror',e=>errors.push(e.message));
await page.route('https://**/*',r=>r.abort());
await page.goto(process.argv[2]);
await page.waitForTimeout(300);
for(const width of [1100,390,1440]){
await page.setViewportSize({width,height:1000});await page.waitForTimeout(200);
const note=page.locator('.annot-implementation:not(.is-margin-note)').first();
assert(await note.count(),'actual inline fallback at '+width);
const id=await note.getAttribute('data-annot-id');
const summary=note.locator(':scope > summary');
if(await note.evaluate(n=>n.open))await summary.click();
await summary.click();await page.waitForTimeout(300);
assert(await note.evaluate(n=>n.open),'click remains open after observer layout at '+width);
await page.evaluate(()=>{for(let i=0;i<5;i++)window.MarqdoReader.refreshAnnotations();});
await page.setViewportSize({width:width+15,height:980});await page.waitForTimeout(200);
assert(await note.evaluate(n=>n.open),'open choice survives resize at '+width);
const raw=note.locator('.logic-source');
if(await raw.count()){
if(!await raw.evaluate(n=>n.open))await raw.locator(':scope > summary').click();
await page.waitForTimeout(200);
assert(await note.evaluate(n=>n.open)&&await raw.evaluate(n=>n.open),'nested source stays readable');
}
await page.evaluate(()=>{
const structure=document.getElementById('structure');
const template=structure.cloneNode(true);
template.querySelectorAll('.annot-implementation,.logic-source').forEach(n=>n.open=false);
window.MarqdoReader.applyExecution({ok:true,page_token:window.MARQDO_VIEW_PAGE_TOKEN,structure_html:template.innerHTML});
});
await page.waitForTimeout(250);
const refreshed=page.locator('[data-annot-id="'+id+'"].annot-implementation');
assert(await refreshed.evaluate(n=>n.open),'live replacement preserves open choice');
if(await raw.count())assert(await refreshed.locator('.logic-source').evaluate(n=>n.open),'live replacement preserves raw source');
await refreshed.locator(':scope > summary').focus();await page.keyboard.press('Enter');
await page.waitForTimeout(250);assert.equal(await refreshed.evaluate(n=>n.open),false,'keyboard close persists');
await refreshed.locator(':scope > summary').focus();await page.keyboard.press('Space');
await page.waitForTimeout(250);assert(await refreshed.evaluate(n=>n.open),'keyboard open persists');
await refreshed.locator(':scope > summary').click();await page.waitForTimeout(150);
await page.evaluate(()=>window.MarqdoReader.refreshAnnotations());await page.waitForTimeout(150);
assert.equal(await refreshed.evaluate(n=>n.open),false,'explicit close persists');
}
assert.deepEqual(errors,[]);await browser.close();
console.log('disclosures: click, keyboard, nested source, repeated layout, resize and live replacement passed');
})().catch(async e=>{console.error(e);if(browser)await browser.close();process.exitCode=1;});
+88
View File
@@ -0,0 +1,88 @@
// Read typed details in the actual static/live reader without executing payloads.
const assert=require('node:assert/strict');
const {chromium}=require(process.env.MARQDO_PLAYWRIGHT_MODULE||'playwright');
let browser;
(async()=>{
browser=await chromium.launch({headless:true,args:['--no-sandbox']});
const context=await browser.newContext({viewport:{width:1440,height:1000}});
await context.route('https://**/*',r=>r.request().isNavigationRequest() ? r.fulfill({contentType:'text/html',body:'<h1>navigation reached</h1>'}) : r.abort());
const page=await context.newPage(),errors=[];
page.on('pageerror',e=>errors.push(e.message));
await page.goto(process.argv[2]);await page.waitForTimeout(250);
const label=text=>page.locator('#structure .occl-label').getByText(text,{exact:true});
const ids=await page.locator('#structure .occl-label').evaluateAll(ns=>ns.map(n=>n.dataset.logicId));
assert(ids.length>=10);assert.equal(new Set(ids).size,ids.length);
for(const id of ids)assert.equal(await page.locator('#'+id+'-note').count(),1,'one detail per description');
const callId=await label('函数与参数').getAttribute('data-logic-id');
const callNote=page.locator('#'+callId+'-note');
assert.equal(await callNote.getAttribute('data-logic-kind'),'call');
assert.deepEqual(await callNote.locator('.logic-arguments dt').allTextContents(),['单价','数量']);
const definition=await callNote.locator('.logic-definition').getAttribute('href');
await label('函数与参数').click();
assert(await page.locator('#reader-dialog').evaluate(n=>n.open));
assert(await page.locator('#reader-dialog .logic-arguments').isVisible());
assert.equal(await page.locator('#reader-dialog .logic-call-name').first().textContent(),'计算费用');
await page.locator('#reader-dialog .logic-source > summary').click();
assert((await page.locator('#reader-dialog pre').innerText()).includes('计算费用(单价=12, 数量=2)'));
await page.locator('#reader-dialog .logic-definition').click();
assert.equal(await page.locator('#reader-dialog').evaluate(n=>n.open),false);
assert.equal(new URL(page.url()).hash,definition);
const nestedId=await label('嵌套调用').getAttribute('data-logic-id');
assert.equal(await page.locator('#'+nestedId+'-note .logic-call-name').count(),2);
const listId=await label('列表内容').getAttribute('data-logic-id');
assert.deepEqual(await page.locator('#'+listId+'-note .logic-values li').allTextContents(),['1','2','3']);
const recordId=await label('记录内容').getAttribute('data-logic-id');
assert((await page.locator('#'+recordId+'-note .logic-body').textContent()).includes('茶'));
assert.equal(await page.locator('#structure .occl-stub').count(),1);
const repository=label('访问项目仓库');
assert.equal(await repository.evaluate(n=>n.tagName),'A');
const repoNote=page.locator('#'+await repository.getAttribute('data-logic-id')+'-note');
if(!await repoNote.evaluate(n=>n.open))await repoNote.locator(':scope > summary').click();
const popupPromise=context.waitForEvent('page');await repoNote.locator('.logic-link-target').click();
const popup=await popupPromise;await popup.waitForLoadState();
assert.equal(popup.url(),'https://github.com/cflmy/marqdo');await popup.close();
await label('跳到函数定义').click();assert.equal(new URL(page.url()).hash,definition);
await label('查看阅读示例').click();await page.waitForLoadState();
assert(page.url().includes('view-reading.mq.md'));
assert(await page.locator('#structure').getByText('购买两件商品',{exact:true}).count());
await page.goto(process.argv[2]);await page.waitForTimeout(200);
for(const width of [1920,1440,1100,1000,800,390]){
await page.setViewportSize({width,height:1000});await page.waitForTimeout(150);
assert(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1),'overflow '+width);
assert.deepEqual(await page.locator('.is-margin-note').evaluateAll(nodes=>{
const issues=[],rects=nodes.map(n=>n.getBoundingClientRect());
nodes.forEach((n,i)=>{
const r=rects[i];if(r.left<0||r.right>innerWidth)issues.push('offscreen');
const source=document.querySelector('[data-reader-source-anchor="'+n.dataset.readerAnchor+'"]');
if(!source||source.dataset.logicId!==n.dataset.annotId)issues.push('wrong source');
for(let j=i+1;j<rects.length;j++){const b=rects[j];if(r.left<b.right&&b.left<r.right&&r.top<b.bottom&&b.top<r.bottom)issues.push('overlap');}
});
if(innerWidth>=1440&&!nodes.length)issues.push('missing wide notes');
if(innerWidth<=1000&&nodes.length)issues.push('mobile margin');
return issues;
}),[],'precise and readable notes '+width);
}
const mobileNote=page.locator('#'+callId+'-note');
await mobileNote.locator(':scope > summary').click();
assert(await mobileNote.locator('.logic-body').isVisible());
await page.setViewportSize({width:430,height:1000});await page.waitForTimeout(150);
assert(await mobileNote.evaluate(n=>n.open),'manual disclosure survives layout');
if(process.env.MARQDO_SCREENSHOT_DIR){
await page.screenshot({path:process.env.MARQDO_SCREENSHOT_DIR+'/details-mobile.png',fullPage:true});
await page.setViewportSize({width:1440,height:1000});await page.waitForTimeout(200);
await page.locator('#structure .doc-prose').first().scrollIntoViewIfNeeded();
await page.screenshot({path:process.env.MARQDO_SCREENSHOT_DIR+'/details-desktop.png'});
await label('函数与参数').click();
await page.screenshot({path:process.env.MARQDO_SCREENSHOT_DIR+'/details-call.png'});
await page.keyboard.press('Escape');
}
const plainContext=await browser.newContext({javaScriptEnabled:false,viewport:{width:390,height:900}});
const plain=await plainContext.newPage();await plain.goto(process.argv[2]);
const note=plain.locator('#'+callId+'-note');await note.locator(':scope > summary').click();
assert(await note.locator('.logic-arguments').isVisible());
await note.locator('.logic-source > summary').click();assert((await note.locator('pre').innerText()).includes('计算费用'));
await plain.locator('#structure a.occl-label').getByText('查看阅读示例',{exact:true}).click();await plain.waitForLoadState();
assert(plain.url().includes('view-reading.mq.md'));await plainContext.close();
assert.deepEqual(errors,[]);await browser.close();
console.log('typed details: calls, values, real links, precise notes, responsive and no-JS passed');
})().catch(async e=>{console.error(e);if(browser)await browser.close();process.exitCode=1;});
+1 -1
View File
@@ -64,7 +64,7 @@ let browser;
// Read-only no-script fallback still exposes native details and real source text.
const context=await browser.newContext({javaScriptEnabled:false,viewport:{width:390,height:900}});
const plain=await context.newPage();await plain.goto(process.argv[2]);
const note=plain.locator('.annot-implementation').first();await note.locator('summary').click();
const note=plain.locator('.annot-implementation').first();await note.locator(':scope > summary').click();
assert(await note.locator('.annot-value').isVisible());
assert.equal(await plain.locator('.occl-stub').count(),1);
await context.close();
+17
View File
@@ -153,3 +153,20 @@ fn automatic_reader_marks_callable_modules_without_executing_tools_or_hiding_pro
assert!(html.contains(">fail</span>"), "a real entry failure was hidden");
assert!(!html.contains(">module</span>"));
}
#[test]
fn typed_details_keep_calls_links_and_content_readable_without_executing() {
let temp = Scratch::new();
let source = temp.0.join("details.mq.md");
fs::write(&source, include_str!("../examples/view-details.mq.md")).unwrap();
fs::write(temp.0.join("view-reading.mq.md"), "## next\n\nReturn *1*.\n").unwrap();
export(&temp.0, &temp.0.join("out"));
let html = fs::read_to_string(temp.0.join("out/pages/details.mq.md.html")).unwrap();
for fragment in ["data-logic-kind=\"call\"", "<dt>单价</dt>", "<dt>数量</dt>",
"class=\"logic-definition\"", "class=\"logic-values\"", "<dt>名称</dt>",
"data-logic-kind=\"empty\"", "待补充实际逻辑",
"href=\"view-reading.mq.md.html\"", "href=\"https://github.com/cflmy/marqdo\""] {
assert!(html.contains(fragment), "missing typed reading detail: {fragment}");
}
assert!(!html.contains("class=\"annot-chip annot-bind"), "reading acquired runtime results");
}