Skip to content

fix(milestones): enforce valid status transitions with state machine …#199

Open
AnoukRImola wants to merge 2 commits intoDisciplr-Org:mainfrom
AnoukRImola:task/milestones-transitions
Open

fix(milestones): enforce valid status transitions with state machine …#199
AnoukRImola wants to merge 2 commits intoDisciplr-Org:mainfrom
AnoukRImola:task/milestones-transitions

Conversation

@AnoukRImola
Copy link
Copy Markdown

@AnoukRImola AnoukRImola commented Mar 29, 2026

fix(milestones): enforce valid status transitions with state machine and logging

Closes: #121

Summary

  • Added a pure milestone state machine (milestoneTransitions.ts) with
    chain-aligned statuses: pending | in_progress | completed | failed
  • Rewrote milestones.ts service to be repository-backed (async, DB-driven)
    instead of in-memory
  • Extended milestoneRepository.ts with getById and allCompletedByVault
    methods
  • Added PATCH /:id/transition endpoint with RBAC (VERIFIER/ADMIN for
    terminal states)
  • Kept PATCH /:id/verify as legacy alias that transitions to completed
  • Updated vaultTransitions.ts to use allMilestonesCompleted() (async,
    DB-backed)
  • Removed conflicting migration 20260226014238_create_milestones_table.cjs
  • Added observable logging on transitions (success, rejection, auto-complete)
    without leaking PII
  • Fixed pre-existing issues in vaults.ts, vault.service.ts, and knex.ts
    (dead code, duplicate exports, bad merge artifacts)

Valid transitions

pending → [in_progress]
in_progress → [completed, failed, pending]
completed → [] (terminal)
failed → [] (terminal)

Files changed

File Action
src/types/milestone.ts Rewritten — chain-aligned types,
VALID_TRANSITIONS, TERMINAL_STATUSES
src/services/milestoneTransitions.ts New — pure state machine
src/repositories/milestoneRepository.ts Extended — getById,
allCompletedByVault
src/services/milestones.ts Rewritten — repository-backed CRUD +
transitions
src/routes/milestones.ts Updated — async handlers, transition endpoint,
logging
src/services/vaultTransitions.ts Updated — async, uses
allMilestonesCompleted()
src/services/expirationScheduler.ts Updated — async callback
src/routes/vaults.ts Fixed — dead code, duplicate routes, duplicate
imports
src/services/vault.service.ts Fixed — removed duplicate class from bad
merge
src/db/knex.ts Fixed — removed duplicate export block
src/tests/milestoneTransitions.test.ts New — 13 unit tests
src/tests/vaultTransitions.test.ts Updated — mocked milestones service
db/migrations/20260226014238_create_milestones_table.cjs Deleted —
conflicted with chain-aligned migration

Test plan

  • milestoneTransitions.test.ts — 13/13 passing (valid, invalid,
    terminal, unknown)
  • vaultTransitions.test.ts — 18/18 unit tests passing (state machine +
    helpers)
  • 14 HTTP integration tests have pre-existing failures (ESM + session.ts
    db mock issue, unrelated to this PR)

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 29, 2026

@AnoukRImola Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@1nonlypiece
Copy link
Copy Markdown
Contributor

Please resolve the conflicts

@AnoukRImola
Copy link
Copy Markdown
Author

Please resolve the conflicts

Ready

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.

Milestones route: status transitions audit

2 participants