Skip to content

test: expand mock tests for 28 executor handler files#254

Merged
ako merged 6 commits intomendixlabs:mainfrom
retran:test/handler-mock-expand
Apr 22, 2026
Merged

test: expand mock tests for 28 executor handler files#254
ako merged 6 commits intomendixlabs:mainfrom
retran:test/handler-mock-expand

Conversation

@retran
Copy link
Copy Markdown
Contributor

@retran retran commented Apr 22, 2026

Why

The mxcli project is preparing to extract the mdl/ runtime into a reusable library. Before any refactoring can safely begin, comprehensive test coverage is needed to catch behavioral regressions. PR #253 (C1) added initial mock tests for 8 handler files that had zero coverage. This PR completes the executor handler coverage by expanding the remaining 28 handler files that had only minimal tests (typically just a happy-path case).

Without these tests, error paths, filter logic, and edge cases in these handlers would go unvalidated during refactoring — exactly the kind of subtle breakage that is hardest to catch.

Part of the stacked PR series: #253 (C1) → #254 (C2) → #255 (D1).

Summary

  • Expand mock test coverage across 28 existing *_mock_test.go files that previously had minimal tests
  • Adds ~95 new tests covering: not-found errors, filter-by-module, backend error propagation, JSON format output, edge cases
  • Builds on PR test: add mock tests for 8 executor handler files #253 (C1) which added the initial 8 handler test files

Batch breakdown

Commit Files Tests added Handlers
1 4 22 settings, fragments, misc, javaactions
2 6 8 modules, entities, associations, enumerations, constants, microflows
3 6 14 odata, published_rest, rest_clients, businessevents, workflows, javascript_actions
4 8 23 datatransformer, dbconnection, imagecollections, jsonstructures, import/export_mappings, mermaid, navigation
5 4 36 pages, security, write_handlers, agenteditor

What's covered

  • Not-found paths for all describe/drop handlers
  • Filter-by-module for list handlers that support it
  • Backend error propagation for handlers not covered by cross-cutting error tests
  • JSON format output with assertValidJSON for list handlers
  • Edge cases: nil-name validation, unsupported type errors, already-exists guards on create handlers, empty result sets

Notes

  • Cross-cutting test files (cmd_notconnected_mock_test.go, cmd_error_mock_test.go, cmd_json_mock_test.go) already cover not-connected, backend errors, and JSON for many handlers — new tests avoid duplication
  • Write handler create/alter tests (OData, REST, business events) deferred — complex multi-backend setup
  • 28 files changed, ~1480 insertions, 0 deletions

retran added 5 commits April 22, 2026 10:53
Add 49 tests across 8 new test files covering executor handlers
that previously had zero test coverage:

- cmd_folders: 9 tests (DropFolder + MoveFolder paths)
- cmd_move: 6 tests (page moves, cross-module refs, error paths)
- cmd_rename: 11 tests (entity/module/microflow/page/enum/assoc/const/nanoflow)
- cmd_alter_page: 9 tests (set property, snippets, widgets, variables, layout)
- cmd_features: 7 tests (ForVersion, AddedSince, connected, invalid version)
- cmd_styling: 5 tests (not-connected guards for all 3 styling commands)
- cmd_lint: 1 test (not-connected guard)
- cmd_import: 1 test (not-connected guard)

Styling, lint, and import have partial coverage (not-connected + error
paths only) because their happy paths depend on filesystem or external
DB connections that cannot be mocked through the current Backend interface.
…ctions, jsonstructures, mappings, mermaid, navigation
Copilot AI review requested due to automatic review settings April 22, 2026 09:50
@github-actions
Copy link
Copy Markdown

AI Code Review

What Looks Good

  • The PR systematically expands test coverage across 28 handler files with ~95 new tests
  • Tests cover important scenarios: not-found errors, filter-by-module, backend error propagation, JSON output, and edge cases
  • Properly avoids duplicating existing cross-cutting test coverage (not-connected, backend errors, JSON)
  • Follows established testing patterns using mock backends and helper functions
  • New test files are created for handlers that previously lacked mock tests (agenteditor, alter_page, features, folders, import, lint, move)
  • Test organization is clear with logical sections (Not Found, Filter by Module, etc.)
  • Uses appropriate assertions (assertError, assertNoError, assertValidJSON, etc.)
  • No actual MDL syntax or logic is modified - purely test expansion
  • PR is well-scoped to a single concern: expanding mock test coverage

