@@ -15,6 +15,7 @@ func TestShouldStartConsoleRequiresTTYForLogin(t *testing.T) {
1515
1616 cmd := & cobra.Command {Use : consts .CommandLogin }
1717 cmd .Flags ().Bool ("console" , false , "" )
18+ cmd .Flags ().Bool ("daemon" , false , "" )
1819
1920 if shouldStartConsole (cmd ) {
2021 t .Fatal ("login should not start an interactive console in non-interactive mode" )
@@ -28,6 +29,7 @@ func TestShouldStartConsoleAllowsExplicitConsoleFlag(t *testing.T) {
2829
2930 cmd := & cobra.Command {Use : "version" }
3031 cmd .Flags ().Bool ("console" , false , "" )
32+ cmd .Flags ().Bool ("daemon" , false , "" )
3133 if err := cmd .Flags ().Set ("console" , "true" ); err != nil {
3234 t .Fatalf ("failed to set console flag: %v" , err )
3335 }
@@ -44,8 +46,48 @@ func TestShouldStartConsoleDoesNotStartRootInNonInteractiveMode(t *testing.T) {
4446
4547 cmd := & cobra.Command {Use : consts .ClientMenu }
4648 cmd .Flags ().Bool ("console" , false , "" )
49+ cmd .Flags ().Bool ("daemon" , false , "" )
4750
4851 if shouldStartConsole (cmd ) {
4952 t .Fatal ("root command should not start the console in non-interactive mode" )
5053 }
5154}
55+
56+ func TestShouldStartDaemonAllowsHeadlessRuntime (t * testing.T ) {
57+ old := common .StdinIsTerminal
58+ common .StdinIsTerminal = func () bool { return false }
59+ t .Cleanup (func () { common .StdinIsTerminal = old })
60+
61+ cmd := & cobra.Command {Use : consts .CommandLogin }
62+ cmd .Flags ().Bool ("console" , false , "" )
63+ cmd .Flags ().Bool ("daemon" , false , "" )
64+ if err := cmd .Flags ().Set ("daemon" , "true" ); err != nil {
65+ t .Fatalf ("failed to set daemon flag: %v" , err )
66+ }
67+
68+ if ! common .ShouldStartDaemon (cmd ) {
69+ t .Fatal ("--daemon should enable headless runtime mode" )
70+ }
71+ if ! common .ShouldStartRuntime (cmd ) {
72+ t .Fatal ("--daemon should keep runtime alive even without REPL" )
73+ }
74+ if common .ShouldSuppressStartupOutput (cmd ) {
75+ t .Fatal ("--daemon should preserve startup output for diagnostics" )
76+ }
77+ }
78+
79+ func TestValidateExecutionModeFlagsRejectsConsoleAndDaemon (t * testing.T ) {
80+ cmd := & cobra.Command {Use : consts .CommandLogin }
81+ cmd .Flags ().Bool ("console" , false , "" )
82+ cmd .Flags ().Bool ("daemon" , false , "" )
83+ if err := cmd .Flags ().Set ("console" , "true" ); err != nil {
84+ t .Fatalf ("failed to set console flag: %v" , err )
85+ }
86+ if err := cmd .Flags ().Set ("daemon" , "true" ); err != nil {
87+ t .Fatalf ("failed to set daemon flag: %v" , err )
88+ }
89+
90+ if err := common .ValidateExecutionModeFlags (cmd ); err == nil {
91+ t .Fatal ("expected --console and --daemon to conflict" )
92+ }
93+ }
0 commit comments