Skip to content

Use the Nullean.Snapshots 0.18.0 features in place of local test helpers - #4891

Merged
Mpdreamz merged 3 commits into
mainfrom
chore/snapshots-0.18
Nov 17, 2026
Merged

Mpdreamz merged 3 commits into
mainfrom
chore/snapshots-0.18

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Replaces three hand-written test helpers with what Nullean.Snapshots 0.18.0 ships and adds the Nullean.Snapshots.Objects package. No product code changes.

Affects: Automation

Prompt summary: Use Nullean.Snapshots 0.18.0 and delete the custom snapshot code in this repo that 0.17 and 0.18 make unnecessary, in one PR, without weakening what any snapshot locks.

Why

The snapshot library now covers private-name scrubbing and guarding, readable file names for [Arguments] tests, and object-graph dumps. Keeping the local copies means two implementations to maintain. The tests protect a coming refactor, so every replacement has to lock at least what it locked before.

What

Package

Nullean.Snapshots.Objects 0.18.0 is added to every unit test project through tests/Directory.Build.props. The 0.18.0 bump itself, with its transitive pins (Nullean.HttpFileParser 0.18.0, Nullean.Cdp and Nullean.Cdp.Journeys 0.13.0), is already on main; the journeys project builds against it.

Private repository names

The hand-written regex scrubbers in PrivateRepositoryScrubbing and SnapshotScrubbing are gone. Names found in the loaded assembler config at test time are scrubbed to private-repo_N with Scrubbers.Values, in any case: a name in another case is first written as the config spells it, because Scrubbers.Values is case-sensitive. The same names go to Forbid, as exact values in the config spelling, lower case and upper case. Navigation.Tests forbids the private names of the shipped config/assembler.yml in every baseline snapshot, and Configuration.Tests does so for the whole project through a module initializer. A snapshot or verified file that names one fails with line numbers and no name, and no received file is written.

Forbid takes literals, so a single word is forbidden only as name://, elastic/name/, elastic/name.git and elastic/name". The old pattern (elastic/name followed by anything but a word character or a hyphen, any case) lives on as LeakingLines, which the guard test uses to scan the frozen baseline inputs and verified files, so that guard is as strong as before. Tests cover each trailing character and the end of the line, other cases, and a temp file that must be counted without naming it. The failure tests use the text as its own inline snapshot, so only the forbid check can fail them, and assert the message gives the line, not the value, and that no received file holds the value.

