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
105 changes: 4 additions & 101 deletions app/api/scan-repo/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import type {
RepoScanResponse,
RepoScanSummary,
RepoStructureSummary,
GitHubTreeItem,
PackageJson,
} from "@/types/repo-scan"
import { buildDependencyAnalysisTasks, hasDependencyDetectionRules } from "@/lib/stack-detection"
import type { DependencyAnalysisTask } from "@/lib/stack-detection"
import { loadStackQuestionMetadata, normalizeConventionValue } from "@/lib/question-metadata"
import { loadStackConventions } from "@/lib/conventions"
import { dependencyHas } from "@/lib/repo-scan/dependency-utils"
import { detectPythonTestingSignals } from "@/lib/repo-scan/python-testing-signals"
import { inferStackFromScan } from "@/lib/scan-to-wizard"
import { stackQuestion } from "@/lib/wizard-config"

Expand All @@ -20,33 +23,6 @@ const JSON_HEADERS = {
Accept: "application/vnd.github+json",
}

interface GitHubTreeItem {
path: string
type: "blob" | "tree" | string
}

interface PackageJson {
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
peerDependencies?: Record<string, string>
optionalDependencies?: Record<string, string>
engines?: { node?: string }
workspaces?: string[] | { packages?: string[] }
}

const dependencyHas = (pkg: PackageJson, names: string[]): boolean => {
const sources = [
pkg.dependencies,
pkg.devDependencies,
pkg.peerDependencies,
pkg.optionalDependencies,
]

return sources.some((source) =>
source ? names.some((name) => Object.prototype.hasOwnProperty.call(source, name)) : false,
)
}

const isNullishOrEmpty = (value: unknown): value is null | undefined | "" => value === null || value === undefined || value === ""

const extractRateLimitRemaining = (response: Response): number | null => {
Expand Down Expand Up @@ -292,79 +268,6 @@ const detectTooling = async (
}
}

type TestingConventionValues = {
unit: string[]
e2e: string[]
}

const testingConventionCache = new Map<string, TestingConventionValues>()

const getTestingConventionValues = async (stackId: string): Promise<TestingConventionValues> => {
const normalized = stackId.trim().toLowerCase()
if (testingConventionCache.has(normalized)) {
return testingConventionCache.get(normalized)!
}

const metadata = await loadStackQuestionMetadata(normalized)
const values: TestingConventionValues = {
unit: metadata.answersByResponseKey.testingUT ?? [],
e2e: metadata.answersByResponseKey.testingE2E ?? [],
}
testingConventionCache.set(normalized, values)
return values
}

const findConventionValue = (values: string[], target: string): string | null => {
const normalizedTarget = normalizeConventionValue(target)
return values.find((value) => normalizeConventionValue(value) === normalizedTarget) ?? null
}

const BEHAVE_DEPENDENCIES = ["behave", "behave-django", "behave-webdriver"]

export const detectPythonTestingSignals = async (
paths: string[],
pkg: PackageJson | null,
testing: Set<string>,
): Promise<void> => {
const { unit } = await getTestingConventionValues("python")
if (unit.length === 0) {
return
}

const behaveValue = findConventionValue(unit, "behave")
const unittestValue = findConventionValue(unit, "unittest")

if (!behaveValue && !unittestValue) {
return
}

const lowerCasePaths = paths.map((path) => path.toLowerCase())

if (behaveValue) {
const hasFeaturesDir = lowerCasePaths.some((path) => path.startsWith("features/") || path.includes("/features/"))
const hasStepsDir = lowerCasePaths.some((path) => path.includes("/steps/"))
const hasEnvironment = lowerCasePaths.some((path) => path.endsWith("/environment.py") || path.endsWith("environment.py"))
const hasDependency = pkg ? dependencyHas(pkg, BEHAVE_DEPENDENCIES) : false

if (hasDependency || (hasFeaturesDir && (hasStepsDir || hasEnvironment))) {
testing.add(behaveValue)
}
}

if (unittestValue) {
const hasUnitFiles = lowerCasePaths.some((path) => {
if (!/(^|\/)(tests?|testcases|specs)\//.test(path)) {
return false
}
return /(^|\/)(test_[^/]+|[^/]+_test)\.py$/.test(path)
})

if (hasUnitFiles) {
testing.add(unittestValue)
}
}
}

const readPackageJson = async (
owner: string,
repo: string,
Expand Down
15 changes: 1 addition & 14 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import type { Metadata } from "next";
import { Suspense } from "react";
import Script from "next/script";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import { ThemeProvider } from "@/components/theme-provider";
import { MixpanelInit } from "@/components/MixpanelInit";
import { SITE_URL } from "@/lib/site-metadata";

const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});

const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});

