Skip to content
This repository was archived by the owner on Oct 14, 2026. It is now read-only.

Commit 81713e7

Browse files
jindaliiitaclaude
andcommitted
fix(tokowaka-client): fold blocked back into edgeOptimizeEnabled
Reverts the previous commit's raw-signal approach per explicit direction: edgeOptimizeEnabled should reflect both routing AND WAF status, accepting that persistEdgeConfig's routingEnabled stamping in spacecat-import-worker will not fire for a routing-confirmed-but- WAF-blocked site until that job is separately updated to read routing and WAF as independent signals. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 0f3380e commit 81713e7

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

‎packages/spacecat-shared-tokowaka-client/src/index.js‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,14 +1345,17 @@ class TokowakaClient {
13451345
* Fetches the customer's own domain directly (no proxy) and checks the response for
13461346
* BOTH the routing signal (x-tokowaka-request-id / x-edgeoptimize-request-id header)
13471347
* and a WAF/bot-block (via classifyProbeResponse, on the same fetched response — no
1348-
* second request).
1348+
* second request). `edgeOptimizeEnabled` folds both together: it is only `true` when
1349+
* the request-id header is present AND the response isn't classified as blocked —
1350+
* routing alone is not sufficient.
13491351
*
1350-
* `edgeOptimizeEnabled` is still the raw routing signal only (unchanged from before —
1351-
* `blocked` does NOT factor into it yet), to stay fully backward compatible with
1352-
* existing consumers (e.g. the import-worker's routingEnabled stamping). `blocked`/
1353-
* `statusCode` are returned (and logged) purely for visibility for now; consuming them
1354-
* on the frontend, and eventually retiring the separate checkWafConnectivity call in
1355-
* favor of this, is follow-up work.
1352+
* NOTE: this changes what `edgeOptimizeEnabled` means for existing consumers. The
1353+
* import-worker's `persistEdgeConfig` stamps `routingEnabled` based on this value
1354+
* (via `isEdgeLive`) — a site with routing confirmed but WAF-blocked will now get
1355+
* `edgeOptimizeEnabled: false`, and so will NOT have `routingEnabled` stamped until
1356+
* it clears the WAF block. This is an accepted, intentional tradeoff for now, pending
1357+
* a follow-up update to the import-worker job to read routing and WAF status as
1358+
* separate signals if that gap needs closing sooner.
13561359
*
13571360
* @param {Object} site - Site entity
13581361
* @param {string} path - Path to check (e.g., '/products/chair')
@@ -1412,15 +1415,12 @@ class TokowakaClient {
14121415
this.log.info(`[edge-optimize-status] Edge optimize headers found: ${requestIdPresent} for ${targetUrl}`);
14131416

14141417
// Classify the same response already fetched above for a WAF/bot-block — no second
1415-
// request. Logged/returned for visibility only for now — edgeOptimizeEnabled stays
1416-
// the raw routing signal (does NOT fold in `blocked` yet) so this stays fully
1417-
// backward compatible: persistEdgeConfig's routingEnabled stamping (and everything
1418-
// downstream of it) is untouched. Consuming `blocked`/`statusCode` on the frontend,
1419-
// and eventually retiring the separate checkWafConnectivity call, is follow-up work.
1418+
// request. edgeOptimizeEnabled folds both signals together: routing alone isn't
1419+
// enough if the customer's own WAF is blocking us.
14201420
// eslint-disable-next-line no-await-in-loop
14211421
const { blocked, statusCode } = await classifyProbeResponse(response, targetHost, this.log);
14221422
this.log.info(`[edge-optimize-status] WAF classification for ${targetUrl}: blocked=${blocked}, statusCode=${statusCode}`);
1423-
const edgeOptimizeEnabled = requestIdPresent;
1423+
const edgeOptimizeEnabled = requestIdPresent && !blocked;
14241424

14251425
return {
14261426
edgeOptimizeEnabled,

‎packages/spacecat-shared-tokowaka-client/test/index.test.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5783,7 +5783,7 @@ describe('TokowakaClient', () => {
57835783
});
57845784
});
57855785

5786-
describe('WAF classification alongside routing check (logged/returned, not gating yet)', () => {
5786+
describe('WAF classification merged into routing check', () => {
57875787
let site;
57885788

57895789
beforeEach(() => {
@@ -5795,7 +5795,7 @@ describe('TokowakaClient', () => {
57955795
};
57965796
});
57975797

5798-
it('routing confirmed but hard-blocked (403) → edgeOptimizeEnabled stays true (raw routing signal), blocked: true reported separately', async () => {
5798+
it('routing confirmed but hard-blocked (403) → edgeOptimizeEnabled: false, blocked: true', async () => {
57995799
const headersMap = new Map([
58005800
['x-tokowaka-request-id', 'abc123'],
58015801
]);
@@ -5809,13 +5809,13 @@ describe('TokowakaClient', () => {
58095809
const result = await esmockClient.checkEdgeOptimizeStatus(site, '/');
58105810

58115811
expect(result).to.deep.equal({
5812-
edgeOptimizeEnabled: true,
5812+
edgeOptimizeEnabled: false,
58135813
blocked: true,
58145814
statusCode: 403,
58155815
});
58165816
});
58175817

5818-
it('routing confirmed but soft-blocked (challenge page body) → edgeOptimizeEnabled stays true (raw routing signal), blocked: true reported separately', async () => {
5818+
it('routing confirmed but soft-blocked (challenge page body) → edgeOptimizeEnabled: false, blocked: true', async () => {
58195819
const headersMap = new Map([
58205820
['x-tokowaka-request-id', 'abc123'],
58215821
['content-type', 'text/html'],
@@ -5831,7 +5831,7 @@ describe('TokowakaClient', () => {
58315831
const result = await esmockClient.checkEdgeOptimizeStatus(site, '/');
58325832

58335833
expect(result).to.deep.equal({
5834-
edgeOptimizeEnabled: true,
5834+
edgeOptimizeEnabled: false,
58355835
blocked: true,
58365836
statusCode: 200,
58375837
});

0 commit comments

Comments
 (0)