forked from mem9-ai/mem9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpc-dialog-content.test.ts
More file actions
228 lines (207 loc) · 6.19 KB
/
npc-dialog-content.test.ts
File metadata and controls
228 lines (207 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import { describe, expect, it } from "vitest";
import type {
AnalysisJobSnapshotResponse,
DeepAnalysisReportDetail,
} from "@/types/analysis";
import {
buildPixelFarmNpcDialogCatalog,
pickNextPixelFarmNpcDialogEntry,
} from "./npc-dialog-content";
function translate(key: string, vars?: Record<string, string | number>): string {
return `${key}:${JSON.stringify(vars ?? {})}`;
}
function createLightSnapshot(): AnalysisJobSnapshotResponse {
return {
jobId: "aj_1",
status: "COMPLETED",
expectedTotalMemories: 42,
expectedTotalBatches: 1,
batchSize: 42,
pipelineVersion: "v1",
taxonomyVersion: "v3",
llmEnabled: true,
createdAt: "2026-04-04T00:00:00.000Z",
progress: {
expectedTotalBatches: 1,
uploadedBatches: 1,
completedBatches: 1,
failedBatches: 0,
processedMemories: 42,
resultVersion: 1,
},
aggregate: {
categoryCounts: { "analysis.category.project": 10 },
tagCounts: { Work: 12 },
topicCounts: { planning: 8 },
summarySnapshot: ["project focus", "planning streak"],
resultVersion: 1,
},
aggregateCards: [],
topTags: ["Work"],
topTopics: ["planning"],
topTagStats: [{ value: "Work", count: 12 }],
topTopicStats: [{ value: "planning", count: 8 }],
batchSummaries: [],
};
}
function createDeepReport(): DeepAnalysisReportDetail {
return {
id: "dar_1",
status: "COMPLETED",
stage: "COMPLETE",
progressPercent: 100,
lang: "en",
timezone: "Asia/Shanghai",
memoryCount: 42,
requestedAt: "2026-04-04T00:00:00.000Z",
preview: null,
report: {
overview: {
memoryCount: 42,
deduplicatedMemoryCount: 40,
generatedAt: "2026-04-04T00:00:00.000Z",
lang: "en",
timeSpan: {
start: "2026-03-01T00:00:00.000Z",
end: "2026-04-04T00:00:00.000Z",
},
},
persona: {
summary: "You keep circling around release prep.",
goals: ["ship the next release"],
notableRoutines: ["daily planning"],
},
themeLandscape: {
highlights: [{ name: "release prep", count: 7, description: "shipping work" }],
},
entities: { people: [], teams: [], projects: [], tools: [], places: [] },
relationships: [],
quality: {
duplicateRatio: 0,
noisyMemoryCount: 0,
duplicateClusters: [],
lowQualityExamples: [],
coverageGaps: [],
},
recommendations: ["protect focus time"],
productSignals: { candidateNodes: [], candidateEdges: [], searchSeeds: [] },
},
};
}
describe("npc-dialog-content", () => {
it("keeps deep-analysis, light-analysis, and tips in the same rotation pool", () => {
const catalog = buildPixelFarmNpcDialogCatalog({
deepReport: createDeepReport(),
lightSnapshot: createLightSnapshot(),
t: translate,
});
const seenSources = new Set<string>();
let rotationState = null;
for (
let index = 0;
index < catalog.deepInsights.length + catalog.lightInsights.length + catalog.tips.length;
index += 1
) {
const next = pickNextPixelFarmNpcDialogEntry({
catalog,
rotationState,
random: () => 0,
});
seenSources.add(next.entry.source);
rotationState = next.rotationState;
}
expect(seenSources).toEqual(new Set([
"deep-analysis",
"analysis-snapshot",
"static-tip",
]));
});
it("keeps light-analysis lines and tips together when no deep-analysis report is available", () => {
const catalog = buildPixelFarmNpcDialogCatalog({
deepReport: null,
lightSnapshot: createLightSnapshot(),
t: translate,
});
const seenSources = new Set<string>();
let rotationState = null;
for (let index = 0; index < catalog.lightInsights.length + catalog.tips.length; index += 1) {
const next = pickNextPixelFarmNpcDialogEntry({
catalog,
rotationState,
random: () => 0,
});
seenSources.add(next.entry.source);
rotationState = next.rotationState;
}
expect(seenSources).toEqual(new Set([
"analysis-snapshot",
"static-tip",
]));
});
it("falls back to static tips when no analysis source exists", () => {
const catalog = buildPixelFarmNpcDialogCatalog({
deepReport: null,
lightSnapshot: null,
t: translate,
});
const { entry } = pickNextPixelFarmNpcDialogEntry({
catalog,
rotationState: null,
random: () => 0,
});
expect(entry.source).toBe("static-tip");
});
it("walks through the full combined pool before repeating entries", () => {
const catalog = buildPixelFarmNpcDialogCatalog({
deepReport: createDeepReport(),
lightSnapshot: createLightSnapshot(),
t: translate,
});
let rotationState = null;
const entryIds = new Set<string>();
for (
let index = 0;
index < catalog.deepInsights.length + catalog.lightInsights.length + catalog.tips.length;
index += 1
) {
const next = pickNextPixelFarmNpcDialogEntry({
catalog,
rotationState,
random: () => 0,
});
entryIds.add(next.entry.id);
rotationState = next.rotationState;
}
expect(entryIds.size).toBe(
catalog.deepInsights.length + catalog.lightInsights.length + catalog.tips.length,
);
});
it("starts a new shuffled round without immediately repeating the previous entry", () => {
const catalog = buildPixelFarmNpcDialogCatalog({
deepReport: createDeepReport(),
lightSnapshot: createLightSnapshot(),
t: translate,
});
let rotationState = null;
let previousEntryId: string | null = null;
for (
let index = 0;
index < catalog.deepInsights.length + catalog.lightInsights.length + catalog.tips.length;
index += 1
) {
const next = pickNextPixelFarmNpcDialogEntry({
catalog,
rotationState,
random: () => 0,
});
previousEntryId = next.entry.id;
rotationState = next.rotationState;
}
const nextRound = pickNextPixelFarmNpcDialogEntry({
catalog,
rotationState,
random: () => 0,
});
expect(nextRound.entry.id).not.toBe(previousEntryId);
});
});