PageSourceSearch

https://jairen.com/assets/AdminAIMusicHarness-aUfSOzwI.js

js jairen.com collected 2026-10-09 22:54:35 UTC 13,494 bytes, 1 lines download raw bytes

1import{c as B,r as _,s as y,j as i,L as S}from"./index-vQd7viLS.js";const A=[{id:"wav-8-8k-mono",label:"WAV 8-bit mono @ 8kHz",mime:"audio/wav",sr:8e3,channels:1,bitDepth:8},{id:"wav-16-22k-mono",label:"WAV 16-bit mono @ 22.05kHz",mime:"audio/wav",sr:22050,channels:1,bitDepth:16},{id:"wav-16-44k-stereo",label:"WAV 16-bit stereo @ 44.1kHz",mime:"audio/wav",sr:44100,channels:2,bitDepth:16},{id:"wav-24-48k-mono",label:"WAV 24-bit mono @ 48kHz",mime:"audio/wav",sr:48e3,channels:1,bitDepth:24},{id:"wav-32f-48k-stereo",label:"WAV 32-bit float stereo @ 48kHz",mime:"audio/wav",sr:48e3,channels:2,bitDepth:32,float:!0},{id:"wav-16-96k-mono",label:"WAV 16-bit mono @ 96kHz",mime:"audio/wav",sr:96e3,channels:1,bitDepth:16},{id:"wav-xwav-alias",label:"WAV under audio/x-wav alias",mime:"audio/x-wav",sr:22050,channels:1,bitDepth:16}],R=[{id:"upload",label:"1. Upload synthetic WAV",detail:"POST cg-music-analyze-sample with 0.5s 440Hz tone, rights affirmed.",status:"idle"},{id:"row",label:"2. Asset + analysis rows persisted",detail:"Confirms cg_music_assets / cg_music_sample_analysis inserted.",status:"idle"},{id:"signed",label:"3. signed_url returned (1h TTL)",detail:"Response must include signed_url for immediate playback.",status:"idle"},{id:"playback",label:"4. signed_url plays in <audio>",detail:"Fetch bytes, decode via Audio element, confirm duration > 0.",status:"idle"},{id:"resigned",label:"5. Re-issued signed_url plays",detail:"createSignedUrl again, fetch + decode to prove URL is reliable.",status:"idle"},{id:"noRights",label:"6. Reject: rights not affirmed",detail:"Expects 400 rights_not_affirmed when affirmed=false.",status:"idle"},{id:"badMime",label:"7. Reject: unsupported mime",detail:"Expects 400 unsupported_mime for application/octet-stream.",status:"idle"},{id:"empty",label:"8. Reject: empty audio body",detail:"Expects 400 missing_audio / empty_audio for zero bytes.",status:"idle"},...A.map((o,c)=>({id:`variant:${o.id}`,label:`${9+c}. Upload + playback — ${o.label}`,detail:`Encodes a 0.4s 440Hz tone (${o.channels===2?"stereo":"mono"}, ${o.bitDepth}-bit${o.float?" float":""} @ ${o.sr}Hz, mime=${o.mime}), uploads, fetches signed URL, decodes via <audio>.`,status:"idle"})),{id:"mp3-shape",label:`${9+A.length}. Upload-only — MP3 mime accepted`,detail:"WAV bytes uploaded under audio/mpeg to confirm the server accepts the MIME and stores the asset. Decoded playback is not asserted (bytes are not real MP3).",status:"idle"},{id:"ogg-shape",label:`${10+A.length}. Upload-only — OGG mime accepted`,detail:"WAV bytes uploaded under audio/ogg to confirm the server accepts the MIME and stores the asset. Decoded playback is not asserted.",status:"idle"},{id:"m4a-shape",label:`${11+A.length}. Upload-only — M4A mime accepted`,detail:"WAV bytes uploaded under audio/x-m4a to confirm the server accepts the MIME and stores the asset. Decoded playback is not asserted.",status:"idle"}];function D(o){const{sr:c,channels:u,bitDepth:d}=o,b=o.float===!0,M=o.seconds??.4,x=Math.floor(c*M),m=d/8,$=x*u*m,N=new ArrayBuffer(44+$),t=new DataView(N),j=(w,f)=>{for(let h=0;h<f.length;h++)t.setUint8(w+h,f.charCodeAt(h))};j(0,"RIFF"),t.setUint32(4,36+$,!0),j(8,"WAVE"),j(12,"fmt "),t.setUint32(16,16,!0),t.setUint16(20,b?3:1,!0),t.setUint16(22,u,!0),t.setUint32(24,c,!0),t.setUint32(28,c*u*m,!0),t.setUint16(32,u*m,!0),t.setUint16(34,d,!0),j(36,"data"),t.setUint32(40,$,!0);for(let w=0;w<x;w++){const f=Math.sin(2*Math.PI*440*w/c);for(let h=0;h<u;h++){const n=44+(w*u+h)*m;if(b&&d===32)t.setFloat32(n,Math.max(-1,Math.min(1,f)),!0);else if(d===8)t.setUint8(n,Math.round((f*.5+.5)*255));else if(d===16)t.setInt16(n,Math.max(-1,Math.min(1,f))*32767,!0);else if(d===24){const g=Math.round(Math.max(-1,Math.min(1,f))*8388607),k=g<0?g+16777216:g;t.setUint8(n,k&255),t.setUint8(n+1,k>>8&255),t.setUint8(n+2,k>>16&255)}else d===32&&!b&&t.setInt32(n,Math.round(Math.max(-1,Math.min(1,f))*2147483647),!0)}}return new Uint8Array(N)}function E(){return D({sr:22050,channels:1,bitDepth:16,seconds:.5})}function z(o){let c="";for(let d=0;d<o.length;d+=32768)c+=String.fromCharCode(...o.subarray(d,d+32768));return btoa(c)}async function U(o){const c=await fetch(o);if(!c.ok)return{ok:!1,note:`HTTP ${c.status}`};const u=c.headers.get("content-type")??"",d=await c.blob();
1if(d.size===0)return{ok:!1,note:"0-byte body"};const b=URL.createObjectURL(d);try{const M=await new Promise(x=>{const m=new Audio;m.preload="metadata",m.onloadedmetadata=()=>x(Number.isFinite(m.duration)?m.duration:0),m.onerror=()=>x(0),m.src=b});return M<=0?{ok:!1,note:`decoded duration=0 (ct=${u})`,bytes:d.size}:{ok:!0,note:`ct=${u}`,bytes:d.size,durationMs:Math.round(M*1e3)}}finally{URL.revokeObjectURL(b)}}function V(){const{isAdmin:o,checking:c}=B(),[u,d]=_.useState(R),[b,M]=_.useState(!1),[x,m]=_.useState(null),[$,N]=_.useState(null),t=_.useCallback((n,g)=>{d(k=>k.map(r=>r.id===n?{...r,...g}:r))},[]),j=_.useCallback(async()=>{M(!0),m(null),N(null),d(R.map(e=>({...e,status:"running",notes:void 0,durationMs:void 0})));const n=E(),g=z(n),k=performance.now();let r=null;try{const{data:e,error:s}=await y.functions.invoke("cg-music-analyze-sample",{body:{audioBase64:g,mime:"audio/wav",originalName:"harness-tone.wav",rightsAffirmed:!0,affirmationText:"Synthetic tone generated by the admin harness.",declaredBpm:120,declaredKey:"C major",declaredMood:"test",declaredGenre:"diagnostic",freeText:"Harness probe — verify storage + signed_url playback.",durationMs:500}});if(s)throw s;r=e,t("upload",{status:r!=null&&r.ok?"pass":"fail",notes:r!=null&&r.ok?`asset_id=${r.asset_id}`:`error=${r==null?void 0:r.error}`,durationMs:Math.round(performance.now()-k)})}catch(e){t("upload",{status:"fail",notes:(e==null?void 0:e.message)??String(e),durationMs:Math.round(performance.now()-k)}),["row","signed","playback","resigned"].forEach(s=>t(s,{status:"skip",notes:"upload failed"}))}if(r!=null&&r.ok){m(r.asset_id),N(r.storage_path);try{const{data:s,error:a}=await y.from("cg_music_assets").select("id,storage_path,bytes,mime").eq("id",r.asset_id).maybeSingle();if(a)throw a;const{data:l,error:p}=await y.from("cg_music_sample_analysis").select("id,status").eq("asset_id",r.asset_id).maybeSingle();if(p)throw p;const v=!!s&&!!l&&l.status==="ready";t("row",{status:v?"pass":"fail",notes:v?`asset.bytes=${s.bytes} analysis.status=${l.status}`:`asset=${!!s} analysis=${!!l}`})}catch(s){t("row",{status:"fail",notes:(s==null?void 0:s.message)??String(s)})}const e=r.signed_url??null;if(t("signed",{status:e?"pass":"fail",notes:e?"present":"missing"}),e){const s=performance.now();try{const a=await U(e);t("playback",{status:a.ok?"pass":"fail",notes:`${a.note}${a.bytes?` · ${a.bytes}B`:""}${a.durationMs?` · ${a.durationMs}ms`:""}`,durationMs:Math.round(performance.now()-s)})}catch(a){t("playback",{status:"fail",notes:(a==null?void 0:a.message)??String(a)})}}else t("playback",{status:"skip",notes:"no signed_url"});try{const{data:s,error:a}=await y.storage.from("assets").createSignedUrl(r.storage_path,600);if(a||!(s!=null&&s.signedUrl))throw a??new Error("no signedUrl");const l=await U(s.signedUrl);t("resigned",{status:l.ok?"pass":"fail",notes:l.ok?`re-issued OK · ${l.bytes}B`:l.note})}catch(s){t("resigned",{status:"fail",notes:(s==null?void 0:s.message)??String(s)})}}try{const{data:e}=await y.functions.invoke("cg-music-analyze-sample",{body:{audioBase64:g,mime:"audio/wav",originalName:"no-rights.wav",rightsAffirmed:!1}}),s=(e==null?void 0:e.ok)===!1&&(e==null?void 0:e.error)==="rights_not_affirmed";t("noRights",{status:s?"pass":"fail",notes:s?"rejected as expected":`unexpected: ${JSON.stringify(e).slice(0,120)}`})}catch(e){t("noRights",{status:"fail",notes:(e==null?void 0:e.message)??String(e)})}try{const{data:e}=await y.functions.invoke("cg-music-analyze-sample",{body:{audioBase64:g,mime:"application/octet-stream",originalName:"bad.bin",rightsAffirmed:!0}}),s=(e==null?void 0:e.ok)===!1&&(e==null?void 0:e.error)==="unsupported_mime";t("badMime",{status:s?"pass":"fail",notes:s?"rejected as expected":`unexpected: ${JSON.stringify(e).slice(0,120)}`})}catch(e){t("badMime",{status:"fail",notes:(e==null?void 0:e.message)??String(e)})}try{const{data:e}=await y.functions.invoke("cg-music-analyze-sample",{body:{audioBase64:"",mime:"audio/wav",originalName:"empty.wav",rightsAffirmed:!0}}),s=(e==null?void 0:e.ok)===!1&&((e==null?void 0:e.error)==="missing_audio"||(e==null?void 0:e.error)==="empty_audio");t("empty",{status:s?"pass":"fail",notes:s?`rejected (${e.error})`:`unexpected: ${JSON.stringify(e).slice(0,120)}`})}catch(e){t("empty",{status:"fail",notes:(e==null?void 0:e.message)??String(e)})}for(const e of A){const s=`variant:${e.id}`,a=performance.now();try{const l=D({sr:e.sr,channels:e.channels,bitDepth:e.bitDepth,float:e.float}),{data:p}=await y.functions.invoke("cg-music-analyze-sample",{body:{audioBase64:z(l),mime:e.mime,originalName:`${e.id}.wav`,rightsAffirmed:!0,affirmationText:"Synthetic harness tone.",durationMs:400,freeText:`Harness variant ${e.id}`}});if(!(p!=null&&p.ok)||!(p!=null&&p.signed_url)){t(s,{status:"fail",notes:`upload failed: ${(p==null?void 0:p.error)??"no signed_url"}`,durationMs:Math.round(performance.now()-a)});continue}const v=await U(p.signed_url);t(s,{status:v.ok?"pass":"fail",notes:`${e.bitDepth}${e.float?"f":""}-bit ${e.channels===2?"stereo":"mono"} @ ${e.sr}Hz · ${v.bytes??l.byteLength}B · ${v.note}${v.durationMs?` · ${v.durationMs}ms`:""}`,durationMs:Math.round(performance.now()-a)})}catch(l){t(s,{status:"fail",notes:(l==null?void 0:l.message)??String(l),durationMs:Math.round(performance.now()-a)})}}const H=[{id:"mp3-shape",mime:"audio/mpeg",ext:"mp3"},{id:"ogg-shape",mime:"audio/ogg",ext:"ogg"},{id:"m4a-shape",mime:"audio/x-m4a",ext:"m4a"}
1];for(const e of H){const s=performance.now();try{const{data:a}=await y.functions.invoke("cg-music-analyze-sample",{body:{audioBase64:g,mime:e.mime,originalName:`harness-mime.${e.ext}`,rightsAffirmed:!0,affirmationText:"Synthetic harness tone (MIME probe).",durationMs:500}}),l=(a==null?void 0:a.ok)===!0&&typeof(a==null?void 0:a.asset_id)=="string";t(e.id,{status:l?"pass":"fail",notes:l?`accepted · asset_id=${a.asset_id.slice(0,8)}… · mime=${e.mime}`:`error=${(a==null?void 0:a.error)??"unknown"}`,durationMs:Math.round(performance.now()-s)})}catch(a){t(e.id,{status:"fail",notes:(a==null?void 0:a.message)??String(a),durationMs:Math.round(performance.now()-s)})}}M(!1)},[t]);if(c)return i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"Checking admin access…"});if(!o)return i.jsx("div",{className:"p-6 text-sm text-destructive",children:"Admin only."});const w=u.filter(n=>n.status==="pass").length,f=u.filter(n=>n.status==="fail").length,h=u.filter(n=>n.status==="skip").length;return i.jsxs("div",{className:"mx-auto max-w-4xl space-y-6 p-6",children:[i.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-2",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-xl font-semibold",children:"Jairen Music Studio — Sample & Playback Harness"}),i.jsx("p",{className:"text-sm text-muted-foreground",children:"End-to-end verification of uploaded sample analysis and signed-URL playback."})]}),i.jsxs("nav",{className:"flex flex-wrap gap-3 text-sm",children:[i.jsx(S,{className:"underline",to:"/music?step=samples",children:"Samples"}),i.jsx(S,{className:"underline",to:"/music?step=create",children:"Studio"}),i.jsx(S,{className:"underline",to:"/music",children:"Diagnostics"})]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{className:"rounded bg-primary px-4 py-2 text-sm text-primary-foreground disabled:opacity-50",onClick:j,disabled:b,children:b?"Running…":"Run all scenarios"}),i.jsxs("div",{className:"text-sm text-muted-foreground",children:[i.jsxs("span",{className:"text-emerald-600",children:["pass ",w]}),i.jsx("span",{className:"mx-2",children:"·"}),i.jsxs("span",{className:"text-destructive",children:["fail ",f]}),i.jsx("span",{className:"mx-2",children:"·"}),i.jsxs("span",{children:["skip ",h]})]})]}),x&&i.jsxs("div",{className:"rounded border bg-muted/30 p-3 text-xs font-mono",children:["asset_id: ",x,$&&i.jsxs("div",{children:["storage_path: ",$]})]}),i.jsx("ol",{className:"space-y-2",children:u.map(n=>i.jsxs("li",{className:"rounded border p-3",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3",children:[i.jsx("div",{className:"font-medium",children:n.label}),i.jsx(I,{status:n.status})]}),i.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:n.detail}),(n.notes||n.durationMs!=null)&&i.jsxs("div",{className:"mt-2 text-xs font-mono",children:[n.notes,n.durationMs!=null&&i.jsxs("span",{className:"ml-2 text-muted-foreground",children:["(",n.durationMs,"ms)"]})]})]},n.id))}),i.jsxs("p",{className:"text-xs text-muted-foreground",children:["Harness writes a real (tiny) asset into the private ",i.jsx("code",{children:"assets"}
1)," bucket so playback can be verified end-to-end. Rows persist in the Library for later cleanup."]})]})}function I({status:o}){const c=o==="pass"?"bg-emerald-500/15 text-emerald-700 border-emerald-500/30":o==="fail"?"bg-destructive/15 text-destructive border-destructive/30":o==="running"?"bg-amber-500/15 text-amber-700 border-amber-500/30":o==="skip"?"bg-muted text-muted-foreground border-border":"bg-muted/40 text-muted-foreground border-border";return i.jsx("span",{className:`rounded border px-2 py-0.5 text-xs uppercase tracking-wide ${c}`,children:o})}export{V as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.