docs(forecasting): a supplied period_start is kept, not snapped (#748) - #1009
Merged
Merged
Conversation
The "How periods are derived" section taught both halves of the derivation in two consecutive sentences — "Supply a `period_start` to snapshot a specific quarter or month", then "Because the boundary is always computed, never typed, every snapshot for the same quarter lines up exactly". Read together they promise that any `period_start` a caller sends is snapped onto the calendar boundary. `forecast_derive_period` fills blanks and never rewrites a value that arrived with the record, so a mid-quarter date is stored mid-quarter, labelled Q3 2026, and missed by every surface that pins `period_start` to the quarter's first day. Rewrite the claim to the measured behaviour on all three locale pages, and pin both halves of it in test/hooks-runtime-service.test.ts so the prose goes red with the handler if the derivation ever starts snapping. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VHrPAGEgFDoHjphqYG4BMa
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
yinlianghui
marked this pull request as ready for review
August 7, 2026 02:05
This was referenced Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #748
content/docs/sales/forecasting.mdx「How periods are derived」一节在相邻两句里教了推导的两半:先说「Supply aperiod_startto snapshot a specific quarter or month」,再说「Because the boundary is always computed, never typed, every snapshot for the same quarter lines up exactly」。两句合起来给读者的结论是:手填什么period_start,系统都会把它吸附到日历边界。实现不是这样。本 PR 只动 boundary 措辞这一个面。同页 #732 在决策箱的宣称(Copilot skill 写 forecast 记录 / 存 transcript 一族句子)一字未动。
一、真实行为取证
src/objects/forecast.hook.ts的forecast_derive_period只补空缺,从不改写随记录送进来的值:period_start缺失时才走startOfPeriod(period, anchor)落到日历真实边界(hook.ts:72-82);已给则原样保留,只拿它去推period_end/period_label(hook.ts:84-91)。把真实 handler 跑起来(
test/helpers/hook-harness.ts的makeCtx,beforeInsert),读回input:即:
never typed只对「没填」的那一半成立。手填一个季度中间的日期,行就以那个日期存下来,标签仍是 Q3 2026,而按周期取数的界面全都对不上它——this_quarter_forecasts视图(src/views/forecast.view.ts:78-81)和销售仪表盘的 Quota Attainment by Rep(src/dashboards/sales.dashboard.ts:332)都是拿period_start去和{current_quarter_start}做等值匹配的。另一半(「同一季度的快照严格对齐」)本身是真的,但成立的理由不是「边界从不由人填」,而是推导只在一个地方发生、自动写入方都不自己算:
forecast-snapshot.flow.ts的create_forecast只送period(该节点注释即如此写),src/data/revenue.seed.ts全部用Date.UTC(y, m, 1)。hook 自己的注释措辞是准确的("give the object aperiodand it lands on a calendar-true boundary or not at all"),英文页压缩成never typed时丢掉了这个前提。二、措辞前后对照
三个语言版本(
.mdx/.zh-Hans.mdx/.zh-Hant.mdx)同改,改动位置一致:第 33 行补一处限定、第 39 行重写、其后新增一段。英文页
Supply a period_start to snapshot…→Supply a period_start — that period's own first day — to snapshot…Because the boundary is always computed, never typed, every snapshot for the same quarter lines up exactly — …→Because that derivation lives in one place instead of in every writer, snapshots that leave period_start blank all land on the same boundary and line up exactly — … Every automated writer takes that route: the nightly sweep sends period and nothing else.**What you do supply is kept exactly as you sent it.**—— 派生只补空缺、不改写;送 2026-07-15 就存 2026-07-15,标签 Q3 2026 但起点在季度中间;This Quarter 页签与 Quota Attainment by Rep 都按季度真正的第一天匹配,因此找不到它;手工或 API 写快照时请送该周期的第一天,或干脆不送。zh-Hans(原句已是
因为周期边界始终是算出来的,而不是由每个写入方各自去填…——比英文页克制,但仍留着「始终是算出来的」)因为这套派生只发生在一个地方,而不是由每个写入方各自去算,所有没有自带 period_start 的快照都会落在同一条边界上,严格对齐——…自动写入方走的都是这条路:每晚的定时快照只提交 period,别的什么都不给。**你自己填进来的值会被原样保留。**术语随页内既有译法(派生 / 行 / 仪表盘 / 本季度)。zh-Hant:同样改动,术语随页内既有译法(衍生 / 資料列 / 儀表板 / 本季 /「」引号)。
保留未动:第 41 行「never see a record labelled 2026-07-01 through ???」、以及 #732 一族句子。回调框(blockquote)数量三语仍相等,
docs-drift的 locale callout parity 规则不受影响。三、守卫
单句措辞不值得造文字黑名单式守卫,
docs-drift现有规则面(flow cron 标签 /src/目录引用 / dashboard tile / callout parity / persona / version)也没有能低成本挂上去的面。改为在既有的forecast_derive_periodruntime 用例块里把行为钉住两条(test/hooks-runtime-service.test.ts):无period_start时吸附到日历边界;手填时逐字保留。哪天有人改成「手填也吸附」,第二条转红,这段新写的散文就必须跟着重写。反向验证(先定方向再跑):预测「把 #748 option 3 的契约变更强行装进 hook(对手填
period_start也做startOfPeriod吸附)→ 逐字保留那条转红、日历边界那条保持绿」。实测一致:改动已回退,
src/无任何改动(git diff --stat只含 3 个 docs 页 + 1 个测试文件 + changeset)。需要说明的是:文档散文本身没有测试钉住,所以「把措辞改回去」不会让任何测试变红——这条不做虚报。转红的是行为面那两条钉子。
四、验证
六门(
pnpm verify的组成)全绿:另跑
grep -naP '[\x00-\x08\x0b\x0c\x0e-\x1f]'自扫四个改动文件,无命中。changeset:.changeset/forecasting-docs-typed-period-start.md(patch)。五、范围外发现
行为面的疑点按要求只记录不修,已另开 #1008(
finding,未指派):手填period_start时period_end走的是「起点 + 3 个月」的滚动窗口而非所属日历季度,因此2026-08-15会推出2026-10-31却仍标Q3 2026;并附一条未实测的二级后果(夜间 sweep 以period_start ... today ... period_end选行,可能把这类手工行当成本季度行覆盖)。三种修法都动crm_forecast写入契约,需维护者拍板,故不由本文档单顺手带。Generated by Claude Code