Skip to content

Commit c26fed8

Browse files
author
Hamed Soleimani
committed
fix tests
1 parent a258118 commit c26fed8

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererProjectCodeScanTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,6 @@ class CodeWhispererProjectCodeScanTest : CodeWhispererCodeScanTestBase(PythonCod
372372
// Adding gitignore file and gitignore file member for testing.
373373
// The tests include the markdown file but not these two files.
374374
projectRule.fixture.addFileToProject("/.gitignore", "node_modules\n.idea\n.vscode\n.DS_Store").virtualFile
375-
projectRule.fixture.addFileToProject("test.idea", "ref: refs/heads/main")
375+
projectRule.fixture.addFileToProject("/.idea/ref", "ref: refs/heads/main")
376376
}
377377
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,33 @@ class RepoSizeLimitError(override val message: String) : RuntimeException(), Rep
4747
class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Long? = null) {
4848
// TODO: Need to correct this class location in the modules going further to support both amazonq and codescan.
4949

50-
private val ignorePatterns = setOf(
51-
"\\.aws-sam",
52-
"\\.svn",
53-
"\\.hg/?",
54-
"\\.rvm",
55-
"\\.git/?",
56-
"\\.gitignore",
57-
"\\.project",
58-
"\\.gem",
59-
"/\\.idea/?",
60-
"\\.zip$",
61-
"\\.bin$",
62-
"\\.png$",
63-
"\\.jpg$",
64-
"\\.svg$",
65-
"\\.pyc$",
66-
"/license\\.txt$",
67-
"/License\\.txt$",
68-
"/LICENSE\\.txt$",
69-
"/license\\.md$",
70-
"/License\\.md$",
71-
"/LICENSE\\.md$",
72-
"node_modules/?",
73-
"build/?",
74-
"dist/?"
75-
).map { Regex(it) }
50+
private val additionalGitIgnoreRules = setOf(
51+
".aws-sam",
52+
".gem",
53+
".git",
54+
".gitignore",
55+
".gradle",
56+
".hg",
57+
".idea",
58+
".project",
59+
".rvm",
60+
".svn",
61+
"*.zip",
62+
"*.bin",
63+
"*.png",
64+
"*.jpg",
65+
"*.svg",
66+
"*.pyc",
67+
"license.txt",
68+
"License.txt",
69+
"LICENSE.txt",
70+
"license.md",
71+
"License.md",
72+
"LICENSE.md",
73+
"node_modules",
74+
"build",
75+
"dist"
76+
)
7677

7778
// well known source files that do not have extensions
7879
private val wellKnownSourceFiles = setOf(
@@ -88,6 +89,7 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
8889

8990
// projectRoot: is the directory where the project is located when selected to open a project.
9091
val projectRoot = project.guessProjectDir() ?: error("Cannot guess base directory for project ${project.name}")
92+
private val projectRootPath = Paths.get(projectRoot.path) ?: error("Can not find project root path")
9193

9294
// selectedSourceFolder": is the directory selected in replacement of the root, this happens when the project is too big to bundle for uploading.
9395
private var _selectedSourceFolder = projectRoot
@@ -97,10 +99,10 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
9799
init {
98100
ignorePatternsWithGitIgnore = try {
99101
buildList {
100-
addAll(ignorePatterns)
101-
parseGitIgnore().mapNotNull { pattern ->
102-
runCatching { Regex(pattern) }.getOrNull()
103-
}.let { addAll(it) }
102+
addAll(additionalGitIgnoreRules.map { convertGitIgnorePatternToRegex(it) })
103+
addAll(parseGitIgnore())
104+
}.mapNotNull { pattern ->
105+
runCatching { Regex(pattern) }.getOrNull()
104106
}
105107
} catch (e: Exception) {
106108
emptyList()
@@ -142,7 +144,8 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
142144
// we convert the glob rules to regex, add a trailing /* to all rules and then match
143145
// entries against them by adding a trailing /.
144146
// TODO: Add unit tests for gitignore matching
145-
async { pattern.matches("$path/") }
147+
val relative = if (path.startsWith(projectRootPath.toString())) Paths.get(path).relativeTo(projectRootPath) else path
148+
async { pattern.matches("$relative/") }
146149
}
147150
}
148151

@@ -212,9 +215,9 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
212215
if (!file.isDirectory) {
213216
val externalFilePath = Path(file.path)
214217
val externalFilePermissions = externalFilePath.getPosixFilePermissions()
215-
val relativePath = Path(file.path).relativeTo(projectRoot.toNioPath())
218+
val relativePath = Path(file.path).relativeTo(projectRootPath)
216219
val zipfsPath = zipfs.getPath("/$relativePath")
217-
withContext(getCoroutineBgContext()) {
220+
withContext(EDT) {
218221
zipfsPath.createParentDirectories()
219222
Files.copy(externalFilePath, zipfsPath, StandardCopyOption.REPLACE_EXISTING)
220223
Files.setAttribute(zipfsPath, "zip:permissions", externalFilePermissions)

0 commit comments

Comments
 (0)