Skip to content
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
5 changes: 5 additions & 0 deletions src/frameworks/android/android-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const ANDROID_AGENT_CONFIG: FrameworkConfig<AndroidContext> = {
detect: async (options) => {
const { installDir } = options;

// pubspec.yaml means Flutter — its android/ subtree would match below.
if (fs.existsSync(path.join(installDir, 'pubspec.yaml'))) {
return false;
}

// Strategy 1: Check for build.gradle(.kts) with Android plugin
for (const name of ['build.gradle', 'build.gradle.kts']) {
const buildGradlePath = path.join(installDir, name);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ export enum Integration {
android = 'android',
rails = 'rails',

// Language fallbacks
// Language fallbacks. Keep javascriptNode last: it matches any package.json.
python = 'python',
ruby = 'ruby',
javascriptNode = 'javascript_node',
javascript_web = 'javascript_web',
javascriptNode = 'javascript_node',
}

export interface Args {
Expand Down
136 changes: 136 additions & 0 deletions src/lib/detection/__tests__/framework.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { detectFramework } from '@lib/detection/framework';
import { Integration } from '@lib/constants';
import { ANDROID_AGENT_CONFIG } from '../../../frameworks/android/android-wizard-agent';

/** A throwaway project dir seeded with the given files. */
function makeProject(files: Record<string, string>): string {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'wizard-detect-'));
for (const [rel, content] of Object.entries(files)) {
const abs = path.join(dir, rel);
fs.mkdirSync(path.dirname(abs), { recursive: true });
fs.writeFileSync(abs, content);
}
return dir;
}

const tmpDirs: string[] = [];
function project(files: Record<string, string>): { installDir: string } {
const dir = makeProject(files);
tmpDirs.push(dir);
return { installDir: dir };
}

afterAll(() => {
for (const dir of tmpDirs) {
fs.rmSync(dir, { recursive: true, force: true });
}
});

describe('Integration enum order (drives first-match detection)', () => {
const order = Object.values(Integration);
const fallbacks = [
Integration.python,
Integration.ruby,
Integration.javascript_web,
Integration.javascriptNode,
];

test('every language fallback comes after every framework', () => {
const firstFallback = Math.min(...fallbacks.map((f) => order.indexOf(f)));
const lastFramework = Math.max(
...order
.filter((i) => !fallbacks.includes(i))
.map((i) => order.indexOf(i)),
);
expect(firstFallback).toBeGreaterThan(lastFramework);
});

test('generic Node is the last resort of the entire detection', () => {
// javascriptNode matches any package.json; anything after it is unreachable.
expect(order[order.length - 1]).toBe(Integration.javascriptNode);
});
});

describe('detectFramework (end-to-end over real project dirs)', () => {
test('a framework beats the fallbacks even though package.json matches Node', async () => {
const opts = project({
'package.json': JSON.stringify({
dependencies: { next: '^16', react: '^19' },
}),
'package-lock.json': '{}',
});
await expect(detectFramework(opts.installDir)).resolves.toBe(
Integration.nextjs,
);
});

test('a Vite React app resolves to javascript_web, not javascript_node', async () => {
const opts = project({
'package.json': JSON.stringify({
dependencies: { react: '^19', 'react-dom': '^19' },
devDependencies: { vite: '^6' },
}),
'package-lock.json': '{}',
'vite.config.ts': 'export default {}',
'index.html': '<html></html>',
});
await expect(detectFramework(opts.installDir)).resolves.toBe(
Integration.javascript_web,
);
});

test('a plain browser app (lockfile + index.html, no bundler) resolves to javascript_web', async () => {
const opts = project({
'package.json': JSON.stringify({ dependencies: {} }),
'package-lock.json': '{}',
'index.html': '<html></html>',
});
await expect(detectFramework(opts.installDir)).resolves.toBe(
Integration.javascript_web,
);
});

test('a server-side Node project still falls through to javascript_node', async () => {
const opts = project({
'package.json': JSON.stringify({ dependencies: { express: '^4' } }),
'package-lock.json': '{}',
});
await expect(detectFramework(opts.installDir)).resolves.toBe(
Integration.javascriptNode,
);
});

test('a Flutter project is not claimed by anything', async () => {
const opts = project({
'pubspec.yaml': 'name: my_flutter_app\nenvironment:\n sdk: ^3.0.0\n',
'android/build.gradle': `plugins { id 'com.android.application' }`,
'android/app/src/main/AndroidManifest.xml': '<manifest/>',
'android/app/src/main/kotlin/MainActivity.kt': 'class MainActivity',
});
await expect(detectFramework(opts.installDir)).resolves.toBeUndefined();
});
});

describe('android detect', () => {
const detect = ANDROID_AGENT_CONFIG.detection.detect;

const androidGradle = `plugins { id 'com.android.application' }`;

test('claims a native Android project', async () => {
const opts = project({ 'build.gradle': androidGradle });
await expect(detect(opts)).resolves.toBe(true);
});

test('does not claim a Flutter project despite its android/ subtree', async () => {
const opts = project({
'pubspec.yaml': 'name: my_flutter_app\nenvironment:\n sdk: ^3.0.0\n',
'android/build.gradle': androidGradle,
'android/app/src/main/AndroidManifest.xml': '<manifest/>',
'android/app/src/main/kotlin/MainActivity.kt': 'class MainActivity',
});
await expect(detect(opts)).resolves.toBe(false);
});
});
Loading