Skip to content

fix(atemschutz): put the Trupp-Typ rules in the Stammdaten, not in its name - #411

Merged
DeepDiver1975 merged 3 commits into
mainfrom
fix/trupp-types-stammdaten
Sep 20, 2026
Merged

DeepDiver1975 merged 3 commits into
mainfrom
fix/trupp-types-stammdaten

Conversation

@DeepDiver1975

@DeepDiver1975 DeepDiver1975 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #398. Closes #397.

The defect

AtemschutzTrupp decided two operational rules by comparing the Trupp's designation against a compiled-in literal:

public const string ChemicalTruppDesignation = "CSA-Trupp";
public static int RequiredMemberCount(string designation) =>
    IsChemicalTrupp(designation) ? ChemicalMemberCount : StandardMemberCount;

The designation comes from md_trupp_types — a free-text list the brigade edits in the Stammdaten editor. A Wehr writing CSA Trupp, CSA-Trupp (Chemikalienschutz) or Chemietrupp got a two-person CSA-Trupp accepted without complaint, on a 30-minute Einsatzzeit instead of 20. No warning, no fallback, nothing in the Einsatztagebuch. The rule simply was not there any more, and the crew under the suits would have been the ones to find out.

The change

A Trupp-Typ carries its own Stärke and Einsatzzeit. The rules follow the type however it is named, and a brigade can give a Sicherheitstrupp or a type of its own the same treatment.

Before — just a list of names; the rules lived in the app.

Trupp-Typen before
After — Stärke and Einsatzzeit per row; the CSA-Trupp is three people on 20 minutes because its row says so.

Trupp-Typen after

The three global Einsatzzeit settings (AGT / CSA / LPA) are gone from Einstellungen, replaced by the per-type value; the Rückzugsdruck and the ILS-Intervalle stay where they were.

Where the crew-size rule lives — the one deliberate departure from #398

The issue proposes that Register "takes the required crew size and duration as arguments it already half-takes". I went the other way, and this is the part worth reviewing:

  • The number would carry no information. The host is the Stammdaten master and a version-mismatched client is refused before /masterdata is ever fetched, so both sides always hold the same MasterDataSet and would compute the same number. A rule you satisfy by restating it is not validation.
  • The honest variant is a reference cycle. Having CommandApplier look the type up itself means passing a MasterDataSet into Incident.AddScbaTrupp — and MasterDataSet lives in LageBuch.Persistence, which already references LageBuch.Domain.
  • Today's domain rejection was not a safety net anyway. RemoteIncidentSession.Send is fire-and-forget (_ = SendAsync(...)), so the host's 400 lands in a discarded Task: the ETB line, sent as a separate command, succeeds while the Trupp silently never appears. Locally the same ArgumentException propagates out of AddTruppCommand and crashes the UI — the failure Atemschutz: If Truppnummer already exists, application crashes #217 already fixed once. What actually protects the operator is CanAddTrupp greying out the button.

So the per-type count is enforced in ScbaViewModel, the only layer that can read the Stammdaten. The domain keeps what it can prove on its own — and that check is now stronger than before: a crew must fill its positions contiguously from Truppführer, so {Truppführer, 2. Truppmann} with a hole in the middle is rejected where the old duplicate-only check let it through.

Trade-off, stated plainly: a hand-crafted sync command could register a two-person "CSA-Trupp". The UI cannot produce one.

Migration

Existing stores migrate once, on first open, mapping the two old names to the rules the old code gave them (CSA-Trupp → 3 people, LPA-Trupp → the longer Einsatzzeit) and carrying over the Einsatzzeiten that store actually had configured — the three md_settings rows the brigade edited in Einstellungen — with the old IncidentSettings defaults only as a per-key fallback. Nothing changes for a brigade using the shipped spellings; a brigade that had renamed the type gets a row it can now correct itself.

