All checks were successful
## What & why S-14: a beoordeling a behandelaar does not pick up within **14 days** escalates to the **teamlead**. A non-interrupting `P14D` boundary timer on the `Beoordelen` user task fires an external-worker task (`BeoordelingEscaleren`); the domain's escalation worker reassigns the still-open task's candidate group from `behandelaar` to `teamlead`. The task keeps its identity — only who may claim it changes. The escalation-via-external-worker decision is recorded in **ADR-0015** (proposal #98); it upholds §8.2 (the Workflow Client stays the only code that talks to Flowable) and keeps Flowable a stock image. Closes #15 ## Definition of Done - [x] Linked Gitea issue (above). - [x] Failing test committed before the implementation. - [x] Implementation makes the test pass; refactor commit if structure improved. - [x] Conventional Commits referencing the issue (`refs #NN`). - [x] CI green — all Gitea Actions jobs. - [x] `docker compose up` from a fresh clone reaches green health checks within 3 minutes (no new services; escalation is additive to the domain worker). - [x] Docs updated (ADR-0015, demo note). - [x] ADR added (`docs/architecture/adr-0015-beoordeling-escalation.md`). - [x] Demo note in `docs/demo-script.md`. ## How it was built (TDD) - **Workflow Client** (`IBeoordelingEscalatieClient`): acquire `BeoordelingEscaleren` jobs → find the open `Beoordelen` task in the instance → add `teamlead`/remove `behandelaar` candidate group → complete the job. Red → green. - **Escalation drain loop** (`BeoordelingEscalatieProcessor`) + hosted `BeoordelingEscalatiePump`, mirroring the OpenZaak worker. Red → green. - **BPMN**: non-interrupting `P14D` boundary timer on `Beoordelen` → external task → escalation end. - **Both branches** (escalate after timeout; no-op when completed in time) covered by the `Een beoordeling escaleren` acceptance scenarios + Workflow Client unit tests. - **Live integration**: `verify-domain` fires the timer early via Flowable's management API and asserts the reassignment to teamlead. ## Notes for reviewers - Interface segregation: escalation is on `IBeoordelingEscalatieClient`, separate from the OpenZaak worker's `IExternalWorkerClient`. - Reassignment is two REST hops (add teamlead, remove behandelaar); idempotent on redelivery — see ADR-0015 consequences. - Local checks green: domain unit tests (104), acceptance (13), `dotnet format --verify-no-changes`, Release build (0 errors), **domain mutation 96.69%** (break 90). The `run-domain-check.sh` escalation path is CI-verified on verify-stack (local full-stack run is constrained here). - `BeoordelingEscalatiePump` excluded from mutation, mirroring the existing `OpenZaakJobPump` exclusion. Reviewed-on: #99
144 lines
6.0 KiB
C#
144 lines
6.0 KiB
C#
using Big.Application;
|
|
using Big.Domain;
|
|
using Big.Infrastructure;
|
|
|
|
namespace Acceptance.Support;
|
|
|
|
/// <summary>An in-memory Workflow Client for the domain acceptance scenario: it records which
|
|
/// registration a process was started for and returns a fixed instance id. The acceptance test
|
|
/// drives the use case without a running Flowable (live verification is the verify-domain check).</summary>
|
|
public sealed class InMemoryWorkflowClient : IWorkflowClient
|
|
{
|
|
public const string StartedProcessInstanceId = "proc-acc-1";
|
|
|
|
public RegistrationId? StartedFor { get; private set; }
|
|
public string? WithdrawnProcessInstanceId { get; private set; }
|
|
|
|
public Task<string> StartRegistrationProcessAsync(RegistrationId registrationId, CancellationToken ct = default)
|
|
{
|
|
StartedFor = registrationId;
|
|
return Task.FromResult(StartedProcessInstanceId);
|
|
}
|
|
|
|
public Task WithdrawProcessAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
WithdrawnProcessInstanceId = processInstanceId;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory ACL stand-in: records the bsn it opened a zaak for and returns a fixed URL,
|
|
/// so the scenario verifies the domain crosses the ACL boundary (§8.1) without a running OpenZaak.</summary>
|
|
public sealed class InMemoryAclClient : IAclClient
|
|
{
|
|
public static readonly Uri OpenedZaakUrl = new("http://openzaak/zaken/api/v1/zaken/acc-zaak");
|
|
|
|
public string? OpenedForBsn { get; private set; }
|
|
public string? OpenedWithReference { get; private set; }
|
|
public Uri? ApprovedZaakUrl { get; private set; }
|
|
|
|
public Task<Uri> OpenZaakAsync(string bsn, string reference, CancellationToken ct = default)
|
|
{
|
|
OpenedForBsn = bsn;
|
|
OpenedWithReference = reference;
|
|
return Task.FromResult(OpenedZaakUrl);
|
|
}
|
|
|
|
public Task ApproveZaakAsync(Uri zaakUrl, CancellationToken ct = default)
|
|
{
|
|
ApprovedZaakUrl = zaakUrl;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory user-task client for the beoordeling acceptance scenario: it holds one open
|
|
/// Beoordelen task per registration and records the besluit each is completed with.</summary>
|
|
public sealed class InMemoryUserTaskClient : IUserTaskClient
|
|
{
|
|
private readonly List<BeoordelingTask> _open = [];
|
|
|
|
public (string TaskId, BeoordelingsBesluit Besluit)? Completed { get; private set; }
|
|
|
|
public void Open(RegistrationId registrationId) => _open.Add(new BeoordelingTask($"task-{registrationId}", registrationId));
|
|
|
|
public Task<IReadOnlyList<BeoordelingTask>> GetOpenBeoordelingenAsync(CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<BeoordelingTask>>(_open);
|
|
|
|
public Task ClaimAsync(string taskId, string behandelaar, CancellationToken ct = default) => Task.CompletedTask;
|
|
|
|
public Task CompleteBeoordelingAsync(string taskId, BeoordelingsBesluit besluit, CancellationToken ct = default)
|
|
{
|
|
Completed = (taskId, besluit);
|
|
_open.RemoveAll(t => t.TaskId == taskId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory Flowable stand-in for the beoordeling-escalation scenario (S-14): it models
|
|
/// one Beoordelen task per process instance — its candidate group and whether it is still open — and
|
|
/// the escalation jobs the non-interrupting 14-day boundary timer parks. It drives the escalation
|
|
/// worker's behaviour without a running Flowable; the timer firing live is the verify-domain check.</summary>
|
|
public sealed class InMemoryEscalatieClient : IBeoordelingEscalatieClient
|
|
{
|
|
private sealed class ParkedTask
|
|
{
|
|
public string CandidateGroup { get; set; } = "behandelaar";
|
|
public bool IsOpen { get; set; } = true;
|
|
}
|
|
|
|
private readonly Dictionary<string, ParkedTask> _tasks = [];
|
|
private readonly List<EscalatieJob> _parked = [];
|
|
private int _seq;
|
|
|
|
/// <summary>A registration parks at Beoordelen, claimable by the behandelaar group.</summary>
|
|
public string ParkBeoordeling()
|
|
{
|
|
var pid = $"pi-{++_seq}";
|
|
_tasks[pid] = new ParkedTask();
|
|
return pid;
|
|
}
|
|
|
|
/// <summary>The behandelaar completes the beoordeling before the timer fires: the task closes.</summary>
|
|
public void CompleteBeoordeling(string processInstanceId) => _tasks[processInstanceId].IsOpen = false;
|
|
|
|
/// <summary>The 14-day boundary timer fires: a non-interrupting token parks an escalation job.</summary>
|
|
public void FireEscalationTimer(string processInstanceId)
|
|
=> _parked.Add(new EscalatieJob($"job-{++_seq}", processInstanceId));
|
|
|
|
/// <summary>The candidate group that may currently pick the task up.</summary>
|
|
public string CandidateGroupFor(string processInstanceId) => _tasks[processInstanceId].CandidateGroup;
|
|
|
|
public Task<IReadOnlyList<EscalatieJob>> AcquireBeoordelingEscalatieJobsAsync(int maxJobs, CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<EscalatieJob>>(_parked.Take(maxJobs).ToList());
|
|
|
|
public Task ReassignBeoordelingToTeamleadAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
// No-op if the behandelaar already completed it — the timer/completion race (§8.6).
|
|
var task = _tasks[processInstanceId];
|
|
if (task.IsOpen)
|
|
task.CandidateGroup = "teamlead";
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task CompleteBeoordelingEscalatieJobAsync(string jobId, CancellationToken ct = default)
|
|
{
|
|
_parked.RemoveAll(j => j.JobId == jobId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory registration store for the domain acceptance scenario.</summary>
|
|
public sealed class InMemoryRegistrationStore : IRegistrationStore
|
|
{
|
|
private readonly Dictionary<RegistrationId, Registration> _byId = [];
|
|
|
|
public Task SaveAsync(Registration registration, CancellationToken ct = default)
|
|
{
|
|
_byId[registration.Id] = registration;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<Registration?> GetAsync(RegistrationId id, CancellationToken ct = default)
|
|
=> Task.FromResult(_byId.GetValueOrDefault(id));
|
|
}
|