Skip to content

Add setup command tests for idempotency, fallback, and GitHub choices #1607

Closed

Description

@propr-dev

Context

The setup wizard touches Docker, .env, backend APIs, and terminal UI. Tests should focus on the setup engine and fallback behavior so the feature remains safe to re-run.

Requirements

  • Test setup state helpers without Docker.
  • Test intake mode .env writes.
  • Test that existing .env is not overwritten by setup initialization.
  • Test fallback prompt behavior with mocked prompts.
  • Test selected agent images are the only agent images pulled.

Implementation Specification

Add focused tests under test/cliSetupWizard.test.ts. Use temporary directories and mocked prompt callbacks. Avoid real Docker by injecting or mocking orchestrator behavior where necessary.

Acceptance Criteria

  • Tests pass in the normal repository test command.
  • No test requires real Docker, real GitHub, or real agent credentials.
  • Tests verify at least one setup re-run scenario.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Jun 22, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    The tests target pure helpers and the engine with fakes instead of trying to snapshot Ink UI output. This gives stronger safety coverage for idempotency and security choices while avoiding brittle terminal rendering tests. Full end-to-end Docker tests were considered, but they would be slow and unreliable in CI.

    File: test/cliSetupWizard.test.ts (new file)

    Why this file: This test file covers the new setup-specific behavior and guards against destructive re-run regressions.

    import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
    import { tmpdir } from 'node:os';
    import { join } from 'node:path';
    import { describe, expect, it } from 'vitest';
    import { createInitialSetupState, updateStep, writeSetupEnv } from '../packages/cli/src/commands/setup/state.js';
    import { configureGithubIntake } from '../packages/cli/src/commands/setup/github.js';
    import type { SetupPrompts } from '../packages/cli/src/commands/setup/engine.js';
    
    function tempRoot(): string {
      return mkdtempSync(join(tmpdir(), 'propr-setup-test-'));
    }
    
    function prompts(overrides: Partial<SetupPrompts>): SetupPrompts {
      return {
        confirm: async () => true,
        input: async () => '',
        choose: async (_message, _choices, defaultValue) => defaultValue,
        multiChoose: async () => [],
        ...overrides,
      };
    }
    
    describe('setup wizard state', () => {
      it('creates stable setup steps', () => {
        const state = createInitialSetupState('/tmp/propr', true);
        expect(state.steps.map((step) => step.id)).toEqual([
          'environment',
          'docker',
          'images',
          'agents',
          'github-cli',
          'github-intake',
          'stack-init',
          'stack-start',
          'whitelist',
          'repository',
          'web-ui',
        ]);
      });
    
      it('updates one step without mutating the original state', () => {
        const original = createInitialSetupState('/tmp/propr', true);
        const next = updateStep(original, 'docker', { status: 'complete', detail: 'ok' });
        expect(original.steps.find((step) => step.id === 'docker')?.status).toBe('pending');
        expect(next.steps.find((step) => step.id === 'docker')?.status).toBe('complete');
      });
    });
    
    describe('setup env writes', () => {
      it('upserts setup values while preserving unrelated env entries', () => {
        const root = tempRoot();
        try {
          writeFileSync(join(root, '.env'), 'EXISTING=value\nENABLE_GITHUB_WEBHOOKS=true\n');
          writeSetupEnv(root, { ENABLE_GITHUB_WEBHOOKS: 'false' });
          const text = readFileSync(join(root, '.env'), 'utf8');
          expect(text).toContain('EXISTING=value');
          expect(text).toContain('ENABLE_GITHUB_WEBHOOKS=false');
          expect(text).not.toContain('ENABLE_GITHUB_WEBHOOKS=true');
        } finally {
          rmSync(root, { recursive: true, force: true });
        }
      });
    });
    
    describe('GitHub intake setup', () => {
      it('writes polling mode as webhook disabled', async () => {
        const root = tempRoot();
        try {
          writeFileSync(join(root, '.env'), 'EXISTING=value\n');
          await configureGithubIntake(root, prompts({ choose: async () => 'polling' }));
          expect(readFileSync(join(root, '.env'), 'utf8')).toContain('ENABLE_GITHUB_WEBHOOKS=false');
        } finally {
          rmSync(root, { recursive: true, force: true });
        }
      });
    
      it('rejects direct webhooks without a secret', async () => {
        const root = tempRoot();
        try {
          writeFileSync(join(root, '.env'), 'EXISTING=value\n');
          await expect(configureGithubIntake(root, prompts({ choose: async () => 'webhooks', input: async () => '' }))).rejects.toThrow(/requires GH_WEBHOOK_SECRET/);
        } finally {
          rmSync(root, { recursive: true, force: true });
        }
      });
    
      it('writes direct webhook mode with secret', async () => {
        const root = tempRoot();
        try {
          writeFileSync(join(root, '.env'), 'EXISTING=value\n');
          await configureGithubIntake(root, prompts({ choose: async () => 'webhooks', input: async () => 'secret-value' }));
          const text = readFileSync(join(root, '.env'), 'utf8');
          expect(text).toContain('ENABLE_GITHUB_WEBHOOKS=true');
          expect(text).toContain('GH_WEBHOOK_SECRET=secret-value');
        } finally {
          rmSync(root, { recursive: true, force: true });
        }
      });
    });
  2. propr-dev commented on Jun 22, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using claude agent with claude-opus-4-8 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-4-8
    • Branch: 1607/claude-opus-4-8-add-setup-command-tests-f-20260622-1124-104
    • Base Branch: 1599-epic-build-comprehensive-b5c
    • Worktree: issue-1607-20260622-1124-claude-opus-4-8-104

    🔍 Track Task Execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions