From 571aaf9cd291780eae16ec48305fe6510bf2a47a Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Sun, 15 Nov 2026 16:16:27 +0100 Subject: [PATCH] ASF-injectie 5/5: end-to-end test op de master-host, ASF Website:AuthoredBaseUrl, rooktest-uitbreiding, docs - ASF appsettings: Website:AuthoredBaseUrl=https://andreaslop.nl, PublicBaseUrl leeg (env). - Api.Tests/AsfInjectionPipelineTests: pagina met markers, echte database; een CMS-wijziging is direct zichtbaar (ETag wijzigt), data-blok == publieke API, 304, sitemap-adres. - smoke-site.sh: onverwerkte CMS-markers op / falen; data-blok moet siteUrl van deze host hebben. - docs: asf-host-injection 'as built'. Co-Authored-By: Claude Sonnet 5.5 --- .../features/asf-host-injection/plan.md | 19 ++- aidlc-docs/features/website-seo/overview.md | 2 +- scripts/smoke-site.sh | 19 +++ .../appsettings.json | 10 +- .../AsfInjectionPipelineTests.cs | 150 ++++++++++++++++++ .../SiteContractTests.cs | 10 ++ 6 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 src/SlpModularCms.Api.Tests/AsfInjectionPipelineTests.cs diff --git a/aidlc-docs/features/asf-host-injection/plan.md b/aidlc-docs/features/asf-host-injection/plan.md index c5d56f7..14697da 100644 --- a/aidlc-docs/features/asf-host-injection/plan.md +++ b/aidlc-docs/features/asf-host-injection/plan.md @@ -2,7 +2,7 @@ - **Slug**: asf-host-injection - **Type**: Feature, **proposal; not approved, build not started** -- **Status**: Plan agreed with the ASF session (their counterpart: `AndreaSlopFotografie-packages/aidlc-docs/features/asf-cms-host-injection/plan.md`, section "Host contract"). Bryan accepted the approach (neutral list first, styled cards after hydration; the host writes the list HTML) on 2026-11-15 but said **not to start building yet**: he first reads the plan and finds out whether .NET 10 can run on the hosting package (hosting bundle or self-contained). +- **Status**: **Built** on `feature/contact-forms-module` (commits 7d66944, a136615, ef4fb9d, 4baadf3 and the one after it; tests green locally), **not yet deployed**: needs the website build with the markers and `Website__PublicBaseUrl=https://test.andreaslop.nl` in the ASF-test env file. Before: plan agreed with the ASF session (their counterpart: `AndreaSlopFotografie-packages/aidlc-docs/features/asf-cms-host-injection/plan.md`, section "Host contract"). Bryan accepted the approach (neutral list first, styled cards after hydration; the host writes the list HTML) on 2026-11-15 but said **not to start building yet**: he first reads the plan and finds out whether .NET 10 can run on the hosting package (hosting bundle or self-contained). - **Affected components (planned)**: `SlpModularCms.Core` (`Hosting/Website`: generalise `IndexHtmlInjector`, hook in `PrerenderedSiteMiddleware`), `SlpModularCms.Modules.Offerings` (marker providers), `scripts/smoke-site.sh`, docs - **Documented**: 2026-11-15 - **Documentation Language**: English @@ -42,3 +42,20 @@ Injected pages: `Cache-Control: no-cache`, strong ETag from the final body, 304 ## Risks Markers stripped by a build (confirmed not the case for ASF's Vite/TanStack prerender); proxy or IIS caching of HTML; .NET 10 unavailable on the package; the per-base-URL cache keyed from the Host header when no `PublicBaseUrl` is configured (to be capped in this unit); several app instances (invalidation is per process; the 60-second TTL bounds the lag). Estimated effort: about 1.5 days for the host side, plus ASF's front-end rework. + +## As built (2026-11-15) + +| Piece | Where | +|---|---| +| Marker edits (regions, data block, JSON-LD, inline values, script escaping) | `Core/Hosting/Website/HtmlMarkerEditor.cs` | +| Injector for every html/xml/txt file of the prerendered host and for the SpaFallback index.html; caching (60 s, direct invalidation, capped at 256 entries), ETag/304, address replacement, per-part fail-open | `Core/Hosting/Website/HtmlMarkerInjector.cs`; hook in `PrerenderedSiteMiddleware` (`ServeFile`); registered by `AddCmsWebsite` | +| Neutral list and banner HTML, price rules (whole euros, `1.250`) | `Offerings/Services/CmsPageHtml.cs`; golden files of the website repo (ASF commit 16027f5) in `Offerings.Tests/Golden/host-injection`, `GoldenHtmlTests` | +| Marker transform (regions, `#cms-data` with `siteUrl`, JSON-LD price, `data-cms-price`) | `Offerings/Services/OfferingsHtmlTransform.cs` (`IHtmlPageTransform`) | +| Settings | ASF `appsettings.json`: `Website:AuthoredBaseUrl=https://andreaslop.nl`, `Website:PublicBaseUrl` empty (env `Website__PublicBaseUrl`) | +| End-to-end test (real database, ASF settings, temporary web root) | `Api.Tests/AsfInjectionPipelineTests` | +| Smoke test | `scripts/smoke-site.sh`: unprocessed `CMS:DATA` / `CMS:OFFER-JSON-LD` markers on `/` fail; a data block must carry this host's `siteUrl`; ETag and no-cache on the injected home page | + +Behaviour choices: a successful empty answer empties a region (no live package, no active banner); a failing service leaves the baked content; a package without a derivable price removes `offers` from the JSON-LD (a failing service does not); a file without markers and without the authored address stays a plain static file; 404.html is not injected. + +**Deploy order matters**: set `Website__PublicBaseUrl=https://test.andreaslop.nl` on ASF-test before the first website build with markers is deployed, otherwise the data block's `siteUrl` is the production address and the smoke test fails on purpose. + diff --git a/aidlc-docs/features/website-seo/overview.md b/aidlc-docs/features/website-seo/overview.md index 9a42dc5..a449a8b 100644 --- a/aidlc-docs/features/website-seo/overview.md +++ b/aidlc-docs/features/website-seo/overview.md @@ -24,6 +24,6 @@ Only hosts in `WebsiteMode.SpaFallback` (SlpSoftware). The ASF host (`Prerendere | `KnownPaths` | Only these paths are pages (200, the SPA shell); any other website path is a real 404 (still the shell). `/api`, `/admin` and assets keep working. | | `Sitemap:Paths` | Paths listed in the sitemap. | -## Index markers (`IndexHtmlInjector`) +## Index markers (`HtmlMarkerInjector` (until 2026-11-15 `IndexHtmlInjector`; generalised for the prerendered host, see asf-host-injection)) The host fills markers in `index.html`: `` (schema.org `ItemList` of `Offer`) and `` (a static `#packages-static` list), rendered by `OfferingsIndexMarkers` from the live offerings. 60-second cache, invalidated directly by every offering change, `ETag` with 304 support; if a provider fails the plain page is still served. The markers must stay in `` above `#root`; the website removes `#packages-static` on start-up. diff --git a/scripts/smoke-site.sh b/scripts/smoke-site.sh index ffb08c0..cb32ef9 100644 --- a/scripts/smoke-site.sh +++ b/scripts/smoke-site.sh @@ -54,6 +54,25 @@ expect_status /api/v1/offerings/all 401 "the administrator list is protected" expect_header / X-Robots-Tag noindex "noindex on the website" expect_body /robots.txt "Disallow: /" "robots.txt disallows everything" +# The home page is served by the host. When the website build left CMS markers in it, the host must have processed +# them: an unprocessed or JSON-LD marker means the page does not go through the injector (a proxy or +# IIS serving files itself, or a host without the injection), and a deployed data block must carry this host's address. +home="$(curl_get "$base/" || true)" +if printf '%s' "$home" | grep -qE '" + + "" + + "baked top" + + "baked list" + + "

