Skip to content

Snapshot-test link handling before the domain-model refactor - #4878

Merged
Mpdreamz merged 1 commit into
mainfrom
snap/links
Nov 17, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
snap/links

Conversation

@Mpdreamz

Copy link
Copy Markdown
Member

Adds snapshot tests that record how links, links.json, redirects and the inbound link check behave today, so the refactor in #4530 can prove it changes none of it.

Affects: Authoring, Internals only

Prompt summary: Lock in the current behaviour of link handling with snapshot tests, ahead of a large domain-model refactor that must not change behaviour. Record odd behaviour as it is, and use only synthetic data.

Why

The refactor in #4530 touches the types behind cross-link resolution and links.json. Today only a few hand-picked assertions cover them, so a silent change in a diagnostic or a resolved URL would pass.

What

links.json and the registry

Each manifest shape is read and written again, and the verified JSON is what a later build would publish. Malformed manifests record the exception they throw. LinkRegistry gets the same treatment.

Cross-link resolution

One verified table per link family (plain, anchors, hidden, redirected, floating, unknown, URI quirks) lists the result in six environment shapes: isolated, codex absolute and relative, and publish with and without a path prefix. Registry URL shapes, the API page check and ToTargetUrlPath have their own tables.

Redirects and fetching

redirects.yml cases (scalar, mapping, many, unknown keys, malformed files) record the redirect map and diagnostics. The link registry cache runs against a fake reader and a mock file system. RedirectKvsDiff gets a small table.

Link diagnostics in pages and directives

Four documentation sets hold every link shape (internal, external, cross-link, directive) and snapshot the diagnostics and rendered hrefs.

Inbound link check

LinkIndexService validation is called by reflection against a fake link index, with each filter combination. No product code changed.

Out of scope: AssemblerBuilder.CollectRedirects is private and needs a full builder, so it is not locked. DocSetConfigurationCrossLinkFetcher needs a ConfigurationFile. The new snapshots are self-contained and do not depend on the scrubber being added on snap/config-global. Each new test class was checked by mutating the product code and confirming a failure.

Verify

mise run test
mise run lint
mise run snap:orphans

Cross-link resolution, `links.json` reading and writing, redirect parsing and the inbound link check have no snapshot coverage. The domain-model refactor in [#4530](#4530) must not change their output, so these tests record what they do today, odd cases included. All data is synthetic.

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:01
@Mpdreamz
Mpdreamz requested a review from technige November 16, 2026 21:01
@Mpdreamz Mpdreamz added the chore label Nov 16, 2026
_ = sb.AppendLine("reader calls: " + string.Join(", ", reader.Calls));
_ = sb.AppendLine("declared: " + string.Join(", ", first.DeclaredRepositories.Order()));
_ = sb.AppendLine("entries: " + string.Join(", ", first.LinkIndexEntries.Select(e => $"{e.Key}={e.Value.Path}").Order()));
_ = sb.AppendLine("same references: " + (second.LinkReferences.Count == first.LinkReferences.Count));

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)

Compare the cached manifests, not just the number of references. A cache hit returning manifests with empty Links or missing anchors would still pass this comparison, and the separate disk-cache test discards its fetched result entirely. Assert equivalence between the fresh and cached payloads so these tests detect data loss during cache deserialization.

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

var sb = new StringBuilder();
foreach (var (name, urls, registries) in cases)
{
// declared-only has no LinkIndexEntries, example-repo has one: that is the difference in the message

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: P4 (Info)

The comment says declared-only is the repository without a LinkIndexEntries entry, but this test never resolves declared-only. The repository whose message changes because it has no entry is codex-repo: it gets internal/elastic/codex-repo/links.json in the internal-registry/registry-only cases. Point the comment at codex-repo so readers know what the snapshot is showing.

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

Comment on lines +94 to +101
var filterType = typeof(LinkIndexService).GetNestedType("RepositoryFilter", BindingFlags.NonPublic)!;
var filter = Activator.CreateInstance(filterType, nonPublic: true)!;
filterType.GetProperty("LinksTo")!.SetValue(filter, linksTo);
filterType.GetProperty("LinksFrom")!.SetValue(filter, linksFrom);
var index = Index();
var method = typeof(LinkIndexService).GetMethod("ValidateCrossLinks", BindingFlags.NonPublic | BindingFlags.Instance)!;
var collector = new CapturingCollector();

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)

These tests locate RepositoryFilter, its LinksTo/LinksFrom properties, and ValidateCrossLinks by private names through reflection, then null-forgive each lookup. If a behavior-preserving refactor renames one of these members or changes the method signature, the tests fail during reflection or invocation instead of checking inbound-link behavior. Prefer an accessible test seam, or at least explicit assertions that identify missing members.

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

Comment on lines +350 to +355
var result = registry
.WithLinkRegistryEntry(Entry("example-repo", "main", "older-is-ignored", 1))
.WithLinkRegistryEntry(Entry("example-repo", "main", "same-day-is-ignored", 5))
.WithLinkRegistryEntry(Entry("example-repo", "9.0", "new-branch", 1))
.WithLinkRegistryEntry(Entry("new-repo", "main", "new-repo", 1));
var updated = result.WithLinkRegistryEntry(Entry("example-repo", "main", "newer-wins", 9));

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)

Assert the retained ETag after each older or equal-timestamp update, before applying newer-wins. Currently the final update overwrites any evidence that either earlier entry was incorrectly accepted. Removing the timestamp comparison from WithLinkRegistryEntry would leave every assertion and the snapshot unchanged, so the test does not protect its advertised update-ordering behavior.

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

@github-actions

Copy link
Copy Markdown
Contributor

@Mpdreamz
Mpdreamz merged commit 20bf738 into main Nov 17, 2026
50 checks passed
@Mpdreamz
Mpdreamz deleted the snap/links branch November 17, 2026 09:46
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