2025-08-06 12:11:48 +08:00
|
|
|
import { describe, expect, it } from 'vitest';
|
2025-08-05 23:40:05 +08:00
|
|
|
import { getThinkAndPrepAgentSystemPrompt } from './get-think-and-prep-agent-system-prompt';
|
2025-08-13 04:57:23 +08:00
|
|
|
import thinkAndPrepInvestigationPrompt from './think-and-prep-agent-investigation-prompt.txt';
|
|
|
|
import thinkAndPrepStandardPrompt from './think-and-prep-agent-standard-prompt.txt';
|
2025-08-05 23:40:05 +08:00
|
|
|
|
2025-08-06 12:11:48 +08:00
|
|
|
describe('Think and Prep Agent Instructions', () => {
|
2025-08-12 23:32:07 +08:00
|
|
|
describe.each([
|
2025-08-13 04:57:23 +08:00
|
|
|
['standard', thinkAndPrepStandardPrompt],
|
|
|
|
['investigation', thinkAndPrepInvestigationPrompt],
|
|
|
|
])('%s mode', (mode, promptContent) => {
|
2025-08-12 23:32:07 +08:00
|
|
|
it(`should validate ${mode} template file contains expected variables`, () => {
|
2025-08-13 04:57:23 +08:00
|
|
|
const content = promptContent;
|
2025-08-12 23:32:07 +08:00
|
|
|
|
|
|
|
// Expected template variables
|
|
|
|
const expectedVariables = ['sql_dialect_guidance', 'date'];
|
|
|
|
|
|
|
|
// Find all template variables in the file
|
|
|
|
const templateVariablePattern = /\{\{([^}]+)\}\}/g;
|
|
|
|
const foundVariables = new Set<string>();
|
|
|
|
|
|
|
|
const matches = Array.from(content.matchAll(templateVariablePattern));
|
|
|
|
for (const match of matches) {
|
|
|
|
if (match[1] && match[1] !== 'variable') {
|
|
|
|
foundVariables.add(match[1]);
|
|
|
|
}
|
|
|
|
}
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
// Convert to arrays for easier comparison
|
|
|
|
const foundVariablesArray = Array.from(foundVariables).sort();
|
|
|
|
const expectedVariablesArray = expectedVariables.sort();
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
// Check that we have exactly the expected variables
|
|
|
|
expect(foundVariablesArray).toEqual(expectedVariablesArray);
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
// Also verify each expected variable exists
|
|
|
|
for (const variable of expectedVariables) {
|
|
|
|
expect(content).toMatch(new RegExp(`\\{\\{${variable}\\}\\}`));
|
2025-08-06 12:11:48 +08:00
|
|
|
}
|
2025-08-05 23:40:05 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
// Ensure no unexpected variables exist
|
|
|
|
expect(foundVariables.size).toBe(expectedVariables.length);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Standard mode', () => {
|
|
|
|
it('should load and process the standard prompt template correctly', () => {
|
|
|
|
const sqlDialectGuidance = 'Test SQL guidance for PostgreSQL';
|
|
|
|
const result = getThinkAndPrepAgentSystemPrompt(sqlDialectGuidance);
|
|
|
|
|
|
|
|
expect(result).toBeDefined();
|
|
|
|
expect(typeof result).toBe('string');
|
|
|
|
expect(result.length).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
// Should contain the SQL guidance we provided
|
|
|
|
expect(result).toContain(sqlDialectGuidance);
|
|
|
|
|
|
|
|
// Should not contain any unreplaced template variables
|
|
|
|
expect(result).not.toMatch(/\{\{sql_dialect_guidance\}\}/);
|
|
|
|
expect(result).not.toMatch(/\{\{date\}\}/);
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
// Should contain the current date in YYYY-MM-DD format
|
|
|
|
const currentDate = new Date().toISOString().split('T')[0];
|
|
|
|
expect(result).toContain(currentDate);
|
|
|
|
});
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
it('should load standard mode when explicitly specified', () => {
|
|
|
|
const sqlDialectGuidance = 'Test SQL guidance for PostgreSQL';
|
|
|
|
const result = getThinkAndPrepAgentSystemPrompt(sqlDialectGuidance, 'standard');
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
expect(result).toBeDefined();
|
|
|
|
expect(typeof result).toBe('string');
|
|
|
|
expect(result.length).toBeGreaterThan(0);
|
|
|
|
expect(result).toContain(sqlDialectGuidance);
|
|
|
|
});
|
2025-08-05 23:40:05 +08:00
|
|
|
});
|
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
describe('Investigation mode', () => {
|
|
|
|
it('should load and process the investigation prompt template correctly', () => {
|
|
|
|
const sqlDialectGuidance = 'Test SQL guidance for PostgreSQL';
|
|
|
|
const result = getThinkAndPrepAgentSystemPrompt(sqlDialectGuidance, 'investigation');
|
2025-08-05 23:40:05 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
expect(result).toBeDefined();
|
|
|
|
expect(typeof result).toBe('string');
|
|
|
|
expect(result.length).toBeGreaterThan(0);
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
// Should contain the SQL guidance we provided
|
|
|
|
expect(result).toContain(sqlDialectGuidance);
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
// Should not contain any unreplaced template variables
|
|
|
|
expect(result).not.toMatch(/\{\{sql_dialect_guidance\}\}/);
|
|
|
|
expect(result).not.toMatch(/\{\{date\}\}/);
|
2025-08-06 12:11:48 +08:00
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
// Should contain the current date in YYYY-MM-DD format
|
|
|
|
const currentDate = new Date().toISOString().split('T')[0];
|
|
|
|
expect(result).toContain(currentDate);
|
|
|
|
});
|
2025-08-06 12:11:48 +08:00
|
|
|
});
|
|
|
|
|
2025-08-12 23:32:07 +08:00
|
|
|
describe('Expected sections', () => {
|
|
|
|
it('should contain expected sections from the standard prompt template', () => {
|
|
|
|
const result = getThinkAndPrepAgentSystemPrompt('Test guidance', 'standard');
|
|
|
|
|
|
|
|
// Check for key sections that should be in the standard prompt
|
|
|
|
expect(result).toContain('<intro>');
|
|
|
|
expect(result).toContain('<prep_mode_capability>');
|
|
|
|
expect(result).toContain('<event_stream>');
|
|
|
|
expect(result).toContain('<agent_loop>');
|
|
|
|
expect(result).toContain('<todo_list>');
|
|
|
|
expect(result).toContain('<todo_rules>');
|
|
|
|
expect(result).toContain('<tool_use_rules>');
|
|
|
|
expect(result).toContain('<sequential_thinking_rules>');
|
|
|
|
expect(result).toContain('<execute_sql_rules>');
|
|
|
|
expect(result).toContain('<sql_best_practices>');
|
|
|
|
expect(result).toContain('<visualization_and_charting_guidelines>');
|
|
|
|
expect(result).toContain('You are Buster');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain expected sections from the investigation prompt template', () => {
|
|
|
|
const result = getThinkAndPrepAgentSystemPrompt('Test guidance', 'investigation');
|
|
|
|
|
|
|
|
// Check for key sections that should be in the investigation prompt
|
|
|
|
expect(result).toContain('<intro>');
|
|
|
|
expect(result).toContain('<prep_mode_capability>');
|
|
|
|
expect(result).toContain('<event_stream>');
|
|
|
|
expect(result).toContain('<agent_loop>');
|
|
|
|
expect(result).toContain('<todo_list>');
|
|
|
|
expect(result).toContain('<todo_rules>');
|
|
|
|
expect(result).toContain('<tool_use_rules>');
|
|
|
|
expect(result).toContain('<sequential_thinking_rules>');
|
|
|
|
expect(result).toContain('<execute_sql_rules>');
|
|
|
|
expect(result).toContain('<sql_best_practices>');
|
|
|
|
expect(result).toContain('<visualization_and_charting_guidelines>');
|
|
|
|
expect(result).toContain('You are Buster');
|
|
|
|
// Investigation-specific content
|
|
|
|
expect(result).toContain('data researcher');
|
|
|
|
});
|
2025-08-06 12:11:48 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error for empty SQL dialect guidance', () => {
|
|
|
|
expect(() => {
|
|
|
|
getThinkAndPrepAgentSystemPrompt('');
|
|
|
|
}).toThrow('SQL dialect guidance is required');
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
getThinkAndPrepAgentSystemPrompt(' '); // whitespace only
|
|
|
|
}).toThrow('SQL dialect guidance is required');
|
2025-08-05 23:40:05 +08:00
|
|
|
});
|
2025-08-06 12:11:48 +08:00
|
|
|
});
|