feat(admin): build tooling, Docker stage and docs; close test gaps

- Add Makefile (admin, build, test) and a node stage in the Dockerfile
- Add .dockerignore so host node_modules and builds stay out of the image
- Document the admin UI in the README
- Cover mutation survivors: token cleanup on non-401 failures, cache dropped on 401 and sign out, member filter by name, archive invalidated after approval, page offset
This commit is contained in:
tgiachi 2026-11-09 15:42:07 +01:00
commit a0a083273c
9 changed files with 103 additions and 2 deletions

7
.dockerignore Normal file
View file

@ -0,0 +1,7 @@
.git
admin/node_modules
internal/adminui/dist/*
!internal/adminui/dist/.gitkeep
parsimony
*.db
*.db-*

View file

@ -1,8 +1,17 @@
FROM node:24 AS admin
WORKDIR /src/admin
COPY admin/package.json admin/package-lock.json ./
RUN npm ci
COPY admin/ ./
# The build writes into ../internal/adminui/dist
RUN mkdir -p /src/internal/adminui/dist && npm run build
FROM golang:1.27 AS build FROM golang:1.27 AS build
WORKDIR /src WORKDIR /src
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
COPY . . COPY . .
COPY --from=admin /src/internal/adminui/dist ./internal/adminui/dist
RUN CGO_ENABLED=0 go build -o /parsimony ./cmd/parsimony RUN CGO_ENABLED=0 go build -o /parsimony ./cmd/parsimony
FROM gcr.io/distroless/static-debian12 FROM gcr.io/distroless/static-debian12

18
Makefile Normal file
View file

@ -0,0 +1,18 @@
.PHONY: all admin test build clean
all: admin build
# Build the admin UI into internal/adminui/dist, which the Go binary embeds.
admin:
cd admin && npm ci && npm run build
build:
go build -o parsimony ./cmd/parsimony
test:
go test ./...
cd admin && npm test
clean:
rm -f parsimony
node admin/scripts/clean.mjs

View file

@ -15,6 +15,8 @@ A modern, single-binary mailing list manager: an evolution of Mailman.
- Per-recipient one-click unsubscribe links (RFC 8058) with signed tokens. - Per-recipient one-click unsubscribe links (RFC 8058) with signed tokens.
- SQLite storage, one YAML config file. - SQLite storage, one YAML config file.
- Admin REST API under `/api/v1` (see `docs/openapi.yaml`). - Admin REST API under `/api/v1` (see `docs/openapi.yaml`).
- Admin web UI (Vite, React, shadcn/ui) served by the API listener at `/`: lists, settings,
members, held queue and archive.
## Run ## Run
@ -40,6 +42,21 @@ the unsubscribe links in every message use it. Keep the `api` listener private.
curl -H "Authorization: Bearer $PARSIMONY_API_TOKEN" -d '{"name":"dev","domain":"example.org","title":"Dev"}' localhost:8080/api/v1/lists curl -H "Authorization: Bearer $PARSIMONY_API_TOKEN" -d '{"name":"dev","domain":"example.org","title":"Dev"}' localhost:8080/api/v1/lists
``` ```
## Admin UI
The UI is a single-page app in `admin/`, built into `internal/adminui/dist` and embedded in the binary.
It is served on the API listener together with `/api`, so it needs no CORS, and only when
`PARSIMONY_API_TOKEN` is set. You sign in with that token (kept in `sessionStorage`, gone when the tab closes).
```
make admin # npm ci && npm run build
make build # go build, embeds the UI
make test # go test + vitest
```
Without `make admin` the binary still builds and the UI answers 503 with a hint.
For frontend work run the daemon, then `cd admin && npm run dev` (Vite proxies `/api` to `127.0.0.1:8080`).
## Postfix ## Postfix
Deliver the list domains to parsimony over LMTP and keep the `+` extensions intact, for example: Deliver the list domains to parsimony over LMTP and keep the `+` extensions intact, for example:

View file

@ -4,6 +4,36 @@ import { aList, installFakeApi, newState } from '@/test/fakeApi'
import { renderApp } from '@/test/render' import { renderApp } from '@/test/render'
describe('authentication', () => { describe('authentication', () => {
it('does not keep the token when the check fails for another reason than 401', async () => {
installFakeApi(newState({ fail: { 'GET /lists': { status: 500, error: 'database is locked' } } }))
const { user } = renderApp('/login')
await user.type(await screen.findByLabelText(/api token/i), 'good')
await user.click(screen.getByRole('button', { name: /sign in/i }))
expect(await screen.findByText('database is locked')).toBeInTheDocument()
expect(sessionStorage.getItem('parsimony.token')).toBeNull()
})
it('drops cached data when the session ends', async () => {
const state = installFakeApi(newState({ lists: [aList()] }))
const { client } = renderApp('/', { token: 'good', keepCache: true })
await screen.findByText('dev@example.org')
expect(client.getQueryData(['lists'])).toBeDefined()
state.token = 'rotated'
const { api } = await import('@/lib/api')
await api.lists.list().catch(() => undefined)
await screen.findByRole('heading', { name: /sign in/i })
expect(client.getQueryData(['lists'])).toBeUndefined()
})
it('drops cached data on sign out', async () => {
installFakeApi(newState({ lists: [aList()] }))
const { user, client } = renderApp('/', { token: 'good', keepCache: true })
await screen.findByText('dev@example.org')
await user.click(screen.getByRole('button', { name: /sign out/i }))
await screen.findByRole('heading', { name: /sign in/i })
expect(client.getQueryData(['lists'])).toBeUndefined()
})
it('sends anonymous visitors to the login page', async () => { it('sends anonymous visitors to the login page', async () => {
installFakeApi(newState()) installFakeApi(newState())
renderApp('/') renderApp('/')

View file

@ -90,6 +90,9 @@ describe('archive tab', () => {
await user.click(screen.getByRole('button', { name: /next/i })) await user.click(screen.getByRole('button', { name: /next/i }))
expect(await screen.findByText('26–50 of 60')).toBeInTheDocument() expect(await screen.findByText('26–50 of 60')).toBeInTheDocument()
// The rows really are the second page, not just the label.
expect(await screen.findByRole('button', { name: 'Subject 26' })).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Subject 1' })).not.toBeInTheDocument()
expect(state.calls).toContain('GET /lists/1/archive') expect(state.calls).toContain('GET /lists/1/archive')
await user.click(screen.getByRole('button', { name: /next/i })) await user.click(screen.getByRole('button', { name: /next/i }))
expect(await screen.findByText('51–60 of 60')).toBeInTheDocument() expect(await screen.findByText('51–60 of 60')).toBeInTheDocument()

View file

@ -106,6 +106,15 @@ describe('held tab', () => {
}) })
}) })
it('marks the archive stale after an approval, because the message is archived on delivery', async () => {
const state = installFakeApi(newState({ lists: [aList({ id: 1, post_policy: 'moderated' })], held: { 1: [held(1)] } }))
const { user, client } = renderApp('/lists/1/held', { token: 'good', keepCache: true })
client.setQueryData(['archive', 1, '', 0], { total: 0, messages: [] })
await user.click(within((await screen.findByText('Subject 1')).closest('tr')!).getByRole('button', { name: /approve/i }))
await waitFor(() => expect(state.held[1]).toHaveLength(0))
await waitFor(() => expect(client.getQueryState(['archive', 1, '', 0])?.isInvalidated).toBe(true))
})
it('updates the badge on the tab when the queue changes', async () => { it('updates the badge on the tab when the queue changes', async () => {
const { user } = await setup([held(1), held(2)]) const { user } = await setup([held(1), held(2)])
expect(await screen.findByRole('tab', { name: /^held\s*2$/i })).toBeInTheDocument() expect(await screen.findByRole('tab', { name: /^held\s*2$/i })).toBeInTheDocument()

View file

@ -54,6 +54,14 @@ describe('members tab', () => {
expect(await screen.findByText(/no members match/i)).toBeInTheDocument() expect(await screen.findByText(/no members match/i)).toBeInTheDocument()
}) })
it('filters by display name too', async () => {
const { user } = await setup([member('x@example.com', { display_name: 'Zoe Quinn' }), member('y@example.com')])
await screen.findByText('y@example.com')
await user.type(screen.getByRole('searchbox', { name: /filter members/i }), 'zoe')
expect(screen.getByText('x@example.com')).toBeInTheDocument()
expect(screen.queryByText('y@example.com')).not.toBeInTheDocument()
})
it('adds a member and clears the form', async () => { it('adds a member and clears the form', async () => {
const { user, state } = await setup([member('alice@example.com')]) const { user, state } = await setup([member('alice@example.com')])
await user.type(screen.getByLabelText(/email address/i), 'Dave@Example.com') await user.type(screen.getByLabelText(/email address/i), 'Dave@Example.com')

View file

@ -7,9 +7,9 @@ import { AuthProvider } from '@/lib/auth'
import { session } from '@/lib/api' import { session } from '@/lib/api'
/** Renders the whole app at `path`. Pass `token` to start logged in. */ /** Renders the whole app at `path`. Pass `token` to start logged in. */
export function renderApp(path = '/', opts: { token?: string } = {}) { export function renderApp(path = '/', opts: { token?: string; keepCache?: boolean } = {}) {
if (opts.token) session.set(opts.token) if (opts.token) session.set(opts.token)
const client = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 0 }, mutations: { retry: false } } }) const client = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: opts.keepCache ? Infinity : 0 }, mutations: { retry: false } } })
const user = userEvent.setup() const user = userEvent.setup()
const utils = render( const utils = render(
<QueryClientProvider client={client}> <QueryClientProvider client={client}>