Skip to content

Commit e1ab6a4

Browse files
committed
Merge branch 'jeongsoolee09/fix-ui5-fn' of github.com:advanced-security/codeql-sap-js into jeongsoolee09/fix-ui5-fn
2 parents 7225c08 + c593a3f commit e1ab6a4

File tree

21 files changed

+832
-268
lines changed

21 files changed

+832
-268
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
applyTo: 'extractors/cds/tools/**/*.ts'
3+
description: 'Instructions for CodeQL CDS extractor TypeScript source and test files.'
4+
---
5+
6+
# Copilot Instructions for `extractors/cds/tools/**/*.ts` files
7+
8+
## PURPOSE
9+
10+
This file contains instructions for working with TypeScript source code files in the `extractors/cds/tools/` directory of the `codeql-sap-js` repository. This includes the main `cds-extractor.ts` entry-point, modular source files in `src/**/*.ts`, and comprehensive test files in `test/**/*.test.ts`.
11+
12+
## REQUIREMENTS
13+
14+
## COMMON REQUIREMENTS
15+
16+
- ALWAYS use modern TypeScript syntax and features compatible with the configured target (ES2020).
17+
- ALWAYS follow best practices for implementing secure and efficient CodeQL extractor functionality.
18+
- ALWAYS order imports, definitions, static lists, and similar constructs alphabetically.
19+
- ALWAYS follow a test-driven development (TDD) approach by writing comprehensive tests for new features or bug fixes.
20+
- ALWAYS fix lint errors by running `npm run lint:fix` from the `extractors/cds/tools/` directory before committing changes.
21+
- ALWAYS maintain consistency between the CDS extractor's compilation behavior and the `extractors/cds/tools/test/cds-compilation-for-actions.test.sh` script to prevent CI/CD workflow failures.
22+
- **ALWAYS run `npm run build:all` from the `extractors/cds/tools/` directory and ensure it passes completely before committing any changes. This is MANDATORY and includes lint checks, test coverage, and bundle validation.**
23+
24+
### CDS EXTRACTOR SOURCE REQUIREMENTS
25+
26+
The following requirements are specific to the CDS extractor main entry-point `cds-extractor.ts` and source files matching `extractors/cds/tools/src/**/*.ts`.
27+
28+
- ALWAYS keep the main entry-point `cds-extractor.ts` focused on orchestration, delegating specific tasks to well-defined modules in `src/`.
29+
- ALWAYS gracefully handle extraction failures using tool-level diagnostics in order to avoid disrupting the overall CodeQL extraction process. Instead of exiting with a non-zero code, the CDS extractor should generate a diagnostic error (or warning) that points to the relative path (from source root) of the problematic source (e.g. `.cds`) file.
30+
31+
### CDS EXTRACTOR TESTING REQUIREMENTS
32+
33+
The following requirements are specific to the CDS extractor test files matching `extractors/cds/tools/test/**/*.test.ts`.
34+
35+
- ALWAYS write unit tests for new functions and classes in corresponding `test/src/**/*.test.ts` files.
36+
- ALWAYS use Jest testing framework with the configured `ts-jest` preset.
37+
- ALWAYS follow the AAA pattern (Arrange, Act, Assert) for test structure.
38+
- ALWAYS mock external dependencies (filesystem, child processes, network calls) using Jest mocks or `mock-fs`.
39+
- ALWAYS test both success and error scenarios with appropriate edge cases.
40+
- ALWAYS maintain test coverage above the established threshold.
41+
- **ALWAYS run `npm test` or `npm run test:coverage` from the `extractors/cds/tools/` directory and ensure all tests pass before committing changes.**
42+
43+
## PREFERENCES
44+
45+
- PREFER modular design with each major functionality implemented in its own dedicated file or module under `src/`.
46+
- PREFER the existing architectural patterns:
47+
- `src/cds/compiler/` for CDS compiler specific logic
48+
- `src/cds/parser/` for CDS parser specific logic
49+
- `src/logging/` for unified logging and performance tracking
50+
- `src/packageManager/` for dependency management and caching
51+
- `src/codeql.ts` for CodeQL JavaScript extractor integration
52+
- `src/environment.ts` for environment setup and validation
53+
- PREFER comprehensive error handling with diagnostic reporting through the `src/diagnostics.ts` module.
54+
- PREFER performance-conscious implementations that minimize filesystem operations and dependency installations.
55+
- PREFER project-aware processing that understands CDS file relationships and dependencies.
56+
57+
## CONSTRAINTS
58+
59+
- NEVER leave any trailing whitespace on any line.
60+
- NEVER directly modify any compiled files in the `dist/` directory; all changes must be made in the corresponding `src/` files and built using the build process.
61+
- NEVER commit changes without verifying that `npm run build:all` passes completely when run from the `extractors/cds/tools/` directory.
62+
- NEVER modify compilation behavior without updating the corresponding test script `extractors/cds/tools/test/cds-compilation-for-actions.test.sh`.
63+
- NEVER process CDS files in isolation - maintain project-aware context for accurate extraction.
64+
- NEVER bypass the unified logging system - use `src/logging/` utilities for all output and diagnostics.
65+
- NEVER commit extra documentation files that purely explain what has been changed and/or fixed; use git commit messages instead of adding any `.md` files that you have not explicitly been requested to create.

