Skip to content

refactor: typed Option consumption / Option 在类型化消费边界内处理 - #117

Merged
tiye merged 4 commits into
mainfrom
fix/typed-member-user-keys
Oct 16, 2026
Merged

tiye merged 4 commits into
mainfrom
fix/typed-member-user-keys

Conversation

@tiye

@tiye tiye commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

从使用 Timegrass 的角度看,成员列表继续保留访客、空用户名和真实 session key;升级后非法姓名仍以原错误拒绝。本次改进让 Calcit 沿 Map 方法保留泛型值类型,并在字段、路由、日期和 cursor 的消费边界内直接处理 Option,避免先擦回 nil 再继续传递。应用数据、通信格式、检查顺序和服务配置不变。

中文

Refs calcit-lang/calcit#2080,后续于 #115(已由外部合并)。

修改

  • twig-members 保留原 Map<K,Map<Tag,S>> / Map<String,Map<Tag,U>> 输入和 Map<K,String> 输出合同。先将用户标识收窄为 String,然后使用现有 .get 方法读取用户和姓名;不增加生产 Dynamic、unsafe、公共 API 或业务默认值。
  • 沿用已批准的“访客”展示边界:缺失/非 String 用户标识、未知用户、缺失或 nil 姓名仍显示访客;空标识仍可查到对应用户,空姓名仍显示空字符串。非 nil 的非法姓名仍由同一个 String 解码器拒绝。
  • 保留原测试原样,新增两组 definition :tests,覆盖 Number/String session key、缺失/nil/false/0/true/Tag 用户标识、空标识/姓名与非法姓名的完整错误文本。
  • 既有 JS 运行器回放这四组同源测试,不新建运行器、不复制语义断言。README 使用中文说明边界。
  • 另外将 10 个定义中 31 处已有解码器移入原 Option 的选中分支:保留原读取、类型参数、解码器与执行位置,None 仍由同一解码器接收 nil;没有用默认值、unwrap 或手写错误代替原失败。类型参数已核对为无效果、无捕获的类型表达式。路由未选中字段、事件回调和 Respo 提前失败顺序不变。
  • 增加四组真实消费处 :tests,验证 history/notes 路由的缺失及非法载荷、overview cursor 和 note 时间的完整原错误;同一组在修改前后回放。原测试完全保留。新增验收用例开发中补齐 HistoryRoute 原有 start/end 必需字段,并按原 Respo >> 早期错误修正新 cursor 用例;不修改运行时或旧预期。
  • 条件判断直接得到 Bool,保留原真值行为,不把开放 state 字段本身冒充为已验证 Bool。按键缺失的固定 String 比较明确为 false;Some 分支保留原比较与 and 的短路顺序。路由名直接分派 Option,保留原 Tag 分支、默认错误及空投影;任务排序在选择后解码 Number,nil/false 回退与未选中 created-time 的惰性不变。
  • 再增加三组定义测试:有效时间的完整失败文本与未选中坏时间、路由名选择及未选中 payload、真实 overview 键盘回调的 13 种事件和派发异常传播。原排序三组测试保留,既有运行器将四组全数选中;不新增运行器或更改原断言。
  • 个人页与备份路径的三个 String 消费点直接处理 Option;其他 str 参数经核对均为纯字面量,原时钟/字段读取顺序不变。消息删除入口直接绑定 Result<String,String>,不先暂存 nil-or-Dynamic;notes 在原空 Map 回退边界保留 Map 后再验证,仅合并同一个不可变 Map 上两次无效果的相同读取。
  • 再增加三组定义测试,覆盖真实个人页的六种问候文本、旧 Map 消息 ID 的完整错误/空 String,以及 native notes 缺失/nil/false/0/空字符串/List/空 Map。只在新增 fixture 中用原解码器明确开放 wire Map,未改生产类型。完整 twig 依赖 native std 日期/dylib:新 JS 回放尝试在 Date0 依赖处失败后,保留其全部 native 测试,不添加 stub 或把它宣称为 JS 已验收;其余新增 UI/协议组通过现有 JS 运行器回放。

