Dynamically check `FsPath` invariants
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- haskell
调研方向
首先阅读 FsPath 的定义以及 pull request 72 中的设计讨论。将提议的 invariant、unsafeFsPathFromList 和 fsPathFromList API 与现有路径行为进行比较,并考虑 force/assert 之间的权衡。完成的标准是就是否需要动态检查达成一致,并定义出在各操作系统之间保持一致的已验证构造和逃生通道构造行为。
由索引模型根据 Issue 内容生成。
描述
First suggested in https://github.com/input-output-hk/fs-sim/pull/72#issue-2337874221. FsPath has a number of invariants, and we currently rely on the user to satisfy them. It might be nice to check these invariants dynamically, while also providing an escape hatch for users in case they want to skip the check. For example:
newtype FsPath = UnsafeFsPath { fsPathToList :: [Strict.Text] }
deriving (Eq, Ord, Generic)
deriving newtype NFData
invariant :: FsPath -> Bool
invariant (UnsafeFsPath xs) = all p xs
where p x = -- Paths are monotonic
x /= ".."
&& -- Paths can not have empty directory/file names
not (any Strict.null xs)
&& -- There are no path separators in individual names
not (Text.any (`Text.elem` allPathSeparators) x)
allPathSeparators :: Text
allPathSeparators = Text.pack (Posix.pathSeparators ++ Windows.pathSeparators)
unsafeFsPathFromList :: [Strict.Text] -> FsPath
unsafeFsPathFromList xs = assert (invariant fsp) $ fsp
where fsp = UnsafeFsPath (force xs)
fsPathFromList :: [Strict.Text] -> Maybe FsPath
fsPathFromList xs
| invariant fsp = Just fsp
| otherwise = Nothing
where fsp = UnsafeFsPath (force xs)
Note two things in the example above:
- Both
unsafeFsPathFromListandfsPathFromListensure that the resultingFsPathcontains no thunks my usingforce. Maybe we want toassertinstead that theFsPathcontains no thunks inunsafeFsPathFromList, and have the user ensure that fact. - To ensure similar behaviour across OS distributions, invariant checks do not depend on the underlying OS distribution, hence
allPathSeparators.
We should also consider whether this design pattern is overkill: in practice, users are probably unlikely to use non-sensible path names
- 主要语言
- Haskell
- 星标
- 2
- 派生
- 6
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
IntersectMBO/fs-sim 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 35/100
IntersectMBO/fs-sim#137 ·
-
难度 1/5 1 小时以内 新手友好度 45/100
IntersectMBO/fs-sim#136 ·
-
难度 2/5 1-3 小时 新手友好度 35/100
IntersectMBO/fs-sim#135 ·
-
No 0.4.1.0 tag未关闭
难度 1/5 1 小时以内 新手友好度 55/100
IntersectMBO/fs-sim#125 ·
-
难度 2/5 1-3 小时 新手友好度 48/100
IntersectMBO/fs-sim#122 ·
查看 IntersectMBO/fs-sim 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 75/100
-
15-minutes 5-minutes algorithm any-language beginner-friendly c cpp csharp easy go good first issue hacktoberfest help wanted java javascript kotlin python rust swift typescript
难度 1/5 1 小时以内 新手友好度 68/100
Huerte/algo-solutions-python#260 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 62/100
IntersectMBO/cardano-ledger#6276 ·
维护者通常 1 天内回复