Skip to content

feat: sync crontab on init and clean test artifacts - #165

Merged
avoidwork merged 7 commits into
mainfrom
feat/sync-crond-on-init
Jun 10, 2026
Merged

feat: sync crontab on init and clean test artifacts#165
avoidwork merged 7 commits into
mainfrom
feat/sync-crond-on-init

Conversation

@avoidwork

@avoidwork avoidwork commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Description

Implement automatic reconciliation of persisted job definitions (memory/schedules/*.json) with the system crontab on every container init. Jobs persist between container updates without duplication or interruption of running crond jobs.

Additionally, cronjob tests now clean the system crontab after each run by calling Cron.uninstall() in the after() hook, ensuring no residual madz-schedules block entries linger.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional change)
  • Performance improvement
  • CI / build / tooling

Testing

Unit tests (tests/unit/cron_sync.test.js — 12 tests):

  • Adds a job that exists on disk but not in crontab
  • Removes a job that exists in crontab but not on disk
  • Updates a job with differing cron expression
  • Updates a job with differing command
  • Excludes paused jobs from crontab
  • Idempotent: produces identical crontab on repeated calls
  • Preserves lines outside the madz block
  • Handles empty schedules directory
  • Handles empty crontab
  • Handles jobs with no command field (skips them)
  • Handles non-existent schedules directory gracefully
  • Syncs multiple jobs correctly

Integration tests (tests/integration/sync_integration.test.js — 4 tests):

  • Create a job via cronjob tool, verify job appears in crontab after sync
  • Remove a job via cronjob tool, verify job is removed from crontab after sync
  • Update a job cron expression via cronjob tool, verify updated cron in crontab after sync
  • Disable sync via config, verify no crontab changes on restart

Test hygiene (tests/unit/tools_cron.test.js):

  • Import Cron scheduler and call uninstall() in after() hook to strip the entire madz-schedules block from the system crontab after all cronjob tests complete.

All 16 new tests pass. Full test suite passes (100% of existing tests unaffected).

Coverage

  • 100% line coverage maintained — pre-commit hook verified

Checklist

  • npm run lint passes — oxlint + oxfmt clean
  • Tests pass with 100% line coverage — 16 new tests, all pass
  • No forbidden patterns used — no console.log in prod (uses console.warn/log with oxlint-disable), no empty catches, no eval
  • Conventional Commit style applied

Archive Status

Change sync-crond-on-init has been archived. The new crontab-sync capability spec has been merged into the main specs directory.

Add OpenSpec change proposing automatic reconciliation of persisted
job definitions (memory/schedules/*.json) with the system crontab on
container init. Covers: add/remove/update/pause of jobs, no-duplication
via full block replacement, no interruption of running crond jobs, and
configurable opt-out via scheduler.syncOnInit flag.

Artifacts: proposal.md, design.md, specs/crontab-sync/spec.md,
specs/cron-scheduler/spec.md (delta), tasks.md (24 tasks, 6 groups).
@avoidwork avoidwork self-assigned this Jun 10, 2026
Implement automatic reconciliation of persisted job definitions
(memory/schedules/*.json) with the system crontab on every container
initialization. Jobs persist between container updates without
duplication or interruption of running crond jobs.

Changes:
- Add Cron.sync() method: reads disk JSON, compares crontab block,
  writes reconciled block (add/remove/update/pause)
- Add scheduler.syncOnInit config flag (default: true)
- Wire sync into index.js boot sequence before TUI init
- Add logging: info on start/complete, warn on error
- 12 unit tests + 4 integration tests covering all scenarios

Files:
- src/scheduler/cron.js: sync() method + helpers
- src/config/schemas.js: syncOnInit schema + default
- index.js: sync boot call with try/catch/logging
- config.yaml: syncOnInit: true
- tests/unit/cron_sync.test.js: 12 unit tests
- tests/integration/sync_integration.test.js: 4 integration tests
@avoidwork avoidwork changed the title feat: propose sync-crond-on-init — init-time crontab synchronization feat: propose and implement sync-crond-on-init Jun 10, 2026
@avoidwork avoidwork changed the title feat: propose and implement sync-crond-on-init feat: sync crontab on init and clean test artifacts Jun 10, 2026
@avoidwork
avoidwork merged commit bc490a7 into main Jun 10, 2026
2 checks passed
@avoidwork
avoidwork deleted the feat/sync-crond-on-init branch June 10, 2026 23:56
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.

1 participant