Differences from the old scrubber: placeholders read private-repo_N (the library's format) and are numbered by first appearance, and a name now also matches inside a longer hyphenated token (widget-hosted becomes private-repo_2-hosted). The case-insensitive matching is preserved, and the original mixed-case test is back. One inline snapshot in AssemblerGoldenTests changed from private-repo-1/-2 to private-repo_1/_2, a pure renaming.

Case files without hashes

Three [Arguments] tests now use NameReplacesArguments with a name per case: ApiPropertySearchTests, StreamTransformerCommonBehaviorTests and EmitsError_WhenRepositoryNotInOrgSlashRepoForm. 19 verified files are renamed from {Method}.{hash} to {Method}.{case}. A script confirmed each new file is byte-identical to the old one.

LF fixtures

.gitattributes gets *.cs text eol=lf, so raw-string fixtures read the same on Windows. The two ReplaceLineEndings calls in BundleLoadingSnapshotTests are removed. Kept on purpose: the one in ChangelogConfigurationSnapshotTests (it also covers an embedded .yml resource, which the rule does not touch), the \r\n replace in SyncPlanSnapshotTests (the JSON serializer writes the platform newline, not a fixture), and all path and drive normalisation.

Deliberately kept

ModelDump, ChangelogConfigurationDump and BaselineDumps stay. MatchObjectSnapshot sorts map keys and writes no type names. I checked this on the versions baseline: the old dump keeps the load order of the dictionary (Stack, All, Ece) and the object dump sorts it. Load order and polymorphic type labels are part of what these snapshots lock before the refactor, and converting would also rewrite about 80 verified files from text or JSON to YAML. BaselineDumps is a text renderer, not a reflection dump. The case tables in AppliesTo and Applicability are already one verified file per table, so splitting them would change content, not names.

Docs

The snapshot section of AGENTS.md describes Scrubbers.Values with Forbid, MatchObjectSnapshot and its limits, NameReplacesArguments, and the eol=lf rule. docs/ has no snapshot conventions to update.

Verify

mise run test
CI=true mise run test
mise run lint
mise run snap:status && mise run snap:orphans
dotnet build tests/Elastic.Documentation.Journeys.Tests

I broke the code once under each converted test class (the case-file tests and the private-name guards), confirmed red, and reverted. The scan for private repository names over the diff and the changed files finds nothing.

🤖 Generated with Claude Code

@Mpdreamz
Mpdreamz requested a review from a team as a code owner November 17, 2026 12:56
@Mpdreamz
Mpdreamz requested a review from reakaleek November 17, 2026 12:56
Comment on lines 34 to +40
/// </summary>
internal static Func<string, string> For(IEnumerable<string> privateRepositories)
{
var names = privateRepositories
.Where(n => !string.IsNullOrWhiteSpace(n) && !n.StartsWith(PlaceholderPrefix, StringComparison.Ordinal))
.Distinct(StringComparer.Ordinal)
.OrderBy(n => n, StringComparer.Ordinal)
.ToArray();
if (names.Length == 0)
return text => text;
internal static string[] Forbidden(IEnumerable<string> privateRepositories) =>
[
.. Real(privateRepositories).SelectMany(
n => n.Contains('-') ? [n] : new[] { $"{n}://", $"elastic/{n}/", $"elastic/{n}.git", $"elastic/{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 guard for single-word private names is weaker than its doc comment and than the old scrubber. The comment says elastic/name is forbidden when followed by a quote, slash, dot, colon or whitespace. The code only forbids elastic/{n}/, elastic/{n}.git and elastic/{n}". So these all get past both the Forbid guard and FrozenBaseline_ContainsNoPrivateRepositoryOfTheShippedConfig: elastic/name at the end of a line (for example an unquoted YAML value), elastic/name:, elastic/name #, elastic/name), elastic/name#readme and elastic/name?x. The old pattern (?<=elastic/)name(?![\w-]) caught every one of them. Either forbid each character the comment lists, plus end-of-line, or use a pattern-based check.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in eb690b9. Forbid keeps the exact values it can cover (now also lower and upper case) and the doc comment lists them. A new case-insensitive LeakingLines check, with the old lookahead and the end of the line included, scans the frozen baselines and verified files. New tests cover end of line, ., :, #, ), #readme, ?x, a quote and a slash, plus -hosted, _x and x that must not match, and a temp file that must be counted without naming it.

Comment on lines +41 to +42
internal static void AddPrivateRepositories(IEnumerable<string> names) =>
PrivateRepositoryNames.Value = PrivateRepositoryScrubbing.Scrub(names);

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 used to match names case-insensitively (RegexOptions.IgnoreCase). It now goes through Scrubbers.Values, which is case-sensitive, and the module-initializer Forbid guard is also an ordinal match. So a private name that the input writes in another case (for example elastic/WIDGET in a URL) now reaches the snapshot unscrubbed and is not caught. The PR describes every difference as stricter, but this one loosens the guard, and the WIDGET test that covered it was changed to lowercase instead of kept. Either add case-insensitive variants to the scrub and forbid lists, or keep a regression test for mixed case.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in eb690b9. The scrub writes any case of a name as the config spells it, then runs Scrubbers.Values, so the old behaviour is kept and the numbering is shared across cases. The forbid values and the pattern check cover other cases too. The original elastic/WIDGET regression test is back and passes.

…ixtures

The 0.18.0 bump ships what three test helpers did by hand. Private
repository names are now scrubbed with Scrubbers.Values and forbidden with
Forbid, so a leaking snapshot fails with line numbers and no name. The
[Arguments] snapshot tests name their files after the case instead of a
hash. C# files are eol=lf, so the bundle fixtures no longer rewrite line
endings. Nullean.Snapshots.Objects is added for object-graph snapshots.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Mpdreamz
Mpdreamz force-pushed the chore/snapshots-0.18 branch from 6d25c0c to 2e82c6c Compare November 17, 2026 13:01
@Mpdreamz Mpdreamz changed the title Move to Nullean.Snapshots 0.18.0 and use what it ships Use the Nullean.Snapshots 0.18.0 features in place of local test helpers Nov 17, 2026
Comment on lines +116 to +134
public void Options_ASnapshotThatNamesAPrivateRepository_FailsWithoutShowingTheName()
{
var shipped = PrivateRepositoryScrubbing.Forbidden(ShippedPrivateRepositories()).First(n => n.Contains('-'));
var options = new SnapshotOptions().Forbid([shipped]);

var message = string.Empty;
try
{
$"first line\nrepository {shipped}\n".Should().MatchSnapshot(options: options);
}
catch (Exception e)
{
message = e.Message;
}

message.Should().NotBeEmpty("the snapshot must fail");
// a failing check must not repeat the name either
message.Contains(shipped, StringComparison.Ordinal).Should().BeFalse("the message names a private repository");
}

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)

This test cannot tell whether Forbid works. It calls MatchSnapshot with no verified file, so the call throws for a missing snapshot even when the forbid check never runs, and message.Should().NotBeEmpty("the snapshot must fail") passes either way. If Forbid regressed, the library could also write a received file with the real private name to .artifacts/.snapshots/received/, which CI uploads as an artifact. Assert that the failure comes from the forbid check (for example, the message reports the forbidden line number). Better, use an inline snapshot or a verified file so the missing-snapshot path can't satisfy the test.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in eb690b9, and the Configuration.Tests twin too. Both now go through ForbidProbe: the text is its own inline snapshot, so it passes when the forbid check does not run and only that check can make the call throw. The tests assert the failure, that the message reports the line and not the value, and that no file under the received folder holds the value. I broke Forbid (and the default guard registration) and the tests went red.

@github-actions

Copy link
Copy Markdown
Contributor

Mpdreamz and others added 2 commits November 17, 2026 14:12
The markdown writer uses AppendLine, so it emits CRLF on Windows while the raw-string expectations are LF.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The single-word guard missed a name at the end of a line and before a
colon, a bracket or a query, and the scrub and guard ignored case. A
pattern check, case-insensitive and ending at any non-word character,
now scans the frozen files, the scrub reads any case, and the forbid
values cover lower and upper case. The forbid tests use the text as its
own inline snapshot, so only the forbid check can fail it, and they
assert that no received file holds the value.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Mpdreamz
Mpdreamz merged commit a7f5e7f into main Nov 17, 2026
43 of 44 checks passed
@Mpdreamz
Mpdreamz deleted the chore/snapshots-0.18 branch November 17, 2026 13:37
Mpdreamz added a commit that referenced this pull request Nov 18, 2026
`.gitattributes` has checked out `*.cs` with LF on every system since #4891, but `.editorconfig` set no `end_of_line`, so curb expects the platform default. On Windows that is CRLF, and curb reports every C# file as unformatted (`CURB0001`).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Mpdreamz added a commit that referenced this pull request Nov 18, 2026
…ase on formatting (#4925)

* Run the per-project curb check on Windows builds with high log output

The Windows release publish failed with `CURB0001` on files that are formatted, and PR checks never run `curb` on Windows, so the cause is invisible. The Windows `build` job now keeps the check and sets `Curb_LogLevel` to `high`.

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

* Pin end_of_line to lf for C# and F# so curb agrees with .gitattributes on Windows

The Windows build reported CURB0001 on five files that are formatted and have LF endings in the checkout. .editorconfig set no end_of_line for them, so curb can fall back to the platform's CRLF there.

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

* Tell curb that C# files use LF line endings

`.gitattributes` has checked out `*.cs` with LF on every system since #4891, but `.editorconfig` set no `end_of_line`, so curb expects the platform default. On Windows that is CRLF, and curb reports every C# file as unformatted (`CURB0001`).

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

* Bypass curb in the release publish and run curb 0.15.1 in lint

The Windows build keeps `Curb_Bypass` as before. The release publish sets it too, so formatting never fails a release, and the `lint` job runs the curb version pinned in `dotnet-tools.json`.

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

* Drop the duplicate end_of_line in the C# section

The shared `[*.{fs,fsx,cs,vb}]` section already sets `end_of_line = lf`.

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

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant