Skip to content

test: cut low-value tests, close coverage gaps and fix the test infrastructure - #418

Merged
hhvrc merged 3 commits into
developfrom
test/suite-quality
Dec 4, 2026
Merged

hhvrc merged 3 commits into
developfrom
test/suite-quality

Conversation

@hhvrc

@hhvrc hhvrc commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

What

An audit of the whole test suite, then the fixes. Test methods go from 565 to 420 while coverage goes up.

Removed or rewritten

  • Tests that could not fail (the rate-limiter tests ran against the no-limit stub; hub revocation tests that never reached the code they named; a copied SQL query instead of the production one; tautologies and status-only assertions).
  • Tests of the framework rather than this project ([Range], [StringLength], required, JSON enum converter, BCrypt salting).
  • Duplicates: per-file unauthenticated-401 copies now live in one parameterised test in AuthorizationTests; flows that were a prefix of another test.
  • One-input-per-test unit files are parameterised (DomainUtils, UsernameValidator, SemVersion, PermissionUtils, ...).
  • Random-id 404 checks are replaced by cross-user ownership checks for tokens, sessions, shockers and devices.
  • Pure-function cases moved from integration to unit tests (slug, social link, signup code, trusted origin).

Coverage added

  • Admin endpoints refuse non-admin sessions and API tokens.
  • An API token cannot mint tokens; token self-delete branches.
  • Another user's shocker cannot be added to a public share.
  • Public-share hub control with real commands (limits, permissions, pause).
  • Share-code linking; password reset with a wrong or reused secret.
  • Legacy PBKDF2 password verification; rate-limiter partition selectors.

Test infrastructure

  • The Cron test host no longer runs the Hangfire server or the outbox listener.
  • Container fixtures are shared through a new IntegrationTests.Shared project; the unused Docker network, packages and data files are gone.
  • Client location is set per request with test-only headers instead of process-wide state (GeoLocatedWebApplicationFactory removed).
  • The Turnstile fake verifies the secret.
  • The shared database bootstraps through the production migration path.

Production changes (small)

  • Rate-limiter partition selectors extracted to Common/Utils/RateLimitPartitions.cs (behaviour unchanged) so they can be unit tested.
  • Removed ISessionService.DeleteSessionByTokenAsync and DomainUtils.HostMatchesCookieDomain, which only tests called.
  • Three incorrect comments fixed.

Verification

  • Solution builds with 0 warnings and 0 errors.
  • Common.Tests and Cron.Tests pass.
  • The integration tests were not run locally. The changed integration tests were checked by compilation and by reading the production code, so CI is the first real run.

Review notes

  • The shared test database now uses ghcr.io/openshock/postgres-timescaledb:2.32.1-18.7-trixie (the image the compose files pin). It has not been confirmed to start under Testcontainers.
  • Dragonfly, Mailpit and the upstream Timescale images in TimescaleDbRequirementTests are still on floating tags.
  • LimitNormalizationMigrationTests and PendingSignupsMigrationTests are kept until their migrations have shipped.
  • Not fixed, flagged only: PasswordAttribute bounds password length with the email-address length constants.

hhvrc added 2 commits December 4, 2026 16:03
…structure

Audit of the whole suite: remove tests that could not fail, tested the
framework or duplicated each other; parameterise one-input-per-test files;
rewrite weak assertions; replace random-id 404 checks with cross-user
ownership checks; move pure-function cases from integration to unit tests.

Coverage added: admin endpoints refusing non-admins and API tokens, API
tokens unable to mint tokens, cross-user access on tokens, sessions,
shockers and devices, public-share hub control, share-code linking,
password reset with a wrong or reused secret, legacy PBKDF2 verification.

Test infrastructure: stop Hangfire and the outbox listener in the Cron test
host, share the container fixtures through IntegrationTests.Shared, set the
client location per request instead of process-wide state, make the
Turnstile fake check the secret, drop the unused Docker network, packages
and data files, bootstrap the database through the production migration
path.

Production: extract the rate-limiter partition selectors into
RateLimitPartitions so they can be unit tested, remove the uncalled
DeleteSessionByTokenAsync and HostMatchesCookieDomain, fix three comments.
TestHelper.UniqueEmail/UniqueUsername only forwarded to UniqueNames, and
PostgresFixture.ConnectionString only forwarded to a private static. Call
the real targets directly.
@hhvrc
hhvrc requested a review from LucHeart as a code owner December 4, 2026 15:24
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Too many files!

