diff --git a/plugins/antianqi/minimax-bot-team/.minimax-plugin/plugin.json b/plugins/antianqi/minimax-bot-team/.minimax-plugin/plugin.json index 02e575ac..9be6758d 100644 --- a/plugins/antianqi/minimax-bot-team/.minimax-plugin/plugin.json +++ b/plugins/antianqi/minimax-bot-team/.minimax-plugin/plugin.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "name": "minimax-bot-team", "displayName": "MiniMax Bot Team / MiniMax Bot 团队", - "version": "1.0.0", + "version": "1.0.1", "description": "现在的 bot 像一个人轮流带着几个面具跟你聊天。MiniMax Bot Team 给你的是一支真正各有能力、各有性格的团队,各自守着一个领域,也能围坐一起,从不同角度讨论同一个问题。 / Today's bot is one person wearing several masks, taking turns with you. MiniMax Bot Team gives you a team instead: members with different skills and different temperaments, each guarding one field, and they can sit down together and argue about the same question from different angles.", "author": "antianqi", "icon": "icon.png", diff --git a/plugins/antianqi/minimax-bot-team/README.md b/plugins/antianqi/minimax-bot-team/README.md index 521012a4..a8e2a5c4 100644 --- a/plugins/antianqi/minimax-bot-team/README.md +++ b/plugins/antianqi/minimax-bot-team/README.md @@ -7,7 +7,7 @@ Bot Team gives you a team instead: members with different skills and different temperaments, each guarding one field, and they can sit down together and argue about the same question from different angles. -Author: [antianqi](https://github.com/antianqi) - Version: `1.0.0` +Author: [antianqi](https://github.com/antianqi) - Version: `1.0.1` ## What it does diff --git a/plugins/antianqi/minimax-bot-team/README.zh-CN.md b/plugins/antianqi/minimax-bot-team/README.zh-CN.md index 32bf7e26..27974f06 100644 --- a/plugins/antianqi/minimax-bot-team/README.zh-CN.md +++ b/plugins/antianqi/minimax-bot-team/README.zh-CN.md @@ -5,7 +5,7 @@ 现在的 bot 像一个人轮流带着几个面具跟你聊天。MiniMax Bot Team 给你的是一支真正各有 能力、各有性格的团队,各自守着一个领域,也能围坐一起,从不同角度讨论同一个问题。 -作者:[antianqi](https://github.com/antianqi) - 版本:`1.0.0` +作者:[antianqi](https://github.com/antianqi) - 版本:`1.0.1` ## 它做什么 diff --git a/plugins/antianqi/minimax-bot-team/miniapp/node/plugin-id.mjs b/plugins/antianqi/minimax-bot-team/miniapp/node/plugin-id.mjs index fc7dadea..512ca8b4 100644 --- a/plugins/antianqi/minimax-bot-team/miniapp/node/plugin-id.mjs +++ b/plugins/antianqi/minimax-bot-team/miniapp/node/plugin-id.mjs @@ -12,4 +12,4 @@ export const PLUGIN_ID = 'minimax-bot-team'; /** The version the Host and the MCP tools report. */ -export const PLUGIN_VERSION = '1.0.0'; +export const PLUGIN_VERSION = '1.0.1'; diff --git a/plugins/antianqi/minimax-bot-team/miniapp/node/store.mjs b/plugins/antianqi/minimax-bot-team/miniapp/node/store.mjs index 51c36262..38968c4d 100644 --- a/plugins/antianqi/minimax-bot-team/miniapp/node/store.mjs +++ b/plugins/antianqi/minimax-bot-team/miniapp/node/store.mjs @@ -601,12 +601,17 @@ export class Store { async deleteChat(chatId) { await this.getMessages(chatId); + // The transcript is the one thing here that cannot be rebuilt, so the state that + // forgets this chat goes to disk first. A failed state write then leaves the chat and + // its messages both as they were, and the caller can simply try again. await this.enqueue(async () => { + const sessions = { ...this.state.sessions }; + delete sessions[chatId]; + await writeJsonAtomic(this.statePath, { ...this.state, sessions }); + delete this.state.sessions[chatId]; await this.writeMessages(chatId, []); this.messageCache.set(chatId, []); - delete this.state.sessions[chatId]; }); - await this.save(); } /** Sidebar summary of one chat, read from the warm cache. */ diff --git a/plugins/antianqi/minimax-bot-team/package.json b/plugins/antianqi/minimax-bot-team/package.json index 3fd0512f..ea7d6763 100644 --- a/plugins/antianqi/minimax-bot-team/package.json +++ b/plugins/antianqi/minimax-bot-team/package.json @@ -1,6 +1,6 @@ { "name": "minimax-bot-team", - "version": "1.0.0", + "version": "1.0.1", "private": true, "type": "module", "mcode": { diff --git a/plugins/antianqi/minimax-bot-team/skills/bot-team-setup/SKILL.md b/plugins/antianqi/minimax-bot-team/skills/bot-team-setup/SKILL.md index aec15463..2a94c28e 100644 --- a/plugins/antianqi/minimax-bot-team/skills/bot-team-setup/SKILL.md +++ b/plugins/antianqi/minimax-bot-team/skills/bot-team-setup/SKILL.md @@ -4,7 +4,7 @@ description: Use this skill when the user wants to build or change a team of Min license: Apache-2.0 metadata: author: antianqi - version: 1.0.0 + version: 1.0.1 --- # MiniMax Bot 团队搭建 diff --git a/plugins/antianqi/minimax-bot-team/tests/chat-delete-atomicity.test.mjs b/plugins/antianqi/minimax-bot-team/tests/chat-delete-atomicity.test.mjs new file mode 100644 index 00000000..2275a608 --- /dev/null +++ b/plugins/antianqi/minimax-bot-team/tests/chat-delete-atomicity.test.mjs @@ -0,0 +1,75 @@ +// @ts-check +// Deleting a chat must not lose its messages when the state write fails. +// +// The transcript is the one thing that cannot be rebuilt, so the state that forgets the +// chat goes to disk first. A failed write then leaves the chat and its messages both as +// they were, and the caller can simply try again. This file fails if that order flips +// back: the failure injection below replaces state.json with a directory of the same name, +// so every write to it fails. + +import assert from 'node:assert/strict'; +import { test } from 'node:test'; +import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; + +import { Store } from '../miniapp/node/store.mjs'; + +async function fixture(t) { + const dir = await mkdtemp(join(tmpdir(), 'bot-delete-chat-')); + t.after(() => rm(dir, { recursive: true, force: true })); + const store = new Store(dir); + await store.init(); + return { dir, store, chat: store.chatIds()[0] }; +} + +test('a failed state write leaves the chat and its messages untouched', async (t) => { + const { dir, store, chat } = await fixture(t); + await store.appendMessage(chat, { role: 'user', text: 'the greeting' }); + await store.appendMessage(chat, { role: 'bot', text: 'the answer' }); + store.state.sessions[chat] = { sessionId: 's_1', stamp: 1, lastSeen: 1 }; + await store.save(); + // The store seeds a greeting of its own, so the count is read, never assumed. + const before = (await store.getMessages(chat)).length; + assert.ok(before >= 2, 'the chat has a transcript to lose'); + + // The state file becomes a directory: every write to it fails. + const statePath = join(dir, 'state.json'); + const saved = await readFile(statePath, 'utf8'); + await rm(statePath, { force: true }); + await mkdir(statePath, { recursive: true }); + + await assert.rejects(() => store.deleteChat(chat)); + + // The transcript is still on disk, and the live state still knows the chat. + const onDisk = JSON.parse(await readFile(store.messagePath(chat), 'utf8')); + assert.equal(onDisk.length, before, 'the messages are still on disk'); + assert.ok(store.state.sessions[chat], 'the live state still knows the chat'); + + // Put the state file back and restart: the chat is still there with its messages. + await rm(statePath, { recursive: true, force: true }); + await writeFile(statePath, saved, 'utf8'); + const restarted = new Store(dir); + await restarted.init(); + const messages = await restarted.getMessages(chat); + assert.equal(messages.length, before, 'the messages survive the restart'); + assert.ok(messages.some((message) => message.text === 'the greeting'), 'the greeting is still there'); + assert.ok(restarted.state.sessions[chat], 'the session survives the restart'); +}); + +test('a delete that succeeds clears the transcript and forgets the chat', async (t) => { + const { dir, store, chat } = await fixture(t); + await store.appendMessage(chat, { role: 'user', text: 'the greeting' }); + await store.appendMessage(chat, { role: 'bot', text: 'the answer' }); + store.state.sessions[chat] = { sessionId: 's_1', stamp: 1, lastSeen: 1 }; + await store.save(); + + await store.deleteChat(chat); + + assert.equal((await store.getMessages(chat)).length, 0, 'the transcript is empty'); + assert.equal(store.state.sessions[chat], undefined, 'the chat is forgotten'); + const restarted = new Store(dir); + await restarted.init(); + assert.equal((await restarted.getMessages(chat)).length, 0, 'the transcript stays empty'); + assert.equal(restarted.state.sessions[chat], undefined, 'the chat stays forgotten'); +});