Skip to content

test: add unit tests for TechStackDetector module - #687

Merged
rafaelscosta merged 4 commits into
mainfrom
devops/pr-503-tech-stack-detector-current-20260507
May 8, 2026
Merged

test: add unit tests for TechStackDetector module#687
rafaelscosta merged 4 commits into
mainfrom
devops/pr-503-tech-stack-detector-current-20260507

Conversation

@rafaelscosta

@rafaelscosta rafaelscosta commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Port test: add unit tests for TechStackDetector module #503 TechStackDetector coverage onto current main in SynkraAI/aiox-core.
  • Replace the stale .aios-core import with current .aiox-core resolution from the repository root.
  • Cover database, frontend, backend, TypeScript, tests, confidence, summary, and full detect() behavior.

Validation

  • npm test -- tests/core/orchestration/tech-stack-detector.test.js --runInBand --forceExit
  • npm run lint (passes with the existing 114 warnings, 0 errors)
  • npm run typecheck
  • git diff --check origin/main...HEAD && git diff --check

Supersedes #503.

Summary by CodeRabbit

Tests

  • Added extensive test coverage for technology stack detection, validating database detection (PostgreSQL, MongoDB, MySQL, SQLite, Supabase), frontend framework identification (React, Vue, Angular, Svelte), backend framework detection, build tools, and language/testing framework support.

nikolasdehor and others added 4 commits May 7, 2026 22:12
84 tests covering:
- Constructor and package.json caching
- Empty profile structure validation
- Database detection (Supabase, Prisma, pg, MongoDB, MySQL, SQLite)
- RLS detection in SQL migrations
- Environment variable detection
- Frontend detection (React, Vue, Angular, Svelte, Next, Nuxt)
- Build tool detection (Vite, Webpack, esbuild, Parcel)
- Styling detection (Tailwind, styled-components, Emotion, SCSS)
- Component library detection (shadcn, MUI, Chakra, Ant Design)
- Backend detection (Express, Fastify, NestJS, Hono, Edge Functions)
- API route detection (api/, pages/api/, app/api/)
- TypeScript and test framework detection
- Applicable phase computation
- Confidence score calculation with cap at 100
- Static getSummary with all combinations
- Full integration test (empty project + full-stack project)
- Extrai setupDeps para nível superior do describe (evita duplicação)
- Move jest.mock('fs-extra') antes dos requires por clareza
- Troca .resolves.not.toThrow() por .resolves.toBeUndefined()
- Env vars de banco: cobre .env, .env.local e .env.example
- Rotas API: cobre api/, src/api/, pages/api/ e app/api/
@vercel

vercel Bot commented May 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aiox-core Ready Ready Preview, Comment May 8, 2026 1:17am

Request Review

@coderabbitai

coderabbitai Bot commented May 8, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR adds a comprehensive Jest test suite for TechStackDetector, using full mocks of fs-extra to validate all detection methods, confidence scoring logic, and the complete integration flow across database, frontend, backend, TypeScript, and testing frameworks.

Changes

TechStackDetector Test Suite

Layer / File(s) Summary
Test Setup and Package Handling
tests/core/orchestration/tech-stack-detector.test.js
Initializes detector instances with default flags/structures; validates _loadPackageJson for missing files, valid/invalid JSON, and caching behavior; validates _getAllDependencies merges dependencies and devDependencies.
Database Detection
tests/core/orchestration/tech-stack-detector.test.js
Tests Supabase detection via directory and @supabase/supabase-js; PostgreSQL via pg and @prisma/client; MongoDB via mongoose; MySQL via mysql2; SQLite via better-sqlite3; Supabase SQL migration inspection for presence, schema, and RLS patterns.
Frontend Detection
tests/core/orchestration/tech-stack-detector.test.js
Validates framework identification (React/Vue/Angular/Svelte, Next.js as React, Nuxt as Vue); build tools (Vite/Webpack); styling (Tailwind, styled-components, Emotion, SCSS); component libraries (shadcn, MUI, Chakra, Ant Design); frontend code heuristics via .tsx files under src.
Backend and Language Detection
tests/core/orchestration/tech-stack-detector.test.js
Tests backend frameworks (Express/Fastify/NestJS/Hono); edge functions via supabase/functions; API routes across multiple directory conventions; TypeScript detection via dependency and config/directory presence; test framework detection via dependencies and standard directories.
Integration and Output
tests/core/orchestration/tech-stack-detector.test.js
Validates _computeApplicablePhases logic; _calculateConfidence scoring and 100 cap; getSummary() formatting (including "No stack detected", pipe-separated composition, and null handling); detect() integration for both empty project and full-stack scenarios with timestamp validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

type: test, area: core

