Skip to content

Implement trigger payload type validation diagnostics (CSDK200-204)#49

Closed
daviburg wants to merge 35 commits into
mainfrom
feature/trigger-payload-validation
Closed

Implement trigger payload type validation diagnostics (CSDK200-204)#49
daviburg wants to merge 35 commits into
mainfrom
feature/trigger-payload-validation

Conversation

@daviburg
Copy link
Copy Markdown
Member

@daviburg daviburg commented Apr 13, 2026

Summary

Implements all 5 trigger payload type validation diagnostics from #42.

Diagnostics

Code Severity Diagnostic Detection
CSDK200 Error Deserialize<T> type mismatch Compares T against expected payload type from SdkIndex
CSDK201 Warning Weak type (object, dynamic, JsonElement, etc.) Checks T against weak type list when typed payload available
CSDK202 Error Type not found in SDK Verifies T exists in SdkIndex.TypeNames
CSDK203 Warning Operation unmapped GetPayloadTypeForOperation returns null
CSDK204 Warning Type name does not follow *TriggerPayload naming convention EndsWith check on type name

Validation

  • All 172 tests pass (0 failures, 16 skipped)
  • Build succeeds with zero warnings
  • Diagnostics appear on the generic type argument (Deserialize<[HERE]>) with precise range

Closes #42

@daviburg daviburg requested a review from a team as a code owner April 13, 2026 23:52
Copilot AI review requested due to automatic review settings April 13, 2026 23:52
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

Adds a new diagnostics validator to the LSP server to validate trigger callback payload deserialization types against the indexed Connectors SDK (CSDK200–CSDK204), and wires it into the existing diagnostics pipeline with unit test coverage.

Changes:

  • Added diagnostic code constants for CSDK200–CSDK204.
  • Implemented TriggerPayloadValidator to analyze Deserialize<T> calls within trigger methods and emit the new diagnostics.
  • Extended SdkIndex.CreateForTesting(...) to accept optional typeNames for validator unit tests, and added a comprehensive new test suite.

Reviewed changes

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

Show a summary per file
File Description
Server/Diagnostics/DiagnosticCodes.cs Defines CSDK200–CSDK204 constants for trigger payload validation diagnostics.
Server/Diagnostics/Validators/TriggerPayloadValidator.cs New validator implementing trigger payload type validation and emitting CSDK200–CSDK204.
Server/Program.cs Registers the new TriggerPayloadValidator in DI so it runs in the diagnostics pipeline.
Server/SdkIndex.cs Allows tests to supply TypeNames via CreateForTesting(...) to simulate SDK type availability.
Server.Tests/TriggerPayloadValidatorTests.cs Adds test coverage for correct usage, each diagnostic code, and key edge cases.

Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
@daviburg daviburg requested a review from Copilot April 14, 2026 00:06
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 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread Server.Tests/TriggerPayloadValidatorTests.cs Outdated
Comment thread Server/Diagnostics/DiagnosticCodes.cs Outdated
Comment thread Server.Tests/TriggerPayloadValidatorTests.cs Outdated
@daviburg daviburg self-assigned this Apr 14, 2026
@daviburg daviburg requested a review from Copilot April 14, 2026 18:49
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 7 out of 7 changed files in this pull request and generated 5 comments.

Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server.Tests/TriggerPayloadValidatorTests.cs
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server/Diagnostics/Validators/ValidatorHelpers.cs
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 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread Server/Diagnostics/DiagnosticCodes.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs
@daviburg daviburg requested a review from Copilot April 14, 2026 22:14
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 7 out of 7 changed files in this pull request and generated 7 comments.

Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server.Tests/TriggerPayloadValidatorTests.cs
Comment thread Server.Tests/TriggerPayloadValidatorTests.cs
Comment thread Server.Tests/TriggerPayloadValidatorTests.cs
@daviburg daviburg requested a review from Copilot April 14, 2026 22:26
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 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread Server/SdkIndex.cs Outdated
Comment thread Server/SdkIndex.cs 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 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread Server/Diagnostics/Validators/ValidatorHelpers.cs
Comment thread Server/Diagnostics/Validators/AttributeValidator.cs
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 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread Server/SdkIndex.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs
Comment thread Server.Tests/TriggerPayloadValidatorTests.cs
@daviburg daviburg requested a review from Copilot April 15, 2026 00:39
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 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs 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 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread Server/SdkIndex.cs Outdated
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
daviburg and others added 10 commits April 15, 2026 11:47
- NormalizeQualifiedName now uses string prefix strip for deeply nested global::

