Skip to content

Commit 73798bd

Browse files
Sync public snapshot from freebuff-private
Source: CodebuffAI/freebuff-private@edb7a157a437b973fdb99ff693be92bdcc672153
1 parent 15a12bc commit 73798bd

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

bun.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/util/__tests__/ad-experiment.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
IMPREZIA_EXPERIMENT_PERCENT,
77
adExperimentArmForUser,
88
firstPartyAdRouteForUser,
9+
isImpreziaAudienceEmail,
910
} from '../ad-experiment'
1011

1112
describe('imprezia experiment arm', () => {
@@ -36,6 +37,19 @@ describe('imprezia experiment arm', () => {
3637
expect(percent).toBeGreaterThan(IMPREZIA_EXPERIMENT_PERCENT - 1.5)
3738
expect(percent).toBeLessThan(IMPREZIA_EXPERIMENT_PERCENT + 1.5)
3839
})
40+
41+
test('forces only the Imprezia domain and named test account', () => {
42+
for (const email of ['dev@Imprezia.AI', 'jahooma@gmail.com']) {
43+
expect(isImpreziaAudienceEmail(email)).toBe(true)
44+
expect(adExperimentArmForUser('user', email)).toBe('imprezia_forced')
45+
}
46+
for (const email of [
47+
'dev@imprezia.ai.evil.com',
48+
'jahooma+test@gmail.com',
49+
]) {
50+
expect(isImpreziaAudienceEmail(email)).toBe(false)
51+
}
52+
})
3953
})
4054

4155
describe('first-party request routing', () => {

common/src/util/ad-experiment.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* Which ad network gets first refusal on a sponsored slot.
33
*
4-
* Imprezia reaches users two different ways, and the whole point of this
5-
* module is that the two stay tellable apart:
4+
* Imprezia reaches users three ways, and this module keeps them tellable apart:
65
*
6+
* - Exclusively for the Imprezia team and our test account.
77
* - As the PRIMARY for a random {@link IMPREZIA_EXPERIMENT_PERCENT}% of users.
88
* This is the experiment arm — a clean random subset whose revenue can be
99
* compared against control.
@@ -52,7 +52,17 @@ export interface FirstPartyRoutingConfig {
5252
backfill: boolean
5353
}
5454

55-
export type AdExperimentArm = 'imprezia_first' | 'control'
55+
export type AdExperimentArm = 'imprezia_forced' | 'imprezia_first' | 'control'
56+
57+
export function isImpreziaAudienceEmail(
58+
email: string | null | undefined,
59+
): boolean {
60+
if (!email) return false
61+
const normalized = email.trim().toLowerCase()
62+
return (
63+
normalized === 'jahooma@gmail.com' || normalized.endsWith('@imprezia.ai')
64+
)
65+
}
5666

5767
/** FNV-1a 32-bit: tiny, dependency-free, stable across runtimes. */
5868
export function fnv1a(input: string): number {
@@ -65,17 +75,19 @@ export function fnv1a(input: string): number {
6575
}
6676

6777
/**
68-
* Deterministic arm for a signed-in user. Stable across devices, sessions and
69-
* products, because it is a pure function of the user id.
78+
* Deterministic arm for a signed-in user, stable across products and sessions.
7079
*/
7180
export function adExperimentArmForUser(
7281
userId: string | null | undefined,
82+
userEmail?: string | null,
7383
): AdExperimentArm {
7484
// Every ad surface rejects unauthenticated callers, so a missing id means no
7585
// ad is served at all. Park those in control rather than letting them dilute
7686
// the arm with impressions that never happened.
7787
if (!userId) return 'control'
7888

89+
if (isImpreziaAudienceEmail(userEmail)) return 'imprezia_forced'
90+
7991
const bucket = fnv1a(`${IMPREZIA_EXPERIMENT}:${userId}`) % 100
8092
return bucket < IMPREZIA_EXPERIMENT_PERCENT ? 'imprezia_first' : 'control'
8193
}

0 commit comments

Comments
 (0)