Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

A live folder signed out of GitHub says so, and its empty message fits its row

Victor41fec6db9988
diff --git a/Sources/Cra/Services/GitHubLiveClient.swift b/Sources/Cra/Services/GitHubLiveClient.swift
index 7d4f00e..4e6ee93 100644
--- a/Sources/Cra/Services/GitHubLiveClient.swift
+++ b/Sources/Cra/Services/GitHubLiveClient.swift
@@ -60,7 +60,8 @@ enum GitHubLiveClient {
/// Turns one response into pull requests, or says why it can't.
static func read(status: Int, finalURL: String, body: String) -> Result<Page, Failure> {
if status == 0 { return .failure(.network) }
- if let path = URL(string: finalURL)?.path, path == "/login" || path.hasPrefix("/session") {
+ let finalPath = URL(string: finalURL)?.path
+ if let path = finalPath, path == "/login" || path.hasPrefix("/session") || isSSOPath(path) {
return .failure(.notSignedIn)
}
if status == 429 || (status == 403 && body.localizedCaseInsensitiveContains("rate limit")) { return .failure(.rateLimited) }
@@ -69,6 +70,9 @@ enum GitHubLiveClient {
if status == 401 || (body.count < 2000 && body.localizedCaseInsensitiveContains("authenticate you")) { return .failure(.notSignedIn) }
if body.contains("\"logged_in\":false") { return .failure(.notSignedIn) }
guard (200..<300).contains(status) else { return .failure(.unexpectedPage) }
+ // Sent somewhere other than the pulls or search page: no pull requests there is no answer,
+ // and reading it as one would empty the folder.
+ let elsewhere = finalPath.map { !$0.isEmpty && !$0.hasPrefix("/pulls") && !$0.hasPrefix("/search") } ?? false
var page = Page()
page.ssoOrganizations = ssoOrganizations(in: body)
@@ -77,6 +81,7 @@ enum GitHubLiveClient {
guard let json = try? JSONSerialization.jsonObject(with: Data(trimmed.utf8)) else { return .failure(.unexpectedPage) }
page.viewer = viewer(inJSON: json)
page.pullRequests = pullRequests(inJSON: json)
+ if page.pullRequests.isEmpty && elsewhere { return .failure(.unexpectedPage) }
return .success(page)
}
// An HTML page: logged out pages carry an empty user-login.
@@ -92,7 +97,7 @@ enum GitHubLiveClient {
}
if found.isEmpty { found = pullRequests(inHTML: body) }
page.pullRequests = unique(found)
- if page.pullRequests.isEmpty && !sawPayload && !body.contains("blankslate") { return .failure(.unexpectedPage) }
+ if page.pullRequests.isEmpty && (elsewhere || (!sawPayload && !body.contains("blankslate"))) { return .failure(.unexpectedPage) }
return .success(page)
}
@@ -215,6 +220,21 @@ enum GitHubLiveClient {
// MARK: Helpers
+ /// GitHub's single sign-on pages. A lapsed Enterprise Managed User session (Victor's JYSK
+ /// account, 6 Nov 2026) is sent to /enterprises/<slug>/sso, a signed-in page with the user's
+ /// login and React data, which read as "no pull requests" until this check.
+ static func isSSOPath(_ path: String) -> Bool {
+ let parts = path.split(separator: "/")
+ return parts.count == 3 && (parts[0] == "enterprises" || parts[0] == "orgs") && parts[2] == "sso"
+ }
+
+ /// The enterprise a link to its single sign-on names (github.com/enterprises/<slug>/sso).
+ static func enterprise(inSSO url: String) -> String? {
+ guard let u = URL(string: url), u.host == "github.com", isSSOPath(u.path) else { return nil }
+ let parts = u.path.split(separator: "/")
+ return parts[0] == "enterprises" ? String(parts[1]) : nil
+ }
+
static func pullPath(_ link: String) -> (owner: String, repo: String, number: Int)? {
guard let m = matches(#"(?:^|github\.com)/([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)/pull/(\d+)"#, in: link).first, m.count > 3,
let n = Int(m[3]) else { return nil }
diff --git a/Sources/Cra/Services/LiveFolderManager.swift b/Sources/Cra/Services/LiveFolderManager.swift
index d796178..f6347bb 100644
--- a/Sources/Cra/Services/LiveFolderManager.swift
+++ b/Sources/Cra/Services/LiveFolderManager.swift
@@ -110,12 +110,7 @@ final class LiveFolderManager {
guard old != url, let store, !store.liveFolders.isEmpty else { return }
let folders = store.liveFolders
guard let page = URL(string: url), page.host == "github.com" else { return }
- // GitHub sends a signed-out Enterprise Managed User to /enterprises/<slug>/sso (JYSK, 29 Oct 2026).
- let parts = page.path.split(separator: "/")
- if parts.count == 3, parts[0] == "enterprises", parts[2] == "sso" {
- let slug = String(parts[1])
- for f in folders where f.liveFolder?.enterprise != slug { store.updateLiveFolder(f.id) { $0.enterprise = slug } }
- }
+ learnEnterprise(from: url)
if folders.contains(where: { $0.liveFolder.map(Self.needsSignIn) ?? false }) { checkSignIn() }
guard let pr = GitHubLiveClient.pullPath(url) else { return }
let oldPath = old.flatMap { URL(string: $0)?.path } ?? ""
@@ -129,6 +124,13 @@ final class LiveFolderManager {
}
}
+ /// GitHub sends a signed-out Enterprise Managed User to /enterprises/<slug>/sso (JYSK, 29 Oct
+ /// 2026), a tab and the folder's own requests alike: the folder's sign-in goes there too.
+ private func learnEnterprise(from url: String) {
+ guard let slug = GitHubLiveClient.enterprise(inSSO: url), let store else { return }
+ for f in store.liveFolders where f.liveFolder?.enterprise != slug { store.updateLiveFolder(f.id) { $0.enterprise = slug } }
+ }
+
/// Signing in ends on a GitHub page, and so does an SSO session that renews by itself (an
/// identity provider that signs in without asking, like JYSK's ADFS): the folder tries again a
/// moment after GitHub pages stop loading, instead of waiting for the next retry.
@@ -158,8 +160,9 @@ final class LiveFolderManager {
private func get(_ url: String, profile: String?, label: String) async -> Result<GitHubLiveClient.Page, GitHubLiveClient.Failure> {
await withCheckedContinuation { continuation in
- CraCEFRuntime.fetchURL(url, headers: GitHubLiveClient.jsonHeaders, profilePath: profile) { status, finalURL, mime, body in
+ CraCEFRuntime.fetchURL(url, headers: GitHubLiveClient.jsonHeaders, profilePath: profile) { [weak self] status, finalURL, mime, body in
if Self.debug { Self.dump(label: label, url: url, status: status, finalURL: finalURL, mime: mime, body: body) }
+ MainActor.assumeIsolated { self?.learnEnterprise(from: finalURL) }
continuation.resume(returning: GitHubLiveClient.read(status: status, finalURL: finalURL, body: body))
}
}
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift b/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
index e1ee06f..ebcd177 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
@@ -2137,7 +2137,10 @@ final class LiveStatusRowView: SidebarRowView {
let l = NSTextField(wrappingLabelWithString: "")
l.font = .systemFont(ofSize: 12)
l.maximumNumberOfLines = 3
- l.lineBreakMode = .byTruncatingTail
+ // Truncating the tail would make the field one line high inside a row measured for
+ // the wrapped text; the last of the three lines gets the ellipsis instead.
+ l.lineBreakMode = .byWordWrapping
+ l.cell?.truncatesLastVisibleLine = true
return l
}()
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index 1f5a322..1508ba6 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -25,6 +25,7 @@ enum StoreTests {
tabSleepCadence()
integrity()
liveFolderExpiry()
+ liveFolderSignIn()
stampsUseTheClock()
persistenceFaults()
incognitoStaysOffDisk()
@@ -274,6 +275,25 @@ enum StoreTests {
expect(store.integrityProblems().contains { $0.contains("lives elsewhere") }, "a window selecting another space's tab is reported")
}
+ /// GitHub's answers that mean "sign in" never read as an empty folder (6 Nov 2026: a lapsed
+ /// Enterprise Managed User session landed on the enterprise's SSO page and emptied the folder).
+ private static func liveFolderSignIn() {
+ let ssoPage = #"<html><meta name="user-login" content="vkp_jysk"><script type="application/json" id="client-env">{"locale":"en"}</script></html>"#
+ expect(GitHubLiveClient.read(status: 200, finalURL: "https://github.com/enterprises/jysk-emu/sso?return_to=%2Fpulls", body: ssoPage) == .failure(.notSignedIn),
+ "a fetch sent to the enterprise's single sign-on needs a sign-in")
+ expect(GitHubLiveClient.read(status: 200, finalURL: "https://github.com/orgs/jysk-dev/sso", body: ssoPage) == .failure(.notSignedIn),
+ "so does an organization's")
+ expect(GitHubLiveClient.enterprise(inSSO: "https://github.com/enterprises/jysk-emu/sso?return_to=%2Fpulls") == "jysk-emu",
+ "the folder learns the enterprise from where its fetch landed")
+ expect(GitHubLiveClient.read(status: 200, finalURL: "https://github.com/dashboard", body: ssoPage) == .failure(.unexpectedPage),
+ "an empty page that isn't the pulls or search page is no answer")
+ let empty = #"{"payload":{"pullsDashboardSurfaceContentRoute":{"results":[],"pageInfo":{},"error":null}}}"#
+ expect(GitHubLiveClient.read(status: 200, finalURL: "https://github.com/pulls?q=is%3Apr", body: empty) == .success(.init()),
+ "the pulls page with no results is an empty folder")
+ expect(GitHubLiveClient.read(status: 404, finalURL: "https://github.com/pulls?q=is%3Apr", body: #"{"error":"Couldn’t authenticate you"}"#) == .failure(.notSignedIn),
+ "signed out, the pulls page can't authenticate you")
+ }
+
/// A pull request that left the results stays for the grace period, then goes, all on the clock.
@MainActor
private static func liveFolderExpiry() {