Commit graph

2 commits

Author SHA1 Message Date
2b37c4b24f Phase 8: extract pure helpers into lib/ and cover with node:test
- Move buildingKey, jobsForApp, getBotToken, isBotEnabled, getBotConfig,
  isAuthorized, getOAuthRedirectUri, buildAuthUrl, cleanCompletedJobs,
  and msToTime into lib/helpers.js as state-free functions that accept
  config, botTokens, or env as parameters. COMPLETED_RETENTION_DAYS also
  lives there so callers and tests share the constant.
- Replace the bodies in index.js with thin wrappers that pass the module-
  level state into the pure helpers. Call sites and behavior are
  unchanged; index.js shrinks by ~60 lines.
- Move the cleanCompletedJobs logging into the cron caller so the pure
  helper returns a result object (jobs, removed, cutoff) that tests can
  assert on without capturing stdout.
- Add test/helpers.test.js with 43 assertions across 10 suites covering
  the enable/disable gating, per-bot draft isolation, authorization,
  OAuth URL construction, retention filter (including endTime -> startTime
  -> created fallback and the safety default for jobs missing a
  timestamp), and the duration formatter.
- Wire `npm test` to `node --test test/*.test.js` (no new deps, uses the
  built-in node:test runner) and document it in the README.

Smoke test confirms unchanged HTTP behavior for /info (known + unknown
bots), the requireBot 404 gate, and the 401 path on jobs/list/completed.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-01 18:21:02 -04:00
b4e5ca3f33 Phase 7: polish for production readiness
- Add README with local setup, add-a-bot walkthrough, Docker run
  recipe, and a rundown of committed vs. runtime state.
- Wrap the cron schedules with an explicit timezone (default
  America/New_York, override via CRON_TIMEZONE) so cadence is
  independent of the host/container clock.
- Route saveServiceAccountToken through a try/catch so a disk hiccup
  no longer bubbles up as an unhandled exception during token refresh,
  and keep the in-memory copy usable even on write failure.
- Silence per-message queue.on('active') / on('completed') logs that
  also registered a new listener on every job invocation (accumulating
  on the shared queue over time).
- Fix logIt reference (undefined; would have thrown if
  checkScheduledJobs ever rejected) and a broken JSON.stringify.result
  debug log that always evaluated to undefined.
- Dockerfile: switch to node:20-slim, install from the lockfile via
  npm ci --omit=dev, set NODE_ENV=production, and document that env
  and volumes are supplied at runtime.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-01 18:00:59 -04:00