Skip to content

Commit 85fdc6d

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/issue-39439-setup-admin-polish-4
2 parents 652976b + 14de0ff commit 85fdc6d

32 files changed

Lines changed: 1070 additions & 138 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/plugin-email': patch
4+
'@objectstack/rest': patch
5+
---
6+
7+
feat(rest, plugin-email): preview an email template through the real send-time renderer, the pending draft when one exists
8+
9+
Clause-②: yes
10+
Metadata-protocol: none
11+
12+
Who sees it: an administrator who previews an email template, and anyone reviewing a template the AI assistant or an MCP client left as a pending draft.
13+
14+
- **New door `POST /api/v1/email/render`.** It renders a saved email template by name against sample values the caller types, through the same locale ladder, required-variable check and renderer a send uses. Nothing is delivered, nothing is queued, no mail-log (`sys_email`) row is written and no business record is read. It requires the mail capability (`manage_platform_settings`), as the send door does. The body is a closed set: `template` (required), `data`, `locale`, `timezone`, `currency`, `package`, `previewDrafts`; any other key, an inline subject or body included, is refused `400`.
15+
- **The pending draft.** With `previewDrafts: true`, a caller the draft-read admission admits (the system, or a holder of `studio.access`, `setup.access` or `manage_metadata`) gets each language member's pending draft where one exists, and a template that exists only as a draft renders. A caller it does not admit gets the published rendering, never a refusal.
16+
- **The answer says what it rendered:** `version` (`draft` or `published`), `locale`, and for a draft its `publishVerdict`, what a publish of that draft would refuse. The send's own refusals keep their sentence: a missing required variable answers `400` with `details.refusal: 'MISSING_VARIABLES'`, an unknown template `404`.
17+
- **Contract (`@objectstack/spec`, additive):** `RenderTemplateInput.previewDrafts?`, `RenderTemplateResult.resolved?` and the new `RenderedTemplateVersion` type. `SendTemplateInput` is unchanged, and `sendTemplate` never reads a draft, even when its input object carries the key.
18+
- **`@objectstack/plugin-email`:** `renderTemplate` sets `resolved` on every render; `TemplateLoadOptions.previewDrafts?` and `EmailTemplateRow.draft?` carry the draft read through the registry loader. A replacement `TemplateLoader` that ignores the option renders the published row, labelled published.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): the automation skill says an assignment rule tells nobody, and gives the creation flow that tells the person it picked
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
Skills-docs: updated here
10+
11+
`skills/objectstack-automation/references/examples-flows.md` § Assignment rules gains the recipe. An assignment rule writes `owner_id` and `queue` and nothing else, and no key on a rule or an entry notifies, so the person a `round_robin` or `least_loaded` entry picks is told by a flow on the object's creation: a `record-after-create` start node with the condition `!isBlank(record.owner_id) && record.owner_id != record.created_by`, then a `notify` to `record.owner_id`. A parked record (an entry with no `strategy`, or a queue nobody staffs) has no owner, so nobody is told; a signed-in creator owns what they file and is not told of it. The section links the guide's whole flow.
12+
13+
No runtime or contract change: the skill now teaches what the platform already does. One eval case in `evals/flows-triggers-approvals.json` asks for the routing and the notice together, and fails an answer that puts a notify key on the rule. Eval 12 of the same file (round-robin routing plus a queue sign-off) stops forbidding `record-after-create`, the trigger the section now teaches for the notice, and forbids `owner_id:` instead, the key a flow writes when it routes the record itself. Its case hash is new, so `skill-evals --regrade` sets it apart from a round recorded before this change: compare it across rounds only after a re-run.
14+
15+
The recipe is paid for in the same file by cutting sentences `SKILL.md` already says: the file goes from 26505 to 26508 bytes and stays at its token ceiling.

‎.claude/skills/pm-dispatch/references/execution-duties.md‎

Lines changed: 63 additions & 62 deletions
Large diffs are not rendered by default.

