chatccc 0.2.252 → 0.2.254
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/bin/cccagent.mjs +12 -3
- package/bin/chatccc.mjs +15 -6
- package/config.sample.json +2 -1
- package/deepccc-agent/README.md +40 -35
- package/deepccc-agent/os-prompts/darwin.md +8 -8
- package/deepccc-agent/os-prompts/linux.md +8 -8
- package/deepccc-agent/os-prompts/win32.md +11 -11
- package/deepccc-agent/package.json +65 -65
- package/dist/deepccc-agent/src/cli.js +634 -0
- package/dist/deepccc-agent/src/config.js +81 -0
- package/dist/deepccc-agent/src/context.js +348 -0
- package/dist/deepccc-agent/src/file-log.js +34 -0
- package/dist/deepccc-agent/src/file-tools.js +1208 -0
- package/dist/deepccc-agent/src/index.js +601 -0
- package/dist/deepccc-agent/src/permissions.js +170 -0
- package/dist/deepccc-agent/src/privacy.js +124 -0
- package/dist/deepccc-agent/src/proc-tree-kill.js +60 -0
- package/dist/deepccc-agent/src/progress/cards-helpers.js +70 -0
- package/dist/deepccc-agent/src/progress/reducer.js +102 -0
- package/dist/deepccc-agent/src/progress/terminal-renderer.js +264 -0
- package/dist/deepccc-agent/src/progress/view.js +30 -0
- package/dist/deepccc-agent/src/raw-stream-log.js +106 -0
- package/dist/deepccc-agent/src/session-search.js +276 -0
- package/dist/deepccc-agent/src/session-select.js +23 -0
- package/dist/deepccc-agent/src/sigint.js +26 -0
- package/dist/deepccc-agent/src/skills.js +178 -0
- package/dist/deepccc-agent/src/web-tools.js +246 -0
- package/dist/src/adapters/adapter-interface.js +19 -0
- package/dist/src/adapters/ccc-adapter.js +112 -0
- package/dist/src/adapters/claude-adapter.js +497 -0
- package/dist/src/adapters/claude-session-meta-store.js +92 -0
- package/dist/src/adapters/codex-adapter.js +279 -0
- package/dist/src/adapters/codex-session-meta-store.js +94 -0
- package/dist/src/adapters/cursor-adapter.js +491 -0
- package/dist/src/adapters/cursor-session-meta-store.js +116 -0
- package/dist/src/adapters/jsonl-stream.js +104 -0
- package/{src/adapters/proc-tree-kill.ts → dist/src/adapters/proc-tree-kill.js} +94 -97
- package/dist/src/adapters/raw-stream-log.js +106 -0
- package/dist/src/adapters/resource-monitor.js +113 -0
- package/dist/src/agent-activity.js +133 -0
- package/dist/src/agent-delegate-task-rpc.js +129 -0
- package/dist/src/agent-delegate-task.js +48 -0
- package/dist/src/agent-file-rpc.js +152 -0
- package/dist/src/agent-image-rpc.js +148 -0
- package/dist/src/agent-platform-routing.js +13 -0
- package/dist/src/agent-reload-config-rpc.js +23 -0
- package/dist/src/agent-rpc-body.js +87 -0
- package/dist/src/agent-stop-stuck.js +110 -0
- package/dist/src/agent-team/application/board-service.js +142 -0
- package/dist/src/agent-team/application/main-agent-service.js +151 -0
- package/dist/src/agent-team/domain/board.js +69 -0
- package/dist/src/agent-team/http/board-routes.js +213 -0
- package/dist/src/agent-team/infrastructure/filesystem-browser.js +112 -0
- package/dist/src/agent-team/infrastructure/main-agent-session-runtime.js +30 -0
- package/dist/src/agent-team/main-agent-bootstrap.js +15 -0
- package/dist/src/agent-team/repositories/board-repository.js +10 -0
- package/dist/src/agent-team/repositories/feishu-p2p-contact-store.js +64 -0
- package/dist/src/agent-team/repositories/json-board-repository.js +209 -0
- package/dist/src/agent-team/repositories/main-agent-binding-repository.js +84 -0
- package/dist/src/agent-team/sync/board-sync-adapter.js +1 -0
- package/dist/src/agent-team/web/agent-team-page.js +219 -0
- package/dist/src/agent-tool.js +10 -0
- package/dist/src/card-action-routing.js +7 -0
- package/dist/src/card-plain-text.js +101 -0
- package/dist/src/cardkit.js +158 -0
- package/dist/src/cards.js +573 -0
- package/dist/src/chatgpt-subscription-rpc.js +18 -0
- package/dist/src/chatgpt-subscription.js +199 -0
- package/dist/src/chrome-devtools-guard.js +238 -0
- package/dist/src/claude-sdk-installer.js +249 -0
- package/dist/src/codex-reset-actions.js +143 -0
- package/dist/src/config-utils.js +149 -0
- package/dist/src/config.js +808 -0
- package/dist/src/cursor-usage.js +77 -0
- package/dist/src/exit-banner.js +28 -0
- package/dist/src/feishu-api.js +1404 -0
- package/dist/src/feishu-message-ingress.js +137 -0
- package/dist/src/feishu-platform.js +97 -0
- package/dist/src/format-message.js +252 -0
- package/dist/src/git-command.js +155 -0
- package/dist/src/im-skills.js +121 -0
- package/dist/src/index.js +835 -0
- package/dist/src/litellm-proxy.js +300 -0
- package/dist/src/orchestrator.js +2096 -0
- package/dist/src/package-root.js +26 -0
- package/dist/src/platform-adapter.js +7 -0
- package/dist/src/platform-startup.js +6 -0
- package/dist/src/privacy.js +100 -0
- package/dist/src/progress/reducer.js +102 -0
- package/dist/src/progress/terminal-renderer.js +264 -0
- package/dist/src/progress/view.js +30 -0
- package/dist/src/response-stall.js +14 -0
- package/dist/src/runtime-entry.js +13 -0
- package/dist/src/runtime-reload.js +19 -0
- package/dist/src/session-chat-binding.js +183 -0
- package/dist/src/session-name.js +7 -0
- package/dist/src/session.js +2147 -0
- package/dist/src/shared-prefix.js +16 -0
- package/dist/src/shared.js +493 -0
- package/dist/src/sim-agent.js +105 -0
- package/dist/src/sim-platform.js +142 -0
- package/dist/src/sim-store.js +231 -0
- package/dist/src/simplify.js +99 -0
- package/dist/src/startup-lifecycle.js +209 -0
- package/dist/src/stream-state.js +141 -0
- package/dist/src/terminal-error.js +100 -0
- package/dist/src/trace.js +50 -0
- package/dist/src/turn-cards.js +92 -0
- package/dist/src/update-command-guard.js +114 -0
- package/{src/web-ui.ts → dist/src/web-ui.js} +753 -839
- package/dist/src/wechat-platform.js +545 -0
- package/package.json +76 -74
- package/deepccc-agent/LICENSE +0 -201
- package/deepccc-agent/bin/deepccc.mjs +0 -26
- package/deepccc-agent/docs/cache-hit-rate-1.jpg +0 -0
- package/deepccc-agent/docs/cache-hit-rate-2.jpg +0 -0
- package/deepccc-agent/package-lock.json +0 -2027
- package/deepccc-agent/src/__tests__/chat-session.test.ts +0 -877
- package/deepccc-agent/src/__tests__/cli-json.test.ts +0 -49
- package/deepccc-agent/src/__tests__/config.test.ts +0 -34
- package/deepccc-agent/src/__tests__/context.test.ts +0 -341
- package/deepccc-agent/src/__tests__/file-tools.test.ts +0 -240
- package/deepccc-agent/src/__tests__/permissions.test.ts +0 -199
- package/deepccc-agent/src/__tests__/privacy.test.ts +0 -318
- package/deepccc-agent/src/__tests__/progress-reducer.test.ts +0 -121
- package/deepccc-agent/src/__tests__/session-search.test.ts +0 -262
- package/deepccc-agent/src/__tests__/session-select.test.ts +0 -116
- package/deepccc-agent/src/__tests__/sigint.test.ts +0 -56
- package/deepccc-agent/src/__tests__/skills.test.ts +0 -284
- package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +0 -247
- package/deepccc-agent/src/__tests__/web-tools.test.ts +0 -220
- package/deepccc-agent/src/cli.ts +0 -682
- package/deepccc-agent/src/config.ts +0 -101
- package/deepccc-agent/src/context.ts +0 -465
- package/deepccc-agent/src/file-log.ts +0 -38
- package/deepccc-agent/src/file-tools.ts +0 -1493
- package/deepccc-agent/src/index.ts +0 -710
- package/deepccc-agent/src/permissions.ts +0 -226
- package/deepccc-agent/src/privacy.ts +0 -141
- package/deepccc-agent/src/proc-tree-kill.ts +0 -61
- package/deepccc-agent/src/progress/cards-helpers.ts +0 -76
- package/deepccc-agent/src/progress/reducer.ts +0 -113
- package/deepccc-agent/src/progress/terminal-renderer.ts +0 -294
- package/deepccc-agent/src/progress/view.ts +0 -77
- package/deepccc-agent/src/raw-stream-log.ts +0 -124
- package/deepccc-agent/src/session-search.ts +0 -370
- package/deepccc-agent/src/session-select.ts +0 -48
- package/deepccc-agent/src/sigint.ts +0 -50
- package/deepccc-agent/src/skills.ts +0 -205
- package/deepccc-agent/src/web-tools.ts +0 -313
- package/deepccc-agent/tsconfig.build.json +0 -13
- package/deepccc-agent/tsconfig.json +0 -13
- package/deepccc-agent/vitest.config.ts +0 -7
- package/src/__tests__/adapter-interface.test.ts +0 -152
- package/src/__tests__/agent-activity.test.ts +0 -86
- package/src/__tests__/agent-delegate-task-rpc.test.ts +0 -165
- package/src/__tests__/agent-image-rpc.test.ts +0 -34
- package/src/__tests__/agent-platform-routing.test.ts +0 -26
- package/src/__tests__/agent-reload-config-rpc.test.ts +0 -99
- package/src/__tests__/agent-rpc-body.test.ts +0 -42
- package/src/__tests__/builtin-chat-session.test.ts +0 -532
- package/src/__tests__/builtin-cli-json.test.ts +0 -39
- package/src/__tests__/builtin-config.test.ts +0 -26
- package/src/__tests__/builtin-context.test.ts +0 -319
- package/src/__tests__/builtin-file-tools.test.ts +0 -240
- package/src/__tests__/builtin-permissions.test.ts +0 -219
- package/src/__tests__/builtin-session-search.test.ts +0 -262
- package/src/__tests__/builtin-session-select.test.ts +0 -116
- package/src/__tests__/builtin-sigint.test.ts +0 -56
- package/src/__tests__/builtin-skills.test.ts +0 -284
- package/src/__tests__/builtin-web-tools.test.ts +0 -220
- package/src/__tests__/card-action-routing.test.ts +0 -18
- package/src/__tests__/card-plain-text.test.ts +0 -45
- package/src/__tests__/cardkit.test.ts +0 -60
- package/src/__tests__/cards.test.ts +0 -607
- package/src/__tests__/ccc-adapter.test.ts +0 -194
- package/src/__tests__/chatgpt-subscription-rpc.test.ts +0 -89
- package/src/__tests__/chatgpt-subscription.test.ts +0 -135
- package/src/__tests__/chrome-devtools-guard.test.ts +0 -165
- package/src/__tests__/claude-adapter.test.ts +0 -614
- package/src/__tests__/claude-raw-stream-log.test.ts +0 -96
- package/src/__tests__/claude-sdk-installer.test.ts +0 -285
- package/src/__tests__/codex-adapter.test.ts +0 -331
- package/src/__tests__/codex-raw-stream-log.test.ts +0 -170
- package/src/__tests__/codex-reset-actions.test.ts +0 -146
- package/src/__tests__/config-reload.test.ts +0 -284
- package/src/__tests__/config-sample.test.ts +0 -97
- package/src/__tests__/config-utils.test.ts +0 -40
- package/src/__tests__/config.test.ts +0 -395
- package/src/__tests__/crash-logging.test.ts +0 -360
- package/src/__tests__/cursor-adapter.test.ts +0 -890
- package/src/__tests__/cursor-session-meta-store.test.ts +0 -212
- package/src/__tests__/feishu-api.test.ts +0 -60
- package/src/__tests__/feishu-avatar.test.ts +0 -504
- package/src/__tests__/feishu-message-ingress.test.ts +0 -138
- package/src/__tests__/feishu-platform.test.ts +0 -75
- package/src/__tests__/fixtures/codex_simple_text.jsonl +0 -4
- package/src/__tests__/fixtures/codex_with_tool.jsonl +0 -6
- package/src/__tests__/fixtures/cursor_partial_only.jsonl +0 -5
- package/src/__tests__/fixtures/cursor_partial_with_final.jsonl +0 -13
- package/src/__tests__/fixtures/cursor_with_tool_call.jsonl +0 -12
- package/src/__tests__/format-message.test.ts +0 -316
- package/src/__tests__/git-command.test.ts +0 -288
- package/src/__tests__/im-skills.test.ts +0 -125
- package/src/__tests__/jsonl-stream.test.ts +0 -79
- package/src/__tests__/orchestrator.test.ts +0 -1268
- package/src/__tests__/package-files.test.ts +0 -24
- package/src/__tests__/platform-startup.test.ts +0 -19
- package/src/__tests__/privacy.test.ts +0 -198
- package/src/__tests__/proc-tree-kill.test.ts +0 -108
- package/src/__tests__/progress-reducer.test.ts +0 -121
- package/src/__tests__/raw-stream-log.test.ts +0 -106
- package/src/__tests__/response-stall.test.ts +0 -49
- package/src/__tests__/restart.test.ts +0 -232
- package/src/__tests__/session-ccc-config.test.ts +0 -66
- package/src/__tests__/session.test.ts +0 -3004
- package/src/__tests__/shared-prefix.test.ts +0 -36
- package/src/__tests__/sim-agent.test.ts +0 -174
- package/src/__tests__/sim-platform.test.ts +0 -93
- package/src/__tests__/sim-store.test.ts +0 -214
- package/src/__tests__/simplify.test.ts +0 -283
- package/src/__tests__/startup-lifecycle.test.ts +0 -231
- package/src/__tests__/stop-session.test.ts +0 -162
- package/src/__tests__/stream-state.test.ts +0 -164
- package/src/__tests__/terminal-error.test.ts +0 -54
- package/src/__tests__/terminal-renderer.test.ts +0 -247
- package/src/__tests__/update-command-guard.test.ts +0 -144
- package/src/__tests__/web-ui.test.ts +0 -438
- package/src/__tests__/wechat-platform.test.ts +0 -111
- package/src/adapters/adapter-interface.ts +0 -217
- package/src/adapters/ccc-adapter.ts +0 -150
- package/src/adapters/claude-adapter.ts +0 -673
- package/src/adapters/claude-session-meta-store.ts +0 -120
- package/src/adapters/codex-adapter.ts +0 -426
- package/src/adapters/codex-session-meta-store.ts +0 -131
- package/src/adapters/cursor-adapter.ts +0 -681
- package/src/adapters/cursor-session-meta-store.ts +0 -154
- package/src/adapters/jsonl-stream.ts +0 -157
- package/src/adapters/raw-stream-log.ts +0 -124
- package/src/adapters/resource-monitor.ts +0 -141
- package/src/agent-activity.ts +0 -175
- package/src/agent-delegate-task-rpc.ts +0 -153
- package/src/agent-delegate-task.ts +0 -91
- package/src/agent-file-rpc.ts +0 -172
- package/src/agent-image-rpc.ts +0 -168
- package/src/agent-platform-routing.ts +0 -28
- package/src/agent-reload-config-rpc.ts +0 -34
- package/src/agent-rpc-body.ts +0 -92
- package/src/agent-stop-stuck.ts +0 -129
- package/src/card-action-routing.ts +0 -14
- package/src/card-plain-text.ts +0 -108
- package/src/cardkit.ts +0 -179
- package/src/cards.ts +0 -684
- package/src/chatgpt-subscription-rpc.ts +0 -27
- package/src/chatgpt-subscription.ts +0 -299
- package/src/chrome-devtools-guard.ts +0 -318
- package/src/claude-sdk-installer.ts +0 -324
- package/src/codex-reset-actions.ts +0 -184
- package/src/config-utils.ts +0 -211
- package/src/config.ts +0 -1063
- package/src/cursor-usage.ts +0 -128
- package/src/exit-banner.ts +0 -33
- package/src/feishu-api.ts +0 -1616
- package/src/feishu-message-ingress.ts +0 -195
- package/src/feishu-platform.ts +0 -159
- package/src/format-message.ts +0 -293
- package/src/git-command.ts +0 -202
- package/src/im-skills.ts +0 -149
- package/src/index.ts +0 -1089
- package/src/litellm-proxy.ts +0 -374
- package/src/orchestrator.ts +0 -2543
- package/src/platform-adapter.ts +0 -70
- package/src/platform-startup.ts +0 -16
- package/src/privacy.ts +0 -118
- package/src/progress/reducer.ts +0 -113
- package/src/progress/terminal-renderer.ts +0 -294
- package/src/progress/view.ts +0 -77
- package/src/response-stall.ts +0 -28
- package/src/runtime-reload.ts +0 -34
- package/src/session-chat-binding.ts +0 -292
- package/src/session-name.ts +0 -8
- package/src/session.ts +0 -2659
- package/src/shared-prefix.ts +0 -29
- package/src/shared.ts +0 -552
- package/src/sim-agent.ts +0 -167
- package/src/sim-platform.ts +0 -177
- package/src/sim-store.ts +0 -317
- package/src/simplify.ts +0 -120
- package/src/startup-lifecycle.ts +0 -250
- package/src/stream-state.ts +0 -177
- package/src/terminal-error.ts +0 -129
- package/src/trace.ts +0 -51
- package/src/turn-cards.ts +0 -118
- package/src/update-command-guard.ts +0 -165
- package/src/wechat-platform.ts +0 -680
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { mkdtempSync, rmSync, writeFileSync, mkdirSync, utimesSync } from "node:fs";
|
|
3
|
-
import { homedir, tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
normalizeSkillPathForPrompt,
|
|
8
|
-
parseSkillFrontmatter,
|
|
9
|
-
scanSkillsDirs,
|
|
10
|
-
buildDefaultSkillDirs,
|
|
11
|
-
buildSkillsIndexPrompt,
|
|
12
|
-
buildSkillTemplate,
|
|
13
|
-
type SkillDirSpec,
|
|
14
|
-
type SkillSource,
|
|
15
|
-
type SkillScope,
|
|
16
|
-
} from "../../deepccc-agent/src/skills.ts";
|
|
17
|
-
|
|
18
|
-
let tempRoot: string;
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
tempRoot = mkdtempSync(join(tmpdir(), "deepccc-skills-"));
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
try {
|
|
26
|
-
rmSync(tempRoot, { recursive: true, force: true });
|
|
27
|
-
} catch {}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
function makeSkill(specDir: string, name: string, description: string): string {
|
|
31
|
-
const dir = join(specDir, name);
|
|
32
|
-
mkdirSync(dir, { recursive: true });
|
|
33
|
-
const skillPath = join(dir, "SKILL.md");
|
|
34
|
-
writeFileSync(skillPath, `---\nname: ${name}\ndescription: ${description}\n---\n\nbody\n`, "utf8");
|
|
35
|
-
return skillPath;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function spec(
|
|
39
|
-
dir: string,
|
|
40
|
-
source: SkillSource,
|
|
41
|
-
scope: SkillScope = "global",
|
|
42
|
-
): SkillDirSpec {
|
|
43
|
-
return { dir, source, scope };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
describe("parseSkillFrontmatter", () => {
|
|
47
|
-
it("parses name and description from frontmatter", () => {
|
|
48
|
-
const content = [
|
|
49
|
-
"---",
|
|
50
|
-
"name: feishu-doc-download-md",
|
|
51
|
-
"description: 下载飞书文档为 Markdown",
|
|
52
|
-
"---",
|
|
53
|
-
"",
|
|
54
|
-
"# 正文",
|
|
55
|
-
].join("\n");
|
|
56
|
-
expect(parseSkillFrontmatter(content)).toEqual({
|
|
57
|
-
name: "feishu-doc-download-md",
|
|
58
|
-
description: "下载飞书文档为 Markdown",
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("returns null when there is no frontmatter", () => {
|
|
63
|
-
expect(parseSkillFrontmatter("# just a heading")).toBeNull();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("tolerates missing description", () => {
|
|
67
|
-
expect(parseSkillFrontmatter("---\nname: minimal-skill\n---\n\nbody")).toEqual({
|
|
68
|
-
name: "minimal-skill",
|
|
69
|
-
description: "",
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("handles CRLF line endings", () => {
|
|
74
|
-
const content = "---\r\nname: crlf-skill\r\ndescription: CRLF 描述\r\n---\r\n\r\nbody";
|
|
75
|
-
expect(parseSkillFrontmatter(content)).toEqual({
|
|
76
|
-
name: "crlf-skill",
|
|
77
|
-
description: "CRLF 描述",
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe("scanSkillsDirs priority matrix", () => {
|
|
83
|
-
it("codex wins over cursor, cursor wins over claude for same-name skills", async () => {
|
|
84
|
-
const claudeDir = join(tempRoot, "claude");
|
|
85
|
-
const cursorDir = join(tempRoot, "cursor");
|
|
86
|
-
const codexDir = join(tempRoot, "codex");
|
|
87
|
-
makeSkill(claudeDir, "dupe", "claude version");
|
|
88
|
-
makeSkill(cursorDir, "dupe", "cursor version");
|
|
89
|
-
makeSkill(codexDir, "dupe", "codex version");
|
|
90
|
-
makeSkill(codexDir, "only-codex", "codex only");
|
|
91
|
-
|
|
92
|
-
const skills = await scanSkillsDirs([
|
|
93
|
-
spec(claudeDir, "claude"),
|
|
94
|
-
spec(cursorDir, "cursor"),
|
|
95
|
-
spec(codexDir, "codex"),
|
|
96
|
-
]);
|
|
97
|
-
|
|
98
|
-
const byName = new Map(skills.map((s) => [s.name, s]));
|
|
99
|
-
expect(byName.get("dupe")?.description).toBe("codex version");
|
|
100
|
-
expect(byName.get("dupe")?.source).toBe("codex");
|
|
101
|
-
expect(byName.get("dupe")?.skillPath).toContain(join("codex", "dupe"));
|
|
102
|
-
expect(byName.get("only-codex")?.source).toBe("codex");
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("project scope wins over global scope within the same source", async () => {
|
|
106
|
-
const globalCodex = join(tempRoot, "codex-global");
|
|
107
|
-
const projectCodex = join(tempRoot, "codex-project");
|
|
108
|
-
makeSkill(globalCodex, "dup", "global version");
|
|
109
|
-
makeSkill(projectCodex, "dup", "project version");
|
|
110
|
-
|
|
111
|
-
const skills = await scanSkillsDirs([
|
|
112
|
-
spec(globalCodex, "codex", "global"),
|
|
113
|
-
spec(projectCodex, "codex", "project"),
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
const byName = new Map(skills.map((s) => [s.name, s]));
|
|
117
|
-
expect(byName.get("dup")?.description).toBe("project version");
|
|
118
|
-
expect(byName.get("dup")?.scope).toBe("project");
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("deepccc source has the highest priority over codex", async () => {
|
|
122
|
-
const codexDir = join(tempRoot, "codex");
|
|
123
|
-
const deepcccDir = join(tempRoot, "deepccc");
|
|
124
|
-
makeSkill(codexDir, "dup", "from codex");
|
|
125
|
-
makeSkill(deepcccDir, "dup", "from deepccc");
|
|
126
|
-
|
|
127
|
-
const skills = await scanSkillsDirs([
|
|
128
|
-
spec(codexDir, "codex"),
|
|
129
|
-
spec(deepcccDir, "deepccc"),
|
|
130
|
-
]);
|
|
131
|
-
|
|
132
|
-
expect(skills.find((s) => s.name === "dup")?.description).toBe("from deepccc");
|
|
133
|
-
expect(skills.find((s) => s.name === "dup")?.source).toBe("deepccc");
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("skips hidden dirs, dirs without SKILL.md, and missing dirs", async () => {
|
|
137
|
-
const dir = join(tempRoot, "src");
|
|
138
|
-
mkdirSync(join(dir, ".system"), { recursive: true });
|
|
139
|
-
writeFileSync(join(dir, ".system", "SKILL.md"), "---\nname: system-skill\ndescription: x\n---\n", "utf8");
|
|
140
|
-
mkdirSync(join(dir, "no-skill-dir"));
|
|
141
|
-
|
|
142
|
-
makeSkill(dir, "ok", "fine");
|
|
143
|
-
const skills = await scanSkillsDirs([
|
|
144
|
-
spec(join(tempRoot, "missing-dir"), "codex"),
|
|
145
|
-
spec(dir, "codex"),
|
|
146
|
-
]);
|
|
147
|
-
|
|
148
|
-
expect(skills).toHaveLength(1);
|
|
149
|
-
expect(skills[0].name).toBe("ok");
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe("scanSkillsDirs hot reload (mtime cache)", () => {
|
|
154
|
-
it("re-reads a skill after its SKILL.md content changes", async () => {
|
|
155
|
-
const dir = join(tempRoot, "src");
|
|
156
|
-
const skillPath = makeSkill(dir, "live", "v1");
|
|
157
|
-
|
|
158
|
-
const first = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
159
|
-
expect(first.find((s) => s.name === "live")?.description).toBe("v1");
|
|
160
|
-
|
|
161
|
-
writeFileSync(skillPath, "---\nname: live\ndescription: v2\n---\n\nbody\n", "utf8");
|
|
162
|
-
utimesSync(skillPath, new Date(Date.now() + 3000), new Date(Date.now() + 3000)); // 强制 mtime 前进
|
|
163
|
-
|
|
164
|
-
const second = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
165
|
-
expect(second.find((s) => s.name === "live")?.description).toBe("v2");
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("new skill dirs are picked up on the next scan", async () => {
|
|
169
|
-
const dir = join(tempRoot, "src");
|
|
170
|
-
makeSkill(dir, "a", "A");
|
|
171
|
-
|
|
172
|
-
const first = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
173
|
-
expect(first).toHaveLength(1);
|
|
174
|
-
|
|
175
|
-
makeSkill(dir, "b", "B"); // 新技能,无需改 mtime(目录枚举每次都做)
|
|
176
|
-
const second = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
177
|
-
expect(second.map((s) => s.name).sort()).toEqual(["a", "b"]);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("unchanged skills return identical results across scans", async () => {
|
|
181
|
-
const dir = join(tempRoot, "src");
|
|
182
|
-
makeSkill(dir, "a", "A");
|
|
183
|
-
|
|
184
|
-
const first = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
185
|
-
const second = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
186
|
-
expect(second).toEqual(first);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe("buildDefaultSkillDirs", () => {
|
|
191
|
-
it("orders dirs low->high priority: claude < cursor < codex < deepccc, project after global", () => {
|
|
192
|
-
const dirs = buildDefaultSkillDirs("C:/proj");
|
|
193
|
-
expect(dirs.map((d) => `${d.source}:${d.scope}`)).toEqual([
|
|
194
|
-
"claude:global",
|
|
195
|
-
"claude:project",
|
|
196
|
-
"cursor:global",
|
|
197
|
-
"cursor:project",
|
|
198
|
-
"codex:global",
|
|
199
|
-
"codex:global",
|
|
200
|
-
"codex:project",
|
|
201
|
-
"deepccc:global",
|
|
202
|
-
"deepccc:project",
|
|
203
|
-
]);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("points codex global dirs at ~/.codex/skills and ~/.agents/skills", () => {
|
|
207
|
-
const dirs = buildDefaultSkillDirs("C:/proj").filter((d) => d.source === "codex" && d.scope === "global");
|
|
208
|
-
expect(dirs.map((d) => d.dir)).toEqual([
|
|
209
|
-
join(require("node:os").homedir(), ".codex", "skills"),
|
|
210
|
-
join(require("node:os").homedir(), ".agents", "skills"),
|
|
211
|
-
]);
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
describe("normalizeSkillPathForPrompt", () => {
|
|
216
|
-
it("abbreviates home-directory paths with ~ and normalizes separators", () => {
|
|
217
|
-
const home = homedir();
|
|
218
|
-
const abs = join(home, ".codex", "skills", "x", "SKILL.md");
|
|
219
|
-
expect(normalizeSkillPathForPrompt(abs)).toBe("~/.codex/skills/x/SKILL.md");
|
|
220
|
-
expect(normalizeSkillPathForPrompt(home)).toBe("~");
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("keeps paths outside the home directory unchanged (separators normalized)", () => {
|
|
224
|
-
expect(normalizeSkillPathForPrompt("C:\\proj\\.claude\\skills\\x\\SKILL.md")).toBe(
|
|
225
|
-
"C:/proj/.claude/skills/x/SKILL.md",
|
|
226
|
-
);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
describe("buildSkillsIndexPrompt", () => {
|
|
231
|
-
it("renders index with source markers and the skill creation convention", () => {
|
|
232
|
-
const prompt = buildSkillsIndexPrompt([
|
|
233
|
-
{
|
|
234
|
-
name: "feishu-doc",
|
|
235
|
-
description: "下载飞书文档",
|
|
236
|
-
skillPath: "C:/x/feishu-doc/SKILL.md",
|
|
237
|
-
source: "codex",
|
|
238
|
-
scope: "global",
|
|
239
|
-
},
|
|
240
|
-
]);
|
|
241
|
-
|
|
242
|
-
expect(prompt).toContain("## 可用技能");
|
|
243
|
-
expect(prompt).toContain("**feishu-doc**");
|
|
244
|
-
expect(prompt).toContain("[codex:global]");
|
|
245
|
-
expect(prompt).toContain("## 创建技能");
|
|
246
|
-
expect(prompt).toContain(".deepccc/skills");
|
|
247
|
-
expect(prompt).toContain("read_file");
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("renders home-abbreviated skill paths so the prompt stays stable across machines", () => {
|
|
251
|
-
const home = homedir();
|
|
252
|
-
const prompt = buildSkillsIndexPrompt([
|
|
253
|
-
{
|
|
254
|
-
name: "demo",
|
|
255
|
-
description: "d",
|
|
256
|
-
skillPath: join(home, ".codex", "skills", "demo", "SKILL.md"),
|
|
257
|
-
source: "codex",
|
|
258
|
-
scope: "global",
|
|
259
|
-
},
|
|
260
|
-
]);
|
|
261
|
-
|
|
262
|
-
expect(prompt).toContain("~/.codex/skills/demo/SKILL.md");
|
|
263
|
-
expect(prompt).not.toContain(home);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("returns empty string for no skills", () => {
|
|
267
|
-
expect(buildSkillsIndexPrompt([])).toBe("");
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe("buildSkillTemplate", () => {
|
|
272
|
-
it("renders a Codex-style SKILL.md with frontmatter", () => {
|
|
273
|
-
const tpl = buildSkillTemplate("my-skill", "does something");
|
|
274
|
-
expect(tpl.startsWith("---")).toBe(true);
|
|
275
|
-
expect(tpl).toContain("name: my-skill");
|
|
276
|
-
expect(tpl).toContain("description: does something");
|
|
277
|
-
expect(tpl).toContain("# my-skill");
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it("defaults description to empty when omitted", () => {
|
|
281
|
-
const tpl = buildSkillTemplate("bare-skill", "");
|
|
282
|
-
expect(tpl).toContain("description: ");
|
|
283
|
-
});
|
|
284
|
-
});
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
decodeDdgHref,
|
|
5
|
-
extractHtmlTitle,
|
|
6
|
-
htmlToPlainText,
|
|
7
|
-
parseDuckDuckGoHtml,
|
|
8
|
-
webFetchForTool,
|
|
9
|
-
webSearchForTool,
|
|
10
|
-
type FetchLike,
|
|
11
|
-
} from "../../deepccc-agent/src/web-tools.ts";
|
|
12
|
-
|
|
13
|
-
const DDG_HTML = `<!DOCTYPE html>
|
|
14
|
-
<html>
|
|
15
|
-
<head><title>Search results</title></head>
|
|
16
|
-
<body>
|
|
17
|
-
<div class="result results_links results_links_deep web-result">
|
|
18
|
-
<h2 class="result__title">
|
|
19
|
-
<a rel="nofollow" class="result__a" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fnodejs.org%2Fen%2Fdocs&rut=abc">Node.js <b>Docs</b></a>
|
|
20
|
-
</h2>
|
|
21
|
-
<a rel="nofollow" class="result__snippet" href="//duckduckgo.com/l/?uddg=...">Official documentation for Node.js & npm.</a>
|
|
22
|
-
</div>
|
|
23
|
-
<div class="result">
|
|
24
|
-
<a rel="nofollow" class="result__a" href="https://example.com/page">Example "quoted" page</a>
|
|
25
|
-
<a rel="nofollow" class="result__snippet" href="https://example.com/page">A plain snippet without highlight.</a>
|
|
26
|
-
</div>
|
|
27
|
-
</body>
|
|
28
|
-
</html>`;
|
|
29
|
-
|
|
30
|
-
const WEB_FETCH_HTML = `<!DOCTYPE html>
|
|
31
|
-
<html><head><title>Fetch & Me</title></head>
|
|
32
|
-
<body>
|
|
33
|
-
<style>.x { color: red }</style>
|
|
34
|
-
<script>alert("x")</script>
|
|
35
|
-
<h1>Hello World</h1>
|
|
36
|
-
<p>First paragraph with & entity.</p>
|
|
37
|
-
<p>Second paragraph<br>with a break.</p>
|
|
38
|
-
<footer>bye</footer>
|
|
39
|
-
</body></html>`;
|
|
40
|
-
|
|
41
|
-
describe("parseDuckDuckGoHtml", () => {
|
|
42
|
-
it("extracts title, decoded url, and snippet per result", () => {
|
|
43
|
-
const results = parseDuckDuckGoHtml(DDG_HTML);
|
|
44
|
-
expect(results).toHaveLength(2);
|
|
45
|
-
expect(results[0]).toEqual({
|
|
46
|
-
title: "Node.js Docs",
|
|
47
|
-
url: "https://nodejs.org/en/docs",
|
|
48
|
-
snippet: "Official documentation for Node.js & npm.",
|
|
49
|
-
});
|
|
50
|
-
expect(results[1]).toEqual({
|
|
51
|
-
title: 'Example "quoted" page',
|
|
52
|
-
url: "https://example.com/page",
|
|
53
|
-
snippet: "A plain snippet without highlight.",
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("returns empty array for pages without results", () => {
|
|
58
|
-
expect(parseDuckDuckGoHtml("<html><body>no results here</body></html>")).toEqual([]);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("decodeDdgHref", () => {
|
|
63
|
-
it("decodes uddg redirect params and restores protocol", () => {
|
|
64
|
-
expect(
|
|
65
|
-
decodeDdgHref("//duckduckgo.com/l/?uddg=https%3A%2F%2Fnodejs.org%2Fen%2Fdocs&rut=abc"),
|
|
66
|
-
).toBe("https://nodejs.org/en/docs");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("passes through plain urls", () => {
|
|
70
|
-
expect(decodeDdgHref("https://example.com/a?b=1")).toBe("https://example.com/a?b=1");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("returns input untouched when unparseable", () => {
|
|
74
|
-
expect(decodeDdgHref("not a url")).toBe("not a url");
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("htmlToPlainText", () => {
|
|
79
|
-
it("strips scripts/styles, keeps block boundaries, decodes entities, compresses whitespace", () => {
|
|
80
|
-
const text = htmlToPlainText(WEB_FETCH_HTML);
|
|
81
|
-
expect(text).not.toContain("alert");
|
|
82
|
-
expect(text).not.toContain(".x {");
|
|
83
|
-
expect(text).toContain("Hello World");
|
|
84
|
-
expect(text).toContain("First paragraph with & entity.");
|
|
85
|
-
expect(text).toContain("Second paragraph\nwith a break.");
|
|
86
|
-
expect(text).toContain("bye");
|
|
87
|
-
// 段落间允许单个空行,但不得出现连续空行
|
|
88
|
-
expect(text).not.toContain("\n\n\n");
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe("extractHtmlTitle", () => {
|
|
93
|
-
it("extracts and decodes the title", () => {
|
|
94
|
-
expect(extractHtmlTitle(WEB_FETCH_HTML)).toBe("Fetch & Me");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("returns empty string when no title", () => {
|
|
98
|
-
expect(extractHtmlTitle("<html><body>x</body></html>")).toBe("");
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("webSearchForTool", () => {
|
|
103
|
-
function mockFetch(html: string, status = 200): FetchLike {
|
|
104
|
-
return async () =>
|
|
105
|
-
new Response(html, {
|
|
106
|
-
status,
|
|
107
|
-
headers: { "content-type": "text/html; charset=utf-8" },
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
it("returns parsed results from the search page", async () => {
|
|
112
|
-
const output = await webSearchForTool(
|
|
113
|
-
{ query: "nodejs docs" },
|
|
114
|
-
{ fetchImpl: mockFetch(DDG_HTML) },
|
|
115
|
-
);
|
|
116
|
-
expect(output.query).toBe("nodejs docs");
|
|
117
|
-
expect(output.results).toHaveLength(2);
|
|
118
|
-
expect(output.results[0].url).toBe("https://nodejs.org/en/docs");
|
|
119
|
-
expect(output.results[0].snippet).toContain("Node.js");
|
|
120
|
-
expect(typeof output.durationMs).toBe("number");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("respects maxResults and caps at 10", async () => {
|
|
124
|
-
const html = Array.from({ length: 12 }, (_, i) => {
|
|
125
|
-
const title = `<a rel="nofollow" class="result__a" href="https://e.com/${i}">R${i}</a>`;
|
|
126
|
-
const snippet = `<a rel="nofollow" class="result__snippet" href="https://e.com/${i}">s${i}</a>`;
|
|
127
|
-
return `<div>${title}${snippet}</div>`;
|
|
128
|
-
}).join("");
|
|
129
|
-
const output = await webSearchForTool({ query: "many" }, { fetchImpl: mockFetch(html) });
|
|
130
|
-
expect(output.results).toHaveLength(5);
|
|
131
|
-
expect(output.truncated).toBe(true);
|
|
132
|
-
|
|
133
|
-
const output2 = await webSearchForTool({ query: "many", maxResults: 20 }, { fetchImpl: mockFetch(html) });
|
|
134
|
-
expect(output2.results).toHaveLength(10);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("returns empty results (not an error) when the page has no matches", async () => {
|
|
138
|
-
const output = await webSearchForTool(
|
|
139
|
-
{ query: "zzz-nothing" },
|
|
140
|
-
{ fetchImpl: mockFetch("<html><body>no results</body></html>") },
|
|
141
|
-
);
|
|
142
|
-
expect(output.results).toEqual([]);
|
|
143
|
-
expect(output.truncated).toBe(false);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("throws on empty query", async () => {
|
|
147
|
-
await expect(webSearchForTool({ query: " " }, { fetchImpl: mockFetch("") })).rejects.toThrow(
|
|
148
|
-
"query is required",
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("throws on non-2xx response", async () => {
|
|
153
|
-
await expect(
|
|
154
|
-
webSearchForTool({ query: "x" }, { fetchImpl: mockFetch("blocked", 429) }),
|
|
155
|
-
).rejects.toThrow("HTTP 429");
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
describe("webFetchForTool", () => {
|
|
160
|
-
function mockFetch(html: string, status = 200, contentType = "text/html; charset=utf-8"): FetchLike {
|
|
161
|
-
return async () =>
|
|
162
|
-
new Response(html, {
|
|
163
|
-
status,
|
|
164
|
-
headers: { "content-type": contentType },
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
it("fetches and converts html to plain text with title", async () => {
|
|
169
|
-
const output = await webFetchForTool(
|
|
170
|
-
{ url: "https://example.com/page" },
|
|
171
|
-
{ fetchImpl: mockFetch(WEB_FETCH_HTML) },
|
|
172
|
-
);
|
|
173
|
-
expect(output.title).toBe("Fetch & Me");
|
|
174
|
-
expect(output.text).toContain("Hello World");
|
|
175
|
-
expect(output.text).toContain("Second paragraph\nwith a break.");
|
|
176
|
-
expect(output.text).not.toContain("alert");
|
|
177
|
-
expect(output.contentType).toContain("text/html");
|
|
178
|
-
expect(output.chars).toBe(output.text.length);
|
|
179
|
-
expect(output.truncated).toBe(false);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("truncates text beyond maxChars", async () => {
|
|
183
|
-
const output = await webFetchForTool(
|
|
184
|
-
{ url: "https://example.com/long", maxChars: 10 },
|
|
185
|
-
{ fetchImpl: mockFetch("<p>hello world and more</p>") },
|
|
186
|
-
);
|
|
187
|
-
expect(output.text).toBe("hello worl");
|
|
188
|
-
expect(output.truncated).toBe(true);
|
|
189
|
-
expect(output.chars).toBe(10);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("truncates oversized response bodies", async () => {
|
|
193
|
-
const big = `<!DOCTYPE html><html><body><p>${"a".repeat(600 * 1024)}</p></body></html>`;
|
|
194
|
-
const output = await webFetchForTool(
|
|
195
|
-
{ url: "https://example.com/big" },
|
|
196
|
-
{ fetchImpl: mockFetch(big) },
|
|
197
|
-
);
|
|
198
|
-
expect(output.truncated).toBe(true);
|
|
199
|
-
expect(output.text.length).toBeLessThan(600 * 1024);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("rejects non-http(s) protocols", async () => {
|
|
203
|
-
await expect(
|
|
204
|
-
webFetchForTool({ url: "file:///etc/passwd" }, { fetchImpl: mockFetch("") }),
|
|
205
|
-
).rejects.toThrow("unsupported protocol");
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("rejects invalid urls", async () => {
|
|
209
|
-
await expect(
|
|
210
|
-
webFetchForTool({ url: "not a url" }, { fetchImpl: mockFetch("") }),
|
|
211
|
-
).rejects.toThrow("invalid URL");
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("throws on missing url and non-2xx", async () => {
|
|
215
|
-
await expect(webFetchForTool({ url: " " })).rejects.toThrow("url is required");
|
|
216
|
-
await expect(
|
|
217
|
-
webFetchForTool({ url: "https://example.com/404" }, { fetchImpl: mockFetch("nf", 404) }),
|
|
218
|
-
).rejects.toThrow("HTTP 404");
|
|
219
|
-
});
|
|
220
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { resolveFeishuCardActionChatType } from "../card-action-routing.ts";
|
|
4
|
-
|
|
5
|
-
describe("resolveFeishuCardActionChatType", () => {
|
|
6
|
-
it("keeps card commands in a persisted private chat on the p2p route", () => {
|
|
7
|
-
expect(resolveFeishuCardActionChatType("private-chat", {
|
|
8
|
-
"private-chat": { chatType: "p2p" },
|
|
9
|
-
})).toBe("p2p");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("defaults unknown and group chats to the group route", () => {
|
|
13
|
-
expect(resolveFeishuCardActionChatType("group-chat", {
|
|
14
|
-
"group-chat": { chatType: "group" },
|
|
15
|
-
})).toBe("group");
|
|
16
|
-
expect(resolveFeishuCardActionChatType("unknown-chat", {})).toBe("group");
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { cardJsonToPlainText } from "../card-plain-text.ts";
|
|
4
|
-
import { progressView } from "../progress/view.ts";
|
|
5
|
-
import {
|
|
6
|
-
buildHelpCard,
|
|
7
|
-
buildProgressCard,
|
|
8
|
-
buildStatusCard,
|
|
9
|
-
} from "../cards.ts";
|
|
10
|
-
|
|
11
|
-
describe("cardJsonToPlainText", () => {
|
|
12
|
-
it("converts help cards to readable text with commands", () => {
|
|
13
|
-
const text = cardJsonToPlainText(buildHelpCard("hello"));
|
|
14
|
-
|
|
15
|
-
expect(text).toContain("# ChatCCC");
|
|
16
|
-
expect(text).toContain("hello");
|
|
17
|
-
expect(text).toContain("/new");
|
|
18
|
-
expect(text).toContain("/new cursor");
|
|
19
|
-
expect(text).toContain("/new codex");
|
|
20
|
-
expect(text).toContain("/restart");
|
|
21
|
-
expect(text).toContain("/update");
|
|
22
|
-
expect(text).toContain("/cd");
|
|
23
|
-
expect(text).toContain("/abd");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("converts status cards from v1 card format", () => {
|
|
27
|
-
const text = cardJsonToPlainText(buildStatusCard("status body", "green"));
|
|
28
|
-
|
|
29
|
-
expect(text).toContain("# 会话状态");
|
|
30
|
-
expect(text).toContain("status body");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("converts schema 2.0 progress cards", () => {
|
|
34
|
-
const text = cardJsonToPlainText(buildProgressCard(progressView({ text: "stream body" })));
|
|
35
|
-
|
|
36
|
-
expect(text).toContain("# 生成中...");
|
|
37
|
-
expect(text).toContain("stream body");
|
|
38
|
-
expect(text).toContain("/state");
|
|
39
|
-
expect(text).toContain("/stop");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("returns null for invalid card json", () => {
|
|
43
|
-
expect(cardJsonToPlainText("{bad json")).toBeNull();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { updateCardKitCard } from "../cardkit.ts";
|
|
4
|
-
|
|
5
|
-
function abortError(): Error {
|
|
6
|
-
const err = new Error("aborted");
|
|
7
|
-
err.name = "AbortError";
|
|
8
|
-
return err;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe("CardKit request timeout", () => {
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
vi.useRealTimers();
|
|
14
|
-
vi.restoreAllMocks();
|
|
15
|
-
vi.unstubAllGlobals();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("aborts a hung card update so display.cardBusy can be released", async () => {
|
|
19
|
-
vi.useFakeTimers();
|
|
20
|
-
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
21
|
-
|
|
22
|
-
const fetchMock = vi.fn((_url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => (
|
|
23
|
-
new Promise<Response>((_resolve, reject) => {
|
|
24
|
-
init?.signal?.addEventListener("abort", () => reject(abortError()));
|
|
25
|
-
})
|
|
26
|
-
));
|
|
27
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
28
|
-
|
|
29
|
-
const update = expect(updateCardKitCard("token", "card-1", "{}", 7))
|
|
30
|
-
.rejects.toThrow("updateCard cardId=card-1 seq=7 timeout after 15000ms");
|
|
31
|
-
await vi.advanceTimersByTimeAsync(15_000);
|
|
32
|
-
|
|
33
|
-
await update;
|
|
34
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
35
|
-
expect.stringContaining("/cardkit/v1/cards/card-1"),
|
|
36
|
-
expect.objectContaining({ signal: expect.any(AbortSignal) }),
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("also aborts when response body reading hangs", async () => {
|
|
41
|
-
vi.useFakeTimers();
|
|
42
|
-
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
43
|
-
|
|
44
|
-
const fetchMock = vi.fn((_url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => (
|
|
45
|
-
Promise.resolve({
|
|
46
|
-
status: 200,
|
|
47
|
-
text: () => new Promise<string>((_resolve, reject) => {
|
|
48
|
-
init?.signal?.addEventListener("abort", () => reject(abortError()));
|
|
49
|
-
}),
|
|
50
|
-
} as Response)
|
|
51
|
-
));
|
|
52
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
53
|
-
|
|
54
|
-
const update = expect(updateCardKitCard("token", "card-2", "{}", 8))
|
|
55
|
-
.rejects.toThrow("updateCard cardId=card-2 seq=8 timeout after 15000ms");
|
|
56
|
-
await vi.advanceTimersByTimeAsync(15_000);
|
|
57
|
-
|
|
58
|
-
await update;
|
|
59
|
-
});
|
|
60
|
-
});
|