You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4c18c43
Browse filesBrowse the repository at this point in the historyBrowse files
fix(print): a print with no filename names the PDF from the record's display name (#36801)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBEaJzgBWzjWCNjBjkVoeRto)_Fixes#35049
repo:objectstack#3 · os-support-ai · session_01WGufzi4PechTRCTBrfxV8W
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户在记录上点"打印"生成的 PDF
附件,现在以记录的标题命名(比如报价单号),不再是"页面名-记录编号"这种看不懂的名字;应用自己指定了文件名的照旧。
- 为兄弟应用 HotCRM 解决:打印报价单得到的附件名看不出是哪张报价单。
- 记录没有标题时仍沿用旧名字;同一条记录打印两次会得到两个同名附件,互不覆盖;改动可直接撤回。
- 无。
## What changes
`printRecordToFile` (and so `POST /api/v1/print/records`) archived every
PDF without an explicit `filename` as `PAGE-RECORDID.pdf`. Seat route
(the card's second option): the default is now the record's display name
(ADR-0079) plus `.pdf`. No template key, no spec change, no new
authorable key.
- **Where the name comes from.** Step 4 already read the record AS THE
CALLER and threw the row away; it now returns that row (`readAsCaller`,
was `refuseUnlessReadable`), and the name is built from it, so there is
no second read and the name never shows a value the caller may not read.
The title field is `resolveDisplayField` (`@objectstack/spec/data`, the
field `resolveRecordDisplayName` reads) over
`engine.registry.getObject(object)`, the same registry the files opt-in
reads.
- **Fallback.** No title field, an empty value, a value the caller's
field-level security leaves out of the row, a value that is not text or
a finite number, or one empty once made safe keeps the old
`PAGE-RECORDID.pdf`. The `Record #ID` floor of
`resolveRecordDisplayName` is deliberately not used, so no file is named
`Record #…`.
- **Hygiene** (`safeFileBase`). Control characters become a space; path
and reserved characters (slash, backslash, colon, asterisk, question
mark, double quote, less-than, greater-than, pipe) become `_`;
whitespace runs collapse; leading dots and spaces go (no hidden file, no
`..`); a trailing `.pdf` is not doubled; the name is cut to 100
characters (code points, never inside a surrogate pair) with trailing
dots and spaces dropped after the cut. The attachment service has no
sanitiser to reuse: `attachFileAs` stores the name as given, keys the
bytes by the file id (`buildKey`), and the download header encodes it
(`contentDispositionValue`). The cap matters because
`sys_attachment.file_name` is `maxLength: 255`, and a longer name would
be refused only after the render.
- **Explicit `filename`** is used exactly as given, unchanged.
**Visible change:** a print with no explicit filename now attaches
`DISPLAY-NAME.pdf` instead of `PAGE-RECORDID.pdf` (stated in the
changeset too).
## Tests
- `print-service.test.ts`, new top-level `describe` "the default file
name": display name used, read once, with the caller's own context;
derived title field (no `nameField`); explicit filename wins unchanged;
five fallback cases (no title field, blank, field absent from the
caller's row, non-text value, nothing left after sanitising) keep
`invoice_print-inv_1.pdf`; a number display value; reserved and control
characters; leading dots and a trailing `.pdf`; the 100-character cut
never splits a character.
- Dogfood (real showcase boot, real storage): `print-service-archive`
now pins `INV-PRINT-OWN.pdf`, and a new case prints one invoice twice.
Both carry the same name, have different `sys_file` and `sys_attachment`
ids, both attachments are listed under that name and both files are
`committed`. That is the collision measurement: the store neither
refuses nor overwrites. `print-service-named-page` now pins the
project's display name.
- `vitest.config.ts`: an anchored alias for `@objectstack/spec/data` so
the tests run the source, not `dist/` (`check:test-source-alias` flagged
the new import).
<details><summary>Local runs (head 4d45f05)</summary>
- `pnpm --filter @objectstack/service-print test` then `typecheck`,
under the verify lock on 4d45f05: VERDICT command-exit 0, Test Files 8
passed (8), Tests 131 passed (131). The typecheck program compiles all 8
test files (`tsc --listFiles`).
- Ablation (one, on the tested behaviour), via
`scripts/ablation-replace.mjs`: the default return was replaced by the
old id-based name. The anchor went x1 to x0 and the blob 33627bb to
eaeb6879. Result: 6 failed, 56 passed in `print-service.test.ts`: every
display-name case went red, and the fallback and explicit-name cases
stayed green, as they should. Restored: blob == HEAD, `git diff HEAD`
empty.
- Dogfood, the two touched files only, after building the dogfood
closure (`pnpm --filter '@objectstack/dogfood^...' build`, service-print
resolved through its rebuilt `dist/`), on c8ec539: VERDICT command-exit
0, Test Files 2 passed (2), Tests 16 passed (16). The full battery was
not run locally: the title carries no `!` and there is no narrowing arm.
It is the merge queue's.
- Derived gate families (`dispatch-gates --commands`): 98 derived. 96
were run with exit 0 (94 on c8ec539; on 4d45f05 the re-run
`check:test-source-alias` and the two `check-console-intercept-disarm`
rows the alias commit added). `check:skill-examples` first answered exit
3 and was re-run green after building the client SDK. `--ran`: "98
derived famil(ies) accounted for — 96 run, 2 NOT-MEASURED". The NOT
MEASURED pair are `check-plugin-teardown-shape --self-test` (the fixture
needs an unshallowed clone, checker health only) and
`check:dual-build-cjs-loads` (needs a full build). Both are left to CI.
</details>
## Acceptance notes
- **Metadata-protocol `none`, measured.** No `packages/spec` file is in
the diff. The `filename` request field lives on `PrintRecordRequest` in
this service, not in any spec schema (`git grep` for a print `filename`
under `packages/spec/src`: 0 hits). What an author can write is
unchanged; the output of an existing print changes. Clause-② `no`: no
exported type or option changes shape. Only the TSDoc of
`PrintRecordRequest.filename` is reworded.
- **Docs.** `content/docs/ui/print-pages.mdx` showed
`invoice_document-inv_1.pdf` as the result. It now shows the
display-name result and states the default, the fallback, the hygiene
and the two-prints behaviour.
- **Files outside the claimed surface:** the two dogfood files (their
pins asserted the old default and would red the merge queue's dogfood
shards; the collision measurement rides in one of them) and
`service-print/vitest.config.ts` (the test-source-alias gate).
## Verification
Read first (by risk): `print-service.ts` `defaultPrintFilename` and
`safeFileBase`; `print-service.ts` `readAsCaller` (the row returned is
the caller's own read); `print-service-archive.dogfood.test.ts` "a
second print of the same invoice".
Two-minute check: `pnpm --filter @objectstack/service-print exec vitest
run --maxWorkers=2 src/print-service.test.ts`. Expect 62 passed,
including the 12 under "the default file name".
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzi4PechTRCTBrfxV8W)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzi4PechTRCTBrfxV8W -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(print): a print with no `filename` names the PDF from the record's display name
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
`printRecordToFile` (and `POST /api/v1/print/records`) used to archive every PDF without an explicit `filename` as `<page>-<recordId>.pdf`, which tells the reader nothing about which record it is. It now names the file from the record's display name (ADR-0079: the object's `nameField`, or the title field derived from its fields), read from the row the caller's own read answered, plus `.pdf` — printing quote `Q-2026-0042` attaches `Q-2026-0042.pdf`.
11
+
12
+
- The name is made a safe file name: `/ \ : * ? " < > |` become `_`, control characters and whitespace runs become one space, leading dots are dropped, a trailing `.pdf` is not doubled, and it is cut to 100 characters.
13
+
- A record with no display value (no title field, an empty value, or one the caller's field-level security leaves out) keeps `<page>-<recordId>.pdf`, never the `Record #<id>` floor.
14
+
- An explicit `filename` is used exactly as given, as before.
15
+
- Printing a record twice attaches two files of the same name; neither replaces the other.
16
+
17
+
Visible change: a print with no explicit filename now attaches `<display name>.pdf` instead of `<page>-<recordId>.pdf`. Nothing to migrate; pass `filename` to keep a fixed name.
0 commit comments