mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-24 00:51:53 +00:00
* feat: configure prettier with pre-commit hook integration Add prettier, lint-staged, and prettier-plugin-tailwindcss at the repo root with husky pre-commit hook integration. Moves husky from gitnexus/ to root package.json for reliable hook installation. - Root package.json with prepare/format/format:check scripts - .prettierrc with endOfLine:lf and tailwindStylesheet for TW v4 - .prettierignore excluding fixtures, vendor, generated, *.d.ts, *.md - .gitattributes enforcing LF line endings for Windows consistency - Pre-commit hook uses direct node_modules/.bin/ paths (no npx) * style: apply prettier formatting to entire codebase One-time bulk format. No logic changes. Use .git-blame-ignore-revs to skip this commit in git blame. * chore: add .git-blame-ignore-revs for prettier format commit * perf: pre-commit hook runs only tests related to staged files Use vitest --related to scope test execution to tests that import the changed files, instead of running the full suite on every commit. * perf: remove vitest from pre-commit hook, keep in CI only Pre-commit now runs lint-staged + tsc only. Tests run in CI (ci-tests.yml) where they belong — keeps commits fast. * ci: add prettier format check to quality workflow PRs will now fail if code isn't formatted with prettier.
91 lines
3.6 KiB
TypeScript
91 lines
3.6 KiB
TypeScript
/**
|
|
* Integration test for PHP response shape extraction.
|
|
*
|
|
* Runs the full pipeline on a PHP fixture with json_encode() calls
|
|
* and verifies that Route nodes have correct responseKeys/errorKeys.
|
|
*/
|
|
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import path from 'path';
|
|
import {
|
|
FIXTURES,
|
|
getNodesByLabel,
|
|
getNodesByLabelFull,
|
|
getRelationships,
|
|
runPipelineFromRepo,
|
|
type PipelineResult,
|
|
} from './helpers.js';
|
|
|
|
describe('PHP response shape extraction (pipeline)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'php-response-shapes'), () => {});
|
|
}, 60000);
|
|
|
|
it('creates Route nodes for PHP endpoints', () => {
|
|
const routes = getNodesByLabel(result, 'Route');
|
|
expect(routes).toContain('/api/items');
|
|
expect(routes).toContain('/api/submit');
|
|
});
|
|
|
|
it('extracts responseKeys from json_encode success path (items.php)', () => {
|
|
const routes = getNodesByLabelFull(result, 'Route');
|
|
const items = routes.find((r) => r.name === '/api/items');
|
|
expect(items).toBeDefined();
|
|
expect(items!.properties.responseKeys).toEqual(expect.arrayContaining(['data', 'total']));
|
|
});
|
|
|
|
it('extracts errorKeys from json_encode with http_response_code >= 400 (items.php)', () => {
|
|
const routes = getNodesByLabelFull(result, 'Route');
|
|
const items = routes.find((r) => r.name === '/api/items');
|
|
expect(items).toBeDefined();
|
|
expect(items!.properties.errorKeys).toEqual(expect.arrayContaining(['error']));
|
|
});
|
|
|
|
it('keeps success and error keys separate (no cross-contamination)', () => {
|
|
const routes = getNodesByLabelFull(result, 'Route');
|
|
const items = routes.find((r) => r.name === '/api/items');
|
|
expect(items).toBeDefined();
|
|
const successKeys = new Set(items!.properties.responseKeys ?? []);
|
|
const errorKeys = new Set(items!.properties.errorKeys ?? []);
|
|
expect(successKeys.has('error')).toBe(false);
|
|
expect(errorKeys.has('data')).toBe(false);
|
|
expect(errorKeys.has('total')).toBe(false);
|
|
});
|
|
|
|
it('extracts responseKeys from submit.php success path', () => {
|
|
const routes = getNodesByLabelFull(result, 'Route');
|
|
const submit = routes.find((r) => r.name === '/api/submit');
|
|
expect(submit).toBeDefined();
|
|
expect(submit!.properties.responseKeys).toEqual(
|
|
expect.arrayContaining(['ok', 'id', 'created_at']),
|
|
);
|
|
});
|
|
|
|
it('extracts errorKeys from submit.php error paths', () => {
|
|
const routes = getNodesByLabelFull(result, 'Route');
|
|
const submit = routes.find((r) => r.name === '/api/submit');
|
|
expect(submit).toBeDefined();
|
|
expect(submit!.properties.errorKeys).toEqual(expect.arrayContaining(['error']));
|
|
});
|
|
|
|
it('respects exit(N) and die() as boundaries in submit.php', () => {
|
|
const routes = getNodesByLabelFull(result, 'Route');
|
|
const submit = routes.find((r) => r.name === '/api/submit');
|
|
expect(submit).toBeDefined();
|
|
const successKeys = new Set(submit!.properties.responseKeys ?? []);
|
|
expect(successKeys.has('ok')).toBe(true);
|
|
expect(successKeys.has('id')).toBe(true);
|
|
expect(successKeys.has('error')).toBe(false);
|
|
});
|
|
|
|
it('creates HANDLES_ROUTE edges from PHP files to Route nodes', () => {
|
|
const edges = getRelationships(result, 'HANDLES_ROUTE');
|
|
const itemsHandler = edges.find((e) => e.target === '/api/items');
|
|
expect(itemsHandler).toBeDefined();
|
|
expect(itemsHandler!.sourceFilePath).toContain('api/items.php');
|
|
const submitHandler = edges.find((e) => e.target === '/api/submit');
|
|
expect(submitHandler).toBeDefined();
|
|
expect(submitHandler!.sourceFilePath).toContain('api/submit.php');
|
|
});
|
|
});
|