‎.github/workflows/ci.yml‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ concurrency:
119119
# ── THE TWO SPEEDS (#22998) ──────────────────────────────────────────────────
120120
# A `pull_request` run carries the FAST SET: `Build Core`, `Test Core`
121121
# (affected-only) and `Build Docs`. A `merge_group` run carries the fast set
122-
# plus the three `dogfood` shards (#30461, ruling record 6663883327, letter B),
122+
# plus the `dogfood` shards (#30461, ruling record 6663883327, letter B),
123123
# whose job alone spells
124124
#
125125
# github.event_name != 'pull_request'
@@ -1032,9 +1032,11 @@ jobs:
10321032
# the longest pole in the whole workflow — and at 2 shards the slower shard
10331033
# still ran ~10 min, keeping merge-queue builds at ~11 min end-to-end
10341034
# (#4859).
1035-
# scripts/partition-test-shards.mjs splits the package list into ten
1036-
# deterministic bins balanced on MEASURED per-package test duration
1037-
# (scripts/test-shard-timings.json, generated — see #10472 below) and each
1035+
# scripts/partition-test-shards.mjs splits the package list into one
1036+
# deterministic bin per matrix shard, balanced on MEASURED per-package
1037+
# test duration (scripts/test-shard-timings.json, generated — see #10472
1038+
# below; a split that carries a file-level slice is placed by modelled
1039+
# wall instead, see TWELVE below) and each
10381040
# shard runs its slice through turbo. NOT the dogfood
10391041
# job's vitest --shard passthrough, deliberately: that works for dogfood
10401042
# because it is ONE package with ~60 files, but applied workspace-wide,
@@ -2964,14 +2966,17 @@ jobs:
29642966
pnpm --filter @objectstack/knowledge-pgvector exec vitest run live-postgres
29652967
29662968
dogfood:
2967-
# Sharded 3-way: the suite is ~60 independent test files, each booting its
2969+
# Sharded 4-way: the suite is ~60 independent test files, each booting its
29682970
# own in-process app; a single 4-vCPU runner needed ~7½ minutes for the
29692971
# lot, and at 2 shards each half still ran ~7 min — the longest pole left
29702972
# once Test Core went 3-way (#4859). vitest partitions the file list
29712973
# deterministically across shards; all shards must pass. The bare
29722974
# "Dogfood Regression Gate" context is carried by the dogfood-gate job
2973-
# below — the shard count can change without touching it.
2974-
name: Dogfood Regression Gate (${{ matrix.shard }}/3)
2975+
# below — the shard count can change without touching it. Four since
2976+
# #36646: on the merge queue the three shard jobs ran ~18 min each (p50)
2977+
# and, after Test Core, set the run's end; a fourth shard cuts each one's
2978+
# file list by a quarter.
2979+
name: Dogfood Regression Gate (${{ matrix.shard }}/4)
29752980
needs: [filter, queue-verdict]
29762981
# See THE FILTER CONTRACT on the filter job's outputs (#4928). The queue
29772982
# build and the full battery, never a pull request: see THE TWO SPEEDS
@@ -2988,13 +2993,13 @@ jobs:
29882993
contents: read
29892994
# Fail-fast on `merge_group` only, as on Test Core (#31517, ruling record
29902995
# 6730013883; the reasons are on the `test` job's strategy). Push and
2991-
# schedule, the other events this matrix runs on, run all three shards to
2992-
# their end. A red shard dominates the matrix result over the siblings it
2996+
# schedule, the other events this matrix runs on, run every shard to
2997+
# its end. A red shard dominates the matrix result over the siblings it
29932998
# cancels, and `Dogfood Regression Gate` reads `failure` as a veto.
29942999
strategy:
29953000
fail-fast: ${{ github.event_name == 'merge_group' }}
29963001
matrix:
2997-
shard: [1, 2, 3]
3002+
shard: [1, 2, 3, 4]
29983003

