From cda82b03770c75609c9e7df883719721273ce1e1 Mon Sep 17 00:00:00 2001 From: Stephen Walsh <868017+stphnwlsh@users.noreply.github.com> Date: Sat, 5 Dec 2026 14:01:27 +0000 Subject: [PATCH] Run dotnet run in the Development environment --- .agents/skills/configuration-and-environments/SKILL.md | 6 +++--- .agents/skills/presentation-integration-tests/SKILL.md | 2 +- .agents/skills/sample-data/SKILL.md | 2 +- .agents/skills/serilog/SKILL.md | 4 ++-- docs/RUN.md | 6 +++--- src/Presentation/Extensions/WebApplicationExtensions.cs | 4 ++-- src/Presentation/Properties/launchSettings.json | 2 +- src/Presentation/Telemetry/TelemetrySettings.cs | 2 +- ...{appsettings.local.json => appsettings.Development.json} | 2 +- .../ModelContextProtocolApplication.cs | 2 +- .../Telemetry/TelemetrySettingsTests.cs | 6 +++--- 11 files changed, 19 insertions(+), 19 deletions(-) rename src/Presentation/{appsettings.local.json => appsettings.Development.json} (84%) diff --git a/.agents/skills/configuration-and-environments/SKILL.md b/.agents/skills/configuration-and-environments/SKILL.md index 9bd1fae..f9bf0e4 100644 --- a/.agents/skills/configuration-and-environments/SKILL.md +++ b/.agents/skills/configuration-and-environments/SKILL.md @@ -1,6 +1,6 @@ --- name: configuration-and-environments -description: How settings are layered with appsettings files and environment variables, what the local and docker environments are, and how to add a new setting. Use when adding configuration, a connection string or environment-specific behaviour. +description: How settings are layered with appsettings files and environment variables, what the Development and docker environments are, and how to add a new setting. Use when adding configuration, a connection string or environment-specific behaviour. metadata: scope: shared --- @@ -15,7 +15,7 @@ The Lambda template has no appsettings files or environments. Its startup builds | Environment | Set by | Used for | | --- | --- | --- | -| `local` | `launchSettings.json` (`DOTNET_ENVIRONMENT=local`) | `dotnet run` on a developer machine: console logs, sample data on | +| `Development` | `launchSettings.json` (`DOTNET_ENVIRONMENT=Development`) | `dotnet run` on a developer machine: console logs, sample data on | | `docker` | `docker-compose.yml` and the Dockerfile | `docker compose up`: telemetry over OTLP through the collector to the Aspire dashboard, database in `/app/data`, sample data on | | anything else | the host | Real deployments: base settings only, sample data off, HSTS on | @@ -39,7 +39,7 @@ Settings that exist today: ## Don't - Put secrets, passwords or tokens in any `appsettings*.json` file. Use environment variables or user secrets. -- Check `IsEnvironment("local")` for behaviour that should be a setting. Add a setting instead. +- Check `IsDevelopment()` or `IsEnvironment("docker")` for behaviour that should be a setting. Add a setting instead. - Read `Environment.GetEnvironmentVariable` directly. Go through `IConfiguration`. ## Check diff --git a/.agents/skills/presentation-integration-tests/SKILL.md b/.agents/skills/presentation-integration-tests/SKILL.md index c29cea9..3203352 100644 --- a/.agents/skills/presentation-integration-tests/SKILL.md +++ b/.agents/skills/presentation-integration-tests/SKILL.md @@ -9,7 +9,7 @@ metadata: ## The rule -`tests/Presentation.Tests.Integration` talks to the whole server the way a real client does. `ModelContextProtocolApplication` (a `WebApplicationFactory`) starts the server with the `local` environment, its own shared-cache in-memory SQLite database and the sample data on. `BaseToolTests` connects an `McpClient` to it over the streamable HTTP transport before each test and disposes both after. +`tests/Presentation.Tests.Integration` talks to the whole server the way a real client does. `ModelContextProtocolApplication` (a `WebApplicationFactory`) starts the server with the `Development` environment, its own shared-cache in-memory SQLite database and the sample data on. `BaseToolTests` connects an `McpClient` to it over the streamable HTTP transport before each test and disposes both after. | Helper | Use it to | | --- | --- | diff --git a/.agents/skills/sample-data/SKILL.md b/.agents/skills/sample-data/SKILL.md index 614c449..bbba8e9 100644 --- a/.agents/skills/sample-data/SKILL.md +++ b/.agents/skills/sample-data/SKILL.md @@ -16,7 +16,7 @@ There are two kinds of data, and they never mix. | Sample data | `src/Infrastructure/Databases/MovieReviews/Extensions/MovieReviewsDbContextExtensions.cs` (`AddData`) | Local runs, Docker and the presentation integration tests | 15 authors, 50 movies, 150 reviews from Bogus with a fixed seed | | Test data | `tests/Infrastructure.Tests.Integration/Databases/MovieReviews/Extensions/MovieReviewsCollectionData.cs` (`AddTestData`) | Repository tests | A handful of hand-written rows named "One", "Two", "Three" so assertions can find them | -Sample data is only added when `Database:SeedSampleData` is `true` (on in `appsettings.local.json` and `appsettings.docker.json`, off in `appsettings.json`; Lambda turns it on only in `docker-compose.yml`) and the database is empty. A deployed copy never starts with fake data. +Sample data is only added when `Database:SeedSampleData` is `true` (on in `appsettings.Development.json` and `appsettings.docker.json`, off in `appsettings.json`; Lambda turns it on only in `docker-compose.yml`) and the database is empty. A deployed copy never starts with fake data. ## Steps diff --git a/.agents/skills/serilog/SKILL.md b/.agents/skills/serilog/SKILL.md index 2c4c22e..a35637d 100644 --- a/.agents/skills/serilog/SKILL.md +++ b/.agents/skills/serilog/SKILL.md @@ -13,7 +13,7 @@ Serilog is the logger. Application and Infrastructure code log through `Microsof | Environment | Sink | Where to look | | --- | --- | --- | -| `local` | Console, with the output template in `appsettings.local.json` | The terminal | +| `Development` | Console, with the output template in `appsettings.Development.json` | The terminal | | `docker` | Console, and OTLP through the collector to the Aspire dashboard | The Aspire dashboard, on the port `docs/RUN.md` lists, or `docker compose logs` | | Lambda, anywhere | Console, as compact JSON, and OTLP when the endpoint is set | CloudWatch Logs, or `docker compose logs` for the emulator, and the Aspire dashboard in Docker Compose | | Any, when `OTEL_EXPORTER_OTLP_ENDPOINT` is set | Also OTLP, through `Serilog.Sinks.OpenTelemetry` | Whatever receives the OTLP (`telemetry`) | @@ -29,7 +29,7 @@ Every event carries these properties: | `AssemblyVersion`, `AssemblyInformationalVersion` | Added in code at startup | | Anything pushed with `LogContext` | `FromLogContext` | -Levels are set in configuration, never in code: `Information` by default and `Debug` in `local`, with `Information` for `Microsoft`, `Warning` for `Microsoft.AspNetCore` and `Microsoft.EntityFrameworkCore.Database.Command` (a line per SQL statement buries everything else, and EF Core's meter already counts them), and `Error` for `System`. The built-in `Logging` section is set to `None` so nothing is written twice. +Levels are set in configuration, never in code: `Information` by default and `Debug` in `Development`, with `Information` for `Microsoft`, `Warning` for `Microsoft.AspNetCore` and `Microsoft.EntityFrameworkCore.Database.Command` (a line per SQL statement buries everything else, and EF Core's meter already counts them), and `Error` for `System`. The built-in `Logging` section is set to `None` so nothing is written twice. Three things log a request, and each says something the others don't: diff --git a/docs/RUN.md b/docs/RUN.md index e5159fe..3ce8593 100644 --- a/docs/RUN.md +++ b/docs/RUN.md @@ -1,10 +1,10 @@ # Running Clean Model Context Protocol -There are two pre-configured environments, `local` and `docker`. Logs go to the console in both. Traces, metrics and logs also leave over OTLP whenever `OTEL_EXPORTER_OTLP_ENDPOINT` is set, which Docker Compose does for you. +There are two pre-configured environments, `Development` and `docker`. Logs go to the console in both. Traces, metrics and logs also leave over OTLP whenever `OTEL_EXPORTER_OTLP_ENDPOINT` is set, which Docker Compose does for you. ## Database -The app stores its data in a SQLite file, `movie-reviews.db`, next to the app. In Docker the file is `/app/data/movie-reviews.db`, on the `movie-reviews-data` volume, so it survives a restart. On startup the app applies any pending Entity Framework Core migrations. When `Database:SeedSampleData` is `true`, it also seeds the same sample data into an empty database. It's on in `appsettings.local.json` and `appsettings.docker.json` and off everywhere else, so a deployed copy never starts with fake data. Delete the file, or run `docker compose down -v`, to start again. Change `ConnectionStrings:MovieReviews` to point somewhere else, or to `Data Source=MovieReviews;Mode=Memory;Cache=Shared` to keep everything in memory. +The app stores its data in a SQLite file, `movie-reviews.db`, next to the app. In Docker the file is `/app/data/movie-reviews.db`, on the `movie-reviews-data` volume, so it survives a restart. On startup the app applies any pending Entity Framework Core migrations. When `Database:SeedSampleData` is `true`, it also seeds the same sample data into an empty database. It's on in `appsettings.Development.json` and `appsettings.docker.json` and off everywhere else, so a deployed copy never starts with fake data. Delete the file, or run `docker compose down -v`, to start again. Change `ConnectionStrings:MovieReviews` to point somewhere else, or to `Data Source=MovieReviews;Mode=Memory;Cache=Shared` to keep everything in memory. To add a migration after changing the data model: @@ -88,7 +88,7 @@ Every span, metric and log carries `service.version`, so you can always tell whi ## HTTPS -The app redirects HTTP to HTTPS whenever it has an HTTPS port, which is why `dotnet run` sends on to . Outside the `local` and `Development` environments it also sends an HSTS header. The container only listens on HTTP, so in production put it behind a proxy or load balancer that ends TLS, and set `ASPNETCORE_FORWARDEDHEADERS_ENABLED=true` so the app knows the original request was HTTPS. +The app redirects HTTP to HTTPS whenever it has an HTTPS port, which is why `dotnet run` sends on to . Outside the `Development` environment it also sends an HSTS header. The container only listens on HTTP, so in production put it behind a proxy or load balancer that ends TLS, and set `ASPNETCORE_FORWARDEDHEADERS_ENABLED=true` so the app knows the original request was HTTPS. ## Browser origins diff --git a/src/Presentation/Extensions/WebApplicationExtensions.cs b/src/Presentation/Extensions/WebApplicationExtensions.cs index 8e7d35e..7ffc3d7 100644 --- a/src/Presentation/Extensions/WebApplicationExtensions.cs +++ b/src/Presentation/Extensions/WebApplicationExtensions.cs @@ -30,8 +30,8 @@ public static WebApplication ConfigureApplication(this WebApplication app) // Browsers send an Origin; the MCP spec asks servers to refuse ones they don't expect. _ = app.UseOriginCheck("/mcp", app.Configuration); - // HSTS tells browsers to only use HTTPS from then on, so it's left off for local runs. - if (!app.Environment.IsDevelopment() && !app.Environment.IsEnvironment("local")) + // HSTS tells browsers to only use HTTPS from then on, so it's left off in Development. + if (!app.Environment.IsDevelopment()) { _ = app.UseHsts(); } diff --git a/src/Presentation/Properties/launchSettings.json b/src/Presentation/Properties/launchSettings.json index 02dc77b..85e0297 100644 --- a/src/Presentation/Properties/launchSettings.json +++ b/src/Presentation/Properties/launchSettings.json @@ -7,7 +7,7 @@ "launchBrowser": false, "applicationUrl": "https://localhost:7321;http://localhost:7320", "environmentVariables": { - "DOTNET_ENVIRONMENT": "local" + "DOTNET_ENVIRONMENT": "Development" } } } diff --git a/src/Presentation/Telemetry/TelemetrySettings.cs b/src/Presentation/Telemetry/TelemetrySettings.cs index 1d84a01..5364c10 100644 --- a/src/Presentation/Telemetry/TelemetrySettings.cs +++ b/src/Presentation/Telemetry/TelemetrySettings.cs @@ -19,7 +19,7 @@ public class TelemetrySettings /// The service.version: the informational version from , the same one the version endpoint returns. public required string ServiceVersion { get; init; } - /// The deployment.environment.name, such as local or docker. + /// The deployment.environment.name, such as Development or docker. public required string EnvironmentName { get; init; } /// Where the OTLP exporters send everything. Empty means nothing is exported. diff --git a/src/Presentation/appsettings.local.json b/src/Presentation/appsettings.Development.json similarity index 84% rename from src/Presentation/appsettings.local.json rename to src/Presentation/appsettings.Development.json index 7f4709f..648ca5a 100644 --- a/src/Presentation/appsettings.local.json +++ b/src/Presentation/appsettings.Development.json @@ -12,7 +12,7 @@ } ], "Properties": { - "ApplicationName": "CleanModelContextProtocol-Local" + "ApplicationName": "CleanModelContextProtocol-Development" } }, "Database": { diff --git a/tests/Presentation.Tests.Integration/ModelContextProtocolApplication.cs b/tests/Presentation.Tests.Integration/ModelContextProtocolApplication.cs index 4bd78db..0ffa49f 100644 --- a/tests/Presentation.Tests.Integration/ModelContextProtocolApplication.cs +++ b/tests/Presentation.Tests.Integration/ModelContextProtocolApplication.cs @@ -6,7 +6,7 @@ namespace CleanModelContextProtocol.Presentation.Tests.Integration; using Microsoft.Extensions.Hosting; internal sealed class ModelContextProtocolApplication( - string environment = "local", + string environment = "Development", Dictionary? settings = null, Action? configureServices = null) : WebApplicationFactory { diff --git a/tests/Presentation.Tests.Unit/Telemetry/TelemetrySettingsTests.cs b/tests/Presentation.Tests.Unit/Telemetry/TelemetrySettingsTests.cs index 8bd80d6..2171a3a 100644 --- a/tests/Presentation.Tests.Unit/Telemetry/TelemetrySettingsTests.cs +++ b/tests/Presentation.Tests.Unit/Telemetry/TelemetrySettingsTests.cs @@ -16,13 +16,13 @@ public void FromConfiguration_ShouldReturn_DisabledDefaults_WhenNothingIsSet() var version = new VersionInfo { FileVersion = "1.2.3.0", InformationalVersion = "1.2.3+e30eba8" }; // Act - var result = TelemetrySettings.FromConfiguration(configuration, "local", version); + var result = TelemetrySettings.FromConfiguration(configuration, "Development", version); // Assert result.Enabled.ShouldBeFalse(); result.ServiceName.ShouldBe(TelemetrySettings.DefaultServiceName); result.ServiceVersion.ShouldBe("1.2.3+e30eba8"); - result.EnvironmentName.ShouldBe("local"); + result.EnvironmentName.ShouldBe("Development"); } [Fact] @@ -56,7 +56,7 @@ public void FromConfiguration_ShouldReturn_UnknownVersion_WhenVersionIsEmpty() var version = VersionInfo.FromAssembly(null); // Act - var result = TelemetrySettings.FromConfiguration(configuration, "local", version); + var result = TelemetrySettings.FromConfiguration(configuration, "Development", version); // Assert result.ServiceVersion.ShouldBe("unknown");