Files
site/tools/harness.html
T

38 lines
3.2 KiB
HTML

<!doctype html>
<meta charset="utf-8">
<title>harness</title>
<p>This file is a fragment: tools/harness.sh appends everything from the marker below to index.html and runs it.</p>
<!-- harness -->
<script>
try {
const MP3 = "data:audio/mpeg;base64,__MP3__";
async function mp3blob() { const b = atob(MP3.split(",")[1]); const u = new Uint8Array(b.length); for (let i = 0; i < b.length; i++) u[i] = b.charCodeAt(i); return new Blob([u], { type: "audio/mpeg" }); }
let renderDelay = 50, n = 0;
venice = async function (path, body, { raw = false } = {}) {
if (path.includes("chat")) return { choices: [{ message: { content: JSON.stringify({ title: "T" + (++n), tags: "lo-fi, piano, instrumental", lyrics: "[verse]\nla\n[chorus]\nlo", bpm: 80, key: "C major", energy: 0.4, seconds: 30, meter: "4/4", station: "Test FM", line: "hi" }) } }] };
if (path === "/render") { await new Promise((r) => setTimeout(r, renderDelay)); const b = await mp3blob(); return new Response(b, { headers: { "content-type": "audio/mpeg", "x-cost": "0.001", "x-renderer": "test" } }); }
throw new Error("unexpected " + path);
};
const log = []; const dd = document.createElement("pre"); dd.id = "diag"; document.body.append(dd);
const L = (m) => { log.push(m); dd.textContent = log.join("\n"); };
const S = (tag) => L(tag + ": src=" + String(state.audio.src).slice(5, 14) + " paused=" + state.audio.paused + " playing=" + state.playing + " holding=" + !!state.holding + " cur=" + (state.current && state.current.spec.title) + " next=" + (state.nextJob && state.nextJob.spec.title) + " nextblob=" + !!(state.nextJob && state.nextJob.blob) + " crackle=" + crackle.on + " loop=" + state.audio.loop);
window.addEventListener("error", (e) => L("ERR " + e.message + " @" + e.lineno));
window.addEventListener("unhandledrejection", (e) => L("REJ " + (e.reason && (e.reason.stack || e.reason)).toString().slice(0, 200)));
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const ended = () => { state.audio.dispatchEvent(new Event("ended")); };
(async () => {
document.dispatchEvent(new Event("keydown")); await sleep(300);
openStation("test seed"); await sleep(1500); S("after first (expect cur=T1 playing, next=T2 cooked)");
ended(); await sleep(600); S("after ended (expect cur=T2 playing, holding=false)");
renderDelay = 3000; state.nextJob = null; cookNext(); await sleep(300); S("slow cook started (expect next cooking, nextblob=false)");
ended(); await sleep(600); S("ended, nothing ready (expect holding=true, loop=true)");
await sleep(3500); S("track landed (expect holding=true, loop=false: queued behind the crackle)");
ended(); await sleep(600); S("crackle pass ended (expect cur=next track playing, holding=false)");
renderDelay = 50; document.querySelector("#play").click(); await sleep(600); S("after pause (expect paused, crackle=true)");
document.querySelector("#play").click(); await sleep(300); S("after resume (expect playing, crackle=false)");
document.querySelector("#skip").click(); await sleep(1500); S("after skip (expect a new cur)");
L("END");
})();
} catch (e) { const p = document.createElement("pre"); p.id = "diag"; p.textContent = "TOPERR " + e.message; document.body.append(p); }
</script>