29993004
steps:
30003005
- name: Checkout repository
@@ -3141,7 +3146,7 @@ jobs:
31413146
# `--summarize` writes `.turbo/runs/<id>.json` and moves no task hash;
31423147
# it names the closure's `build` tasks and `dogfood#test` alike, and
31433148
# the prune before the seed save keeps exactly those entries.
3144-
export OS_TEST_SHARD="${{ matrix.shard }}/3"
3149+
export OS_TEST_SHARD="${{ matrix.shard }}/4"
31453150
node scripts/run-with-stall-guard.mjs --log "$RUNNER_TEMP/dogfood.log" --stall-minutes 10 \
31463151
--report-dir "$RUNNER_TEMP/stall-reports" -- \
31473152
pnpm turbo run test --filter=@objectstack/dogfood --summarize --log-order=stream
@@ -3154,7 +3159,7 @@ jobs:
31543159
run: |
31553160
node scripts/ci/report-test-leftovers.mjs report \
31563161
--before "$RUNNER_TEMP/test-leftovers/before.json" \
3157-
--label "Dogfood Regression Gate (${{ matrix.shard }}/3)"
3162+
--label "Dogfood Regression Gate (${{ matrix.shard }}/4)"
31583163
31593164
# Dogfood boots real apps in-process, so a native/OOM abort is likelier
31603165
# here than in the unit suites — and a shard that dies silently looks like
@@ -3194,7 +3199,7 @@ jobs:
31943199
id: prune-turbo-cache
31953200
if: always() && github.event_name == 'push'
31963201
run: |
3197-
node scripts/ci/prune-turbo-cache.mjs --site 'Dogfood Regression Gate (${{ matrix.shard }}/3)' \
3202+
node scripts/ci/prune-turbo-cache.mjs --site 'Dogfood Regression Gate (${{ matrix.shard }}/4)' \
31983203
--cache .turbo/cache --run-summaries .turbo/runs
31993204
32003205
# Seed the shared Turbo cache from main only (see the restore step
@@ -3214,14 +3219,14 @@ jobs:
32143219
if: needs.queue-verdict.outputs.covered != 'true'
32153220
run: |
32163221
node scripts/check-shard-attestation.mjs --emit \
3217-
--job dogfood --shard ${{ matrix.shard }} --total 3 \
3222+
--job dogfood --shard ${{ matrix.shard }} --total 4 \
32183223
--out "$RUNNER_TEMP/shard-attestation"
32193224
32203225
- name: Publish this shard's attestation
32213226
if: needs.queue-verdict.outputs.covered != 'true'
32223227
uses: actions/upload-artifact@v7
32233228
with:
3224-
name: shard-attest-dogfood-${{ matrix.shard }}-of-3
3229+
name: shard-attest-dogfood-${{ matrix.shard }}-of-4
32253230
path: ${{ runner.temp }}/shard-attestation/
32263231
if-no-files-found: error
32273232
retention-days: 1
@@ -3313,7 +3318,7 @@ jobs:
33133318
# Stable check name for a SHARDED job (#3622 follow-up), a required
33143319
# context again since #30461 (THE TWO SPEEDS above `jobs:`). On a PR both
33153320
# legs skip and this gate counts zero expected attestations; on a
3316-
# queue build (since #30461) the three dogfood shards run and are counted,
3321+
# queue build (since #30461) the four dogfood shards run and are counted,
33173322
# while `dogfood-verify` skips and is judged with zero expected; the full
33183323
# battery runs and counts both. The history below is why the name and the
33193324
# `if: always()` stay.
@@ -3347,7 +3352,7 @@ jobs:
33473352
# undocumented `abandoned` that runner starvation produces, in both of
33483353
# those runs — either paints a false red or, once whitelisted, swallows a
33493354
# sibling's real `failure`. Each of the FOUR legs this context covers
3350-
# (3 dogfood shards + the CLI pass) now publishes its own "I ran and
3355+
# (4 dogfood shards + the CLI pass) now publishes its own "I ran and
33513356
# passed" artifact, and this gate passes only when it counts all four.
33523357
#
33533358
# `cancelled` still passes without counting, for #3668's reason: it is a
@@ -3397,8 +3402,8 @@ jobs:
33973402
- name: Checkout repository
33983403
uses: actions/checkout@v7
33993404

