@@ -2,14 +2,16 @@ import assert from 'node:assert/strict';
22import fs from 'node:fs' ;
33import path from 'node:path' ;
44import createDebug from 'debug' ;
5+ import { pick } from 'lodash' ;
56
67import { handler as writeBuildInfo } from 'hadron-build/commands/info' ;
78
89import { type PackageKind } from './packages' ;
910import { type SmokeTestsContextWithSandbox } from './context' ;
10- import { pick } from 'lodash ' ;
11+ import { createSandbox } from './directories ' ;
1112
1213const debug = createDebug ( 'compass:smoketests:build-info' ) ;
14+ const COMPASS_PATH = path . resolve ( __dirname , '../../compass' ) ;
1315
1416const SUPPORTED_CHANNELS = [ 'dev' , 'beta' , 'stable' ] as const ;
1517
@@ -229,16 +231,18 @@ export function readPackageDetails(
229231 return getPackageDetails ( kind , result ) ;
230232}
231233
232- export function writeAndReadPackageDetails (
233- context : SmokeTestsContextWithSandbox
234- ) : PackageDetails {
235- const compassDir = path . resolve ( __dirname , '../../compass' ) ;
234+ export function writeAndReadPackageDetails ( {
235+ package : packageKind ,
236+ platform,
237+ arch,
238+ sandboxPath,
239+ } : SmokeTestsContextWithSandbox ) : PackageDetails {
236240 const infoArgs = {
237241 format : 'json' ,
238- dir : compassDir ,
239- platform : context . platform ,
240- arch : context . arch ,
241- out : path . resolve ( context . sandboxPath , 'target.json' ) ,
242+ dir : COMPASS_PATH ,
243+ platform,
244+ arch,
245+ out : path . resolve ( sandboxPath , 'target.json' ) ,
242246 } ;
243247 debug ( { infoArgs } ) ;
244248
@@ -258,5 +262,25 @@ export function writeAndReadPackageDetails(
258262 ] )
259263 ) ;
260264 writeBuildInfo ( infoArgs ) ;
261- return readPackageDetails ( context . package , infoArgs . out ) ;
265+ return readPackageDetails ( packageKind , infoArgs . out ) ;
266+ }
267+
268+ export function getCompassVersionFromBuildInfo ( ) : string {
269+ const out = path . resolve ( createSandbox ( ) , 'target.json' ) ;
270+ writeBuildInfo ( {
271+ format : 'json' ,
272+ dir : COMPASS_PATH ,
273+ platform : 'linux' ,
274+ arch : 'x64' ,
275+ out,
276+ } ) ;
277+ const result = readJson ( out ) ;
278+ assert ( typeof result === 'object' , 'Expected hadron to write an object' ) ;
279+ assert (
280+ 'version' in result ,
281+ 'Expected hadron to write an object with a version'
282+ ) ;
283+ const { version } = result ;
284+ assert ( typeof version === 'string' , 'Expected version to be a string' ) ;
285+ return version ;
262286}
0 commit comments