Skip to content

chore(api): close the follow-ups of #194 and keep the Api tests under the file-size rule - #209

Merged
mwg-bender[bot] merged 2 commits into
devfrom
chore/060-api-followups
Nov 23, 2026
Merged

mwg-bender[bot] merged 2 commits into
devfrom
chore/060-api-followups

Conversation

@mwg-bender

@mwg-bender mwg-bender Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the API and Api.Tests items of #194 (spec #205). Splits the five Api test files that were over the 400-line rule, pins the stored table and partition names, keeps the Azurite tests on local Azurite only, and makes the storage query test prove the filtering happens in storage.

Change

 MW-GC.EventManager.API/
   Program.cs                      # registrations -> builder.Services.AddTableStores()
   Services/
~    TableNames.cs                 # all seven tables + partitions
+    TableStoreRegistration.cs     # AddTableStores(): one TableStore<T> singleton per table
 MW-GC.EventManager.Api.Tests/
-  EventMetricsTests.cs (624)      -> EventMetricsTests, EventMetricsIfMatchTests, EventMetricsEventRouteTests, EventMetricsBulkReadTests, EventMetricsTestSupport
-  FeedbackTests.cs (573)          -> ClientIpTests, FeedbackLinkTests, FeedbackLikeTests, FeedbackTestSupport
-  CommentApiTests.cs (524)        -> CommentAddTests, CommentListTests, CommentEditTests, CommentDeleteTests, CommentCascadeTests, CommentApiTestSupport
-  ActivityNoteConversionTests (494) -> ActivityNoteConversionTests, ActivityNoteConversionPutTests, ActivityNoteConversionStartupTests, ActivityNoteConversionTestSupport
-  ApiValidationRouteTests (408)   -> ApiValidationRouteTests, GameFieldRouteTests, ActivityFieldRouteTests
-  RetiredCommentsFieldTests.cs    -> RetiredOldTextFieldTests.cs
+  StoredNamesTests.cs             # the one literal pin of every stored table/partition name
+  TableStoreRegistrationTests.cs  # AddTableStores over a mocked TableServiceClient
~  AzuriteSupport(.cs/Tests)       # local-Azurite guard, shared Flow<T>, marker read/restore
~  StorageQueryAzuriteTests.cs     # counts rows storage returns; cascade checked with the raw client
~  ActivityNoteConversionAzuriteTests.cs  # marker restored as found in finally; derived Comment cleaned
~  ApiTestSupport / PartitionedTableMock  # Store/Check take the key; StoreKeyed/CheckKeyed removed

Largest Api test file afterwards: 361 lines (SingleActivityApiTests, untouched).

Azurite guard: EM_AZURITE_CONNECTION must be UseDevelopmentStorage=true, or every endpoint must be on a loopback host (127.0.0.1, localhost, ::1), or it must name devstoreaccount1 together with its own endpoints. Otherwise the tests skip with Azurite test skipped: EM_AZURITE_CONNECTION does not point at local Azurite (...) before any client is built. Account settings with no endpoint (Azure public cloud) never count as local, whatever the account name.

The "activity-note:" hash salt and the names ActivityNoteConversion, ActivityNoteConversionStartup and activity-notes-v1 are unchanged. The salt derives the Comment ids, so changing it would add duplicate Comments on a re-run.

Validation

Base origin/dev 2730911, cold builds (--no-incremental after deleting bin/obj):

errors warnings Api.Tests Web.Tests
base 0 0 495 passed + 4 skipped (499) 727
head 0 0 514 passed + 4 skipped (518) 727
head, with the slot's Azurite (UseDevelopmentStorage=true) + running API 518 passed, 0 skipped

