test(ci): [CI-01] verify installed JASSUB bundles and worker resources

This commit is contained in:
Harvey Zhao committed 2026-09-15 03:20:10 +08:00
1 parent 25a0c6303d
commit 54169fdca1
19 files changed
+2500 -217

No files matched your search

+8 -4
View File
@@ -1,10 +1,14 @@
import fs from 'node:fs'
import process from 'node:process'
import { hash } from '../../refactor/scripts/releases.mjs'
import { browserCandidate } from '../helpers/browser-candidate.js'
import { expect, test } from './fixtures.js'
const artifact = process.env.ARTPLAYER_JASSUB_ARTIFACT || 'packages/artplayer-plugin-jassub/dist/artplayer-plugin-jassub.js'
const code = fs.readFileSync(artifact, 'utf8')
const { code, provenance } = await browserCandidate('artplayer-plugin-jassub', process.env.ARTPLAYER_JASSUB_ARTIFACT)
const artifact = provenance.file || 'source-build'
test.beforeEach(async ({ browserName }, testInfo) => {
await testInfo.attach('jassub-selected-input', { contentType: 'application/json', body: JSON.stringify({ browserName, provenance }) })
})
const subtitle = `[Script Info]
ScriptType: v4.00+
PlayResX: 640
@@ -152,7 +156,7 @@ test('JASSUB actual subtitle color-space transitions tolerate a queued native hy
}
return { available: probe.available, selected: probe.selected, matrix: probe.matrix, sent: probe.sent, received: probe.received, late: probe.late, terminal: probe.terminal, errors: probe.errors, busy: window.jassub.busy, lastDemand: window.jassub._lastDemandTime }
})
await testInfo.attach('jassub-native-hybrid', { body: JSON.stringify({ artifact, sha256: hash(code), state, limitation: 'Actual Worker/WASM/ASS color-space transition and native ImageBitmap; one received render is held and delivered after synchronous public setTrack to reproduce a queued message. Not unmodified event timing, GPU endurance or physical-device evidence.' }), contentType: 'application/json' })
await testInfo.attach('jassub-native-hybrid', { body: JSON.stringify({ artifact, provenance, sha256: hash(code), state, limitation: 'Actual Worker/WASM/ASS color-space transition and native ImageBitmap; one received render is held and delivered after synchronous public setTrack to reproduce a queued message. Not unmodified event timing, GPU endurance or physical-device evidence.' }), contentType: 'application/json' })
await page.evaluate(() => {
if (!window.art.isDestroy)
window.art.destroy()
+10 -6
View File
@@ -1,10 +1,14 @@
import fs from 'node:fs'
import process from 'node:process'
import { hash } from '../../refactor/scripts/releases.mjs'
import { browserCandidate } from '../helpers/browser-candidate.js'
import { expect, test } from './fixtures.js'
const artifact = process.env.ARTPLAYER_JASSUB_ARTIFACT || 'packages/artplayer-plugin-jassub/dist/artplayer-plugin-jassub.js'
const code = fs.readFileSync(artifact, 'utf8')
const { code, provenance } = await browserCandidate('artplayer-plugin-jassub', process.env.ARTPLAYER_JASSUB_ARTIFACT)
const artifact = provenance.file || 'source-build'
test.beforeEach(async ({ browserName }, testInfo) => {
await testInfo.attach('jassub-selected-input', { contentType: 'application/json', body: JSON.stringify({ browserName, provenance }) })
})
const subtitles = `[Script Info]
ScriptType: v4.00+
PlayResX: 640
@@ -116,7 +120,7 @@ for (const onDemandRender of [true, false]) {
expect(state.errors).toEqual([])
if (!onDemandRender)
expect(state.sent.some(message => message.target === 'video' && message.rate === 1.5)).toBe(true)
await testInfo.attach('jassub-native-lifecycle', { body: JSON.stringify({ artifact, sha256: hash(code), onDemandRender, state }), contentType: 'application/json' })
await testInfo.attach('jassub-native-lifecycle', { body: JSON.stringify({ artifact, provenance, sha256: hash(code), onDemandRender, state }), contentType: 'application/json' })
}
finally {
await page.evaluate(() => {
@@ -158,7 +162,7 @@ test('JASSUB actual invalid Worker URL construction releases the newly created c
expect(state.error?.name).toBe('SyntaxError')
expect(state.activeListeners).toBe(0)
expect(state.ownedContainers).toBe(0)
await testInfo.attach('jassub-native-construction-failure', { body: JSON.stringify({ artifact, sha256: hash(code), state }), contentType: 'application/json' })
await testInfo.attach('jassub-native-construction-failure', { body: JSON.stringify({ artifact, provenance, sha256: hash(code), state }), contentType: 'application/json' })
})
test('JASSUB native asynchronous CSP Worker error reaches a pending query and explicit destruction cleans up', async ({ page }, testInfo) => {
@@ -186,5 +190,5 @@ test('JASSUB native asynchronous CSP Worker error reaches a pending query and ex
expect(state.calls).toBe(1)
expect(state.terminated).toBe(1)
expect(state.ownedContainers).toBe(0)
await testInfo.attach('jassub-native-worker-error', { body: JSON.stringify({ artifact, sha256: hash(code), state }), contentType: 'application/json' })
await testInfo.attach('jassub-native-worker-error', { body: JSON.stringify({ artifact, provenance, sha256: hash(code), state }), contentType: 'application/json' })
})
+205 -195
View File
@@ -1,6 +1,7 @@
import fs from 'node:fs'
import process from 'node:process'
import { ensureArchive, hash, readMember } from '../../refactor/scripts/releases.mjs'
import { browserCandidate } from '../helpers/browser-candidate.js'
import { expect, test } from './fixtures.js'
import { captureJassubDisplay } from './jassub-display.js'
@@ -8,9 +9,14 @@ const baseline = JSON.parse(fs.readFileSync('refactor/baselines/jassub-release.j
const release = baseline.release
const archive = await ensureArchive(release)
const member = `package/${release.manifest.main.replace(/^\.\//, '')}`
const artifact = process.env.ARTPLAYER_JASSUB_ARTIFACT
const explicitArtifact = process.env.ARTPLAYER_JASSUB_ARTIFACT
const publishedCode = readMember(archive, member).toString()
if (hash(publishedCode) !== release.files[member])
throw new Error('Published JASSUB artifact changed')
const published = { code: publishedCode, provenance: { kind: 'published', version: release.version, integrity: release.integrity, member, sha256: hash(publishedCode) } }
const candidate = process.env.ARTPLAYER_BROWSER_ARTIFACTS || explicitArtifact ? await browserCandidate('artplayer-plugin-jassub', explicitArtifact) : null
const inputs = process.env.ARTPLAYER_BROWSER_ARTIFACTS ? [published, candidate] : [candidate || published]
const customCanvas = process.env.ARTPLAYER_JASSUB_CUSTOM_CANVAS === 'true'
const code = artifact ? fs.readFileSync(artifact, 'utf8') : readMember(archive, member).toString()
const onDemandRender = process.env.ARTPLAYER_JASSUB_ON_DEMAND !== 'false'
const defaultOffscreen = process.env.ARTPLAYER_JASSUB_OFFSCREEN === 'default'
const readbackFrame = process.env.ARTPLAYER_JASSUB_READBACK_FRAME === 'true'
@@ -50,202 +56,206 @@ Dialogue: 0,${screenshotReadback ? '0:00:40.00,0:01:50.00' : '0:00:05.00,0:00:30
`
const testedSubtitles = screenshotReadback ? subtitles.replace('&H00FFFFFF', '&H0000FF00') : subtitles
for (const core of ['candidate', 'published', 'published-5.3.1-beta.1']) {
test(`JASSUB ${artifact ? 'candidate artifact' : `published ${release.version}`} renders actual WASM subtitles through seek and layout with ${core} core, customCanvas=${customCanvas}, defaultOffscreen=${defaultOffscreen}`, async ({ page, context }, testInfo) => {
const resources = []
const external = []
const origin = new URL(testInfo.project.use.baseURL).origin
await context.route('**/*', (route) => {
if (new URL(route.request().url()).origin !== origin) {
external.push(route.request().url())
return route.abort()
for (const { code, provenance } of inputs) {
const artifact = provenance.kind !== 'published' ? provenance.file : null
for (const core of ['candidate', 'published', 'published-5.3.1-beta.1']) {
test(`JASSUB ${artifact ? 'candidate artifact' : `published ${release.version}`} renders actual WASM subtitles through seek and layout with ${core} core, customCanvas=${customCanvas}, defaultOffscreen=${defaultOffscreen}`, async ({ page, context }, testInfo) => {
await testInfo.attach('jassub-selected-input', { contentType: 'application/json', body: JSON.stringify({ core, provenance }) })
const resources = []
const external = []
const origin = new URL(testInfo.project.use.baseURL).origin
await context.route('**/*', (route) => {
if (new URL(route.request().url()).origin !== origin) {
external.push(route.request().url())
return route.abort()
}
return route.continue()
})
context.on('response', (response) => {
if (response.url().includes('/assets/jassub/'))
resources.push({ url: response.url(), status: response.status(), contentType: response.headers()['content-type'] })
})
await page.goto(`/test/player.html?core=${core}`)
await page.evaluate(() => {
window.jassubFramePlatform = { before: typeof HTMLVideoElement.prototype.requestVideoFrameCallback, registered: 0, delivered: 0 }
})
await page.addScriptTag({ content: code })
await page.evaluate(() => {
const frames = window.jassubFramePlatform
frames.after = typeof HTMLVideoElement.prototype.requestVideoFrameCallback
if (frames.after === 'function') {
const request = HTMLVideoElement.prototype.requestVideoFrameCallback
HTMLVideoElement.prototype.requestVideoFrameCallback = function (callback) {
frames.registered++
return request.call(this, function (...args) {
frames.delivered++
frames.lastMetadata = args[1]
return callback.apply(this, args)
})
}
}
window.jassubNative = { workers: [], snapshots: [], errors: [], frames }
const NativeWorker = window.Worker
window.Worker = class extends NativeWorker {
constructor(...args) {
super(...args)
this.observation = { url: String(args[0]), terminated: 0, sent: [], received: [] }
window.jassubNative.workers.push(this.observation)
this.addEventListener('message', ({ data }) => this.observation.received.push({ target: data.target, images: data.images?.length, width: data.width, height: data.height }))
}
postMessage(message, ...rest) {
this.observation.sent.push({ target: message.target, time: message.time, width: message.width, height: message.height, asyncRender: message.asyncRender })
return super.postMessage(message, ...rest)
}
terminate() {
this.observation.terminated++
return super.terminate()
}
}
window.createPlayer('/assets/sample/steve-jobs.mp4')
})
try {
await expect.poll(() => page.evaluate(() => window.art.duration)).toBeGreaterThan(30)
await page.locator('#play').click()
await expect.poll(() => page.evaluate(() => window.art.currentTime)).toBeGreaterThan(0.1)
await page.locator('#pause').click()
await page.evaluate(async ({ subContent, onDemandRender, customCanvas, defaultOffscreen, synchronousRender }) => {
const register = window.artplayerPluginJassub.default || window.artplayerPluginJassub
let canvas
if (customCanvas) {
canvas = document.createElement('canvas')
canvas.style.position = 'absolute'
canvas.style.pointerEvents = 'none'
canvas.style.zIndex = '20'
window.art.video.insertAdjacentElement('afterend', canvas)
window.jassubUserCanvas = canvas
}
window.art.plugins.add(register({
subContent,
workerUrl: '/assets/jassub/jassub-worker.js',
wasmUrl: '/assets/jassub/jassub-worker.wasm',
modernWasmUrl: '/assets/jassub/jassub-worker-modern.wasm',
availableFonts: { 'liberation sans': '/assets/jassub/default.woff2' },
fonts: ['/assets/jassub/default.woff2'],
...(defaultOffscreen ? {} : { offscreenRender: false }),
...(synchronousRender ? { asyncRender: false } : {}),
onDemandRender,
...(canvas ? { canvas } : {}),
}))
window.jassub = window.art.plugins.artplayerPluginJassub.instance
window.jassubNative.renderCalls = []
const render = window.jassub._render
window.jassub._render = function (message) {
window.jassubNative.renderCalls.push({ context: Boolean(this._ctx), images: message.images.length })
return render.call(this, message)
}
window.jassubNative.offscreen = { available: 'transferControlToOffscreen' in HTMLCanvasElement.prototype, selected: window.jassub._offscreenRender }
window.jassub.addEventListener('error', event => window.jassubNative.errors.push(String(event.error)))
await new Promise((resolve, reject) => {
window.jassub.addEventListener('ready', resolve, { once: true })
window.jassub.addEventListener('error', event => reject(event.error), { once: true })
})
const readback = document.createElement('canvas')
window.jassubGeometry = () => {
const canvas = window.jassub._canvas
const rect = canvas.getBoundingClientRect()
const video = window.art.video
const quality = video.getVideoPlaybackQuality?.()
return { width: canvas.width, height: canvas.height, cssWidth: rect.width, cssHeight: rect.height, clip: { x: rect.x, y: rect.y, width: rect.width, height: rect.height }, time: window.art.currentTime, connected: canvas.isConnected, media: { paused: video.paused, readyState: video.readyState, totalFrames: quality?.totalVideoFrames, droppedFrames: quality?.droppedVideoFrames, decodedFrames: video.webkitDecodedFrameCount, mozPresentedFrames: video.mozPresentedFrames }, onDemand: window.jassub._onDemandRender }
}
window.jassubPixels = (phase) => {
const canvas = window.jassub._canvas
readback.width = canvas.width
readback.height = canvas.height
const context = readback.getContext('2d')
context.drawImage(canvas, 0, 0)
const pixels = context.getImageData(0, 0, readback.width, readback.height).data
let visible = 0
let signature = 0
for (let i = 3; i < pixels.length; i += 4) {
if (pixels[i] > 0) {
visible++
signature = (signature + i * pixels[i]) >>> 0
}
}
const state = { phase, visible, signature, ...window.jassubGeometry() }
window.jassubNative.lastPixel = state
if (phase)
window.jassubNative.snapshots.push(state)
return state
}
}, { subContent: testedSubtitles, onDemandRender, customCanvas, defaultOffscreen, synchronousRender })
const offscreen = await page.evaluate(() => window.jassubNative.offscreen)
expect(offscreen.selected).toBe(defaultOffscreen && !customCanvas && offscreen.available)
await page.locator('#play').click()
await expect.poll(async () => (await pixels(page)).visible).toBeGreaterThan(100)
const before = await pixels(page, 'before-seek')
expect(before.connected).toBe(true)
if (screenshotReadback) {
expect(before.time).toBeLessThan(30)
expect(before.visible).toBeGreaterThan(100)
}
await page.locator('#pause').click()
await page.evaluate(async (seekTime) => {
const seeked = new Promise(resolve => window.art.video.addEventListener('seeked', resolve, { once: true }))
window.art.currentTime = seekTime
await seeked
}, seekTime)
await page.locator('#play').click()
await expect.poll(async () => (await pixels(page)).signature).not.toBe(before.signature)
await expect.poll(async () => (await pixels(page)).visible).toBeGreaterThan(100)
const after = await pixels(page, 'after-seek')
expect(after.time).toBeGreaterThanOrEqual(seekTime)
expect(after.signature).not.toBe(before.signature)
await page.evaluate(() => {
window.art.fullscreenWeb = true
})
await expect.poll(async () => (await pixels(page)).cssWidth).toBeGreaterThan(before.cssWidth)
await expect.poll(async () => (await pixels(page)).visible).toBeGreaterThan(100)
await pixels(page, 'fullscreen')
if (screenshotReadback) {
await expect.poll(() => page.evaluate(() => window.art.currentTime)).toBeGreaterThan(after.time + 0.2)
await page.evaluate(() => {
window.art.pause()
window.jassub._canvas.style.visibility = 'hidden'
})
const hidden = await pixels(page, 'hidden-negative-control')
expect(hidden.visible).toBe(0)
await page.evaluate(() => window.jassub._canvas.style.visibility = '')
await expect.poll(async () => (await pixels(page)).visible).toBeGreaterThan(100)
await pixels(page, 'restored')
}
await testInfo.attach('actual-jassub-page', { body: await page.screenshot(), contentType: 'image/png' })
if (artifact)
await page.evaluate(() => window.jassub.destroy())
await page.evaluate(() => window.art.destroy(false))
if (customCanvas)
expect(await page.evaluate(() => window.jassubUserCanvas.isConnected)).toBe(true)
expect(await page.evaluate(() => document.querySelectorAll('.JASSUB').length)).toBe(0)
expect(await page.evaluate(() => window.jassubNative.workers.map(worker => worker.terminated))).toEqual([1])
expect(await page.evaluate(() => window.jassubNative.errors)).toEqual([])
expect(external).toEqual([])
expect(resources.some(item => item.url.endsWith('.wasm') && item.status === 200 && item.contentType === 'application/wasm')).toBe(true)
expect(resources.some(item => item.url.endsWith('.woff2') && item.status === 200)).toBe(true)
}
return route.continue()
})
context.on('response', (response) => {
if (response.url().includes('/assets/jassub/'))
resources.push({ url: response.url(), status: response.status(), contentType: response.headers()['content-type'] })
})
await page.goto(`/test/player.html?core=${core}`)
await page.evaluate(() => {
window.jassubFramePlatform = { before: typeof HTMLVideoElement.prototype.requestVideoFrameCallback, registered: 0, delivered: 0 }
})
await page.addScriptTag({ content: code })
await page.evaluate(() => {
const frames = window.jassubFramePlatform
frames.after = typeof HTMLVideoElement.prototype.requestVideoFrameCallback
if (frames.after === 'function') {
const request = HTMLVideoElement.prototype.requestVideoFrameCallback
HTMLVideoElement.prototype.requestVideoFrameCallback = function (callback) {
frames.registered++
return request.call(this, function (...args) {
frames.delivered++
frames.lastMetadata = args[1]
return callback.apply(this, args)
finally {
const state = await page.evaluate(() => window.jassubNative).catch(error => ({ unavailable: error.message }))
state.readbackFrame = readbackFrame
state.synchronousRender = synchronousRender
state.screenshotReadback = screenshotReadback
const observation = screenshotReadback
? 'Composited page PNG decoded in Node; authored green ASS glyphs with hidden/restored negative control. No transferred-canvas copy.'
: 'Canvas pixels are read from a separate canvas copying the native display bitmap.'
await testInfo.attach('actual-jassub-evidence', { body: JSON.stringify({ core, onDemandRender, customCanvas, defaultOffscreen, source: provenance, subtitleSha256: hash(testedSubtitles), resources, external, state, limitation: `Actual worker, WASM and local font; offscreen option ${defaultOffscreen ? 'omitted, actual capability/selection recorded' : 'explicitly false'}. ${observation} No full failure recovery, sustained GPU/memory or physical-device acceptance; candidate adds direct-then-host destruction.` }, null, 2), contentType: 'application/json' })
if (!page.isClosed()) {
await page.evaluate(() => {
if (window.art && !window.art.isDestroy)
window.art.destroy()
})
}
}
window.jassubNative = { workers: [], snapshots: [], errors: [], frames }
const NativeWorker = window.Worker
window.Worker = class extends NativeWorker {
constructor(...args) {
super(...args)
this.observation = { url: String(args[0]), terminated: 0, sent: [], received: [] }
window.jassubNative.workers.push(this.observation)
this.addEventListener('message', ({ data }) => this.observation.received.push({ target: data.target, images: data.images?.length, width: data.width, height: data.height }))
}
postMessage(message, ...rest) {
this.observation.sent.push({ target: message.target, time: message.time, width: message.width, height: message.height, asyncRender: message.asyncRender })
return super.postMessage(message, ...rest)
}
terminate() {
this.observation.terminated++
return super.terminate()
}
}
window.createPlayer('/assets/sample/steve-jobs.mp4')
})
try {
await expect.poll(() => page.evaluate(() => window.art.duration)).toBeGreaterThan(30)
await page.locator('#play').click()
await expect.poll(() => page.evaluate(() => window.art.currentTime)).toBeGreaterThan(0.1)
await page.locator('#pause').click()
await page.evaluate(async ({ subContent, onDemandRender, customCanvas, defaultOffscreen, synchronousRender }) => {
const register = window.artplayerPluginJassub.default || window.artplayerPluginJassub
let canvas
if (customCanvas) {
canvas = document.createElement('canvas')
canvas.style.position = 'absolute'
canvas.style.pointerEvents = 'none'
canvas.style.zIndex = '20'
window.art.video.insertAdjacentElement('afterend', canvas)
window.jassubUserCanvas = canvas
}
window.art.plugins.add(register({
subContent,
workerUrl: '/assets/jassub/jassub-worker.js',
wasmUrl: '/assets/jassub/jassub-worker.wasm',
modernWasmUrl: '/assets/jassub/jassub-worker-modern.wasm',
availableFonts: { 'liberation sans': '/assets/jassub/default.woff2' },
fonts: ['/assets/jassub/default.woff2'],
...(defaultOffscreen ? {} : { offscreenRender: false }),
...(synchronousRender ? { asyncRender: false } : {}),
onDemandRender,
...(canvas ? { canvas } : {}),
}))
window.jassub = window.art.plugins.artplayerPluginJassub.instance
window.jassubNative.renderCalls = []
const render = window.jassub._render
window.jassub._render = function (message) {
window.jassubNative.renderCalls.push({ context: Boolean(this._ctx), images: message.images.length })
return render.call(this, message)
}
window.jassubNative.offscreen = { available: 'transferControlToOffscreen' in HTMLCanvasElement.prototype, selected: window.jassub._offscreenRender }
window.jassub.addEventListener('error', event => window.jassubNative.errors.push(String(event.error)))
await new Promise((resolve, reject) => {
window.jassub.addEventListener('ready', resolve, { once: true })
window.jassub.addEventListener('error', event => reject(event.error), { once: true })
})
const readback = document.createElement('canvas')
window.jassubGeometry = () => {
const canvas = window.jassub._canvas
const rect = canvas.getBoundingClientRect()
const video = window.art.video
const quality = video.getVideoPlaybackQuality?.()
return { width: canvas.width, height: canvas.height, cssWidth: rect.width, cssHeight: rect.height, clip: { x: rect.x, y: rect.y, width: rect.width, height: rect.height }, time: window.art.currentTime, connected: canvas.isConnected, media: { paused: video.paused, readyState: video.readyState, totalFrames: quality?.totalVideoFrames, droppedFrames: quality?.droppedVideoFrames, decodedFrames: video.webkitDecodedFrameCount, mozPresentedFrames: video.mozPresentedFrames }, onDemand: window.jassub._onDemandRender }
}
window.jassubPixels = (phase) => {
const canvas = window.jassub._canvas
readback.width = canvas.width
readback.height = canvas.height
const context = readback.getContext('2d')
context.drawImage(canvas, 0, 0)
const pixels = context.getImageData(0, 0, readback.width, readback.height).data
let visible = 0
let signature = 0
for (let i = 3; i < pixels.length; i += 4) {
if (pixels[i] > 0) {
visible++
signature = (signature + i * pixels[i]) >>> 0
}
}
const state = { phase, visible, signature, ...window.jassubGeometry() }
window.jassubNative.lastPixel = state
if (phase)
window.jassubNative.snapshots.push(state)
return state
}
}, { subContent: testedSubtitles, onDemandRender, customCanvas, defaultOffscreen, synchronousRender })
const offscreen = await page.evaluate(() => window.jassubNative.offscreen)
expect(offscreen.selected).toBe(defaultOffscreen && !customCanvas && offscreen.available)
await page.locator('#play').click()
await expect.poll(async () => (await pixels(page)).visible).toBeGreaterThan(100)
const before = await pixels(page, 'before-seek')
expect(before.connected).toBe(true)
if (screenshotReadback) {
expect(before.time).toBeLessThan(30)
expect(before.visible).toBeGreaterThan(100)
}
await page.locator('#pause').click()
await page.evaluate(async (seekTime) => {
const seeked = new Promise(resolve => window.art.video.addEventListener('seeked', resolve, { once: true }))
window.art.currentTime = seekTime
await seeked
}, seekTime)
await page.locator('#play').click()
await expect.poll(async () => (await pixels(page)).signature).not.toBe(before.signature)
await expect.poll(async () => (await pixels(page)).visible).toBeGreaterThan(100)
const after = await pixels(page, 'after-seek')
expect(after.time).toBeGreaterThanOrEqual(seekTime)
expect(after.signature).not.toBe(before.signature)
await page.evaluate(() => {
window.art.fullscreenWeb = true
})
await expect.poll(async () => (await pixels(page)).cssWidth).toBeGreaterThan(before.cssWidth)
await expect.poll(async () => (await pixels(page)).visible).toBeGreaterThan(100)
await pixels(page, 'fullscreen')
if (screenshotReadback) {
await expect.poll(() => page.evaluate(() => window.art.currentTime)).toBeGreaterThan(after.time + 0.2)
await page.evaluate(() => {
window.art.pause()
window.jassub._canvas.style.visibility = 'hidden'
})
const hidden = await pixels(page, 'hidden-negative-control')
expect(hidden.visible).toBe(0)
await page.evaluate(() => window.jassub._canvas.style.visibility = '')
await expect.poll(async () => (await pixels(page)).visible).toBeGreaterThan(100)
await pixels(page, 'restored')
}
await testInfo.attach('actual-jassub-page', { body: await page.screenshot(), contentType: 'image/png' })
if (artifact)
await page.evaluate(() => window.jassub.destroy())
await page.evaluate(() => window.art.destroy(false))
if (customCanvas)
expect(await page.evaluate(() => window.jassubUserCanvas.isConnected)).toBe(true)
expect(await page.evaluate(() => document.querySelectorAll('.JASSUB').length)).toBe(0)
expect(await page.evaluate(() => window.jassubNative.workers.map(worker => worker.terminated))).toEqual([1])
expect(await page.evaluate(() => window.jassubNative.errors)).toEqual([])
expect(external).toEqual([])
expect(resources.some(item => item.url.endsWith('.wasm') && item.status === 200 && item.contentType === 'application/wasm')).toBe(true)
expect(resources.some(item => item.url.endsWith('.woff2') && item.status === 200)).toBe(true)
}
finally {
const state = await page.evaluate(() => window.jassubNative).catch(error => ({ unavailable: error.message }))
state.readbackFrame = readbackFrame
state.synchronousRender = synchronousRender
state.screenshotReadback = screenshotReadback
const observation = screenshotReadback
? 'Composited page PNG decoded in Node; authored green ASS glyphs with hidden/restored negative control. No transferred-canvas copy.'
: 'Canvas pixels are read from a separate canvas copying the native display bitmap.'
await testInfo.attach('actual-jassub-evidence', { body: JSON.stringify({ core, onDemandRender, customCanvas, defaultOffscreen, source: artifact ? { artifact, sha256: hash(code) } : { version: release.version, integrity: release.integrity, member, sha256: hash(code) }, subtitleSha256: hash(testedSubtitles), resources, external, state, limitation: `Actual worker, WASM and local font; offscreen option ${defaultOffscreen ? 'omitted, actual capability/selection recorded' : 'explicitly false'}. ${observation} No full failure recovery, sustained GPU/memory or physical-device acceptance; candidate adds direct-then-host destruction.` }, null, 2), contentType: 'application/json' })
if (!page.isClosed()) {
await page.evaluate(() => {
if (window.art && !window.art.isDestroy)
window.art.destroy()
})
}
}
})
}
}
+8 -4
View File
@@ -1,10 +1,14 @@
import fs from 'node:fs'
import process from 'node:process'
import { hash } from '../../refactor/scripts/releases.mjs'
import { browserCandidate } from '../helpers/browser-candidate.js'
import { expect, test } from './fixtures.js'
const artifact = process.env.ARTPLAYER_JASSUB_ARTIFACT || 'packages/artplayer-plugin-jassub/dist/artplayer-plugin-jassub.js'
const code = fs.readFileSync(artifact, 'utf8')
const { code, provenance } = await browserCandidate('artplayer-plugin-jassub', process.env.ARTPLAYER_JASSUB_ARTIFACT)
const artifact = provenance.file || 'source-build'
test.beforeEach(async ({ browserName }, testInfo) => {
await testInfo.attach('jassub-selected-input', { contentType: 'application/json', body: JSON.stringify({ browserName, provenance }) })
})
const subtitle = `[Script Info]
ScriptType: v4.00+
PlayResX: 640
@@ -76,7 +80,7 @@ test('JASSUB closes the entire bitmap batch after a native draw failure and rend
probe.holding = false
return { before, after, failure, asyncRender: event.data.asyncRender }
})
await testInfo.attach('bitmap-failure', { contentType: 'application/json', body: JSON.stringify({ artifact, sha256: hash(code), evidence, limitation: 'Actual JASSUB Worker/WASM bitmap, plus two native bitmap copies. Deliberately closing the first bitmap injects a native draw error; this does not claim spontaneous Worker corruption or Firefox offscreen recovery.' }) })
await testInfo.attach('bitmap-failure', { contentType: 'application/json', body: JSON.stringify({ artifact, provenance, sha256: hash(code), evidence, limitation: 'Actual JASSUB Worker/WASM bitmap, plus two native bitmap copies. Deliberately closing the first bitmap injects a native draw error; this does not claim spontaneous Worker corruption or Firefox offscreen recovery.' }) })
expect(evidence.before.every(width => width > 0)).toBe(true)
expect(evidence.asyncRender).toBe(true)
expect(evidence.failure?.name).toBe('InvalidStateError')
+5
View File
@@ -11,6 +11,7 @@ import { ensureArchive, hash, readMember } from '../../refactor/scripts/releases
import { performanceHtml, performanceScript } from '../../scripts/performance-fixture.mjs'
import { getEntryFile } from '../../scripts/projects.js'
import { getGlobalName, getViteBuildConfig } from '../../scripts/utils.js'
import { jassubAssets } from '../helpers/jassub-assets.js'
import { skippableVast } from './vast-fixture.mjs'
const workspace = fileURLToPath(new URL('../../', import.meta.url))
@@ -28,6 +29,10 @@ function add(route, bytes, source) {
// An explicit artifact map takes precedence over source builds and never falls back.
const mapFile = process.env.ARTPLAYER_BROWSER_ARTIFACTS
const overrides = mapFile ? JSON.parse(fs.readFileSync(mapFile, 'utf8')) : {}
if (Object.hasOwn(overrides, 'artplayer-plugin-jassub')) {
for (const resource of jassubAssets(workspace, mapFile))
add(resource.route, resource.bytes, resource.source)
}
for (const name of ['artplayer', 'artplayer-plugin-chapter']) {
const route = `/candidate/${name}.js`
if (mapFile) {
+27
View File
@@ -0,0 +1,27 @@
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { hash } from '../../refactor/scripts/releases.mjs'
import { verifyInstalledArtifacts } from '../../scripts/installed-artifacts.mjs'
export function jassubAssets(root, mapFile) {
const name = 'artplayer-plugin-jassub'
const baseline = JSON.parse(fs.readFileSync(path.join(root, 'refactor/baselines/jassub-release.json'), 'utf8'))
const installed = mapFile ? verifyInstalledArtifacts(root, mapFile, ['artplayer', 'artplayer-plugin-chapter', name]) : null
const input = installed?.inputs.find(item => item.name === name)
const pkg = installed?.packages.find(item => item.name === name)
return ['jassub-worker.js', 'jassub-worker.wasm', 'jassub-worker-modern.wasm', 'default.woff2'].map((filename) => {
const worker = filename !== 'default.woff2'
const relative = worker ? `packages/${name}/worker/${filename}` : `docs/assets/jassub/${filename}`
const expected = baseline.assets.find(item => item.file === relative)
assert(expected, `Missing JASSUB resource baseline: ${relative}`)
const member = `package/worker/${filename}`
const file = input && worker ? path.resolve(path.dirname(input.file), '../worker', filename) : path.join(root, relative)
const bytes = fs.readFileSync(file)
const sha256 = hash(bytes)
assert.equal(sha256, expected.sha256, `JASSUB resource differs from baseline: ${relative}`)
if (input && worker)
assert.equal(sha256, pkg.files[member], `Installed JASSUB resource differs from archive: ${member}`)
return { route: `/assets/jassub/${filename}`, bytes, source: { kind: input && worker ? 'installed-resource' : 'local-resource', file, sha256, baseline: relative, member: input && worker ? member : null, archiveSha256: input && worker ? input.archiveSha256 : null } }
})
}
+1 -1
View File
@@ -61,7 +61,7 @@ test('Explicit installed plugin maps never fall back to source or frozen workspa
delete process.env.ARTPLAYER_AUTO_THUMBNAIL_BASELINE
process.env.ARTPLAYER_AUTO_THUMBNAIL_ARTIFACT = 'override.js'
await assert.rejects(autoThumbnailCandidate(), /cannot override artplayer-plugin-auto-thumbnail artifact/)
for (const name of ['artplayer-plugin-hls-control', 'artplayer-plugin-dash-control', 'artplayer-plugin-asr', 'artplayer-plugin-chromecast']) {
for (const name of ['artplayer-plugin-hls-control', 'artplayer-plugin-dash-control', 'artplayer-plugin-asr', 'artplayer-plugin-chromecast', 'artplayer-plugin-jassub']) {
await assert.rejects(browserCandidate(name), { code: 'ENOENT' })
await assert.rejects(browserCandidate(name, 'override.js'), new RegExp(`cannot override ${name} artifact`))
}
+41 -2
View File
@@ -1,4 +1,5 @@
import assert from 'node:assert/strict'
import { Buffer } from 'node:buffer'
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
@@ -10,6 +11,7 @@ import { verifyInstalledArtifacts } from '../scripts/installed-artifacts.mjs'
import { verifyPerformanceArtifacts } from '../scripts/performance-artifacts.mjs'
import { performanceHtml, performanceScript, waitForObservation } from '../scripts/performance-fixture.mjs'
import { validatePairedPerformance } from '../scripts/performance-report.mjs'
import { jassubAssets } from './helpers/jassub-assets.js'
const baseline = JSON.parse(fs.readFileSync(new URL('../refactor/baselines/performance.json', import.meta.url), 'utf8')).runs[0]
function fixture() {
@@ -129,7 +131,7 @@ test('performance refuses stale sources, build tools and altered installed bundl
write(path.join(root, file), content)
write(path.join(snapshot, file), content)
}
const names = ['artplayer', 'artplayer-plugin-chapter', 'artplayer-plugin-ambilight']
const names = ['artplayer', 'artplayer-plugin-chapter', 'artplayer-plugin-ambilight', 'artplayer-plugin-jassub']
const packages = names.map((name) => {
const entry = `packages/${name}/src/index.ts`
write(path.join(root, entry), 'export default 1\n')
@@ -142,11 +144,48 @@ test('performance refuses stale sources, build tools and altered installed bundl
return { name, sha256: 'archive fixture', files: { [`package/dist/${name}.js`]: hash(bytes) } }
})
const map = path.join(output, 'browser-artifacts.json')
const jassub = packages.find(pkg => pkg.name === 'artplayer-plugin-jassub')
const assets = ['jassub-worker.js', 'jassub-worker.wasm', 'jassub-worker-modern.wasm', 'default.woff2'].map((name) => {
const worker = name !== 'default.woff2'
const file = worker ? `packages/artplayer-plugin-jassub/worker/${name}` : `docs/assets/jassub/${name}`
const bytes = Buffer.from(`fixture ${name}`)
write(path.join(root, file), bytes)
if (worker) {
write(path.join(snapshot, file), bytes)
write(path.join(output, `artifacts/artplayer-plugin-jassub/worker/${name}`), bytes)
jassub.files[`package/worker/${name}`] = hash(bytes)
}
return { file, sha256: hash(bytes) }
})
write(path.join(root, 'refactor/baselines/jassub-release.json'), JSON.stringify({ assets }))
write(map, JSON.stringify(Object.fromEntries(names.map(name => [name, `artifacts/${name}/dist/${name}.js`]))))
write(path.join(output, 'report.json'), JSON.stringify({ task: 'ENG-07', knownTypeBlockers: 0, node: process.versions.node, packages }))
assert.equal(verifyPerformanceArtifacts(root, map).inputs.length, 2)
assert.equal(verifyPerformanceArtifacts(root, map).packages.length, 2)
assert.equal(verifyInstalledArtifacts(root, map, names).inputs.length, 3)
assert.equal(verifyInstalledArtifacts(root, map, names).inputs.length, 4)
assert.deepEqual(jassubAssets(root, map).map(item => item.source.kind), ['installed-resource', 'installed-resource', 'installed-resource', 'local-resource'])
assert(jassubAssets(root).every(item => item.source.kind === 'local-resource'))
const worker = path.join(root, assets[0].file)
const originalWorker = fs.readFileSync(worker)
write(worker, 'stale worker')
assert.throws(() => jassubAssets(root, map), /Stale package source/)
write(worker, originalWorker)
const installedWorker = path.join(output, 'artifacts/artplayer-plugin-jassub/worker/jassub-worker.js')
write(installedWorker, 'tampered installed worker')
assert.throws(() => jassubAssets(root, map), /resource differs from baseline/)
write(installedWorker, originalWorker)
const reportFile = path.join(output, 'report.json')
const originalReport = fs.readFileSync(reportFile)
const missingMember = JSON.parse(originalReport)
delete missingMember.packages.find(pkg => pkg.name === 'artplayer-plugin-jassub').files['package/worker/jassub-worker.js']
write(reportFile, JSON.stringify(missingMember))
assert.throws(() => jassubAssets(root, map), /resource differs from archive/)
write(reportFile, originalReport)
const font = path.join(root, assets[3].file)
const originalFont = fs.readFileSync(font)
write(font, 'wrong font')
assert.throws(() => jassubAssets(root, map), /resource differs from baseline/)
write(font, originalFont)
assert.throws(() => verifyInstalledArtifacts(root, map, [...names, 'artplayer-proxy-canvas']), /Missing installed package/)
const pluginSource = path.join(root, 'packages/artplayer-plugin-ambilight/src/index.ts')
write(pluginSource, 'export default 2\n')