forked from pwrdrvr/openclaw-codex-app-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread-selection.test.ts
More file actions
89 lines (81 loc) · 2.25 KB
/
thread-selection.test.ts
File metadata and controls
89 lines (81 loc) · 2.25 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
parseThreadSelectionArgs,
selectThreadFromMatches,
} from "./thread-selection.js";
import type { ThreadSummary } from "./types.js";
const THREADS: ThreadSummary[] = [
{
threadId: "thread-openclaw",
title: "OpenClaw work",
projectKey: "/workspace/openclaw",
},
{
threadId: "thread-home",
title: "Home dotfiles",
projectKey: "/workspace/home",
},
];
describe("thread selection args", () => {
it("parses --all without inventing a query", () => {
expect(parseThreadSelectionArgs("--all")).toEqual({
includeAll: true,
listProjects: false,
syncTopic: false,
cwd: undefined,
query: "",
});
});
it("parses em dash all from Telegram-style input", () => {
expect(parseThreadSelectionArgs("—all")).toEqual({
includeAll: true,
listProjects: false,
syncTopic: false,
cwd: undefined,
query: "",
});
});
it("parses --all with a target query", () => {
expect(parseThreadSelectionArgs("--all thread-home")).toEqual({
includeAll: true,
listProjects: false,
syncTopic: false,
cwd: undefined,
query: "thread-home",
});
});
it("parses --projects and expands a home-relative cwd", () => {
expect(parseThreadSelectionArgs("--projects --cwd ~/github/openclaw")).toEqual({
includeAll: false,
listProjects: true,
syncTopic: false,
cwd: path.join(os.homedir(), "github/openclaw"),
query: "",
});
});
it("parses --sync separately from the query text", () => {
expect(parseThreadSelectionArgs("—all —sync approvals")).toEqual({
includeAll: true,
listProjects: false,
syncTopic: true,
cwd: undefined,
query: "approvals",
});
});
});
describe("thread selection", () => {
it("picks an exact thread id match", () => {
expect(selectThreadFromMatches(THREADS, "thread-home")).toEqual({
kind: "unique",
thread: THREADS[1],
});
});
it("does not auto-pick the first fuzzy match when multiple threads exist", () => {
expect(selectThreadFromMatches(THREADS, "thread")).toEqual({
kind: "ambiguous",
threads: THREADS,
});
});
});