Skip to content

refactor(events): split services/events.py into a package - #317

Closed
vidit-admin wants to merge 8 commits into
mainfrom
claude/refactor-candidates-unscheduled-e8c3fa
Closed

vidit-admin wants to merge 8 commits into
mainfrom
claude/refactor-candidates-unscheduled-e8c3fa

Conversation

@vidit-admin

Copy link
Copy Markdown
Member

What

Splits `backend/app/services/events.py` (1,493 lines, the largest service module) into a `services/events/` package: one module per write verb plus shared rule modules, with the public API re-exported from the package root so every existing `from app.services import events` import stays unchanged.

Module Contents
`init.py` docstring, module map, re-exports, `all`
`errors.py` the 11 typed exceptions
`coordinates.py` `validate_coordinates`, `_optional_point`
`source_links.py` secondary source link helpers and row builders
`rules.py` publication floors (Python and jsonpath), source-media swap, geolocator credit
`create.py` / `geolocate.py` / `revise.py` / `batch.py` / `close.py` the five write verbs

How

Pure move: the first commit is a `git mv` so git records a rename, then one extraction per commit with the events test suite green at each step. Code moved verbatim; only import headers, module docstrings, and the `init` re-exports are new text. Dependency direction is one-way (`errors` → shared rules → verbs), no circular imports.

One external import changed: `tests/events/test_detections_readiness.py` reaches the private `_publish_detection` from `app.services.events.batch` directly.

Also in this PR

  • `planning/next.md`: removes the duplicate rows a fusion pass left behind (one topic, one row; 33 lines removed) and records the split as landed.
  • `AGENTS.md`: fixes the stale mirror name `services/events._publish_draft` to `services/events/batch._publish_detection`.
  • `docs/design.md`, `docs/engineering.md`: references re-pointed at the modules that now hold the cited symbols.

Checks

Full backend suite 1,420 passed, 3 skipped. `ruff`, `mypy`, `vulture`, jscpd (0.21%) all clean. `services/events.validate_coordinates` and the generated route docstring in `api-types.ts` stay true via re-export, so the api-types drift gate is untouched.

🤖 Generated with Claude Code

vidit-admin and others added 8 commits August 25, 2026 15:22
The merge pass that fused related rows in the Refactors and Unscheduled
tables added the fused rows without deleting the originals. One topic now
has one row, kept at the position of the earliest duplicate. Same cleanup
in the v0.6 table (re-home attribution, clickable handles, the fulfilled
request notification row subsumed by the notifications feed row).

Corrections carried while merging: analyst-helper@vidit.app does not
exist under video/, ArchiveSourceField is really ArchiveSnapshotField,
and three facts the docs fusion had dropped are restored.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pure move, no code change: the module becomes
services/events/__init__.py so the write verbs and the shared rules can
be split into submodules behind the same import surface.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Three leaf modules out of the package root, code moved verbatim: the
typed failures, the coordinate bounds check plus the optional point, and
the secondary source link normalization. The package root re-exports
them, so every caller keeps importing from app.services.events.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
rules.py takes the evidence floor helpers, the proof sanitiser wrapper,
the source-media swap, the tag / conflict resolvers, the geolocation
credit and the SQL readiness predicate, moved verbatim out of the
package root.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
close.py holds the terminal withdraw / reject / retract, batch.py the
per-row detection completion and its module logger. The readiness test
takes the private _publish_detection from its new home and keeps the
public predicate from the package root.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The last three write verbs leave the package root, which is now the
package docstring, a module map, the re-exports and __all__. save_version
lands in revise.py, since services/versions.py already holds that name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
AGENTS.md names the batch floor as services/events/batch._publish_detection,
design.md points the readiness mirror at batch.py and rules.py,
engineering.md states the package shape under the layering section, and
next.md records the split plus the two rows that linked the old file.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The batch floor is named services/events/batch._publish_detection at each
of its five mirrors (the detections router docstring and the api-types it
generates, lib/events.ts, lib/events.test.ts, the readiness suite, and the
next.md removal row), the tag floor points at services/events/rules.py and
the coordinate bounds at services/events/coordinates.py. The package
docstring counts four shared modules, and the changelog records the split.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@vidit-admin

Copy link
Copy Markdown
Member Author

Superseded by #371, rebuilt against the current events.py.

@vidit-admin vidit-admin closed this Oct 3, 2026
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.

1 participant