3
3
// review
4
4
// run
5
5
6
- import { assertEquals } from "jsr:@std/assert" ;
6
+ import { assertEquals , assertArrayIncludes } from "jsr:@std/assert" ;
7
7
import { assertSnapshot } from "jsr:@std/testing/snapshot" ;
8
8
import { $ } from "jsr:@david/dax"
9
9
@@ -81,9 +81,12 @@ Deno.test.ignore("diff", async (t) => {
81
81
82
82
Deno . test ( "init" , async ( t ) => {
83
83
const { dir} = await setup ( ) ;
84
- const files = await Array . fromAsync ( Deno . readDir ( dir ) ) ;
85
- const filenames = files . map ( f => f . name ) . sort ( ) ;
86
- assertSnapshot ( t , filenames ) ;
84
+ const files = ( await getAllFiles ( dir ) ) . map ( f => f . replace ( dir , "" ) ) ;
85
+ assertEquals ( files , [
86
+ "/runbooks/binder/_template-deno.ipynb" ,
87
+ "/runbooks/binder/_template-python.ipynb" ,
88
+ "/runbooks/.runbook.json" ,
89
+ ] )
87
90
} ) ;
88
91
89
92
Deno . test ( "list" , async ( t ) => {
@@ -99,6 +102,27 @@ Deno.test("show", async (t) => {
99
102
assertSnapshot ( t , { stdout : cmd . stdout , stderr : cmd . stderr , exitCode : cmd . code } ) ;
100
103
} ) ;
101
104
105
+ // plan
106
+ Deno . test ( "plan: prompter interface" , async ( t ) => {
107
+ const cwd = Deno . cwd ( ) ;
108
+ const { runbook, dir } = await setup ( ) ;
109
+ const cmd = await runbook ( [ "plan" , "runbooks/binder/_template-deno.ipynb" , "--prompter" , [ cwd , "tests/fixtures/prompters/echoer" ] . join ( "/" ) ] ) ;
110
+ assertEquals ( cmd . code , 0 ) ;
111
+
112
+ const files = await getAllFiles ( $ . path ( dir ) . join ( "runbooks/runs" ) . toString ( ) ) ;
113
+ const planFile = files . find ( f => f . endsWith ( "_template-deno/_template-deno.ipynb" ) ) ;
114
+ if ( ! planFile ) {
115
+ throw new Error ( "Plan file not found" ) ;
116
+ }
117
+ const json = await Deno . readTextFile ( planFile ) ;
118
+ const plan = JSON . parse ( json ) ;
119
+ const maybeParamCells = plan . cells . filter ( ( c : any ) => c . cell_type === "code" && c . metadata ?. tags ?. includes ( "injected-parameters" ) ) ;
120
+ assertEquals ( maybeParamCells . length , 1 ) ;
121
+ const paramCell = maybeParamCells [ 0 ] ;
122
+ assertArrayIncludes ( paramCell . source , [ `server = "main.xargs.io";\n` , `arg = 1;\n` , `anArray = ["a", "b"];\n` ] ) ;
123
+ // assertSnapshot(t, { stdout: cmd.stdout, stderr: cmd.stderr, exitCode: cmd.code });
124
+ } ) ;
125
+
102
126
// run
103
127
/* failing on nested dax commands
104
128
Exception encountered at "In [3]":
@@ -122,3 +146,22 @@ Deno.test("version", async (t) => {
122
146
assertSnapshot ( t , { stdout : cmd . stdout . split ( ":" ) [ 0 ] , stderr : cmd . stderr , exitCode : cmd . code } ) ;
123
147
} ) ;
124
148
149
+ async function * walkFiles ( dir : string ) : AsyncGenerator < string > {
150
+ for await ( const entry of Deno . readDir ( dir ) ) {
151
+ const path = `${ dir } /${ entry . name } ` ;
152
+ if ( entry . isDirectory ) {
153
+ yield * walkFiles ( path ) ;
154
+ } else {
155
+ yield path ;
156
+ }
157
+ }
158
+ }
159
+
160
+ async function getAllFiles ( dir : string ) : Promise < string [ ] > {
161
+ const files = [ ] ;
162
+ for await ( const file of walkFiles ( dir ) ) {
163
+ files . push ( file ) ;
164
+ }
165
+ return files ;
166
+ }
167
+
0 commit comments