Skip to content

test: let a golden baseline hold a text of another language than SQL - #74

Open
xperiandri wants to merge 1 commit into
mainfrom
test/baseline-extension
Open

xperiandri wants to merge 1 commit into
mainfrom
test/baseline-extension

Conversation

@xperiandri

@xperiandri xperiandri commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Baseline can now compare a golden file of another language than SQL, for example a Groovy script. The tests of the Gremlin libraries will compare their Groovy scripts in this way, as the tests of the query translator compare SQL. This is the second step of the plan for the Gremlin libraries. It is independent of the first step (branch feat/cosmos-json-package).

Change

  • Baseline.compareText and Baseline.assertTextMatches take the extension of the text file as their first argument, for example groovy. The files are Baselines/<suite>/<case>.<extension> and Baselines/<suite>/<case>.params.json.
  • They compare two texts after Baseline.normalizeText, which changes only the line breaks and the whitespace at both ends. In Groovy, a line break ends a comment: g.V() // all followed by .hasLabel('P') on the next line is another script than the same text on one line.
  • Baseline.compare and Baseline.assertMatches use Baseline.SqlExtension (sql) and still compare after Baseline.normalizeSql, which collapses the whitespace. Thus the tests that compare SQL do not change.
  • compareText refuses an extension that is empty, starts with a dot, cannot be part of a file name, or is the extension of the parameter file (params.json, in capital or small letters). On Windows and macOS, a text file with that extension is the parameter file.
  • A suite, a case name or an extension must not end with a dot or a space. Windows removes such a character from the end of a file or directory name. Thus the extension params.json. would give the parameter file, and the suite Suite. would give the directory Suite.
  • The union cases Comparison.Missing and Comparison.Rewritten name their path textPath.
  • The description of COSMOS_REWRITE_BASELINES in .github/copilot-instructions.md names assertTextMatches.

On main and on the open branches, only BaselineTests uses Baseline. Thus the new names break no other code.

Tests

  • New tests: a round trip of a groovy baseline, which also checks that compare looks for the .sql file of the same case; a text that differs from its baseline only in a line break; a text that differs only in the kind of line break; normalizeText; the two assertion functions; eight extensions that compareText refuses; two suite names that end with a dot or a space.
  • The 28 tests of BaselineTests pass. 16 of them are new.
  • To check the new tests, I planted defects: I changed the new code in 13 small, incorrect ways, one change at a time, and ran the tests after each change. Each change made at least one test fail. Examples: no check of the leading dot, of the extension of the parameter file, or of a dot or a space at the end; a path that ignores the extension; a compareText that collapses whitespace and a compare that does not; a normalizeText that keeps a carriage return or does not trim; an assertMatches that compares exactly; an assertion that ignores a difference.

Review

Round 1 (Copilot): a dot or a space at the end of an extension, and the line breaks of a text other than SQL. The commit has the fixes for both.

Not in this change

The plan had an overridable CleanupAsync of the emulator fixture in this step too. It moves to the step that adds the fixture of the Gremlin emulator tests, its only user.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Test baseline tooling now supports text files with caller-selected extensions, in addition to SQL baselines. Text comparisons normalize line endings and trim only the beginning and end, preserving internal whitespace.
    • Text baselines follow the existing rewrite behavior: rewrite attempts are inconclusive, and rewriting is not allowed in CI.
  • Documentation

    • Clarified that baseline rewriting applies to text comparisons as well as SQL.

@xperiandri
xperiandri requested a balanced review from Copilot November 8, 2026 00:42
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a29b249-36be-4a3d-b790-e17414c8b27f
Commits

Reviewing files that changed from the base of the PR and between 9a083d4 and 75ca625.

Files selected for processing: 3

  • .github/copilot-instructions.md
  • tests/Cosmos.Tests.Infrastructure/Baseline.fs
  • tests/Cosmos.Tests/TestInfrastructure/BaselineTests.fs

No actionable comments were generated in the recent review.

Walkthrough

The baseline module now supports comparisons and assertions for arbitrary text files with caller-selected extensions. SQL comparisons retain SQL normalization. Text comparisons normalize line endings and trim text ends while preserving internal whitespace.

Changes: Baseline comparison and assertions

