Skip to content

test: expand unit coverage for parser and offline command paths#121

Merged
mkrueger merged 13 commits into
mainfrom
dev/mkrueger/test-coverage
Jun 11, 2026
Merged

test: expand unit coverage for parser and offline command paths#121
mkrueger merged 13 commits into
mainfrom
dev/mkrueger/test-coverage

Conversation

@mkrueger

@mkrueger mkrueger commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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:

Metric Current
Overall line coverage 71.5%
Overall branch coverage 67.9%
Overall method coverage 80.7%
Azure.Data.Cosmos.Shell.Parser namespace 79.2%
CatCommand 100%
RmCommand 44.7%
MakeItemCommand 39.1%
WatchCommand 28.8%

Full local coverage/test run completed successfully: 1647 passed, 2 skipped, 0 failed.

CI also regenerates coverage in the existing validate-and-package workflow and publishes the HTML/text coverage report as the code-coverage-report artifact.

What's covered

Parser namespace

Adds tests for:

  • Operator evaluation: arithmetic, comparison, logical, unary
  • Control-flow execution: if, while, do-while, for, loop, break, continue
  • Loop element-kind binding and positional-error wrapping
  • Filter builtins: type, length, keys, contains, select, sort_by
  • JSON array/object construction
  • Filter path/index/iterate expressions
  • Command dispatch and option/positional binding via CommandExpression
  • ShellObject.Parse
  • PositionalErrorHelper and PositionalException
  • AST visitor walking
  • Statement/expression parser edge cases and error-recovery cases

Commands

Adds offline tests for:

  • CatCommand: existing/empty file reads, missing/null path errors, state visitors
  • RmCommand: missing-filter guard and state-routing errors before live Cosmos calls
  • MakeItemCommand: recursive JSON parsing and input/not-connected guards
  • WatchCommand: interval validation and ExecuteAsync guard paths

Scope notes

Some low-coverage areas are intentionally not forced into unit tests:

  • EditCommand launches an external editor, so unit coverage is low-value and environment-sensitive.
  • The remaining RmCommand, MakeItemCommand, and WatchCommand gaps are mostly live Cosmos operations: delete/create/upsert and change-feed polling. Those are better suited to emulator-backed integration tests.
  • The parser still has some defensive branches and impossible-state guards that are not worth covering just to move the percentage.

mkrueger added 12 commits June 9, 2026 15:35
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.
@mkrueger mkrueger requested review from a team and Copilot June 9, 2026 15:17

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.

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.

Comment thread tools/coverage.ps1
Comment thread CosmosDBShell.Tests/Parser/ShellObjectParseTests.cs
Comment thread CosmosDBShell.Tests/CommandTests/RmCommandTests.cs Outdated
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.
@mkrueger mkrueger requested a review from sevoku June 9, 2026 22:03
@mkrueger mkrueger merged commit 043393b into main Jun 11, 2026
8 checks passed
@mkrueger mkrueger deleted the dev/mkrueger/test-coverage branch June 11, 2026 15:05
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.

3 participants