Skip to content
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

Bundle analysis: [GQL] Add asset routes to BundleAsset type #1010

Merged
merged 6 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 156 additions & 23 deletions graphql_api/tests/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3267,7 +3267,7 @@ def test_bundle_analysis_asset_routes(self, get_storage_service):
)

with open(
"./services/tests/samples/bundle_with_assets_and_modules.sqlite", "rb"
"./services/tests/samples/bundle_with_asset_routes.sqlite", "rb"
) as f:
storage_path = StoragePaths.bundle_report.path(
repo_key=ArchiveService.get_archive_hash(self.repo),
Expand All @@ -3285,8 +3285,8 @@ def test_bundle_analysis_asset_routes(self, get_storage_service):
bundleAnalysisReport {
__typename
... on BundleAnalysisReport {
bundle(name: "b5") {
asset(name: "assets/LazyComponent-fcbb0922.js") {
bundle(name: "@codecov/example-sveltekit-app-client-esm") {
assets {
name
normalizedName
routes
Expand All @@ -3310,18 +3310,151 @@ def test_bundle_analysis_asset_routes(self, get_storage_service):
data = self.gql_request(query, variables=variables)
commit = data["owner"]["repository"]["commit"]

asset_report = commit["bundleAnalysis"]["bundleAnalysisReport"]["bundle"][
"asset"
asset_reports = commit["bundleAnalysis"]["bundleAnalysisReport"]["bundle"][
"assets"
]

assert asset_report is not None
assert asset_report["name"] == "assets/LazyComponent-fcbb0922.js"
assert asset_report["normalizedName"] == "assets/LazyComponent-*.js"
assert asset_report["routes"] == [
"/",
"/about",
"/login",
"/super/long/url/path",
assert asset_reports == [
{
"name": "_app/immutable/assets/svelte-welcome.VNiyy3gC.png",
"normalizedName": "_app/immutable/assets/svelte-welcome.*.png",
"routes": [],
},
{
"name": "_app/immutable/assets/svelte-welcome.0pIiHnVF.webp",
"normalizedName": "_app/immutable/assets/svelte-welcome.*.webp",
"routes": [],
},
{
"name": "_app/immutable/assets/fira-mono-all-400-normal.B2mvLtSD.woff",
"normalizedName": "_app/immutable/assets/fira-mono-all-400-normal.*.woff",
"routes": [],
},
{
"name": "_app/immutable/chunks/entry.BaWB2kHj.js",
"normalizedName": "_app/immutable/chunks/entry.*.js",
"routes": [],
},
{
"name": "_app/immutable/nodes/4.CcjRtXvw.js",
"normalizedName": "_app/immutable/nodes/4.*.js",
"routes": ["/sverdle"],
},
{
"name": "_app/immutable/assets/fira-mono-latin-400-normal.DKjLVgQi.woff2",
"normalizedName": "_app/immutable/assets/fira-mono-latin-400-normal.*.woff2",
"routes": [],
},
{
"name": "_app/immutable/assets/fira-mono-cyrillic-ext-400-normal.B04YIrm4.woff2",
"normalizedName": "_app/immutable/assets/fira-mono-cyrillic-ext-400-normal.*.woff2",
"routes": [],
},
{
"name": "_app/immutable/assets/fira-mono-latin-ext-400-normal.D6XfiR-_.woff2",
"normalizedName": "_app/immutable/assets/fira-mono-latin-ext-400-normal.D6XfiR-_.woff2",
"routes": [],
},
{
"name": "_app/immutable/assets/fira-mono-greek-400-normal.C3zng6O6.woff2",
"normalizedName": "_app/immutable/assets/fira-mono-greek-400-normal.*.woff2",
"routes": [],
},
{
"name": "_app/immutable/assets/fira-mono-cyrillic-400-normal.36-45Uyg.woff2",
"normalizedName": "_app/immutable/assets/fira-mono-cyrillic-400-normal.*.woff2",
"routes": [],
},
{
"name": "_app/immutable/nodes/0.CL_S-12h.js",
"normalizedName": "_app/immutable/nodes/0.CL_S-12h.js",
"routes": ["/"],
},
{
"name": "_app/immutable/assets/fira-mono-greek-ext-400-normal.CsqI23CO.woff2",
"normalizedName": "_app/immutable/assets/fira-mono-greek-ext-400-normal.*.woff2",
"routes": [],
},
{
"name": "_app/immutable/chunks/index.DDRweiI9.js",
"normalizedName": "_app/immutable/chunks/index.*.js",
"routes": [],
},
{
"name": "_app/immutable/entry/app.Dd9ByE1Q.js",
"normalizedName": "_app/immutable/entry/app.*.js",
"routes": [],
},
{
"name": "_app/immutable/nodes/2.BMQFqo-e.js",
"normalizedName": "_app/immutable/nodes/2.*.js",
"routes": ["/"],
},
{
"name": "_app/immutable/assets/0.CT0x_Q5c.css",
"normalizedName": "_app/immutable/assets/0.CT0x_Q5c.css",
"routes": [],
},
{
"name": "_app/immutable/assets/4.DOkkq0IA.css",
"normalizedName": "_app/immutable/assets/4.*.css",
"routes": [],
},
{
"name": "_app/immutable/nodes/5.CwxmUzn6.js",
"normalizedName": "_app/immutable/nodes/5.*.js",
"routes": ["/sverdle/how-to-play"],
},
{
"name": "_app/immutable/chunks/scheduler.Dk-snqIU.js",
"normalizedName": "_app/immutable/chunks/scheduler.*.js",
"routes": [],
},
{
"name": "_app/immutable/nodes/3.BqQOub2U.js",
"normalizedName": "_app/immutable/nodes/3.*.js",
"routes": ["/about"],
},
{
"name": "_app/immutable/assets/2.Cs8KR-Bb.css",
"normalizedName": "_app/immutable/assets/2.*.css",
"routes": [],
},
{
"name": "_app/immutable/nodes/1.stWWSe4n.js",
"normalizedName": "_app/immutable/nodes/1.*.js",
"routes": [],
},
{
"name": "_app/immutable/assets/5.CU6psp88.css",
"normalizedName": "_app/immutable/assets/5.*.css",
"routes": [],
},
{
"name": "_app/immutable/chunks/index.Ice1EKvx.js",
"normalizedName": "_app/immutable/chunks/index.*.js",
"routes": [],
},
{
"name": "_app/immutable/chunks/stores.BrqGIpx3.js",
"normalizedName": "_app/immutable/chunks/stores.*.js",
"routes": [],
},
{
"name": "_app/immutable/entry/start.B1Q1eB84.js",
"normalizedName": "_app/immutable/entry/start.*.js",
"routes": [],
},
{
"name": "_app/immutable/chunks/index.R8ovVqwX.js",
"normalizedName": "_app/immutable/chunks/index.*.js",
"routes": [],
},
{
"name": "_app/version.json",
"normalizedName": "_app/version.json",
"routes": [],
},
]

@patch("graphql_api.dataloader.bundle_analysis.get_appropriate_storage_service")
Expand Down Expand Up @@ -3355,12 +3488,12 @@ def test_bundle_analysis_report_info(self, get_storage_service):
bundle(name: "b5") {
info {
version
plugin_name
plugin_version
built_at
pluginName
pluginVersion
builtAt
duration
bundler_name
bundler_version
bundlerName
bundlerVersion
}
}
}
Expand All @@ -3384,9 +3517,9 @@ def test_bundle_analysis_report_info(self, get_storage_service):
bundle_info = commit["bundleAnalysis"]["bundleAnalysisReport"]["bundle"]["info"]

assert bundle_info["version"] == "1"
assert bundle_info["plugin_name"] == "codecov-vite-bundle-analysis-plugin"
assert bundle_info["plugin_version"] == "1.0.0"
assert bundle_info["built_at"] == "2023-12-01 17:17:28.604000"
assert bundle_info["pluginName"] == "codecov-vite-bundle-analysis-plugin"
assert bundle_info["pluginVersion"] == "1.0.0"
assert bundle_info["builtAt"] == "2023-12-01 17:17:28.604000"
assert bundle_info["duration"] == 331
assert bundle_info["bundler_name"] == "rollup"
assert bundle_info["bundler_version"] == "3.29.4"
assert bundle_info["bundlerName"] == "rollup"
assert bundle_info["bundlerVersion"] == "3.29.4"
10 changes: 5 additions & 5 deletions graphql_api/types/bundle_analysis/base.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ type BundleAsset {

type BundleReportInfo {
version: String!
plugin_name: String!
plugin_version: String!
built_at: String!
pluginName: String!
pluginVersion: String!
builtAt: String!
duration: Int!
bundler_name: String!
bundler_version: String!
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any consumers of this api that need to be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question, nothing is using BundleReportInfo yet

bundlerName: String!
bundlerVersion: String!
}

type BundleReport {
Expand Down
12 changes: 6 additions & 6 deletions graphql_api/types/bundle_analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def resolve_asset_report_measurements(
def resolve_routes(
bundle_asset: AssetReport, info: GraphQLResolveInfo
) -> Optional[List[str]]:
return ["/", "/about", "/login", "/super/long/url/path"]
return bundle_asset.routes


# ============= Bundle Report Bindable =============
Expand Down Expand Up @@ -390,21 +390,21 @@ def resolve_bundle_report_info_version(
return bundle_report_info.version


@bundle_report_info_bindable.field("plugin_name")
@bundle_report_info_bindable.field("pluginName")
def resolve_bundle_report_info_plugin_name(
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
) -> str:
return bundle_report_info.plugin_name


@bundle_report_info_bindable.field("plugin_version")
@bundle_report_info_bindable.field("pluginVersion")
def resolve_bundle_report_info_plugin_version(
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
) -> str:
return bundle_report_info.plugin_version


@bundle_report_info_bindable.field("built_at")
@bundle_report_info_bindable.field("builtAt")
def resolve_bundle_report_info_built_at(
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
) -> str:
Expand All @@ -418,14 +418,14 @@ def resolve_bundle_report_info_duration(
return bundle_report_info.duration


@bundle_report_info_bindable.field("bundler_name")
@bundle_report_info_bindable.field("bundlerName")
def resolve_bundle_report_info_bundler_name(
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
) -> str:
return bundle_report_info.bundler_name


@bundle_report_info_bindable.field("bundler_version")
@bundle_report_info_bindable.field("bundlerVersion")
def resolve_bundle_report_info_bundler_version(
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
) -> str:
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ factory-boy
fakeredis
freezegun
https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
https://github.com/codecov/shared/archive/c481846ba657aee3fc15a613a0fd2c18ac1eabd2.tar.gz#egg=shared
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to be updated once the shared PR is merged into main
codecov/shared#443

https://github.com/codecov/shared/archive/00e90bb2085d3a54709328e9b3a39d578feb9992.tar.gz#egg=shared
google-cloud-pubsub
gunicorn>=22.0.0
https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ sentry-sdk[celery]==2.13.0
# shared
setproctitle==1.1.10
# via -r requirements.in
shared @ https://github.com/codecov/shared/archive/c481846ba657aee3fc15a613a0fd2c18ac1eabd2.tar.gz
shared @ https://github.com/codecov/shared/archive/00e90bb2085d3a54709328e9b3a39d578feb9992.tar.gz
# via -r requirements.in
simplejson==3.17.2
# via -r requirements.in
Expand Down
4 changes: 4 additions & 0 deletions services/bundle_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def modules(self) -> List[ModuleReport]:
def module_extensions(self) -> List[str]:
return list(set([module.extension for module in self.modules]))

@cached_property
def routes(self) -> Optional[List[str]]:
return self.asset.routes()


@dataclass
class BundleReport(object):
Expand Down
Binary file not shown.
Binary file modified services/tests/samples/head_bundle_report.sqlite
Binary file not shown.
Loading