@timmeck/brain 1.9.0 → 2.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.
- package/README.md +33 -0
- package/brain.log +3876 -0
- package/{src/cli/commands/dashboard.ts → dashboard.html} +694 -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 +2 -0
- package/dist/brain.js +15 -4
- 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/dashboard.js +21 -2
- package/dist/cli/commands/dashboard.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/cli/commands/status.js +0 -1
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/config.js +2 -29
- package/dist/config.js.map +1 -1
- 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.d.ts +2 -0
- package/dist/ipc/router.js +30 -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/learning/confidence-scorer.d.ts +2 -5
- package/dist/learning/confidence-scorer.js +4 -19
- package/dist/learning/confidence-scorer.js.map +1 -1
- package/dist/learning/decay.js +2 -3
- package/dist/learning/decay.js.map +1 -1
- package/dist/learning/learning-engine.d.ts +2 -5
- package/dist/learning/learning-engine.js +3 -15
- package/dist/learning/learning-engine.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/mcp/tools.js +36 -0
- package/dist/mcp/tools.js.map +1 -1
- package/dist/parsing/parsers/compiler.js +1 -1
- package/dist/parsing/parsers/compiler.js.map +1 -1
- package/dist/research/research-engine.d.ts +2 -6
- package/dist/research/research-engine.js +3 -23
- package/dist/research/research-engine.js.map +1 -1
- package/dist/services/synapse.service.d.ts +3 -3
- 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/synapses/activation.d.ts +3 -13
- package/dist/synapses/activation.js +2 -49
- package/dist/synapses/activation.js.map +1 -1
- package/dist/synapses/decay.d.ts +2 -11
- package/dist/synapses/decay.js +2 -26
- package/dist/synapses/decay.js.map +1 -1
- package/dist/synapses/hebbian.d.ts +2 -13
- package/dist/synapses/hebbian.js +2 -35
- package/dist/synapses/hebbian.js.map +1 -1
- package/dist/synapses/pathfinder.d.ts +2 -14
- package/dist/synapses/pathfinder.js +2 -49
- package/dist/synapses/pathfinder.js.map +1 -1
- package/dist/synapses/synapse-manager.d.ts +7 -23
- package/dist/synapses/synapse-manager.js +6 -63
- package/dist/synapses/synapse-manager.js.map +1 -1
- 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/eslint.config.js +14 -0
- package/package.json +56 -49
- 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,25 +0,0 @@
|
|
|
1
|
-
export const rustCompilerError = `error[E0308]: mismatched types
|
|
2
|
-
--> src/main.rs:10:5
|
|
3
|
-
|
|
|
4
|
-
9 | fn get_count() -> u32 {
|
|
5
|
-
| --- expected \`u32\` because of return type
|
|
6
|
-
10| "hello"
|
|
7
|
-
| ^^^^^^^ expected \`u32\`, found \`&str\``;
|
|
8
|
-
|
|
9
|
-
export const rustBorrowError = `error[E0502]: cannot borrow \`v\` as mutable because it is also borrowed as immutable
|
|
10
|
-
--> src/main.rs:6:5
|
|
11
|
-
|
|
|
12
|
-
4 | let first = &v[0];
|
|
13
|
-
| - immutable borrow occurs here
|
|
14
|
-
5 |
|
|
15
|
-
6 | v.push(4);
|
|
16
|
-
| ^^^^^^^^^ mutable borrow occurs here
|
|
17
|
-
7 |
|
|
18
|
-
8 | println!("{}", first);
|
|
19
|
-
| ----- immutable borrow later used here`;
|
|
20
|
-
|
|
21
|
-
export const rustLifetimeError = `error[E0106]: missing lifetime specifier
|
|
22
|
-
--> src/lib.rs:5:16
|
|
23
|
-
|
|
|
24
|
-
5 | fn longest(x: &str, y: &str) -> &str {
|
|
25
|
-
| ---- ---- ^ expected named lifetime parameter`;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const shellCommandNotFound = `bash: docker-compose: command not found`;
|
|
2
|
-
|
|
3
|
-
export const shellPermissionDenied = `bash: ./deploy.sh: Permission denied`;
|
|
4
|
-
|
|
5
|
-
export const npmError = `npm ERR! code ERESOLVE
|
|
6
|
-
npm ERR! ERESOLVE unable to resolve dependency tree
|
|
7
|
-
npm ERR!
|
|
8
|
-
npm ERR! While resolving: my-app@1.0.0
|
|
9
|
-
npm ERR! Found: react@18.2.0
|
|
10
|
-
npm ERR! node_modules/react
|
|
11
|
-
npm ERR! react@"^18.2.0" from the root project`;
|
|
12
|
-
|
|
13
|
-
export const buildFailed = `BUILD FAILED in 2.3s
|
|
14
|
-
Error: Module build failed (from ./node_modules/ts-loader/index.js):
|
|
15
|
-
Error: TypeScript compilation failed`;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const solutionFixtures = [
|
|
2
|
-
{
|
|
3
|
-
description: 'Add null check before accessing .map() on potentially undefined array',
|
|
4
|
-
commands: '',
|
|
5
|
-
codeChange: 'const items = data?.items ?? [];\nconst mapped = items.map(fn);',
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
description: 'Install missing module with npm install',
|
|
9
|
-
commands: 'npm install flask',
|
|
10
|
-
codeChange: '',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
description: 'Fix type mismatch by converting string to number',
|
|
14
|
-
commands: '',
|
|
15
|
-
codeChange: 'return parseInt(value, 10);',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
description: 'Add missing lifetime annotation to function signature',
|
|
19
|
-
commands: '',
|
|
20
|
-
codeChange: "fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {",
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
description: 'Grant execute permission to script',
|
|
24
|
-
commands: 'chmod +x deploy.sh',
|
|
25
|
-
codeChange: '',
|
|
26
|
-
},
|
|
27
|
-
];
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import Database from 'better-sqlite3';
|
|
2
|
-
import { runMigrations } from '../../src/db/migrations/index.js';
|
|
3
|
-
import { ProjectRepository } from '../../src/db/repositories/project.repository.js';
|
|
4
|
-
import { ErrorRepository } from '../../src/db/repositories/error.repository.js';
|
|
5
|
-
import { SolutionRepository } from '../../src/db/repositories/solution.repository.js';
|
|
6
|
-
import { RuleRepository } from '../../src/db/repositories/rule.repository.js';
|
|
7
|
-
import { AntipatternRepository } from '../../src/db/repositories/antipattern.repository.js';
|
|
8
|
-
import { TerminalRepository } from '../../src/db/repositories/terminal.repository.js';
|
|
9
|
-
import { CodeModuleRepository } from '../../src/db/repositories/code-module.repository.js';
|
|
10
|
-
import { SynapseRepository } from '../../src/db/repositories/synapse.repository.js';
|
|
11
|
-
import { NotificationRepository } from '../../src/db/repositories/notification.repository.js';
|
|
12
|
-
import { InsightRepository } from '../../src/db/repositories/insight.repository.js';
|
|
13
|
-
|
|
14
|
-
export interface TestDb {
|
|
15
|
-
db: Database.Database;
|
|
16
|
-
repos: {
|
|
17
|
-
project: ProjectRepository;
|
|
18
|
-
error: ErrorRepository;
|
|
19
|
-
solution: SolutionRepository;
|
|
20
|
-
rule: RuleRepository;
|
|
21
|
-
antipattern: AntipatternRepository;
|
|
22
|
-
terminal: TerminalRepository;
|
|
23
|
-
codeModule: CodeModuleRepository;
|
|
24
|
-
synapse: SynapseRepository;
|
|
25
|
-
notification: NotificationRepository;
|
|
26
|
-
insight: InsightRepository;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function createTestDb(): TestDb {
|
|
31
|
-
const db = new Database(':memory:');
|
|
32
|
-
db.pragma('journal_mode = WAL');
|
|
33
|
-
db.pragma('foreign_keys = ON');
|
|
34
|
-
|
|
35
|
-
runMigrations(db);
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
db,
|
|
39
|
-
repos: {
|
|
40
|
-
project: new ProjectRepository(db),
|
|
41
|
-
error: new ErrorRepository(db),
|
|
42
|
-
solution: new SolutionRepository(db),
|
|
43
|
-
rule: new RuleRepository(db),
|
|
44
|
-
antipattern: new AntipatternRepository(db),
|
|
45
|
-
terminal: new TerminalRepository(db),
|
|
46
|
-
codeModule: new CodeModuleRepository(db),
|
|
47
|
-
synapse: new SynapseRepository(db),
|
|
48
|
-
notification: new NotificationRepository(db),
|
|
49
|
-
insight: new InsightRepository(db),
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { createTestDb, type TestDb } from '../helpers/setup-db.js';
|
|
3
|
-
import { CodeService } from '../../src/services/code.service.js';
|
|
4
|
-
import { SynapseManager } from '../../src/synapses/synapse-manager.js';
|
|
5
|
-
import { retryModule, hashModule } from '../fixtures/code-modules/modules.js';
|
|
6
|
-
|
|
7
|
-
const synapsesConfig = {
|
|
8
|
-
initialWeight: 0.1,
|
|
9
|
-
learningRate: 0.15,
|
|
10
|
-
decayHalfLifeDays: 45,
|
|
11
|
-
pruneThreshold: 0.05,
|
|
12
|
-
decayAfterDays: 14,
|
|
13
|
-
maxDepth: 3,
|
|
14
|
-
minActivationWeight: 0.2,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
describe('Code Flow Integration', () => {
|
|
18
|
-
let testDb: TestDb;
|
|
19
|
-
let codeService: CodeService;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
testDb = createTestDb();
|
|
23
|
-
const synapseManager = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
24
|
-
codeService = new CodeService(testDb.repos.codeModule, testDb.repos.project, synapseManager);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('registers a code module and retrieves it', () => {
|
|
28
|
-
const result = codeService.analyzeAndRegister({
|
|
29
|
-
project: 'utils-lib',
|
|
30
|
-
name: retryModule.name,
|
|
31
|
-
filePath: retryModule.filePath,
|
|
32
|
-
language: retryModule.language,
|
|
33
|
-
source: retryModule.source,
|
|
34
|
-
description: retryModule.description,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
expect(result.moduleId).toBeTruthy();
|
|
38
|
-
expect(result.isNew).toBe(true);
|
|
39
|
-
expect(result.reusabilityScore).toBeGreaterThan(0);
|
|
40
|
-
|
|
41
|
-
const mod = codeService.getById(result.moduleId);
|
|
42
|
-
expect(mod).toBeTruthy();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('finds reusable modules by query', () => {
|
|
46
|
-
codeService.analyzeAndRegister({
|
|
47
|
-
project: 'utils-lib',
|
|
48
|
-
name: retryModule.name,
|
|
49
|
-
filePath: retryModule.filePath,
|
|
50
|
-
language: retryModule.language,
|
|
51
|
-
source: retryModule.source,
|
|
52
|
-
description: retryModule.description,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const results = codeService.findReusable({ query: 'retry backoff' });
|
|
56
|
-
// FTS matching may or may not find results
|
|
57
|
-
expect(results).toBeDefined();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('lists all modules', () => {
|
|
61
|
-
codeService.analyzeAndRegister({
|
|
62
|
-
project: 'project-a',
|
|
63
|
-
name: retryModule.name,
|
|
64
|
-
filePath: retryModule.filePath,
|
|
65
|
-
language: retryModule.language,
|
|
66
|
-
source: retryModule.source,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// listModules requires a projectId — project is created with id=1 by analyzeAndRegister
|
|
70
|
-
const modules = codeService.listModules(1);
|
|
71
|
-
expect(modules.length).toBe(1);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('detects similar code', () => {
|
|
75
|
-
codeService.analyzeAndRegister({
|
|
76
|
-
project: 'project-a',
|
|
77
|
-
name: retryModule.name,
|
|
78
|
-
filePath: retryModule.filePath,
|
|
79
|
-
language: retryModule.language,
|
|
80
|
-
source: retryModule.source,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const similarities = codeService.checkSimilarity(retryModule.source, 'typescript');
|
|
84
|
-
expect(similarities).toBeDefined();
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { createTestDb, type TestDb } from '../helpers/setup-db.js';
|
|
3
|
-
import { ErrorService } from '../../src/services/error.service.js';
|
|
4
|
-
import { SolutionService } from '../../src/services/solution.service.js';
|
|
5
|
-
import { SynapseManager } from '../../src/synapses/synapse-manager.js';
|
|
6
|
-
|
|
7
|
-
const synapsesConfig = {
|
|
8
|
-
initialWeight: 0.1,
|
|
9
|
-
learningRate: 0.15,
|
|
10
|
-
decayHalfLifeDays: 45,
|
|
11
|
-
pruneThreshold: 0.05,
|
|
12
|
-
decayAfterDays: 14,
|
|
13
|
-
maxDepth: 3,
|
|
14
|
-
minActivationWeight: 0.2,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
describe('Error Flow Integration', () => {
|
|
18
|
-
let testDb: TestDb;
|
|
19
|
-
let errorService: ErrorService;
|
|
20
|
-
let solutionService: SolutionService;
|
|
21
|
-
let synapseManager: SynapseManager;
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
testDb = createTestDb();
|
|
25
|
-
synapseManager = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
26
|
-
errorService = new ErrorService(testDb.repos.error, testDb.repos.project, synapseManager);
|
|
27
|
-
solutionService = new SolutionService(testDb.repos.solution, synapseManager);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('reports error and queries it back', () => {
|
|
31
|
-
const result = errorService.report({
|
|
32
|
-
project: 'test-project',
|
|
33
|
-
errorOutput: "TypeError: Cannot read properties of undefined (reading 'map')",
|
|
34
|
-
});
|
|
35
|
-
expect(result.errorId).toBeTruthy();
|
|
36
|
-
expect(result.isNew).toBe(true);
|
|
37
|
-
|
|
38
|
-
const errors = errorService.query({ resolved: false });
|
|
39
|
-
expect(errors.length).toBe(1);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('adds and finds solutions for errors', () => {
|
|
43
|
-
const errResult = errorService.report({
|
|
44
|
-
project: 'test-project',
|
|
45
|
-
errorOutput: "TypeError: Cannot read properties of undefined",
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const solutionId = solutionService.report({
|
|
49
|
-
errorId: errResult.errorId,
|
|
50
|
-
description: 'Add null check before accessing .map()',
|
|
51
|
-
});
|
|
52
|
-
expect(solutionId).toBeTruthy();
|
|
53
|
-
|
|
54
|
-
const solutions = solutionService.findForError(errResult.errorId);
|
|
55
|
-
expect(solutions.length).toBeGreaterThanOrEqual(0); // may need error_solution join
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('matches similar errors', () => {
|
|
59
|
-
const first = errorService.report({
|
|
60
|
-
project: 'project-a',
|
|
61
|
-
errorOutput: "TypeError: Cannot read properties of undefined (reading 'map')",
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const second = errorService.report({
|
|
65
|
-
project: 'project-a',
|
|
66
|
-
errorOutput: "TypeError: Cannot read properties of undefined (reading 'filter')",
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const matches = errorService.matchSimilar(second.errorId);
|
|
70
|
-
expect(matches).toBeDefined();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('creates project on first error report', () => {
|
|
74
|
-
errorService.report({
|
|
75
|
-
project: 'new-project',
|
|
76
|
-
errorOutput: 'Error: something broke',
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const projects = testDb.repos.project.getAll();
|
|
80
|
-
expect(projects.length).toBe(1);
|
|
81
|
-
expect(projects[0].name).toBe('new-project');
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
-
import { encodeMessage, MessageDecoder } from '../../src/ipc/protocol.js';
|
|
3
|
-
import type { IpcMessage } from '../../src/types/ipc.types.js';
|
|
4
|
-
|
|
5
|
-
describe('IPC Protocol', () => {
|
|
6
|
-
it('round-trips a request message', () => {
|
|
7
|
-
const msg: IpcMessage = {
|
|
8
|
-
id: 'test-123',
|
|
9
|
-
type: 'request',
|
|
10
|
-
method: 'error.report',
|
|
11
|
-
params: { project: 'test', errorOutput: 'Error: something' },
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const encoded = encodeMessage(msg);
|
|
15
|
-
const decoder = new MessageDecoder();
|
|
16
|
-
const decoded = decoder.feed(encoded);
|
|
17
|
-
|
|
18
|
-
expect(decoded.length).toBe(1);
|
|
19
|
-
expect(decoded[0].id).toBe('test-123');
|
|
20
|
-
expect(decoded[0].type).toBe('request');
|
|
21
|
-
expect(decoded[0].method).toBe('error.report');
|
|
22
|
-
expect(decoded[0].params).toEqual(msg.params);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('round-trips a response message', () => {
|
|
26
|
-
const msg: IpcMessage = {
|
|
27
|
-
id: 'test-456',
|
|
28
|
-
type: 'response',
|
|
29
|
-
result: { errorId: 42, isNew: true },
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const encoded = encodeMessage(msg);
|
|
33
|
-
const decoder = new MessageDecoder();
|
|
34
|
-
const decoded = decoder.feed(encoded);
|
|
35
|
-
|
|
36
|
-
expect(decoded.length).toBe(1);
|
|
37
|
-
expect(decoded[0].result).toEqual({ errorId: 42, isNew: true });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('round-trips an error response', () => {
|
|
41
|
-
const msg: IpcMessage = {
|
|
42
|
-
id: 'test-789',
|
|
43
|
-
type: 'response',
|
|
44
|
-
error: { code: -1, message: 'Unknown method' },
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const encoded = encodeMessage(msg);
|
|
48
|
-
const decoder = new MessageDecoder();
|
|
49
|
-
const decoded = decoder.feed(encoded);
|
|
50
|
-
|
|
51
|
-
expect(decoded[0].error?.code).toBe(-1);
|
|
52
|
-
expect(decoded[0].error?.message).toBe('Unknown method');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('handles multiple messages in one feed', () => {
|
|
56
|
-
const msg1: IpcMessage = { id: '1', type: 'request', method: 'a' };
|
|
57
|
-
const msg2: IpcMessage = { id: '2', type: 'request', method: 'b' };
|
|
58
|
-
|
|
59
|
-
const buf = Buffer.concat([encodeMessage(msg1), encodeMessage(msg2)]);
|
|
60
|
-
const decoder = new MessageDecoder();
|
|
61
|
-
const decoded = decoder.feed(buf);
|
|
62
|
-
|
|
63
|
-
expect(decoded.length).toBe(2);
|
|
64
|
-
expect(decoded[0].id).toBe('1');
|
|
65
|
-
expect(decoded[1].id).toBe('2');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('handles partial messages across feeds', () => {
|
|
69
|
-
const msg: IpcMessage = { id: 'partial', type: 'request', method: 'test' };
|
|
70
|
-
const encoded = encodeMessage(msg);
|
|
71
|
-
|
|
72
|
-
const decoder = new MessageDecoder();
|
|
73
|
-
// Split buffer in half
|
|
74
|
-
const mid = Math.floor(encoded.length / 2);
|
|
75
|
-
const part1 = encoded.subarray(0, mid);
|
|
76
|
-
const part2 = encoded.subarray(mid);
|
|
77
|
-
|
|
78
|
-
const decoded1 = decoder.feed(part1);
|
|
79
|
-
expect(decoded1.length).toBe(0); // incomplete
|
|
80
|
-
|
|
81
|
-
const decoded2 = decoder.feed(part2);
|
|
82
|
-
expect(decoded2.length).toBe(1);
|
|
83
|
-
expect(decoded2[0].id).toBe('partial');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('decoder reset clears buffer', () => {
|
|
87
|
-
const msg: IpcMessage = { id: 'x', type: 'request', method: 'y' };
|
|
88
|
-
const encoded = encodeMessage(msg);
|
|
89
|
-
const partial = encoded.subarray(0, 5);
|
|
90
|
-
|
|
91
|
-
const decoder = new MessageDecoder();
|
|
92
|
-
decoder.feed(partial);
|
|
93
|
-
decoder.reset();
|
|
94
|
-
|
|
95
|
-
// After reset, feeding a complete message should work
|
|
96
|
-
const decoded = decoder.feed(encodeMessage(msg));
|
|
97
|
-
expect(decoded.length).toBe(1);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('IPC Router', () => {
|
|
102
|
-
it('routes methods to services', async () => {
|
|
103
|
-
const { createTestDb } = await import('../helpers/setup-db.js');
|
|
104
|
-
const { IpcRouter } = await import('../../src/ipc/router.js');
|
|
105
|
-
const { ErrorService } = await import('../../src/services/error.service.js');
|
|
106
|
-
const { SolutionService } = await import('../../src/services/solution.service.js');
|
|
107
|
-
const { TerminalService } = await import('../../src/services/terminal.service.js');
|
|
108
|
-
const { PreventionService } = await import('../../src/services/prevention.service.js');
|
|
109
|
-
const { CodeService } = await import('../../src/services/code.service.js');
|
|
110
|
-
const { SynapseService } = await import('../../src/services/synapse.service.js');
|
|
111
|
-
const { ResearchService } = await import('../../src/services/research.service.js');
|
|
112
|
-
const { NotificationService } = await import('../../src/services/notification.service.js');
|
|
113
|
-
const { AnalyticsService } = await import('../../src/services/analytics.service.js');
|
|
114
|
-
const { SynapseManager } = await import('../../src/synapses/synapse-manager.js');
|
|
115
|
-
|
|
116
|
-
const testDb = createTestDb();
|
|
117
|
-
const synapsesConfig = {
|
|
118
|
-
initialWeight: 0.1, learningRate: 0.15, decayHalfLifeDays: 45,
|
|
119
|
-
pruneThreshold: 0.05, decayAfterDays: 14, maxDepth: 3, minActivationWeight: 0.2,
|
|
120
|
-
};
|
|
121
|
-
const sm = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
122
|
-
|
|
123
|
-
const services = {
|
|
124
|
-
error: new ErrorService(testDb.repos.error, testDb.repos.project, sm),
|
|
125
|
-
solution: new SolutionService(testDb.repos.solution, sm),
|
|
126
|
-
terminal: new TerminalService(testDb.repos.terminal, 300000),
|
|
127
|
-
prevention: new PreventionService(testDb.repos.rule, testDb.repos.antipattern, sm),
|
|
128
|
-
code: new CodeService(testDb.repos.codeModule, testDb.repos.project, sm),
|
|
129
|
-
synapse: new SynapseService(sm),
|
|
130
|
-
research: new ResearchService(testDb.repos.insight, testDb.repos.error, sm),
|
|
131
|
-
notification: new NotificationService(testDb.repos.notification),
|
|
132
|
-
analytics: new AnalyticsService(
|
|
133
|
-
testDb.repos.error, testDb.repos.solution, testDb.repos.codeModule,
|
|
134
|
-
testDb.repos.rule, testDb.repos.antipattern, testDb.repos.insight, sm,
|
|
135
|
-
),
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const router = new IpcRouter(services);
|
|
139
|
-
|
|
140
|
-
// Test analytics.summary
|
|
141
|
-
const summary = router.handle('analytics.summary', {});
|
|
142
|
-
expect(summary).toBeTruthy();
|
|
143
|
-
|
|
144
|
-
// Test synapse.stats
|
|
145
|
-
const stats = router.handle('synapse.stats', {});
|
|
146
|
-
expect(stats).toBeTruthy();
|
|
147
|
-
|
|
148
|
-
// Test error.report
|
|
149
|
-
const result = router.handle('error.report', {
|
|
150
|
-
project: 'test',
|
|
151
|
-
errorOutput: 'Error: test error',
|
|
152
|
-
}) as any;
|
|
153
|
-
expect(result.errorId).toBeTruthy();
|
|
154
|
-
|
|
155
|
-
// Test unknown method throws
|
|
156
|
-
expect(() => router.handle('nonexistent.method', {})).toThrow('Unknown method');
|
|
157
|
-
|
|
158
|
-
// Test listMethods
|
|
159
|
-
const methods = router.listMethods();
|
|
160
|
-
expect(methods.length).toBeGreaterThan(20);
|
|
161
|
-
expect(methods).toContain('error.report');
|
|
162
|
-
expect(methods).toContain('analytics.summary');
|
|
163
|
-
|
|
164
|
-
testDb.db.close();
|
|
165
|
-
});
|
|
166
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { createTestDb, type TestDb } from '../helpers/setup-db.js';
|
|
3
|
-
import { LearningEngine } from '../../src/learning/learning-engine.js';
|
|
4
|
-
import { SynapseManager } from '../../src/synapses/synapse-manager.js';
|
|
5
|
-
|
|
6
|
-
const learningConfig = {
|
|
7
|
-
intervalMs: 900000,
|
|
8
|
-
minOccurrences: 3,
|
|
9
|
-
minSuccessRate: 0.7,
|
|
10
|
-
minConfidence: 0.6,
|
|
11
|
-
pruneThreshold: 0.2,
|
|
12
|
-
maxRejectionRate: 0.5,
|
|
13
|
-
decayHalfLifeDays: 30,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const synapsesConfig = {
|
|
17
|
-
initialWeight: 0.1,
|
|
18
|
-
learningRate: 0.15,
|
|
19
|
-
decayHalfLifeDays: 45,
|
|
20
|
-
pruneThreshold: 0.05,
|
|
21
|
-
decayAfterDays: 14,
|
|
22
|
-
maxDepth: 3,
|
|
23
|
-
minActivationWeight: 0.2,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
describe('Learning Cycle Integration', () => {
|
|
27
|
-
let testDb: TestDb;
|
|
28
|
-
let learningEngine: LearningEngine;
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
testDb = createTestDb();
|
|
32
|
-
const synapseManager = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
33
|
-
|
|
34
|
-
learningEngine = new LearningEngine(
|
|
35
|
-
learningConfig,
|
|
36
|
-
testDb.repos.error,
|
|
37
|
-
testDb.repos.solution,
|
|
38
|
-
testDb.repos.rule,
|
|
39
|
-
testDb.repos.antipattern,
|
|
40
|
-
synapseManager,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
// Seed data
|
|
44
|
-
testDb.repos.project.create({ name: 'test', path: '/test' } as any);
|
|
45
|
-
for (let i = 0; i < 5; i++) {
|
|
46
|
-
testDb.repos.error.create({
|
|
47
|
-
project_id: 1,
|
|
48
|
-
terminal_id: null,
|
|
49
|
-
type: 'TypeError',
|
|
50
|
-
message: "Cannot read properties of undefined (reading 'map')",
|
|
51
|
-
fingerprint: 'fp_type_error',
|
|
52
|
-
raw_output: `TypeError: Cannot read properties of undefined`,
|
|
53
|
-
context: null,
|
|
54
|
-
file_path: null,
|
|
55
|
-
line_number: null,
|
|
56
|
-
column_number: null,
|
|
57
|
-
} as any);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('runs a learning cycle without error', () => {
|
|
62
|
-
const result = learningEngine.runCycle();
|
|
63
|
-
expect(result).toBeTruthy();
|
|
64
|
-
expect(typeof result.newPatterns).toBe('number');
|
|
65
|
-
expect(typeof result.updatedRules).toBe('number');
|
|
66
|
-
expect(typeof result.prunedRules).toBe('number');
|
|
67
|
-
expect(typeof result.duration).toBe('number');
|
|
68
|
-
expect(result.duration).toBeGreaterThan(0);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('tracks last cycle time', () => {
|
|
72
|
-
expect(learningEngine.getLastCycleAt()).toBeNull();
|
|
73
|
-
learningEngine.runCycle();
|
|
74
|
-
expect(learningEngine.getLastCycleAt()).toBeTruthy();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('start/stop controls scheduling', () => {
|
|
78
|
-
learningEngine.start();
|
|
79
|
-
learningEngine.stop();
|
|
80
|
-
// Should not throw
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { createTestDb, type TestDb } from '../helpers/setup-db.js';
|
|
3
|
-
import { SynapseManager } from '../../src/synapses/synapse-manager.js';
|
|
4
|
-
import { SynapseService } from '../../src/services/synapse.service.js';
|
|
5
|
-
|
|
6
|
-
const synapsesConfig = {
|
|
7
|
-
initialWeight: 0.1,
|
|
8
|
-
learningRate: 0.15,
|
|
9
|
-
decayHalfLifeDays: 45,
|
|
10
|
-
pruneThreshold: 0.05,
|
|
11
|
-
decayAfterDays: 14,
|
|
12
|
-
maxDepth: 3,
|
|
13
|
-
minActivationWeight: 0.2,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
describe('Synapse Flow Integration', () => {
|
|
17
|
-
let testDb: TestDb;
|
|
18
|
-
let synapseManager: SynapseManager;
|
|
19
|
-
let synapseService: SynapseService;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
testDb = createTestDb();
|
|
23
|
-
synapseManager = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
24
|
-
synapseService = new SynapseService(synapseManager);
|
|
25
|
-
|
|
26
|
-
// Create test data
|
|
27
|
-
testDb.repos.project.create({ name: 'test', path: '/test' } as any);
|
|
28
|
-
testDb.repos.error.create({
|
|
29
|
-
project_id: 1, terminal_id: null, fingerprint: 'fp1', type: 'TypeError',
|
|
30
|
-
message: 'error 1', raw_output: 'TypeError: 1', context: null,
|
|
31
|
-
file_path: null, line_number: null, column_number: null,
|
|
32
|
-
} as any);
|
|
33
|
-
testDb.repos.error.create({
|
|
34
|
-
project_id: 1, terminal_id: null, fingerprint: 'fp2', type: 'TypeError',
|
|
35
|
-
message: 'error 2', raw_output: 'TypeError: 2', context: null,
|
|
36
|
-
file_path: null, line_number: null, column_number: null,
|
|
37
|
-
} as any);
|
|
38
|
-
testDb.repos.error.create({
|
|
39
|
-
project_id: 1, terminal_id: null, fingerprint: 'fp3', type: 'TypeError',
|
|
40
|
-
message: 'error 3', raw_output: 'TypeError: 3', context: null,
|
|
41
|
-
file_path: null, line_number: null, column_number: null,
|
|
42
|
-
} as any);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('builds and queries a synapse network', () => {
|
|
46
|
-
synapseManager.strengthen(
|
|
47
|
-
{ type: 'error', id: 1 },
|
|
48
|
-
{ type: 'error', id: 2 },
|
|
49
|
-
'similar_to',
|
|
50
|
-
);
|
|
51
|
-
synapseManager.strengthen(
|
|
52
|
-
{ type: 'error', id: 1 },
|
|
53
|
-
{ type: 'project', id: 1 },
|
|
54
|
-
'co_occurs',
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const stats = synapseService.getNetworkStats();
|
|
58
|
-
expect(stats.totalSynapses).toBe(2);
|
|
59
|
-
|
|
60
|
-
const strongest = synapseService.getStrongestSynapses(10);
|
|
61
|
-
expect(strongest.length).toBe(2);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('strengthening same synapse increases weight', () => {
|
|
65
|
-
const first = synapseManager.strengthen(
|
|
66
|
-
{ type: 'error', id: 1 },
|
|
67
|
-
{ type: 'error', id: 2 },
|
|
68
|
-
'similar_to',
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const second = synapseManager.strengthen(
|
|
72
|
-
{ type: 'error', id: 1 },
|
|
73
|
-
{ type: 'error', id: 2 },
|
|
74
|
-
'similar_to',
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
expect(second.weight).toBeGreaterThan(first.weight);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('finds path between connected nodes', () => {
|
|
81
|
-
synapseManager.strengthen(
|
|
82
|
-
{ type: 'error', id: 1 },
|
|
83
|
-
{ type: 'error', id: 2 },
|
|
84
|
-
'similar_to',
|
|
85
|
-
);
|
|
86
|
-
synapseManager.strengthen(
|
|
87
|
-
{ type: 'error', id: 2 },
|
|
88
|
-
{ type: 'error', id: 3 },
|
|
89
|
-
'similar_to',
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const path = synapseService.findPath('error', 1, 'error', 3);
|
|
93
|
-
expect(path).not.toBeNull();
|
|
94
|
-
expect(path!.hops).toBe(2);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('returns null for unconnected nodes', () => {
|
|
98
|
-
const path = synapseService.findPath('error', 1, 'error', 3);
|
|
99
|
-
expect(path).toBeNull();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('decay reduces old synapse weights', () => {
|
|
103
|
-
synapseManager.strengthen(
|
|
104
|
-
{ type: 'error', id: 1 },
|
|
105
|
-
{ type: 'error', id: 2 },
|
|
106
|
-
'similar_to',
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
// Make synapse old
|
|
110
|
-
testDb.db.prepare(
|
|
111
|
-
`UPDATE synapses SET last_activated_at = datetime('now', '-100 days')`
|
|
112
|
-
).run();
|
|
113
|
-
|
|
114
|
-
const { decayed, pruned } = synapseManager.runDecay();
|
|
115
|
-
expect(decayed + pruned).toBeGreaterThanOrEqual(0);
|
|
116
|
-
});
|
|
117
|
-
});
|