11import * as filepath from "path" ;
22
3- import * as core from "@actions/core" ;
43import * as toolcache from "@actions/tool-cache" ;
54import test , { ExecutionContext } from "ava" ;
65import sinon from "sinon" ;
@@ -18,7 +17,6 @@ import { getRunnerLogger, Logger } from "./logging";
1817import { BundlePlatform , getBundlePlatform } from "./platform" ;
1918import * as repository from "./setup/repository" ;
2019import * as startProxyExports from "./start-proxy" ;
21- import * as statusReport from "./status-report" ;
2220import {
2321 addSinonAssertions ,
2422 assertNotLogged ,
@@ -32,94 +30,10 @@ import {
3230 setupTests ,
3331 withRecordingLoggerAsync ,
3432} from "./testing-utils" ;
35- import {
36- ConfigurationError ,
37- GitHubVariant ,
38- GitHubVersion ,
39- withTmpDir ,
40- } from "./util" ;
33+ import { GitHubVariant , GitHubVersion , withTmpDir } from "./util" ;
4134
4235setupTests ( test ) ;
4336
44- const sendFailedStatusReportTest = makeMacro ( {
45- exec : async (
46- t : ExecutionContext < unknown > ,
47- err : Error ,
48- expectedMessage : string ,
49- expectedStatus : statusReport . ActionStatus = "failure" ,
50- ) => {
51- const now = new Date ( ) ;
52-
53- // Override core.setFailed to avoid it setting the program's exit code
54- sinon . stub ( core , "setFailed" ) . returns ( ) ;
55-
56- const createStatusReportBase = sinon . stub (
57- statusReport ,
58- "createStatusReportBase" ,
59- ) ;
60- createStatusReportBase . resolves ( undefined ) ;
61-
62- await withRecordingLoggerAsync ( async ( logger ) => {
63- await startProxyExports . sendFailedStatusReport (
64- logger ,
65- now ,
66- undefined ,
67- err ,
68- ) ;
69-
70- // Check that the stub has been called exactly once, with the expected arguments,
71- // but not with the message from the error.
72- sinon . assert . calledOnceWithExactly (
73- createStatusReportBase ,
74- statusReport . ActionName . StartProxy ,
75- expectedStatus ,
76- now ,
77- sinon . match . any ,
78- sinon . match . any ,
79- sinon . match . any ,
80- expectedMessage ,
81- ) ;
82- t . false (
83- createStatusReportBase . calledWith (
84- statusReport . ActionName . StartProxy ,
85- expectedStatus ,
86- now ,
87- sinon . match . any ,
88- sinon . match . any ,
89- sinon . match . any ,
90- sinon . match ( ( msg : string ) => msg . includes ( err . message ) ) ,
91- ) ,
92- "createStatusReportBase was called with the error message" ,
93- ) ;
94- } ) ;
95- } ,
96-
97- title : ( providedTitle = "" ) => `sendFailedStatusReport - ${ providedTitle } ` ,
98- } ) ;
99-
100- sendFailedStatusReportTest . serial (
101- "reports generic error message for non-StartProxyError error" ,
102- new Error ( "Something went wrong today" ) ,
103- "Error from start-proxy Action omitted (Error)." ,
104- ) ;
105-
106- sendFailedStatusReportTest . serial (
107- "reports generic error message for non-StartProxyError error with safe error message" ,
108- new Error (
109- startProxyExports . getStartProxyErrorMessage (
110- startProxyExports . StartProxyErrorType . DownloadFailed ,
111- ) ,
112- ) ,
113- "Error from start-proxy Action omitted (Error)." ,
114- ) ;
115-
116- sendFailedStatusReportTest . serial (
117- "reports generic error message for ConfigurationError error" ,
118- new ConfigurationError ( "Something went wrong today" ) ,
119- "Error from start-proxy Action omitted (ConfigurationError)." ,
120- "user-error" ,
121- ) ;
122-
12337const toEncodedJSON = ( data : any ) =>
12438 Buffer . from ( JSON . stringify ( data ) ) . toString ( "base64" ) ;
12539
@@ -1021,16 +935,17 @@ test.serial(
1021935 sinon . stub ( actionsUtil , "isRunningLocalAction" ) . returns ( true ) ;
1022936
1023937 const features = mockOfflineFeatures ( tempDir , logger ) ;
1024- const path = await startProxyExports . getProxyBinaryPath (
938+ const result = await startProxyExports . getProxyBinaryPath (
1025939 initAllState ( { logger, features } ) ,
1026940 SAMPLE_DOTCOM_API_DETAILS ,
1027941 ) ;
1028942
1029- t . assert ( path ) ;
943+ t . assert ( result ) ;
1030944 t . is (
1031- path ,
945+ result . path ,
1032946 filepath . join ( toolcachePath , startProxyExports . getProxyFilename ( ) ) ,
1033947 ) ;
948+ t . is ( result . version , defaults . cliVersion ) ;
1034949 } ) ;
1035950 } ,
1036951) ;
@@ -1067,7 +982,7 @@ test.serial(
1067982 sinon . stub ( actionsUtil , "isRunningLocalAction" ) . returns ( false ) ;
1068983 state . env . set ( ActionsEnvVars . GITHUB_ACTION_REPOSITORY , "test/repo" ) ;
1069984
1070- const path = await startProxyExports . getProxyBinaryPath (
985+ const result = await startProxyExports . getProxyBinaryPath (
1071986 {
1072987 ...state ,
1073988 features : createFeatures ( [ ] ) ,
@@ -1084,11 +999,12 @@ test.serial(
1084999 st . onceWith ( extractTar , archivePath ) ;
10851000 st . onceWith ( cacheDir , extractedPath ) ;
10861001
1087- t . assert ( path ) ;
1002+ t . assert ( result ) ;
10881003 t . is (
1089- path ,
1004+ result . path ,
10901005 filepath . join ( toolcachePath , startProxyExports . getProxyFilename ( ) ) ,
10911006 ) ;
1007+ t . is ( result . version , defaults . cliVersion ) ;
10921008
10931009 checkExpectedLogMessages ( t , logger . messages , [
10941010 `Found private registry proxy ${ startProxyExports . getProxyPackage ( getTestPlatform ( state ) ) } in test/repo on https://github.com with URL ${ downloadUrl } ` ,
@@ -1101,7 +1017,8 @@ test.serial(
11011017 async ( t ) => {
11021018 const logger = new RecordingLogger ( ) ;
11031019 const state = initAllState ( { logger } ) ;
1104- const expectedTag = "codeql-bundle-v2.20.1" ;
1020+ const expectedVersion = "2.20.1" ;
1021+ const expectedTag = `codeql-bundle-v${ expectedVersion } ` ;
11051022 const expectedParams = {
11061023 owner : "test" ,
11071024 repo : "repo" ,
@@ -1154,14 +1071,16 @@ test.serial(
11541071 const getDefaultCliVersion = sinon
11551072 . stub ( features , "getEnabledDefaultCliVersions" )
11561073 . resolves ( {
1157- enabledVersions : [ { cliVersion : "2.20.1" , tagName : expectedTag } ] ,
1074+ enabledVersions : [
1075+ { cliVersion : expectedVersion , tagName : expectedTag } ,
1076+ ] ,
11581077 } ) ;
11591078
11601079 // Stub this to always return `false` so we force `getCodeQLAssetDownloadURL` to use the (mocked) API.
11611080 sinon . stub ( actionsUtil , "isRunningLocalAction" ) . returns ( false ) ;
11621081 state . env . set ( ActionsEnvVars . GITHUB_ACTION_REPOSITORY , "test/repo" ) ;
11631082
1164- const path = await startProxyExports . getProxyBinaryPath (
1083+ const result = await startProxyExports . getProxyBinaryPath (
11651084 {
11661085 ...state ,
11671086 features,
@@ -1179,11 +1098,12 @@ test.serial(
11791098 st . onceWith ( extractTar , archivePath ) ;
11801099 st . onceWith ( cacheDir , extractedPath ) ;
11811100
1182- t . assert ( path ) ;
1101+ t . assert ( result ) ;
11831102 t . is (
1184- path ,
1103+ result . path ,
11851104 filepath . join ( toolcachePath , startProxyExports . getProxyFilename ( ) ) ,
11861105 ) ;
1106+ t . is ( result . version , expectedVersion ) ;
11871107 } ) ;
11881108
11891109 checkExpectedLogMessages ( t , logger . messages , [
0 commit comments