@@ -327,6 +327,50 @@ def test_fingerprint_stable(self):
327327 self .assertEqual (fingerprint ("slug" , "a/b.ts" ), fingerprint ("slug" , "a/b.ts" ))
328328 self .assertTrue (fingerprint ("slug" , "a/b.ts" ).startswith ("opencode2api-scan:" ))
329329
330+ def test_secret_patterns_require_quotes (self ):
331+ import re
332+ from repo_scan import SECRET_PATTERNS
333+ by_rule = {rule : pattern for pattern , rule in SECRET_PATTERNS }
334+ # Real pasted secrets (quoted) still match.
335+ self .assertTrue (re .search (by_rule ["possible-api-key" ], 'api_key = "sk-live-abc123"' ))
336+ self .assertTrue (re .search (by_rule ["possible-password" ], "password: 'hunter2-hunter2'" ))
337+ self .assertTrue (re .search (by_rule ["private-key-material" ],
338+ "-----BEGIN PRIVATE KEY-----" ))
339+ # Bare code and unquoted env lines are noise, not findings.
340+ self .assertFalse (re .search (
341+ by_rule ["possible-api-key" ], 'self.api_key = default_pdata.get("apikey", "")' ))
342+ self .assertFalse (re .search (
343+ by_rule ["possible-api-key" ], "API_KEY= OPENCODE_PROXY_MANAGE_BACKEND=true" ))
344+ self .assertFalse (re .search (
345+ by_rule ["possible-password" ], "password = get_password()" ))
346+
347+ def test_low_risk_path_downgrade (self ):
348+ from repo_scan import is_low_risk_path
349+ self .assertTrue (is_low_risk_path ("tests/auth-multikey.test.js" ))
350+ self .assertTrue (is_low_risk_path ("docs/docker.md" ))
351+ self .assertTrue (is_low_risk_path (".github/workflows/ai-review.yml" ))
352+ self .assertFalse (is_low_risk_path ("src/proxy.ts" ))
353+ self .assertFalse (is_low_risk_path ("github_bot/src/llm_client.py" ))
354+
355+ def test_prior_dry_run_fps_resolved (self ):
356+ # The three dry-run false positives from the first live scan:
357+ # bare-code hit, unquoted yml env hit gone; quoted fixture hit is nit.
358+ from repo_scan import collect_findings , is_low_risk_path
359+ by_loc = {}
360+ for item in collect_findings ():
361+ by_loc .setdefault (item ["location" ].split (":" )[0 ], []).append (item )
362+ llm_hits = [i for i in by_loc .get ("github_bot/src/llm_client.py" , [])
363+ if "possible-api-key" in i ["fingerprint" ]]
364+ self .assertEqual (llm_hits , [])
365+ yml_hits = [i for i in by_loc .get (".github/workflows/ai-review.yml" , [])
366+ if "possible-api-key" in i ["fingerprint" ]]
367+ self .assertEqual (yml_hits , [])
368+ for path , items in by_loc .items ():
369+ for item in items :
370+ slug = item ["fingerprint" ].split (":" )[1 ]
371+ if slug in ("possible-api-key" , "possible-password" ) and is_low_risk_path (path ):
372+ self .assertEqual (item ["severity" ], "nit" , item ["location" ])
373+
330374 def test_comment_modes (self ):
331375 self .assertEqual (github_runner ._resolve_comment_mode ("/review please" ), "review" )
332376 self .assertEqual (github_runner ._resolve_comment_mode ("/fix this" ), "fix-plan" )
0 commit comments