const siteUrl = SITE_URL;
const siteTitle = "DevContext – AI Coding Guidelines & Repo Analyzer";
const siteDescription =
Expand Down Expand Up @@ -155,9 +144,7 @@ export default function RootLayout({
}>) {
return (
<html lang="en" suppressHydrationWarning className="dark">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<body className="antialiased font-sans">
<Script
id="structured-data"
type="application/ld+json"
Expand Down
10 changes: 2 additions & 8 deletions lib/__tests__/repo-scan-python-detection.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { describe, expect, it } from "vitest"

import { detectPythonTestingSignals } from "@/app/api/scan-repo/route"

type PackageJson = {
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
peerDependencies?: Record<string, string>
optionalDependencies?: Record<string, string>
}
import { detectPythonTestingSignals } from "@/lib/repo-scan/python-testing-signals"
import type { PackageJson } from "@/types/repo-scan"

const createPkg = (deps: Partial<PackageJson>): PackageJson => ({ ...deps })

Expand Down
14 changes: 14 additions & 0 deletions lib/repo-scan/dependency-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { PackageJson } from "@/types/repo-scan"

export const dependencyHas = (pkg: PackageJson, names: string[]): boolean => {
const sources = [
pkg.dependencies,
pkg.devDependencies,
pkg.peerDependencies,
pkg.optionalDependencies,
]

return sources.some((source) =>
source ? names.some((name) => Object.prototype.hasOwnProperty.call(source, name)) : false,
)
}
76 changes: 76 additions & 0 deletions lib/repo-scan/python-testing-signals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { loadStackQuestionMetadata, normalizeConventionValue } from "@/lib/question-metadata"
import { dependencyHas } from "@/lib/repo-scan/dependency-utils"
import type { PackageJson } from "@/types/repo-scan"

type TestingConventionValues = {
unit: string[]
e2e: string[]
}

const testingConventionCache = new Map<string, TestingConventionValues>()

const getTestingConventionValues = async (stackId: string): Promise<TestingConventionValues> => {
const normalized = stackId.trim().toLowerCase()
if (testingConventionCache.has(normalized)) {
return testingConventionCache.get(normalized)!
}

const metadata = await loadStackQuestionMetadata(normalized)
const values: TestingConventionValues = {
unit: metadata.answersByResponseKey.testingUT ?? [],
e2e: metadata.answersByResponseKey.testingE2E ?? [],
}
testingConventionCache.set(normalized, values)
return values
}

const findConventionValue = (values: string[], target: string): string | null => {
const normalizedTarget = normalizeConventionValue(target)
return values.find((value) => normalizeConventionValue(value) === normalizedTarget) ?? null
}

const BEHAVE_DEPENDENCIES = ["behave", "behave-django", "behave-webdriver"]

export const detectPythonTestingSignals = async (
paths: string[],
pkg: PackageJson | null,
testing: Set<string>,
): Promise<void> => {
const { unit } = await getTestingConventionValues("python")
if (unit.length === 0) {
return
}

const behaveValue = findConventionValue(unit, "behave")
const unittestValue = findConventionValue(unit, "unittest")

if (!behaveValue && !unittestValue) {
return
}

const lowerCasePaths = paths.map((path) => path.toLowerCase())

if (behaveValue) {
const hasFeaturesDir = lowerCasePaths.some((path) => path.startsWith("features/") || path.includes("/features/"))
const hasStepsDir = lowerCasePaths.some((path) => path.includes("/steps/"))
const hasEnvironment = lowerCasePaths.some((path) => path.endsWith("/environment.py") || path.endsWith("environment.py"))
const hasDependency = pkg ? dependencyHas(pkg, BEHAVE_DEPENDENCIES) : false

if (hasDependency || (hasFeaturesDir && (hasStepsDir || hasEnvironment))) {
testing.add(behaveValue)
}
}

if (unittestValue) {
const hasUnitFiles = lowerCasePaths.some((path) => {
if (!/(^|\/)(tests?|testcases|specs)\//.test(path)) {
return false
}
return /(^|\/)(test_[^/]+|[^/]+_test)\.py$/.test(path)
})

if (hasUnitFiles) {
testing.add(unittestValue)
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build --turbopack",
"build": "next build",
"start": "next start",
"lint": "eslint",
"test": "vitest",
Expand Down
14 changes: 14 additions & 0 deletions types/repo-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,17 @@ export type RepoScanResponse = RepoScanSummary | RepoScanErrorResponse
export type RepoScanRouteParams = {
repoUrl: string
}

export type GitHubTreeItem = {
path: string
type: "blob" | "tree" | string
}

export type PackageJson = {
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
peerDependencies?: Record<string, string>
optionalDependencies?: Record<string, string>
engines?: { node?: string }
workspaces?: string[] | { packages?: string[] }
}
4 changes: 4 additions & 0 deletions types/stack-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export type StackDependencyFileDetection = {
* Explicit paths that should be evaluated (useful for root-level files).
*/
paths?: string[]
/**
* Legacy support for single path detection.
*/
path?: string
/**
* Signals that should be evaluated against the file contents.
*/
Expand Down