验证

  • 正式 CLI / @calcit/procs 0.30.1-alpha.4,依赖与版本不变。
  • 新旧实现分别通过同一组 4/4 native 及同源 JS 测试;保留所有原断言和输入。
  • 正式 CLI 独立 type-at:用户名表达式为 String(exact,无 expected-type);用户读取为 Option<Map<Tag,U>>,.get 静态方法 lowering 成功,保留 U 而非退回 Dynamic。
  • 解码改写与后续选择改写分别完成改前/改后对照:Dayjs 20 组 / 84 项,以及 20 组 / 86 项与宿主检查均通过,排序与标题运行器也在改前改后通过。改后 full strict workflow passed,diagnostics 为空;native 147/147、client 47/47;标题/登录/容器、session/wire、typed database、隐私与持久化检查通过。
  • 独立 type-at 给出 Bool/exact、Result<HistoryRoute,String>/exact,且无 expected-type 注入;cursor 仍是 List/partial,未把未知元素类型宣称为精确。没有扩大原生产类型合同。
  • 后续选择表达式独立推断为 Bool、Number、Result<Route,String>(均 exact、无 expected-type)。初次显式 String/nil 常量比较被 strict 拒绝后,按已证明的缺失按键语义改为 false;没有放宽检查、扩大类型或改测试。
  • 最新叶子消费改前/改后支持范围内 JS 为22组/109项;原 native twig9/9与消息解码22/22在改前通过。改后 full strict passed/diagnostics[]、native149/149、client48/48,既有完整业务检查、双端codegen、production build、format和AST审计通过。独立推断为String与Result<String,String>/exact;notes容器仍是Map<String,Map<Tag,Dynamic>>/partial,不宣称内部字段已全部定型。备份路径仅有上述原位纯字面量转换证明及既有构建检查,没有新增不稳定的跨午夜时钟测试。
  • 客户端/服务端代码生成、production build、规范格式与完整 Snapshot AST delta 审计通过。审计仅模型化新增边界与两组测试,其余 schema、测试、示例、imports/config 不变。旧 require 标记及 Vite chunk-size warning 保留。

本 PR 不操作生产环境,不使用 #115 的旧人工 review 代替新 HEAD review。远端 CI/审查、最终维护版本配对与其余消费者迁移仍须完成;不宣称 0.30.1 已可稳定发版。

English

Refs calcit-lang/calcit#2080; follow-up to the externally merged #115.

Change

Keep twig-members' existing generic input/output contracts. Narrow user identifiers to String before the existing typed Map .get calls. Preserve generic user/name values until the original String decoder consumes a name. No wider production Dynamic, unsafe, new public API or chosen business default.

Preserve the approved guest behavior for missing/non-String identifiers, unknown users and missing/nil names. Empty identifiers remain valid lookup keys; empty names remain empty. Other invalid names still produce the same full String decoder error. Keep original tests unchanged, add two definition-attached groups, and replay the same four groups through the existing JS runner. User documentation is Chinese.

Also move 31 existing decoder calls across10 definitions into the selected Option branch, preserving the original lookup, pure/non-capturing type arguments, decoder and evaluation point. None still passes nil to the same decoder, not a chosen default, unwrap or hand-written error. Preserve unselected-route laziness, callback timing and earlier Respo errors. Add four attached regression groups for missing/invalid route payloads, overview cursors and note timestamps. During development, correct only new fixtures to include HistoryRoute's existing start/end fields and respect the earlier Respo cursor failure; no original test expectation/runtime changes.

Consume UI/keyboard decisions as Bool without claiming the original open state fields are validated Bool. Preserve truthiness and short-circuiting; a missing key cannot equal the fixed String literal and yields false, while Some retains the original comparison. Dispatch route-name Options through the original literal Tag/default branches. Decode the selected sort timestamp as Number, retaining nil/false fallback and unselected-created-time laziness. Add three attached groups for complete time errors, literal route selection,13 actual keyboard inputs and dispatch-error propagation. Keep the original three sort groups and extend the existing runner to select all four.

