< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.ActivityExecutions.GetCallStack.Endpoint
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/ActivityExecutions/GetCallStack/Endpoint.cs
Line coverage
13%
Covered lines: 4
Uncovered lines: 25
Coverable lines: 29
Total lines: 66
Line coverage: 13.7%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
HandleAsync()0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/ActivityExecutions/GetCallStack/Endpoint.cs

#LineLine coverage
 1using Elsa.Authorization;
 2using Elsa.Abstractions;
 3using Elsa.Workflows.Runtime;
 4using Elsa.Workflows.Runtime.Filters;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Workflows.Api.Endpoints.ActivityExecutions.GetCallStack;
 8
 9/// <summary>
 10/// Gets the call stack (execution chain) for a given activity execution.
 11/// Returns activity execution records from root to the specified activity, ordered by call stack depth.
 12/// Supports pagination for deep call stacks.
 13/// </summary>
 14[PublicAPI]
 315internal class Endpoint(IActivityExecutionStore store) : ElsaEndpoint<Request, Response>
 16{
 17    /// <inheritdoc />
 18    public override void Configure()
 19    {
 320        Get("/activity-executions/{id}/call-stack");
 321        RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.ActivityExecutions, CoreVerbs.View);
 322    }
 23
 24    /// <inheritdoc />
 25    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 26    {
 027        var id = Route<string>("id")!;
 028        var includeCrossWorkflowChain = request.IncludeCrossWorkflowChain ?? true;
 29
 30        // Apply defaulting and upper bound to the requested page size to prevent excessive queries.
 31        const int defaultTake = 100;
 32        const int maxTake = 1000;
 33
 034        var skip = request.Skip;
 035        var take = request.Take ?? defaultTake;
 36
 037        if (take <= 0)
 038            take = defaultTake;
 39
 040        if (take > maxTake)
 041            take = maxTake;
 42
 43        // First, check if the activity execution exists.
 044        var idFilter = new ActivityExecutionRecordFilter
 045        {
 046            Id = id
 047        };
 048        var activityExecution = await store.FindAsync(idFilter, cancellationToken);
 049        if (activityExecution == null)
 50        {
 051            await Send.NotFoundAsync(cancellationToken);
 052            return;
 53        }
 54
 55        // Then, get the execution chain. An empty chain should result in 200 with an empty items array.
 056        var result = await store.GetExecutionChainAsync(id, includeCrossWorkflowChain, skip, take, cancellationToken);
 057        var response = new Response
 058        {
 059            ActivityExecutionId = id,
 060            Items = result.Items.ToList(),
 061            TotalCount = result.TotalCount
 062        };
 63
 064        await Send.OkAsync(response, cancellationToken);
 065    }
 66}