Skip to content

Split out QueueDefinitionAnalyzer - #40

Merged
viceroypenguin merged 3 commits into
masterfrom
queue-analyzer
Jul 28, 2026
Merged

Split out QueueDefinitionAnalyzer#40
viceroypenguin merged 3 commits into
masterfrom
queue-analyzer

Conversation

@viceroypenguin

@viceroypenguin viceroypenguin commented Jul 28, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added validation for queue definitions, including required attributes, valid names, and non-negative concurrency settings.
    • Added diagnostics for conflicting job and queue-definition configurations.
    • Improved queue metadata handling for jobs using queues.
  • Bug Fixes

    • Duplicate queue detection now consistently targets queue definitions.
  • Tests

    • Added coverage for valid and invalid queue configurations and related diagnostics.

@viceroypenguin viceroypenguin changed the title Queue analyzer QueueDefinitionAnalyzer Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 29492d1f-c1c9-4dde-8a97-9a19f3841f37

📥 Commits

Reviewing files that changed from the base of the PR and between 34b8aac and b5dfddf.

📒 Files selected for processing (1)
  • tests/Immediate.Jobs.Tests/AnalyzerTests/QueueDefinitionAnalyzerTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Immediate.Jobs.Tests/AnalyzerTests/QueueDefinitionAnalyzerTests.cs

📝 Walkthrough

Walkthrough

Queue attribute discovery now distinguishes queue definitions from queue usage. A new analyzer validates queue references and configuration, duplicate detection targets queue definitions, and job generation derives queue metadata directly from uses-queue attributes.

Changes

Queue definition flow

Layer / File(s) Summary
Queue attribute contracts
src/Common/AttributeDataExtensions.cs
Replaces the generic queue accessor with QueueDefinitionAttribute and adds UsesQueueAttribute.
Queue definition diagnostics
src/Immediate.Jobs.Analyzers/DiagnosticIds.cs, src/Immediate.Jobs.Analyzers/QueueDefinitionAnalyzer.cs, src/Immediate.Jobs.Analyzers/DuplicateElementsAnalyzer.cs, tests/Immediate.Jobs.Tests/AnalyzerTests/QueueDefinitionAnalyzerTests.cs
Adds diagnostic identifiers and validates missing queue definitions, conflicting attributes, invalid queue configuration, and duplicate queue definitions with analyzer coverage.
Generated queue metadata
src/Immediate.Jobs.Generators/ImmediateJobsGenerator.Transform.cs
Derives queue name, priority, and concurrency from UsesQueueAttribute metadata during job transformation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Compilation
  participant QueueDefinitionAnalyzer
  participant AttributeDataExtensions
  participant Diagnostics
  Compilation->>QueueDefinitionAnalyzer: Analyze named type
  QueueDefinitionAnalyzer->>AttributeDataExtensions: Read queue attributes
  AttributeDataExtensions-->>QueueDefinitionAnalyzer: Return attribute metadata
  QueueDefinitionAnalyzer->>Diagnostics: Report validation diagnostics
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: extracting a new QueueDefinitionAnalyzer and related queue-definition handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch queue-analyzer

Comment @coderabbitai help to get the list of available commands.