Consume three profile/backup String leaves directly; other str arguments are verified pure literals and clock/field evaluation order is unchanged. Bind checked Result<String,String> directly for legacy message-ID Maps. Keep the notes Map through its existing empty-Map fallback and decoder; combine only identical effect-free reads of the same immutable Map. Add three attached groups for six real greeting displays, complete legacy message-ID errors/empty Strings, and native notes boundary values. Clarify the open wire Map only in a new test fixture, not production types. Full twig projection depends on native std dates/dylib: an attempted new JS replay failed at its Date0 dependency; retain every native test and do not introduce a stub or claim JS acceptance. Replay supported UI/protocol groups through the existing JS runner.

Verification

Use the published matching CLI/procs 0.30.1-alpha.4; no dependency/version changes. The unchanged and revised implementations both pass the same 4/4 native tests and JS replay. Independent CLI type-at infers String with exact evidence and no expected type, and Option<Map<Tag,U>> with specialized .get lowering; generic U is retained.

Before/after replay passes for both stages: Dayjs20 groups/84 tests for decoder changes and20 groups/86 for selection changes, plus original host checks and the title/sort runner. Afterward, full strict passes with empty diagnostics; native147/147, client47/47; title/login/container, session/wire and typed-database/privacy/persistence checks pass. Independent type-at gives exact Bool and Result<HistoryRoute,String> without an expected-type assertion; cursor remains coarse List/partial, not a claim about precise elements. Later selection expressions independently infer exact Bool, Number and Result<Route,String>, with no expected type. Strict rejected an initial explicit String/nil comparison; replace only its proven-false absence branch, without weaker checking, wider types or changed tests. Client/server codegen, production build, canonical format and whole-Snapshot delta audit pass. The audit verifies every original consumer and precise replacements, freshness, effect-free type arguments and preserved control context. Original schemas/tests/examples/imports/config remain intact except the stated additions/body refinements. Existing require-marker/chunk warnings remain disclosed.

No production operation. #115's earlier human review does not approve this new HEAD. Remote CI/review, the final maintenance pair and remaining consumer migration gates still apply; this does not claim stable0.30.1 readiness.

Latest leaf-stage before/after JS replay passes22 groups/109 tests; unchanged native twig9/9 and message decoder22/22 pass before modification. Afterward full strict passes with empty diagnostics, native149/149 and client48/48, plus original business checks/codegen/build/format/audit. Independent inference is exact String and Result<String,String>; notes remains partial Map<String,Map<Tag,Dynamic>>, not a claim of fully typed contents. Backup-path evidence is the original-position pure-literal transformation and existing build checks, not a new flaky clock/midnight integration test.

@tiye

tiye commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

Please review the latest HEAD. This preserves generic member lookup values and the existing guest/String-decoder behavior, with the same attached native/JS tests passing before and after. No production or dependency changes.

@tiye tiye changed the title refactor: retain typed member lookups / 成员读取保留泛型与 String 边界 refactor: typed Option consumption / Option 在类型化消费边界内处理 Oct 16, 2026
@tiye

tiye commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

Latest HEAD 86ec724 adds branch-local consumption for31 existing decoder calls across10 definitions. All original tests/schemas are retained. Four additional actual-consumer groups and the same20-group/84-test JS replay pass before/after; full strict,145 native,45 client and existing application checks pass. Please review this latest HEAD rather than the earlier member-only commit.

@tiye
tiye merged commit 9e9cac3 into main Oct 16, 2026
1 check passed
@tiye
tiye deleted the fix/typed-member-user-keys branch October 16, 2026 17:41
@tiye

tiye commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

