import { describe, report } from '../core/_harness.mjs';
// Placeholder until commandExtractService implemented
function mockExtractCommands(chunks, riskClassifier) {
const commands = [];
for (const chunk of chunks) {
const codeBlocks = chunk.text.match(/```[\s\S]*?```/g) || [];
const shellLines = chunk.text.match(/^\s*\$\s+.+$/gm) || [];
commands.push(...codeBlocks.map(c => c.replace(/```\w*\n?|```/g, '').trim()).filter(Boolean));
commands.push(...shellLines.map(l => l.replace(/^\s*\$\s+/, '').trim()).filter(Boolean));
}
return riskClassifier ? riskClassifier(commands) : { safe: commands, risky: [] };
}
describe('commands extract', (it) => {
const mockChunks = [
{ text: 'Run this command:\n```bash\nsudo systemctl restart nginx\n```' },
{ text: 'Check status with: $ systemctl status nginx' },
{ text: 'Regular text without commands' }
];
it('extracts code blocks and shell commands', () => {
const result = mockExtractCommands(mockChunks);
const allCommands = [...result.safe, ...result.risky];
if (allCommands.length < 1) throw new Error(`Expected at least 1 command, got ${allCommands.length}`);
if (!allCommands.some(c => c.includes('systemctl restart'))) throw new Error('Missing restart command');
});
it('handles chunks without commands', () => {
const result = mockExtractCommands([{ text: 'No commands here' }]);
const allCommands = [...result.safe, ...result.risky];
if (allCommands.length !== 0) throw new Error('Expected no commands');
});
});
report();