Skip to content

feat(messaging): preview a saved notification template against sample values - #39622

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-7jwovy
Dec 4, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-7jwovy

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Tesla · project thread
Fixes #39565
Clause-②: yes
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:系统设置里写通知模板的管理员,保存模板后可以填几项示例值,看到真实发信会生成的主题和正文;这一单只做服务端入口,表单上的预览面板由下一张卡接上,今天用户无感。
  • 为什么做:属于「通知与邮件模板预览」这组工作(按维护者已定的「真实渲染加示例值预览」方案拆出的第一张卡),解决管理员只能真发一次才知道收件人收到什么的问题,没配发信服务的新公司也能预览。
  • 出错会怎样:只有能查看该模板的人能预览,看不了的人被拒;预览不发信、不写任何记录,出错只影响预览本身,撤回这个改动不影响真实发信。
  • 要你做什么:无。

What changes

  • New route POST /api/v1/messaging/notification-templates/:id/preview (notification-template-preview-routes.ts). It reads one saved sys_notification_template row by id, under the caller's own execution context, and answers renderNotification(row, { topic: row.topic, payload }): the same function and the same columns (TEMPLATE_RENDER_FIELDS, now shared with the store's send-time read) the email channel sends with. Answer: { subject, html } for an html/mjml row, { subject, text } for markdown/text.
  • Body: a closed set, { payload } (optional; must be a JSON object). Query: closed empty set. Order before the row is read: caller (one composition) → held sign-in → anonymous → query → body → data engine → row.
  • Read refusals: the platform read gate's own 403 code is relayed (PERMISSION_DENIED); a row the caller cannot see, or that does not exist, answers 404 RECORD_NOT_FOUND.
  • The door is composed over a caller resolver and a data engine only: no messaging service, channel or mail service is reachable from it, and it writes nothing.
  • Mounted in MessagingServicePlugin beside the other messaging doors (one call; the plugin file is over 1,000 lines, so the door lives in its own module). The "no HTTP server" warning names it.
  • Ledger row in messaging-route-ledger.ts (server-only, consumer: the template form's preview pane, card 2 of the ruling), and the conformance test enumerates the new registrar.

Ruling: 7405856818 on #39412 (item 2 = B). Maintainer ruling 6335348115 on #25082 respected: the door renders a SAVED row by id and refuses any body key but payload (a body key is refused 400 by name).

Tests

Premise and pins, verbatim from the card:

Premise to prove first (on a real boot): "renderNotification (packages/services/service-messaging/src/template-renderer.ts:155) is callable in-package with the template row read under the caller's context and a caller-supplied payload, and answers what email-channel.ts:570-576 would send for the same inputs. If the row cannot be read without the system context (today template-renderer.ts:369-372 reads it as the system), report a fork; do not call the store's loader."

  • A member without read on the template is refused.
  • Nothing reaches the mail service; no sys_email, sys_notification or delivery row is written.
  • An html row's values are escaped exactly as on send.
  • A ledger row for the new route and its conformance test.

How each is held:

  • Premise, on a real boot (showcase, pnpm dev -- --fresh, head 3a33c7a3): an html row saved by the seeded admin through the data door; the same row read through the data door as a plain member of the same organization answers 403 PERMISSION_DENIED. The door, as the admin, answered 200 with the rendered subject and escaped html; as the member, 403 PERMISSION_DENIED. The store's loader is not called by the door (it reads the row itself, under the caller's context). Premise holds: no fork.
  • Member refused: real boot as above; in-package, a member without read on the template is refused with the gate's own PERMISSION_DENIED / 403 (the gate's throw shape is plugin-security's PermissionDeniedError).
  • Read as the caller: reads the row under the caller's own context, never the system's (the engine receives the caller's context object) and an administrator of another organization reads no row (two walled organizations on a real ObjectQL + better-sqlite3).
  • Nothing delivered or written: real boot, sys_email / sys_notification / sys_notification_delivery totals 1 / 4 / 4 before and after three previews; in-package, no engine write runs and every engine call touches only the template object.
  • Escaped as on send: an html row answers the subject and html face the email channel sends drives the real createEmailChannel over the same engine with a capturing mail service and asserts the door's answer equals what the channel handed to send, with hostile values (angle brackets, quotes, ampersand, apostrophe) entity-encoded in element text and in a quoted attribute; the markdown face equals the channel's verbatim text.
  • Ledger: messaging-route-ledger.conformance.test.ts enumerates registerNotificationTemplatePreviewRoutes.
Readings
  • pnpm --filter @objectstack/service-messaging exec vitest run --maxWorkers=2 at 8866e046: Test Files 84 passed (84), Tests 1130 passed (1130).
  • pnpm --filter @objectstack/service-messaging typecheck at 8866e046: exit 0; the new test file is in the program (tsc --listFiles).
  • Ablation A (row read as the system instead of the caller, via scripts/ablation-replace.mjs, restored to the HEAD blob): 3 failed / 14 passed: the caller-context pin, the other-organization 404 and the member 403.
  • Ablation B (a second, non-escaping substitution in place of renderNotification): 5 failed / 12 passed, the html equivalence pin among them. Restored to the HEAD blob.
  • Real boot transcript (showcase, private port, torn down): admin 200 with escaped html; member 403 PERMISSION_DENIED; unknown id 404 RECORD_NOT_FOUND; a body key 400 VALIDATION_ERROR; ?locale=en 400 VALIDATION_ERROR; anonymous 401 UNAUTHENTICATED.

Acceptance notes

  • Inactive rows preview. The door addresses the saved row by id, the one the administrator is editing, and does not mirror the send-time lookup's is_active: true filter or its locale ladder: a template is drafted before it is switched on, and the pane is on that row's form. A send never uses an inactive row; the answer does not say so (the form shows the row's own Active flag).
  • No separate title/body inputs. A send passes the notification's title and body beside the payload; a template that writes the title or body placeholder reads them from the sample payload here, which is the send's own fallback. One input, payload.
  • SMS rows render through the same function; the SMS channel then sends the text face, else the subject. The answer is the render, not the SMS byte string.
  • check:route-envelope is red on this head and needs one declaration row for the new module in scripts/check-route-envelope.mjs ({ responses: 0, ok: 0, err: 0 }, as its four messaging siblings carry). That file is outside the claim's file surface and the edit was refused in this session, so it is left to the seat: amend the surface and add the row, or dispatch it.
  • Not built: the pane (card 2), a past-notification picker, a test mail to oneself (ruled out of scope).

Verification

First read (by risk):

  1. packages/services/service-messaging/src/notification-template-preview-routes.ts: the findOne call under the caller's context and the refusal relay.
  2. packages/services/service-messaging/src/notification-template-preview-routes.integration.test.ts: the equivalence pin against createEmailChannel.
  3. packages/services/service-messaging/src/template-renderer.ts: TEMPLATE_RENDER_FIELDS now feeds the store's send-time read.

Two-minute check: pnpm --filter @objectstack/service-messaging exec vitest run src/notification-template-preview-routes.integration.test.ts shows 17 passed, including the html equivalence and the member refusal.

L2 at CONTRACT_REVIEW_TIER is owed besides L1 (Clause-② yes, new route).


Generated by Claude Code

… values

POST /api/v1/messaging/notification-templates/:id/preview renders a saved
sys_notification_template row with renderNotification, the renderer the
email channel sends with, against the caller's sample payload. The row is
read under the caller's own context, never the system's; nothing is
delivered and no row is written. Ledger row and conformance enumeration
added.

Claude-Session: https://claude.ai/code/session_01L9qibx73WZPdtRp9c7gYDR
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/service-messaging, touching 31 documentable anchor(s).

51 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json cefbc839cdf8a7ebd495b7126d781dff433127b3.

⛔ 12 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: VALIDATION_ERROR (literal, 40 pages)
  • 3 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 71 of 255 client-bound route-ledger rows — the other 184 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 184: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 60 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 6 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json cefbc839cdf8a7ebd495b7126d781dff433127b3 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 4081624005226dd7fe1bb3e5ce5737baa0c7a3c8 — the merge of head 53aea1c1427d1daa626d58d3644df82db95a04d7 into base cefbc839cdf8a7ebd495b7126d781dff433127b3, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 4081624005226dd7fe1bb3e5ce5737baa0c7a3c8 && git checkout 4081624005226dd7fe1bb3e5ce5737baa0c7a3c8
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin cefbc839cdf8a7ebd495b7126d781dff433127b3 53aea1c1427d1daa626d58d3644df82db95a04d7 && git checkout -B drift-repro cefbc839cdf8a7ebd495b7126d781dff433127b3 && git merge --no-ff 53aea1c1427d1daa626d58d3644df82db95a04d7

node scripts/docs-audit/affected-docs.mjs --json cefbc839cdf8a7ebd495b7126d781dff433127b3

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs cefbc839cdf8a7ebd495b7126d781dff433127b3 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…'s module

The new messaging route module writes every body through the shared
sendOk / sendError / sendServerFault pair, so it is declared with zero
hand-built responses, like its four messaging siblings.

Claude-Session: https://claude.ai/code/session_01L9qibx73WZPdtRp9c7gYDR
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-tesla · os-tesla · session_01L9qibxZ1DSpavkJARmHCQF

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 53aea1c1427d1daa626d58d3644df82db95a04d7
Local-runs: none
Scope: packages/services/service-messaging/src/notification-template-preview-routes.ts, packages/services/service-messaging/src/messaging-route-ledger.ts, packages/services/service-messaging/src/messaging-service-plugin.ts, packages/services/service-messaging/src/template-renderer.ts + scripts/check-route-envelope.mjs
Security-touching: yes
Rule-change-verified: none

Face: the Clause-②: yes declaration alone. There is no packages/spec/src/** path, no governed path and no narrowing arm, so the exact tier is TIER_DEFAULT (contract-review.md: the declaration face alone owes TIER_DEFAULT, and a tier is exact, not a floor). The PR body's line asking for CONTRACT_REVIEW_TIER is read as superseded by this face reading. Recorded by the seat's L1-c thread, the lane's own review.

① Derived judgments

  • The widening. One new route, POST /api/v1/messaging/notification-templates/:id/preview. Its body has the closed key set { payload }, its query set is empty, and the answer is RenderedNotification (subject + html | text). It is the door that ruling 7405856818 (mail and notification templates: the log-only banner promises notification mail is logged but it is skipped, and the template form gives a new admin nothing to go on #39412 item 2 = B) orders, and the card's four pins are each met by a named case in notification-template-preview-routes.integration.test.ts (real ObjectQL on SqlDriver, two walled orgs).
  • Read as the caller. data.findOne(TEMPLATE_OBJECT, { where: { id }, fields }, { context }) passes the resolved caller's context, and there is no system opt-in. The send path's FAN_OUT_SYSTEM_CONTEXT read is unchanged apart from sharing TEMPLATE_RENDER_FIELDS. A cross-org id answers 404 through the engine's wall. A gate refusal is relayed from the thrown error's own status 403 + code, the shape of PermissionDeniedError (plugin-security/src/errors.ts:41, read on main). No new capability is introduced: whoever reads the row may preview it.
  • Same render as a send. renderTemplatePreview calls renderNotification(row, { topic, payload }), a pure function of its inputs (template-renderer.ts, read). title and body fall back to payload.title / payload.body, which is the documented divergence from a send that passes them separately. The pinned equivalence against createEmailChannel covers html escaping and markdown verbatim.
  • Never delivers or writes. The deps hold only resolveCaller and getData, so no mail, messaging or channel service is reachable. The pin asserts that no engine write runs on success or on refusal.
  • Order before the read. The order is caller, then held sign-in (ADR-0069), then anonymous (ADR-0056 D2), then query, then body, then id, then data engine, and only then the row. Each refusal has a case asserting code + status through ApiErrorSchema / envelopeViolations.

② Semver level

Metadata-protocol: none, so the package takes patch (AGENTS.md Post-Task Checklist step 3: the level follows the kind, and none takes patch). The changeset carries '@objectstack/service-messaging': patch and both declaration lines. No error code is new: PERMISSION_DENIED, RECORD_NOT_FOUND, VALIDATION_ERROR, SERVICE_UNAVAILABLE and INTERNAL_ERROR are all existing ledger codes.

③ Boundary flags

  • The PR author is objectstack-fleet[bot] (relay write), so no author note is owed.
  • No SQL push-down issue: one findOne by id with three columns, and no in-app join or id materialisation.
  • The check-route-envelope.mjs MODULES row (responses 0 / ok 0 / err 0) declares the new module and matches its body: every answer goes through sendOk / sendError / sendServerFault. The claim amendment 7408663334 widened the file surface to cover it. It is a declaration row in an existing gate, not a new gate.
  • The dev's open questions are none in the report.

④ Design judgment

Not owed on the declaration face.

Implemented-by: claude/project-thread-7jwovy
Reviewed-by: session_01L9qibxZ1DSpavkJARmHCQF

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-tesla · os-tesla · session_01L9qibxZ1DSpavkJARmHCQF

席位核对

L1-c · 2026-12-04T11:01Z · ACCEPT · head 53aea1c142 · claim 7407321355, restated 7408663334 · L2 record 7409484450 (TIER_DEFAULT PASS, same head)

  • L2 tier. The face is declaration only: Clause-②: yes, with no packages/spec/src/** path, governed path or narrowing arm. check-owed-reviews.mjs reads it that way, TIER_DEFAULT, and marks the record above current and DONE. The PR body line "L2 at CONTRACT_REVIEW_TIER is owed" overstates the tier. Leave it or correct it when the PR is marked ready; neither blocks.
  • Ruling and pins. The PR delivers the render-only door that ruling 7405856818 (mail and notification templates: the log-only banner promises notification mail is logged but it is skipped, and the template form gives a new admin nothing to go on #39412 item 2 = B) orders. The card's premise is that the row is read under the caller's context, with no system read, and it holds: findOne(..., { context }). The four card pins map to named integration cases on a real ObjectQL + SqlDriver with two walled orgs: a member without read gets 403 PERMISSION_DENIED, nothing is delivered and no write runs, an html row is escaped as on send (equivalence against createEmailChannel), and there is a ledger row plus conformance enumeration. The refusal relay reads status 403 + code, which is PermissionDeniedError's shape on main (plugin-security/src/errors.ts:41).
  • Scope. All 8 files are in the restated surface, with check-route-envelope.mjs added there with its reason. TEMPLATE_RENDER_FIELDS is shared by the send-time read and the preview, so the two cannot drift apart in the columns they read.
  • Changeset (.changeset/39565-notification-template-preview.md), read sentence by sentence against the code:
    • The route and body shape { payload }, optional, defaulting to empty, match the code.
    • {subject, html} for html/mjml and {subject, text} for markdown/text matches the renderer.
    • Escaping and empty holes "as on a send" are pinned.
    • "Nothing is sent and nothing is written" matches the deps, which are data only.
    • "Who may preview" is 403 / 404 per the code.
    • Saved-only, and an inactive row previews: pinned.
    • The 400 refusals for query, extra key and non-object payload match the code.
    • The level is patch with Metadata-protocol: none (AGENTS.md step 3).
  • Face (l1-face.mjs --pr 39622 at 53aea1c142): CLEAN. 39 success, 18 expected skip, 0 failed, 0 pending. Lint & Repo Gates and TypeScript Type Check succeeded, and mergeable is clean.
  • Fixes #39565 is right. The card is card 1 of 4 (the server door), and the preview pane is card 2 Notification template form: a preview pane that renders the saved template through the real renderer with sample values #39569. The card's own text excludes it, so closing Notifications: a render-only door that previews a saved notification template against sample values #39565 at merge is right. Notification template form: a preview pane that renders the saved template through the real renderer with sample values #39569 is Blocked-by this card and unblocks on the merge.
  • Landing to-do: not governed, 638 lines, under 3000, so not Tier H. Before ready/queue, the L2 PASS at this head is the one needed; if the head moves past a pure main merge, a delta L2 is owed. Fixes closes the card, so no pm:dispatched hand removal is owed. ot-ux2 lands.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-tesla · os-tesla · session_01L9qibyrf8y7cWLVu7DMgBN

Landing — zone ot-ux2 · 2026-12-04T11:02Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notifications: a render-only door that previews a saved notification template against sample values

2 participants