From 3a9be91f1df45ed07f3e6c51cf5379a6913b94e2 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Mon, 16 Feb 2026 15:00:09 -0800 Subject: [PATCH] test(setup): cover operator pack automation flow --- docs/plans/state.json | 5 +- src/cli/setup/automation.test.ts | 92 ++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/cli/setup/automation.test.ts diff --git a/docs/plans/state.json b/docs/plans/state.json index 2422f92..24030d3 100644 --- a/docs/plans/state.json +++ b/docs/plans/state.json @@ -197,6 +197,7 @@ "files_modified": [ "src/cli/setup/config.ts", "src/cli/setup/config.test.ts", + "src/cli/setup/automation.test.ts", "src/cli/setup/automation.ts", "src/automation/heartbeat.ts", "src/automation/heartbeat.test.ts", @@ -208,7 +209,7 @@ "README.md", "docs/plans/state.json" ], - "test_status": "pnpm test:run src/cli/setup/config.test.ts src/automation/heartbeat.test.ts src/config/schema.test.ts src/cli/doctor.test.ts + pnpm typecheck passing" + "test_status": "pnpm test:run src/cli/setup/automation.test.ts src/cli/setup/config.test.ts src/automation/heartbeat.test.ts src/config/schema.test.ts src/cli/doctor.test.ts + pnpm typecheck passing" }, "backup-session-summary-audit-trail": { "status": "completed", @@ -3494,7 +3495,7 @@ } }, "overall_progress": { - "total_test_count": 1863, + "total_test_count": 1865, "all_tests_passing": true, "p0_completion": "3/3 (100%)", "p1_completion": "4/4 (100%)", diff --git a/src/cli/setup/automation.test.ts b/src/cli/setup/automation.test.ts new file mode 100644 index 0000000..6c8b803 --- /dev/null +++ b/src/cli/setup/automation.test.ts @@ -0,0 +1,92 @@ +import { describe, it, expect } from 'vitest'; +import { setupAutomation } from './automation.js'; +import { ConfigBuilder } from './config.js'; +import type { Prompter } from './prompts.js'; + +function makePrompter(answers: { + confirms?: boolean[]; + asks?: string[]; +}): Prompter { + const confirms = [...(answers.confirms ?? [])]; + const asks = [...(answers.asks ?? [])]; + + return { + ask: async (_question: string, defaultValue?: string) => { + if (asks.length > 0) { + return asks.shift() ?? ''; + } + return defaultValue ?? ''; + }, + confirm: async (_question: string, defaultYes?: boolean) => { + if (confirms.length > 0) { + return confirms.shift() ?? false; + } + return defaultYes ?? false; + }, + choose: async (_question: string, options: Array<{ value: T }>) => options[0].value, + password: async () => '', + println: () => {}, + }; +} + +describe('setupAutomation', () => { + it('applies operator pack defaults when enabled', async () => { + const builder = new ConfigBuilder(); + builder.setTelegram('123:ABC', [987654321]); + + const p = makePrompter({ + confirms: [ + true, // enable operator pack + true, // include minio sync + false, // enable cron scheduler + false, // enable webhook receiver + false, // configure google services + ], + asks: [ + '0 3 * * *', // backup schedule + '0 7 * * 1-5', // daily briefing schedule + ], + }); + + await setupAutomation(p, builder); + + const config = builder.build() as Record; + const backup = config.backup as Record; + const automation = config.automation as Record; + const heartbeat = automation.heartbeat as Record; + const briefing = automation.daily_briefing as Record; + const minioSync = automation.minio_sync as Record; + + expect(backup.enabled).toBe(true); + expect(backup.schedule).toBe('0 3 * * *'); + expect(heartbeat.enabled).toBe(true); + expect(heartbeat.notify_cooldown).toBe('30m'); + expect(briefing.enabled).toBe(true); + expect(briefing.schedule).toBe('0 7 * * 1-5'); + expect(minioSync.enabled).toBe(true); + }); + + it('leaves operator pack disabled when not selected', async () => { + const builder = new ConfigBuilder(); + + const p = makePrompter({ + confirms: [ + false, // enable operator pack + false, // enable cron scheduler + false, // enable webhook receiver + false, // configure google services + ], + }); + + await setupAutomation(p, builder); + + const config = builder.build() as Record; + const backup = config.backup as Record | undefined; + const automation = config.automation as Record | undefined; + + expect(backup).toBeUndefined(); + expect(automation?.daily_briefing).toBeUndefined(); + expect(automation?.heartbeat).toBeUndefined(); + expect(automation?.minio_sync).toBeUndefined(); + }); +});