beast-agent 0.30.0 → 1.0.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.
Files changed (46) hide show
  1. package/package.json +6 -3
  2. package/src/agent/engine.js +463 -21
  3. package/src/agent/llm.js +52 -3
  4. package/src/agent/obscura.js +26 -10
  5. package/src/agent/skills.js +2 -2
  6. package/src/agent/tools.js +519 -7
  7. package/src/main.js +28 -13
  8. package/src/renderer/i18n.js +7 -7
  9. package/src/renderer/index.html +5 -2
  10. package/src/renderer/renderer.js +154 -5
  11. package/src/renderer/style.css +45 -4
  12. package/.env.example +0 -8
  13. package/config.example.yaml +0 -39
  14. package/eng.traineddata +0 -0
  15. package/scripts/fix-electron.js +0 -126
  16. package/scripts/release.js +0 -121
  17. package/scripts/swap-electron.js +0 -40
  18. package/store/skills.json +0 -5
  19. package/tests/approval.test.js +0 -56
  20. package/tests/bg-jobs.test.js +0 -424
  21. package/tests/bots-name.test.js +0 -42
  22. package/tests/bus.test.js +0 -46
  23. package/tests/computeruse-context.test.js +0 -69
  24. package/tests/cron.test.js +0 -95
  25. package/tests/engine.test.js +0 -203
  26. package/tests/eval.test.js +0 -91
  27. package/tests/fallout.test.js +0 -188
  28. package/tests/llm.test.js +0 -205
  29. package/tests/memory.test.js +0 -33
  30. package/tests/memoryloop.test.js +0 -26
  31. package/tests/notegen.test.js +0 -63
  32. package/tests/obscura.test.js +0 -124
  33. package/tests/owner.test.js +0 -32
  34. package/tests/python.test.js +0 -76
  35. package/tests/research.test.js +0 -116
  36. package/tests/scenarios.json +0 -81
  37. package/tests/sessioncode.test.js +0 -50
  38. package/tests/setup.js +0 -9
  39. package/tests/tokens.test.js +0 -42
  40. package/tests/tools.test.js +0 -84
  41. package/tests/usage.test.js +0 -44
  42. package/tests/v11.test.js +0 -76
  43. package/tests/watchers.test.js +0 -206
  44. package/tests/watext.test.js +0 -53
  45. package/tests/whatsapp.test.js +0 -103
  46. package/tests/wherewasi.test.js +0 -40
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- /* #18 python_run altyapısı testleri — ağ çağrısı YOK */
4
-
5
- const test = require('node:test');
6
- const assert = require('node:assert');
7
- const tools = require('../src/agent/tools');
8
-
9
- test('python_run tanımı TOOLS içinde', () => {
10
- const def = tools.definitions.find((d) => d.function.name === 'python_run');
11
- assert.ok(def, 'python_run var');
12
- const props = def.function.parameters.properties;
13
- for (const k of ['code', 'script', 'args', 'timeout_ms']) assert.ok(props[k], k);
14
- });
15
-
16
- test('code/script yoksa net hata döner (interpreter araması bile gerekmez)', async () => {
17
- const out = await tools.exec('python_run', {}, { cwd: process.cwd(), allowDownload: false });
18
- const r = JSON.parse(out);
19
- assert.strictEqual(r.ok, false);
20
- assert.ok(/code ya da script/.test(r.error), r.error);
21
- });
22
-
23
- test('olmayan script: interpreter bakılmadan bulunamadı + klasör ipucu döner', async () => {
24
- const out = await tools.exec(
25
- 'python_run',
26
- { script: 'kesinlikle-yok-abc123.py' },
27
- { cwd: process.cwd(), allowDownload: false }
28
- );
29
- const r = JSON.parse(out);
30
- assert.strictEqual(r.ok, false);
31
- assert.match(String(r.error || ''), /bulunamadı/);
32
- assert.match(String(r.hint || ''), /scripts/, 'klasör ipucu verildi');
33
- });
34
-
35
- test('scripts klasörü çözümlenir ve oluşturulur', () => {
36
- const dir = tools.pythonScriptsDir();
37
- assert.ok(typeof dir === 'string' && dir.length > 0);
38
- });
39
-
40
- test('paketlenmiş python scriptleri mevcut ve tohumlanır', () => {
41
- for (const name of ['websearch.py', 'news.py']) {
42
- assert.ok(require('fs').existsSync(tools.bundledScriptPath(name)), 'paket içi: ' + name);
43
- const dest = tools.seedScript(name);
44
- assert.ok(require('fs').existsSync(dest), 'tohumlandı: ' + dest);
45
- }
46
- });
47
-
48
- /* canlı: python hızlı arama yolu (ağ varsa gerçek sonuç, yoksa JS fallback) */
49
- test('webSearchFast: python yolu ya da fallback sonuç döner', async function () {
50
- const r = await tools.webSearchFast('electron builder portable windows', { maxResults: 5 });
51
- /* rate-limit/CAPTCHA turlarında motorlar ok:false dönebilir — kablaj testi;
52
- ağ nazik davranınca sonuç şekli doğrulanır, aksi halde skip */
53
- if (!r || !r.ok || !r.results.length) return this.skip('motorlar bu turda sonuç döndürmedi (ağ/rate-limit) — kablaj doğru');
54
- assert.ok(r.results[0].title && r.results[0].url);
55
- }, { timeout: 40000 });
56
-
57
- /* canlı python varsa (BEAST_PYTHON / sistem / önceden kurulmuş gömülü):
58
- gerçek bir hesap çalıştırılır — ağ kurulumu yapılmaz */
59
- test('canlı interpreter ile inline code çalışır (kuruluysa)', async () => {
60
- let py = null;
61
- try { py = await tools.findSystemPython(); } catch {}
62
- if (!py) {
63
- try { fsAccess(tools.embeddedPythonExe()); } catch { return test.skip('interpreter yok — atlandı'); }
64
- }
65
- const out = await tools.exec(
66
- 'python_run',
67
- { code: 'print(21*2)' },
68
- { cwd: process.cwd(), allowDownload: false }
69
- );
70
- const r = JSON.parse(out);
71
- if (r.ok) assert.ok(/42/.test(r.output), 'çıktı: ' + r.output);
72
- }, { timeout: 30000 });
73
-
74
- function fsAccess(p) {
75
- require('fs').accessSync(p);
76
- }
@@ -1,116 +0,0 @@
1
- 'use strict';
2
-
3
- require('./setup');
4
- const test = require('node:test');
5
- const assert = require('node:assert');
6
-
7
- const research = require('../src/agent/research');
8
-
9
- test('normKey: scheme/www/slash/hash farklarını yok sayar', () => {
10
- assert.equal(research.normKey('http://www.Example.com/a/'), research.normKey('https://example.com/a#x'));
11
- });
12
-
13
- test('mergeResults: round-robin harman + tekilleştirme', () => {
14
- const a = [
15
- { title: 'A1', url: 'https://a.com/1' },
16
- { title: 'A2', url: 'https://a.com/2' },
17
- ];
18
- const b = [
19
- { title: 'B1', url: 'https://a.com/1/' }, // A1 ile aynı (slash)
20
- { title: 'B1x', url: 'http://www.b.com/x' },
21
- ];
22
- const merged = research.mergeResults([a, b], 10);
23
- assert.deepEqual(merged.map((r) => r.url), ['https://a.com/1', 'https://a.com/2', 'http://www.b.com/x']);
24
- assert.equal(merged[2].title, 'B1x'); // ilk gören kazanır, orijinal url korunur
25
- });
26
-
27
- test('normalizeRows: {results} veya dizi + alternatif anahtarlar', () => {
28
- const r1 = research.normalizeRows({ results: [{ name: 'X', href: 'https://x.com', body: 'b' }] });
29
- assert.equal(r1[0].title, 'X');
30
- assert.equal(r1[0].url, 'https://x.com');
31
- const r2 = research.normalizeRows([{ title: 'Y', link: 'https://y.com', description: 'd' }]);
32
- assert.equal(r2[0].url, 'https://y.com');
33
- assert.equal(research.normalizeRows(null).length, 0);
34
- assert.equal(research.normalizeRows([{ title: '', url: 'https://z.com' }]).length, 0); // başlıksız elenir
35
- });
36
-
37
- test('deepSearch: paralel sorgular harmanlanır, ilk N sayfa okunur', async () => {
38
- const searches = {
39
- 'elma': [{ title: 'A', url: 'https://a.com' }, { title: 'B', url: 'https://b.com' }],
40
- 'apple': [{ title: 'B2', url: 'https://b.com' }, { title: 'C', url: 'https://c.com' }],
41
- };
42
- const readCalls = [];
43
- const r = await research.deepSearch(
44
- { queries: ['elma', 'apple'], read_top: 2 },
45
- {
46
- search: async (q) => searches[q],
47
- readPage: async (u) => { readCalls.push(u); return { ok: true, url: u, title: 'T:' + u, content: 'icerik ' + u }; },
48
- }
49
- );
50
- assert.ok(r.ok);
51
- assert.deepEqual(r.queries, ['elma', 'apple']);
52
- assert.equal(r.results.length, 3); // b.com duplike düştü
53
- assert.deepEqual(readCalls, ['https://a.com', 'https://b.com']); // ilk 2 hedef
54
- assert.equal(r.pages.length, 2);
55
- assert.ok(r.pages[0].content.includes('https://a.com'));
56
- assert.match(r.note, /gizli tarayıcı/);
57
- });
58
-
59
- test('deepSearch: ikili dosya hedefleri okumadan atlanır', async () => {
60
- const readCalls = [];
61
- const r = await research.deepSearch(
62
- { queries: ['q'], read_top: 3 },
63
- {
64
- search: async () => [
65
- { title: 'PDF', url: 'https://x.com/doc.pdf' },
66
- { title: 'Sayfa', url: 'https://x.com/page' },
67
- ],
68
- readPage: async (u) => { readCalls.push(u); return { ok: true, url: u, content: 'c' }; },
69
- }
70
- );
71
- assert.deepEqual(readCalls, ['https://x.com/page']);
72
- assert.equal(r.pages.length, 1);
73
- });
74
-
75
- test('deepSearch: readPage yoksa yalnız sonuç listesiyle döner', async () => {
76
- const r = await research.deepSearch(
77
- { queries: ['q'] },
78
- { search: async () => [{ title: 'A', url: 'https://a.com' }] }
79
- );
80
- assert.ok(r.ok);
81
- assert.equal(r.results.length, 1);
82
- assert.equal(r.pages, undefined);
83
- });
84
-
85
- test('deepSearch: bir sorgu çökerse diğerleri kurtarır; boşsa ok:false', async () => {
86
- const r1 = await research.deepSearch(
87
- { queries: ['patlar', 'iyi'] },
88
- {
89
- search: async (q) => { if (q === 'patlar') throw new Error('boom'); return [{ title: 'A', url: 'https://a.com' }]; },
90
- readPage: async () => ({ ok: false }),
91
- }
92
- );
93
- assert.ok(r1.ok && r1.results.length === 1);
94
- const r2 = await research.deepSearch(
95
- { queries: ['yok1', 'yok2'] },
96
- { search: async () => [], readPage: async () => ({ ok: false }) }
97
- );
98
- assert.equal(r2.ok, false);
99
- assert.match(r2.error, /boş/);
100
- });
101
-
102
- test('deepSearch: sorgu yoksa net hata; queries string de kabul edilir', async () => {
103
- const bad = await research.deepSearch({}, { search: async () => [] });
104
- assert.equal(bad.ok, false);
105
- const r = await research.deepSearch(
106
- { queries: 'tek sorgu' },
107
- { search: async () => [{ title: 'A', url: 'https://a.com' }] }
108
- );
109
- assert.deepEqual(r.queries, ['tek sorgu']);
110
- });
111
-
112
- test('SKIP_FILE_RE: pdf/görsel/arşiv yakalanır, sayfa yakalanmaz', () => {
113
- assert.ok(research.SKIP_FILE_RE.test('https://x.com/a.pdf'));
114
- assert.ok(research.SKIP_FILE_RE.test('https://x.com/img.png?w=9'));
115
- assert.ok(!research.SKIP_FILE_RE.test('https://x.com/article'));
116
- });
@@ -1,81 +0,0 @@
1
- {
2
- "note": "Beast eval senaryoları (#4). Her senaryo offline doğrulanabilir olmalı: ya modül fonksiyonu çağrılır ya da prompt/sistem davranışı regex ile kontrol edilir. LLM çağıran uçtan uca testler burada DEĞİL — maliyet ve kararsızlık nedeniyle.",
3
- "scenarios": [
4
- {
5
- "id": "cron-invalid-rejected",
6
- "desc": "Bozuk cron ifadesi kabul edilmez",
7
- "module": "cron",
8
- "call": { "fn": "parseCron", "args": ["61 * * * *"] },
9
- "expectNull": true
10
- },
11
- {
12
- "id": "reminder-daily-schedule",
13
- "desc": "Tekrarlı hatırlatma daily preset doğru cron üretir",
14
- "module": "cron",
15
- "call": { "fn": "reminderSchedule", "args": ["2026-08-27T09:00", "daily"] },
16
- "expectEquals": { "schedule": "0 9 * * *" }
17
- },
18
- {
19
- "id": "watcher-edge-trigger",
20
- "desc": "İzleyici kenar tetiklemeli: koşul doğruyken tek atış",
21
- "module": "watchers",
22
- "manual": true,
23
- "coveredBy": "watchers.test.js"
24
- },
25
- {
26
- "id": "wa-multi-message-merge",
27
- "desc": "Ard arda WA mesajları tek pakette birleşir",
28
- "module": "main",
29
- "manual": true,
30
- "coveredBy": "manuel (wa.log queue→flush→perm zinciri)"
31
- },
32
- {
33
- "id": "session-code-format",
34
- "desc": "Oturum kodu 6 haneli, karıştırılan harfler yok",
35
- "module": "engine",
36
- "coveredBy": "sessioncode.test.js"
37
- },
38
- {
39
- "id": "reflection-json-parse",
40
- "desc": "Yansıma JSON'u fence'li/gömülü olsa da ayrışır",
41
- "module": "engine",
42
- "coveredBy": "v11.test.js"
43
- },
44
- {
45
- "id": "kb-search-citation",
46
- "desc": "kb_search sonucu citation taşır",
47
- "module": "kb",
48
- "check": "citation"
49
- },
50
- {
51
- "id": "memory-hygiene-dedup",
52
- "desc": "Duplike hafıza kayıtları tekilleşir",
53
- "module": "memory",
54
- "coveredBy": "eval.test.js"
55
- },
56
- {
57
- "id": "system-prompt-has-local-time",
58
- "desc": "Sistem promptu yerel tarih/saat bildirir",
59
- "module": "engine",
60
- "regex": "Yerel saat:"
61
- },
62
- {
63
- "id": "system-prompt-rules-injected",
64
- "desc": "Kalıcı kurallar sistem promptuna girer",
65
- "module": "engine",
66
- "check": "rules"
67
- },
68
- {
69
- "id": "usage-cost-math",
70
- "desc": "Maliyet hesabı (1M token fiyatıyla) doğru",
71
- "module": "usage",
72
- "coveredBy": "usage.test.js"
73
- },
74
- {
75
- "id": "bus-price-filter",
76
- "desc": "Fiyat olayı eşiğiyle filtrelenir",
77
- "module": "bus",
78
- "coveredBy": "bus.test.js"
79
- }
80
- ]
81
- }
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- require('./setup');
4
- const test = require('node:test');
5
- const assert = require('node:assert');
6
- const path = require('path');
7
- const os = require('os');
8
- const fs = require('fs');
9
- const Engine = require('../src/agent/engine');
10
-
11
- function mkEng() {
12
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'beast-code-'));
13
- return new Engine({}, { sessionsDir: dir });
14
- }
15
-
16
- test('oturum kodu: benzersiz, formatta, meta\u2019dan geri yüklenir', () => {
17
- const eng = mkEng();
18
- const a = eng.createSession();
19
- const b = eng.createSession();
20
- assert.match(a.code, /^[23456789ABCDEFGHJKMNPQRSTUVWXYZ]{6}$/);
21
- assert.notEqual(a.code, b.code);
22
-
23
- // cache temizlenmiş gibi: yeni engine aynı dosyadan code okumalı
24
- const eng2 = new Engine({}, { sessionsDir: eng.sessionsDir });
25
- const view = eng2.listSessions().find((s) => s.id === a.id);
26
- assert.equal(view.code, a.code);
27
- });
28
-
29
- test('findByCode: kod ile oturumu bulur, hızlı indeks kullanır', async () => {
30
- const eng = mkEng();
31
- const v = eng.createSession();
32
- // gerçek bir mesaj yaz → dosya oluşsun
33
- eng.send(v.id, { text: 'merhaba' });
34
- await new Promise((r) => setTimeout(r, 30));
35
- const hit = eng.findByCode(v.code);
36
- assert.ok(hit);
37
- assert.equal(hit.id, v.id);
38
- assert.equal(eng.findByCode('ZZZZZZ'), null);
39
- assert.equal(eng.findByCode(v.code.toLowerCase()).id, v.id);
40
- fs.rmSync(eng.sessionsDir, { recursive: true, force: true });
41
- });
42
-
43
- test('ORTAM: yerel tarih/saat/dilim prompta girer', () => {
44
- const eng = mkEng();
45
- const sys = eng.buildSystem('test');
46
- assert.match(sys, /Yerel tarih:/);
47
- assert.match(sys, /Yerel saat:/);
48
- assert.match(sys, /UTC varsayma/);
49
- fs.rmSync(eng.sessionsDir, { recursive: true, force: true });
50
- });
package/tests/setup.js DELETED
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- /* Ortak test kurulumu: tüm modüller izole BEAST_DATA altına yazsın. */
4
- const fs = require('fs');
5
- const os = require('os');
6
- const path = require('path');
7
-
8
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'beast-test-'));
9
- process.env.BEAST_DATA = path.join(tmp, 'data');
@@ -1,42 +0,0 @@
1
- 'use strict';
2
-
3
- require('./setup');
4
- const test = require('node:test');
5
- const assert = require('node:assert');
6
- const { estTokens, estMsgTokens } = require('../src/agent/tokens');
7
-
8
- test('estTokens boş metin 0', () => {
9
- assert.equal(estTokens(''), 0);
10
- assert.equal(estTokens(null), 0);
11
- });
12
-
13
- test('estTokens uzunlukla monoton artar', () => {
14
- const a = estTokens('hello world');
15
- const b = estTokens('hello world and more words here');
16
- assert.ok(a > 0 && b > a);
17
- });
18
-
19
- test('geniş karakterler (CJK/emoji) daha pahalı', () => {
20
- const ascii = estTokens('aaaa');
21
- const wide = estTokens('\u4e00\u4e01\u4e02\u4e03'); // 4 CJK karakter
22
- assert.ok(wide > ascii);
23
- });
24
-
25
- test('Türkçe karakterler ASCII\u0027den hafif pahalı', () => {
26
- assert.ok(estTokens('ğğğğ') >= estTokens('aaaa'));
27
- });
28
-
29
- test('estMsgTokens mesaj zarfı ekler', () => {
30
- const m = { role: 'user', content: 'selam' };
31
- assert.ok(estMsgTokens(m) > estTokens('selam'));
32
- });
33
-
34
- test('tool_calls içeren mesaj daha ağır', () => {
35
- const base = { role: 'assistant', content: 'x' };
36
- const withTools = {
37
- role: 'assistant',
38
- content: 'x',
39
- tool_calls: [{ id: '1', type: 'function', function: { name: 'run_command', arguments: '{"command":"dir"}' } }],
40
- };
41
- assert.ok(estMsgTokens(withTools) > estMsgTokens(base));
42
- });
@@ -1,84 +0,0 @@
1
- 'use strict';
2
-
3
- require('./setup');
4
- const test = require('node:test');
5
- const assert = require('node:assert');
6
- const tools = require('../src/agent/tools');
7
-
8
- /* ---------- SSRF guard ---------- */
9
-
10
- test('public URL kabul edilir', () => {
11
- const u = tools.assertPublicHttpUrl('https://example.com/x?y=1');
12
- assert.ok(u.startsWith('https://example.com'));
13
- });
14
-
15
- test('localhost ve özel ağlar engellenir', () => {
16
- const bad = [
17
- 'http://localhost/a',
18
- 'http://127.0.0.1/',
19
- 'http://10.0.0.5/',
20
- 'http://192.168.1.1/',
21
- 'http://172.16.0.1/',
22
- 'http://172.31.255.255/',
23
- 'http://169.254.169.254/meta',
24
- 'http://pc.local/',
25
- 'file:///C:/Windows',
26
- 'ftp://example.com',
27
- 'http://[::1]/',
28
- 'http://user:pass@example.com/',
29
- ];
30
- for (const u of bad) assert.throws(() => tools.assertPublicHttpUrl(u));
31
- });
32
-
33
- test('geçersiz URL atar', () => {
34
- assert.throws(() => tools.assertPublicHttpUrl('not a url'));
35
- });
36
-
37
- /* ---------- DDG parser ---------- */
38
-
39
- test('parseDdgResults sonuçları ayrıştırır', () => {
40
- const html = `
41
- <div class="result results_links">
42
- <a rel="nofollow" class="result__a" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.com%2Fa&amp;rut=abc">Örnek <b>Başlık</b></a>
43
- <a class="result__snippet" href="#">Açıklama &amp; özet</a>
44
- </div>
45
- <div class="result">
46
- <a class="result__a" href="https://direct.com/b">Direkt</a>
47
- <a class="result__snippet">snpt</a>
48
- </div>`;
49
- const out = tools.parseDdgResults(html);
50
- assert.equal(out.length, 2);
51
- assert.equal(out[0].url, 'https://example.com/a');
52
- assert.equal(out[0].title, 'Örnek Başlık');
53
- assert.ok(out[0].snippet.includes('özet'));
54
- assert.equal(out[1].url, 'https://direct.com/b');
55
- });
56
-
57
- test('parseDdgResults boş HTML\u0027de boş döner', () => {
58
- assert.deepEqual(tools.parseDdgResults('<html></html>'), []);
59
- });
60
-
61
- /* ---------- htmlToText ---------- */
62
-
63
- test('htmlToText script/style temizler', () => {
64
- const t = tools.htmlToText('<head><style>p{color:red}</style><script>evil()</script></head><body><p>Merhaba</p> dünya</body>');
65
- assert.ok(t.includes('Merhaba'));
66
- assert.ok(!t.includes('evil'));
67
- assert.ok(!t.includes('color:red'));
68
- });
69
-
70
- /* ---------- dosya araçları ---------- */
71
-
72
- const fs = require('fs');
73
- const os = require('os');
74
- const path = require('path');
75
-
76
- test('exec write/read/list turu', async () => {
77
- const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'beast-tools-'));
78
- const w = JSON.parse(await tools.exec('write_file', { path: 'alt/dosya.txt', content: 'içerik' }, { cwd }));
79
- assert.ok(w.ok);
80
- const r = JSON.parse(await tools.exec('read_file', { path: 'alt/dosya.txt' }, { cwd }));
81
- assert.equal(r.content, 'içerik');
82
- const l = JSON.parse(await tools.exec('list_dir', {}, { cwd }));
83
- assert.ok(l.entries.split('\n')[0].includes('alt'));
84
- });
@@ -1,44 +0,0 @@
1
- 'use strict';
2
-
3
- require('./setup');
4
- const test = require('node:test');
5
- const assert = require('node:assert');
6
- const usageMod = require('../src/agent/usage');
7
-
8
- test('usage: kayıt + bugün/ay raporu + maliyet hesabı', () => {
9
- usageMod.reset();
10
-
11
- /* maliyetsiz çağrı */
12
- usageMod.record({ providerId: 'p1', model: 'm1', promptTokens: 1000, completionTokens: 500 });
13
- /* fiyatlı çağrı: $2/M giriş, $8/M çıkış → (2000*2 + 1000*8)/1e6 = $0.012 */
14
- usageMod.record({
15
- providerId: 'p1',
16
- model: 'm2',
17
- promptTokens: 2000,
18
- completionTokens: 1000,
19
- costIn: 2,
20
- costOut: 8,
21
- });
22
- /* sıfır/eksik token — sayılmaz */
23
- usageMod.record({});
24
- usageMod.record({ providerId: 'pX', model: 'mY' });
25
-
26
- const rep = usageMod.report();
27
- assert.equal(rep.today.total.calls, 2);
28
- assert.equal(rep.today.total.pin, 3000);
29
- assert.equal(rep.today.total.pout, 1500);
30
- assert.ok(Math.abs(rep.today.total.cost - 0.012) < 1e-9);
31
-
32
- const byModel = Object.fromEntries(rep.today.models.map((m) => [m.model, m]));
33
- assert.equal(byModel['p1::m1'].calls, 1);
34
- assert.equal(byModel['p1::m1'].cost, 0);
35
- assert.equal(byModel['p1::m2'].calls, 1);
36
-
37
- /* ay raporu aynı günü kapsar */
38
- assert.equal(rep.month.total.calls, 2);
39
-
40
- /* reset gerçekten temizler */
41
- usageMod.reset();
42
- const rep2 = usageMod.report();
43
- assert.equal(rep2.today.total.calls, 0);
44
- });
package/tests/v11.test.js DELETED
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- require('./setup');
4
- const test = require('node:test');
5
- const assert = require('node:assert');
6
- const Engine = require('../src/agent/engine');
7
-
8
- /* parseReflectionJson: düz / fence'li / gömülü JSON + bozuk girdi */
9
- test('reflection JSON ayrıştırıcı', () => {
10
- const good = Engine.parseReflectionJson(
11
- '{"create": true, "name": "rapor-al", "description": "d", "body": "# Rapor\\n- adım"}'
12
- );
13
- assert.equal(good.create, true);
14
- assert.equal(good.name, 'rapor-al');
15
-
16
- const fenced = Engine.parseReflectionJson(
17
- 'İşte öneri:\n```json\n{"create": false}\n```\nbitti'
18
- );
19
- assert.equal(fenced.create, false);
20
-
21
- const embedded = Engine.parseReflectionJson(
22
- 'önce metin {"create": true, "name": "x", "description": "y", "body": "z"} sonra metin'
23
- );
24
- assert.equal(embedded.name, 'x');
25
-
26
- assert.equal(Engine.parseReflectionJson('JSON yok burada'), null);
27
- assert.equal(Engine.parseReflectionJson('{bozuk'), null);
28
- });
29
-
30
- /* skills taslak yaşam döngüsü */
31
- test('skills draft: add → list → accept → scan\u2019de görünür', () => {
32
- const skills = require('../src/agent/skills');
33
- const r = skills.addDraft({
34
- name: 'Test Yetenek',
35
- description: 'deneme taslağı',
36
- body: '# Test Yetenek\n- adım bir',
37
- });
38
- assert.ok(r.ok);
39
-
40
- const drafts = skills.listDrafts();
41
- const d = drafts.find((x) => x.id === 'test-yetenek');
42
- assert.ok(d, 'taslak listede olmalı');
43
-
44
- // scan taslağı GÖRMEMELİ
45
- assert.ok(!skills.scan().some((s) => s.name === 'Test Yetenek'));
46
-
47
- // kabul → kurulur, taslak silinir
48
- const acc = skills.acceptDraft('test-yetenek');
49
- assert.ok(acc.ok);
50
- assert.ok(skills.scan().some((s) => s.name === 'Test Yetenek'));
51
- assert.ok(!skills.listDrafts().some((x) => x.id === 'test-yelenek' || x.id === 'test-yetenek'));
52
-
53
- // temizlik
54
- const folder = require('path').join(skills.dir(), 'test-yetenek');
55
- require('fs').rmSync(folder, { recursive: true, force: true });
56
- });
57
-
58
- /* kural hattı (#3) */
59
- test('rules: ekle/liste/çıkar + skill\u2019e madde', () => {
60
- const memory = require('../src/agent/memory');
61
- const before = memory.listRules();
62
- const r = memory.addRule('Terminal çıktısını asla kısaltma');
63
- assert.ok(r.ok);
64
- const after = memory.listRules();
65
- assert.equal(after.length, before.length + 1);
66
- assert.ok(after.some((x) => x.includes('Terminal çıktısını')));
67
-
68
- // dup
69
- const dup = memory.addRule('Terminal çıktısını asla kısaltma');
70
- assert.ok(dup.duplicate);
71
-
72
- // kaldır
73
- const rm = memory.removeRule('Terminal çıktısını asla kısaltma');
74
- assert.ok(rm.ok);
75
- assert.ok(!memory.listRules().some((x) => x.includes('Terminal çıktısını')));
76
- });