Skip to content

fix(test): a guard file may name the module it forbids - #444

Open
bomly-guy wants to merge 1 commit into
mainfrom
claude/guard-files-may-name-what-they-forbid
Open

fix(test): a guard file may name the module it forbids#444
bomly-guy wants to merge 1 commit into
mainfrom
claude/guard-files-may-name-what-they-forbid

Conversation

@bomly-guy

Copy link
Copy Markdown
Collaborator

main is red right now. This fixes it. Reproduced on origin/main directly, not just on a branch:

--- FAIL: TestNoDirectPackageURLUse
    these files reference a package-url library directly ...
    [../../internal/output/registry_lookup_guard_test.go names github.com/package-url/packageurl-go]

Cause

#436 and #437 each added a guard and merged independently, and neither could have seen it alone:

Two rules doing their jobs, one flagging the other. A guard file naming a module in a rule that bans it is the opposite of reaching for it.

Fix

The exemption is a set of canonical paths.

Not a name — exempting anything called guards_test.go was the earlier bug in this very line, and it hid a forbidden import in a second guard file. Not a single hard-coded path either, which is what made the two guards collide as soon as a second one existed.

Adding a guard now costs one line in that set, on purpose: a new exemption should be an edit someone reviews, not a pattern that widens by itself.

The test exists because a mutation passed

My first mutation — reverting the predicate to a basename match — passed, which meant nothing pinned "exempt by path, not by name". The predicate is extracted now and TestGuardExemptionIsByPathNotByName covers both failure directions:

  • a file exempt for being named like a guard → fails
  • an entry naming a file that no longer exists → fails, because a dead exemption is a rule nobody is applying

Re-run after extracting: "../../internal/sbom/guards_test.go" is exempt for being named guards_test.go rather than for being a guard. Dropping the output guard from the set reproduces main's current failure.

make verify green.

Merge this before #440 — that PR is otherwise green and only red because it merged a broken main.

🤖 Generated with Claude Code

main is red. #436 and #437 each added a guard and merged independently:
the presentation-layer guard has to spell packageurl-go in order to ban
it, and the module-boundary guard reports any file under internal/ that
names it. Two rules doing their job, one flagging the other.

The exemption is a set of canonical paths now. Not a name -- exempting
anything called guards_test.go was the earlier bug in this same line, and
it hid a forbidden import in a second guard file. Not one hard-coded path
either, which is what made the guards collide the moment a second one
existed.

Adding a guard costs one line in that set, deliberately: a new exemption
should be an edit somebody reviews, not a pattern that widens on its own.

The predicate is extracted so the property can be pinned rather than
described. TestGuardExemptionIsByPathNotByName fails if a file becomes
exempt for being *named* like a guard, and if an entry names a file that
no longer exists -- a dead exemption is a rule nobody is applying. The
first mutation I ran against the old shape passed, which is how the
missing test surfaced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 5e5227b9-cea1-49a8-a95b-2a791ae4cd50

📥 Commits

Reviewing files that changed from the base of the PR and between 96a5c55 and 4e99cea.

📒 Files selected for processing (1)
  • internal/detectors/guards_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Bomly Diff Summary

Compared 96a5c55f74cc8ab7ca24d6516d835e115f34ee2b to 4e99cea8f6db6221ec861185e7a908b7ae1eb784.

Overview

Status Manifests Dependencies Findings Duration
✅ Pass +0 / ~0 / -0 0 added / 0 version changed / 0 detail changes / 0 removed 0 introduced / 0 persisted / 0 resolved 1m 23s

Dependency Changes

✅ No dependency changes.

Vulnerabilities

✅ No vulnerability changes.

License Changes

✅ No license changes.

Project Posture

✅ No project posture changes (--matchers +scorecard was not selected).

Policy Findings

✅ No policy differences were identified.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e99cea8f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +167 to 169
if isGuardFile(path) {
return nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope each guard-file exemption to its forbidden module

The unconditional isGuardFile return exempts each listed file from every filesNamingModule check, not just from the module its own guard must name. For example, registry_lookup_guard_test.go legitimately names the official package-URL module, but it can now directly import github.com/github/go-spdx or the deprecated Anchore package-URL module without either repository guard reporting it, despite the rule covering all files under internal/, including tests. Track exemptions by both path and module so each guard only suppresses its intentional self-reference.

AGENTS.md reference: AGENTS.md:L122-L123

Useful? React with 👍 / 👎.

bomly-guy added a commit that referenced this pull request Sep 9, 2026
…de/adopt-sdk-0.9.5

Test on this PR fails on a collision inherited from main, not on anything
this branch changed: #436's module-boundary guard reports #437's
presentation guard, which has to spell packageurl-go in order to forbid
it. #444 fixes it. Merging that branch in so this PR's CI reflects its own
changes; the merge collapses when #444 lands on main.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bomly-guy added a commit that referenced this pull request Sep 9, 2026
main is red: #436 tightened TestNoDirectPackageURLUse while #437 added
internal/output/registry_lookup_guard_test.go, whose own forbidden-string
literal names the module the other guard forbids, so the two guards report
each other. The failure is inherited by every branch cut from main,
including this one, and is unrelated to the digest vocabulary change here.

#444 fixes it and is green. Merging that branch rather
than writing a second fix: it is the same commit, so when #444 lands on
main this history dedupes with no conflict, and #443 never carries a
competing version of the same fix. It touches only
internal/detectors/guards_test.go, which this PR does not.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant