88 type TerminalRestartInput ,
99 ProviderDriverKind ,
1010 ProviderInstanceId ,
11+ ProjectId ,
1112 TerminalProviderInstanceNotFoundError ,
1213} from "@t3tools/contracts" ;
1314import * as HostProcess from "@t3tools/shared/HostProcess" ;
@@ -32,6 +33,8 @@ import * as ServerConfig from "../config.ts";
3233import * as SqlitePersistence from "../persistence/Sqlite.ts" ;
3334import * as ProcessRunner from "../processRunner.ts" ;
3435import * as ServerSettings from "../serverSettings.ts" ;
36+ import * as ProjectService from "../project/ProjectService.ts" ;
37+ import * as ProjectSetupScriptRunner from "../project/ProjectSetupScriptRunner.ts" ;
3538import * as TerminalManager from "./Manager.ts" ;
3639import { terminalOutputStream } from "./OutputProtocol.ts" ;
3740import * as PtyAdapter from "@t3tools/shared/PtyAdapter" ;
@@ -925,6 +928,64 @@ it.layer(
925928 } ) ,
926929 ) ;
927930
931+ it . effect . each ( [ "setup" , "settle" ] as const ) (
932+ "observes %s completion in the fallback shell instead of the configured fish shell" ,
933+ ( trigger ) =>
934+ Effect . gen ( function * ( ) {
935+ const env = { SHELL : "/missing/fish" } ;
936+ const { manager, ptyAdapter, baseDir } = yield * createManager ( 5 , { env } ) . pipe (
937+ Effect . provide ( layerWithHostPlatform ( "linux" ) ) ,
938+ ) ;
939+ ptyAdapter . spawnFailures . push ( new Error ( "spawn fish ENOENT" ) ) ;
940+ const runner = yield * ProjectSetupScriptRunner . make . pipe (
941+ Effect . provide (
942+ Layer . mergeAll (
943+ Layer . succeed ( TerminalManager . TerminalManager , manager ) ,
944+ Layer . mock ( ProjectService . ProjectService ) ( { } ) ,
945+ ServerSettings . layerTest ( ) ,
946+ Layer . succeed ( HostProcess . Platform , "linux" ) ,
947+ Layer . succeed ( HostProcess . Environment , env ) ,
948+ ) ,
949+ ) ,
950+ ) ;
951+ const result = yield * runner . runForThread ( {
952+ threadId : "thread-setup-fallback" ,
953+ worktreePath : baseDir ,
954+ trigger,
955+ project : {
956+ id : ProjectId . make ( "project-setup-fallback" ) ,
957+ workspaceRoot : baseDir ,
958+ scripts : [
959+ {
960+ id : "setup" ,
961+ name : "Setup" ,
962+ command : "echo setup-ready" ,
963+ icon : "play" ,
964+ runOnWorktreeCreate : true ,
965+ runOnSettle : true ,
966+ } ,
967+ ] ,
968+ } ,
969+ observeCompletion : { } ,
970+ } ) ;
971+ expect ( ptyAdapter . spawnInputs . map ( ( input ) => input . shell ) ) . toEqual ( [
972+ "/missing/fish" ,
973+ "/bin/zsh" ,
974+ ] ) ;
975+ const process = ptyAdapter . processes [ 0 ] ! ;
976+ const command = process . writes [ 0 ] ! ;
977+ expect ( command ) . toContain ( '"$?"' ) ;
978+ expect ( command ) . not . toContain ( "$status" ) ;
979+ const sentinel = / _ _ T 3 _ S E T U P _ D O N E _ _ [ a - z A - Z 0 - 9 _ ] + : / . exec ( command ) ?. [ 0 ] ;
980+ assert . isDefined ( sentinel ) ;
981+ assert . equal ( result . status , "started" ) ;
982+ if ( result . status !== "started" ) return ;
983+ assert . isDefined ( result . completion ) ;
984+ process . emitData ( `setup-ready\r\n${ sentinel } 0\r\nprompt> ` ) ;
985+ expect ( ( yield * result . completion ! ) . exitCode ) . toBe ( 0 ) ;
986+ } ) ,
987+ ) ;
988+
928989 it . effect ( "preserves Windows Path casing when appending managed ACP binaries" , ( ) =>
929990 Effect . gen ( function * ( ) {
930991 const fileSystem = yield * FileSystem . FileSystem ;
@@ -1015,6 +1076,55 @@ it.layer(
10151076 ] ) ;
10161077 expect ( ptyAdapter . spawnInputs [ 1 ] ?. args ) . toEqual ( [ "-NoLogo" ] ) ;
10171078 expect ( ptyAdapter . spawnInputs [ 2 ] ?. args ) . toEqual ( [ "-NoLogo" ] ) ;
1079+ expect ( yield * manager . getShell ( openInput ( ) ) ) . toBe (
1080+ "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" ,
1081+ ) ;
1082+ } ) ,
1083+ ) ;
1084+
1085+ it . effect ( "rejects cmd fallback before writing an unsupported completion wrapper" , ( ) =>
1086+ Effect . gen ( function * ( ) {
1087+ const { manager, ptyAdapter, baseDir } = yield * createManager ( 5 , {
1088+ env : { SystemRoot : "C:\\Windows" } ,
1089+ } ) . pipe ( Effect . provide ( layerWithHostPlatform ( "win32" ) ) ) ;
1090+ ptyAdapter . spawnFailures . push (
1091+ new Error ( "spawn pwsh ENOENT" ) ,
1092+ new Error ( "spawn WindowsPowerShell ENOENT" ) ,
1093+ new Error ( "spawn powershell ENOENT" ) ,
1094+ ) ;
1095+ const runner = yield * ProjectSetupScriptRunner . make . pipe (
1096+ Effect . provide (
1097+ Layer . mergeAll (
1098+ Layer . succeed ( TerminalManager . TerminalManager , manager ) ,
1099+ Layer . mock ( ProjectService . ProjectService ) ( { } ) ,
1100+ ServerSettings . layerTest ( ) ,
1101+ ) ,
1102+ ) ,
1103+ ) ;
1104+ const error = yield * runner
1105+ . runForThread ( {
1106+ threadId : "thread-cmd-fallback" ,
1107+ worktreePath : baseDir ,
1108+ project : {
1109+ id : ProjectId . make ( "project-cmd-fallback" ) ,
1110+ workspaceRoot : baseDir ,
1111+ scripts : [
1112+ {
1113+ id : "setup" ,
1114+ name : "Setup" ,
1115+ command : "echo setup-ready" ,
1116+ icon : "play" ,
1117+ runOnWorktreeCreate : true ,
1118+ } ,
1119+ ] ,
1120+ } ,
1121+ observeCompletion : { } ,
1122+ } )
1123+ . pipe ( Effect . flip ) ;
1124+
1125+ expect ( error . _tag ) . toBe ( "ProjectSetupScriptUnsupportedShellError" ) ;
1126+ expect ( ptyAdapter . spawnInputs . at ( - 1 ) ?. shell ) . toBe ( "C:\\Windows\\System32\\cmd.exe" ) ;
1127+ expect ( ptyAdapter . processes [ 0 ] ?. writes ) . toEqual ( [ ] ) ;
10181128 } ) ,
10191129 ) ;
10201130
0 commit comments