Files
snake-python/tests/test_DashboardStaticAssets.py
T
daniel156161 a2414f0b3d
Build and Push Docker Container / build-and-push (push) Successful in 2m18s
feat: add Zenith strategy and move latency tracing
- Register Zenith 1.1 with balanced duel verdicts and forced-outcome overrides.
- Prioritize permanent-trail space in Constrictor and health-aware hazard routes.
- Deduct executor queue delays and return fallback directions on move timeouts.
- Correlate response headers, replay timings, and sampled structured trace logs.
- Move shared metrics publication off the response path without losing local counts.
- Allow configurable tournament opponents and add a psql helper recipe.
- Preserve empty latency values through compact replay encoding and migration.
- Update Arena game links and use default assets for missing customizations.
- Cover strategy, HTTP lifecycle, tracing, replay codecs, and dashboard behavior.
- Validate with 260 passing Python tests, 4 skips, and 2 passing JavaScript tests.
2026-11-05 01:11:31 +01:00

68 lines
2.4 KiB
Python

import os
import re
import unittest
from server.Server import Server
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class TestDashboardStaticAssets(unittest.IsolatedAsyncioTestCase):
def setUp(self):
self.server = Server(
data_path=REPO_ROOT,
snake_type='PrismBattleSnake',
storage_type='memory',
metrics_backend='memory',
gameplay_db_enabled=False,
)
async def test_dashboard_uses_arena_game_url(self):
from unittest.mock import patch
with patch.dict(os.environ, {}, clear=True):
response = await self.server.app.test_client().get('/dashboard')
self.assertEqual(response.status_code, 200)
html = await response.get_data(as_text=True)
self.assertIn('https://arena.battlesnake.com/games', html)
self.assertNotIn('https://play.battlesnake.com/game', html)
def test_gameboard_uses_arena_game_url(self):
from types import SimpleNamespace
from server.GameBoard import GameBoard
game = SimpleNamespace(id='example-game')
self.assertEqual(GameBoard._get_game_url(game, False), 'https://arena.battlesnake.com/games/example-game')
self.assertIsNone(GameBoard._get_game_url(game, True))
def _static_url(self):
return self.server.app.jinja_env.globals['static_url']
async def test_static_url_carries_file_mtime(self):
asset = 'js/GameBoard.js'
expected_version = int(os.path.getmtime(
os.path.join(self.server.app.static_folder, asset)
))
async with self.server.app.test_request_context('/dashboard'):
url = self._static_url()(asset)
self.assertEqual(url, f'/files/{asset}?v={expected_version}')
async def test_static_url_tolerates_missing_asset(self):
async with self.server.app.test_request_context('/dashboard'):
url = self._static_url()('js/DoesNotExist.js')
self.assertEqual(url, '/files/js/DoesNotExist.js?v=0')
async def test_dashboard_page_versions_every_static_asset(self):
client = self.server.app.test_client()
response = await client.get('/dashboard')
self.assertEqual(response.status_code, 200)
body = await response.get_data(as_text=True)
references = re.findall(r'(?:href|src)="(/files/[^"]+)"', body)
self.assertTrue(references, 'dashboard page referenced no static assets')
for reference in references:
self.assertRegex(reference, r'\?v=\d+$', f'unversioned static asset: {reference}')
if __name__ == '__main__':
unittest.main()