extractors/cds/tools/cds-extractor.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ try {
183183
if (!extractorResult.success && extractorResult.error) {
184184
cdsExtractorLog('error', `Error running JavaScript extractor: ${extractorResult.error}`);
185185
if (codeqlExePath) {
186-
addJavaScriptExtractorDiagnostic(sourceRoot, extractorResult.error, codeqlExePath);
186+
addJavaScriptExtractorDiagnostic(
187+
sourceRoot,
188+
extractorResult.error,
189+
codeqlExePath,
190+
sourceRoot,
191+
);
187192
}
188193
logExtractorStop(false, 'JavaScript extractor failed');
189194
} else {
@@ -223,7 +228,12 @@ try {
223228
if (!extractorResult.success && extractorResult.error) {
224229
cdsExtractorLog('error', `Error running JavaScript extractor: ${extractorResult.error}`);
225230
if (codeqlExePath) {
226-
addJavaScriptExtractorDiagnostic(sourceRoot, extractorResult.error, codeqlExePath);
231+
addJavaScriptExtractorDiagnostic(
232+
sourceRoot,
233+
extractorResult.error,
234+
codeqlExePath,
235+
sourceRoot,
236+
);
227237
}
228238
logExtractorStop(false, 'JavaScript extractor failed');
229239
} else {
@@ -316,6 +326,7 @@ try {
316326
cdsFilePathsToProcess[0], // Use first file as representative
317327
`Compilation orchestration failed: ${String(error)}`,
318328
codeqlExePath,
329+
sourceRoot,
319330
);
320331
}
321332
}
@@ -350,7 +361,12 @@ if (!extractorResult.success && extractorResult.error) {
350361
// Use the first CDS file as a representative file for the diagnostic
351362
const firstProject = Array.from(dependencyGraph.projects.values())[0];
352363
const representativeFile = firstProject.cdsFiles[0] || sourceRoot;
353-
addJavaScriptExtractorDiagnostic(representativeFile, extractorResult.error, codeqlExePath);
364+
addJavaScriptExtractorDiagnostic(
365+
representativeFile,
366+
extractorResult.error,
367+
codeqlExePath,
368+
sourceRoot,
369+
);
354370
}
355371

356372
logExtractorStop(false, 'JavaScript extractor failed');

extractors/cds/tools/dist/cds-extractor.bundle.js

Lines changed: 82 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extractors/cds/tools/dist/cds-extractor.bundle.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)