S-003: IWindowsWorkerClient contract + null-impl + worker-absence detection#712
Open
benhegartysefe wants to merge 1 commit into
Open
S-003: IWindowsWorkerClient contract + null-impl + worker-absence detection#712benhegartysefe wants to merge 1 commit into
benhegartysefe wants to merge 1 commit into
Conversation
…ection
Establishes the seam every later worker-move step (S-004 / S-005 / S-006)
extends. Resolves HLPS U-6 (URL discovery via config), U-7 (contract DTO
location: Dorc.ApiModel — future steps), and U-11 (worker-absence
detection: explicit WindowsWorker:Enabled config flag).
New types:
- Dorc.Api/Interfaces/IWindowsWorkerClient.cs — empty marker interface;
later S-steps add concrete worker methods.
- Dorc.Api/Services/HttpWindowsWorkerClient.cs — real HTTP impl; takes
injected typed HttpClient.
- Dorc.Api/Services/WorkerUnavailableClient.cs — null impl; methods (added
by later steps) throw WorkerUnavailableException.
- Dorc.Api/Services/WorkerKeyDelegatingHandler.cs — DelegatingHandler that
attaches the X-Worker-Key shared secret to every outbound call.
- Dorc.Api/Services/WorkerUnavailableExceptionFilter.cs — global
IExceptionFilter that translates WorkerUnavailableException to a
documented 503 body {"error":"windows_worker_unavailable","endpoint":"..."}.
- Dorc.Api/Exceptions/WorkerUnavailableException.cs — typed exception.
DI wiring in Program.cs:
- Reads WindowsWorker:Enabled bool. When true: AddHttpClient<...> for
the typed client with WorkerKeyDelegatingHandler. When false:
AddSingleton<IWindowsWorkerClient, WorkerUnavailableClient>.
- WorkerUnavailableExceptionFilter registered globally on controllers.
Config: appsettings.json gains WindowsWorker section. Enabled defaults
to false so existing Windows-install topology is unchanged at this commit
(no worker process running). Flag flips true in S-008 (installer).
Tests (Dorc.Api.Tests/WindowsWorkerClientTests.cs) — 4 pass:
- WorkerKeyDelegatingHandler adds the X-Worker-Key header from config.
- WorkerKeyDelegatingHandler omits the header when secret is empty
(lets the worker's auth scheme emit the documented 401 cleanly).
- WorkerUnavailableExceptionFilter translates WorkerUnavailableException
→ 503 + documented body shape.
- WorkerUnavailableExceptionFilter ignores other exception types.
Test results:
- Dorc.Api.Tests: 194 / 194 pass (4 new + 190 existing).
Branched off main; independent of #706 / #710 / #711 per IS multi-PR plan.
S-004/S-005/S-006 stack on this once it merges (they add methods to the
interface that both implementations cover).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| LastRequest = request; | ||
| return Task.FromResult(new HttpResponseMessage(System.Net.HttpStatusCode.OK)); |
| Assert.AreEqual(StatusCodes.Status503ServiceUnavailable, result!.StatusCode); | ||
|
|
||
| // Body is anonymous: {error="windows_worker_unavailable", endpoint="reset-password"} | ||
| var body = result.Value!.GetType(); |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IWindowsWorkerClientinterface (empty marker for now; later steps add methods).HttpWindowsWorkerClient(typed HttpClient withWorkerKeyDelegatingHandlerinjectingX-Worker-Key), andWorkerUnavailableClient(null impl that throwsWorkerUnavailableException→ global filter renders503 {"error":"windows_worker_unavailable","endpoint":"…"}).WindowsWorker:Enabledconfig flag selects the implementation. Defaults tofalseso existing Windows installs behave unchanged at this commit (flag flipstruein S-008 when the installer wires the worker).Dorc.ApiModel— to be exercised by later steps), U-11 (worker-absence detection — explicit config flag).Test plan
Dorc.Api.Tests/WindowsWorkerClientTests.cs— 4 new tests covering the delegating handler's header injection (with and without configured secret) and the global exception filter's behaviour (translate + ignore).Dorc.Api.Tests: 194 / 194 pass (4 new + 190 existing).Dorc.Apibuilds clean.Independent of PR #706 / #710 / #711 per IS multi-PR plan. S-004 / S-005 / S-006 stack on this once it merges.
🤖 Generated with Claude Code