Skip to content

Commit 3b3a393

Browse files
authored
Fix OSS Parse Tests (#372)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent b6141d7 commit 3b3a393

File tree

9 files changed

+35
-37
lines changed

9 files changed

+35
-37
lines changed

src/codegen/sdk/codebase/codebase_graph.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
logger = logging.getLogger(__name__)
5252

5353

54-
GLOBAL_FILE_IGNORE_LIST = [".git/*", ".yarn/releases/*", ".*/tests/static/chunk-.*.js", ".*/ace/.*.js"]
54+
# src/vs/platform/contextview/browser/contextMenuService.ts is ignored as there is a parsing error with tree-sitter
55+
GLOBAL_FILE_IGNORE_LIST = [".git/*", ".yarn/releases/*", ".*/tests/static/chunk-.*.js", ".*/ace/.*.js", "src/vs/platform/contextview/browser/contextMenuService.ts"]
5556

5657

5758
@unique

src/codegen/sdk/codebase/validation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ class PostInitValidationStatus(StrEnum):
3030

3131
def post_init_validation(codebase: CodebaseType) -> PostInitValidationStatus:
3232
"""Post codebase._init_graph verifies that the built graph is valid."""
33+
from codegen.sdk.codebase.codebase_graph import GLOBAL_FILE_IGNORE_LIST
34+
3335
# Verify the graph has nodes
3436
if len(codebase.G.nodes) == 0:
3537
return PostInitValidationStatus.NO_NODES
3638

3739
# Verify the graph has the same number of files as there are in the repo
38-
if len(codebase.files) != len(codebase.op.list_files(codebase.G.projects[0].subdirectories, extensions=codebase.G.extensions)):
40+
if len(codebase.files) != len(list(codebase.op.iter_files(codebase.G.projects[0].subdirectories, extensions=codebase.G.extensions, ignore_list=GLOBAL_FILE_IGNORE_LIST))):
3941
return PostInitValidationStatus.MISSING_FILES
4042

4143
# Verify import resolution

src/codegen/sdk/core/detached_symbols/function_call.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,15 @@ def function_definition_frames(self) -> list[ResolutionStack[Callable]]:
424424
from codegen.sdk.core.interfaces.callable import Callable
425425

426426
result = []
427-
for resolution in self.get_name().resolved_type_frames:
428-
top_node = resolution.top.node
429-
if isinstance(top_node, Callable):
430-
if isinstance(top_node, Class):
431-
if constructor := top_node.constructor:
432-
result.append(resolution.with_new_base(constructor, direct=True))
433-
continue
434-
result.append(resolution)
427+
if self.get_name():
428+
for resolution in self.get_name().resolved_type_frames:
429+
top_node = resolution.top.node
430+
if isinstance(top_node, Callable):
431+
if isinstance(top_node, Class):
432+
if constructor := top_node.constructor:
433+
result.append(resolution.with_new_base(constructor, direct=True))
434+
continue
435+
result.append(resolution)
435436
return result
436437

437438
@cached_property
@@ -546,15 +547,16 @@ def _compute_dependencies(self, usage_type: UsageKind, dest: HasName | None = No
546547
if desc := self.child_by_field_name("type_arguments"):
547548
desc._compute_dependencies(UsageKind.GENERIC, dest)
548549
match = self.get_name()
549-
if len(self.function_definition_frames) > 0:
550-
if isinstance(match, ChainedAttribute):
551-
match.object._compute_dependencies(usage_type, dest)
552-
if isinstance(match, FunctionCall):
550+
if match:
551+
if len(self.function_definition_frames) > 0:
552+
if isinstance(match, ChainedAttribute):
553+
match.object._compute_dependencies(usage_type, dest)
554+
if isinstance(match, FunctionCall):
555+
match._compute_dependencies(usage_type, dest)
556+
for definition in self.function_definition_frames:
557+
definition.add_usage(match=self, dest=dest, usage_type=usage_type, G=self.G)
558+
else:
553559
match._compute_dependencies(usage_type, dest)
554-
for definition in self.function_definition_frames:
555-
definition.add_usage(match=self, dest=dest, usage_type=usage_type, G=self.G)
556-
else:
557-
match._compute_dependencies(usage_type, dest)
558560

559561
@property
560562
@reader

src/codegen/sdk/core/expressions/chained_attribute.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,17 @@ def object(self) -> Object:
8989
@noapidoc
9090
@override
9191
def _resolved_types(self) -> Generator[ResolutionStack[Self], None, None]:
92+
from codegen.sdk.typescript.namespace import TSNamespace
93+
9294
if not self.G.config.feature_flags.method_usages:
9395
return
9496
if res := self.file.valid_import_names.get(self.full_name, None):
9597
# Module imports
9698
yield from self.with_resolution_frame(res)
9799
return
100+
# HACK: This is a hack to skip the resolved types for namespaces
101+
if isinstance(self.object, TSNamespace):
102+
return
98103
for resolved_type in self.object.resolved_type_frames:
99104
top = resolved_type.top
100105
if not isinstance(top.node, HasAttribute):

src/codegen/sdk/typescript/ts_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ def _precompute_import_aliases(self):
163163
cleaned_relative_path = relative_path.replace("*", "").rstrip("/").replace("//", "/")
164164
if self._self_base_url:
165165
cleaned_relative_path = os.path.join(self._self_base_url, cleaned_relative_path)
166-
formatted_relative_path = str(self.config_file.G.to_relative(self._relative_to_absolute_directory_path(cleaned_relative_path)))
166+
formatted_absolute_path = self._relative_to_absolute_directory_path(cleaned_relative_path)
167+
formatted_relative_path = str(self.config_file.G.to_relative(formatted_absolute_path))
168+
# Fix absolute path if its base
169+
if formatted_relative_path == ".":
170+
formatted_relative_path = ""
167171
formatted_relative_paths.append(formatted_relative_path)
168172
self_path_import_aliases[formatted_pattern] = formatted_relative_paths
169173
self._path_import_aliases = {**base_path_import_aliases, **self_path_import_aliases}

tests/integration/codemod/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def pytest_generate_tests(metafunc: Metafunc) -> None:
8080
scope="session",
8181
)
8282
case "test_codemods_parse":
83-
excluded_repos = {"typeshed", "plone", "papermark", "vscode"} # TODO(CG-10655): fix these reps
84-
to_test = {name: repo for name, repo in repos.items() if name not in excluded_repos}
83+
to_test = {name: repo for name, repo in repos.items()}
8584
metafunc.parametrize(
8685
"repo",
8786
[pytest.param(repo, marks=pytest.mark.xdist_group(repo.name)) for repo in to_test.values()],

tests/integration/codemod/repos/open_source/plone.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/integration/codemod/repos/open_source/typeshed.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/integration/codemod/repos/open_source/vscode.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vscode",
3-
"commit": "9c79e7322af656155bbc9b64341334d3a8269bc8",
3+
"commit": "32a41e158d04c9777522dc567574f2a74b8f2bf9",
44
"url": "https://github.com/microsoft/vscode",
55
"language": "TYPESCRIPT",
66
"size": "large",

0 commit comments

Comments
 (0)