fix(macos): show full browser tab ids
This commit is contained in:
@@ -74,4 +74,11 @@ let package = Package(
|
||||
.enableUpcomingFeature("StrictConcurrency"),
|
||||
.enableExperimentalFeature("SwiftTesting"),
|
||||
]),
|
||||
.testTarget(
|
||||
name: "ClawdisCLITests",
|
||||
dependencies: ["ClawdisCLI"],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("StrictConcurrency"),
|
||||
.enableExperimentalFeature("SwiftTesting"),
|
||||
]),
|
||||
])
|
||||
|
||||
@@ -270,19 +270,37 @@ enum BrowserCLI {
|
||||
}
|
||||
}
|
||||
|
||||
private static func printTabs(res: [String: Any]) {
|
||||
let running = (res["running"] as? Bool) ?? false
|
||||
print("Running: \(running)")
|
||||
guard let tabs = res["tabs"] as? [[String: Any]], !tabs.isEmpty else { return }
|
||||
private static func formatTabs(res: [String: Any]) -> [String] {
|
||||
guard let tabs = res["tabs"] as? [[String: Any]], !tabs.isEmpty else { return [] }
|
||||
var lines: [String] = []
|
||||
lines.reserveCapacity(tabs.count * 2)
|
||||
for tab in tabs {
|
||||
let id = (tab["targetId"] as? String) ?? ""
|
||||
let title = (tab["title"] as? String) ?? ""
|
||||
let url = (tab["url"] as? String) ?? ""
|
||||
let shortId = id.isEmpty ? "" : String(id.prefix(8))
|
||||
print("- \(shortId) \(title) \(url)")
|
||||
lines.append("- \(shortId) \(title) \(url)")
|
||||
if !id.isEmpty {
|
||||
lines.append(" id: \(id)")
|
||||
}
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
private static func printTabs(res: [String: Any]) {
|
||||
let running = (res["running"] as? Bool) ?? false
|
||||
print("Running: \(running)")
|
||||
for line in self.formatTabs(res: res) {
|
||||
print(line)
|
||||
}
|
||||
}
|
||||
|
||||
#if SWIFT_PACKAGE
|
||||
static func _testFormatTabs(res: [String: Any]) -> [String] {
|
||||
self.formatTabs(res: res)
|
||||
}
|
||||
#endif
|
||||
|
||||
private static func printJSON(ok: Bool, result: Any) {
|
||||
let obj: [String: Any] = ["ok": ok, "result": result]
|
||||
if let data = try? JSONSerialization.data(withJSONObject: obj, options: [.prettyPrinted]),
|
||||
|
||||
20
apps/macos/Tests/ClawdisCLITests/BrowserCLITests.swift
Normal file
20
apps/macos/Tests/ClawdisCLITests/BrowserCLITests.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
import Testing
|
||||
@testable import ClawdisCLI
|
||||
|
||||
@Suite struct BrowserCLITests {
|
||||
@Test func tabsOutputIncludesFullTargetId() async throws {
|
||||
let res: [String: Any] = [
|
||||
"running": true,
|
||||
"tabs": [
|
||||
[
|
||||
"targetId": "57A01309E14B5DEE0FB41F908515A2FC",
|
||||
"title": "Example",
|
||||
"url": "https://example.com/",
|
||||
],
|
||||
],
|
||||
]
|
||||
|
||||
let lines = BrowserCLI._testFormatTabs(res: res)
|
||||
#expect(lines.contains(" id: 57A01309E14B5DEE0FB41F908515A2FC"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user