Recommendation

Approve - This PR provides valuable test coverage expansion that improves code robustness while following project testing conventions. No issues found with overlap, syntax design, full-stack consistency (not applicable as no new MDL features), security, scope, or code quality. The tests appropriately extend existing patterns without duplication.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands mock-based test coverage across many executor handler areas, exercising previously untested branches (not-found, module filtering, backend error propagation, JSON output, and a few edge cases). It builds on the existing mock backend + newMockCtx helper infrastructure to cover more handler behavior without requiring filesystem/DB/BSON-heavy setups.

Changes:

  • Added/expanded mock tests across a broad set of cmd_*_mock_test.go files to cover not-found paths, module filtering, and backend error propagation.
  • Added JSON-format assertions (assertValidJSON) for additional list handlers.
  • Added targeted edge-case tests (e.g., nil-name validation, unsupported type errors, “already exists” guards).

Reviewed changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
mdl/executor/cmd_write_handlers_mock_test.go Adds mock tests for additional write-handler branches (already-exists + not-found paths).
mdl/executor/cmd_workflows_mock_test.go Adds not-found + filter-by-module tests for workflow handlers.
mdl/executor/cmd_styling_mock_test.go Introduces coverage for “not connected” and missing-project-path guards in styling commands.
mdl/executor/cmd_settings_mock_test.go Adds not-connected/backend-error/JSON coverage for settings listing/describe.
mdl/executor/cmd_security_mock_test.go Adds module filtering + not-found/edge-case coverage for security-related describe/list helpers.
mdl/executor/cmd_rest_clients_mock_test.go Adds not-found + filter-by-module tests for REST client handlers.
mdl/executor/cmd_rename_mock_test.go Adds comprehensive mock coverage for rename command across types and failure modes.
mdl/executor/cmd_published_rest_mock_test.go Adds not-found + filter-by-module tests for published REST handlers.
mdl/executor/cmd_pages_mock_test.go Adds filter-by-module tests for snippets/layouts and not-found tests for describe paths.
mdl/executor/cmd_odata_mock_test.go Adds not-found + module-filtering coverage for OData client/service handlers.
mdl/executor/cmd_navigation_mock_test.go Adds not-found and “all profiles” describe coverage for navigation.
mdl/executor/cmd_move_mock_test.go Adds mock coverage for move command (not connected, not found, cross-module refs, backend error).
mdl/executor/cmd_modules_mock_test.go Adds backend error + JSON output coverage for module listing.
mdl/executor/cmd_misc_mock_test.go Adds not-connected and “no schema hash” coverage for version output + help smoke test.
mdl/executor/cmd_microflows_mock_test.go Adds notes pointing to existing cross-cutting backend-error/JSON tests.
mdl/executor/cmd_mermaid_mock_test.go Adds microflow + error-path coverage for mermaid output generation.
mdl/executor/cmd_lint_mock_test.go Adds tests for not-connected and ShowRules branch.
mdl/executor/cmd_jsonstructures_mock_test.go Adds module filtering + describe + not-found coverage for JSON structures.
mdl/executor/cmd_javascript_actions_mock_test.go Adds not-found + module filtering coverage for JavaScript actions.
mdl/executor/cmd_javaactions_mock_test.go Adds backend error + not-found + module filtering + JSON coverage for Java actions.
mdl/executor/cmd_import_mock_test.go Adds not-connected coverage for import command (documents mock limitations).
mdl/executor/cmd_import_mappings_mock_test.go Adds module filtering + describe + not-found coverage for import mappings.
mdl/executor/cmd_imagecollections_mock_test.go Adds module filtering + not-found coverage for image collections.
mdl/executor/cmd_fragments_mock_test.go Adds describe + not-found coverage for fragment handling.
mdl/executor/cmd_folders_mock_test.go Adds mock coverage for folder drop/move command branches and error paths.
mdl/executor/cmd_features_mock_test.go Adds coverage for version-based feature listing and validation error cases.
mdl/executor/cmd_export_mappings_mock_test.go Adds module filtering + describe + not-found coverage for export mappings.
mdl/executor/cmd_enumerations_mock_test.go Adds notes pointing to existing cross-cutting backend-error/JSON tests.
mdl/executor/cmd_entities_mock_test.go Adds backend error + JSON output coverage for entity listing.
mdl/executor/cmd_dbconnection_mock_test.go Adds module filtering + not-found coverage for database connections.
mdl/executor/cmd_datatransformer_mock_test.go Adds module filtering + not-found coverage for data transformers.
mdl/executor/cmd_constants_mock_test.go Adds notes pointing to existing cross-cutting backend-error/JSON tests.
mdl/executor/cmd_businessevents_mock_test.go Adds not-found + module filtering coverage for business event services.
mdl/executor/cmd_associations_mock_test.go Adds backend error + JSON output coverage for association listing.
mdl/executor/cmd_alter_page_mock_test.go Adds mock coverage for alter page/snippet behavior and error paths via page mutator.
mdl/executor/cmd_agenteditor_mock_test.go Expands agent editor mock tests with not-found/drop-not-found and module filtering cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mdl/executor/cmd_lint_mock_test.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mdl/executor/cmd_move_mock_test.go
@ako
Copy link
Copy Markdown
Collaborator

