Repository navigation
Use the Nullean.Snapshots 0.18.0 features in place of local test helpers - #4891
Conversation
| /// </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}\"" } | ||
| ) | ||
| ]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| internal static void AddPrivateRepositories(IEnumerable<string> names) => | ||
| PrivateRepositoryNames.Value = PrivateRepositoryScrubbing.Scrub(names); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
6d25c0c to
2e82c6c
Compare
| 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"); | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4891/ Sample changed pages: |
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]>
`.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]>
…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]>
Replaces three hand-written test helpers with what Nullean.Snapshots 0.18.0 ships and adds the
Nullean.Snapshots.Objectspackage. 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.Objects0.18.0 is added to every unit test project throughtests/Directory.Build.props. The 0.18.0 bump itself, with its transitive pins (Nullean.HttpFileParser0.18.0,Nullean.CdpandNullean.Cdp.Journeys0.13.0), is already on main; the journeys project builds against it.Private repository names
The hand-written regex scrubbers in
PrivateRepositoryScrubbingandSnapshotScrubbingare gone. Names found in the loaded assembler config at test time are scrubbed toprivate-repo_NwithScrubbers.Values, in any case: a name in another case is first written as the config spells it, becauseScrubbers.Valuesis case-sensitive. The same names go toForbid, as exact values in the config spelling, lower case and upper case.Navigation.Testsforbids the private names of the shippedconfig/assembler.ymlin every baseline snapshot, andConfiguration.Testsdoes 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.Forbidtakes literals, so a single word is forbidden only asname://,elastic/name/,elastic/name.gitandelastic/name". The old pattern (elastic/namefollowed by anything but a word character or a hyphen, any case) lives on asLeakingLines, 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-hostedbecomesprivate-repo_2-hosted). The case-insensitive matching is preserved, and the original mixed-case test is back. One inline snapshot inAssemblerGoldenTestschanged fromprivate-repo-1/-2toprivate-repo_1/_2, a pure renaming.Case files without hashes
Three
[Arguments]tests now useNameReplacesArgumentswith a name per case:ApiPropertySearchTests,StreamTransformerCommonBehaviorTestsandEmitsError_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
.gitattributesgets*.cs text eol=lf, so raw-string fixtures read the same on Windows. The twoReplaceLineEndingscalls inBundleLoadingSnapshotTestsare removed. Kept on purpose: the one inChangelogConfigurationSnapshotTests(it also covers an embedded.ymlresource, which the rule does not touch), the\r\nreplace inSyncPlanSnapshotTests(the JSON serializer writes the platform newline, not a fixture), and all path and drive normalisation.Deliberately kept
ModelDump,ChangelogConfigurationDumpandBaselineDumpsstay.MatchObjectSnapshotsorts 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.BaselineDumpsis a text renderer, not a reflection dump. The case tables inAppliesToandApplicabilityare already one verified file per table, so splitting them would change content, not names.Docs
The snapshot section of
AGENTS.mddescribesScrubbers.ValueswithForbid,MatchObjectSnapshotand its limits,NameReplacesArguments, and theeol=lfrule.docs/has no snapshot conventions to update.Verify
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