Skip to content

fix: migrate cron module to async API and merge duplicate imports - #668

Merged
avoidwork merged 12 commits into
mainfrom
fix/cron-reflection-path
Aug 1, 2026
Merged

fix: migrate cron module to async API and merge duplicate imports#668
avoidwork merged 12 commits into
mainfrom
fix/cron-reflection-path

Conversation

@avoidwork

@avoidwork avoidwork commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Description

Migrated the cron module from synchronous to asynchronous execution — replaced execSync with promisified exec from node:child_process/promises and all sync fs calls with fs/promises variants. Also replaced the hardcoded /app path in the reflection job with process.cwd(). Additionally merged duplicate import statements across multiple TUI panels and the shutdown module, and added the no-duplicate-imports lint rule.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)

Testing

  • Rewrote tests/unit/scheduler/cron.test.js with async-compatible mock exec that intercepts crontab commands via callback-based mock, falling through to real exec for other commands.
  • Removed sync Cron tests from tests/unit/scheduler.test.js that relied on execSync and direct sync method calls.
  • Updated tests/unit/tools_cron.test.js to await async Cron methods.
  • Verified npm run lint passes with no errors.

Coverage

  • Line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with maintained line coverage
  • No forbidden patterns used (no sync I/O in async context, no execSync)
  • Conventional Commit style applied

@avoidwork avoidwork added the bug Something isn't working label Aug 1, 2026
@avoidwork avoidwork self-assigned this Aug 1, 2026
@avoidwork avoidwork added the bug Something isn't working label Aug 1, 2026
The callback-based readdir and readFile from node:fs don't auto-promisify
in Node 25 — await readdir() throws ERR_INVALID_ARG_TYPE. Switched to
node:fs/promises so the async method works correctly.

Also changed the reflection-daily command from hardcoded /app to
process.cwd() so it resolves correctly regardless of launch directory.
@avoidwork
avoidwork force-pushed the fix/cron-reflection-path branch from a1479ab to 0b6445c Compare August 1, 2026 18:17
Switched _ensureReflectionJob from sync to async, using node:fs/promises
for readdir, mkdir, readFile, and writeFile. This eliminates blocking
I/O in the scheduler module.
All filesystem and shell operations in the scheduler module are now
non-blocking. Converted isAvailable, _readCrontab, _writeCrontab,
add, remove, install, uninstall, list, and sync to async. Updated
all callers in tools/cron.js and test files.
Switched _ensureReflectionJob from sync to async, using node:fs/promises
for readdir, mkdir, readFile, and writeFile. This eliminates blocking
I/O in the scheduler module.

Also refactored Cron to accept a mock exec via setExecOverride() so tests
can isolate from the system crontab without actually modifying it.
@avoidwork avoidwork changed the title fix: use process.cwd() instead of hardcoded /app path in reflection job fix: migrate cron module to async API and merge duplicate imports Aug 1, 2026
@avoidwork
avoidwork enabled auto-merge (squash) August 1, 2026 21:30
@avoidwork
avoidwork merged commit 1b87b70 into main Aug 1, 2026
2 checks passed
@avoidwork
avoidwork deleted the fix/cron-reflection-path branch August 1, 2026 22:36
@avoidwork avoidwork mentioned this pull request Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant