feat: 9-agent migration matrix (dsh/workbuddy/zcode/mimo), 81 combinations tested, 210 tests
031fd6d verified Download tests/parsers.test.ts from hongcoding/agentlens: direct link, hf CLI and curl.
- Browser
- Download file 4.57 kB
-
https://huggingface.co/datasets/hongcoding/agentlens/resolve/main/tests/parsers.test.ts
- Command line
-
hf download hf://datasets/hongcoding/agentlens/tests/parsers.test.ts
-
curl -L -o parsers.test.ts https://huggingface.co/datasets/hongcoding/agentlens/resolve/main/tests/parsers.test.ts
4.57 kB
| import { describe, it, expect } from "vitest"; | |
| import { extractRuleBlocks, classifyRule } from "../src/parsers/base.js"; | |
| import { claudeParser } from "../src/parsers/claude.js"; | |
| import { cursorParser } from "../src/parsers/cursor.js"; | |
| import { codexParser } from "../src/parsers/codex.js"; | |
| describe("extractRuleBlocks", () => { | |
| it("extracts bullet list items as rules", () => { | |
| const content = `- Always use TypeScript strict mode | |
| - Never commit directly to main | |
| - Prefer composition over inheritance`; | |
| const blocks = extractRuleBlocks(content); | |
| expect(blocks.length).toBe(3); | |
| expect(blocks[0]).toBe("Always use TypeScript strict mode"); | |
| expect(blocks[1]).toBe("Never commit directly to main"); | |
| }); | |
| it("treats headings as labels, not rules", () => { | |
| const content = `## Code Style\n\nSome content here.\n\n## Testing\n\nMore content.`; | |
| const blocks = extractRuleBlocks(content); | |
| expect(blocks).not.toContain("Code Style"); | |
| expect(blocks).not.toContain("Testing"); | |
| expect(blocks).toContain("Some content here."); | |
| expect(blocks).toContain("More content."); | |
| }); | |
| it("handles numbered lists", () => { | |
| const content = `1. First rule | |
| 2. Second rule`; | |
| const blocks = extractRuleBlocks(content); | |
| expect(blocks.length).toBe(2); | |
| expect(blocks[0]).toBe("First rule"); | |
| }); | |
| it("filters out short noise", () => { | |
| const content = `- OK\n\nThis is a real rule that has enough content.`; | |
| const blocks = extractRuleBlocks(content); | |
| expect(blocks.length).toBe(1); | |
| expect(blocks[0]).toBe("This is a real rule that has enough content."); | |
| }); | |
| }); | |
| describe("classifyRule", () => { | |
| it("classifies style rules", () => { | |
| expect(classifyRule("Use 4 spaces for indentation")).toBe("style"); | |
| expect(classifyRule("Follow ESLint conventions")).toBe("style"); | |
| }); | |
| it("classifies constraint rules", () => { | |
| expect(classifyRule("Never commit secrets to the repository")).toBe("constraint"); | |
| expect(classifyRule("必须先运行测试再提交")).toBe("constraint"); | |
| }); | |
| it("classifies workflow rules", () => { | |
| expect(classifyRule("Use feature branches for all PRs")).toBe("workflow"); | |
| expect(classifyRule("Deploy after review approval")).toBe("workflow"); | |
| }); | |
| it("classifies tooling rules", () => { | |
| expect(classifyRule("Use pnpm as package manager")).toBe("tooling"); | |
| expect(classifyRule("Prefer Zod for schema validation")).toBe("tooling"); | |
| }); | |
| it("defaults to context", () => { | |
| expect(classifyRule("This project is a web application")).toBe("context"); | |
| }); | |
| }); | |
| describe("claudeParser", () => { | |
| it("parses CLAUDE.md content into rules", () => { | |
| const content = `# Project Rules | |
| - Use TypeScript for all new code | |
| - Always run tests before committing | |
| ## Architecture | |
| Prefer serverless functions over long-running servers.`; | |
| const rules = claudeParser.parse(content, "CLAUDE.md"); | |
| expect(rules.length).toBeGreaterThan(0); | |
| expect(rules[0].source.agent).toBe("claude"); | |
| expect(rules[0].source.file).toBe("CLAUDE.md"); | |
| expect(rules[0].status).toBe("active"); | |
| // Should have rules from bullets and headings | |
| const contents = rules.map((r) => r.content); | |
| expect(contents).toContain("Use TypeScript for all new code"); | |
| }); | |
| }); | |
| describe("cursorParser", () => { | |
| it("parses .mdc with frontmatter", () => { | |
| const content = `--- | |
| description: My rules | |
| globs: ["src/**/*.ts"] | |
| --- | |
| - Use async/await over raw promises | |
| - Always handle errors explicitly`; | |
| const rules = cursorParser.parse(content, ".cursor/rules/main.mdc"); | |
| expect(rules.length).toBe(2); | |
| expect(rules[0].source.agent).toBe("cursor"); | |
| expect(rules[0].content).toBe("Use async/await over raw promises"); | |
| expect(rules[1].content).toBe("Always handle errors explicitly"); | |
| }); | |
| it("parses plain .cursorrules", () => { | |
| const content = `Use single quotes | |
| Max line length 100`; | |
| const rules = cursorParser.parse(content, ".cursorrules"); | |
| expect(rules.length).toBe(2); | |
| expect(rules[0].source.agent).toBe("cursor"); | |
| }); | |
| }); | |
| describe("codexParser", () => { | |
| it("parses AGENTS.md content", () => { | |
| const content = `# Agent Guidelines | |
| - Write unit tests for all utility functions | |
| - Document all public APIs with JSDoc`; | |
| const rules = codexParser.parse(content, "AGENTS.md"); | |
| expect(rules.length).toBeGreaterThan(0); | |
| expect(rules[0].source.agent).toBe("codex"); | |
| const contents = rules.map((r) => r.content); | |
| expect(contents).toContain("Write unit tests for all utility functions"); | |
| }); | |
| }); | |