@@ -5,12 +5,8 @@ import { afterEach, describe, expect, it, vi } from "vitest";
55import { mockProcessPlatform } from "../test-utils/vitest-spies.js" ;
66import {
77 evaluateRuntimeEligibility ,
8- evaluateRuntimeRequires ,
98 hasBinary ,
109 isConfigPathTruthyWithDefaults ,
11- isTruthy ,
12- resolveConfigPath ,
13- resolveRuntimePlatform ,
1410} from "./config-eval.js" ;
1511
1612const originalPath = process . env . PATH ;
@@ -32,15 +28,19 @@ afterEach(() => {
3228
3329describe ( "config-eval helpers" , ( ) => {
3430 it ( "normalizes truthy values across primitive types" , ( ) => {
35- expect ( isTruthy ( undefined ) ) . toBe ( false ) ;
36- expect ( isTruthy ( null ) ) . toBe ( false ) ;
37- expect ( isTruthy ( false ) ) . toBe ( false ) ;
38- expect ( isTruthy ( true ) ) . toBe ( true ) ;
39- expect ( isTruthy ( 0 ) ) . toBe ( false ) ;
40- expect ( isTruthy ( 1 ) ) . toBe ( true ) ;
41- expect ( isTruthy ( " " ) ) . toBe ( false ) ;
42- expect ( isTruthy ( " ok " ) ) . toBe ( true ) ;
43- expect ( isTruthy ( { } ) ) . toBe ( true ) ;
31+ for ( const [ value , expected ] of [
32+ [ undefined , false ] ,
33+ [ null , false ] ,
34+ [ false , false ] ,
35+ [ true , true ] ,
36+ [ 0 , false ] ,
37+ [ 1 , true ] ,
38+ [ " " , false ] ,
39+ [ " ok " , true ] ,
40+ [ { } , true ] ,
41+ ] as const ) {
42+ expect ( isConfigPathTruthyWithDefaults ( { value } , "value" , { } ) ) . toBe ( expected ) ;
43+ }
4444 } ) ;
4545
4646 it ( "resolves nested config paths and missing branches safely" , ( ) => {
@@ -53,10 +53,10 @@ describe("config-eval helpers", () => {
5353 } ,
5454 } ;
5555
56- expect ( resolveConfigPath ( config , "browser.enabled" ) ) . toBe ( true ) ;
57- expect ( resolveConfigPath ( config , ".browser..nested.count." ) ) . toBe ( 1 ) ;
58- expect ( resolveConfigPath ( config , "browser.missing.value" ) ) . toBeUndefined ( ) ;
59- expect ( resolveConfigPath ( "not-an-object" , "browser.enabled" ) ) . toBeUndefined ( ) ;
56+ expect ( isConfigPathTruthyWithDefaults ( config , "browser.enabled" , { } ) ) . toBe ( true ) ;
57+ expect ( isConfigPathTruthyWithDefaults ( config , ".browser..nested.count." , { } ) ) . toBe ( true ) ;
58+ expect ( isConfigPathTruthyWithDefaults ( config , "browser.missing.value" , { } ) ) . toBe ( false ) ;
59+ expect ( isConfigPathTruthyWithDefaults ( "not-an-object" , "browser.enabled" , { } ) ) . toBe ( false ) ;
6060 } ) ;
6161
6262 it ( "blocks prototype keys while resolving config paths" , ( ) => {
@@ -66,10 +66,10 @@ describe("config-eval helpers", () => {
6666 } ,
6767 } ;
6868
69- expect ( resolveConfigPath ( config , "safe.enabled" ) ) . toBe ( true ) ;
70- expect ( resolveConfigPath ( config , "__proto__" ) ) . toBeUndefined ( ) ;
71- expect ( resolveConfigPath ( config , "constructor.name" ) ) . toBeUndefined ( ) ;
72- expect ( resolveConfigPath ( config , "prototype.polluted" ) ) . toBeUndefined ( ) ;
69+ expect ( isConfigPathTruthyWithDefaults ( config , "safe.enabled" , { } ) ) . toBe ( true ) ;
70+ expect ( isConfigPathTruthyWithDefaults ( config , "__proto__" , { } ) ) . toBe ( false ) ;
71+ expect ( isConfigPathTruthyWithDefaults ( config , "constructor.name" , { } ) ) . toBe ( false ) ;
72+ expect ( isConfigPathTruthyWithDefaults ( config , "prototype.polluted" , { } ) ) . toBe ( false ) ;
7373 } ) ;
7474
7575 it ( "uses defaults only when config paths are unresolved" , ( ) => {
@@ -96,7 +96,14 @@ describe("config-eval helpers", () => {
9696
9797 it ( "returns the active runtime platform" , ( ) => {
9898 setPlatform ( "darwin" ) ;
99- expect ( resolveRuntimePlatform ( ) ) . toBe ( "darwin" ) ;
99+ expect (
100+ evaluateRuntimeEligibility ( {
101+ os : [ "darwin" ] ,
102+ hasBin : ( ) => true ,
103+ hasEnv : ( ) => true ,
104+ isConfigPathTruthy : ( ) => true ,
105+ } ) ,
106+ ) . toBe ( true ) ;
100107 } ) ;
101108
102109 it ( "caches binary lookups until PATH changes" , ( ) => {
@@ -147,9 +154,9 @@ describe("config-eval helpers", () => {
147154 } ) ;
148155} ) ;
149156
150- describe ( "evaluateRuntimeRequires " , ( ) => {
157+ describe ( "runtime requirements through eligibility " , ( ) => {
151158 it ( "accepts remote bins and remote any-bin matches" , ( ) => {
152- const result = evaluateRuntimeRequires ( {
159+ const result = evaluateRuntimeEligibility ( {
153160 requires : {
154161 bins : [ "node" ] ,
155162 anyBins : [ "bun" , "deno" ] ,
@@ -168,7 +175,7 @@ describe("evaluateRuntimeRequires", () => {
168175
169176 it ( "rejects when any required runtime check is still unsatisfied" , ( ) => {
170177 expect (
171- evaluateRuntimeRequires ( {
178+ evaluateRuntimeEligibility ( {
172179 requires : { bins : [ "node" ] } ,
173180 hasBin : ( ) => false ,
174181 hasEnv : ( ) => true ,
@@ -177,7 +184,7 @@ describe("evaluateRuntimeRequires", () => {
177184 ) . toBe ( false ) ;
178185
179186 expect (
180- evaluateRuntimeRequires ( {
187+ evaluateRuntimeEligibility ( {
181188 requires : { anyBins : [ "bun" , "node" ] } ,
182189 hasBin : ( ) => false ,
183190 hasAnyRemoteBin : ( ) => false ,
0 commit comments