Adopt norn's CI, release, API and docs practices; bare module path
Test / Lint, test and build (push) Successful in 3m17s
Test / Lint, test and build (push) Successful in 3m17s
Module
- The module path is now the bare "uberbringer"; imports read
uberbringer/internal/... The banner keeps the Gitea URL.
CI and releases
- Workflows move to .gitea/workflows: test.yml (every branch push:
gofmt, goimports, tidy, vet, staticcheck, race tests, goreleaser
snapshot), security.yml (govulncheck weekly and on main) and a hardened
release.yml (v* tags on main only, tags fetched, goreleaser pinned to
2.20.3). The broken labeler workflow is removed.
- go.mod pins toolchain go1.27.4, which fixes GO-2026-6859; workflows
check that the running Go matches it.
- .goreleaser.yaml: tidy check that never writes, reproducible file times,
prerelease: auto, a release header linking CHANGELOG.md, and archives
that ship CHANGELOG.md, the example config and the systemd unit.
- Makefile mirrors the CI gate; .dockerignore is an allowlist.
API and tests
- Every error answers {"error", "code", "details"} with a stable code from
server/errors.go; the framework's own error text is never sent.
- Panics and unexpected errors are logged and reported to Sentry once;
refusals are not logged as failures. /healthz sends no-store.
- TestRoutesConform requires auth, rate limiting and the body limit on
every /api/v1 route.
- Race-prone tests no longer rely on freed ports or sleeps; serve takes
an injected listener.
- The test config uses a placeholder secret instead of a real one.
Install and packaging
- install.sh resolves the latest release through the Gitea API, verifies
checksums, requests a certificate only when none exists, installs the
hardened packaging/uberbringer.service and writes the first token to a
0600 file instead of printing it. It is now executable in git.
Docs
- CLAUDE.md, CHANGELOG.md (0.2.0 with breaking changes and upgrade
steps), docs/design.md, and docs/plans/formatters.md for the planned
CP437 blocks, modules and ntfy printing. README updated throughout.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
afcf96431f
commit
9b91109550
39 files changed
+3197
-433
No files matched your search
+129
@@ -0,0 +1,129 @@
|
||||
# Überbringer: design
|
||||
|
||||
Status: the daemon is built and has been checked on paper on the TM-T88IV.
|
||||
Next is the release of CHANGELOG.md § Unreleased as 0.2.0, and the formatters
|
||||
work in `docs/plans/formatters.md`. This page records why the daemon is
|
||||
shaped as it is. README.md describes how to use it.
|
||||
|
||||
## Why
|
||||
|
||||
Scripts and services on the owner's network send short JSON jobs, and one
|
||||
Epson receipt printer prints them. The daemon replaces the 0.1 one on the
|
||||
same endpoint, `POST /api/v1/print` behind nginx, and 0.1 installs are
|
||||
deployed. It is one static binary with no database, sized for receipt rates
|
||||
on one printer.
|
||||
|
||||
```text
|
||||
client ─HTTPS─▶ nginx ─▶ server ── validate ──▶ printqueue (memory, 1 worker)
|
||||
│ │ receipt.Render: whole job
|
||||
│ │ to bytes, images via safehttp
|
||||
│ ▼
|
||||
└─ /healthz ──────▶ printer.Client ─TCP 9100─▶ printer
|
||||
(one connection at a time)
|
||||
```
|
||||
|
||||
## Decisions
|
||||
|
||||
- **One printer per instance.** The config names one printer, and its client
|
||||
holds one connection to it at a time, shared by sends and status reads. A
|
||||
second printer means a second instance with its own config and port.
|
||||
The planned TM-T88VII and TM-m50II (owner, 2026-11-29) have the same
|
||||
geometry as the TM-T88IV, so a single profile default covers all three.
|
||||
- **The queue lives in memory, on purpose.** ESC/POS gives no
|
||||
acknowledgement of what has printed. A queue replayed after a crash could
|
||||
therefore print a receipt twice. A lost job, by contrast, shows as failed
|
||||
or unknown, and the client can send it again. Waiting jobs are marked
|
||||
failed at shutdown. After a crash their IDs answer `job_not_found`. One
|
||||
worker keeps jobs in submission order, and the history is capped by
|
||||
`queue.history`.
|
||||
- **Render, then send.** The handler validates the whole job, and a `400`
|
||||
lists every problem. The worker then renders the complete receipt, images
|
||||
included, to one byte stream that starts with a printer reset (ESC @). It
|
||||
sends that stream over one connection. A failure before the send, such as a
|
||||
broken image, costs no paper and leaves no half-printed receipt. A retry
|
||||
resends the same bytes and does not render again. A send that fails
|
||||
part-way can print part of a receipt twice. That is accepted, because
|
||||
retries are what let a job survive a printer that is briefly offline.
|
||||
- **Text in, code page out.** Clients send UTF-8, which is transcoded to
|
||||
`printer.codepage`. The default is CP437, for the box drawing and shading
|
||||
the owner prints (owner, 2026-11-29). Control characters are stripped, so
|
||||
data can never become a printer command. Only the `raw` element sends bytes
|
||||
as given.
|
||||
- **Profiles set the layout, and the default is the narrower one.** Columns
|
||||
are the profile's dots per line divided by the glyph width; nothing
|
||||
hard-codes 42 or 512. The first paper test ran the 576-dot `tm-t20`
|
||||
profile on the TM-T88IV, which has 512 dots, and the printer broke words at
|
||||
its own edge (`seve` / `ral`). A profile wider than the printer breaks
|
||||
words, while a narrower one only shortens lines. So `tm-t88` (512 dots, 42
|
||||
columns) is the default.
|
||||
- **Status is read in a way that tolerates a busy printer.** `/healthz` sends
|
||||
DLE EOT 1 to 4 over the same connection slot that sends use.
|
||||
- The DLE EOT 2 bits (cover open, paper-end stop) are cleared while DLE
|
||||
EOT 1 says online. Epson printers go offline for both causes, and a
|
||||
TM-T88IV reported a stale cover-open bit while cutting.
|
||||
- A not-ready reading is re-read 750 ms later.
|
||||
- A read cut short by our own deadline is `timeout` with `503`. It never
|
||||
counts as "status unsupported", because an unknown state must not look
|
||||
healthy.
|
||||
- A printer that never answers status gets `200` `unknown`.
|
||||
- The TM-T88VII does not report paper near-end through DLE EOT 4.
|
||||
- **Health is for monitors.** `/healthz` answers `200` when the printer is
|
||||
ready, or when it cannot report status. It answers `503` when a job could
|
||||
not print now: the printer is unreachable, not ready or timed out. A `503`
|
||||
from it is a refusal: it is logged at WARN by the request line and never
|
||||
sent to Sentry.
|
||||
- **Images are fetched by the worker, through an SSRF guard.** A slow or
|
||||
broken image URL holds no HTTP request and shows up as a `failed` job.
|
||||
`safehttp` checks the resolved address at connect time, so DNS rebinding
|
||||
and redirects cannot reach loopback, private, link-local or cloud metadata
|
||||
addresses. Exceptions are configured explicitly (`images.*`). Time, size,
|
||||
pixel and height limits bound each image.
|
||||
- **Errors are flat JSON with a stable code.** The shape is
|
||||
`{"error", "code", "details"}`. `code` is the contract with clients, and
|
||||
`error` is for people. A refusal is answered and never logged as a failure.
|
||||
An unexpected error or panic is logged once and reported to Sentry once,
|
||||
without the body or the `Authorization` header.
|
||||
- **What stays compatible with 0.1.** The endpoint, the HS256 tokens and the
|
||||
config keys stay as they were. The 0.1 body and its plain-text answer do
|
||||
not. A 0.1 body gets a `400` that points to the migration table, instead of
|
||||
being translated. Tokens are read only from the header, because tokens in
|
||||
query strings end up in proxy logs.
|
||||
- **Stack choices (owner, 2026-11-29):**
|
||||
- Fiber v3 instead of Echo.
|
||||
- TypeID (UUIDv7) job and request IDs instead of snowflakes. They sort by
|
||||
time and need no node configuration.
|
||||
- An Alpine Docker image.
|
||||
- **Packaging.** The release tarballs are built for linux amd64, armv6, armv7
|
||||
and arm64. `install.sh` sets up nginx (TLS, `X-Real-IP`), acme.sh and the
|
||||
sandboxed unit from `packaging/`. The daemon binds 127.0.0.1 by default and
|
||||
serves no TLS itself.
|
||||
|
||||
## Planned: formatters
|
||||
|
||||
Layout blocks and modules, ntfy among them, that turn plain input into
|
||||
receipts. The plan is `docs/plans/formatters.md`. Decided so far (owner,
|
||||
2026-11-29):
|
||||
|
||||
- ntfy is an input: its notifications are printed. The server is
|
||||
self-hosted at a public URL, the subscriber authenticates with a token, and
|
||||
attachments come from a public host, so image fetches need no
|
||||
private-network exception.
|
||||
- Which priorities print is configurable per subscription. By default every
|
||||
priority prints, and priorities 1 and 2 print in a compact form.
|
||||
- On `/print`, characters the code page lacks fold to ASCII look-alikes
|
||||
(smart quotes, dashes, the ellipsis), and an emoji sequence prints as one
|
||||
`?`. Today each such character prints as `?`.
|
||||
- Labels are in English. The footer's time zone and date format come from
|
||||
the config.
|
||||
|
||||
## Deferred
|
||||
|
||||
- **Paper near-end on the TM-T88VII**, which `GS r 1` reports. Add it when
|
||||
that printer arrives.
|
||||
- **Several printers from one instance**, through routing or a pool. Until
|
||||
then, run one instance per printer.
|
||||
- **A durable queue.** It needs a way to tell which receipts printed before a
|
||||
crash.
|
||||
- **Printer alerts sent out to ntfy** (paper out, cover open). They have not
|
||||
been requested. Printing incoming ntfy messages is part of the formatters
|
||||
plan.
|
||||
Reference in new issue
Block a user