MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / seedChatSessionDb

Function seedChatSessionDb

tests/e2e/smoke/chart-runtime.smoke.test.js:146–193  ·  view source on GitHub ↗
(chatDataDir)

Source from the content-addressed store, hash-verified

144}
145
146function seedChatSessionDb(chatDataDir) {
147 const Database = getDatabaseConstructor()
148 const dbDir = path.join(chatDataDir, 'databases')
149 ensureDir(dbDir)
150 const db = new Database(path.join(dbDir, `${SESSION_ID}.db`), {
151 nativeBinding: resolveNativeBinding(),
152 })
153
154 try {
155 db.exec(CHAT_DB_SCHEMA)
156 db.prepare(
157 `INSERT INTO meta (name, platform, type, imported_at, group_id, owner_id, schema_version)
158 VALUES (?, ?, ?, ?, ?, ?, 5)`
159 ).run(SESSION_NAME, 'wechat', 'group', unixTs('2026-06-03T00:00:00Z'), 'g_chart', 'u_alice')
160
161 const insertMember = db.prepare(
162 `INSERT INTO member (platform_id, account_name, group_nickname)
163 VALUES (?, ?, ?)`
164 )
165 insertMember.run('u_alice', 'Alice Account', 'Alice')
166 insertMember.run('u_bob', 'Bob Account', 'Bob')
167 insertMember.run('u_cara', 'Cara Account', 'Cara')
168
169 const members = db.prepare('SELECT id, group_nickname FROM member').all()
170 const memberIds = new Map(members.map((row) => [row.group_nickname, row.id]))
171 const insertMessage = db.prepare(
172 `INSERT INTO message (sender_id, sender_account_name, sender_group_nickname, ts, type, content, platform_message_id)
173 VALUES (?, ?, ?, ?, ?, ?, ?)`
174 )
175
176 const addMessage = (name, ts, type, content) => {
177 const id = memberIds.get(name)
178 assert.ok(id, `missing member id for ${name}`)
179 insertMessage.run(id, `${name} Account`, name, unixTs(ts), type, content, `${name}-${ts}`)
180 }
181
182 addMessage('Alice', '2026-06-01T09:00:00Z', 0, 'morning hello')
183 addMessage('Alice', '2026-06-01T10:00:00Z', 0, 'standup note')
184 addMessage('Alice', '2026-06-02T09:00:00Z', 1, '[图片]')
185 addMessage('Alice', '2026-06-02T10:00:00Z', 0, 'follow up')
186 addMessage('Bob', '2026-06-01T09:00:00Z', 0, 'first reply')
187 addMessage('Bob', '2026-06-02T10:00:00Z', 0, 'second reply')
188 addMessage('Bob', '2026-06-02T11:00:00Z', 0, 'third reply')
189 addMessage('Cara', '2026-06-01T09:00:00Z', 0, 'other member')
190 } finally {
191 db.close()
192 }
193}
194
195function seedAiConversationDb(homeDir) {
196 const Database = getDatabaseConstructor()

Callers 1

Calls 10

getDatabaseConstructorFunction · 0.85
ensureDirFunction · 0.70
resolveNativeBindingFunction · 0.70
unixTsFunction · 0.70
addMessageFunction · 0.70
execMethod · 0.65
runMethod · 0.65
prepareMethod · 0.65
allMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected