33 writeQueryHistoryToFile ,
44} from "../../../../../src/query-history/store/query-history-store" ;
55import { join } from "path" ;
6- import { writeFileSync , mkdirpSync , writeFile } from "fs-extra" ;
6+ import { writeFileSync , mkdirpSync } from "fs-extra" ;
77import type { InitialQueryInfo } from "../../../../../src/query-results" ;
88import { LocalQueryInfo } from "../../../../../src/query-results" ;
99import type { QueryWithResults } from "../../../../../src/run-queries-shared" ;
@@ -13,46 +13,42 @@ import type { DatabaseInfo } from "../../../../../src/common/interface-types";
1313import type { CancellationTokenSource } from "vscode" ;
1414import { Uri } from "vscode" ;
1515import { tmpDir } from "../../../../../src/tmp-dir" ;
16- import type { VariantAnalysisHistoryItem } from "../../../../../src/query-history/variant-analysis-history-item" ;
1716import type { QueryHistoryInfo } from "../../../../../src/query-history/query-history-info" ;
1817import { createMockVariantAnalysisHistoryItem } from "../../../../factories/query-history/variant-analysis-history-item" ;
1918import { nanoid } from "nanoid" ;
19+ import type {
20+ QueryHistoryDto ,
21+ QueryHistoryItemDto ,
22+ } from "../../../../../src/query-history/store/query-history-dto" ;
23+ import { mapQueryHistoryToDto } from "../../../../../src/query-history/store/query-history-domain-mapper" ;
2024
2125describe ( "write and read" , ( ) => {
22- let infoSuccessRaw : LocalQueryInfo ;
23- let infoSuccessInterpreted : LocalQueryInfo ;
24- let infoEarlyFailure : LocalQueryInfo ;
25- let infoLateFailure : LocalQueryInfo ;
26- let infoInProgress : LocalQueryInfo ;
27-
28- let variantAnalysis1 : VariantAnalysisHistoryItem ;
29- let variantAnalysis2 : VariantAnalysisHistoryItem ;
30-
3126 let allHistory : QueryHistoryInfo [ ] ;
27+ let allHistoryDtos : QueryHistoryItemDto [ ] ;
3228 let expectedHistory : QueryHistoryInfo [ ] ;
3329 let queryPath : string ;
3430 let cnt = 0 ;
3531
3632 beforeEach ( ( ) => {
3733 queryPath = join ( Uri . file ( tmpDir . name ) . fsPath , `query-${ cnt ++ } ` ) ;
3834
39- infoSuccessRaw = createMockFullQueryInfo (
35+ const infoSuccessRaw = createMockFullQueryInfo (
4036 "a" ,
4137 createMockQueryWithResults ( `${ queryPath } -a` , false , "/a/b/c/a" ) ,
4238 ) ;
43- infoSuccessInterpreted = createMockFullQueryInfo (
39+ const infoSuccessInterpreted = createMockFullQueryInfo (
4440 "b" ,
4541 createMockQueryWithResults ( `${ queryPath } -b` , true , "/a/b/c/b" ) ,
4642 ) ;
47- infoEarlyFailure = createMockFullQueryInfo ( "c" , undefined , true ) ;
48- infoLateFailure = createMockFullQueryInfo (
43+ const infoEarlyFailure = createMockFullQueryInfo ( "c" , undefined , true ) ;
44+ const infoLateFailure = createMockFullQueryInfo (
4945 "d" ,
5046 createMockQueryWithResults ( `${ queryPath } -c` , false , "/a/b/c/d" ) ,
5147 ) ;
52- infoInProgress = createMockFullQueryInfo ( "e" ) ;
48+ const infoInProgress = createMockFullQueryInfo ( "e" ) ;
5349
54- variantAnalysis1 = createMockVariantAnalysisHistoryItem ( { } ) ;
55- variantAnalysis2 = createMockVariantAnalysisHistoryItem ( { } ) ;
50+ const variantAnalysis1 = createMockVariantAnalysisHistoryItem ( { } ) ;
51+ const variantAnalysis2 = createMockVariantAnalysisHistoryItem ( { } ) ;
5652
5753 allHistory = [
5854 infoSuccessRaw ,
@@ -64,6 +60,8 @@ describe("write and read", () => {
6460 variantAnalysis2 ,
6561 ] ;
6662
63+ allHistoryDtos = mapQueryHistoryToDto ( allHistory ) ;
64+
6765 // the expected results only contains the history with completed queries
6866 expectedHistory = [
6967 infoSuccessRaw ,
@@ -139,69 +137,61 @@ describe("write and read", () => {
139137
140138 it ( "should remove remote queries from the history" , async ( ) => {
141139 const path = join ( tmpDir . name , "query-history-with-remote.json" ) ;
142- await writeFile (
143- path ,
144- JSON . stringify ( {
145- version : 2 ,
146- queries : [
147- ...allHistory ,
148- {
149- t : "remote" ,
150- status : "InProgress" ,
151- completed : false ,
152- queryId : nanoid ( ) ,
153- remoteQuery : {
154- queryName : "query-name" ,
155- queryFilePath : "query-file.ql" ,
156- queryText : "select 1" ,
157- language : "javascript" ,
158- controllerRepository : {
159- owner : "github" ,
160- name : "vscode-codeql-integration-tests" ,
161- } ,
162- executionStartTime : Date . now ( ) ,
163- actionsWorkflowRunId : 1 ,
164- repositoryCount : 0 ,
140+ writeRawQueryHistory ( path , {
141+ version : 2 ,
142+ queries : [
143+ ...allHistoryDtos ,
144+ {
145+ t : "remote" ,
146+ status : "InProgress" ,
147+ completed : false ,
148+ queryId : nanoid ( ) ,
149+ remoteQuery : {
150+ queryName : "query-name" ,
151+ queryFilePath : "query-file.ql" ,
152+ queryText : "select 1" ,
153+ language : "javascript" ,
154+ controllerRepository : {
155+ owner : "github" ,
156+ name : "vscode-codeql-integration-tests" ,
165157 } ,
158+ executionStartTime : Date . now ( ) ,
159+ actionsWorkflowRunId : 1 ,
160+ repositoryCount : 0 ,
166161 } ,
167- {
168- t : "remote" ,
169- status : "Completed" ,
170- completed : true ,
171- queryId : nanoid ( ) ,
172- remoteQuery : {
173- queryName : "query-name" ,
174- queryFilePath : "query-file.ql" ,
175- queryText : "select 1" ,
176- language : "javascript" ,
177- controllerRepository : {
178- owner : "github" ,
179- name : "vscode-codeql-integration-tests" ,
180- } ,
181- executionStartTime : Date . now ( ) ,
182- actionsWorkflowRunId : 1 ,
183- repositoryCount : 0 ,
162+ } as unknown as QueryHistoryItemDto ,
163+ {
164+ t : "remote" ,
165+ status : "Completed" ,
166+ completed : true ,
167+ queryId : nanoid ( ) ,
168+ remoteQuery : {
169+ queryName : "query-name" ,
170+ queryFilePath : "query-file.ql" ,
171+ queryText : "select 1" ,
172+ language : "javascript" ,
173+ controllerRepository : {
174+ owner : "github" ,
175+ name : "vscode-codeql-integration-tests" ,
184176 } ,
177+ executionStartTime : Date . now ( ) ,
178+ actionsWorkflowRunId : 1 ,
179+ repositoryCount : 0 ,
185180 } ,
186- ] ,
187- } ) ,
188- "utf8" ,
189- ) ;
181+ } as unknown as QueryHistoryItemDto ,
182+ ] ,
183+ } ) ;
190184
191185 const actual = await readQueryHistoryFromFile ( path ) ;
192186 expect ( actual . length ) . toEqual ( expectedHistory . length ) ;
193187 } ) ;
194188
195189 it ( "should handle an invalid query history version" , async ( ) => {
196190 const badPath = join ( tmpDir . name , "bad-query-history.json" ) ;
197- writeFileSync (
198- badPath ,
199- JSON . stringify ( {
200- version : 3 ,
201- queries : allHistory ,
202- } ) ,
203- "utf8" ,
204- ) ;
191+ writeRawQueryHistory ( badPath , {
192+ version : 3 ,
193+ queries : allHistoryDtos ,
194+ } ) ;
205195
206196 const allHistoryActual = await readQueryHistoryFromFile ( badPath ) ;
207197 // version number is invalid. Should return an empty array.
@@ -274,4 +264,8 @@ describe("write and read", () => {
274264
275265 return result ;
276266 }
267+
268+ function writeRawQueryHistory ( path : string , queryHistory : QueryHistoryDto ) {
269+ writeFileSync ( path , JSON . stringify ( queryHistory ) , "utf8" ) ;
270+ }
277271} ) ;
0 commit comments