@@ -678,6 +678,49 @@ class FossIdSnippetChoiceTest : WordSpec({
678678 summary.snippetFindings should beEmpty()
679679 }
680680
681+ " add the license of already marked file with a snippet choice to the license findings (scan in archive mode)" {
682+ val projectCode = PROJECT
683+ val scanCode = scanCode(PROJECT , null)
684+ val config = createConfig(deltaScans = false, fetchSnippetMatchedLines = true, isArchiveMode = true)
685+ val vcsInfo = createVcsInfo()
686+ val scan = createScan(vcsInfo.url, "${vcsInfo.revision}_other ", scanCode)
687+ val pkgId = createIdentifier(index = 42)
688+
689+ val choiceLocation = TextLocation (FILE_1 , 10, 20)
690+ val payload = OrtCommentPayload (mapOf("MIT " to listOf(choiceLocation)), 1, 0)
691+ val comment = jsonMapper.writeValueAsString(mapOf(ORT_NAME to payload))
692+ val markedAsIdentifiedFile = createMarkAsIdentifiedFile("MIT ", FILE_1_ARCHIVE_MODE , comment)
693+ FossIdRestService .create(config.serverUrl)
694+ .expectProjectRequest(projectCode)
695+ .expectListScans(projectCode, listOf(scan))
696+ .expectCheckScanStatus(scanCode, ScanStatus .FINISHED )
697+ .expectCreateScan(projectCode, scanCode, vcsInfo, "", isArchiveMode = true)
698+ .expectRemoveUploadedContent(scanCode)
699+ .expectUploadFile(scanCode)
700+ .expectExtractArchives(scanCode)
701+ .mockFiles(
702+ scanCode,
703+ markedFiles = listOf(markedAsIdentifiedFile)
704+ )
705+
706+ val snippetChoices = createSnippetChoices(
707+ vcsInfo.url,
708+ createSnippetChoice(choiceLocation, PURL_1 , "")
709+ )
710+ val fossId = createFossId(config)
711+
712+ val summary = fossId.scan(createPackage(pkgId, vcsInfo), snippetChoices = snippetChoices).summary
713+
714+ summary.licenseFindings shouldHaveSize 1
715+ summary.licenseFindings.first().apply {
716+ license shouldBe " MIT" .toSpdx()
717+ location shouldBe choiceLocation
718+ }
719+
720+ summary.issues.filter { it.severity > Severity .HINT } should beEmpty()
721+ summary.snippetFindings should beEmpty()
722+ }
723+
681724 " add the license of marked as identified files that have been manually marked in the UI (legacy behavior)" {
682725 val projectCode = PROJECT
683726 val scanCode = scanCode(PROJECT , null)
@@ -775,6 +818,74 @@ class FossIdSnippetChoiceTest : WordSpec({
775818 }
776819 }
777820
821+ " put a marked as identified file back to pending if it has no snippet choice (scan in archive mode)" {
822+ val projectCode = PROJECT
823+ val scanCode = scanCode(PROJECT , null)
824+ val config = createConfig(deltaScans = false, fetchSnippetMatchedLines = true, isArchiveMode = true)
825+ val vcsInfo = createVcsInfo()
826+ val scan = createScan(vcsInfo.url, "${vcsInfo.revision}_other ", scanCode)
827+ val pkgId = createIdentifier(index = 42)
828+
829+ val choiceLocation = TextLocation (FILE_1 , 10, 20)
830+ val payload = OrtCommentPayload (mapOf("MIT " to listOf(choiceLocation)), 1, 0)
831+ val comment = jsonMapper.writeValueAsString(mapOf(ORT_NAME to payload))
832+ val markedAsIdentifiedFile = createMarkAsIdentifiedFile("MIT ", FILE_1_ARCHIVE_MODE , comment)
833+ val service = FossIdRestService .create(config.serverUrl)
834+ .expectProjectRequest(projectCode)
835+ .expectListScans(projectCode, listOf(scan))
836+ .expectCheckScanStatus(scanCode, ScanStatus .FINISHED )
837+ .expectCreateScan(projectCode, scanCode, vcsInfo, "", isArchiveMode = true)
838+ .expectRemoveUploadedContent(scanCode)
839+ .expectUploadFile(scanCode)
840+ .expectExtractArchives(scanCode)
841+ .mockFiles(
842+ scanCode,
843+ markedFiles = listOf(markedAsIdentifiedFile),
844+ snippets = listOf(
845+ createSnippet(0, FILE_1 , PURL_1 ),
846+ createSnippet(1, FILE_1 , PURL_2 ),
847+ createSnippet(2, FILE_1 , PURL_3 )
848+ ),
849+ matchedLines = mapOf(
850+ 0 to MatchedLines .create((10..20).toList(), (10..20).toList()),
851+ 1 to MatchedLines .create((10..20).toList(), (10..20).toList()),
852+ 2 to MatchedLines .create((20..30).toList(), (20..30).toList())
853+ )
854+ )
855+ // The unmark as identified call is made on the real snippet path.
856+ .expectUnmarkAsIdentified(scanCode, FILE_1_ARCHIVE_MODE )
857+
858+ val fossId = createFossId(config)
859+
860+ val summary = fossId.scan(createPackage(pkgId, vcsInfo), snippetChoices = emptyList()).summary
861+
862+ summary.issues.forAtLeastOne {
863+ it.message shouldBe " This scan has 1 file(s) pending identification in FossID. " +
864+ " Please review and resolve them at: https://www.example.org/fossid/index.html?action=scanview&sid=1"
865+ }
866+
867+ summary.issues.filter { it.severity > Severity .HINT } should beEmpty()
868+ summary.snippetFindings shouldHaveSize 2
869+ summary.snippetFindings.first().apply {
870+ sourceLocation.path shouldBe FILE_1
871+ snippets shouldHaveSize 2
872+ snippets.map { it.purl } shouldBe listOf(PURL_1 , PURL_2 )
873+ }
874+
875+ summary.snippetFindings.last().apply {
876+ sourceLocation.path shouldBe FILE_1
877+ snippets shouldHaveSize 1
878+ snippets.map { it.purl } shouldBe listOf(PURL_3 )
879+ }
880+
881+ coVerify {
882+ service.removeUploadedContent(USER , API_KEY , scanCode)
883+ service.uploadFile(USER , API_KEY , scanCode, any())
884+ service.extractArchives(USER , API_KEY , scanCode, any())
885+ service.unmarkAsIdentified(USER , API_KEY , scanCode, FILE_1_ARCHIVE_MODE , any())
886+ }
887+ }
888+
778889 " put a marked as identified file back to pending if some of its snippet choices have been deleted" {
779890 val projectCode = PROJECT
780891 val scanCode = scanCode(PROJECT , null)
0 commit comments