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