From a761452885408c433ea32c2db5318ebec9f2b847 Mon Sep 17 00:00:00 2001 From: The Daijin <6650280+totamarusenku@users.noreply.github.com> Date: Wed, 22 Apr 2026 02:43:05 +0530 Subject: [PATCH 1/5] fix(#701): turn off telemetry by default on self-hosted instances --- src/defaults/settings.test.ts | 16 ++++++++++++++++ src/defaults/settings.ts | 9 ++++++++- src/lib/posthog.tsx | 3 ++- src/settings/preferences.tsx | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/defaults/settings.test.ts diff --git a/src/defaults/settings.test.ts b/src/defaults/settings.test.ts new file mode 100644 index 000000000..a9d148c52 --- /dev/null +++ b/src/defaults/settings.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from 'bun:test' +import { getDefaultDataCollectionValue } from './settings' + +describe('getDefaultDataCollectionValue', () => { + it('returns false for oidc mode (self-hosted)', () => { + expect(getDefaultDataCollectionValue('oidc')).toBe(false) + }) + + it('returns true for consumer mode', () => { + expect(getDefaultDataCollectionValue('consumer')).toBe(true) + }) + + it('defaults to true when mode is missing', () => { + expect(getDefaultDataCollectionValue()).toBe(true) + }) +}) diff --git a/src/defaults/settings.ts b/src/defaults/settings.ts index 07b2121e7..8c592493f 100644 --- a/src/defaults/settings.ts +++ b/src/defaults/settings.ts @@ -4,6 +4,13 @@ import type { InferSelectModel } from 'drizzle-orm' export type Setting = InferSelectModel +/** + * Data collection default: + * - consumer mode: enabled by default + * - oidc mode (self-hosted/enterprise): disabled by default + */ +export const getDefaultDataCollectionValue = (authMode?: string): boolean => authMode !== 'oidc' + /** * Compute hash of user-editable fields for a setting */ @@ -24,7 +31,7 @@ export const hashSetting = (setting: Setting): string => { export const defaultSettingDataCollection: Setting = { key: 'data_collection', - value: 'true', + value: String(getDefaultDataCollectionValue(import.meta.env.VITE_AUTH_MODE)), updatedAt: null, defaultHash: null, userId: null, diff --git a/src/lib/posthog.tsx b/src/lib/posthog.tsx index f81af8292..6b63e3621 100644 --- a/src/lib/posthog.tsx +++ b/src/lib/posthog.tsx @@ -1,6 +1,7 @@ import { type HttpClient } from '@/contexts' import { getSettings } from '@/dal' import { getDb } from '@/db/database' +import { getDefaultDataCollectionValue } from '@/defaults/settings' import { createHandleError } from '@/lib/error-utils' import { createClient } from '@/lib/http' import type { HandleError, HandleResult } from '@/types/handle-errors' @@ -52,7 +53,7 @@ export const initPosthog = async (httpClient?: HttpClient): Promise Date: Tue, 28 Apr 2026 03:21:16 +0530 Subject: [PATCH 2/5] refactor(#701): reuse auth mode helper for telemetry default - centralize data collection default on isOidcMode - update default helper tests to mock the auth mode utility --- src/defaults/settings.test.ts | 21 +++++++++++++-------- src/defaults/settings.ts | 5 +++-- src/lib/posthog.tsx | 2 +- src/settings/preferences.tsx | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/defaults/settings.test.ts b/src/defaults/settings.test.ts index a9d148c52..99e235035 100644 --- a/src/defaults/settings.test.ts +++ b/src/defaults/settings.test.ts @@ -1,16 +1,21 @@ -import { describe, expect, it } from 'bun:test' +import { describe, expect, it, mock } from 'bun:test' + +// Mock isOidcMode before importing settings +const mockIsOidcMode = mock(() => false) +mock.module('@/lib/auth-mode', () => ({ + isOidcMode: mockIsOidcMode, +})) + import { getDefaultDataCollectionValue } from './settings' describe('getDefaultDataCollectionValue', () => { - it('returns false for oidc mode (self-hosted)', () => { - expect(getDefaultDataCollectionValue('oidc')).toBe(false) - }) - - it('returns true for consumer mode', () => { - expect(getDefaultDataCollectionValue('consumer')).toBe(true) + it('returns false when isOidcMode is true', () => { + mockIsOidcMode.mockReturnValue(true) + expect(getDefaultDataCollectionValue()).toBe(false) }) - it('defaults to true when mode is missing', () => { + it('returns true when isOidcMode is false', () => { + mockIsOidcMode.mockReturnValue(false) expect(getDefaultDataCollectionValue()).toBe(true) }) }) diff --git a/src/defaults/settings.ts b/src/defaults/settings.ts index 8c592493f..7d076d860 100644 --- a/src/defaults/settings.ts +++ b/src/defaults/settings.ts @@ -1,3 +1,4 @@ +import { isOidcMode } from '@/lib/auth-mode' import type { settingsTable } from '@/db/tables' import { hashValues } from '@/lib/utils' import type { InferSelectModel } from 'drizzle-orm' @@ -9,7 +10,7 @@ export type Setting = InferSelectModel * - consumer mode: enabled by default * - oidc mode (self-hosted/enterprise): disabled by default */ -export const getDefaultDataCollectionValue = (authMode?: string): boolean => authMode !== 'oidc' +export const getDefaultDataCollectionValue = (): boolean => !isOidcMode() /** * Compute hash of user-editable fields for a setting @@ -31,7 +32,7 @@ export const hashSetting = (setting: Setting): string => { export const defaultSettingDataCollection: Setting = { key: 'data_collection', - value: String(getDefaultDataCollectionValue(import.meta.env.VITE_AUTH_MODE)), + value: String(getDefaultDataCollectionValue()), updatedAt: null, defaultHash: null, userId: null, diff --git a/src/lib/posthog.tsx b/src/lib/posthog.tsx index 6b63e3621..2b918f1b8 100644 --- a/src/lib/posthog.tsx +++ b/src/lib/posthog.tsx @@ -53,7 +53,7 @@ export const initPosthog = async (httpClient?: HttpClient): Promise Date: Wed, 22 Apr 2026 02:43:05 +0530 Subject: [PATCH 3/5] fix(#701): turn off telemetry by default on self-hosted instances --- src/defaults/settings.test.ts | 16 ++++++++++++++++ src/defaults/settings.ts | 9 ++++++++- src/lib/posthog.tsx | 3 ++- src/settings/preferences.tsx | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/defaults/settings.test.ts diff --git a/src/defaults/settings.test.ts b/src/defaults/settings.test.ts new file mode 100644 index 000000000..a9d148c52 --- /dev/null +++ b/src/defaults/settings.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from 'bun:test' +import { getDefaultDataCollectionValue } from './settings' + +describe('getDefaultDataCollectionValue', () => { + it('returns false for oidc mode (self-hosted)', () => { + expect(getDefaultDataCollectionValue('oidc')).toBe(false) + }) + + it('returns true for consumer mode', () => { + expect(getDefaultDataCollectionValue('consumer')).toBe(true) + }) + + it('defaults to true when mode is missing', () => { + expect(getDefaultDataCollectionValue()).toBe(true) + }) +}) diff --git a/src/defaults/settings.ts b/src/defaults/settings.ts index 07b2121e7..8c592493f 100644 --- a/src/defaults/settings.ts +++ b/src/defaults/settings.ts @@ -4,6 +4,13 @@ import type { InferSelectModel } from 'drizzle-orm' export type Setting = InferSelectModel +/** + * Data collection default: + * - consumer mode: enabled by default + * - oidc mode (self-hosted/enterprise): disabled by default + */ +export const getDefaultDataCollectionValue = (authMode?: string): boolean => authMode !== 'oidc' + /** * Compute hash of user-editable fields for a setting */ @@ -24,7 +31,7 @@ export const hashSetting = (setting: Setting): string => { export const defaultSettingDataCollection: Setting = { key: 'data_collection', - value: 'true', + value: String(getDefaultDataCollectionValue(import.meta.env.VITE_AUTH_MODE)), updatedAt: null, defaultHash: null, userId: null, diff --git a/src/lib/posthog.tsx b/src/lib/posthog.tsx index f81af8292..6b63e3621 100644 --- a/src/lib/posthog.tsx +++ b/src/lib/posthog.tsx @@ -1,6 +1,7 @@ import { type HttpClient } from '@/contexts' import { getSettings } from '@/dal' import { getDb } from '@/db/database' +import { getDefaultDataCollectionValue } from '@/defaults/settings' import { createHandleError } from '@/lib/error-utils' import { createClient } from '@/lib/http' import type { HandleError, HandleResult } from '@/types/handle-errors' @@ -52,7 +53,7 @@ export const initPosthog = async (httpClient?: HttpClient): Promise Date: Tue, 28 Apr 2026 03:21:16 +0530 Subject: [PATCH 4/5] refactor(#701): reuse auth mode helper for telemetry default - centralize data collection default on isOidcMode - update default helper tests to mock the auth mode utility --- src/defaults/settings.test.ts | 21 +++++++++++++-------- src/defaults/settings.ts | 5 +++-- src/lib/posthog.tsx | 2 +- src/settings/preferences.tsx | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/defaults/settings.test.ts b/src/defaults/settings.test.ts index a9d148c52..99e235035 100644 --- a/src/defaults/settings.test.ts +++ b/src/defaults/settings.test.ts @@ -1,16 +1,21 @@ -import { describe, expect, it } from 'bun:test' +import { describe, expect, it, mock } from 'bun:test' + +// Mock isOidcMode before importing settings +const mockIsOidcMode = mock(() => false) +mock.module('@/lib/auth-mode', () => ({ + isOidcMode: mockIsOidcMode, +})) + import { getDefaultDataCollectionValue } from './settings' describe('getDefaultDataCollectionValue', () => { - it('returns false for oidc mode (self-hosted)', () => { - expect(getDefaultDataCollectionValue('oidc')).toBe(false) - }) - - it('returns true for consumer mode', () => { - expect(getDefaultDataCollectionValue('consumer')).toBe(true) + it('returns false when isOidcMode is true', () => { + mockIsOidcMode.mockReturnValue(true) + expect(getDefaultDataCollectionValue()).toBe(false) }) - it('defaults to true when mode is missing', () => { + it('returns true when isOidcMode is false', () => { + mockIsOidcMode.mockReturnValue(false) expect(getDefaultDataCollectionValue()).toBe(true) }) }) diff --git a/src/defaults/settings.ts b/src/defaults/settings.ts index 8c592493f..7d076d860 100644 --- a/src/defaults/settings.ts +++ b/src/defaults/settings.ts @@ -1,3 +1,4 @@ +import { isOidcMode } from '@/lib/auth-mode' import type { settingsTable } from '@/db/tables' import { hashValues } from '@/lib/utils' import type { InferSelectModel } from 'drizzle-orm' @@ -9,7 +10,7 @@ export type Setting = InferSelectModel * - consumer mode: enabled by default * - oidc mode (self-hosted/enterprise): disabled by default */ -export const getDefaultDataCollectionValue = (authMode?: string): boolean => authMode !== 'oidc' +export const getDefaultDataCollectionValue = (): boolean => !isOidcMode() /** * Compute hash of user-editable fields for a setting @@ -31,7 +32,7 @@ export const hashSetting = (setting: Setting): string => { export const defaultSettingDataCollection: Setting = { key: 'data_collection', - value: String(getDefaultDataCollectionValue(import.meta.env.VITE_AUTH_MODE)), + value: String(getDefaultDataCollectionValue()), updatedAt: null, defaultHash: null, userId: null, diff --git a/src/lib/posthog.tsx b/src/lib/posthog.tsx index 6b63e3621..2b918f1b8 100644 --- a/src/lib/posthog.tsx +++ b/src/lib/posthog.tsx @@ -53,7 +53,7 @@ export const initPosthog = async (httpClient?: HttpClient): Promise Date: Fri, 1 May 2026 01:35:43 +0530 Subject: [PATCH 5/5] fix: sets telemetry to false by default --- src/defaults/settings.test.ts | 21 --------------------- src/defaults/settings.ts | 10 +--------- src/lib/posthog.tsx | 3 +-- src/settings/preferences.tsx | 3 +-- 4 files changed, 3 insertions(+), 34 deletions(-) delete mode 100644 src/defaults/settings.test.ts diff --git a/src/defaults/settings.test.ts b/src/defaults/settings.test.ts deleted file mode 100644 index 99e235035..000000000 --- a/src/defaults/settings.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { describe, expect, it, mock } from 'bun:test' - -// Mock isOidcMode before importing settings -const mockIsOidcMode = mock(() => false) -mock.module('@/lib/auth-mode', () => ({ - isOidcMode: mockIsOidcMode, -})) - -import { getDefaultDataCollectionValue } from './settings' - -describe('getDefaultDataCollectionValue', () => { - it('returns false when isOidcMode is true', () => { - mockIsOidcMode.mockReturnValue(true) - expect(getDefaultDataCollectionValue()).toBe(false) - }) - - it('returns true when isOidcMode is false', () => { - mockIsOidcMode.mockReturnValue(false) - expect(getDefaultDataCollectionValue()).toBe(true) - }) -}) diff --git a/src/defaults/settings.ts b/src/defaults/settings.ts index 7d076d860..705bf022b 100644 --- a/src/defaults/settings.ts +++ b/src/defaults/settings.ts @@ -1,17 +1,9 @@ -import { isOidcMode } from '@/lib/auth-mode' import type { settingsTable } from '@/db/tables' import { hashValues } from '@/lib/utils' import type { InferSelectModel } from 'drizzle-orm' export type Setting = InferSelectModel -/** - * Data collection default: - * - consumer mode: enabled by default - * - oidc mode (self-hosted/enterprise): disabled by default - */ -export const getDefaultDataCollectionValue = (): boolean => !isOidcMode() - /** * Compute hash of user-editable fields for a setting */ @@ -32,7 +24,7 @@ export const hashSetting = (setting: Setting): string => { export const defaultSettingDataCollection: Setting = { key: 'data_collection', - value: String(getDefaultDataCollectionValue()), + value: 'false', updatedAt: null, defaultHash: null, userId: null, diff --git a/src/lib/posthog.tsx b/src/lib/posthog.tsx index 2b918f1b8..85ea5e4f2 100644 --- a/src/lib/posthog.tsx +++ b/src/lib/posthog.tsx @@ -1,7 +1,6 @@ import { type HttpClient } from '@/contexts' import { getSettings } from '@/dal' import { getDb } from '@/db/database' -import { getDefaultDataCollectionValue } from '@/defaults/settings' import { createHandleError } from '@/lib/error-utils' import { createClient } from '@/lib/http' import type { HandleError, HandleResult } from '@/types/handle-errors' @@ -53,7 +52,7 @@ export const initPosthog = async (httpClient?: HttpClient): Promise