mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
feat(app): gate a collapsing guild header behind an experiment (#2779)
This commit is contained in:
@@ -35,6 +35,7 @@ import {BlockedMessageGroupsConfigSchema} from '@fluxer/schema/src/domains/exper
|
||||
import {ExperimentDeliveryConfigSchema} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
|
||||
import {ExpressionInfoCardConfigSchema} from '@fluxer/schema/src/domains/experiment/ExpressionInfoCardSchemas';
|
||||
import {GuildActivityLogPresentationConfigSchema} from '@fluxer/schema/src/domains/experiment/GuildActivityLogPresentationSchemas';
|
||||
import {GuildHeaderCollapseConfigSchema} from '@fluxer/schema/src/domains/experiment/GuildHeaderCollapseSchemas';
|
||||
import {MessageHoverTrackingConfigSchema} from '@fluxer/schema/src/domains/experiment/MessageHoverTrackingSchemas';
|
||||
import {MessageKeyboardFocusConfigSchema} from '@fluxer/schema/src/domains/experiment/MessageKeyboardFocusSchemas';
|
||||
import type {InstanceBranding} from '@fluxer/schema/src/domains/instance/InstanceSchemas';
|
||||
@@ -68,6 +69,7 @@ async function buildInstanceConfigResponse(): Promise<InstanceConfigResponse> {
|
||||
messageKeyboardFocus,
|
||||
blockedMessageGroups,
|
||||
expressionInfoCard,
|
||||
guildHeaderCollapse,
|
||||
registrationConfig,
|
||||
registrationUrls,
|
||||
pendingRegistrations,
|
||||
@@ -81,6 +83,7 @@ async function buildInstanceConfigResponse(): Promise<InstanceConfigResponse> {
|
||||
instanceConfigRepository.getMessageKeyboardFocusConfig(),
|
||||
instanceConfigRepository.getBlockedMessageGroupsConfig(),
|
||||
instanceConfigRepository.getExpressionInfoCardConfig(),
|
||||
instanceConfigRepository.getGuildHeaderCollapseConfig(),
|
||||
instanceConfigRepository.getRegistrationConfig(),
|
||||
instanceConfigRepository.getRegistrationUrlsForAdmin(),
|
||||
instanceConfigRepository.getPendingRegistrations(),
|
||||
@@ -117,6 +120,7 @@ async function buildInstanceConfigResponse(): Promise<InstanceConfigResponse> {
|
||||
message_keyboard_focus: messageKeyboardFocus,
|
||||
blocked_message_groups: blockedMessageGroups,
|
||||
expression_info_card: expressionInfoCard,
|
||||
guild_header_collapse: guildHeaderCollapse,
|
||||
registration: {
|
||||
...registrationConfig,
|
||||
urls: registrationUrls,
|
||||
@@ -321,6 +325,18 @@ export function InstanceConfigAdminController(app: HonoApp) {
|
||||
await instanceConfigRepository.setExpressionInfoCardConfig(validated);
|
||||
}
|
||||
}
|
||||
if (data.guild_header_collapse) {
|
||||
const patch = omitUndefinedFields(data.guild_header_collapse);
|
||||
if (Object.keys(patch).length > 0) {
|
||||
const currentGuildHeaderCollapse = await instanceConfigRepository.getGuildHeaderCollapseConfig();
|
||||
const validated = GuildHeaderCollapseConfigSchema.parse({
|
||||
...currentGuildHeaderCollapse,
|
||||
...patch,
|
||||
config_version: currentGuildHeaderCollapse.config_version + 1,
|
||||
});
|
||||
await instanceConfigRepository.setGuildHeaderCollapseConfig(validated);
|
||||
}
|
||||
}
|
||||
if (data.experiment_delivery) {
|
||||
const currentExperimentDelivery = await instanceConfigRepository.getExperimentDeliveryConfig();
|
||||
const validated = ExperimentDeliveryConfigSchema.parse({
|
||||
|
||||
@@ -13,6 +13,7 @@ import {resolveBlockedMessageGroupsAssignment} from '@fluxer/schema/src/domains/
|
||||
import {ExperimentAssignmentsResponse} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
|
||||
import {resolveExpressionInfoCardAssignment} from '@fluxer/schema/src/domains/experiment/ExpressionInfoCardSchemas';
|
||||
import {resolveGuildActivityLogPresentationAssignment} from '@fluxer/schema/src/domains/experiment/GuildActivityLogPresentationSchemas';
|
||||
import {resolveGuildHeaderCollapseAssignment} from '@fluxer/schema/src/domains/experiment/GuildHeaderCollapseSchemas';
|
||||
import {resolveMessageHoverTrackingAssignment} from '@fluxer/schema/src/domains/experiment/MessageHoverTrackingSchemas';
|
||||
import {resolveMessageKeyboardFocusAssignment} from '@fluxer/schema/src/domains/experiment/MessageKeyboardFocusSchemas';
|
||||
|
||||
@@ -41,6 +42,7 @@ export function ExperimentController(app: HonoApp) {
|
||||
blockedMessageGroupsConfig,
|
||||
guildActivityLogPresentationConfig,
|
||||
expressionInfoCardConfig,
|
||||
guildHeaderCollapseConfig,
|
||||
] = await Promise.all([
|
||||
instanceConfigRepository.getExperimentDeliveryConfig(),
|
||||
instanceConfigRepository.getVoiceNoiseSuppressionConfig(),
|
||||
@@ -49,6 +51,7 @@ export function ExperimentController(app: HonoApp) {
|
||||
instanceConfigRepository.getBlockedMessageGroupsConfig(),
|
||||
instanceConfigRepository.getGuildActivityLogPresentationConfig(),
|
||||
instanceConfigRepository.getExpressionInfoCardConfig(),
|
||||
instanceConfigRepository.getGuildHeaderCollapseConfig(),
|
||||
]);
|
||||
const userId = ctx.get('user').id.toString();
|
||||
const body: ExperimentAssignmentsResponse = {
|
||||
@@ -64,6 +67,7 @@ export function ExperimentController(app: HonoApp) {
|
||||
userId,
|
||||
),
|
||||
expression_info_card: resolveExpressionInfoCardAssignment(expressionInfoCardConfig, userId),
|
||||
guild_header_collapse: resolveGuildHeaderCollapseAssignment(guildHeaderCollapseConfig, userId),
|
||||
},
|
||||
};
|
||||
const etag = `"${createHash('sha256').update(JSON.stringify(body)).digest('hex')}"`;
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
readBlockedMessageGroupsAssignment,
|
||||
readExpressionInfoCardAssignment,
|
||||
readGuildActivityLogPresentationAssignment,
|
||||
readGuildHeaderCollapseAssignment,
|
||||
readMessageHoverTrackingAssignment,
|
||||
readMessageKeyboardFocusAssignment,
|
||||
readVoiceNoiseSuppressionAssignment,
|
||||
@@ -34,6 +35,10 @@ import {
|
||||
DEFAULT_GUILD_ACTIVITY_LOG_PRESENTATION_CONFIG,
|
||||
INERT_GUILD_ACTIVITY_LOG_PRESENTATION_ASSIGNMENT,
|
||||
} from '@fluxer/schema/src/domains/experiment/GuildActivityLogPresentationSchemas';
|
||||
import {
|
||||
DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG,
|
||||
INERT_GUILD_HEADER_COLLAPSE_ASSIGNMENT,
|
||||
} from '@fluxer/schema/src/domains/experiment/GuildHeaderCollapseSchemas';
|
||||
import {
|
||||
DEFAULT_MESSAGE_HOVER_TRACKING_CONFIG,
|
||||
INERT_MESSAGE_HOVER_TRACKING_ASSIGNMENT,
|
||||
@@ -81,6 +86,7 @@ describe('GET /experiments', () => {
|
||||
blocked_message_groups: INERT_BLOCKED_MESSAGE_GROUPS_ASSIGNMENT,
|
||||
guild_activity_log_presentation: INERT_GUILD_ACTIVITY_LOG_PRESENTATION_ASSIGNMENT,
|
||||
expression_info_card: INERT_EXPRESSION_INFO_CARD_ASSIGNMENT,
|
||||
guild_header_collapse: INERT_GUILD_HEADER_COLLAPSE_ASSIGNMENT,
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -364,7 +370,53 @@ describe('GET /experiments', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves all six experiments independently', async () => {
|
||||
it('populates the guild header collapse key even when the rollout is disabled', async () => {
|
||||
const account = await createTestAccount(harness);
|
||||
|
||||
const body = await createBuilder<ExperimentAssignmentsResponse>(harness, account.token).get(ENDPOINT).execute();
|
||||
|
||||
expect(Object.hasOwn(body.assignments, 'guild_header_collapse')).toBe(true);
|
||||
expect(readGuildHeaderCollapseAssignment(body)).toEqual(INERT_GUILD_HEADER_COLLAPSE_ASSIGNMENT);
|
||||
});
|
||||
|
||||
it('targets an allowlisted account for guild header collapse', async () => {
|
||||
const account = await createTestAccount(harness);
|
||||
await getInstanceConfigRepository().setGuildHeaderCollapseConfig({
|
||||
...DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG,
|
||||
enabled: true,
|
||||
config_version: 4,
|
||||
included_user_ids: [account.userId],
|
||||
});
|
||||
|
||||
const body = await createBuilder<ExperimentAssignmentsResponse>(harness, account.token).get(ENDPOINT).execute();
|
||||
|
||||
expect(readGuildHeaderCollapseAssignment(body)).toEqual({
|
||||
enabled: true,
|
||||
config_version: 4,
|
||||
user_targeted: true,
|
||||
source: 'user_rule',
|
||||
});
|
||||
});
|
||||
|
||||
it('leaves an account outside a zero-width guild header collapse rollout', async () => {
|
||||
const account = await createTestAccount(harness);
|
||||
await getInstanceConfigRepository().setGuildHeaderCollapseConfig({
|
||||
...DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG,
|
||||
enabled: true,
|
||||
config_version: 2,
|
||||
});
|
||||
|
||||
const body = await createBuilder<ExperimentAssignmentsResponse>(harness, account.token).get(ENDPOINT).execute();
|
||||
|
||||
expect(readGuildHeaderCollapseAssignment(body)).toEqual({
|
||||
enabled: true,
|
||||
config_version: 2,
|
||||
user_targeted: false,
|
||||
source: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves all seven experiments independently', async () => {
|
||||
const account = await createTestAccount(harness);
|
||||
await getInstanceConfigRepository().setMessageHoverTrackingConfig({
|
||||
...DEFAULT_MESSAGE_HOVER_TRACKING_CONFIG,
|
||||
@@ -391,6 +443,11 @@ describe('GET /experiments', () => {
|
||||
enabled: true,
|
||||
rollout_basis_points: 10000,
|
||||
});
|
||||
await getInstanceConfigRepository().setGuildHeaderCollapseConfig({
|
||||
...DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG,
|
||||
enabled: true,
|
||||
rollout_basis_points: 10000,
|
||||
});
|
||||
|
||||
const body = await createBuilder<ExperimentAssignmentsResponse>(harness, account.token).get(ENDPOINT).execute();
|
||||
|
||||
@@ -399,6 +456,7 @@ describe('GET /experiments', () => {
|
||||
expect(readBlockedMessageGroupsAssignment(body).user_targeted).toBe(true);
|
||||
expect(readGuildActivityLogPresentationAssignment(body).user_targeted).toBe(true);
|
||||
expect(readExpressionInfoCardAssignment(body).user_targeted).toBe(true);
|
||||
expect(readGuildHeaderCollapseAssignment(body).user_targeted).toBe(true);
|
||||
expect(readVoiceNoiseSuppressionAssignment(body).enabled).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@ import {
|
||||
DEFAULT_GUILD_ACTIVITY_LOG_PRESENTATION_CONFIG,
|
||||
type GuildActivityLogPresentationConfig,
|
||||
} from '@fluxer/schema/src/domains/experiment/GuildActivityLogPresentationSchemas';
|
||||
import {
|
||||
DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG,
|
||||
type GuildHeaderCollapseConfig,
|
||||
} from '@fluxer/schema/src/domains/experiment/GuildHeaderCollapseSchemas';
|
||||
import {
|
||||
DEFAULT_MESSAGE_HOVER_TRACKING_CONFIG,
|
||||
type MessageHoverTrackingConfig,
|
||||
@@ -45,6 +49,7 @@ const MESSAGE_KEYBOARD_FOCUS_CONFIG_KEY = 'message_keyboard_focus_config';
|
||||
const BLOCKED_MESSAGE_GROUPS_CONFIG_KEY = 'blocked_message_groups_config';
|
||||
const GUILD_ACTIVITY_LOG_PRESENTATION_CONFIG_KEY = 'guild_activity_log_presentation_config';
|
||||
const EXPRESSION_INFO_CARD_CONFIG_KEY = 'expression_info_card_config';
|
||||
const GUILD_HEADER_COLLAPSE_CONFIG_KEY = 'guild_header_collapse_config';
|
||||
const EXPERIMENT_DELIVERY_CONFIG_KEY = 'experiment_delivery_config';
|
||||
const APP_PUBLIC_CONFIG_KEY = 'app_public_config';
|
||||
const INSTANCE_POLICY_CONFIG_KEY = 'instance_policy_config';
|
||||
@@ -566,6 +571,70 @@ describe('InstanceConfigRepository', () => {
|
||||
await expect(repository.getExpressionInfoCardConfig()).resolves.toEqual(config);
|
||||
});
|
||||
|
||||
it('returns the default guild header collapse config when the key is absent', async () => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
const kvProvider = new MockKVProvider();
|
||||
const repository = createRepository(kvProvider);
|
||||
|
||||
await expect(repository.getGuildHeaderCollapseConfig()).resolves.toEqual(DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{name: 'unparseable text', stored: 'not-json'},
|
||||
{name: 'a json array', stored: '[]'},
|
||||
{name: 'out-of-range values', stored: '{"rollout_basis_points":99999}'},
|
||||
{name: 'a target that is not a snowflake', stored: '{"included_user_ids":["nope"]}'},
|
||||
])('falls back to the default guild header collapse config for $name', async ({stored}) => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
const kvProvider = new MockKVProvider();
|
||||
const repository = createRepository(kvProvider);
|
||||
|
||||
await repository.setConfig(GUILD_HEADER_COLLAPSE_CONFIG_KEY, stored);
|
||||
|
||||
await expect(repository.getGuildHeaderCollapseConfig()).resolves.toEqual(DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG);
|
||||
});
|
||||
|
||||
it('round-trips a stored guild header collapse config', async () => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
const kvProvider = new MockKVProvider();
|
||||
const repository = createRepository(kvProvider);
|
||||
|
||||
const config: GuildHeaderCollapseConfig = {
|
||||
...DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG,
|
||||
enabled: true,
|
||||
config_version: 5,
|
||||
rollout_basis_points: 1500,
|
||||
rollout_salt: 'guild-header-collapse-v2',
|
||||
included_user_ids: ['1400000000000000001'],
|
||||
excluded_user_ids: ['1400000000000000002'],
|
||||
};
|
||||
await repository.setGuildHeaderCollapseConfig(config);
|
||||
|
||||
await expect(repository.getGuildHeaderCollapseConfig()).resolves.toEqual(config);
|
||||
});
|
||||
|
||||
it('fills newly added guild header collapse fields from the schema defaults', async () => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
const kvProvider = new MockKVProvider();
|
||||
const repository = createRepository(kvProvider);
|
||||
|
||||
await repository.setConfig(
|
||||
GUILD_HEADER_COLLAPSE_CONFIG_KEY,
|
||||
JSON.stringify({enabled: true, config_version: 2, rollout_basis_points: 1000}),
|
||||
);
|
||||
|
||||
await expect(repository.getGuildHeaderCollapseConfig()).resolves.toEqual({
|
||||
...DEFAULT_GUILD_HEADER_COLLAPSE_CONFIG,
|
||||
enabled: true,
|
||||
config_version: 2,
|
||||
rollout_basis_points: 1000,
|
||||
});
|
||||
});
|
||||
|
||||
it('fills newly added voice noise suppression fields from the schema defaults', async () => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
|
||||
@@ -48,6 +48,10 @@ import {
|
||||
type GuildActivityLogPresentationConfig,
|
||||
GuildActivityLogPresentationConfigSchema,
|
||||
} from '@fluxer/schema/src/domains/experiment/GuildActivityLogPresentationSchemas';
|
||||
import {
|
||||
type GuildHeaderCollapseConfig,
|
||||
GuildHeaderCollapseConfigSchema,
|
||||
} from '@fluxer/schema/src/domains/experiment/GuildHeaderCollapseSchemas';
|
||||
import {
|
||||
type MessageHoverTrackingConfig,
|
||||
MessageHoverTrackingConfigSchema,
|
||||
@@ -80,6 +84,7 @@ const MESSAGE_HOVER_TRACKING_CONFIG_KEY = 'message_hover_tracking_config';
|
||||
const MESSAGE_KEYBOARD_FOCUS_CONFIG_KEY = 'message_keyboard_focus_config';
|
||||
const BLOCKED_MESSAGE_GROUPS_CONFIG_KEY = 'blocked_message_groups_config';
|
||||
const EXPRESSION_INFO_CARD_CONFIG_KEY = 'expression_info_card_config';
|
||||
const GUILD_HEADER_COLLAPSE_CONFIG_KEY = 'guild_header_collapse_config';
|
||||
const REGISTRATION_CONFIG_KEY = 'registration_config';
|
||||
const REGISTRATION_URLS_KEY = 'registration_urls';
|
||||
const REGISTRATION_PENDING_APPROVALS_KEY = 'registration_pending_approvals';
|
||||
@@ -368,6 +373,7 @@ type StoredConfigSection =
|
||||
| 'message keyboard focus'
|
||||
| 'blocked message groups'
|
||||
| 'expression info card'
|
||||
| 'guild header collapse'
|
||||
| 'instance policy'
|
||||
| 'integrations'
|
||||
| 'media'
|
||||
@@ -529,6 +535,10 @@ function parseStoredExpressionInfoCardConfig(raw: string | null): ExpressionInfo
|
||||
return parseStoredConfigOrDefault(ExpressionInfoCardConfigSchema, raw, 'expression info card');
|
||||
}
|
||||
|
||||
function parseStoredGuildHeaderCollapseConfig(raw: string | null): GuildHeaderCollapseConfig {
|
||||
return parseStoredConfigOrDefault(GuildHeaderCollapseConfigSchema, raw, 'guild header collapse');
|
||||
}
|
||||
|
||||
function validateStoredCollection<T>(schema: z.ZodType<T>, value: unknown, section: StoredConfigSection): Array<T> {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error(`Stored ${section} configuration must be an array`);
|
||||
@@ -1053,6 +1063,7 @@ export class InstanceConfigRepository {
|
||||
parseStoredMessageKeyboardFocusConfig(snapshot.get(MESSAGE_KEYBOARD_FOCUS_CONFIG_KEY) ?? null);
|
||||
parseStoredBlockedMessageGroupsConfig(snapshot.get(BLOCKED_MESSAGE_GROUPS_CONFIG_KEY) ?? null);
|
||||
parseStoredExpressionInfoCardConfig(snapshot.get(EXPRESSION_INFO_CARD_CONFIG_KEY) ?? null);
|
||||
parseStoredGuildHeaderCollapseConfig(snapshot.get(GUILD_HEADER_COLLAPSE_CONFIG_KEY) ?? null);
|
||||
const policy = parseStoredInstancePolicyConfig(snapshot.get(INSTANCE_POLICY_CONFIG_KEY) ?? null);
|
||||
checkStoredConfig('registration', () =>
|
||||
parseStoredRegistrationConfig(snapshot.get(REGISTRATION_CONFIG_KEY) ?? null),
|
||||
@@ -1192,6 +1203,16 @@ export class InstanceConfigRepository {
|
||||
await this.setConfig(EXPRESSION_INFO_CARD_CONFIG_KEY, JSON.stringify(validated));
|
||||
}
|
||||
|
||||
async getGuildHeaderCollapseConfig(): Promise<GuildHeaderCollapseConfig> {
|
||||
const raw = await this.getConfig(GUILD_HEADER_COLLAPSE_CONFIG_KEY);
|
||||
return parseStoredGuildHeaderCollapseConfig(raw);
|
||||
}
|
||||
|
||||
async setGuildHeaderCollapseConfig(config: GuildHeaderCollapseConfig): Promise<void> {
|
||||
const validated = validateStoredConfig(GuildHeaderCollapseConfigSchema, config, 'guild header collapse');
|
||||
await this.setConfig(GUILD_HEADER_COLLAPSE_CONFIG_KEY, JSON.stringify(validated));
|
||||
}
|
||||
|
||||
async setExperimentDeliveryConfig(config: ExperimentDeliveryConfig): Promise<void> {
|
||||
const validated = validateStoredConfig(ExperimentDeliveryConfigSchema, config, 'experiment delivery');
|
||||
await this.setConfig(EXPERIMENT_DELIVERY_CONFIG_KEY, JSON.stringify(validated));
|
||||
|
||||
@@ -28319,7 +28319,8 @@
|
||||
"guild_activity_log_presentation": {
|
||||
"$ref": "#/components/schemas/GuildActivityLogPresentationAssignmentResponse"
|
||||
},
|
||||
"expression_info_card": {"$ref": "#/components/schemas/ExpressionInfoCardAssignmentResponse"}
|
||||
"expression_info_card": {"$ref": "#/components/schemas/ExpressionInfoCardAssignmentResponse"},
|
||||
"guild_header_collapse": {"$ref": "#/components/schemas/GuildHeaderCollapseAssignmentResponse"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -32074,6 +32075,17 @@
|
||||
"additionalProperties": false,
|
||||
"description": "Public presentation of the source guild of an expression"
|
||||
},
|
||||
"GuildHeaderCollapseAssignmentResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"enabled": {"type": "boolean"},
|
||||
"config_version": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
|
||||
"user_targeted": {"type": "boolean"},
|
||||
"source": {"anyOf": [{"type": "string", "enum": ["user_rule", "canary"]}, {"type": "null"}]}
|
||||
},
|
||||
"required": ["enabled", "config_version", "user_targeted", "source"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"ExpressionInfoCardAssignmentResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Reference in New Issue
Block a user