An earlier revision of this PR wrote the shipped defaults here instead and then deleted those settings, which silently lengthened the Einsatzzeit for any brigade that had shortened it. Caught in review, fixed in 3ce3146.

That mapping is the only place a Trupp-Typ name is compared against a literal, it runs once, and:

  • it is shared with the JSON parser, so a brigade restoring from an older exported file and one simply reopening its masterdata.db end up with identical rows;
  • it is gated on a marker row, not on the column being absent — a store whose column was dropped and restored (exactly what the new drift sweep does) must not be mistaken for a first migration and have the brigade's own edits overwritten;
  • memberCount is clamped, never rejected, at every entrance. This parses a payload that crossed a trust boundary, and HomeViewModel catches only the JSON exception types around a sync host's /masterdata — throwing would escape that catch and leak the open hub connection instead of failing the join cleanly.

An older exported JSON, where truppTypes is an array of bare strings, still imports. The reverse is not true: a new sample file opened by an older release fails the import cleanly (Import fehlgeschlagen), which matters because the README links demo-stammdaten.json directly.

#397, folded in

This PR adds the first new md_* columns since #397 was filed — the exact case it describes. The drop-column sweep it asks for is now a test, and it found a real gap on its first run: md_personnel's optional columns had no AddColumnIfMissing line. No shipped version ever lacked them, so nothing was broken in practice, but nothing would have caught it either.

Verification

  • dotnet build clean: analyzers at AnalysisMode=All, StyleCop, warnings as errors.
  • dotnet test: 1362 passed, 0 failed, 1 pre-existing skip.
  • make samples and make screenshots regenerated. docs/screenshots/stammdaten-editor.png is byte-identical — it renders the Fahrzeuge section, which did not change.
  • New coverage: the store's one-shot migration (including that a second open changes nothing and a later edit survives), the legacy bare-string JSON branch asserting the same mapping as the store so the two entrances cannot drift, the clamp, StammdatenCatalogue.Find, the TruppTypesSection editor, an unlisted designation falling back rather than blocking, and the crew-gap rejection.

Not covered by tests, and worth a human doing once before release: opening a real pre-existing masterdata.db and confirming Trupp-Typen reads CSA-Trupp at 3 / 20.

🤖 Generated with Claude Code

…s name

"CSA-Trupp" and "LPA-Trupp" were compiled-in literals that AtemschutzTrupp
matched the designation against: the first decided whether a Trupp needed
three people, both picked which Einsatzzeit was suggested. But the Trupp-Typen
are a list the brigade edits freely, so a Wehr writing "CSA Trupp",
"CSA-Trupp (Chemikalienschutz)" or "Chemietrupp" got a two-person CSA-Trupp
accepted without complaint, on 30 minutes instead of 20 -- no warning, nothing
in the Einsatztagebuch.

A Trupp-Typ now carries its own Staerke and Einsatzzeit, so the rules follow
the type however it is named and a brigade can define its own. The three global
Einsatzzeit settings (AGT/CSA/LPA) are replaced by the per-type value; the
Rueckzugsdruck and the ILS intervals stay where they were.

The per-type crew size is enforced in ScbaViewModel, the only layer that can
read the Stammdaten -- not threaded into AtemschutzTrupp.Register. Passing the
number in would mean growing the sync wire format to re-check a value the
caller just derived from the same master data, and having CommandApplier look
it up itself would need MasterDataSet inside the domain, which is a reference
cycle. The domain keeps what it can prove on its own, and that check is now
stronger: a crew must fill its positions contiguously from Truppfuehrer, so
{Truppfuehrer, 2. Truppmann} with a hole in the middle is no longer accepted.

Existing stores migrate once, on first open, mapping the two old names to the
values the old rule gave them -- so nothing changes for a brigade using the
shipped spellings. That mapping is the only place a Trupp-Typ name is compared
to a literal, it is shared with the JSON parser so a restored backup and a
reopened masterdata.db agree, and it is gated on a marker row rather than on
the column being absent, so a repaired store is not mistaken for a first
migration.

