Add test suite (box rules, Python, QML against a fake Jellyfin server) and local preview jobs
CI / Vérifications et paquet (push) Successful in 48s
CI / Release Gitea (push) Skipped

- freebox-jellyfin test: box-only rules (ES5, QtQuick 2.5, qmldir, singletons),
  tooling unit tests, qmltestrunner on tests/qml against fake_server.py
- freebox-jellyfin fake-server and preview --fake-server
- package enforces the box rules; CI runs the tests
- JetBrains run configs: Local Preview, Local Preview (faux serveur), Tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
stilobiqueandClaude Opus 5.5 committed 2026-11-15 00:08:03 +01:00
1 parent d0d019ac1e
commit 1b2acae316
19 files changed
+2097 -17

No files matched your search

+113
View File
@@ -0,0 +1,113 @@
import tempfile
import textwrap
import unittest
from pathlib import Path
from freebox_jellyfin import boxrules
def es5(code):
return boxrules.check_es5("x.js", textwrap.dedent(code))
class Es5Test(unittest.TestCase):
def test_detects_es6(self):
cases = {
"let a = 1;": "let",
"const b = 2;": "const",
"list.map(x => x * 2);": "fléchée",
"var s = `a${b}`;": "gabarit",
"class A {}": "class",
"for (var x of list) {}": "for…of",
"f(...args);": "...",
}
for code, expected in cases.items():
with self.subTest(code=code):
problems = es5(code)
self.assertEqual(len(problems), 1, problems)
self.assertIn(expected, problems[0])
def test_ignores_comments_strings_and_regexes(self):
code = """
// let a = 1; x => y
/* const b = 2;
`gabarit` */
var s = "let c = 3 => ...rest";
var t = 'const d = `e`';
var url = /^https?:\\/\\//i; // (regex avec « // »)
var clean = text.replace(/\\/+$/, "");
var letter = constant + lettuce; // mots qui commencent par let/const
var ok = a >= b;
"""
self.assertEqual(es5(code), [])
def test_reports_line_numbers(self):
self.assertEqual(es5("var a;\n\nlet b;\n"), ["x.js:3: « let » (ES6) : utiliser var"])
class ImportsTest(unittest.TestCase):
def test_qtquick_version(self):
self.assertEqual(boxrules.check_imports("a.qml", "import QtQuick 2.5\n"), [])
self.assertEqual(boxrules.check_imports("a.qml", "import QtQuick 2.0\n"), [])
self.assertEqual(len(boxrules.check_imports("a.qml", "import QtQuick 2.6\n")), 1)
self.assertEqual(len(boxrules.check_imports("a.qml", "import QtQuick 2.15\n")), 1)
def test_forbidden_imports(self):
self.assertEqual(len(boxrules.check_imports("a.qml", "import QtQuick.Controls 1.4\n")), 1)
self.assertEqual(len(boxrules.check_imports("a.qml", 'import "."\n')), 1)
self.assertEqual(boxrules.check_imports("a.qml", '// import QtQuick 2.15\nimport "../Shared"\n'), [])
class DirectoriesTest(unittest.TestCase):
def make_app(self, files):
folder = tempfile.TemporaryDirectory()
self.addCleanup(folder.cleanup)
root = Path(folder.name)
for name, content in files.items():
path = root / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(textwrap.dedent(content), encoding="utf-8")
return root
def test_valid_layout(self):
app = self.make_app({
"Main.qml": 'import QtQuick 2.5\nimport "Components"\nimport "Shared"\nItem {}\n',
"Components/qmldir": "Button 1.0 Button.qml\n",
"Components/Button.qml": 'import QtQuick 2.5\nimport "../Shared"\nItem { width: Theme.size }\n',
"Shared/qmldir": "singleton Theme 1.0 Theme.qml\n",
"Shared/Theme.qml": "pragma Singleton\nimport QtQuick 2.5\nQtObject { property int size: 1 }\n",
})
self.assertEqual(boxrules.check_directories(app), [])
def test_missing_qmldir_and_entries(self):
app = self.make_app({
"Main.qml": 'import "Components"\nimport "Other"\nItem {}\n',
"Components/qmldir": "Button 1.0 Button.qml\nGone 1.0 Gone.qml\n",
"Components/Button.qml": "Item {}\n",
"Components/Card.qml": "Item {}\n",
"Other/Thing.qml": "Item {}\n",
})
problems = "\n".join(boxrules.check_directories(app))
self.assertIn("Card.qml absent", problems)
self.assertIn("Gone.qml introuvable", problems)
self.assertIn("Other/: importé mais sans qmldir", problems)
def test_singleton_cycles(self):
app = self.make_app({
"Main.qml": 'import "Shared"\nItem {}\n',
"Shared/qmldir": "singleton Theme 1.0 Theme.qml\nsingleton Style 1.0 Style.qml\nCard 1.0 Card.qml\n",
"Shared/Theme.qml": "QtObject {}\n",
"Shared/Style.qml": "QtObject {}\n",
"Shared/Card.qml": "Item { width: Theme.size }\n",
})
problems = "\n".join(boxrules.check_directories(app))
self.assertIn("plusieurs singletons", problems)
self.assertIn("Card.qml: utilise le singleton Theme", problems)
def test_real_app_is_clean(self):
from freebox_jellyfin.project import APP_DIR
self.assertEqual(boxrules.check_app(APP_DIR), [])
if __name__ == "__main__":
unittest.main()