From ff99d8c5c3c5b4b6e43641379aa66af90260db7a Mon Sep 17 00:00:00 2001 From: chaodu-agent <274062505+chaodu-agent@users.noreply.github.com> Date: Tue, 24 Nov 2026 07:18:32 -0500 Subject: [PATCH 1/3] fix: installed Chrome fallback, call-time logging and candidate order (#169) Follow-up items from the #165 review that are still valid on main: - M2: a Chrome check that fails during browser use is now logged as `browser: chrome_check_failed class=` (class only, no path). Before, only the consent step logged it. - M3: InstalledChromeChecker.check() walks /Applications then ~/Applications and returns the first copy that passes. If none passes, it returns the problem of the first existing copy, as before. - L1: the FakeInstallFixture default chrome checker reads no directories, so no test reads the real /Applications. - L3: the Remove copy says the installed Chrome choice is removed only when install.json is removed, matching R7.7. Tests (failing before, passing after): - testChromeProblemDuringBrowserUseIsLoggedWithItsClass - testAValidCopyInHomeApplicationsIsUsedWhenTheSystemCopyFails - testFixtureDefaultCheckerNeverReadsRealApplications (failed before on a Mac with a Chrome-named bundle in /Applications, passes after) - testRemoveCopySaysTheChoiceGoesOnlyWhenInstallJSONIsRemoved Verification on the final tree: - Swift: swift build passed. swift test: 856 executed, 5 skipped (environment-gated), 0 failures. - Rust: the repo has no root Cargo.toml. The crate under poc/ was tested with cargo test: 604 passed, 0 failed, 17 ignored. Not changed: M1 (check cost) and L2 (version shown when the check fails) are open product decisions, tracked on the issue. --- .../Browser/BrowserWizardCopy.swift | 2 +- .../Browser/InstalledChrome.swift | 11 +++++-- .../Browser/PlaywrightBackend.swift | 1 + .../BrowserWizardWiringTests.swift | 6 ++++ .../FakeInstallFixture.swift | 2 +- .../InstalledChromeTests.swift | 31 +++++++++++++++++++ .../PlaywrightInstallerTests.swift | 7 +++++ 7 files changed, 56 insertions(+), 4 deletions(-) diff --git a/Sources/InstanceMCPCore/Browser/BrowserWizardCopy.swift b/Sources/InstanceMCPCore/Browser/BrowserWizardCopy.swift index 4f51cb7..a644f88 100644 --- a/Sources/InstanceMCPCore/Browser/BrowserWizardCopy.swift +++ b/Sources/InstanceMCPCore/Browser/BrowserWizardCopy.swift @@ -79,7 +79,7 @@ extension WizardCopy { /// `PlaywrightInstaller.remove()`: only items that carry the installer's marker, or that an `install.json` /// written by the installer owns. A foreign or unreadable `install.json`, and the profile, stay. public static func removalConfirmation(path: String, home: String = NSHomeDirectory()) -> String { - "This removes what this app installed in \(displayPath(path, home: home)). Version folders that carry this app's marker (Node.js, the Playwright MCP server and the downloaded Chromium) are removed even if install.json is unreadable, invalid or made by hand. The browser profile with its cookies and sign-ins, the output folder and install.json are removed only when a readable install.json written by this app confirms it created them. Anything else stays, and it does not touch Chrome, Safari or ~/.local/oab-computer/. Agents lose the browser tools until you install it again. If you had chosen your installed Google Chrome, that choice is removed too, and Chrome itself is left as it is." + "This removes what this app installed in \(displayPath(path, home: home)). Version folders that carry this app's marker (Node.js, the Playwright MCP server and the downloaded Chromium) are removed even if install.json is unreadable, invalid or made by hand. The browser profile with its cookies and sign-ins, the output folder and install.json are removed only when a readable install.json written by this app confirms it created them. Anything else stays, and it does not touch Chrome, Safari or ~/.local/oab-computer/. Agents lose the browser tools until you install it again. If you had chosen your installed Google Chrome, that choice is removed too when install.json is removed, and Chrome itself is left as it is." } public static let removalDone = "Playwright was removed." diff --git a/Sources/InstanceMCPCore/Browser/InstalledChrome.swift b/Sources/InstanceMCPCore/Browser/InstalledChrome.swift index 467e8b9..04e354f 100644 --- a/Sources/InstanceMCPCore/Browser/InstalledChrome.swift +++ b/Sources/InstanceMCPCore/Browser/InstalledChrome.swift @@ -121,8 +121,15 @@ public final class InstalledChromeChecker: InstalledChromeChecking, @unchecked S } public func check() -> Result { - guard let first = candidates().first(where: { Self.kind($0.path) != nil }) else { return .failure(.notFound) } - return check(appPath: first.path) + // The first existing copy in priority order that passes; otherwise the first existing copy's problem. + var firstProblem: InstalledChromeProblem? + for candidate in candidates() where Self.kind(candidate.path) != nil { + switch check(appPath: candidate.path) { + case .success(let chrome): return .success(chrome) + case .failure(let problem): firstProblem = firstProblem ?? problem + } + } + return .failure(firstProblem ?? .notFound) } private func plist(_ app: URL) -> [String: Any]? { diff --git a/Sources/InstanceMCPCore/Browser/PlaywrightBackend.swift b/Sources/InstanceMCPCore/Browser/PlaywrightBackend.swift index 3107e08..98577e4 100644 --- a/Sources/InstanceMCPCore/Browser/PlaywrightBackend.swift +++ b/Sources/InstanceMCPCore/Browser/PlaywrightBackend.swift @@ -91,6 +91,7 @@ public actor PlaywrightBackend: BrowserBackend { switch m.locator.locate() { case .failure(let e): health = nil; toolCache = nil + if InstalledChromeProblem.classes.contains(e.errorClass) { log("browser: chrome_check_failed class=\(e.errorClass)") } await shutdown() return .failure(e) case .success(let spec): diff --git a/Tests/InstanceMCPCoreTests/BrowserWizardWiringTests.swift b/Tests/InstanceMCPCoreTests/BrowserWizardWiringTests.swift index f8552b6..8ea23fa 100644 --- a/Tests/InstanceMCPCoreTests/BrowserWizardWiringTests.swift +++ b/Tests/InstanceMCPCoreTests/BrowserWizardWiringTests.swift @@ -30,6 +30,12 @@ final class BrowserWizardWiringTests: InstallerTestCase { // MARK: BrowserToolsController.remove() + func testRemoveCopySaysTheChoiceGoesOnlyWhenInstallJSONIsRemoved() { + let text = WizardCopy.removalConfirmation(path: "/tmp/oab-playwright", home: "/Users/someone") + XCTAssertTrue(text.contains("that choice is removed too when install.json is removed"), text) + XCTAssertFalse(text.contains("that choice is removed too, and"), text) + } + func testRemoveReReadsTheStateAfterRemovalAndReportsRemoved() async throws { let fx = try FakeInstallFixture() let installer = fx.installer(root: root) diff --git a/Tests/InstanceMCPCoreTests/FakeInstallFixture.swift b/Tests/InstanceMCPCoreTests/FakeInstallFixture.swift index 661b186..8e540fe 100644 --- a/Tests/InstanceMCPCoreTests/FakeInstallFixture.swift +++ b/Tests/InstanceMCPCoreTests/FakeInstallFixture.swift @@ -179,7 +179,7 @@ final class FakeInstallFixture { lockTries: Int = 50, npmTimeout: TimeInterval = 30, healthTimeout: TimeInterval = 20, now: @escaping @Sendable () -> Date = { Date() }, downloader: (any ArtifactDownloader)? = nil, lockfile: String? = nil, - chromeChecker: any InstalledChromeChecking = InstalledChromeChecker()) -> PlaywrightInstaller { + chromeChecker: any InstalledChromeChecking = InstalledChromeChecker(directories: [])) -> PlaywrightInstaller { let man = m ?? manifest! return PlaywrightInstaller( root: root, manifest: man, archProvider: FixedArch(.arm64), diff --git a/Tests/InstanceMCPCoreTests/InstalledChromeTests.swift b/Tests/InstanceMCPCoreTests/InstalledChromeTests.swift index b991dcb..81d704c 100644 --- a/Tests/InstanceMCPCoreTests/InstalledChromeTests.swift +++ b/Tests/InstanceMCPCoreTests/InstalledChromeTests.swift @@ -136,6 +136,37 @@ final class InstalledChromeCheckerTests: XCTestCase { XCTAssertEqual(v.calls.value, 5) } + func testAValidCopyInHomeApplicationsIsUsedWhenTheSystemCopyFails() throws { + struct PathVerifier: ChromeSignatureVerifying { + let valid: String + func verify(app: URL) -> Bool { app.standardizedFileURL.path == valid } + } + let system = try FakeChromeBundle() + let home = try FakeChromeBundle() + let v = PathVerifier(valid: home.app.standardizedFileURL.path) + let both = InstalledChromeChecker(directories: [system.applications, home.applications], verifier: v) + guard case .success(let chrome) = both.check() else { return XCTFail("the ~/Applications copy is valid and must be used") } + XCTAssertEqual(chrome.appPath, home.app.standardizedFileURL.path) + // With no valid copy anywhere, the class is still the one from the first existing copy. + let systemOnly = InstalledChromeChecker(directories: [system.applications, home.applications], + verifier: StubChromeVerifier(false)) + XCTAssertEqual(systemOnly.check(), .failure(.invalidSignature)) + } + + func testChromeProblemDuringBrowserUseIsLoggedWithItsClass() async throws { + let tree = try InstallTree() + let chrome = try FakeChromeBundle() + let record = "{\"version\":\"1.0\",\"chromiumExecutable\":\"chromium/chrome\"," + + "\"systemChrome\":{\"appPath\":\"\(chrome.app.path)\",\"versionAtConsent\":\"157.0.8103.79\"}}" + try record.write(to: tree.root.appendingPathComponent("install.json"), atomically: true, encoding: .utf8) + let logs = MutableBox<[String]>([]) + let backend = PlaywrightBackend(managed: ManagedPlaywrightLocator(root: tree.root, chrome: chrome.checker(StubChromeVerifier(false))), + log: { logs.value += [$0] }) + _ = try? await backend.call("browser_navigate", arguments: .object([:])) + XCTAssertTrue(logs.value.contains("browser: chrome_check_failed class=chrome_invalid_signature"), "\(logs.value)") + XCTAssertFalse(logs.value.joined().contains(chrome.app.path), "no path in a log line") + } + func testTheRequirementNamesGoogleLLCAndTheRealVerifierRefusesAnUnsignedBundle() throws { let r = InstalledChromePolicy.requirement XCTAssertTrue(r.contains("anchor apple generic")) diff --git a/Tests/InstanceMCPCoreTests/PlaywrightInstallerTests.swift b/Tests/InstanceMCPCoreTests/PlaywrightInstallerTests.swift index fd9ca50..461110d 100644 --- a/Tests/InstanceMCPCoreTests/PlaywrightInstallerTests.swift +++ b/Tests/InstanceMCPCoreTests/PlaywrightInstallerTests.swift @@ -78,6 +78,13 @@ final class PlaywrightInstallerTests: InstallerTestCase { } } + func testFixtureDefaultCheckerNeverReadsRealApplications() throws { + let fx = try FakeInstallFixture() + let installer = fx.installer(root: root) + XCTAssertFalse(installer.chromeChecker.isInstalled()) + XCTAssertEqual(installer.chromeChecker.check(), .failure(.notFound)) + } + func testFullInstall() async throws { let fx = try FakeInstallFixture() let logs = MutableBox<[String]>([]) From 6c26ea450333369c0ff2dca9f2356e27d408fca1 Mon Sep 17 00:00:00 2001 From: chaodu-agent Date: Tue, 24 Nov 2026 07:56:45 -0500 Subject: [PATCH 2/3] fix: address review findings on the #169 follow-up - InstalledChromeChecking.check() doc comment now describes the rule: the first allowed copy that passes, else the first existing copy's problem. - testAValidCopyInHomeApplicationsIsUsedWhenTheSystemCopyFails gives the two copies different failure classes (system copy too old, ~/Applications copy bad signature) and asserts the system copy's class is reported, so the priority order is pinned. - BrowserWizardWiringTests uses /home/example as the home path. Failing before, passing after (base sources with the new tests): - testChromeProblemDuringBrowserUseIsLoggedWithItsClass: fails, no log line. - testAValidCopyInHomeApplicationsIsUsedWhenTheSystemCopyFails: fails, returns invalidSignature. - testFixtureDefaultCheckerNeverReadsRealApplications: fails on the test host only when a Chrome-named bundle is present in /Applications. A temporary stand-in bundle reproduced that, and it was removed afterward. - testRemoveCopySaysTheChoiceGoesOnlyWhenInstallJSONIsRemoved: fails, old copy text. Verification on this head: - Swift: swift build passed. swift test: 856 executed, 5 skipped (environment-gated), 0 failures. - Rust: the repo has no Cargo.toml at its root. The crate at poc/reverse-attach-linux: cargo test gave 604 passed, 0 failed, 17 ignored. --- Sources/InstanceMCPCore/Browser/InstalledChrome.swift | 3 ++- .../InstanceMCPCoreTests/BrowserWizardWiringTests.swift | 2 +- Tests/InstanceMCPCoreTests/InstalledChromeTests.swift | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Sources/InstanceMCPCore/Browser/InstalledChrome.swift b/Sources/InstanceMCPCore/Browser/InstalledChrome.swift index 04e354f..8900405 100644 --- a/Sources/InstanceMCPCore/Browser/InstalledChrome.swift +++ b/Sources/InstanceMCPCore/Browser/InstalledChrome.swift @@ -79,7 +79,8 @@ public struct SecurityFrameworkChromeVerifier: ChromeSignatureVerifying { public protocol InstalledChromeChecking: Sendable { /// Cheap: a `Google Chrome.app` exists in an allowed folder. No signature check; used to decide whether to offer. func isInstalled() -> Bool - /// The first allowed `Google Chrome.app`, fully checked. + /// The first allowed `Google Chrome.app` that passes every check, in priority order. If none passes, the + /// problem of the first existing copy. func check() -> Result /// A recorded path, fully checked. A path that is not one of the allowed locations is refused. func check(appPath: String) -> Result diff --git a/Tests/InstanceMCPCoreTests/BrowserWizardWiringTests.swift b/Tests/InstanceMCPCoreTests/BrowserWizardWiringTests.swift index 8ea23fa..f73fbf4 100644 --- a/Tests/InstanceMCPCoreTests/BrowserWizardWiringTests.swift +++ b/Tests/InstanceMCPCoreTests/BrowserWizardWiringTests.swift @@ -31,7 +31,7 @@ final class BrowserWizardWiringTests: InstallerTestCase { // MARK: BrowserToolsController.remove() func testRemoveCopySaysTheChoiceGoesOnlyWhenInstallJSONIsRemoved() { - let text = WizardCopy.removalConfirmation(path: "/tmp/oab-playwright", home: "/Users/someone") + let text = WizardCopy.removalConfirmation(path: "/tmp/oab-playwright", home: "/home/example") XCTAssertTrue(text.contains("that choice is removed too when install.json is removed"), text) XCTAssertFalse(text.contains("that choice is removed too, and"), text) } diff --git a/Tests/InstanceMCPCoreTests/InstalledChromeTests.swift b/Tests/InstanceMCPCoreTests/InstalledChromeTests.swift index 81d704c..1ea5bed 100644 --- a/Tests/InstanceMCPCoreTests/InstalledChromeTests.swift +++ b/Tests/InstanceMCPCoreTests/InstalledChromeTests.swift @@ -147,10 +147,11 @@ final class InstalledChromeCheckerTests: XCTestCase { let both = InstalledChromeChecker(directories: [system.applications, home.applications], verifier: v) guard case .success(let chrome) = both.check() else { return XCTFail("the ~/Applications copy is valid and must be used") } XCTAssertEqual(chrome.appPath, home.app.standardizedFileURL.path) - // With no valid copy anywhere, the class is still the one from the first existing copy. - let systemOnly = InstalledChromeChecker(directories: [system.applications, home.applications], - verifier: StubChromeVerifier(false)) - XCTAssertEqual(systemOnly.check(), .failure(.invalidSignature)) + // Both copies fail with different classes: the system copy is first in priority, so its class is reported. + try system.write(version: "100.0.0") + let oldFirst = InstalledChromeChecker(directories: [system.applications, home.applications], + verifier: PathVerifier(valid: system.app.standardizedFileURL.path)) + XCTAssertEqual(oldFirst.check(), .failure(.tooOld(found: 100, minimum: 120))) } func testChromeProblemDuringBrowserUseIsLoggedWithItsClass() async throws { From 0bf2864f5c48db9818e1933f1e9083e567aa2d40 Mon Sep 17 00:00:00 2001 From: chaodu-agent <274062505+chaodu-agent@users.noreply.github.com> Date: Tue, 24 Nov 2026 12:58:29 +0000 Subject: [PATCH 3/3] fix(review): wait for the probe stub to settle before asserting listeners=none The arm64 run failed a_tree_that_listens_is_reported_by_kind_and_a_silent_one_as_none with listeners=unknown. spawn returns right after exec while the loader may still open and close library fds, and a vanished fd is unknown by design. Poll gather for up to 5s; a tree that stays unknown still fails. --- poc/reverse-attach-linux/src/probe_tests.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/poc/reverse-attach-linux/src/probe_tests.rs b/poc/reverse-attach-linux/src/probe_tests.rs index ef369da..449d4b2 100644 --- a/poc/reverse-attach-linux/src/probe_tests.rs +++ b/poc/reverse-attach-linux/src/probe_tests.rs @@ -107,7 +107,18 @@ fn a_tree_that_listens_is_reported_by_kind_and_a_silent_one_as_none() { let dir = root.abs_path().join("pw-1/node/bin"); let mut c = detached(&sleeper_at(&dir, "node")); let real = crate::procnet::Proc; - let x = gather(&t.base(), false, None, &real, ¬hing); + // `spawn` returns right after `exec`, while the dynamic loader may still open and close + // library files. An fd that vanishes during the scan is `unknown` by design (see + // `socket_inodes_in`), so wait for the stub to settle instead of racing its startup. + // A tree that stays `unknown` still fails the assertion below. + let end = std::time::Instant::now() + std::time::Duration::from_secs(5); + let x = loop { + let x = gather(&t.base(), false, None, &real, ¬hing); + if x.listeners != "unknown" || std::time::Instant::now() >= end { + break x; + } + std::thread::sleep(std::time::Duration::from_millis(20)); + }; assert_eq!(x.listeners, "none", "{x:?}"); c.kill().unwrap(); c.wait().unwrap();