ako commented Apr 22, 2026

Code Review

Overview

This is C2 in the stacked series (#253#254#255), adding ~95 tests across 28 executor handler files. The coverage is systematic and well-organized: not-found paths, filter-by-module, backend error propagation, JSON output, and edge cases. The test structure is consistent throughout and the inline documentation comments (explaining WHY certain paths are left uncovered, with "tracked separately" notes) are a good pattern.

Blocking issue

TestHelp_Mock will not compile.

The test calls execHelp(ctx) with one argument, but the current cmd_misc.go:55 signature is:

func execHelp(ctx *ExecContext, s *ast.HelpStmt) error {

This was changed during the PR #172 rebase (syntax feature registry). The fix is either:

// Option A — test the no-topic path
assertNoError(t, execHelp(ctx, &ast.HelpStmt{}))

or extract a zero-arg wrapper if the REPL really does call execHelp(ctx) directly (it doesn't — register_stubs.go passes stmt.(*ast.HelpStmt)). Option A is correct.

Non-blocking issues

  1. cmd_misc_mock_test.goTestHelp_Mock: See above. Also check that execHelp(ctx, &ast.HelpStmt{}) actually emits "MDL Commands" / "connect local" in the no-topic branch (the assertions are reasonable, just verify they match the actual output format).

  2. cmd_mermaid_mock_test.goTestDescribeMermaid_UnsupportedType: Uses fmt.Sprint(err) instead of err.Error(). All other error string assertions in this PR use err.Error() — this one is an inconsistency, though not a bug.

  3. cmd_features_mock_test.goTestShowFeatures_InArea_ForVersion: The assertion assertContainsStr(t, buf.String(), "domain_model") relies on the area filter header format emitting the literal string domain_model. If the output says "domain model" (with a space) or uses a display name, this test will fail spuriously. Worth verifying against the actual execShowFeatures output format.

  4. cmd_lint_mock_test.go — comment accuracy: The comment says "execLint currently checks ctx.Connected() before dispatching to the ShowRules branch, so this test still needs a connected backend." If that's true, it means SHOW LINT RULES fails when disconnected — which seems like a UX bug in the implementation, not in the test. Worth flagging as a separate issue if the ShowRules path doesn't actually need a live project.

Strengths

  • TestDropFolder_NestedPath: verifies that the child folder ID (not the parent) is passed to DeleteFolder — exactly the kind of off-by-one that integration tests miss.
  • TestMoveFolder_ToModule / TestMoveFolder_ToFolder: captures the movedTo ID and asserts it matches the destination — good mutation verification pattern.
  • TestAlterPage_* suite: thorough coverage of the mutator lifecycle (open, operate, save, and each error path).
  • Cross-reference comments in cmd_constants_mock_test.go, cmd_enumerations_mock_test.go, cmd_microflows_mock_test.go: helpful pointers to where cross-cutting tests live, without duplicating them.
  • cmd_import_mock_test.go / cmd_lint_mock_test.go: honest about coverage limitations with "tracked separately" notes rather than writing shallow tests that give false confidence.

Summary

One hard compile error (TestHelp_Mock argument count mismatch) needs to be fixed before this can merge. Everything else is either a minor style inconsistency or a note for follow-up. The test structure and scope are solid.

@ako ako merged commit 96a5d9e into mendixlabs:main Apr 22, 2026
4 of 6 checks passed
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