Skip to content

Tests: Add portable CLI contracts for the Rust port - #304

Open
Mike Krüger (mkrueger) wants to merge 16 commits into
mainfrom
dev/mkrueger/cli-contract-tests
Open

Mike Krüger (mkrueger) wants to merge 16 commits into
mainfrom
dev/mkrueger/cli-contract-tests

Conversation

@mkrueger

@mkrueger Mike Krüger (mkrueger) commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add a Python/pytest suite that checks observable behavior against a real shell executable. The same cases can run against the C# reference and a future Rust build without changing the assertions.
  • Mirror selected xUnit behavior in portable contracts and link cases to their source tests. Keep the original xUnit assertions for the official OneBranch pipeline, which does not yet run the portable suite.
  • Cover all built-in commands except jq: 46 have successful invocations, and edit verifies the noninteractive error and absence of file creation. Emulator fixtures seed and verify item mutations independently through the Python Cosmos SDK.
  • Run offline and emulator profiles in CI. Include coverage from Python-launched C# shell processes; publish combined coverage only when both collectors succeed.

Emulator CI stability

Pin the Linux preview emulator to the exact image digest verified in #305 and block startup package updates that replace modules under running PostgreSQL (Azure/azure-cosmos-db-emulator-docker#390). Keep the .NET tests, both portable emulator profiles, and all assertions enabled.

Introduce a Python runner with strict output comparisons, shared offline and emulator cases, independent fixtures, and migration tracking. Wire CI and document the cross-implementation testing workflow while retaining existing C# coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Exercise filter behavior through the executable so the Rust port can run the same cases. Track removed xUnit methods and validate their replacement case links.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Exercise the seven output-only scenarios through the shell executable. Cover optional property access on scalar input and retain a C# check for ShellJson normalization before rendering.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Exercise redirection, script arguments, help and filter behavior through the executable while retaining internal type and parser checks in xUnit. Collect coverage from the Python-launched shell alongside the solution tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add successful invocations where possible and verify that edit refuses noninteractive use without creating files. Tighten structured output assertions and publish combined coverage only when both collectors succeed.

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 contract tests do not reliably enforce English application UI culture, and emulator validation accepts hosts unsupported by the reference shell, risking false failures and connection or authentication errors.

2 open issues
What changed in this PR

Adds executable-level CLI contracts for validating the C# shell and a future Rust implementation against the same observable behavior.

Changes:

  • Introduces a Python runner, strict output comparisons, and independently managed emulator fixtures.
  • Moves selected behavioral assertions from xUnit into portable contracts while retaining implementation-specific checks.
  • Adds cross-platform CI execution, combined C# coverage, and migration guidance.
File Description
tests/​cli-contracts/​test_runner.py Tests process isolation, timeouts, paths, and manifest validation.
tests/​cli-contracts/​test_reviewed_expectations.py Checks that reviewed expectations reject malformed output.
tests/​cli-contracts/​test_inventory.py Tests source links and migration accounting.
tests/​cli-contracts/​test_emulator_fixtures.py Tests fixture validation, verification, and cleanup.
tests/​cli-contracts/​test_contracts.py Executes contracts and captures failure artifacts.
tests/​cli-contracts/​test_comparisons.py Tests strict output comparison behavior.
tests/​cli-contracts/​schema.json Defines the contract manifest format.
tests/​cli-contracts/​runner.py Launches isolated shell processes and checks results.
tests/​cli-contracts/​requirements.txt Pins runner dependencies.
tests/​cli-contracts/​requirements-emulator.txt Adds the independent Cosmos SDK dependency.
tests/​cli-contracts/​inventory.py Audits xUnit methods and contract migration links.
tests/​cli-contracts/​emulator.py Seeds, verifies, and cleans emulator resources.
tests/​cli-contracts/​coverage.config Limits coverage collection to product assemblies.
tests/​cli-contracts/​conftest.py Configures launchers and profile selection.
tests/​cli-contracts/​comparisons.py Implements structured, text, and byte comparisons.
tests/​cli-contracts/​cases/​offline/​value-semantics.json Covers numeric, JSON, scope, and return semantics.
tests/​cli-contracts/​cases/​offline/​startup.json Covers startup options and string handling.
tests/​cli-contracts/​cases/​offline/​import.json Covers import dry runs and output formats.
tests/​cli-contracts/​cases/​offline/​errors.json Covers diagnostics, failures, and error redirection.
tests/​cli-contracts/​cases/​offline/​echo-and-files.json Covers echo, files, and output redirection.
tests/​cli-contracts/​cases/​offline/​control-flow.json Covers loops, conditions, and script arguments.
tests/​cli-contracts/​cases/​offline/​contracts.json Defines structured metadata and result expectations.
tests/​cli-contracts/​cases/​offline/​command-smoke.json Exercises offline commands and noninteractive editor rejection.
tests/​cli-contracts/​cases/​offline/​binding.json Checks invalid-option handling across commands.
tests/​cli-contracts/​cases/​emulator/​resources.json Covers connection, navigation, and resource lifecycle.
tests/​cli-contracts/​cases/​emulator/​partition-keys.json Covers typed, hierarchical, and colliding partition keys.
tests/​cli-contracts/​cases/​emulator/​data.json Covers item mutations, queries, and conditional deletion.
tests/​cli-contracts/​cases/​emulator/​command-smoke.json Exercises metadata, change feed, and script registration commands.
tests/​cli-contracts/​cases/​emulator/​bulk.json Covers bulk previews and mixed-partition operations.
tests/​cli-contracts/​cases/​emulator/​batch-and-files.json Covers transactions, rollback, import, and export.
docs/​cli-contract-tests.md Documents execution, comparisons, coverage, and migration.
CosmosDBShell.Tests/​Parser/​FilterPathExpressionTests.cs Retains internal path-result and exception checks.
CosmosDBShell.Tests/​Parser/​FilterBuiltinsTests.cs Retains internal types and decimal representation checks.
CosmosDBShell.Tests/​Integration/​VersionAndHelpTests.cs Consolidates retained internal result-type checks.
CosmosDBShell.Tests/​Integration/​ScriptArgumentTests.cs Removes migrated tests while retaining internal assertions.
CosmosDBShell.Tests/​Integration/​OutputRedirectionTests.cs Removes tests replaced by portable redirection contracts.
CosmosDBShell.Tests/​Integration/​FilterIntegrationTests.cs Removes tests replaced by portable filter contracts.
CosmosDBShell.Tests/​Integration/​EchoTests.cs Removes tests replaced by portable echo contracts.
CosmosDBShell.Tests/​CommandTests/​FilterCommandTests.cs Retains normalization, ownership, cancellation, and exception checks.
CONTRIBUTING.md Adds portable contract contribution guidance.
.gitignore Excludes Python environment and pytest cache files.
.github/​workflows/​validate-and-package.yml Collects and combines xUnit and CLI product coverage.
.github/​workflows/​integration-tests.yml Runs offline and emulator contract profiles in CI.
.config/​dotnet-tools.json Adds the C# coverage collector.

