THINK FIRST·CODE LATER

← All labs

Dependency check: hallucinated and typosquatted packages

Problem

Before merging an AI-generated build change, check its dependencies against the team's list of approved packages.

Input:

APPROVED
<lines: group:artifact version1,version2,...>
REQUESTED
<lines: group:artifact:version>

For each requested dependency, in order, print one line:

  • OK group:artifact:version if the package is approved and the version is one of its approved versions;
  • VERSION? group:artifact:version (approved: v1, v2) if the package is approved but not that version;
  • TYPOSQUAT? group:artifact:version (did you mean G:A?) if it is not approved but its group:artifact string is within Levenshtein distance 1 or 2 of an approved one (choose the closest; first in the approved list on a tie);
  • UNKNOWN group:artifact:version (possible hallucination) otherwise.

Finally print Approved: a, Needs review: r (r = all lines that are not OK) and Verdict: BLOCK MERGE if any line is TYPOSQUAT? or UNKNOWN, otherwise Verdict: REVIEW VERSIONS if any VERSION?, otherwise Verdict: OK.

Input:

APPROVED
com.google.code.gson:gson 2.8.9,2.10.1
org.junit.jupiter:junit-jupiter 5.9.3
REQUESTED
com.google.code.gson:gson:2.10.1
com.google.code.gsom:gson:2.10.1
org.junit.jupiter:junit-jupiter:5.10.0
io.fastjson.utils:json-quickparse:1.0.2

Output:

OK com.google.code.gson:gson:2.10.1
TYPOSQUAT? com.google.code.gsom:gson:2.10.1 (did you mean com.google.code.gson:gson?)
VERSION? org.junit.jupiter:junit-jupiter:5.10.0 (approved: 5.9.3)
UNKNOWN io.fastjson.utils:json-quickparse:1.0.2 (possible hallucination)
Approved: 1, Needs review: 3
Verdict: BLOCK MERGE

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s7-4-data-1.txt

APPROVED
com.google.code.gson:gson 2.8.9,2.10.1
org.junit.jupiter:junit-jupiter 5.9.3
REQUESTED
com.google.code.gson:gson:2.10.1
com.google.code.gsom:gson:2.10.1
org.junit.jupiter:junit-jupiter:5.10.0
io.fastjson.utils:json-quickparse:1.0.2
What your program must print for s7-4-data-1.txt
OK com.google.code.gson:gson:2.10.1
TYPOSQUAT? com.google.code.gsom:gson:2.10.1 (did you mean com.google.code.gson:gson?)
VERSION? org.junit.jupiter:junit-jupiter:5.10.0 (approved: 5.9.3)
UNKNOWN io.fastjson.utils:json-quickparse:1.0.2 (possible hallucination)
Approved: 1, Needs review: 3
Verdict: BLOCK MERGE

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s7-4-data-1.txt

Windows PowerShell does not understand <:

Get-Content s7-4-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.