gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitcc68a063cc68a063jukebox JB13 (jukebox#13): a tapped song plays the song that was tapped, found by its id in the list as it is now (not by its row number, which counted plays move); the queue goes on from its place there, the rows refresh on the tap; gate tests/jb13.mjs (songs by plays, favourites)mrecc68a063/tests/jb13.mjs

7.7 KB

  1. // tests/jb13.mjs — JB13 (jukebox#13): a tapped song must be the song that plays, even when counted plays changed the server's order
  2. // while the rows on the screen stayed where they were. Own server on a generated database of 300 songs (one 3 s tone), headless Chrome.
  3. // Songs sorted by plays and Favourites: the screen is open, a play is counted for another song through POST /api/played/<id> (the order
  4. // changes), then a row is tapped: the song that plays (currentSrc of the audio element) must be the tapped row's id. The queue goes on
  5. // from that song's place in the new order, and the rows on the screen refresh to what the server now has.
  6. // node tests/jb13.mjs env: JB13_PORT (default 8735), JB13_DIR (scratch), JB13_ROOT (checkout to test), HL_PORT_BASE (default 8520), JUKEBOX_COLD_MS
  7. import { spawn, execFileSync } from 'node:child_process'
  8. import { rmSync, mkdirSync } from 'node:fs'
  9. import { dirname, join } from 'node:path'
  10. import { fileURLToPath } from 'node:url'
  11. process.env.HL_CHROME = process.env.HL_CHROME || '/opt/google/chrome/chrome'
  12. process.env.HL_PORT_BASE = process.env.HL_PORT_BASE || '8520'
  13. const { launchBrowser, sleep } = await import('./cdp.mjs')
  14. const root = process.env.JB13_ROOT || join(dirname(fileURLToPath(import.meta.url)), '..')
  15. const dir = process.env.JB13_DIR || '/media/STORAGE/claude-scratch/atlas/JB13/gate'
  16. const port = Number(process.env.JB13_PORT || 8735)
  17. const BASE = `http://127.0.0.1:${port}`
  18. const COLD_MS = Number(process.env.JUKEBOX_COLD_MS || 150000)
  19. let pass = 0, fail = 0
  20. const check = (name, ok, detail = '') => { console.log((ok ? 'ok ' : 'FAIL ') + name + (ok ? '' : ' — ' + detail)); if (ok) pass++; else fail++ }
  21. mkdirSync(dir, { recursive: true })
  22. process.env.TMPDIR = dir
  23. let server = null, browser = null, log = ''
  24. async function stop() {
  25. if (browser) { try { await browser.close() } catch {} browser = null }
  26. if (server) { try { server.kill('SIGTERM') } catch {} await sleep(500); server = null }
  27. }
  28. process.on('SIGINT', async () => { await stop(); process.exit(1) })
  29. const storage = join(dir, 'storage')
  30. const tone = join(dir, 'tone3.mp3')
  31. rmSync(storage, { recursive: true, force: true })
  32. execFileSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=3', '-q:a', '9', tone])
  33. const cover = join(root, 'tests/fixtures/withcover/folder.jpg')
  34. execFileSync(join(root, 'bin/hybriel'), [join(root, 'tools/make-test-db.hl'), tone, cover, '300'], { env: { ...process.env, JUKEBOX_STORAGE: storage }, encoding: 'utf8', timeout: 600000 })
  35. server = spawn(join(root, 'bin/hybriel'), ['project.hl'], { cwd: root, env: { ...process.env, JUKEBOX_PORT: String(port), JUKEBOX_STORAGE: storage, JUKEBOX_AUTOSCAN: '0', JUKEBOX_WATCH: '0', HL_HOST: '127.0.0.1' }, stdio: ['ignore', 'pipe', 'pipe'] })
  36. console.log('server pid ' + server.pid)
  37. server.stdout.on('data', (d) => { log += d }); server.stderr.on('data', (d) => { log += d })
  38. const api = async (path, method = 'GET') => (await fetch(BASE + path, { method })).json()
  39. const play = async (id, n = 1) => { for (let i = 0; i < n; i++) await api('/api/played/' + id, 'POST') }
  40. try {
  41. for (const t0 = Date.now(); ; ) {
  42. try { if ((await fetch(BASE + '/api/stats')).ok) break } catch {}
  43. if (Date.now() - t0 > COLD_MS) { console.log(log); throw new Error('the server did not come up') }
  44. await sleep(500)
  45. }
  46. browser = await launchBrowser()
  47. console.log('chrome pid ' + browser.proc?.pid)
  48. const page = await browser.newPage()
  49. const ev = (e) => page.evaluate(e)
  50. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true })
  51. const byArtist = (await api('/api/songs?sort=artist&limit=200')).items
  52. // three songs that are favourites already (5 plays), far down the artist order
  53. for (const s of byArtist.slice(100, 103)) await play(s.id, 5)
  54. const rowIds = () => ev(`[...document.querySelectorAll('virtual-list .vl-row:not(.blank)')].map((r) => r.getAttribute('data-id'))`)
  55. const playing = () => ev(`(() => { const a = document.querySelector('media-player audio'); return a && a.currentSrc ? a.currentSrc.split('/stream/')[1] : '' })()`)
  56. const tapAndRead = async (index) => {
  57. await page.click(`virtual-list .vl-row[data-index="${index}"]`)
  58. await page.waitFor(`(() => { const a = document.querySelector('media-player audio'); return a && a.currentSrc.indexOf('/stream/') > 0 })()`, { timeout: 20000, label: 'a song plays' })
  59. await sleep(800)
  60. return playing()
  61. }
  62. // ---- Songs, most played ----
  63. await page.goto(BASE + '/')
  64. await page.waitForSelector('virtual-list .vl-row:not(.blank)')
  65. const press = async (key, code, vk) => { await page.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key, code, windowsVirtualKeyCode: vk }); await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key, code, windowsVirtualKeyCode: vk }) }
  66. await page.focus('#sort')
  67. for (let i = 0; i < 3; i++) { await press('ArrowDown', 'ArrowDown', 40); await sleep(300) }
  68. await page.waitFor(`document.querySelector('virtual-list .vl-row .vl-aside') && /×/.test(document.querySelector('virtual-list .vl-row .vl-aside').textContent)`, { label: 'sorted by plays' })
  69. await sleep(500)
  70. const before = await rowIds()
  71. const tapped = before[6], other = before[9]
  72. await play(other) // the order on the server changes: `other` jumps up, the rows above it move down one place
  73. const after = (await api('/api/songs?sort=plays&limit=40')).items.map((s) => s.id)
  74. check('setup: counting a play changed the server order at the tapped place', after[6] !== tapped, 'row 6 is still ' + tapped)
  75. const got = await tapAndRead(6)
  76. check('Songs by plays: the song that plays is the tapped row (not the song that moved into its place)', got === tapped, `tapped ${tapped}, plays ${got}, server row 6 now ${after[6]}`)
  77. const at = after.indexOf(tapped)
  78. const next = (await api('/api/songs?sort=plays&limit=40')).items[at + 1]
  79. const q = await ev(`[...document.querySelectorAll('.jb-bar ol.mp-queue li .mp-q-title')].map((e) => e.textContent)`)
  80. check('Songs by plays: the queue goes on from the tapped song\'s place in the current order', q.length > 1 && !!next && q.includes(next.title) && q.indexOf(next.title) <= 1, JSON.stringify({ next: next && next.title, q: q.slice(0, 3) }))
  81. await page.waitFor(`(() => { const a = [...document.querySelectorAll('virtual-list .vl-row:not(.blank)')].map((r) => r.getAttribute('data-id')); return a.length > 8 && a[0] === ${JSON.stringify(after[0])} && a[5] === ${JSON.stringify(after[5])} && a[6] === ${JSON.stringify(after[6])} })()`, { timeout: 8000, label: 'rows refreshed' }).then(() => check('Songs by plays: the rows on the screen show the server\'s order after the tap', true), (e) => check('Songs by plays: the rows on the screen show the server\'s order after the tap', false, 'rows ' + JSON.stringify([]) ))
  82. // ---- Favourites ----
  83. await page.goto(BASE + '/')
  84. await page.waitForSelector('virtual-list .vl-row:not(.blank)')
  85. await page.click('#fav')
  86. await page.waitFor(`document.querySelector('#favmin') && document.querySelectorAll('virtual-list .vl-row:not(.blank)').length >= 3`, { label: 'favourites list' })
  87. await sleep(500)
  88. const fbefore = await rowIds()
  89. const ftapped = fbefore[1]
  90. await play(byArtist[0].id, 5) // a new favourite that sorts first: every row moves down one place
  91. const fafter = (await api('/api/songs?sort=artist&minPlays=5&limit=40')).items.map((s) => s.id)
  92. check('setup: a new favourite changed the order at the tapped place', fafter[1] !== ftapped, 'row 1 is still ' + ftapped)
  93. const fgot = await tapAndRead(1)
  94. check('Favourites: the song that plays is the tapped row', fgot === ftapped, `tapped ${ftapped}, plays ${fgot}, server row 1 now ${fafter[1]}`)
  95. } finally {
  96. await stop()
  97. }
  98. console.log(`${pass} passed, ${fail} failed`)
  99. process.exit(fail ? 1 : 0)

