Add simulated failure retry and recovery
This commit is contained in:
+16
-3
@@ -25,6 +25,8 @@ const fileInput = ref<HTMLInputElement | null>(null)
|
||||
const placingPreset = ref<SystemPreset | null>(null)
|
||||
const selectedCapabilityIds = ref<string[]>([])
|
||||
const presentationMode = ref(false)
|
||||
const failureState = ref<'none' | 'rejected' | 'timeout'>('none')
|
||||
const retryAttempts = ref<Record<string, number>>({})
|
||||
type TransferKind = 'received' | 'sent' | 'stored'
|
||||
interface TransferChange { key: string; status: 'added' | 'removed' | 'changed' | 'same'; incoming?: unknown; outgoing?: unknown }
|
||||
interface TransferRecord { id: string; kind: TransferKind; scenarioName: string; stepNumber: number; stepExplanation: string; senderId: string; destinationId: string; payload: string; incoming: string; outgoing: string; changes: TransferChange[]; timestamp: string }
|
||||
@@ -78,7 +80,7 @@ function addStep() {
|
||||
}
|
||||
function deleteStep(index: number) { selectedScenario.value?.steps.splice(index, 1); persist() }
|
||||
|
||||
function resetPlayback() { playing.value = false; stepIndex.value = -1; packetProgress.value = 0; eventLog.value = []; transferHistory.value = []; stopAnimation() }
|
||||
function resetPlayback() { playing.value = false; stepIndex.value = -1; packetProgress.value = 0; eventLog.value = []; transferHistory.value = []; failureState.value = 'none'; retryAttempts.value = {}; stopAnimation() }
|
||||
function startScenario(systemId?: string) {
|
||||
if (systemId) {
|
||||
const candidate = landscape.value.scenarios.find((scenario) => scenario.startSystemId === systemId)
|
||||
@@ -91,6 +93,8 @@ function advanceStep() {
|
||||
stepIndex.value += 1; packetProgress.value = 0
|
||||
const step = selectedScenario.value.steps[stepIndex.value]
|
||||
recordTransfers(step)
|
||||
failureState.value = step.outcome && step.outcome !== 'success' ? step.outcome : 'none'
|
||||
if (failureState.value !== 'none') eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${step.outcome === 'timeout' ? 'TIMEOUT' : 'REJECTED'} · ${step.explanation}`)
|
||||
eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${step.explanation}`)
|
||||
animatePacket(step.delayMs / speed.value)
|
||||
}
|
||||
@@ -116,9 +120,17 @@ function systemName(id: string) { return landscape.value.systems.find((system) =
|
||||
const latestSelectedRecord = computed(() => selectedSystem.value ? transferHistory.value.filter((record) => record.destinationId === selectedSystem.value?.id).slice(-1)[0] : undefined)
|
||||
function animatePacket(duration: number) {
|
||||
stopAnimation(); const started = performance.now()
|
||||
const tick = (now: number) => { packetProgress.value = Math.min(1, (now - started) / duration); drawPackets(); if (packetProgress.value < 1) animationFrame = requestAnimationFrame(tick); else if (playing.value) setTimeout(advanceStep, 180 / speed.value) }
|
||||
const tick = (now: number) => { packetProgress.value = Math.min(1, (now - started) / duration); drawPackets(); if (packetProgress.value < 1) animationFrame = requestAnimationFrame(tick); else if (playing.value) setTimeout(finishStep, 180 / speed.value) }
|
||||
animationFrame = requestAnimationFrame(tick)
|
||||
}
|
||||
function finishStep() {
|
||||
const step = currentStep.value
|
||||
if (!step || !selectedScenario.value || !step.outcome || step.outcome === 'success') { advanceStep(); return }
|
||||
const targetId = step.retryStepId && (retryAttempts.value[step.id] || 0) < 1 ? step.retryStepId : step.recoveryStepId
|
||||
if (step.retryStepId && targetId === step.retryStepId) retryAttempts.value[step.id] = (retryAttempts.value[step.id] || 0) + 1
|
||||
const targetIndex = targetId ? selectedScenario.value.steps.findIndex((candidate) => candidate.id === targetId) : -1
|
||||
if (targetIndex >= 0) { stepIndex.value = targetIndex - 1; failureState.value = 'none'; advanceStep() } else { playing.value = false }
|
||||
}
|
||||
function stopAnimation() { if (animationFrame) cancelAnimationFrame(animationFrame); animationFrame = 0 }
|
||||
function togglePlay() { if (!selectedScenario.value) return; if (playing.value) { playing.value = false; stopAnimation() } else { playing.value = true; if (stepIndex.value < 0) advanceStep(); else animatePacket(currentStep.value?.delayMs || 1000) } }
|
||||
|
||||
@@ -154,7 +166,7 @@ function drawPackets() {
|
||||
if (!from || !to) continue
|
||||
const x = from.pos[0] + from.size[0] + (to.pos[0] - from.pos[0] - from.size[0]) * packetProgress.value
|
||||
const y = from.pos[1] + 50 + (to.pos[1] + 50 - from.pos[1] - 50) * packetProgress.value
|
||||
ctx.save(); ctx.fillStyle = '#f8c15c'; ctx.shadowColor = '#f8c15c'; ctx.shadowBlur = 16; ctx.beginPath(); ctx.arc(x, y, 7, 0, Math.PI * 2); ctx.fill(); ctx.restore()
|
||||
const packetColor = failureState.value === 'none' ? '#f8c15c' : '#ef627d'; ctx.save(); ctx.fillStyle = packetColor; ctx.shadowColor = packetColor; ctx.shadowBlur = 18; ctx.beginPath(); ctx.arc(x, y, failureState.value === 'none' ? 7 : 9, 0, Math.PI * 2); ctx.fill(); ctx.restore()
|
||||
}
|
||||
}
|
||||
function exportJson() {
|
||||
@@ -195,5 +207,6 @@ onUnmounted(stopAnimation)
|
||||
<div v-if="placingPreset" class="modal-backdrop" @click.self="placingPreset = null"><section class="preset-modal panel"><div class="inspector-header"><div><span class="eyebrow">PLACE PRESET</span><h2>{{ placingPreset.name }}</h2><p>{{ placingPreset.description }}</p></div><button class="danger-icon" @click="placingPreset = null">×</button></div><p class="muted">Choose the capabilities to place. The new canvas system will have its own editable copies.</p><label v-for="capability in placingPreset.capabilities" :key="capability.id" class="capability-choice" :title="capability.description"><input v-model="selectedCapabilityIds" type="checkbox" :value="capability.id" /><span><b>{{ capability.name }}</b><small>{{ capability.description }}</small></span></label><div class="modal-actions"><button class="ghost" @click="placingPreset = null">Cancel</button><button class="primary" :disabled="!selectedCapabilityIds.length" @click="placePreset">Place system</button></div></section></div>
|
||||
<section v-if="selectedConnection" class="transformation-panel panel"><div><span class="eyebrow">SIMULATED TRANSFORMATION</span><strong>{{ selectedConnection.label }}</strong><p class="muted">Configure the data change explicitly; playback never calls a real service.</p></div><label>Incoming JSON<textarea v-model="selectedConnection.transformation!.incoming" rows="4" class="code" @focus="enableTransformation"></textarea></label><label>Outgoing JSON<textarea v-model="selectedConnection.transformation!.outgoing" rows="4" class="code" @focus="enableTransformation"></textarea></label><label>Explanation<input v-model="selectedConnection.transformation!.note" placeholder="What changed?" @focus="enableTransformation" /></label></section><section v-if="latestSelectedRecord" class="transformation-view panel"><span class="eyebrow">LAST RECEIVED PAYLOAD</span><div class="json-columns"><div><b>Incoming</b><pre>{{ latestSelectedRecord.incoming }}</pre></div><div><b>Outgoing</b><pre>{{ latestSelectedRecord.outgoing }}</pre></div></div><div class="change-list"><span v-for="change in latestSelectedRecord.changes" :key="change.key" :class="`change-${change.status}`"><b>{{ change.status }}</b> {{ change.key }}: {{ change.incoming }} → {{ change.outgoing }}</span></div></section>
|
||||
<section v-if="currentStep" class="guided-card panel"><span class="eyebrow">GUIDED STEP {{ stepIndex + 1 }}</span><strong>{{ currentStep.explanation }}</strong><p>{{ selectedScenario?.description }}</p></section><button class="presentation-toggle ghost" @click="presentationMode = !presentationMode">{{ presentationMode ? 'Exit presentation' : 'Presentation mode' }}</button>
|
||||
<section v-if="selectedScenario" class="failure-config panel"><div><span class="eyebrow">STEP OUTCOMES</span><strong>Failure and recovery routing</strong><p class="muted">Choose how a simulated step behaves. Retry is limited to one automatic attempt per reset.</p></div><div v-for="(step, index) in selectedScenario.steps" :key="step.id" class="failure-row"><b>{{ index + 1 }}. {{ step.explanation }}</b><select v-model="step.outcome"><option value="success">Success</option><option value="rejected">Reject data</option><option value="timeout">Time out</option></select><select v-model="step.retryStepId"><option value="">No retry</option><option v-for="candidate in selectedScenario.steps" :key="candidate.id" :value="candidate.id" :disabled="candidate.id === step.id">Retry step {{ selectedScenario.steps.indexOf(candidate) + 1 }}</option></select><select v-model="step.recoveryStepId"><option value="">No recovery step</option><option v-for="candidate in selectedScenario.steps" :key="candidate.id" :value="candidate.id" :disabled="candidate.id === step.id">Recover at step {{ selectedScenario.steps.indexOf(candidate) + 1 }}</option></select></div></section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user