agent-ecosystem/test/shared/constants/agentBlocks.test.ts
iliya a3844a085f refactor: standardize agent block handling and improve messaging format
- Introduced a new `wrapAgentBlock` function to standardize the formatting of agent-only messages across the application.
- Updated the `requestReview` method to utilize the new agent block format, enhancing consistency in review request messages.
- Refactored legacy agent block handling to support both new XML-like and legacy fenced formats, ensuring backward compatibility.
- Enhanced tests to validate the new agent block formatting and ensure proper extraction of agent-only content from messages.
2026-03-07 21:59:38 +02:00

32 lines
1.4 KiB
TypeScript

import {
AGENT_BLOCK_CLOSE,
AGENT_BLOCK_OPEN,
extractAgentBlockContents,
stripAgentBlocks,
unwrapAgentBlock,
} from '@shared/constants/agentBlocks';
describe('agentBlocks', () => {
it('strips the canonical info_for_agent tags from display text', () => {
const text = `Visible line\n${AGENT_BLOCK_OPEN}\ninternal instruction\n${AGENT_BLOCK_CLOSE}\nAfter`;
expect(stripAgentBlocks(text)).toBe('Visible line\nAfter');
expect(extractAgentBlockContents(text)).toEqual(['internal instruction']);
});
it('keeps backward compatibility for legacy agent block formats', () => {
const legacyFenced = 'Hello\n```info_for_agent\nhidden fenced\n```\nWorld';
const legacyXml = 'Hello\n<agent-block>\nhidden xml\n</agent-block>\nWorld';
expect(stripAgentBlocks(legacyFenced)).toBe('Hello\nWorld');
expect(stripAgentBlocks(legacyXml)).toBe('Hello\nWorld');
expect(extractAgentBlockContents(legacyFenced)).toEqual(['hidden fenced']);
expect(extractAgentBlockContents(legacyXml)).toEqual(['hidden xml']);
});
it('unwraps canonical and legacy wrappers consistently', () => {
expect(unwrapAgentBlock(`${AGENT_BLOCK_OPEN}\ninside\n${AGENT_BLOCK_CLOSE}`)).toBe('inside');
expect(unwrapAgentBlock('```info_for_agent\ninside\n```')).toBe('inside');
expect(unwrapAgentBlock('<agent-block>\ninside\n</agent-block>')).toBe('inside');
});
});