|
| 1 | +# ============================================================================ |
| 2 | +# Debug Logs Toggle - Conditional Visibility State Machine |
| 3 | +# Level 11.40: Debug toggle for LIVE LOG, CORPUS LOG, ALL EVENTS sections |
| 4 | +# Sacred Formula: V = n x 3^k x pi^m x phi^p x e^q |
| 5 | +# Golden Identity: phi^2 + 1/phi^2 = 3 = TRINITY |
| 6 | +# ============================================================================ |
| 7 | + |
| 8 | +name: debug_logs_toggle |
| 9 | +version: "1.0.0" |
| 10 | +language: zig |
| 11 | +module: debug_logs_toggle |
| 12 | + |
| 13 | +description: | |
| 14 | + Debug toggle state machine for conditional visibility of diagnostic UI sections. |
| 15 | + Controls LIVE LOG, CORPUS LOG, and ALL EVENTS panels through a single boolean gate. |
| 16 | + When debug mode is OFF, all three sections are hidden from the user interface. |
| 17 | + When debug mode is ON, sections render with full telemetry and event streams. |
| 18 | + State transitions are atomic to prevent partial visibility glitches. |
| 19 | + |
| 20 | +constants: |
| 21 | + DIM: 4096 |
| 22 | + SECTION_COUNT: 3 |
| 23 | + LIVE_LOG_INDEX: 0 |
| 24 | + CORPUS_LOG_INDEX: 1 |
| 25 | + ALL_EVENTS_INDEX: 2 |
| 26 | + DEFAULT_DEBUG_STATE: 0 |
| 27 | + MAX_LOG_BUFFER_SIZE: 8192 |
| 28 | + LOG_FLUSH_INTERVAL_MS: 500 |
| 29 | + TRANSITION_TIMEOUT_MS: 100 |
| 30 | + |
| 31 | +types: |
| 32 | + DebugState: |
| 33 | + description: "Binary state of the debug toggle" |
| 34 | + enum: |
| 35 | + - debug_off |
| 36 | + - debug_on |
| 37 | + |
| 38 | + LogSection: |
| 39 | + description: "Identifiers for the three debug log sections" |
| 40 | + enum: |
| 41 | + - live_log |
| 42 | + - corpus_log |
| 43 | + - all_events |
| 44 | + |
| 45 | + SectionVisibility: |
| 46 | + description: "Visibility state of a single debug section" |
| 47 | + fields: |
| 48 | + section: LogSection |
| 49 | + visible: Bool |
| 50 | + render_enabled: Bool |
| 51 | + last_toggled_at: Int |
| 52 | + |
| 53 | + ToggleState: |
| 54 | + description: "Complete state of the debug toggle system" |
| 55 | + fields: |
| 56 | + debug_enabled: Bool |
| 57 | + sections: List<SectionVisibility> |
| 58 | + transition_count: Int |
| 59 | + last_transition_at: Int |
| 60 | + is_transitioning: Bool |
| 61 | + |
| 62 | + ToggleEvent: |
| 63 | + description: "Event emitted on state transition" |
| 64 | + fields: |
| 65 | + from_state: DebugState |
| 66 | + to_state: DebugState |
| 67 | + timestamp_ms: Int |
| 68 | + sections_affected: Int |
| 69 | + success: Bool |
| 70 | + |
| 71 | + LogEntry: |
| 72 | + description: "Single log entry in a debug section" |
| 73 | + fields: |
| 74 | + section: LogSection |
| 75 | + timestamp_ms: Int |
| 76 | + level: String |
| 77 | + message: String |
| 78 | + source: String |
| 79 | + |
| 80 | + LogBuffer: |
| 81 | + description: "Buffered log entries for a section" |
| 82 | + fields: |
| 83 | + section: LogSection |
| 84 | + entries: List<LogEntry> |
| 85 | + capacity: Int |
| 86 | + count: Int |
| 87 | + overflow_count: Int |
| 88 | + |
| 89 | +behaviors: |
| 90 | + # State machine transitions |
| 91 | + - name: init |
| 92 | + given: Default debug state (OFF) |
| 93 | + when: Application starts or toggle system is created |
| 94 | + then: Return ToggleState with all 3 sections hidden |
| 95 | + |
| 96 | + - name: toggle_debug |
| 97 | + given: Current ToggleState |
| 98 | + when: User activates or deactivates debug mode |
| 99 | + then: Atomically flip all 3 sections visibility, emit ToggleEvent |
| 100 | + |
| 101 | + - name: set_debug_on |
| 102 | + given: ToggleState with debug_enabled = false |
| 103 | + when: Debug mode explicitly enabled |
| 104 | + then: Set debug_enabled = true, show LIVE LOG, CORPUS LOG, ALL EVENTS |
| 105 | + |
| 106 | + - name: set_debug_off |
| 107 | + given: ToggleState with debug_enabled = true |
| 108 | + when: Debug mode explicitly disabled |
| 109 | + then: Set debug_enabled = false, hide all 3 sections atomically |
| 110 | + |
| 111 | + # Section visibility queries |
| 112 | + - name: is_section_visible |
| 113 | + given: LogSection identifier and current ToggleState |
| 114 | + when: UI renderer queries section visibility |
| 115 | + then: Return true only if debug_enabled is true |
| 116 | + |
| 117 | + - name: get_visible_sections |
| 118 | + given: Current ToggleState |
| 119 | + when: Layout engine needs visible section list |
| 120 | + then: Return list of 3 sections if debug ON, empty list if debug OFF |
| 121 | + |
| 122 | + # Atomic transition guard |
| 123 | + - name: begin_transition |
| 124 | + given: ToggleState with is_transitioning = false |
| 125 | + when: Toggle action initiated |
| 126 | + then: Set is_transitioning = true, prevent concurrent toggles |
| 127 | + |
| 128 | + - name: complete_transition |
| 129 | + given: ToggleState with is_transitioning = true |
| 130 | + when: All sections have been updated |
| 131 | + then: Set is_transitioning = false, increment transition_count |
| 132 | + |
| 133 | + - name: abort_transition |
| 134 | + given: ToggleState with is_transitioning = true |
| 135 | + when: Transition timeout exceeded (TRANSITION_TIMEOUT_MS) |
| 136 | + then: Rollback to previous state, emit error event |
| 137 | + |
| 138 | + # Log buffer management |
| 139 | + - name: push_log_entry |
| 140 | + given: LogEntry and target LogBuffer |
| 141 | + when: New log event arrives for a section |
| 142 | + then: Append entry if debug ON, discard silently if debug OFF |
| 143 | + |
| 144 | + - name: flush_buffer |
| 145 | + given: LogBuffer with pending entries |
| 146 | + when: Flush interval elapsed or buffer near capacity |
| 147 | + then: Render buffered entries to UI, reset buffer count |
| 148 | + |
| 149 | + - name: clear_all_buffers |
| 150 | + given: All LogBuffers |
| 151 | + when: Debug mode toggled OFF |
| 152 | + then: Clear all 3 section buffers, reset overflow counts |
| 153 | + |
| 154 | +test_cases: |
| 155 | + - name: default_state_is_off |
| 156 | + given: "Fresh initialization" |
| 157 | + expected: "debug_enabled = false, all 3 sections hidden" |
| 158 | + |
| 159 | + - name: toggle_on_shows_all_sections |
| 160 | + given: "debug_enabled = false" |
| 161 | + expected: "All 3 sections visible after toggle" |
| 162 | + |
| 163 | + - name: toggle_off_hides_all_sections |
| 164 | + given: "debug_enabled = true" |
| 165 | + expected: "All 3 sections hidden after toggle" |
| 166 | + |
| 167 | + - name: atomic_transition_no_partial |
| 168 | + given: "Toggle from OFF to ON" |
| 169 | + expected: "Never observe 1 or 2 sections visible mid-transition" |
| 170 | + |
| 171 | + - name: concurrent_toggle_blocked |
| 172 | + given: "Toggle while is_transitioning = true" |
| 173 | + expected: "Second toggle rejected, no state corruption" |
| 174 | + |
| 175 | + - name: logs_discarded_when_off |
| 176 | + given: "debug_enabled = false, log entry arrives" |
| 177 | + expected: "Entry silently dropped, no buffer growth" |
| 178 | + |
| 179 | + - name: transition_timeout_rollback |
| 180 | + given: "Transition exceeds TRANSITION_TIMEOUT_MS" |
| 181 | + expected: "State rolled back to previous, error event emitted" |
0 commit comments