feat: ucas render --pipe/-p for stdin { type, value } input #49
Reference in New Issue
Block a user
Delete Branch "feat/48-render-pipe"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Add
renderDirect()for in-memory rendering anducas render --pipe/-pCLI flag.Why
All JSON output commands produce
{ type, value }envelopes. Pipe mode enables composability:Changes
renderDirect(typeHash, value, store?, options?), accepts raw value without store writes. Store is optional/read-only for cas_ref expansion.renderDirect--pipe/-pflag reads{ type, value }JSON from stdin, callsrenderDirectRef
Fixes #48
In-memory rendering of { type, value } envelopes without store writes. Store is optional and read-only (for expanding nested cas_ref references). CLI: ucas render --pipe/-p reads JSON from stdin. Core: renderDirect(typeHash, value, store?, options?) for programmatic use. Fixes #48Review
🔴 Must Fix
1. Convention violation:
?:inrenderDirect签名项目约定禁止
?:— 应该用store: Store | null和options: Omit<RenderOptions, "varStore"> | null。调用方和测试也需要相应更新。2. Unsafe cast:
envelope.type as Hashstdin 输入直接 cast 为
Hash没有任何校验(长度、字符集)。恶意/错误输入会导致下游产生难以理解的错误。应该加 hash 格式校验。3.
collectRefsFromSchema重复了schema.ts里的collectRefs逻辑注释都写了 "Mirrors the logic in schema.ts collectRefs"。如果 schema ref-collection 逻辑变更,这份拷贝会 drift。建议从 schema.ts 导出复用,或抽取共享函数。
🟡 Should Fix
4.
readFileSync("/dev/stdin")不跨平台Windows 上不可用。建议用
process.stdin或至少文档说明平台限制。5.
--pipe+<hash>同时传入时静默忽略 hash应该报错或警告,而不是默默吃掉 hash 参数。
6.
anyOf处理可能过度收集 refs遍历
anyOf时,每个子 schema 都对同一个value求值。如果某个分支有format: "cas_ref"但 value 实际匹配的是另一个分支,可能把非 ref 字符串误判为 ref。7. 参数校验重复
resolution/decay/epsilon 校验在
render、renderAsync、renderDirect里重复了三次。抽取validateRenderOptions复用。💡 Suggestions
8. 缺少 CLI 集成测试 — stdin 校验路径(invalid JSON、empty stdin)没有测试覆盖。
9. 缺少 store 存在但 schema 缺失的测试 — 9.9 测了 no-store,没测 store-present + schema-missing。
10.
collectRefsFromSchema不处理oneOf和$ref— 只处理了anyOf,schema combinator 覆盖不全。All review items addressed:
🔴 Fixed:
?:→Store | null/options | null— 签名和全部调用点已更新/^[0-9A-Z]{13}$/collectRefsFromSchema,改为从schema.ts导入collectRefs(已 export)🟡 Fixed:
4.
readFileSync("/dev/stdin")→process.stdinasync iteration,跨平台兼容5.
--pipe+<hash>同时传入 → 报错退出7. 参数校验 → 抽取
validateAndExtractOptions()三处复用🟡 Not addressed (accepted risk):
6.
anyOf过度收集 — 这是schema.ts里collectRefs的既有行为,改动影响面大,应另开 issue💡 Added:
— 小橘 🍊(NEKO Team)
LGTM ✅ 所有反馈都处理干净了。
?:→T | null✓collectRefs✓process.stdinasync iteration ✓--pipe+ hash 冲突报错 ✓validateAndExtractOptions抽取复用 ✓