Files
F-r-ldraledigplannerare/backend/tests/fixtures/fk_min_foraldrapenning_synthetic.html
T
jacobh2 97a7200c1a Parse transferable days from FK instead of deriving them
The scraper never read "överlåtbara dagar" from Försäkringskassan. It only
visited ansok-och-planera-foraldrapenning#/valjdagar and derived the
reserved/transferable split in build_snapshot, assuming transferable days
are spent before reserved ones. On real data that gave 49 for the user and
0 for the partner where FK states 129 and 71.

The assumption cannot be repaired: reserved-first, transferable-first,
proportional and cap-based models were all checked against real figures and
none reproduces FK's accounting (reserved-first fits the partner but is 10
days off for the user). FK publishes the real numbers per parent per tier on
the min-foraldrapenning page, which the scraper had never visited.

- Scrape the "Dagar ni kan föra över" panel after the valjdagar extraction,
  summing sjukpenningnivå + lägstanivå per parent. The totals are not
  literals on the page. Parse only direct-child <p> elements: the first
  group embeds a tooltip with decoy "45 dagar"/"90 dagar" text.
- build_snapshot accepts the reported value and derives reserved days from
  it; the old arithmetic remains only as a fallback. An implausible FK value
  degrades to that fallback rather than failing the fetch.
- Record provenance in transferable_days_reported (migration 006) and badge
  derived values as estimates in the dashboard breakdown. Drop the footnote's
  claim that at most 150 days are transferable — real data contradicts it as
  a per-family figure.
- Select the child's section by name when FK lists several; never guess.

Verified against a live BankID scrape: scraped 240/101/139 with 129
transferable, deduced partner 240/169/71 with 71, both flagged as reported.

Incidental fixes found along the way:

- The fetch router never forwarded the partner's transferable figure to
  persist_partner_deduction, so the partner's stored snapshot would have kept
  the flawed split even once the parse landed.
- 'deduced' snapshots were labelled "Manually entered" by a two-way ternary
  over a three-value union. Replaced with a compiler-checked exhaustive map.
- Alembic resolved its database from alembic.ini alone, ignoring
  APP_SQLITE_PATH, so migrations silently targeted the developer's real
  database even when pointed elsewhere. env.py now resolves it, preferring
  -x sqlalchemy.url, then a real APP_SQLITE_PATH, then the ini value.
- backend/captures/ was not ignored: the root pattern was anchored as
  /captures/ despite a comment saying scraper dumps must never be tracked.
- CLAUDE.md quoted test counts and coverage percentages that had gone stale,
  which made a correct verification report look suspect. Gate thresholds kept.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXPBfr1v7F71t6QcbHCaaT
2026-09-20 09:11:53 +02:00

90 lines
3.9 KiB
HTML

<!DOCTYPE html>
<!--
Synthetic stand-in for a captured FK "min-foraldrapenning" e-service page
(https://www.forsakringskassan.se/privatperson/mina-sidor/alla-e-tjanster/min-foraldrapenning).
This is NOT a real Försäkringskassan page dump — it is a hand-built,
minimal HTML fragment that reproduces only the DOM structure and CSS
selectors that `app/scrapers/fk_scraper.py::_extract_transferable_days`
reads (see `_SEL.MIN_FP_*` / `_SEL.BARN_RUBRIK` / `_SEL.PANEL_FORA_OVER_DAGAR`
/ `_SEL.FORA_OVER_GROUP` / `_SEL.MINFP_LABEL` / `_SEL.EXPANDABLE_BUTTON` in
that module). All names, day counts, and amounts below are fictitious (see
F1 of the scraper/config/ops security audit — real captures never belong
in the repo; `captures/` is gitignored).
The tooltip block under "Du kan föra över" deliberately repeats the
fixed "45 dagar"/"90 dagar" boilerplate text FK shows on the real page
(how many days each guardian may transfer to another *person*, not the
other parent) so tests genuinely exercise `:scope > p` scoping rather
than passing by luck on a fixture with no decoy text.
-->
<html lang="sv">
<head>
<meta charset="UTF-8">
<title>Min föräldrapenning - Försäkringskassan (synthetic fixture)</title>
</head>
<body>
<div class="min-fp">
<div class="barn-sektion">
<div class="barn-header">
<h2 class="barn-rubrik"><strong>Testbarn</strong></h2>
</div>
<div class="panel-fora-over-dagar">
<div class="expandable-paragraph expandable-paragraph--open">
<h3 class="expandable-paragraph__heading heading--h4">
<button type="button" class="expandable-paragraph__button" aria-expanded="true"
aria-controls="fkui-vue-element-0002">
<span class="expandable-paragraph__icon"></span>
Dagar ni kan föra över
</button>
</h3>
<div id="fkui-vue-element-0002" class="expandable-paragraph__container"
style="overflow: hidden;">
<div class="expandable-paragraph__content">
<div class="fora-over-group">
<div class="tooltip__container">
<h4 class="minfp-label">Du kan föra över</h4>
<button class="tooltip__button" type="button" aria-label="Mer information">?</button>
</div>
<div class="tooltip">
<div class="tooltip__bubble">
<h4 class="tooltip__header">Vem kan du föra över dagar till?</h4>
<div class="tooltip__body">
<div>
<strong>Förälder</strong>
<div>Du kan föra över alla dina dagar till barnets andra förälder.</div>
<p><strong>Annan person</strong></p>
<div>Du kan föra över dagar till en annan person som är folkbokförd med barnet.</div>
<p>Varje vårdnadshavare kan föra över 45 dagar till andra personer.
Om du har ensam vårdnad kan du föra över 90 dagar till andra personer.</p>
</div>
</div>
</div>
</div>
<p>84 dagar på sjukpenningnivå</p>
<p>45 dagar på lägstanivå</p>
</div>
<div class="fora-over-group">
<h4 class="minfp-label">Annan förälder kan föra över</h4>
<p>26 dagar på sjukpenningnivå</p>
<p>45 dagar på lägstanivå</p>
</div>
<!---->
<div class="reserverade-dagar">
<h4 class="heading--h6">Reserverade dagar</h4>
<p>Vissa dagar är reserverade och går inte att föra över till någon annan.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>