@@ -5,6 +5,7 @@ import { describe, expect, it } from "@effect/vitest"
55import { Effect } from "effect"
66import * as fc from "fast-check"
77
8+ import { resolveControllerRuntimeOverlayPath } from "../../src/docker-git/controller-compose-runtime.js"
89import {
910 controllerBuildSkillerEnvKey ,
1011 controllerGpuModeEnvKey ,
@@ -107,6 +108,7 @@ type PreparedRevision = {
107108}
108109
109110type ControllerBuildSkillerFixtureMode = "0" | "1" | undefined
111+ type ControllerDockerRuntimeEnvFixtureMode = "host" | "isolated" | undefined
110112
111113type PrepareRevisionFixture = {
112114 readonly buildSkillerMode : ControllerBuildSkillerFixtureMode
@@ -118,6 +120,11 @@ const controllerBuildSkillerFixtureModeArbitrary = fc.constantFrom<ControllerBui
118120 "0" ,
119121 "1"
120122)
123+ const controllerDockerRuntimeEnvFixtureModeArbitrary = fc . constantFrom < ControllerDockerRuntimeEnvFixtureMode > (
124+ undefined ,
125+ "host" ,
126+ "isolated"
127+ )
121128const prepareRevisionFixtureArbitrary : fc . Arbitrary < PrepareRevisionFixture > = fc
122129 . record ( {
123130 buildSkillerMode : controllerBuildSkillerFixtureModeArbitrary ,
@@ -126,18 +133,27 @@ const prepareRevisionFixtureArbitrary: fc.Arbitrary<PrepareRevisionFixture> = fc
126133 . filter ( ( { buildSkillerMode, includeSkillerPackage } ) => buildSkillerMode === "0" || includeSkillerPackage )
127134const controllerRevisionPattern = / ^ [ a - f 0 - 9 ] { 16 } - h o s t - n o n e - s k i l l e r [ 0 1 ] $ / u
128135
136+ const withMinimalControllerRoot = < A , E , R > (
137+ effect : ( rootDir : string ) => Effect . Effect < A , E , R >
138+ ) =>
139+ Effect . scoped (
140+ Effect . gen ( function * ( _ ) {
141+ const rootDir = yield * _ ( temporaryControllerRoot )
142+ yield * _ ( writeMinimalCompose ( rootDir ) )
143+ yield * _ ( withWorkingDirectory ( rootDir ) )
144+ return yield * _ ( effect ( rootDir ) )
145+ } )
146+ )
147+
129148const prepareRevisionInTemporaryRoot = ( {
130149 buildSkillerMode,
131150 includeSkillerPackage
132151} : PrepareRevisionFixture ) =>
133- Effect . scoped (
152+ withMinimalControllerRoot ( ( rootDir ) =>
134153 Effect . gen ( function * ( _ ) {
135- const rootDir = yield * _ ( temporaryControllerRoot )
136- yield * _ ( writeMinimalCompose ( rootDir ) )
137154 if ( includeSkillerPackage ) {
138155 yield * _ ( writeSkillerPackage ( rootDir ) )
139156 }
140- yield * _ ( withWorkingDirectory ( rootDir ) )
141157 yield * _ (
142158 withControllerEnv ( [
143159 [ controllerBuildSkillerEnvKey , buildSkillerMode ] ,
@@ -165,6 +181,23 @@ const expectPreparedRevisionInvariants = (fixture: PrepareRevisionFixture, prepa
165181 expect ( prepared . revision . endsWith ( expectedSkillerSuffixForMode ( fixture . buildSkillerMode ) ) ) . toBe ( true )
166182}
167183
184+ const resolveComposeFilesInTemporaryRoot = (
185+ dockerRuntimeMode : ControllerDockerRuntimeEnvFixtureMode
186+ ) =>
187+ withMinimalControllerRoot ( ( rootDir ) =>
188+ Effect . gen ( function * ( _ ) {
189+ yield * _ ( writeMinimalIsolatedCompose ( rootDir ) )
190+ yield * _ (
191+ withControllerEnv ( [
192+ [ controllerBuildSkillerEnvKey , "0" ] ,
193+ [ controllerDockerRuntimeEnvKey , dockerRuntimeMode ] ,
194+ [ controllerGpuModeEnvKey , undefined ]
195+ ] )
196+ )
197+ return yield * _ ( resolveControllerComposeFiles ( ) )
198+ } )
199+ ) . pipe ( Effect . provide ( NodeContext . layer ) )
200+
168201const assertControllerComposeProperty = < PropertyArgs > ( property : fc . IAsyncProperty < PropertyArgs > ) =>
169202 Effect . tryPromise ( {
170203 catch : ( cause ) => cause ,
@@ -217,32 +250,38 @@ describe("controller compose preparation", () => {
217250 } )
218251 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
219252
220- /* jscpd:ignore-start */
221253 it . effect ( "adds the isolated runtime overlay only for isolated controller mode" , ( ) =>
254+ assertControllerComposeProperty (
255+ fc . asyncProperty ( controllerDockerRuntimeEnvFixtureModeArbitrary , ( dockerRuntimeMode ) =>
256+ Effect . runPromise (
257+ resolveComposeFilesInTemporaryRoot ( dockerRuntimeMode ) . pipe (
258+ Effect . tap ( ( files ) =>
259+ Effect . sync ( ( ) => {
260+ if ( dockerRuntimeMode === "isolated" ) {
261+ expect ( files . runtimeOverlayPath ) . toBeDefined ( )
262+ expect ( files . runtimeOverlayPath ?. endsWith ( "docker-compose.isolated.yml" ) ) . toBe ( true )
263+ return
264+ }
265+ expect ( files . runtimeOverlayPath ) . toBeNull ( )
266+ } )
267+ ) ,
268+ Effect . asVoid
269+ )
270+ ) )
271+ ) )
272+
273+ it . effect ( "rejects unsupported compose filename extensions for isolated controller mode" , ( ) =>
222274 Effect . scoped (
223275 Effect . gen ( function * ( _ ) {
276+ const path = yield * _ ( Path . Path )
224277 const rootDir = yield * _ ( temporaryControllerRoot )
225- yield * _ ( writeMinimalCompose ( rootDir ) )
226- yield * _ ( writeMinimalIsolatedCompose ( rootDir ) )
227- yield * _ ( withWorkingDirectory ( rootDir ) )
228-
229- yield * _ (
230- withControllerEnv ( [
231- [ controllerBuildSkillerEnvKey , "0" ] ,
232- [ controllerDockerRuntimeEnvKey , "host" ] ,
233- [ controllerGpuModeEnvKey , undefined ]
234- ] )
278+ const error = yield * _ (
279+ resolveControllerRuntimeOverlayPath ( path . join ( rootDir , "docker-compose.json" ) , "isolated" ) . pipe ( Effect . flip )
235280 )
236- const hostFiles = yield * _ ( resolveControllerComposeFiles ( ) )
237- expect ( hostFiles . runtimeOverlayPath ) . toBeNull ( )
238-
239- yield * _ ( withControllerEnv ( [ [ controllerDockerRuntimeEnvKey , "isolated" ] ] ) )
240- const isolatedFiles = yield * _ ( resolveControllerComposeFiles ( ) )
241- expect ( isolatedFiles . runtimeOverlayPath ) . toBeDefined ( )
242- expect ( isolatedFiles . runtimeOverlayPath ?. endsWith ( "docker-compose.isolated.yml" ) ) . toBe ( true )
281+ expect ( error . _tag ) . toBe ( "ControllerBootstrapError" )
282+ expect ( error . message ) . toContain ( ".yml or .yaml" )
243283 } )
244284 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
245- /* jscpd:ignore-end */
246285
247286 it . effect ( "prepares and persists host controller revisions for Skiller build modes" , ( ) =>
248287 assertControllerComposeProperty (
0 commit comments