Skip to content

Conversation

greghuels
Copy link
Contributor

@greghuels greghuels commented Mar 11, 2025

Tests will pass after Eppo-exp/sdk-test-data#123 is merged

Fixes scenario where a bandit flag is assigned to a non-bandit variation. Instead of returning the programmatic default, we want to return the assigned variation when getBanditAction is called.

See also: Eppo-exp/sdk-test-data#123

@greghuels greghuels force-pushed the greg/FF-4105/no-bandit-flag-2 branch from 3881f2d to fe23022 Compare March 11, 2025 19:58
@greghuels greghuels marked this pull request as ready for review March 11, 2025 19:58
@greghuels greghuels changed the title fix: non-bandit variations return programmatic default in getBanditAc… fix: fix: non-bandit flags return string assignment Mar 11, 2025
@greghuels greghuels changed the title fix: fix: non-bandit flags return string assignment fix: non-bandit flags return string assignment Mar 11, 2025
@greghuels greghuels force-pushed the greg/FF-4105/no-bandit-flag-2 branch 2 times, most recently from e3c041a to 43078e9 Compare March 11, 2025 20:19
@greghuels greghuels force-pushed the greg/FF-4105/no-bandit-flag-2 branch from 43078e9 to 264202c Compare March 11, 2025 20:30
Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as-is although it would be nice to have a couple more test cases:

  • bandit happy path
  • non-bandit variation in flag with a bandit variation/allocation

expect(precomputedConfiguration).toEqual({ action: null, variation: 'nike' });
});

it('should return the assigned variation if a flag is not a bandit', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌


it('should return the assigned variation if a flag is not a bandit', () => {
const precomputedConfiguration = client.getBanditAction('not-a-bandit-flag', 'default');
expect(precomputedConfiguration).toEqual({ action: null, variation: 'control' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also consider a situation where a flag IS a bandit flag, but they got assigned a non-bandit variation.

Also we should be using mocks to make sure the proper event loggers are called or not

Copy link
Contributor Author

@greghuels greghuels Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also consider a situation where a flag IS a bandit flag, but they got assigned a non-bandit variation.

For the precomputed response, wouldn't that be the same situation? The flag would be in flags but not in bandits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we should be using mocks to make sure the proper event loggers are called or not

Updated! And I also added the happy path case of a bandit flag with a bandit variation

const precomputedFlag = this.getPrecomputedFlag(flagKey);
if (!precomputedFlag) {
logger.warn(`${loggerPrefix} No assigned variation. Flag not found: ${flagKey}`);
return { variation: defaultValue, action: null };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning this if the precomputed flag is not found, otherwise returning the precomputed flag assignment if the bandit could not be evaluated. Makes sense

@greghuels greghuels force-pushed the greg/FF-4105/no-bandit-flag-2 branch from a83d1e1 to 7dbd361 Compare March 11, 2025 21:19
} catch (error) {
logger.error(`${loggerPrefix} Error logging bandit action: ${error}`);
}
return { variation: assignedVariation, action: banditEvent.action };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning the banditEvent.action is interesting here. Are you counting on it being undefined | null? If so please return that directly - or is it preforming randomization in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we ax this line all together, just keeping that final return with optional chaining and null coalesce:

return { variation: assignedVariation, action: banditEvent?.action ?? null }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry banditEvaluation.action

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good I misread it ✅

@greghuels greghuels merged commit 9dfebeb into main Mar 11, 2025
8 checks passed
@greghuels greghuels deleted the greg/FF-4105/no-bandit-flag-2 branch March 11, 2025 21:21
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.

4 participants