逐行解析 JSONL。 崩溃安全: 跳过空行和解析失败的行。 CC 的保证: 最多丢失最后一行(写入被中断的行)。
(path: Path)
| 157 | |
| 158 | @staticmethod |
| 159 | def _read_entries(path: Path) -> list[StorageEntry]: |
| 160 | """逐行解析 JSONL。 |
| 161 | |
| 162 | 崩溃安全: 跳过空行和解析失败的行。 |
| 163 | CC 的保证: 最多丢失最后一行(写入被中断的行)。 |
| 164 | """ |
| 165 | if not path.exists(): |
| 166 | return [] |
| 167 | |
| 168 | entries: list[StorageEntry] = [] |
| 169 | with open(path, "r", encoding="utf-8") as f: |
| 170 | for line in f: |
| 171 | line = line.strip() |
| 172 | if not line: |
| 173 | continue |
| 174 | try: |
| 175 | entries.append(StorageEntry.model_validate_json(line)) |
| 176 | except Exception: |
| 177 | continue # 跳过损坏的行 |
| 178 | return entries |
| 179 | |
| 180 | @staticmethod |
| 181 | def _rebuild_chain(entries: list[StorageEntry]) -> list[StorageEntry]: |
no test coverage detected