Skip to content

test: validate the DI container to catch captive-dependency regressions - #57

Merged
bilbospocketses merged 1 commit into
masterfrom
test/di-container-validation
Jun 12, 2026
Merged

test: validate the DI container to catch captive-dependency regressions#57
bilbospocketses merged 1 commit into
masterfrom
test/di-container-validation

Conversation

@bilbospocketses

Copy link
Copy Markdown
Owner

What

Pulls Control Menu's service registrations out of Program.cs into an AddControlMenuServices(this IServiceCollection, IDataPathResolver) extension, and adds a test that builds the real container with ValidateScopes + ValidateOnBuild turned on.

Why

The v1.2.0 imaging captive-dependency bug (fixed in #56) shipped past 444 green tests and CI because nothing ever built the Program.cs container. IImageService/ITracingService were registered Singleton while depending on the scoped IDependencyPathResolver -- a captive dependency that aborts dotnet run in Development (exit 82) via ValidateOnBuild. bUnit assembles its own minimal service collections, and the packaged app runs Production where scope validation is off, so both blind spots lined up.

This closes the gap: the registrations now live behind one testable seam, and DependencyInjectionValidationTests builds them under full validation. Program.cs behavior is unchanged -- it just calls the extension.

Tests

  • AddControlMenuServices_BuildsWithFullValidation_DoesNotThrow -- builds the real graph; fails on any captive dependency or missing registration.
  • BuildServiceProvider_WithFullValidation_CatchesCaptiveDependency -- guards the guard: proves the validation options actually detect a singleton-consuming-scoped capture, so the first test cannot silently rot if someone weakens the options.

Confirmed it bites: temporarily flipping IImageService back to Singleton makes the first test fail with exactly "Cannot consume scoped service 'IDependencyPathResolver' from singleton 'IImageService'" -- the original bug. Reverted; full suite green at 446.

Extract Control Menu's service registrations from Program.cs into an AddControlMenuServices extension so a test can build the real container with ValidateScopes + ValidateOnBuild. This catches captive dependencies (a Singleton consuming a scoped service) at test time instead of at the first dotnet run -- the class of bug that shipped in v1.2.0 when IImageService/ITracingService were registered Singleton against the scoped IDependencyPathResolver and aborted Dev startup (exit 82), invisible to 444 green tests + CI because nothing ever built the Program.cs container.

Adds DependencyInjectionValidationTests: one test builds the real container and asserts no validation error; a second proves the validation options actually detect the captive-dependency shape. Program.cs behavior is unchanged -- it just calls the extension.
@bilbospocketses
bilbospocketses enabled auto-merge (squash) June 12, 2026 19:02
@bilbospocketses
bilbospocketses merged commit 1aced98 into master Jun 12, 2026
8 checks passed
@bilbospocketses
bilbospocketses deleted the test/di-container-validation branch June 12, 2026 19:04
bilbospocketses added a commit that referenced this pull request Jun 24, 2026
… vendored icons (#76)

* docs(plan): audit MINOR mop-up + follow-ups (5-PR batch)

* fix(frontend): audit MINOR cleanup #42-#47 + #57

- #43 define semantic --*-bg / --*-text theme tokens (light + dark); dark mode
  now resolves real values instead of silently using the light-mode fallback
- #44 dedup byte-identical .dialog/.modal CSS; theme-aware pill :hover via color-mix
- #45 re-key scrcpy settings modal to app theme tokens (was unset Bootstrap
  --bs-*); the modal now follows light/dark instead of always-dark fallbacks
- #46 fix stale "conic" comment (the code is four linear gradients)
- #47 home-tiles.js batches reads then writes (no per-card layout thrash);
  remove dead .home-module-* CSS from the reverted tile experiment
- #42 subnets.html Close-tab link no longer traps a non-script-opened tab
- #57 vendor bootstrap-icons 1.11.3 (CSS + woff2/woff) under wwwroot/lib;
  drop the jsDelivr CDN dependency (works offline, closes the no-SRI gap)
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