Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import {
remoteConfig,
remoteConfigRevision
} from '@/platform/remoteConfig/remoteConfig'
import type { RemoteConfig } from '@/platform/remoteConfig/types'
import { useTelemetry } from '@/platform/telemetry'
import { getDevOverride } from '@/utils/devFeatureFlagOverride'
import { getSessionOverride } from '@/utils/sessionFeatureFlagOverride'

import { useFreeUsePlacement } from './freeUsePlacement'
import {
FREE_USE_PLACEMENT_FLAG,
useFreeUsePlacement
} from './freeUsePlacement'

vi.mock(import('@/platform/remoteConfig/remoteConfig'))
vi.mock(import('@/platform/telemetry'))
Expand Down Expand Up @@ -39,15 +43,32 @@ describe('useFreeUsePlacement', () => {
})
})

it.for([undefined, 'unknown'])('keeps control for %s', async (value) => {
Reflect.set(remoteConfig.value, 'agent-free-use-message-placement', value)
it('keeps control when the flag is absent', () => {
remoteConfig.value = {}
authenticatedRemoteConfigState.value = 'authenticated'
const { variant } = useFreeUsePlacement()

expect(variant.value).toBe('control')
expect(useTelemetry()?.trackAgentFreeUseExposure).toHaveBeenCalledWith({
placement: 'control',
[`$feature/${FREE_USE_PLACEMENT_FLAG}`]: 'control'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: Building the expected telemetry key from FREE_USE_PLACEMENT_FLAG computes the expectation with the same value production uses, which testing-principles.md asks us to avoid ("Expected values are literal"). If the constant changes, the PostHog $feature/... key changes with it and these two cases still pass. Only the first case's literal would catch it. Could both use the literal '$feature/agent-free-use-message-placement', as the first case does? The same applies at line 71.

})
})

it('keeps control for an unknown flag value', () => {
const config: RemoteConfig = {}
Object.defineProperty(config, FREE_USE_PLACEMENT_FLAG, {
enumerable: true,
value: 'unknown'
})
remoteConfig.value = config
authenticatedRemoteConfigState.value = 'authenticated'
const { variant } = useFreeUsePlacement()

expect(variant.value).toBe('control')
expect(useTelemetry()?.trackAgentFreeUseExposure).toHaveBeenCalledWith({
placement: 'control',
'$feature/agent-free-use-message-placement': 'control'
[`$feature/${FREE_USE_PLACEMENT_FLAG}`]: 'control'
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { AgentFreeUsePlacement } from '@/platform/telemetry/types'
import { getDevOverride } from '@/utils/devFeatureFlagOverride'
import { getSessionOverride } from '@/utils/sessionFeatureFlagOverride'

const FREE_USE_PLACEMENT_FLAG = 'agent-free-use-message-placement'
export const FREE_USE_PLACEMENT_FLAG = 'agent-free-use-message-placement'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit-pick (non-blocking): The test is the only importer of this export. Keeping the constant module-private, and writing the literal 'agent-free-use-message-placement' in the test as the first case already does, keeps the module's surface minimal and avoids the problem in the next comment.


export const FREE_USE_PLACEMENTS = [
'control',
Expand Down
Loading