Repository navigation
fix: protect task data and validate CLI inputs - #1
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa98ceeba7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let data; | ||
| try { data = fs.readFileSync(tasksFilePath, "utf8"); } | ||
| catch (error) { if (error.code === "ENOENT") return []; throw error; } | ||
| const tasks = data.trim() ? JSON.parse(data) : []; |
There was a problem hiding this comment.
Reject empty files instead of treating them as no tasks
When an existing tasks.json is empty or contains only whitespace, this branch treats it as a valid empty task list, so the next mutating command succeeds and overwrites the damaged file. Since application-created empty stores are serialized as [], a blank file indicates invalid JSON and should be rejected and preserved just like other malformed content.
Useful? React with 👍 / 👎.
| if (!Array.isArray(tasks) || tasks.some(t => !t || !Number.isSafeInteger(t.id) || | ||
| t.id < 1 || typeof t.description !== "string" || !statuses.has(t.status)) || | ||
| new Set(tasks.map(t => t.id)).size !== tasks.length) { |
There was a problem hiding this comment.
Validate the required task timestamps
When a persisted row omits createdAt or updatedAt (or stores a non-string value), this predicate accepts the invalid record; list then prints undefined, and later additions preserve the malformed row rather than stopping for recovery. Both required timestamp fields should be validated before returning the task list.
Useful? React with 👍 / 👎.
Corrige los errores silenciosos de lectura/escritura, valida IDs completos y conserva el archivo si su JSON está dañado. Añade seis pruebas de regresión con datos temporales y CI en Windows/Linux con Node.js 22 y 24.
Retira node_modules y el archivo inicial tasks.json vacío del árbol actual; siguen disponibles en el historial. Documenta uso, límites de concurrencia y TASKS_FILE.
Validación local: 6/6 pruebas correctas con Node.js 24.14.0. La ejecución de GitHub Actions debe comprobarse antes de integrar.