mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-06 23:12:22 +02:00
static/js/document.js is 17,579 lines and is about to be decomposed behind a
re-export wrapper. 51 test files read it off disk and grep it as text, and 28
of those slice it with `src.split("function a", 1)[1].split("function b", 1)[0]`
-- "the region between a and b", which only means what the test intends while a
and b are neighbours in one file. Several also hard-code the file's two-space
indentation, which no extracted module reproduces. Left alone, the first
extraction makes those assertions cover the wrong region, and an `x in region`
check passes while covering more than it was written for.
tests/helpers/document_source is the one place that names the file now:
- document_source() is the entry plus everything under static/js/document/,
so a membership assertion keeps finding its subject wherever it lands;
- function_body()/declaration() locate a construct by name in whichever
module defines it and end at its real closing brace, so neither moving it
nor moving its neighbour changes the region.
The rewrite only collapses a slice when the old terminator sat at the
construct's end. 28 slices deliberately span a whole family of functions --
everything from _docxHexColor to exportAsDocx -- and collapsing one to its
first member drops what the assertions look for, so those stay as they are and
are listed in KNOWN_ADJACENCY_SLICES, to be converted as each family becomes a
module. That list may only shrink.
Two guards come with it:
- test_document_source_test_hygiene fails on a direct read of the entry file
and on any new adjacency slice;
- test_frontend_module_graph resolves every relative import under static/
(718 of them, none broken today) and requires the document module set to
stay in the sw.js precache, since the worker fetches the URLs it lists and
not what they import.
test_document_module_api pins the 38 default-export keys and 29 named exports
by loading the module in a browser and reading what it actually exports, rather
than grepping for the literal object -- after extraction that object may be
assembled from imports, and a source-shape check would pass while the export
was broken.
No JavaScript moves here. static/ is untouched.
72 lines
3.0 KiB
Python
72 lines
3.0 KiB
Python
from pathlib import Path
|
|
import re
|
|
from tests.helpers.document_source import document_source, function_body
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DOCUMENT_JS = document_source()
|
|
CHAT_JS = (ROOT / "static/js/chat.js").read_text(encoding="utf-8")
|
|
APP_JS = (ROOT / "static/app.js").read_text(encoding="utf-8")
|
|
SETTINGS_JS = (ROOT / "static/js/settings.js").read_text(encoding="utf-8")
|
|
INDEX_HTML = (ROOT / "static/index.html").read_text(encoding="utf-8")
|
|
CHAT_ROUTE = (ROOT / "routes/chat_routes.py").read_text(encoding="utf-8")
|
|
|
|
|
|
def test_visible_or_minimized_linked_document_is_sent_as_chat_context():
|
|
function = function_body("getChatDocumentId")
|
|
assert "pane?.isConnected" in function
|
|
assert "document.body.classList.contains('doc-view')" not in function
|
|
assert "style?.display !== 'none'" in function
|
|
assert "style?.visibility !== 'hidden'" in function
|
|
assert "const id = visiblyOpen ? activeDocId : minimizedId" in function
|
|
assert "_minimizedDocId" in function
|
|
|
|
|
|
def test_browser_explicitly_reports_absent_document_context():
|
|
assert "? (documentModule?.isPanelOpen?.() ? 'visible' : 'minimized')" in CHAT_JS
|
|
assert ": 'none'" in CHAT_JS
|
|
|
|
|
|
def test_chat_and_app_share_one_document_module_instance():
|
|
chat_version = re.search(r"from './document\.js\?v=([^']+)'", CHAT_JS).group(1)
|
|
app_version = re.search(r"from './js/document\.js\?v=([^']+)'", APP_JS).group(1)
|
|
assert chat_version == app_version
|
|
|
|
|
|
def test_all_runtime_document_imports_share_one_module_url():
|
|
runtime_files = [
|
|
ROOT / "static/app.js",
|
|
ROOT / "static/index.html",
|
|
ROOT / "static/sw.js",
|
|
ROOT / "static/js/chat.js",
|
|
ROOT / "static/js/chatStream.js",
|
|
ROOT / "static/js/chatRenderer.js",
|
|
ROOT / "static/js/emailLibrary.js",
|
|
ROOT / "static/js/slashCommands.js",
|
|
]
|
|
versions = {
|
|
match
|
|
for path in runtime_files
|
|
for match in re.findall(r"document\.js\?v=([A-Za-z0-9_-]+)", path.read_text(encoding="utf-8"))
|
|
}
|
|
assert versions == {"20260916docctx2"}
|
|
|
|
|
|
def test_server_fallback_is_legacy_only_when_ui_state_is_absent():
|
|
assert "legacy_active_doc_fallback = not active_doc_state" in CHAT_ROUTE
|
|
assert CHAT_ROUTE.count("if not active_doc and legacy_active_doc_fallback:") == 3
|
|
|
|
|
|
def test_document_writing_action_uses_document_style_not_email_style():
|
|
assert "const generalStyle = String(generalData.document_writing_style || '').trim()" in DOCUMENT_JS
|
|
assert "emailResponse = await fetch(`/api/email/style${suffix}`" in DOCUMENT_JS
|
|
assert "GENERAL WRITING STYLE:" in DOCUMENT_JS
|
|
assert "EMAIL CONVENTIONS:" in DOCUMENT_JS
|
|
assert 'id="set-document-style"' in INDEX_HTML
|
|
assert 'id="set-document-style-extract"' in INDEX_HTML
|
|
assert "'/api/auth/settings/document-style/extract'" in SETTINGS_JS
|
|
assert "spinner.createWhirlpool(14)" in SETTINGS_JS
|
|
assert 'id="set-document-style-save"' in INDEX_HTML
|
|
assert 'M17 21v-8H7v8' in INDEX_HTML
|
|
assert "document_writing_style: styleEl.value" in SETTINGS_JS
|