Files
openclaw/src/agents/identity-file.test.ts
samzong 0f0a192ecb [Fix] agents.create RPC: support model param, write identity to config (#61577)
* fix(gateway): support model on agents.create, write identity to config

Signed-off-by: samzong <samzong.lu@gmail.com>

* fix(gateway): sync agent identity file writes

* fix(gateway): preserve richer identity markdown

* fix(gateway): preserve destination identity on workspace moves

* fix(gateway): preserve source identity on workspace moves

---------

Signed-off-by: samzong <samzong.lu@gmail.com>
Co-authored-by: Frank Yang <frank.ekn@gmail.com>
2026-04-10 14:36:22 +08:00

83 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { mergeIdentityMarkdownContent, parseIdentityMarkdown } from "./identity-file.js";
describe("parseIdentityMarkdown", () => {
it("ignores identity template placeholders", () => {
const content = `
# IDENTITY.md - Who Am I?
- **Name:** *(pick something you like)*
- **Creature:** *(AI? robot? familiar? ghost in the machine? something weirder?)*
- **Vibe:** *(how do you come across? sharp? warm? chaotic? calm?)*
- **Emoji:** *(your signature - pick one that feels right)*
- **Avatar:** *(workspace-relative path, http(s) URL, or data URI)*
`;
const parsed = parseIdentityMarkdown(content);
expect(parsed).toEqual({});
});
it("parses explicit identity values", () => {
const content = `
- **Name:** Samantha
- **Creature:** Robot
- **Vibe:** Warm
- **Emoji:** :robot:
- **Avatar:** avatars/openclaw.png
`;
const parsed = parseIdentityMarkdown(content);
expect(parsed).toEqual({
name: "Samantha",
creature: "Robot",
vibe: "Warm",
emoji: ":robot:",
avatar: "avatars/openclaw.png",
});
});
});
describe("mergeIdentityMarkdownContent", () => {
it("updates writable fields without clobbering richer identity sections", () => {
const content = `
# IDENTITY.md - Agent Identity
- **Name:** C-3PO
- **Creature:** Flustered Protocol Droid
- **Vibe:** Anxious, detail-obsessed
- **Emoji:** 🤖
## Role
Fluent in over six million error messages.
`;
const merged = mergeIdentityMarkdownContent(content, {
name: "Patch Agent",
emoji: "🦀",
avatar: "avatars/patch.png",
});
expect(merged).toContain("- Name: Patch Agent");
expect(merged).toContain("- **Creature:** Flustered Protocol Droid");
expect(merged).toContain("- **Vibe:** Anxious, detail-obsessed");
expect(merged).toContain("- Emoji: 🦀");
expect(merged).toContain("- Avatar: avatars/patch.png");
expect(merged).toContain("## Role");
expect(merged).toContain("Fluent in over six million error messages.");
});
it("replaces duplicate writable lines with one normalized entry", () => {
const merged = mergeIdentityMarkdownContent(
`
- Name: Old Name
- Name: Older Name
- Emoji: 🙂
`,
{ name: "New Name", emoji: "🦀" },
);
expect(merged.match(/Name:/g)).toHaveLength(1);
expect(merged).toContain("- Name: New Name");
expect(merged).toContain("- Emoji: 🦀");
});
});