feat(server,web): open the license and third-party notices from Settings

The sidecar serves LICENSE and THIRD_PARTY_NOTICES.md read-only at
GET /api/legal/license and GET /api/legal/third-party-notices, from the
copies next to service.js in the desktop app and the server archive, or
from the repository root when run from source. Like every API route it
needs the session token.

Settings > General gets an About section at every detail level with
License and Third-party licenses buttons; each opens the document in a
dialog, loaded once through the adapter, so it works the same in the
Tauri webview and in a browser.
This commit is contained in:
shumeiko.it
2026-11-04 10:30:33 +01:00
parent 9ac6b9f0d4
commit 58535a580f
8 changed files with 349 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ import EraseDataDialog from '@/components/os/overlays/EraseDataDialog';
import TelegramDigestCard from '@/components/os/settings/TelegramDigestCard';
import ChannelsSettings from '@/components/os/settings/ChannelsSettings';
import BrowserCompanionSettings from '@/components/os/settings/BrowserCompanionSettings';
import LegalNotices from '@/components/os/settings/LegalNotices';
import { AVAILABLE_SHAPES, useSelectedShape, type PromptShape } from '@/lib/shape-selection';
import { SectionLabel } from '@/components/os/warm';
import { ApprovalModal, type ApprovalRequest } from '@/components/ui/approval-modal';
@@ -565,6 +566,9 @@ const SettingsApp = () => {
</div>
)}
{/* UF-059: the license and the third-party notices, at every level. */}
<LegalNotices />
{/* Phase 4.1: Erase All Data — visible at ALL tiers (GDPR Art. 17
cannot be tier-gated, so this stays on General rather than
moving to the Everything-only Advanced tab). Closes the only

View File

@@ -0,0 +1,65 @@
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
const mocks = vi.hoisted(() => ({
getLegalDocument: vi.fn(),
}));
vi.mock('@/lib/adapter', () => ({ adapter: { getLegalDocument: mocks.getLegalDocument } }));
import LegalNotices from './LegalNotices';
afterEach(() => {
cleanup();
vi.clearAllMocks();
});
describe('LegalNotices', () => {
it('opens the third-party notices served by the sidecar', async () => {
mocks.getLegalDocument.mockResolvedValue('# Third-party notices\n\n| sharp | 0.35.3 | Apache-2.0 |');
render(<LegalNotices />);
fireEvent.click(screen.getByRole('button', { name: /third-party licenses/i }));
const dialog = await screen.findByRole('dialog', { name: /third-party licenses/i });
expect(mocks.getLegalDocument).toHaveBeenCalledWith('third-party-notices');
const text = await within(dialog).findByLabelText(/third-party licenses text/i);
expect(text).toHaveTextContent('# Third-party notices');
expect(text).toHaveTextContent('sharp | 0.35.3');
});
it('opens the MIT license', async () => {
mocks.getLegalDocument.mockResolvedValue('MIT License\n\nCopyright (c) 2026');
render(<LegalNotices />);
fireEvent.click(screen.getByRole('button', { name: /^license$/i }));
const dialog = await screen.findByRole('dialog', { name: /^license$/i });
expect(mocks.getLegalDocument).toHaveBeenCalledWith('license');
expect(await within(dialog).findByLabelText(/license text/i)).toHaveTextContent('MIT License');
});
it('loads each document once', async () => {
mocks.getLegalDocument.mockResolvedValue('notices');
render(<LegalNotices />);
fireEvent.click(screen.getByRole('button', { name: /third-party licenses/i }));
await screen.findByLabelText(/third-party licenses text/i);
fireEvent.keyDown(screen.getByRole('dialog'), { key: 'Escape' });
fireEvent.click(screen.getByRole('button', { name: /third-party licenses/i }));
await screen.findByLabelText(/third-party licenses text/i);
expect(mocks.getLegalDocument).toHaveBeenCalledTimes(1);
});
it('says so when the server cannot send the document', async () => {
mocks.getLegalDocument.mockRejectedValue(new Error('404'));
render(<LegalNotices />);
fireEvent.click(screen.getByRole('button', { name: /third-party licenses/i }));
const alert = await screen.findByRole('alert');
expect(alert).toHaveTextContent(/could not load this document/i);
expect(alert.textContent).not.toMatch(/—/);
});
});

View File

@@ -0,0 +1,95 @@
/**
* Settings > General > About: the license and the third-party notices (UF-059).
*
* Both files ship with every installation; the sidecar serves them from
* /api/legal/*, so this works in the desktop app, the server install and a
* source checkout alike.
*/
import { useState } from 'react';
import { FileText, Loader2, Scale } from 'lucide-react';
import { adapter } from '@/lib/adapter';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
type LegalDocument = 'license' | 'third-party-notices';
type DocumentState = { status: 'loading' } | { status: 'ready'; text: string } | { status: 'error' };
const DOCUMENTS: Record<LegalDocument, { label: string; description: string }> = {
license: {
label: 'License',
description: 'The MIT License that covers Waggle.',
},
'third-party-notices': {
label: 'Third-party licenses',
description: 'The open-source components that ship with Waggle, their licenses and where to get their source code.',
},
};
const buttonClass = 'inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] rounded-lg bg-muted/50 text-foreground hover:bg-muted transition-colors';
export default function LegalNotices() {
const [openDocument, setOpenDocument] = useState<LegalDocument | null>(null);
const [documents, setDocuments] = useState<Partial<Record<LegalDocument, DocumentState>>>({});
const show = (document: LegalDocument) => {
setOpenDocument(document);
if (documents[document]?.status === 'ready' || documents[document]?.status === 'loading') return;
setDocuments((current) => ({ ...current, [document]: { status: 'loading' } }));
adapter.getLegalDocument(document)
.then((text) => setDocuments((current) => ({ ...current, [document]: { status: 'ready', text } })))
.catch(() => setDocuments((current) => ({ ...current, [document]: { status: 'error' } })));
};
const state = openDocument ? documents[openDocument] : undefined;
return (
<div className="space-y-3" data-testid="settings-legal">
<h3 className="text-xs font-display font-semibold text-foreground flex items-center gap-2">
<Scale className="w-3.5 h-3.5 text-muted-foreground" />
About
</h3>
<p className="text-[11px] text-muted-foreground leading-relaxed">
Waggle is open-source software under the MIT License. The open-source components it ships keep their own licenses.
</p>
<div className="flex flex-wrap gap-2">
{(Object.keys(DOCUMENTS) as LegalDocument[]).map((document) => (
<button key={document} type="button" onClick={() => show(document)} className={buttonClass}>
<FileText className="w-3 h-3" />
{DOCUMENTS[document].label}
</button>
))}
</div>
<Dialog open={openDocument !== null} onOpenChange={(open) => { if (!open) setOpenDocument(null); }}>
<DialogContent className="flex max-h-[85vh] flex-col sm:max-w-3xl" data-testid="legal-document-dialog">
{openDocument && (
<>
<DialogHeader>
<DialogTitle>{DOCUMENTS[openDocument].label}</DialogTitle>
<DialogDescription>{DOCUMENTS[openDocument].description}</DialogDescription>
</DialogHeader>
{state?.status === 'ready' ? (
<pre
tabIndex={0}
aria-label={`${DOCUMENTS[openDocument].label} text`}
className="min-h-0 flex-1 overflow-auto whitespace-pre-wrap break-words rounded-lg border border-border/30 bg-secondary/30 p-3 font-mono text-[11px] leading-relaxed text-foreground"
>
{state.text}
</pre>
) : state?.status === 'error' ? (
<p role="alert" className="text-[11px] text-destructive">
Could not load this document from the Waggle server. Check that the server is running, then try again.
</p>
) : (
<p role="status" className="flex items-center gap-2 text-[11px] text-muted-foreground">
<Loader2 className="w-3 h-3 animate-spin" />
Loading...
</p>
)}
</>
)}
</DialogContent>
</Dialog>
</div>
);
}

View File

@@ -2712,6 +2712,13 @@ class LocalAdapter {
return this.healthProbe();
}
// --- Legal ---
/** The license or the third-party notices that ship with this installation (UF-059). */
async getLegalDocument(document: 'license' | 'third-party-notices'): Promise<string> {
const res = await this.fetch(`/api/legal/${document}`);
return res.text();
}
// --- Connectors ---
/** §8a consumption switch: the shared ConnectorDefinition (incl. the C16
* lastSyncAt enrichment) replaces the deleted thin FE `Connector` type. */

View File

@@ -17,6 +17,7 @@ const mocks = vi.hoisted(() => ({
clearTelemetry: vi.fn(),
getMemoryCapabilities: vi.fn(),
setMemoryExtraction: vi.fn(),
getLegalDocument: vi.fn(),
},
}));
@@ -75,6 +76,18 @@ afterEach(() => {
});
describe('Settings trust flows', () => {
it('opens the third-party licenses from General at the default level (UF-059)', async () => {
mocks.adapter.getLegalDocument.mockResolvedValue('# Third-party notices');
renderSettings();
fireEvent.click(await screen.findByRole('tab', { name: /^general$/i }));
const section = await screen.findByTestId('settings-legal');
expect(section.textContent).not.toMatch(/\u2014/);
fireEvent.click(within(section).getByRole('button', { name: /third-party licenses/i }));
const dialog = await screen.findByRole('dialog', { name: /third-party licenses/i });
expect(await within(dialog).findByLabelText(/third-party licenses text/i)).toHaveTextContent('# Third-party notices');
expect(mocks.adapter.getLegalDocument).toHaveBeenCalledWith('third-party-notices');
});
it('turns background fact extraction off and on from General', async () => {
renderSettings();
fireEvent.click(await screen.findByRole('tab', { name: /^general$/i }));