Also closes #397: EnsureSchema's reconciliation was three hand-written lines,
and a column added without one would break every existing store while a fresh
one looked fine. The drop-column sweep it asks for is now a test -- it found
md_personnel's optional columns unguarded on its first run.

Fixes #398
Closes #397

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Claude finished @DeepDiver1975's task in 2m 25s —— View job


Reviewing PR #411

  • Read repo instructions (CLAUDE.md / AGENTS.md)
  • Gather context: PR description, diff vs actual parent commit (HEAD~1, since origin/main has since diverged with unrelated merges)
  • Review domain changes (AtemschutzTrupp, TruppMember)
  • Review Stammdaten/persistence changes (MasterDataSet, MasterDataStore, migration)
  • Review view-model / UI changes (ScbaViewModel, TruppTypesSection, MasterDataEditorView)
  • Review tests for coverage
  • Post review feedback

Summary

This is a well-scoped, well-reasoned fix. Read through the domain (AtemschutzTrupp, TruppMember), the Stammdaten model/store (MasterDataSet, MasterDataStore, MasterDataJson), the ScbaViewModel/TruppTypesSection/editor XAML, and the associated test files.

The core design holds up. Moving crew size and Einsatzzeit onto the TruppType row instead of matching designation strings is the right fix, and I agree with the stated trade-off of enforcing crew size in ScbaViewModel rather than threading a MasterDataSet into the domain — the reference-cycle argument (LageBuch.Persistence → LageBuch.Domain) is correct, and AtemschutzTrupp.ValidateCrew's contiguous-position check (src/LageBuch.Domain/Atemschutz/AtemschutzTrupp.cs:177) is strictly stronger than the old duplicate-only check without needing the Stammdaten at all.

Migration logic checked out. MasterDataStore.MigrateTruppTypeDefaults (src/LageBuch.Persistence/MasterData/MasterDataStore.cs:247) gates on a marker row rather than column absence, which the new Every_repairable_column_is_restored_after_being_dropped test (tests/LageBuch.Persistence.Tests/MasterDataStoreTests.cs:394) exercises correctly: it drops and restores the member_count/max_duration_minutes columns but leaves the md_settings marker row untouched, so a repaired store is correctly not re-migrated (verified by tracing through — the marker key isn't dropped since it's a md_settings row, not a column of md_trupp_types). LegacyTruppTypeDefaults is confirmed to be the single shared translation table used by both the SQLite widening and MasterDataJson.ParseTruppTypes's bare-string branch, as claimed.

Sync surface unchanged, as claimed. Confirmed AddScbaTruppCommand (src/LageBuch.Sync/SyncCommand.cs:93) carries no crew-size field — the per-type count genuinely isn't threaded onto the wire, matching the PR's stated rationale.

Minor observations (non-blocking)

  1. MaxDurationMinutes isn't clamped on read, unlike MemberCount. MasterDataStore.ReadTruppTypes (src/LageBuch.Persistence/MasterData/MasterDataStore.cs:403) clamps member_count via TruppType.ClampMemberCount but passes max_duration_minutes straight through, and MasterDataJson.ParseTruppTypes (src/LageBuch.Persistence/MasterData/MasterDataSet.cs:465) does the same for the JSON import path. A masterdata.db or import file hand-edited (or corrupted) to carry max_duration_minutes <= 0 would flow through ScbaViewModel.ApplyDefaultMaxDuration into NewMaxDurationMinutes, and AtemschutzTrupp.Register's ArgumentOutOfRangeException.ThrowIfNegativeOrZero(maxDurationMinutes) (AtemschutzTrupp.cs:132) would then throw on AddTrupp — the same UI-crash shape Atemschutz: If Truppnummer already exists, application crashes #217 fixed for the Truppnummer field. The EINSATZZEIT NumericUpDown in ScbaView.axaml has Minimum="1", which may coerce a sub-1 bound value on render, but that's relying on Avalonia's control behavior rather than an explicit guard at the data boundary the way TruppType.ClampMemberCount does it. Worth a ClampMaxDuration (or similar) alongside ClampMemberCount if you want the same defense-in-depth on this field that member count already gets — low severity given it requires a hand-edited store/file, but it's the identical trust-boundary pattern the PR's own doc-comments call out for MemberCount.
    Fix this →

  2. RequiresThirdMember uses >= AtemschutzTrupp.MaxMemberCount (ScbaViewModel.cs:294) rather than == 3. Since MemberCount is clamped to [StandardMemberCount, MaxMemberCount] everywhere it's read, this is currently equivalent to == MaxMemberCount and not a bug — just flagging that it reads as intentionally future-proofed for a MaxMemberCount bump, which would need TruppRole to actually grow a fourth position too (the doc-comment on MaxMemberCount already notes this constraint, so this is consistent, not a gap).

