< Summary

Information
Class: AsiBackbone.Core.Actors.GovernanceActorContext
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Actors/GovernanceActorContext.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 130
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.cctor()100%11100%
Human(...)100%11100%
Service(...)100%11100%
Agent(...)100%11100%
NormalizeActorId(...)100%11100%
NormalizeDisplayName(...)100%44100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Actors/GovernanceActorContext.cs

#LineLine coverage
 1namespace AsiBackbone.Core.Actors;
 2
 3/// <summary>
 4/// Provides a default framework-neutral actor context implementation.
 5/// </summary>
 6public sealed record GovernanceActorContext : IGovernanceActorContext
 7{
 8    /// <summary>
 9    /// The stable identifier used for unknown actors.
 10    /// </summary>
 11    public const string UnknownActorId = "unknown";
 12
 13    /// <summary>
 14    /// The stable identifier used for system actors.
 15    /// </summary>
 16    public const string SystemActorId = "system";
 17
 20018    private GovernanceActorContext(
 20019        string actorId,
 20020        GovernanceActorType actorType,
 20021        string? displayName,
 20022        bool isKnown,
 20023        bool isAuthenticated)
 24    {
 20025        ActorId = NormalizeActorId(actorId);
 19726        ActorType = actorType;
 19727        DisplayName = NormalizeDisplayName(displayName);
 19728        IsKnown = isKnown;
 19729        IsAuthenticated = isAuthenticated;
 19730    }
 31
 32    /// <inheritdoc />
 33    public string ActorId { get; }
 34
 35    /// <inheritdoc />
 36    public GovernanceActorType ActorType { get; }
 37
 38    /// <inheritdoc />
 39    public string? DisplayName { get; }
 40
 41    /// <inheritdoc />
 42    public bool IsKnown { get; }
 43
 44    /// <inheritdoc />
 45    public bool IsAuthenticated { get; }
 46
 47    /// <summary>
 48    /// Gets a shared actor context for unknown or unauthenticated operations.
 49    /// </summary>
 50    public static GovernanceActorContext Unknown { get; } =
 351        new(UnknownActorId, GovernanceActorType.Unknown, null, isKnown: false, isAuthenticated: false);
 52
 53    /// <summary>
 54    /// Gets a shared actor context for trusted system operations.
 55    /// </summary>
 56    public static GovernanceActorContext System { get; } =
 357        new(SystemActorId, GovernanceActorType.System, "System", isKnown: true, isAuthenticated: true);
 58
 59    /// <summary>
 60    /// Creates an actor context for a human participant.
 61    /// </summary>
 62    /// <param name="actorId">The stable actor identifier.</param>
 63    /// <param name="displayName">The optional display name.</param>
 64    /// <param name="isAuthenticated">Whether the host has authenticated the actor.</param>
 65    /// <returns>A human actor context.</returns>
 66    public static GovernanceActorContext Human(
 67        string actorId,
 68        string? displayName = null,
 69        bool isAuthenticated = true)
 70    {
 10571        return new GovernanceActorContext(
 10572            actorId,
 10573            GovernanceActorType.Human,
 10574            displayName,
 10575            isKnown: true,
 10576            isAuthenticated: isAuthenticated);
 77    }
 78
 79    /// <summary>
 80    /// Creates an actor context for a service participant.
 81    /// </summary>
 82    /// <param name="actorId">The stable service actor identifier.</param>
 83    /// <param name="displayName">The optional display name.</param>
 84    /// <returns>A service actor context.</returns>
 85    public static GovernanceActorContext Service(string actorId, string? displayName = null)
 86    {
 8387        return new GovernanceActorContext(
 8388            actorId,
 8389            GovernanceActorType.Service,
 8390            displayName,
 8391            isKnown: true,
 8392            isAuthenticated: true);
 93    }
 94
 95    /// <summary>
 96    /// Creates an actor context for a delegated or autonomous software agent.
 97    /// </summary>
 98    /// <param name="actorId">The stable agent actor identifier.</param>
 99    /// <param name="displayName">The optional display name.</param>
 100    /// <param name="isAuthenticated">Whether the host has authenticated the agent.</param>
 101    /// <returns>An agent actor context.</returns>
 102    public static GovernanceActorContext Agent(
 103        string actorId,
 104        string? displayName = null,
 105        bool isAuthenticated = true)
 106    {
 6107        return new GovernanceActorContext(
 6108            actorId,
 6109            GovernanceActorType.Agent,
 6110            displayName,
 6111            isKnown: true,
 6112            isAuthenticated: isAuthenticated);
 113    }
 114
 115    private static string NormalizeActorId(string actorId)
 116    {
 200117        ArgumentException.ThrowIfNullOrWhiteSpace(actorId);
 118
 197119        return actorId.Trim();
 120    }
 121
 122    private static string? NormalizeDisplayName(string? displayName)
 123    {
 197124        string? normalizedDisplayName = displayName?.Trim();
 125
 197126        return string.IsNullOrWhiteSpace(normalizedDisplayName)
 197127            ? null
 197128            : normalizedDisplayName;
 129    }
 130}