Просмотр исходного кода

fix(cli): fix quiet mode tests by capturing console before host creation (#10827)

Chris Estreich 3 недель назад
Родитель
Сommit
ea62173792

+ 13 - 6
apps/cli/src/agent/__tests__/extension-host.test.ts

@@ -100,16 +100,17 @@ describe("ExtensionHost", () => {
 				ephemeral: false,
 				debug: false,
 				exitOnComplete: false,
+				integrationTest: true, // Set explicitly for testing
 			}
 
 			const host = new ExtensionHost(options)
 
-			// Options are stored but integrationTest is set to true
+			// Options are stored as-is
 			const storedOptions = getPrivate<ExtensionHostOptions>(host, "options")
 			expect(storedOptions.mode).toBe(options.mode)
 			expect(storedOptions.workspacePath).toBe(options.workspacePath)
 			expect(storedOptions.extensionPath).toBe(options.extensionPath)
-			expect(storedOptions.integrationTest).toBe(true) // Always set to true in constructor
+			expect(storedOptions.integrationTest).toBe(true)
 		})
 
 		it("should be an EventEmitter instance", () => {
@@ -298,16 +299,19 @@ describe("ExtensionHost", () => {
 			})
 
 			it("should suppress console when integrationTest is false", () => {
-				const host = createTestHost()
+				// Capture the real console.log before any host is created
 				const originalLog = console.log
 
-				// Override integrationTest to false
+				// Create host with integrationTest: true to prevent constructor from suppressing
+				const host = createTestHost({ integrationTest: true })
+
+				// Override integrationTest to false to test suppression
 				const options = getPrivate<ExtensionHostOptions>(host, "options")
 				options.integrationTest = false
 
 				callPrivate(host, "setupQuietMode")
 
-				// Console should be modified
+				// Console should be modified (suppressed)
 				expect(console.log).not.toBe(originalLog)
 
 				// Restore for other tests
@@ -332,9 +336,12 @@ describe("ExtensionHost", () => {
 
 		describe("restoreConsole", () => {
 			it("should restore original console methods when suppressed", () => {
-				const host = createTestHost()
+				// Capture the real console.log before any host is created
 				const originalLog = console.log
 
+				// Create host with integrationTest: true to prevent constructor from suppressing
+				const host = createTestHost({ integrationTest: true })
+
 				// Override integrationTest to false to actually suppress
 				const options = getPrivate<ExtensionHostOptions>(host, "options")
 				options.integrationTest = false

+ 1 - 4
apps/cli/src/agent/extension-host.ts

@@ -152,10 +152,7 @@ export class ExtensionHost extends EventEmitter implements ExtensionHostInterfac
 	constructor(options: ExtensionHostOptions) {
 		super()
 
-		this.options = {
-			...options,
-			integrationTest: true, // Always set to true in CLI mode to allow tests to control console suppression
-		}
+		this.options = options
 
 		// Set up quiet mode early, before any extension code runs.
 		// This suppresses console output from the extension during load.