Count preservation (by [TestMethod] name, base vs head): 230 methods / 366 cases -> 235 / 385. Missing 0; moved unchanged 95; renamed 3 (...OldCommentsColumn... -> ...OldTextColumn... x2, RetiredCommentsFieldTests.AnOldCommentsValue... -> RetiredOldTextFieldTests.AnOldTextValue...); added 5 methods / 19 cases (StoredNamesTests 1, TableStoreRegistrationTests 1, AzuriteSupportTests 7 + 9 + 1).

Break-it mutations, each applied, run, then restored. All 8 turned red:

  • M1 TableNames.Games = "Game" -> StoredNamesTests red
  • M2 Event metrics store registered under the Event partition -> TableStoreRegistrationTests red
  • M3 Holiday store registration dropped -> TableStoreRegistrationTests red
  • M4 guard: any named account counts as local -> AzuriteSupportTests 5 red
  • M5 Connection() no longer checks for local Azurite -> AzuriteSupportTests 1 red
  • M6 guard: account with no endpoint counts as local -> AzuriteSupportTests 1 red
  • M7 (Azurite) GetWhereAsync reads the whole partition and filters in memory -> StorageQueryAzuriteTests red
  • M8 (Azurite) Activity delete leaves its Comments -> StorageQueryAzuriteTests red (raw-client check)

The Azurite run left the account as it found it: same marker CompletedUtc, and the same row count in every table before and after.

Live flows (worker, with-slot.sh slot 0, Azurite + API):

