2026-05-10 23:12:26 +02:00
import assert from 'node:assert/strict' ;
import { readFile } from 'node:fs/promises' ;
import { describe , it } from 'node:test' ;
import {
buildPublishedPackageNpxCommand ,
buildPublishedPackageSmokeCommands ,
2026-05-11 15:50:34 +02:00
isPublishedPackageSemanticQueryLabel ,
isPublishedPackageVersionLabel ,
2026-05-10 23:12:26 +02:00
publishedPackageSpec ,
readPublishedPackageSmokeConfig ,
} from './published-package-smoke.mjs' ;
describe ( 'published package smoke config' , ( ) => {
it ( 'skips by default until a published package name is supplied' , ( ) => {
assert . deepEqual ( readPublishedPackageSmokeConfig ( { } , [ ] ) , {
enabled : false ,
requireConfig : false ,
reason :
2026-05-10 23:51:24 +02:00
'Set KTX_PUBLISHED_KTX_PACKAGE or release-policy.json publishedPackageSmoke.packageName to the published npm package name after the release decision.' ,
2026-05-10 23:12:26 +02:00
} ) ;
} ) ;
it ( 'can require the published package config for post-publication CI' , ( ) => {
assert . deepEqual ( readPublishedPackageSmokeConfig ( { } , [ '--require-config' ] ) , {
enabled : false ,
requireConfig : true ,
reason :
2026-05-10 23:51:24 +02:00
'Set KTX_PUBLISHED_KTX_PACKAGE or release-policy.json publishedPackageSmoke.packageName to the published npm package name after the release decision.' ,
2026-05-10 23:12:26 +02:00
} ) ;
} ) ;
it ( 'reads the package, version, and registry from environment variables' , ( ) => {
assert . deepEqual (
readPublishedPackageSmokeConfig (
{
2026-05-11 15:50:34 +02:00
KTX _PUBLISHED _KTX _PACKAGE : '@kaelio/ktx' ,
2026-05-10 23:51:24 +02:00
KTX _PUBLISHED _KTX _VERSION : 'latest' ,
KTX _PUBLISHED _KTX _REGISTRY : 'https://registry.npmjs.org/' ,
2026-05-10 23:12:26 +02:00
} ,
[ ] ,
) ,
{
enabled : true ,
requireConfig : false ,
configSource : 'environment' ,
2026-05-11 15:50:34 +02:00
packageName : '@kaelio/ktx' ,
2026-05-10 23:12:26 +02:00
packageVersion : 'latest' ,
registry : 'https://registry.npmjs.org/' ,
} ,
) ;
} ) ;
it ( 'reads the package, version, and registry from release policy when env vars are absent' , ( ) => {
assert . deepEqual (
readPublishedPackageSmokeConfig (
{ } ,
[ ] ,
{
2026-05-11 15:50:34 +02:00
packageName : '@kaelio/ktx' ,
2026-05-10 23:12:26 +02:00
version : '2026.5.8' ,
registry : 'https://registry.npmjs.org/' ,
} ,
) ,
{
enabled : true ,
requireConfig : false ,
configSource : 'release-policy' ,
2026-05-11 15:50:34 +02:00
packageName : '@kaelio/ktx' ,
2026-05-10 23:12:26 +02:00
packageVersion : '2026.5.8' ,
registry : 'https://registry.npmjs.org/' ,
} ,
) ;
} ) ;
it ( 'lets environment variables override release policy values' , ( ) => {
assert . deepEqual (
readPublishedPackageSmokeConfig (
{
2026-05-11 15:50:34 +02:00
KTX _PUBLISHED _KTX _PACKAGE : '@kaelio/ktx' ,
2026-05-10 23:51:24 +02:00
KTX _PUBLISHED _KTX _VERSION : 'latest' ,
2026-05-10 23:12:26 +02:00
} ,
[ ] ,
{
2026-05-11 15:50:34 +02:00
packageName : '@kaelio/ktx' ,
2026-05-10 23:12:26 +02:00
version : '2026.5.8' ,
registry : 'https://registry.npmjs.org/' ,
} ,
) ,
{
enabled : true ,
requireConfig : false ,
configSource : 'environment' ,
2026-05-11 15:50:34 +02:00
packageName : '@kaelio/ktx' ,
2026-05-10 23:12:26 +02:00
packageVersion : 'latest' ,
registry : 'https://registry.npmjs.org/' ,
} ,
) ;
} ) ;
it ( 'rejects package names that would be unsafe as npx package specs' , ( ) => {
assert . throws (
2026-05-10 23:51:24 +02:00
( ) => readPublishedPackageSmokeConfig ( { KTX _PUBLISHED _KTX _PACKAGE : '--package=@evil/pkg' } , [ ] ) ,
/Invalid KTX_PUBLISHED_KTX_PACKAGE/ ,
2026-05-10 23:12:26 +02:00
) ;
assert . throws (
2026-05-10 23:51:24 +02:00
( ) => readPublishedPackageSmokeConfig ( { KTX _PUBLISHED _KTX _PACKAGE : '@ktx/cli public' } , [ ] ) ,
/Invalid KTX_PUBLISHED_KTX_PACKAGE/ ,
2026-05-10 23:12:26 +02:00
) ;
assert . throws (
( ) =>
readPublishedPackageSmokeConfig (
{ } ,
[ ] ,
{
2026-05-10 23:51:24 +02:00
packageName : '@ktx/cli public' ,
2026-05-10 23:12:26 +02:00
version : 'latest' ,
registry : null ,
} ,
) ,
/Invalid release-policy\.json publishedPackageSmoke\.packageName/ ,
) ;
} ) ;
it ( 'rejects unsafe version tags and non-HTTP registries' , ( ) => {
assert . throws (
( ) =>
readPublishedPackageSmokeConfig (
{
2026-05-11 15:50:34 +02:00
KTX _PUBLISHED _KTX _PACKAGE : '@kaelio/ktx' ,
2026-05-10 23:51:24 +02:00
KTX _PUBLISHED _KTX _VERSION : '--tag latest' ,
2026-05-10 23:12:26 +02:00
} ,
[ ] ,
) ,
2026-05-10 23:51:24 +02:00
/Invalid KTX_PUBLISHED_KTX_VERSION/ ,
2026-05-10 23:12:26 +02:00
) ;
assert . throws (
( ) =>
readPublishedPackageSmokeConfig (
{
2026-05-11 15:50:34 +02:00
KTX _PUBLISHED _KTX _PACKAGE : '@kaelio/ktx' ,
2026-05-10 23:51:24 +02:00
KTX _PUBLISHED _KTX _REGISTRY : 'file:///tmp/npm' ,
2026-05-10 23:12:26 +02:00
} ,
[ ] ,
) ,
2026-05-10 23:51:24 +02:00
/KTX_PUBLISHED_KTX_REGISTRY must be an http\(s\) URL/ ,
2026-05-10 23:12:26 +02:00
) ;
} ) ;
} ) ;
2026-05-11 15:50:34 +02:00
describe ( 'published package smoke output validation labels' , ( ) => {
it ( 'classifies version and semantic query commands' , ( ) => {
assert . equal ( isPublishedPackageVersionLabel ( 'published package npx version' ) , true ) ;
assert . equal ( isPublishedPackageVersionLabel ( 'published package local version' ) , true ) ;
assert . equal ( isPublishedPackageVersionLabel ( 'published package global version' ) , true ) ;
assert . equal ( isPublishedPackageVersionLabel ( 'published package setup demo' ) , false ) ;
assert . equal ( isPublishedPackageSemanticQueryLabel ( 'published package npx sl query' ) , true ) ;
assert . equal ( isPublishedPackageSemanticQueryLabel ( 'published package local sl query' ) , true ) ;
assert . equal ( isPublishedPackageSemanticQueryLabel ( 'published package global sl query' ) , true ) ;
assert . equal ( isPublishedPackageSemanticQueryLabel ( 'published package local install' ) , false ) ;
} ) ;
} ) ;
2026-05-10 23:12:26 +02:00
describe ( 'published package smoke command construction' , ( ) => {
const config = {
enabled : true ,
requireConfig : false ,
2026-05-11 15:50:34 +02:00
packageName : '@kaelio/ktx' ,
2026-05-10 23:12:26 +02:00
packageVersion : 'latest' ,
registry : 'https://registry.npmjs.org/' ,
} ;
it ( 'builds the npx package spec from package name and version tag' , ( ) => {
2026-05-11 15:50:34 +02:00
assert . equal ( publishedPackageSpec ( config ) , '@kaelio/ktx@latest' ) ;
2026-05-10 23:12:26 +02:00
} ) ;
it ( 'builds npx commands with a registry env patch instead of shell interpolation' , ( ) => {
assert . deepEqual ( buildPublishedPackageNpxCommand ( config , [ '--version' ] ) , {
label : 'published package command' ,
command : 'npx' ,
2026-05-11 15:50:34 +02:00
args : [ '--yes' , '@kaelio/ktx@latest' , '--version' ] ,
2026-05-10 23:12:26 +02:00
env : { npm _config _registry : 'https://registry.npmjs.org/' } ,
} ) ;
} ) ;
2026-05-11 15:50:34 +02:00
it ( 'builds the full public package smoke command list' , ( ) => {
assert . deepEqual (
buildPublishedPackageSmokeCommands (
config ,
'/tmp/ktx-smoke/demo' ,
'/tmp/ktx-smoke/managed-runtime' ,
) ,
[
{
label : 'published package npx version' ,
command : 'npx' ,
args : [ '--yes' , '@kaelio/ktx@latest' , '--version' ] ,
env : { npm _config _registry : 'https://registry.npmjs.org/' } ,
} ,
{
label : 'published package setup demo' ,
command : 'npx' ,
args : [
'--yes' ,
'@kaelio/ktx@latest' ,
'setup' ,
'demo' ,
'--project-dir' ,
'/tmp/ktx-smoke/demo' ,
'--no-input' ,
'--plain' ,
] ,
env : {
npm _config _registry : 'https://registry.npmjs.org/' ,
KTX _RUNTIME _ROOT : '/tmp/ktx-smoke/managed-runtime' ,
} ,
} ,
{
label : 'published package npx sl query' ,
command : 'npx' ,
args : [
'--yes' ,
'@kaelio/ktx@latest' ,
'sl' ,
'query' ,
'--project-dir' ,
'/tmp/ktx-smoke/demo' ,
'--connection-id' ,
'orbit_demo' ,
'--measure' ,
'contracts.contract_count' ,
'--format' ,
'sql' ,
'--yes' ,
] ,
env : {
npm _config _registry : 'https://registry.npmjs.org/' ,
KTX _RUNTIME _ROOT : '/tmp/ktx-smoke/managed-runtime' ,
} ,
} ,
{
label : 'published package local install' ,
command : 'pnpm' ,
args : [ 'add' , '@kaelio/ktx@latest' ] ,
env : { npm _config _registry : 'https://registry.npmjs.org/' } ,
} ,
{
label : 'published package local version' ,
command : 'npx' ,
args : [ 'ktx' , '--version' ] ,
env : { npm _config _registry : 'https://registry.npmjs.org/' } ,
} ,
{
label : 'published package local sl query' ,
command : 'npx' ,
args : [
'ktx' ,
'sl' ,
'query' ,
'--project-dir' ,
'/tmp/ktx-smoke/demo' ,
'--connection-id' ,
'orbit_demo' ,
'--measure' ,
'contracts.contract_count' ,
'--format' ,
'sql' ,
'--yes' ,
] ,
env : {
npm _config _registry : 'https://registry.npmjs.org/' ,
KTX _RUNTIME _ROOT : '/tmp/ktx-smoke/managed-runtime' ,
} ,
} ,
{
label : 'published package global install' ,
command : 'pnpm' ,
args : [ 'add' , '--global' , '@kaelio/ktx@latest' ] ,
env : { npm _config _registry : 'https://registry.npmjs.org/' } ,
} ,
{
label : 'published package global version' ,
command : 'ktx' ,
args : [ '--version' ] ,
env : { npm _config _registry : 'https://registry.npmjs.org/' } ,
} ,
{
label : 'published package global sl query' ,
command : 'ktx' ,
args : [
'sl' ,
'query' ,
'--project-dir' ,
'/tmp/ktx-smoke/demo' ,
'--connection-id' ,
'orbit_demo' ,
'--measure' ,
'contracts.contract_count' ,
'--format' ,
'sql' ,
'--yes' ,
] ,
env : {
npm _config _registry : 'https://registry.npmjs.org/' ,
KTX _RUNTIME _ROOT : '/tmp/ktx-smoke/managed-runtime' ,
} ,
} ,
] ,
) ;
2026-05-10 23:12:26 +02:00
} ) ;
it ( 'exposes the smoke through the package release script' , async ( ) => {
const packageJson = JSON . parse ( await readFile ( new URL ( '../package.json' , import . meta . url ) , 'utf8' ) ) ;
assert . equal (
packageJson . scripts [ 'release:published-smoke' ] ,
'node scripts/published-package-smoke.mjs --require-config' ,
) ;
} ) ;
} ) ;