Skip to content

Commit 309f565

Browse files
committed
updates
1 parent 112bddb commit 309f565

3 files changed

Lines changed: 11 additions & 28 deletions

File tree

lib/message/error_message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const INVALID_CMAB_FETCH_RESPONSE = 'Invalid CMAB fetch response';
100100
export const PROMISE_NOT_ALLOWED = "Promise value is not allowed in sync operation";
101101
export const SERVICE_NOT_RUNNING = "%s not running";
102102
export const EVENT_STORE_FULL = 'Event store is full. Not saving event with id %d.';
103+
export const LOCAL_HOLDOUT_MISSING_INCLUDED_RULES = 'Local holdout "%s" is missing or has empty "includedRules"; skipping.';
103104

104105
export const messages: string[] = [];
105106

lib/project_config/project_config.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
UNEXPECTED_RESERVED_ATTRIBUTE_PREFIX,
2222
UNRECOGNIZED_ATTRIBUTE,
2323
VARIABLE_KEY_NOT_IN_DATAFILE,
24+
LOCAL_HOLDOUT_MISSING_INCLUDED_RULES,
2425
} from 'error_message';
2526
import { Mock, afterAll, afterEach, assert, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
2627
import { OptimizelyError } from '../error/optimizly_error';
@@ -643,7 +644,7 @@ describe('createProjectConfig - localHoldouts section (FSSDK-12760)', () => {
643644
expect(getHoldoutsForRule(config, 'any_rule')).toEqual([]);
644645
expect(config.holdoutIdMap!['bad']).toBeUndefined();
645646
expect(logger.error).toHaveBeenCalledWith(
646-
expect.stringMatching(/invalid_local.*includedRules/i)
647+
LOCAL_HOLDOUT_MISSING_INCLUDED_RULES, 'invalid_local'
647648
);
648649
});
649650

@@ -657,7 +658,7 @@ describe('createProjectConfig - localHoldouts section (FSSDK-12760)', () => {
657658
expect(getHoldoutsForRule(config, 'any_rule')).toEqual([]);
658659
expect(config.holdoutIdMap!['bad_null']).toBeUndefined();
659660
expect(logger.error).toHaveBeenCalledWith(
660-
expect.stringMatching(/null_local.*includedRules/i)
661+
LOCAL_HOLDOUT_MISSING_INCLUDED_RULES, 'null_local'
661662
);
662663
});
663664

@@ -671,7 +672,7 @@ describe('createProjectConfig - localHoldouts section (FSSDK-12760)', () => {
671672
expect(getHoldoutsForRule(config, 'any_rule')).toEqual([]);
672673
expect(config.holdoutIdMap!['bad_empty']).toBeUndefined();
673674
expect(logger.error).toHaveBeenCalledWith(
674-
expect.stringMatching(/empty_local.*includedRules/i)
675+
LOCAL_HOLDOUT_MISSING_INCLUDED_RULES, 'empty_local'
675676
);
676677
});
677678

lib/project_config/project_config.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
UNRECOGNIZED_ATTRIBUTE,
5050
VARIABLE_KEY_NOT_IN_DATAFILE,
5151
VARIATION_ID_NOT_IN_DATAFILE,
52+
LOCAL_HOLDOUT_MISSING_INCLUDED_RULES,
5253
} from 'error_message';
5354
import { SKIPPING_JSON_VALIDATION, VALID_DATAFILE } from 'log_message';
5455
import { OptimizelyError } from '../error/optimizly_error';
@@ -118,20 +119,6 @@ export interface ProjectConfig {
118119
*/
119120
localHoldouts: Holdout[];
120121
holdoutIdMap?: { [id: string]: Holdout };
121-
holdoutConfig?: HoldoutConfig;
122-
}
123-
124-
/**
125-
* Holds pre-computed holdout lookup structures built during config parsing.
126-
* Stored as plain data (no methods) to be serializable and equality-safe.
127-
*
128-
* Scope is determined by datafile section membership: entries from the top-level
129-
* `holdouts` section are global; entries from the top-level `localHoldouts`
130-
* section are local (rule-scoped via `includedRules`).
131-
*/
132-
export interface HoldoutConfig {
133-
/** Holdouts parsed from the top-level `holdouts` datafile section (global). */
134-
global: Holdout[];
135122
/** Maps a rule ID to the local holdouts that target it. */
136123
ruleHoldoutsMap: { [ruleId: string]: Holdout[] };
137124
}
@@ -439,7 +426,7 @@ const parseHoldoutsConfig = (projectConfig: ProjectConfig, logger?: LoggerFacade
439426
projectConfig.holdouts = projectConfig.holdouts || [];
440427
projectConfig.localHoldouts = projectConfig.localHoldouts || [];
441428

442-
const global: Holdout[] = [];
429+
// const global: Holdout[] = [];
443430
const ruleHoldoutsMap: { [ruleId: string]: Holdout[] } = {};
444431
const holdoutIdMap: { [id: string]: Holdout } = {};
445432

@@ -462,7 +449,6 @@ const parseHoldoutsConfig = (projectConfig: ProjectConfig, logger?: LoggerFacade
462449
delete holdout.includedRules;
463450
holdout.isGlobal = true;
464451
holdoutIdMap[holdout.id] = holdout;
465-
global.push(holdout);
466452
});
467453

468454
// Process local holdouts: every entry must carry a non-empty `includedRules` list.
@@ -472,9 +458,7 @@ const parseHoldoutsConfig = (projectConfig: ProjectConfig, logger?: LoggerFacade
472458
projectConfig.localHoldouts.forEach((holdout) => {
473459
const includedRules = holdout.includedRules;
474460
if (!Array.isArray(includedRules) || includedRules.length === 0) {
475-
logger?.error(
476-
`Local holdout "${holdout.key || holdout.id}" is missing or has empty "includedRules"; skipping.`
477-
);
461+
logger?.error(LOCAL_HOLDOUT_MISSING_INCLUDED_RULES, holdout.key);
478462
return;
479463
}
480464

@@ -490,10 +474,7 @@ const parseHoldoutsConfig = (projectConfig: ProjectConfig, logger?: LoggerFacade
490474
});
491475

492476
projectConfig.holdoutIdMap = holdoutIdMap;
493-
projectConfig.holdoutConfig = {
494-
global,
495-
ruleHoldoutsMap,
496-
};
477+
projectConfig.ruleHoldoutsMap = ruleHoldoutsMap;
497478
}
498479

499480
/**
@@ -502,7 +483,7 @@ const parseHoldoutsConfig = (projectConfig: ProjectConfig, logger?: LoggerFacade
502483
* any `includedRules` field on these entries is ignored.
503484
*/
504485
export const getGlobalHoldouts = (projectConfig: ProjectConfig): Holdout[] => {
505-
return projectConfig.holdoutConfig?.global ?? [];
486+
return projectConfig.holdouts;
506487
};
507488

508489
/**
@@ -512,7 +493,7 @@ export const getGlobalHoldouts = (projectConfig: ProjectConfig): Holdout[] => {
512493
* are scoped per-rule via their `includedRules` field.
513494
*/
514495
export const getHoldoutsForRule = (projectConfig: ProjectConfig, ruleId: string): Holdout[] => {
515-
return projectConfig.holdoutConfig?.ruleHoldoutsMap[ruleId] ?? [];
496+
return projectConfig.ruleHoldoutsMap[ruleId] ?? [];
516497
};
517498

518499
/**

0 commit comments

Comments
 (0)