@timmeck/brain 1.9.0 → 2.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.
- package/README.md +19 -0
- package/brain.log +1164 -0
- package/{src/cli/commands/dashboard.ts → dashboard.html} +688 -807
- package/dist/api/server.d.ts +4 -18
- package/dist/api/server.js +4 -173
- package/dist/api/server.js.map +1 -1
- package/dist/brain.d.ts +1 -0
- package/dist/brain.js +6 -1
- package/dist/brain.js.map +1 -1
- package/dist/cli/colors.d.ts +4 -25
- package/dist/cli/colors.js +3 -89
- package/dist/cli/colors.js.map +1 -1
- package/dist/cli/commands/peers.d.ts +2 -0
- package/dist/cli/commands/peers.js +38 -0
- package/dist/cli/commands/peers.js.map +1 -0
- package/dist/db/connection.d.ts +1 -2
- package/dist/db/connection.js +1 -18
- package/dist/db/connection.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/ipc/__tests__/protocol.test.d.ts +1 -0
- package/dist/ipc/__tests__/protocol.test.js +117 -0
- package/dist/ipc/__tests__/protocol.test.js.map +1 -0
- package/dist/ipc/client.d.ts +1 -16
- package/dist/ipc/client.js +1 -100
- package/dist/ipc/client.js.map +1 -1
- package/dist/ipc/protocol.d.ts +1 -8
- package/dist/ipc/protocol.js +1 -28
- package/dist/ipc/protocol.js.map +1 -1
- package/dist/ipc/router.js +8 -0
- package/dist/ipc/router.js.map +1 -1
- package/dist/ipc/server.d.ts +1 -22
- package/dist/ipc/server.js +1 -163
- package/dist/ipc/server.js.map +1 -1
- package/dist/mcp/http-server.d.ts +1 -7
- package/dist/mcp/http-server.js +6 -117
- package/dist/mcp/http-server.js.map +1 -1
- package/dist/mcp/server.js +5 -61
- package/dist/mcp/server.js.map +1 -1
- package/dist/signals/__tests__/fingerprint.test.d.ts +1 -0
- package/dist/signals/__tests__/fingerprint.test.js +118 -0
- package/dist/signals/__tests__/fingerprint.test.js.map +1 -0
- package/dist/types/ipc.types.d.ts +1 -11
- package/dist/utils/__tests__/hash.test.d.ts +1 -0
- package/dist/utils/__tests__/hash.test.js +32 -0
- package/dist/utils/__tests__/hash.test.js.map +1 -0
- package/dist/utils/__tests__/paths.test.d.ts +1 -0
- package/dist/utils/__tests__/paths.test.js +75 -0
- package/dist/utils/__tests__/paths.test.js.map +1 -0
- package/dist/utils/events.d.ts +4 -8
- package/dist/utils/events.js +2 -14
- package/dist/utils/events.js.map +1 -1
- package/dist/utils/hash.d.ts +1 -1
- package/dist/utils/hash.js +1 -4
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/logger.d.ts +3 -2
- package/dist/utils/logger.js +8 -35
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -1
- package/dist/utils/paths.js +4 -13
- package/dist/utils/paths.js.map +1 -1
- package/package.json +2 -1
- package/BRAIN_PLAN.md +0 -3324
- package/reddit_post.md +0 -45
- package/src/api/server.ts +0 -395
- package/src/brain.ts +0 -313
- package/src/cli/colors.ts +0 -116
- package/src/cli/commands/config.ts +0 -169
- package/src/cli/commands/doctor.ts +0 -124
- package/src/cli/commands/explain.ts +0 -83
- package/src/cli/commands/export.ts +0 -31
- package/src/cli/commands/import.ts +0 -199
- package/src/cli/commands/insights.ts +0 -65
- package/src/cli/commands/learn.ts +0 -24
- package/src/cli/commands/modules.ts +0 -53
- package/src/cli/commands/network.ts +0 -67
- package/src/cli/commands/projects.ts +0 -42
- package/src/cli/commands/query.ts +0 -120
- package/src/cli/commands/start.ts +0 -105
- package/src/cli/commands/status.ts +0 -75
- package/src/cli/commands/stop.ts +0 -34
- package/src/cli/ipc-helper.ts +0 -22
- package/src/cli/update-check.ts +0 -63
- package/src/code/analyzer.ts +0 -117
- package/src/code/fingerprint.ts +0 -87
- package/src/code/matcher.ts +0 -129
- package/src/code/parsers/generic.ts +0 -29
- package/src/code/parsers/python.ts +0 -54
- package/src/code/parsers/typescript.ts +0 -65
- package/src/code/registry.ts +0 -60
- package/src/code/scorer.ts +0 -120
- package/src/config.ts +0 -135
- package/src/dashboard/server.ts +0 -142
- package/src/db/connection.ts +0 -22
- package/src/db/migrations/001_core_schema.ts +0 -120
- package/src/db/migrations/002_learning_schema.ts +0 -38
- package/src/db/migrations/003_code_schema.ts +0 -53
- package/src/db/migrations/004_synapses_schema.ts +0 -57
- package/src/db/migrations/005_fts_indexes.ts +0 -78
- package/src/db/migrations/006_synapses_phase3.ts +0 -17
- package/src/db/migrations/007_feedback.ts +0 -13
- package/src/db/migrations/008_git_integration.ts +0 -38
- package/src/db/migrations/009_embeddings.ts +0 -8
- package/src/db/migrations/index.ts +0 -70
- package/src/db/repositories/antipattern.repository.ts +0 -66
- package/src/db/repositories/code-module.repository.ts +0 -142
- package/src/db/repositories/error.repository.ts +0 -189
- package/src/db/repositories/insight.repository.ts +0 -99
- package/src/db/repositories/notification.repository.ts +0 -66
- package/src/db/repositories/project.repository.ts +0 -93
- package/src/db/repositories/rule.repository.ts +0 -108
- package/src/db/repositories/solution.repository.ts +0 -154
- package/src/db/repositories/synapse.repository.ts +0 -163
- package/src/db/repositories/terminal.repository.ts +0 -101
- package/src/embeddings/engine.ts +0 -238
- package/src/hooks/post-tool-use.ts +0 -92
- package/src/hooks/post-write.ts +0 -129
- package/src/index.ts +0 -63
- package/src/ipc/client.ts +0 -118
- package/src/ipc/protocol.ts +0 -35
- package/src/ipc/router.ts +0 -133
- package/src/ipc/server.ts +0 -176
- package/src/learning/confidence-scorer.ts +0 -80
- package/src/learning/decay.ts +0 -46
- package/src/learning/learning-engine.ts +0 -170
- package/src/learning/pattern-extractor.ts +0 -90
- package/src/learning/rule-generator.ts +0 -74
- package/src/main.rs:10:5 +0 -0
- package/src/matching/error-matcher.ts +0 -166
- package/src/matching/fingerprint.ts +0 -34
- package/src/matching/similarity.ts +0 -61
- package/src/matching/tfidf.ts +0 -74
- package/src/matching/tokenizer.ts +0 -41
- package/src/mcp/auto-detect.ts +0 -93
- package/src/mcp/http-server.ts +0 -140
- package/src/mcp/server.ts +0 -73
- package/src/mcp/tools.ts +0 -328
- package/src/parsing/error-parser.ts +0 -28
- package/src/parsing/parsers/compiler.ts +0 -93
- package/src/parsing/parsers/generic.ts +0 -28
- package/src/parsing/parsers/go.ts +0 -97
- package/src/parsing/parsers/node.ts +0 -69
- package/src/parsing/parsers/python.ts +0 -62
- package/src/parsing/parsers/rust.ts +0 -50
- package/src/parsing/parsers/shell.ts +0 -42
- package/src/parsing/types.ts +0 -47
- package/src/research/gap-analyzer.ts +0 -135
- package/src/research/insight-generator.ts +0 -123
- package/src/research/research-engine.ts +0 -116
- package/src/research/synergy-detector.ts +0 -126
- package/src/research/template-extractor.ts +0 -130
- package/src/research/trend-analyzer.ts +0 -127
- package/src/services/analytics.service.ts +0 -226
- package/src/services/code.service.ts +0 -271
- package/src/services/error.service.ts +0 -266
- package/src/services/git.service.ts +0 -132
- package/src/services/notification.service.ts +0 -41
- package/src/services/prevention.service.ts +0 -159
- package/src/services/research.service.ts +0 -98
- package/src/services/solution.service.ts +0 -174
- package/src/services/synapse.service.ts +0 -59
- package/src/services/terminal.service.ts +0 -81
- package/src/synapses/activation.ts +0 -80
- package/src/synapses/decay.ts +0 -38
- package/src/synapses/hebbian.ts +0 -69
- package/src/synapses/pathfinder.ts +0 -81
- package/src/synapses/synapse-manager.ts +0 -113
- package/src/types/code.types.ts +0 -52
- package/src/types/config.types.ts +0 -103
- package/src/types/error.types.ts +0 -67
- package/src/types/ipc.types.ts +0 -8
- package/src/types/mcp.types.ts +0 -53
- package/src/types/research.types.ts +0 -28
- package/src/types/solution.types.ts +0 -30
- package/src/types/synapse.types.ts +0 -50
- package/src/utils/events.ts +0 -45
- package/src/utils/hash.ts +0 -5
- package/src/utils/logger.ts +0 -48
- package/src/utils/paths.ts +0 -19
- package/tests/e2e/test_code_intelligence.py +0 -1015
- package/tests/e2e/test_error_memory.py +0 -451
- package/tests/e2e/test_full_integration.py +0 -534
- package/tests/fixtures/code-modules/modules.ts +0 -83
- package/tests/fixtures/errors/go.ts +0 -9
- package/tests/fixtures/errors/node.ts +0 -24
- package/tests/fixtures/errors/python.ts +0 -21
- package/tests/fixtures/errors/rust.ts +0 -25
- package/tests/fixtures/errors/shell.ts +0 -15
- package/tests/fixtures/solutions/solutions.ts +0 -27
- package/tests/helpers/setup-db.ts +0 -52
- package/tests/integration/code-flow.test.ts +0 -86
- package/tests/integration/error-flow.test.ts +0 -83
- package/tests/integration/ipc-flow.test.ts +0 -166
- package/tests/integration/learning-cycle.test.ts +0 -82
- package/tests/integration/synapse-flow.test.ts +0 -117
- package/tests/unit/code/analyzer.test.ts +0 -58
- package/tests/unit/code/fingerprint.test.ts +0 -51
- package/tests/unit/code/scorer.test.ts +0 -55
- package/tests/unit/learning/confidence-scorer.test.ts +0 -60
- package/tests/unit/learning/decay.test.ts +0 -45
- package/tests/unit/learning/pattern-extractor.test.ts +0 -50
- package/tests/unit/matching/error-matcher.test.ts +0 -69
- package/tests/unit/matching/fingerprint.test.ts +0 -47
- package/tests/unit/matching/similarity.test.ts +0 -65
- package/tests/unit/matching/tfidf.test.ts +0 -71
- package/tests/unit/matching/tokenizer.test.ts +0 -83
- package/tests/unit/parsing/parsers.test.ts +0 -113
- package/tests/unit/research/gap-analyzer.test.ts +0 -45
- package/tests/unit/research/trend-analyzer.test.ts +0 -45
- package/tests/unit/synapses/activation.test.ts +0 -80
- package/tests/unit/synapses/decay.test.ts +0 -27
- package/tests/unit/synapses/hebbian.test.ts +0 -96
- package/tests/unit/synapses/pathfinder.test.ts +0 -72
- package/tsconfig.json +0 -18
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { analyzeCode, checkPurity, measureCohesion } from '../../../src/code/analyzer.js';
|
|
3
|
-
import { retryModule, loggerModule, hashModule } from '../../fixtures/code-modules/modules.js';
|
|
4
|
-
|
|
5
|
-
describe('analyzeCode', () => {
|
|
6
|
-
it('analyzes TypeScript module', () => {
|
|
7
|
-
const result = analyzeCode(retryModule.source, 'typescript');
|
|
8
|
-
expect(result).toBeTruthy();
|
|
9
|
-
expect(result.exports).toBeDefined();
|
|
10
|
-
expect(result.linesOfCode).toBeGreaterThan(0);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('analyzes Python module', () => {
|
|
14
|
-
const result = analyzeCode(hashModule.source, 'python');
|
|
15
|
-
expect(result).toBeTruthy();
|
|
16
|
-
expect(result.exports.length).toBeGreaterThan(0);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('detects exports in TypeScript', () => {
|
|
20
|
-
const result = analyzeCode(retryModule.source, 'typescript');
|
|
21
|
-
const exportNames = result.exports.map((e: any) => e.name);
|
|
22
|
-
expect(exportNames).toContain('retry');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('detects external dependencies', () => {
|
|
26
|
-
const result = analyzeCode(loggerModule.source, 'typescript');
|
|
27
|
-
expect(result.externalDeps.length).toBeGreaterThan(0);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('checkPurity', () => {
|
|
32
|
-
it('pure function returns true', () => {
|
|
33
|
-
const pureCode = `export function add(a: number, b: number): number { return a + b; }`;
|
|
34
|
-
expect(checkPurity(pureCode)).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('function with side effects returns false', () => {
|
|
38
|
-
const impureCode = `export function save(data: any) { fs.writeFileSync('file', data); console.log('saved'); }`;
|
|
39
|
-
expect(checkPurity(impureCode)).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('measureCohesion', () => {
|
|
44
|
-
it('returns value between 0 and 1', () => {
|
|
45
|
-
const exports = [
|
|
46
|
-
{ name: 'sha256', type: 'function' },
|
|
47
|
-
{ name: 'md5', type: 'function' },
|
|
48
|
-
] as any[];
|
|
49
|
-
const score = measureCohesion(exports);
|
|
50
|
-
expect(score).toBeGreaterThanOrEqual(0);
|
|
51
|
-
expect(score).toBeLessThanOrEqual(1);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('handles empty exports without crashing', () => {
|
|
55
|
-
const score = measureCohesion([]);
|
|
56
|
-
expect(typeof score).toBe('number');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { fingerprintCode, stripComments } from '../../../src/code/fingerprint.js';
|
|
3
|
-
|
|
4
|
-
describe('fingerprintCode', () => {
|
|
5
|
-
it('produces consistent fingerprint', () => {
|
|
6
|
-
const code = 'function add(a, b) { return a + b; }';
|
|
7
|
-
const fp1 = fingerprintCode(code, 'typescript');
|
|
8
|
-
const fp2 = fingerprintCode(code, 'typescript');
|
|
9
|
-
expect(fp1).toBe(fp2);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('produces different fingerprint for different code', () => {
|
|
13
|
-
const fp1 = fingerprintCode('function add(a, b) { return a + b; }', 'typescript');
|
|
14
|
-
const fp2 = fingerprintCode('function mul(a, b) { return a * b; }', 'typescript');
|
|
15
|
-
expect(fp1).not.toBe(fp2);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('ignores whitespace differences', () => {
|
|
19
|
-
const fp1 = fingerprintCode('function add(a, b) { return a + b; }', 'typescript');
|
|
20
|
-
const fp2 = fingerprintCode('function add(a, b) {\n return a + b;\n}', 'typescript');
|
|
21
|
-
expect(fp1).toBe(fp2);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('returns hex string', () => {
|
|
25
|
-
const fp = fingerprintCode('const x = 1;', 'typescript');
|
|
26
|
-
expect(fp).toMatch(/^[a-f0-9]+$/);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('stripComments', () => {
|
|
31
|
-
it('removes single-line comments', () => {
|
|
32
|
-
const code = 'const x = 1; // this is a comment\nconst y = 2;';
|
|
33
|
-
const stripped = stripComments(code, 'typescript');
|
|
34
|
-
expect(stripped).not.toContain('this is a comment');
|
|
35
|
-
expect(stripped).toContain('const x = 1');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('removes multi-line comments', () => {
|
|
39
|
-
const code = '/* block comment */\nconst x = 1;';
|
|
40
|
-
const stripped = stripComments(code, 'typescript');
|
|
41
|
-
expect(stripped).not.toContain('block comment');
|
|
42
|
-
expect(stripped).toContain('const x = 1');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('removes Python comments', () => {
|
|
46
|
-
const code = '# python comment\nx = 1';
|
|
47
|
-
const stripped = stripComments(code, 'python');
|
|
48
|
-
expect(stripped).not.toContain('python comment');
|
|
49
|
-
expect(stripped).toContain('x = 1');
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { computeReusabilityScore, getSignalBreakdown, MODULE_THRESHOLD } from '../../../src/code/scorer.js';
|
|
3
|
-
import { analyzeCode } from '../../../src/code/analyzer.js';
|
|
4
|
-
import { retryModule } from '../../fixtures/code-modules/modules.js';
|
|
5
|
-
|
|
6
|
-
describe('computeReusabilityScore', () => {
|
|
7
|
-
it('scores a real module', () => {
|
|
8
|
-
const analysis = analyzeCode(retryModule.source, 'typescript');
|
|
9
|
-
const score = computeReusabilityScore({
|
|
10
|
-
source: retryModule.source,
|
|
11
|
-
filePath: retryModule.filePath,
|
|
12
|
-
exports: analysis.exports,
|
|
13
|
-
internalDeps: analysis.internalDeps,
|
|
14
|
-
hasTypeAnnotations: analysis.hasTypeAnnotations,
|
|
15
|
-
});
|
|
16
|
-
expect(score).toBeGreaterThan(0);
|
|
17
|
-
expect(score).toBeLessThanOrEqual(1);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('returns value between 0 and 1', () => {
|
|
21
|
-
const score = computeReusabilityScore({
|
|
22
|
-
source: 'export function add(a: number, b: number) { return a + b; }',
|
|
23
|
-
filePath: 'utils/add.ts',
|
|
24
|
-
exports: [{ name: 'add', type: 'function' }] as any[],
|
|
25
|
-
internalDeps: [],
|
|
26
|
-
hasTypeAnnotations: true,
|
|
27
|
-
});
|
|
28
|
-
expect(score).toBeGreaterThanOrEqual(0);
|
|
29
|
-
expect(score).toBeLessThanOrEqual(1);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('getSignalBreakdown', () => {
|
|
34
|
-
it('returns named signals with scores', () => {
|
|
35
|
-
const signals = getSignalBreakdown({
|
|
36
|
-
source: 'export function add(a: number, b: number) { return a + b; }',
|
|
37
|
-
filePath: 'utils/add.ts',
|
|
38
|
-
exports: [{ name: 'add', type: 'function' }] as any[],
|
|
39
|
-
internalDeps: [],
|
|
40
|
-
hasTypeAnnotations: true,
|
|
41
|
-
});
|
|
42
|
-
expect(signals.length).toBeGreaterThan(0);
|
|
43
|
-
for (const signal of signals) {
|
|
44
|
-
expect(signal.name).toBeTruthy();
|
|
45
|
-
expect(typeof signal.score).toBe('number');
|
|
46
|
-
expect(typeof signal.weighted).toBe('number');
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('MODULE_THRESHOLD', () => {
|
|
52
|
-
it('is 0.6', () => {
|
|
53
|
-
expect(MODULE_THRESHOLD).toBe(0.6);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { wilsonScore, timeDecayedConfidence, computeConfidence } from '../../../src/learning/confidence-scorer.js';
|
|
3
|
-
|
|
4
|
-
describe('wilsonScore', () => {
|
|
5
|
-
it('returns 0 for 0 trials', () => {
|
|
6
|
-
expect(wilsonScore(0, 0)).toBe(0);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('returns low score for single success', () => {
|
|
10
|
-
const score = wilsonScore(1, 1);
|
|
11
|
-
// 1/1 = 100% but Wilson should be conservative
|
|
12
|
-
expect(score).toBeLessThan(0.9);
|
|
13
|
-
expect(score).toBeGreaterThan(0);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('increases with more samples', () => {
|
|
17
|
-
const score5 = wilsonScore(5, 5);
|
|
18
|
-
const score50 = wilsonScore(50, 50);
|
|
19
|
-
expect(score50).toBeGreaterThan(score5);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('reflects success rate', () => {
|
|
23
|
-
const high = wilsonScore(9, 10);
|
|
24
|
-
const low = wilsonScore(1, 10);
|
|
25
|
-
expect(high).toBeGreaterThan(low);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('returns value between 0 and 1', () => {
|
|
29
|
-
const score = wilsonScore(7, 10);
|
|
30
|
-
expect(score).toBeGreaterThanOrEqual(0);
|
|
31
|
-
expect(score).toBeLessThanOrEqual(1);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('timeDecayedConfidence', () => {
|
|
36
|
-
it('recent usage has higher confidence', () => {
|
|
37
|
-
const now = new Date().toISOString();
|
|
38
|
-
const recent = timeDecayedConfidence(8, 10, now, 30);
|
|
39
|
-
|
|
40
|
-
const oldDate = new Date(Date.now() - 90 * 86400000).toISOString();
|
|
41
|
-
const old = timeDecayedConfidence(8, 10, oldDate, 30);
|
|
42
|
-
|
|
43
|
-
expect(recent).toBeGreaterThan(old);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('computeConfidence', () => {
|
|
48
|
-
it('combines success rate and time decay', () => {
|
|
49
|
-
const now = new Date().toISOString();
|
|
50
|
-
const conf = computeConfidence(8, 2, now);
|
|
51
|
-
expect(conf).toBeGreaterThan(0);
|
|
52
|
-
expect(conf).toBeLessThanOrEqual(1);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('zero successes gives low confidence', () => {
|
|
56
|
-
const now = new Date().toISOString();
|
|
57
|
-
const conf = computeConfidence(0, 5, now);
|
|
58
|
-
expect(conf).toBeLessThan(0.3);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { relevanceDecay, shouldPruneRule } from '../../../src/learning/decay.js';
|
|
3
|
-
|
|
4
|
-
describe('relevanceDecay', () => {
|
|
5
|
-
it('returns 1.0 for current timestamp', () => {
|
|
6
|
-
const now = new Date().toISOString();
|
|
7
|
-
expect(relevanceDecay(now, 30)).toBeCloseTo(1.0, 1);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('returns ~0.5 after one half-life', () => {
|
|
11
|
-
const halfLifeDays = 30;
|
|
12
|
-
const past = new Date(Date.now() - halfLifeDays * 86400000).toISOString();
|
|
13
|
-
expect(relevanceDecay(past, halfLifeDays)).toBeCloseTo(0.5, 1);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns near 0 for very old timestamps', () => {
|
|
17
|
-
const veryOld = new Date(Date.now() - 365 * 86400000).toISOString();
|
|
18
|
-
expect(relevanceDecay(veryOld, 30)).toBeLessThan(0.01);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('returns value between 0 and 1', () => {
|
|
22
|
-
const past = new Date(Date.now() - 10 * 86400000).toISOString();
|
|
23
|
-
const val = relevanceDecay(past, 30);
|
|
24
|
-
expect(val).toBeGreaterThanOrEqual(0);
|
|
25
|
-
expect(val).toBeLessThanOrEqual(1);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('shouldPruneRule', () => {
|
|
30
|
-
it('prunes low confidence rules', () => {
|
|
31
|
-
expect(shouldPruneRule(0.1, 0, 10, 0.2, 0.5)).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('keeps high confidence rules', () => {
|
|
35
|
-
expect(shouldPruneRule(0.8, 1, 20, 0.2, 0.5)).toBe(false);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('prunes rules with high rejection rate', () => {
|
|
39
|
-
expect(shouldPruneRule(0.5, 8, 10, 0.2, 0.5)).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('keeps rules with low rejection rate', () => {
|
|
43
|
-
expect(shouldPruneRule(0.5, 1, 10, 0.2, 0.5)).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { extractPatterns } from '../../../src/learning/pattern-extractor.js';
|
|
3
|
-
import type { ErrorRecord } from '../../../src/types/error.types.js';
|
|
4
|
-
|
|
5
|
-
function makeErrorRecord(overrides: Partial<ErrorRecord> = {}): ErrorRecord {
|
|
6
|
-
return {
|
|
7
|
-
id: 1,
|
|
8
|
-
project_id: 1,
|
|
9
|
-
terminal_id: null,
|
|
10
|
-
type: 'TypeError',
|
|
11
|
-
message: "Cannot read properties of undefined (reading 'map')",
|
|
12
|
-
fingerprint: 'fp1',
|
|
13
|
-
raw_output: '',
|
|
14
|
-
context: null,
|
|
15
|
-
file_path: '/app/main.ts',
|
|
16
|
-
line_number: null,
|
|
17
|
-
column_number: null,
|
|
18
|
-
occurrence_count: 1,
|
|
19
|
-
first_seen: new Date().toISOString(),
|
|
20
|
-
last_seen: new Date().toISOString(),
|
|
21
|
-
resolved: 0,
|
|
22
|
-
resolved_at: null,
|
|
23
|
-
...overrides,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe('extractPatterns', () => {
|
|
28
|
-
it('finds pattern from similar errors', () => {
|
|
29
|
-
const errors = [
|
|
30
|
-
makeErrorRecord({ id: 1, message: "Cannot read properties of undefined (reading 'map')", fingerprint: 'fp1' }),
|
|
31
|
-
makeErrorRecord({ id: 2, message: "Cannot read properties of undefined (reading 'filter')", fingerprint: 'fp2' }),
|
|
32
|
-
makeErrorRecord({ id: 3, message: "Cannot read properties of undefined (reading 'forEach')", fingerprint: 'fp3' }),
|
|
33
|
-
makeErrorRecord({ id: 4, message: "Cannot read properties of undefined (reading 'reduce')", fingerprint: 'fp4' }),
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
const patterns = extractPatterns(errors);
|
|
37
|
-
expect(patterns.length).toBeGreaterThan(0);
|
|
38
|
-
expect(patterns[0].errorIds.length).toBeGreaterThanOrEqual(2);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('returns empty for single error', () => {
|
|
42
|
-
const errors = [makeErrorRecord({ id: 1 })];
|
|
43
|
-
const patterns = extractPatterns(errors);
|
|
44
|
-
expect(patterns).toEqual([]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('returns empty for empty input', () => {
|
|
48
|
-
expect(extractPatterns([])).toEqual([]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { matchError } from '../../../src/matching/error-matcher.js';
|
|
3
|
-
import type { ErrorRecord } from '../../../src/types/error.types.js';
|
|
4
|
-
|
|
5
|
-
function makeError(overrides: Partial<ErrorRecord> = {}): ErrorRecord {
|
|
6
|
-
return {
|
|
7
|
-
id: 1,
|
|
8
|
-
project_id: 1,
|
|
9
|
-
terminal_id: null,
|
|
10
|
-
type: 'TypeError',
|
|
11
|
-
message: "Cannot read properties of undefined (reading 'map')",
|
|
12
|
-
fingerprint: 'abc123',
|
|
13
|
-
raw_output: "TypeError: Cannot read properties of undefined (reading 'map')",
|
|
14
|
-
context: null,
|
|
15
|
-
file_path: '/app/src/main.ts',
|
|
16
|
-
line_number: null,
|
|
17
|
-
column_number: null,
|
|
18
|
-
occurrence_count: 1,
|
|
19
|
-
first_seen: new Date().toISOString(),
|
|
20
|
-
last_seen: new Date().toISOString(),
|
|
21
|
-
resolved: 0,
|
|
22
|
-
resolved_at: null,
|
|
23
|
-
...overrides,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe('matchError', () => {
|
|
28
|
-
it('returns matches sorted by score', () => {
|
|
29
|
-
const incoming = makeError({ id: 0 });
|
|
30
|
-
const candidates = [
|
|
31
|
-
makeError({ id: 1, fingerprint: 'abc123', type: 'TypeError' }),
|
|
32
|
-
makeError({ id: 2, fingerprint: 'different', type: 'RangeError', message: 'Maximum call stack size exceeded' }),
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const results = matchError(incoming, candidates);
|
|
36
|
-
expect(results.length).toBeGreaterThan(0);
|
|
37
|
-
// Identical fingerprint should score highest
|
|
38
|
-
expect(results[0].errorId).toBe(1);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('returns empty for no candidates', () => {
|
|
42
|
-
const incoming = makeError({ id: 0 });
|
|
43
|
-
const results = matchError(incoming, []);
|
|
44
|
-
expect(results).toEqual([]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('fingerprint match boosts score', () => {
|
|
48
|
-
const incoming = makeError({ id: 0, fingerprint: 'same_fp' });
|
|
49
|
-
const exactFp = makeError({ id: 1, fingerprint: 'same_fp' });
|
|
50
|
-
const diffFp = makeError({ id: 2, fingerprint: 'other_fp', type: 'RangeError', message: 'completely different' });
|
|
51
|
-
|
|
52
|
-
const results = matchError(incoming, [exactFp, diffFp]);
|
|
53
|
-
if (results.length >= 2) {
|
|
54
|
-
expect(results[0].errorId).toBe(1);
|
|
55
|
-
expect(results[0].score).toBeGreaterThan(results[1].score);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('results have score and signals', () => {
|
|
60
|
-
const incoming = makeError({ id: 0 });
|
|
61
|
-
const candidate = makeError({ id: 1 });
|
|
62
|
-
const results = matchError(incoming, [candidate]);
|
|
63
|
-
if (results.length > 0) {
|
|
64
|
-
expect(typeof results[0].score).toBe('number');
|
|
65
|
-
expect(results[0].signals.length).toBeGreaterThan(0);
|
|
66
|
-
expect(typeof results[0].isStrong).toBe('boolean');
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { templateMessage, generateFingerprint } from '../../../src/matching/fingerprint.js';
|
|
3
|
-
|
|
4
|
-
describe('templateMessage', () => {
|
|
5
|
-
it('replaces file paths with placeholder', () => {
|
|
6
|
-
const result = templateMessage('Error in /app/src/main.ts:42:5');
|
|
7
|
-
expect(result).not.toContain('/app/src/main.ts');
|
|
8
|
-
expect(result).toContain('<PATH>');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('replaces hex addresses with <ADDR>', () => {
|
|
12
|
-
const result = templateMessage('at 0x7fff5fbff8c0');
|
|
13
|
-
expect(result).toContain('<ADDR>');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('produces consistent output for similar messages', () => {
|
|
17
|
-
const a = templateMessage("Cannot read property 'name' of undefined at /foo/bar.js:10:5");
|
|
18
|
-
const b = templateMessage("Cannot read property 'name' of undefined at /baz/qux.js:20:3");
|
|
19
|
-
expect(a).toBe(b);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('replaces URLs', () => {
|
|
23
|
-
// Unix path regex runs before URL regex, so URL domain/path part gets <PATH>
|
|
24
|
-
// Test that the URL string is at least transformed (not left as-is)
|
|
25
|
-
const result = templateMessage('Failed to fetch https://api.example.com/data');
|
|
26
|
-
expect(result).not.toContain('https://api.example.com/data');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('generateFingerprint', () => {
|
|
31
|
-
it('produces consistent hash for same error', () => {
|
|
32
|
-
const fp1 = generateFingerprint('TypeError', 'Cannot read undefined', []);
|
|
33
|
-
const fp2 = generateFingerprint('TypeError', 'Cannot read undefined', []);
|
|
34
|
-
expect(fp1).toBe(fp2);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('produces different hash for different error types', () => {
|
|
38
|
-
const fp1 = generateFingerprint('TypeError', 'msg', []);
|
|
39
|
-
const fp2 = generateFingerprint('RangeError', 'msg', []);
|
|
40
|
-
expect(fp1).not.toBe(fp2);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns a hex string', () => {
|
|
44
|
-
const fp = generateFingerprint('Error', 'test', []);
|
|
45
|
-
expect(fp).toMatch(/^[a-f0-9]+$/);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { levenshteinDistance, cosineSimilarity, jaccardSimilarity } from '../../../src/matching/similarity.js';
|
|
3
|
-
|
|
4
|
-
describe('levenshteinDistance (normalized similarity)', () => {
|
|
5
|
-
it('returns 1 for identical strings', () => {
|
|
6
|
-
expect(levenshteinDistance('hello', 'hello')).toBeCloseTo(1.0);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('returns 0 for completely different strings', () => {
|
|
10
|
-
expect(levenshteinDistance('', 'abc')).toBeCloseTo(0.0);
|
|
11
|
-
expect(levenshteinDistance('abc', '')).toBeCloseTo(0.0);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('returns high similarity for single edit', () => {
|
|
15
|
-
// cat vs bat: 1 edit / 3 length = 0.33 distance → 0.67 similarity
|
|
16
|
-
expect(levenshteinDistance('cat', 'bat')).toBeCloseTo(1 - 1 / 3, 1);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('returns value between 0 and 1', () => {
|
|
20
|
-
const sim = levenshteinDistance('kitten', 'sitting');
|
|
21
|
-
expect(sim).toBeGreaterThanOrEqual(0);
|
|
22
|
-
expect(sim).toBeLessThanOrEqual(1);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('cosineSimilarity', () => {
|
|
27
|
-
it('returns 1 for identical token arrays', () => {
|
|
28
|
-
expect(cosineSimilarity(['a', 'b', 'c'], ['a', 'b', 'c'])).toBeCloseTo(1.0);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('returns 0 for disjoint token arrays', () => {
|
|
32
|
-
expect(cosineSimilarity(['a', 'b'], ['c', 'd'])).toBeCloseTo(0.0);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('returns value between 0 and 1 for partial overlap', () => {
|
|
36
|
-
const sim = cosineSimilarity(['a', 'b', 'c'], ['b', 'c', 'd']);
|
|
37
|
-
expect(sim).toBeGreaterThan(0);
|
|
38
|
-
expect(sim).toBeLessThan(1);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('handles empty arrays', () => {
|
|
42
|
-
expect(cosineSimilarity([], [])).toBe(0);
|
|
43
|
-
expect(cosineSimilarity(['a'], [])).toBe(0);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('jaccardSimilarity', () => {
|
|
48
|
-
it('returns 1 for identical sets', () => {
|
|
49
|
-
expect(jaccardSimilarity(['a', 'b'], ['a', 'b'])).toBeCloseTo(1.0);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('returns 0 for disjoint sets', () => {
|
|
53
|
-
expect(jaccardSimilarity(['a', 'b'], ['c', 'd'])).toBeCloseTo(0.0);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('computes correct ratio for partial overlap', () => {
|
|
57
|
-
// intersection {b} = 1, union {a,b,c} = 3
|
|
58
|
-
const sim = jaccardSimilarity(['a', 'b'], ['b', 'c']);
|
|
59
|
-
expect(sim).toBeCloseTo(1 / 3);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('handles empty arrays', () => {
|
|
63
|
-
expect(jaccardSimilarity([], [])).toBe(0);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { TfIdfIndex } from '../../../src/matching/tfidf.js';
|
|
3
|
-
|
|
4
|
-
describe('TfIdfIndex', () => {
|
|
5
|
-
it('indexes documents and returns matches', () => {
|
|
6
|
-
const index = new TfIdfIndex();
|
|
7
|
-
// Add docs in order where query terms get correct IDF
|
|
8
|
-
// IDF is only recomputed for terms in the newly added doc,
|
|
9
|
-
// so add the doc with query terms last to ensure fresh IDF
|
|
10
|
-
index.addDocument(3, ['rust', 'borrow', 'lifetime']);
|
|
11
|
-
index.addDocument(2, ['python', 'import', 'module']);
|
|
12
|
-
index.addDocument(1, ['typescript', 'error', 'module']);
|
|
13
|
-
|
|
14
|
-
const results = index.query(['typescript']);
|
|
15
|
-
expect(results.length).toBeGreaterThan(0);
|
|
16
|
-
// Doc 1 has 'typescript'
|
|
17
|
-
expect(results[0].id).toBe(1);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('tracks document count', () => {
|
|
21
|
-
const index = new TfIdfIndex();
|
|
22
|
-
expect(index.getDocumentCount()).toBe(0);
|
|
23
|
-
index.addDocument(1, ['a', 'b']);
|
|
24
|
-
expect(index.getDocumentCount()).toBe(1);
|
|
25
|
-
index.addDocument(2, ['c', 'd']);
|
|
26
|
-
expect(index.getDocumentCount()).toBe(2);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('removes documents', () => {
|
|
30
|
-
const index = new TfIdfIndex();
|
|
31
|
-
index.addDocument(1, ['error', 'type']);
|
|
32
|
-
index.addDocument(2, ['error', 'syntax']);
|
|
33
|
-
index.removeDocument(1);
|
|
34
|
-
expect(index.getDocumentCount()).toBe(1);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('returns empty for no match', () => {
|
|
38
|
-
const index = new TfIdfIndex();
|
|
39
|
-
index.addDocument(1, ['foo', 'bar']);
|
|
40
|
-
const results = index.query(['completely', 'different']);
|
|
41
|
-
expect(results).toEqual([]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('respects topK parameter', () => {
|
|
45
|
-
const index = new TfIdfIndex();
|
|
46
|
-
for (let i = 0; i < 20; i++) {
|
|
47
|
-
index.addDocument(i, ['shared', `unique${i}`]);
|
|
48
|
-
}
|
|
49
|
-
// 'unique0' only in doc 0, so has high IDF — query with it plus 'shared'
|
|
50
|
-
const results = index.query(['unique0', 'shared'], 5);
|
|
51
|
-
expect(results.length).toBeLessThanOrEqual(5);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('getIdf returns a map', () => {
|
|
55
|
-
const index = new TfIdfIndex();
|
|
56
|
-
// IDF = log(N/df), only recomputed for terms in the just-added doc.
|
|
57
|
-
// Add 'frequent' in all 3 docs, 'rare' in last doc only.
|
|
58
|
-
// When doc3 is added (N=3), 'rare' df=1 → IDF=log(3)=1.099
|
|
59
|
-
// 'frequent' df=3 → IDF=log(3/3)=0
|
|
60
|
-
index.addDocument(1, ['frequent', 'alpha']);
|
|
61
|
-
index.addDocument(2, ['frequent', 'beta']);
|
|
62
|
-
index.addDocument(3, ['frequent', 'rare']);
|
|
63
|
-
|
|
64
|
-
const idf = index.getIdf();
|
|
65
|
-
expect(idf).toBeInstanceOf(Map);
|
|
66
|
-
expect(idf.has('rare')).toBe(true);
|
|
67
|
-
expect(idf.has('frequent')).toBe(true);
|
|
68
|
-
// rare appears in 1/3 docs, frequent in 3/3
|
|
69
|
-
expect(idf.get('rare')!).toBeGreaterThan(idf.get('frequent')!);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { splitCamelCase, splitSnakeCase, removeStopwords, tokenize } from '../../../src/matching/tokenizer.js';
|
|
3
|
-
|
|
4
|
-
describe('splitCamelCase', () => {
|
|
5
|
-
it('splits camelCase words (preserves case)', () => {
|
|
6
|
-
const result = splitCamelCase('camelCase');
|
|
7
|
-
expect(result).toContain('camel');
|
|
8
|
-
expect(result).toContain('Case');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('splits PascalCase words', () => {
|
|
12
|
-
const result = splitCamelCase('PascalCase');
|
|
13
|
-
expect(result).toContain('Pascal');
|
|
14
|
-
expect(result).toContain('Case');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('handles consecutive uppercase (acronyms)', () => {
|
|
18
|
-
const result = splitCamelCase('parseHTMLResponse');
|
|
19
|
-
expect(result).toContain('parse');
|
|
20
|
-
expect(result).toContain('HTML');
|
|
21
|
-
expect(result).toContain('Response');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('returns single word unchanged', () => {
|
|
25
|
-
expect(splitCamelCase('hello')).toEqual(['hello']);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('splitSnakeCase', () => {
|
|
30
|
-
it('splits snake_case words', () => {
|
|
31
|
-
expect(splitSnakeCase('snake_case')).toEqual(['snake', 'case']);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('splits kebab-case words', () => {
|
|
35
|
-
expect(splitSnakeCase('kebab-case')).toEqual(['kebab', 'case']);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('returns single word unchanged', () => {
|
|
39
|
-
expect(splitSnakeCase('hello')).toEqual(['hello']);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('removeStopwords', () => {
|
|
44
|
-
it('removes common stopwords', () => {
|
|
45
|
-
const tokens = ['the', 'is', 'in', 'module'];
|
|
46
|
-
const result = removeStopwords(tokens);
|
|
47
|
-
expect(result).toContain('module');
|
|
48
|
-
expect(result).not.toContain('the');
|
|
49
|
-
expect(result).not.toContain('is');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('error is treated as stopword', () => {
|
|
53
|
-
// 'error' is in the stopword list
|
|
54
|
-
const tokens = ['error', 'module'];
|
|
55
|
-
const result = removeStopwords(tokens);
|
|
56
|
-
expect(result).toContain('module');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('tokenize', () => {
|
|
61
|
-
it('tokenizes and lowercases text', () => {
|
|
62
|
-
const tokens = tokenize('Cannot read property map of undefined');
|
|
63
|
-
expect(tokens).toContain('read');
|
|
64
|
-
expect(tokens).toContain('property');
|
|
65
|
-
expect(tokens).toContain('map');
|
|
66
|
-
expect(tokens).toContain('undefined');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('handles empty string', () => {
|
|
70
|
-
expect(tokenize('')).toEqual([]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('lowercases all tokens', () => {
|
|
74
|
-
const tokens = tokenize('Something FAILED');
|
|
75
|
-
tokens.forEach(t => expect(t).toBe(t.toLowerCase()));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('returns unique tokens', () => {
|
|
79
|
-
const tokens = tokenize('error error error');
|
|
80
|
-
const unique = new Set(tokens);
|
|
81
|
-
expect(tokens.length).toBe(unique.size);
|
|
82
|
-
});
|
|
83
|
-
});
|