This PR contains 111 files, which is 11 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This organization's CodeRabbit subscription is cancelled. Resubscribe in Billing to continue reviews beyond the free-tier limit.

Check out review usage here.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 935ae951-700d-4ef7-950f-b5d344b52c4e
Commits

Reviewing files that changed from the base of the PR and between 4602c01 and b32b089.

Files selected for processing: 111

  • API.IntegrationTests/API.IntegrationTests.csproj
  • API.IntegrationTests/AssemblyAttributes.cs
  • API.IntegrationTests/Docker/DockerNetwork.cs
  • API.IntegrationTests/Docker/InMemoryDatabase.cs
  • API.IntegrationTests/Docker/InMemoryRedis.cs
  • API.IntegrationTests/GeoLocatedWebApplicationFactory.cs
  • API.IntegrationTests/HeaderIpEnrichmentService.cs
  • API.IntegrationTests/Helpers/OAuthFlowCookieHelper.cs
  • API.IntegrationTests/Helpers/TestHelper.cs
  • API.IntegrationTests/HttpMessageHandlers/InterceptedHttpMessageHandler.cs
  • API.IntegrationTests/Tests/AccountAuthenticatedTests.cs
  • API.IntegrationTests/Tests/AccountLoginTests.cs
  • API.IntegrationTests/Tests/AccountSignupTests.cs
  • API.IntegrationTests/Tests/AccountTests.cs
  • API.IntegrationTests/Tests/AdminUserLifecycleTests.cs
  • API.IntegrationTests/Tests/AdminUsersViewTests.cs
  • API.IntegrationTests/Tests/AuthorizationTests.cs
  • API.IntegrationTests/Tests/AutomationTokenTests.cs
  • API.IntegrationTests/Tests/ControlStatChangesTests.cs
  • API.IntegrationTests/Tests/ControlStatsTests.cs
  • API.IntegrationTests/Tests/DatabaseConstraintTests.cs
  • API.IntegrationTests/Tests/DeviceEndpointTests.cs
  • API.IntegrationTests/Tests/DevicesTests.cs
  • API.IntegrationTests/Tests/EmailOutboxPersistenceTests.cs
  • API.IntegrationTests/Tests/EmailProviderBlacklistTests.cs
  • API.IntegrationTests/Tests/EmailStatusEnumTests.cs
  • API.IntegrationTests/Tests/LcgAssignmentTests.cs
  • API.IntegrationTests/Tests/LcgCoordinateAssignmentTests.cs
  • API.IntegrationTests/Tests/LimitNormalizationMigrationTests.cs
  • API.IntegrationTests/Tests/MailDisabledTests.cs
  • API.IntegrationTests/Tests/MailTests.cs
  • API.IntegrationTests/Tests/MetadataTests.cs
  • API.IntegrationTests/Tests/OAuthConnectionTests.cs
  • API.IntegrationTests/Tests/OAuthFlowTests.cs
  • API.IntegrationTests/Tests/PendingSignupsMigrationTests.cs
  • API.IntegrationTests/Tests/PublicShareControlTests.cs
  • API.IntegrationTests/Tests/PublicSharePasswordTests.cs
  • API.IntegrationTests/Tests/PublicShareProfileTests.cs
  • API.IntegrationTests/Tests/PublicTests.cs
  • API.IntegrationTests/Tests/RateLimiterTests.cs
  • API.IntegrationTests/Tests/RegistrationDisabledTests.cs
  • API.IntegrationTests/Tests/RetiredRoutesTests.cs
  • API.IntegrationTests/Tests/SessionsTests.cs
  • API.IntegrationTests/Tests/ShareCodeTests.cs
  • API.IntegrationTests/Tests/ShareLimitTests.cs
  • API.IntegrationTests/Tests/ShareLinksTests.cs
  • API.IntegrationTests/Tests/ShockerPermissionsTests.cs
  • API.IntegrationTests/Tests/ShockersTests.cs
  • API.IntegrationTests/Tests/SignalRUserHubTests.cs
  • API.IntegrationTests/Tests/SignupActivationTests.cs
  • API.IntegrationTests/Tests/SignupBrowserCookieCountryTests.cs
  • API.IntegrationTests/Tests/TimescaleDbRequirementTests.cs
  • API.IntegrationTests/Tests/TokensTests.cs
  • API.IntegrationTests/Tests/TransactionLockTests.cs
  • API.IntegrationTests/Tests/UsersTests.cs
  • API.IntegrationTests/WebApplicationFactory.cs
  • API/Models/Requests/EditTokenRequestV2.cs
  • Common.Tests/Authentication/TrustedOriginAttributeTests.cs
  • Common.Tests/Common.Tests.csproj
  • Common.Tests/HealthChecks/CachedHealthCheckServiceTests.cs
  • Common.Tests/Hubs/TrackedHubConnectionTests.cs
  • Common.Tests/JsonSerialization/IPAddressJsonConverterTests.cs
  • Common.Tests/Models/ApiTokenControlLimitsTests.cs
  • Common.Tests/Models/AuditMetadataTests.cs
  • Common.Tests/Models/SemVersion.cs
  • Common.Tests/OpenShockDb/EmailOutboxMessageTests.cs
  • Common.Tests/OpenShockDb/SaturatingConverterTests.cs
  • Common.Tests/Options/SecurityTxtOptionsTests.cs
  • Common.Tests/Redis/PubSubSerializationTests.cs
  • Common.Tests/Services/GeoPointTests.cs
  • Common.Tests/Services/IpEnrichmentServiceTests.cs
  • Common.Tests/Utils/ControlLimitUtilsTests.cs
  • Common.Tests/Utils/DomainUtilsTests.cs
  • Common.Tests/Utils/GravatarUtilsTests.cs
  • Common.Tests/Utils/HashingUtilsTests.cs
  • Common.Tests/Utils/IpAddressUtilsTests.cs
  • Common.Tests/Utils/PermissionUtilsTests.cs
  • Common.Tests/Utils/RateLimitPartitionsTests.cs
  • Common.Tests/Utils/SignupCodeTests.cs
  • Common.Tests/Utils/StringUtilsTests.cs
  • Common.Tests/Validation/DataSets/BlackList.txt
  • Common.Tests/Validation/DataSets/WhiteList.txt
  • Common.Tests/Validation/EmailValidatorTests.cs
  • Common.Tests/Validation/SlugValidatorTests.cs
  • Common.Tests/Validation/SocialValidatorTests.cs
  • Common.Tests/Validation/UsernameValidatorTests.cs
  • Common/Models/SemVersion.cs
  • Common/OpenShockServiceHelper.cs
  • Common/Services/Session/ISessionService.cs
  • Common/Services/Session/SessionService.cs
  • Common/Utils/DomainUtils.cs
  • Common/Utils/RateLimitPartitions.cs
  • Cron.IntegrationTests/AssemblyAttributes.cs
  • Cron.IntegrationTests/Cron.IntegrationTests.csproj
  • Cron.IntegrationTests/CronApplicationFactory.cs
  • Cron.IntegrationTests/Docker/DockerNetwork.cs
  • Cron.IntegrationTests/Docker/InMemoryDatabase.cs
  • Cron.IntegrationTests/Docker/InMemoryRedis.cs
  • Cron.IntegrationTests/Docker/TestMailServer.cs
  • Cron.IntegrationTests/Helpers/MailpitHelper.cs
  • Cron.IntegrationTests/Tests/EmailOutboxDeliveryTests.cs
  • Cron.IntegrationTests/Tests/EmailOutboxQueryTests.cs
  • Cron.Tests/Services/Email/Outbox/EmailOutboxStateMachineTests.cs
  • Cron/Program.cs
  • Directory.Packages.props
  • IntegrationTests.Shared/ContainerImages.cs
  • IntegrationTests.Shared/IntegrationTests.Shared.csproj
  • IntegrationTests.Shared/PostgresFixture.cs
  • IntegrationTests.Shared/RedisFixture.cs
  • IntegrationTests.Shared/UniqueNames.cs
  • OpenShockBackend.slnx

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

The pinned image enables TimescaleDB through its default command, and
Testcontainers replaces that command with its own flags, so the extension
was not preloaded and every integration test failed in the session hook.
@hhvrc
hhvrc merged commit 4572f08 into develop Dec 4, 2026
25 checks passed
@hhvrc
hhvrc deleted the test/suite-quality branch December 4, 2026 15:45
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