From 113adcdbb8ac6e965f65ad6edaa3483d1e01391b Mon Sep 17 00:00:00 2001 From: ekremney Date: Tue, 10 Mar 2026 12:26:14 +0100 Subject: [PATCH 1/2] feat(utils): export resetFetchContext and clearFetchCache from @adobe/fetch context The h1/h2 context created by @adobe/fetch has internal connection pooling and response caching. Exposing reset and clearCache allows consumers (especially tests using nock with fake timers) to properly isolate fetch state between test runs. Co-Authored-By: Claude Opus 4.6 --- packages/spacecat-shared-utils/src/adobe-fetch.js | 5 ++++- packages/spacecat-shared-utils/src/index.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/spacecat-shared-utils/src/adobe-fetch.js b/packages/spacecat-shared-utils/src/adobe-fetch.js index 5b90b601e..d13c33b02 100644 --- a/packages/spacecat-shared-utils/src/adobe-fetch.js +++ b/packages/spacecat-shared-utils/src/adobe-fetch.js @@ -11,4 +11,7 @@ */ import { context as h2, h1 } from '@adobe/fetch'; -export const { fetch } = process.env.HELIX_FETCH_FORCE_HTTP1 ? h1() : h2(); +const fetchContext = process.env.HELIX_FETCH_FORCE_HTTP1 ? h1() : h2(); +export const { + fetch, reset: resetFetchContext, clearCache: clearFetchCache, +} = fetchContext; diff --git a/packages/spacecat-shared-utils/src/index.js b/packages/spacecat-shared-utils/src/index.js index 64c623ec4..60b59ed51 100644 --- a/packages/spacecat-shared-utils/src/index.js +++ b/packages/spacecat-shared-utils/src/index.js @@ -83,7 +83,7 @@ export { s3Wrapper, getObjectFromKey } from './s3.js'; export { OPPORTUNITY_TYPES, DEFAULT_CPC_VALUE } from './constants.js'; -export { fetch } from './adobe-fetch.js'; +export { fetch, resetFetchContext, clearFetchCache } from './adobe-fetch.js'; export { tracingFetch, SPACECAT_USER_AGENT } from './tracing-fetch.js'; export { getHighFormViewsLowConversionMetrics, From 117a897d31f48acd55e82f491e32a50ffb616eea Mon Sep 17 00:00:00 2001 From: ekremney Date: Tue, 10 Mar 2026 12:36:45 +0100 Subject: [PATCH 2/2] fix(utils): add new exports to index test expected list Co-Authored-By: Claude Opus 4.6 --- packages/spacecat-shared-utils/test/index.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/spacecat-shared-utils/test/index.test.js b/packages/spacecat-shared-utils/test/index.test.js index c6a590d60..70cec92f0 100644 --- a/packages/spacecat-shared-utils/test/index.test.js +++ b/packages/spacecat-shared-utils/test/index.test.js @@ -41,6 +41,7 @@ describe('Index Exports', () => { 'ensureHttps', 'extractUrlsFromOpportunity', 'extractUrlsFromSuggestion', + 'clearFetchCache', 'fetch', 'formatAllowlistMessage', 'FORMS_AUDIT_INTERVAL', @@ -97,6 +98,7 @@ describe('Index Exports', () => { 'prettifyLogForwardingConfig', 'replacePlaceholders', 'resolveCanonicalUrl', + 'resetFetchContext', 'resolveCustomerSecretsName', 'resolveSecretsName', 's3Wrapper',