Skip to content

refactor: Extract Ali je vroče read model - #418

Open
jalezi wants to merge 5 commits into
chore/prepare-repo-for-agentsfrom
refactor/ali-je-vroce-read-model
Open

refactor: Extract Ali je vroče read model#418
jalezi wants to merge 5 commits into
chore/prepare-repo-for-agentsfrom
refactor/ali-je-vroce-read-model

Conversation

@jalezi

@jalezi jalezi commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Stacking note

This PR is stacked on #416 and should be reviewed against chore/prepare-repo-for-agents, not directly against main.

That matters because the new frontend-check workflow runs yarn typecheck, which depends on the TypeScript configuration fix from #416. The unrelated chore/upgrade-yarn-deps branch is no longer part of this branch chain.

Why

The Ali je vroče flow had several read-model responsibilities spread across the Solid hook, query helpers, network helpers, and an optimistic-update utility. Understanding station selection required following localStorage preference migration, station shape conversion, current-hotness display mapping, raw Datasette/Vremenar transformations, cache lookup behavior, and optimistic placeholders across multiple modules.

This PR deepens that module boundary by putting the station/current-hotness read model behind a plain TypeScript interface while preserving the existing UI-facing useWeatherData() return shape.

What changed

  • Added code/ali-je-vroce/model/readModel.ts as a plain read-model module.
  • Moved selected-station preference reading/writing, legacy migration, validation, and storage-error fallback into the read model.
  • Moved station preference conversion and current-hotness display-field mapping into the read model.
  • Moved raw Datasette station-row and Vremenar/percentile response transformations into the read model.
  • Replaced the old optimistic-update utility with read-model-owned optimistic display policy and removed the orphaned file.
  • Added Node test coverage for preference migration, storage failure fallback, malformed preferences, station conversion, display mapping, optimistic display, and raw response transformation.
  • Added yarn test and wired yarn test plus yarn typecheck into the website build workflow.

Impact

The page behavior is intended to stay the same, with a few deliberate improvements:

  • Station-switch optimistic cache lookup now uses the same string station id shape as the query cache.
  • Malformed stored station preferences reset to the default station instead of leaking invalid shapes into UI state.
  • Invalid/non-finite percentile values now fail fast instead of risking an incorrect current-hotness bucket.
  • Preference storage errors still degrade gracefully, so blocked/unavailable localStorage does not break page initialization or station switching.

Follow-up

Created #417 for the next related slice: reducing duplicated query/cache fallback policy across hooks/queries.ts, utils/prefetching.ts, and hooks/useWeatherData.ts.

Validation

  • yarn test
  • yarn typecheck
  • yarn build

@jalezi jalezi added javascript Pull requests that update Javascript code typescript Typescript migration github_actions Pull requests that update GitHub Actions code labels Jun 21, 2026
@jalezi
jalezi requested a review from Copilot June 21, 2026 06:58
@jalezi
jalezi changed the base branch from main to chore/prepare-repo-for-agents June 21, 2026 07:01
@jalezi
jalezi marked this pull request as ready for review June 21, 2026 07:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extracts the “Ali je vroče” station/current-hotness read model into a plain TypeScript module (with tests) while keeping the existing useWeatherData() UI-facing shape, and wires yarn test + yarn typecheck into CI.

Changes:

  • Introduces code/ali-je-vroce/model/readModel.ts to own preference storage/migration, station shape conversion, current-hotness display mapping, optimistic display policy, and raw response transforms.
  • Updates useWeatherData + helpers.ts to use the read model and removes the old optimistic-update utility.
  • Adds Node test coverage for the read model and runs yarn test + yarn typecheck in the build workflow.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsconfig.json Adjusts TS path-mapping configuration comment / baseUrl usage.
skills-lock.json Adds skills lock scaffold for agent-skill management.
README.md Documents canonical vs generated agent skills locations and sync command.
package.json Adds sync-skills, updates postinstall, adds test and typecheck scripts.
code/ali-je-vroce/utils/optimistic.ts Removes legacy optimistic-update helper (now owned by read model).
code/ali-je-vroce/model/readModel.ts New read-model module (prefs, transformations, optimistic display).
code/ali-je-vroce/model/readModel.test.ts New Node tests for the read-model behavior.
code/ali-je-vroce/hooks/useWeatherData.ts Switches UI hook to read-model state/transformations + new optimistic policy.
code/ali-je-vroce/helpers.ts Delegates station/current-hotness transforms to the read model.
CLAUDE.md Points Claude Code at the canonical agent instructions.
AGENTS.md Adds canonical, tool-neutral agent instruction entrypoint and skills guidance.
.gitignore Ignores generated .claude/skills copy.
.github/workflows/copilot-setup-steps.yml Adds Copilot coding-agent setup workflow for consistent environment.
.github/workflows/build.yaml Runs yarn test and yarn typecheck in CI before yarn build.
.github/instructions/typescript-solid-eleventy.instructions.md Adds scoped frontend/TS/Solid/Eleventy guidance.
.github/instructions/testing.instructions.md Adds scoped testing/validation guidance.
.github/instructions/security.instructions.md Adds scoped security guidance for code/workflows/content/data.
.github/instructions/performance.instructions.md Adds scoped performance guidance for site + frontend.
.github/instructions/documentation.instructions.md Adds scoped docs/content guidance.
.github/instructions/code-review.instructions.md Adds scoped code review guidance for this repo.
.github/copilot-instructions.md Adds canonical repository-wide Copilot instructions.
.github/agents/software-engineer.agent.md Adds “Software Engineer” agent definition.
.github/agents/reviewer.agent.md Adds “Reviewer” agent definition.
.github/agents/debugger.agent.md Adds “Debugger” agent definition.
.github/agents/architect.agent.md Adds “Architect” agent definition.
.agents/skills/write-tests/SKILL.md Adds reusable “write-tests” skill.
.agents/skills/setup-component/SKILL.md Adds reusable “setup-component” skill.
.agents/skills/refactor-code/SKILL.md Adds reusable “refactor-code” skill.
.agents/skills/generate-docs/SKILL.md Adds reusable “generate-docs” skill.
.agents/skills/debug-issue/SKILL.md Adds reusable “debug-issue” skill.
.agents/skills/code-review/SKILL.md Adds reusable “code-review” skill.

