test: expand unit coverage for parser and offline command paths#121
Merged
Conversation
Add ReportGenerator as a local dotnet tool and a coverage.ps1 script that runs the tests with coverlet and produces an HTML report with per-namespace breakdown. Add a VS Code 'coverage' task and integrate coverage into the Validate And Package workflow: collect Cobertura coverage, render a GitHub markdown summary into the job summary, and upload the HTML report as an artifact.
Adds focused tests for MakeDb, Bucket, Delete, Print/Replace/Patch, and IndexPolicy/RmContainer/Edit commands covering validation and wrong-scope branches that run without an emulator.
Adds offline tests for current/list/show/use/set/load/save/reload and unknown-action branches, including file-backed load and save paths, without launching an editor or file browser.
Add focused conversion tests for ShellJson, ShellIdentifier, and ShellSequence covering every DataType branch including error paths, raising coverage of the low-covered Shell value types.
Add FoldingRangeHandler tests (no-document, no/single/multi-line braces, nested, unbalanced) and CosmosShellWorkspace tests (open/update/close/get, word-at-position, completion context, parse diagnostics), raising coverage of previously 0%/low-covered LSP classes.
…dges Add tests for ClearCurrentLineCommand and ClearScreenCommand (previously 0% covered) plus no-match branches of ReverseHistorySearch FindInitial/FindInitialForward/FindPrevious.
Add CallToolHandler/ListToolsHandler tests exercising null params, unknown command, MCP-restricted command, unknown argument, missing required parameter, sanitized invalid-value errors, and the echo success path. Add ResourceOperations tests for the embedded scripting guide and query-language reference.
Add focused unit tests for the Azure.Data.Cosmos.Shell.Parser namespace: operator evaluation, control-flow execution (if/while/do-while/for/loop, break/continue, element-kind binding), filter builtins (type/length/keys/contains/select/sort_by) and equality/compare branches, JSON array/object construction, filter path/index/iterate expressions, command dispatch and option/positional binding via CommandExpression, ExecStatement and loop positional-error wrapping, ShellObject.Parse, PositionalErrorHelper/PositionalException, AST visitor walk, and statement/expression parser edge and error-recovery cases.
Add tests for CatCommand reading existing/empty files into a ShellText result, throwing CommandException on missing or null paths, and the unused state-visitor methods (previously 40% covered).
Add tests for RmCommand error and state-visitor branches that run without a live Cosmos connection: missing pattern/pipe input throws CommandException, disconnected state throws NotConnectedException, and connected/database states without a target container throw NotInContainerException (previously 40% covered).
Extend MakeItemCommand tests with the remaining ParseJson value kinds (long/double, booleans, null, nested arrays/objects) and the ExecuteAsync input-validation branches: missing data/pipe throws CommandException, and data or pipe input while disconnected throws NotConnectedException (previously 33% covered).
Add tests for the non-finite interval branch of ResolveInterval (NaN/Infinity throws CommandException) and the ExecuteAsync guards (null shell throws ArgumentNullException, disconnected state throws NotConnectedException). The long-running change feed loop still requires a live connection and is out of scope for unit tests.
Contributor
There was a problem hiding this comment.
Pull request overview
Expands offline unit test coverage across the Azure.Data.Cosmos.Shell.Parser namespace and several under-tested command paths, and adds a lightweight local/CI code-coverage reporting workflow to make coverage results easier to inspect.
Changes:
- Added extensive parser-focused unit tests covering statement parsing/execution, filter expressions/builtins, JSON construction, positional error wrapping, and AST visitor traversal.
- Added offline command/unit tests for multiple command guards and dispatch/routing branches (e.g., theme actions, MCP tool operations, item write validation, watch interval validation).
- Added local + CI coverage report generation (PowerShell script, VS Code task, CI artifact upload + job summary).
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/coverage.ps1 | New helper script to run tests with coverage and generate an HTML/text report locally. |
| CosmosDBShell.Tests/ToolOperationsCallToolTests.cs | Adds tests for MCP tool call/list handlers, including error sanitization and restricted commands. |
| CosmosDBShell.Tests/Shell/HotkeyCommandTests.cs | Adds tests for additional hotkey command behaviors and reverse-search helpers. |
| CosmosDBShell.Tests/ResourceOperationsTests.cs | Verifies embedded MCP resource markdown is non-empty and stable. |
| CosmosDBShell.Tests/Parser/StatementPositionalErrorTests.cs | Covers loop-body error wrapping into PositionalException when script context is present. |
| CosmosDBShell.Tests/Parser/StatementParserStructureTests.cs | Covers redirects, option value syntaxes, and JSON-path variable parsing. |
| CosmosDBShell.Tests/Parser/StatementParserEdgeTests.cs | Covers pipe/exec/def parsing, error recovery, and tolerant parsing behaviors. |
| CosmosDBShell.Tests/Parser/StatementExecutionTests.cs | Executes full scripts to cover control-flow statement runtime branches. |
| CosmosDBShell.Tests/Parser/ShellObjectParseTests.cs | Adds unit tests for ShellObject.Parse(Lexer) token-to-object mapping. |
| CosmosDBShell.Tests/Parser/ShellObjectConversionTests.cs | Adds conversion tests across ShellObject variants and error branches. |
| CosmosDBShell.Tests/Parser/PositionalErrorTests.cs | Tests line/column resolution and PositionalException carrier behavior. |
| CosmosDBShell.Tests/Parser/OperatorEvaluationTests.cs | Exercises arithmetic/comparison/logical/unary operator evaluation paths. |
| CosmosDBShell.Tests/Parser/JsonConstructionTests.cs | Tests JSON object/array construction across value-kind branches. |
| CosmosDBShell.Tests/Parser/FilterPathExpressionTests.cs | Tests filter-path navigation, optional segments, and type-mismatch errors. |
| CosmosDBShell.Tests/Parser/FilterBuiltinsTests.cs | Tests builtin filter functions and helper comparison/equality branches. |
| CosmosDBShell.Tests/Parser/ExpressionParserErrorTests.cs | Covers parser error reporting/recovery nodes and malformed input handling. |
| CosmosDBShell.Tests/Parser/CommandExpressionTests.cs | Covers command-in-expression dispatch and binding/error branches. |
| CosmosDBShell.Tests/Parser/CommandExecutionTests.cs | Covers command statement execution + dynamic exec dispatch and errors. |
| CosmosDBShell.Tests/Parser/AstVisitorWalkTests.cs | Adds traversal tests for default AST visitor recursion across node types. |
| CosmosDBShell.Tests/Lsp/FoldingRangeHandlerTests.cs | Adds tests for folding range generation over brace blocks. |
| CosmosDBShell.Tests/Lsp/CosmosShellWorkspaceTests.cs | Adds tests for workspace document lifecycle, parsing, and word/completion context. |
| CosmosDBShell.Tests/CommandTests/WatchCommandTests.cs | Extends watch command tests to include non-finite intervals and execution guards. |
| CosmosDBShell.Tests/CommandTests/ThemeCommandDispatchTests.cs | Adds offline tests covering ThemeCommand action dispatch and file-backed operations. |
| CosmosDBShell.Tests/CommandTests/RmCommandTests.cs | Extends rm command tests to cover missing-filter guard and state routing. |
| CosmosDBShell.Tests/CommandTests/MakeItemCommand.cs | Extends mkitem tests to cover JSON kind recursion and disconnected/validation guards. |
| CosmosDBShell.Tests/CommandTests/MakeDbCommandTests.cs | Adds mkdb tests for throughput helper + invalid-state visitors. |
| CosmosDBShell.Tests/CommandTests/ItemWriteCommandTests.cs | Adds offline validation/not-connected tests for item write commands (print/replace/patch). |
| CosmosDBShell.Tests/CommandTests/DeleteCommandTests.cs | Adds offline routing tests for delete command invalid types + not-connected branches. |
| CosmosDBShell.Tests/CommandTests/ContainerScopedCommandTests.cs | Adds offline tests for container-scoped commands’ wrong-scope/not-connected branches. |
| CosmosDBShell.Tests/CommandTests/CatCommandTests.cs | Adds cat command tests for file reading and guard paths (null/missing file). |
| CosmosDBShell.Tests/CommandTests/BucketCommandTests.cs | Adds tests for bucket validation and state-based behaviors. |
| CONTRIBUTING.md | Documents the new local coverage script and VS Code coverage task. |
| .vscode/tasks.json | Adds a VS Code coverage task to run the coverage script. |
| .github/workflows/validate-and-package.yml | Switches to XPlat coverage collection and generates/uploads a coverage report artifact + summary. |
| .config/dotnet-tools.json | Adds ReportGenerator as a local dotnet tool dependency. |
Use dotnet tool run reportgenerator in the local coverage script, parse ShellObject numeric tokens as ShellNumber/ShellDecimal with invariant culture, update the numeric parse tests accordingly, and restore four-space indentation in RmCommandTests.
sevoku
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds focused, offline unit tests across the parser namespace and several under-tested command paths. No production code changes; this PR is tests only.
The goal is to improve meaningful coverage around behavior that can be exercised reliably without a live Cosmos DB dependency, while avoiding brittle tests for external-editor behavior or live-service loops.
Current coverage snapshot
Latest local coverage run after these changes:
Azure.Data.Cosmos.Shell.ParsernamespaceCatCommandRmCommandMakeItemCommandWatchCommandFull local coverage/test run completed successfully: 1647 passed, 2 skipped, 0 failed.
CI also regenerates coverage in the existing
validate-and-packageworkflow and publishes the HTML/text coverage report as thecode-coverage-reportartifact.What's covered
Parser namespace
Adds tests for:
if,while,do-while,for,loop,break,continuetype,length,keys,contains,select,sort_byCommandExpressionShellObject.ParsePositionalErrorHelperandPositionalExceptionCommands
Adds offline tests for:
CatCommand: existing/empty file reads, missing/null path errors, state visitorsRmCommand: missing-filter guard and state-routing errors before live Cosmos callsMakeItemCommand: recursive JSON parsing and input/not-connected guardsWatchCommand: interval validation andExecuteAsyncguard pathsScope notes
Some low-coverage areas are intentionally not forced into unit tests:
EditCommandlaunches an external editor, so unit coverage is low-value and environment-sensitive.RmCommand,MakeItemCommand, andWatchCommandgaps are mostly live Cosmos operations: delete/create/upsert and change-feed polling. Those are better suited to emulator-backed integration tests.