Repository navigation
Snapshot-test link handling before the domain-model refactor - #4878
Conversation
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]>
| _ = 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)); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| 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(); | ||
|
|
There was a problem hiding this comment.
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.
| 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)); |
There was a problem hiding this comment.
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.
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4878/ |
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.jsonand the registryEach 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.
LinkRegistrygets 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
ToTargetUrlPathhave their own tables.Redirects and fetching
redirects.ymlcases (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.RedirectKvsDiffgets 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
LinkIndexServicevalidation is called by reflection against a fake link index, with each filter combination. No product code changed.Out of scope:
AssemblerBuilder.CollectRedirectsis private and needs a full builder, so it is not locked.DocSetConfigurationCrossLinkFetcherneeds aConfigurationFile. The new snapshots are self-contained and do not depend on the scrubber being added onsnap/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