Comment thread code/ali-je-vroce/model/readModel.ts
Comment thread code/ali-je-vroce/hooks/useWeatherData.ts Outdated
Comment thread code/ali-je-vroce/hooks/useWeatherData.ts Outdated
@jalezi
jalezi requested review from ntadej and stefanb June 21, 2026 07:10
@jalezi jalezi changed the title [codex] Extract Ali je vroče read model refactor: Extract Ali je vroče read model Jun 21, 2026
@kesma01

kesma01 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Heads up before this merges: it would silently revert #487.

This PR's model/readModel.ts queries the percentiles climatology with
date__exact=${date}. That is the bug #487 fixed on 2026-07-29 — average_percentiles
is a 365-slot climatology whose date column carries an arbitrary year label (currently
ending 2026-06-30), so an exact-date lookup matches nothing once the calendar crosses it,
and every station throws "Percentiles not found". #487 changed it to month-day matching
(date__endswith=-MM-DD), which queries the climatology by day-of-year — what it actually
is — so the lookup never expires.

This PR was last updated ~5 weeks before that fix and is based on
chore/prepare-repo-for-agents rather than main, so it does not contain it.

Before merging: rebase onto post-#487 main and reconcile the query to date__endswith.
Note that no test or CI check would catch this — the failure only appears after the
labelled year rolls over.

@ntadej

ntadej commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

@jalezi, could you rebase this one on recent state of the webpage?

@jalezi
jalezi force-pushed the refactor/ali-je-vroce-read-model branch from 49103f9 to 5796efd Compare August 16, 2026 18:19
@jalezi

jalezi commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Fixed — rebased onto current main (was based on chore/prepare-repo-for-agents, 5+ weeks stale) and reconciled the query. helpers.ts now goes through monthDayForCurrentHotnessPercentiles() in the read model, which returns the MM-DD used with date__endswith=-${date} (leap-day 02-29→02-28 fallback included), matching #487.

While rebasing I also caught that the read-model's ProcessedStation type would have silently dropped the name_station field main added after this branch diverged (shown as "postaja: ..." in TemperatureDisplay) — threaded that through as well. And found that readModel.test.ts was never actually running in CI (vitest.config.ts only picks up tests/unit/**, this file used node:test and lived under code/) — moved it to tests/unit/ on vitest so it's covered going forward.

Verified with tsc --noEmit (0 errors) and vitest run (111/111 passing).

@jalezi

jalezi commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

@ntadej Done — rebased onto current main. Also reconciled a regression the rebase surfaced (see the comment above to @kesma01) and moved the read-model tests so they actually run in CI. Ready for another look.

jalezi and others added 5 commits August 16, 2026 20:31
…rebase

Rebasing onto main dropped the ProcessedStation type alias and the
name_station field the read-model refactor's base branch never had:
main added StationModel.name_station (shown as "postaja: ..." in
TemperatureDisplay) after this branch diverged, so toProcessedStations,
toStationPreference, and toProcessedStation silently lost it. Restored
the alias and threaded name_station/station through the round trip,
keeping it optional on StationPreference so existing cached preferences
without it still migrate instead of resetting to default.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… runs them

vitest.config.ts only includes tests/unit/**/*.test.ts; the read model
tests lived at code/ali-je-vroce/model/readModel.test.ts using node:test,
so `yarn test` (what build.yaml runs) silently never executed them.
Moved the file to tests/unit/ and switched the runner import to vitest,
keeping node:assert for assertions. Also renamed
dateForCurrentHotnessPercentiles to monthDayForCurrentHotnessPercentiles
since it now returns MM-DD, not a full date.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jalezi
jalezi force-pushed the refactor/ali-je-vroce-read-model branch from 5796efd to ea52aff Compare August 16, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

github_actions Pull requests that update GitHub Actions code javascript Pull requests that update Javascript code preview-deploy typescript Typescript migration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants