2.0.0 Beta : Self-hosted Release

This commit is contained in:
2026-08-09 02:03:29 +08:00
parent 63a0751aba
commit 37cb05eb70
33 changed files with 810 additions and 31 deletions
+104
View File
@@ -3,6 +3,8 @@ import io
import os
import shutil
import sqlite3
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
@@ -60,6 +62,42 @@ class ApplicationIntegrationTests(unittest.TestCase):
self.assertEqual(response.status_code, 200)
self.assertGreater(len(response.data), 100)
def test_health_endpoint_and_brand_watermark(self):
response = self.client.get('/healthz')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get_json()['brand'], 'Superjacky6')
response = self.client.get('/')
self.assertIn(b'Superjacky6', response.data)
self.assertIn(b'jacky', response.data)
def test_private_visibility_requires_viewer_token(self):
from web.app import create_app
class PrivateConfig(Config):
TESTING = True
SECRET_KEY = 'private-test'
SITE_VISIBILITY = 'private'
VIEWER_TOKEN = 'viewer-secret'
app = create_app(PrivateConfig)
client = app.test_client()
response = client.get('/')
self.assertEqual(response.status_code, 302)
self.assertIn('/access/', response.location)
self.assertEqual(client.get('/healthz').status_code, 200)
with client.session_transaction() as session:
session['_csrf_token'] = 'viewer-csrf'
response = client.post(
'/access/',
data={
'_csrf_token': 'viewer-csrf',
'token': 'viewer-secret',
},
)
self.assertEqual(response.status_code, 302)
self.assertEqual(client.get('/').status_code, 200)
def test_discovery_filters_and_player_medals_render(self):
response = self.client.get('/discover/')
self.assertEqual(response.status_code, 200)
@@ -567,6 +605,72 @@ class DatabaseGovernanceTests(unittest.TestCase):
self.assertTrue(path.is_absolute())
self.assertTrue(path.exists())
def test_external_data_root_bootstraps_without_touching_current_data(self):
current_hashes = {}
for path in (
Path(Config.DB_L2_PATH),
Path(Config.DB_L3_PATH),
Path(Config.DB_WEB_PATH),
):
current_hashes[str(path)] = path.stat().st_size
with tempfile.TemporaryDirectory() as temp_dir:
env = os.environ.copy()
env['YRTV_DATA_DIR'] = temp_dir
result = subprocess.run(
[sys.executable, '-m', 'database.bootstrap'],
cwd=Config.BASE_DIR,
env=env,
capture_output=True,
text=True,
timeout=60,
)
self.assertEqual(result.returncode, 0, result.stderr)
runtime = Path(temp_dir)
expected_tables = {
runtime / 'L1' / 'L1.db': 'raw_iframe_network',
runtime / 'L2' / 'L2.db': 'fact_matches',
runtime / 'L3' / 'L3.db': 'dm_player_features',
runtime / 'Web' / 'Web_App.sqlite': 'team_lineups',
}
for path, table in expected_tables.items():
with self.subTest(path=path):
self.assertTrue(path.exists())
with sqlite3.connect(str(path)) as db:
self.assertEqual(
db.execute('PRAGMA quick_check').fetchone()[0],
'ok',
)
self.assertIsNotNone(db.execute(
"""
SELECT 1 FROM sqlite_master
WHERE type = 'table' AND name = ?
""",
[table],
).fetchone())
for path, size in current_hashes.items():
self.assertEqual(Path(path).stat().st_size, size)
def test_existing_data_migrates_to_external_root(self):
from database.migrate_data import migrate_data
from database.paths import DATABASE_CODE_ROOT
with tempfile.TemporaryDirectory() as temp_dir:
manifest_path = migrate_data(
DATABASE_CODE_ROOT,
temp_dir,
include_imports=False,
)
manifest = json.loads(manifest_path.read_text(encoding='utf-8'))
self.assertEqual(
set(manifest['databases']),
{'L1', 'L2', 'L3', 'Web'},
)
for item in manifest['databases'].values():
self.assertEqual(item['quick_check'], 'ok')
self.assertEqual(len(item['sha256']), 64)
def test_valid_capture_is_identified_from_network_urls(self):
from database.paths import L1_DB
from web.services.import_service import MatchImportService