diff --git a/src/App.vue b/src/App.vue index 42e6dc4..6da8b59 100644 --- a/src/App.vue +++ b/src/App.vue @@ -25,6 +25,8 @@ const fileInput = ref(null) const placingPreset = ref(null) const selectedCapabilityIds = ref([]) const presentationMode = ref(false) +const failureState = ref<'none' | 'rejected' | 'timeout'>('none') +const retryAttempts = ref>({}) 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)
SIMULATED TRANSFORMATION{{ selectedConnection.label }}

Configure the data change explicitly; playback never calls a real service.

LAST RECEIVED PAYLOAD
Incoming
{{ latestSelectedRecord.incoming }}
Outgoing
{{ latestSelectedRecord.outgoing }}
{{ change.status }} {{ change.key }}: {{ change.incoming }} → {{ change.outgoing }}
GUIDED STEP {{ stepIndex + 1 }}{{ currentStep.explanation }}

{{ selectedScenario?.description }}

+
STEP OUTCOMESFailure and recovery routing

Choose how a simulated step behaves. Retry is limited to one automatic attempt per reset.

{{ index + 1 }}. {{ step.explanation }}
diff --git a/src/failure.css b/src/failure.css new file mode 100644 index 0000000..0007f85 --- /dev/null +++ b/src/failure.css @@ -0,0 +1 @@ +.failure-config{padding:14px 16px}.failure-config>div:first-child{margin-bottom:10px}.failure-config strong{display:block;margin-top:4px}.failure-row{display:grid;grid-template-columns:minmax(160px,1fr) 130px 130px 150px;gap:8px;align-items:center;border-top:1px solid #263149;padding:8px 0;color:#c9d3e8;font-size:11px}.failure-row select{background:#0d1320;color:#dce4f4;border:1px solid #303d58;border-radius:4px;padding:6px;font-size:10px}.presentation .failure-config{display:none}.presentation .guided-card{display:block}@media(max-width:800px){.failure-row{grid-template-columns:1fr 1fr}.failure-row b{grid-column:1/-1}} diff --git a/src/main.ts b/src/main.ts index 9422e95..371612c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import './style.css' import './inspector.css' import './transformation.css' import './presentation.css' +import './failure.css' import './style.css' createApp(App).mount('#app') diff --git a/src/model.ts b/src/model.ts index d57d7ea..0b5fb00 100644 --- a/src/model.ts +++ b/src/model.ts @@ -32,6 +32,9 @@ export interface ScenarioStep { explanation: string payload: string delayMs: number + outcome?: 'success' | 'rejected' | 'timeout' + retryStepId?: string + recoveryStepId?: string } export interface ScenarioModel {