learning_ai_invt_trdg/backend/src
Devin 4fc53703c6 feat(backtest): runtime + per-user feature flags (Option C)
Replaces the build-time VITE_BACKTEST_ENABLED gate with a fully runtime
flow: a global Cosmos-backed default (already shipped in the existing
dynamicConfig system) plus a new per-user override layer. An admin can
now enable backtest for specific users without flipping the global
switch — useful for staged rollout and beta testers.

Resolution order: per-user override > global config > env fallback.
Both /api/feature-flags (FE display) and /api/backtest/run (server
guard) consult the same merge logic.

Backend (backend/src/...):
  ~ services/profileRepository.ts
      + TradingUserFeatureFlags interface
      + featureFlags?: TradingUserFeatureFlags on TradingUserProfile
      + setUserFeatureFlags(userId, { backtestEnabled, ... })
      ~ saveCurrentUserProfile() — strip role + featureFlags from input
        so non-admins can't elevate via PATCH /api/me/profile
      ~ mergeTradingUserProfiles() — preserves explicit flag values only
  ~ services/apiServer.ts
      ~ /api/feature-flags merges per-user override into the response
      + /api/admin/users/:userId/feature-flags  (GET — overrides + effective)
      + /api/admin/users/:userId/feature-flags  (PATCH — admin-only writer)
      ~ /api/backtest/run resolves effective flags before guarding
  ~ backtest/index.ts
      + RunBacktestOptions.skipGlobalFeatureFlagCheck
      ~ runBacktest() honors the override (route already gated stricter)

Frontend (web/src/...):
  ~ backtest/flags.ts — isBacktestBuildEnabled() now returns true.
    Kept as a no-op function so existing callers don't break.
  + lib/userFeatureFlagsApi.ts — typed admin client
  + components/admin/UserFeatureFlagsPanel.tsx
      Tri-state picker per flag (Default / On / Off), Look up by user id,
      Save/Reset, shows the merged "effective" value.
  ~ tabs/ConfigTab.tsx — mounts <UserFeatureFlagsPanel /> below the
    existing global Backtest Access Control section.
  ~ layout-fixes.css §27 — styles for the per-user panel.

Tests:
  + testBacktestEngine: skipGlobalFeatureFlagCheck enables per-user
    override semantics. 12/12 regression checks pass.

Security note: featureFlags + role are explicitly stripped from
saveCurrentUserProfile input. Only the admin-only PATCH endpoint can
set per-user overrides.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-05-10 19:04:12 +00:00
..
backtest feat(backtest): runtime + per-user feature flags (Option C) 2026-05-10 19:04:12 +00:00
config feat(simple): add amount sizing and runtime status 2026-05-06 07:04:48 +00:00
connectors fix(simple): support crypto fallback and scale-in entries 2026-05-06 07:33:52 +00:00
domain feat(simple): add setup activity history 2026-05-06 17:23:45 +00:00
scripts refactor: align reconciliation runtime flows with repository 2026-04-04 16:28:59 -07:00
services feat(backtest): runtime + per-user feature flags (Option C) 2026-05-10 19:04:12 +00:00
strategies feat: scaffold trading monorepo foundation 2026-04-04 11:18:21 -07:00
utils feat(backend): quiet-mode logging for backtest runs (Stage D) 2026-05-10 10:44:30 +00:00
bootstrap.ts feat(backend): WebSocket namespaces, audit persistence, tab flags, telemetry 2026-04-29 19:35:00 -04:00
index.ts feat(simple): add long-term hold mode 2026-05-06 17:37:04 +00:00
test_simulation.js feat: scaffold trading monorepo foundation 2026-04-04 11:18:21 -07:00