forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost-compat.test.ts
More file actions
92 lines (84 loc) · 2.92 KB
/
Copy pathhost-compat.test.ts
File metadata and controls
92 lines (84 loc) · 2.92 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
90
91
92
import { describe, expect, it } from "vitest";
import {
assertContextEngineHostSupport,
buildGenericCliContextEngineHostSupport,
CODEX_APP_SERVER_CONTEXT_ENGINE_HOST,
evaluateContextEngineHostSupport,
OPENCLAW_EMBEDDED_CONTEXT_ENGINE_HOST,
} from "./host-compat.js";
import type { ContextEngine, ContextEngineHostCapability } from "./types.js";
function createEngine(requiredCapabilities: ContextEngineHostCapability[]): ContextEngine {
return {
info: {
id: "lossless-claw",
name: "Lossless",
hostRequirements: {
"agent-run": {
requiredCapabilities,
unsupportedMessage:
"Use the native Codex or OpenClaw embedded runtime, or switch contextEngine to legacy.",
},
},
},
async ingest() {
return { ingested: true };
},
async assemble({ messages }) {
return { messages, estimatedTokens: 0 };
},
async compact() {
return { ok: true, compacted: false };
},
};
}
describe("context engine host compatibility", () => {
it("allows engines with no host requirements", () => {
assertContextEngineHostSupport({
contextEngine: createEngine([]),
operation: "agent-run",
host: buildGenericCliContextEngineHostSupport({ backendId: "claude-cli" }),
});
});
it("rejects generic CLI hosts when an engine requires pre-prompt assembly", () => {
expect(() =>
assertContextEngineHostSupport({
contextEngine: createEngine(["assemble-before-prompt"]),
operation: "agent-run",
host: buildGenericCliContextEngineHostSupport({ backendId: "claude-cli" }),
}),
).toThrow(
'Context engine "lossless-claw" cannot run operation "agent-run" on CLI backend "claude-cli".',
);
});
it("evaluates missing capabilities without throwing", () => {
const evaluation = evaluateContextEngineHostSupport({
contextEngineInfo: createEngine(["assemble-before-prompt"]).info,
operation: "agent-run",
host: buildGenericCliContextEngineHostSupport({ backendId: "claude-cli" }),
});
expect(evaluation).toMatchObject({
ok: false,
missingCapabilities: ["assemble-before-prompt"],
});
});
it("allows native Codex and OpenClaw embedded hosts to satisfy pre-prompt assembly", () => {
const engine = createEngine(["assemble-before-prompt"]);
assertContextEngineHostSupport({
contextEngine: engine,
operation: "agent-run",
host: CODEX_APP_SERVER_CONTEXT_ENGINE_HOST,
});
assertContextEngineHostSupport({
contextEngine: engine,
operation: "agent-run",
host: OPENCLAW_EMBEDDED_CONTEXT_ENGINE_HOST,
});
});
it("allows native Codex to satisfy thread bootstrap projection", () => {
assertContextEngineHostSupport({
contextEngine: createEngine(["assemble-before-prompt", "thread-bootstrap-projection"]),
operation: "agent-run",
host: CODEX_APP_SERVER_CONTEXT_ENGINE_HOST,
});
});
});