3400-
# One pattern covers both legs: `shard-attest-dogfood-*` matches the three
3401-
# `…-dogfood-<n>-of-3` shard credentials and `…-dogfood-verify-1-of-1`
3405+
# One pattern covers both legs: `shard-attest-dogfood-*` matches the four
3406+
# `…-dogfood-<n>-of-4` shard credentials and `…-dogfood-verify-1-of-1`
34023407
# alike. See test-gate for why continue-on-error and why no new
34033408
# permission is needed.
34043409
- name: Download dogfood attestations
@@ -3426,7 +3431,7 @@ jobs:
34263431
--dir "$OS_ATTEST_DIR" \
34273432
--filter-result "$OS_FILTER_RESULT" \
34283433
--download-outcome "$OS_DOWNLOAD_OUTCOME" \
3429-
--leg "dogfood/3:$OS_DOGFOOD_RESULT" \
3434+
--leg "dogfood/4:$OS_DOGFOOD_RESULT" \
34303435
--leg "dogfood-verify/1:$OS_VERIFY_RESULT"
34313436
34323437
build-core:

‎packages/plugins/plugin-email/src/email-service.ts‎

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
SendTemplateInput,
99
RenderTemplateInput,
1010
RenderTemplateResult,
11+
RenderedTemplateVersion,
1112
NormalizedEmailMessage,
1213
EmailAddress,
1314
EmailDeliveryStatus,
@@ -708,6 +709,14 @@ export interface TemplateLoader {
708709
export interface TemplateLoadOptions {
709710
/** The package the send is made from; absent or `null`, a caller with no package (ADR-0150 D3). */
710711
callerPackageId?: string | null;
712+
/**
713+
* [#39566] Read each locale member's PENDING DRAFT where one exists
714+
* (`RenderTemplateInput.previewDrafts`). Passed by `renderTemplate` alone,
715+
* never by `sendTemplate`: a send reads the published template only. The
716+
* row answered from a draft carries `draft: true`. A loader that cannot read
717+
* drafts answers the published row, unmarked.
718+
*/
719+
previewDrafts?: boolean;
711720
}
712721

713722
/**
@@ -724,6 +733,22 @@ export const TEMPLATE_BUNDLE_LOCALES = Symbol('@objectstack/plugin-email:templat
724733
/** What the built-in loader answers under {@link TEMPLATE_BUNDLE_LOCALES}. */
725734
export type TemplateBundleLocales = (name: string, options?: TemplateLoadOptions) => Promise<string[]>;
726735

736+
/**
737+
* [#39566] The built-in registry loader's second private capability, kept off
738+
* {@link TemplateLoader} like {@link TEMPLATE_BUNDLE_LOCALES}: under this key it
739+
* answers the publish verdict of the pending draft of `(name, locale)` that a
740+
* `previewDrafts` load read — the metadata draft read's `_diagnostics`. Asked
741+
* only for a row marked `draft`, after it rendered.
742+
*/
743+
export const TEMPLATE_DRAFT_VERDICT = Symbol('@objectstack/plugin-email:template-draft-verdict');
744+
745+
/** What the built-in loader answers under {@link TEMPLATE_DRAFT_VERDICT}. */
746+
export type TemplateDraftVerdict = (
747+
name: string,
748+
locale: string,
749+
options?: TemplateLoadOptions,
750+
) => Promise<RenderedTemplateVersion['publishVerdict']>;
751+
727752
/**
728753
* What the loader answers: the render input of one resolved `email_template`
729754
* definition, spelled as the `sys_email_template` columns were — the shape
@@ -741,6 +766,11 @@ export interface EmailTemplateRow {
741766
reply_to?: string | null;
742767
active?: boolean;
743768
variables_json?: string | null;
769+
/**
770+
* [#39566] `true` when the row is the member's pending draft, read only under
771+
* {@link TemplateLoadOptions.previewDrafts}; absent for a published row.
772+
*/
773+
draft?: boolean;
744774
}
745775

