Skip to content

test: cover server SDK User-Agent contract - #295

Merged
dustinbyrne merged 1 commit into
mainfrom
test/harden-server-snapshot-coverage
Aug 19, 2026
Merged

dustinbyrne merged 1 commit into
mainfrom
test/harden-server-snapshot-coverage

Conversation

@dustinbyrne

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

The server SDK wire snapshots validate request JSON, but did not protect the accompanying User-Agent header contract. This adds coverage that every snapshotted request sends the expected posthog-dotnet/<version> product and runtime comment containing the framework, OS, and process architecture.

The contract compares the product version with the generated VersionConstants.Version value rather than a literal version, so release version bumps are covered without causing test churn. Negative tests prove that unexpected product/version values and missing runtime components are rejected.

💚 How did you test it?

  • dotnet test tests/UnitTests/UnitTests.csproj --framework net8.0 --filter 'FullyQualifiedName~ServerSdkSnapshotTests.FinalWireSnapshots|FullyQualifiedName~ServerSdkSnapshotTests.UserAgentContractTests' --no-restore — passed 9/9 tests.
  • dotnet format tests/UnitTests/UnitTests.csproj --verify-no-changes --no-restore — passed (workspace-load warnings only).
  • The equivalent netcoreapp3.1 focused command built the projects successfully, but test execution is unavailable on this local Apple Silicon host because VSTest requests an x64 dotnet host that is not installed. CI remains responsible for executing that target.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

A human directed the User-Agent contract hardening and PR submission. The Pi coding agent inspected the existing test-only diff, reran focused validation, and submitted it without adding release metadata; the independent final review supplied by the human reported no blockers. No shareable agent-session link is available.

@dustinbyrne
dustinbyrne requested a review from a team as a code owner August 18, 2026 20:45
@dustinbyrne dustinbyrne self-assigned this Aug 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-08-18 20:46:26 UTC
Duration: 4467ms

✅ All Tests Passed!

17/17 tests passed


Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 251ms
Request Payload.Flags Request Uses V2 Query Param ✅ 125ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 115ms
Request Payload.Flags Request Omits Authorization Header ✅ 111ms
Request Payload.Token In Flags Body Matches Init ✅ 111ms
Request Payload.Groups Round Trip ✅ 112ms
Request Payload.Groups Default To Empty Object ✅ 109ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 111ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 112ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 109ms
Request Lifecycle.No Flags Request On Init Alone ✅ 4ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 114ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 212ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 113ms
Retry Behavior.Retries Flags On 502 ✅ 1116ms
Retry Behavior.Retries Flags On 504 ✅ 1115ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 214ms

@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "test: cover server SDK User-Agent contra..." | Re-trigger Greptile

@arnohillen arnohillen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(created by PostHog Desktop)

The asserted shape matches production exactly (PostHogApiClient.cs:49 sends posthog-dotnet/{Version} ({Framework}; {OS}; {Arch}), which HttpClient parses into precisely the two ProductInfoHeaderValue entries the helper checks). The negative tests fail for the intended reason rather than by accident: 2.13.3-unexpected is a valid HTTP token and (; os; arch) a valid comment, so neither throws a FormatException that would mask the XunitException.

@dustinbyrne
dustinbyrne merged commit 9df8d2c into main Aug 19, 2026
20 checks passed
@dustinbyrne
dustinbyrne deleted the test/harden-server-snapshot-coverage branch August 19, 2026 15:48
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.

2 participants