-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup_studio_contract.py
More file actions
255 lines (217 loc) · 10.1 KB
/
test_setup_studio_contract.py
File metadata and controls
255 lines (217 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
from __future__ import annotations
import re
from dataclasses import dataclass
from typing import Any, cast
from fastapi.testclient import TestClient
from adapter_api import create_app
from core_config import Config
from video_rss_aggregator.bootstrap import AppRuntime, AppUseCases
@dataclass
class _AsyncValue:
value: Any
async def execute(self, *_args, **_kwargs) -> Any:
return self.value
def _build_runtime(config: Config) -> AppRuntime:
runtime_status = {
"ollama_version": "0.6.0",
"local_models": {"qwen3.5:2b-q4_K_M": {}},
"reachable": True,
"database_path": config.database_path,
"storage_dir": config.storage_dir,
"models": list(config.model_priority),
}
return AppRuntime(
config=config,
use_cases=AppUseCases(
get_runtime_status=_AsyncValue(runtime_status),
bootstrap_runtime=_AsyncValue({"models": ["qwen3.5:2b-q4_K_M"]}),
ingest_feed=cast(Any, _AsyncValue(None)),
process_source=cast(Any, _AsyncValue(None)),
render_rss_feed=_AsyncValue("<rss></rss>"),
),
close=lambda: None,
)
client = TestClient(create_app(_build_runtime(Config())))
def class_tokens_for_id(html: str, element_id: str) -> set[str]:
tag_match = re.search(rf'<[^>]*\bid="{re.escape(element_id)}"[^>]*>', html)
assert tag_match is not None
class_match = re.search(r'\bclass="([^"]+)"', tag_match.group(0))
assert class_match is not None
return set(class_match.group(1).split())
def test_setup_css_supports_shell_and_disclosure_layout() -> None:
css = client.get("/static/setup.css")
assert css.status_code == 200
assert "--paper-base" in css.text
assert ".shell" in css.text
assert ".progress-rail" in css.text
assert ".detail-drawer" in css.text
assert ".summary-card" in css.text
assert "@media (max-width: 860px)" in css.text
assert '#setup-progress[data-mobile-open="false"]' in css.text
assert '#mobile-step-toggle[aria-expanded="true"]' in css.text
assert "#6366f1" not in css.text
def test_setup_home_renders_shell_and_collapsed_detail_drawers() -> None:
home = client.get("/")
workbench_classes = class_tokens_for_id(home.text, "setup-workbench")
progress_classes = class_tokens_for_id(home.text, "setup-progress")
prerequisites_panel_classes = class_tokens_for_id(
home.text, "step-panel-prerequisites"
)
configuration_panel_classes = class_tokens_for_id(
home.text, "step-panel-configuration"
)
runtime_panel_classes = class_tokens_for_id(home.text, "step-panel-runtime")
process_panel_classes = class_tokens_for_id(home.text, "step-panel-process")
assert home.status_code == 200
assert 'id="setup-workbench"' in home.text
assert 'id="setup-progress"' in home.text
assert 'id="readiness-summary"' in home.text
assert 'id="blocker-summary"' in home.text
assert 'id="common-fixes"' in home.text
assert 'data-step-id="prerequisites"' in home.text
assert 'data-step-id="configuration"' in home.text
assert 'data-step-id="runtime"' in home.text
assert 'data-step-id="process"' in home.text
assert "shell" in workbench_classes
assert "progress-rail" in progress_classes
assert {"step-panel", "card"} <= prerequisites_panel_classes
assert {"step-panel", "card", "wide"} <= configuration_panel_classes
assert {"step-panel", "card"} <= runtime_panel_classes
assert {"step-panel", "card"} <= process_panel_classes
assert 'id="mobile-step-toggle"' in home.text
assert 'aria-controls="setup-progress"' in home.text
assert 'aria-expanded="false"' in home.text
assert 'id="run-diagnostics"' in home.text
assert 'id="copy-env"' in home.text
assert 'id="runtime-check"' in home.text
assert 'id="bootstrap-models"' in home.text
assert 'id="process-run"' in home.text
assert 'id="runtime-summary"' in home.text
assert 'id="process-summary"' in home.text
assert 'id="advanced-config"' in home.text
assert 'id="runtime-details"' in home.text
assert 'id="process-details"' in home.text
assert re.search(
r'<details[^>]*id="advanced-config"(?![^>]*\bopen\b)[^>]*>', home.text
)
assert re.search(
r'<details[^>]*id="runtime-details"(?![^>]*\bopen\b)[^>]*>', home.text
)
assert re.search(
r'<details[^>]*id="process-details"(?![^>]*\bopen\b)[^>]*>', home.text
)
def test_setup_assets_expose_module_and_top_level_contracts() -> None:
home = client.get("/")
entry_js = client.get("/static/setup.js")
api_js = client.get("/static/setup_api.js")
state_js = client.get("/static/setup_state.js")
view_models_js = client.get("/static/setup_view_models.js")
views_js = client.get("/static/setup_views.js")
assert 'src="static/setup.js" type="module"' in home.text
for response in (entry_js, api_js, state_js, view_models_js, views_js):
assert response.status_code == 200
assert response.headers["content-type"].startswith("text/javascript")
assert 'import { createSetupApi } from "./setup_api.js";' in entry_js.text
assert 'import { createSetupState } from "./setup_state.js";' in entry_js.text
assert (
'import { buildShellSummaryView } from "./setup_view_models.js";'
in entry_js.text
)
assert (
'import { buildProcessSummaryView } from "./setup_view_models.js";'
in entry_js.text
)
assert (
'import { buildProcessFailureView } from "./setup_view_models.js";'
in entry_js.text
)
assert 'import { createSetupViews } from "./setup_views.js";' in entry_js.text
assert "function boot()" in entry_js.text
assert "boot();" in entry_js.text
assert "handleDiagnosticsRun" in entry_js.text
assert "handleRuntimeCheck" in entry_js.text
assert "handleBootstrapModels" in entry_js.text
assert "handleProcessRun" in entry_js.text
assert "runDiagnostics();" not in entry_js.text
assert "export function createSetupApi" in api_js.text
assert "runDiagnostics" in api_js.text
assert "checkRuntime" in api_js.text
assert "bootstrapModels" in api_js.text
assert "runProcess" in api_js.text
assert "export function createSetupState" in state_js.text
assert "beginDiagnosticsCheck" in state_js.text
assert "markConfigurationComplete" in state_js.text
assert "beginRuntimeCheck" in state_js.text
assert "completeRuntimeCheck" in state_js.text
assert "beginProcess" in state_js.text
assert "markProcessSuccess" in state_js.text
assert "markProcessFailure" in state_js.text
assert (
'const STEP_ORDER = ["prerequisites", "configuration", "runtime", "process"]'
in state_js.text
)
assert "export function buildShellSummaryView" in view_models_js.text
assert "export function buildStaleSummaryLabel" in view_models_js.text
assert "export function buildProcessSummaryView" in view_models_js.text
assert "export function buildProcessFailureView" in view_models_js.text
assert "export function createSetupViews" in views_js.text
assert "renderShellState" in views_js.text
assert "renderDiagnosticsSummary" in views_js.text
assert "renderRuntimeSummary" in views_js.text
assert "renderRuntimeDetails" in views_js.text
assert "renderProcessSummary" in views_js.text
assert "renderProcessDetails" in views_js.text
assert "bindMobileStepToggle" in views_js.text
assert 'document.getElementById("mobile-step-toggle")' in views_js.text
assert (
'progressRail.dataset.mobileOpen = expanded ? "true" : "false";'
in views_js.text
)
assert (
'mobileStepToggle.setAttribute("aria-expanded", String(expanded));'
in views_js.text
)
assert "views.bindMobileStepToggle();" in entry_js.text
def test_setup_js_prefers_backend_setup_views_for_state_transitions() -> None:
entry_js = client.get("/static/setup.js")
assert entry_js.status_code == 200
assert "function toDiagnosticsView(report)" in entry_js.text
assert (
'return report.setup_view || { state: report.ready ? "ready" : "blocked" };'
in entry_js.text
)
assert "function toRuntimeView(runtime)" in entry_js.text
assert (
'return runtime.setup_view || { state: runtime.reachable ? "ready" : "blocked" };'
in entry_js.text
)
assert "const diagnosticsView = toDiagnosticsView(report);" in entry_js.text
assert "state.applyDiagnosticsResult(diagnosticsView);" in entry_js.text
assert "const runtimeView = toRuntimeView(runtime);" in entry_js.text
assert "state.completeRuntimeCheck(runtimeView);" in entry_js.text
def test_setup_js_renders_shaped_setup_view_summaries_and_common_fixes() -> None:
entry_js = client.get("/static/setup.js")
assert entry_js.status_code == 200
assert "const diagnosticsView = toDiagnosticsView(report);" in entry_js.text
assert "views.renderDiagnosticsSummary(diagnosticsView);" in entry_js.text
assert "views.renderCommonFixes(diagnosticsView);" in entry_js.text
assert "const runtimeView = toRuntimeView(runtime);" in entry_js.text
assert "renderRuntimeState(runtimeView, runtime);" in entry_js.text
assert (
"renderRuntimeState(runtimeView, { ...runtime, bootstrap: report });"
in entry_js.text
)
def test_setup_views_expose_common_fixes_and_runtime_readiness_copy() -> None:
views_js = client.get("/static/setup_views.js")
assert views_js.status_code == 200
assert "function renderCommonFixes(view)" in views_js.text
assert 'const container = document.getElementById("common-fixes");' in views_js.text
assert "const fixes = Array.isArray(view?.checks)" in views_js.text
assert "view.checks.filter((check) => check.fix)" in views_js.text
assert "function renderRuntimeSummary(runtimeView, runtime)" in views_js.text
assert (
'["Required models", `${requiredModels.length} configured`],' in views_js.text
)
assert '["Available locally", `${localModels.length} ready`],' in views_js.text
assert "runtimeView?.next_action ||" in views_js.text
assert "renderCommonFixes," in views_js.text