Skip to content

Commit 78b3bec

Browse files
abueideclaude
andcommitted
fix: remove auto-flush wiring from SegmentDestination, add CDN validation tests
Remove autoFlushOnRetryReady check, setAutoFlushCallback call, and shutdown() method. Add tests for CDN integrations validation (null, array, string, and no-defaults scenarios). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1a62f18 commit 78b3bec

2 files changed

Lines changed: 63 additions & 10 deletions

File tree

packages/core/src/__tests__/internal/fetchSettings.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,69 @@ describe('internal #getSettings', () => {
436436
});
437437
});
438438

439+
describe('CDN integrations validation', () => {
440+
it('falls back to defaults when CDN returns null integrations', async () => {
441+
(fetch as jest.MockedFunction<typeof fetch>).mockResolvedValueOnce({
442+
ok: true,
443+
json: () => Promise.resolve({ integrations: null }),
444+
status: 200,
445+
} as Response);
446+
447+
const client = new SegmentClient(clientArgs);
448+
await client.fetchSettings();
449+
450+
expect(setSettingsSpy).toHaveBeenCalledWith(
451+
defaultIntegrationSettings.integrations
452+
);
453+
});
454+
455+
it('falls back to defaults when CDN returns integrations as an array', async () => {
456+
(fetch as jest.MockedFunction<typeof fetch>).mockResolvedValueOnce({
457+
ok: true,
458+
json: () => Promise.resolve({ integrations: ['invalid'] }),
459+
status: 200,
460+
} as Response);
461+
462+
const client = new SegmentClient(clientArgs);
463+
await client.fetchSettings();
464+
465+
expect(setSettingsSpy).toHaveBeenCalledWith(
466+
defaultIntegrationSettings.integrations
467+
);
468+
});
469+
470+
it('falls back to defaults when CDN returns integrations as a string', async () => {
471+
(fetch as jest.MockedFunction<typeof fetch>).mockResolvedValueOnce({
472+
ok: true,
473+
json: () => Promise.resolve({ integrations: 'invalid' }),
474+
status: 200,
475+
} as Response);
476+
477+
const client = new SegmentClient(clientArgs);
478+
await client.fetchSettings();
479+
480+
expect(setSettingsSpy).toHaveBeenCalledWith(
481+
defaultIntegrationSettings.integrations
482+
);
483+
});
484+
485+
it('does not set settings when CDN returns invalid integrations and no defaults', async () => {
486+
(fetch as jest.MockedFunction<typeof fetch>).mockResolvedValueOnce({
487+
ok: true,
488+
json: () => Promise.resolve({ integrations: null }),
489+
status: 200,
490+
} as Response);
491+
492+
const client = new SegmentClient({
493+
...clientArgs,
494+
config: { ...clientArgs.config, defaultSettings: undefined },
495+
});
496+
await client.fetchSettings();
497+
498+
expect(setSettingsSpy).not.toHaveBeenCalled();
499+
});
500+
});
501+
439502
describe('httpConfig extraction', () => {
440503
it('extracts httpConfig from CDN response and merges with defaults', async () => {
441504
const serverHttpConfig = {

packages/core/src/plugins/SegmentDestination.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,6 @@ export class SegmentDestination extends DestinationPlugin {
369369
this.analytics?.logger,
370370
config?.retryStrategy ?? 'lazy'
371371
);
372-
373-
if (config?.autoFlushOnRetryReady === true) {
374-
this.retryManager.setAutoFlushCallback(() => {
375-
void this.flush();
376-
});
377-
}
378372
}
379373
}
380374

@@ -390,8 +384,4 @@ export class SegmentDestination extends DestinationPlugin {
390384
// Wait until the queue is done restoring before flushing
391385
return this.queuePlugin.flush();
392386
}
393-
394-
shutdown(): void {
395-
this.retryManager?.destroy();
396-
}
397387
}

0 commit comments

Comments
 (0)