Skip to content

Cache command method discovery in convention tests#142

Merged
lex57ukr merged 1 commit intomainfrom
141-cache-command-method-discovery-in-convention-tests
Feb 4, 2026
Merged

Cache command method discovery in convention tests#142
lex57ukr merged 1 commit intomainfrom
141-cache-command-method-discovery-in-convention-tests

Conversation

@lex57ukr
Copy link
Contributor

@lex57ukr lex57ukr commented Feb 4, 2026

Summary

Improve convention test efficiency by caching discovered command methods. Reflection now runs once and is shared across all convention tests, making the pattern clearer for contributors adding new tests.

Related Issues

Fixes #141

Changes

  • Add thread-safe Lazy<MethodInfo[]> field to cache discovered command methods
  • Update existing convention tests to use the cached value
  • Update how-to documentation to reflect the caching pattern

Add Lazy<MethodInfo[]> field to cache discovered command methods for
shared use across tests. Update documentation to reflect the pattern.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@lex57ukr lex57ukr added the enhancement New feature or request label Feb 4, 2026
Copilot AI review requested due to automatic review settings February 4, 2026 13:57
Copy link

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 optimizes convention test performance by introducing a caching mechanism for command method discovery. Instead of running reflection separately for each test, methods are discovered once and shared across all convention tests through a thread-safe lazy initialization pattern.

Changes:

  • Added a Lazy<MethodInfo[]> field to cache discovered command methods with thread-safe initialization
  • Refactored existing convention tests to use the cached value instead of calling DiscoverCommandMethods() directly
  • Updated documentation to explain the caching pattern for future contributors

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/Keystone.Cli.UnitTests/Presentation/Cocona/CoconaCommandMethodConventionsTests.cs Introduced cached lazy field and updated two test methods to consume it
docs/how-to/how-to-convention-tests.md Updated documentation to reference the new caching pattern and guide contributors to use LazyCommandMethods.Value

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

@lex57ukr lex57ukr enabled auto-merge (squash) February 4, 2026 13:59
@lex57ukr lex57ukr merged commit 452fbcd into main Feb 4, 2026
5 checks passed
@lex57ukr lex57ukr deleted the 141-cache-command-method-discovery-in-convention-tests branch February 4, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache command method discovery in convention tests

1 participant