Layer / File(s) Summary
Shared baseline comparison
tests/Cosmos.Tests.Infrastructure/Baseline.fs, tests/Cosmos.Tests/TestInfrastructure/BaselineTests.fs
Shared comparison logic accepts an extension and normalizer. Text normalization converts line endings to LF and trims the ends. Name and extension validation rejects invalid values. Tests cover normalization and validation.
Text comparison and assertion APIs
tests/Cosmos.Tests.Infrastructure/Baseline.fs, tests/Cosmos.Tests/TestInfrastructure/BaselineTests.fs, .github/copilot-instructions.md
compareText and assertTextMatches support text baselines. SQL and text assertions share rewrite-mode checks and reporting. Tests cover text comparisons, assertion results, and SQL compatibility. Documentation includes a text-baseline example.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant TestCaller
  participant assertTextMatches
  participant compareText
  participant compareWith
  participant BaselineFiles
  TestCaller->>assertTextMatches: Submit text, extension, and case details
  assertTextMatches->>compareText: Request text baseline comparison
  compareText->>compareWith: Provide normalized text and extension
  compareWith->>BaselineFiles: Read or rewrite text and parameter baselines
  compareWith-->>assertTextMatches: Return comparison result
  assertTextMatches-->>TestCaller: Report match, failure, or inconclusive rewrite
Loading
Merge Risk: Minimal · previous review 9a083

This change extends the test baseline helpers to hold non-SQL text such as Groovy scripts. It affects only test infrastructure, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "test: let a golden baseline hold a text of another language than SQL" matches the main change. The PR adds extension-aware text baseline comparison (compareText and assertTextMatches) so a …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "test: let a golden baseline hold a text of another language than SQL" matches the main change. The PR adds extension-aware text baseline comparison (compareText and assertTextMatches) so a golden baseline can hold non-SQL text such as Groovy scripts. The title names the primary change and uses a conventional commit prefix. It is specific and does not use vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e57aca55-d168-4ed5-9390-4b6fb3de4dca
Commits

Reviewing files that changed from the base of the PR and between ef5d60b and 9a083d4.

Files selected for processing: 3

  • .github/copilot-instructions.md
  • tests/Cosmos.Tests.Infrastructure/Baseline.fs
  • tests/Cosmos.Tests/TestInfrastructure/BaselineTests.fs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unrejected Windows filename aliases can overwrite or delete scripts, while whitespace normalization can falsely report semantically different Groovy scripts as matching.

2 open issues
What changed in this PR

Extends the shared golden-baseline helpers beyond SQL to support future Gremlin script tests, while preserving the existing SQL comparison APIs.

Changes:

  • Adds extension-based compareText and assertTextMatches helpers with extension validation.
  • Adds Groovy round-trip, SQL-wrapper, and invalid-extension tests.
  • Updates naming and documentation to describe language-independent text baselines.
File Description
tests/​Cosmos.Tests/​TestInfrastructure/​BaselineTests.fs Tests custom extensions, SQL compatibility, and extension rejection.
tests/​Cosmos.Tests.Infrastructure/​Baseline.fs Generalizes baseline comparison and assertions while retaining SQL wrappers.
.github/​copilot-instructions.md Documents rewriting baselines for languages other than SQL.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The comparison-mode test expects AssertFailedException but receives AssertInconclusiveException when baseline rewriting is enabled outside CI, causing it to fail during the documented rewrite workflow.

1 open issue
2 resolved since last review

Review effort: Balanced


[<TestMethod>]
member _.``assertTextMatches fails the test for a text that differs from its baseline in a line break`` () =
inTemporaryDirectory (fun directory ->
The tests of the Gremlin libraries will compare Groovy scripts with golden
files, as the tests of the query translator compare SQL. `Baseline` wrote
and read only `<case>.sql`.

`Baseline.compareText` and `Baseline.assertTextMatches` take the extension
of the text file as their first argument, for example `groovy`. They
compare two texts after `normalizeText`, which changes only the line breaks
and the whitespace at both ends. In Groovy, a line break ends a comment, so
the line breaks must count. `Baseline.compare` and `Baseline.assertMatches`
use `SqlExtension` and still collapse the whitespace of a query with
`normalizeSql`. Thus the tests that compare SQL do not change.
`Baseline.isRewriting` tells whether the assertions write the baselines
instead of comparing them, so that a test of an assertion can be
inconclusive then.

`compareText` refuses an extension that is empty, starts with a dot, cannot
be part of a file name, or is the extension of the parameter file
(`params.json`, in capital or small letters). A suite, a case name or an
extension must not end with a dot or a space: Windows removes such a
character from the end of a file or directory name, so the extension
`params.json.` would give the parameter file.

The union cases `Missing` and `Rewritten` name their path `textPath`,
because the text can be other than SQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xperiandri
xperiandri force-pushed the test/baseline-extension branch from 9a083d4 to 75ca625 Compare November 8, 2026 02:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants