@@ -268,6 +268,87 @@ func TestAgent(t *testing.T) {
268268 "For more information and troubleshooting, see" ,
269269 },
270270 },
271+ {
272+ // Verify that in non-blocking mode (Wait=false), startup script
273+ // logs are suppressed. This prevents dumping a wall of logs on
274+ // users who explicitly pass --wait=no. See issue #13580.
275+ name : "No logs in non-blocking mode" ,
276+ opts : cliui.AgentOptions {
277+ FetchInterval : time .Millisecond ,
278+ Wait : false ,
279+ },
280+ iter : []func (context.Context , * testing.T , * codersdk.WorkspaceAgent , <- chan string , chan []codersdk.WorkspaceAgentLog ) error {
281+ func (_ context.Context , _ * testing.T , agent * codersdk.WorkspaceAgent , _ <- chan string , logs chan []codersdk.WorkspaceAgentLog ) error {
282+ agent .Status = codersdk .WorkspaceAgentConnected
283+ agent .FirstConnectedAt = ptr .Ref (time .Now ())
284+ agent .StartedAt = ptr .Ref (time .Now ())
285+ agent .LifecycleState = codersdk .WorkspaceAgentLifecycleStartError
286+ agent .ReadyAt = ptr .Ref (time .Now ())
287+ // These logs should NOT be shown in non-blocking mode.
288+ logs <- []codersdk.WorkspaceAgentLog {
289+ {
290+ CreatedAt : time .Now (),
291+ Output : "Startup script log 1" ,
292+ },
293+ {
294+ CreatedAt : time .Now (),
295+ Output : "Startup script log 2" ,
296+ },
297+ }
298+ return nil
299+ },
300+ },
301+ // Note: Log content like "Startup script log 1" should NOT appear here.
302+ want : []string {
303+ "⧗ Running workspace agent startup scripts (non-blocking)" ,
304+ "✘ Running workspace agent startup scripts (non-blocking)" ,
305+ "Warning: A startup script exited with an error and your workspace may be incomplete." ,
306+ "For more information and troubleshooting, see" ,
307+ },
308+ },
309+ {
310+ // Verify that even after waiting for the agent to connect, logs
311+ // are still suppressed in non-blocking mode. See issue #13580.
312+ name : "No logs after connection wait in non-blocking mode" ,
313+ opts : cliui.AgentOptions {
314+ FetchInterval : time .Millisecond ,
315+ Wait : false ,
316+ },
317+ iter : []func (context.Context , * testing.T , * codersdk.WorkspaceAgent , <- chan string , chan []codersdk.WorkspaceAgentLog ) error {
318+ func (_ context.Context , _ * testing.T , agent * codersdk.WorkspaceAgent , _ <- chan string , _ chan []codersdk.WorkspaceAgentLog ) error {
319+ agent .Status = codersdk .WorkspaceAgentConnecting
320+ return nil
321+ },
322+ func (_ context.Context , t * testing.T , agent * codersdk.WorkspaceAgent , output <- chan string , _ chan []codersdk.WorkspaceAgentLog ) error {
323+ return waitLines (t , output , "⧗ Waiting for the workspace agent to connect" )
324+ },
325+ func (_ context.Context , _ * testing.T , agent * codersdk.WorkspaceAgent , _ <- chan string , logs chan []codersdk.WorkspaceAgentLog ) error {
326+ agent .Status = codersdk .WorkspaceAgentConnected
327+ agent .FirstConnectedAt = ptr .Ref (time .Now ())
328+ agent .StartedAt = ptr .Ref (time .Now ())
329+ agent .LifecycleState = codersdk .WorkspaceAgentLifecycleStartError
330+ agent .ReadyAt = ptr .Ref (time .Now ())
331+ // These logs should NOT be shown in non-blocking mode,
332+ // even though we waited for connection.
333+ logs <- []codersdk.WorkspaceAgentLog {
334+ {
335+ CreatedAt : time .Now (),
336+ Output : "Startup script log 1" ,
337+ },
338+ }
339+ return nil
340+ },
341+ },
342+ // Note: Log content should NOT appear here despite waiting for connection.
343+ want : []string {
344+ "⧗ Waiting for the workspace agent to connect" ,
345+ "✔ Waiting for the workspace agent to connect" ,
346+ "⧗ Running workspace agent startup scripts (non-blocking)" ,
347+ "✘ Running workspace agent startup scripts (non-blocking)" ,
348+ "Warning: A startup script exited with an error and your workspace may be incomplete." ,
349+ "For more information and troubleshooting, see" ,
350+ },
351+ },
271352 {
272353 name : "Error when shutting down" ,
273354 opts : cliui.AgentOptions {
0 commit comments