Skip to content

fix: construct content-backed services at startup - #1734

Open
BenjaminMichaelis wants to merge 1 commit into
mainfrom
chore/startup-content-check-and-smoke-test
Open

BenjaminMichaelis wants to merge 1 commit into
mainfrom
chore/startup-content-check-and-smoke-test

Conversation

@BenjaminMichaelis

Copy link
Copy Markdown
Member

Why

On dev, a bad sitemap.descriptions.json made every page return 500 while /health stayed green, because ChapterDescriptionService (and IGuidelinesService) are singletons built lazily on the first page request. The failure only appeared after the revision was already serving traffic.

What changed

  • Program.cs resolves ChapterDescriptionService and IGuidelinesService at startup, right after the routes are mapped. An unreadable content file now fails startup, so the new container revision never takes traffic.

Relation to #1561

This is the startup-check part of #1561, rebased onto current main. The rest of #1561 is intentionally not included:

  • The Key/Keys compatibility code is no longer needed (tooling now ships Keys, chore: bump tooling packages to 1.1.1.19573 #1562).
  • The smoke-test script is redundant: main now runs the Playwright Deployed smoke tests (including the reading journey) after the dev deploy, and prod promotion needs them.
  • The NuGet-credential / AccessToNugetFeed=true CI changes carry more risk and should be reviewed on their own.

Test plan

  • EssentialCSharp.Web.Tests: 350 passed
  • Not tested end to end: startup failing on a deliberately bad content file. The first dev deploy after merge will exercise the normal path.
  • Note: the solution build fails locally on EssentialCSharp.Web.AppHost (NETSDK1228, Aspire workload deprecated in this SDK); unrelated to this change. I built and tested the web and test projects directly.

ChapterDescriptionService and IGuidelinesService are singletons built lazily on the
first page request, so an unreadable content file left /health green while pages
returned 500. Resolve them at startup so a bad content package fails the new
revision before it takes traffic.
BenjaminMichaelis added a commit that referenced this pull request Nov 28, 2026
## Why
The dev outage came from `sitemap.descriptions.json` changing shape
(`Key` vs `Keys`), and the placeholders that PR builds use did not model
that file at all, so CI could not notice.

## What changed
- Add `Placeholders/sitemap.descriptions.json` in the shape the content
package now ships (`Keys` + `Value`, matching `SiteMappingDescription`)
and copy it into `Chapters/` for placeholder builds.
- Bring `Placeholders/sitemap.json` in line with `SiteMapping`
(`PrimaryKey`, `LastModified`).
- Add `PlaceholderShapeTests`, which compares each placeholder's JSON
property names and value kinds with the content files the app loads.
Built against the real content package (`-p:AccessToNugetFeed=true`) it
fails when the package changes shape; failures print property names
only, so no book content reaches a public log.

## Relation to earlier work
This is the remaining part of #1561, which was closed in favour of #1734
(startup check). Not included: the `Key`/`Keys` reader fallback (tooling
ships `Keys`), the smoke-test script (main runs the Playwright
`Deployed` smoke tests), and a real-package restore in CI, which should
be reviewed on its own. Until that exists, `PlaceholderShapeTests`
compares the placeholders with themselves in CI.

## Test plan
- [x] `EssentialCSharp.Web.Tests`: 351 passed; 2 failures
(`CaptchaService_Verify_Success`, `KnownBreachedPassword_IsDetected`)
call external services and are unrelated.
- [x] `Parser.Shared.dll` from package 19663 declares
`SiteMappingDescription { Keys, Value }` and `SiteMapping` with
`PrimaryKey` and `LastModified`, matching the placeholders.
- [ ] Not run against the real content files (no feed credentials
available).

This branch has not been deployed

No deployments
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.

1 participant