94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { systemInfoTool } from './system-info.js';
|
|
|
|
function getOutput(output: string | undefined): string {
|
|
if (!output) {
|
|
throw new Error('Expected output');
|
|
}
|
|
return output;
|
|
}
|
|
|
|
describe('system.info tool', () => {
|
|
// ── Metadata ─────────────────────────────────────────────────────────────
|
|
|
|
it('has correct metadata', () => {
|
|
expect(systemInfoTool.name).toBe('system.info');
|
|
expect(systemInfoTool.description).toBeTruthy();
|
|
expect(systemInfoTool.inputSchema.type).toBe('object');
|
|
});
|
|
|
|
// ── Execution ────────────────────────────────────────────────────────────
|
|
|
|
it('returns success with system info', async () => {
|
|
const result = await systemInfoTool.execute({});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(typeof result.output).toBe('string');
|
|
expect(getOutput(result.output).length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('output contains expected fields', async () => {
|
|
const result = await systemInfoTool.execute({});
|
|
|
|
expect(result.success).toBe(true);
|
|
const output = getOutput(result.output);
|
|
|
|
const expectedFields = [
|
|
'System Snapshot',
|
|
'Host',
|
|
'Resources',
|
|
'Storage',
|
|
'Time',
|
|
'Hostname:',
|
|
'Platform:',
|
|
'Node.js:',
|
|
'Uptime:',
|
|
'Memory:',
|
|
];
|
|
|
|
for (const field of expectedFields) {
|
|
expect(output).toContain(field);
|
|
}
|
|
});
|
|
|
|
it('output contains valid ISO timestamp', async () => {
|
|
const result = await systemInfoTool.execute({});
|
|
|
|
expect(result.success).toBe(true);
|
|
const output = getOutput(result.output);
|
|
|
|
// Find the line containing 'ISO 8601:'
|
|
const isoLine = output.split('\n').find((line) => line.includes('ISO 8601:'));
|
|
expect(isoLine).toBeTruthy();
|
|
|
|
// Extract the ISO string and validate it
|
|
const isoMatch = getOutput(isoLine).match(/ISO 8601:\s*(.+)/);
|
|
expect(isoMatch).toBeTruthy();
|
|
|
|
const isoString = getOutput(isoMatch?.[1]).trim();
|
|
const parsed = new Date(isoString);
|
|
expect(parsed.toISOString()).toBe(isoString);
|
|
});
|
|
|
|
it('output contains working directory', async () => {
|
|
const result = await systemInfoTool.execute({});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.output).toContain('Working Dir:');
|
|
});
|
|
|
|
// ── Idempotency ──────────────────────────────────────────────────────────
|
|
|
|
it('handles repeated calls', async () => {
|
|
const result1 = await systemInfoTool.execute({});
|
|
const result2 = await systemInfoTool.execute({});
|
|
|
|
expect(result1.success).toBe(true);
|
|
expect(result2.success).toBe(true);
|
|
expect(typeof result1.output).toBe('string');
|
|
expect(typeof result2.output).toBe('string');
|
|
expect(getOutput(result1.output).length).toBeGreaterThan(0);
|
|
expect(getOutput(result2.output).length).toBeGreaterThan(0);
|
|
});
|
|
});
|