< 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: 65
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.Abstractions;
 2using Elsa.Workflows.Runtime;
 3using Elsa.Workflows.Runtime.Filters;
 4using JetBrains.Annotations;
 5
 6namespace Elsa.Workflows.Api.Endpoints.ActivityExecutions.GetCallStack;
 7
 8/// <summary>
 9/// Gets the call stack (execution chain) for a given activity execution.
 10/// Returns activity execution records from root to the specified activity, ordered by call stack depth.
 11/// Supports pagination for deep call stacks.
 12/// </summary>
 13[PublicAPI]
 314internal class Endpoint(IActivityExecutionStore store) : ElsaEndpoint<Request, Response>
 15{
 16    /// <inheritdoc />
 17    public override void Configure()
 18    {
 319        Get("/activity-executions/{id}/call-stack");
 320        ConfigurePermissions("read:activity-execution");
 321    }
 22
 23    /// <inheritdoc />
 24    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 25    {
 026        var id = Route<string>("id")!;
 027        var includeCrossWorkflowChain = request.IncludeCrossWorkflowChain ?? true;
 28
 29        // Apply defaulting and upper bound to the requested page size to prevent excessive queries.
 30        const int defaultTake = 100;
 31        const int maxTake = 1000;
 32
 033        var skip = request.Skip;
 034        var take = request.Take ?? defaultTake;
 35
 036        if (take <= 0)
 037            take = defaultTake;
 38
 039        if (take > maxTake)
 040            take = maxTake;
 41
 42        // First, check if the activity execution exists.
 043        var idFilter = new ActivityExecutionRecordFilter
 044        {
 045            Id = id
 046        };
 047        var activityExecution = await store.FindAsync(idFilter, cancellationToken);
 048        if (activityExecution == null)
 49        {
 050            await Send.NotFoundAsync(cancellationToken);
 051            return;
 52        }
 53
 54        // Then, get the execution chain. An empty chain should result in 200 with an empty items array.
 055        var result = await store.GetExecutionChainAsync(id, includeCrossWorkflowChain, skip, take, cancellationToken);
 056        var response = new Response
 057        {
 058            ActivityExecutionId = id,
 059            Items = result.Items.ToList(),
 060            TotalCount = result.TotalCount
 061        };
 62
 063        await Send.OkAsync(response, cancellationToken);
 064    }
 65}