Files
music/web/lyrics.test.ts
T
Claude Opus 5 6e07da7a36 music, extracted from the platform into its own repository
Everything the plugin is, moved out of officerdev/platform on 2026-08-15 —
41 files, unchanged from the tree they left.

  manifest.ts   identity, one permission, ffmpeg/ffprobe declared
  api/          the sidecar proxy; the prefix comes from mountPrefix()
  sidecar/      the whole /api/music contract — indexing, streaming, per-user state
  db/           music_favorites, _playlists, _playlist_items, _now_playing
  web/          panels, layout, and the player: engine, bar, lyrics, favourites
  cliamp/       the second playback path, parked — not working, kept deliberately
  widgets/      the dashboard widget, parked — plugins cannot contribute widgets
  assets/       icon.png, the dock tile
  scripts/      the reindex CLI

PLUGIN.md is the design record: what moved, what stayed, what broke, and why.
MUSIC_API.md is the contract the phone and tablet apps speak, and the reason
the sidecar's HTTP shape is not free to change.

── It does not build here, and that is the point ──

The platform resolves `hooks/useClient`, `officerdev`, `officerdb/db` and `@@/*`
through the workspace links in its own node_modules. Measured from this
directory, outside the platform checkout, every one of them fails to resolve —
7 imports in the backend, ~29 in the frontend.

So this repository is the source of truth, not yet a buildable unit. Making it
one means the host API becoming something a plugin can depend on rather than
something it reaches into. That is the next problem, and having the code here
is what makes it unavoidable rather than theoretical.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 17:34:51 +00:00

74 lines
2.5 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import { parseLyrics, activeLineIndex } from './lyrics';
describe('parseLyrics', () => {
test('plain text is not synced and keeps every line, blanks included', () => {
const { synced, lines } = parseLyrics('first\n\n second \n');
expect(synced).toBe(false);
expect(lines.map((l) => l.text)).toEqual(['first', '', 'second', '']);
expect(lines.every((l) => l.timeSec === undefined)).toBe(true);
});
test('lrc timestamps parse to seconds, with hundredths', () => {
const { synced, lines } = parseLyrics('[00:12.50]hello\n[01:03]world');
expect(synced).toBe(true);
expect(lines).toEqual([
{ timeSec: 12.5, text: 'hello' },
{ timeSec: 63, text: 'world' },
]);
});
test('a single-digit fraction is tenths, not thousandths', () => {
expect(parseLyrics('[00:01.5]x').lines[0]?.timeSec).toBe(1.5);
});
test('metadata tags are dropped', () => {
const { lines } = parseLyrics('[ar:Artist]\n[ti:Title]\n[00:01.00]real');
expect(lines).toEqual([{ timeSec: 1, text: 'real' }]);
});
test('several stamps on one line become several lines, sorted by time', () => {
const { lines } = parseLyrics('[02:00.00][00:30.00]chorus\n[01:00.00]verse');
expect(lines).toEqual([
{ timeSec: 30, text: 'chorus' },
{ timeSec: 60, text: 'verse' },
{ timeSec: 120, text: 'chorus' },
]);
});
test('an untimed line inside a synced file survives, but blanks do not', () => {
const { lines } = parseLyrics('[00:01.00]a\n\nspoken\n');
expect(lines.map((l) => l.text)).toEqual(['spoken', 'a']);
});
test('an empty timed line is kept — it is a musical rest', () => {
expect(parseLyrics('[00:10.00]').lines).toEqual([{ timeSec: 10, text: '' }]);
});
});
describe('activeLineIndex', () => {
const lines = [
{ timeSec: 10, text: 'a' },
{ timeSec: 20, text: 'b' },
{ timeSec: 30, text: 'c' },
];
test('-1 before the first line', () => {
expect(activeLineIndex(lines, 0)).toBe(-1);
});
test('the 0.2s lookahead highlights fractionally early', () => {
expect(activeLineIndex(lines, 9.7)).toBe(-1);
expect(activeLineIndex(lines, 9.9)).toBe(0);
});
test('holds the last line past the end', () => {
expect(activeLineIndex(lines, 25)).toBe(1);
expect(activeLineIndex(lines, 9999)).toBe(2);
});
test('untimed lines never become active', () => {
expect(activeLineIndex([{ text: 'x' }, { timeSec: 5, text: 'y' }], 60)).toBe(1);
});
});