Everything else — the crew-gap validation, the JSON legacy bare-string import path, the drop-column sweep test that caught the real md_personnel gap, the CHANGELOG entry, and the docs/master-data.md/master-data.example.json updates — is accurate and consistent with the code. Nice catch on the #397 sweep finding a real gap on its first run.

…it too

Two follow-ups to the same change.

#418 is the practitioner's answer to #398: a Strahlenschutztrupp is also a
three-person Trupp, but on the full 30 minutes rather than a CSA-Trupp's 20.
It needs no code -- it is a Stammdaten row now -- so it joins the shipped
examples in docs/master-data.example.json and docs/samples/demo-stammdaten.json.
Keeping both in the demo set is deliberate: two three-person types with
*different* Einsatzzeiten is precisely what a rule keyed off the designation
could never express, so the sample now demonstrates the point rather than
merely benefiting from it. The issue's second ask, that the third crew field
not be labelled "(CSA)", was already done earlier on this branch.

The review on #411 found the other one: MaxDurationMinutes crossed the trust
boundary unclamped, unlike MemberCount. A zero or negative value out of a
hand-edited masterdata.db or an imported file reached
AtemschutzTrupp.Register's ThrowIfNegativeOrZero from inside a fire-and-forget
mutation -- the UI-crash shape #217 fixed once already. ClampMaxDurationMinutes
now guards all three entrances: the SQLite read, the JSON parse, and the
editor's ToValues, which the review did not name but is the same boundary and
already clamps the crew size on the very next argument.

It is a floor only. A crew size has a structural ceiling because TruppRole
fixes how many people fit on the sheet; an Einsatzzeit has none, and a brigade
running a four-hour LPA must not find that silently shortened. The editor's
Maximum is a convenience for the spinner, not a rule about Atemschutz.

The review's other observation -- RequiresThirdMember reading >= MaxMemberCount
rather than == 3 -- it flagged as consistent rather than a defect, and it is
left alone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975

DeepDiver1975 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Pushed 4444244, picking up #418 and the review above.

#418 — Strahlenschutztrupp

Three people like a CSA-Trupp, but the full 30 minutes. With this PR that is a Stammdaten row, not a code change, so it goes into the two shipped examples (docs/master-data.example.json, docs/samples/demo-stammdaten.json) and nowhere else — there are no compiled-in Trupp-Typ defaults to update, since master data is never compiled into the app.

Keeping both three-person types in the demo set is deliberate rather than incidental: two three-person types with different Einsatzzeiten (20 and 30) is exactly what a rule keyed off the designation could never have expressed. The sample now demonstrates the fix instead of merely benefiting from it, and DemoIncidentTests asserts the pair so it stays that way.

The issue's second point was already done earlier on this branch: ScbaView.axaml:83 reads Header="2. TRUPPMANN", not "2. TRUPPMANN (CSA)". I've added A_three_person_type_that_is_not_the_CSA_one_also_reveals_the_third_name so it is pinned by a test with a name that contains no "CSA" at all, rather than left to inspection.