中文:补充合并后验收:精确 main 9e9cac3 的 Upload 38941640793 completed/success。b31ec64 快照使用已发布 0.30.1-alpha.4 CLI/procs、WSS 0.2.36 的隔离浏览器/native 服务,验证注册、任务创建/编辑/Done/Put back、Clear 只关闭菜单、笔记创建/编辑与初值、刷新自动登录、独立访客显示;持久化后停止并重启本地服务,任务/笔记恢复,完整 DB 导出 deepEqual。刻意停服窗口有预期 WS 断连,恢复后无新增 error。本地测试端口/标签已关闭。未执行生产切换或重启,也不把本次 alpha.4 验收冒称最终维护版配对。

English: Post-merge acceptance: exact main 9e9cac3 Upload 38941640793 completed/success. The b31ec64 snapshot passed isolated browser/native acceptance with published 0.30.1-alpha.4 CLI/procs and WSS 0.2.36: registration, task editing/Done/Put back, Clear only dismissing menus, note editing/prefill, refresh login and a separate guest. After persistence and local service restart, tasks/notes recovered and complete exported DBs were deepEqual. Expected WS errors occurred only during deliberate downtime; none were added after recovery. Local test ports/tabs are closed. No production switch/restart was performed; this is not final maintenance-pair acceptance.

@tiye

tiye commented Oct 18, 2026

Copy link
Copy Markdown
Member Author

中文:获授权的独立完整补审

维护者现已明确授权独立 agent 补审此前保留待审的最终提交。本次实际审查精确 31e03483dcfaa486caa83ee39c7993922ac4bfbe → b31ec64c97fe02a970833311bbde2b4be199f787,完整覆盖 README、Snapshot、check-dayjs-adapter、check-title-contract 四文件;未发现需要修复的回归,不是用 #115/#118 的 review 替代本单。

审查者通过 CLI 比较全部22个namespace AST:无定义增删、无schema改动,原194个附带测试的代码/名称/tag逐项不变,新增12个;逐项核对15个业务定义的 Option/Some nil/false/0/空String、访客及泛型key、解码与异常位置、路由/时间惰性、事件延迟读取、存储和备份顺序。新测试实际使用断言,原JS运行器重放同一AST,没有日期stub冒充支持。

本次独立实跑的是 git archive 提取的精确b31ec64,使用原正式alpha.4 CLI/procs及Node24:完整strict --verify passed、diagnostics/suggestions空;client/server检查通过;client48、server149测试均零失败;原Dayjs与title运行器通过。精确HEAD原CI38940271973 success,构建/生成JS步骤成功。本次不冒称alpha.5、当前main或生产复跑。

限制:未重新安装依赖、重跑构建/其余两个JS脚本、浏览器、原生重启或生产;既有记录与本次复跑明确分开。原checkout仍0b278791且clean;精确head副本Snapshot blob2464e3d48ef2d8081ea0f777ff17abd6b302b9f9未变。没有提交、推送、部署、重启或服务监听。管理员生产配对门槛按维护者最新决定保留。

English: authorized independent full supplementary review

The maintainer now explicitly authorized an independent agent to review the previously held final commit. Actual review covers the exact base/head above and all four complete files, with no regressions requiring fixes. This does not reuse #115/#118 approval.

CLI AST comparison covers all22namespaces: no definition additions/removals or schema changes; all194original attached tests retain code/names/tags, with12new groups. Review checks all15business-definition refinements for Option/present nil/false/zero/empty Strings, guests/generic keys, decoding/failure position, lazy route/time selection, delayed event reads and storage/backup order. New tests assert outcomes and existing JS runners replay the same AST without date stubs.

Actual independent reruns use an archived exactb31ec64 with its original published alpha.4 CLI/procs and Node24: full strict --verify passes with empty diagnostics/suggestions; both entry checks pass; client48/server149tests have zero failures; original Dayjs/title runners pass. Original exact-head CI38940271973 succeeds, including build/generated-JS steps. This is not claimed as alpha.5/current-main/production rerun.

No dependency reinstall, new build/remaining two JS scripts, browser/native restart or production run was performed in this supplementary review. Original checkout stays0b278791/clean and the exact-head Snapshot blob above is unchanged. No commit/push/deployment/restart/listener. The administrator production-pair gate remains explicitly required.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant