11/**
22 * Pack the exact publish manifests, install them as an external npm consumer,
33 * then exercise every public SDK entry point plus the CLI and Playground bins.
4+ *
5+ * `--sdk-only` restricts the run to the SDK package: pack/install only the sdk
6+ * tarball (still with --engine-strict) and execute the SDK entry-point imports.
7+ * This is the mode CI uses on Node versions below the cli/playground engines
8+ * floor (>=22) to enforce the SDK's own >=18.17.0 engines contract.
49 */
510
611import { mkdirSync , mkdtempSync , readFileSync , rmSync , writeFileSync } from "node:fs" ;
@@ -18,6 +23,14 @@ import {
1823
1924const root = resolve ( import . meta. dirname , "../.." ) ;
2025
26+ export function isSdkOnly ( argv : readonly string [ ] ) : boolean {
27+ return argv . includes ( "--sdk-only" ) ;
28+ }
29+
30+ export function smokePackages ( sdkOnly : boolean ) : readonly ( typeof PACKAGES ) [ number ] [ ] {
31+ return sdkOnly ? PACKAGES . filter ( ( pkg ) => pkg === "sdk" ) : PACKAGES ;
32+ }
33+
2134type PackedPackage = { filename : string } ;
2235
2336export function packedFilename ( raw : string , pkg : string ) : string {
@@ -33,9 +46,9 @@ function run(command: string[], cwd: string, stdout: "inherit" | "pipe" = "inher
3346 return stdout === "pipe" ? ( result . stdout ?. toString ( ) . trim ( ) ?? "" ) : "" ;
3447}
3548
36- function packPackages ( destination : string ) : string [ ] {
49+ function packPackages ( destination : string , packages : readonly ( typeof PACKAGES ) [ number ] [ ] ) : string [ ] {
3750 const versions = workspaceVersions ( ) ;
38- return PACKAGES . map ( ( pkg ) => {
51+ return packages . map ( ( pkg ) => {
3952 const pkgDir = join ( root , "packages" , pkg ) ;
4053 let originalLicense : string | undefined ;
4154 let originalManifest : string | undefined ;
@@ -104,6 +117,8 @@ async function smokePlayground(consumer: string): Promise<void> {
104117}
105118
106119async function main ( ) : Promise < void > {
120+ const sdkOnly = isSdkOnly ( process . argv . slice ( 2 ) ) ;
121+ const packages = smokePackages ( sdkOnly ) ;
107122 const temporaryRoot = mkdtempSync ( join ( tmpdir ( ) , "openagentpack-consumer-" ) ) ;
108123 try {
109124 const tarballsDir = join ( temporaryRoot , "tarballs" ) ;
@@ -112,7 +127,7 @@ async function main(): Promise<void> {
112127 mkdirSync ( consumer ) ;
113128 writeFileSync ( join ( consumer , "package.json" ) , '{"name":"agents-package-smoke","private":true,"type":"module"}\n' ) ;
114129
115- const tarballs = packPackages ( tarballsDir ) ;
130+ const tarballs = packPackages ( tarballsDir , packages ) ;
116131 run (
117132 [
118133 "npm" ,
@@ -126,7 +141,7 @@ async function main(): Promise<void> {
126141 ] ,
127142 consumer ,
128143 ) ;
129- for ( const pkg of PACKAGES ) {
144+ for ( const pkg of packages ) {
130145 const license = readFileSync ( join ( consumer , `node_modules/@openagentpack/${ pkg } /LICENSE` ) , "utf8" ) ;
131146 if ( license !== readFileSync ( join ( root , "LICENSE" ) , "utf8" ) ) {
132147 throw new Error ( `${ pkg } package is missing the repository license` ) ;
@@ -143,21 +158,23 @@ async function main(): Promise<void> {
143158 consumer ,
144159 ) ;
145160
146- const expectedVersion = JSON . parse ( readFileSync ( join ( root , "packages/cli/package.json" ) , "utf8" ) ) as {
147- version : string ;
148- } ;
149- const cliVersion = run (
150- [ "node" , join ( consumer , "node_modules/@openagentpack/cli/dist/bin/agents.js" ) , "--version" ] ,
151- consumer ,
152- "pipe" ,
153- ) ;
154- if ( cliVersion !== expectedVersion . version ) {
155- throw new Error ( `Packed CLI version mismatch: expected ${ expectedVersion . version } , received ${ cliVersion } ` ) ;
156- }
161+ if ( ! sdkOnly ) {
162+ const expectedVersion = JSON . parse ( readFileSync ( join ( root , "packages/cli/package.json" ) , "utf8" ) ) as {
163+ version : string ;
164+ } ;
165+ const cliVersion = run (
166+ [ "node" , join ( consumer , "node_modules/@openagentpack/cli/dist/bin/agents.js" ) , "--version" ] ,
167+ consumer ,
168+ "pipe" ,
169+ ) ;
170+ if ( cliVersion !== expectedVersion . version ) {
171+ throw new Error ( `Packed CLI version mismatch: expected ${ expectedVersion . version } , received ${ cliVersion } ` ) ;
172+ }
157173
158- await smokePlayground ( consumer ) ;
174+ await smokePlayground ( consumer ) ;
175+ }
159176 const nodeVersion = run ( [ "node" , "--version" ] , consumer , "pipe" ) ;
160- console . log ( `✓ Packed packages install and run under ${ nodeVersion } ` ) ;
177+ console . log ( `✓ Packed ${ sdkOnly ? "SDK package installs" : " packages install" } and run under ${ nodeVersion } ` ) ;
161178 } finally {
162179 rmSync ( temporaryRoot , { recursive : true , force : true } ) ;
163180 }
0 commit comments