diff --git a/.github/fork/carried-prs.json b/.github/fork/carried-prs.json new file mode 100644 index 0000000000000..a399712b2eb36 --- /dev/null +++ b/.github/fork/carried-prs.json @@ -0,0 +1,55 @@ +{ + "upstream": "pingdotgg/t3code", + "prs": [ + { + "number": 15030, + "takenSha": "a2d855c9f602d50da63fea6c07d3ca6c7db36655", + "reason": "iOS race fixes and Android keyboard parity" + }, + { + "number": 15975, + "takenSha": "b5d05a6ebf3c0b99a097f2a197983cb1203669c6", + "reason": "Home agent that manages threads across machines" + }, + { + "number": 17195, + "takenSha": "31f51f4746d0ed3d59e672bdbb5596e919a73e5d", + "reason": "Android terminal transfers and paints dirty rows only", + "closedUpstream": true + }, + { + "number": 17618, + "takenSha": "ce7e86f0aece6a52073c8be09ab3db479c14d532", + "reason": "Claude next-prompt composer ghost text", + "closedUpstream": true + }, + { + "number": 17890, + "takenSha": "0a5d3e0083e43946b180dc4cc89568af111c645c", + "reason": "Android subscription usage widgets", + "closedUpstream": true + }, + { + "number": 18634, + "takenSha": "6485555d5d7c365849dd6def5a335c8171238ccf", + "reason": "Android tablets launched in landscape open full screen" + }, + { + "number": 18839, + "takenSha": "457acb425c5fa5d5248bc0ed646b5ccb68f8f256", + "reason": "Android PR viewer keeps the chat back stack" + }, + { + "number": 19273, + "takenSha": "c983c522ad9c2e3ffd5735cdbfca6c073f9cde95", + "reason": "Local-model composer dictation" + }, + { + "number": 19424, + "takenSha": "9e5e520f786566b3004a004efc9e21817ad49e9c", + "reason": "Android foldables use the sidebar header", + "note": "Took only the first two commits. Upstream superseded it with merged #21071, #20812 and #20813.", + "closedUpstream": true + } + ] +} diff --git a/.github/workflows/fork-carried-prs.yml b/.github/workflows/fork-carried-prs.yml new file mode 100644 index 0000000000000..510fd83ee3b5e --- /dev/null +++ b/.github/workflows/fork-carried-prs.yml @@ -0,0 +1,29 @@ +name: Fork carried PRs + +on: + schedule: + - cron: "17 6 * * 1" + workflow_dispatch: + +permissions: + contents: read + +jobs: + check: + name: Carried upstream PRs drift + if: github.repository == 'issuelt/t3code' + runs-on: ubuntu-24.04 + timeout-minutes: 15 + steps: + - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 + - uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1 + with: + node-version-file: package.json + cache: true + run-install: true + - name: Check carried PRs + env: + GH_TOKEN: ${{ github.token }} + # Explicit bash adds pipefail, so drift still fails the step through tee. + shell: bash + run: node scripts/fork-carried-prs.ts | tee -a "$GITHUB_STEP_SUMMARY" diff --git a/apps/desktop/src/app/DesktopStartupRecovery.ts b/apps/desktop/src/app/DesktopStartupRecovery.ts index 2418ac52f4697..6b61d4998db4c 100644 --- a/apps/desktop/src/app/DesktopStartupRecovery.ts +++ b/apps/desktop/src/app/DesktopStartupRecovery.ts @@ -1,4 +1,5 @@ import type { DesktopUpdateState } from "@t3tools/contracts"; +import { FORK_RELEASES_URL as RELEASES_URL } from "@t3tools/shared/fork"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Option from "effect/Option"; @@ -18,7 +19,6 @@ import * as DesktopEnvironment from "./DesktopEnvironment.ts"; import * as DesktopObservability from "./DesktopObservability.ts"; import * as DesktopState from "./DesktopState.ts"; -const RELEASES_URL = "https://github.com/issuelt/t3code/releases"; const LAST_STARTED_VERSION_FILE = "desktop-last-started-version"; // Buttons are plain links to this host; will-navigate cancels them and runs the action. const ACTION_ORIGIN = "https://startup-recovery.invalid"; diff --git a/apps/mobile/src/features/settings/environment-maintenance.test.ts b/apps/mobile/src/features/settings/environment-maintenance.test.ts index 86b104a45e638..e80c1276e9602 100644 --- a/apps/mobile/src/features/settings/environment-maintenance.test.ts +++ b/apps/mobile/src/features/settings/environment-maintenance.test.ts @@ -1,4 +1,5 @@ import { AuthOrchestrationOperateScope } from "@t3tools/contracts"; +import { FORK_RELEASES_URL, FORK_REPOSITORY } from "@t3tools/shared/fork"; import { afterEach, describe, expect, it, vi } from "vite-plus/test"; import { canMaintainEnvironment, findEnvironmentUpdate } from "./environment-maintenance"; @@ -58,7 +59,7 @@ describe("environment release checks", () => { const signal = new AbortController().signal; const feed = (...tags: ReadonlyArray) => new Response( - `tag:github.com,2008:https://github.com/pingdotgg/t3code/releases${tags + `tag:github.com,2008:${FORK_RELEASES_URL}${tags .map((tag) => `tag:github.com,2008:Repository/1/${tag}`) .join("")}`, ); @@ -67,7 +68,7 @@ describe("environment release checks", () => { vi.stubGlobal( "fetch", vi.fn(async (url: string) => - url === "https://github.com/pingdotgg/t3code/releases.atom" + url === `${FORK_RELEASES_URL}.atom` ? feed( "desktop-preview", "v1.0.0-preview.20260924.3", @@ -93,11 +94,12 @@ describe("environment release checks", () => { vi.stubGlobal( "fetch", vi.fn(async (url: string) => { - if (url === "https://github.com/pingdotgg/t3code/releases.atom") return feed(...nightlies); - if (url === "https://api.github.com/repos/pingdotgg/t3code/releases?per_page=100&page=1") { + const releasesApi = `https://api.github.com/repos/${FORK_REPOSITORY}/releases?per_page=100`; + if (url === `${FORK_RELEASES_URL}.atom`) return feed(...nightlies); + if (url === `${releasesApi}&page=1`) { return Response.json(Array.from({ length: 100 }, () => ({ tag_name: "v2.0.0" }))); } - if (url === "https://api.github.com/repos/pingdotgg/t3code/releases?per_page=100&page=2") { + if (url === `${releasesApi}&page=2`) { return Response.json([ { tag_name: "v1.0.0-preview.20260925.1", draft: true }, { tag_name: "v1.0.0-preview.20260924.3" }, diff --git a/apps/server/src/cli/update.test.ts b/apps/server/src/cli/update.test.ts index 848c2c798df41..00b3cbcf067ad 100644 --- a/apps/server/src/cli/update.test.ts +++ b/apps/server/src/cli/update.test.ts @@ -1,6 +1,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, it } from "@effect/vitest"; import type { ManagedUpdatesPolicy } from "@t3tools/contracts"; +import { FORK_REPOSITORY } from "@t3tools/shared/fork"; import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; @@ -43,7 +44,7 @@ it.effect("authenticates each release page until the requested channel is found" const httpClient = HttpClient.make((request) => { const url = new URL(request.url); assert.equal(url.origin, "https://api.github.com"); - assert.equal(url.pathname, "/repos/pingdotgg/t3code/releases"); + assert.equal(url.pathname, `/repos/${FORK_REPOSITORY}/releases`); assert.equal(request.headers.accept, "application/vnd.github+json"); assert.equal(request.headers.authorization, "Bearer gh-token"); const page = url.searchParams.get("page") ?? ""; diff --git a/apps/web/src/components/desktopUpdate.logic.test.ts b/apps/web/src/components/desktopUpdate.logic.test.ts index c7d7c607ea238..21fbd10b3d26b 100644 --- a/apps/web/src/components/desktopUpdate.logic.test.ts +++ b/apps/web/src/components/desktopUpdate.logic.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vite-plus/test"; import type { DesktopUpdateState } from "@t3tools/contracts"; +import { FORK_RELEASES_URL } from "@t3tools/shared/fork"; import { canCheckForUpdate, @@ -66,13 +67,11 @@ describe("desktop update button state", () => { describe("desktop update UI helpers", () => { it.each(["owner/repo/extra", "owner#notes/repo", "owner/repo?tab=notes"])( - "falls back to upstream for an invalid configured repository: %s", + "falls back to the fork for an invalid configured repository: %s", (repository) => { - expect(getDesktopUpdateReleaseHistoryUrl(repository)).toBe( - "https://github.com/pingdotgg/t3code/releases", - ); + expect(getDesktopUpdateReleaseHistoryUrl(repository)).toBe(FORK_RELEASES_URL); expect(getDesktopUpdateReleaseUrl("1.2.3", repository)).toBe( - "https://github.com/pingdotgg/t3code/releases/tag/v1.2.3", + `${FORK_RELEASES_URL}/tag/v1.2.3`, ); }, ); diff --git a/apps/web/src/components/desktopUpdate.logic.ts b/apps/web/src/components/desktopUpdate.logic.ts index 51b2b92b0a8ba..37b2466c68081 100644 --- a/apps/web/src/components/desktopUpdate.logic.ts +++ b/apps/web/src/components/desktopUpdate.logic.ts @@ -1,8 +1,8 @@ import type { DesktopUpdateActionResult, DesktopUpdateState } from "@t3tools/contracts"; +import { FORK_REPOSITORY as DEFAULT_DESKTOP_RELEASE_REPOSITORY } from "@t3tools/shared/fork"; export type DesktopUpdateButtonAction = "download" | "install" | "none"; -const DEFAULT_DESKTOP_RELEASE_REPOSITORY = "pingdotgg/t3code"; const GITHUB_REPOSITORY_SEGMENT = /^[A-Za-z0-9._-]+$/u; function isValidRepositorySegment(value: string | undefined): value is string { diff --git a/packages/shared/package.json b/packages/shared/package.json index a28d239458f3a..a22dd6d80f525 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -427,6 +427,10 @@ "types": "./src/cliRelease.ts", "import": "./src/cliRelease.ts" }, + "./fork": { + "types": "./src/fork.ts", + "import": "./src/fork.ts" + }, "./gitPatchPath": { "types": "./src/gitPatchPath.ts", "import": "./src/gitPatchPath.ts" diff --git a/packages/shared/src/cliRelease.ts b/packages/shared/src/cliRelease.ts index 66777cc044478..d473cbccdd316 100644 --- a/packages/shared/src/cliRelease.ts +++ b/packages/shared/src/cliRelease.ts @@ -1,9 +1,10 @@ import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; +import { FORK_REPOSITORY } from "./fork.ts"; import { compareSemverVersions } from "./semver.ts"; -const CLI_RELEASE_REPOSITORY = "pingdotgg/t3code"; +const CLI_RELEASE_REPOSITORY = FORK_REPOSITORY; export const CLI_RELEASES_PAGE_URL = `https://github.com/${CLI_RELEASE_REPOSITORY}/releases`; export const CLI_RELEASE_CHECKSUMS_FILE = "SHA256SUMS"; export const CLI_RELEASE_BASE_URL_ENV = "T3CODE_RELEASE_BASE_URL"; diff --git a/packages/shared/src/fork.test.ts b/packages/shared/src/fork.test.ts new file mode 100644 index 0000000000000..69614ec16057a --- /dev/null +++ b/packages/shared/src/fork.test.ts @@ -0,0 +1,41 @@ +// @effect-diagnostics-next-line nodeBuiltinImport:off -- reads repo files synchronously to cross-check literals. +import * as NodeFS from "node:fs"; + +import { describe, expect, it } from "vite-plus/test"; + +import { + CLI_RELEASES_PAGE_URL, + cliReleaseDownloadBaseUrl, + cliReleaseIndexPageUrl, +} from "./cliRelease.ts"; +import { FORK_RELEASES_URL, FORK_REPOSITORY } from "./fork.ts"; + +const repoFile = (path: string) => + NodeFS.readFileSync(new URL(`../../../${path}`, import.meta.url), "utf8"); + +// Upstream syncs have reverted the release source to pingdotgg/t3code before. +describe("fork release source", () => { + it("serves CLI updates and downloads from the fork", () => { + expect(CLI_RELEASES_PAGE_URL).toBe(FORK_RELEASES_URL); + expect(cliReleaseDownloadBaseUrl("1.2.3")).toBe(`${FORK_RELEASES_URL}/download/v1.2.3`); + expect(cliReleaseIndexPageUrl(1)).toBe( + `https://api.github.com/repos/${FORK_REPOSITORY}/releases?per_page=100&page=1`, + ); + }); + + it.each([ + ["scripts/install.sh", /^repo="([^"]+)"$/m], + ["scripts/install.ps1", /^\$repo = "([^"]+)"$/m], + ])("installs from the fork in %s", (path, repoLiteral) => { + expect(repoLiteral.exec(repoFile(path))?.[1]).toBe(FORK_REPOSITORY); + }); + + it.each([ + "apps/desktop/src/app/DesktopStartupRecovery.ts", + "apps/web/src/components/desktopUpdate.logic.ts", + ])("takes desktop release links from the fork module in %s", (path) => { + const source = repoFile(path); + expect(source).toContain('from "@t3tools/shared/fork"'); + expect(source).not.toContain("pingdotgg/t3code"); + }); +}); diff --git a/packages/shared/src/fork.ts b/packages/shared/src/fork.ts new file mode 100644 index 0000000000000..be5322d9ce71c --- /dev/null +++ b/packages/shared/src/fork.ts @@ -0,0 +1,4 @@ +// The fork's release source: CLI and desktop updates, installers, and release links point here. +// scripts/install.sh and scripts/install.ps1 repeat the slug as a literal; fork.test.ts keeps them in sync. +export const FORK_REPOSITORY = "issuelt/t3code"; +export const FORK_RELEASES_URL = `https://github.com/${FORK_REPOSITORY}/releases`; diff --git a/scripts/fork-carried-prs.test.ts b/scripts/fork-carried-prs.test.ts new file mode 100644 index 0000000000000..fa5894a7ae0d2 --- /dev/null +++ b/scripts/fork-carried-prs.test.ts @@ -0,0 +1,52 @@ +import { assert, describe, it } from "@effect/vitest"; + +import { classifyCarriedPr } from "./fork-carried-prs.ts"; + +const taken = "a".repeat(40); +const later = "b".repeat(40); +const other = "c".repeat(40); + +function pullRequest( + state: "OPEN" | "CLOSED" | "MERGED", + headRefOid: string, + oids: ReadonlyArray, + totalCount = oids.length, +) { + return { + state, + headRefOid, + commits: { totalCount, nodes: oids.map((oid) => ({ commit: { oid } })) }, + } as const; +} + +describe("classifyCarriedPr", () => { + it("separates every upstream state", () => { + const cases = [ + [pullRequest("OPEN", taken, [other, taken]), { kind: "unchanged" }], + [pullRequest("OPEN", later, [taken, other, later]), { kind: "new-commits", newCommits: 2 }], + [ + pullRequest("OPEN", later, [other, later]), + { kind: "new-commits", newCommits: "rewritten" }, + ], + [ + pullRequest("OPEN", later, [other, later], 150), + { kind: "new-commits", newCommits: "unknown" }, + ], + [pullRequest("MERGED", taken, [taken]), { kind: "merged" }], + [pullRequest("CLOSED", taken, [taken]), { kind: "closed-unmerged" }], + ] as const; + for (const [pr, expected] of cases) { + assert.deepStrictEqual(classifyCarriedPr({ takenSha: taken }, pr), expected); + } + }); + + it("stays quiet on an accepted closed PR until its head moves", () => { + const entry = { takenSha: taken, closedUpstream: true } as const; + assert.deepStrictEqual(classifyCarriedPr(entry, pullRequest("CLOSED", taken, [taken])), { + kind: "unchanged", + }); + assert.deepStrictEqual(classifyCarriedPr(entry, pullRequest("CLOSED", later, [taken, later])), { + kind: "closed-unmerged", + }); + }); +}); diff --git a/scripts/fork-carried-prs.ts b/scripts/fork-carried-prs.ts new file mode 100644 index 0000000000000..ed855b99ac0d3 --- /dev/null +++ b/scripts/fork-carried-prs.ts @@ -0,0 +1,156 @@ +#!/usr/bin/env node + +import * as NodeRuntime from "@effect/platform-node/NodeRuntime"; +import * as NodeServices from "@effect/platform-node/NodeServices"; +import * as Console from "effect/Console"; +import * as Effect from "effect/Effect"; +import * as FileSystem from "effect/FileSystem"; +import * as Path from "effect/Path"; +import * as Schema from "effect/Schema"; +import { ChildProcess, ChildProcessSpawner } from "effect/process"; + +// Reports how each upstream PR the fork carries (.github/fork/carried-prs.json) has moved +// since we took it. Exits non-zero when any PR is no longer open at the head we took. + +const CarriedPr = Schema.Struct({ + number: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)), + takenSha: Schema.String.check(Schema.isPattern(/^[0-9a-f]{40}$/)), + reason: Schema.NonEmptyString, + note: Schema.optional(Schema.String), + // Upstream closed it unmerged and the fork now owns it; only a moved head is drift. + closedUpstream: Schema.optional(Schema.Literal(true)), +}); +type CarriedPr = typeof CarriedPr.Type; + +const CarriedPrsManifest = Schema.Struct({ + upstream: Schema.String.check(Schema.isPattern(/^[\w.-]+\/[\w.-]+$/)), + prs: Schema.Array(CarriedPr), +}); + +const UpstreamPullRequest = Schema.Struct({ + state: Schema.Literals(["OPEN", "CLOSED", "MERGED"]), + headRefOid: Schema.String, + commits: Schema.Struct({ + totalCount: Schema.Int, + nodes: Schema.Array(Schema.Struct({ commit: Schema.Struct({ oid: Schema.String }) })), + }), +}); +type UpstreamPullRequest = typeof UpstreamPullRequest.Type; + +const PullRequestQueryResponse = Schema.Struct({ + data: Schema.Struct({ + repository: Schema.Record(Schema.String, UpstreamPullRequest), + }), +}); + +const decodeManifest = Schema.decodeEffect(Schema.fromJsonString(CarriedPrsManifest)); +const decodeQueryResponse = Schema.decodeEffect(Schema.fromJsonString(PullRequestQueryResponse)); + +export type CarriedPrStatus = + | { readonly kind: "unchanged" } + // "rewritten": the taken commit left the PR's history (force-push or rebase). + // "unknown": the PR has more commits than the query returned. + | { readonly kind: "new-commits"; readonly newCommits: number | "rewritten" | "unknown" } + | { readonly kind: "merged" } + | { readonly kind: "closed-unmerged" }; + +export function classifyCarriedPr( + { takenSha, closedUpstream }: Pick, + pr: UpstreamPullRequest, +): CarriedPrStatus { + if (pr.state === "MERGED") return { kind: "merged" }; + if (pr.state === "CLOSED" && !(closedUpstream && pr.headRefOid === takenSha)) { + return { kind: "closed-unmerged" }; + } + if (pr.headRefOid === takenSha) return { kind: "unchanged" }; + const oids = pr.commits.nodes.map((node) => node.commit.oid); + const taken = oids.lastIndexOf(takenSha); + if (taken !== -1) return { kind: "new-commits", newCommits: oids.length - 1 - taken }; + return { + kind: "new-commits", + newCommits: oids.length === pr.commits.totalCount ? "rewritten" : "unknown", + }; +} + +function formatStatus(status: CarriedPrStatus): string { + if (status.kind !== "new-commits") return status.kind; + const { newCommits } = status; + return typeof newCommits === "number" + ? `new-commits (+${newCommits})` + : `new-commits (${newCommits})`; +} + +function renderTable( + upstream: string, + rows: ReadonlyArray<{ entry: CarriedPr; pr: UpstreamPullRequest; status: CarriedPrStatus }>, +): string { + const lines = rows.map( + ({ entry, pr, status }) => + `| [#${entry.number}](https://github.com/${upstream}/pull/${entry.number}) | ${formatStatus(status)} | ${entry.takenSha.slice(0, 10)} | ${pr.headRefOid.slice(0, 10)} | ${entry.reason} |`, + ); + return [ + "| PR | Status | Taken | Head | Reason |", + "| --- | --- | --- | --- | --- |", + ...lines, + ].join("\n"); +} + +export class CarriedPrsDriftedError extends Schema.TaggedError()( + "CarriedPrsDriftedError", + { drifted: Schema.Int, total: Schema.Int }, +) { + override get message(): string { + return `${this.drifted} of ${this.total} carried upstream PRs changed upstream.`; + } +} + +const readUpstreamPullRequests = Effect.fn("forkCarriedPrs.readUpstreamPullRequests")(function* ( + upstream: string, + numbers: ReadonlyArray, +) { + const [owner = "", name = ""] = upstream.split("/"); + const fields = numbers + .map( + (number) => + `pr${number}: pullRequest(number: ${number}) { state headRefOid commits(last: 100) { totalCount nodes { commit { oid } } } }`, + ) + .join("\n"); + const query = `query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { ${fields} } }`; + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; + const output = yield* spawner.string( + ChildProcess.make( + "gh", + ["api", "graphql", "-f", `query=${query}`, "-f", `owner=${owner}`, "-f", `name=${name}`], + { stderr: "inherit" }, + ), + ); + return (yield* decodeQueryResponse(output)).data.repository; +}); + +const main = Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const root = yield* path.fromFileUrl(new URL("..", import.meta.url)); + const manifest = yield* decodeManifest( + yield* fs.readFileString(path.join(root, ".github/fork/carried-prs.json")), + ); + const pullRequests = yield* readUpstreamPullRequests( + manifest.upstream, + manifest.prs.map((entry) => entry.number), + ); + const rows = manifest.prs.flatMap((entry) => { + const pr = pullRequests[`pr${entry.number}`]; + return pr ? [{ entry, pr, status: classifyCarriedPr(entry, pr) }] : []; + }); + yield* Console.log(renderTable(manifest.upstream, rows)); + // A PR missing from the response counts as drifted. + const total = manifest.prs.length; + const drifted = total - rows.filter((row) => row.status.kind === "unchanged").length; + if (drifted > 0) { + return yield* new CarriedPrsDriftedError({ drifted, total }); + } +}); + +if (import.meta.main) { + main.pipe(Effect.provide(NodeServices.layer), NodeRuntime.runMain); +}