@jamesaphoenix/tx-test-utils 0.4.2
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/dist/database/index.d.ts +8 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +7 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/test-database.d.ts +101 -0
- package/dist/database/test-database.d.ts.map +1 -0
- package/dist/database/test-database.js +130 -0
- package/dist/database/test-database.js.map +1 -0
- package/dist/factories/anchor.factory.d.ts +117 -0
- package/dist/factories/anchor.factory.d.ts.map +1 -0
- package/dist/factories/anchor.factory.js +201 -0
- package/dist/factories/anchor.factory.js.map +1 -0
- package/dist/factories/candidate.factory.d.ts +151 -0
- package/dist/factories/candidate.factory.d.ts.map +1 -0
- package/dist/factories/candidate.factory.js +194 -0
- package/dist/factories/candidate.factory.js.map +1 -0
- package/dist/factories/edge.factory.d.ts +119 -0
- package/dist/factories/edge.factory.d.ts.map +1 -0
- package/dist/factories/edge.factory.js +191 -0
- package/dist/factories/edge.factory.js.map +1 -0
- package/dist/factories/factories.test.d.ts +8 -0
- package/dist/factories/factories.test.d.ts.map +1 -0
- package/dist/factories/factories.test.js +419 -0
- package/dist/factories/factories.test.js.map +1 -0
- package/dist/factories/index.d.ts +15 -0
- package/dist/factories/index.d.ts.map +1 -0
- package/dist/factories/index.js +21 -0
- package/dist/factories/index.js.map +1 -0
- package/dist/factories/learning.factory.d.ts +107 -0
- package/dist/factories/learning.factory.d.ts.map +1 -0
- package/dist/factories/learning.factory.js +150 -0
- package/dist/factories/learning.factory.js.map +1 -0
- package/dist/factories/task.factory.d.ts +106 -0
- package/dist/factories/task.factory.d.ts.map +1 -0
- package/dist/factories/task.factory.js +151 -0
- package/dist/factories/task.factory.js.map +1 -0
- package/dist/fixtures/index.d.ts +36 -0
- package/dist/fixtures/index.d.ts.map +1 -0
- package/dist/fixtures/index.js +47 -0
- package/dist/fixtures/index.js.map +1 -0
- package/dist/helpers/effect.d.ts +186 -0
- package/dist/helpers/effect.d.ts.map +1 -0
- package/dist/helpers/effect.js +298 -0
- package/dist/helpers/effect.js.map +1 -0
- package/dist/helpers/effect.test.d.ts +7 -0
- package/dist/helpers/effect.test.d.ts.map +1 -0
- package/dist/helpers/effect.test.js +271 -0
- package/dist/helpers/effect.test.js.map +1 -0
- package/dist/helpers/index.d.ts +7 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +11 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-cache/cache.d.ts +152 -0
- package/dist/llm-cache/cache.d.ts.map +1 -0
- package/dist/llm-cache/cache.js +199 -0
- package/dist/llm-cache/cache.js.map +1 -0
- package/dist/llm-cache/cache.test.d.ts +7 -0
- package/dist/llm-cache/cache.test.d.ts.map +1 -0
- package/dist/llm-cache/cache.test.js +310 -0
- package/dist/llm-cache/cache.test.js.map +1 -0
- package/dist/llm-cache/cli.d.ts +113 -0
- package/dist/llm-cache/cli.d.ts.map +1 -0
- package/dist/llm-cache/cli.js +248 -0
- package/dist/llm-cache/cli.js.map +1 -0
- package/dist/llm-cache/index.d.ts +31 -0
- package/dist/llm-cache/index.d.ts.map +1 -0
- package/dist/llm-cache/index.js +31 -0
- package/dist/llm-cache/index.js.map +1 -0
- package/dist/mocks/anthropic.mock.d.ts +173 -0
- package/dist/mocks/anthropic.mock.d.ts.map +1 -0
- package/dist/mocks/anthropic.mock.js +125 -0
- package/dist/mocks/anthropic.mock.js.map +1 -0
- package/dist/mocks/ast-grep.mock.d.ts +216 -0
- package/dist/mocks/ast-grep.mock.d.ts.map +1 -0
- package/dist/mocks/ast-grep.mock.js +164 -0
- package/dist/mocks/ast-grep.mock.js.map +1 -0
- package/dist/mocks/file-system.mock.d.ts +181 -0
- package/dist/mocks/file-system.mock.d.ts.map +1 -0
- package/dist/mocks/file-system.mock.js +280 -0
- package/dist/mocks/file-system.mock.js.map +1 -0
- package/dist/mocks/index.d.ts +10 -0
- package/dist/mocks/index.d.ts.map +1 -0
- package/dist/mocks/index.js +16 -0
- package/dist/mocks/index.js.map +1 -0
- package/dist/mocks/mocks.test.d.ts +10 -0
- package/dist/mocks/mocks.test.d.ts.map +1 -0
- package/dist/mocks/mocks.test.js +961 -0
- package/dist/mocks/mocks.test.js.map +1 -0
- package/dist/mocks/openai.mock.d.ts +205 -0
- package/dist/mocks/openai.mock.d.ts.map +1 -0
- package/dist/mocks/openai.mock.js +178 -0
- package/dist/mocks/openai.mock.js.map +1 -0
- package/dist/setup/index.d.ts +7 -0
- package/dist/setup/index.d.ts.map +1 -0
- package/dist/setup/index.js +9 -0
- package/dist/setup/index.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Candidate factory for creating test learning candidate data.
|
|
3
|
+
*
|
|
4
|
+
* Learning candidates are potential learnings extracted from transcripts
|
|
5
|
+
* that await promotion to the learnings table.
|
|
6
|
+
*
|
|
7
|
+
* @module @tx/test-utils/factories/candidate
|
|
8
|
+
*/
|
|
9
|
+
import type { TestDatabase } from "../database/index.js";
|
|
10
|
+
/**
|
|
11
|
+
* Confidence level for a learning candidate.
|
|
12
|
+
*/
|
|
13
|
+
export type CandidateConfidence = "high" | "medium" | "low";
|
|
14
|
+
/**
|
|
15
|
+
* Status of a learning candidate.
|
|
16
|
+
*/
|
|
17
|
+
export type CandidateStatus = "pending" | "promoted" | "rejected" | "merged";
|
|
18
|
+
/**
|
|
19
|
+
* Learning candidate entity.
|
|
20
|
+
* Represents a potential learning extracted from a transcript.
|
|
21
|
+
*/
|
|
22
|
+
export interface LearningCandidate {
|
|
23
|
+
readonly id: number;
|
|
24
|
+
readonly content: string;
|
|
25
|
+
readonly confidence: CandidateConfidence;
|
|
26
|
+
readonly category: string | null;
|
|
27
|
+
readonly sourceFile: string;
|
|
28
|
+
readonly sourceRunId: string | null;
|
|
29
|
+
readonly sourceTaskId: string | null;
|
|
30
|
+
readonly extractedAt: Date;
|
|
31
|
+
readonly status: CandidateStatus;
|
|
32
|
+
readonly reviewedAt: Date | null;
|
|
33
|
+
readonly reviewedBy: string | null;
|
|
34
|
+
readonly promotedLearningId: number | null;
|
|
35
|
+
readonly rejectionReason: string | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for creating a test learning candidate.
|
|
39
|
+
*/
|
|
40
|
+
export interface CreateCandidateOptions {
|
|
41
|
+
/** Candidate ID (auto-generated if not provided) */
|
|
42
|
+
id?: number;
|
|
43
|
+
/** The extracted learning content */
|
|
44
|
+
content?: string;
|
|
45
|
+
/** Confidence level (high, medium, low) */
|
|
46
|
+
confidence?: CandidateConfidence;
|
|
47
|
+
/** Category of the learning */
|
|
48
|
+
category?: string | null;
|
|
49
|
+
/** Source JSONL file path */
|
|
50
|
+
sourceFile?: string;
|
|
51
|
+
/** Source run ID */
|
|
52
|
+
sourceRunId?: string | null;
|
|
53
|
+
/** Source task ID */
|
|
54
|
+
sourceTaskId?: string | null;
|
|
55
|
+
/** Extraction timestamp */
|
|
56
|
+
extractedAt?: Date;
|
|
57
|
+
/** Candidate status */
|
|
58
|
+
status?: CandidateStatus;
|
|
59
|
+
/** Review timestamp */
|
|
60
|
+
reviewedAt?: Date | null;
|
|
61
|
+
/** Reviewer identifier ('auto' or user ID) */
|
|
62
|
+
reviewedBy?: string | null;
|
|
63
|
+
/** ID of the promoted learning (if promoted) */
|
|
64
|
+
promotedLearningId?: number | null;
|
|
65
|
+
/** Reason for rejection (if rejected) */
|
|
66
|
+
rejectionReason?: string | null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Factory class for creating test learning candidates.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
74
|
+
* const factory = new CandidateFactory(db)
|
|
75
|
+
*
|
|
76
|
+
* // Create high-confidence candidate (will be auto-promoted)
|
|
77
|
+
* const high = factory.highConfidence({ content: 'Always use Effect-TS' })
|
|
78
|
+
*
|
|
79
|
+
* // Create pending candidate for review
|
|
80
|
+
* const pending = factory.pending({ content: 'Consider using Effect-TS' })
|
|
81
|
+
*
|
|
82
|
+
* // Create promoted candidate
|
|
83
|
+
* const promoted = factory.promoted({ content: 'Use Effect-TS', promotedLearningId: 1 })
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare class CandidateFactory {
|
|
87
|
+
private counter;
|
|
88
|
+
private readonly db;
|
|
89
|
+
constructor(db: TestDatabase);
|
|
90
|
+
/**
|
|
91
|
+
* Create a single test learning candidate.
|
|
92
|
+
*/
|
|
93
|
+
create(options?: CreateCandidateOptions): LearningCandidate;
|
|
94
|
+
/**
|
|
95
|
+
* Create multiple test candidates.
|
|
96
|
+
*/
|
|
97
|
+
createMany(count: number, options?: CreateCandidateOptions): LearningCandidate[];
|
|
98
|
+
/**
|
|
99
|
+
* Create a high-confidence candidate (ready for auto-promotion).
|
|
100
|
+
*/
|
|
101
|
+
highConfidence(options?: CreateCandidateOptions): LearningCandidate;
|
|
102
|
+
/**
|
|
103
|
+
* Create a medium-confidence candidate (needs review).
|
|
104
|
+
*/
|
|
105
|
+
mediumConfidence(options?: CreateCandidateOptions): LearningCandidate;
|
|
106
|
+
/**
|
|
107
|
+
* Create a low-confidence candidate (needs review).
|
|
108
|
+
*/
|
|
109
|
+
lowConfidence(options?: CreateCandidateOptions): LearningCandidate;
|
|
110
|
+
/**
|
|
111
|
+
* Create a pending candidate awaiting review.
|
|
112
|
+
*/
|
|
113
|
+
pending(options?: CreateCandidateOptions): LearningCandidate;
|
|
114
|
+
/**
|
|
115
|
+
* Create a promoted candidate.
|
|
116
|
+
*/
|
|
117
|
+
promoted(options: CreateCandidateOptions & {
|
|
118
|
+
promotedLearningId: number;
|
|
119
|
+
}): LearningCandidate;
|
|
120
|
+
/**
|
|
121
|
+
* Create a rejected candidate.
|
|
122
|
+
*/
|
|
123
|
+
rejected(rejectionReason: string, options?: CreateCandidateOptions): LearningCandidate;
|
|
124
|
+
/**
|
|
125
|
+
* Create a merged candidate (merged with existing learning).
|
|
126
|
+
*/
|
|
127
|
+
merged(existingLearningId: number, options?: CreateCandidateOptions): LearningCandidate;
|
|
128
|
+
/**
|
|
129
|
+
* Create a candidate from a specific source.
|
|
130
|
+
*/
|
|
131
|
+
fromSource(sourceFile: string, sourceRunId?: string | null, sourceTaskId?: string | null, options?: CreateCandidateOptions): LearningCandidate;
|
|
132
|
+
/**
|
|
133
|
+
* Reset the internal counter.
|
|
134
|
+
*/
|
|
135
|
+
reset(): void;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create a single test learning candidate (convenience function).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
143
|
+
* const candidate = createTestCandidate(db, {
|
|
144
|
+
* content: 'Always validate user input',
|
|
145
|
+
* confidence: 'high',
|
|
146
|
+
* category: 'security'
|
|
147
|
+
* })
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare const createTestCandidate: (db: TestDatabase, options?: CreateCandidateOptions) => LearningCandidate;
|
|
151
|
+
//# sourceMappingURL=candidate.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidate.factory.d.ts","sourceRoot":"","sources":["../../src/factories/candidate.factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAA;AAE3D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAA;AAE5E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YAAY,GAAE,MAAM,GAAG,IAAW,EAClC,OAAO,GAAE,sBAA2B,GACnC,iBAAiB;IASpB;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,GAC9B,IAAI,YAAY,EAChB,UAAS,sBAA2B,KACnC,iBAGF,CAAA"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Candidate factory for creating test learning candidate data.
|
|
3
|
+
*
|
|
4
|
+
* Learning candidates are potential learnings extracted from transcripts
|
|
5
|
+
* that await promotion to the learnings table.
|
|
6
|
+
*
|
|
7
|
+
* @module @tx/test-utils/factories/candidate
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Factory class for creating test learning candidates.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
15
|
+
* const factory = new CandidateFactory(db)
|
|
16
|
+
*
|
|
17
|
+
* // Create high-confidence candidate (will be auto-promoted)
|
|
18
|
+
* const high = factory.highConfidence({ content: 'Always use Effect-TS' })
|
|
19
|
+
*
|
|
20
|
+
* // Create pending candidate for review
|
|
21
|
+
* const pending = factory.pending({ content: 'Consider using Effect-TS' })
|
|
22
|
+
*
|
|
23
|
+
* // Create promoted candidate
|
|
24
|
+
* const promoted = factory.promoted({ content: 'Use Effect-TS', promotedLearningId: 1 })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class CandidateFactory {
|
|
28
|
+
counter = 0;
|
|
29
|
+
db;
|
|
30
|
+
constructor(db) {
|
|
31
|
+
this.db = db;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a single test learning candidate.
|
|
35
|
+
*/
|
|
36
|
+
create(options = {}) {
|
|
37
|
+
this.counter++;
|
|
38
|
+
const now = new Date();
|
|
39
|
+
const id = options.id ?? this.counter;
|
|
40
|
+
const content = options.content ?? `Test candidate learning ${this.counter}`;
|
|
41
|
+
const confidence = options.confidence ?? "medium";
|
|
42
|
+
const category = options.category ?? null;
|
|
43
|
+
const sourceFile = options.sourceFile ?? `~/.claude/projects/test/session-${this.counter}.jsonl`;
|
|
44
|
+
const sourceRunId = options.sourceRunId ?? null;
|
|
45
|
+
const sourceTaskId = options.sourceTaskId ?? null;
|
|
46
|
+
const extractedAt = options.extractedAt ?? now;
|
|
47
|
+
const status = options.status ?? "pending";
|
|
48
|
+
const reviewedAt = options.reviewedAt ?? null;
|
|
49
|
+
const reviewedBy = options.reviewedBy ?? null;
|
|
50
|
+
const promotedLearningId = options.promotedLearningId ?? null;
|
|
51
|
+
const rejectionReason = options.rejectionReason ?? null;
|
|
52
|
+
this.db.run(`INSERT INTO learning_candidates (id, content, confidence, category, source_file, source_run_id, source_task_id, extracted_at, status, reviewed_at, reviewed_by, promoted_learning_id, rejection_reason)
|
|
53
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
54
|
+
id,
|
|
55
|
+
content,
|
|
56
|
+
confidence,
|
|
57
|
+
category,
|
|
58
|
+
sourceFile,
|
|
59
|
+
sourceRunId,
|
|
60
|
+
sourceTaskId,
|
|
61
|
+
extractedAt.toISOString(),
|
|
62
|
+
status,
|
|
63
|
+
reviewedAt ? reviewedAt.toISOString() : null,
|
|
64
|
+
reviewedBy,
|
|
65
|
+
promotedLearningId,
|
|
66
|
+
rejectionReason
|
|
67
|
+
]);
|
|
68
|
+
return {
|
|
69
|
+
id,
|
|
70
|
+
content,
|
|
71
|
+
confidence,
|
|
72
|
+
category,
|
|
73
|
+
sourceFile,
|
|
74
|
+
sourceRunId,
|
|
75
|
+
sourceTaskId,
|
|
76
|
+
extractedAt,
|
|
77
|
+
status,
|
|
78
|
+
reviewedAt,
|
|
79
|
+
reviewedBy,
|
|
80
|
+
promotedLearningId,
|
|
81
|
+
rejectionReason
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create multiple test candidates.
|
|
86
|
+
*/
|
|
87
|
+
createMany(count, options = {}) {
|
|
88
|
+
const candidates = [];
|
|
89
|
+
for (let i = 0; i < count; i++) {
|
|
90
|
+
candidates.push(this.create({
|
|
91
|
+
...options,
|
|
92
|
+
content: options.content ? `${options.content} ${i + 1}` : undefined
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
return candidates;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a high-confidence candidate (ready for auto-promotion).
|
|
99
|
+
*/
|
|
100
|
+
highConfidence(options = {}) {
|
|
101
|
+
return this.create({ ...options, confidence: "high" });
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a medium-confidence candidate (needs review).
|
|
105
|
+
*/
|
|
106
|
+
mediumConfidence(options = {}) {
|
|
107
|
+
return this.create({ ...options, confidence: "medium" });
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create a low-confidence candidate (needs review).
|
|
111
|
+
*/
|
|
112
|
+
lowConfidence(options = {}) {
|
|
113
|
+
return this.create({ ...options, confidence: "low" });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create a pending candidate awaiting review.
|
|
117
|
+
*/
|
|
118
|
+
pending(options = {}) {
|
|
119
|
+
return this.create({ ...options, status: "pending" });
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a promoted candidate.
|
|
123
|
+
*/
|
|
124
|
+
promoted(options) {
|
|
125
|
+
const now = new Date();
|
|
126
|
+
return this.create({
|
|
127
|
+
...options,
|
|
128
|
+
status: "promoted",
|
|
129
|
+
reviewedAt: options.reviewedAt ?? now,
|
|
130
|
+
reviewedBy: options.reviewedBy ?? "auto"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create a rejected candidate.
|
|
135
|
+
*/
|
|
136
|
+
rejected(rejectionReason, options = {}) {
|
|
137
|
+
const now = new Date();
|
|
138
|
+
return this.create({
|
|
139
|
+
...options,
|
|
140
|
+
status: "rejected",
|
|
141
|
+
rejectionReason,
|
|
142
|
+
reviewedAt: options.reviewedAt ?? now,
|
|
143
|
+
reviewedBy: options.reviewedBy ?? "manual"
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create a merged candidate (merged with existing learning).
|
|
148
|
+
*/
|
|
149
|
+
merged(existingLearningId, options = {}) {
|
|
150
|
+
const now = new Date();
|
|
151
|
+
return this.create({
|
|
152
|
+
...options,
|
|
153
|
+
status: "merged",
|
|
154
|
+
promotedLearningId: existingLearningId,
|
|
155
|
+
reviewedAt: options.reviewedAt ?? now,
|
|
156
|
+
reviewedBy: options.reviewedBy ?? "auto"
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a candidate from a specific source.
|
|
161
|
+
*/
|
|
162
|
+
fromSource(sourceFile, sourceRunId = null, sourceTaskId = null, options = {}) {
|
|
163
|
+
return this.create({
|
|
164
|
+
...options,
|
|
165
|
+
sourceFile,
|
|
166
|
+
sourceRunId,
|
|
167
|
+
sourceTaskId
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Reset the internal counter.
|
|
172
|
+
*/
|
|
173
|
+
reset() {
|
|
174
|
+
this.counter = 0;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Create a single test learning candidate (convenience function).
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
183
|
+
* const candidate = createTestCandidate(db, {
|
|
184
|
+
* content: 'Always validate user input',
|
|
185
|
+
* confidence: 'high',
|
|
186
|
+
* category: 'security'
|
|
187
|
+
* })
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export const createTestCandidate = (db, options = {}) => {
|
|
191
|
+
const factory = new CandidateFactory(db);
|
|
192
|
+
return factory.create(options);
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingURL=candidate.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidate.factory.js","sourceRoot":"","sources":["../../src/factories/candidate.factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkEH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,gBAAgB;IACnB,OAAO,GAAG,CAAC,CAAA;IACF,EAAE,CAAc;IAEjC,YAAY,EAAgB;QAC1B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAkC,EAAE;QACzC,IAAI,CAAC,OAAO,EAAE,CAAA;QACd,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;QAEtB,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,OAAO,CAAA;QACrC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,2BAA2B,IAAI,CAAC,OAAO,EAAE,CAAA;QAC5E,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAA;QACjD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAA;QACzC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mCAAmC,IAAI,CAAC,OAAO,QAAQ,CAAA;QAChG,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAA;QAC/C,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,CAAA;QACjD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,CAAA;QAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,SAAS,CAAA;QAC1C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAA;QAC7C,MAAM,UAAU,GAAG,OAAO,CAAC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ACjB,GAAG,OAAO;YACV,MAAM,EAAE,QAAQ;YAChB,kBAAkB,EAAE,kBAAkB;YACtC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,GAAG;YACrC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,MAAM;SACzC,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,UAAU,CACR,UAAkB,EAClB,cAA6B,IAAI,EACjC,eAA8B,IAAI,EAClC,UAAkC,EAAE;QAEpC,OAAO,IAAI,CAAC,MAAM,CAAC;YACjB,GAAG,OAAO;YACV,UAAU;YACV,WAAW;YACX,YAAY;SACb,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;IAClB,CAAC;CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,EAAgB,EAChB,UAAkC,EAAE,EACjB,EAAE;IACrB,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAA;IACxC,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAChC,CAAC,CAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edge factory for creating test graph edge data.
|
|
3
|
+
*
|
|
4
|
+
* @module @tx/test-utils/factories/edge
|
|
5
|
+
*/
|
|
6
|
+
import type { Edge, EdgeType, NodeType } from "@jamesaphoenix/tx-types";
|
|
7
|
+
import type { TestDatabase } from "../database/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Options for creating a test edge.
|
|
10
|
+
*/
|
|
11
|
+
export interface CreateEdgeOptions {
|
|
12
|
+
/** Edge ID (auto-generated if not provided) */
|
|
13
|
+
id?: number;
|
|
14
|
+
/** Type of edge relationship */
|
|
15
|
+
edgeType?: EdgeType;
|
|
16
|
+
/** Source node type */
|
|
17
|
+
sourceType?: NodeType;
|
|
18
|
+
/** Source node ID */
|
|
19
|
+
sourceId?: string;
|
|
20
|
+
/** Target node type */
|
|
21
|
+
targetType?: NodeType;
|
|
22
|
+
/** Target node ID */
|
|
23
|
+
targetId?: string;
|
|
24
|
+
/** Edge weight (0-1) */
|
|
25
|
+
weight?: number;
|
|
26
|
+
/** Additional metadata */
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
/** Creation timestamp */
|
|
29
|
+
createdAt?: Date;
|
|
30
|
+
/** Invalidation timestamp (null if active) */
|
|
31
|
+
invalidatedAt?: Date | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Factory class for creating test graph edges.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
39
|
+
* const factory = new EdgeFactory(db)
|
|
40
|
+
*
|
|
41
|
+
* // Create edge between two learnings
|
|
42
|
+
* const edge = factory.betweenLearnings(1, 2, 'SIMILAR_TO', 0.85)
|
|
43
|
+
*
|
|
44
|
+
* // Create anchor edge from learning to file
|
|
45
|
+
* const anchor = factory.anchorToFile(1, 'src/service.ts')
|
|
46
|
+
*
|
|
47
|
+
* // Create custom edge
|
|
48
|
+
* const custom = factory.create({
|
|
49
|
+
* edgeType: 'DERIVED_FROM',
|
|
50
|
+
* sourceType: 'learning',
|
|
51
|
+
* sourceId: '1',
|
|
52
|
+
* targetType: 'run',
|
|
53
|
+
* targetId: 'run-123'
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class EdgeFactory {
|
|
58
|
+
private counter;
|
|
59
|
+
private readonly db;
|
|
60
|
+
constructor(db: TestDatabase);
|
|
61
|
+
/**
|
|
62
|
+
* Create a single test edge.
|
|
63
|
+
*/
|
|
64
|
+
create(options?: CreateEdgeOptions): Edge;
|
|
65
|
+
/**
|
|
66
|
+
* Create multiple test edges.
|
|
67
|
+
*/
|
|
68
|
+
createMany(count: number, options?: CreateEdgeOptions): Edge[];
|
|
69
|
+
/**
|
|
70
|
+
* Create an edge between two learnings.
|
|
71
|
+
*/
|
|
72
|
+
betweenLearnings(sourceId: number | string, targetId: number | string, edgeType?: EdgeType, weight?: number): Edge;
|
|
73
|
+
/**
|
|
74
|
+
* Create an anchor edge from learning to file.
|
|
75
|
+
*/
|
|
76
|
+
anchorToFile(learningId: number | string, filePath: string, weight?: number): Edge;
|
|
77
|
+
/**
|
|
78
|
+
* Create a derivation edge from learning to run.
|
|
79
|
+
*/
|
|
80
|
+
derivedFromRun(learningId: number | string, runId: string, weight?: number): Edge;
|
|
81
|
+
/**
|
|
82
|
+
* Create a usage edge from learning to run.
|
|
83
|
+
*/
|
|
84
|
+
usedInRun(learningId: number | string, runId: string, weight?: number): Edge;
|
|
85
|
+
/**
|
|
86
|
+
* Create an invalidation edge.
|
|
87
|
+
*/
|
|
88
|
+
invalidatedBy(learningId: number | string, invalidatorId: number | string, weight?: number): Edge;
|
|
89
|
+
/**
|
|
90
|
+
* Reset the internal counter.
|
|
91
|
+
*/
|
|
92
|
+
reset(): void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a single test edge (convenience function).
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
100
|
+
* const edge = createTestEdge(db, {
|
|
101
|
+
* edgeType: 'SIMILAR_TO',
|
|
102
|
+
* sourceId: '1',
|
|
103
|
+
* targetId: '2',
|
|
104
|
+
* weight: 0.9
|
|
105
|
+
* })
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare const createTestEdge: (db: TestDatabase, options?: CreateEdgeOptions) => Edge;
|
|
109
|
+
/**
|
|
110
|
+
* Create an edge between two learnings (convenience function).
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
115
|
+
* const edge = createEdgeBetweenLearnings(db, 1, 2, 'SIMILAR_TO', 0.85)
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare const createEdgeBetweenLearnings: (db: TestDatabase, sourceId: number | string, targetId: number | string, edgeType?: EdgeType, weight?: number) => Edge;
|
|
119
|
+
//# sourceMappingURL=edge.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edge.factory.d.ts","sourceRoot":"","sources":["../../src/factories/edge.factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,IAAI,EAEJ,QAAQ,EACR,QAAQ,EACT,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,+CAA+C;IAC/C,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,gCAAgC;IAChC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,uBAAuB;IACvB,UAAU,CAAC,EAAE,QAAQ,CAAA;IACrB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uBAAuB;IACvB,UAAU,CAAC,EAAE,QAAQ,CAAA;IACrB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,wBAAwB;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,yBAAyB;IACzB,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,8CAA8C;IAC9C,aAAa,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAI;IACnB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAc;gBAErB,EAAE,EAAE,YAAY;IAI5B;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
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Factory class for creating test graph edges.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
12
|
+
* const factory = new EdgeFactory(db)
|
|
13
|
+
*
|
|
14
|
+
* // Create edge between two learnings
|
|
15
|
+
* const edge = factory.betweenLearnings(1, 2, 'SIMILAR_TO', 0.85)
|
|
16
|
+
*
|
|
17
|
+
* // Create anchor edge from learning to file
|
|
18
|
+
* const anchor = factory.anchorToFile(1, 'src/service.ts')
|
|
19
|
+
*
|
|
20
|
+
* // Create custom edge
|
|
21
|
+
* const custom = factory.create({
|
|
22
|
+
* edgeType: 'DERIVED_FROM',
|
|
23
|
+
* sourceType: 'learning',
|
|
24
|
+
* sourceId: '1',
|
|
25
|
+
* targetType: 'run',
|
|
26
|
+
* targetId: 'run-123'
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class EdgeFactory {
|
|
31
|
+
counter = 0;
|
|
32
|
+
db;
|
|
33
|
+
constructor(db) {
|
|
34
|
+
this.db = db;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a single test edge.
|
|
38
|
+
*/
|
|
39
|
+
create(options = {}) {
|
|
40
|
+
this.counter++;
|
|
41
|
+
const now = new Date();
|
|
42
|
+
const id = options.id ?? this.counter;
|
|
43
|
+
const edgeType = options.edgeType ?? "SIMILAR_TO";
|
|
44
|
+
const sourceType = options.sourceType ?? "learning";
|
|
45
|
+
const sourceId = options.sourceId ?? String(this.counter);
|
|
46
|
+
const targetType = options.targetType ?? "learning";
|
|
47
|
+
const targetId = options.targetId ?? String(this.counter + 1);
|
|
48
|
+
const weight = options.weight ?? 1.0;
|
|
49
|
+
const metadata = options.metadata ?? {};
|
|
50
|
+
const createdAt = options.createdAt ?? now;
|
|
51
|
+
const invalidatedAt = options.invalidatedAt ?? null;
|
|
52
|
+
this.db.run(`INSERT INTO learning_edges (id, edge_type, source_type, source_id, target_type, target_id, weight, metadata, created_at, invalidated_at)
|
|
53
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
54
|
+
id,
|
|
55
|
+
edgeType,
|
|
56
|
+
sourceType,
|
|
57
|
+
sourceId,
|
|
58
|
+
targetType,
|
|
59
|
+
targetId,
|
|
60
|
+
weight,
|
|
61
|
+
JSON.stringify(metadata),
|
|
62
|
+
createdAt.toISOString(),
|
|
63
|
+
invalidatedAt ? invalidatedAt.toISOString() : null
|
|
64
|
+
]);
|
|
65
|
+
return {
|
|
66
|
+
id: id,
|
|
67
|
+
edgeType,
|
|
68
|
+
sourceType,
|
|
69
|
+
sourceId,
|
|
70
|
+
targetType,
|
|
71
|
+
targetId,
|
|
72
|
+
weight,
|
|
73
|
+
metadata,
|
|
74
|
+
createdAt,
|
|
75
|
+
invalidatedAt
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create multiple test edges.
|
|
80
|
+
*/
|
|
81
|
+
createMany(count, options = {}) {
|
|
82
|
+
const edges = [];
|
|
83
|
+
for (let i = 0; i < count; i++) {
|
|
84
|
+
edges.push(this.create(options));
|
|
85
|
+
}
|
|
86
|
+
return edges;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create an edge between two learnings.
|
|
90
|
+
*/
|
|
91
|
+
betweenLearnings(sourceId, targetId, edgeType = "SIMILAR_TO", weight = 1.0) {
|
|
92
|
+
return this.create({
|
|
93
|
+
edgeType,
|
|
94
|
+
sourceType: "learning",
|
|
95
|
+
sourceId: String(sourceId),
|
|
96
|
+
targetType: "learning",
|
|
97
|
+
targetId: String(targetId),
|
|
98
|
+
weight
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create an anchor edge from learning to file.
|
|
103
|
+
*/
|
|
104
|
+
anchorToFile(learningId, filePath, weight = 1.0) {
|
|
105
|
+
return this.create({
|
|
106
|
+
edgeType: "ANCHORED_TO",
|
|
107
|
+
sourceType: "learning",
|
|
108
|
+
sourceId: String(learningId),
|
|
109
|
+
targetType: "file",
|
|
110
|
+
targetId: filePath,
|
|
111
|
+
weight
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a derivation edge from learning to run.
|
|
116
|
+
*/
|
|
117
|
+
derivedFromRun(learningId, runId, weight = 1.0) {
|
|
118
|
+
return this.create({
|
|
119
|
+
edgeType: "DERIVED_FROM",
|
|
120
|
+
sourceType: "learning",
|
|
121
|
+
sourceId: String(learningId),
|
|
122
|
+
targetType: "run",
|
|
123
|
+
targetId: runId,
|
|
124
|
+
weight
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create a usage edge from learning to run.
|
|
129
|
+
*/
|
|
130
|
+
usedInRun(learningId, runId, weight = 1.0) {
|
|
131
|
+
return this.create({
|
|
132
|
+
edgeType: "USED_IN_RUN",
|
|
133
|
+
sourceType: "learning",
|
|
134
|
+
sourceId: String(learningId),
|
|
135
|
+
targetType: "run",
|
|
136
|
+
targetId: runId,
|
|
137
|
+
weight
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create an invalidation edge.
|
|
142
|
+
*/
|
|
143
|
+
invalidatedBy(learningId, invalidatorId, weight = 1.0) {
|
|
144
|
+
return this.create({
|
|
145
|
+
edgeType: "INVALIDATED_BY",
|
|
146
|
+
sourceType: "learning",
|
|
147
|
+
sourceId: String(learningId),
|
|
148
|
+
targetType: "learning",
|
|
149
|
+
targetId: String(invalidatorId),
|
|
150
|
+
weight
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Reset the internal counter.
|
|
155
|
+
*/
|
|
156
|
+
reset() {
|
|
157
|
+
this.counter = 0;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a single test edge (convenience function).
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
166
|
+
* const edge = createTestEdge(db, {
|
|
167
|
+
* edgeType: 'SIMILAR_TO',
|
|
168
|
+
* sourceId: '1',
|
|
169
|
+
* targetId: '2',
|
|
170
|
+
* weight: 0.9
|
|
171
|
+
* })
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export const createTestEdge = (db, options = {}) => {
|
|
175
|
+
const factory = new EdgeFactory(db);
|
|
176
|
+
return factory.create(options);
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Create an edge between two learnings (convenience function).
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const db = await Effect.runPromise(createTestDatabase())
|
|
184
|
+
* const edge = createEdgeBetweenLearnings(db, 1, 2, 'SIMILAR_TO', 0.85)
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export const createEdgeBetweenLearnings = (db, sourceId, targetId, edgeType = "SIMILAR_TO", weight = 1.0) => {
|
|
188
|
+
const factory = new EdgeFactory(db);
|
|
189
|
+
return factory.betweenLearnings(sourceId, targetId, edgeType, weight);
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=edge.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edge.factory.js","sourceRoot":"","sources":["../../src/factories/edge.factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoCH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,WAAW;IACd,OAAO,GAAG,CAAC,CAAA;IACF,EAAE,CAAc;IAEjC,YAAY,EAAgB;QAC1B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAA6B,EAAE;QACpC,IAAI,CAAC,OAAO,EAAE,CAAA;QACd,MA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