48 lines
3.0 KiB
Python
48 lines
3.0 KiB
Python
import importlib.util
|
|||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
import tempfile
|
||
|
|
import unittest
|
||
|
|
import zipfile
|
||
|
|
ROOT=Path(__file__).resolve().parents[1]
|
||
|
|
spec=importlib.util.spec_from_file_location('package_module',ROOT/'scripts/package_module.py')
|
||
|
|
packager=importlib.util.module_from_spec(spec);spec.loader.exec_module(packager)
|
||
|
|
|
||
|
|
class DevelopmentPackageTests(unittest.TestCase):
|
||
|
|
def test_package_excludes_gateway_private_state_and_false_verification(self):
|
||
|
|
with tempfile.TemporaryDirectory() as folder:
|
||
|
|
target=packager.build(Path(folder)/'module.zip')
|
||
|
|
first=target.read_bytes();packager.build(target);self.assertEqual(first,target.read_bytes())
|
||
|
|
with zipfile.ZipFile(target) as archive:
|
||
|
|
names=archive.namelist()
|
||
|
|
self.assertTrue(all(n.startswith('adaptive-music/') for n in names))
|
||
|
|
self.assertFalse(any('/gateway/' in n or '/.local/' in n for n in names))
|
||
|
|
manifest=json.loads(archive.read('adaptive-music/module.json'))
|
||
|
|
self.assertNotIn('verified',manifest['compatibility'])
|
||
|
|
self.assertEqual(manifest['relationships']['requires'],[])
|
||
|
|
self.assertTrue(all('adaptive-music/'+p in names for p in manifest['esmodules']))
|
||
|
|
self.assertIn('adaptive-music/licenses/VGM-MIT.txt',names)
|
||
|
|
for browser_file in ('src/providers/ma/remote.mjs','src/foundry/setup.mjs','src/foundry/listener-audio.mjs','src/core/scene-music.mjs'):
|
||
|
|
self.assertIn('adaptive-music/'+browser_file,names)
|
||
|
|
self.assertTrue(all('adaptive-music/'+style in names for style in manifest['styles']))
|
||
|
|
for name in names:
|
||
|
|
if name.endswith('.mjs'):
|
||
|
|
source=archive.read(name)
|
||
|
|
self.assertNotIn(b'node:',source);self.assertNotIn(b'gateway/',source)
|
||
|
|
|
||
|
|
def test_companion_is_separate_complete_and_excludes_private_configuration(self):
|
||
|
|
with tempfile.TemporaryDirectory() as folder:
|
||
|
|
target=packager.build_companion(Path(folder)/'companion.zip')
|
||
|
|
with zipfile.ZipFile(target) as archive:
|
||
|
|
names=archive.namelist()
|
||
|
|
self.assertTrue(all(n.startswith('adaptive-music-companion/') for n in names))
|
||
|
|
self.assertFalse(any('/.local/' in n or '/node_modules/' in n for n in names))
|
||
|
|
for name in ('gateway/run-development.mjs','gateway/development-http.mjs','gateway/ma-client.mjs','src/core/controller.mjs','gateway/SETUP.md'):
|
||
|
|
self.assertIn('adaptive-music-companion/'+name,names)
|
||
|
|
for name in names:
|
||
|
|
if name.endswith('.mjs'):
|
||
|
|
import re
|
||
|
|
for relative in re.findall(rb"from ['\"](\.[^'\"]+)['\"]",archive.read(name)):
|
||
|
|
import posixpath
|
||
|
|
resolved=posixpath.normpath(posixpath.join(posixpath.dirname(name),relative.decode()))
|
||
|
|
self.assertIn(resolved,names)
|