@@ -18,25 +18,12 @@ import { replMountsJourney } from "../../packages/cli/tests/support/repl-mounts-
1818 */
1919
2020import { describe , it } from "@executablemd/test-support/bdd" ;
21- import { expect } from "@executablemd/test-support/expect" ;
22- import { useTempDirectory } from "@executablemd/test-support/temp" ;
23- import { chmod , link , readlink , realpath , symlink , unlink } from "node:fs/promises" ;
24- import { runShell , shellQuote } from "@executablemd/test-support/launch" ;
25- import { copyFile , ensureDir , exists , readTextFile , writeTextFile } from "@effectionx/fs" ;
26- import { scoped , until , type Operation } from "effection" ;
27- import {
28- allocate ,
29- focusPtyDraft ,
30- settledEntry ,
31- showing ,
32- showingAcross ,
33- } from "../../packages/cli/tests/support/pty.ts" ;
21+ import { shellQuote } from "@executablemd/test-support/launch" ;
22+ import { exists } from "@effectionx/fs" ;
23+ import type { Operation } from "effection" ;
3424import { fileURLToPath as fromFileUrl } from "node:url" ;
35- import { join , relative } from "node:path" ;
25+ import { join } from "node:path" ;
3626import {
37- click ,
38- ended ,
39- printedLocation ,
4027 replFilesJourney ,
4128 replGitJourney ,
4229 replRepositoryJourney ,
@@ -90,194 +77,3 @@ describe("the compiled binary's REPL entry files", () => {
9077 yield * replMountsJourney ( compiled ) ;
9178 } ) ;
9279} ) ;
93-
94- describe ( "1440: installed development and explicit compiled launchers" , ( ) => {
95- it ( "pastes each full reopen hint through the correct launcher and restores the selected entry" , function * ( ) {
96- yield * requireBinary ( ) ;
97- const home = yield * until ( realpath ( yield * useTempDirectory ( "xmd-1440 home " ) ) ) ;
98- const bin = join ( home , ".local" , "xmd-dev" , "bin" ) ;
99- const project = join ( home , "project" , "nested" ) ;
100- const leading = join ( home , "leading PATH directory" ) ;
101- yield * ensureDir ( join ( leading , "xmd" ) ) ;
102- yield * ensureDir ( project ) ;
103- const launcher = join ( bin , "xmd-dev" ) ;
104- const installer = compiled ( [
105- "run" ,
106- shellQuote ( join ( ROOT , "examples" , "install-xmd-dev.md" ) ) ,
107- "--raw" ,
108- ] ) ;
109- const install = ( installHome : string , checkout = ROOT ) =>
110- runShell ( installer , {
111- cwd : checkout ,
112- env : { HOME : installHome } ,
113- } ) ;
114- const installed = yield * install ( home ) . expect ( ) ;
115- expect ( installed . stdout ) . toContain ( `Installed the launcher at ${ launcher } .` ) ;
116- expect ( installed . stdout ) . toContain ( 'export PATH="$HOME/.local/xmd-dev/bin:$PATH"' ) ;
117- const source = join ( ROOT , "scripts" , "xmd-dev" ) ;
118- expect ( yield * until ( readlink ( launcher ) ) ) . toBe ( source ) ;
119- const repeated = yield * install ( home ) . expect ( ) ;
120- expect ( repeated . stdout ) . toContain ( "already points to this checkout" ) ;
121- expect ( yield * until ( readlink ( launcher ) ) ) . toBe ( source ) ;
122- const selectedInstall = yield * runShell ( `PATH=${ shellQuote ( bin ) } :"$PATH" ${ installer } ` , {
123- cwd : ROOT ,
124- env : { HOME : home } ,
125- } ) . expect ( ) ;
126- expect ( selectedInstall . stdout ) . not . toContain ( "export PATH=" ) ;
127-
128- const checkoutAlias = join ( home , "checkout alias" ) ;
129- yield * until ( symlink ( ROOT , checkoutAlias ) ) ;
130- const priorHome = join ( home , "prior README home" ) ;
131- const priorLink = join ( priorHome , ".local" , "xmd-dev" , "bin" , "xmd-dev" ) ;
132- yield * runShell (
133- `cd ${ shellQuote ( checkoutAlias ) } &&
134- mkdir -p "$HOME/.local/xmd-dev/bin" &&
135- ln -s "$PWD/scripts/xmd-dev" "$HOME/.local/xmd-dev/bin/xmd-dev"` ,
136- { cwd : ROOT , env : { HOME : priorHome } } ,
137- ) . expect ( ) ;
138- const priorTarget = join ( checkoutAlias , "scripts" , "xmd-dev" ) ;
139- expect ( yield * until ( readlink ( priorLink ) ) ) . toBe ( priorTarget ) ;
140- expect ( ( yield * install ( priorHome ) . expect ( ) ) . stdout ) . toContain (
141- "already points to this checkout" ,
142- ) ;
143- expect ( yield * until ( readlink ( priorLink ) ) ) . toBe ( priorTarget ) ;
144-
145- const relativeHome = join ( home , "relative link home" ) ;
146- const relativeBin = join ( relativeHome , ".local" , "xmd-dev" , "bin" ) ;
147- const relativeLink = join ( relativeBin , "xmd-dev" ) ;
148- const relativeTarget = relative ( relativeBin , source ) ;
149- yield * ensureDir ( relativeBin ) ;
150- yield * until ( symlink ( relativeTarget , relativeLink ) ) ;
151- expect ( ( yield * install ( relativeHome ) . expect ( ) ) . stdout ) . toContain (
152- "already points to this checkout" ,
153- ) ;
154- expect ( yield * until ( readlink ( relativeLink ) ) ) . toBe ( relativeTarget ) ;
155-
156- const conflictHome = join ( home , "conflicting home" ) ;
157- const conflictBin = join ( conflictHome , ".local" , "xmd-dev" , "bin" ) ;
158- const conflict = join ( conflictBin , "xmd-dev" ) ;
159- yield * ensureDir ( conflictBin ) ;
160- const conflictContents = "#!/bin/sh\nprintf '%s\\n' existing-launcher\n" ;
161- yield * writeTextFile ( conflict , conflictContents ) ;
162- yield * until ( chmod ( conflict , 0o755 ) ) ;
163- const refused = yield * install ( conflictHome ) . join ( ) ;
164- expect ( refused . code ) . toBe ( 1 ) ;
165- expect ( refused . stderr ) . toContain ( `Could not install ${ conflict } .` ) ;
166- expect ( yield * readTextFile ( conflict ) ) . toBe ( conflictContents ) ;
167- yield * until ( unlink ( conflict ) ) ;
168- yield * writeTextFile ( join ( conflictBin , "other-launcher" ) , conflictContents ) ;
169- for ( const target of [ "other-launcher" , "missing-launcher" ] ) {
170- yield * until ( symlink ( target , conflict ) ) ;
171- expect ( ( yield * install ( conflictHome ) . join ( ) ) . code ) . toBe ( 1 ) ;
172- expect ( yield * until ( readlink ( conflict ) ) ) . toBe ( target ) ;
173- yield * until ( unlink ( conflict ) ) ;
174- }
175- yield * ensureDir ( conflict ) ;
176- expect ( ( yield * install ( conflictHome ) . join ( ) ) . code ) . toBe ( 1 ) ;
177- expect ( yield * exists ( join ( conflict , "xmd-dev" ) ) ) . toBe ( false ) ;
178- const checkoutA = join ( home , "checkout A" ) ;
179- const checkoutB = join ( home , "checkout B" ) ;
180- const launcherA = join ( checkoutA , "scripts" , "xmd-dev" ) ;
181- const launcherB = join ( checkoutB , "scripts" , "xmd-dev" ) ;
182- yield * ensureDir ( join ( checkoutA , "scripts" ) ) ;
183- yield * ensureDir ( join ( checkoutB , "scripts" ) ) ;
184- yield * copyFile ( source , launcherA ) ;
185- yield * until ( chmod ( launcherA , 0o755 ) ) ;
186- yield * until ( link ( launcherA , launcherB ) ) ;
187-
188- const linkedHome = join ( home , "hard-linked launcher home" ) ;
189- const linkedBin = join ( linkedHome , ".local" , "xmd-dev" , "bin" ) ;
190- const linkedLauncher = join ( linkedBin , "xmd-dev" ) ;
191- yield * ensureDir ( linkedBin ) ;
192- yield * until ( symlink ( launcherB , linkedLauncher ) ) ;
193- const wrongCheckout = yield * install ( linkedHome , checkoutA ) . join ( ) ;
194- expect ( wrongCheckout . code ) . toBe ( 1 ) ;
195- expect ( wrongCheckout . stderr ) . toContain ( `Could not install ${ linkedLauncher } .` ) ;
196- expect ( yield * until ( readlink ( linkedLauncher ) ) ) . toBe ( launcherB ) ;
197-
198- const prefix = `unset XMD_DEV_ROOT XMD_DEV_DENO; export PATH=${ shellQuote ( leading ) } :${ shellQuote ( bin ) } :"$PATH"; cd ${ shellQuote ( project ) } &&` ;
199- const version = ( yield * runShell ( compiled ( [ "--version" ] ) ) . expect ( ) ) . stdout . trim ( ) ;
200- const found = yield * runShell ( `${ prefix } command -v xmd-dev && xmd-dev --version` ) . expect ( ) ;
201- expect ( found . stdout . trim ( ) . split ( "\n" ) ) . toEqual ( [ launcher , version ] ) ;
202-
203- const override = join ( home , "override checkout" ) ;
204- const overrideDir = join ( override , "packages" , "cli" , "src" ) ;
205- yield * ensureDir ( overrideDir ) ;
206- yield * writeTextFile (
207- join ( overrideDir , "deno.ts" ) ,
208- 'console.log("override checkout witness");\n' ,
209- ) ;
210- const overrideLaunch = yield * runShell (
211- `${ prefix } XMD_DEV_ROOT=${ shellQuote ( override ) } xmd-dev --version` ,
212- ) . expect ( ) ;
213- expect ( overrideLaunch . stdout . trim ( ) ) . toBe ( "override checkout witness" ) ;
214-
215- const decoy = join ( bin , "xmd" ) ;
216- yield * writeTextFile (
217- decoy ,
218- `#!/bin/sh\nif [ "$1" = --version ]; then printf '%s\\n' ${ shellQuote ( version ) } ; else exit 73; fi\n` ,
219- ) ;
220- yield * until ( chmod ( decoy , 0o755 ) ) ;
221- expect ( ( yield * runShell ( `${ prefix } xmd --version` ) . expect ( ) ) . stdout . trim ( ) ) . toBe ( version ) ;
222- expect ( ( yield * runShell ( `${ prefix } xmd repl` ) . join ( ) ) . code ) . toBe ( 73 ) ;
223-
224- const task = `deno task --cwd ${ shellQuote ( ROOT ) } xmd` ;
225- expect ( ( yield * runShell ( `${ prefix } ${ task } --version` ) . expect ( ) ) . stdout . trim ( ) ) . toBe ( version ) ;
226- const taskOutput = yield * runShell (
227- `${ prefix } ${ task } run --eval ${ shellQuote ( "<Output>Task argument witness</Output>" ) } ` ,
228- ) . expect ( ) ;
229- expect ( taskOutput . stdout . trim ( ) ) . toBe ( "Task argument witness" ) ;
230-
231- for ( const command of [ "xmd-dev" , task , shellQuote ( BINARY ) , "xmd" ] ) {
232- if ( command === "xmd" ) {
233- yield * until ( unlink ( decoy ) ) ;
234- yield * until ( symlink ( BINARY , decoy ) ) ;
235- }
236- yield * scoped ( function * ( ) {
237- const pty = yield * allocate ( `${ prefix } ${ command } repl --deny-all` , home ) ;
238- yield * showing ( pty , "[exit]" , 60_000 ) ;
239- yield * focusPtyDraft ( pty , 10_000 ) ;
240- yield * pty . type ( "<Output>Retained launcher witness</Output>" ) ;
241- yield * showing ( pty , "Retained launcher witness" , 10_000 ) ;
242- yield * pty . type ( "\t\r" ) ;
243- yield * settledEntry ( pty , 1 , "ok" , 10_000 ) ;
244- yield * click ( pty , "[exit]" ) ;
245- expect ( yield * ended ( pty ) ) . toBe ( 0 ) ;
246- const saved = printedLocation ( yield * pty . finalOutput ( ) ) . split ( "?" ) [ 0 ] ;
247- expect ( saved ) . toMatch ( / \/ e n t r i e s \/ e n t r y - 1 $ / ) ;
248- const location = saved + "?at=close:root&right=bindings" ;
249- const selected = yield * allocate ( `${ prefix } ${ command } repl ${ shellQuote ( location ) } ` , home ) ;
250- yield * showingAcross ( selected , "Retained launcher witness" , 30_000 ) ;
251- yield * click ( selected , "[exit]" ) ;
252- expect ( yield * ended ( selected ) ) . toBe ( 0 ) ;
253- const printed = / ^ ( .+ r e p l ' x m d : \/ \/ r e p l \/ [ ^ ' ] + ' ) \r ? $ / m. exec (
254- yield * selected . finalOutput ( ) ,
255- ) ?. [ 1 ] ;
256- if ( printed === undefined ) {
257- throw new Error ( "The terminal printed no complete reopen command." ) ;
258- }
259- if ( command === "xmd" ) {
260- expect ( printed . startsWith ( "xmd repl " ) ) . toBe ( true ) ;
261- } else if ( command === task ) {
262- expect ( printed ) . toContain ( "XMD_REPL_DENO_PROFILE='repository-task'" ) ;
263- expect ( printed ) . toContain ( " run --allow-all " ) ;
264- expect ( printed ) . toContain ( join ( ROOT , "packages" , "cli" , "src" , "deno.ts" ) ) ;
265- } else {
266- expect ( printed ) . toContain ( command === "xmd-dev" ? shellQuote ( launcher ) : BINARY ) ;
267- }
268- expect ( printed . endsWith ( shellQuote ( location ) ) ) . toBe ( true ) ;
269-
270- // A pasted development hint carries its original checkout even when
271- // the receiving shell has selected another checkout.
272- const pasted = yield * allocate (
273- `${ prefix } export XMD_DEV_ROOT=${ shellQuote ( override ) } ; ${ printed } ` ,
274- home ,
275- ) ;
276- yield * showingAcross ( pasted , "Retained launcher witness" , 30_000 ) ;
277- yield * click ( pasted , "[exit]" ) ;
278- expect ( yield * ended ( pasted ) ) . toBe ( 0 ) ;
279- expect ( yield * pasted . finalOutput ( ) ) . toContain ( printed ) ;
280- } ) ;
281- }
282- } ) ;
283- } ) ;
0 commit comments