Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Playwright loads the built extension into a real Chromium profile. Tests replace
- The default check interval is one minute; settings offer 1, 2, 5, or 10 minutes. Chrome can delay alarms during sleep. Freshness is checked whenever the worker or popup runs.
- A failed check retains the last successful snapshot, marks it stale, and changes the toolbar to unknown. Expired data is never treated as fresh operational status. Cached service rows are labeled explicitly.
- The GitHub toolbar icon is green for operational status, yellow for degraded performance or maintenance, red for partial or major outages, and gray for unknown, stale, or failed checks. Attention/outage badges and tooltip text provide status information beyond color. The Chrome Extensions page uses a neutral GitHub icon. Icon sources and regeneration instructions are in [assets/README.md](assets/README.md).
- Manual refresh respects the next permitted check time. Failed checks use exponential backoff with jitter and honor bounded `Retry-After` values. Requests time out after ten seconds, reject redirects, omit credentials, and cap response size at 1 MiB.
- Manual refresh requests the latest status immediately, even when cached data is fresh or an automatic retry is scheduled. The configured interval applies only to background checks. The button shows progress and confirms success or failure, and the update time includes seconds. An explicit provider `Retry-After` temporarily disables refresh with a visible countdown. Failed automatic checks use exponential backoff with jitter. Requests time out after ten seconds, reject redirects, omit credentials, and cap response size at 1 MiB.
- The summary API supplies unresolved incidents, not resolved incident history. This MVP does not request extra historical feeds or invent uptime metrics.
- GitHub is the only configured source in this release. Multiple sources, GitLab, and runtime host permissions are deferred to later milestones. The normalized domain and provider interface are separate from the GitHub schema.
- Browser-based status is informational and reflects GitHub's published reports. Toolbar updates occur when Chrome wakes the service worker; they cannot update while the browser is suspended.
Expand Down
1 change: 1 addition & 0 deletions public/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ <h2 id="maintenance-heading">Scheduled maintenance</h2>
<footer>
<div>
<p id="updated">No cached status</p>
<p id="refresh-feedback" role="status" aria-live="polite"></p>
<a
href="https://www.githubstatus.com/api"
target="_blank"
Expand Down
38 changes: 28 additions & 10 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { toolbar, stale, github, type Cache } from "../domain.js";
import {
toolbar,
stale,
github,
refreshAllowedAt,
type Cache,
type RefreshResult,
} from "../domain.js";
import {
providers,
ProviderError,
Expand All @@ -7,7 +14,7 @@ import {
import { emptyCache, readCache, readSettings } from "../storage.js";
import { fetchCache } from "./polling.js";
const alarmName = "github-refresh";
let inFlight: Promise<Cache> | undefined;
let inFlight: Promise<RefreshResult> | undefined;
const authorizedProvider: StatusProvider = {
id: "github-statuspage",
async fetchStatus(source, signal, interval) {
Expand Down Expand Up @@ -44,20 +51,31 @@ async function schedule(cache: Cache) {
periodInMinutes: 1,
});
}
function refresh(): Promise<Cache> {
if (inFlight) return inFlight;
inFlight = (async () => {
function refresh(manual = false): Promise<RefreshResult> {
if (inFlight) {
return manual
? inFlight.then((result) => {
// A manual click may arrive while an automatic cache check is finishing.
// Join a real request, but start one if that check only returned the cache.
return result.outcome === "deferred" &&
Date.now() >= refreshAllowedAt(result.cache, true)
? refresh(true)
: result;
})
: inFlight;
}
inFlight = (async (): Promise<RefreshResult> => {
const [cache, settings] = await Promise.all([readCache(), readSettings()]);
await updateToolbar(cache);
if (Date.now() < cache.nextAttemptAt) {
if (Date.now() < refreshAllowedAt(cache, manual)) {
await schedule(cache);
return cache;
return { cache, outcome: "deferred" };
}
const next = await fetchCache(cache, settings, authorizedProvider);
await chrome.storage.local.set({ cache: next });
await updateToolbar(next);
await schedule(next);
return next;
return { cache: next, outcome: next.error ? "failed" : "updated" };
})().finally(() => {
inFlight = undefined;
});
Expand All @@ -82,8 +100,8 @@ chrome.runtime.onMessage.addListener((message: unknown, sender, reply) => {
)
return false;
if (message.type === "refresh") {
refresh()
.then((cache) => reply({ cache }))
refresh("manual" in message && message.manual === true)
.then((result) => reply(result))
.catch(() => reply({ error: "storage" }));
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/background/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export async function fetchCache(
lastFailure: now,
error: failure.kind,
failures,
retryAfterUntil:
failure.retryAfter > 0 ? now + failure.retryAfter : undefined,
nextAttemptAt:
now +
retryDelay(failures, settings.intervalMinutes, failure.retryAfter),
Expand Down
8 changes: 8 additions & 0 deletions src/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export interface Cache {
error?: ErrorKind;
failures: number;
nextAttemptAt: number;
retryAfterUntil?: number;
}
export interface RefreshResult {
cache: Cache;
outcome: "updated" | "failed" | "deferred";
}
export interface Settings {
theme: "system" | "light" | "dark";
Expand Down Expand Up @@ -95,6 +100,9 @@ export function worst(states: Health[]): Health {
export function stale(cache: Cache, now = Date.now()): boolean {
return !cache.snapshot || !!cache.error || cache.snapshot.expiresAt <= now;
}
export function refreshAllowedAt(cache: Cache, manual: boolean): number {
return manual ? (cache.retryAfterUntil ?? 0) : cache.nextAttemptAt;
}
export function toolbar(cache: Cache, now = Date.now()) {
const state = stale(cache, now) ? "unknown" : cache.snapshot!.overall;
const icon =
Expand Down
80 changes: 62 additions & 18 deletions src/ui/popup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import { labels, stale, type Cache, type Incident } from "../domain.js";
import {
labels,
stale,
refreshAllowedAt,
type Cache,
type Incident,
type RefreshResult,
} from "../domain.js";
import { safeLink } from "../providers/github.js";
import { readCache, readSettings } from "../storage.js";
import { emptyCache, readCache, readSettings } from "../storage.js";
import { applyTheme, element, get, time } from "./shared.js";
let current: Cache | undefined;
let refreshing = false;
const refreshButton = get<HTMLButtonElement>("refresh");
const refreshFeedback = get("refresh-feedback");
function renderRefreshControl(cache: Cache) {
const wait = Math.max(
0,
Math.ceil((refreshAllowedAt(cache, true) - Date.now()) / 1000),
);
refreshButton.disabled = refreshing || wait > 0;
refreshButton.textContent = refreshing
? "↻ Checking…"
: wait > 0
? `↻ Retry in ${wait}s`
: "↻ Refresh";
refreshButton.title =
wait > 0
? `GitHub requested a wait until ${time(refreshAllowedAt(cache, true), true)}`
: "Fetch the latest GitHub Status now";
}
function incidents(id: string, values: Incident[], empty: string) {
const parent = get(id);
parent.replaceChildren();
Expand Down Expand Up @@ -83,39 +108,55 @@ function render(cache: Cache) {
get("maintenance-section").hidden = !snapshot?.maintenance.length;
incidents("maintenance", snapshot?.maintenance ?? [], "");
get("updated").textContent = snapshot
? `Updated ${time(snapshot.fetchedAt)}${isStale ? " · stale" : ""}`
? `Updated ${time(snapshot.fetchedAt, true)}${isStale ? " · stale" : ""}`
: "No successful checks yet";
get("updated").title = snapshot
? new Date(snapshot.fetchedAt).toLocaleString()
: "";
const wait = Math.max(0, (cache.nextAttemptAt - Date.now()) / 1000);
refreshButton.title =
wait > 0
? `Next API check in about ${Math.ceil(wait)} seconds`
: "Check GitHub Status";
renderRefreshControl(cache);
}
async function refresh() {
refreshButton.disabled = true;
refreshButton.textContent = "↻ Checking…";
async function refresh(manual = false) {
if (refreshing) return;
refreshing = true;
renderRefreshControl(current ?? emptyCache());
if (manual) refreshFeedback.textContent = "Checking GitHub Status…";
try {
const result = (await chrome.runtime.sendMessage({ type: "refresh" })) as {
cache?: Cache;
const result = (await chrome.runtime.sendMessage({
type: "refresh",
manual,
})) as Partial<RefreshResult> & {
error?: string;
};
if (result.cache) render(result.cache);
else throw new Error("unavailable");
if (!result.cache) throw new Error("unavailable");
render(result.cache);
if (manual) {
if (result.outcome === "updated" && result.cache.snapshot) {
refreshFeedback.textContent = `Status refreshed at ${time(result.cache.snapshot.fetchedAt, true)}.`;
} else if (
result.outcome === "deferred" ||
(result.cache.retryAfterUntil ?? 0) > Date.now()
) {
refreshFeedback.textContent = `GitHub requested a wait. Try again at ${time(refreshAllowedAt(result.cache, true), true)}.`;
} else {
refreshFeedback.textContent =
"Refresh failed. The last successful update time is unchanged.";
}
}
} catch {
const notice = get("notice");
notice.hidden = false;
notice.textContent =
"Background check unavailable. Reload the extension and try again.";
if (manual)
refreshFeedback.textContent =
"Could not refresh status. Please try again.";
} finally {
refreshButton.disabled = false;
refreshButton.textContent = "↻ Refresh";
refreshing = false;
renderRefreshControl(current ?? emptyCache());
}
}
refreshButton.addEventListener("click", () => {
void refresh();
void refresh(true);
});
get("settings").addEventListener("click", () => {
void chrome.runtime.openOptionsPage();
Expand All @@ -132,6 +173,9 @@ setInterval(() => {
if (stale(current) && Date.now() >= current.nextAttemptAt) void refresh();
}
}, 15_000);
setInterval(() => {
if (current) renderRefreshControl(current);
}, 1000);
void (async () => {
applyTheme(await readSettings());
const cache = await readCache();
Expand Down
3 changes: 2 additions & 1 deletion src/ui/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export function get<T extends HTMLElement = HTMLElement>(id: string): T {
export function applyTheme(settings: Settings) {
document.documentElement.dataset.theme = settings.theme;
}
export function time(value: number): string {
export function time(value: number, seconds = false): string {
return new Date(value).toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
...(seconds ? ({ second: "2-digit" } as const) : {}),
});
}
36 changes: 35 additions & 1 deletion tests/domain.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { toolbar, stale, settingsFrom, defaults } from "../src/domain.js";
import {
toolbar,
stale,
settingsFrom,
defaults,
refreshAllowedAt,
} from "../src/domain.js";
import {
normalize,
componentState,
Expand Down Expand Up @@ -237,3 +243,31 @@ test("permission denial remains explicit in cache and toolbar", async () => {
assert.equal(result.error, "permission");
assert.equal(toolbar(result).state, "unknown");
});

test("manual refresh bypasses the configured interval and network backoff", () => {
const cache = { ...emptyCache(), nextAttemptAt: Date.now() + 600_000 };
assert.equal(refreshAllowedAt(cache, false), cache.nextAttemptAt);
assert.equal(refreshAllowedAt(cache, true), 0);
assert.equal(refreshAllowedAt({ ...cache, error: "network" }, true), 0);
});

test("manual refresh honors only the explicit provider Retry-After", async () => {
const before = Date.now();
const failed = await fetchCache(emptyCache(), defaults, {
id: "github-statuspage",
async fetchStatus() {
throw new ProviderError("http_error", 30_000);
},
});
assert.ok(failed.retryAfterUntil! >= before + 30_000);
assert.equal(refreshAllowedAt(failed, true), failed.retryAfterUntil);
assert.ok(failed.nextAttemptAt > failed.retryAfterUntil!);
const recovered = await fetchCache(failed, defaults, {
id: "github-statuspage",
async fetchStatus() {
return normalize(summary());
},
});
assert.equal(recovered.retryAfterUntil, undefined);
assert.equal(refreshAllowedAt(recovered, true), 0);
});
Loading
Loading