-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add duplicate file analysis for Android #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
from pydantic import ConfigDict, Field | ||
from pydantic import BaseModel, ConfigDict, Field | ||
|
||
from .common import BaseAnalysisResults, BaseAppInfo | ||
from .insights import DuplicateFilesInsightResult | ||
|
||
|
||
class AndroidAppInfo(BaseAppInfo): | ||
model_config = ConfigDict(frozen=True) | ||
package_name: str = Field(..., description="Android package name") | ||
|
||
|
||
class AndroidAnalysisResults(BaseAnalysisResults): | ||
"""Complete Android analysis results.""" | ||
class AndroidInsightResults(BaseModel): | ||
model_config = ConfigDict(frozen=True) | ||
|
||
duplicate_files: DuplicateFilesInsightResult | None = Field(None, description="Duplicate files analysis") | ||
|
||
|
||
class AndroidAnalysisResults(BaseAnalysisResults): | ||
model_config = ConfigDict(frozen=True) | ||
app_info: AndroidAppInfo = Field(..., description="Android app information") | ||
insights: AndroidInsightResults | None = Field( | ||
description="Generated insights from the analysis", | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Tests for Android analyzer with duplicate file detection.""" | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from launchpad.analyzers.android import AndroidAnalyzer | ||
from launchpad.artifacts.artifact_factory import ArtifactFactory | ||
|
||
|
||
@pytest.fixture | ||
def test_apk_path() -> Path: | ||
return Path("tests/_fixtures/android/hn.apk") | ||
|
||
|
||
@pytest.fixture | ||
def android_analyzer() -> AndroidAnalyzer: | ||
return AndroidAnalyzer() | ||
|
||
|
||
class TestAndroidAnalyzer: | ||
def test_analyze_with_duplicate_detection(self, test_apk_path: Path, android_analyzer: AndroidAnalyzer) -> None: | ||
"""Test that Android analyzer includes duplicate file detection.""" | ||
artifact = ArtifactFactory.from_path(test_apk_path) | ||
results = android_analyzer.analyze(artifact) | ||
|
||
assert results.app_info.name == "Hacker News" | ||
assert results.app_info.package_name == "com.emergetools.hackernews" | ||
assert results.file_analysis is not None | ||
assert len(results.file_analysis.files) > 0 | ||
|
||
assert results.insights is not None | ||
assert results.insights.duplicate_files is not None | ||
|
||
duplicate_insight = results.insights.duplicate_files | ||
assert hasattr(duplicate_insight, "files") | ||
assert hasattr(duplicate_insight, "total_savings") | ||
assert hasattr(duplicate_insight, "duplicate_count") | ||
assert isinstance(duplicate_insight.total_savings, int) | ||
assert isinstance(duplicate_insight.duplicate_count, int) | ||
assert duplicate_insight.total_savings == 51709 | ||
assert duplicate_insight.duplicate_count == 52 | ||
|
||
def test_duplicate_files_have_hashes(self, test_apk_path: Path, android_analyzer: AndroidAnalyzer) -> None: | ||
"""Test that all files have MD5 hashes for duplicate detection.""" | ||
artifact = ArtifactFactory.from_path(test_apk_path) | ||
results = android_analyzer.analyze(artifact) | ||
|
||
for file_info in results.file_analysis.files: | ||
assert file_info.hash_md5 is not None | ||
assert len(file_info.hash_md5) > 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turns out there were some dupes in hn.apk. it is mostly duplicated META-INF files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be curious how users can remove those, if they can't remove them or mitigate we should try to add ignores on our end to not show. Any idea behind these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! Here’s how you can remove them: EmergeTools/hackernews#489
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appears this would just filter out the META-INF/ files, not just duplicates? I don't think that's what we'd want to do here as I know some tools package files in there for tooling & runtime analysis.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah you're right. the kotlin
.module
files are important.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the PR to just remove the duplicate
.version
files and the duplicateLICENSE.txt
files. This way it keeps the.module
files which are needed. (and also the.module
files were not duplicates)