11import { afterEach , beforeEach , describe , expect , mock , spyOn , test } from 'bun:test'
22import * as announce from '../lib/announce'
33import * as ci from '../lib/ci'
4- import { SLACK_CHANNELS } from '../lib/constants'
4+ import { CLI_PACKAGE_NAME , SLACK_CHANNELS } from '../lib/constants'
55import { io } from '../lib/io'
66import { SAMPLE_CHANGELOG , shellPromise , shellResult , silenceIO } from '../lib/test-helpers'
77import { finalize } from './finalize'
8+ import { platformPackageNames } from './targets'
89
910describe ( 'finalize.ts' , ( ) => {
1011 beforeEach ( ( ) => {
@@ -21,7 +22,7 @@ describe('finalize.ts', () => {
2122 function setupFinalizePath ( ) {
2223 spyOn ( io , 'mintGitHubAppToken' ) . mockResolvedValue ( 'fake-gh-token' )
2324 spyOn ( io , 'publishCliPackage' ) . mockResolvedValue ( shellResult ( ) )
24- spyOn ( io , 'verifyCli ' ) . mockResolvedValue ( shellResult ( ) )
25+ spyOn ( io , 'verifyPackages ' ) . mockResolvedValue ( shellResult ( ) )
2526 spyOn ( ci , 'loadWorkspacePackages' ) . mockResolvedValue ( [
2627 { name : 'agent-facets' , version : '0.4.0' , dir : 'packages/cli' } ,
2728 ] )
@@ -44,37 +45,47 @@ describe('finalize.ts', () => {
4445 expect ( code ) . toBe ( 1 )
4546 } )
4647
47- test ( 'runs the full verify → publish pipeline' , async ( ) => {
48+ test ( 'runs the full verify → publish → verify pipeline' , async ( ) => {
4849 process . env . CIRCLE_TAG = 'agent-facets@0.4.0'
4950 setupFinalizePath ( )
5051
5152 const publishSpy = spyOn ( io , 'publishCliPackage' ) . mockResolvedValue ( shellResult ( ) )
52- const verifySpy = spyOn ( io , 'verifyCli ' ) . mockResolvedValue ( shellResult ( ) )
53+ const verifySpy = spyOn ( io , 'verifyPackages ' ) . mockResolvedValue ( shellResult ( ) )
5354
5455 const code = await finalize ( )
5556
5657 expect ( code ) . toBe ( 0 )
5758 expect ( publishSpy ) . toHaveBeenCalledTimes ( 1 )
58- expect ( verifySpy ) . toHaveBeenCalledTimes ( 1 )
59+ expect ( verifySpy ) . toHaveBeenCalledTimes ( 2 )
5960 } )
6061
61- test ( 'verifies platform packages before publishing CLI package ' , async ( ) => {
62+ test ( 'verifies platforms, publishes CLI, then verifies CLI wrapper ' , async ( ) => {
6263 process . env . CIRCLE_TAG = 'agent-facets@0.4.0'
6364 setupFinalizePath ( )
6465
65- const callOrder : string [ ] = [ ]
66- spyOn ( io , 'verifyCli ' ) . mockImplementation ( ( ) => {
67- callOrder . push ( 'verify' )
66+ const callOrder : Array < { phase : string ; args ?: unknown [ ] } > = [ ]
67+ spyOn ( io , 'verifyPackages ' ) . mockImplementation ( ( packages : string [ ] , version : string ) => {
68+ callOrder . push ( { phase : 'verify' , args : [ packages , version ] } )
6869 return shellPromise ( )
6970 } )
7071 spyOn ( io , 'publishCliPackage' ) . mockImplementation ( ( ) => {
71- callOrder . push ( 'publish' )
72+ callOrder . push ( { phase : 'publish' } )
7273 return shellPromise ( )
7374 } )
7475
7576 await finalize ( )
7677
77- expect ( callOrder ) . toEqual ( [ 'verify' , 'publish' ] )
78+ expect ( callOrder . map ( ( c ) => c . phase ) ) . toEqual ( [ 'verify' , 'publish' , 'verify' ] )
79+
80+ // First verify call: the 12 platform packages
81+ const firstVerifyArgs = callOrder [ 0 ] ?. args
82+ expect ( firstVerifyArgs ?. [ 0 ] ) . toEqual ( platformPackageNames ( ) )
83+ expect ( firstVerifyArgs ?. [ 1 ] ) . toBe ( '0.4.0' )
84+
85+ // Second verify call: just the CLI wrapper
86+ const secondVerifyArgs = callOrder [ 2 ] ?. args
87+ expect ( secondVerifyArgs ?. [ 0 ] ) . toEqual ( [ CLI_PACKAGE_NAME ] )
88+ expect ( secondVerifyArgs ?. [ 1 ] ) . toBe ( '0.4.0' )
7889 } )
7990
8091 test ( 'mints GitHub token for release creation' , async ( ) => {
@@ -90,15 +101,17 @@ describe('finalize.ts', () => {
90101 expect ( process . env . GITHUB_TOKEN ) . toBe ( 'gh-token' )
91102 } )
92103
93- test ( 'passes version to verify' , async ( ) => {
104+ test ( 'passes version and correct package list to both verify calls ' , async ( ) => {
94105 process . env . CIRCLE_TAG = 'agent-facets@0.4.0'
95106 setupFinalizePath ( )
96107
97- const verifySpy = spyOn ( io , 'verifyCli ' ) . mockResolvedValue ( shellResult ( ) )
108+ const verifySpy = spyOn ( io , 'verifyPackages ' ) . mockResolvedValue ( shellResult ( ) )
98109
99110 await finalize ( )
100111
101- expect ( verifySpy ) . toHaveBeenCalledWith ( '0.4.0' )
112+ expect ( verifySpy ) . toHaveBeenCalledTimes ( 2 )
113+ expect ( verifySpy ) . toHaveBeenNthCalledWith ( 1 , platformPackageNames ( ) , '0.4.0' )
114+ expect ( verifySpy ) . toHaveBeenNthCalledWith ( 2 , [ CLI_PACKAGE_NAME ] , '0.4.0' )
102115 } )
103116
104117 test ( 'creates GitHub Release after verify' , async ( ) => {
0 commit comments