/ opencodehub / cli / src / smoke.test.ts
swadhinbiswas test: fix failing tests · 7/10/2026
c4c4ada
42 lines · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { describe, it, expect } from 'vitest';
import { execFileSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import path from 'node:path';

function resolveCliBinary(): string | null {
    const candidates = [
        path.resolve(process.cwd(), 'dist/bin/och.js'),
        path.resolve(process.cwd(), 'cli/dist/bin/och.js'),
    ];
    return candidates.find((candidate) => existsSync(candidate)) || null;
}

describe('CLI Smoke Test', () => {
    const cliBinary = resolveCliBinary();

    it('should show help menu', () => {
        if (!cliBinary) return;
        let output = '';
        try {
            output = execFileSync(process.execPath, [cliBinary, '--help'], { encoding: 'utf8' });
        } catch (error: any) {
            if (error?.code === 'EPERM') return;
            throw error;
        }
        expect(output).toContain('OCH CLI');
        expect(output).toContain('Usage: och');
    });

    it('should show version', () => {
        if (!cliBinary) return;
        let output = '';
        try {
            output = execFileSync(process.execPath, [cliBinary, '--version'], { encoding: 'utf8' });
        } catch (error: any) {
            if (error?.code === 'EPERM') return;
            throw error;
        }
        expect(output).toMatch(/\d+\.\d+\.\d+/);
    });
});