@@ -22,22 +22,6 @@ import { writeFile, outputFile } from "fs-extra";
2222import { dump as dumpYaml } from "js-yaml" ;
2323import { MethodSignature } from "./external-api-usage" ;
2424
25- type AutoModelQueryOptions = {
26- queryTag : string ;
27- mode : Mode ;
28- cliServer : CodeQLCliServer ;
29- queryRunner : QueryRunner ;
30- databaseItem : DatabaseItem ;
31- qlpack : QlPacksForLanguage ;
32- sourceInfo : SourceInfo | undefined ;
33- additionalPacks : string [ ] ;
34- extensionPacks : string [ ] ;
35- queryStorageDir : string ;
36-
37- progress : ProgressCallback ;
38- token : CancellationToken ;
39- } ;
40-
4125function modeTag ( mode : Mode ) : string {
4226 switch ( mode ) {
4327 case Mode . Application :
@@ -49,108 +33,6 @@ function modeTag(mode: Mode): string {
4933 }
5034}
5135
52- async function runAutoModelQuery ( {
53- queryTag,
54- mode,
55- cliServer,
56- queryRunner,
57- databaseItem,
58- qlpack,
59- sourceInfo,
60- additionalPacks,
61- extensionPacks,
62- queryStorageDir,
63- progress,
64- token,
65- } : AutoModelQueryOptions ) : Promise < Sarif . Log | undefined > {
66- // First, resolve the query that we want to run.
67- // All queries are tagged like this:
68- // internal extract automodel <mode> <queryTag>
69- // Example: internal extract automodel framework-mode candidates
70- const queries = await resolveQueries (
71- cliServer ,
72- qlpack ,
73- `Extract automodel ${ queryTag } ` ,
74- {
75- kind : "problem" ,
76- "tags contain all" : [ "automodel" , modeTag ( mode ) , ...queryTag . split ( " " ) ] ,
77- } ,
78- ) ;
79- if ( queries . length > 1 ) {
80- throw new Error (
81- `Found multiple auto model queries for ${ mode } ${ queryTag } . Can't continue` ,
82- ) ;
83- }
84- if ( queries . length === 0 ) {
85- throw new Error (
86- `Did not found any auto model queries for ${ mode } ${ queryTag } . Can't continue` ,
87- ) ;
88- }
89-
90- const queryPath = queries [ 0 ] ;
91- const { cleanup : cleanupLockFile } = await createLockFileForStandardQuery (
92- cliServer ,
93- queryPath ,
94- ) ;
95-
96- // Get metadata for the query. This is required to interpret the results. We already know the kind is problem
97- // (because of the constraint in resolveQueries), so we don't need any more checks on the metadata.
98- const metadata = await cliServer . resolveMetadata ( queryPath ) ;
99-
100- const queryRun = queryRunner . createQueryRun (
101- databaseItem . databaseUri . fsPath ,
102- {
103- queryPath,
104- quickEvalPosition : undefined ,
105- quickEvalCountOnly : false ,
106- } ,
107- false ,
108- additionalPacks ,
109- extensionPacks ,
110- queryStorageDir ,
111- undefined ,
112- undefined ,
113- ) ;
114-
115- const completedQuery = await queryRun . evaluate (
116- progress ,
117- token ,
118- new TeeLogger ( queryRunner . logger , queryRun . outputDir . logPath ) ,
119- ) ;
120-
121- await cleanupLockFile ?.( ) ;
122-
123- if ( completedQuery . resultType !== QueryResultType . SUCCESS ) {
124- void showAndLogExceptionWithTelemetry (
125- extLogger ,
126- telemetryListener ,
127- redactableError `Auto-model query ${ queryTag } failed: ${
128- completedQuery . message ?? "No message"
129- } `,
130- ) ;
131- return ;
132- }
133-
134- const interpretedResultsPath = join (
135- queryStorageDir ,
136- `interpreted-results-${ queryTag . replaceAll ( " " , "-" ) } -${ queryRun . id } .sarif` ,
137- ) ;
138-
139- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- We only need the actual SARIF data, not the extra fields added by SarifInterpretationData
140- const { t, sortState, ...sarif } = await interpretResultsSarif (
141- cliServer ,
142- metadata ,
143- {
144- resultsPath : completedQuery . outputDir . bqrsPath ,
145- interpretedResultsPath,
146- } ,
147- sourceInfo ,
148- [ "--sarif-add-snippets" ] ,
149- ) ;
150-
151- return sarif ;
152- }
153-
15436type AutoModelQueriesOptions = {
15537 mode : Mode ;
15638 candidateMethods : MethodSignature [ ] ;
@@ -284,3 +166,121 @@ export async function generateCandidateFilterPack(
284166
285167 return packDir ;
286168}
169+
170+ type AutoModelQueryOptions = {
171+ queryTag : string ;
172+ mode : Mode ;
173+ cliServer : CodeQLCliServer ;
174+ queryRunner : QueryRunner ;
175+ databaseItem : DatabaseItem ;
176+ qlpack : QlPacksForLanguage ;
177+ sourceInfo : SourceInfo | undefined ;
178+ additionalPacks : string [ ] ;
179+ extensionPacks : string [ ] ;
180+ queryStorageDir : string ;
181+
182+ progress : ProgressCallback ;
183+ token : CancellationToken ;
184+ } ;
185+
186+ async function runAutoModelQuery ( {
187+ queryTag,
188+ mode,
189+ cliServer,
190+ queryRunner,
191+ databaseItem,
192+ qlpack,
193+ sourceInfo,
194+ additionalPacks,
195+ extensionPacks,
196+ queryStorageDir,
197+ progress,
198+ token,
199+ } : AutoModelQueryOptions ) : Promise < Sarif . Log | undefined > {
200+ // First, resolve the query that we want to run.
201+ // All queries are tagged like this:
202+ // internal extract automodel <mode> <queryTag>
203+ // Example: internal extract automodel framework-mode candidates
204+ const queries = await resolveQueries (
205+ cliServer ,
206+ qlpack ,
207+ `Extract automodel ${ queryTag } ` ,
208+ {
209+ kind : "problem" ,
210+ "tags contain all" : [ "automodel" , modeTag ( mode ) , ...queryTag . split ( " " ) ] ,
211+ } ,
212+ ) ;
213+ if ( queries . length > 1 ) {
214+ throw new Error (
215+ `Found multiple auto model queries for ${ mode } ${ queryTag } . Can't continue` ,
216+ ) ;
217+ }
218+ if ( queries . length === 0 ) {
219+ throw new Error (
220+ `Did not found any auto model queries for ${ mode } ${ queryTag } . Can't continue` ,
221+ ) ;
222+ }
223+
224+ const queryPath = queries [ 0 ] ;
225+ const { cleanup : cleanupLockFile } = await createLockFileForStandardQuery (
226+ cliServer ,
227+ queryPath ,
228+ ) ;
229+
230+ // Get metadata for the query. This is required to interpret the results. We already know the kind is problem
231+ // (because of the constraint in resolveQueries), so we don't need any more checks on the metadata.
232+ const metadata = await cliServer . resolveMetadata ( queryPath ) ;
233+
234+ const queryRun = queryRunner . createQueryRun (
235+ databaseItem . databaseUri . fsPath ,
236+ {
237+ queryPath,
238+ quickEvalPosition : undefined ,
239+ quickEvalCountOnly : false ,
240+ } ,
241+ false ,
242+ additionalPacks ,
243+ extensionPacks ,
244+ queryStorageDir ,
245+ undefined ,
246+ undefined ,
247+ ) ;
248+
249+ const completedQuery = await queryRun . evaluate (
250+ progress ,
251+ token ,
252+ new TeeLogger ( queryRunner . logger , queryRun . outputDir . logPath ) ,
253+ ) ;
254+
255+ await cleanupLockFile ?.( ) ;
256+
257+ if ( completedQuery . resultType !== QueryResultType . SUCCESS ) {
258+ void showAndLogExceptionWithTelemetry (
259+ extLogger ,
260+ telemetryListener ,
261+ redactableError `Auto-model query ${ queryTag } failed: ${
262+ completedQuery . message ?? "No message"
263+ } `,
264+ ) ;
265+ return ;
266+ }
267+
268+ const interpretedResultsPath = join (
269+ queryStorageDir ,
270+ `interpreted-results-${ queryTag . replaceAll ( " " , "-" ) } -${ queryRun . id } .sarif` ,
271+ ) ;
272+
273+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- We only need the actual SARIF data, not the extra fields added by SarifInterpretationData
274+ const { t, sortState, ...sarif } = await interpretResultsSarif (
275+ cliServer ,
276+ metadata ,
277+ {
278+ resultsPath : completedQuery . outputDir . bqrsPath ,
279+ interpretedResultsPath,
280+ } ,
281+ sourceInfo ,
282+ [ "--sarif-add-snippets" ] ,
283+ ) ;
284+
285+ return sarif ;
286+ }
0 commit comments