@viceroypenguin viceroypenguin changed the title QueueDefinitionAnalyzer Split out QueueDefinitionAnalyzer Jul 28, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Immediate.Jobs.Generators/ImmediateJobsGenerator.Transform.cs`:
- Around line 85-103: Update the UsesQueue<T> resolution in
ImmediateJobsGenerator.Transform.cs so it consistently reads T’s QueueDefinition
priority and concurrency, preserving the resolved values for critical-queue;
update
AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ..WorkJob.g.verified.cs
lines 157-158 to retain 10 and 1, and remove the competing zero-valued
registration from
AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ.ServiceCollectionExtensions.g.verified.cs
lines 25-30.
- Around line 85-103: Update the queue-name validation in the
`UsesQueueAttribute` switch within `ImmediateJobsGenerator.Transform` to reject
names that are null, empty, or whitespace-only, matching
`QueueDefinitionAnalyzer` and `TransformQueue`; preserve the existing priority
and concurrency validation and default-name handling.

In `@tests/Immediate.Jobs.Tests/AnalyzerTests/QueueDefinitionAnalyzerTests.cs`:
- Around line 35-36: Update PresentQueueDefinitionAttributeShouldNotError to
instantiate and run QueueDefinitionAnalyzer instead of
MissingHandlerAttributeAnalyzer, so the test validates the valid
queue-definition path while preserving its existing no-error assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a94eba0f-43f4-4b28-b0d4-1cdd6e71a0ba

📥 Commits

Reviewing files that changed from the base of the PR and between 3dbb078 and 34b8aac.

📒 Files selected for processing (8)
  • src/Common/AttributeDataExtensions.cs
  • src/Immediate.Jobs.Analyzers/DiagnosticIds.cs
  • src/Immediate.Jobs.Analyzers/DuplicateElementsAnalyzer.cs
  • src/Immediate.Jobs.Analyzers/QueueDefinitionAnalyzer.cs
  • src/Immediate.Jobs.Generators/ImmediateJobsGenerator.Transform.cs
  • tests/Immediate.Jobs.Tests/AnalyzerTests/QueueDefinitionAnalyzerTests.cs
  • tests/Immediate.Jobs.Tests/GeneratorTests/Snapshots/AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ..WorkJob.g.verified.cs
  • tests/Immediate.Jobs.Tests/GeneratorTests/Snapshots/AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ.ServiceCollectionExtensions.g.verified.cs

Comment on lines +85 to +103
if (
attributes.UsesQueueAttribute switch
{
{ AttributeClass.TypeArguments: [{ } queueSymbol] }
when queueSymbol.GetAttributes().QueueDefinitionAttribute is { } queueDefinitionAttribute =>
(
QueueName: queueDefinitionAttribute.GetQueueName(queueSymbol.Name).NullIf("default"),
QueuePriority: queueDefinitionAttribute.NamedArguments.GetIntValue("Priority", 0),
QueueConcurrency: queueDefinitionAttribute.NamedArguments.GetIntValue("Concurrency", 0)
),

{ } => default((string? QueueName, int QueuePriority, int QueueConcurrency)?),

_ => (QueueName: "default", QueuePriority: 0, QueueConcurrency: 0),
} is not ({ } queueName, var queuePriority, >= 0 and var queueConcurrency)
)
{
return null;
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve the referenced queue definition’s configuration. The generated output now treats critical-queue as both { Priority = 10, Concurrency = 1 } and { Priority = 0, Concurrency = 0 }, so jobs and DI consumers can observe conflicting definitions.

  • src/Immediate.Jobs.Generators/ImmediateJobsGenerator.Transform.cs#L85-L103: ensure the UsesQueue<T> path resolves the same priority and concurrency as T’s QueueDefinition.
  • tests/Immediate.Jobs.Tests/GeneratorTests/Snapshots/AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ..WorkJob.g.verified.cs#L157-L158: retain the resolved 10 and 1 values for critical-queue.
  • tests/Immediate.Jobs.Tests/GeneratorTests/Snapshots/AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ.ServiceCollectionExtensions.g.verified.cs#L25-L30: remove the competing zero-valued registration; only the queue-definition configuration should be registered.
📍 Affects 3 files
  • src/Immediate.Jobs.Generators/ImmediateJobsGenerator.Transform.cs#L85-L103 (this comment)
  • tests/Immediate.Jobs.Tests/GeneratorTests/Snapshots/AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ..WorkJob.g.verified.cs#L157-L158
  • tests/Immediate.Jobs.Tests/GeneratorTests/Snapshots/AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ.ServiceCollectionExtensions.g.verified.cs#L25-L30
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Immediate.Jobs.Generators/ImmediateJobsGenerator.Transform.cs` around
lines 85 - 103, Update the UsesQueue<T> resolution in
ImmediateJobsGenerator.Transform.cs so it consistently reads T’s QueueDefinition
priority and concurrency, preserving the resolved values for critical-queue;
update
AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ..WorkJob.g.verified.cs
lines 157-158 to retain 10 and 1, and remove the competing zero-valued
registration from
AddJobsTests.ServiceCollectionExtensionsUsesQueuesAndTaggedRegistrations_framework=net11.0#IJ.ServiceCollectionExtensions.g.verified.cs
lines 25-30.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Reject whitespace-only queue names here too.

QueueDefinitionAnalyzer and TransformQueue reject whitespace-only names, but this path only excludes "default". A job can therefore reference " " while its queue definition is skipped.

Proposed fix
 		if (
 			attributes.UsesQueueAttribute switch
 			{
 				// ...
 			} is not ({ } queueName, var queuePriority, >= 0 and var queueConcurrency)
 		)
 		{
 			return null;
 		}
+
+		if (string.IsNullOrWhiteSpace(queueName))
+			return null;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (
attributes.UsesQueueAttribute switch
{
{ AttributeClass.TypeArguments: [{ } queueSymbol] }
when queueSymbol.GetAttributes().QueueDefinitionAttribute is { } queueDefinitionAttribute =>
(
QueueName: queueDefinitionAttribute.GetQueueName(queueSymbol.Name).NullIf("default"),
QueuePriority: queueDefinitionAttribute.NamedArguments.GetIntValue("Priority", 0),
QueueConcurrency: queueDefinitionAttribute.NamedArguments.GetIntValue("Concurrency", 0)
),
{ } => default((string? QueueName, int QueuePriority, int QueueConcurrency)?),
_ => (QueueName: "default", QueuePriority: 0, QueueConcurrency: 0),
} is not ({ } queueName, var queuePriority, >= 0 and var queueConcurrency)
)
{
return null;
}
if (
attributes.UsesQueueAttribute switch
{
{ AttributeClass.TypeArguments: [{ } queueSymbol] }
when queueSymbol.GetAttributes().QueueDefinitionAttribute is { } queueDefinitionAttribute =>
(
QueueName: queueDefinitionAttribute.GetQueueName(queueSymbol.Name).NullIf("default"),
QueuePriority: queueDefinitionAttribute.NamedArguments.GetIntValue("Priority", 0),
QueueConcurrency: queueDefinitionAttribute.NamedArguments.GetIntValue("Concurrency", 0)
),
{ } => default((string? QueueName, QueuePriority, QueueConcurrency)?),
_ => (QueueName: "default", QueuePriority: 0, QueueConcurrency: 0),
} is not ({ } queueName, var queuePriority, >= 0 and var queueConcurrency)
)
{
return null;
}
if (string.IsNullOrWhiteSpace(queueName))
return null;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Immediate.Jobs.Generators/ImmediateJobsGenerator.Transform.cs` around
lines 85 - 103, Update the queue-name validation in the `UsesQueueAttribute`
switch within `ImmediateJobsGenerator.Transform` to reject names that are null,
empty, or whitespace-only, matching `QueueDefinitionAnalyzer` and
`TransformQueue`; preserve the existing priority and concurrency validation and
default-name handling.

Comment thread tests/Immediate.Jobs.Tests/AnalyzerTests/QueueDefinitionAnalyzerTests.cs Outdated
@viceroypenguin
viceroypenguin merged commit d9ff229 into master Jul 28, 2026
2 checks passed
@viceroypenguin
viceroypenguin deleted the queue-analyzer branch July 28, 2026 13:39
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.

1 participant