This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new 64c412bc7 fix(instance): reject duplicate mock instance names (#7237)
64c412bc7 is described below
commit 64c412bc7f87036f7815a09cd277eb986d07ba96
Author: Loyal-Young <[email protected]>
AuthorDate: Mon Oct 26 21:22:23 2026 +0800
fix(instance): reject duplicate mock instance names (#7237)
* fix(instance): reject duplicate mock instance names
---
web/src/services/instanceService.test.ts | 14 ++++++++++++++
web/src/services/instanceService.ts | 4 ++++
2 files changed, 18 insertions(+)
diff --git a/web/src/services/instanceService.test.ts
b/web/src/services/instanceService.test.ts
index f119a4310..00ccf0ff7 100644
--- a/web/src/services/instanceService.test.ts
+++ b/web/src/services/instanceService.test.ts
@@ -105,6 +105,20 @@ describe('instanceService mock instances', () => {
expect(storedUpdated?.remark).toBe('updated');
});
+ it('rejects an existing instance name without changing the mock store',
async () => {
+ const before = await listInstances();
+ const existing = before[0];
+
+ await expect(
+ createInstance({ name: existing.name, type: 'DIRECT', endpoint:
'127.0.0.1:9876' }),
+ ).rejects.toThrow(`Instance name already exists: ${existing.name}`);
+ await expect(
+ createInstance({ name: ` ${existing.name} `, type: 'DIRECT', endpoint:
'127.0.0.1:9876' }),
+ ).rejects.toThrow(`Instance name already exists: ${existing.name}`);
+
+ expect(await listInstances()).toEqual(before);
+ });
+
it('rejects deleting missing mock instances', async () => {
const before = await listInstances();
diff --git a/web/src/services/instanceService.ts
b/web/src/services/instanceService.ts
index 366e9ef74..2f73e3cc6 100644
--- a/web/src/services/instanceService.ts
+++ b/web/src/services/instanceService.ts
@@ -86,6 +86,10 @@ export async function getInstanceCapabilities(instanceId:
string): Promise<Insta
export async function createInstance(data: CreateInstanceRequest):
Promise<Instance> {
if (isMockMode()) {
+ const requestedName = data.name?.trim();
+ if (requestedName && mockInstances.some((instance) => instance.name.trim()
=== requestedName)) {
+ throw new Error(`Instance name already exists: ${requestedName}`);
+ }
const cloudManaged = data.vendor === 'ALIYUN' || data.vendor === 'TENCENT';
const instance: Instance = {
id: Date.now(),