746776
export interface EmailServiceOptions {
@@ -1673,6 +1703,7 @@ export class EmailService implements IEmailService {
16731703
*/
16741704
private async resolveAndRenderTemplate(
16751705
input: RenderTemplateInput,
1706+
readsDrafts = false,
16761707
): Promise<{ row: EmailTemplateRow; rendered: RenderTemplateResult }> {
16771708
if (!input?.template) {
16781709
throw new Error('VALIDATION_FAILED: template name is required');
@@ -1699,9 +1730,13 @@ export class EmailService implements IEmailService {
16991730
const bundleLocales = (loader as { [TEMPLATE_BUNDLE_LOCALES]?: TemplateBundleLocales })[TEMPLATE_BUNDLE_LOCALES];
17001731
// [ADR-0150 D3, #31699] The package the send is made from: the name
17011732
// resolves from it, on every rung. Absent, the bare-name meaning.
1702-
const loadOptions: TemplateLoadOptions | undefined = typeof input.callerPackageId === 'string' && input.callerPackageId !== ''
1733+
// [#39566] …and the draft switch, from `readsDrafts` alone — never read off
1734+
// `input`, which `sendTemplate` hands over whole: a send whose input object
1735+
// carries a stray `previewDrafts` still reads the published template.
1736+
const callerOptions: TemplateLoadOptions | undefined = typeof input.callerPackageId === 'string' && input.callerPackageId !== ''
17031737
? { callerPackageId: input.callerPackageId }
17041738
: undefined;
1739+
const loadOptions: TemplateLoadOptions | undefined = readsDrafts ? { ...callerOptions, previewDrafts: true } : callerOptions;
17051740
const locales = preferred && typeof bundleLocales === 'function'
17061741
? await bundleLocales.call(loader, input.template, loadOptions)
17071742
: undefined;
@@ -1848,8 +1883,21 @@ export class EmailService implements IEmailService {
18481883
* format filters included).
18491884
*/
18501885
async renderTemplate(input: RenderTemplateInput): Promise<RenderTemplateResult> {
1851-
const { rendered } = await this.resolveAndRenderTemplate(input);
1852-
return rendered;
1886+
// [#39566, ruling 7407899642] The draft switch is this method's alone; the
1887+
// answer names the version and locale it rendered, and a draft's publish
1888+
// verdict, read after the render so a refused render reads nothing more.
1889+
const readsDrafts = input?.previewDrafts === true;
1890+
const { row, rendered } = await this.resolveAndRenderTemplate(input, readsDrafts);
1891+
const resolved: RenderedTemplateVersion = { version: row.draft === true ? 'draft' : 'published', locale: row.locale };
1892+
if (resolved.version === 'draft') {
1893+
const verdictOf = (this.options.templateLoader as { [TEMPLATE_DRAFT_VERDICT]?: TemplateDraftVerdict } | undefined)?.[TEMPLATE_DRAFT_VERDICT];
1894+
const options: TemplateLoadOptions = typeof input.callerPackageId === 'string' && input.callerPackageId !== ''
1895+
? { callerPackageId: input.callerPackageId, previewDrafts: true }
1896+
: { previewDrafts: true };
1897+
const verdict = typeof verdictOf === 'function' ? await verdictOf(input.template, row.locale, options) : undefined;
1898+
if (verdict) resolved.publishVerdict = verdict;
1899+
}
1900+
return { ...rendered, resolved };
18531901
}
18541902

18551903
/**

0 commit comments

Comments
 (0)