PY-79488 Add a test on removing the fake top-level module on model sync

GitOrigin-RevId: 910bad221ec0342c10dfe75908418174814f1392
This commit is contained in:
Mikhail Golubev
2025-05-12 15:50:13 +00:00
committed by intellij-monorepo-bot
parent 8cc9b6ed97
commit 4de911624f
2 changed files with 30 additions and 0 deletions
@@ -124,6 +124,8 @@ abstract class BaseProjectModelService<E : EntitySource> {
/**
* Removes the default IJ module created for the root of the project
* (that's going to be replaced with a module belonging to a specific project management system).
*
* @see com.intellij.platform.PlatformProjectConfigurator
*/
fun removeFakeModuleEntity(project: Project, storage: MutableEntityStorage) {
val virtualFileUrlManager = project.workspaceModel.getVirtualFileUrlManager()
@@ -4,6 +4,7 @@ package com.jetbrains.python.projectModel.uv
import com.intellij.openapi.components.service
import com.intellij.openapi.externalSystem.testFramework.fixtures.multiProjectFixture
import com.intellij.platform.testFramework.assertion.collectionAssertion.CollectionAssertions
import com.intellij.platform.testFramework.assertion.moduleAssertion.ContentRootAssertions
import com.intellij.platform.testFramework.assertion.moduleAssertion.DependencyAssertions
import com.intellij.platform.testFramework.assertion.moduleAssertion.ModuleAssertions
import com.intellij.testFramework.common.timeoutRunBlocking
@@ -74,6 +75,33 @@ class PyUvOpenIntegrationTest {
}
}
@Test
fun `manually syncing a not recognized project removes its fake top-level module`() = timeoutRunBlocking(timeout = 20.seconds) {
val projectPath = testRoot.resolve("project")
projectPath.createFile("pyproject.toml").writeText("""
[project]
name = "myproject"
""".trimIndent())
multiprojectFixture.openProject(projectPath).useProjectAsync { project ->
// Nothing was linked automatically. There is only the module created by PlatformProjectConfigurator.
ModuleAssertions.assertModules(project, "project")
ContentRootAssertions.assertContentRoots(project, "project", listOf(projectPath))
CollectionAssertions.assertEqualsUnordered(emptyList(), project.service<UvSettings>().getLinkedProjects())
multiprojectFixture.awaitProjectConfiguration(project) {
UvProjectModelService.linkAllProjectModelRoots(project, project.basePath!!)
UvProjectModelService.syncAllProjectModelRoots(project)
}
// Now there is only the module owned by Uv
ModuleAssertions.assertModules(project, "myproject")
CollectionAssertions.assertEqualsUnordered(listOf(projectPath), project.service<UvSettings>().getLinkedProjects())
ContentRootAssertions.assertContentRoots(project, "myproject", listOf(projectPath))
}
}
@Test
fun `test monorepo without top-level pyproject-toml and with sibling path dependency`() = timeoutRunBlocking(timeout = 20.seconds) {
val projectPath = testRoot.resolve("project")