Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | 11x 136x 136x 136x 136x 136x 136x 5x 12x 12x 12x 12x 12x 12x 25346x 25346x 12x 7345x 7345x 7345x 7345x 7345x 7345x 7345x 7x 12x 12x 18001x 18001x 11x 11x 18x 18x 18x 18x 18x 14x 18x 18x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 11x 76x 76x 76x 76x 76x 144x 125x 76x 144x 2x 2x 2x 4x 4x 2x 2x 2x 2x 5x 5x 5x 32x 10x 32x 5x 5x 5x 5x 2x 2x 2x 2x 5x 3546x 3630085x 1x 3545x | import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { createEmptyJSON } from '../../../chart-source/src/index.ts';
import { vi } from 'vite-plus/test';
import type { CreatePlayerUIRuntimeContext } from '../index.ts';
import { getEngineScheduler } from '../core/engine-clock.ts';
import type { PlayerInputCommand } from '../core/input-signal-bus.ts';
import type { PlayerUICommand } from '../core/ui-signal-bus.ts';
/**
* Shared set-up of the player engine's tests (`*.test.ts` next to `index.ts`): a mocked Node audio sink whose clock
* follows `performance.now()` and which records every write, and the small charts and input scripts the tests play.
* Each test file mocks the Node adapter's `audio-sink.ts` with {@link mockAudioSinkModule} and calls {@link resetAudioSinkState} before
* each test; the state lives here, so the mock and the tests see the same object.
*/
/** What the mocked audio sink has been written, and its clock. */
export const audioSinkState = {
writes: [] as Uint8Array[],
startMs: 0,
pausedAtMs: 0,
pausedDurationMs: 0,
paused: false,
scheduledSeconds: 0,
};
/** Clears the mocked sink's writes and clock; call before each test. */
export function resetAudioSinkState(): void {
audioSinkState.writes = [];
audioSinkState.startMs = 0;
audioSinkState.pausedAtMs = 0;
audioSinkState.pausedDurationMs = 0;
audioSinkState.paused = false;
audioSinkState.scheduledSeconds = 0;
}
/** The module the mocked Node adapter sink hands the engine: a Node sink that plays nothing and keeps time. */
export function mockAudioSinkModule() {
return {
createNodeAudioSink: vi.fn(async (options: { sampleRate: number; channels: number }) => {
audioSinkState.startMs = performance.now();
audioSinkState.pausedAtMs = 0;
audioSinkState.pausedDurationMs = 0;
audioSinkState.paused = false;
audioSinkState.scheduledSeconds = 0;
const resolveOutputSeconds = (): number => {
const referenceMs = audioSinkState.paused ? audioSinkState.pausedAtMs : performance.now();
return Math.max(0, (referenceMs - audioSinkState.startMs - audioSinkState.pausedDurationMs) / 1000);
};
return {
runtime: 'node',
engine: 'webaudio',
label: 'mock-audio',
write: (chunk: Uint8Array) => {
audioSinkState.writes.push(Uint8Array.from(chunk));
const bytesPerFrame = Math.max(2, options.channels * 2);
const frameCount = Math.floor(chunk.byteLength / bytesPerFrame);
Eif (frameCount > 0) {
const outputSeconds = resolveOutputSeconds();
audioSinkState.scheduledSeconds =
Math.max(outputSeconds, audioSinkState.scheduledSeconds) + frameCount / options.sampleRate;
}
return true;
},
waitWritable: async () => undefined,
end: async () => undefined,
destroy: () => undefined,
onError: () => undefined,
getClockState: () => {
const outputSeconds = resolveOutputSeconds();
return {
outputSeconds,
scheduledSeconds: Math.max(outputSeconds, audioSinkState.scheduledSeconds),
};
},
suspend: async () => {
if (audioSinkState.paused) {
return;
}
audioSinkState.paused = true;
audioSinkState.pausedAtMs = performance.now();
},
resume: async () => {
if (!audioSinkState.paused) {
return;
}
audioSinkState.pausedDurationMs += Math.max(0, performance.now() - audioSinkState.pausedAtMs);
audioSinkState.paused = false;
audioSinkState.pausedAtMs = 0;
},
};
}),
};
}
export const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), '../../../..');
export const unifiedBMSChartPath = resolve(rootDir, 'test/fixtures/four-measure-command-combo-test.bms');
export function createLNOBJLongNoteChart(lnMode?: 1 | 2 | 3) {
const json = createEmptyJSON('bms');
json.metadata.bpm = 480;
json.bms.lnObjs = ['AA'];
json.resources.wav['01'] = 'ln.wav';
if (lnMode) {
json.bms.lnMode = lnMode;
}
json.events = [
{ measure: 1, channel: '11', position: [0, 1] as const, value: '01' },
{ measure: 3, channel: '11', position: [0, 1] as const, value: 'AA' },
];
return json;
}
export function createScratchLNOBJLongNoteChart() {
const json = createEmptyJSON('bms');
json.metadata.bpm = 480;
json.bms.lnObjs = ['AA'];
json.events = [
{ measure: 1, channel: '16', position: [0, 1] as const, value: '01' },
{ measure: 3, channel: '16', position: [0, 1] as const, value: 'AA' },
];
return json;
}
export function createDynamicExRankChart() {
const json = createEmptyJSON('bms');
json.metadata.bpm = 480;
json.metadata.rank = 2;
json.bms.exRank['AA'] = '48';
json.bms.exRank['CC'] = '100';
json.events = [
{ measure: 0, channel: 'A0', position: [0, 1] as const, value: 'AA' },
{ measure: 1, channel: '11', position: [0, 1] as const, value: '01' },
{ measure: 2, channel: 'A0', position: [0, 1] as const, value: 'CC' },
{ measure: 3, channel: '11', position: [0, 1] as const, value: '02' },
];
return json;
}
export function createInvisibleOnlyChart(channel = '31') {
const json = createEmptyJSON('bms');
json.metadata.bpm = 120;
json.resources.wav['01'] = 'not-found.wav';
json.events = [{ measure: 0, channel, position: [0, 1] as const, value: '01' }];
return json;
}
export function createPlayableOnlyChart() {
const json = createEmptyJSON('bms');
json.metadata.bpm = 120;
json.resources.wav['01'] = 'not-found.wav';
json.events = [{ measure: 0, channel: '11', position: [0, 1] as const, value: '01' }];
return json;
}
export function createBGMOnlyChart() {
const json = createEmptyJSON('bms');
json.metadata.bpm = 120;
json.resources.wav['01'] = 'not-found.wav';
json.events = [{ measure: 0, channel: '01', position: [0, 1] as const, value: '01' }];
return json;
}
export function createTimelineLoggingChart() {
const json = createEmptyJSON('bms');
json.metadata.bpm = 120;
json.measures.push({ index: 1, length: 0.5 });
json.resources.wav['01'] = 'not-found.wav';
json.resources.bmp['00'] = 'fallback.png';
json.resources.bmp['01'] = 'base.png';
json.resources.bmp['02'] = 'poor.png';
json.resources.bmp['03'] = 'layer.png';
json.resources.bmp['04'] = 'layer2.png';
json.resources.bpm['01'] = 180;
json.resources.stop['01'] = 192;
json.bms.scroll['01'] = 0.5;
json.bms.speed['01'] = 1.5;
json.bms.exRank['01'] = '48';
json.events = [
{ measure: 0, channel: '04', position: [0, 1] as const, value: '01' },
{ measure: 0, channel: '06', position: [0, 1] as const, value: '02' },
{ measure: 0, channel: '07', position: [0, 1] as const, value: '03' },
{ measure: 0, channel: '0A', position: [0, 1] as const, value: '04' },
{ measure: 0, channel: 'A0', position: [0, 1] as const, value: '01' },
{ measure: 0, channel: 'SC', position: [0, 1] as const, value: '01' },
{ measure: 0, channel: '09', position: [1, 2] as const, value: '01' },
{ measure: 1, channel: '08', position: [0, 1] as const, value: '01' },
{ measure: 1, channel: 'SP', position: [0, 1] as const, value: '01' },
{ measure: 2, channel: '11', position: [0, 1] as const, value: '01' },
];
return json;
}
export function createPoorBGALoggingChart() {
const json = createEmptyJSON('bms');
json.metadata.bpm = 120;
json.resources.wav['01'] = 'not-found.wav';
json.resources.bmp['00'] = 'fallback.png';
json.events = [{ measure: 0, channel: '11', position: [0, 1] as const, value: '01' }];
return json;
}
export function createLandmineOnlyChart(options: { includeExplosionSound?: boolean; value?: string } = {}) {
const { includeExplosionSound = true, value = '10' } = options;
const json = createEmptyJSON('bms');
json.metadata.bpm = 120;
Eif (includeExplosionSound) {
json.resources.wav['00'] = 'explode.wav';
}
// Mine on measure 1 (chart 2.0 s at BPM 120) so a held key can deterministically detonate it as it crosses the
// judge line. A mine on measure 0 (chart 0 s) is racy under LR2's passage-based detonation: with playback sped up,
// a single poll tick can advance chart time past the mine's PGREAT window before the input is processed.
json.events = [{ measure: 1, channel: 'D1', position: [0, 1] as const, value }];
return json;
}
// Deterministic landmine detonation — holds the 1P key-1 lane (`z` → channel 11) from 0.2 s through the mine's
// passage at chart 2.0 s, then ends the run at 2.3 s. Mirrors the proven hold-through test timing so CI doesn't race.
export const HELD_LANDMINE_INPUT: Array<{ delayMs: number; command: PlayerInputCommand }> = [
{ delayMs: 200, command: { kind: 'kitty-state', pressTokens: ['z'], repeatTokens: [], releaseTokens: [] } },
{ delayMs: 2300, command: { kind: 'interrupt', reason: 'escape' } },
];
/**
* An input runtime that pushes `commands` after their delays from `start()`. The delays run on the engine's scheduler,
* so they are host timers by default and exact when the play runs on a virtual clock (`core/characterization/
* virtual-clock.ts`), which keeps timing-sensitive input off the wall clock.
*/
export function createScheduledInputRuntime(commands: Array<{ delayMs: number; command: PlayerInputCommand }>) {
return ({ inputSignals }: { inputSignals: { pushCommand: (command: PlayerInputCommand) => void } }) => {
const cancels: Array<() => void> = [];
return {
start: () => {
const scheduler = getEngineScheduler();
for (const { delayMs, command } of commands) {
cancels.push(
scheduler.setTimeout(() => {
inputSignals.pushCommand(command);
}, delayMs),
);
}
},
stop: () => {
for (const cancel of cancels) {
cancel();
}
},
};
};
}
export interface RecordedJudgeCombo {
judge: string;
combo: number;
channel?: string;
seconds: number;
}
export function createJudgeComboRecorder(records: RecordedJudgeCombo[]) {
return async (context: CreatePlayerUIRuntimeContext) => {
const originalPublishJudgeCombo = context.stateSignals.publishJudgeCombo;
context.stateSignals.publishJudgeCombo = (judge, combo, channel, updatedAtMs) => {
records.push({
judge,
combo,
channel,
seconds: context.uiSignals.getFrame().currentSeconds,
});
originalPublishJudgeCombo(judge, combo, channel, updatedAtMs);
};
return {
tuiEnabled: true,
start: () => undefined,
stop: () => undefined,
dispose: () => undefined,
triggerPoor: () => undefined,
clearPoor: () => undefined,
};
};
}
/** UI runtime that records every long-note command the engine pushes (the UI must be enabled for them to fire). */
export function createLongNoteCommandRecorder(records: PlayerUICommand[]) {
return async (context: CreatePlayerUIRuntimeContext) => {
const original = context.uiSignals.pushCommand;
context.uiSignals.pushCommand = (command) => {
if (command.kind === 'long-note-start' || command.kind === 'long-note-end') {
records.push(command);
}
original(command);
};
return {
tuiEnabled: true,
start: () => undefined,
stop: () => undefined,
dispose: () => undefined,
triggerPoor: () => undefined,
clearPoor: () => undefined,
};
};
}
export function createPlaybackEndRecorder(targetSeconds: number, records: number[]) {
return async (context: CreatePlayerUIRuntimeContext) => ({
tuiEnabled: true,
playbackEndSeconds: targetSeconds,
start: () => undefined,
stop: () => {
records.push(context.uiSignals.getFrame().currentSeconds);
},
dispose: () => undefined,
triggerPoor: () => undefined,
clearPoor: () => undefined,
});
}
export function hasAnyNonSilentAudioWrite(): boolean {
return audioSinkState.writes.some((chunk) => {
for (let index = 0; index < chunk.length; index += 1) {
if (chunk[index] !== 0) {
return true;
}
}
return false;
});
}
|