mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 04:42:10 +03:00
* fix: add re-entrancy guard to token health check sweep Adds an in-flight guard to prevent overlapping sweep() executions. Uses global state sweeping flag that is set before the first await and cleared in a finally block. Subsequent calls while sweeping return early with a debug log line. Test coverage: - skips when a previous sweep is still in flight - resets sweeping flag after normal completion - resets sweeping flag on empty connections * fix(test): move sweep re-entrancy test to node:test, wire CI correctly tests/unit/token-health-check-sweep.test.ts used vitest syntax while living directly under tests/unit/, which is exactly the glob `npm run test:unit` (node's native runner) scans — running it there threw "Vitest mocker was not initialized" and failed the file outright. Separately, the vitest.config.ts include-array edit didn't wire the test into any CI-blocking script either: `npm run test:vitest` runs vitest.mcp.config.ts (a different config, not this path), and test:vitest:ui is scoped to tests/unit/ui only — so the 3 tests never ran in CI at all while node's runner actively failed on the file. Rewrite the test to node:test, matching the tests/unit/apikey-connection-health-check.test.ts / tests/unit/token-health-check.test.ts convention (real temp-dir SQLite DB rather than vi.mock, since mock.module() is unavailable in this tsx/ESM + Node native test-runner setup). The re-entrancy scenario now drives the real, unmocked sweep() with real OAuth connections (healthCheckInterval: 0 keeps checkConnection() a fast no-op) and asserts on wall-clock elapsed time + the shared sweeping flag instead of a mocked call count. Verified this fails without the guard (909ms, ~3x the stagger) and passes with it restored. Remove the now-unused vitest.config.ts include entry since the test no longer needs it. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * refactor(health): compact sweep guard + restore one-line stagger delay (file-size cap) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: oyi77 <oyi77@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>