Repository navigation
Besluitenzaal-kamer (optie C): kern + 9 tests #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| """growkit_besluitenzaal — Slice: besluitenzaal-kamer (optie C, KairOS 9 sept). | ||
|
|
||
| Rendert de 'wacht op de Baas'-kamer uit register + voorstellen-wachtrij. | ||
| Data blijft bij de aanroeper (privé); de kern is puur tekst → HTML, offline testbaar. | ||
|
|
||
| Bronnen: | ||
| - besluiten-index.md: ONBEVESTIGD-regels staan onder de kop | ||
| 'ONBEVESTIGD (...)' en beginnen met [BSL-xxx] (ingesprongen toegestaan). | ||
| - voorstellen: elk item {titel, opties[], aanbeveling, geldig, bron}. | ||
| HARD: max 3 opties en een verplichte aanbeveling — anders ongeldig. | ||
| - bevestigd: lijst register-regels voor het 'loopt automatisch'-blok. | ||
|
|
||
| Huisstijl: papier #F4F1E9, inkt #19202C, oranje #F2673F (wacht-accent), | ||
| lime #D9F65C (register-accent). Kamervolgorde: wacht → voorstellen → register. | ||
| """ | ||
| import html as _html | ||
| import re | ||
|
|
||
| MAX_OPTIES = 3 | ||
|
|
||
| _ONB_KOP = re.compile(r"^ONBEVESTIGD", re.I) | ||
| _BSL = re.compile(r"^\s*(\[BSL-\d+\].+)$") | ||
|
|
||
|
|
||
| def onbevestigd_uit_index(tekst: str) -> list[str]: | ||
| """Regels [BSL-...] onder de ONBEVESTIGD-kop; de rest niet.""" | ||
| wacht: list[str] = [] | ||
| in_onb = False | ||
| for regel in tekst.splitlines(): | ||
| s = regel.strip() | ||
| if _ONB_KOP.match(s) and not s.startswith("[BSL-"): | ||
| in_onb = True | ||
| continue | ||
| if s.startswith("[BSL-") or _BSL.match(regel): | ||
| if in_onb: | ||
| wacht.append(_BSL.match(regel).group(1).strip()) | ||
| continue | ||
| if s and not s.startswith(("#", "-", " ", "<!--")) and not _ONB_KOP.match(s): | ||
| in_onb = False | ||
| return wacht | ||
|
|
||
|
|
||
| def parseer_voorstel(tekst: str, bron: str) -> dict: | ||
| """Eén voorstellingsbestand naar dict. geldig=False bij >3 opties of geen aanbeveling.""" | ||
| titel = "" | ||
| opties: list[str] = [] | ||
| aanbeveling = "" | ||
| for regel in tekst.splitlines(): | ||
| s = regel.strip() | ||
| if s.startswith("# ") and not titel: | ||
| titel = s[2:].strip() | ||
| elif re.match(r"^(Optie|optie)\s+[A-Za-z0-9]+:", s): | ||
| opties.append(s) | ||
| elif re.match(r"^(Aanbeveling|aanbeveling):", s): | ||
| aanbeveling = s.split(":", 1)[1].strip() | ||
| geldig = len(opties) <= MAX_OPTIES and bool(aanbeveling) | ||
| return { | ||
| "titel": titel or bron, | ||
| "opties": opties, | ||
| "aanbeveling": aanbeveling, | ||
| "geldig": geldig, | ||
| "bron": bron, | ||
| } | ||
|
|
||
|
|
||
| def render(index_tekst: str, voorstellen: list[dict], bevestigd: list[str]) -> str: | ||
| """De besluitenzaal-kamer: wacht-op-baas → voorstellen → register.""" | ||
| wacht = onbevestigd_uit_index(index_tekst) | ||
|
|
||
| wacht_html = "".join( | ||
| f'<div class="wacht-item">{_html.escape(s)}</div>' for s in wacht | ||
| ) or "<p><i>niets wacht op de Baas</i></p>" | ||
|
|
||
| voor_html = "" | ||
| for v in voorstellen: | ||
| cls = "voor" if v["geldig"] else "voor voor-ongeldig" | ||
| opts = "".join(f"<li>{_html.escape(o)}</li>" for o in v["opties"]) | ||
| adv = _html.escape(v["aanbeveling"]) or "<i>geen aanbeveling — ongeldig voorstel</i>" | ||
| voor_html += ( | ||
| f'<div class="{cls}"><h3>{_html.escape(v["titel"])}</h3>' | ||
| f"<ul>{opts}</ul><p><strong>Aanbeveling:</strong> {adv}</p></div>" | ||
| ) | ||
| if not voor_html: | ||
| voor_html = "<p><i>geen open voorstellen</i></p>" | ||
|
|
||
| reg_html = "".join( | ||
| f'<div class="bsl-item">{_html.escape(s)}</div>' for s in bevestigd | ||
| ) or "<p><i>—</i></p>" | ||
|
|
||
| return f"""<!doctype html><html><head><meta charset="utf-8"><title>Besluitenzaal — Agent Family</title> | ||
| <style> | ||
| :root{{--papier:#F4F1E9;--inkt:#19202C;--oranje:#F2673F;--lime:#D9F65C}} | ||
| body{{font-family:'DM Sans',sans-serif;background:var(--papier);color:var(--inkt);max-width:1100px;margin:2em auto;padding:0 1em;line-height:1.55}} | ||
| h1,h2,h3{{font-family:'Space Grotesk',sans-serif}}h1{{color:var(--oranje)}} | ||
| .kamer-wacht{{border-left:4px solid var(--oranje);background:#fff;padding:1em;margin:1em 0}} | ||
| .wacht-item{{padding:.5em .8em;border-bottom:1px solid #eee}} | ||
| .voor{{border-left:4px solid var(--lime);background:#fff;padding:1em;margin:1em 0}} | ||
| .voor-ongeldig{{opacity:.6}} | ||
| .kamer-register{{border-left:4px solid var(--lime);background:#fff;padding:1em;margin:1em 0}} | ||
| label{{font-family:'DM Mono',monospace;font-size:.8em;text-transform:uppercase;letter-spacing:.08em}} | ||
| </style></head><body> | ||
| <h1>Besluitenzaal</h1> | ||
| <section class="kamer-wacht"><label>Wacht op de Baas ({len(wacht)})</label> | ||
| {wacht_html}</section> | ||
| <section class="kamer-voor"><label>Voorstellen met opties</label> | ||
| {voor_html}</section> | ||
| <section class="kamer-register"><label>Loopt automatisch — register</label> | ||
| {reg_html}</section> | ||
| </body></html>""" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """Tests voor growkit_besluitenzaal — Slice: besluitenzaal-kamer (optie C, KairOS 9 sept). | ||
|
|
||
| Rendert de 'wacht op de Baas'-kamer uit register + voorstellen-wachtrij: | ||
| - ONBEVESTIGD/open besluiten uit besluiten-index.md (sectie na de ONBEVESTIGD-kop) | ||
| - voorstellen-wachtrij: *.md met max 3 opties + 1 aanbeveling | ||
| - HTML-output in fabriek-huisstijl, kamervolgorde: wacht-op-baas → register → hartslag (aanroeper beslist) | ||
| Offline: alle bronnen als tekst/lijst binnen, geen bestands-I/O in de kern. | ||
| """ | ||
| import sys | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | ||
|
|
||
| from kern import growkit_besluitenzaal as bz | ||
|
|
||
| INDEX_TEKST = """--- | ||
| titel: "besluiten index" | ||
| --- | ||
|
|
||
| BEVESTIGD: | ||
| [BSL-001] PLAN-EERST-regel | 08-09 | ||
| [BSL-002] Licentie MIT | 07-09 | ||
|
|
||
| ONBEVESTIGD (gemeld, nog niet gecureerd — NIET als groen licht; vraag de Baas): | ||
| [BSL-099] Testbesluit wacht | 09-09 | ||
| """ | ||
|
|
||
| VOORSTEL_TEKST = """# Titel van voorstel | ||
| Geadviseerd door: KairOS | ||
| Optie A: doe dit | ||
| Optie B: laat het | ||
| Aanbeveling: A""" | ||
|
|
||
|
|
||
| class TestOnbevestigdUitIndex(unittest.TestCase): | ||
| def test_pakt_regels_onder_onbevestigd_kop(self): | ||
| wacht = bz.onbevestigd_uit_index(INDEX_TEKST) | ||
| self.assertEqual(len(wacht), 1) | ||
| self.assertIn("BSL-099", wacht[0]) | ||
|
|
||
| def test_bevestigd_blijft_buiten_wacht(self): | ||
| wacht = bz.onbevestigd_uit_index(INDEX_TEKST) | ||
| self.assertFalse(any("BSL-001" in r for r in wacht)) | ||
|
|
||
| def test_leeg_register_geen_wacht(self): | ||
| self.assertEqual(bz.onbevestigd_uit_index("BEVESTIGD:\n [BSL-001] x | 08-09"), []) | ||
|
|
||
|
|
||
| class TestVoorstelParsing(unittest.TestCase): | ||
| def test_opties_en_aanbeveling_gepakt(self): | ||
| v = bz.parseer_voorstel(VOORSTEL_TEKST, "2026-09-09-test.md") | ||
| self.assertEqual(v["titel"], "Titel van voorstel") | ||
| self.assertEqual(len(v["opties"]), 2) | ||
| self.assertIn("A", v["aanbeveling"]) | ||
|
|
||
| def test_te_veel_opties_wordt_afgekeurd(self): | ||
| tekst = VOORSTEL_TEKST + "\nOptie C: meer\nOptie D: te veel" | ||
| v = bz.parseer_voorstel(tekst, "x.md") | ||
| self.assertFalse(v["geldig"]) # max 3 opties is HARD | ||
|
|
||
| def test_zonder_aanbeveling_ongeldig(self): | ||
| tekst = "# T\nOptie A: x\nOptie B: y" | ||
| v = bz.parseer_voorstel(tekst, "x.md") | ||
| self.assertFalse(v["geldig"]) | ||
|
|
||
|
|
||
| class TestRender(unittest.TestCase): | ||
| def test_kamer_toont_wacht_en_register(self): | ||
| html = bz.render( | ||
| index_tekst=INDEX_TEKST, | ||
| voorstellen=[bz.parseer_voorstel(VOORSTEL_TEKST, "x.md")], | ||
| bevestigd=["[BSL-001] PLAN-EERST-regel | 08-09"], | ||
| ) | ||
| self.assertIn("BSL-099", html) # wacht op de Baas | ||
| self.assertIn("Titel van voorstel", html) # voorstellen-wachtrij | ||
| self.assertIn("BSL-001", html) # register eronder | ||
|
|
||
| def test_leeg_wacht_geeft_rustige_staat(self): | ||
| html = bz.render(index_tekst="", voorstellen=[], bevestigd=[]) | ||
| self.assertIn("niets wacht", html) | ||
|
|
||
| def test_huisstijl_kleuren_aanwezig(self): | ||
| html = bz.render(index_tekst=INDEX_TEKST, voorstellen=[], bevestigd=[]) | ||
| self.assertIn("#F4F1E9", html) # papier | ||
| self.assertIn("#19202C", html) # inkt | ||
| self.assertIn("#F2673F", html) # oranje (wacht-op-baas accent) | ||
| self.assertIn("#D9F65C", html) # lime (register accent) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a normal Markdown
besluiten-index.mdsection such as## ONBEVESTIGD,sbegins with#, so this condition never enablesin_onband every following[BSL-...]entry is omitted from the “Wacht op de Baas” room. Accept Markdown heading prefixes (and terminate at the next heading) so the documented index can be rendered rather than always showing the empty state.Useful? React with 👍 / 👎.