Skip to content

Replace expect CLI tests with vitest + child_process #60

@macterra

Description

@macterra

Summary

The CLI integration tests currently use Tcl expect scripts (tests/cli-tests/*.expect). These should be migrated to vitest using child_process.execFile, matching the rest of the test suite.

Motivation

The recent names→aliases refactoring (#59) required updating all 28 .expect files — version checks, command renames, flag changes, and a fragile help-text string comparison. This highlighted several pain points:

  • Wrong language: Tests are written in Tcl, while the project is TypeScript
  • No shared utilities: Every script duplicates wallet setup/teardown boilerplate
  • Fragile matching: The help text test does character-by-character comparison with hardcoded spacing
  • No integration with vitest: Separate test runner, separate JUnit XML generation, separate CI configuration
  • expect is overkill: None of the tests use interactive TTY features (prompts, password input) — they just spawn a command and check stdout

Proposed approach

Use vitest with a thin wrapper around child_process.execFile:

import { execFile } from 'node:child_process';
import { promisify } from 'node:util';

const exec = promisify(execFile);
const archon = (...args: string[]) => exec('bash', ['archon', ...args]);

describe('alias commands', () => {
    let did: string;

    beforeAll(async () => {
        await archon('new-wallet');
        const { stdout } = await archon('create-id', '-r', 'local', 'test');
        did = stdout.trim();
    });

    afterAll(async () => {
        await exec('bash', ['admin', 'reset-db']);
    });

    it('add-alias / list-aliases / remove-alias', async () => {
        await archon('add-alias', 'qa', did);
        const { stdout } = await archon('list-aliases');
        expect(JSON.parse(stdout)).toHaveProperty('qa', did);

        await archon('remove-alias', 'qa');
        const { stdout: after } = await archon('list-aliases');
        expect(JSON.parse(after)).not.toHaveProperty('qa');
    });
});

Benefits

  • Same language, same runner, same reporting as unit tests
  • Shared beforeAll/afterAll replaces copy-pasted Tcl blocks
  • Real assertions instead of regex + timeouts
  • vitest --reporter=junit replaces the manual JUnit XML generator in run_cli_tests.sh
  • Still integration tests — spawns the real CLI binary against the real server

Scope

  • Migrate all 28 .expect scripts to vitest test files
  • Remove run_cli_tests.sh and the cli-tests/ directory
  • Update CI to run CLI tests as part of the standard vitest suite

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions