@cachly-dev/mcp-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { detectNamespace } from '../namespace.js';
3
+
4
+ // ── Namespace Auto-Detection ───────────────────────────────────────────────
5
+
6
+ describe('detectNamespace', () => {
7
+ // ── Code ────────────────────────────────────────────────────────────────────
8
+ describe('code detection', () => {
9
+ it.each([
10
+ ['python def', 'def process(data): return data * 2'],
11
+ ['js const arrow', 'const handler = () => response.send(200)'],
12
+ ['ts class', 'class UserService { constructor(private repo: Repo) {} }'],
13
+ ['import statement', 'import { useState } from "react"'],
14
+ ['shebang line', '#!/usr/bin/env python3\nprint("hello")'],
15
+ ['go func', 'func main() { fmt.Println("hello") }'],
16
+ ['cpp include', '#include <iostream>\nint main() { return 0; }'],
17
+ ['interface block', 'interface ICache { get(key: string): void; }'],
18
+ ['struct block', 'struct Config { host string }'],
19
+ ['async def', 'async def fetch_data(url: str) -> dict:'],
20
+ ['lambda', 'fn = lambda x: x * 2'],
21
+ ['package decl', 'package com.example.service;'],
22
+ ])('detects code: %s', (_, prompt) => {
23
+ expect(detectNamespace(prompt)).toBe('cachly:sem:code');
24
+ });
25
+ });
26
+
27
+ // ── Translation ─────────────────────────────────────────────────────────────
28
+ describe('translation detection', () => {
29
+ it.each([
30
+ ['translate', 'translate this paragraph to Spanish'],
31
+ ['übersetze', 'übersetze diesen Text bitte'],
32
+ ['auf deutsch', 'Schreib das auf deutsch'],
33
+ ['in english', 'Please write this in english'],
34
+ ['ins deutsche', 'Bitte übersetze ins Deutsche'],
35
+ ['traduce', 'traduce este texto al alemán'],
36
+ ['traduis', 'traduis ce texte en anglais'],
37
+ ['vertaal', 'vertaal dit naar het Nederlands'],
38
+ ])('detects translation: %s', (_, prompt) => {
39
+ expect(detectNamespace(prompt)).toBe('cachly:sem:translation');
40
+ });
41
+ });
42
+
43
+ // ── Summary ──────────────────────────────────────────────────────────────────
44
+ describe('summary detection', () => {
45
+ it.each([
46
+ ['summarize', 'summarize this article for me'],
47
+ ['summarise', 'summarise the key points'],
48
+ ['tl;dr', 'tl;dr of the following blog post:'],
49
+ ['tldr', 'tldr of this document'],
50
+ ['key points', 'what are the key points?'],
51
+ ['zusammenfass', 'fasse zusammen worum es geht'],
52
+ ['give me a brief', 'give me a brief overview'],
53
+ ['in a nutshell', 'explain machine learning in a nutshell'],
54
+ ['stichpunkte', 'Gib mir die wichtigsten Stichpunkte'],
55
+ ])('detects summary: %s', (_, prompt) => {
56
+ expect(detectNamespace(prompt)).toBe('cachly:sem:summary');
57
+ });
58
+ });
59
+
60
+ // ── Q&A ──────────────────────────────────────────────────────────────────────
61
+ describe('qa detection', () => {
62
+ it.each([
63
+ ['what is', 'what is the capital of France?'],
64
+ ['how does', 'how does photosynthesis work?'],
65
+ ['why is', 'why is the sky blue?'],
66
+ ['who invented', 'who invented the internet?'],
67
+ ['where is', 'where is Mount Everest located?'],
68
+ ['when was', 'when was the Eiffel Tower built?'],
69
+ ['can you', 'can you explain recursion?'],
70
+ ['is redis', 'is Redis single-threaded?'],
71
+ ['does postgres', 'does postgres support JSON natively?'],
72
+ ['wer ist', 'wer ist der aktuelle Bundeskanzler?'],
73
+ ['wie funktioniert', 'wie funktioniert ein JWT Token?'],
74
+ ['trailing ?', 'Redis vs Memcached?'],
75
+ ])('detects q&a: %s', (_, prompt) => {
76
+ expect(detectNamespace(prompt)).toBe('cachly:sem:qa');
77
+ });
78
+ });
79
+
80
+ // ── Creative ─────────────────────────────────────────────────────────────────
81
+ describe('creative fallback', () => {
82
+ it.each([
83
+ ['poem request', 'Write a short poem about autumn leaves'],
84
+ ['story request', 'Tell me a fantasy story about dragons'],
85
+ ['product copy', 'Generate a product description for running shoes'],
86
+ ['greeting', 'Good morning, how are you today'],
87
+ ['general task', 'Help me brainstorm names for my startup'],
88
+ ])('falls back to creative: %s', (_, prompt) => {
89
+ expect(detectNamespace(prompt)).toBe('cachly:sem:creative');
90
+ });
91
+ });
92
+
93
+ // ── Edge cases ────────────────────────────────────────────────────────────────
94
+ describe('edge cases', () => {
95
+ it('is case-insensitive', () => {
96
+ expect(detectNamespace('CONST x = 1')).toBe('cachly:sem:code');
97
+ expect(detectNamespace('TRANSLATE THIS')).toBe('cachly:sem:translation');
98
+ expect(detectNamespace('SUMMARIZE PLEASE')).toBe('cachly:sem:summary');
99
+ expect(detectNamespace('WHAT IS GRAVITY?')).toBe('cachly:sem:qa');
100
+ });
101
+
102
+ it('trims surrounding whitespace', () => {
103
+ expect(detectNamespace(' what is Redis? ')).toBe('cachly:sem:qa');
104
+ expect(detectNamespace(' const x = 1 ')).toBe('cachly:sem:code');
105
+ });
106
+
107
+ it('code keyword takes priority over translation', () => {
108
+ // Both "translate" and "def" present – code wins (checked first)
109
+ expect(detectNamespace('translate this function: def foo(): pass')).toBe('cachly:sem:code');
110
+ });
111
+
112
+ it('code keyword takes priority over summary', () => {
113
+ expect(detectNamespace('summarize this class MyService { }'))
114
+ .toBe('cachly:sem:code');
115
+ });
116
+
117
+ it('handles empty string as creative', () => {
118
+ expect(detectNamespace('')).toBe('cachly:sem:creative');
119
+ });
120
+
121
+ it('a single ? at end is qa', () => {
122
+ expect(detectNamespace('Interesting concept?')).toBe('cachly:sem:qa');
123
+ });
124
+ });
125
+ });
126
+