The issue's "Zu klären" — that 30 minutes is one brigade's practice, not a universal rule — needs nothing: it lands in the Stammdaten, so it is a Voreinstellung a Wehr can change, which is the whole intent of #398.

Review finding 1 — the unclamped Einsatzzeit: taken, and widened slightly

Correct, and the reasoning about the #217 crash shape is right. Added TruppType.ClampMaxDurationMinutes and applied it at three entrances — the two you named plus TruppTypesSection.ToValues, which you didn't, but which is the same boundary and already clamps the crew size on the very next argument, so leaving it out would have been an odd asymmetry.

Floor only, no ceiling. A crew size has a structural ceiling because TruppRole fixes how many people fit on the monitoring sheet; an Einsatzzeit has none. Capping at the NumericUpDown's 180 would silently shorten a brigade running a four-hour LPA, and that spinner bound is a convenience, not a rule about Atemschutz. So 0 and -5 become 1 — visibly wrong and correctable — while 240 survives untouched. Clamp, don't reinterpret: mapping an invalid value to 30 would have looked right and hidden the corruption.

Covered at each entrance: MasterDataJsonTests.Parse_clamps_an_unrunnable_einsatzzeit_rather_than_throwing (asserting it parses rather than throws, since that is the property protecting the hub connection), MasterDataStoreTests.A_stored_einsatzzeit_no_countdown_can_run_is_clamped_on_read, and MasterDataSectionTests.TruppTypes_ToValues_clamps_an_einsatzzeit_no_countdown_can_run.

Review finding 2 — RequiresThirdMember using >=: left alone

Agreed with your own read that it is consistent rather than a gap, so no change.

Stammdaten → Trupp-Typen, now

Trupp-Typen with the Strahlenschutztrupp

Build clean with all analyzers; 1366 tests passing (was 1362), nothing regressed. make samples and make screenshots re-run.

🤖 Generated with Claude Code

…the defaults

Found in review of this PR, and the more serious of the three because it was
silent and pointed the wrong way for a safety parameter.

The Einsatzzeiten were never constants at runtime. AGT, CSA and LPA each had a
row in md_settings, edited in Stammdaten -> Einstellungen, and ScbaViewModel
read them from there. The one-time migration ignored all three and wrote the
shipped defaults onto the rows instead -- and EnsureSchema then deleted the
settings, so the real values were gone. A Wehr that had shortened its
CSA-Trupp to 15 minutes came up at 20: longer under air than it had decided on,
with no warning and nothing in the Einsatztagebuch. The comment above the
DELETE even claimed the migration was allowed to read them; it did not.

It reads them now, before the delete, and uses them per row -- csa for the
CSA-Trupp, lpa for the LPA-Trupp, agt for everything else -- with the old
IncidentSettings defaults only as a per-key fallback. The same fix applies to
the legacy JSON branch, where the file being imported still carries those three
keys in its settings object: the two entrances agreeing with each other is only
worth anything if they agree on the brigade's own numbers.

Also from the review: the Atemschutz form's Einsatzzeit spinner stopped at 120
while the Stammdaten editor offered 180, so a Trupp-Typ could be configured and
then not registered at its own Einsatzzeit. Both bind one bound now, generous
enough for a four-hour LPA, with a test that they cannot drift apart.

The review's remaining observation -- RequiresThirdMember reading
>= MaxMemberCount rather than == 3 -- it called consistent rather than a
defect, and it is left alone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975

Copy link
Copy Markdown
Contributor Author

Review addressed in 3ce3146. All three findings were real; one of them was a genuine defect I had introduced and then described wrongly in this PR's own text.

1. Migration discarded the brigade's configured Einsatzzeiten — fixed

