Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void resolveFromCliPathReturnsAbsolutePathForRelativeCliPath(@TempDir Path tempD

@Test
void cliPathOverrideTakesPriorityOverClasspathExtraction(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
// Create a valid runtime.node alongside the fake CLI path
Path fakeCliDir = tempDir.resolve("cli-dir");
Files.createDirectories(fakeCliDir);
Expand All @@ -193,6 +194,7 @@ void cliPathOverrideTakesPriorityOverClasspathExtraction(@TempDir Path tempDir)

@Test
void extractToCacheCopiesResourceToVersionedCacheDirectory(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader loader = classLoaderWithRuntimeResource(tempDir, TEST_CLASSIFIER);

Expand All @@ -207,6 +209,7 @@ void extractToCacheCopiesResourceToVersionedCacheDirectory(@TempDir Path tempDir

@Test
void extractToCacheReturnsCachedFileOnSecondCall(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader loader = classLoaderWithRuntimeResource(tempDir, TEST_CLASSIFIER);

Expand All @@ -226,6 +229,7 @@ void extractToCacheReturnsCachedFileOnSecondCall(@TempDir Path tempDir) throws E

@Test
void changedNativeVersionDoesNotReuseCachedArtifactsForSameSdkVersion(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader firstLoader = classLoaderWithNativeArtifacts(tempDir.resolve("native-v1"), TEST_CLASSIFIER, "1.0.0",
FAKE_BINARY_CONTENT, FAKE_CLI_CONTENT);
Expand All @@ -246,6 +250,7 @@ void changedNativeVersionDoesNotReuseCachedArtifactsForSameSdkVersion(@TempDir P

@Test
void extractToCacheThrowsWhenClasspathResourceMissing(@TempDir Path tempDir) {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader emptyLoader = new URLClassLoader(new URL[0], null);

Expand All @@ -255,6 +260,7 @@ void extractToCacheThrowsWhenClasspathResourceMissing(@TempDir Path tempDir) {

@Test
void extractToCacheThrowsWhenNativeMetadataMissing(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path resourceDir = tempDir.resolve("native").resolve(TEST_CLASSIFIER);
Files.createDirectories(resourceDir);
Files.write(resourceDir.resolve(NativeRuntimeLoader.RUNTIME_FILENAME), FAKE_BINARY_CONTENT);
Expand All @@ -268,6 +274,7 @@ void extractToCacheThrowsWhenNativeMetadataMissing(@TempDir Path tempDir) throws

@Test
void extractedBinaryContentsMatchClasspathResource(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader loader = classLoaderWithRuntimeResource(tempDir, TEST_CLASSIFIER);

Expand All @@ -279,6 +286,7 @@ void extractedBinaryContentsMatchClasspathResource(@TempDir Path tempDir) throws

@Test
void extractToCacheFiltersClasspathByClassifier(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
writeRuntimeResource(tempDir, TEST_CLASSIFIER, FAKE_BINARY_CONTENT);
writeRuntimeResource(tempDir, OTHER_CLASSIFIER, OTHER_BINARY_CONTENT);
Expand All @@ -292,6 +300,7 @@ void extractToCacheFiltersClasspathByClassifier(@TempDir Path tempDir) throws Ex

@Test
void extractToCacheRepairsInvalidCacheEntry(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
Path cached = cacheBase.resolve(TEST_VERSION).resolve(TEST_NATIVE_VERSION).resolve(TEST_CLASSIFIER)
.resolve(NativeRuntimeLoader.RUNTIME_FILENAME);
Expand All @@ -307,6 +316,7 @@ void extractToCacheRepairsInvalidCacheEntry(@TempDir Path tempDir) throws Except

@Test
void nonExecutableCachedCliIsNotAcceptedAsValid(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
assumeTrue(Files.getFileStore(tempDir).supportsFileAttributeView("posix"));
Path cacheBase = tempDir.resolve("cache");
Path cacheDir = cacheBase.resolve(TEST_VERSION).resolve(TEST_NATIVE_VERSION).resolve(TEST_CLASSIFIER);
Expand All @@ -327,6 +337,7 @@ void nonExecutableCachedCliIsNotAcceptedAsValid(@TempDir Path tempDir) throws Ex

@Test
void bundledCliSiblingIsUsedWhenClasspathResourceAbsent(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path bundledCliDir = tempDir.resolve("bundled-cli");
Files.createDirectories(bundledCliDir);
Path runtimeNode = bundledCliDir.resolve(NativeRuntimeLoader.RUNTIME_FILENAME);
Expand All @@ -344,6 +355,7 @@ void bundledCliSiblingIsUsedWhenClasspathResourceAbsent(@TempDir Path tempDir) t

@Test
void classpathResourceWinsOverBundledCliSibling(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
// Source 3: bundled CLI dir with runtime.node (should NOT win)
Path bundledCliDir = tempDir.resolve("bundled-cli");
Files.createDirectories(bundledCliDir);
Expand All @@ -365,6 +377,7 @@ void classpathResourceWinsOverBundledCliSibling(@TempDir Path tempDir) throws Ex

@Test
void bundledCliSiblingIsIgnoredWhenRuntimeNodeMissing(@TempDir Path tempDir) {
assumeLinuxX64();
Path bundledCliDir = tempDir.resolve("bundled-cli-no-runtime");
// bundledCliDir doesn't even exist — no runtime.node present

Expand Down Expand Up @@ -396,6 +409,7 @@ void defaultPublisherMovesSourceToTarget(@TempDir Path tempDir) throws Exception

@Test
void cliIsExecutableBeforeAtomicPublication(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
assumeTrue(Files.getFileStore(tempDir).supportsFileAttributeView("posix"));
Path cacheBase = tempDir.resolve("cache");
ClassLoader loader = classLoaderWithRuntimeAndCliResources(tempDir, TEST_CLASSIFIER);
Expand All @@ -411,6 +425,7 @@ void cliIsExecutableBeforeAtomicPublication(@TempDir Path tempDir) throws Except

@Test
void extractionCleansUpTempFileWhenPublicationFails(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader loader = classLoaderWithRuntimeResource(tempDir, TEST_CLASSIFIER);

Expand All @@ -431,6 +446,7 @@ void extractionCleansUpTempFileWhenPublicationFails(@TempDir Path tempDir) throw

@Test
void extractionCleansUpTempFileWhenPublisherThrowsIllegalStateException(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader loader = classLoaderWithRuntimeResource(tempDir, TEST_CLASSIFIER);

Expand Down Expand Up @@ -458,6 +474,7 @@ void extractionCleansUpTempFileWhenPublisherThrowsIllegalStateException(@TempDir

@Test
void concurrentExtractionByMultipleThreadsBothSucceed(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader loader = classLoaderWithRuntimeResource(tempDir, TEST_CLASSIFIER);
int threadCount = 8;
Expand Down Expand Up @@ -495,6 +512,7 @@ void concurrentExtractionByMultipleThreadsBothSucceed(@TempDir Path tempDir) thr

@Test
void resolveWithNullCliEnvExtractsFromClasspath(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader loader = classLoaderWithRuntimeResource(tempDir, TEST_CLASSIFIER);

Expand All @@ -507,6 +525,7 @@ void resolveWithNullCliEnvExtractsFromClasspath(@TempDir Path tempDir) throws Ex

@Test
void resolveThrowsWhenNoSourceIsAvailable(@TempDir Path tempDir) {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader emptyLoader = new URLClassLoader(new URL[0], null);

Expand All @@ -517,6 +536,7 @@ void resolveThrowsWhenNoSourceIsAvailable(@TempDir Path tempDir) {

@Test
void resolveFallsBackToRuntimeAlongsideBundledCli(@TempDir Path tempDir) throws Exception {
assumeLinuxX64();
Path cacheBase = tempDir.resolve("cache");
ClassLoader emptyLoader = new URLClassLoader(new URL[0], null);
Path bundledCli = tempDir.resolve("copilot");
Expand All @@ -534,6 +554,17 @@ void resolveFallsBackToRuntimeAlongsideBundledCli(@TempDir Path tempDir) throws
// Helpers
// -------------------------------------------------------------------------

private static void assumeLinuxX64() {
String actualClassifier;
try {
actualClassifier = PlatformDetector.detectClassifier();
} catch (IllegalStateException ex) {
actualClassifier = "unsupported";
}
assumeTrue(TEST_CLASSIFIER.equals(actualClassifier),
"Requires linux-x64; detected " + actualClassifier + "; see #2323");
Comment thread
edburns marked this conversation as resolved.
}

private static ClassLoader classLoaderWithVersionResource(Path tempDir, String version) throws IOException {
Path propsFile = tempDir.resolve(NativeRuntimeLoader.VERSION_RESOURCE);
Files.writeString(propsFile, "version=" + version + "\n");
Expand Down
Loading