fix: stabilize session tools and tests
This commit is contained in:
@@ -44,11 +44,13 @@ export function createClawdbotTools(options?: {
|
||||
/** Mutable ref to track if a reply was sent (for "first" mode). */
|
||||
hasRepliedRef?: { value: boolean };
|
||||
}): AnyAgentTool[] {
|
||||
const imageTool = createImageTool({
|
||||
config: options?.config,
|
||||
agentDir: options?.agentDir,
|
||||
sandboxRoot: options?.sandboxRoot,
|
||||
});
|
||||
const imageTool = options?.agentDir?.trim()
|
||||
? createImageTool({
|
||||
config: options?.config,
|
||||
agentDir: options.agentDir,
|
||||
sandboxRoot: options?.sandboxRoot,
|
||||
})
|
||||
: null;
|
||||
const memorySearchTool = createMemorySearchTool({
|
||||
config: options?.config,
|
||||
agentSessionKey: options?.agentSessionKey,
|
||||
|
||||
@@ -703,45 +703,49 @@ describe("runEmbeddedPiAgent", () => {
|
||||
).resolves.toBeTruthy();
|
||||
});
|
||||
|
||||
it("persists the first user message before assistant output", async () => {
|
||||
const agentDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-agent-"),
|
||||
);
|
||||
const workspaceDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-workspace-"),
|
||||
);
|
||||
const sessionFile = path.join(workspaceDir, "session.jsonl");
|
||||
it(
|
||||
"persists the first user message before assistant output",
|
||||
{ timeout: 15_000 },
|
||||
async () => {
|
||||
const agentDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-agent-"),
|
||||
);
|
||||
const workspaceDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-workspace-"),
|
||||
);
|
||||
const sessionFile = path.join(workspaceDir, "session.jsonl");
|
||||
|
||||
const cfg = makeOpenAiConfig(["mock-1"]);
|
||||
await ensureModels(cfg, agentDir);
|
||||
const cfg = makeOpenAiConfig(["mock-1"]);
|
||||
await ensureModels(cfg, agentDir);
|
||||
|
||||
await runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: "agent:main:main",
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
prompt: "hello",
|
||||
provider: "openai",
|
||||
model: "mock-1",
|
||||
timeoutMs: 5_000,
|
||||
agentDir,
|
||||
});
|
||||
await runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: "agent:main:main",
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
prompt: "hello",
|
||||
provider: "openai",
|
||||
model: "mock-1",
|
||||
timeoutMs: 5_000,
|
||||
agentDir,
|
||||
});
|
||||
|
||||
const messages = await readSessionMessages(sessionFile);
|
||||
const firstUserIndex = messages.findIndex(
|
||||
(message) =>
|
||||
message?.role === "user" &&
|
||||
textFromContent(message.content) === "hello",
|
||||
);
|
||||
const firstAssistantIndex = messages.findIndex(
|
||||
(message) => message?.role === "assistant",
|
||||
);
|
||||
expect(firstUserIndex).toBeGreaterThanOrEqual(0);
|
||||
if (firstAssistantIndex !== -1) {
|
||||
expect(firstUserIndex).toBeLessThan(firstAssistantIndex);
|
||||
}
|
||||
}, 15_000);
|
||||
const messages = await readSessionMessages(sessionFile);
|
||||
const firstUserIndex = messages.findIndex(
|
||||
(message) =>
|
||||
message?.role === "user" &&
|
||||
textFromContent(message.content) === "hello",
|
||||
);
|
||||
const firstAssistantIndex = messages.findIndex(
|
||||
(message) => message?.role === "assistant",
|
||||
);
|
||||
expect(firstUserIndex).toBeGreaterThanOrEqual(0);
|
||||
if (firstAssistantIndex !== -1) {
|
||||
expect(firstUserIndex).toBeLessThan(firstAssistantIndex);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("persists the user message when prompt fails before assistant output", async () => {
|
||||
const agentDir = await fs.mkdtemp(
|
||||
|
||||
@@ -14,35 +14,39 @@ vi.mock("../commands/models.js", async () => {
|
||||
});
|
||||
|
||||
describe("models cli", () => {
|
||||
it("registers github-copilot login command", async () => {
|
||||
const { Command } = await import("commander");
|
||||
const { registerModelsCli } = await import("./models-cli.js");
|
||||
it(
|
||||
"registers github-copilot login command",
|
||||
{ timeout: 15_000 },
|
||||
async () => {
|
||||
const { Command } = await import("commander");
|
||||
const { registerModelsCli } = await import("./models-cli.js");
|
||||
|
||||
const program = new Command();
|
||||
registerModelsCli(program);
|
||||
const program = new Command();
|
||||
registerModelsCli(program);
|
||||
|
||||
const models = program.commands.find((cmd) => cmd.name() === "models");
|
||||
expect(models).toBeTruthy();
|
||||
const models = program.commands.find((cmd) => cmd.name() === "models");
|
||||
expect(models).toBeTruthy();
|
||||
|
||||
const auth = models?.commands.find((cmd) => cmd.name() === "auth");
|
||||
expect(auth).toBeTruthy();
|
||||
const auth = models?.commands.find((cmd) => cmd.name() === "auth");
|
||||
expect(auth).toBeTruthy();
|
||||
|
||||
const login = auth?.commands.find(
|
||||
(cmd) => cmd.name() === "login-github-copilot",
|
||||
);
|
||||
expect(login).toBeTruthy();
|
||||
const login = auth?.commands.find(
|
||||
(cmd) => cmd.name() === "login-github-copilot",
|
||||
);
|
||||
expect(login).toBeTruthy();
|
||||
|
||||
await program.parseAsync(
|
||||
["models", "auth", "login-github-copilot", "--yes"],
|
||||
{
|
||||
from: "user",
|
||||
},
|
||||
);
|
||||
await program.parseAsync(
|
||||
["models", "auth", "login-github-copilot", "--yes"],
|
||||
{
|
||||
from: "user",
|
||||
},
|
||||
);
|
||||
|
||||
expect(githubCopilotLoginCommand).toHaveBeenCalledTimes(1);
|
||||
expect(githubCopilotLoginCommand).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ yes: true }),
|
||||
expect.any(Object),
|
||||
);
|
||||
}, 15_000);
|
||||
expect(githubCopilotLoginCommand).toHaveBeenCalledTimes(1);
|
||||
expect(githubCopilotLoginCommand).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ yes: true }),
|
||||
expect.any(Object),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -325,7 +325,7 @@ vi.mock("./doctor-state-migrations.js", () => ({
|
||||
describe("doctor", () => {
|
||||
it(
|
||||
"migrates routing.allowFrom to whatsapp.allowFrom",
|
||||
{ timeout: 15_000 },
|
||||
{ timeout: 30_000 },
|
||||
async () => {
|
||||
readConfigFileSnapshot.mockResolvedValue({
|
||||
path: "/tmp/clawdbot.json",
|
||||
|
||||
Reference in New Issue
Block a user