vanaf € 1

"; + + private readonly AsfInjectionFactory _factory; + + public AsfInjectionPipelineTests(AsfInjectionFactory factory) + { + _factory = factory; + File.WriteAllText(Path.Combine(factory.WebRoot, "web", "smoke.html"), Page); + File.WriteAllText(Path.Combine(factory.WebRoot, "web", "sitemap.xml"), "https://andreaslop.nl/"); + } + + private async Task InScope(Func> action) + { + _ = _factory.CreateClient(); // starts the host and migrates the database + await using var scope = _factory.Services.CreateAsyncScope(); + return await action(scope.ServiceProvider); + } + + [Fact] + public async Task ACmsChange_ShowsInTheServedPage_AtOnce_AndTheAddressIsTheTestHosts() + { + var client = _factory.CreateClient(); + var caller = Guid.NewGuid(); + + // Clean slate for the slug of this test (the database is shared with other tests). + await InScope(async sp => + { + var service = sp.GetRequiredService(); + foreach (var existing in (await service.ListAllAsync()).Where(o => o.Slug == "smoke")) await service.DeleteAsync(Guid.Parse(existing.Id), caller); + return 0; + }); + + // Nothing live: regions are emptied, the data block has no package, the price element is gone, the address is the host's. + var empty = await client.GetAsync("/smoke"); + empty.StatusCode.Should().Be(HttpStatusCode.OK); + var emptyBody = await empty.Content.ReadAsStringAsync(); + emptyBody.Should().Contain(""); + emptyBody.Should().Contain("https://test.andreaslop.nl/soorten-fotoshoots/smoke").And.NotContain("https://andreaslop.nl"); + emptyBody.Should().NotContain("\"offers\"").And.NotContain("baked"); + var etagBefore = empty.Headers.ETag!.Tag; + + // Create the package through the module: the very next request shows it. + await InScope(async sp => + { + await sp.GetRequiredService().CreateAsync( + new CreateOfferingRequest("Smoke", null, "€ 1.250", null, ["Eén uur", "O'Brien & zoon"], "Boek", Slug: "smoke"), caller); + await sp.GetRequiredService().CreateAsync( + new OfferingBannerRequest("", "Nog twee plekken", Position: "top"), caller); + return 0; + }); + + var live = await client.GetAsync("/smoke"); + var body = await live.Content.ReadAsStringAsync(); + live.Headers.ETag!.Tag.Should().NotBe(etagBefore); + body.Should().Contain("
  • Smoke

    € 1.250

    "); + body.Should().Contain("
  • O'Brien & zoon
  • "); + body.Should().Contain(""); + body.Should().Contain("€ 1.250"); + body.Should().Contain("\"price\":1250").And.Contain("\"priceCurrency\":\"EUR\""); + + // The data block is the public API's answer plus the site's address. + var start = body.IndexOf("", start, StringComparison.Ordinal)]; + var data = JsonDocument.Parse(json).RootElement; + data.GetProperty("siteUrl").GetString().Should().Be("https://test.andreaslop.nl"); + var api = JsonDocument.Parse(await client.GetStringAsync("/api/v1/offerings")).RootElement; + Same(data.GetProperty("offerings"), api).Should().BeTrue("the data block carries the same JSON as GET /api/v1/offerings"); + var topApi = await client.GetStringAsync("/api/v1/offerings/banner?position=top"); + Same(data.GetProperty("banners").GetProperty("top"), JsonDocument.Parse(topApi).RootElement).Should().BeTrue(); + data.GetProperty("banners").GetProperty("bottom").ValueKind.Should().Be(JsonValueKind.Null); + + // A matching ETag is a 304. + var conditional = new HttpRequestMessage(HttpMethod.Get, "/smoke"); + conditional.Headers.IfNoneMatch.Add(live.Headers.ETag); + (await client.SendAsync(conditional)).StatusCode.Should().Be(HttpStatusCode.NotModified); + + // Switching the package off removes it again, and the JSON-LD loses its offers. + await InScope(async sp => + { + var service = sp.GetRequiredService(); + var id = Guid.Parse((await service.ListAllAsync()).Single(o => o.Slug == "smoke").Id); + await service.DeleteAsync(id, caller); + return 0; + }); + var gone = await client.GetStringAsync("/smoke"); + gone.Should().NotContain("data-slug=\"smoke\"").And.NotContain("\"offers\""); + } + + // The same JSON value; the writers may differ in escaping (the API writes "€" as is, the data block as €). + private static bool Same(JsonElement a, JsonElement b) => + System.Text.Json.Nodes.JsonNode.DeepEquals(System.Text.Json.Nodes.JsonNode.Parse(a.GetRawText()), System.Text.Json.Nodes.JsonNode.Parse(b.GetRawText())); + + [Fact] + public async Task TheSitemap_GetsTheTestHostsAddress_ButStillComesFromTheBuild() + { + var client = _factory.CreateClient(); + + var response = await client.GetAsync("/sitemap.xml"); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + (await response.Content.ReadAsStringAsync()).Should().Contain("https://test.andreaslop.nl/"); + } +} diff --git a/src/SlpModularCms.Api.Tests/SiteContractTests.cs b/src/SlpModularCms.Api.Tests/SiteContractTests.cs index 3a6a6fe..b634a8e 100644 --- a/src/SlpModularCms.Api.Tests/SiteContractTests.cs +++ b/src/SlpModularCms.Api.Tests/SiteContractTests.cs @@ -133,6 +133,16 @@ public class SiteContractTests config.GetSection("SecurityHeaders:AllowedConnectOrigins").Get().Should().BeEmpty(); } + [Fact] + public void AndreaSlopFotografie_WritesItsProductionAddressInTheBuild_AndHasNoPublicAddressByDefault() + { + // The build is the same on test and production: the host swaps the authored address for the instance's own. + var config = SiteFiles.Committed(SiteFiles.AndreaSlopFotografie); + + config["Website:AuthoredBaseUrl"].Should().Be("https://andreaslop.nl"); + config["Website:PublicBaseUrl"].Should().BeNullOrEmpty("the instance's own address is environment configuration"); + } + [Fact] public void AndreaSlopFotografie_MailBrandingPointsAtTheAdminAssets() {