flow this branch plain origin/dev
A1 CRUD of Game, Activity, Theme, Holiday, Event; one Comment; Event metrics save/read; one Like PASS PASS
A2 tables in the Azurite account (Tables SDK) = the pinned literal list of 9 PASS PASS
A3 non-local connection string (a listener on the container's own address) PASS: 4 skipped with the guard's message, 0 connections FAIL: 4 failed, 16 connections (no guard on dev; this is the item being fixed)

A2 list on both trees: Activities, ActivityComments, EventMetrics, Events, FeedbackLikes, FeedbackLinks, Games, Holidays, Themes. Themes and Holidays have no GET-one route, so A1 reads them through their list. E2E not run: no Web or E2E file changes.

Notes

mwg-bender Bot added 2 commits November 22, 2026 19:44
… the file-size rule

Split the five Api test files over about 400 lines by behaviour
(EventMetrics, Feedback, Comment API, the old-text conversion and the
route validation tests) into files named for what they test, with the
shared helpers in *TestSupport.cs bases. Every test exists exactly once
afterwards; three are renamed to say "old text" for the retired column.

TableNames now names all seven tables and their partitions, and the
registrations move from Program.cs into AddTableStores (no behaviour
change). StoredNamesTests pins the stored table and partition names as
literals, and TableStoreRegistrationTests checks the extension registers
one store per table under those names, over a mocked service client.

The Azurite tests now run only against local Azurite and skip with the
reason otherwise, before any client exists. The conversion tests put the
marker back as they found it and delete the Comments they caused. The
storage query test counts the rows storage returns, so a list that read
the whole partition and filtered in memory fails it, and checks the
cascade with the raw table client instead of the code under test. The
two Azurite files share one Flow helper, Store/Check take the row key so
StoreKeyed/CheckKeyed are gone, and CommentApiTests.Stored() is inlined.

The "activity-note:" salt is unchanged: it derives the Comment ids, and
changing it would add duplicate Comments on a re-run.

Refs #194, #205
… assertions able to fail

The local-Azurite guard of the Azurite tests decided on the connection
string text. UseDevelopmentStorage=true with a remote
DevelopmentStorageProxyUri, or the devstoreaccount1 account with a remote
TableEndpoint, passed it, and the Tables client then wrote to that remote
host. The guard now builds a TableServiceClient from the string (this
contacts nothing) and runs the tests only when client.Uri.Host is
loopback (127.0.0.1, localhost, ::1). A string the client cannot read
skips, and the skip message names the reason or the refused host. The
"devstoreaccount1 on any host" allowance is gone: the azurite:10002 row
is now refused. UseDevelopmentStorage=TRUE moves to the refused rows,
because Azure.Data.Tables 12.11.0 cannot parse that value.

TableStoreRegistrationTests counted the table clients it had created
itself. A new test counts the service descriptors AddTableStores
registers, so an eighth or a duplicate store registration fails it.
StoredNamesTests compared test literals with test literals. A new test
compares StoredNames.Stores and StoredNames.AllTables with the
production TableNames and FeedbackStore constants. The startup test
registers its stores with AddTableStores() instead of by hand, so it
cannot drift from Program.cs.

Refs #194
@mwg-bender

mwg-bender Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Review fixes (commit 1080de2) and DISPOSITION

This adds one commit on top of 56e0d98. It touches only Api.Tests: AzuriteSupport.cs, AzuriteSupportTests.cs, TableStoreRegistrationTests.cs, StoredNamesTests.cs, ActivityNoteConversionStartupTests.cs. It changes no production file.

Review-fix card

item disposition proof
R1 guard bypass DONE AzuriteSupport.WhyNotLocal builds new TableServiceClient(conn) and runs only when Uri.Host is loopback. A string the client cannot read skips with the reason (MW-GC.EventManager.Api.Tests/AzuriteSupport.cs:58). The two bypass strings are refused (AzuriteSupportTests.cs:48, :49); azurite:10002 moved to refused (:46); the DevelopmentStorageProxyUri=http://127.0.0.1 row is accepted (:27). Mutation G1 (put the PR's text guard back) turns 6 cases red.
R1 deviation DONE, noted The old accepted row usedevelopmentstorage=TRUE; now reads usedevelopmentstorage=true;. Azure.Data.Tables 12.11.0 throws ArgumentException: Connection string parsing error on the value TRUE (probe output is in the evidence), so the Azurite tests could never have built a client from that string. UseDevelopmentStorage=TRUE is now a refused row (AzuriteSupportTests.cs:42); the keyword stays case-free.
R2a registration count DONE TableStoreRegistrationTests.TheExtensionRegistersTheSevenStoresEachOnceAndNothingElse compares the ServiceCollection descriptors' service types with the seven store types (TableStoreRegistrationTests.cs:67). It replaces HasCount(7, clients). Mutation R1 (an eighth store registration in AddTableStores) turns it red.
R2b literal vs literal DONE StoredNamesTests.TheLiteralListsTheOtherTestsUseMatchTheProductionNames compares StoredNames.Stores with TableNames.* (StoredNamesTests.cs:70) and StoredNames.AllTables with TableNames.* plus FeedbackStore.LinksTable/LikesTable (:80). Mutations N1 (TableNames.Games = "Game") and N2 (FeedbackStore.LikesTable = "FeedbackLike") each turn it red.
R3 no duplicate registration DONE ActivityNoteConversionStartupTests.cs:65 calls services.AddTableStores(). The same 3 tests keep the same names. Mutation S1 (drop the Comment store from AddTableStores) turns AStoreThatFailsWhileTheHostBuildsItIsLoggedAndNeverStopsTheHost red.
R4 this table DONE this comment

Original card, #194 items 1 to 9

item disposition proof
#194.1 file size DONE The five files are split by behaviour; the largest of the split files is ActivityNoteConversionTests.cs at 241 lines, and the largest Api test file is SingleActivityApiTests.cs at 361 lines (untouched). Count preservation: 0 tests missing. The PR body's "moved unchanged (95)" is, per the review of #209, more exactly 76 identical, 19 changed only by items 6, 7 and 9 (I did not recount it in this run).
#194.2 pinned names DONE literal pin StoredNamesTests.cs:36; TableNames covers all seven tables (MW-GC.EventManager.API/Services/TableNames.cs:12–:25); Program.cs:16 uses AddTableStores(); TableNames.ActivityPartition seeds at ApiValidationRouteTests.cs:39, DeleteInUseRefusalTests.cs:66, PropertyLimitTests.cs:168
#194.3 storage filtering DONE StorageQueryAzuriteTests.cs:124 counts the rows storage returns ("2, 1"); the cascade is read with the raw client (:75, :130–:135); mutations M7 and M8 were red in the first PR run
#194.4 Azurite conversion tests + guard DONE marker restored in finally (ActivityNoteConversionAzuriteTests.cs:143–:146, :196–:200); seeded rows cleaned (:217); guard AzuriteSupport.cs:58 with rows AzuriteSupportTests.cs:19–:50. README warning OUTSIDE (docs card, #207). CI sets no EM_AZURITE_CONNECTION: MOVED to Nerd (needs .github/).
#194.5 registration extension DONE MW-GC.EventManager.API/Services/TableStoreRegistration.cs:15; tests at TableStoreRegistrationTests.cs:18 and :60
#194.6 duplicates and dead code DONE one shared Flow<T> (AzuriteSupport.cs:88); StoreKeyed/CheckKeyed gone, Store/Check take the key (PartitionedTableMock.cs:33, :41, :47); System.Linq.Expressions dropped from the Comment tests (IDE0005 reports none left); OldActivityRows.OldTextColumn used (ActivityNoteConversionTests.cs:21)
#194.7 vocabulary DONE RetiredOldTextFieldTests.cs:8; harness OldTextConversion (ApiTestSupport.cs:219). DECLINED: renaming ActivityNoteConversion, ActivityNoteConversionStartup and activity-notes-v1 (GLOSSARY keeps them; the conversion is deleted last in 0.6.0). DECLINED: the "activity-note:" hash salt (ActivityNoteConversion.cs:79) stays, because it derives the Comment ids and a change would create duplicate Comments on a re-run.
#194.8 docs OUTSIDE docs card (#207)
#194.9 Stored() middle man DONE inlined to h.StoredComment(...) (e.g. CommentAddTests.cs:36). The commit-type remark is DECLINED (commit-message nit).

Validation of 1080de2 (cold: bin/obj deleted, --no-incremental)

errors warnings Api.Tests Web.Tests
56e0d98 0 0 514 passed + 4 skipped 727
1080de2 0 0 521 passed + 4 skipped (525) 727
1080de2 with slot Azurite (127.0.0.1:10012) + running API 525 passed, 0 skipped

The 7 new Api cases are:

  • AzuriteSupportTests.AConnectionStringToLocalAzuriteRuns("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1")
  • AConnectionStringToOtherStorageDoesNotRun for the two bypass strings
  • AConnectionStringToOtherStorageDoesNotRun("UseDevelopmentStorage=TRUE")
  • AConnectionStringThatCannotBeReadSkipsAndSaysWhy
  • TableStoreRegistrationTests.TheExtensionRegistersTheSevenStoresEachOnceAndNothingElse
  • StoredNamesTests.TheLiteralListsTheOtherTestsUseMatchTheProductionNames

The azurite:10002 row moved from accepted to refused, so it is not a new case.

A3 flow (worker, with-slot.sh slot 1). The 4 Azurite tests run against each connection string. A listener on the container's own non-loopback address, also bound on port 10002, counts connections.

case 1080de2 control 56e0d98
remote account PASS: 4 skipped, 0 connections PASS
UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://<listener> PASS: 4 skipped, 0 connections FAIL: 4 failed, 16 connections
devstoreaccount1 + TableEndpoint=http://<listener>/… PASS: 4 skipped, 0 connections FAIL: 4 failed, 16 connections
card literal …ProxyUri=http://evil.example.test PASS: 4 skipped FAIL: 4 failed; the client tried evil.example.test:10002 ("Name or service not known")
card literal …TableEndpoint=https://evil.example.test/… PASS: 4 skipped FAIL: 4 failed; the client tried evil.example.test:443 ("Name or service not known")

E2E was not run because no Web or E2E file changed.

@github-actions

Copy link
Copy Markdown

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
1346 1342 0 0 4 0 53.6s

🎉 No failed tests in this run.

Github Test Reporter by CTRF 💚

@mwg-bender
mwg-bender Bot merged commit fedb5f5 into dev Nov 23, 2026
7 checks passed
mwg-bender Bot added a commit that referenced this pull request Nov 27, 2026
…d one-off edits (0.6.0 #268)

Closes items 1 to 4 of the 0.6.0 spec-audit leftovers.

- Zone-pinned list and details tests (#204 story 19): OccurrenceLocalTimeTests
  pins the browser zone to Kathmandu (UTC+05:45) and stores an Occurrence at
  its Series' UTC-04:00, then reads the time the Events list and the Event
  details dialog show. Dropping ToLocalTime() from either page turns its test
  red on any machine.
- If-Match on one-off edits and cancel (#204 story 22): EventService.UpdateAsync
  and DeleteAsync take the Event's eTag and send it as If-Match as read (Azure's
  weak tags are not .NET-parsed), and send none when there is no tag. The edit
  dialog (a standalone Event, and This event only on an Occurrence) sends the
  tag of the Event it opened, Delete and This event only cancel send the row's
  tag, and Select Winner sends the tag of the Event the details dialog shows.
  A 409 goes through the existing message path. The Series cancel is unchanged:
  the list row holds no Series tag, so it sends none.
- docs/api-validation.md: the test-class names #209 split or renamed.
- AccessibleNamesTests uses PageActions.Pick instead of its own copy.

Refs #268
mwg-bender Bot added a commit that referenced this pull request Nov 27, 2026
…d one-off edits (0.6.0 #268) (#270)

## Summary

Items 1 to 4 of #268, the 0.6.0 spec-audit leftovers. Item 5 (splitting the five Web.Tests files over 400 lines) belongs to the next card and is not in this PR.

| Item | Disposition |
| --- | --- |
| #268.1 zone-pinned list and details tests (#204 story 19) | DONE: `OccurrenceLocalTimeTests` (2 tests) |
| #268.2 If-Match on cancel and one-off edits (#204 story 22) | DONE: `EventService` sends the Event's eTag; 10 tests in `EventIfMatchTests.cs` |
| #268.3 stale test-class names in `docs/api-validation.md` | DONE: all 38 class names the file mentions now exist |
| #268.4 duplicate `Pick` in `AccessibleNamesTests.cs` | DONE: uses `PageActions.Pick` (530 -> 524 lines) |
| #268.5 Web.Tests files over 400 lines | OUTSIDE: next card |

## Cause (item 2)

`EventService.UpdateAsync` and `DeleteAsync` sent no `If-Match`, although the API honours it on `PUT` and `DELETE api/events/{id}`. A one-off edit, a "This event only" edit or cancel, a plain Delete and Select Winner could therefore overwrite an Event another admin had saved in the meantime. The live control run below shows it: on plain `dev` a stale edit answered 200 and replaced the other admin's name.

## Change

- `EventService.UpdateAsync(entity, ETag eTag = default)` and `DeleteAsync(id, ETag eTag = default)` send the tag as `If-Match` as read (`TryAddWithoutValidation`, the way `SeriesService.UpdateAsync` and `CommentClient` do, because Azure's weak tags are not .NET-parsed). A default tag sends no header, so a caller with no tag behaves as before.
- The callers pass the tag they already hold: the edit dialog passes the tag of the Event it opened (a standalone Event, and This event only on an Occurrence); the Events page passes the row's tag on Delete and on This event only cancel; Select Winner passes the tag of the Event the details dialog shows. A 409 goes through the existing `ApiResult` message path, so no UX changed.
- `SeriesService.DeleteAsync` (cancel all) is unchanged: the cancel runs from the list row, which holds no Series tag, and the card says to send no header where no tag is held. Its no-header behaviour is pinned by `TheSeriesCancel_SendsNoIfMatch`.
- `docs/api-validation.md` (Test coverage): `CommentApiTests`, `RetiredCommentsFieldTests` and the unsplit `EventMetricsTests` / `ApiValidationRouteTests` coverage now name the classes #209 split them into.
- `AccessibleNamesTests` drops its own `Pick` and uses `PageActions.Pick` (already imported with `using static`).

## Validation

All numbers from cold builds (`clean-build.sh`, then build the slnx, then `test --no-build`), base `origin/dev` `3279277ac7b91a8e4de0e97454f90ce92b10432c`.

| | Baseline | After |
| --- | --- | --- |
| Build | 0 errors, 0 warnings | 0 errors, 0 warnings |
| Api.Tests | 911 passed + 2 skipped (913) | 911 passed + 2 skipped (913) |
| Web.Tests | 1247 | **1259** (+12) |
| E2E | 5 passed + 14 skipped (19) | 5 passed + 14 skipped (19) |

No test was removed, renamed or rewritten. Added: `OccurrenceLocalTimeTests` (2), `EventEditIfMatchTests` (4), `EventDeleteAndWinnerIfMatchTests` (6).

Red first: on `dev` 8 of the 10 If-Match tests failed (the two that pin "no tag, no header" pass on both). The item 1 tests pin behaviour `dev` already has, so their red comes from mutations. Mutations, each applied, run, then restored:

| Mutation | Tests red |
| --- | --- |
| `EventList.razor`: drop `ToLocalTime()` | `TheList_ShowsTheOccurrencesTime_InTheBrowsersZone` |
| `EventDetailsDialog.razor`: drop `ToLocalTime()` | `TheDetailsDialog_ShowsTheOccurrencesTime_InTheBrowsersZone` |
| `EventService`: drop the If-Match header | 8 of 10 |
| `EventEditDialog.Save.cs`: drop the edit's tag | 2 (standalone update, stale update) |
| `EventEditDialog.razor.cs`: drop This event only's tag | 1 (This event only) |
| `Events.razor`: drop the Delete's tag | 3 (Delete, This event only cancel, stale delete) |
| `EventDetailsDialog.razor`: drop Select Winner's tag | 2 (Select Winner, stale Select Winner) |

### Live run (by the worker, Playwright headless Chromium on a `with-slot.sh` stack, browser zone Asia/Kathmandu)

The script seeds a standalone Event and a weekly Series through the API, drives the UI, and records the headers of every write the browser sends.

| Flow | Branch `fbf7e4f` | Control plain `dev` |
| --- | --- | --- |
| F1 Update Event on a standalone Event | PASS: `If-Match` = the listed eTag, 200 | FAIL: `If-Match` null |
| F2 Update Event, This event only, on an Occurrence | PASS: the Occurrence's own eTag, 200, stored Modified, no Series PUT | FAIL: `If-Match` null |
| F3 Delete, This event only (cancel one Occurrence) | PASS: the Occurrence's eTag, 204, row gone, no Series DELETE | FAIL: `If-Match` null |
| F4 stale edit (the Event saved through the API after the list loaded) | PASS: 409, the dialog shows "The event was not saved. The request conflicts with the stored data. Reload and try again.", the other save kept | FAIL: no header, 200, the other admin's name overwritten |

Branch SUMMARY pass=4 fail=0 error=0; control SUMMARY pass=0 fail=4 error=0. The control failures are the behaviour this PR changes, not a regression. Select Winner and the plain standalone Delete were covered by bUnit tests only, not in the live run.

## Notes

- One commit by `MWG Bender[bot]` (author and committer). `Refs #268`: Nerd closes the issue by hand once item 5 has a disposition.
- Observations (not fixed): none beyond item 5.
@MWG-Logan
MWG-Logan deleted the chore/060-api-followups branch November 27, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants