Fix the license screen for AI-written pull requests

Review the AI's codeEasy10 minAnthropic and Microsoft style

Your task

You maintain an Apache-2.0 command line tool, and a contributor opened a pull request with a module an AI agent generated. A model can reproduce licensed code with no attribution, and GPL code inside your project would break the license your enterprise users depend on. So every pull request now goes through a license scan before it merges.

An assistant wrote screen_ai_contribution(matched_licenses, match_scores, has_attestation, threshold), which turns the scan report into a verdict. It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • matched_licenses and match_scores: each license the scanner matched, and how strong the match is as a percent, at the same index.
  • has_attestation: the contributor signed that they have the right to contribute the code under your license.
  • threshold: a match counts only when its score is at least this.
  • Return one verdict: reject_copyleft, manual_review, needs_attribution, needs_attestation or accept.

Rules the tests check:

  • If the two lists differ in length, return manual_review.
  • Ignore matches that score below threshold.
  • Uppercase the ASCII letters of each license id, then sort it into a family:
    • copyleft: it starts with AGPL, LGPL, GPL or SSPL
    • permissive: it starts with MIT, BSD, ISC, APACHE or ZLIB
    • unknown: anything else
  • Return the first of these that applies:
    1. Any counted match is copyleft: reject_copyleft.
    2. Any counted match is unknown: manual_review.
    3. Any counted match is permissive: needs_attribution.
    4. There is no attestation: needs_attestation.
    5. Otherwise: accept.

Examples

screen_ai_contribution(matched_licenses: list[str], match_scores: list[int], has_attestation: bool, threshold: int) -> str
Example 1
Inputscreen_ai_contribution(["MIT", "BSD-3-Clause"], [92, 40], True, 80)
Output"needs_attribution"
Example 2
Inputscreen_ai_contribution(["GPL-3.0"], [85], True, 80)
Output"reject_copyleft"