refactor(test): dedupe agent and status command fixtures

This commit is contained in:
Peter Steinberger
2026-02-16 16:48:28 +00:00
parent 44ef045614
commit ac5f6e7c9d
5 changed files with 168 additions and 211 deletions

View File

@@ -43,6 +43,14 @@ function getWrittenMainIdentity() {
return written.agents?.list?.find((entry) => entry.id === "main")?.identity;
}
async function runIdentityCommandFromWorkspace(workspace: string, fromIdentity = true) {
configMocks.readConfigFileSnapshot.mockResolvedValue({
...baseConfigSnapshot,
config: { agents: { list: [{ id: "main", workspace }] } },
});
await agentsSetIdentityCommand({ workspace, fromIdentity }, runtime);
}
describe("agents set-identity command", () => {
beforeEach(() => {
configMocks.readConfigFileSnapshot.mockReset();
@@ -171,12 +179,7 @@ describe("agents set-identity command", () => {
const { workspace } = await createIdentityWorkspace();
await writeIdentityFile(workspace, ["- Avatar: avatars/only.png"]);
configMocks.readConfigFileSnapshot.mockResolvedValue({
...baseConfigSnapshot,
config: { agents: { list: [{ id: "main", workspace }] } },
});
await agentsSetIdentityCommand({ workspace, fromIdentity: true }, runtime);
await runIdentityCommandFromWorkspace(workspace);
expect(getWrittenMainIdentity()).toEqual({
avatar: "avatars/only.png",
@@ -202,12 +205,7 @@ describe("agents set-identity command", () => {
it("errors when identity data is missing", async () => {
const { workspace } = await createIdentityWorkspace();
configMocks.readConfigFileSnapshot.mockResolvedValue({
...baseConfigSnapshot,
config: { agents: { list: [{ id: "main", workspace }] } },
});
await agentsSetIdentityCommand({ workspace, fromIdentity: true }, runtime);
await runIdentityCommandFromWorkspace(workspace);
expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("No identity data found"));
expect(runtime.exit).toHaveBeenCalledWith(1);