fix(doc-repo): case-insensitive re-ingest/retract status guard (#831)
Root cause
dataprep persists dataprep.status capitalized ('Ingested', 'Retracted') via _update_doc_status, and the /status Joi schema only accepts capitalized values. But the doc-repo ingest/retract guards compared against lowercase ('ingested' / 'retracted'), so the ingest guard never matched an already-ingested file.
Because re-ingestion was never blocked, ingest_file_with_guardrail re-inserted chunks for an already-ingested file_id without retracting the old ones first. Old chunks (with old labels) therefore remained and the duplicate insertion raised _key conflicts → "changing the file labels doesn't delete the old ones, leading to errors in ingesting".
Fix
Compare the status case-insensitively so both guards fire regardless of stored casing:
-
fileController.js:977— ingest guard (the bug) -
fileController.js:1060— retract guard (same root cause, prevents recurrence)
Blocking behavior preserved. To apply new file labels to chunks: retract → re-ingest.
Verification
- ESLint: clean
- Prettier: clean
- doc-repo suite: 402/402 pass, 17/17 suites
- New unit tests cover the canonical capitalized status (
'Ingested') and the case-insensitive path
Closes #831 (closed)