New test files (83 tests): - src/agent-identity.test.ts — resolveAgentIdentity across locales/genders - src/env.test.ts — readEnvFile parsing, quoting, edge cases - src/jail-registry.test.ts — getJailIp with/without env override - src/local-hosts.test.ts — block markers, entries, render, upsert - src/mount-security.test.ts — validateMount allowlist enforcement - src/transcription.test.ts — initTranscription + transcribeAudio with mocked OpenAI setup/ TypeScript audit (tsconfig.setup.json): - agent-jails: JAILS value serialised to JSON string for emitStatus - environment.test: use import type for pg.Pool type cast - onboarding: wrap showProfileMenu in normalizePiTuiProfile - preflight.test: fix process.exit mock type + typed call array casts - sanoid: execSync → spawnSync for multi-arg zfs invocation - skills-memory: bracket access for legacy chunking_version field - upstream: pass process.cwd() to isGitRepo() - verify: import StripeKeyMode type, annotate stripeKeyMode variable Full suite: 69 files, 1162 tests passing; tsc --noEmit clean. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --- Build: pass | Tests: pass — Tests 1162 passed (1162) --- Build: pass | Tests: pass — Tests 1162 passed (1162)
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import type * as pg from 'pg';
|
|
|
|
describe('environment detection', () => {
|
|
it('detects platform correctly', async () => {
|
|
const { getPlatform } = await import('./platform.js');
|
|
const platform = getPlatform();
|
|
expect(['freebsd', 'unknown']).toContain(platform);
|
|
});
|
|
});
|
|
|
|
describe('registered groups DB query', () => {
|
|
it('returns 0 for empty table', async () => {
|
|
const groups: Map<string, unknown> = new Map();
|
|
const pool = {
|
|
query: async (sql: string) => {
|
|
if (/SELECT COUNT/i.test(sql)) {
|
|
return { rows: [{ count: String(groups.size) }] };
|
|
}
|
|
return { rows: [] };
|
|
},
|
|
end: async () => {},
|
|
} as unknown as pg.Pool;
|
|
|
|
const { rows } = await pool.query(
|
|
'SELECT COUNT(*) as count FROM registered_groups',
|
|
);
|
|
expect((rows[0] as Record<string, unknown>).count).toBe('0');
|
|
});
|
|
|
|
it('returns correct count after inserts', async () => {
|
|
const groups: Map<string, unknown> = new Map();
|
|
groups.set('123@g.us', { jid: '123@g.us' });
|
|
groups.set('456@g.us', { jid: '456@g.us' });
|
|
const pool = {
|
|
query: async (sql: string) => {
|
|
if (/SELECT COUNT/i.test(sql)) {
|
|
return { rows: [{ count: String(groups.size) }] };
|
|
}
|
|
return { rows: [] };
|
|
},
|
|
end: async () => {},
|
|
} as unknown as pg.Pool;
|
|
|
|
const { rows } = await pool.query(
|
|
'SELECT COUNT(*) as count FROM registered_groups',
|
|
);
|
|
expect((rows[0] as Record<string, unknown>).count).toBe('2');
|
|
});
|
|
});
|
|
|
|
describe('credentials detection', () => {
|
|
it('detects ANTHROPIC_API_KEY in env content', () => {
|
|
const content =
|
|
'SOME_KEY=value\nANTHROPIC_API_KEY=sk-ant-test123\nOTHER=foo';
|
|
const hasCredentials = /^(ANTHROPIC_API_KEY|OPENROUTER_API_KEY)=/m.test(
|
|
content,
|
|
);
|
|
expect(hasCredentials).toBe(true);
|
|
});
|
|
|
|
it('detects OPENROUTER_API_KEY in env content', () => {
|
|
const content = 'OPENROUTER_API_KEY=sk-or-test123';
|
|
const hasCredentials = /^(ANTHROPIC_API_KEY|OPENROUTER_API_KEY)=/m.test(
|
|
content,
|
|
);
|
|
expect(hasCredentials).toBe(true);
|
|
});
|
|
|
|
it('returns false when no credentials', () => {
|
|
const content = 'ASSISTANT_NAME="Andy"\nOTHER=foo';
|
|
const hasCredentials = /^(ANTHROPIC_API_KEY|OPENROUTER_API_KEY)=/m.test(
|
|
content,
|
|
);
|
|
expect(hasCredentials).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('command detection logic', () => {
|
|
it('commandExists returns boolean', async () => {
|
|
const { commandExists } = await import('./platform.js');
|
|
expect(typeof commandExists('jexec')).toBe('boolean');
|
|
expect(typeof commandExists('nonexistent_binary_xyz')).toBe('boolean');
|
|
});
|
|
});
|
|
|
|
describe('Telegram auth detection', () => {
|
|
it('detects TELEGRAM_BOT_TOKEN in env content', () => {
|
|
const content = 'TELEGRAM_BOT_TOKEN=123456:token';
|
|
const configured = /^TELEGRAM_BOT_TOKEN=.+/m.test(content);
|
|
expect(configured).toBe(true);
|
|
});
|
|
|
|
it('returns false when TELEGRAM_BOT_TOKEN is missing', () => {
|
|
const content = 'ASSISTANT_NAME="Andy"\nOTHER=foo';
|
|
const configured = /^TELEGRAM_BOT_TOKEN=.+/m.test(content);
|
|
expect(configured).toBe(false);
|
|
});
|
|
});
|