Skip to content

Commit 005a71f

Browse files
authored
test: normalize inline block comments in gatekeeper scanning (#2705)
Blank single-line block comments with index-preserving spaces so punctuation adjacency stays visible to position heuristics; document nested-suppressed-call attribution and multi-line block comments as parser-requiring out-of-scope patterns.
1 parent 5cb69f0 commit 005a71f

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ struct ProviderArchitectureGatekeeperTests {
287287
#expect(references.first?.providerIDs == ["claude", "codex"])
288288
}
289289

290+
@Test
291+
func `provider reference scanner sees through inline block comments`() {
292+
let assignment = "let provider: UsageProvider = /* fallback */ .claude"
293+
let labeled = "choose(provider: /* fallback */ .claude)"
294+
295+
#expect(Self.providerReferences(in: assignment, providerIDs: ["claude"]).count == 1)
296+
#expect(Self.providerReferences(in: labeled, providerIDs: ["claude"]).count == 1)
297+
}
298+
290299
@Test
291300
func `single provider argument remains an architecture finding`() {
292301
let failures = Self.analyze(
@@ -4402,21 +4411,38 @@ struct ProviderArchitectureGatekeeperTests {
44024411
private static func codeBeforeLineComment(_ line: String) -> String {
44034412
var previous: Character?
44044413
var isInsideString = false
4405-
var index = line.startIndex
4406-
while index < line.endIndex {
4407-
let character = line[index]
4414+
var characters = Array(line)
4415+
var index = 0
4416+
while index < characters.count {
4417+
let character = characters[index]
44084418
if character == "\"", previous != "\\" {
44094419
isInsideString.toggle()
4410-
} else if character == "/", !isInsideString {
4411-
let next = line.index(after: index)
4412-
if next < line.endIndex, line[next] == "/" {
4413-
return String(line[..<index])
4420+
} else if character == "/", !isInsideString, index + 1 < characters.count {
4421+
if characters[index + 1] == "/" {
4422+
return String(characters[..<index])
4423+
}
4424+
if characters[index + 1] == "*" {
4425+
// Blank single-line block comments with spaces so punctuation adjacency stays
4426+
// visible to position heuristics while every character index is preserved.
4427+
var end = index + 2
4428+
while end + 1 < characters.count, !(characters[end] == "*" && characters[end + 1] == "/") {
4429+
end += 1
4430+
}
4431+
guard end + 1 < characters.count else {
4432+
return String(characters[..<index])
4433+
}
4434+
for blank in index...(end + 1) {
4435+
characters[blank] = " "
4436+
}
4437+
previous = " "
4438+
index = end + 2
4439+
continue
44144440
}
44154441
}
44164442
previous = character
4417-
index = line.index(after: index)
4443+
index += 1
44184444
}
4419-
return line
4445+
return String(characters)
44204446
}
44214447

44224448
private static func isIdentifierCharacter(_ character: Character) -> Bool {

docs/provider.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ The following are out of scope by design:
7070
closure-body dataflow. A line-and-statement lexical scan cannot model those positions honestly.
7171
- String concatenation, reflection, and dynamic lookup. Their runtime values are not recoverable from literal-token
7272
matching.
73+
- Provider literals nested inside the arguments of a suppressed call (for example a routing call passed into a logging
74+
call). Attributing a literal to the inner rather than the outer call requires expression-tree parsing.
75+
- Multi-line block comments interleaved with an expression. Single-line `/* ... */` comments are blanked before
76+
scanning; comments spanning statement lines are treated as ending the scanned code for that line.
7377
- `Tests/**`, where fixtures legitimately name providers, and non-Swift files, because this tripwire is scoped to
7478
shipped Swift architecture.
7579

0 commit comments

Comments
 (0)