Adaptive Music v0.8.0 release candidate
Validate and generate manual release / package (push) Waiting to run
Validate and generate manual release / package (push) Waiting to run
This commit is contained in:
1 parent
8c07a468a4
commit
95b0427aa1
48 files changed
+3631
-313
No files matched your search
@@ -4,14 +4,28 @@
|
||||
<section id="adaptive-music-setup"><main id="app" class="window-content"></main></section>
|
||||
<script type="module">
|
||||
import {createSetupClass,createListenerClass} from '/src/foundry/setup.mjs';
|
||||
import {startConfigurationInterfaces} from '/src/foundry/configuration.mjs';
|
||||
let flag={},catalog=[];const settings={ownedPlaylistIds:'native',musicDefaults:{},enabled:false,advancedDevelopment:false};
|
||||
const collection=items=>{const map=new Map(items.map(x=>[x.id,x]));map[Symbol.iterator]=function*(){yield*map.values()};return map};
|
||||
const scene={id:'scene',name:'Moonlit forest',active:true,getFlag:()=>flag,setFlag:async(ns,k,v)=>{flag=v;window.saved=flag}};
|
||||
const scene={id:'scene',name:'Moonlit forest',documentName:'Scene',active:true,getFlag:()=>flag,setFlag:async(ns,k,v)=>{flag=v;window.saved=flag}};
|
||||
const game={user:{isGM:true},settings:{get:(ns,k)=>settings[k],set:async(ns,k,v)=>{settings[k]=v}},playlists:collection([{id:'native',name:'Foundry fallback'}]),scenes:collection([scene]),combats:[]};
|
||||
let trackState='playing',position=12;window.controlActions=[];
|
||||
const connection={status:{state:'disconnected',catalog:0,audioContext:'closed'},open:async p=>{if(p.token!=='fixture-token')throw {code:'denied'};catalog=[{provider:'ma',id:'ambient',kind:'playlist',name:'Forest at night'},{provider:'ma',id:'combat',kind:'playlist',name:'Battle drums'}];connection.status={state:'connected',catalog:2,audioContext:'running',hasPrivateDraft:true,peers:2}},refresh:async()=>{},resume:async()=>{},disconnect:async()=>{},playback:async()=>({source:'Music Assistant',state:trackState,title:'Forest at night',position,duration:90}),
|
||||
control:async(action,value)=>{window.controlActions.push(action);if(action==='seek')position=value;else trackState={pause:'paused',resume:'playing',stop:'idle'}[action];},setVolume:value=>{connection.status.volume=value;}};
|
||||
let trackState='playing',position=12,repeat='off';window.controlActions=[];
|
||||
const connection={status:{state:'disconnected',catalog:0,audioContext:'closed'},open:async p=>{if(p.token!=='fixture-token')throw {code:'denied'};catalog=[{provider:'ma',id:'ambient',kind:'playlist',name:'Forest at night'},{provider:'ma',id:'combat',kind:'playlist',name:'Battle drums'}];connection.status={state:'connected',catalog:2,audioContext:'running',hasPrivateDraft:true,peers:2}},refresh:async()=>{},resume:async()=>{},disconnect:async()=>{},playback:async()=>({source:'Music Assistant',state:trackState,title:'Forest at night',position,duration:90,repeat}),
|
||||
control:async(action,value)=>{window.controlActions.push(action);if(action==='seek')position=value;else if(action==='repeat')repeat=value;else trackState={pause:'paused',resume:'playing',stop:'idle'}[action];},setVolume:value=>{connection.status.volume=value;}};
|
||||
const Setup=createSetupClass({game,connection,getChoices:async()=>[{provider:'native',id:'native',name:'Foundry fallback'},...catalog],start(){},stop(){},setOverrides(){},onError(){},Base:class{}});
|
||||
document.querySelector('#app').append(await new Setup()._renderHTML());window.ready=true;
|
||||
window.nativeConfiguration=async()=>{
|
||||
const callbacks=new Map();
|
||||
const Hooks={on:(event,callback)=>callbacks.set(event,callback),off:event=>callbacks.delete(event)};
|
||||
const directory=document.createElement('aside'),sheet=document.createElement('section');
|
||||
directory.id='fixture-playlists';sheet.id='fixture-scene';document.body.append(directory,sheet);
|
||||
const interfaces=startConfigurationInterfaces({game,Hooks,getChoices:()=>catalog,onError(error){throw error;}});
|
||||
await callbacks.get('renderPlaylistDirectory')({},directory);
|
||||
window.refreshNativeConfiguration=async()=>{
|
||||
await interfaces.refreshDirectory({element:directory});
|
||||
await callbacks.get('renderSceneConfig')({document:scene},sheet);
|
||||
};
|
||||
window.closeNativeConfiguration=()=>{interfaces.dispose();directory.remove();sheet.remove();};
|
||||
};
|
||||
window.listener=async()=>{const Listener=createListenerClass({game,audio:{stop(){}},resumeListener:()=>{window.activated=true},Base:class{}});document.querySelector('#app').replaceChildren(await new Listener()._renderHTML())};
|
||||
</script>
|
||||
@@ -39,5 +39,5 @@ test('editor uses text for catalog labels and rechecks GM on actual save event',
|
||||
test('configuration hook disposal prevents pending asynchronous render from mounting',async()=>{
|
||||
const f=fixture(),callbacks=new Map();let resolve;const off=[];
|
||||
const ui=startConfigurationInterfaces({...f,Hooks:{on(e,fn){callbacks.set(e,fn);return e;},off(...args){off.push(args);}},getChoices:()=>new Promise(r=>{resolve=r;})});
|
||||
const root=container();const pending=callbacks.get('renderSceneConfig')({document:f.document},root);ui.dispose();resolve(choices);await pending;assert.equal(root.children.length,0);assert.equal(off.length,2);
|
||||
const root=container();const pending=callbacks.get('renderSceneConfig')({document:f.document},root);ui.dispose();resolve(choices);await pending;assert.equal(root.children.length,0);assert.equal(off.length,3);
|
||||
});
|
||||
@@ -152,3 +152,29 @@ test('superseded cross-provider apply is reconciled by stopping partially touche
|
||||
const newest=f.controller.update({scene:scene()});resume();await assert.rejects(stale,{code:'stale'});await newest;
|
||||
assert.equal(cleanups,1);assert.equal(f.playback.items[0],'A');
|
||||
});
|
||||
|
||||
test('duplicate hooks during a transition share its fence and a shared playlist does not restart',async()=>{
|
||||
const {controller,log}=fixture();
|
||||
const state={scene:{id:'A',playlist:ref('same')}};
|
||||
const first=controller.update(state),duplicate=controller.update(structuredClone(state));
|
||||
assert.equal(duplicate,first);
|
||||
await first;
|
||||
assert.equal((await controller.update({scene:{id:'B',playlist:ref('same')}})).unchanged,true);
|
||||
assert.deepEqual(log,[['resolve','same'],['apply','same']]);
|
||||
});
|
||||
|
||||
test('shared ambient and combat cue retains its position when combat ends under an override',async()=>{
|
||||
const f=fixture();
|
||||
const ambient={scene:scene()};
|
||||
const fighting={...ambient,combats:[{...combat(),playlist:ambient.scene.playlist}]};
|
||||
const overrides=[{id:'manual',playlist:ref('different')}];
|
||||
await f.controller.update(ambient);
|
||||
await f.controller.update(fighting);
|
||||
const saved={...f.playback,offset:73};
|
||||
f.playback=saved;
|
||||
await f.controller.update({...fighting,overrides});
|
||||
await f.controller.update({...ambient,overrides});
|
||||
assert.equal((await f.controller.update(ambient)).restored,true);
|
||||
assert.equal(f.playback.offset,saved.offset);
|
||||
assert.deepEqual(f.playback.items,saved.items);
|
||||
});
|
||||
@@ -113,3 +113,14 @@ test('Sendspin pause emulation retains position and restores paused queues witho
|
||||
assert.deepEqual(f.writes.slice(before).map(w=>w.action),['stop','clear','repeat','play_media']);
|
||||
const again=await f.provider.snapshot({...f.ctx,generation:7});assert.equal(again.value.state,'paused');assert.equal(again.value.index,1);assert.equal(again.value.position,17);
|
||||
});
|
||||
|
||||
test('an exhausted ambient queue can be interrupted and restored without starting audio',async()=>{
|
||||
const f=fixture();
|
||||
Object.assign(f.state,{state:'idle',ended:true,current_index:2,elapsed_time:0,repeat_mode:'off'});
|
||||
const finished=await f.provider.snapshot(f.ctx);
|
||||
assert.equal(finished.value.ended,true);
|
||||
f.state.ended=false;
|
||||
await f.provider.restore(finished,{...f.ctx,generation:2});
|
||||
assert.deepEqual(f.writes.map(write=>write.action),['stop','clear','repeat','play_media']);
|
||||
assert.equal(f.state.state,'idle');
|
||||
});
|
||||
@@ -8,6 +8,6 @@ test('installable development entry defaults automation off and imports no gatew
|
||||
try{
|
||||
await import('../../src/foundry/module.mjs');once.get('init')();once.get('ready')();
|
||||
assert.equal(settings.get('enabled').default,false);assert.equal(settings.get('ownedPlaylistIds').default,'');
|
||||
assert.equal(registrations,2);assert.equal(typeof module.api.mountConfiguration,'function');assert.throws(()=>module.api.setOverrides([]));module.api.dispose();
|
||||
assert.equal(registrations,4);assert.equal(typeof module.api.mountConfiguration,'function');assert.throws(()=>module.api.setOverrides([]));module.api.dispose();
|
||||
}finally{delete globalThis.game;delete globalThis.Hooks;delete globalThis.ui;}
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {test} from 'node:test';
|
||||
import {PcmTimeline} from '../../src/audio/pcm-timeline.mjs';
|
||||
|
||||
const sampleRate=48000;
|
||||
const packet=serverTimeUs=>({samples:[new Float32Array(960)],sampleRate,serverTimeUs});
|
||||
|
||||
function fixture(){
|
||||
const sources=[];
|
||||
const context={currentTime:1,state:'running',
|
||||
createBuffer:(_channels,frames)=>({data:new Float32Array(frames),getChannelData(){return this.data;}}),
|
||||
createBufferSource(){
|
||||
const source={playbackRate:{value:1},connect(){},disconnect(){},start(time){this.time=time;},stop(time){this.stopTime=time;}};
|
||||
sources.push(source);
|
||||
return source;
|
||||
},
|
||||
};
|
||||
return {context,sources,timeline:new PcmTimeline(context,{})};
|
||||
}
|
||||
|
||||
test('consecutive PCM stays contiguous under a jittering browser clock',()=>{
|
||||
const {context,sources,timeline}=fixture();
|
||||
for(let i=0;i<8;i++){
|
||||
context.currentTime=1+i*0.02+i%2*0.0025;
|
||||
timeline.push(packet(2000000+i*20000),1900000+i*20000);
|
||||
}
|
||||
for(let i=1;i<sources.length;i++){
|
||||
const previous=sources[i-1],current=sources[i];
|
||||
assert.ok(Math.abs(current.time-previous.time-0.02/previous.playbackRate.value)<1e-9);
|
||||
}
|
||||
assert.equal(timeline.diagnostics.sourceGaps,0);
|
||||
assert.equal(timeline.diagnostics.underruns,0);
|
||||
});
|
||||
|
||||
test('partial clear preserves only the valid span and allows replacement at its boundary',()=>{
|
||||
const {sources,timeline}=fixture();
|
||||
const start=timeline.push(packet(2000000),1900000);
|
||||
timeline.push(packet(2020000),1900000);
|
||||
timeline.push(packet(2040000),1900000);
|
||||
timeline.clear(2030000);
|
||||
assert.ok(Math.abs(sources[1].stopTime-start-0.03)<1e-9);
|
||||
assert.equal(sources[2].stopTime,undefined);
|
||||
assert.equal(timeline.push(packet(2030000),1900000),sources[1].stopTime);
|
||||
assert.equal(timeline.diagnostics.sourceOverlaps,0);
|
||||
});
|
||||
|
||||
test('source gaps and late packets are observable separately from suspension',()=>{
|
||||
const {context,timeline}=fixture();
|
||||
timeline.push(packet(2000000),1900000);
|
||||
timeline.push(packet(2030000),1900000);
|
||||
assert.equal(timeline.diagnostics.sourceGaps,1);
|
||||
assert.equal(timeline.diagnostics.gapMs,10);
|
||||
assert.equal(timeline.push(packet(1000000),1900000),false);
|
||||
assert.equal(timeline.diagnostics.droppedLate,1);
|
||||
context.state='suspended';
|
||||
assert.equal(timeline.push(packet(2080000),1900000),false);
|
||||
assert.equal(timeline.diagnostics.bufferedMs,0);
|
||||
context.state='running';
|
||||
assert.ok(timeline.push(packet(2080000),1900000)>0);
|
||||
assert.equal(timeline.diagnostics.sourceGaps,1);
|
||||
});
|
||||
+36
-1
@@ -2,6 +2,7 @@ import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import stat
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
@@ -24,7 +25,7 @@ class ReleaseTests(unittest.TestCase):
|
||||
root=Path(folder);bundle=release.build_release(output=root);first=bundle.read_bytes();release.build_release(output=root)
|
||||
self.assertEqual(first,bundle.read_bytes())
|
||||
with zipfile.ZipFile(bundle) as outer:
|
||||
self.assertTrue({'adaptive-music.zip','module.json','adaptive-music-source.zip','README.md','INSTALL.md','CHANGELOG.md','LICENSE','THIRD-PARTY-NOTICES','SHA256SUMS'}.issubset(outer.namelist()))
|
||||
self.assertTrue({'adaptive-music.zip','module.json','adaptive-music-source.zip','README.md','INSTALL.md','CHANGELOG.md','HANDOFF.md','USER-ACCEPTANCE.md','LICENSE','THIRD-PARTY-NOTICES','SHA256SUMS'}.issubset(outer.namelist()))
|
||||
standalone=json.loads(outer.read('module.json'))
|
||||
for row in outer.read('SHA256SUMS').decode().splitlines():
|
||||
digest,name=row.split(' ',1);self.assertEqual(hashlib.sha256(outer.read(name)).hexdigest(),digest)
|
||||
@@ -39,6 +40,8 @@ class ReleaseTests(unittest.TestCase):
|
||||
if (ROOT/evidence).is_file():
|
||||
self.assertEqual(outer.read(evidence),source.read(f'adaptive-music-source/{evidence}'))
|
||||
release.validate_package(root/'adaptive-music.zip',standalone)
|
||||
self.assertEqual(json.loads((root/'release.json').read_bytes())['runtimeAssetsSHA256'],
|
||||
release.runtime_assets_sha256(root/'adaptive-music.zip'))
|
||||
(root/'licenses').mkdir(exist_ok=True)
|
||||
(root/'licenses/unmanaged.txt').write_text('must not be swept into the release')
|
||||
with self.assertRaises(ValueError):release.build_release(output=root)
|
||||
@@ -58,4 +61,36 @@ class ReleaseTests(unittest.TestCase):
|
||||
with patch.object(release.subprocess,'check_output',side_effect=FileNotFoundError):
|
||||
entries=release.source_entries(manifest)
|
||||
self.assertIn('adaptive-music-source/src/audio/gm-host.mjs',entries)
|
||||
self.assertIn('adaptive-music-source/HANDOFF.md',entries)
|
||||
self.assertIn('adaptive-music-source/USER-ACCEPTANCE.md',entries)
|
||||
self.assertIn('adaptive-music-source/SOURCE_REVISION.txt',entries)
|
||||
|
||||
def test_source_revision_status_distinguishes_checkout_and_generated_manifest(self):
|
||||
manifest=release.release_manifest()
|
||||
with patch.object(release.subprocess,'check_output',return_value=''):
|
||||
self.assertEqual(release.source_revision_status(manifest),'clean Git checkout')
|
||||
generated=release.release_manifest('https://github.com/example/adaptive-music')
|
||||
self.assertIn('generated release manifest',release.source_revision_status(generated))
|
||||
with patch.object(release.subprocess,'check_output',return_value=' M src/file\n'):
|
||||
self.assertIn('base revision',release.source_revision_status(manifest))
|
||||
with patch.object(release.subprocess,'check_output',side_effect=FileNotFoundError):
|
||||
self.assertIn('without Git metadata',release.source_revision_status(manifest))
|
||||
|
||||
def test_package_rejects_unexpected_files_or_replaced_provenance(self):
|
||||
manifest=release.release_manifest()
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path=Path(folder)/'bad.zip'
|
||||
entries=release.module_entries(manifest)
|
||||
release.write_zip(path,{**entries,'adaptive-music/extra.json':b'{}'})
|
||||
with self.assertRaisesRegex(ValueError,'inventory'):release.validate_package(path)
|
||||
entries['adaptive-music/vendor/provenance.json']=b'{}'
|
||||
release.write_zip(path,entries)
|
||||
with self.assertRaisesRegex(ValueError,'provenance'):release.validate_package(path)
|
||||
entries=release.module_entries(manifest)
|
||||
with zipfile.ZipFile(path,'w') as archive:
|
||||
for name,data in entries.items():
|
||||
info=zipfile.ZipInfo(name)
|
||||
if name.endswith('/LICENSE'):
|
||||
info.external_attr=(stat.S_IFLNK|0o777)<<16
|
||||
archive.writestr(info,data)
|
||||
with self.assertRaisesRegex(ValueError,'inventory'):release.validate_package(path)
|
||||
Reference in new issue
Block a user