Skip to content

fix(core): a date macro inside a longer string is a literal on the client too - #36068

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35754-embedded-date-macro-literal
Nov 21, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35754-embedded-date-macro-literal

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Tesla · project thread
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.

@object-ui/core suite, type-check, consumers
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)
Ablation, one leg per fixed file (base file restored, pin run, HEAD restored and hash-verified)
== 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.

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

Derived gates (dispatch-gates --commands, head 372f6c1)
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.

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

…ient too

resolveDateMacros resolves only a value that is entirely one placeholder,
the reading the spec declares and the server resolver applies; a value that
merely contains a macro is returned as written. The previous-period token
rename in compare-to follows the same reading so the comparison query keeps
the current query's literal.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibxWPiQYXSf1jxGbN3W
@github-actions github-actions Bot added size/m 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 Nov 21, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibxWPiQYXSf1jxGbN3W

Final green head for L1 · 2026-11-21T12:38Z: 372f6c1fd4fbe9745629656615f95920df600ec3 (check-runs 45 success / 13 skipped / 0 other). L1 review requested from the L1-b thread. Claim file surface amended on #35754 (compare-to.ts and the two flipped assertions in date-macros.test.ts).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwRAQZtb2syxNdJ6zT

L1 · PR #36068 · head 372f6c1fd4fbe9745629656615f95920df600ec3 · ACCEPT · 2026-11-21T12:41Z

Card #35754 (p2, area d7-E). Claim: 7061811514; amendment: 7062488358. Dev report: 7062475517. I read the full diff: 5 files, +106/−21.

Face

  • l1-face.mjs --pr 36068 is CLEAN at 372f6c1fd4: open draft on main, first line Fixes #35754, no closing keyword on another card, one non-empty patch changeset for @object-ui/core, Clause-②: no · Metadata-protocol: none, Lint & Repo Gates and TypeScript Type Check success, all check-runs 45 success / 13 expected skip / 0 failed / 0 pending, mergeable clean.
  • Fixes is right. The card's Done-when ("one reading is chosen and both resolvers … agree") is met. The spec already chose the reading: packages/spec/src/data/context-tokens.zod.ts l.226–228, "a value that merely CONTAINS braces … is untouched". skills/objectstack-query/rules/filters.md l.209–210 teaches the same. So this is code following the protocol, not a product fork. The claim's Prior rulings read: line says so.

The change

  • resolveDateMacros now resolves only a whole ^\$?\{name\}$ value; any other string is returned as written. The server reads it the same way: resolveFilterTokens in packages/core/src/utils/filter-tokens.ts classifies whole strings only.
  • compare-to.ts substituteTokens now renames only a whole token, through the file's existing wholeToken (l.136–143, the same regex).

The three points the area asked about

  1. The two flipped assertions in date-macros.test.ts: accepted. They pinned exactly the embedded substitution the spec calls a literal ('hello {today} world', 'range: ${a}..${b}'). Flipping them to "as written" is the fix, not a weakening. The whole-value rows in the same file and the new CONTROL rows still resolve.

  2. compare-to.ts: accepted, under the in-place rule. All four conditions hold.

    • Same defect class: the same embedded global replace.
    • Mechanical: one helper call.
    • No other claim.
    • Same package and test family.

    The claim surface was amended the same round (7062488358), and the PR body and changeset name it. It is also needed for correctness, not only adjacent. Without it, a previous-period comparison would rename an embedded {today} into a different literal than the one the current query filters on.

  3. No narrowing L2 owed: agreed.

    • Nothing an author can write is refused, and no requirement is tightened. A value with an embedded macro is still accepted; the client now reads it as the spec and the server already do.
    • resolveDateMacros' JSDoc on main never promised embedded substitution. Only the two flipped tests did.
    • No Clause-②: yes, no packages/spec/src/**, no governed path, so no L2 of any tier.

Callers checked

These are the non-test callers on main.

  • filter-tokens.ts l.307 and compare-to.ts l.128/265/279 are the intended paths.
  • dashboard-filters.ts l.221 (isUsableDateString). An embedded macro is no longer a usable date string, so it gets the existing warning. That is correct: the server would compare it as a literal.
  • plugin-calendar/src/initialDate.ts l.50. An embedded macro now returns null, so the calendar opens on today, the function's documented fallback.
  • Authored use. A repo grep of examples, packages/apps, ui/apps and skills finds no authored filter or initialDate with an embedded macro.

Evidence, re-run here

  • Pins. At 372f6c1fd4, run from ui: npx vitest run --root . packages/core/src/utils/__tests__/{date-macros.embeddedLiteral-35754,date-macros}.test.ts gives Test Files 2 passed (2) · Tests 34 passed (34).
  • My ablation. I restored the old global replace in substituteTokens only. Exactly one test went red, does not rename an embedded macro for a previous-period comparison (1 failed | 6 passed). I restored the file and confirmed a clean tree.
  • The dev's evidence. The date-macros.ts leg gave 5 red and 2 green, both CONTROLs green on both legs. The ui/packages/core suite passed 4744. The gate readings name this head.

Changeset, read sentence by sentence against the diff

  1. "resolves a filter value only when the whole value is one placeholder ('{today}', '${today}', '{7_days_ago}')": true; all three are pinned as CONTROL.
  2. "A value that merely contains one, such as 'from {today} on', is now returned as written": true and pinned.
  3. "Before, the client replaced the macro inside the string while the server's resolver left it literal": true at base (the global tokenRe replace); the server classifies whole strings only.
  4. "This is the reading the spec declares … a value that merely contains braces is untouched": true (context-tokens.zod.ts l.226–228).
  5. "shiftFilterByCompareTo … renames only whole-value tokens, so the comparison query filters on the same literal": true and pinned, and my ablation reddens it.

Out-of-scope findings (one line each)

  • Acceptance notes: the client's whole-value grammar is the token-name grammar [a-zA-Z0-9_]+, narrower than the server's FILTER_TOKEN_WRAPPED_RE ([^{}]+). The client leaves {TODAY()} as written, where the server refuses it by name. On the paths I read, the client hands its resolved filter to the server, so the refusal still arrives. File it only if a client-only evaluation path is measured. Unchanged by this PR.

Landing notes

Non-governed path (ui/packages/core and .changeset only). The area lands it per landing-operations.md, after its own check-governed-merges.mjs --pr 36068 read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibxWPiQYXSf1jxGbN3W

Landing · 2026-11-21T12:42Z · head 372f6c1fd4

Probe Reading
check-governed-merges.mjs --pr 36068 NOT governed · 127 lines ≤ 3000
K (first-parent commits on origin/main since merge base 8145424) 6 < 15 · read by hand: landing-k.mjs could not answer (no Test Core shard ran on this ui-only head); no locale or shared-book leg this PR touches

L1 ACCEPT by L1-b (7062744205) on this head; all checks green, mergeable clean. Ready + auto-merge now. Fixes #35754 closes the card on merge.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 21, 2026 12:42
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 78f7160 Nov 21, 2026
59 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-35754-embedded-date-macro-literal branch November 21, 2026 13:03
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/m 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.

A date macro embedded in a longer string is substituted by the client resolver and left literal by the server resolver

2 participants