native macOS codings agent orchestrator
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(sentry): cheapen release action breadcrumbs

onevcat 946d626b 942a5609

+91 -2
+51 -2
supacode/Support/DebugCaseOutput.swift
··· 16 16 private let logger = SupaLogger("TCA") 17 17 18 18 func reduce(into state: inout Base.State, action: Base.Action) -> Effect<Base.Action> { 19 - let actionLabel = debugCaseOutput(action) 20 - logger.debug("Action: \(actionLabel)") 21 19 #if DEBUG 20 + let actionLabel = debugCaseOutput(action) 21 + logger.debug("Action: \(actionLabel)") 22 22 let previousState = state 23 23 let effects = base.reduce(into: &state, action: action) 24 24 if previousState != state, let diff = CustomDump.diff(previousState, state) { ··· 26 26 } 27 27 return effects 28 28 #else 29 + let actionLabel = releaseActionLabel(action) 30 + logger.debug("Action: \(actionLabel)") 29 31 SentrySDK.logger.info("Action: \(actionLabel)") 30 32 let breadcrumb = Breadcrumb(level: .debug, category: "action") 31 33 breadcrumb.message = actionLabel ··· 66 68 ?? "\(abbreviated ? "" : typeName(type(of: value)))\(debugCaseOutputHelp(value))" 67 69 } 68 70 71 + func releaseActionLabel(_ value: Any) -> String { 72 + let rootType = shortTypeName(type(of: value)) 73 + let casePath = releaseEnumCasePath(value) 74 + guard !casePath.isEmpty else { 75 + return rootType 76 + } 77 + return "\(rootType).\(casePath.joined(separator: "."))" 78 + } 79 + 69 80 private func isUnlabeledArgument(_ label: String) -> Bool { 70 81 label.firstIndex(where: { $0 != "." && !$0.isNumber }) == nil 82 + } 83 + 84 + private func releaseEnumCasePath(_ value: Any) -> [String] { 85 + var labels: [String] = [] 86 + var currentValue = value 87 + 88 + while true { 89 + let mirror = Mirror(reflecting: currentValue) 90 + guard mirror.displayStyle == .enum else { 91 + return labels 92 + } 93 + if let child = mirror.children.first, let label = child.label { 94 + labels.append(label) 95 + let childMirror = Mirror(reflecting: child.value) 96 + guard childMirror.displayStyle == .enum else { 97 + return labels 98 + } 99 + currentValue = child.value 100 + } else { 101 + labels.append(caseName(String(describing: currentValue))) 102 + return labels 103 + } 104 + } 105 + } 106 + 107 + private func caseName(_ description: String) -> String { 108 + if let parenIndex = description.firstIndex(of: "(") { 109 + return String(description[..<parenIndex]) 110 + } 111 + return description 112 + } 113 + 114 + private func shortTypeName(_ type: Any.Type) -> String { 115 + let components = String(reflecting: type) 116 + .split(separator: ".") 117 + .filter { !$0.hasPrefix("(unknown context at $") } 118 + .suffix(2) 119 + return components.isEmpty ? String(reflecting: type) : components.joined(separator: ".") 71 120 } 72 121 73 122 private func typeName(
+40
supacodeTests/ReleaseActionLabelTests.swift
··· 1 + import Testing 2 + 3 + @testable import supacode 4 + 5 + struct ReleaseActionLabelTests { 6 + private enum OuterAction { 7 + case idle 8 + case inner(InnerAction) 9 + case payload(id: Int, title: String) 10 + } 11 + 12 + private enum InnerAction { 13 + case ready 14 + case deep(DeepAction) 15 + } 16 + 17 + private enum DeepAction { 18 + case done(worktreeID: String, added: Int, removed: Int) 19 + } 20 + 21 + @Test func nestedEnumLabelUsesCasePathWithoutPayloads() { 22 + let label = releaseActionLabel( 23 + OuterAction.inner(.deep(.done(worktreeID: "wt-1", added: 3, removed: 1))) 24 + ) 25 + 26 + #expect(label == "ReleaseActionLabelTests.OuterAction.inner.deep.done") 27 + } 28 + 29 + @Test func payloadCaseDoesNotExpandAssociatedValues() { 30 + let label = releaseActionLabel(OuterAction.payload(id: 42, title: "repo")) 31 + 32 + #expect(label == "ReleaseActionLabelTests.OuterAction.payload") 33 + } 34 + 35 + @Test func payloadlessCaseKeepsTypeAndCase() { 36 + let label = releaseActionLabel(OuterAction.idle) 37 + 38 + #expect(label == "ReleaseActionLabelTests.OuterAction.idle") 39 + } 40 + }