Suggested reviewers

  • oalanicolas
  • Pedrovaleriolopez
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding comprehensive unit tests for the TechStackDetector module, which is the sole focus of this pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devops/pr-503-tech-stack-detector-current-20260507

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added area: agents Agent system related area: workflows Workflow system related squad mcp type: test Test coverage and quality area: core Core framework (.aios-core/core/) area: installer Installer and setup (packages/installer/) area: synapse SYNAPSE context engine area: cli CLI tools (bin/, packages/aios-pro-cli/) area: pro Pro features (pro/) area: health-check Health check system area: docs Documentation (docs/) area: devops CI/CD, GitHub Actions (.github/) labels May 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/core/orchestration/tech-stack-detector.test.js (1)

182-203: ⚡ Quick win

Consolidate repeated filesystem mock setup into reusable helpers.

There are many near-identical fs.pathExists.mockImplementation blocks (e.g., Line 182, Line 215, Line 232, Line 248, Line 319, etc.). Extracting a small helper for “existing paths” will reduce duplication and prevent test drift when path rules change.

Refactor sketch
+function mockExistingPaths(paths) {
+  const normalized = new Set(paths.map((p) => path.normalize(p)));
+  fs.pathExists.mockImplementation(async (p) => normalized.has(path.normalize(p)));
+}
+
+function mockPackageJson(dependencies = {}, devDependencies = {}) {
+  mockExistingPaths([path.join(PROJECT_ROOT, 'package.json')]);
+  fs.readJson.mockResolvedValue({ dependencies, devDependencies });
+}

Then in tests:

- fs.pathExists.mockImplementation(async (p) => {
-   if (p === path.join(PROJECT_ROOT, 'package.json')) return true;
-   if (p === path.join(PROJECT_ROOT, 'tsconfig.json')) return true;
-   if (p === path.join(PROJECT_ROOT, 'tests')) return true;
-   return false;
- });
+ mockExistingPaths([
+   path.join(PROJECT_ROOT, 'package.json'),
+   path.join(PROJECT_ROOT, 'tsconfig.json'),
+   path.join(PROJECT_ROOT, 'tests'),
+ ]);

Also applies to: 215-220, 232-237, 248-253, 319-323, 335-340, 439-443, 473-477, 487-491, 535-539, 551-555, 570-573, 582-585, 604-607, 616-619, 628-631, 639-642, 858-863

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/core/orchestration/tech-stack-detector.test.js` around lines 182 - 203,
Many tests repeat identical fs.pathExists.mockImplementation and
fs.readJson.mockResolvedValue blocks; create a reusable helper (e.g.,
mockPathExists or setupFsMocks) that accepts an array of existing path suffixes
and stubs fs.pathExists accordingly, and another helper for fs.readJson (e.g.,
mockReadJson) to return desired JSON; then replace repeated inline mocks in
tests like the ones around detector._createEmptyProfile() /
detector._detectDatabase() with calls to these helpers so all occurrences
(including the blocks that check for 'supabase', 'migrations', 'package.json',
etc.) are consolidated and easier to maintain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/core/orchestration/tech-stack-detector.test.js`:
- Around line 182-203: Many tests repeat identical
fs.pathExists.mockImplementation and fs.readJson.mockResolvedValue blocks;
create a reusable helper (e.g., mockPathExists or setupFsMocks) that accepts an
array of existing path suffixes and stubs fs.pathExists accordingly, and another
helper for fs.readJson (e.g., mockReadJson) to return desired JSON; then replace
repeated inline mocks in tests like the ones around
detector._createEmptyProfile() / detector._detectDatabase() with calls to these
helpers so all occurrences (including the blocks that check for 'supabase',
'migrations', 'package.json', etc.) are consolidated and easier to maintain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5db07442-2318-47a1-91d1-75707873b30b

📥 Commits

Reviewing files that changed from the base of the PR and between 6b4b241 and 4b9a64d.

📒 Files selected for processing (1)
  • tests/core/orchestration/tech-stack-detector.test.js

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

📊 Coverage Report

Coverage report not available

📈 Full coverage report available in Codecov


Generated by PR Automation (Story 6.1)

@rafaelscosta
rafaelscosta merged commit a2bbcf3 into main May 8, 2026
43 checks passed
@rafaelscosta
rafaelscosta deleted the devops/pr-503-tech-stack-detector-current-20260507 branch May 8, 2026 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: agents Agent system related area: cli CLI tools (bin/, packages/aios-pro-cli/) area: core Core framework (.aios-core/core/) area: devops CI/CD, GitHub Actions (.github/) area: docs Documentation (docs/) area: health-check Health check system area: installer Installer and setup (packages/installer/) area: pro Pro features (pro/) area: synapse SYNAPSE context engine area: workflows Workflow system related mcp squad type: test Test coverage and quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants