dsh-memu-memory 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +3 -1
- package/CHANGELOG.md +15 -0
- package/README.md +34 -15
- package/README.zh.md +35 -13
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/libraries.jpg +0 -0
- package/assets/screenshots/mobile.jpg +0 -0
- package/assets/screenshots/relations.jpg +0 -0
- package/assets/screenshots/settings.jpg +0 -0
- package/assets/screenshots/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +19 -3
- package/docs/contributing.md +4 -2
- package/docs/env-and-commands.md +9 -1
- package/docs/graph-scale.md +214 -0
- package/docs/lexicon-recall.md +100 -0
- package/docs/mcp-porting.md +8 -6
- package/docs/memory-semantics.md +35 -3
- package/docs/pending-work.md +3 -1
- package/docs/retention.md +83 -0
- package/docs/rt-index.md +452 -0
- package/docs/scale-performance.md +101 -0
- package/docs/token-budget.md +92 -0
- package/docs/troubleshooting.md +50 -11
- package/lib/auto-link/apply.js +7 -2
- package/lib/auto-link/candidates.js +32 -10
- package/lib/backup.js +67 -32
- package/lib/binding-diagnostics.js +1 -1
- package/lib/bounded-cache.js +80 -0
- package/lib/client.js +2096 -409
- package/lib/consolidation-ledger.js +21 -4
- package/lib/consolidation-worker.js +14 -1
- package/lib/cycle.js +16 -11
- package/lib/diagnostic-context.js +372 -0
- package/lib/diagnostics.js +147 -61
- package/lib/embedding-download.js +7 -8
- package/lib/engine-sources.js +286 -0
- package/lib/engine.js +23 -10
- package/lib/entity-repair.js +43 -13
- package/lib/entity-review.js +64 -0
- package/lib/environment-check.js +348 -36
- package/lib/feedback.js +25 -0
- package/lib/global-graph.js +46 -2
- package/lib/graph-adjacency-index.js +525 -0
- package/lib/graph-overview.js +293 -0
- package/lib/graph.js +658 -105
- package/lib/inbound.js +44 -15
- package/lib/index-pages.js +57 -0
- package/lib/index.js +44 -6
- package/lib/inject.js +119 -50
- package/lib/lexicon-rt-source.js +25 -0
- package/lib/lexicon-rt-worker.js +26 -0
- package/lib/lexicon-rt.js +224 -0
- package/lib/lexicon-scope.js +56 -5
- package/lib/lexicon.js +143 -54
- package/lib/local-vector-service.js +3 -0
- package/lib/maintenance-ledger.js +542 -12
- package/lib/managed-runtime.js +260 -80
- package/lib/media.js +1 -1
- package/lib/memory.js +564 -131
- package/lib/port-surface.js +96 -11
- package/lib/preset-mount.js +13 -7
- package/lib/private.js +47 -21
- package/lib/recall-cache.js +20 -34
- package/lib/retention.js +173 -0
- package/lib/rpc.js +135 -52
- package/lib/rt-index/builder.js +209 -0
- package/lib/rt-index/format.js +231 -0
- package/lib/rt-index/manifest.js +105 -0
- package/lib/rt-index/reader.js +673 -0
- package/lib/rt-index-retention.js +151 -0
- package/lib/rt-index-service.js +283 -0
- package/lib/rt-index-worker.js +21 -0
- package/lib/salient-wake.js +55 -4
- package/lib/state.js +195 -24
- package/lib/temporal.js +39 -13
- package/lib/token-measurement.js +126 -0
- package/lib/tools.js +101 -6
- package/lib/turn-log.js +108 -3
- package/lib/webui/graph-layout-worker.js +68 -0
- package/lib/webui/graph-local-physics.js +390 -0
- package/lib/webui/graph-spatial-grid.js +64 -0
- package/lib/webui/graph-view.bundle.js +6 -1
- package/lib/webui/graph-view.js +478 -135
- package/lib/webui/graph-webgl-renderer.js +74 -0
- package/lib/webui/standalone.js +1 -1
- package/lib/worker-pool.js +38 -7
- package/package.json +3 -2
- package/scripts/acceptance-local.mjs +4 -10
- package/scripts/bench-all-libraries.mjs +47 -0
- package/scripts/check-classic-graph-browser.mjs +189 -0
- package/scripts/check-client-browser.mjs +929 -0
- package/scripts/check-graph-browser.mjs +6 -0
- package/scripts/check-graph-elastic-browser.mjs +139 -0
- package/scripts/check-memory-review-browser.mjs +124 -0
- package/scripts/entity-dedupe.mjs +19 -3
- package/scripts/graph-artifact-provenance.mjs +30 -0
- package/scripts/graph-freeze-manifest.mjs +129 -0
- package/scripts/graph-geometry-fixture.mjs +40 -0
- package/scripts/graph-physics-bench.mjs +218 -0
- package/scripts/graph-scale-bench.mjs +213 -0
- package/scripts/graph-scale-memory.mjs +48 -0
- package/scripts/graph-service-bench.mjs +72 -0
- package/scripts/make-readme-shots.mjs +17 -5
- package/scripts/preview.mjs +1 -0
- package/scripts/rebuild-rt.mjs +18 -0
- package/scripts/scale-bench.mjs +183 -0
- package/scripts/simulate-injection.mjs +47 -8
- package/scripts/verify-host-fixtures.mjs +108 -0
- package/scripts/verify-host-recovery.mjs +565 -0
- package/scripts/verify-vector-recovery.mjs +740 -0
- package/tests/auto-link-candidates.test.mjs +20 -0
- package/tests/browser.test.mjs +16 -2
- package/tests/client-export.test.mjs +16 -1
- package/tests/client-pagination.test.mjs +1495 -0
- package/tests/client-render.test.mjs +223 -28
- package/tests/consolidation-fork.test.mjs +97 -13
- package/tests/consolidation-ledger.test.mjs +17 -1
- package/tests/diagnostic-entity-candidates.test.mjs +54 -0
- package/tests/diagnostic-report.test.mjs +429 -0
- package/tests/diagnostic-wiring.test.mjs +88 -0
- package/tests/diagnostics.test.mjs +27 -0
- package/tests/embedding-download.test.mjs +44 -0
- package/tests/engine-source-settings.test.mjs +69 -0
- package/tests/engine-sources.test.mjs +145 -0
- package/tests/entity-dedupe.test.mjs +143 -0
- package/tests/entity-merge-review.test.mjs +363 -0
- package/tests/entity-merge.test.mjs +12 -4
- package/tests/entity-review.test.mjs +87 -0
- package/tests/environment-check.test.mjs +51 -1
- package/tests/feedback.test.mjs +95 -0
- package/tests/graph-adjacency-index.test.mjs +536 -0
- package/tests/graph-cascade.test.mjs +229 -0
- package/tests/graph-import-diagnostic.test.mjs +25 -0
- package/tests/graph-overview.test.mjs +709 -0
- package/tests/graph-session-authorization.test.mjs +419 -0
- package/tests/graph-view-geometry.test.mjs +426 -0
- package/tests/graph-view-scale.test.mjs +88 -0
- package/tests/graph-view.test.mjs +444 -5
- package/tests/graph.test.mjs +43 -0
- package/tests/help-page.test.mjs +128 -54
- package/tests/inbound.test.mjs +19 -0
- package/tests/index-pagination.test.mjs +113 -0
- package/tests/index-read-view.test.mjs +212 -0
- package/tests/inject-guide.test.mjs +9 -0
- package/tests/injection-dedupe.test.mjs +213 -0
- package/tests/lexicon-recall.test.mjs +641 -0
- package/tests/lexicon-rt-lifecycle.test.mjs +196 -0
- package/tests/lexicon-rt.test.mjs +468 -0
- package/tests/local-embedding-worker.test.mjs +38 -0
- package/tests/local-vector-service.test.mjs +32 -3
- package/tests/maintenance-compat.test.mjs +128 -0
- package/tests/maintenance-settlement.test.mjs +1003 -0
- package/tests/managed-memory.test.mjs +39 -11
- package/tests/managed-runtime.test.mjs +109 -0
- package/tests/memory-fields.test.mjs +24 -12
- package/tests/observed-evidence.test.mjs +52 -0
- package/tests/port-surface.test.mjs +93 -1
- package/tests/preset-mount.test.mjs +12 -4
- package/tests/recall-cache.test.mjs +56 -3
- package/tests/recall-dedup.test.mjs +63 -2
- package/tests/retention.test.mjs +260 -0
- package/tests/rt-index-cross-library.test.mjs +230 -0
- package/tests/rt-index-integration.test.mjs +194 -0
- package/tests/rt-index-retention.test.mjs +552 -0
- package/tests/rt-index-scale.test.mjs +204 -0
- package/tests/rt-index.test.mjs +705 -0
- package/tests/salient-date-boundaries.test.mjs +121 -0
- package/tests/salient-wake.test.mjs +29 -0
- package/tests/scale-bench.test.mjs +53 -0
- package/tests/settings-plumbing.test.mjs +25 -0
- package/tests/simulate-injection.test.mjs +15 -1
- package/tests/standalone-navigation.test.mjs +44 -0
- package/tests/state.test.mjs +51 -0
- package/tests/temporal-precision.test.mjs +102 -0
- package/tests/temporal.test.mjs +10 -6
- package/tests/token-measurement.test.mjs +98 -0
- package/tests/tool-schema.test.mjs +41 -5
- package/tests/tools.test.mjs +6 -3
- package/tests/turn-token-budget.test.mjs +149 -0
- package/tests/webui-auth.test.mjs +57 -1
- package/tests/webui.test.mjs +40 -15
- package/tests/worker-lifecycle.test.mjs +2 -1
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import http from 'node:http'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { createHash } from 'node:crypto'
|
|
7
|
+
import { chromium } from 'playwright'
|
|
8
|
+
|
|
9
|
+
// Real shared WebUI and RPC, with synthetic memories in an isolated temporary home.
|
|
10
|
+
// Run: node --import ./tests/loader-register.mjs scripts/check-client-browser.mjs
|
|
11
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-client-browser-'))
|
|
12
|
+
process.env.DSH_MEMU_HOME = home
|
|
13
|
+
process.env.DSH_MEMU_MEMORY_HOME = home
|
|
14
|
+
process.env.MEMU_CONFIG = path.join(home, 'config.env')
|
|
15
|
+
const state = await import('../lib/state.js')
|
|
16
|
+
const graph = await import('../lib/graph.js')
|
|
17
|
+
const { recordDiagnostic } = await import('../lib/diagnostics.js')
|
|
18
|
+
const { registerRpc } = await import('../lib/rpc.js')
|
|
19
|
+
const output = path.resolve('logs')
|
|
20
|
+
fs.mkdirSync(output, { recursive: true })
|
|
21
|
+
state.updateSettings({ autoInstallEngine: false, sleepConsolidation: false, memoryMode: 'local' })
|
|
22
|
+
const books = ['Browser A', 'Browser B'].map(name => state.createLibrary({ name, cwd: path.join(home, name) }))
|
|
23
|
+
const managementBooks = []
|
|
24
|
+
const managementOnly = process.argv.includes('--management-only')
|
|
25
|
+
const reportFile = path.join(output, managementOnly ? 'recovery-ui-browser-orphan-report.json' : 'recovery-ui-browser-report.json')
|
|
26
|
+
const actionEntities = []
|
|
27
|
+
const id = i => 'mem-ui-' + String(i).padStart(4, '0')
|
|
28
|
+
for (const [bookIndex, book] of books.entries()) {
|
|
29
|
+
const entries = {}
|
|
30
|
+
for (let i = 0; i < (bookIndex ? 360 : 960); i++) {
|
|
31
|
+
const at = new Date(Date.UTC(2026, 9, 1) - i * 1000).toISOString()
|
|
32
|
+
entries[id(i)] = { title: `${book.name} memory ${String(i).padStart(4, '0')}`,
|
|
33
|
+
content: 'Synthetic browser verification memory. '.repeat(12) + (i === 900 ? 'needle-new' : i === 880 ? 'needle-old' : 'body-tail'),
|
|
34
|
+
status: i % 20 === 19 ? 'archived' : 'active', layer: i % 7 ? 'long_term' : 'must_remember',
|
|
35
|
+
source: 'user_said', domain: i % 2 ? 'coding' : 'rp', visibility: 'shared', createdAt: at, updatedAt: at,
|
|
36
|
+
tags: ['browser-fixture'], strength: .8, links: i % 64 ? [{ to: id(i - 1), kind: 'relation', source: 'manual',
|
|
37
|
+
...(i === 42 ? { note: 'Browser graph recorded edge evidence' } : {}) }] : [] }
|
|
38
|
+
}
|
|
39
|
+
state.savePrivateIndex(book.id, { version: 1, entries })
|
|
40
|
+
state.ensureSession('browser-session-' + bookIndex, { cwd: path.join(home, book.name), libraryId: book.id })
|
|
41
|
+
const source = graph.createEntity({ libraryId: book.id, name: 'Harbor Alic', kind: 'person', status: 'confirmed' })
|
|
42
|
+
const target = graph.createEntity({ libraryId: book.id, name: 'Harbor Alice', kind: 'person', status: 'confirmed' })
|
|
43
|
+
const pending = graph.createEntity({ libraryId: book.id, name: 'Review Traveler', kind: 'person' })
|
|
44
|
+
actionEntities.push({ source, target, pending })
|
|
45
|
+
state.updatePrivateIndex(book.id, index => {
|
|
46
|
+
index.entries[id(0)].links.push({ to: target.id, kind: 'person', source: 'auto', confidence: .91,
|
|
47
|
+
note: 'Synthetic person mention evidence', evidence: { rule: 'entity-mention', surface: 'Harbor Alice', field: 'content' } })
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
state.saveGlobalIndex({ version: 1, entries: {} })
|
|
51
|
+
state.flushState()
|
|
52
|
+
let handler, browser, server
|
|
53
|
+
const services = { sessionQuery: {
|
|
54
|
+
listSessions: async () => books.map((book, i) => ({ header: { id: 'browser-session-' + i, cwd: path.join(home, book.name), title: book.name + ' conversation' }, live: true })),
|
|
55
|
+
readTitleSnapshots: async () => [],
|
|
56
|
+
} }
|
|
57
|
+
const privateMarker = 'BROWSER_PRIVATE_CONTENT_NOT_FOR_REPORT'
|
|
58
|
+
process.env.UI_BROWSER_API_KEY = 'sk-ui-browser-fixture-redaction-only'
|
|
59
|
+
recordDiagnostic({ level: 'error', scope: 'rpc', code: 'RPC_BROWSER_FIXTURE', message: 'failed to load worker fixture',
|
|
60
|
+
error: Object.assign(new Error('failed to load worker fixture'), { code: 'RPC_BROWSER_FIXTURE', cause: Object.assign(new Error('ENOENT fixture dependency'), { code: 'ENOENT' }) }),
|
|
61
|
+
context: { operation: 'browser-fixture', sessionId: 'browser-session-0', libraryId: books[0].id, content: privateMarker },
|
|
62
|
+
detail: { apiKey: process.env.UI_BROWSER_API_KEY, content: privateMarker }, retry: { retryable: true, afterMs: 500 } })
|
|
63
|
+
registerRpc({ get: key => services[key], logger: console,
|
|
64
|
+
inject: (_deps, callback) => callback({ effect: fn => fn(), logger: console,
|
|
65
|
+
connection: { requestRejection: req => req.headers.origin && req.headers.origin !== `http://${req.headers.host}` ? 403 : undefined,
|
|
66
|
+
authorizeLibrary: async (_req, target) => !target.libraryId || [...books, ...managementBooks].some(book => book.id === target.libraryId) },
|
|
67
|
+
webServer: { register: route => { if (route.path === '/dsh-memu-memory') handler = route.handler; return () => {} } } }) })
|
|
68
|
+
assert.equal(typeof handler, 'function')
|
|
69
|
+
const report = { startedAt: new Date().toISOString(), scenarios: [], screenshots: [], pageErrors: [] }
|
|
70
|
+
let recentCalls = []
|
|
71
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
72
|
+
const shot = async (page, name, fullPage = false) => {
|
|
73
|
+
const file = path.join(output, `recovery-ui-browser-${managementOnly ? 'orphan-' : ''}${name}.png`)
|
|
74
|
+
await page.screenshot({ path: file, fullPage })
|
|
75
|
+
report.screenshots.push(file)
|
|
76
|
+
}
|
|
77
|
+
const scrollPosition = page => page.evaluate(() => {
|
|
78
|
+
const wall = document.querySelector('.dshm-wall')
|
|
79
|
+
let node = wall
|
|
80
|
+
while (node && node !== document.body) {
|
|
81
|
+
if (/(auto|scroll)/.test(getComputedStyle(node).overflowY) && node.scrollHeight > node.clientHeight) return { top: node.scrollTop, height: node.scrollHeight }
|
|
82
|
+
node = node.parentElement
|
|
83
|
+
}
|
|
84
|
+
return { top: document.scrollingElement.scrollTop, height: document.scrollingElement.scrollHeight }
|
|
85
|
+
})
|
|
86
|
+
const scrollTop = page => page.evaluate(() => {
|
|
87
|
+
for (let node = document.querySelector('.dshm-wall'); node; node = node.parentElement) node.scrollTop = 0
|
|
88
|
+
window.scrollTo(0, 0)
|
|
89
|
+
})
|
|
90
|
+
const bottom = page => page.locator('.dshm-wall .dshm-settings-note[role="status"]').last().scrollIntoViewIfNeeded()
|
|
91
|
+
const graphView = page => page.locator('canvas.dshm-graph-canvas')
|
|
92
|
+
const graphSnapshot = page => graphView(page).evaluate(canvas => canvas.__dshmGraphView.snapshot())
|
|
93
|
+
const graphViewport = page => graphView(page).evaluate(canvas => canvas.__dshmGraphView.viewport())
|
|
94
|
+
|
|
95
|
+
async function checkOrphanManagement({ page, base, viewport, calls, write }) {
|
|
96
|
+
const book = state.createLibrary({ name: `Empty management ${viewport.width}`, cwd: path.join(home, 'empty-' + viewport.width) })
|
|
97
|
+
managementBooks.push(book)
|
|
98
|
+
state.savePrivateIndex(book.id, { version: 1, entries: {} })
|
|
99
|
+
const url = `${base}?libraryId=${encodeURIComponent(book.id)}#/settings/graph`
|
|
100
|
+
await page.goto(url); await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
101
|
+
await page.locator('.dshm-gs-topbar').getByRole('button', { name: '管理', exact: true }).waitFor()
|
|
102
|
+
assert.equal(await page.locator('.dshm-gs-topbar select[aria-label="当前记忆库"]').inputValue(), book.id)
|
|
103
|
+
await page.waitForFunction(() => !!document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView)
|
|
104
|
+
assert.equal((await graphSnapshot(page)).length, 0)
|
|
105
|
+
const start = calls.length
|
|
106
|
+
await page.locator('.dshm-gs-topbar').getByRole('button', { name: '管理', exact: true }).click()
|
|
107
|
+
const manager = page.locator('.dshm-gs-manager'), rows = manager.locator('.dshm-gs-mgr-row')
|
|
108
|
+
const include = manager.getByRole('checkbox', { name: '包含未关联实体', exact: true })
|
|
109
|
+
await manager.getByRole('button', { name: '刷新', exact: true }).waitFor({ state: 'visible' })
|
|
110
|
+
await page.waitForFunction(() => !document.querySelector('.dshm-gs-mgr-foot button[title="刷新"]')?.disabled)
|
|
111
|
+
assert.equal(await rows.count(), 0); assert.equal(await include.isChecked(), false)
|
|
112
|
+
await manager.getByRole('button', { name: '新增节点', exact: true }).click()
|
|
113
|
+
await manager.getByRole('button', { name: '实体', exact: true }).click()
|
|
114
|
+
const name = `Unique unlinked ${viewport.width}`
|
|
115
|
+
await manager.getByLabel('实体名称', { exact: true }).fill(name)
|
|
116
|
+
await shot(page, `graph-${viewport.width}-empty-create`)
|
|
117
|
+
const created = await write('createEntity', () => manager.getByRole('button', { name: '写入', exact: true }).click(), args => args.libraryId === book.id && args.name === name)
|
|
118
|
+
await rows.filter({ hasText: name }).waitFor()
|
|
119
|
+
assert.equal(await include.isChecked(), true)
|
|
120
|
+
assert.match(await manager.locator('.dshm-gs-mgr-focus[role="status"]').innerText(), new RegExp(book.id))
|
|
121
|
+
assert.ok((await manager.locator('.dshm-gs-mgr-focus[role="status"]').innerText()).includes(created.id))
|
|
122
|
+
assert.match(await manager.locator('[role="note"]').innerText(), /下次|启动/)
|
|
123
|
+
assert.equal(graph.listEntities({ libraryId: book.id, entityId: created.id }).items[0].linked, false)
|
|
124
|
+
assert.equal(Object.keys(state.loadPrivateIndex(book.id).entries).length, 0)
|
|
125
|
+
assert.equal((await graphSnapshot(page)).length, 0, 'orphan management cannot pollute the default canvas')
|
|
126
|
+
await write('getGraph', () => manager.getByRole('button', { name: '刷新', exact: true }).click(), args => args.focusId === created.id && args.includeOrphans === true)
|
|
127
|
+
await rows.filter({ hasText: name }).waitFor()
|
|
128
|
+
await shot(page, `graph-${viewport.width}-created-focus`)
|
|
129
|
+
await manager.getByRole('button', { name: '编辑节点', exact: true }).click()
|
|
130
|
+
const aliases = 'Preserved alias ' + viewport.width
|
|
131
|
+
await manager.getByLabel('别名(逗号分隔)', { exact: true }).fill(aliases)
|
|
132
|
+
await write('renameEntity', () => manager.getByRole('button', { name: '保存', exact: true }).click(), args => args.entityId === created.id)
|
|
133
|
+
await page.waitForFunction(() => !document.querySelector('.dshm-gs-mgr-add'))
|
|
134
|
+
for (let i = 0; i < 64; i++) graph.createEntity({ libraryId: book.id, name: `Unlinked decoy ${viewport.width} ${i}`, status: 'confirmed' })
|
|
135
|
+
await page.reload(); await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
136
|
+
await page.locator('.dshm-gs-topbar').getByRole('button', { name: '管理', exact: true }).click()
|
|
137
|
+
const firstPage = await write('getGraph', () => include.check(), args => args.includeOrphans === true && args.zoom === 1 && args.offset === 0 && args.limit === 60)
|
|
138
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-gs-mgr-row').length === 60)
|
|
139
|
+
const ids = new Set(firstPage.nodes.map(node => node.id))
|
|
140
|
+
assert.equal(ids.size, 60)
|
|
141
|
+
assert.deepEqual((await rows.locator('.dshm-gs-mgr-title').allTextContents()).sort(), firstPage.nodes.map(node => node.title).sort())
|
|
142
|
+
const secondPage = await write('getGraph', () => manager.getByRole('button', { name: '下一页', exact: true }).click(),
|
|
143
|
+
args => args.includeOrphans === true && args.zoom === 1 && args.offset === 60 && args.limit === 60)
|
|
144
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-gs-mgr-row').length === 5)
|
|
145
|
+
assert.ok(secondPage.nodes.every(node => !ids.has(node.id)), 'replacement pages must not reuse any full entity ID from page one')
|
|
146
|
+
assert.deepEqual((await rows.locator('.dshm-gs-mgr-title').allTextContents()).sort(), secondPage.nodes.map(node => node.title).sort())
|
|
147
|
+
await shot(page, `graph-${viewport.width}-page2`)
|
|
148
|
+
await manager.getByRole('button', { name: '上一页', exact: true }).click()
|
|
149
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-gs-mgr-row').length === 60)
|
|
150
|
+
const search = page.locator('.dshm-gs-topbar input[aria-label="搜索节点 / 证据…"]')
|
|
151
|
+
await search.fill(created.id)
|
|
152
|
+
await page.waitForFunction(expected => {
|
|
153
|
+
const rows = document.querySelectorAll('.dshm-gs-mgr-row')
|
|
154
|
+
return rows.length === 1 && rows[0].querySelector('.dshm-gs-mgr-title')?.textContent === expected
|
|
155
|
+
}, name)
|
|
156
|
+
await rows.first().click()
|
|
157
|
+
const beforeRead = calls.filter(call => call.method === 'listEntities').length
|
|
158
|
+
await write('listEntities', () => manager.getByRole('button', { name: '编辑节点', exact: true }).click(), args => args.entityId === created.id && args.libraryId === book.id)
|
|
159
|
+
assert.equal(calls.filter(call => call.method === 'listEntities').length, beforeRead + 1)
|
|
160
|
+
assert.equal(await manager.getByLabel('别名(逗号分隔)', { exact: true }).inputValue(), aliases, 'a multi-entity library supports a real bounded alias read')
|
|
161
|
+
const renamed = name + ' renamed'
|
|
162
|
+
await manager.getByLabel('实体名称', { exact: true }).fill(renamed)
|
|
163
|
+
await shot(page, `graph-${viewport.width}-multi-entity-edit`)
|
|
164
|
+
await write('renameEntity', () => manager.getByRole('button', { name: '保存', exact: true }).click(), args => args.entityId === created.id && args.aliases[0] === aliases)
|
|
165
|
+
await rows.filter({ hasText: renamed }).waitFor()
|
|
166
|
+
assert.deepEqual(graph.listEntities({ libraryId: book.id, entityId: created.id }).items[0].aliases, [aliases])
|
|
167
|
+
const deletes = calls.filter(call => call.method === 'deleteEntity').length
|
|
168
|
+
await manager.getByRole('button', { name: '删除节点', exact: true }).click()
|
|
169
|
+
assert.equal(calls.filter(call => call.method === 'deleteEntity').length, deletes)
|
|
170
|
+
assert.equal(graph.listEntities({ libraryId: book.id, entityId: created.id }).total, 1)
|
|
171
|
+
await shot(page, `graph-${viewport.width}-delete-confirm`)
|
|
172
|
+
await write('deleteEntity', () => manager.getByRole('button', { name: '删除节点', exact: true }).click(), args => args.entityId === created.id && args.libraryId === book.id)
|
|
173
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-gs-mgr-row').length === 0)
|
|
174
|
+
assert.equal(graph.listEntities({ libraryId: book.id, entityId: created.id }).total, 0)
|
|
175
|
+
assert.equal((await graphSnapshot(page)).length, 0)
|
|
176
|
+
const managerCalls = calls.slice(start).filter(call => call.method === 'getGraph' && Object.hasOwn(call.args, 'includeOrphans'))
|
|
177
|
+
assert.ok(managerCalls.every(call => call.args.libraryId === book.id && [1, 60].includes(call.args.limit)))
|
|
178
|
+
assert.ok(calls.slice(start).filter(call => call.method === 'listEntities').every(call => call.args.entityId === created.id))
|
|
179
|
+
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false)
|
|
180
|
+
const controlBoxes = await manager.locator('.dshm-gs-mgr-head > label,.dshm-gs-mgr-foot > button').evaluateAll(items => items.map(item => {
|
|
181
|
+
const rect = item.getBoundingClientRect(); return { width: rect.width, height: rect.height, left: rect.left, right: rect.right }
|
|
182
|
+
}))
|
|
183
|
+
assert.ok(controlBoxes.every(box => box.width > 40 && box.height >= 25 && box.left >= 0 && box.right <= viewport.width), 'management controls wrap without vertical names or viewport overflow')
|
|
184
|
+
await shot(page, `graph-${viewport.width}-deleted`)
|
|
185
|
+
report.scenarios.push({ name: 'unlinked-entity-management', viewport, libraryId: book.id, entityId: created.id,
|
|
186
|
+
emptyLibrary: true, linked: false, refreshReadback: true, pageReloadReadback: true, replacementPages: [60, 5],
|
|
187
|
+
multiEntityAliasRead: true, aliasesPreserved: true, deleteTwoClicks: true, defaultCanvasUnchanged: true, controlBoxes })
|
|
188
|
+
await page.goto('about:blank')
|
|
189
|
+
state.archiveLibrary(book.id)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
server = http.createServer((req, res) => { void handler(req, res).catch(error => { console.error(error); res.writeHead(500); res.end('browser fixture failure') }) })
|
|
194
|
+
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve))
|
|
195
|
+
const base = `http://127.0.0.1:${server.address().port}/dsh-memu-memory/ui`
|
|
196
|
+
console.log('isolated-browser-handle', JSON.stringify({ pid: process.pid, port: server.address().port, managementOnly }))
|
|
197
|
+
browser = await chromium.launch({ headless: true, channel: process.env.UI_BROWSER_CHANNEL || 'msedge' })
|
|
198
|
+
for (const viewport of [{ width: 1440, height: 1000 }, { width: 390, height: 844 }]) {
|
|
199
|
+
const context = await browser.newContext({ viewport, locale: 'zh-CN', reducedMotion: 'reduce' })
|
|
200
|
+
await context.grantPermissions(['clipboard-read', 'clipboard-write'], { origin: new URL(base).origin })
|
|
201
|
+
const page = await context.newPage(), calls = [], replies = []
|
|
202
|
+
recentCalls = calls
|
|
203
|
+
const write = async (method, action, match = () => true) => {
|
|
204
|
+
const [response] = await Promise.all([
|
|
205
|
+
page.waitForResponse(response => response.url().endsWith('/' + method) && match(response.request().postDataJSON().payload)), action(),
|
|
206
|
+
])
|
|
207
|
+
const result = (await response.json()).result
|
|
208
|
+
assert.equal(result?.ok, true, `${method}: ${JSON.stringify(result?.error)}`)
|
|
209
|
+
return result.value
|
|
210
|
+
}
|
|
211
|
+
page.setDefaultTimeout(15000)
|
|
212
|
+
page.on('pageerror', error => report.pageErrors.push(String(error)))
|
|
213
|
+
page.on('request', request => {
|
|
214
|
+
if (request.method() === 'POST') { const body = request.postDataJSON(); if (body?.method) calls.push({ method: body.method, args: body.payload, at: Date.now() }) }
|
|
215
|
+
})
|
|
216
|
+
page.on('response', response => {
|
|
217
|
+
if (response.request().method() !== 'POST') return
|
|
218
|
+
void response.json().then(body => replies.push({ method: response.request().postDataJSON().method,
|
|
219
|
+
args: response.request().postDataJSON().payload, ...body.result })).catch(() => {})
|
|
220
|
+
})
|
|
221
|
+
if (managementOnly) {
|
|
222
|
+
await checkOrphanManagement({ page, base, viewport, calls, write })
|
|
223
|
+
await context.close()
|
|
224
|
+
continue
|
|
225
|
+
}
|
|
226
|
+
let beat = null, frozenBeat = null, forceWrites = 0, heldQuery = null, releaseQuery = null, continuationGate = null, lastWriteTitle = ''
|
|
227
|
+
for (const method of ['getSettingsState', 'getSidebarState']) await page.route(`**/dsh-memu-memory/${method}`, async route => {
|
|
228
|
+
const response = await route.fetch(), body = await response.json()
|
|
229
|
+
if (body.result?.value) {
|
|
230
|
+
if (method === 'getSettingsState') beat = { revision: body.result.value.revision, stamp: body.result.value.stamp }
|
|
231
|
+
if (method === 'getSidebarState' && frozenBeat) Object.assign(body.result.value, frozenBeat)
|
|
232
|
+
}
|
|
233
|
+
await route.fulfill({ response, json: body })
|
|
234
|
+
})
|
|
235
|
+
await page.route('**/dsh-memu-memory/browseWall', async route => {
|
|
236
|
+
const args = route.request().postDataJSON().payload
|
|
237
|
+
if (args.offset && continuationGate) { const gate = continuationGate; continuationGate = null; await gate }
|
|
238
|
+
if (args.query === 'needle-old' && heldQuery) { const gate = heldQuery; heldQuery = null; await gate }
|
|
239
|
+
if (forceWrites && args.offset) {
|
|
240
|
+
forceWrites--
|
|
241
|
+
state.updatePrivateIndex(books[0].id, index => {
|
|
242
|
+
lastWriteTitle = 'Written before continuation ' + Date.now()
|
|
243
|
+
index.entries[id(0)].title = lastWriteTitle
|
|
244
|
+
index.entries[id(0)].updatedAt = new Date().toISOString()
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
await route.continue()
|
|
248
|
+
})
|
|
249
|
+
await page.goto(base + '#/settings/memories')
|
|
250
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
251
|
+
const cards = page.locator('.dshm-wall-item')
|
|
252
|
+
await cards.first().waitFor()
|
|
253
|
+
await page.locator('.dshm-wall select[aria-label="当前记忆库"]').selectOption(books[0].id)
|
|
254
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-wall-item').length >= 50)
|
|
255
|
+
const wallCalls = () => calls.filter(call => call.method === 'browseWall')
|
|
256
|
+
await sleep(400)
|
|
257
|
+
const firstCalls = wallCalls().length
|
|
258
|
+
assert.equal(wallCalls().at(-1).args.limit, 60)
|
|
259
|
+
assert.equal(wallCalls().at(-1).args.offset, 0)
|
|
260
|
+
await sleep(400)
|
|
261
|
+
assert.equal(wallCalls().length, firstCalls, 'mount must not automatically drain subsequent pages')
|
|
262
|
+
const firstIds = await cards.locator('strong').allTextContents()
|
|
263
|
+
let releaseContinuation
|
|
264
|
+
continuationGate = new Promise(resolve => { releaseContinuation = resolve })
|
|
265
|
+
await bottom(page)
|
|
266
|
+
await sleep(300)
|
|
267
|
+
const beforeAppend = await scrollPosition(page)
|
|
268
|
+
const cardPositions = await cards.evaluateAll(items => items.slice(-6).map(item => ({ title: item.querySelector('strong').textContent, top: item.getBoundingClientRect().top })))
|
|
269
|
+
releaseContinuation()
|
|
270
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-wall-item').length > 300)
|
|
271
|
+
const afterAppend = await scrollPosition(page)
|
|
272
|
+
console.log('append', viewport.width, JSON.stringify({ beforeAppend, afterAppend, cardPositions,
|
|
273
|
+
afterPositions: await cards.evaluateAll(items => items.slice(51, 57).map(item => ({ title: item.querySelector('strong').textContent, top: item.getBoundingClientRect().top }))) }))
|
|
274
|
+
assert.ok(Math.abs(afterAppend.top - beforeAppend.top) < 3, `append moved the scroll position: ${JSON.stringify({ beforeAppend, afterAppend })}`)
|
|
275
|
+
assert.deepEqual((await cards.locator('strong').allTextContents()).slice(0, firstIds.length), firstIds)
|
|
276
|
+
assert.equal(wallCalls().at(-1).args.offset, 60)
|
|
277
|
+
assert.equal(wallCalls().at(-1).args.limit, 300)
|
|
278
|
+
assert.ok(wallCalls().at(-1).args.snapshotRevision)
|
|
279
|
+
await scrollTop(page)
|
|
280
|
+
await shot(page, `wall-${viewport.width}-paged`)
|
|
281
|
+
|
|
282
|
+
const query = page.locator('.dshm-wall input[type="search"]')
|
|
283
|
+
await page.locator('.dshm-wall select[aria-label="域"]').selectOption('rp')
|
|
284
|
+
await query.fill('needle-new')
|
|
285
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-wall-item').length === 1 && document.querySelector('.dshm-wall-item strong')?.textContent.includes('0900'))
|
|
286
|
+
assert.equal(wallCalls().at(-1).args.domain, 'rp')
|
|
287
|
+
assert.equal(wallCalls().at(-1).args.query, 'needle-new')
|
|
288
|
+
assert.equal(wallCalls().at(-1).args.offset, 0)
|
|
289
|
+
await shot(page, `wall-${viewport.width}-filter`)
|
|
290
|
+
heldQuery = new Promise(resolve => { releaseQuery = resolve })
|
|
291
|
+
await query.fill('needle-old')
|
|
292
|
+
await page.waitForRequest(request => request.url().endsWith('/browseWall') && request.postDataJSON().payload.query === 'needle-old')
|
|
293
|
+
await query.fill('needle-new')
|
|
294
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-wall-item').length === 1 && document.querySelector('.dshm-wall-item strong')?.textContent.includes('0900'))
|
|
295
|
+
releaseQuery()
|
|
296
|
+
await sleep(400)
|
|
297
|
+
assert.match(await cards.first().innerText(), /0900/, 'a late response from the previous search must not repaint the wall')
|
|
298
|
+
|
|
299
|
+
await query.fill('')
|
|
300
|
+
await page.locator('.dshm-wall select[aria-label="域"]').selectOption('')
|
|
301
|
+
await page.waitForFunction(() => document.querySelectorAll('.dshm-wall-item').length >= 50)
|
|
302
|
+
frozenBeat = beat
|
|
303
|
+
forceWrites = 1
|
|
304
|
+
const changesBefore = replies.filter(reply => reply.method === 'browseWall' && reply.error?.code === 'MEMORY_CHANGED').length
|
|
305
|
+
const restarted = page.waitForResponse(response => response.url().endsWith('/browseWall') && response.request().postDataJSON().payload.offset === 0)
|
|
306
|
+
continuationGate = new Promise(resolve => { releaseContinuation = resolve })
|
|
307
|
+
await bottom(page)
|
|
308
|
+
await sleep(300)
|
|
309
|
+
releaseContinuation()
|
|
310
|
+
await restarted
|
|
311
|
+
await page.waitForFunction(title => document.querySelector('.dshm-wall-item strong')?.textContent === title, lastWriteTitle)
|
|
312
|
+
await sleep(150)
|
|
313
|
+
assert.equal(replies.filter(reply => reply.method === 'browseWall' && reply.error?.code === 'MEMORY_CHANGED').length, changesBefore + 1)
|
|
314
|
+
assert.equal(wallCalls().at(-1).args.offset, 0, 'a write restarts the first page without the old cursor: ' + JSON.stringify(wallCalls().slice(-5)))
|
|
315
|
+
assert.equal(wallCalls().at(-1).args.snapshotRevision, undefined)
|
|
316
|
+
assert.ok(await cards.count() <= 60, 'a restarted snapshot must not contain rows appended from the old one')
|
|
317
|
+
const restartScroll = await scrollPosition(page)
|
|
318
|
+
await scrollTop(page)
|
|
319
|
+
await shot(page, `wall-${viewport.width}-restart`)
|
|
320
|
+
report.scenarios.push({ name: 'wall', viewport, firstPage: 60, continuation: 300, firstCalls, beforeAppend, afterAppend,
|
|
321
|
+
queryOutsidePreview: true, staleQueryDropped: true, snapshotRestart: true, restartScroll })
|
|
322
|
+
|
|
323
|
+
if (viewport.width === 1440) {
|
|
324
|
+
forceWrites = 3
|
|
325
|
+
// One automatic restart was already spent; the next two conflicts stop this query.
|
|
326
|
+
for (let i = 0; i < 2; i++) {
|
|
327
|
+
await bottom(page)
|
|
328
|
+
await sleep(400)
|
|
329
|
+
}
|
|
330
|
+
await page.locator('.dshm-wall [role="alert"]').filter({ hasText: 'MEMORY_CHANGED' }).waitFor()
|
|
331
|
+
const stopped = wallCalls().length
|
|
332
|
+
await sleep(600)
|
|
333
|
+
assert.equal(wallCalls().length, stopped, 'bounded restart must stop without an observer retry loop')
|
|
334
|
+
forceWrites = 0
|
|
335
|
+
await page.locator('.dshm-wall [role="alert"]').getByRole('button').click()
|
|
336
|
+
await cards.first().waitFor()
|
|
337
|
+
report.scenarios.push({ name: 'wall-bounded-restart', automaticRestarts: 2, stopped: true, explicitRetry: true })
|
|
338
|
+
}
|
|
339
|
+
frozenBeat = null
|
|
340
|
+
await page.goto(base + '?libraryId=' + books[1].id + '#/settings/browser')
|
|
341
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
342
|
+
const oldEntryReads = calls.filter(call => ['suggestEntityMerges', 'getAnchorCandidates'].includes(call.method)).length
|
|
343
|
+
await page.getByRole('tab', { name: '关系', exact: true }).click()
|
|
344
|
+
const graphEntry = page.getByRole('button', { name: '打开关系图谱', exact: true })
|
|
345
|
+
await graphEntry.waitFor(); await sleep(100)
|
|
346
|
+
assert.equal(calls.filter(call => ['suggestEntityMerges', 'getAnchorCandidates'].includes(call.method)).length, oldEntryReads,
|
|
347
|
+
'the browser relations entry cannot mount the legacy full entity/candidate panel')
|
|
348
|
+
await graphEntry.click()
|
|
349
|
+
await page.waitForFunction(() => location.hash === '#/settings/graph')
|
|
350
|
+
await page.waitForFunction(() => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().length > 0)
|
|
351
|
+
assert.equal(await page.locator('.dshm-gs-topbar select[aria-label="当前记忆库"]').inputValue(), books[1].id)
|
|
352
|
+
assert.equal(calls.filter(call => ['suggestEntityMerges', 'getAnchorCandidates'].includes(call.method)).length, oldEntryReads)
|
|
353
|
+
assert.equal(calls.filter(call => call.method === 'getGraph').at(-1).args.libraryId, books[1].id)
|
|
354
|
+
await shot(page, `browser-${viewport.width}-graph-entry`)
|
|
355
|
+
report.scenarios.push({ name: 'browser-relations-route', viewport, selectedLibraryInherited: true, legacyPanelAbsent: true, collapsedCandidateReads: 0 })
|
|
356
|
+
await page.goto(base + '#/settings/graph')
|
|
357
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
358
|
+
const canvas = graphView(page)
|
|
359
|
+
await page.waitForFunction(() => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().length > 0)
|
|
360
|
+
const graphCalls = () => calls.filter(call => call.method === 'getGraph')
|
|
361
|
+
const scene = async () => {
|
|
362
|
+
const box = await canvas.boundingBox()
|
|
363
|
+
return { box, nodes: await graphSnapshot(page), viewport: await graphViewport(page) }
|
|
364
|
+
}
|
|
365
|
+
const initialGraphCalls = graphCalls().length
|
|
366
|
+
await sleep(600)
|
|
367
|
+
assert.ok(graphCalls().slice(initialGraphCalls).every(call => !call.args.bbox),
|
|
368
|
+
'initial update/fit must not schedule a bbox fetch: ' + JSON.stringify(graphCalls()))
|
|
369
|
+
let initial = await scene()
|
|
370
|
+
const expandable = new Set(replies.filter(reply => reply.method === 'getGraph' && reply.ok).at(-1).value.nodes.filter(node => node.count > 1).map(node => node.id))
|
|
371
|
+
const cluster = initial.nodes.find(node => expandable.has(node.id) && node.x > 20 && node.x < initial.box.width - 20 && node.y > 20 && node.y < initial.box.height - 20)
|
|
372
|
+
assert.ok(cluster)
|
|
373
|
+
const expanded = page.waitForResponse(response => response.url().endsWith('/getGraph') && Boolean(response.request().postDataJSON().payload.clusterId))
|
|
374
|
+
await page.mouse.click(initial.box.x + cluster.x, initial.box.y + cluster.y)
|
|
375
|
+
await expanded
|
|
376
|
+
await sleep(400)
|
|
377
|
+
assert.ok(graphCalls().at(-1).args.clusterId)
|
|
378
|
+
const expandedCount = (await graphSnapshot(page)).length
|
|
379
|
+
assert.ok(expandedCount > 1 && expandedCount <= 3000, 'expand must show a real connected component: ' + expandedCount)
|
|
380
|
+
await shot(page, `graph-${viewport.width}-expanded`)
|
|
381
|
+
const overview = page.waitForResponse(response => response.url().endsWith('/getGraph') && !response.request().postDataJSON().payload.clusterId && !response.request().postDataJSON().payload.bbox)
|
|
382
|
+
await page.locator('.dshm-gs-status').getByRole('button', { name: '总览', exact: true }).click()
|
|
383
|
+
await overview
|
|
384
|
+
await sleep(400)
|
|
385
|
+
await shot(page, `graph-${viewport.width}-overview`)
|
|
386
|
+
initial = await scene()
|
|
387
|
+
const center = initial.nodes.find(node => node.x > 25 && node.x < initial.box.width - 25 && node.y > 25 && node.y < initial.box.height - 25)
|
|
388
|
+
assert.ok(center)
|
|
389
|
+
await page.mouse.move(initial.box.x + center.x, initial.box.y + center.y)
|
|
390
|
+
const near = page.waitForResponse(response => response.url().endsWith('/getGraph') && response.request().postDataJSON().payload.zoom >= 1)
|
|
391
|
+
for (let i = 0; i < 12 && (await graphViewport(page)).zoom < 1; i++) await page.mouse.wheel(0, -500)
|
|
392
|
+
await near
|
|
393
|
+
await sleep(400)
|
|
394
|
+
assert.ok(graphCalls().at(-1).args.limit <= 3000)
|
|
395
|
+
assert.ok((await graphSnapshot(page)).length <= 3000)
|
|
396
|
+
const nearCalls = graphCalls().length
|
|
397
|
+
await sleep(500)
|
|
398
|
+
assert.equal(graphCalls().length, nearCalls, 'viewport results cannot cause a camera request loop')
|
|
399
|
+
const box = await canvas.boundingBox()
|
|
400
|
+
const panned = page.waitForResponse(response => response.url().endsWith('/getGraph') && Boolean(response.request().postDataJSON().payload.bbox))
|
|
401
|
+
await page.mouse.move(box.x + 8, box.y + 8); await page.mouse.down()
|
|
402
|
+
await page.mouse.move(box.x + 80, box.y + 55, { steps: 10 }); await page.mouse.up()
|
|
403
|
+
await panned
|
|
404
|
+
await sleep(350)
|
|
405
|
+
assert.equal(graphCalls().length, nearCalls + 1, 'a pan burst makes one trailing request')
|
|
406
|
+
await shot(page, `graph-${viewport.width}-viewport`)
|
|
407
|
+
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
|
|
408
|
+
const far = page.waitForResponse(response => response.url().endsWith('/getGraph') && response.request().postDataJSON().payload.zoom < 1)
|
|
409
|
+
await page.mouse.wheel(0, 2400)
|
|
410
|
+
await far
|
|
411
|
+
await sleep(350)
|
|
412
|
+
assert.equal(graphCalls().at(-1).args.limit, 200)
|
|
413
|
+
const lastReply = replies.filter(reply => reply.method === 'getGraph' && reply.ok).at(-1)
|
|
414
|
+
assert.equal(lastReply.value.mode, 'clusters')
|
|
415
|
+
const paintedPixels = await canvas.evaluate(element => {
|
|
416
|
+
const data = element.getContext('2d').getImageData(0, 0, element.width, element.height).data
|
|
417
|
+
let painted = 0
|
|
418
|
+
for (let i = 3; i < data.length; i += 4) if (data[i]) painted++
|
|
419
|
+
return painted
|
|
420
|
+
})
|
|
421
|
+
assert.ok(paintedPixels > 100)
|
|
422
|
+
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false)
|
|
423
|
+
report.scenarios.push({ name: 'graph', viewport, expandedCount, realWheel: true, realPan: true, trailingPanRequests: 1,
|
|
424
|
+
returnsToClusters: true, requestLoop: false, paintedPixels })
|
|
425
|
+
|
|
426
|
+
const librarySelect = page.locator('.dshm-gs-topbar select[aria-label="当前记忆库"]')
|
|
427
|
+
await librarySelect.selectOption('__global__')
|
|
428
|
+
await page.waitForFunction(() => {
|
|
429
|
+
const nodes = document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot() || []
|
|
430
|
+
return new Set(nodes.map(node => { try { return JSON.parse(node.id)[0] } catch { return '' } })).size === 2
|
|
431
|
+
})
|
|
432
|
+
let merged = await scene()
|
|
433
|
+
const localB = replies.filter(reply => reply.method === 'getGraph' && reply.ok && reply.args.libraryId === books[1].id && !reply.args.bbox).at(-1).value.nodes
|
|
434
|
+
const localMap = new Map(localB.map(node => [node.id, node]))
|
|
435
|
+
const worldB = merged.nodes.find(node => { try { return JSON.parse(node.id)[0] === books[1].id && localMap.has(JSON.parse(node.id)[1]) } catch { return false } })
|
|
436
|
+
assert.ok(worldB)
|
|
437
|
+
const shiftB = worldB.worldX - localMap.get(JSON.parse(worldB.id)[1]).x
|
|
438
|
+
assert.ok(shiftB > 0, 'the second library needs a distinct merged world origin')
|
|
439
|
+
await page.mouse.move(merged.box.x + worldB.x, merged.box.y + worldB.y)
|
|
440
|
+
const mergedNear = page.waitForResponse(response => response.url().endsWith('/getGraph') && response.request().postDataJSON().payload.libraryId === books[1].id && response.request().postDataJSON().payload.zoom >= 1)
|
|
441
|
+
for (let i = 0; i < 14 && (await graphViewport(page)).zoom < 1; i++) await page.mouse.wheel(0, -500)
|
|
442
|
+
await mergedNear; await sleep(400)
|
|
443
|
+
const bRead = graphCalls().filter(call => call.args.bbox && call.args.libraryId === books[1].id).at(-1).args
|
|
444
|
+
const worldCamera = await graphViewport(page)
|
|
445
|
+
assert.ok(Math.abs(bRead.bbox.minX - (worldCamera.bbox.minX - shiftB)) < .01, 'merged bbox is converted into library-local coordinates')
|
|
446
|
+
assert.equal(bRead.sessionId, undefined)
|
|
447
|
+
assert.ok((await graphSnapshot(page)).length <= 3000)
|
|
448
|
+
await shot(page, `graph-${viewport.width}-merged`)
|
|
449
|
+
report.scenarios.push({ name: 'merged-viewport', viewport, shiftB, localBbox: bRead.bbox, aggregateCredentials: true, bounded: true })
|
|
450
|
+
|
|
451
|
+
const bookIndex = viewport.width === 1440 ? 0 : 1, book = books[bookIndex], fixture = actionEntities[bookIndex]
|
|
452
|
+
await librarySelect.selectOption(book.id)
|
|
453
|
+
await sleep(500)
|
|
454
|
+
let pinScene = await scene()
|
|
455
|
+
const stableClusters = new Set(replies.filter(reply => reply.method === 'getGraph' && reply.ok && reply.args.libraryId === book.id).at(-1).value.nodes
|
|
456
|
+
.filter(node => node.kind === 'cluster' && node.count === 64).map(node => node.id))
|
|
457
|
+
const pinCluster = pinScene.nodes.find(node => stableClusters.has(node.id) && node.x > 30 && node.x < pinScene.box.width - 30 && node.y > 30 && node.y < pinScene.box.height - 30)
|
|
458
|
+
assert.ok(pinCluster)
|
|
459
|
+
await page.mouse.click(pinScene.box.x + pinCluster.x, pinScene.box.y + pinCluster.y, { button: 'right' })
|
|
460
|
+
assert.equal((await graphSnapshot(page)).find(node => node.id === pinCluster.id)?.pinned, true)
|
|
461
|
+
const pinDetail = await write('getGraph', () => page.mouse.click(pinScene.box.x + pinCluster.x, pinScene.box.y + pinCluster.y), args => args.clusterId === pinCluster.id)
|
|
462
|
+
await page.waitForFunction(ids => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().some(node => ids.includes(node.id)), pinDetail.nodes.map(node => node.id))
|
|
463
|
+
pinScene = await scene()
|
|
464
|
+
const pinNode = pinScene.nodes.find(node => node.id.startsWith('mem-ui-') && Number(node.id.slice(7)) >= 64
|
|
465
|
+
&& node.x > 30 && node.x < pinScene.box.width - 30 && node.y > 30 && node.y < pinScene.box.height - 30)
|
|
466
|
+
assert.ok(pinNode)
|
|
467
|
+
await page.mouse.click(pinScene.box.x + pinNode.x, pinScene.box.y + pinNode.y, { button: 'right' })
|
|
468
|
+
assert.equal((await graphSnapshot(page)).find(node => node.id === pinNode.id)?.pinned, true)
|
|
469
|
+
const pinScope = await canvas.evaluate(element => element.__dshmGraphView.diagnostics().localPhysics.positionScope)
|
|
470
|
+
const cameraBeforeWrite = await graphViewport(page)
|
|
471
|
+
const actionPanel = page.locator('.dshm-gs-actions')
|
|
472
|
+
const entry = page.locator('.dshm-gs-topbar').getByRole('button', { name: '图谱处理', exact: true })
|
|
473
|
+
assert.match(await entry.innerText(), /待检查/, 'the graph entry does not invent a count before an explicit candidate read')
|
|
474
|
+
assert.equal(calls.filter(call => ['getAnchorCandidates', 'suggestEntityMerges'].includes(call.method)).length, 0, 'a collapsed graph entry cannot start full-body ngram work or a candidate scan')
|
|
475
|
+
await entry.click()
|
|
476
|
+
await actionPanel.waitFor()
|
|
477
|
+
const pendingCard = actionPanel.locator('.dshm-gs-action-row').filter({ hasText: 'Review Traveler' }).first()
|
|
478
|
+
await pendingCard.waitFor()
|
|
479
|
+
const confirmationsBefore = calls.filter(call => call.method === 'confirmEntities').length
|
|
480
|
+
await pendingCard.getByRole('button', { name: '确认', exact: true }).click()
|
|
481
|
+
assert.equal(calls.filter(call => call.method === 'confirmEntities').length, confirmationsBefore)
|
|
482
|
+
await write('confirmEntities', () => pendingCard.getByRole('button', { name: '确认执行?', exact: true }).click())
|
|
483
|
+
assert.equal(graph.listEntities({ libraryId: book.id }).items.find(entity => entity.id === fixture.pending.id)?.status, 'confirmed')
|
|
484
|
+
const mergeCard = actionPanel.locator('.dshm-gs-sec').filter({ hasText: 'Harbor Alic' }).first()
|
|
485
|
+
await mergeCard.getByRole('button', { name: '合并', exact: true }).first().hover()
|
|
486
|
+
const nameBox = await mergeCard.locator('.dshm-gs-merge-pair > span').first().boundingBox()
|
|
487
|
+
const actionBox = await mergeCard.getByRole('button', { name: '合并', exact: true }).first().boundingBox()
|
|
488
|
+
const pairBox = await mergeCard.locator('.dshm-gs-merge-pair').boundingBox()
|
|
489
|
+
assert.ok(nameBox.width >= pairBox.width - 2, 'candidate names and direction occupy their own readable row')
|
|
490
|
+
assert.ok(actionBox.y >= nameBox.y + nameBox.height - 1, 'candidate actions wrap below the names')
|
|
491
|
+
await shot(page, `graph-${viewport.width}-candidates`)
|
|
492
|
+
const rename = async name => {
|
|
493
|
+
const response = await page.request.post(base.replace(/\/ui$/, '/renameEntity'), { data: {
|
|
494
|
+
type: 'client-request', rpcId: 'browser-rename-' + Date.now(), method: 'renameEntity', payload: { libraryId: book.id, entityId: fixture.target.id, name },
|
|
495
|
+
} })
|
|
496
|
+
assert.equal((await response.json()).result.ok, true)
|
|
497
|
+
}
|
|
498
|
+
for (const [method, label, suffix] of [['setEntityMergeRejection', '不是同一实体', 'candidate-changed'], ['mergeEntities', '合并', 'merge-changed']]) {
|
|
499
|
+
const oldPair = graph.suggestEntityMerges({ libraryId: book.id }).items[0]
|
|
500
|
+
let queued, releaseQueued
|
|
501
|
+
const queuedRequest = new Promise(resolve => { queued = resolve }), releaseDecision = new Promise(resolve => { releaseQueued = resolve })
|
|
502
|
+
await page.route('**/dsh-memu-memory/' + method, async route => { queued(); await releaseDecision; await route.continue() }, { times: 1 })
|
|
503
|
+
await mergeCard.getByRole('button', { name: label, exact: true }).click()
|
|
504
|
+
const staleDecisionResponse = page.waitForResponse(response => response.url().endsWith('/' + method))
|
|
505
|
+
await mergeCard.getByRole('button', { name: '确认执行?', exact: true }).click()
|
|
506
|
+
await queuedRequest
|
|
507
|
+
await rename('Harbor Alicia')
|
|
508
|
+
releaseQueued()
|
|
509
|
+
const staleDecision = (await (await staleDecisionResponse).json()).result
|
|
510
|
+
assert.equal(staleDecision.ok, false)
|
|
511
|
+
assert.equal(staleDecision.error.code, 'ENTITY_MERGE_CANDIDATE_CHANGED')
|
|
512
|
+
const oldRequest = calls.filter(call => call.method === method).at(-1)
|
|
513
|
+
assert.equal(oldRequest.args.reviewToken, oldPair.reviewToken)
|
|
514
|
+
await page.waitForFunction(() => document.querySelector('.dshm-gs-action-result')?.textContent.includes('ENTITY_MERGE_CANDIDATE_CHANGED'))
|
|
515
|
+
assert.equal(graph.suggestEntityMerges({ libraryId: book.id }).rejectedTotal, 0)
|
|
516
|
+
assert.ok(graph.listEntities({ libraryId: book.id }).items.some(entity => entity.id === fixture.source.id))
|
|
517
|
+
await actionPanel.locator('.dshm-gs-action-result').scrollIntoViewIfNeeded()
|
|
518
|
+
await shot(page, `graph-${viewport.width}-${suffix}`)
|
|
519
|
+
await rename('Harbor Alice')
|
|
520
|
+
await write('suggestEntityMerges', () => actionPanel.getByRole('button', { name: '从头检查', exact: true }).click())
|
|
521
|
+
await sleep(200)
|
|
522
|
+
}
|
|
523
|
+
const pendingBeforeReject = graph.suggestEntityMerges({ libraryId: book.id }).total
|
|
524
|
+
const rejectionsBefore = calls.filter(call => call.method === 'setEntityMergeRejection').length
|
|
525
|
+
await mergeCard.getByRole('button', { name: '不是同一实体', exact: true }).click()
|
|
526
|
+
assert.equal(calls.filter(call => call.method === 'setEntityMergeRejection').length, rejectionsBefore)
|
|
527
|
+
await write('setEntityMergeRejection', () => mergeCard.getByRole('button', { name: '确认执行?', exact: true }).click(), args => args.rejected === true && args.confirmed === true && args.libraryId === book.id)
|
|
528
|
+
const excluded = actionPanel.locator('details').filter({ has: page.locator('summary', { hasText: /^已排除的相似候选/ }) })
|
|
529
|
+
await page.waitForFunction(() => document.querySelector('.dshm-gs-topbar button[aria-label="图谱处理"] .dshm-gs-count')?.textContent === '0')
|
|
530
|
+
assert.equal(graph.suggestEntityMerges({ libraryId: book.id }).total, pendingBeforeReject - 1)
|
|
531
|
+
assert.equal(graph.suggestEntityMerges({ libraryId: book.id }).rejectedTotal, 1)
|
|
532
|
+
await excluded.locator('summary').click()
|
|
533
|
+
await excluded.getByRole('button', { name: '恢复候选', exact: true }).waitFor()
|
|
534
|
+
await shot(page, `graph-${viewport.width}-excluded`)
|
|
535
|
+
const proofPage = await context.newPage()
|
|
536
|
+
proofPage.on('pageerror', error => report.pageErrors.push(String(error)))
|
|
537
|
+
await proofPage.goto(base + '#/settings/graph')
|
|
538
|
+
await proofPage.locator('#boot').waitFor({ state: 'hidden' })
|
|
539
|
+
await proofPage.locator('.dshm-gs-topbar select[aria-label="当前记忆库"]').selectOption(book.id)
|
|
540
|
+
await proofPage.locator('.dshm-gs-topbar').getByRole('button', { name: '图谱处理', exact: true }).click()
|
|
541
|
+
await proofPage.locator('.dshm-gs-actions details').filter({ has: proofPage.locator('summary', { hasText: /^已排除的相似候选 1$/ }) }).waitFor()
|
|
542
|
+
await proofPage.close()
|
|
543
|
+
await excluded.getByRole('button', { name: '恢复候选', exact: true }).click()
|
|
544
|
+
assert.equal(calls.filter(call => call.method === 'setEntityMergeRejection').length, rejectionsBefore + 1)
|
|
545
|
+
await write('setEntityMergeRejection', () => excluded.getByRole('button', { name: '确认执行?', exact: true }).click(), args => args.rejected === false && args.confirmed === true && args.libraryId === book.id)
|
|
546
|
+
await mergeCard.getByRole('button', { name: '不是同一实体', exact: true }).waitFor()
|
|
547
|
+
assert.equal(graph.suggestEntityMerges({ libraryId: book.id }).total, pendingBeforeReject)
|
|
548
|
+
assert.equal(graph.suggestEntityMerges({ libraryId: book.id }).rejectedTotal, 0)
|
|
549
|
+
assert.ok(graph.listEntities({ libraryId: book.id }).items.some(entity => entity.id === fixture.source.id))
|
|
550
|
+
await shot(page, `graph-${viewport.width}-candidate-restored`)
|
|
551
|
+
report.scenarios.push({ name: 'graph-candidate-exclusion', viewport, twoClicks: true, persistedAcrossPageLoad: true,
|
|
552
|
+
staleIdentityRejected: true, staleMergeIdentityRejected: true, restored: true, totalReloaded: true, entitiesRetained: true, sourceLibrary: book.id })
|
|
553
|
+
const mergeButton = mergeCard.getByRole('button', { name: '合并', exact: true }).first()
|
|
554
|
+
const beforeMerges = calls.filter(call => call.method === 'mergeEntities').length
|
|
555
|
+
await mergeButton.click(); await sleep(80)
|
|
556
|
+
assert.equal(calls.filter(call => call.method === 'mergeEntities').length, beforeMerges)
|
|
557
|
+
const mergedWrite = page.waitForResponse(response => response.url().endsWith('/mergeEntities'))
|
|
558
|
+
await mergeCard.getByRole('button', { name: '确认执行?', exact: true }).click()
|
|
559
|
+
await mergedWrite
|
|
560
|
+
await page.waitForFunction(() => document.querySelector('.dshm-gs-action-result')?.textContent.includes('Harbor'))
|
|
561
|
+
assert.ok(!graph.listEntities({ libraryId: book.id }).items.some(entity => entity.id === fixture.source.id))
|
|
562
|
+
assert.ok(state.loadPrivateIndex(book.id).entries[id(0)].content.includes('Synthetic browser verification memory.'))
|
|
563
|
+
await shot(page, `graph-${viewport.width}-merge-receipt`)
|
|
564
|
+
|
|
565
|
+
const linkDetails = actionPanel.locator('details').filter({ has: page.locator('summary', { hasText: /^建立关联$/ }) })
|
|
566
|
+
await linkDetails.locator('summary').first().click()
|
|
567
|
+
await actionPanel.getByLabel('来源记忆 ID', { exact: true }).fill(id(1))
|
|
568
|
+
await actionPanel.getByLabel('目标记忆或实体 ID', { exact: true }).fill(id(2))
|
|
569
|
+
await actionPanel.getByLabel('关系类型', { exact: true }).selectOption('event')
|
|
570
|
+
await actionPanel.getByLabel('关联置信度', { exact: true }).fill('0.85')
|
|
571
|
+
await actionPanel.getByLabel('关系依据(至少 8 字)', { exact: true }).fill('Browser verified relationship evidence')
|
|
572
|
+
const beforeLinks = calls.filter(call => call.method === 'linkEntries').length
|
|
573
|
+
await linkDetails.getByRole('button', { name: '建立关联', exact: true }).click()
|
|
574
|
+
assert.equal(calls.filter(call => call.method === 'linkEntries').length, beforeLinks)
|
|
575
|
+
let writeResponse = page.waitForResponse(response => response.url().endsWith('/linkEntries'))
|
|
576
|
+
await linkDetails.getByRole('button', { name: '确认执行?', exact: true }).click()
|
|
577
|
+
await writeResponse; await sleep(250)
|
|
578
|
+
assert.ok(state.loadPrivateIndex(book.id).entries[id(1)].links.some(edge => edge.to === id(2) && edge.kind === 'event' && edge.confidence === .85))
|
|
579
|
+
await shot(page, `graph-${viewport.width}-linked`)
|
|
580
|
+
await actionPanel.getByLabel('来源记忆 ID', { exact: true }).fill(id(0))
|
|
581
|
+
await actionPanel.getByLabel('目标记忆或实体 ID', { exact: true }).fill(fixture.target.id)
|
|
582
|
+
await actionPanel.getByLabel('关系类型', { exact: true }).selectOption('person')
|
|
583
|
+
await linkDetails.getByRole('button', { name: '移除关联', exact: true }).click()
|
|
584
|
+
writeResponse = page.waitForResponse(response => response.url().endsWith('/unlinkEntry'))
|
|
585
|
+
await linkDetails.getByRole('button', { name: '确认执行?', exact: true }).click()
|
|
586
|
+
await writeResponse; await sleep(250)
|
|
587
|
+
assert.ok(!state.loadPrivateIndex(book.id).entries[id(0)].links.some(edge => edge.to === fixture.target.id))
|
|
588
|
+
await shot(page, `graph-${viewport.width}-unlinked`)
|
|
589
|
+
const pinAfter = (await graphSnapshot(page)).find(node => node.id === pinNode.id)
|
|
590
|
+
assert.equal(pinAfter?.pinned, true, 'writes retain an existing user pin')
|
|
591
|
+
assert.equal(pinAfter.worldX, pinNode.worldX)
|
|
592
|
+
assert.equal(pinAfter.worldY, pinNode.worldY)
|
|
593
|
+
const cameraAfterWrite = await graphViewport(page)
|
|
594
|
+
assert.deepEqual(cameraAfterWrite, cameraBeforeWrite, 'writes must not fit or move the camera')
|
|
595
|
+
assert.equal(await canvas.evaluate(element => element.__dshmGraphView.diagnostics().localPhysics.positionScope), pinScope)
|
|
596
|
+
assert.equal((await graphSnapshot(page)).some(node => node.id === pinCluster.id), false,
|
|
597
|
+
'a cluster pin is absent from the detail snapshot, rather than reported as unpinned')
|
|
598
|
+
await write('getGraph', () => page.locator('.dshm-gs-status').getByRole('button', { name: '总览', exact: true }).click(), args => !args.clusterId && !args.bbox)
|
|
599
|
+
await page.waitForFunction(target => !document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().some(node => node.id === target), pinNode.id)
|
|
600
|
+
await page.waitForFunction(target => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().some(node => node.id === target), pinCluster.id)
|
|
601
|
+
const clusterReturned = (await graphSnapshot(page)).find(node => node.id === pinCluster.id)
|
|
602
|
+
assert.equal(clusterReturned.pinned, true, 'returning to overview restores the original cluster pin')
|
|
603
|
+
assert.equal(clusterReturned.worldX, pinCluster.worldX)
|
|
604
|
+
assert.equal(clusterReturned.worldY, pinCluster.worldY)
|
|
605
|
+
if (!(await page.locator('.dshm-gs').getAttribute('class')).includes('is-collapsed')) await page.locator('.dshm-gs-topbar .dshm-gs-icon').click()
|
|
606
|
+
const returnScene = await scene(), returnCluster = returnScene.nodes.find(node => node.id === pinCluster.id)
|
|
607
|
+
assert.ok(returnCluster, 'the unchanged memory component remains reachable after management writes')
|
|
608
|
+
await write('getGraph', () => page.mouse.click(returnScene.box.x + returnCluster.x, returnScene.box.y + returnCluster.y), args => args.clusterId === pinCluster.id)
|
|
609
|
+
await page.waitForFunction(target => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().some(node => node.id === target), pinNode.id)
|
|
610
|
+
const pinReturned = (await graphSnapshot(page)).find(node => node.id === pinNode.id)
|
|
611
|
+
assert.equal(pinReturned.pinned, true, 'returning to the actual node viewport restores the user pin')
|
|
612
|
+
assert.equal(pinReturned.worldX, pinNode.worldX, 'returning restores the exact pinned world X')
|
|
613
|
+
assert.equal(pinReturned.worldY, pinNode.worldY, 'returning restores the exact pinned world Y')
|
|
614
|
+
assert.equal(await canvas.evaluate(element => element.__dshmGraphView.diagnostics().localPhysics.positionScope), pinScope)
|
|
615
|
+
console.log('pin-roundtrip', JSON.stringify({ width: viewport.width, id: pinNode.id, positionScope: pinScope,
|
|
616
|
+
before: pinNode, afterWrites: pinAfter, returned: pinReturned, cameraBeforeWrite, cameraAfterWrite,
|
|
617
|
+
clusterBefore: pinCluster, clusterReturned }))
|
|
618
|
+
await shot(page, `graph-${viewport.width}-pin-restored`)
|
|
619
|
+
await write('getGraph', () => page.locator('.dshm-gs-status').getByRole('button', { name: '总览', exact: true }).click(), args => !args.clusterId && !args.bbox)
|
|
620
|
+
await page.waitForFunction(target => !document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().some(node => node.id === target), pinNode.id)
|
|
621
|
+
report.scenarios.push({ name: 'graph-management', viewport, candidateEntry: true, mergeTwoClicks: true, memoryRetained: true,
|
|
622
|
+
confirmTwoClicks: true, linkPersisted: true, confidence: .85, autoEdgeRemoved: true, pinPreserved: true, cameraPreserved: true,
|
|
623
|
+
pinViewportRoundtrip: { id: pinNode.id, positionScope: pinScope, before: pinNode, afterWrites: pinAfter, returned: pinReturned,
|
|
624
|
+
clusterBefore: pinCluster, clusterReturned }, sourceLibrary: book.id })
|
|
625
|
+
|
|
626
|
+
const collapseInspector = page.locator('.dshm-gs-topbar .dshm-gs-icon')
|
|
627
|
+
if (!(await page.locator('.dshm-gs').getAttribute('class')).includes('is-collapsed')) await collapseInspector.click()
|
|
628
|
+
let suppressionScene = await scene()
|
|
629
|
+
const suppressionCluster = suppressionScene.nodes.find(node => node.x > 25 && node.x < suppressionScene.box.width - 25 && node.y > 25 && node.y < suppressionScene.box.height - 25)
|
|
630
|
+
assert.ok(suppressionCluster)
|
|
631
|
+
await write('getGraph', () => page.mouse.click(suppressionScene.box.x + suppressionCluster.x, suppressionScene.box.y + suppressionCluster.y), args => Boolean(args.clusterId))
|
|
632
|
+
await sleep(300)
|
|
633
|
+
suppressionScene = await scene()
|
|
634
|
+
const suppressedNode = suppressionScene.nodes.find(node => node.id.startsWith('mem-ui-') && node.x > 25 && node.x < suppressionScene.box.width - 25 && node.y > 25 && node.y < suppressionScene.box.height - 25)
|
|
635
|
+
assert.ok(suppressedNode)
|
|
636
|
+
await page.mouse.click(suppressionScene.box.x + suppressedNode.x, suppressionScene.box.y + suppressedNode.y)
|
|
637
|
+
await page.waitForFunction(expected => document.querySelector('.dshm-gs-inspector .dshm-gs-kv dd')?.textContent === expected, suppressedNode.id)
|
|
638
|
+
await collapseInspector.click()
|
|
639
|
+
const selectedId = page.locator('.dshm-gs-inspector .dshm-gs-kv dd').first()
|
|
640
|
+
assert.equal(await selectedId.innerText(), suppressedNode.id, 'the actual selected node must match the intended suppression target')
|
|
641
|
+
const suppressDetails = actionPanel.locator('details').filter({ has: page.locator('summary', { hasText: /排除自动召回/ }) })
|
|
642
|
+
await suppressDetails.locator('summary').first().click()
|
|
643
|
+
const suppressCalls = calls.filter(call => call.method === 'updateMemory').length
|
|
644
|
+
await suppressDetails.getByRole('button', { name: '排除自动召回', exact: true }).click()
|
|
645
|
+
assert.equal(calls.filter(call => call.method === 'updateMemory').length, suppressCalls)
|
|
646
|
+
assert.equal(await selectedId.innerText(), suppressedNode.id, 'arming suppression must not select a different node')
|
|
647
|
+
await write('updateMemory', () => suppressDetails.getByRole('button', { name: '确认执行?', exact: true }).click(),
|
|
648
|
+
args => args.libraryId === book.id && args.id === suppressedNode.id && args.patch.status === 'suppressed')
|
|
649
|
+
console.log('suppression-selection', JSON.stringify({ width: viewport.width, expectedId: suppressedNode.id,
|
|
650
|
+
actualIdBeforeConfirm: suppressedNode.id, payload: calls.filter(call => call.method === 'updateMemory').at(-1).args }))
|
|
651
|
+
assert.equal(state.loadPrivateIndex(book.id).entries[suppressedNode.id].status, 'suppressed')
|
|
652
|
+
await shot(page, `graph-${viewport.width}-suppressed`)
|
|
653
|
+
await page.goto(base + '#/settings/memories')
|
|
654
|
+
await page.locator('.dshm-wall select[aria-label="当前记忆库"]').selectOption(book.id)
|
|
655
|
+
await page.locator('.dshm-wall input[type="search"]').fill(suppressedNode.id)
|
|
656
|
+
await page.locator('.dshm-wall button').filter({ hasText: /^已失效/ }).first().click()
|
|
657
|
+
await page.locator('.dshm-wall-item').first().click()
|
|
658
|
+
const drawer = page.locator('.dshm-drawer')
|
|
659
|
+
await write('updateMemory', () => drawer.getByRole('button', { name: '恢复', exact: true }).click(), args => args.id === suppressedNode.id && args.patch.status === 'active')
|
|
660
|
+
assert.equal(state.loadPrivateIndex(book.id).entries[suppressedNode.id].status, 'active')
|
|
661
|
+
assert.ok(state.loadPrivateIndex(book.id).entries[suppressedNode.id].content.includes('Synthetic browser verification memory.'))
|
|
662
|
+
await shot(page, `wall-${viewport.width}-restored`)
|
|
663
|
+
report.scenarios.push({ name: 'graph-suppression', viewport, selectedIdVerifiedBeforeBothClicks: suppressedNode.id,
|
|
664
|
+
exactWriteIdMatched: true, twoClicks: true, restoredFromWall: true, memoryRetained: true })
|
|
665
|
+
|
|
666
|
+
await page.goto(base + '#/settings/graph')
|
|
667
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
668
|
+
await page.locator('.dshm-gs-topbar select[aria-label="当前记忆库"]').selectOption(book.id)
|
|
669
|
+
await sleep(400)
|
|
670
|
+
const searchInput = page.locator('.dshm-gs-search input'), graphSearchCalls = () => calls.filter(call => call.method === 'getGraph' && call.args.query)
|
|
671
|
+
assert.equal(await searchInput.isVisible(), true, 'graph search remains available at desktop and 390px widths')
|
|
672
|
+
const cameraBeforeSearch = await graphViewport(page)
|
|
673
|
+
const hiddenId = id(bookIndex ? 340 : 900), hiddenTitle = state.loadPrivateIndex(book.id).entries[hiddenId].title
|
|
674
|
+
assert.ok(!(await graphSnapshot(page)).some(node => node.id === hiddenId), 'the target starts inside an unexpanded cluster')
|
|
675
|
+
const searchRead = await write('getGraph', () => searchInput.fill(hiddenTitle), args => args.query === hiddenTitle)
|
|
676
|
+
assert.ok(searchRead.nodes.some(node => node.id === hiddenId))
|
|
677
|
+
for (const key of ['bbox', 'zoom', 'clusterId']) assert.equal(graphSearchCalls().at(-1).args[key], undefined)
|
|
678
|
+
await page.waitForFunction(target => document.querySelector('canvas.dshm-graph-canvas').__dshmGraphView.snapshot().some(node => node.id === target), hiddenId)
|
|
679
|
+
await shot(page, `graph-${viewport.width}-search-hidden`)
|
|
680
|
+
await write('getGraph', () => searchInput.fill(hiddenId), args => args.query === hiddenId)
|
|
681
|
+
const edgeSearch = await write('getGraph', () => searchInput.fill('Browser graph recorded edge evidence'), args => args.query === 'Browser graph recorded edge evidence')
|
|
682
|
+
assert.ok([id(41), id(42)].every(target => edgeSearch.nodes.some(node => node.id === target)))
|
|
683
|
+
assert.ok(edgeSearch.edges.some(edge => edge.note === 'Browser graph recorded edge evidence'))
|
|
684
|
+
await page.waitForFunction(() => document.querySelector('canvas.dshm-graph-canvas').__dshmGraphView.snapshot().length === 2)
|
|
685
|
+
await shot(page, `graph-${viewport.width}-search-evidence`)
|
|
686
|
+
let releaseOld, queuedOld
|
|
687
|
+
const oldGate = new Promise(resolve => { releaseOld = resolve }), oldQueued = new Promise(resolve => { queuedOld = resolve })
|
|
688
|
+
await page.route('**/dsh-memu-memory/getGraph', async route => {
|
|
689
|
+
if (route.request().postDataJSON().payload.query !== 'Review Traveler') { await route.continue(); return }
|
|
690
|
+
const response = await route.fetch(); queuedOld(); await oldGate; await route.fulfill({ response })
|
|
691
|
+
}, { times: 1 })
|
|
692
|
+
await searchInput.fill('Review Traveler'); await oldQueued
|
|
693
|
+
const queryReadsBefore = graphSearchCalls().length
|
|
694
|
+
await searchInput.fill(hiddenTitle)
|
|
695
|
+
releaseOld(); await sleep(100)
|
|
696
|
+
assert.equal(graphSearchCalls().length, queryReadsBefore, 'new raw input waits for debounce but cancels the old response immediately')
|
|
697
|
+
assert.ok(!(await graphSnapshot(page)).some(node => node.id === fixture.pending.id), 'a stale search cannot paint during the next trailing window')
|
|
698
|
+
await page.waitForFunction(target => document.querySelector('canvas.dshm-graph-canvas').__dshmGraphView.snapshot().some(node => node.id === target), hiddenId)
|
|
699
|
+
await write('getGraph', () => searchInput.fill('needle-new'), args => args.query === 'needle-new')
|
|
700
|
+
await page.waitForFunction(() => document.querySelector('canvas.dshm-graph-canvas').__dshmGraphView.snapshot().length === 0)
|
|
701
|
+
await write('getGraph', () => searchInput.fill(''), args => !args.query)
|
|
702
|
+
await page.waitForFunction(() => document.querySelector('.dshm-gs-status')?.textContent.includes('簇'))
|
|
703
|
+
await sleep(100)
|
|
704
|
+
const cameraAfterSearch = await graphViewport(page)
|
|
705
|
+
assert.ok(Math.abs(cameraAfterSearch.zoom - cameraBeforeSearch.zoom) < .000001)
|
|
706
|
+
for (const key of ['minX', 'minY', 'maxX', 'maxY']) assert.ok(Math.abs(cameraAfterSearch.bbox[key] - cameraBeforeSearch.bbox[key]) < .001, 'clear restores ' + key)
|
|
707
|
+
await shot(page, `graph-${viewport.width}-search-cleared`)
|
|
708
|
+
report.scenarios.push({ name: 'graph-server-search', viewport, hiddenTitle: true, rawId: true, edgeEvidenceEndpoints: true, bodyExcluded: true,
|
|
709
|
+
staleDuringTrailingDropped: true, debounce: true, cameraRestored: true, unconstrainedByViewport: true })
|
|
710
|
+
|
|
711
|
+
for (let i = 0; i < 102; i++) graph.createEntity({ libraryId: book.id,
|
|
712
|
+
name: createHash('sha256').update('browser-cursor-' + viewport.width + '-' + i).digest('hex').slice(0, 28), kind: 'thing', status: 'confirmed' })
|
|
713
|
+
const scanSource = graph.createEntity({ libraryId: book.id, name: 'Cursor Harbor Traveler', kind: 'org', status: 'confirmed' })
|
|
714
|
+
graph.createEntity({ libraryId: book.id, name: 'Cursor Harbor Travelers', kind: 'org', status: 'confirmed' })
|
|
715
|
+
assert.equal(graph.suggestEntityMerges({ libraryId: book.id }).items.length, 0, 'the synthetic first batch is a real zero-hit partial scan')
|
|
716
|
+
await page.reload(); await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
717
|
+
await page.locator('.dshm-gs-topbar select[aria-label="当前记忆库"]').selectOption(book.id)
|
|
718
|
+
await sleep(250)
|
|
719
|
+
const scansBefore = calls.filter(call => call.method === 'suggestEntityMerges').length
|
|
720
|
+
assert.match(await entry.innerText(), /待检查/)
|
|
721
|
+
const firstScan = await write('suggestEntityMerges', () => entry.click())
|
|
722
|
+
assert.equal(firstScan.total, null); assert.equal(firstScan.totalExact, false); assert.equal(firstScan.scanComplete, false)
|
|
723
|
+
assert.equal(firstScan.items.length, 0); assert.ok(firstScan.batchComparisons <= 4096)
|
|
724
|
+
await actionPanel.getByText('尚未检查完,可继续扫描下一批候选', { exact: true }).waitFor()
|
|
725
|
+
assert.match(await entry.innerText(), /≥0/)
|
|
726
|
+
await sleep(150)
|
|
727
|
+
assert.equal(calls.filter(call => call.method === 'suggestEntityMerges').length, scansBefore + 1)
|
|
728
|
+
await shot(page, `graph-${viewport.width}-scan-partial`)
|
|
729
|
+
const anchorsBeforeNext = calls.filter(call => call.method === 'getAnchorCandidates').length
|
|
730
|
+
const nextScan = await write('suggestEntityMerges', () => actionPanel.getByRole('button', { name: '继续扫描', exact: true }).click())
|
|
731
|
+
assert.equal(calls.filter(call => call.method === 'suggestEntityMerges').at(-1).args.cursor, firstScan.nextCursor)
|
|
732
|
+
assert.equal(nextScan.scanStart, firstScan.scannedPairs)
|
|
733
|
+
assert.ok(nextScan.items.some(pair => pair.sourceId === scanSource.id || pair.targetId === scanSource.id))
|
|
734
|
+
assert.equal(calls.filter(call => call.method === 'getAnchorCandidates').length, anchorsBeforeNext)
|
|
735
|
+
const scanPair = actionPanel.locator('.dshm-gs-sec').filter({ hasText: 'Cursor Harbor Traveler' }).first()
|
|
736
|
+
await scanPair.getByRole('button', { name: '不是同一实体', exact: true }).waitFor()
|
|
737
|
+
await shot(page, `graph-${viewport.width}-scan-next`)
|
|
738
|
+
await scanPair.getByRole('button', { name: '不是同一实体', exact: true }).click()
|
|
739
|
+
await write('setEntityMergeRejection', () => scanPair.getByRole('button', { name: '确认执行?', exact: true }).click())
|
|
740
|
+
await actionPanel.getByText('尚未检查完,可继续扫描下一批候选', { exact: true }).waitFor()
|
|
741
|
+
assert.equal(calls.filter(call => call.method === 'suggestEntityMerges').at(-1).args.cursor, undefined)
|
|
742
|
+
report.scenarios.push({ name: 'graph-bounded-scan', viewport, collapsedDefers: true, partialZeroUnknown: true,
|
|
743
|
+
explicitContinuation: true, firstComparisons: firstScan.batchComparisons, secondScanStart: nextScan.scanStart,
|
|
744
|
+
anchorReused: true, writeRestarts: true })
|
|
745
|
+
|
|
746
|
+
await page.goto(base + '#/settings/settings')
|
|
747
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
748
|
+
const budget = page.getByLabel('中途召回 token 上限', { exact: true })
|
|
749
|
+
const savedBudget = viewport.width === 1440 ? 420 : 440
|
|
750
|
+
writeResponse = page.waitForResponse(response => response.url().endsWith('/setSettings') && response.request().postDataJSON().payload.patch.midTurnTokens === savedBudget)
|
|
751
|
+
await budget.fill(String(savedBudget))
|
|
752
|
+
await writeResponse
|
|
753
|
+
const turnLogMode = viewport.width === 1440 ? 'off' : 'on'
|
|
754
|
+
await Promise.all([
|
|
755
|
+
page.waitForResponse(response => response.url().endsWith('/setSettings') && response.request().postDataJSON().payload.patch.consolidationTurnLog === turnLogMode),
|
|
756
|
+
page.getByLabel('增量回合日志', { exact: true }).selectOption(turnLogMode),
|
|
757
|
+
])
|
|
758
|
+
const numericSettings = { midTurnMinSteps: 5, midTurnMinUnits: 4, midTurnMinChars: 6400, midTurnMaxPerTurn: 3,
|
|
759
|
+
midTurnCooldownMs: 62000, midTurnFullUnits: 7, midTurnFullChars: 16000 }
|
|
760
|
+
const numericLabels = { midTurnMinSteps: '中途召回最少工具步数', midTurnMinUnits: '中途召回最少上下文单元', midTurnMinChars: '中途召回最少字符数',
|
|
761
|
+
midTurnMaxPerTurn: '每回合最多中途召回次数', midTurnCooldownMs: '中途召回冷却(毫秒)', midTurnFullUnits: '完整补充召回单元阈值', midTurnFullChars: '完整补充召回字符阈值' }
|
|
762
|
+
for (const [key, value] of Object.entries(numericSettings)) {
|
|
763
|
+
const next = value + (viewport.width === 390 ? 1 : 0)
|
|
764
|
+
await write('setSettings', () => page.getByLabel(numericLabels[key], { exact: true }).fill(String(next)), args => args.patch[key] === next)
|
|
765
|
+
numericSettings[key] = next
|
|
766
|
+
}
|
|
767
|
+
await write('setSettings', () => page.getByRole('switch', { name: '长工具回合中途补充召回', exact: true }).click(), args => typeof args.patch.midTurnRecall === 'boolean')
|
|
768
|
+
const toolLogMode = viewport.width === 1440 ? 'errors' : 'summary'
|
|
769
|
+
await write('setSettings', () => page.getByLabel('回合日志工具明细', { exact: true }).selectOption(toolLogMode), args => args.patch.consolidationTurnLogTools === toolLogMode)
|
|
770
|
+
const sessionDefault = viewport.width === 1440 ? 'auto' : 'global'
|
|
771
|
+
await write('setSettings', () => page.getByLabel('不再询问时的新会话默认范围', { exact: true }).selectOption(sessionDefault), args => args.patch.newSessionDefault === sessionDefault)
|
|
772
|
+
const mirror = `https://mirror-${viewport.width}.invalid/simple`
|
|
773
|
+
await write('setSettings', () => page.getByLabel('Python 包索引(按优先顺序)', { exact: true }).fill(mirror), args => args.patch.pipIndexes?.[0] === mirror)
|
|
774
|
+
await page.reload(); await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
775
|
+
assert.equal(await budget.inputValue(), viewport.width === 1440 ? '420' : '440')
|
|
776
|
+
assert.equal(await page.getByLabel('增量回合日志', { exact: true }).inputValue(), turnLogMode)
|
|
777
|
+
assert.equal(state.getSettings().midTurnTokens, viewport.width === 1440 ? 420 : 440)
|
|
778
|
+
for (const [key, value] of Object.entries(numericSettings)) {
|
|
779
|
+
assert.equal(await page.getByLabel(numericLabels[key], { exact: true }).inputValue(), String(value))
|
|
780
|
+
assert.equal(state.getSettings()[key], value)
|
|
781
|
+
}
|
|
782
|
+
assert.equal(await page.getByLabel('回合日志工具明细', { exact: true }).inputValue(), toolLogMode)
|
|
783
|
+
assert.equal(await page.getByLabel('不再询问时的新会话默认范围', { exact: true }).inputValue(), sessionDefault)
|
|
784
|
+
assert.equal(await page.getByLabel('Python 包索引(按优先顺序)', { exact: true }).inputValue(), mirror)
|
|
785
|
+
assert.equal(await page.locator('output').count(), 6)
|
|
786
|
+
await budget.scrollIntoViewIfNeeded(); await shot(page, `settings-${viewport.width}-saved`)
|
|
787
|
+
report.scenarios.push({ name: 'settings-parity', viewport, savedRPC: true, reloadReadback: true,
|
|
788
|
+
keys: ['midTurnTokens', ...Object.keys(numericSettings), 'midTurnRecall', 'consolidationTurnLog', 'consolidationTurnLogTools', 'newSessionDefault', 'pipIndexes'], readOnlyPolicies: 6 })
|
|
789
|
+
await write('setSettings', () => page.getByLabel('检索相关度下限(相对最高分,0=不限)', { exact: true }).fill('0.42'), args => args.patch.relevanceThreshold === .42)
|
|
790
|
+
await page.getByRole('button', { name: '恢复默认', exact: true }).click()
|
|
791
|
+
await write('resetSettings', () => page.getByRole('button', { name: '确认恢复默认?', exact: true }).click())
|
|
792
|
+
await page.reload(); await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
793
|
+
for (const key of ['midTurnRecall', 'midTurnTokens', ...Object.keys(numericSettings), 'relevanceThreshold']) assert.equal(state.getSettings()[key], state.DEFAULT_SETTINGS[key], key)
|
|
794
|
+
assert.equal(await budget.inputValue(), String(state.DEFAULT_SETTINGS.midTurnTokens))
|
|
795
|
+
for (const [key, label] of Object.entries(numericLabels)) assert.equal(await page.getByLabel(label, { exact: true }).inputValue(), String(state.DEFAULT_SETTINGS[key]))
|
|
796
|
+
assert.equal(await page.getByLabel('检索相关度下限(相对最高分,0=不限)', { exact: true }).inputValue(), String(state.DEFAULT_SETTINGS.relevanceThreshold))
|
|
797
|
+
report.scenarios.push({ name: 'settings-reset', viewport, confirmedRPC: true, midTurnNineKeysAndRelevanceReadback: true })
|
|
798
|
+
|
|
799
|
+
await page.goto(base + '#/settings/libraries')
|
|
800
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
801
|
+
const sessionPanel = page.locator('.dshm-card').filter({ hasText: '指定会话的记忆设置' }).first()
|
|
802
|
+
await sessionPanel.getByLabel('选择目标会话', { exact: true }).selectOption('browser-session-' + bookIndex)
|
|
803
|
+
await sessionPanel.getByLabel('绑定到记忆库', { exact: true }).selectOption(books[1 - bookIndex].id)
|
|
804
|
+
await write('setLibrary', () => sessionPanel.getByRole('button', { name: '确认绑定目标库', exact: true }).click())
|
|
805
|
+
await sleep(150)
|
|
806
|
+
assert.equal(state.getSessionBinding('browser-session-' + bookIndex).libraryId, books[1 - bookIndex].id)
|
|
807
|
+
await sessionPanel.getByLabel('绑定到记忆库', { exact: true }).selectOption(book.id)
|
|
808
|
+
await write('setLibrary', () => sessionPanel.getByRole('button', { name: '确认绑定目标库', exact: true }).click())
|
|
809
|
+
for (const key of ['使用私有记忆', '使用全局记忆']) {
|
|
810
|
+
assert.equal(await sessionPanel.getByText(key, { exact: true }).isVisible(), true)
|
|
811
|
+
const toggle = sessionPanel.getByRole('switch', { name: key, exact: true })
|
|
812
|
+
await write('setSessionScope', () => toggle.click())
|
|
813
|
+
await page.waitForFunction(label => document.querySelector(`[role="switch"][aria-label="${label}"]`)?.getAttribute('aria-checked') === 'false', key)
|
|
814
|
+
await write('setSessionScope', () => toggle.click())
|
|
815
|
+
}
|
|
816
|
+
await write('setDomain', () => sessionPanel.getByLabel('领域', { exact: true }).selectOption('coding'), args => args.sessionId === 'browser-session-' + bookIndex)
|
|
817
|
+
await sleep(200)
|
|
818
|
+
assert.equal(state.getSessionBinding('browser-session-' + bookIndex).domainOverride, 'coding')
|
|
819
|
+
await sessionPanel.getByText('消息与角色作用域', { exact: true }).click()
|
|
820
|
+
await sessionPanel.getByLabel('群组 / 频道 ID', { exact: true }).fill('browser-channel-' + viewport.width)
|
|
821
|
+
await write('setMemoryContext', () => sessionPanel.getByRole('button', { name: '保存作用域', exact: true }).click())
|
|
822
|
+
await sleep(200)
|
|
823
|
+
assert.equal(state.getSessionBinding('browser-session-' + bookIndex).memoryContext.channelId, 'browser-channel-' + viewport.width)
|
|
824
|
+
await sessionPanel.scrollIntoViewIfNeeded(); await shot(page, `session-${viewport.width}-saved`)
|
|
825
|
+
report.scenarios.push({ name: 'session-parity', viewport, explicitTarget: true, rebindPersisted: true, scopeReadback: true, domainPersisted: true, contextPersisted: true })
|
|
826
|
+
|
|
827
|
+
await page.goto(base + '#/settings/global')
|
|
828
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
829
|
+
const curation = page.locator('.dshm-card').filter({ hasText: '执行者仅提供 curator 的运行上下文' }).first()
|
|
830
|
+
const executor = curation.getByLabel('执行者会话', { exact: true }), start = curation.getByRole('button', { name: /^开始提炼/ })
|
|
831
|
+
await executor.locator('option[value="browser-session-1"]').waitFor({ state: 'attached' })
|
|
832
|
+
assert.equal(await executor.inputValue(), '')
|
|
833
|
+
const sources = curation.getByRole('checkbox')
|
|
834
|
+
await sources.nth(0).check()
|
|
835
|
+
assert.equal(await start.isDisabled(), true, 'selected source material does not implicitly choose an executor')
|
|
836
|
+
await executor.selectOption('browser-session-1')
|
|
837
|
+
assert.equal(await start.isEnabled(), true)
|
|
838
|
+
assert.equal(await sources.nth(1).isChecked(), false, 'choosing an executor does not silently select it as source material')
|
|
839
|
+
await curation.scrollIntoViewIfNeeded(); await shot(page, `curation-${viewport.width}-executor`)
|
|
840
|
+
let releaseCuration, curationQueued
|
|
841
|
+
const curationGate = new Promise(resolve => { releaseCuration = resolve }), queuedCuration = new Promise(resolve => { curationQueued = resolve })
|
|
842
|
+
await page.route('**/dsh-memu-memory/generateGlobal', async route => {
|
|
843
|
+
const response = await route.fetch(); curationQueued(); await curationGate; await route.fulfill({ response })
|
|
844
|
+
}, { times: 1 })
|
|
845
|
+
await start.click(); await queuedCuration
|
|
846
|
+
await executor.selectOption('browser-session-0')
|
|
847
|
+
await sources.nth(0).uncheck(); await sources.nth(1).check()
|
|
848
|
+
const curationResponse = page.waitForResponse(response => response.url().endsWith('/generateGlobal'))
|
|
849
|
+
releaseCuration(); await curationResponse; await sleep(100)
|
|
850
|
+
assert.deepEqual(calls.filter(call => call.method === 'generateGlobal').at(-1).args, { sessionId: 'browser-session-1', sessionIds: ['browser-session-0'] })
|
|
851
|
+
assert.equal(await executor.inputValue(), 'browser-session-0')
|
|
852
|
+
assert.equal(await sources.nth(0).isChecked(), false); assert.equal(await sources.nth(1).isChecked(), true)
|
|
853
|
+
await shot(page, `curation-${viewport.width}-late-result`)
|
|
854
|
+
report.scenarios.push({ name: 'global-curation-executor', viewport, explicitLiveTarget: true, independentSourceSelection: true,
|
|
855
|
+
capturedRPC: true, lateResultPreservesNewSelection: true, modelExecution: false })
|
|
856
|
+
|
|
857
|
+
await page.goto(base + '#/settings/help')
|
|
858
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
859
|
+
const steps = page.locator('.dshm-help-steps button')
|
|
860
|
+
assert.equal(await steps.count(), 7)
|
|
861
|
+
for (let i = 0; i < 7; i++) {
|
|
862
|
+
await steps.nth(i).click()
|
|
863
|
+
await page.locator(`[data-help-action="helpStep${i + 1}"]`).waitFor()
|
|
864
|
+
assert.match(await page.locator('.dshm-help-progress').innerText(), new RegExp(`${i + 1} / 7`))
|
|
865
|
+
assert.equal(await page.locator('.dshm-help-lesson dd').count(), 2)
|
|
866
|
+
}
|
|
867
|
+
await page.locator('.dshm-help-lesson').scrollIntoViewIfNeeded(); await shot(page, `help-${viewport.width}-step7`)
|
|
868
|
+
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false)
|
|
869
|
+
report.scenarios.push({ name: 'help', viewport, steps: 7, expectedAndTroubleshooting: true })
|
|
870
|
+
|
|
871
|
+
await page.goto(base + '#/settings/diagnostics')
|
|
872
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
873
|
+
await page.locator('.dshm-diag-facts').waitFor()
|
|
874
|
+
assert.match(await page.title(), /^诊断 · /)
|
|
875
|
+
await page.waitForFunction(() => document.querySelectorAll('[data-diag-layer]').length === 7)
|
|
876
|
+
assert.deepEqual((await page.locator('[data-diag-layer]').evaluateAll(items => items.map(item => item.dataset.diagLayer))).sort(), ['engine', 'host', 'plugin', 'rpc', 'state', 'vector', 'workers'])
|
|
877
|
+
assert.match(await page.locator('.dshm-diag-facts dd').first().innerText(), /未知/)
|
|
878
|
+
await page.getByRole('button', { name: '复制全部', exact: true }).click()
|
|
879
|
+
await sleep(150)
|
|
880
|
+
const copied = await page.evaluate(() => navigator.clipboard.readText())
|
|
881
|
+
const copiedReport = JSON.parse(copied)
|
|
882
|
+
assert.equal(copiedReport.redacted, true)
|
|
883
|
+
assert.equal(copiedReport.runtime.host.version, null)
|
|
884
|
+
assert.ok(!copied.includes(process.env.UI_BROWSER_API_KEY) && !copied.includes(privateMarker))
|
|
885
|
+
const downloadEvent = page.waitForEvent('download')
|
|
886
|
+
await page.getByRole('button', { name: '下载脱敏报告', exact: true }).click()
|
|
887
|
+
const download = await downloadEvent, downloaded = path.join(output, `recovery-ui-browser-diagnostics-${viewport.width}.json`)
|
|
888
|
+
await download.saveAs(downloaded)
|
|
889
|
+
const downloadedText = fs.readFileSync(downloaded, 'utf8')
|
|
890
|
+
assert.equal(JSON.parse(downloadedText).redacted, true)
|
|
891
|
+
assert.ok(!downloadedText.includes(process.env.UI_BROWSER_API_KEY) && !downloadedText.includes(privateMarker))
|
|
892
|
+
await page.locator('.dshm-diag-facts').scrollIntoViewIfNeeded(); await shot(page, `diagnostics-${viewport.width}-layers`)
|
|
893
|
+
await page.locator('[data-diag-layer="workers"]').scrollIntoViewIfNeeded(); await shot(page, `diagnostics-${viewport.width}-layers-lower`)
|
|
894
|
+
const fixtureRow = page.locator('.dshm-diag-code').filter({ hasText: /^RPC_BROWSER_FIXTURE$/ }).locator('../../..')
|
|
895
|
+
await fixtureRow.waitFor()
|
|
896
|
+
for (const details of await fixtureRow.locator('details').all()) if (await details.getAttribute('open') === null) await details.locator('summary').click()
|
|
897
|
+
assert.match(await fixtureRow.innerText(), /ENOENT/)
|
|
898
|
+
assert.match(await fixtureRow.innerText(), /operation/)
|
|
899
|
+
assert.match(await fixtureRow.innerText(), /value withheld/)
|
|
900
|
+
assert.match(await fixtureRow.innerText(), /重试策略/)
|
|
901
|
+
assert.ok(!(await fixtureRow.innerText()).includes(privateMarker))
|
|
902
|
+
await fixtureRow.scrollIntoViewIfNeeded(); await shot(page, `diagnostics-${viewport.width}-details`)
|
|
903
|
+
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false)
|
|
904
|
+
report.scenarios.push({ name: 'diagnostics', viewport, titleCorrect: true, layers: 7, unknownHostVersion: true, copiedRedacted: true, downloadedRedacted: true, download: downloaded })
|
|
905
|
+
await checkOrphanManagement({ page, base, viewport, calls, write })
|
|
906
|
+
await context.close()
|
|
907
|
+
}
|
|
908
|
+
assert.deepEqual(report.pageErrors, [])
|
|
909
|
+
report.completedAt = new Date().toISOString()
|
|
910
|
+
fs.writeFileSync(reportFile, JSON.stringify(report, null, 2))
|
|
911
|
+
console.log(JSON.stringify(report, null, 2))
|
|
912
|
+
} catch (error) {
|
|
913
|
+
report.error = String(error?.stack || error)
|
|
914
|
+
report.recentCalls = recentCalls.slice(-20)
|
|
915
|
+
console.error(error)
|
|
916
|
+
if (browser) for (const context of browser.contexts()) for (const page of context.pages()) {
|
|
917
|
+
try { await shot(page, `failure-${Date.now()}`); console.error((await page.locator('body').innerText()).slice(0, 5000)) } catch {}
|
|
918
|
+
}
|
|
919
|
+
fs.writeFileSync(reportFile, JSON.stringify(report, null, 2))
|
|
920
|
+
fs.writeFileSync(path.join(output, `recovery-ui-browser-failure-report-${Date.now()}.json`), JSON.stringify(report, null, 2))
|
|
921
|
+
console.error('Browser evidence:', report.screenshots.join('\n'))
|
|
922
|
+
process.exitCode = 1
|
|
923
|
+
} finally {
|
|
924
|
+
await browser?.close()
|
|
925
|
+
if (server) await new Promise(resolve => server.close(resolve))
|
|
926
|
+
console.log('isolated-browser-closed', JSON.stringify({ pid: process.pid, browserClosed: true, serverClosed: true }))
|
|
927
|
+
state.flushState()
|
|
928
|
+
fs.rmSync(home, { recursive: true, force: true })
|
|
929
|
+
}
|