Commit 17e6107
fix(project-engine-client): bypass Counterfact 406 on empty-body 2xx mock acks (#1744)
<!-- mysticat-pr-skill -->
## 1. Abstract
Makes the Project Engine Counterfact mock return its intended empty-body
2xx ack (publish, batch-delete, update-benchmark) when the request
carries `Accept: application/json`, instead of `406 Not Acceptable`.
## 2. Reasoning
The mock 406'd on every empty-body 2xx handler whenever the caller sent
`Accept: application/json` — which the serenity transport in
spacecat-api-service does on every call. A bare `{ status, body }`
return goes through Counterfact's response content-negotiation, and an
empty-body `202` declares no `application/json` representation, so
Counterfact answered `406` rather than the `202`. This is a
mock-fidelity bug, not a production bug: the real Semrush gateway
returns the empty ack regardless of `Accept`. The 406 blocked the
serenity create/activate API-level IT increment — `createMarket` /
`activate` create a draft then `publish`, and the publish step failed
upstream with a `502 serenityUpstreamError`.
## 3. High-level overview of the changes
A new `emptyAck()` helper returns a raw `{ status, body: '', contentType
}` envelope. The explicit content type is the signal that makes
Counterfact skip response negotiation/validation — the same bypass the
mock's auth 401 and quota 405 already rely on. The helper is wired onto
the per-request Context as `context.emptyAck`, mirroring how the auth
guard is exposed.
Behaviour delta:
- Before: the four empty-body `202` ack handlers (publish, benchmarks
batch-delete, benchmark update, brand-urls batch-delete) returned `406`
under `Accept: application/json`; `*/*` or no `Accept` got `202`.
- After: all four return `202` with an empty body regardless of
`Accept`, matching the live gateway's `content-length: 0` ack.
The three `204 No Content` handlers (project delete, ai_models
batch-delete, prompts batch-delete) are intentionally left as bare `{
status: 204 }`: Counterfact special-cases `204` and serves it without
negotiating, so they never 406. A `204` carries no body and no
`Content-Type`, which the bare return preserves — keeping them closer to
the live response than routing them through the helper would.
## 4. Required information
- Jira / issue: #1742
- Other: blocked IT increment
adobe/spacecat-api-service#2709 · PE mock image
#1732
## 5. Affected / used mysticat-workspace projects
- spacecat-api-service — consumer (contract). Its serenity API-level IT
suite boots this mock as a GHCR image; the create/activate lifecycle
increment is unblocked once the mock image carrying this fix is
published and the tag is bumped there.
## 6. Additional information outside the code
Booted the mock locally (`MOCK_SEED=workspace-with-data`) and replayed
the issue's reproduction against the seeded workspace/project under
`Accept: application/json`:
- publish, benchmarks batch-delete, benchmark PUT, brand-urls
batch-delete — each now responds `202` (was `406`); the publish response
body is `0` bytes, matching the live `content-length: 0` ack.
- The three `204` delete handlers still respond `204` under the same
`Accept: application/json`, confirming they were correctly left
untouched.
Validated against the real prod gateway with an IMS prod token
(workspace `bfe3c7eb-469f-4331-9b10-7b1319bb6460`), probing the
empty-2xx ack path non-destructively via a no-op batch delete (`{"ids":
[]}`):
- Prod returns `202` with `content-length: 0` and **no `Content-Type`
header**.
- The mock matches prod on status and (empty) body, but adds one
`Content-Type: application/json` header prod does not send. This is a
known, unavoidable Counterfact limitation — a truthy content type is the
only way to get a 0-byte body past Counterfact's negotiation; without it
the response either `406`s or falls back to a `text/plain` "Accepted"
8-byte body (verified across both the raw-return and typed
`$.response[202]` paths). The extra header is invisible to the consumer,
which keys off `response.ok`/status. Documented inline in
`mock/responses.js`.
## 7. Test plan
- Local: booted the mock and ran the issue's repro `curl` for all four
ack endpoints with `Accept: application/json` (results in section 6);
also ran the package e2e suite, which drives the real typed client
against a live mock and now sends `Accept: application/json` on the
raw-fetch ack assertions to pin the regression.
- To verify in the consuming repo: build/publish the mock image from
this branch (or the released tag), bump the mock image tag in
adobe/spacecat-api-service#2709 , and run the
serenity create/activate IT lifecycle — `POST .../markets`
(createMarket) and `POST .../activate` should reach `201` / `200`
instead of `502`.
## 8. Deployment & merge order
- Related: adobe/spacecat-api-service#2709
(related) — consumes the fixed mock image; its create/activate increment
depends on this.
- Related: #1732 (related)
— the release-tag workflow that publishes the mock GHCR image.
Order: merge this PR → semantic-release publishes a new package version
and the mock-image workflow publishes a new GHCR tag → bump that tag in
the api-service PR to unblock its IT.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 2f43104 commit 17e6107
9 files changed
Lines changed: 146 additions & 16 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
77 | 84 | | |
78 | 85 | | |
79 | 86 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
73 | 80 | | |
74 | 81 | | |
75 | 82 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
58 | 59 | | |
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
Lines changed: 23 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
| 588 | + | |
| 589 | + | |
588 | 590 | | |
589 | 591 | | |
590 | 592 | | |
591 | 593 | | |
592 | | - | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
593 | 599 | | |
594 | 600 | | |
595 | 601 | | |
| |||
604 | 610 | | |
605 | 611 | | |
606 | 612 | | |
| 613 | + | |
607 | 614 | | |
608 | 615 | | |
609 | 616 | | |
610 | 617 | | |
611 | | - | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
612 | 623 | | |
613 | 624 | | |
614 | 625 | | |
| |||
656 | 667 | | |
657 | 668 | | |
658 | 669 | | |
| 670 | + | |
659 | 671 | | |
660 | 672 | | |
661 | 673 | | |
662 | 674 | | |
663 | | - | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
664 | 680 | | |
665 | 681 | | |
666 | 682 | | |
| |||
677 | 693 | | |
678 | 694 | | |
679 | 695 | | |
| 696 | + | |
| 697 | + | |
680 | 698 | | |
681 | 699 | | |
682 | | - | |
| 700 | + | |
| 701 | + | |
683 | 702 | | |
684 | 703 | | |
685 | 704 | | |
| |||
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
0 commit comments