Review effort: Balanced

Comment thread tests/cli-contracts/emulator.py Resolved
Comment thread tests/cli-contracts/runner.py Resolved
Resolve the RID-specific shell assembly through MSBuild, pin application UI language independently of the host, and match the reference emulator host list. Addresses review and CI failures in PR #304.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:14
Use an explicit fixture catalog because clean checkouts ship only the English source catalog. Covers PR #304.

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

Startup crashes when English is forced under invariant globalization, and the German integration case fails on clean builds that lack the generated German catalog.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread CosmosDBShell/Program.cs Resolved
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:21

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.

🔵 Needs a closer look

Explicit English UI-language selection crashes startup in the documented invariant-globalization mode, and the official pipeline omits the migrated behavioral checks.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Run portable behavioral contracts in the official pipeline

CosmosDBShell.Tests/​Parser/​FilterBuiltinsTests.cs:59

The replacement theory checks only CLR result types; the value assertions now run exclusively in pytest. However, .pipelines/CosmosDB-Shell-Official.yml:170–175 still runs only solution tests, and no step in that pipeline invokes the portable suite. Consequently the official build loses the migrated behavioral checks (including sorting, containment, and path results), even though GitHub Actions runs their replacements. Please add the offline contracts to the official pipeline, or retain the value assertions until that entry point runs the replacements.

1 resolved since last review

Review effort: Balanced

Use the invariant UI culture for the English catalog and exercise the combination in PR #304.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:32
Keep the portable contracts alongside the original xUnit assertions until the official OneBranch pipeline runs both suites. Addresses the review overview in PR #304.

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.

🔵 Needs a closer look

Human judgment is needed to weigh an unpublished documentation nit that causes the offline CLI examples to require a connection instead of producing the expected JSON.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:37

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 contract checks allow malformed error diagnostics and incorrect or additional numeric output to pass, weakening their ability to detect compatibility regressions.

2 open issues

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 3628267 dev/mkrueger/cli-con... aa7892a +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 3628267 dev/mkrueger/cli-con... aa7892a +/-
D:\a\CosmosDBSh...ainerCommand.cs 24% 15% -9%
D:\a\CosmosDBSh...BatchCommand.cs 54% 51% -3%
D:\a\CosmosDBSh...ThemeCommand.cs 73% 71% -2%
D:\a\CosmosDBSh...lInterpreter.cs 81% 80% -1%
D:\a\CosmosDBSh...mportCommand.cs 97% 96% -1%
D:\a\CosmosDBSh...SprocCommand.cs 58% 57% -1%
D:\a\CosmosDBSh....Highlighter.cs 82% 82% 0%
D:\a\CosmosDBSh...hell\Program.cs 85% 85% 0%
D:\a\CosmosDBSh...tementParser.cs 78% 79% +1%
D:\a\CosmosDBSh...ttingHandler.cs 59% 60% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 25, 2026 11:04 UTC

Copilot AI balanced review requested due to automatic review settings November 20, 2026 14:01

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.

🟢 Approval recommended

No active review issues remain for the CLI contract testing changes.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 20, 2026 14:36

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.

🔵 Needs a closer look

Human assessment is needed because the JSONL comparator can reject valid records containing legal Unicode line separators, producing serialization-dependent results.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

…304)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 15:46

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.

🔵 Needs a closer look

Human assessment is needed because a moderate-severity localization issue affecting LSP startup was omitted from the published review.

No open issues 🎉

Review effort: Balanced

Use the preview image verified by PR #305 and prevent startup package updates from replacing PostgreSQL modules. Keep all test profiles and assertions enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 10:36

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.

🔵 Needs a closer look

The offline review could not verify restoration of dotnet-coverage 18.12.0 from OneBranch’s exclusive CosmosDB_PublicPackages feed or child-process coverage collection in Windows CI.

No open issues 🎉

Review effort: Balanced

Resolve emulator image and contributor documentation conflicts while preserving portable contract jobs and all test expectations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 14:16

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.

🟢 Approval recommended

No active review issues are recorded for the executable-level compatibility testing changes.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 25, 2026 09:27

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.

🔵 Needs a closer look

CI must verify profiler coverage collection across child processes, merged product hits, and dotnet-coverage 18.12.0 restoration from OneBranch’s restricted feed, none of which could be confirmed in this dependency-free review.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 25, 2026 10:54

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.

🟢 Approval recommended

There are no active review issues blocking the portable CLI contract testing changes.

No open issues 🎉

Review effort: Balanced

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