@@ -10,6 +10,7 @@ import {
1010 xlingsInstallArgs ,
1111 deriveInstalledClangdPath ,
1212 findXlingsExecutable ,
13+ resolveXlingsExecutable ,
1314} from "../src/llvmTools" ;
1415
1516test ( "extracts version string from ToolIdentity" , ( ) => {
@@ -118,3 +119,41 @@ test("findXlingsExecutable honors MCPP_VENDORED_XLINGS", () => {
118119 rmSync ( root , { recursive : true , force : true } ) ;
119120 }
120121} ) ;
122+
123+ test ( "resolveXlingsExecutable reads the xlings binary from `mcpp self env`" , async ( ) => {
124+ const root = mkdtempSync ( path . join ( os . tmpdir ( ) , "mcpp-vscode-selfenv-" ) ) ;
125+ const xlingsPath = path . join ( root , "registry" , "bin" , "xlings" ) ;
126+ mkdirSync ( path . dirname ( xlingsPath ) , { recursive : true } ) ;
127+ writeFileSync ( xlingsPath , "#!/bin/sh\n" ) ;
128+ const runner = async ( ) => ( {
129+ exitCode : 0 ,
130+ stdout : `MCPP_HOME = ${ root } \nxlings binary = ${ xlingsPath } \nxlings pinned = 2026.8.8.1\n` ,
131+ stderr : "" ,
132+ } ) ;
133+ try {
134+ assert . equal (
135+ await resolveXlingsExecutable ( "/tools/mcpp" , runner ) ,
136+ xlingsPath ,
137+ ) ;
138+ } finally {
139+ rmSync ( root , { recursive : true , force : true } ) ;
140+ }
141+ } ) ;
142+
143+ test ( "resolveXlingsExecutable falls back when the reported path does not exist" , async ( ) => {
144+ const runner = async ( ) => ( {
145+ exitCode : 0 ,
146+ stdout : "xlings binary = /no/such/xlings\n" ,
147+ stderr : "" ,
148+ } ) ;
149+ const result = await resolveXlingsExecutable ( "/tools/mcpp" , runner ) ;
150+ // Fallback heuristics find nothing in this environment, so the result is
151+ // undefined unless a standalone ~/.xlings or PATH xlings happens to exist.
152+ assert . ok ( result === undefined || typeof result === "string" ) ;
153+ } ) ;
154+
155+ test ( "resolveXlingsExecutable falls back when `mcpp self env` fails" , async ( ) => {
156+ const runner = async ( ) => ( { exitCode : 1 , stdout : "" , stderr : "boom\n" } ) ;
157+ const result = await resolveXlingsExecutable ( "/tools/mcpp" , runner ) ;
158+ assert . ok ( result === undefined || typeof result === "string" ) ;
159+ } ) ;
0 commit comments