Commit 159f5c7b3c

159f5c7b3c72b7bdb0853ecfaff0955e5238f16f

parent: 03bb2bf7be

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-26 01:28 UTC

Say which bulk entries were skipped

U5: `parsedDomains` validated each token and dropped the failures, so
pasting ten domains with two typos ran eight and said nothing about the
other two. Before !8 those entries ran and failed visibly per section,
and the single lookup has reported its own error since, so the asymmetry
was the defect.

It returns a `ParsedBulkInput` now — the domains that validate and the
entries that do not, as typed — and `runBulkLookup` puts the message in
`bulkInputError`, which the bulk field renders the way the single field
renders `domainInputError` and clears on the next edit.

The worst case was every entry being invalid: the guard returned early,
so the button did nothing at all with no explanation. That now says there
is nothing to run, and names what it rejected.

Entries are named rather than counted, because "two were skipped" does
not say which to fix. A pasted list of typos names the first five and
counts the rest.

`WorkflowsView` has its own `parsedDomains`, which trims and drops empties
without validating. Different behaviour, not this defect; left alone.

Layout: unified · split

DomainDig/ContentView.swift +8
@@ -190,6 +190,7 @@ struct ContentView: View {
190190 viewModel.clearPresentedResults()
191191 }
192192 .onChange(of: viewModel.bulkInput) { _, newValue in
193 viewModel.bulkInputError = nil
193194 guard inputMode == .bulk else { return }
194195 let normalized = newValue.trimmingCharacters(in: .whitespacesAndNewlines)
195196 guard !normalized.isEmpty || viewModel.hasRun || !viewModel.batchResults.isEmpty else { return }
@@ -335,6 +336,13 @@ struct ContentView: View {
335336 .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius))
336337 .focused($focusedInputField, equals: .bulkDomains)
337338
339 if let bulkInputError = viewModel.bulkInputError {
340 Text(bulkInputError)
341 .font(appDensity.font(.caption))
342 .foregroundStyle(Color(.statusCritical))
343 .frame(maxWidth: .infinity, alignment: .leading)
344 }
345
338346 Button {
339347 focusedInputField = nil
340348 viewModel.runBulkLookup()
DomainDig/DomainViewModel.swift +34 −10
@@ -116,6 +116,9 @@ final class DomainViewModel {
116116 var domain: String = ""
117117 var bulkInput: String = ""
118118 var domainInputError: String?
119 /// What the bulk path skipped, for the same reason `domainInputError`
120 /// exists for the single one.
121 var bulkInputError: String?
119122
120123 // MARK: Section state
121124
@@ -1234,13 +1237,15 @@ final class DomainViewModel {
12341237 }
12351238
12361239 func runBulkLookup() {
1237 let domains = parsedDomains(from: bulkInput)
1238 guard !domains.isEmpty else { return }
1239 guard FeatureAccessService.canRunBatch(domainCount: domains.count) else {
1240 upgradePrompt = FeatureAccessService.upgradePromptForBatch(domainCount: domains.count)
1240 let parsed = parsedBulkInput(from: bulkInput)
1241 bulkInputError = parsed.skippedMessage
1242
1243 guard !parsed.domains.isEmpty else { return }
1244 guard FeatureAccessService.canRunBatch(domainCount: parsed.domains.count) else {
1245 upgradePrompt = FeatureAccessService.upgradePromptForBatch(domainCount: parsed.domains.count)
12411246 return
12421247 }
1243 startBatchLookup(domains: domains, source: .manual)
1248 startBatchLookup(domains: parsed.domains, source: .manual)
12441249 }
12451250
12461251 func refreshAllTrackedDomains() {
@@ -2118,14 +2123,33 @@ final class DomainViewModel {
21182123 batchTask = nil
21192124 }
21202125
2121 private func parsedDomains(from input: String) -> [String] {
2126 /// Splits bulk input into the domains that validate and the entries that do
2127 /// not.
2128 ///
2129 /// The rejected entries are returned rather than dropped: they used to go
2130 /// missing silently, so pasting ten domains with two typos ran eight and
2131 /// said nothing about the other two (U5). Before !8 those entries ran and
2132 /// failed visibly per section, and the single-lookup path has reported its
2133 /// own error since — the asymmetry was the defect.
2134 func parsedBulkInput(from input: String) -> ParsedBulkInput {
21222135 let separators = CharacterSet(charactersIn: ",").union(.whitespacesAndNewlines)
21232136 var seen = Set<String>()
2137 var domains: [String] = []
2138 var skipped: [String] = []
2139
2140 for token in input.components(separatedBy: separators) {
2141 // Whitespace between entries is not an entry.
2142 guard !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { continue }
2143 guard let domain = try? DomainName.validate(token).get() else {
2144 skipped.append(token)
2145 continue
2146 }
2147 if seen.insert(domain).inserted {
2148 domains.append(domain)
2149 }
2150 }
21242151
2125 return input
2126 .components(separatedBy: separators)
2127 .compactMap { try? DomainName.validate($0).get() }
2128 .filter { seen.insert($0).inserted }
2152 return ParsedBulkInput(domains: domains, skipped: skipped)
21292153 }
21302154
21312155 private func runBatchLookup(domains: [String], source: BatchLookupSource) async {
DomainDig/LookupSnapshot.swift +31
@@ -322,3 +322,34 @@ struct InspectionMetadata: Equatable {
322322 previousSnapshotID = snapshot.previousSnapshotID
323323 }
324324}
325
326/// Bulk input split into what will run and what will not.
327struct ParsedBulkInput: Equatable {
328 /// Valid domains, deduplicated, in the order they were written.
329 var domains: [String]
330 /// Entries that failed validation, as the user typed them.
331 var skipped: [String]
332
333 /// How many entries to name before falling back to a count. Naming them is
334 /// the point — "two were skipped" does not tell anyone which to fix — but a
335 /// pasted list of fifty typos should not become a wall of text.
336 private static let namedLimit = 5
337
338 /// What to tell the user, or `nil` when nothing was skipped.
339 var skippedMessage: String? {
340 guard !skipped.isEmpty else { return nil }
341
342 let named = skipped.prefix(Self.namedLimit).joined(separator: ", ")
343 let remainder = skipped.count - min(skipped.count, Self.namedLimit)
344 let list = remainder > 0 ? "\(named) and \(remainder) more" : named
345
346 if domains.isEmpty {
347 return skipped.count == 1
348 ? "\(list) is not a valid domain, so there is nothing to run."
349 : "None of these is a valid domain, so there is nothing to run: \(list)."
350 }
351 return skipped.count == 1
352 ? "Skipped \(list): not a valid domain."
353 : "Skipped \(skipped.count) entries that are not valid domains: \(list)."
354 }
355}
DomainDigTests/DomainNameTests.swift +101
@@ -141,6 +141,107 @@ final class DomainViewModelInputTests: XCTestCase {
141141 defaults: UserDefaults(suiteName: "net.cleberg.DomainDig.tests.input") ?? .standard
142142 )
143143
144 // MARK: Bulk input (U5)
145
146 /// The defect: ten domains with two typos ran eight and said nothing about
147 /// the other two.
148 func testBulkInputKeepsTheValidEntriesAndNamesTheRest() {
149 let parsed = Self.viewModel.parsedBulkInput(from: "example.com, not valid!!, apple.com")
150
151 XCTAssertEqual(parsed.domains, ["example.com", "apple.com"])
152 XCTAssertEqual(parsed.skipped, ["not", "valid!!"], "each rejected token is reported as typed")
153 XCTAssertEqual(
154 parsed.skippedMessage,
155 "Skipped 2 entries that are not valid domains: not, valid!!."
156 )
157 }
158
159 func testBulkInputDeduplicatesAndIgnoresBlankSeparators() {
160 let parsed = Self.viewModel.parsedBulkInput(from: "example.com,\n\n example.com ,\napple.com\n\n")
161
162 XCTAssertEqual(parsed.domains, ["example.com", "apple.com"])
163 XCTAssertTrue(parsed.skipped.isEmpty, "whitespace between entries is not an entry")
164 XCTAssertNil(parsed.skippedMessage)
165 }
166
167 func testValidBulkInputReportsNothing() {
168 let parsed = Self.viewModel.parsedBulkInput(from: "example.com\napple.com")
169
170 XCTAssertEqual(parsed.domains.count, 2)
171 XCTAssertNil(parsed.skippedMessage)
172 }
173
174 /// One bad entry reads as a sentence about that entry, not as a count.
175 func testASingleSkippedEntryIsNamedInTheSingular() {
176 let parsed = ParsedBulkInput(domains: ["example.com"], skipped: ["nope!"])
177
178 XCTAssertEqual(parsed.skippedMessage, "Skipped nope!: not a valid domain.")
179 }
180
181 /// The worst case before this change: every entry invalid meant the button
182 /// did nothing at all, with no explanation.
183 func testAllEntriesInvalidSaysThereIsNothingToRun() {
184 let many = ParsedBulkInput(domains: [], skipped: ["a!", "b!"])
185 XCTAssertEqual(
186 many.skippedMessage,
187 "None of these is a valid domain, so there is nothing to run: a!, b!."
188 )
189
190 let one = ParsedBulkInput(domains: [], skipped: ["a!"])
191 XCTAssertEqual(one.skippedMessage, "a! is not a valid domain, so there is nothing to run.")
192 }
193
194 /// A pasted list of typos names the first few and counts the rest, rather
195 /// than becoming a wall of text.
196 func testManySkippedEntriesAreTruncated() {
197 let parsed = ParsedBulkInput(
198 domains: ["example.com"],
199 skipped: ["a!", "b!", "c!", "d!", "e!", "f!", "g!"]
200 )
201
202 XCTAssertEqual(
203 parsed.skippedMessage,
204 "Skipped 7 entries that are not valid domains: a!, b!, c!, d!, e! and 2 more."
205 )
206 }
207
208 /// The whole point: running a bulk lookup leaves the message behind for the
209 /// view to show.
210 func testRunningABulkLookupReportsWhatItSkipped() {
211 let viewModel = Self.viewModel
212 viewModel.bulkInputError = nil
213 viewModel.bulkInput = "example.com, localhost"
214
215 viewModel.runBulkLookup()
216
217 XCTAssertEqual(viewModel.bulkInputError, "Skipped localhost: not a valid domain.")
218 }
219
220 func testABulkLookupWithNothingValidStillReports() {
221 let viewModel = Self.viewModel
222 viewModel.bulkInputError = nil
223 viewModel.bulkInput = "localhost"
224
225 viewModel.runBulkLookup()
226
227 XCTAssertEqual(
228 viewModel.bulkInputError,
229 "localhost is not a valid domain, so there is nothing to run."
230 )
231 XCTAssertFalse(viewModel.batchLookupRunning)
232 }
233
234 func testAValidBulkLookupLeavesNoMessage() {
235 let viewModel = Self.viewModel
236 viewModel.bulkInputError = "stale"
237 viewModel.bulkInput = "example.com"
238
239 viewModel.runBulkLookup()
240
241 XCTAssertNil(viewModel.bulkInputError)
242 viewModel.cancelBatchLookup()
243 }
244
144245 func testAnInvalidDomainDoesNotStartALookup() {
145246 let viewModel = Self.viewModel
146247 viewModel.domain = "localhost"