Skip to content

fix: resolve file deletion conflict, empty paths, timestamp comparison and event mutation (#149) - #151

Open
ranadheer-designs wants to merge 1 commit into
tscircuit:mainfrom
ranadheer-designs:fix/file-event-consistency-defects
Open

ranadheer-designs wants to merge 1 commit into
tscircuit:mainfrom
ranadheer-designs:fix/file-event-consistency-defects

Conversation

@ranadheer-designs

Copy link
Copy Markdown

Fixes #149
/claim #149

Summary

Resolves four file and event consistency bugs in file-server:

  1. Conflicting delete selectors (routes/files/delete.ts):
    • Supplying both file_id and file_path now returns HTTP 400 ("Provide only one of file_id or file_path"), preventing ctx.db.deleteFile from deleting two files in a single request.
  2. Empty file path validation (routes/files/upsert.ts & routes/files/rename.ts):
    • Validates normalizePath(file_path) and normalizePath(new_file_path). If it resolves to empty (such as "" or "/"), returns HTTP 400 with descriptive error ("file_path must name a file" / "new_file_path must name a file").
  3. Timestamp instant comparison (lib/db/db-client.ts):
    • listEvents now compares since using Date.parse() epoch numbers rather than lexicographical string comparison, so timestamps with timezone offsets (e.g. +02:00, -01:00) evaluate accurately.
  4. Event snapshot immutability (lib/db/db-client.ts):
    • renameFile now returns a newly allocated events array [...state.events, createdEvent, deletedEvent] instead of mutating state.events in-place, preserving earlier snapshots.

Tests

Added 4 dedicated regression test suites:

  • tests/routes/selector-conflict.test.ts: verifies conflicting delete selectors return 400 and preserve both files.
  • tests/routes/empty-file-path.test.ts: verifies empty or root file paths on upsert and rename are rejected with 400.
  • tests/routes/event-timestamp.test.ts: verifies since correctly filters events with timezone offsets.
  • tests/rename-events.test.ts: verifies renameFile preserves previous event array snapshots.

All 33 tests pass locally with bun test and typecheck passes with bunx tsc --noEmit.

@ranadheer-designs

Copy link
Copy Markdown
Author

cc @seveibar @looternikhil-cpu (issue author)

All CI checks are passing (3/3 green). Fixes #149 covering the 4 consistency fixes (delete selector conflict handling, empty path validation, timestamp parsing with timezones, and event snapshot immutability) with dedicated regression tests.

Ready for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Four reproduced file/event consistency defects with tested fixes

1 participant