Skip to content

Snapshot how docset.yml and toc.yml resolve - #4883

Merged
Mpdreamz merged 2 commits into
mainfrom
snap/config-docset
Nov 17, 2026
Merged

Mpdreamz merged 2 commits into
mainfrom
snap/config-docset

Conversation

@Mpdreamz

Copy link
Copy Markdown
Member

Adds golden snapshots of how docset.yml, toc.yml and _redirects.yml resolve today, so the domain-model refactor in #4530 can prove it changes no behaviour.

Affects: Configuration, Authoring

Stack: 2 of 2, on top of #4879. The branch reuses its dump helper and scrubber, so the diff against main includes that PR's commit until it merges. Review the last commit only.

Prompt summary: Lock in the current behaviour of docset and table of contents loading with snapshot tests ahead of a large domain-model refactor. Record what the loaders do today, including odd results, and change no product code.

Why

#4530 must not change how a docset resolves, but only a few hand-picked cases pin that today. A changed path rule, a dropped option or a different diagnostic would pass the current tests.

What

Every construct, resolved

Each table of contents construct resolves in a mock file system and is written as the resolved tree plus the full model: files, folders, nested toc.yml, islands, cross links, cli, detection_rules, listings, sorting and excludes. The docset options go through ConfigurationFile against the frozen global config: subs, cta, features, registry, products, api, release_notes, branding, storybook and redirects.

This repository's own docs

A frozen copy of the docs/ docset, its toc.yml files and an empty page for each other file, so later edits to docs/ do not churn the snapshots. The copy holds no private repository names.

Tables of malformed input

About 80 cases record the diagnostics and the surviving tree, or the exception. Missing files, .. paths, duplicate files and unknown keys are covered. So are toc cycles, hidden cross links and bad redirects. Several results look like bugs and are recorded unchanged.

Out of scope

A root toc.yml that includes itself (toc: .) overflows the stack and ends the test process, so that case has a comment instead of a test.

Verify

dotnet test --project tests/Elastic.Documentation.Configuration.Tests
mise run test
mise run snap:orphans

I broke the resolvers on purpose and confirmed each new test class fails.

@Mpdreamz
Mpdreamz requested a review from a team as a code owner November 16, 2026 21:19
@Mpdreamz Mpdreamz added the chore label Nov 16, 2026
@Mpdreamz
Mpdreamz requested a review from akira28 November 16, 2026 21:19
Comment on lines +57 to +58
var pattern = new Regex($"(?<![\\w.\\-])(?:{alternatives})(?![\\w\\-])", RegexOptions.IgnoreCase, RegexTimeouts.MatchTimeout);
PrivateRepositoryNames.Value = text => pattern.Replace(text, m => placeholders[m.Value]);

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)

AddPrivateRepositories replaces the scrubber that a previous call in the same test installed, so names from that earlier call stop being scrubbed. The scrubber runs when the snapshot is matched, at the end of the test. If a test loads two configurations with different private sets (GoldenConfig.Outcome/LoadAssembler call RegisterPrivateRepositories on every load), only the last set is scrubbed, and the first set's real names can land in a committed snapshot. Numbering is also recomputed from the last set alone. The doc comment promises that a snapshot never records one of these names, which only holds if each test makes a single call. Merging new names into the names already registered for the test would keep that promise.

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

Comment on lines +278 to +281
new DocFile("posts/one.md", "---\nlisting_group: news\n---\n# One\n"),
new DocFile("posts/two.md", "---\nlisting_group: how-to\n---\n# Two\n"),
new DocFile("posts/three.md", "# Three\n"),
new DocFile("posts/archive/deep.md", "---\nlisting_group: news\n---\n# Deep\n"),

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)

The listing fixtures use listing_group, but ListingFrontMatterReader only recognizes listing: news or listing: { group: news }. These pages therefore all resolve as ungrouped, and the golden snapshot never exercises group creation or the explicit groups ordering. Use the supported frontmatter syntax so this construct test actually pins grouped-listing behavior.

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

Comment on lines +263 to +280
[Test]
public void LinkOrderIsKept_Loaded_Outcome() =>
Load("links:\n z:\n title: Z\n url: https://example.com/z\n a:\n title: A\n url: https://example.com/a\n")
.Should()
.MatchInlineSnapshot(
"""
model <RelatedLearningConfiguration>:
Links:
a <RelatedLearningLink>:
Id: "a"
Title: "A"
Url: "https://example.com/a"
z <RelatedLearningLink>:
Id: "z"
Title: "Z"
Url: "https://example.com/z"
"""
);

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)

LinkOrderIsKept_Loaded_Outcome can't detect a change in link order. RelatedLearningConfiguration.Links is a FrozenDictionary, and ModelDump sorts hashed collections by key before writing them. That is why the snapshot lists a before z, even though the YAML declares z first. The test passes whatever order the loader keeps, and its name says the opposite of what the snapshot records. Either rename it to describe what it actually checks (for example, that links are keyed by id), or assert on Links.Keys in declaration order if declaration order is meant to be part of the contract.

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

@github-actions

Copy link
Copy Markdown
Contributor

Mpdreamz and others added 2 commits November 17, 2026 10:48
Every table of contents construct, the docset options and this repository's own docs/ docset now resolve into verified snapshots, and a table of malformed inputs records the diagnostics or exception each produces today, including results that look like bugs.

This stacks on the global config snapshots and locks behaviour ahead of the domain-model refactor in #4530.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The scoped file system did not recognise a bare /docs root on Windows, so every docset test threw there. The root now comes from the current drive, and argument exception messages, which the runtime words differently per operating system, are left out of the snapshots.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
}

_ = sb.Append(ModelDump.ToText(config, Summarize, "Substitutions"));
_ = sb.AppendLine("substitutions:");

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)

The full ConfigurationFile dump includes every FeatureFlags property. FeatureFlags.IsEnabled checks FEATURE_* process environment variables before it looks at the docset value, so these goldens depend on the environment. If a developer or CI job exports a variable such as FEATURE_PRIMARY_NAV or FEATURE_DIAGNOSTICS_PANEL, DocsetSettings, ApiConfigurations, Branding, Redirects and BaselineDocs_Configured fail even though the loader has not changed. That undercuts their purpose as a refactor safety net. Either clear or pin FEATURE_* for these tests, or summarise FeatureFlags from the docset input rather than the resolved getters.

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

@Mpdreamz
Mpdreamz merged commit a3db737 into main Nov 17, 2026
44 checks passed
@Mpdreamz
Mpdreamz deleted the snap/config-docset branch November 17, 2026 10:01
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