Branches

Latest commits

  • cc68a063jukebox JB13 (jukebox#13): a tapped song plays the song that was tapped, found by its id in the list as it is now (not by its row number, which counted plays move); the queue goes on from its place there, the rows refresh on the tap; gate tests/jb13.mjs (songs by plays, favourites)mre
  • 88d3d5c1jukebox JB12b (jukebox#12): the scroll handle is big (2.75rem x 4rem, accent colour, grip) and drawn on every device, no media query; native bar hidden; gate tests/touch.mjs checks the drawn width with and without touchmre
  • b58e4495jukebox JB11 (jukebox#11): the next song starts in the ended event on the same audio element, so it also starts with the screen locked; gate tests/jb11.mjs (hidden tab, no frames)mre
  • 12a26233jukebox JB12 (jukebox#12): the long lists get a scroll handle a finger can use on touch screens (44 px tap area, slim look, drag through all rows), gate tests/touch.mjsmre
  • 0f2157a9jukebox JV1: onto Hybriel set-day27b: readBytes and stat for /stream and the mp3 tags (no dd, head or tail), startup fault exits 1, fs and mpackdb plugins re-vendored; songs with a comma in the title are indexed againmre
  • 63d0f2eejukebox ST1 (jukebox#2): styles of main, songs and search moved into their own Style blocks (styles.hl 81 to 8 rules, pixel-identical at 390 and 1280); artist and album wait for an hl:web fixmre
  • c5b8fde9jukebox JB3b: keyboard gap repro as a reportmre
  • 9daebb4bjukebox JB3b: shuffle, now-playing overlay, next and previous, play counting, media session, gates; keyboard left open (Hybriel gap)mre
  • 59c1373ejukebox JB3 (work in progress): albums without folder and with disc markers folded, compilations, duplicate songs, own play counter, server-side shuffle queuemre
  • 2a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre
  • 93a44212jukebox: report, numbers of the full scan, notes on the index key rulemre
  • bf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmre
  • 28a82fa2jukebox: README, STATUS, LOG, DECISIONSmre
  • d13987dfjukebox: library scanner, ID3 reader, mpackdb database and JSON API, with fixtures and a gatemre