• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Genfic / Ogma / 36636116355

29 Sep 2026 09:52PM UTC coverage: 0.583% (+0.03%) from 0.555%
36636116355

push

github

Atulin
Better invite code handling, resource monitor, better CI/CD
- Unified invite code redemption and user creation into a single atomic transaction for better consistency
- Added `SystemResourceMonitor` with cross-platform CPU, memory, and disk usage tracking
- Improved deployment workflow for better secrets management

46 of 257 new or added lines in 12 files covered. (17.9%)

734 existing lines in 7 files now uncovered.

933 of 159931 relevant lines covered (0.58%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Ogma3/Services/InviteCodeService/InviteCodeService.cs
1
using Immediate.Injections.Shared;
2
using JetBrains.Annotations;
3
using Microsoft.EntityFrameworkCore;
4
using Ogma3.Data;
5

6
namespace Ogma3.Services.InviteCodeService;
7

8
/// <summary>
9
/// Single point of truth for redeeming an invite code. Registration is invite-only, so every
10
/// path that can create a user must claim a code through here.
11
/// </summary>
12
/// <remarks>
13
/// A code is unused exactly while both <c>UsedDate</c> and <c>UsedById</c> are null, and redeemed
14
/// once <c>UsedById</c> points at the user it authorised. There is deliberately no in-between
15
/// state: claiming and creating the user happen in the same transaction, so a code can never be
16
/// burnt on a user that does not exist and a user can never exist without a code behind it.
17
/// </remarks>
18
[RegisterTransient]
19
[UsedImplicitly]
20
public sealed class InviteCodeService(AppDbContext context, ILogger<InviteCodeService> logger)
×
21
{
22
        /// <summary>
23
        /// Atomically claims an unused invite code for a user that has already been created.
24
        /// </summary>
25
        /// <remarks>
26
        /// This runs inside the caller's transaction, so rolling that transaction back hands the code
27
        /// back without any compensating write. The claim is a single conditional
28
        /// <c>UPDATE ... WHERE Code = @code AND UsedById IS NULL AND UsedDate IS NULL</c>, so the
29
        /// database — not a prior read — decides the winner when two requests race with the same code.
30
        /// Under PostgreSQL <c>READ COMMITTED</c> the loser's <c>UPDATE</c> blocks on the row lock and
31
        /// then re-evaluates the predicate, so exactly one caller can ever see
32
        /// <see cref="InviteCodeRedemptionResult.Redeemed" />.
33
        /// </remarks>
34
        public async Task<InviteCodeRedemptionResult> RedeemAsync(string? code, long userId, CancellationToken cancellationToken)
35
        {
NEW
36
                if (string.IsNullOrWhiteSpace(code)) return InviteCodeRedemptionResult.NotFound;
×
37

NEW
38
                var now = DateTimeOffset.UtcNow;
×
NEW
39
                var redeemed = await context.InviteCodes
×
40
                        .Where(ic => ic.Code == code)
×
NEW
41
                        .Where(ic => ic.UsedById == null)
×
42
                        .Where(ic => ic.UsedDate == null)
×
43
                        .ExecuteUpdateAsync(s => s
×
NEW
44
                                        .SetProperty(ic => ic.UsedById, userId)
×
NEW
45
                                        .SetProperty(ic => ic.UsedDate, now),
×
UNCOV
46
                                cancellationToken);
×
47

NEW
48
                if (redeemed > 0) return InviteCodeRedemptionResult.Redeemed;
×
49

50
                // The conditional update matched nothing. Distinguish "no such code" from "already taken"
51
                // so the caller can show the right message. This only runs on the failure path, and
52
                // projecting the nullable key keeps a code that exists but is not yet claimed distinct
53
                // from a code that does not exist at all.
NEW
54
                var existing = await context.InviteCodes
×
55
                        .Where(ic => ic.Code == code)
×
NEW
56
                        .Select(ic => ic.UsedById)
×
NEW
57
                        .ToListAsync(cancellationToken);
×
58

NEW
59
                if (existing.Count == 0)
×
60
                {
61
                        logger.LogWarning("An unknown invite code was submitted for redemption");
×
NEW
62
                        return InviteCodeRedemptionResult.NotFound;
×
63
                }
64

NEW
65
                logger.LogWarning("Invite code was already claimed when user {UserId} tried to redeem it", userId);
×
NEW
66
                return InviteCodeRedemptionResult.AlreadyClaimed;
×
67
        }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc