52b7c20c2a
Testy / Testy warstwy logicznej (silnik) (pull_request) Successful in 10m30s
Testy / Testy warstwy prezentacji (dostęp do baz) (pull_request) Successful in 9m28s
Testy / Build obrazu silnika B (swisseph) (pull_request) Successful in 15s
Testy / Kontrola składni wszystkich warstw (pull_request) Successful in 10s
Testy / Testy warstwy logicznej (silnik) (push) Successful in 11m5s
Testy / Testy warstwy prezentacji (dostęp do baz) (push) Successful in 9m31s
Testy / Build obrazu silnika B (swisseph) (push) Successful in 15s
Testy / Kontrola składni wszystkich warstw (push) Successful in 10s
build / build (push) Successful in 2m49s
Regresja: „Skompiluj" przeliczało horoskop od nowa z OKROJONYM zestawem opcji (tylko system domów + zodiak), więc jeśli przy horoskopie policzyłeś stacje, tabele (żywioły, faza Księżyca…) albo porównanie domów — w podsumowaniu ich NIE było. Zamiast pokazać to, co policzono, liczyło uboższą wersję. Zostaje czysty przelicz (bez trzymania dużego wyniku w przeglądarce), ale z TYMI SAMYMI opcjami co przy horoskopie: - `formsync`: synchronizuje między zakładkami też opcje — checkboxy (stacje, tabele) i wielo-checkbox (porównanie domów). Wcześniej umiał tylko `.value`. - „Skompiluj" (formularz): dostaje te same opcje; `compile_build` i `compile_pdf` przekazują je do logiki (stations/tables/house_systems). `compile.js` wysyła je w payloadzie PDF-a. - Wspólny plik `_result_tables.html`: podsumowanie renderuje DOKŁADNIE te same tabele co „Horoskop" (porównanie domów, stacje, aspekty, paralele, antyscja, żywioły/faza/godziny, Lots…). Każda sekcja pokazuje się tylko, gdy jej dane są w wyniku — opcja niepoliczona → sekcji nie ma (zgodnie z prośbą). (TODO: przełączyć też chart.html na ten include, by widoki nie mogły się rozjechać — na razie zgodność pilnowana ręcznie, jest komentarz w pliku.) Weryfikacja: render wspólnego pliku na bogatym wyniku pokazuje wszystkie sekcje. Testy: +8 (opcje niesione w /compile i /compile/pdf, sync checkboxów/multi, wspólny include). Prezentacja 202. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
195 lines
7.6 KiB
Python
195 lines
7.6 KiB
Python
"""Zakładka „Skompiluj" — zbiorczy raport (PRE-23).
|
|
|
|
Raport składa się z trzech kawałków liczonych w różnych miejscach: horoskopu
|
|
(serwer), interpretacji natalnej i predykcji okresowych (magazyn przeglądarki).
|
|
Pilnujemy, żeby zakładka umiała je zebrać, a przede wszystkim — żeby POWIEDZIAŁA,
|
|
czego brakuje. Niekompletny raport, o którym dowiadujesz się dopiero z PDF-a,
|
|
byłby najgorszym wynikiem.
|
|
"""
|
|
import pathlib
|
|
|
|
from starlette.testclient import TestClient
|
|
|
|
APP = pathlib.Path(__file__).resolve().parents[1] / "app"
|
|
TPL = (APP / "templates" / "compile.html").read_text(encoding="utf-8")
|
|
BASE = (APP / "templates" / "base.html").read_text(encoding="utf-8")
|
|
JS = (APP / "static" / "compile.js").read_text(encoding="utf-8")
|
|
NATAL_JS = (APP / "static" / "natal.js").read_text(encoding="utf-8")
|
|
INTERPRET = (APP / "templates" / "interpret.html").read_text(encoding="utf-8")
|
|
MAIN = (APP / "main.py").read_text(encoding="utf-8")
|
|
|
|
|
|
def _client():
|
|
import os
|
|
|
|
os.environ.pop("APP_PASSWORD", None) # bez bramki logowania w teście
|
|
from app.main import app
|
|
|
|
return TestClient(app)
|
|
|
|
|
|
# ───────────────────────────────── nawigacja i trasa ─────────────────────
|
|
|
|
def test_tab_is_in_the_menu():
|
|
assert 'href="/compile"' in BASE and "Skompiluj" in BASE
|
|
|
|
|
|
def test_get_renders_empty_form():
|
|
r = _client().get("/compile")
|
|
assert r.status_code == 200
|
|
assert "Złóż podsumowanie" in r.text
|
|
|
|
|
|
def test_routes_exist():
|
|
assert '@app.get("/compile"' in MAIN and '@app.post("/compile"' in MAIN
|
|
|
|
|
|
# ─────────────────────────── kolejność w raporcie ────────────────────────
|
|
|
|
def test_report_order_matches_the_brief():
|
|
"""Prośba partnerów: najpierw imię i nazwisko, potem wprowadzone dane, potem
|
|
RYSUNEK kosmogramu, a dopiero po nim interpretacja natalna i predykcje."""
|
|
person = TPL.index('id="reportPerson"')
|
|
wheel = TPL.index("wheel_svg")
|
|
natal = TPL.index('id="reportNatal"')
|
|
preds = TPL.index('id="reportPredictions"')
|
|
assert person < wheel < natal < preds
|
|
|
|
|
|
def test_person_name_heads_the_report():
|
|
assert 'id="reportPerson"' in TPL
|
|
assert "form.person" in TPL
|
|
|
|
|
|
# ───── wszystkie rysunki w raporcie i w PDF (nie tylko koło) ─────
|
|
# Zasada: co pokazujemy na stronie, ma trafić do podsumowania i do PDF-a.
|
|
|
|
def test_report_shows_every_chart_figure():
|
|
"""Raport «Skompiluj» pokazuje wszystkie rysunki, nie tylko koło."""
|
|
for cls in ("wheel-fig", "aspectarian-fig", "declination-fig", "antiscia-fig"):
|
|
assert cls in TPL, f"brak {cls} w raporcie"
|
|
|
|
|
|
def test_compile_page_renders_all_figures():
|
|
"""Handler /compile liczy wszystkie rysunki do podglądu raportu."""
|
|
for var in ("aspectarian_svg", "declination_svg", "antiscia_svg"):
|
|
assert var in MAIN, f"/compile nie ustawia {var}"
|
|
|
|
|
|
def test_pdf_bundles_all_figures_in_print_theme():
|
|
"""compile_pdf składa KOMPLET rysunków (motyw druku) i wysyła jako `figures`."""
|
|
assert '"figures": figures' in MAIN
|
|
for call in (
|
|
'render(chart, theme="print")',
|
|
'render_aspectarian(chart, theme="print")',
|
|
'render_declination(chart, theme="print")',
|
|
'render_antiscia(chart, theme="print")',
|
|
):
|
|
assert call in MAIN, f"PDF nie składa: {call}"
|
|
|
|
|
|
# ──────────────────────── zbieranie materiału z magazynów ────────────────
|
|
|
|
def test_reads_stores_through_their_api_not_raw_storage():
|
|
"""Format danych ma jednego właściciela — moduł, który je zapisuje.
|
|
Sięganie tu wprost do localStorage rozjechałoby się przy pierwszej zmianie."""
|
|
assert "window.astrololoNatal" in JS
|
|
assert "window.astrololoPredictions" in JS
|
|
# chodzi o brak BEZPOŚREDNIEGO dostępu, nie o samo słowo (pada w komentarzu)
|
|
assert "localStorage.getItem" not in JS
|
|
assert "localStorage.setItem" not in JS
|
|
|
|
|
|
def test_stores_are_loaded_on_the_tab():
|
|
for src in ("natal.js", "predictions.js", "compile.js"):
|
|
assert src in TPL, f"brak {src} na zakładce"
|
|
|
|
|
|
def test_stores_load_before_the_assembler():
|
|
"""Szukamy TAGÓW skryptów, nie samych nazw — te padają też w komentarzach."""
|
|
def tag(name):
|
|
return TPL.index('src="/static/' + name + '"')
|
|
|
|
assert tag("natal.js") < tag("compile.js")
|
|
assert tag("predictions.js") < tag("compile.js")
|
|
|
|
|
|
# ─────────────────────────── mówi, czego brakuje ─────────────────────────
|
|
|
|
def test_shows_what_is_missing():
|
|
assert 'id="readiness"' in TPL
|
|
assert "rdy-missing" in JS
|
|
for hint in ("Interpretacje", "Kalendarz"):
|
|
assert hint in JS, f"brak podpowiedzi, gdzie uzupełnić: {hint}"
|
|
|
|
|
|
def test_all_three_parts_are_checked():
|
|
for label in ("Policzony horoskop", "Interpretacja natalna", "Predykcje okresowe"):
|
|
assert label in JS
|
|
|
|
|
|
# ───────────────────────────── natalna zapamiętywana ─────────────────────
|
|
|
|
def test_natal_is_captured_on_interpret_tab():
|
|
assert "natal.js" in INTERPRET
|
|
assert 'id="natalNote"' in INTERPRET
|
|
|
|
|
|
def test_natal_store_keeps_a_single_entry():
|
|
"""Natalna jest JEDNA — dotyczy momentu urodzenia, nie okresu. Ponowne
|
|
wygenerowanie ma podmienić, nie dokładać."""
|
|
assert "setItem" in NATAL_JS and "push" not in NATAL_JS
|
|
|
|
|
|
def test_natal_only_stores_natal_profile():
|
|
assert "'natal'" in NATAL_JS
|
|
|
|
|
|
def test_full_storage_is_reported():
|
|
assert "pełny" in NATAL_JS
|
|
|
|
|
|
# ─────────────────────────────── bezpieczeństwo ──────────────────────────
|
|
|
|
def test_ai_text_is_escaped_before_injection():
|
|
"""Treść od modelu wstawiamy do DOM — bez ucieczki byłby to wektor wstrzyknięcia."""
|
|
assert "function esc" in JS
|
|
assert "replace(/</g, '<')" in JS
|
|
|
|
|
|
def test_does_nothing_on_other_tabs():
|
|
assert "if (!document.getElementById('readiness')) return;" in JS
|
|
|
|
|
|
# ─────── podsumowanie NIE gubi opcji policzonych przy horoskopie ──────────
|
|
# Regresja 2026-07-28: „Skompiluj" przeliczało horoskop bez stacji/tabel/
|
|
# porównania domów, więc podsumowanie miało braki względem tego, co policzono.
|
|
|
|
def test_compile_form_carries_the_options():
|
|
"""Te same opcje co „Horoskop" (synchronizowane) — inaczej nie da się ich przekazać."""
|
|
for f in ('name="stations"', 'name="tables"', 'name="house_systems"'):
|
|
assert f in TPL, f"brak opcji w formularzu podsumowania: {f}"
|
|
|
|
|
|
def test_compile_handler_recomputes_with_all_options():
|
|
assert "house_systems: list[str] = Form([])" in MAIN
|
|
assert "stations: bool = Form(False)" in MAIN
|
|
assert "house_systems=house_systems" in MAIN # przekazane do logiki
|
|
assert "stations=stations, zodiac=zodiac, tables=tables" in MAIN
|
|
|
|
|
|
def test_compile_pdf_recomputes_with_all_options():
|
|
assert 'stations=bool(data.get("stations"))' in MAIN
|
|
assert 'house_systems=[s for s in (data.get("house_systems")' in MAIN
|
|
|
|
|
|
def test_compile_pdf_payload_includes_options():
|
|
assert "house_systems: multi('house_systems')" in JS
|
|
assert "stations: checked('stations')" in JS
|
|
|
|
|
|
def test_summary_uses_shared_result_tables():
|
|
"""Podsumowanie pokazuje te same tabele co horoskop — jeden wspólny plik,
|
|
żeby nie mogły znowu się rozjechać."""
|
|
assert '{% include "_result_tables.html" %}' in TPL
|