Repository navigation
Commit 78f7160
fix(core): a date macro inside a longer string is a literal on the client too (#36068)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoH1SLb7yGpZj1NnaFvhbT6W)_
Fixes #35754
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 控制台里筛选值若只是「包含」日期宏的一段文字(例如 from {today}
on),改前浏览器会把其中的宏换成日期,改后原样保留,与服务器的读法一致;整值为一个宏的写法照常解析。
- 属于筛选占位符契约一致性的收口:同一个筛选在控制台和服务器上应命中同一批记录。
- 只有把日期宏夹在长文本里当筛选值的作者会看到差异(以前也只在控制台生效、服务器不认),影响面小,可直接撤回本改动恢复旧行为。
- 无。
## What changes
The spec reads a filter value as a placeholder only when the value is
ENTIRELY one wrapped token (`FILTER_TOKEN_WRAPPED_RE` in
`@objectstack/spec/data`: "a value that merely CONTAINS braces (`'acme
{x} deal'`) is untouched, as are `{a}{b}` and `{{x}}`"), and the server
resolver `resolveFilterTokens` in `@objectstack/core` applies that
reading. The client resolver did not: after its whole-value match,
`resolveDateMacros` in `@object-ui/core` ran a second, global replace
over the string, so `'from {today} on'` became `'from 2026-05-25 on'` in
the console and stayed literal on the server. The card's question (which
side is the contract) is answered by the spec text above, so the client
aligns with it.
- `resolveDateMacros` (`ui/packages/core/src/utils/date-macros.ts`): the
global pass is removed. A string resolves only when it is one whole
`{token}` / `${token}`; anything else is returned as written. The header
says so and names the spec reading.
- `substituteTokens` in `ui/packages/core/src/utils/compare-to.ts` (the
previous-period token rename behind `shiftFilterByCompareTo`) had the
same embedded pass. With the resolver fixed alone, `'from {today} on'`
would have been renamed to `'from {yesterday} on'` and then kept
literal, so the comparison query would have filtered on a different
literal from the current one. It now renames only whole-value tokens,
through the file's existing `wholeToken` helper. Same defect class,
mechanical, no other claim on the file, same test family: fixed here
under the bounded in-place rule and declared in the report.
**Caller census** (every non-test caller of `resolveDateMacros` at base
`8145424b`; none relies on the embedded form):
| Caller | What it passes | Effect |
|:---|:---|:---|
| `resolveFilterPlaceholders` (core `filter-tokens.ts`), and through it
every list, grid, chart, dashboard and detail surface | filter trees |
the fix itself |
| `shiftFilterByCompareTo` / `lastPeriodBefore` (core `compare-to.ts`) |
filter trees; `lastPeriodBefore` builds a whole `{last_UNIT_start}` |
aligned (see above); `lastPeriodBefore` unchanged |
| `isUsableDateString` (core `dashboard-filters.ts`) | a dashboard
date-filter value | an embedded macro no longer counts as a usable date;
it never reached the server as one |
| `resolveInitialDateMacro` (plugin-calendar `initialDate.ts`) |
`calendar.initialDate`, which the spec defines as a wrapped token | same
outcome: an embedded string already resolved to a non-date and fell back
to today |
| plugin-dashboard `utils.ts` | re-export only | none |
The card's "page/URL params" hypothesis does not hold: `resolveParam`
inside `resolveDateMacros` is the parameterised date-macro grammar
(`{N_days_ago}` and friends), which the server also resolves
(`parseDateMacroParam`), not page or URL parameters. No dashboard title
or URL template calls this resolver.
## Tests
- New pin
`ui/packages/core/src/utils/__tests__/date-macros.embeddedLiteral-35754.test.ts`:
an embedded fixed macro, an embedded parameterised macro, an embedded
macro beside a whole one in a filter tree (through
`resolveFilterPlaceholders`), a previous-period comparison, and
`{{today}}` all stay literal. CONTROLS: a whole `{today}`, `${today}`
and `{7_days_ago}` still resolve; `'acme {x} deal'` and `{a}{b}` are
untouched.
- **Pin flip (deviation):** `date-macros.test.ts` pinned the embedded
behaviour in two assertions: "leaves unknown tokens untouched and
ignores non-strings" expected `'hello {today} world'` to become `'hello
2026-05-25 world'`, and "accepts both {token} and ${token} forms"
expected `'range: ${last_week_start}..${today}'` to become `'range:
2026-05-18..2026-05-25'`. Both now expect the value as written; the
whole-value `'${today}'` assertion beside them is unchanged.
All runs on head `372f6c1f`.
<details><summary>@object-ui/core suite, type-check, consumers</summary>
```text
pnpm --dir ui exec vitest run --maxWorkers=2 packages/core/
Test Files 245 passed (245)
Tests 4744 passed | 27 skipped (4771)
os-verify-lock: VERDICT command-exit 0
pnpm --filter @object-ui/core run type-check
os-verify-lock: VERDICT command-exit 0
pnpm --dir ui exec vitest run --maxWorkers=2 (new pin + plugin-dashboard DatasetWidget.compareTo.test.tsx + plugin-calendar ObjectCalendar.initialDate-28102.test.tsx)
Test Files 3 passed (3)
Tests 57 passed (57)
```
</details>
<details><summary>Ablation, one leg per fixed file (base file restored,
pin run, HEAD restored and hash-verified)</summary>
```text
== ablate compare-to.ts : globalReplaceMarkers=1 wholeOnlyMarkers=0
x does not rename an embedded macro for a previous-period comparison
Tests 1 failed | 6 passed (7)
restored: hash match
== ablate date-macros.ts : globalReplaceMarkers=1 wholeOnlyMarkers=0
x leaves a fixed macro inside a longer string as written
x leaves a parameterised macro inside a longer string as written
x leaves an embedded macro literal inside a filter tree, beside a whole one that resolves
x does not rename an embedded macro for a previous-period comparison
x leaves a macro wrapped in a second pair of braces as written
Tests 5 failed | 2 passed (7)
restored: hash match
diff HEAD empty: yes
green re-run: Tests 7 passed (7)
```
Both CONTROL cases stay green under both ablations, as controls should.
</details>
## Acceptance notes
- Not filed: the hotcrm reconciliation harness keeps its own date-macro
resolver (`scripts/analytics-reconcile/macros.ts`); read at hotcrm
`e7fe77f`, it has no global replace pass, so nothing there disagrees.
- The client whole-value grammar stays the token-NAME grammar
(`[a-zA-Z0-9_]+`), narrower than the server's recognition grammar. That
is a separate question (what an unknown wrapped value does on the
client) and is not touched here.
## Verification
<details><summary>Derived gates (dispatch-gates --commands, head
372f6c1)</summary>
```text
dispatch-gates --ran: 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN (a DERIVED zero, every row carries its exit code)
all exit 0 except: pnpm --dir ui exec vitest run scripts/ :: exit 1
1 failure, scripts/__tests__/unit-registry-absence-collision.test.ts: 39 app-shell modules
"Failed to resolve entry for package @objectstack/client" (that package was unbuilt in this worktree).
After building @objectstack/client: that file 15/15 passed, VERDICT command-exit 0.
```
</details>
Read first:
1. `ui/packages/core/src/utils/date-macros.ts`, the `walk` string branch
inside `resolveDateMacros`: the whole cut.
2. `ui/packages/core/src/utils/compare-to.ts`, `substituteTokens`: the
comparison-query twin.
3. `ui/packages/core/src/utils/__tests__/date-macros.test.ts`: the two
flipped assertions.
Two-minute check: `pnpm --dir ui exec vitest run
packages/core/src/utils/__tests__/date-macros.embeddedLiteral-35754.test.ts`
from the repo root shows 7 passed.
Seat: `repo:objectstack#7 · os-tesla · session_01L9qibxWPiQYXSf1jxGbN3W`
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibxWPiQYXSf1jxGbN3W)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1647fb3 commit 78f7160
5 files changed
Lines changed: 106 additions & 21 deletions
File tree
- .changeset
- ui/packages/core/src/utils
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
217 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
221 | 224 | | |
222 | | - | |
| 225 | + | |
| 226 | + | |
223 | 227 | | |
224 | 228 | | |
225 | 229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
| |||
183 | 190 | | |
184 | 191 | | |
185 | 192 | | |
186 | | - | |
187 | | - | |
188 | 193 | | |
189 | 194 | | |
190 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
191 | 200 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
206 | 205 | | |
207 | 206 | | |
208 | 207 | | |
| |||
0 commit comments