Skip to content

Better validation - #25

Merged
TopSwagCode merged 1 commit into
masterfrom
features/validation-and-improvements
Feb 12, 2026
Merged

TopSwagCode merged 1 commit into
masterfrom
features/validation-and-improvements

Conversation

@TopSwagCode

Copy link
Copy Markdown
Owner

No description provided.

@TopSwagCode
TopSwagCode requested a review from Copilot February 12, 2026 15:23
@TopSwagCode
TopSwagCode merged commit 2312062 into master Feb 12, 2026
11 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.42%. Comparing base (3fedf59) to head (6c97524).
⚠️ Report is 2 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #25      +/-   ##
==========================================
+ Coverage   77.95%   78.42%   +0.46%     
==========================================
  Files           2        2              
  Lines         186      190       +4     
  Branches       28       30       +2     
==========================================
+ Hits          145      149       +4     
  Misses         21       21              
  Partials       20       20              
Flag Coverage Δ
unittests 78.42% <100.00%> (+0.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

This PR tightens input validation for MinimalWorker’s periodic and cron worker registration APIs and improves source-generator diagnostics/reporting behavior, with accompanying test updates.

Changes:

  • Add fail-fast argument validation for RunPeriodicBackgroundWorker (interval must be > 0) and RunCronBackgroundWorker (cron expression must be non-empty/whitespace).
  • Update/add unit tests to assert the new exception behavior for invalid intervals/cron expressions.
  • Enhance the source generator to collect/report diagnostics and skip generation for models flagged as errored; refactor generated worker init code to cache some lookups and reduce per-error allocations.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/MinimalWorker.Test/PeriodicWorkerTests.cs Updates the zero-interval test to expect an exception; adds negative-interval coverage.
test/MinimalWorker.Test/CronWorkerTests.cs Adds theory coverage for null/empty/whitespace cron expressions throwing ArgumentException.
src/MinimalWorker/BackgroundWorkerExtensions.cs Adds argument validation for periodic interval and cron expression.
src/MinimalWorker.Generators/WorkerGenerator.cs Adds diagnostic collection/reporting and filters errored worker models from code generation.
src/MinimalWorker.Generators/WorkerEmitter.cs Refactors emitted code to cache some lookups and adjust tag handling in error paths.
src/MinimalWorker.Generators/InvocationModel.cs Extends the invocation model to track diagnostics and generation-blocking errors.
.claude/settings.local.json Expands allowed Claude Bash commands (ls/publish) in local settings.
Comments suppressed due to low confidence (1)

src/MinimalWorker.Generators/WorkerGenerator.cs:161

  • AnalyzeDelegate returns false when delegateType/invokeMethod can't be resolved, but it doesn't set model.HasErrors or add a diagnostic in those paths. Since Execute() now only filters out HasErrors, these unresolved delegates can still be treated as valid and code generation may proceed with an incomplete/incorrect model. Mark the model as errored and report a diagnostic when the delegate cannot be analyzed (not just for MW0001/MW0002).
        if (delegateType == null)
            return false;

        var invokeMethod = delegateType.DelegateInvokeMethod;
        if (invokeMethod == null)
            return false;

public static IWorkerBuilder RunCronBackgroundWorker(this IHost host, string cronExpression, Delegate action)
{
if (string.IsNullOrWhiteSpace(cronExpression))
throw new ArgumentException("Cron expression cannot be null or empty.", nameof(cronExpression));

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

The validation uses string.IsNullOrWhiteSpace(cronExpression) but the thrown message says "null or empty". This is inaccurate for whitespace-only inputs; update the message to mention whitespace (or change the guard to IsNullOrEmpty to match the message).

Suggested change
throw new ArgumentException("Cron expression cannot be null or empty.", nameof(cronExpression));
throw new ArgumentException("Cron expression cannot be null, empty, or whitespace.", nameof(cronExpression));

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +7
"Bash(dotnet build:*)",
"Bash(ls:*)",
"Bash(dotnet publish:*)"

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

This PR is titled "Better validation", but this change expands Claude tool permissions (ls/publish). If this is intentional, it should be called out in the PR description; otherwise consider moving it to a separate PR to keep the scope focused.

Copilot uses AI. Check for mistakes.
Comment on lines +226 to +236
foreach (var worker in workers)
{
if (worker?.Diagnostics != null)
{
foreach (var diag in worker.Diagnostics)
{
context.ReportDiagnostic(Diagnostic.Create(
diag.Descriptor,
diag.Location,
diag.MessageArgs ?? System.Array.Empty<object>()));
}

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.

Suggested change
foreach (var worker in workers)
{
if (worker?.Diagnostics != null)
{
foreach (var diag in worker.Diagnostics)
{
context.ReportDiagnostic(Diagnostic.Create(
diag.Descriptor,
diag.Location,
diag.MessageArgs ?? System.Array.Empty<object>()));
}
foreach (var worker in workers.Where(w => w?.Diagnostics != null))
{
foreach (var diag in worker.Diagnostics!)
{
context.ReportDiagnostic(Diagnostic.Create(
diag.Descriptor,
diag.Location,
diag.MessageArgs ?? System.Array.Empty<object>()));

Copilot uses AI. Check for mistakes.
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