Add the list block and the module layer with the note module
Security / Vulnerability check (push) Successful in 41s
Test / Lint and test (push) Successful in 1m50s

The list block prints items with a dot, dash, number or checkbox bullet,
wrapping a long item with a hanging indent; a checkbox list ticks its
done items as [√], or [x] on code pages without √. It stands alone or
inside a box, and its items, bullet and done fields carry their enums
and limits as jsonschema tags.

internal/pkg/modules holds modules that build ordinary jobs from their
own payloads: a registry by name, an Env with the clock, time zone and
time layout, strict payload decoding that reports every problem, ErrSkip
and PayloadError. The note module prints a boxed note with an optional
checklist and a time stamp in the footer.

Three routes join the route table: POST /api/v1/print/{module} and
POST /api/v1/preview/{module}, which take ?copies and a reserved
?printer, and GET /api/v1/modules. Print and the module route share one
submit path, and preview shares one too. New error codes:
invalid_payload, invalid_query, unknown_printer, module_not_found and
module_failed; a module that builds an invalid receipt is logged and
reported to Sentry once. [format] gains timezone and time_layout, the
binary embeds the time zone database, and uberbringer preview takes
--module.

The note receipt passed on the TM-T88IV, and its bytes are pinned in
TestPaperReceipts. docs/api.md describes the list block, the module
routes and the note payload; docs/swagger.json is regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-30 10:55:50 -06:00
1 parent 6b2e402f1a
commit 3e9779f71a
69 files changed
+3092 -262

No files matched your search

+39 -2
View File
@@ -44,8 +44,10 @@ func TestValidateBlocks(t *testing.T) {
"elements[0].children[3] (cut): not allowed inside a box; place it after the box",
"elements[0].children[4] (barcode): not allowed inside a box; place it after the box",
}},
{"unknown child type", box(receipt.Element{Type: "list"}),
[]string{`elements[0].children[0] (list): unknown type "list" (inside a box, want text, feed, rule or kv)`}},
{"unknown child type", box(receipt.Element{Type: "table"}),
[]string{`elements[0].children[0] (table): unknown type "table" (inside a box, want text, feed, rule, kv or list)`}},
{"unknown type", receipt.Element{Type: "table"},
[]string{`elements[0] (table): unknown type "table" (want text, feed, qr, barcode, image, raw, cut, box, rule, kv or list)`}},
{"child without a type", box(receipt.Element{}),
[]string{"elements[0].children[0] (): type is required"}},
{"divider style", box(text, receipt.Element{Type: "rule", Style: "dark"}),
@@ -83,6 +85,31 @@ func TestValidateBlocks(t *testing.T) {
{"no pairs", receipt.Element{Type: "kv"}, []string{"elements[0] (kv): pairs: at least one pair is required"}},
{"too many pairs", receipt.Element{Type: "kv", Pairs: manyPairs(101)}, []string{"elements[0] (kv): pairs: 101 pairs, limit is 100"}},
{"kv size", receipt.Element{Type: "kv", Size: 9, Pairs: []receipt.Pair{{Key: "a"}}}, []string{"elements[0] (kv): size must be 1-3"}},
{"no items", receipt.Element{Type: "list"}, []string{"elements[0] (list): items: at least one item is required"}},
{"too many items", receipt.Element{Type: "list", Items: manyItems(201)}, []string{"elements[0] (list): items: 201 items, limit is 200"}},
{"empty item", receipt.Element{Type: "list", Items: []string{"a", ""}}, []string{"elements[0] (list): items[1]: must not be empty"}},
{"bullet", receipt.Element{Type: "list", Bullet: "star", Items: []string{"a"}},
[]string{"elements[0] (list): bullet must be dot, dash, number or checkbox"}},
{"done without checkboxes", receipt.Element{Type: "list", Bullet: "number", Items: []string{"a"}, Done: []int{0}},
[]string{`elements[0] (list): done: only a list with bullet "checkbox" has done items`}},
{"done out of range and repeated", receipt.Element{Type: "list", Bullet: "checkbox", Items: []string{"a", "b"}, Done: []int{1, 2, -1, 1}},
[]string{
"elements[0] (list): done[1]: index 2 is out of range",
"elements[0] (list): done[2]: index -1 is out of range",
"elements[0] (list): done[3]: index 1 is repeated",
}},
{"list size and columns", receipt.Element{Type: "list", Size: 4, Columns: 300, Items: []string{"a"}},
[]string{"elements[0] (list): size must be 1-3"}},
{"list columns", receipt.Element{Type: "list", Columns: 300, Items: []string{"a"}},
[]string{"elements[0] (list): columns must be 1-255"}},
{"field that does not apply to a list", receipt.Element{Type: "list", Items: []string{"a"}, Bold: true, Leader: "."},
[]string{`elements[0] (list): field "bold" does not apply to list`, `elements[0] (list): field "leader" does not apply to list`}},
{"list fields on an old type", receipt.Element{Type: "text", Text: "x", Items: []string{"a"}, Done: []int{0}},
[]string{`elements[0] (text): field "items" does not apply to text`, `elements[0] (text): field "done" does not apply to text`}},
{"list fields inside a box", box(receipt.Element{Type: "list", Items: []string{"a"}, Columns: 10, Font: "b"}),
[]string{"elements[0].children[0] (list): font is inherited from the box", `elements[0].children[0] (list): field "columns" does not apply to list inside a box`}},
{"list problems inside a box", box(receipt.Element{Type: "list", Bullet: "checkbox", Items: []string{"a"}, Done: []int{3}}),
[]string{"elements[0].children[0] (list): done[0]: index 3 is out of range"}},
{"old types stay lenient", receipt.Element{Type: "feed", Text: "ignored", Bold: true}, nil},
{"a full box", receipt.Element{
@@ -95,6 +122,8 @@ func TestValidateBlocks(t *testing.T) {
}}, nil},
{"a full rule", receipt.Element{Type: "rule", Style: "dashed", Text: "l", Align: "right", Bold: true, Columns: 255, Size: 3, Font: "a"}, nil},
{"a full kv", receipt.Element{Type: "kv", Leader: "space", Columns: 1, Size: 1, Font: "B", Pairs: manyPairs(100)}, nil},
{"a full list", receipt.Element{Type: "list", Bullet: "Checkbox", Columns: 1, Size: 3, Font: "b", Items: manyItems(200), Done: []int{0, 199}}, nil},
{"a list in a box", box(receipt.Element{Type: "list", Bullet: "checkbox", Items: []string{"a", "b"}, Done: []int{1}}), nil},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -106,6 +135,14 @@ func TestValidateBlocks(t *testing.T) {
}
}
func manyItems(n int) []string {
items := make([]string, n)
for i := range items {
items[i] = "item"
}
return items
}
func TestValidateCountsChildren(t *testing.T) {
children := make([]receipt.Element, receipt.MaxElements)
for i := range children {