-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathautonomous.test.ts
More file actions
95 lines (84 loc) · 2.5 KB
/
autonomous.test.ts
File metadata and controls
95 lines (84 loc) · 2.5 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
93
94
95
import { afterEach, describe, expect, test } from "bun:test";
import { type Config, getConfig, validateConfig } from "./autonomous";
const ENV_KEYS = [
"MOLTBOOK_AGENT_NAME",
"LLM_API_KEY",
"OPENROUTER_API_KEY",
"OPENAI_API_KEY",
"LLM_BASE_URL",
"MODEL",
"MOLTBOOK_TOKEN",
"MOLTBOOK_AUTONOMY_INTERVAL_MS",
"MOLTBOOK_AUTONOMY_MAX_STEPS",
] as const;
const originalEnv = new Map(
ENV_KEYS.map((key) => [key, process.env[key]] as const),
);
function clearConfigEnv(): void {
for (const key of ENV_KEYS) {
delete process.env[key];
}
}
afterEach(() => {
for (const key of ENV_KEYS) {
const value = originalEnv.get(key);
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
});
describe("Moltbook autonomous config", () => {
test("uses deterministic defaults and OpenRouter fallback", () => {
clearConfigEnv();
process.env.OPENROUTER_API_KEY = "openrouter-key";
process.env.MOLTBOOK_AUTONOMY_INTERVAL_MS = "15000";
process.env.MOLTBOOK_AUTONOMY_MAX_STEPS = "3";
const config = getConfig();
expect(config.agentName).toBe("PROPHET_ELIZA_7");
expect(config.llmApiKey).toBe("openrouter-key");
expect(config.llmBaseUrl).toBe("https://openrouter.ai/api/v1");
expect(config.model).toBe("anthropic/claude-sonnet-4.6");
expect(config.autonomyIntervalMs).toBe(15000);
expect(config.autonomyMaxSteps).toBe(3);
});
test("requires an LLM key and treats Moltbook token as optional", () => {
const baseConfig: Config = {
agentName: "PROPHET_ELIZA_7",
personality: "test",
llmBaseUrl: "https://openrouter.ai/api/v1",
model: "anthropic/claude-sonnet-4.6",
autonomyIntervalMs: 45000,
autonomyMaxSteps: 0,
};
expect(validateConfig(baseConfig)).toEqual({
valid: false,
errors: [
"LLM_API_KEY (or OPENROUTER_API_KEY / OPENAI_API_KEY) is required for autonomous mode",
],
warnings: [
"MOLTBOOK_TOKEN not set - posting and commenting will be disabled",
],
});
expect(
validateConfig({
...baseConfig,
llmApiKey: "llm-key",
}),
).toEqual({
valid: true,
errors: [],
warnings: [
"MOLTBOOK_TOKEN not set - posting and commenting will be disabled",
],
});
expect(
validateConfig({
...baseConfig,
llmApiKey: "llm-key",
moltbookToken: "moltbook-token",
}),
).toEqual({ valid: true, errors: [], warnings: [] });
});
});