- Add ValidateAsync_GlobalQualifiedCorrectType_NoDiagnostic test

Co-authored-by: Dobby <dobby@microsoft.com>
…nown limitations

- Iterate MethodDeclarationSyntax first, filter by trigger attribute, then scan invocations

- Pass TriggerMetadataInfo directly to ValidateDeserializeInvocation (no more ancestor walk)

- Document syntax-only limitation for same-named types in different namespaces

Co-authored-by: Dobby <dobby@microsoft.com>
- Require using System.Text.Json or using Newtonsoft.Json for simple-name receiver matching

- Add KnownSerializerNamespaces set and IsKnownSerializerNamespace helper

- Update conditional access test to include using System.Text.Json

Co-authored-by: Dobby <dobby@microsoft.com>
- Changed return null to continue in ExtractTriggerMetadata for unparseable attributes

- Allows finding valid attributes when multiple/malformed attributes exist

Co-authored-by: Dobby <dobby@microsoft.com>
- Each method is visited once in the loop, so cache is redundant — removed

Co-authored-by: Dobby <dobby@microsoft.com>
- Check full receiver expression text for System.Text.Json.JsonSerializer etc.

- Allows diagnostics when using fully-qualified calls without a using directive

Co-authored-by: Dobby <dobby@microsoft.com>
- Map each serializer type to its specific namespace (JsonSerializer->System.Text.Json)

- Fix NormalizeQualifiedName doc: uses string prefix strip, not recursive walk

- Acknowledge nested type '+' vs '.' and using static false positive as known limitations

Co-authored-by: Dobby <dobby@microsoft.com>
- Use exact namespace match instead of StartsWith to prevent child namespace false positives

- Strip global:: prefix from fully-qualified receiver text

- Remove unused IsKnownSerializerNamespace and KnownSerializerNamespaces

Co-authored-by: Dobby <dobby@microsoft.com>
- Check using static against KnownFullyQualifiedSerializerTypes instead of simple name

- Add NormalizeUsingName to strip global:: from using name

Co-authored-by: Dobby <dobby@microsoft.com>
…er detection

Known serializer types (JsonSerializer, JsonConvert) are static classes, so
conditional access (?.) cannot be used on them. Any conditional-access
Deserialize call is on a user-defined type/variable — skip it entirely.

Also suppress simple-name serializer matching when the compilation unit
declares a type with the same name (e.g., class JsonSerializer), since
the local declaration shadows the imported type.
Copilot AI review requested due to automatic review settings April 15, 2026 18:47
@daviburg daviburg force-pushed the feature/trigger-payload-validation branch from f89811f to 7481e5a Compare April 15, 2026 18:47
…heck

Replace hardcoded string comparisons with the shared set so serializer
identity is defined in one place. Adding a new serializer now only
requires updating the static data declarations, not hunting for
scattered string literals.
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 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread Server.Tests/TriggerPayloadValidatorTests.cs
1. Test global::System.Text.Json using directive normalization — found and
   fixed a bug where importedNamespaces wasn't normalizing global:: prefix,
   so 'using global::System.Text.Json;' wouldn't recognize JsonSerializer.

2. Test nested SDK type with '+' separator — verifies BuildTypeNameLookup
   correctly extracts simple names from 'Outer+WrongTriggerPayload' and
   that CSDK200 fires for a mismatched nested type.
Copilot AI review requested due to automatic review settings April 15, 2026 19:08
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 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs
Comment thread Server/Diagnostics/Validators/TriggerPayloadValidator.cs Outdated
1. Alias using directives (e.g., 'using STJ = System.Text.Json;') do not
   bring types into scope by simple name — exclude them from
   importedNamespaces to prevent false serializer matches.

2. Support simple-name using static (e.g., 'using static JsonSerializer;')
   when the corresponding namespace is already imported and the name is
   not shadowed by a local type declaration.

3. Extracted IsKnownStaticSerializerImport helper to consolidate both
   fully-qualified and simple-name static import detection.
@daviburg
Copy link
Copy Markdown
Member Author

Closing to re-create with a fresh review context (86 resolved threads were likely overwhelming Copilot reviewer). Same branch, same code — new PR for a clean review pass.

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.

Diagnostics: trigger payload type validation

2 participants