This one was right and it was the serious one. The Einsatzzeiten were never constants at runtime: AGT, CSA and LPA each had a row in md_settings, edited in Stammdaten → Einstellungen, and ScbaViewModel read them from there. MigrateTruppTypeDefaults wrote the shipped defaults onto the rows regardless, and EnsureSchema then deleted the settings — so the real values were gone with no way back. A Wehr that had set Einsatzzeit CSA = 15 came up at 20: longer under air than it decided on, silently, on first launch. For a safety parameter that is the wrong direction.

The reviewer also caught that my comment above the DELETE claimed the migration "is allowed to read them" when it did not. It does now: the three keys are read before the delete and applied per row — csa → CSA-Trupp, lpa → LPA-Trupp, agt → everything else — with the old IncidentSettings defaults only as a per-key fallback.

This also corrects a claim in the PR description. I wrote that migration meant "nothing changes for a brigade using the shipped spellings". That was only true for a brigade that had never opened Einstellungen. It is true now.

2. Same loss at the JSON entrance — fixed

Correct, and the framing was the useful part: "the two entrances agreeing with each other just means they are consistently wrong together." A legacy file carries those three keys in its own settings object, which ParseSettings no longer reads. ParseTruppTypes now reads them from the same root and feeds the translation, so restoring a pre-#398 backup and reopening a pre-#398 masterdata.db produce the same rows — and the brigade's rows, not the shipped ones.

MasterDataStoreTests.The_migration_carries_over_the_einsatzzeiten_the_brigade_had_configured and MasterDataJsonTests.A_legacy_file_keeps_the_einsatzzeiten_it_had_configured are deliberately mirror images, plus a per-key fallback test for a store that never overrode them.

3. Three disagreeing spinner bounds — fixed

Also correct: no ceiling in the data, 180 in the editor, 120 on the Atemschutz form. A Trupp-Typ configured above 120 could not be registered at the Einsatzzeit its own row specifies. Both spinners now bind one MaxEditableDurationMinutes (240, enough for a four-hour LPA), documented as a UI affordance rather than an Atemschutz rule, with The_two_einsatzzeit_spinners_offer_the_same_range so they cannot drift apart again.

4. RequiresThirdMember using >= — left alone

Per your own read that it is consistent rather than a gap.


Build clean with all analyzers; 1370 tests passing (was 1366).

One consequence worth flagging for whoever merges: the earlier commits on this branch already contained the broken migration, so any masterdata.db opened with a build from 08ce132/4444244 has the marker row set and will not re-migrate. That only affects someone who tested this branch locally — no released version has ever run this migration — but if you did try it on a real store, delete the trupp_type_defaults_migrated row from md_settings before re-testing.

🤖 Generated with Claude Code

@DeepDiver1975
DeepDiver1975 merged commit c6d409d into main Sep 20, 2026
6 checks passed
@DeepDiver1975
DeepDiver1975 deleted the fix/trupp-types-stammdaten branch September 20, 2026 19:58
DeepDiver1975 added a commit that referenced this pull request Sep 20, 2026
The changelog rule was never actually written down. AGENTS.md and
CONTRIBUTING.md said "add a changelog entry as its own file", which does not
say how many, and #431 arrived with seven fragments — one per commit,
describing a single feature layer by layer, plus an unrelated build fix.

State the rule in both places and in the PR template: exactly one entry per
pull request, describing what the change does for the reader rather than the
layers it was built in. A PR carrying an unrelated fix folds it into the same
entry; if the two cannot share an entry they are two pull requests.

Then make the existing fragments follow it. Seven merged pull requests had
contributed more than one entry, 22 files between them, now 7 — #313, #310,
#355, #390, #395, #411 and #431. The prose is rewritten rather than
concatenated, but nothing a reader would act on is dropped: schema versions,
migrated JSON keys, file-format compatibility, what changes on first open and
what stays untouched all survive, as do the ticket references. The remaining
27 fragments were already one-per-PR and are untouched.

`towncrier build --draft` renders 34 entries across Added, Changed, Fixed and
Security.

Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant