Skip to content

refactor: add Configuration.reset() static method#3649

Merged
B4nan merged 1 commit into
v4from
feat/configuration-reset
May 12, 2026
Merged

refactor: add Configuration.reset() static method#3649
B4nan merged 1 commit into
v4from
feat/configuration-reset

Conversation

@B4nan
Copy link
Copy Markdown
Member

@B4nan B4nan commented May 12, 2026

Summary

  • Adds Configuration.reset() as a discoverable static method on the new v4 Configuration class. Delegates to serviceLocator.reset() so the cached configuration, event manager, storage client, and logger are all dropped together.
  • Adds a test verifying that after Configuration.reset(), the next Configuration.getGlobalConfig() re-reads process.env.

Motivation

v4 Configuration resolves env vars eagerly at construction, so tests that mutate process.env after the global singleton has been resolved need a way to drop the cached instance. Today that's either serviceLocator.reset() (works, but the name suggests "service tree" rather than "the config I just changed env vars for") or reaching into the private Configuration.globalConfig via type assertions (currently happening across multiple test files in apify-sdk-js).

A class-side Configuration.reset() makes the intent obvious from the call site and lives next to Configuration.getGlobalConfig() in autocomplete. The implementation just delegates to serviceLocator.reset() rather than resetting only the configuration — resetting only the config would leave a stale EventManager / StorageClient / logger holding the old config, which is the wrong contract for callers wanting to "start fresh".

Test plan

  • vitest run packages/core/test/core/configuration.test.ts -t "reset"

🤖 Generated with Claude Code

Tests that mutate `process.env` after the global Configuration has
been resolved currently have to bypass the public API and reach into
either `serviceLocator.reset()` (clears too much by name) or the
private `Configuration.globalConfig` field via type assertions. Add
`Configuration.reset()` as the discoverable, class-side equivalent —
it delegates to `serviceLocator.reset()` so the entire service tree
(configuration + event manager + storage client + logger) is dropped
together, which is what callers actually want (resetting only the
configuration would leave dependents holding the stale instance).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@B4nan B4nan changed the title feat(config): add Configuration.reset() static method refactor: add Configuration.reset() static method May 12, 2026
B4nan added a commit to apify/apify-sdk-js that referenced this pull request May 12, 2026
v4 `Configuration` resolves env vars eagerly at construction, so tests
that mutate `process.env` afterwards need to drop the cached singleton.
The previous pattern bypassed the public API and poked private static
state via type assertions, duplicated across multiple test files.

- `Configuration.reset()` clears the SDK's own `globalConfig` static
  *and* delegates to `serviceLocator.reset()` (matches the upcoming
  crawlee API in apify/crawlee#3649 — once published the SDK can
  swap the explicit `serviceLocator.reset()` call for `super.reset()`).
- `Actor.reset()` clears `Actor._instance` and calls
  `Configuration.reset()`. Tests use this single call instead of the
  three-step boilerplate.
- `utils.test.ts` and `actor.test.ts` updated; the awkward inline
  `(Configuration as unknown as { globalConfig?: ... })` /
  `(Actor as unknown as { _instance?: ... })` blocks are gone.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
B4nan added a commit to apify/apify-sdk-js that referenced this pull request May 12, 2026
v4 `Configuration` resolves env vars eagerly at construction, so tests
that mutate `process.env` afterwards need to drop the cached singleton.
The previous pattern bypassed the public API and poked private static
state via type assertions, duplicated across multiple test files.

- `Configuration.reset()` clears the SDK's own `globalConfig` static
  *and* delegates to `serviceLocator.reset()` (matches the upcoming
  crawlee API in apify/crawlee#3649 — once published the SDK can
  swap the explicit `serviceLocator.reset()` call for `super.reset()`).
- `Actor.reset()` clears `Actor._instance` and calls
  `Configuration.reset()`. Tests use this single call instead of the
  three-step boilerplate.
- `utils.test.ts` and `actor.test.ts` updated; the awkward inline
  `(Configuration as unknown as { globalConfig?: ... })` /
  `(Actor as unknown as { _instance?: ... })` blocks are gone.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@B4nan B4nan merged commit d633c8b into v4 May 12, 2026
7 checks passed
@B4nan B4nan deleted the feat/configuration-reset branch May 12, 2026 14:31
B4nan added a commit to apify/apify-sdk-js that referenced this pull request May 12, 2026
…uration

crawlee 4.0.0-beta.56 ships `Configuration.reset()` (apify/crawlee#3649),
so the SDK's override can delegate to `super.reset()` instead of calling
`serviceLocator.reset()` directly. The SDK still owns clearing its own
`globalConfig` static and replacing the `AsyncLocalStorage` singleton.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants