@gongfpp/dsh-novel-fish 1.1.0 → 1.2.0
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/CHANGELOG.md +21 -0
- package/README.md +41 -20
- package/docs/evidence/settings-reliability.png +0 -0
- package/index.json +12 -0
- package/lib/client.js +734 -128
- package/locale/en.json +15 -0
- package/locale/zh.json +15 -0
- package/package.json +5 -7
- package/screenshots.json +6 -0
- package/docs/acceptance.md +0 -42
- package/docs/community-markets.md +0 -88
- package/docs/compatibility-017.md +0 -70
- package/docs/compatibility-101.md +0 -41
- package/docs/continuous-reading-020.md +0 -46
- package/docs/ebook-tests.md +0 -99
- package/docs/evidence/abc-result.json +0 -9
- package/docs/evidence/banner-100.png +0 -0
- package/docs/evidence/community-market-014-result.json +0 -170
- package/docs/evidence/compatibility-017-result.json +0 -65
- package/docs/evidence/continuous-reading-020-result.json +0 -72
- package/docs/evidence/formats-result.json +0 -12
- package/docs/evidence/live-ab.png +0 -0
- package/docs/evidence/live-collapsed.png +0 -0
- package/docs/evidence/live-disabled.png +0 -0
- package/docs/evidence/live-epub.png +0 -0
- package/docs/evidence/live-market.png +0 -0
- package/docs/evidence/live-resume.png +0 -0
- package/docs/evidence/live-unloaded.png +0 -0
- package/docs/evidence/long-result.json +0 -11
- package/docs/evidence/multi-region-014-result.json +0 -47
- package/docs/evidence/native-disclosure-013-result.json +0 -36
- package/docs/evidence/native-disclosures-013.png +0 -0
- package/docs/evidence/native-open-013.png +0 -0
- package/docs/evidence/native-settings-sample.md +0 -11
- package/docs/evidence/native-settings-types-015.png +0 -0
- package/docs/evidence/npm-market-014-result.json +0 -132
- package/docs/evidence/plugin-settings-details.png +0 -0
- package/docs/evidence/public-release-014-result.json +0 -51
- package/docs/evidence/public-release-015-result.json +0 -36
- package/docs/evidence/public-release-result.json +0 -48
- package/docs/evidence/reading-demo-100.png +0 -0
- package/docs/evidence/reading-two-expansions-110.gif +0 -0
- package/docs/evidence/reading-two-expansions-110.json +0 -89
- package/docs/evidence/samples-110-capture.json +0 -49
- package/docs/evidence/settings-011-result.json +0 -28
- package/docs/evidence/settings-011.png +0 -0
- package/docs/evidence/settings-100.png +0 -0
- package/docs/evidence/settings-110.png +0 -0
- package/docs/evidence/settings-chat-011.png +0 -0
- package/docs/evidence/type-append-012-result.json +0 -30
- package/docs/evidence/type-append-012.png +0 -0
- package/docs/evidence/type-settings-012.png +0 -0
- package/docs/evidence/unload-result.json +0 -7
- package/docs/host-adapter.md +0 -43
- package/docs/icon-metadata-021.md +0 -40
- package/docs/interaction-paths-020.md +0 -39
- package/docs/marketplace.md +0 -42
- package/docs/multi-region-update.md +0 -53
- package/docs/native-disclosure-update.md +0 -39
- package/docs/native-settings-update.md +0 -48
- package/docs/plugin-settings-update.md +0 -61
- package/docs/release.md +0 -151
- package/docs/settings-update.md +0 -49
- package/docs/type-append-update.md +0 -50
- package/pnpm-workspace.yaml +0 -5
- package/scripts/build.mjs +0 -70
- package/scripts/check-host-contracts.mjs +0 -247
- package/scripts/licenses/path-webpack.txt +0 -28
- package/scripts/make-readme-gif.mjs +0 -69
- package/scripts/test-browser-samples.mjs +0 -665
- package/scripts/test-candidate-books.mjs +0 -71
- package/scripts/test-ebook-corpus.mjs +0 -161
- package/src/bundled-books.js +0 -42
- package/src/chat-adapter.js +0 -278
- package/src/client.js +0 -61
- package/src/epub.js +0 -166
- package/src/novel-content.js +0 -28
- package/src/persistence.js +0 -271
- package/src/pg-notice.js +0 -19
- package/src/segments.js +0 -185
- package/src/settings.js +0 -243
- package/src/store.js +0 -429
- package/src/text-decoding.js +0 -28
- package/test/bundled-library.test.js +0 -526
- package/test/chat-adapter.test.js +0 -518
- package/test/client.test.js +0 -124
- package/test/ebooks.test.js +0 -192
- package/test/epub.test.js +0 -185
- package/test/helpers/host-primitives.js +0 -28
- package/test/helpers/memory-storage.js +0 -48
- package/test/host-contracts.test.js +0 -32
- package/test/import.test.js +0 -102
- package/test/persistence.test.js +0 -27
- package/test/pg-notice.test.js +0 -109
- package/test/release.test.js +0 -87
- package/test/segments.test.js +0 -182
- package/test/settings.test.js +0 -312
- package/test/store.test.js +0 -617
- package/test/text-decoding.test.js +0 -49
|
@@ -1,665 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Isolated Chromium component test, NOT the official DSH GUI or host primitives.
|
|
3
|
-
// No server, plugin installation, persistent browser profile, or source client entry.
|
|
4
|
-
// Usage: PLAYWRIGHT_MODULE=/path/to/playwright-core REACT_DOM_MODULE=/path/to/react-dom/client.js node scripts/test-browser-samples.mjs
|
|
5
|
-
// Optional: CHROME_EXECUTABLE=/path/to/chrome (otherwise uses installed channel chrome).
|
|
6
|
-
// CAPTURE_SETTINGS=1 saves an explicitly mocked component preview under dist/ebooks;
|
|
7
|
-
// stdout is the JSON report (redirect to dist/ebooks/browser-results.json if desired).
|
|
8
|
-
import assert from 'node:assert/strict'
|
|
9
|
-
import { createHash } from 'node:crypto'
|
|
10
|
-
import { mkdtemp, readFile, realpath, rm } from 'node:fs/promises'
|
|
11
|
-
import { createRequire } from 'node:module'
|
|
12
|
-
import { tmpdir } from 'node:os'
|
|
13
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path'
|
|
14
|
-
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
15
|
-
import { build } from 'esbuild'
|
|
16
|
-
import { PG_NOTICE } from '../src/pg-notice.js'
|
|
17
|
-
|
|
18
|
-
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
19
|
-
const require = createRequire(join(root, 'package.json'))
|
|
20
|
-
let playwrightPath
|
|
21
|
-
try {
|
|
22
|
-
playwrightPath = require.resolve(process.env.PLAYWRIGHT_MODULE || 'playwright-core')
|
|
23
|
-
} catch (cause) {
|
|
24
|
-
throw new Error('No existing Playwright found. Set PLAYWRIGHT_MODULE to an existing playwright-core/index.js; this test never installs dependencies.', { cause })
|
|
25
|
-
}
|
|
26
|
-
const playwright = await import(pathToFileURL(playwrightPath).href)
|
|
27
|
-
const { chromium } = playwright.default ?? playwright
|
|
28
|
-
assert.ok(chromium?.launch, 'PLAYWRIGHT_MODULE must export Chromium')
|
|
29
|
-
let reactDomClient
|
|
30
|
-
try {
|
|
31
|
-
reactDomClient = require.resolve(process.env.REACT_DOM_MODULE || 'react-dom/client')
|
|
32
|
-
} catch (cause) {
|
|
33
|
-
throw new Error('No existing ReactDOM found. Set REACT_DOM_MODULE to an existing react-dom/client.js; this test never installs dependencies.', { cause })
|
|
34
|
-
}
|
|
35
|
-
// Resolve React beside ReactDOM, avoiding mismatched React copies/versions.
|
|
36
|
-
const domRequire = createRequire(reactDomClient)
|
|
37
|
-
const reactModule = domRequire.resolve('react')
|
|
38
|
-
const reactVersion = domRequire('react').version
|
|
39
|
-
const bundlePath = join(root, 'lib/client.js')
|
|
40
|
-
const bundle = await readFile(bundlePath)
|
|
41
|
-
const bundleSha256 = createHash('sha256').update(bundle).digest('hex')
|
|
42
|
-
const manifest = JSON.parse(await readFile(join(root, 'samples/ebooks/sources.json'), 'utf8'))
|
|
43
|
-
assert.deepEqual(manifest.books.map(({ id, format }) => ({ id, format })), [
|
|
44
|
-
{ id: 'million-pound-bank-note', format: 'txt' }, { id: 'aq-zheng-zhuan', format: 'md' },
|
|
45
|
-
])
|
|
46
|
-
const expectedSegments = { 'million-pound-bank-note': 820, 'aq-zheng-zhuan': 100 }
|
|
47
|
-
const expectedLicense = await readFile(join(root, 'samples/ebooks/LICENSE.md'), 'utf8')
|
|
48
|
-
assert.ok(expectedLicense.includes('START: FULL LICENSE'))
|
|
49
|
-
assert.ok(expectedLicense.includes('CC BY-SA 4.0'))
|
|
50
|
-
assert.ok(expectedLicense.includes('阿Q正傳'))
|
|
51
|
-
assert.doesNotMatch(expectedLicense, /山海經|南山經|shanhaijing/u)
|
|
52
|
-
const temp = await mkdtemp(join(tmpdir(), 'novel-browser-samples-'))
|
|
53
|
-
const origin = 'http://novel-samples.test'
|
|
54
|
-
const failures = []
|
|
55
|
-
const requestLog = []
|
|
56
|
-
const reports = []
|
|
57
|
-
// Deliberately keep an oversized legacy passage: new imports must not rewrite it.
|
|
58
|
-
const legacyPassage = 'Existing segment B\n' + Array.from({ length: 80 }, (_, i) => `旧书第 ${i + 1} 行:完整正文保留,可滚动阅读。`).join('\n')
|
|
59
|
-
let browser
|
|
60
|
-
|
|
61
|
-
// The fixture imports only React/ReactDOM and existing contract doubles. The
|
|
62
|
-
// application under test is loaded separately, verbatim from lib/client.js.
|
|
63
|
-
const fixtureSource = `
|
|
64
|
-
import React from 'react'
|
|
65
|
-
import { createRoot } from ${JSON.stringify(reactDomClient)}
|
|
66
|
-
import { hostPrimitives } from ${JSON.stringify(join(root, 'test/helpers/host-primitives.js'))}
|
|
67
|
-
const h = React.createElement
|
|
68
|
-
// The shared Modal double omits host chrome. Supply its close-button contract
|
|
69
|
-
// locally so information is opened AND closed with real browser clicks.
|
|
70
|
-
const primitives = { ...hostPrimitives, Modal({ open, title, description, children, footer, closeLabel, onClose }) {
|
|
71
|
-
return open ? h('div', { role: 'dialog', 'aria-label': title },
|
|
72
|
-
h('h2', null, title), h('button', { type: 'button', 'aria-label': closeLabel, onClick: onClose }, closeLabel),
|
|
73
|
-
description, children, footer) : null
|
|
74
|
-
} }
|
|
75
|
-
const registrations = [], injections = [], effects = [], hostImports = []
|
|
76
|
-
const dictionaries = new Map()
|
|
77
|
-
const translate = namespace => (key, values = {}) => {
|
|
78
|
-
const text = dictionaries.get(namespace)?.zh?.[key] ?? key
|
|
79
|
-
return text.replace(/\\{(\\w+)\\}/g, (_, name) => String(values[name] ?? '{' + name + '}'))
|
|
80
|
-
}
|
|
81
|
-
function hook(source) {
|
|
82
|
-
return select => select(React.useSyncExternalStore(source.subscribe, source.getSnapshot))
|
|
83
|
-
}
|
|
84
|
-
window.__ModuleLoader__ = { load(module) {
|
|
85
|
-
try {
|
|
86
|
-
if (module.id !== '@gongfpp/dsh-novel-fish') throw new Error('Unexpected plugin module: ' + module.id)
|
|
87
|
-
const plugin = module.factory(name => {
|
|
88
|
-
hostImports.push(name)
|
|
89
|
-
if (name === 'react') return React
|
|
90
|
-
if (name === '@deepseek-ai/dsh-client-ui-primitives') return primitives
|
|
91
|
-
throw new Error('Unexpected host import: ' + name)
|
|
92
|
-
})
|
|
93
|
-
plugin.apply({
|
|
94
|
-
locale: { register(name, dictionary) { dictionaries.set(name, dictionary); return () => dictionaries.delete(name) }, bind: translate },
|
|
95
|
-
effect(callback, label) { effects.push({ callback, label }) },
|
|
96
|
-
slots: {
|
|
97
|
-
inject(name, callback) { injections.push(name); callback() },
|
|
98
|
-
register(options, Component) { registrations.push({ options, Component }); return () => {} },
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
const config = registrations.filter(item => item.options.name === 'plugins.bundle.config')
|
|
102
|
-
if (config.length !== 1 || config[0].options.key !== module.id) throw new Error('Missing unique bundle settings registration')
|
|
103
|
-
const entry = config[0], props = entry.options.inject()
|
|
104
|
-
if (props.sampleBooks?.length !== 2 || typeof props.onImportFile !== 'function') throw new Error('lib/client.js does not expose the unified bundled library and file import contracts')
|
|
105
|
-
if ('onImportSample' in props) throw new Error('Obsolete sample-import action remains in lib/client.js')
|
|
106
|
-
const reasoning = registrations.find(item => item.options.name === 'conversation.chat.reasoning.body')
|
|
107
|
-
if (!reasoning) throw new Error('Missing reasoning body registration')
|
|
108
|
-
const bodyProps = reasoning.options.inject()
|
|
109
|
-
// Run genuine bundle effects, including the trusted-event disclosure adapter.
|
|
110
|
-
for (const effect of effects) effect.cleanup = effect.callback()
|
|
111
|
-
function ReasoningFixture() {
|
|
112
|
-
const [open, setOpen] = React.useState(false)
|
|
113
|
-
return h('div', { 'data-conversation-session': 'isolated-session', style: { width: '100%', maxWidth: 600 } },
|
|
114
|
-
h('div', { 'data-chat-node-key': 'isolated-node', 'data-chat-flow-kind': 'assistant-step' },
|
|
115
|
-
h('div', { 'data-variant': 'think' },
|
|
116
|
-
h('div', { 'data-disclosure-row': true }, h('button', {
|
|
117
|
-
id: 'fixture-disclosure', 'aria-expanded': open, onClick: () => setOpen(value => !value),
|
|
118
|
-
}, 'Isolated reasoning fixture')),
|
|
119
|
-
open ? h(reasoning.Component, {
|
|
120
|
-
...bodyProps, text: 'Original reasoning fixture text', running: false, sessionId: 'isolated-session',
|
|
121
|
-
t: translate(reasoning.options.locale),
|
|
122
|
-
useNovelSettings: hook(bodyProps.hooks.novelSettings), useNovelPassages: hook(bodyProps.hooks.novelPassages),
|
|
123
|
-
renderFactorySlot: (_name, input) => input.text,
|
|
124
|
-
}) : null)))
|
|
125
|
-
}
|
|
126
|
-
const view = createRoot(document.getElementById('root'))
|
|
127
|
-
view.render(h(React.Fragment, null,
|
|
128
|
-
h(entry.Component, { ...props, t: translate(entry.options.locale), view: 'page',
|
|
129
|
-
useNovelState: hook(props.hooks.novelState), useNovelUi: hook(props.hooks.novelUi) }),
|
|
130
|
-
h(ReasoningFixture)))
|
|
131
|
-
window.__novelTest = {
|
|
132
|
-
moduleId: module.id, state: () => props.hooks.novelState.getSnapshot(),
|
|
133
|
-
samples: props.sampleBooks, hostImports, injections,
|
|
134
|
-
}
|
|
135
|
-
addEventListener('pagehide', () => {
|
|
136
|
-
view.unmount()
|
|
137
|
-
for (const effect of [...effects].reverse()) effect.cleanup?.()
|
|
138
|
-
}, { once: true })
|
|
139
|
-
} catch (error) { window.__fixtureError = error.stack || String(error); console.error(error) }
|
|
140
|
-
} }
|
|
141
|
-
`
|
|
142
|
-
const html = `<!doctype html><html lang="zh"><meta charset="utf-8"><link rel="icon" href="data:,"><title>Isolated sample component test — not DSH GUI</title><body><h1>Isolated component fixture · mocked Host primitives · NOT official DSH GUI</h1><div id="root"></div><script src="/host-fixture.js"></script><script src="/lib/client.js"></script></body></html>`
|
|
143
|
-
|
|
144
|
-
async function state(page) {
|
|
145
|
-
return page.evaluate(() => window.__novelTest.state())
|
|
146
|
-
}
|
|
147
|
-
async function hydrated(page) {
|
|
148
|
-
await page.waitForFunction(() => window.__fixtureError || window.__novelTest?.state().hydrated)
|
|
149
|
-
assert.equal(await page.evaluate(() => window.__fixtureError ?? null), null)
|
|
150
|
-
const value = await state(page)
|
|
151
|
-
assert.equal(value.error, null)
|
|
152
|
-
return value
|
|
153
|
-
}
|
|
154
|
-
async function database(page) {
|
|
155
|
-
return page.evaluate(async () => {
|
|
156
|
-
if (!(indexedDB instanceof IDBFactory)) throw new Error('Not native IndexedDB')
|
|
157
|
-
const db = await new Promise((resolve, reject) => {
|
|
158
|
-
const request = indexedDB.open('dsh-touch-fish-novel', 1)
|
|
159
|
-
request.onsuccess = () => resolve(request.result)
|
|
160
|
-
request.onerror = () => reject(request.error)
|
|
161
|
-
})
|
|
162
|
-
try {
|
|
163
|
-
const tx = db.transaction(['books', 'settings', 'segments'], 'readonly')
|
|
164
|
-
const done = new Promise((resolve, reject) => { tx.oncomplete = resolve; tx.onerror = () => reject(tx.error); tx.onabort = () => reject(tx.error) })
|
|
165
|
-
const getAll = name => new Promise((resolve, reject) => {
|
|
166
|
-
const request = tx.objectStore(name).getAll()
|
|
167
|
-
request.onsuccess = () => resolve(request.result)
|
|
168
|
-
request.onerror = () => reject(request.error)
|
|
169
|
-
})
|
|
170
|
-
const [books, settings, segments] = await Promise.all(['books', 'settings', 'segments'].map(getAll))
|
|
171
|
-
await done
|
|
172
|
-
return { books, settings: settings.find(item => item.key === 'settings')?.value,
|
|
173
|
-
bundledBooksInitialized: settings.find(item => item.key === 'bundled-books-v1')?.value === true,
|
|
174
|
-
bundledCatalogVersion: settings.find(item => item.key === 'bundled-catalog-version')?.value,
|
|
175
|
-
settingsRecords: settings, segments }
|
|
176
|
-
} finally { db.close() }
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
async function seedExisting(page, savedSamples = null, oldCatalog = false) {
|
|
180
|
-
await page.evaluate(async ({ legacyPassage, savedSamples, oldCatalog }) => {
|
|
181
|
-
const db = await new Promise((resolve, reject) => {
|
|
182
|
-
const request = indexedDB.open('dsh-touch-fish-novel', 1)
|
|
183
|
-
request.onupgradeneeded = () => {
|
|
184
|
-
const db = request.result
|
|
185
|
-
db.createObjectStore('books', { keyPath: 'id' })
|
|
186
|
-
db.createObjectStore('settings', { keyPath: 'key' })
|
|
187
|
-
db.createObjectStore('segments', { keyPath: 'id' }).createIndex('bookId', 'bookId')
|
|
188
|
-
}
|
|
189
|
-
request.onsuccess = () => resolve(request.result)
|
|
190
|
-
request.onerror = () => reject(request.error)
|
|
191
|
-
})
|
|
192
|
-
try {
|
|
193
|
-
const tx = db.transaction(['books', 'settings', 'segments'], 'readwrite')
|
|
194
|
-
const done = new Promise((resolve, reject) => { tx.oncomplete = resolve; tx.onerror = () => reject(tx.error); tx.onabort = () => reject(tx.error) })
|
|
195
|
-
tx.objectStore('books').put({ id: 'existing-book', title: 'Existing isolated book', format: 'txt', progress: 1, segmentCount: 2, importedAt: 1 })
|
|
196
|
-
tx.objectStore('settings').put({ key: 'settings', value: { enabled: true, currentBookId: 'existing-book', targetTypes: ['reasoning'], mainTitle: 'Saved title', extraTitle: '', continueOnReopen: false } })
|
|
197
|
-
for (let index = 0; index < 2; index++) tx.objectStore('segments').put({ id: 'existing-book:' + index, bookId: 'existing-book', index, text: index ? legacyPassage : 'Existing segment A' })
|
|
198
|
-
// Simulate either untagged legacy manual imports or explicitly owned v1 defaults.
|
|
199
|
-
if (savedSamples) {
|
|
200
|
-
for (const book of savedSamples.books) tx.objectStore('books').put(book)
|
|
201
|
-
for (const segment of savedSamples.segments) tx.objectStore('segments').put(segment)
|
|
202
|
-
if (oldCatalog) {
|
|
203
|
-
tx.objectStore('settings').put({ key: 'bundled-books-v1', value: true })
|
|
204
|
-
tx.objectStore('settings').put({ key: 'settings', value: { enabled: true, currentBookId: 'bundled:shanhaijing-illustrated', targetTypes: ['reasoning'], mainTitle: 'Saved title', extraTitle: '', continueOnReopen: false } })
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
await done
|
|
208
|
-
} finally { db.close() }
|
|
209
|
-
}, { legacyPassage, savedSamples, oldCatalog })
|
|
210
|
-
}
|
|
211
|
-
async function assertConciseLibrary(page) {
|
|
212
|
-
assert.equal(await page.locator('[data-novel-sample-select], [data-novel-samples]').count(), 0, 'no separate bundled import UI')
|
|
213
|
-
assert.equal(await page.locator('[data-novel-book-info], [data-novel-sample-license]').count(), 0, 'information is unmounted by default')
|
|
214
|
-
assert.equal(await page.getByRole('dialog').count(), 0)
|
|
215
|
-
assert.equal(await page.locator('[data-novel-notice]').count(), 0, 'automatic seeding and selections do not announce imports')
|
|
216
|
-
// Source books retain original notices inside their reading text; only the
|
|
217
|
-
// ordinary settings UI must omit the separate legal/instruction block.
|
|
218
|
-
const text = await page.locator('[data-novel-settings]').innerText()
|
|
219
|
-
for (const phrase of ['Project Gutenberg', 'CC BY-SA', 'This eBook is for the use', '离线完整许可', '书源、作者与许可', '首次主动展开另一个区域才续读', '图标与折叠交互跟随 DSH']) {
|
|
220
|
-
assert.ok(!text.includes(phrase), `ordinary settings must not show ${phrase}`)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
async function assertUnifiedMenu(page) {
|
|
224
|
-
const value = await state(page)
|
|
225
|
-
const selector = page.locator('[data-novel-book-select]')
|
|
226
|
-
assert.equal(await selector.isEnabled(), true, 'information remains accessible with an empty library')
|
|
227
|
-
await selector.click()
|
|
228
|
-
assert.deepEqual(await page.getByRole('menuitem').allTextContents(), [
|
|
229
|
-
'请选择书籍', ...value.books.map(book => `${book.title} · ${book.format.toUpperCase()}`), '书籍信息',
|
|
230
|
-
])
|
|
231
|
-
await selector.click()
|
|
232
|
-
}
|
|
233
|
-
async function assertProgress(page, book) {
|
|
234
|
-
await page.waitForFunction(({ progress, total }) => {
|
|
235
|
-
const bar = document.querySelector('[data-novel-settings] progress')
|
|
236
|
-
return bar?.value === progress && bar.max === total
|
|
237
|
-
}, { progress: book.progress, total: book.segmentCount })
|
|
238
|
-
assert.equal(await page.locator('[data-novel-progress]').innerText(), `已读 ${book.progress} / ${book.segmentCount} 段 · ${Math.floor(book.progress / book.segmentCount * 100)}%`)
|
|
239
|
-
}
|
|
240
|
-
async function importFileByInput(page, sample, suppliedBytes = null) {
|
|
241
|
-
const before = await state(page)
|
|
242
|
-
const path = join(root, 'samples/ebooks', sample.file)
|
|
243
|
-
const bytes = suppliedBytes ?? await readFile(path)
|
|
244
|
-
assert.equal(bytes.length, sample.bytes)
|
|
245
|
-
assert.equal(createHash('sha256').update(bytes).digest('hex'), sample.sha256)
|
|
246
|
-
// Use the application's genuine file-input change handler, never an exposed
|
|
247
|
-
// import action. A recovered official TXT payload exercises the genuine old AQ parser.
|
|
248
|
-
await page.locator('[data-novel-file-input]').setInputFiles(suppliedBytes ? { name: sample.file, mimeType: 'text/plain', buffer: bytes } : path)
|
|
249
|
-
await page.waitForFunction(count => window.__novelTest.state().books.length === count, before.books.length + 1)
|
|
250
|
-
await page.waitForFunction(() => document.querySelector('[data-novel-notice]')?.textContent.startsWith('导入完成:'))
|
|
251
|
-
const value = await state(page)
|
|
252
|
-
assert.equal(value.books.length, before.books.length + 1)
|
|
253
|
-
const imported = value.books.find(book => !before.books.some(previous => previous.id === book.id))
|
|
254
|
-
assert.ok(imported)
|
|
255
|
-
assert.equal(imported.format, sample.format)
|
|
256
|
-
assert.equal(imported.segmentCount, sample.expectedSegments ?? expectedSegments[sample.id])
|
|
257
|
-
assert.equal(value.settings.currentBookId, before.settings.currentBookId ?? imported.id)
|
|
258
|
-
return imported
|
|
259
|
-
}
|
|
260
|
-
async function selectByClick(page, book) {
|
|
261
|
-
await page.locator('[data-novel-book-select]').click()
|
|
262
|
-
await page.getByRole('menuitem', { name: `${book.title} · ${book.format.toUpperCase()}`, exact: true }).click()
|
|
263
|
-
await page.waitForFunction(id => window.__novelTest.state().settings.currentBookId === id, book.id)
|
|
264
|
-
await assertProgress(page, (await state(page)).books.find(item => item.id === book.id))
|
|
265
|
-
}
|
|
266
|
-
async function readByClick(page, book, expectedText) {
|
|
267
|
-
const toggle = page.locator('#fixture-disclosure')
|
|
268
|
-
if (await toggle.getAttribute('aria-expanded') === 'true') await toggle.click()
|
|
269
|
-
await toggle.click() // Playwright dispatches trusted browser input, not evaluate().click().
|
|
270
|
-
await page.waitForFunction(id => window.__novelTest.state().books.find(book => book.id === id)?.progress > 0, book.id)
|
|
271
|
-
await page.waitForFunction(() => document.querySelector('[data-novel-passage]')?.textContent?.length > 0)
|
|
272
|
-
await page.waitForFunction(text => document.querySelector('[data-novel-passage]')?.textContent === text, expectedText)
|
|
273
|
-
assert.equal(await page.locator('[data-novel-original]').innerText(), 'Original reasoning fixture text')
|
|
274
|
-
assert.equal(await page.locator('[data-novel-append] hr').count(), 1)
|
|
275
|
-
const first = (await database(page)).segments.find(segment => segment.bookId === book.id && segment.index === 0)
|
|
276
|
-
const pg = /\bProject\s+Gutenberg\b/iu.test(first?.text ?? '')
|
|
277
|
-
const notice = page.locator('[data-novel-pg-notice]')
|
|
278
|
-
assert.equal(await notice.count(), pg ? 1 : 0, 'only PG text has the required display notice')
|
|
279
|
-
if (pg) {
|
|
280
|
-
assert.equal(await notice.locator('p').textContent(), PG_NOTICE)
|
|
281
|
-
assert.equal(await notice.isVisible(), true)
|
|
282
|
-
assert.equal(await notice.evaluate(element => element.parentElement === document.querySelector('[data-novel-passage]').parentElement), true, 'notice is outside the scroll-clipped passage')
|
|
283
|
-
const link = notice.locator('a[download]')
|
|
284
|
-
const href = await link.getAttribute('href')
|
|
285
|
-
assert.equal(decodeURIComponent(href.slice(href.indexOf(',') + 1)), expectedLicense)
|
|
286
|
-
const waiting = page.waitForEvent('download')
|
|
287
|
-
await link.click()
|
|
288
|
-
const download = await waiting
|
|
289
|
-
assert.equal(download.suggestedFilename(), 'project-gutenberg-full-license.txt')
|
|
290
|
-
const target = join(temp, `pg-${createHash('sha256').update(book.id).digest('hex').slice(0, 12)}.txt`)
|
|
291
|
-
await download.saveAs(target)
|
|
292
|
-
assert.equal(await download.failure(), null)
|
|
293
|
-
assert.equal(await readFile(target, 'utf8'), expectedLicense)
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
async function probeLegacyLayout(page) {
|
|
297
|
-
const measurements = []
|
|
298
|
-
for (const width of [320, 600]) {
|
|
299
|
-
await page.setViewportSize({ width: width + 16, height: 640 })
|
|
300
|
-
const passage = page.locator('[data-novel-passage]')
|
|
301
|
-
assert.equal(await passage.textContent(), legacyPassage)
|
|
302
|
-
const box = await passage.evaluate(element => {
|
|
303
|
-
element.scrollTop = 0
|
|
304
|
-
const rect = element.getBoundingClientRect()
|
|
305
|
-
const toggle = document.querySelector('#fixture-disclosure').getBoundingClientRect()
|
|
306
|
-
const style = getComputedStyle(element)
|
|
307
|
-
return { width: rect.width, height: rect.height, scrollHeight: element.scrollHeight,
|
|
308
|
-
clientHeight: element.clientHeight, overflowY: style.overflowY,
|
|
309
|
-
originalHeight: document.querySelector('[data-novel-original]').getBoundingClientRect().height,
|
|
310
|
-
distanceFromToggle: rect.top - toggle.bottom, fontSize: style.fontSize, lineHeight: style.lineHeight }
|
|
311
|
-
})
|
|
312
|
-
assert.ok(box.height <= 257, '40vh guard bounds the novel, including legacy passages')
|
|
313
|
-
assert.ok(box.scrollHeight > box.clientHeight * 3, 'oversized text remains present, not truncated')
|
|
314
|
-
assert.equal(box.overflowY, 'auto')
|
|
315
|
-
assert.ok(box.distanceFromToggle < 100, 'novel does not add a large gap before its scroll container')
|
|
316
|
-
await passage.focus()
|
|
317
|
-
await passage.press('End')
|
|
318
|
-
await page.waitForFunction(() => document.querySelector('[data-novel-passage]').scrollTop > 0)
|
|
319
|
-
assert.equal(await passage.textContent(), legacyPassage, 'keyboard scrolling preserves the complete text')
|
|
320
|
-
const progress = (await state(page)).books.find(book => book.id === 'existing-book').progress
|
|
321
|
-
await page.locator('#fixture-disclosure').click()
|
|
322
|
-
await passage.waitFor({ state: 'detached' })
|
|
323
|
-
await page.locator('#fixture-disclosure').click()
|
|
324
|
-
await page.waitForFunction(text => document.querySelector('[data-novel-passage]')?.textContent === text, legacyPassage)
|
|
325
|
-
assert.equal((await state(page)).books.find(book => book.id === 'existing-book').progress, progress, 'collapse/reopen is cached')
|
|
326
|
-
measurements.push({ viewportWidth: width + 16, ...box, keyboardScroll: true, cachedReopen: true })
|
|
327
|
-
}
|
|
328
|
-
return measurements
|
|
329
|
-
}
|
|
330
|
-
async function openBookInfo(page) {
|
|
331
|
-
const before = await state(page)
|
|
332
|
-
await page.locator('[data-novel-book-select]').click()
|
|
333
|
-
await page.getByRole('menuitem', { name: '书籍信息', exact: true }).click()
|
|
334
|
-
const dialog = page.getByRole('dialog', { name: '书籍信息', exact: true })
|
|
335
|
-
await dialog.waitFor({ state: 'visible' })
|
|
336
|
-
assert.equal(await page.locator('[role="menu"]').count(), 0)
|
|
337
|
-
assert.deepEqual(await state(page), before, 'footer opens information without selecting a fake book')
|
|
338
|
-
for (const sample of manifest.books) {
|
|
339
|
-
assert.equal(await dialog.getByRole('link', { name: sample.title, exact: true }).getAttribute('href'), sample.source)
|
|
340
|
-
assert.ok((await dialog.innerText()).includes(sample.author))
|
|
341
|
-
assert.ok((await dialog.innerText()).includes(sample.license))
|
|
342
|
-
}
|
|
343
|
-
assert.equal(await dialog.locator('[data-novel-sample-license]').count(), 1)
|
|
344
|
-
return dialog
|
|
345
|
-
}
|
|
346
|
-
async function closeBookInfo(page) {
|
|
347
|
-
await page.getByRole('dialog', { name: '书籍信息', exact: true }).getByRole('button', { name: '关闭', exact: true }).click()
|
|
348
|
-
await page.locator('[data-novel-book-info]').waitFor({ state: 'detached' })
|
|
349
|
-
await assertConciseLibrary(page)
|
|
350
|
-
}
|
|
351
|
-
async function deleteByClick(page, book, { cancelFirst = false } = {}) {
|
|
352
|
-
await selectByClick(page, book)
|
|
353
|
-
const before = await state(page)
|
|
354
|
-
await page.locator('[data-novel-delete]').click()
|
|
355
|
-
const dialog = page.getByRole('dialog', { name: '删除当前书籍', exact: true })
|
|
356
|
-
await dialog.waitFor({ state: 'visible' })
|
|
357
|
-
assert.ok((await dialog.innerText()).includes(`删除《${book.title}》及其本地阅读进度?`))
|
|
358
|
-
assert.deepEqual(await state(page), before, 'opening confirmation must not delete')
|
|
359
|
-
if (cancelFirst) {
|
|
360
|
-
await dialog.getByRole('button', { name: '取消', exact: true }).last().click()
|
|
361
|
-
await dialog.waitFor({ state: 'detached' })
|
|
362
|
-
assert.deepEqual(await state(page), before, 'cancelling preserves the complete library')
|
|
363
|
-
await page.locator('[data-novel-delete]').click()
|
|
364
|
-
}
|
|
365
|
-
await dialog.locator('[data-novel-delete-confirm]').click()
|
|
366
|
-
await page.waitForFunction(id => !window.__novelTest.state().books.some(book => book.id === id), book.id)
|
|
367
|
-
await dialog.waitFor({ state: 'detached' })
|
|
368
|
-
await page.waitForFunction(() => !document.querySelector('[data-novel-passage]'))
|
|
369
|
-
const after = await state(page)
|
|
370
|
-
assert.equal(after.books.length, before.books.length - 1)
|
|
371
|
-
assert.equal(after.settings.currentBookId, after.books[0]?.id ?? null)
|
|
372
|
-
assert.notEqual(after.settings.currentBookId, book.id, 'selection cannot remain on deleted book')
|
|
373
|
-
const stored = await database(page)
|
|
374
|
-
assert.equal(stored.bundledBooksInitialized, true)
|
|
375
|
-
assert.deepEqual(stored.books, after.books)
|
|
376
|
-
assert.equal(stored.settings.currentBookId, after.settings.currentBookId)
|
|
377
|
-
assert.ok(stored.segments.every(segment => segment.bookId !== book.id), 'deletion removes book segments too')
|
|
378
|
-
return stored
|
|
379
|
-
}
|
|
380
|
-
async function downloadLicense(page, label) {
|
|
381
|
-
const dialog = await openBookInfo(page)
|
|
382
|
-
const anchor = dialog.locator('[data-novel-book-info] a[download]')
|
|
383
|
-
const href = await anchor.getAttribute('href')
|
|
384
|
-
assert.ok(href.startsWith('data:text/plain;charset=utf-8,'))
|
|
385
|
-
assert.equal(decodeURIComponent(href.slice(href.indexOf(',') + 1)), expectedLicense)
|
|
386
|
-
const waiting = page.waitForEvent('download')
|
|
387
|
-
await anchor.click()
|
|
388
|
-
const download = await waiting
|
|
389
|
-
assert.equal(download.suggestedFilename(), 'bundled-ebooks-notices.txt')
|
|
390
|
-
const target = join(temp, `${label}-license.txt`)
|
|
391
|
-
await download.saveAs(target)
|
|
392
|
-
assert.equal(await download.failure(), null)
|
|
393
|
-
const bytes = await readFile(target)
|
|
394
|
-
assert.deepEqual(bytes, Buffer.from(expectedLicense, 'utf8'), 'download is byte-identical to original LICENSE.md')
|
|
395
|
-
const text = bytes.toString('utf8')
|
|
396
|
-
for (const section of ['START: FULL LICENSE', 'Section 1.', 'Section 2.', 'Section 3.', 'Section 4.', 'Section 5.']) assert.ok(text.includes(section), section)
|
|
397
|
-
await closeBookInfo(page)
|
|
398
|
-
return { bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') }
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
try {
|
|
402
|
-
const fixture = await build({
|
|
403
|
-
stdin: { contents: fixtureSource, resolveDir: root, sourcefile: 'isolated-browser-fixture.js', loader: 'js' },
|
|
404
|
-
bundle: true, platform: 'browser', format: 'iife', target: ['chrome120'], write: false,
|
|
405
|
-
outfile: join(temp, 'host-fixture.js'), define: { 'process.env.NODE_ENV': '"production"' },
|
|
406
|
-
plugins: [{ name: 'single-react-runtime', setup(build) { build.onResolve({ filter: /^react$/ }, () => ({ path: reactModule })) } }],
|
|
407
|
-
})
|
|
408
|
-
const fixtureJs = Buffer.from(fixture.outputFiles[0].contents)
|
|
409
|
-
browser = await chromium.launch({
|
|
410
|
-
headless: true,
|
|
411
|
-
...(process.env.CHROME_EXECUTABLE ? { executablePath: process.env.CHROME_EXECUTABLE } : { channel: 'chrome' }),
|
|
412
|
-
args: ['--disable-background-networking', '--no-first-run', '--no-default-browser-check'],
|
|
413
|
-
})
|
|
414
|
-
let savedSamples = null, savedV1 = null
|
|
415
|
-
for (const label of ['fresh-library', 'existing-library', 'legacy-saved-samples', 'v1-catalog-upgrade']) {
|
|
416
|
-
const seeded = label !== 'fresh-library'
|
|
417
|
-
const migrated = label === 'legacy-saved-samples'
|
|
418
|
-
const upgraded = label === 'v1-catalog-upgrade'
|
|
419
|
-
const context = await browser.newContext({ offline: true, serviceWorkers: 'block', acceptDownloads: true })
|
|
420
|
-
try {
|
|
421
|
-
const page = await context.newPage()
|
|
422
|
-
page.setDefaultTimeout(15000)
|
|
423
|
-
page.on('pageerror', error => failures.push(`${label}: ${error.stack || error.message}`))
|
|
424
|
-
page.on('console', message => { if (message.type() === 'error') failures.push(`${label}: console: ${message.text()}`) })
|
|
425
|
-
await page.route('**/*', async route => {
|
|
426
|
-
const url = route.request().url()
|
|
427
|
-
requestLog.push({ scenario: label, url })
|
|
428
|
-
const paths = new Map([
|
|
429
|
-
[`${origin}/`, { contentType: 'text/html; charset=utf-8', body: html }],
|
|
430
|
-
[`${origin}/seed`, { contentType: 'text/html', body: '<!doctype html><link rel="icon" href="data:,"><title>Isolated IndexedDB seed</title>' }],
|
|
431
|
-
[`${origin}/host-fixture.js`, { contentType: 'text/javascript', body: fixtureJs }],
|
|
432
|
-
[`${origin}/lib/client.js`, { contentType: 'text/javascript', body: bundle }],
|
|
433
|
-
])
|
|
434
|
-
const response = paths.get(url)
|
|
435
|
-
if (!response || route.request().method() !== 'GET') {
|
|
436
|
-
failures.push(`${label}: unexpected network request ${route.request().method()} ${url}`)
|
|
437
|
-
await route.abort('internetdisconnected')
|
|
438
|
-
} else await route.fulfill({ status: 200, ...response })
|
|
439
|
-
})
|
|
440
|
-
if (seeded) {
|
|
441
|
-
await page.goto(`${origin}/seed`)
|
|
442
|
-
await seedExisting(page, migrated ? savedSamples : upgraded ? savedV1 : null, upgraded)
|
|
443
|
-
assert.equal((await database(page)).bundledBooksInitialized, upgraded)
|
|
444
|
-
}
|
|
445
|
-
await page.goto(`${origin}/`)
|
|
446
|
-
let value = await hydrated(page)
|
|
447
|
-
assert.equal(await page.evaluate(() => navigator.onLine), false)
|
|
448
|
-
const initialCount = manifest.books.length + Number(seeded)
|
|
449
|
-
assert.equal(value.books.length, initialCount, 'bundled books are seeded automatically, not imported through a separate UI')
|
|
450
|
-
const preservedId = upgraded ? 'bundled:aq-zheng-zhuan' : seeded ? 'existing-book' : `bundled:${manifest.books[0].id}`
|
|
451
|
-
assert.equal(value.settings.currentBookId, preservedId)
|
|
452
|
-
await assertConciseLibrary(page)
|
|
453
|
-
await assertUnifiedMenu(page)
|
|
454
|
-
await assertProgress(page, value.books.find(book => book.id === preservedId))
|
|
455
|
-
const registration = await page.evaluate(() => ({ imports: window.__novelTest.hostImports, slots: window.__novelTest.injections, samples: window.__novelTest.samples }))
|
|
456
|
-
assert.deepEqual(registration.imports, ['react', '@deepseek-ai/dsh-client-ui-primitives'])
|
|
457
|
-
assert.ok(registration.slots.includes('plugins.bundle.config'))
|
|
458
|
-
assert.ok(!registration.slots.includes('settings.general.item'))
|
|
459
|
-
assert.deepEqual(registration.samples, manifest.books.map(({ id, title, author, format, bytes, source, license }) => ({ id, title, author, format, bytes, source, license })))
|
|
460
|
-
const samples = manifest.books.map((sample, index) => {
|
|
461
|
-
const id = migrated ? savedSamples.books[index].id : `bundled:${sample.id}`
|
|
462
|
-
const book = value.books.find(book => book.id === id)
|
|
463
|
-
assert.ok(book)
|
|
464
|
-
assert.equal(book.title, migrated ? savedSamples.books[index].title : upgraded ? savedV1.books.find(item => item.id === id).title : sample.title)
|
|
465
|
-
assert.equal(book.format, sample.format)
|
|
466
|
-
assert.equal(book.segmentCount, upgraded ? savedV1.books.find(item => item.id === id).segmentCount : expectedSegments[sample.id])
|
|
467
|
-
assert.equal(book.progress, migrated ? savedSamples.books[index].progress : upgraded ? savedV1.books.find(item => item.id === id).progress : 0)
|
|
468
|
-
if (!migrated) assert.equal(book.bundledId, sample.id)
|
|
469
|
-
return book
|
|
470
|
-
})
|
|
471
|
-
let stored = await database(page)
|
|
472
|
-
assert.equal(stored.books.length, initialCount)
|
|
473
|
-
assert.equal(stored.bundledBooksInitialized, true)
|
|
474
|
-
assert.equal(stored.settings.currentBookId, preservedId)
|
|
475
|
-
assert.equal(stored.settingsRecords.filter(record => record.key === 'bundled-books-v1').length, 1)
|
|
476
|
-
assert.equal(stored.bundledCatalogVersion, 2)
|
|
477
|
-
assert.ok(!('bundledBooksInitialized' in stored.settings), 'marker is separate from user settings')
|
|
478
|
-
for (const book of samples) {
|
|
479
|
-
const segments = stored.segments.filter(segment => segment.bookId === book.id).sort((a, b) => a.index - b.index)
|
|
480
|
-
assert.equal(segments.length, book.segmentCount)
|
|
481
|
-
assert.ok(segments.every((segment, index) => segment.index === index && typeof segment.text === 'string' && segment.text.length > 0))
|
|
482
|
-
}
|
|
483
|
-
if (migrated) {
|
|
484
|
-
assert.deepEqual(stored.books.filter(book => book.id !== 'existing-book'), savedSamples.books, 'all legacy sample metadata and progress are preserved without duplicates')
|
|
485
|
-
assert.deepEqual(stored.segments.filter(segment => segment.bookId !== 'existing-book'), savedSamples.segments)
|
|
486
|
-
assert.equal(stored.books.filter(book => book.id.startsWith('bundled:')).length, 0)
|
|
487
|
-
}
|
|
488
|
-
if (upgraded) {
|
|
489
|
-
const surviving = savedV1.books.filter(book => book.bundledId !== 'shanhaijing-illustrated').map(book => book.bundledId === 'aq-zheng-zhuan' ? { ...book, format: 'md' } : book)
|
|
490
|
-
assert.deepEqual(stored.books.filter(book => book.id !== 'existing-book'), surviving.sort((a, b) => a.id.localeCompare(b.id)))
|
|
491
|
-
assert.deepEqual(stored.segments.filter(segment => segment.bookId !== 'existing-book'), savedV1.segments.filter(segment => segment.bookId !== 'bundled:shanhaijing-illustrated').sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
|
|
492
|
-
assert.ok(stored.segments.every(segment => segment.bookId !== 'bundled:shanhaijing-illustrated'))
|
|
493
|
-
assert.equal(stored.settings.currentBookId, preservedId)
|
|
494
|
-
}
|
|
495
|
-
if (!seeded) {
|
|
496
|
-
if (process.env.CAPTURE_SETTINGS === '1') {
|
|
497
|
-
await page.setViewportSize({ width: 760, height: 1000 })
|
|
498
|
-
await page.locator('[data-novel-book-select]').click()
|
|
499
|
-
await page.screenshot({ path: join(root, 'dist/ebooks/settings-unified-preview.png'), fullPage: true })
|
|
500
|
-
await page.locator('[data-novel-book-select]').click()
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
await page.reload()
|
|
504
|
-
value = await hydrated(page)
|
|
505
|
-
assert.equal(value.settings.currentBookId, preservedId)
|
|
506
|
-
assert.deepEqual(value.books, stored.books)
|
|
507
|
-
await assertConciseLibrary(page)
|
|
508
|
-
if (seeded) {
|
|
509
|
-
assert.equal(value.settings.mainTitle, 'Saved title')
|
|
510
|
-
assert.equal(value.books.find(book => book.id === 'existing-book').progress, 1)
|
|
511
|
-
assert.deepEqual(stored.segments.filter(segment => segment.bookId === 'existing-book').map(segment => segment.text), ['Existing segment A', legacyPassage])
|
|
512
|
-
}
|
|
513
|
-
for (const book of samples) {
|
|
514
|
-
await selectByClick(page, book)
|
|
515
|
-
const next = stored.segments.find(segment => segment.bookId === book.id && segment.index === book.progress)
|
|
516
|
-
await readByClick(page, book, next.text)
|
|
517
|
-
await page.waitForFunction(({ id, progress }) => window.__novelTest.state().books.find(book => book.id === id).progress === progress + 1, book)
|
|
518
|
-
await assertProgress(page, { ...book, progress: book.progress + 1 })
|
|
519
|
-
await assertConciseLibrary(page)
|
|
520
|
-
}
|
|
521
|
-
const license = await downloadLicense(page, label)
|
|
522
|
-
stored = await database(page)
|
|
523
|
-
assert.equal(stored.settings.currentBookId, samples.at(-1).id)
|
|
524
|
-
assert.ok(samples.every(book => stored.books.find(item => item.id === book.id).progress === book.progress + 1))
|
|
525
|
-
await page.reload()
|
|
526
|
-
value = await hydrated(page)
|
|
527
|
-
assert.equal(value.settings.currentBookId, samples.at(-1).id)
|
|
528
|
-
assert.deepEqual(value.books, stored.books)
|
|
529
|
-
await assertConciseLibrary(page)
|
|
530
|
-
let layout = null
|
|
531
|
-
if (seeded) {
|
|
532
|
-
const existing = value.books.find(book => book.id === 'existing-book')
|
|
533
|
-
await selectByClick(page, existing)
|
|
534
|
-
await readByClick(page, existing, legacyPassage)
|
|
535
|
-
await page.waitForFunction(() => window.__novelTest.state().books.find(book => book.id === 'existing-book').progress === 2)
|
|
536
|
-
layout = await probeLegacyLayout(page)
|
|
537
|
-
assert.equal((await database(page)).segments.find(segment => segment.bookId === 'existing-book' && segment.index === 1).text, legacyPassage)
|
|
538
|
-
await page.reload()
|
|
539
|
-
value = await hydrated(page)
|
|
540
|
-
assert.equal(value.settings.currentBookId, 'existing-book')
|
|
541
|
-
assert.equal(value.books.find(book => book.id === 'existing-book').progress, 2)
|
|
542
|
-
}
|
|
543
|
-
// Keep a genuine passage visible during the first deletion, so clearing
|
|
544
|
-
// stale text is verified rather than inferred from a closed disclosure.
|
|
545
|
-
await selectByClick(page, samples[0])
|
|
546
|
-
const deleting = (await state(page)).books.find(book => book.id === samples[0].id)
|
|
547
|
-
const deletingSegment = (await database(page)).segments.find(segment => segment.bookId === deleting.id && segment.index === deleting.progress)
|
|
548
|
-
await readByClick(page, deleting, deletingSegment.text)
|
|
549
|
-
assert.equal(await page.locator('[data-novel-passage]').count(), 1)
|
|
550
|
-
// Delete through the same menu and confirmation as an imported book.
|
|
551
|
-
// The selected fallback and deletion survive reload.
|
|
552
|
-
stored = await deleteByClick(page, deleting, { cancelFirst: true })
|
|
553
|
-
const afterFirstDeletion = stored.books.length
|
|
554
|
-
assert.equal(afterFirstDeletion, initialCount - 1)
|
|
555
|
-
await page.reload()
|
|
556
|
-
value = await hydrated(page)
|
|
557
|
-
assert.deepEqual(value.books, stored.books, 'deleted bundled book must not be restored')
|
|
558
|
-
assert.equal(value.settings.currentBookId, stored.settings.currentBookId)
|
|
559
|
-
await assertConciseLibrary(page)
|
|
560
|
-
await assertUnifiedMenu(page)
|
|
561
|
-
const deletionCounts = [initialCount, afterFirstDeletion]
|
|
562
|
-
while (value.books.length) {
|
|
563
|
-
stored = await deleteByClick(page, value.books[0])
|
|
564
|
-
value = await state(page)
|
|
565
|
-
deletionCounts.push(value.books.length)
|
|
566
|
-
}
|
|
567
|
-
for (let reload = 0; reload < 2; reload++) {
|
|
568
|
-
await page.reload()
|
|
569
|
-
value = await hydrated(page)
|
|
570
|
-
assert.deepEqual(value.books, [], 'deleting every book must not trigger reseeding')
|
|
571
|
-
assert.equal(value.settings.currentBookId, null)
|
|
572
|
-
stored = await database(page)
|
|
573
|
-
assert.deepEqual(stored.books, [])
|
|
574
|
-
assert.deepEqual(stored.segments, [])
|
|
575
|
-
assert.equal(stored.settings.currentBookId, null)
|
|
576
|
-
assert.equal(stored.bundledBooksInitialized, true)
|
|
577
|
-
assert.equal(await page.locator('[data-novel-delete], [data-novel-progress], [data-novel-settings] progress').count(), 0)
|
|
578
|
-
await assertConciseLibrary(page)
|
|
579
|
-
await assertUnifiedMenu(page)
|
|
580
|
-
}
|
|
581
|
-
await openBookInfo(page)
|
|
582
|
-
await closeBookInfo(page)
|
|
583
|
-
let actualFileImports = null
|
|
584
|
-
if (!seeded) {
|
|
585
|
-
// Re-create the previous sample-import path with the real file input.
|
|
586
|
-
// Copy its ACTUAL parsed metadata, not the new bundled descriptor,
|
|
587
|
-
// into the later pre-marker adoption fixture.
|
|
588
|
-
const imported = []
|
|
589
|
-
for (const sample of manifest.books) imported.push(await importFileByInput(page, sample))
|
|
590
|
-
await page.reload()
|
|
591
|
-
value = await hydrated(page)
|
|
592
|
-
await assertConciseLibrary(page)
|
|
593
|
-
await assertUnifiedMenu(page)
|
|
594
|
-
assert.equal(value.books.length, manifest.books.length)
|
|
595
|
-
for (const book of imported) {
|
|
596
|
-
await selectByClick(page, book)
|
|
597
|
-
const first = (await database(page)).segments.find(segment => segment.bookId === book.id && segment.index === 0)
|
|
598
|
-
await readByClick(page, book, first.text)
|
|
599
|
-
await assertProgress(page, { ...book, progress: 1 })
|
|
600
|
-
}
|
|
601
|
-
const actual = await database(page)
|
|
602
|
-
const remap = new Map(imported.map((book, index) => [book.id, `saved-sample:${index}`]))
|
|
603
|
-
savedSamples = {
|
|
604
|
-
books: imported.map(book => ({ ...actual.books.find(item => item.id === book.id), id: remap.get(book.id) })),
|
|
605
|
-
segments: actual.segments.map(segment => ({ ...segment, id: `${remap.get(segment.bookId)}:${segment.index}`, bookId: remap.get(segment.bookId) })),
|
|
606
|
-
}
|
|
607
|
-
savedSamples.segments.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0)
|
|
608
|
-
actualFileImports = savedSamples.books.map(book => ({ title: book.title, format: book.format, segments: book.segmentCount, progress: book.progress }))
|
|
609
|
-
// Recover all original export bytes from the shipped MD, then import
|
|
610
|
-
// through the REAL file input to produce exact historical TXT passages.
|
|
611
|
-
const aqSource = manifest.books.find(book => book.id === 'aq-zheng-zhuan')
|
|
612
|
-
const mdBytes = await readFile(join(root, 'samples/ebooks', aqSource.file))
|
|
613
|
-
const prefix = Buffer.from(aqSource.derivation.prefix, 'utf8')
|
|
614
|
-
assert.deepEqual(mdBytes.subarray(0, prefix.length), prefix)
|
|
615
|
-
const oldBytes = mdBytes.subarray(prefix.length)
|
|
616
|
-
const legacyAq = await importFileByInput(page, { file: 'aq-legacy.txt', format: 'txt', expectedSegments: 98, bytes: aqSource.derivation.originalBytes, sha256: aqSource.derivation.originalSha256 }, oldBytes)
|
|
617
|
-
await selectByClick(page, legacyAq)
|
|
618
|
-
const oldSegment = (await database(page)).segments.find(segment => segment.bookId === legacyAq.id && segment.index === 0)
|
|
619
|
-
await readByClick(page, legacyAq, oldSegment.text)
|
|
620
|
-
const withOld = await database(page)
|
|
621
|
-
const english = savedSamples.books[0]
|
|
622
|
-
const oldAq = withOld.books.find(book => book.id === legacyAq.id)
|
|
623
|
-
const removedId = 'bundled:shanhaijing-illustrated'
|
|
624
|
-
const mapping = new Map([[english.id, 'bundled:million-pound-bank-note'], [oldAq.id, 'bundled:aq-zheng-zhuan']])
|
|
625
|
-
savedV1 = {
|
|
626
|
-
books: [
|
|
627
|
-
{ ...english, id: mapping.get(english.id), bundledId: 'million-pound-bank-note' },
|
|
628
|
-
{ ...oldAq, id: mapping.get(oldAq.id), bundledId: 'aq-zheng-zhuan' },
|
|
629
|
-
{ id: removedId, bundledId: 'shanhaijing-illustrated', title: 'Removed legacy default', format: 'epub', progress: 1, segmentCount: 1, importedAt: 1 },
|
|
630
|
-
],
|
|
631
|
-
segments: [...savedSamples.segments.filter(segment => segment.bookId === english.id), ...withOld.segments.filter(segment => segment.bookId === oldAq.id)]
|
|
632
|
-
.map(segment => ({ ...segment, id: `${mapping.get(segment.bookId)}:${segment.index}`, bookId: mapping.get(segment.bookId) })),
|
|
633
|
-
}
|
|
634
|
-
savedV1.segments.push({ id: removedId + ':0', bookId: removedId, index: 0, text: 'Legacy default passage removed atomically.' })
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
reports.push({ scenario: label, initialBooks: initialCount, actualFileImports,
|
|
638
|
-
samples: samples.map(book => ({ id: book.id, title: book.title, format: book.format, segments: book.segmentCount, initialProgress: book.progress, readProgress: book.progress + 1 })),
|
|
639
|
-
licenseBytes: license.bytes, licenseSha256: license.sha256,
|
|
640
|
-
automaticSeed: !migrated && !upgraded, legacySamplesDeduplicated: migrated, v1CatalogMigrated: upgraded, markerSeparateFromSettings: true,
|
|
641
|
-
reloadPersistence: true, menuClicks: true, trustedDisclosureRead: true, originalReasoningPreserved: true,
|
|
642
|
-
conciseMainUi: true, conditionalBookInfo: true, emptyLibraryInfoAccess: true,
|
|
643
|
-
deleteConfirmationClicks: true, deleteCancelPreserved: true, deletionCounts, noReseedAfterEmptyReloads: 2,
|
|
644
|
-
legacyLayout: layout })
|
|
645
|
-
} finally { await context.close() }
|
|
646
|
-
}
|
|
647
|
-
assert.deepEqual(failures, [], failures.join('\n'))
|
|
648
|
-
// Explicitly detect concurrent rebuilds instead of attributing results to a new bundle.
|
|
649
|
-
assert.equal(createHash('sha256').update(await readFile(bundlePath)).digest('hex'), bundleSha256, 'lib/client.js changed during this run; rerun against the final build')
|
|
650
|
-
console.log(JSON.stringify({
|
|
651
|
-
ok: true, verifiedOn: new Date().toISOString(), environment: 'isolated headless Chromium component test; mocked Host primitives; NOT official DSH GUI',
|
|
652
|
-
browser: browser.version(), react: reactVersion, offline: true, bundle: 'lib/client.js', bundleBytes: bundle.length, bundleSha256,
|
|
653
|
-
unexpectedRequests: failures.length, virtualRequests: requestLog.length, network: 'only page.route-fulfilled virtual HTML/fixture/bundle; no sample or external HTTP requests', scenarios: reports,
|
|
654
|
-
}, null, 2))
|
|
655
|
-
} catch (error) {
|
|
656
|
-
console.error(JSON.stringify({ ok: false, failures, requests: requestLog }, null, 2))
|
|
657
|
-
throw error
|
|
658
|
-
} finally {
|
|
659
|
-
await browser?.close()
|
|
660
|
-
// Only remove the exact directory allocated by this script, never user data.
|
|
661
|
-
const canonicalTemp = await realpath(temp)
|
|
662
|
-
const canonicalParent = await realpath(tmpdir())
|
|
663
|
-
assert.ok(isAbsolute(canonicalTemp) && dirname(canonicalTemp) === canonicalParent && canonicalTemp.split('/').at(-1).startsWith('novel-browser-samples-'))
|
|
664
|
-
await rm(canonicalTemp, { recursive: true, force: true })
|
|
665
|
-
}
|