@@ -3,6 +3,7 @@ import { assert, expect, it } from "@effect/vitest";
33import { HostProcessEnvironment } from "@t3tools/shared/hostProcess" ;
44import * as NetService from "@t3tools/shared/Net" ;
55import * as ConfigProvider from "effect/ConfigProvider" ;
6+ import * as Console from "effect/Console" ;
67import * as Effect from "effect/Effect" ;
78import * as FileSystem from "effect/FileSystem" ;
89import * as Layer from "effect/Layer" ;
@@ -13,6 +14,7 @@ import { afterEach, vi } from "vite-plus/test";
1314import packageJson from "../../package.json" with { type : "json" } ;
1415import * as BootService from "../cloud/bootService.ts" ;
1516import {
17+ formatServiceChange ,
1618 formatServiceStatus ,
1719 offerServiceDuringOnboarding ,
1820 reconcileService ,
@@ -42,6 +44,24 @@ it("reports the installed service version and host paths", () => {
4244 ) ;
4345} ) ;
4446
47+ it ( "does not claim a handed-off install has finished" , ( ) => {
48+ const plan = {
49+ program : [ "/home/me/.t3/runtime/versions/0.0.30/t3" , "__service-launcher" ] ,
50+ baseDir : "/home/me/.t3" ,
51+ logPath : status . logPath ,
52+ unitPath : status . unitPath ,
53+ } ;
54+ expect ( formatServiceChange ( { changed : true , previouslyInstalled : true , plan } , "0.0.30" ) ) . toBe (
55+ `Updated T3 Code service with [email protected] .\nLogs: ${ status . logPath } ` , 56+ ) ;
57+ const handedOff = formatServiceChange (
58+ { changed : true , previouslyInstalled : true , plan : { ...plan , handedOff : true } } ,
59+ "0.0.30" ,
60+ ) ;
61+ expect ( handedOff ) . not . toContain ( "Updated" ) ;
62+ expect ( handedOff ) . toContain ( `Result: ${ status . logPath } ` ) ;
63+ } ) ;
64+
4565it ( "gives a direct repair command for a stale service" , ( ) => {
4666 assert . include (
4767 formatServiceStatus ( { ...status , current : false } , "0.0.29" ) ,
@@ -97,14 +117,17 @@ it("reports a newer installed service and tells the CLI to catch up to it", () =
97117
98118const newerServiceStatus = { ...status , current : false , installedVersion : "999.0.0" } ;
99119
100- function makeTestService ( serviceStatus : BootService . BootServiceStatus ) {
120+ function makeTestService (
121+ serviceStatus : BootService . BootServiceStatus ,
122+ restartOutcome : "restarted" | "queued" = "restarted" ,
123+ ) {
101124 const installOptions : Array < Parameters < BootService . BootService [ "Service" ] [ "install" ] > [ 0 ] > = [ ] ;
102125 const restarts : Array < true > = [ ] ;
103126 const service = BootService . BootService . of ( {
104127 status : Effect . succeed ( serviceStatus ) ,
105128 restart : Effect . sync ( ( ) => {
106129 restarts . push ( true ) ;
107- return serviceStatus . installed ;
130+ return serviceStatus . installed ? restartOutcome : "skipped" ;
108131 } ) ,
109132 install : ( options ) =>
110133 Effect . sync ( ( ) => {
@@ -145,6 +168,39 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
145168 } ) ,
146169 ) ;
147170
171+ it . effect ( "restart from inside the service says the restart is only queued" , ( ) =>
172+ Effect . gen ( function * ( ) {
173+ const fs = yield * FileSystem . FileSystem ;
174+ const baseDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-service-cli-test-" } ) ;
175+ const { service } = makeTestService ( { ...status , installedVersion : "0.0.30" } , "queued" ) ;
176+ vi . spyOn ( BootService , "layer" ) . mockReturnValue (
177+ Layer . succeed ( BootService . BootService , service ) ,
178+ ) ;
179+ const lines : Array < string > = [ ] ;
180+ const testConsole = {
181+ ...globalThis . console ,
182+ log : ( ...args : ReadonlyArray < unknown > ) => {
183+ lines . push ( args . map ( String ) . join ( " " ) ) ;
184+ } ,
185+ } satisfies Console . Console ;
186+
187+ yield * Command . runWith ( serviceCommand , { version : packageJson . version } ) ( [
188+ "restart" ,
189+ "--base-dir" ,
190+ baseDir ,
191+ ] ) . pipe (
192+ Effect . provideService ( HostProcessEnvironment , { } ) ,
193+ Effect . provideService ( Console . Console , testConsole ) ,
194+ Effect . provide ( ConfigProvider . layer ( ConfigProvider . fromEnv ( { env : { } } ) ) ) ,
195+ ) ;
196+
197+ const output = lines . join ( "\n" ) ;
198+ expect ( output ) . not . toContain ( "Restarted" ) ;
199+ expect ( output ) . toContain ( "Queued a restart of the T3 Code service on [email protected] " ) ; 200+ expect ( output ) . toContain ( `Logs: ${ status . logPath } ` ) ;
201+ } ) ,
202+ ) ;
203+
148204 it . effect . each ( [ "install" , "update" ] as const ) (
149205 "%s refuses a downgrade before changing the service" ,
150206 ( command ) =>
@@ -246,7 +302,7 @@ it.effect("leaves a newer service unchanged during onboarding without prompting"
246302 Effect . provide ( NodeServices . layer ) ,
247303 ) ;
248304
249- expect ( ready ) . toBe ( false ) ;
305+ expect ( ready ) . toBe ( "skipped" ) ;
250306 expect ( installOptions ) . toEqual ( [ ] ) ;
251307 } ) ,
252308) ;
@@ -262,7 +318,7 @@ it.effect("keeps onboarding successful when a newer version appears before insta
262318 ) ,
263319 ) ;
264320
265- expect ( ready ) . toBe ( false ) ;
321+ expect ( ready ) . toBe ( "skipped" ) ;
266322 } ) ,
267323) ;
268324
@@ -271,6 +327,6 @@ it.effect("keeps the manual-server fallback when background prerequisites fail",
271327 const ready = yield * recoverServiceOnboardingOffer (
272328 Effect . fail ( new BootService . BootServicePrerequisiteError ( { problem : "linger-disabled" } ) ) ,
273329 ) ;
274- expect ( ready ) . toBe ( false ) ;
330+ expect ( ready ) . toBe ( "skipped" ) ;
275331 } ) ,
276332) ;
0 commit comments