Skip to content

Snapshot-test in-memory assembler and codex builds ahead of the refactor - #4884

Merged
Mpdreamz merged 1 commit into
mainfrom
snap/inmemory-builds
Nov 17, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
snap/inmemory-builds

Conversation

@Mpdreamz

Copy link
Copy Markdown
Member

Adds snapshot tests that build an assembled site and a codex in memory and record what they output today, so #4530 can prove it changes none of it.

Affects: Assembler builds, Codex builds

Prompt summary: Lock in the current output of in-memory assembler and codex builds with snapshot tests before the large domain model refactor in #4530 lands. The tests record behaviour, including nondeterminism, and scrub it in the snapshot, not in product code.

Why

Nothing builds a whole assembled site in a unit test, so a refactor of the domain model can change navigation, cross-link URLs, redirects, sitemap or llms.txt without a test noticing. The codex landing and group pages have no output snapshot either.

What

Assembled site fixture

Four fake repositories (a narrative repository and three references) go through the real AssembleSources, SiteNavigation, AssemblerBuilder, sitemap and llms.txt steps. They carry cross links in both directions, redirects, applies_to, a hidden page, a nested toc and a repository mounted at a path prefix. The cross links the link index would serve are generated from the fake content, so no network is used.

Snapshots of the assembled output

The output tree, links.json, sitemap.xml with the build time scrubbed, redirects.json, the appended llms.txt sections, the navigation tree and the Markdown export, plus the content section of five rendered pages.

Codex fixture

Five documentation sets in two groups and one ungrouped repository. Snapshots cover the navigation with and without a site prefix, the group listings, the generated output tree, and the landing grid and group page.

Two product seams

AssembleSources.AssembleOfflineAsync builds the sources from known cross links without a link index or release-notes fetch; AssembleAsync is untouched. CheckoutsFileSystem.InnerFileSystem exposes the wrapped file system and AssemblerDocumentationSet passes it to the documentation scope. Without it the assembler always reads the physical disk. Production passes the same physical file system as before.

Out of scope: the assembler's API and CLI tocs need an OpenAPI spec fetch, and AssemblerBuildService.BuildAll itself clones with git and reads the link registry from disk, so the test runs its later steps directly. The assembler never writes a documentation state, so none is snapshotted. Per-docset codex pages need CodexBuildService checkouts. Recorded oddities are not fixed: every repository writes the same docs/links.json, so the last one wins.

Verify

dotnet test --project tests/Elastic.Documentation.Build.Tests
dotnet test --project tests/Navigation.Tests
mise run test
mise run lint

Mutation checked: hiding the hidden-page filter in the sitemap, changing the redirect output, the codex output path and the path prefix in cross-link resolution each fails the matching tests. Independent of #4880, which has a separate set of helpers.

Builds an assembled site of four fake repositories in memory through the real assembler steps and snapshots the output tree, links.json, sitemap, redirects, llms.txt, navigation and the content section of five pages. A codex fixture does the same for navigation and the generated landing pages. Two small seams let the assembler read a non-physical file system and skip the link index.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Mpdreamz
Mpdreamz requested a review from a team as a code owner November 16, 2026 21:25
@Mpdreamz Mpdreamz added the chore label Nov 16, 2026
@Mpdreamz
Mpdreamz requested a review from theletterf November 16, 2026 21:25
@Mpdreamz Mpdreamz added the chore label Nov 16, 2026
Comment on lines +129 to +156
internal static async Task<AssembleSources> AssembleOfflineAsync(
ILoggerFactory logFactory,
AssembleContext context,
Checkout[] checkouts,
IConfigurationContext configurationContext,
IReadOnlySet<Exporter> availableExporters,
FetchedCrossLinks crossLinks,
Cancel ctx
)
{
var navigationTocMappings = GetTocMappings(context);
var uriResolver = new PublishEnvironmentUriResolver(navigationTocMappings, context.Environment);
var sources = new AssembleSources(
logFactory,
context,
checkouts,
configurationContext,
navigationTocMappings,
configurationContext.LegacyUrlMappings,
uriResolver,
new CrossLinkResolver(crossLinks, uriResolver),
new ReleaseNotesResolver(),
availableExporters
);
foreach (var (_, set) in sources.AssembleSets)
await set.DocumentationSet.ResolveDirectoryTree(ctx);
return sources;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

AssembleOfflineAsync copies the wiring from AssembleAsync (GetTocMappings, the PublishEnvironmentUriResolver, the constructor arguments, the ResolveDirectoryTree loop) instead of sharing it. The new snapshot tests only call the copy. If #4530 changes how AssembleAsync builds the sources (for example the resolver, legacy URL mappings or tree resolution), these tests won't notice, which defeats their stated purpose. Move the shared construction and resolve steps into one private helper that both methods call, so the only difference is where the cross links and release notes come from.

Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.

DocumentationFileSystem.Resolve(Paths.WorkingDirectoryRoot.FullName),
CreateConfigurationContext()
)
{ UrlPathPrefix = "/docs" };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

Set BuildType = BuildType.Codex on this context. BuildContext defaults to Isolated, whereas production passes a Codex context to the generator, so these snapshots exercise different rendering branches. For example, the landing-page snapshot records /docs/_static/logo-elastic-horizontal-color.svg, while the current Codex-specific static-prefix logic produces /_static/logo-elastic-horizontal-color.svg. The fixture should record actual Codex output rather than isolated-mode output.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

@github-actions

Copy link
Copy Markdown
Contributor

@Mpdreamz
Mpdreamz merged commit bcf7e1c into main Nov 17, 2026
56 checks passed
@Mpdreamz
Mpdreamz deleted the snap/inmemory-builds branch November 17, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant