Skip to content

Commit 11f68d5

Browse files
committed
chore(mocks): cover rule version history/diff/rollback paths
The round-3/4 review introduced new error paths (VERSION_CONFLICT, VERSION_LEDGER_PENDING, FEATURE_DISABLED, intent repair/abandon) that the dev-mode mocks could not exercise, so UI regressions in those flows would only surface against a live backend. - new ruleVersion.ts: in-memory ledger per (kind, ruleName); rollback appends a ROLLBACK version so the history-drawer close-the-loop is realistic - routing/tag/dynamicConfig writes honour -conflict / -pending / -disabled rule-name conventions to trigger the matching 409/503 branches without runtime config knobs
1 parent ae5ed03 commit 11f68d5

5 files changed

Lines changed: 399 additions & 10 deletions

File tree

ui-vue3/src/mocks/handlers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { versionHandlers } from './handlers/version'
2727
import { dynamicConfigHandlers } from './handlers/dynamicConfig'
2828
import { routingRuleHandlers } from './handlers/routingRule'
2929
import { tagRuleHandlers } from './handlers/tagRule'
30+
import { ruleVersionHandlers } from './handlers/ruleVersion'
3031
import { destinationRuleHandlers, virtualServiceHandlers } from './handlers/istio'
3132
import { promQLHandlers } from './handlers/promQL'
3233
import { serverHandlers } from './handlers/server'
@@ -46,6 +47,7 @@ export const handlers: HttpHandler[] = [
4647
...dynamicConfigHandlers,
4748
...routingRuleHandlers,
4849
...tagRuleHandlers,
50+
...ruleVersionHandlers,
4951
...destinationRuleHandlers,
5052
...virtualServiceHandlers,
5153
...promQLHandlers,

ui-vue3/src/mocks/handlers/dynamicConfig.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { http, type HttpHandler } from 'msw'
1919
import { success, base } from '../utils'
20+
import { ruleVersionMock } from './ruleVersion'
2021
import type { ConfiguratorRule, ConfiguratorDetail, PaginatedData } from '@/types/api'
2122

2223
function randomInt(min: number, max: number): number {
@@ -28,6 +29,24 @@ function randomString(min: number, max: number): string {
2829
return Array.from({ length: len }, () => String.fromCharCode(97 + randomInt(0, 25))).join('')
2930
}
3031

32+
const decodeRuleName = (raw: string) => {
33+
try {
34+
return decodeURIComponent(raw)
35+
} catch {
36+
return raw
37+
}
38+
}
39+
40+
const writeOrConflict = (rawName: string, operation: 'CREATE' | 'UPDATE' | 'DELETE') => {
41+
const ruleName = decodeRuleName(rawName)
42+
if (ruleVersionMock.shouldConflict(ruleName))
43+
return ruleVersionMock.conflictResponse('configurator', ruleName)
44+
if (ruleVersionMock.shouldPend(ruleName))
45+
return ruleVersionMock.pendingResponse('configurator', ruleName)
46+
ruleVersionMock.recordAdminWrite('configurator', ruleName, operation)
47+
return success(null)
48+
}
49+
3150
export const dynamicConfigHandlers: HttpHandler[] = [
3251
http.get(`${base}/configurator/search`, () => {
3352
const total = randomInt(8, 1000)
@@ -45,15 +64,21 @@ export const dynamicConfigHandlers: HttpHandler[] = [
4564

4665
http.get(`${base}/configurator/:ruleName`, ({ params }) => {
4766
const detail: ConfiguratorDetail = {
48-
name: params.ruleName as string,
67+
name: decodeRuleName(params.ruleName as string),
4968
configs: [{ side: 'provider', timeout: 3000, retries: 2, loadbalance: 'roundrobin' }]
5069
}
5170
return success(detail)
5271
}),
5372

54-
http.delete(`${base}/configurator/:ruleName`, () => success(null)),
73+
http.delete(`${base}/configurator/:ruleName`, ({ params }) =>
74+
writeOrConflict(params.ruleName as string, 'DELETE')
75+
),
5576

56-
http.put(`${base}/configurator/:ruleName`, () => success(null)),
77+
http.put(`${base}/configurator/:ruleName`, ({ params }) =>
78+
writeOrConflict(params.ruleName as string, 'UPDATE')
79+
),
5780

58-
http.post(`${base}/configurator/:ruleName`, () => success(null))
81+
http.post(`${base}/configurator/:ruleName`, ({ params }) =>
82+
writeOrConflict(params.ruleName as string, 'CREATE')
83+
)
5984
]

ui-vue3/src/mocks/handlers/routingRule.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { http, type HttpHandler } from 'msw'
1919
import { success, base } from '../utils'
20+
import { ruleVersionMock } from './ruleVersion'
2021
import type { RoutingRule, RoutingRuleDetail, PaginatedData } from '@/types/api'
2122

2223
function randomInt(min: number, max: number): number {
@@ -28,6 +29,15 @@ function randomString(min: number, max: number): string {
2829
return Array.from({ length: len }, () => String.fromCharCode(97 + randomInt(0, 25))).join('')
2930
}
3031

32+
const writeOrConflict = (ruleName: string, operation: 'CREATE' | 'UPDATE' | 'DELETE') => {
33+
if (ruleVersionMock.shouldConflict(ruleName))
34+
return ruleVersionMock.conflictResponse('condition-rule', ruleName)
35+
if (ruleVersionMock.shouldPend(ruleName))
36+
return ruleVersionMock.pendingResponse('condition-rule', ruleName)
37+
ruleVersionMock.recordAdminWrite('condition-rule', ruleName, operation)
38+
return success(null)
39+
}
40+
3141
export const routingRuleHandlers: HttpHandler[] = [
3242
http.get(`${base}/condition-rule/search`, () => {
3343
const total = randomInt(8, 1000)
@@ -59,9 +69,15 @@ export const routingRuleHandlers: HttpHandler[] = [
5969
return success(detail)
6070
}),
6171

62-
http.delete(`${base}/condition-rule/:ruleName`, () => success(null)),
72+
http.delete(`${base}/condition-rule/:ruleName`, ({ params }) =>
73+
writeOrConflict(params.ruleName as string, 'DELETE')
74+
),
6375

64-
http.put(`${base}/condition-rule/:ruleName`, () => success(null)),
76+
http.put(`${base}/condition-rule/:ruleName`, ({ params }) =>
77+
writeOrConflict(params.ruleName as string, 'UPDATE')
78+
),
6579

66-
http.post(`${base}/condition-rule/:ruleName`, () => success(null))
80+
http.post(`${base}/condition-rule/:ruleName`, ({ params }) =>
81+
writeOrConflict(params.ruleName as string, 'CREATE')
82+
)
6783
]

0 commit comments

Comments
 (0)