Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(inhaltsregel): der Bestaetigungsschritt haengt am Server, nicht an der App

purple2b479a889ae6
diff --git a/src/api/cloud/__tests__/inhaltsregel-fragt-im-zweifel.test.ts b/src/api/cloud/__tests__/inhaltsregel-fragt-im-zweifel.test.ts
new file mode 100644
index 00000000..102aa091
--- /dev/null
+++ b/src/api/cloud/__tests__/inhaltsregel-fragt-im-zweifel.test.ts
@@ -0,0 +1,97 @@
+/**
+ * Die Altersbestaetigung haengt am Server, und im Zweifel wird gefragt.
+ *
+ * Entscheid David vom 13.09.2026: fuer 3.0.0 faellt der Bestaetigungsschritt
+ * weg und kommt in 3.0.1 wieder. Die Stellung steht im Server
+ * (`AGE_CONFIRMATION_REQUIRED`, `apps/web/lib/launch.ts`) und kommt mit der
+ * GET-Antwort von `/api/account/content-policy` als `ageConfirmationRequired`
+ * mit. Die App haelt keine eigene Kopie davon.
+ *
+ * Der Posten hier ist der Rand des Vertrags, nicht die Oberflaeche: was
+ * passiert, wenn das Feld fehlt oder Unsinn traegt. Ein aelterer oder gerade
+ * nicht erreichbarer Server liefert es nicht, und daran darf eine
+ * Altersschranke nicht verloren gehen.
+ *
+ * Lauf: npx vitest run src/api/cloud/__tests__/inhaltsregel-fragt-im-zweifel.test.ts
+ */
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+const http = vi.hoisted(() => ({ fetch: vi.fn(), json: vi.fn() }))
+vi.mock('../client', () => ({
+ cloudFetch: http.fetch,
+ jsonOrError: http.json,
+ CloudJobError: class CloudJobError extends Error {},
+}))
+
+import { getContentPolicy, setContentPolicy } from '../jobs'
+
+beforeEach(() => {
+ http.fetch.mockReset()
+ http.json.mockReset()
+ http.fetch.mockResolvedValue({} as Response)
+})
+
+const antwortet = (nutzlast: unknown) => http.json.mockResolvedValue(nutzlast)
+const rumpf = () => JSON.parse((http.fetch.mock.calls[0][1] as { body: string }).body)
+
+describe('die Stellung des Bestaetigungsschritts', () => {
+ it('kommt vom Server, wenn er sie nennt', async () => {
+ for (const stellung of [true, false]) {
+ http.json.mockReset()
+ antwortet({ policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: stellung })
+ expect((await getContentPolicy()).ageConfirmationRequired).toBe(stellung)
+ }
+ })
+
+ it('faellt auf fragen zurueck, wenn das Feld fehlt', async () => {
+ // Der ganze Grund dieser Datei. Ein Server ohne den Schalter kennt das Feld
+ // nicht, und die vorsichtige Antwort ist die einzige, die keine Schranke
+ // still verliert.
+ antwortet({ policy: 'off', ageConfirmedAt: null })
+ expect((await getContentPolicy()).ageConfirmationRequired).toBe(true)
+ })
+
+ it('faellt auch dann auf fragen zurueck, wenn das Feld kein Wahrheitswert ist', async () => {
+ for (const muell of ['false', 0, null, 'nein', {}]) {
+ http.json.mockReset()
+ antwortet({ policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: muell })
+ expect((await getContentPolicy()).ageConfirmationRequired, String(muell)).toBe(true)
+ }
+ })
+
+ /**
+ * NEGATIVKONTROLLE zur Leseart.
+ *
+ * Das Web liest `d.ageConfirmationRequired === true` und faellt damit auf
+ * "kein Schritt" zurueck. Dort ist das richtig, weil das PUT derselben
+ * Herkunft ohnehin abgewiesen wird. Hier waere es falsch, und ohne diese
+ * Zeile saehe man dem Code nicht an, dass die Abweichung Absicht ist.
+ */
+ it('liest das Feld ausdruecklich anders als das Web, und das ist der Unterschied', async () => {
+ const naivWieImWeb = (antwort: Record<string, unknown>) => antwort.ageConfirmationRequired === true
+ expect(naivWieImWeb({ policy: 'soft' })).toBe(false)
+ antwortet({ policy: 'soft', ageConfirmedAt: null })
+ expect((await getContentPolicy()).ageConfirmationRequired).toBe(true)
+ })
+})
+
+describe('was beim Setzen wirklich hinausgeht', () => {
+ it('schickt keine Bestaetigung, die niemand gegeben hat', async () => {
+ antwortet({ policy: 'off' })
+ await setContentPolicy('off', false)
+ expect(rumpf()).toEqual({ policy: 'off' })
+ expect('ageConfirmed' in rumpf()).toBe(false)
+ })
+
+ it('schickt sie, wenn jemand sie gegeben hat', async () => {
+ antwortet({ policy: 'off' })
+ await setContentPolicy('off', true)
+ expect(rumpf()).toEqual({ policy: 'off', ageConfirmed: true })
+ })
+
+ it('und schickt bei den harmlosen Stufen nichts dazu', async () => {
+ antwortet({ policy: 'strict' })
+ await setContentPolicy('strict')
+ expect(rumpf()).toEqual({ policy: 'strict' })
+ })
+})
diff --git a/src/api/cloud/jobs.ts b/src/api/cloud/jobs.ts
index 84a5618b..82afe3dc 100644
--- a/src/api/cloud/jobs.ts
+++ b/src/api/cloud/jobs.ts
@@ -235,6 +235,14 @@ export type ContentPolicy = 'strict' | 'soft' | 'off'
export interface ContentPolicyState {
policy: ContentPolicy
ageConfirmedAt: string | null
+ /**
+ * Ob der Server fuer 'off' eine Altersbestaetigung verlangt.
+ *
+ * Die Stellung steht im Server (AGE_CONFIRMATION_REQUIRED, lib/launch.ts im
+ * Web-Repo) und kommt mit der GET-Antwort mit. Die App haelt keine eigene
+ * Kopie davon, die abweichen koennte von der, die wirklich geprueft wird.
+ */
+ ageConfirmationRequired: boolean
}
/**
@@ -248,10 +256,26 @@ export interface ContentPolicyState {
*/
export async function getContentPolicy(): Promise<ContentPolicyState> {
const res = await cloudFetch('/api/account/content-policy')
- const data = await jsonOrError<{ policy?: string; ageConfirmedAt?: string | null }>(res)
+ const data = await jsonOrError<{
+ policy?: string
+ ageConfirmedAt?: string | null
+ ageConfirmationRequired?: unknown
+ }>(res)
return {
policy: data.policy === 'strict' || data.policy === 'off' ? data.policy : 'soft',
ageConfirmedAt: data.ageConfirmedAt ?? null,
+ /*
+ * Fehlt das Feld, wird gefragt.
+ *
+ * Ein aelterer Server kennt es nicht, und eine unvollstaendige Antwort darf
+ * keine Altersschranke abraeumen. Einmal zu viel fragen ist ein Aergernis,
+ * eine still verlorene Schranke ist es nicht. Deshalb gilt hier NICHT das
+ * `=== true` des Webs: dort ist die Vorgabe "kein Schritt", weil das PUT
+ * derselben Herkunft ohnehin abgewiesen wird. Der Desktop haengt an einem
+ * fremden Server und kennt dessen Stand nur aus dieser Antwort.
+ */
+ ageConfirmationRequired:
+ typeof data.ageConfirmationRequired === 'boolean' ? data.ageConfirmationRequired : true,
}
}
@@ -259,7 +283,13 @@ export async function setContentPolicy(policy: ContentPolicy, ageConfirmed = fal
const res = await cloudFetch('/api/account/content-policy', {
method: 'PUT',
headers: { 'content-type': 'application/json' },
- body: JSON.stringify({ policy, ageConfirmed }),
+ /*
+ * `ageConfirmed` geht nur mit, wenn wirklich jemand bestaetigt hat. Wo der
+ * Server keinen Schritt verlangt, behauptet die App auch keinen: ein fest
+ * mitgeschicktes `false` waere harmlos, ein fest mitgeschicktes `true`
+ * waere eine Bestaetigung, die niemand gegeben hat.
+ */
+ body: JSON.stringify(ageConfirmed ? { policy, ageConfirmed: true } : { policy }),
})
const data = await jsonOrError<{ policy?: string }>(res)
return data.policy === 'strict' || data.policy === 'off' ? data.policy : 'soft'
diff --git a/src/components/settings/ContentPolicySettings.tsx b/src/components/settings/ContentPolicySettings.tsx
index c5ea60d0..bffe8c72 100644
--- a/src/components/settings/ContentPolicySettings.tsx
+++ b/src/components/settings/ContentPolicySettings.tsx
@@ -3,11 +3,24 @@ import { HINWEIS_TEXT } from '../../lib/hinweis'
import { getContentPolicy, setContentPolicy, type ContentPolicy } from '../../api/cloud/jobs'
import { useCloudAuthStore } from '../../stores/cloudAuthStore'
-const OPTIONS: { value: ContentPolicy; label: string; hint: string }[] = [
- { value: 'strict', label: 'Strict', hint: 'The tightest filter we have. Choose this if others use your screen.' },
- { value: 'soft', label: 'Standard', hint: 'The default for every account.' },
- { value: 'off', label: 'Off', hint: 'No filter beyond the legal limits below. Requires an age confirmation.' },
-]
+/*
+ * Der Zusatz am Off-Hinweis haengt am Schalter des Servers. Ein Satz, der eine
+ * Bestaetigung ankuendigt, die nicht mehr kommt, verspricht genau das, was die
+ * Oberflaeche nicht mehr tut. Gleicher Bau wie im Web.
+ */
+function options(bestaetigungNoetig: boolean): { value: ContentPolicy; label: string; hint: string }[] {
+ return [
+ { value: 'strict', label: 'Strict', hint: 'The tightest filter we have. Choose this if others use your screen.' },
+ { value: 'soft', label: 'Standard', hint: 'The default for every account.' },
+ {
+ value: 'off',
+ label: 'Off',
+ hint: bestaetigungNoetig
+ ? 'No filter beyond the legal limits below. Requires an age confirmation.'
+ : 'No filter beyond the legal limits below.',
+ },
+ ]
+}
/**
* Die Inhaltsrichtlinie des Kontos, hier und in der Webanwendung dieselbe.
@@ -23,6 +36,12 @@ export function ContentPolicySettings() {
const signedIn = useCloudAuthStore((s) => s.status === 'signed-in')
const [policy, setPolicy] = useState<ContentPolicy>('soft')
const [confirmedAt, setConfirmedAt] = useState<string | null>(null)
+ /*
+ * Vorsichtiger Standard: bis der Server widerspricht, wird gefragt. Siehe die
+ * Begruendung in api/cloud/jobs.ts; eine Antwort, die nicht ankommt, darf die
+ * Schranke nicht abraeumen.
+ */
+ const [requiresAge, setRequiresAge] = useState(true)
const [pending, setPending] = useState<ContentPolicy | null>(null)
const [busy, setBusy] = useState(false)
const [error, setError] = useState('')
@@ -31,7 +50,12 @@ export function ContentPolicySettings() {
if (!signedIn) return
let live = true
getContentPolicy()
- .then((s) => { if (live) { setPolicy(s.policy); setConfirmedAt(s.ageConfirmedAt) } })
+ .then((s) => {
+ if (!live) return
+ setPolicy(s.policy)
+ setConfirmedAt(s.ageConfirmedAt)
+ setRequiresAge(s.ageConfirmationRequired)
+ })
.catch(() => { /* signed out or offline: the default stands */ })
return () => { live = false }
}, [signedIn])
@@ -85,7 +109,7 @@ export function ContentPolicySettings() {
your own machine is.
</p>
- {OPTIONS.map((o) => (
+ {options(requiresAge).map((o) => (
<label key={o.value} className="flex cursor-pointer items-start gap-2">
<input
type="radio"
@@ -94,7 +118,10 @@ export function ContentPolicySettings() {
value={o.value}
checked={policy === o.value}
disabled={busy}
- onChange={() => { if (o.value === 'off') setPending('off'); else void save(o.value, false) }}
+ onChange={() => {
+ if (o.value === 'off' && requiresAge) setPending('off')
+ else void save(o.value, false)
+ }}
/>
<span>
<span className="text-[0.7rem] text-gray-700 dark:text-gray-300">{o.label}</span>
@@ -129,7 +156,10 @@ export function ContentPolicySettings() {
</div>
)}
- {policy === 'off' && confirmedAt && (
+ {/* Auch der Rueckblick haengt am Schalter. Ein Konto kann einen Stempel
+ aus der Zeit tragen, in der bestaetigt wurde; ohne diese Bedingung
+ spraeche die Zeile von einem Schritt, den es nicht mehr gibt. */}
+ {policy === 'off' && requiresAge && confirmedAt && (
<p className="text-[0.6rem] text-gray-500">
Age confirmed on {new Date(confirmedAt).toLocaleDateString()}. Switching to another
option clears that confirmation.
diff --git a/src/components/settings/__tests__/content-policy-settings.test.tsx b/src/components/settings/__tests__/content-policy-settings.test.tsx
index 42caf8d5..da389e62 100644
--- a/src/components/settings/__tests__/content-policy-settings.test.tsx
+++ b/src/components/settings/__tests__/content-policy-settings.test.tsx
@@ -10,8 +10,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
const api = vi.hoisted(() => ({
- get: vi.fn(async (): Promise<{ policy: 'strict' | 'soft' | 'off'; ageConfirmedAt: string | null }> =>
- ({ policy: 'soft', ageConfirmedAt: null })),
+ get: vi.fn(async (): Promise<{ policy: 'strict' | 'soft' | 'off'; ageConfirmedAt: string | null; ageConfirmationRequired: boolean }> =>
+ ({ policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: true })),
set: vi.fn(async (p: string) => p),
}))
vi.mock('../../../api/cloud/jobs', () => ({
@@ -32,14 +32,14 @@ beforeEach(() => {
// Einmalantwort des vorigen und misst etwas anderes, als er behauptet.
api.get.mockReset()
api.set.mockReset()
- api.get.mockResolvedValue({ policy: 'soft', ageConfirmedAt: null })
+ api.get.mockResolvedValue({ policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: true })
api.set.mockImplementation(async (p: string) => p)
signIn()
})
describe('ContentPolicySettings', () => {
it('asks the server instead of keeping its own copy', async () => {
- api.get.mockResolvedValue({ policy: 'strict', ageConfirmedAt: null })
+ api.get.mockResolvedValue({ policy: 'strict', ageConfirmedAt: null, ageConfirmationRequired: true })
render(<ContentPolicySettings />)
await waitFor(() => expect((screen.getByDisplayValue('strict') as HTMLInputElement).checked).toBe(true))
})
@@ -60,6 +60,39 @@ describe('ContentPolicySettings', () => {
await waitFor(() => expect(api.set).toHaveBeenCalledWith('off', true))
})
+ it('zeigt keinen Bestaetigungsschritt, wenn der Server keinen verlangt', async () => {
+ // Entscheid David vom 13.09.2026. Die Stellung kommt aus der GET-Antwort,
+ // nicht aus der App: AGE_CONFIRMATION_REQUIRED steht im Server.
+ api.get.mockResolvedValue({ policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: false })
+ render(<ContentPolicySettings />)
+ await waitFor(() =>
+ expect(document.body.textContent ?? '').not.toMatch(/Requires an age confirmation/))
+ fireEvent.click(screen.getByDisplayValue('off'))
+ expect(screen.queryByTestId('age-gate')).toBeNull()
+ await waitFor(() => expect(api.set).toHaveBeenCalledWith('off', false))
+ })
+
+ it('und verschweigt in dieser Stellung auch den alten Bestaetigungsstempel', async () => {
+ // Ein Konto kann den Stempel aus der Zeit tragen, in der bestaetigt wurde.
+ // Die Zeile spraeche sonst von einem Schritt, den es nicht mehr gibt.
+ api.get.mockResolvedValue({
+ policy: 'off', ageConfirmedAt: '2026-09-10T08:00:00.000Z', ageConfirmationRequired: false,
+ })
+ render(<ContentPolicySettings />)
+ await waitFor(() => expect((screen.getByDisplayValue('off') as HTMLInputElement).checked).toBe(true))
+ expect(document.body.textContent ?? '').not.toContain('Age confirmed on')
+ })
+
+ it('NEGATIVKONTROLLE: verlangt der Server den Schritt, steht alles wieder da', async () => {
+ api.get.mockResolvedValue({ policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: true })
+ render(<ContentPolicySettings />)
+ await waitFor(() =>
+ expect(document.body.textContent ?? '').toMatch(/Requires an age confirmation/))
+ fireEvent.click(screen.getByDisplayValue('off'))
+ expect(screen.getByTestId('age-gate')).toBeTruthy()
+ expect(api.set).not.toHaveBeenCalled()
+ })
+
it('lets the gate be cancelled without changing anything', () => {
render(<ContentPolicySettings />)
fireEvent.click(screen.getByDisplayValue('off'))
@@ -120,7 +153,7 @@ describe('ContentPolicySettings', () => {
const WEB_SATZ = 'Switching to another option clears that confirmation.'
it('nennt die Altersbestaetigung mit dem Verb des Web', async () => {
- api.get.mockResolvedValue({ policy: 'off', ageConfirmedAt: '2026-09-10T08:00:00.000Z' })
+ api.get.mockResolvedValue({ policy: 'off', ageConfirmedAt: '2026-09-10T08:00:00.000Z', ageConfirmationRequired: true })
render(<ContentPolicySettings />)
await waitFor(() => {
const text = (document.body.textContent ?? '').replace(/\s+/g, ' ')
@@ -139,8 +172,8 @@ describe('ContentPolicySettings', () => {
const SERVERDATUM = '2019-03-04T12:00:00.000Z'
const ALS_TEXT = new Date(SERVERDATUM).toLocaleDateString()
api.get
- .mockResolvedValueOnce({ policy: 'soft', ageConfirmedAt: null })
- .mockResolvedValueOnce({ policy: 'off', ageConfirmedAt: SERVERDATUM })
+ .mockResolvedValueOnce({ policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: true })
+ .mockResolvedValueOnce({ policy: 'off', ageConfirmedAt: SERVERDATUM, ageConfirmationRequired: true })
render(<ContentPolicySettings />)
fireEvent.click(screen.getByDisplayValue('off'))
fireEvent.click(screen.getByRole('button', { name: 'I am 18 or older' }))
@@ -158,7 +191,7 @@ describe('ContentPolicySettings', () => {
// das Netz genau dazwischen aus, gibt es keinen Fehler zu lesen und
// trotzdem kein erfundenes Datum.
api.get
- .mockResolvedValueOnce({ policy: 'soft', ageConfirmedAt: null })
+ .mockResolvedValueOnce({ policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: true })
.mockRejectedValueOnce(new Error('offline'))
render(<ContentPolicySettings />)
fireEvent.click(screen.getByDisplayValue('off'))
@@ -175,7 +208,7 @@ describe('ContentPolicySettings', () => {
// nicht da, auch wenn der Server ein Bestaetigungsdatum mitliefert.
for (const policy of ['strict', 'soft'] as const) {
cleanup()
- api.get.mockResolvedValue({ policy, ageConfirmedAt: '2026-09-10T08:00:00.000Z' })
+ api.get.mockResolvedValue({ policy, ageConfirmedAt: '2026-09-10T08:00:00.000Z', ageConfirmationRequired: true })
render(<ContentPolicySettings />)
await waitFor(() => expect((screen.getByDisplayValue(policy) as HTMLInputElement).checked).toBe(true))
expect(document.body.textContent ?? '', policy).not.toContain('Age confirmed on')