xonecas.io
5875
Os

ollama-space-molt-player / files

ollama-space-molt-player / packages / client / tests / cli.test.ts

3.6 KB
1import { describe, expect, test } from "bun:test";
2import { parseArgs } from "../src/cli.ts";
3
4describe("CLI Argument Parser", () => {
5	test("should parse help command", () => {
6		const result = parseArgs(["help"]);
7		expect(result.command).toBe("help");
8	});
9
10	test("should parse --help flag", () => {
11		const result = parseArgs(["--help"]);
12		expect(result.command).toBe("help");
13	});
14
15	test("should parse list-instances command", () => {
16		const result = parseArgs(["list-instances"]);
17		expect(result.command).toBe("list-instances");
18	});
19
20	test("should parse update-hint command", () => {
21		const result = parseArgs(["update-hint", "--instance", "abc1", "--hint", "test hint"]);
22		expect(result.command).toBe("update-hint");
23		expect(result.instanceId).toBe("abc1");
24		expect(result.hint).toBe("test hint");
25	});
26
27	test("should throw error for update-hint without instance", () => {
28		expect(() => {
29			parseArgs(["update-hint", "--hint", "test"]);
30		}).toThrow(/requires.*instance/);
31	});
32
33	test("should throw error for update-hint without hint", () => {
34		expect(() => {
35			parseArgs(["update-hint", "--instance", "abc1"]);
36		}).toThrow(/requires.*hint/);
37	});
38
39	test("should parse start command with defaults", () => {
40		const result = parseArgs(["start"]);
41		expect(result.command).toBe("start");
42		expect(result.config?.model).toBeUndefined();
43		expect(result.config?.contextWindowSize).toBeUndefined();
44	});
45
46	test("should parse start with instance ID", () => {
47		const result = parseArgs(["start", "--instance", "test1"]);
48		expect(result.command).toBe("start");
49		expect(result.config?.instanceId).toBe("test1");
50	});
51
52	test("should parse start with short instance flag", () => {
53		const result = parseArgs(["start", "-i", "test2"]);
54		expect(result.config?.instanceId).toBe("test2");
55	});
56
57	test("should parse start with hint", () => {
58		const result = parseArgs(["start", "--hint", "focus on trading"]);
59		expect(result.config?.hint).toBe("focus on trading");
60	});
61
62	test("should parse start with custom model", () => {
63		const result = parseArgs(["start", "--model", "llama3:8b"]);
64		expect(result.config?.model).toBe("llama3:8b");
65	});
66
67	test("should parse start with short model flag", () => {
68		const result = parseArgs(["start", "-m", "custom"]);
69		expect(result.config?.model).toBe("custom");
70	});
71
72	test("should parse start with archetype", () => {
73		const result = parseArgs(["start", "--archetype", "diplomat"]);
74		expect(result.config?.archetype).toBe("diplomat");
75	});
76
77	test("should parse start with short archetype flag", () => {
78		const result = parseArgs(["start", "-a", "agitator"]);
79		expect(result.config?.archetype).toBe("agitator");
80	});
81
82	test("should parse start with multiple options", () => {
83		const result = parseArgs([
84			"start",
85			"-i",
86			"xyz9",
87			"-m",
88			"qwen2.5",
89			"-a",
90			"opportunist",
91			"--hint",
92			"explore",
93		]);
94
95		expect(result.config?.instanceId).toBe("xyz9");
96		expect(result.config?.model).toBe("qwen2.5");
97		expect(result.config?.archetype).toBe("opportunist");
98		expect(result.config?.hint).toBe("explore");
99	});
100
101	test("should parse context window size when provided", () => {
102		const result = parseArgs(["start", "--context-window", "15"]);
103		expect(result.config?.contextWindowSize).toBe(15);
104	});
105
106	test("should parse context window size with short flag", () => {
107		const result = parseArgs(["start", "-cw", "25"]);
108		expect(result.config?.contextWindowSize).toBe(25);
109	});
110
111	test("should throw error for unknown command", () => {
112		expect(() => {
113			parseArgs(["unknown-command"]);
114		}).toThrow(/Unknown command/);
115	});
116
117	test("should default to help with no args", () => {
118		const result = parseArgs([]);
119		expect(result.command).toBe("help");
120	});
121});