Public: anyone can read this; the crew can change it.

A granted app's two-page print comes out as one sheet, printed on both sides #18194

opened this

Merged 14h 22m ago, live in production

An app can now ask for a two-page print on both sides of one sheet, and the daily cap counts sheets of paper instead of jobs. Nothing was printed on the real printer. The print, raster, OpenAPI-error, module-state and dead-code tests pass, as do tsc and the gate.

Notes

opened this

An app can now ask for a two-page print on both sides of one sheet, and the daily cap counts sheets of paper instead of jobs. Nothing was printed on the real printer. The print, raster, OpenAPI-error, module-state and dead-code tests pass, as do tsc and the gate.

print.test.ts and print_raster.test.ts fail together in one process: one raster test gets 429, apparently from the shared per-minute limiter. They fail the same way on main and pass when run alone.

What changed

  • sides option: POST /api/v1/devices/:id/print?sides= takes one-sided (the default) or two-sided-long-edge. Anything else is a 400 invalid_sides that names both values. It is checked after the grant lookup but before the body is read, and the permit is released.
  • IPP encoding: encodePrintJob adds the IPP sides attribute only when asked. A test decodes the bytes and finds it for two-sided and finds none otherwise.
  • Printer support:
    • Two-sided is sent only when the printer's sides-supported lists it. reportOf now reads that attribute, and a fresh Get-Printer-Attributes is made at print time.
    • Otherwise the answer is 422 sides_unsupported, a plain sentence, and nothing reaches the printer. Tested with a fake printer that lists nothing.
  • Sheet cap:
    • A job's sheets are pages one-sided and ceil(pages/2) two-sided. Rows older than the new print_job.sheets column count as one each, as before.
    • After the body is read, the job's sheets are checked against printed-today plus the sheets other in-flight jobs hold, and reserved before any await. A job that does not fit gets a 429 daily_cap and is never sent.
    • Tested: two pages two-sided is 1, two pages one-sided is 2, and a job over the remainder is refused unsent.
  • Words: the OpenAPI entry, docs/features/devices.md, the device page and the terminal Devices screen all say "sheets". A test holds the OpenAPI refusal lines to the route's own sentences.

Behaviour change. A one-sided 20-page job is now 20 sheets against the default cap of 10. I changed two tests for that: print.test.ts raises the grant cap to 100 for its 20-page job, and the old "1 page, then 3 pages, cap 2" case is now two 1-page jobs. The same raise went into print_raster.test.ts.

What I chose not to do

  • No change to the comic or raster.ts, which live in the morning-paper app.
  • No detection of printers that silently ignore sides. The cap counts what was asked.
  • No two-sided-short-edge.

Reused: the probeRasterSupport pattern (ask the printer just before sending) and permitPrint's synchronous reservation. I changed the in-flight map's value to hold sheets, so no new module-level state was added.

To try: POST /api/v1/devices/<id>/print?sides=two-sided-long-edge with a two-page PDF and an app token on a preview. ?sides=duplex should return a 400 naming the allowed values. I have not tried it on a preview.

No review block: the only page change is two labels ("sheets") on /settings/devices.

🤖 Generated with Claude Code

Closes #18190

commented

An app can now ask for a two-page print on both sides of one sheet, and the daily cap counts sheets of paper instead of jobs. Nothing was printed on the real printer. The print, raster, OpenAPI-error, module-state and dead-code tests pass, as do tsc and the gate.

print.test.ts and print_raster.test.ts fail together in one process: one raster test gets 429, apparently from the shared per-minute limiter. They fail the same way on main and pass when run alone.

What changed

  • sides option: POST /api/v1/devices/:id/print?sides= takes one-sided (the default) or two-sided-long-edge. Anything else is a 400 invalid_sides that names both values. It is checked after the grant lookup but before the body is read, and the permit is released.
  • IPP encoding: encodePrintJob adds the IPP sides attribute only when asked. A test decodes the bytes and finds it for two-sided and finds none otherwise.
  • Printer support:
    • Two-sided is sent only when the printer's sides-supported lists it. reportOf now reads that attribute, and a fresh Get-Printer-Attributes is made at print time.
    • Otherwise the answer is 422 sides_unsupported, a plain sentence, and nothing reaches the printer. Tested with a fake printer that lists nothing.
  • Sheet cap:
    • A job's sheets are pages one-sided and ceil(pages/2) two-sided. Rows older than the new print_job.sheets column count as one each, as before.
    • After the body is read, the job's sheets are checked against printed-today plus the sheets other in-flight jobs hold, and reserved before any await. A job that does not fit gets a 429 daily_cap and is never sent.
    • Tested: two pages two-sided is 1, two pages one-sided is 2, and a job over the remainder is refused unsent.
  • Words: the OpenAPI entry, docs/features/devices.md, the device page and the terminal Devices screen all say "sheets". A test holds the OpenAPI refusal lines to the route's own sentences.

Behaviour change. A one-sided 20-page job is now 20 sheets against the default cap of 10. I changed two tests for that: print.test.ts raises the grant cap to 100 for its 20-page job, and the old "1 page, then 3 pages, cap 2" case is now two 1-page jobs. The same raise went into print_raster.test.ts.

What I chose not to do

  • No change to the comic or raster.ts, which live in the morning-paper app.
  • No detection of printers that silently ignore sides. The cap counts what was asked.
  • No two-sided-short-edge.

Reused: the probeRasterSupport pattern (ask the printer just before sending) and permitPrint's synchronous reservation. I changed the in-flight map's value to hold sheets, so no new module-level state was added.

To try: POST /api/v1/devices/<id>/print?sides=two-sided-long-edge with a two-page PDF and an app token on a preview. ?sides=duplex should return a 400 naming the allowed values. I have not tried it on a preview.

No review block: the only page change is two labels ("sheets") on /settings/devices.

🤖 Generated with Claude Code

commented

Both changes @sentinel asked for are in and pushed, along with the smaller cleanup. bun test test/print.test.ts passes and tsc is clean. I haven't run the full suite or exercised the preview.

  • Failed sides probe: in printFor, a probe that fails is now logged failed with sheets = 0, so a refusal where nothing reached the printer no longer uses up a sheet of the day. A new test points a two-sided job at a printer that answers 500. It checks that the response is 502 and that printedToday does not change.
  • daily_cap words: the OpenAPI route entry now uses the PRINT_WORDS.daily_cap sentence. The words test now holds daily_cap to it too, alongside invalid_sides and sides_unsupported.
  • Cleanup: I removed the expect(decodeResponse).toBeDefined() assertion and its unused import from the encodePrintJob test.

I left the raster probe alone. When it fails, the job is still logged failed with one sheet, and the raster probe sits outside this round's scope. Say so if you want it to log zero sheets as well.

gate.ts also reported a possible duplicate (printDocument and readJob in src/devices/ipp.ts) and some long comment lines, and I changed neither. --fix rewrapped nothing and I added no comment lines. The gate's note says the nightly rewrap handles the long lines on main.

The commit line carries No door: because only a refusal's accounting and one contract sentence changed, with no page, action or tool.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs