diff --git a/.agents/skills/contribution-triage/SKILL.md b/.agents/skills/contribution-triage/SKILL.md index 21ba3b7a6566a..e5325c398bc48 100644 --- a/.agents/skills/contribution-triage/SKILL.md +++ b/.agents/skills/contribution-triage/SKILL.md @@ -71,13 +71,12 @@ from evidence you could not access. Do not run untrusted PR code merely to decid Read the guide's linked sections before applying these checks. Inspect enough source to substantiate scope and behavioral claims; leave the full correctness, security, and performance audit to code review. -- Under [prior approval](../../../CONTRIBUTING.md#prior-approval), identify the actual failure and - intended behavior. Inspect maintainer responses in the linked issue or discussion, including what - direction and scope they approved. A link, label, or acknowledgment alone is not approval. Judge a - claimed obvious-bug exception by purpose, impact, and necessary changes, without numeric cutoffs. - Separately assess focused configuration of an established capability: identify what already exists, - what the option controls, and its effects and necessary scope. This route does not require a proven - obvious bug. Adding a setting alone establishes neither a new feature nor an approval exemption. +- Under [fix a bug](../../../CONTRIBUTING.md#prior-approval), identify the actual failure and + intended behavior. A feature, or anything on the guide's not-interested list, warrants closure + unless a maintainer in the trusted exemption list asked for that PR. Inspect the request and the + direction and scope it covers. A link, label, or acknowledgment alone is not a request. Judge a + claimed bug fix by purpose, impact, and necessary changes, without numeric cutoffs. A setting that + adds a workflow or changes a default is a feature. Check whether an alleged fix intentionally changes product behavior or overlooks an existing workflow. Preserve any useful documentation, onboarding, or discoverability problem when declining the solution. - Under [one problem](../../../CONTRIBUTING.md#one-problem), trace how each material change contributes @@ -90,27 +89,18 @@ scope and behavioral claims; leave the full correctness, security, and performan as the guide requires them. Do not demand unrelated evidence or repo-wide tests. An unavailable local platform does not defeat adequate contributor evidence. Do not infer fabrication or AI authorship from writing style, suspicion, or a check you cannot reproduce. +- Under [models](../../../CONTRIBUTING.md#models), use only the model and harness the PR names, + usually in its closing attribution line. -### Configuration and workflow examples - -- Hosting CLI-path configuration in [#11653](https://github.com/pingdotgg/t3code/pull/11653) is eligible - for deeper review under the maintainer's ruling: it makes an existing capability configurable. - It need not qualify as an obvious-bug repair or obtain prior feature approval on that basis. - Still assess one underlying problem, necessary scope and credible verification. Deeper review can - reject the configuration mechanism or its implementation. -- Preserving Files as an independent tab in [#14436](https://github.com/pingdotgg/t3code/pull/14436) - changes tab lifetime and navigation. The maintainer classified it as a broader workflow change - requiring prior product-direction approval, which is absent. Propose closure for missing approval - in a dry run, or carry out closure in authorized enforcement. Its good evidence does not make it - eligible or justify keeping it pending after that ruling. The remedy is to obtain scope approval. - -Use these examples to distinguish effects, not to exempt every configuration option. Apply current -trusted policy and reassess changed submission evidence; neither example grants permanent eligibility. +Bans in the guide are a maintainer decision. Report suspected spam to maintainers; do not ban or +threaten a ban. ## Apply the outcome Do not automatically close a PR if a maintainer in the trusted `TRIAGE_EXEMPTIONS.td` list has commented or submitted a review, including on earlier heads, or if `triage:keep-open` is present. +Comments that triage itself posted, such as an earlier notice or question, are not maintainer +involvement, even when they were posted from a maintainer's account on that maintainer's behalf. Leave protected PRs open for maintainer decision. This does not grant an author exemption, eligibility, or review approval. @@ -126,10 +116,20 @@ comment text but do not write to GitHub. Keep the eligibility finding separate f This is a routing exception, not a claim that the PR passed eligibility or correctness review. - **Closure warranted.** The assessment is complete and establishes a specific policy violation. Prepare a clear explanation under [closure and reconsideration](../../../CONTRIBUTING.md#closure-and-reconsideration), - post it, and close the PR. Verify that the explanation is present and the PR is closed. The comment + post it, then read the repository variable `PR_LIMITS_ENFORCE` + (`gh variable get PR_LIMITS_ENFORCE -R pingdotgg/t3code`). When it prints `true`, apply + `triage:closing` as the last thing you do to the PR, verify that the explanation and the label + are present, and do not close the PR yourself: + [pr-limits.yml](../../../.github/workflows/pr-limits.yml) closes it 72 hours after the label. Any + activity on the PR after the label, including a further comment or label from you, removes the + label; treat an author's reply or push as new evidence, reassess, and apply the label again only + if the finding still holds. When the command prints any other value, or fails saying the variable + was not found, the variable is off and nothing would close a labeled PR: close it yourself and + verify that the explanation is present and the PR is closed. Only another failure, such as a + permission error, means the variable cannot be read; then report the closure as incomplete. The comment must name the violated rule, cite supporting submission evidence, link the maintained guide section, and give a concrete remedy. Missing contributor evidence can warrant closure; explain what must be - established. Missing product approval calls for maintainer discussion, not an agent's product decision. + established. The remedy for a feature is an Ideas discussion, not an agent's product decision. Close for multiple problems only when the independence of those changes is supported. Closing a PR does not require a configured Macroscope label. - **Needs explanation or maintainer decision.** Name the unresolved question and who can resolve it. @@ -137,9 +137,9 @@ comment text but do not write to GitHub. Keep the eligibility finding separate f was posted. If tracing the source leaves an extra diff's necessity unclear, request the causal explanation needed. If established facts leave a product-direction choice to maintainers, identify that choice. Leave the PR open and pending that answer; do not mark it eligible. Do not substitute - "the agent was uncertain" for a violated rule. Once maintainers establish that a workflow change - requires approval and that approval is absent, apply the closure outcome instead of retaining a - pending classification. Good verification does not cure missing approval. + "the agent was uncertain" for a violated rule. Once a change is established as a feature with no + maintainer request, apply the closure outcome instead of retaining a pending classification. Good + verification does not make a feature eligible. - **Incomplete; retry required.** State the failed retrieval, missing access, truncated diff, or unfinished assessment and what is needed to resume. Do not convert operational failures into policy violations or hand the PR off as having passed. An inaccessible artifact is different from an omitted artifact. @@ -173,9 +173,10 @@ description, evidence, approvals, existing triage comments, PR open/closed state label when relevant. Reassess changes that could invalidate the finding. Reuse an existing explanation only if it still matches the current finding; avoid duplicate comments, closures, or label applications. -For closure, establish that the required explanation is posted before closing. If posting fails or its -result is ambiguous, read back the comments before retrying or proceeding. If the comment succeeds but -closure fails, preserve the comment and retry only the unfinished closure after checking current state. +For closure, establish that the required explanation is posted before applying `triage:closing` or +closing. If posting fails or its result is ambiguous, read back the comments before retrying or +proceeding. If the comment succeeds but the label or the closure fails, preserve the comment and retry +only that unfinished step after checking current state. Handle a failed or ambiguous label application the same way: inspect labels before any retry. If access or state still cannot be verified, report an incomplete action and the step needed to resume. Do not retry blindly or claim success for an unverified action. diff --git a/.github/VOUCHED.td b/.github/VOUCHED.td index 1c4ae817060a9..69c1ea6575a4a 100644 --- a/.github/VOUCHED.td +++ b/.github/VOUCHED.td @@ -83,6 +83,7 @@ github:tris203 github:tsouth89 github:UtkarshUsername github:vitalyiegorov +-github:wSedlacek Opened over 130 unapproved PRs in 12 days, far past the open PR limit github:Yash-Singh1 github:yashranaway github:Ymit24 diff --git a/.github/fork-ci-tests.txt b/.github/fork-ci-tests.txt new file mode 100644 index 0000000000000..005a330dbb333 --- /dev/null +++ b/.github/fork-ci-tests.txt @@ -0,0 +1,10 @@ +# Fork script tests the workflow job runs (.github/scripts/fork-ci-tests.cjs). +# Every fork-*.test.{sh,py,cjs} must be listed here. A listed file that is not +# present yet is a note; one that was present and then deleted fails. +.github/scripts/fork-ci-tests.test.cjs +.github/scripts/fork-follow.test.sh +.github/scripts/fork-release-workflow.test.py +.github/scripts/fork-release.test.sh +.github/scripts/fork-schema-check.test.cjs +.github/scripts/fork-test-shards.test.cjs +.github/scripts/fork-tests-drift.test.cjs diff --git a/.github/fork-tests-upstream.json b/.github/fork-tests-upstream.json new file mode 100644 index 0000000000000..b2d826809a501 --- /dev/null +++ b/.github/fork-tests-upstream.json @@ -0,0 +1,456 @@ +{ + ".github/workflows/ci.yml": { + "changes": { + "header": "8ff211d87838fee8", + "steps": [ + { + "name": "Checkout", + "digest": "6e4f4d400d7166d3" + }, + { + "name": "Detect affected jobs", + "digest": "34a172066c8bd43c" + } + ] + }, + "lint": { + "header": "fb1d2080e81f407b", + "steps": [ + { + "name": "Checkout", + "digest": "b209d3ae4e2481dd" + }, + { + "name": "Reject repository-owned PR assets", + "digest": "a3b3fe56a20d10bc" + }, + { + "name": "Setup Vite+", + "digest": "26d8e10bd2d55595" + }, + { + "name": "Cache Electron download", + "digest": "353e0a76c1955ee0" + }, + { + "name": "Ensure Electron runtime is installed", + "digest": "b49682a395d1db97" + }, + { + "name": "Check unused code", + "digest": "1968f76ced131f47" + }, + { + "name": "Check generated GitHub GraphQL operations", + "digest": "7b0bc86822fffb65" + }, + { + "name": "Check generated Expo GraphQL operations", + "digest": "dfb39b82dec44c75" + }, + { + "name": "Check", + "digest": "b9e0beb00c16198e" + } + ] + }, + "build": { + "header": "7f62c17d569bc89a", + "steps": [ + { + "name": "Checkout", + "digest": "b209d3ae4e2481dd" + }, + { + "name": "./.github/actions/setup-apt-mirrors", + "digest": "0aeff75c5e98e418" + }, + { + "name": "Start installing browser secret helper build libraries", + "digest": "290064f86f52f6b7" + }, + { + "name": "Setup Vite+", + "digest": "26d8e10bd2d55595" + }, + { + "name": "Cache Electron download", + "digest": "353e0a76c1955ee0" + }, + { + "name": "Ensure Electron runtime is installed", + "digest": "154f683f77774ac2" + }, + { + "name": "Start typecheck", + "digest": "7e2b27816c22c788" + }, + { + "name": "Finish installing browser secret helper build libraries", + "digest": "f4047c9d5eb47c6f" + }, + { + "name": "Build desktop pipeline", + "digest": "aee0689d0bf38dc0" + }, + { + "name": "Verify preload bundle output", + "digest": "d70f3343194f687c" + }, + { + "name": "Open the seeded thread in the built desktop app", + "digest": "ef43acf89154cc0d" + }, + { + "name": "Upload desktop launch check", + "digest": "898b201dd5ae5f71" + }, + { + "name": "Resolve Playwright version", + "digest": "21bc211f7756f8f9" + }, + { + "name": "Cache Chromium", + "digest": "404b1c6c70f7eab0" + }, + { + "name": "Install Chromium for the built web client boot check", + "digest": "6bbf4f1dd3173918" + }, + { + "name": "Install missing Chromium system dependencies", + "digest": "1f3b26a2eb8d4245" + }, + { + "name": "Boot the built web client", + "digest": "2d647c22798cb29c" + }, + { + "name": "Typecheck", + "digest": "97be7ff701d1b8dd" + } + ] + }, + "test": { + "header": "0cae18bdc1ae5bb3", + "steps": [ + { + "name": "Checkout", + "digest": "b209d3ae4e2481dd" + }, + { + "name": "./.github/actions/setup-apt-mirrors", + "digest": "14f039b4273b5477" + }, + { + "name": "Start installing browser secret helper build libraries", + "digest": "3b68a19e5e1cf008" + }, + { + "name": "Setup Vite+", + "digest": "26d8e10bd2d55595" + }, + { + "name": "Cache Electron download", + "digest": "353e0a76c1955ee0" + }, + { + "name": "Ensure Electron runtime is installed", + "digest": "b49682a395d1db97" + }, + { + "name": "Test preview artifact validation", + "digest": "8ae0b86bebe56975" + }, + { + "name": "Test release checks", + "digest": "fbb6d647ca2913e8" + }, + { + "name": "Finish installing browser secret helper build libraries", + "digest": "939804bc6530a921" + }, + { + "name": "Test", + "digest": "801fc4dfe59fb6cd" + } + ] + }, + "test_web": { + "header": "f070980792433ae6", + "steps": [ + { + "name": "Checkout", + "digest": "b209d3ae4e2481dd" + }, + { + "name": "Setup Vite+", + "digest": "26d8e10bd2d55595" + }, + { + "name": "Resolve Playwright version", + "digest": "287797def955482a" + }, + { + "name": "Cache Chromium", + "digest": "a26f01a6a03f3797" + }, + { + "name": "Install Chromium for web browser tests", + "digest": "6148d0bd5a6f738e" + }, + { + "name": "Install missing Chromium system dependencies", + "digest": "c2a97e6621813cb4" + }, + { + "name": "Test", + "digest": "fc0c7beecafd3de9" + } + ] + }, + "test_server": { + "header": "88f6bbaecaaa2d68", + "steps": [ + { + "name": "Checkout", + "digest": "b300e7178ac6e5a0" + }, + { + "name": "Detect affected jobs", + "digest": "5648db2117818e11" + }, + { + "name": "Setup Vite+", + "digest": "f939b7b648c8903f" + }, + { + "name": "Resolve Playwright version", + "digest": "5181e0fc26afb953" + }, + { + "name": "Cache Chromium", + "digest": "c11a7e038f53f2e0" + }, + { + "name": "Install Chromium for server browser integration tests", + "digest": "925ae79b31188f3a" + }, + { + "name": "Install missing Chromium system dependencies", + "digest": "862e4a563cb8a6b1" + }, + { + "name": "Restore Vitest module cache", + "digest": "a9f2e0ea95ad6af3" + }, + { + "name": "Test", + "digest": "937c849dc92283cb" + }, + { + "name": "Save Vitest module cache", + "digest": "2af919f0e9798f00" + }, + { + "name": "Detect transfer budget report", + "digest": "6663d3329e713273" + }, + { + "name": "Publish transfer budget report", + "digest": "9e8eac20b2e9877f" + }, + { + "name": "Upload thread transfer result", + "digest": "f063a55279351e0c" + } + ] + }, + "rust": { + "header": "30bedddbe04fd44e", + "steps": [ + { + "name": "Checkout", + "digest": "b209d3ae4e2481dd" + }, + { + "name": "Setup Rust", + "digest": "7e4bade2fcac6c02" + }, + { + "name": "Check Rust formatting", + "digest": "e945fdc4fdd62992" + }, + { + "name": "Test Rust crates", + "digest": "0ecfc49333a39740" + } + ] + }, + "mobile_native_static_analysis": { + "header": "8b1472b3fce2c1bf", + "steps": [ + { + "name": "Checkout", + "digest": "3ac69f008422eb40" + }, + { + "name": "Setup Vite+", + "digest": "6e158a8bbd17c378" + }, + { + "name": "Install mobile native static analysis tools", + "digest": "2ce921f9eed13925" + }, + { + "name": "Lint mobile native sources", + "digest": "828af132b4613197" + } + ] + }, + "release_smoke": { + "header": "d8e29a4630f1113b", + "steps": [ + { + "name": "Checkout", + "digest": "b209d3ae4e2481dd" + }, + { + "name": "Setup Vite+", + "digest": "26d8e10bd2d55595" + }, + { + "name": "Exercise release-only workflow steps", + "digest": "40dae22ed3a65fd4" + } + ] + }, + "check": { + "header": "68e1588ae1870178", + "steps": [ + { + "name": "Require every job to pass", + "digest": "d7af266a25bf845d" + }, + { + "name": "Require transfer measurements", + "digest": "67ca47d5bd5ffc3d" + } + ] + } + }, + ".github/workflows/release.yml": { + "quality": { + "header": "64aee6ef731d6767", + "steps": [ + { + "name": "Checkout", + "digest": "6c2d53c2bffa53dd" + }, + { + "name": "Setup dependencies", + "digest": "7956327a0eceab8a" + }, + { + "name": "Ensure Electron runtime is installed", + "digest": "b49682a395d1db97" + }, + { + "name": "Check", + "digest": "b9e0beb00c16198e" + }, + { + "name": "Typecheck", + "digest": "a6830e957ddbd801" + } + ] + }, + "test": { + "header": "d304a3329d6f527f", + "steps": [ + { + "name": "Checkout", + "digest": "6c2d53c2bffa53dd" + }, + { + "name": "Setup dependencies", + "digest": "7956327a0eceab8a" + }, + { + "name": "Ensure Electron runtime is installed", + "digest": "b49682a395d1db97" + }, + { + "name": "./.github/actions/setup-apt-mirrors", + "digest": "14f039b4273b5477" + }, + { + "name": "Install browser secret helper build libraries", + "digest": "9ef6c7220ef74e0a" + }, + { + "name": "Test", + "digest": "af6646f21efe6013" + } + ] + }, + "test_web": { + "header": "558b5ad0011b866b", + "steps": [ + { + "name": "Checkout", + "digest": "6c2d53c2bffa53dd" + }, + { + "name": "Setup dependencies", + "digest": "7956327a0eceab8a" + }, + { + "name": "Resolve Playwright version", + "digest": "287797def955482a" + }, + { + "name": "Cache Chromium", + "digest": "a26f01a6a03f3797" + }, + { + "name": "Install Chromium for web browser tests", + "digest": "6148d0bd5a6f738e" + }, + { + "name": "Install missing Chromium system dependencies", + "digest": "c2a97e6621813cb4" + }, + { + "name": "Test", + "digest": "fc0c7beecafd3de9" + }, + { + "name": "Boot the built web client", + "digest": "4ee85e6cd11f1d42" + } + ] + }, + "test_server": { + "header": "dcb7af07046ed9c0", + "steps": [ + { + "name": "Checkout", + "digest": "6c2d53c2bffa53dd" + }, + { + "name": "Setup dependencies", + "digest": "7956327a0eceab8a" + }, + { + "name": "Install Chromium for server browser integration tests", + "digest": "69d36de687d7ae89" + }, + { + "name": "Test", + "digest": "c5d091ce655d8187" + } + ] + } + } +} diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4a66b5d268103..94157c4135fac 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -15,16 +15,11 @@ reproduction steps or environment where relevant. --> -## Scope and approval - - +## Scope + + ## Verification diff --git a/.github/scripts/fork-ci-tests.cjs b/.github/scripts/fork-ci-tests.cjs new file mode 100644 index 0000000000000..0a73f2e164a36 --- /dev/null +++ b/.github/scripts/fork-ci-tests.cjs @@ -0,0 +1,99 @@ +// Fork only: runs every `.github/scripts/fork-*.test.{sh,py,cjs}` and checks +// them against `.github/fork-ci-tests.txt`. A present test missing from the list +// fails; a listed test that is missing fails once it has been in the tested +// commit's history (deleted while still listed) and is a note before that. +const childProcess = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); + +const ROOT = path.resolve(__dirname, "../.."); +const LIST = ".github/fork-ci-tests.txt"; +const TEST_FILE = /^fork-.+\.test\.(sh|py|cjs)$/; +const RUNNER = { sh: ["bash"], py: ["python3"], cjs: ["node", "--test"] }; + +// `ever(file)` says whether the file is in the tested commit's history. +function plan(listed, present, ever) { + const unlisted = present.filter((file) => !listed.includes(file)); + const missing = listed.filter((file) => !present.includes(file)); + const deleted = missing.filter((file) => ever(file)); + const pending = missing.filter((file) => !deleted.includes(file)); + return { run: present, unlisted, deleted, pending }; +} + +function readList(text) { + return text + .split("\n") + .map((line) => line.replace(/#.*/, "").trim()) + .filter(Boolean); +} + +function git(args) { + return childProcess.execFileSync("git", args, { cwd: ROOT, encoding: "utf8" }).trim(); +} + +// A shallow checkout first fetches the full history of HEAD, trees only. +function everInHistory(file) { + if (git(["rev-parse", "--is-shallow-repository"]) === "true") + git([ + "fetch", + "--quiet", + "--no-tags", + "--filter=blob:none", + "--unshallow", + "origin", + git(["rev-parse", "HEAD"]), + ]); + return git(["log", "-1", "--format=%h", "HEAD", "--", file]) !== ""; +} + +function main() { + const listed = readList(fs.readFileSync(path.join(ROOT, LIST), "utf8")); + const present = fs + .readdirSync(path.join(ROOT, ".github/scripts")) + .filter((name) => TEST_FILE.test(name)) + .map((name) => `.github/scripts/${name}`) + .toSorted(); + const result = plan(listed, present, everInHistory); + const rows = []; + let failed = result.unlisted.length + result.deleted.length; + for (const file of result.run) { + const [command, ...args] = RUNNER[path.basename(file).match(TEST_FILE)[1]]; + const started = Date.now(); + console.log(`::group::${file}`); + const run = childProcess.spawnSync(command, [...args, file], { cwd: ROOT, stdio: "inherit" }); + console.log("::endgroup::"); + const seconds = ((Date.now() - started) / 1000).toFixed(1); + if (run.status !== 0) { + failed += 1; + console.log(`::error file=${file}::${file} failed (exit ${run.status ?? run.signal})`); + } + rows.push(`| \`${file}\` | ${run.status === 0 ? "passed" : "**failed**"} | ${seconds} s |`); + } + for (const file of result.unlisted) + console.log(`::error file=${file}::${file} is not in ${LIST}; add it there`); + for (const file of result.deleted) + console.log(`::error::${file} is listed in ${LIST} but was deleted; restore it or unlist it`); + for (const file of result.pending) + rows.push(`| \`${file}\` | not present: its PR has not merged | |`); + for (const file of result.unlisted) rows.push(`| \`${file}\` | **not in ${LIST}** | |`); + for (const file of result.deleted) rows.push(`| \`${file}\` | **deleted while listed** | |`); + + const summary = process.env.GITHUB_STEP_SUMMARY; + if (summary) + fs.appendFileSync( + summary, + [ + "### Fork script tests", + "", + "| Test | Result | Time |", + "| --- | --- | --- |", + ...rows, + "", + ].join("\n") + "\n", + ); + if (failed) process.exitCode = 1; +} + +module.exports = { plan, readList }; + +if (require.main === module) main(); diff --git a/.github/scripts/fork-ci-tests.test.cjs b/.github/scripts/fork-ci-tests.test.cjs new file mode 100644 index 0000000000000..8703b0d841c84 --- /dev/null +++ b/.github/scripts/fork-ci-tests.test.cjs @@ -0,0 +1,30 @@ +const assert = require("node:assert/strict"); +const test = require("node:test"); + +const { plan, readList } = require("./fork-ci-tests.cjs"); + +const never = () => false; + +test("runs every present test, listed or not", () => { + assert.deepEqual(plan(["a"], ["a", "b"], never).run, ["a", "b"]); +}); + +test("a present test missing from the list fails", () => { + assert.deepEqual(plan(["a"], ["a", "b"], never).unlisted, ["b"]); +}); + +test("a listed test never in history is pending, not a failure", () => { + const result = plan(["a", "later"], ["a"], never); + assert.deepEqual(result.pending, ["later"]); + assert.deepEqual(result.deleted, []); +}); + +test("a listed test deleted from history fails", () => { + const result = plan(["a", "gone"], ["a"], (file) => file === "gone"); + assert.deepEqual(result.deleted, ["gone"]); + assert.deepEqual(result.pending, []); +}); + +test("the list ignores comments and blank lines", () => { + assert.deepEqual(readList("# head\n\na.sh # from #2\n b.py\n"), ["a.sh", "b.py"]); +}); diff --git a/.github/scripts/fork-release-workflow.test.py b/.github/scripts/fork-release-workflow.test.py new file mode 100644 index 0000000000000..2ee5be72787cc --- /dev/null +++ b/.github/scripts/fork-release-workflow.test.py @@ -0,0 +1,142 @@ +"""Checks the shape of .github/workflows/fork-release.yml that its guards rely on. + + python3 .github/scripts/fork-release-workflow.test.py [path/to/fork-release.yml] + +Needs PyYAML. Each check prints ok/FAIL; any FAIL exits 1. +""" + +import pathlib +import re +import sys + +import yaml + +root = pathlib.Path(__file__).resolve().parents[2] +path = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else root / ".github/workflows/fork-release.yml" +text = path.read_text() +wf = yaml.safe_load(text) +desktop = yaml.safe_load((root / ".github/workflows/release-desktop.yml").read_text()) +jobs = wf["jobs"] +failures = [] + + +def check(name, ok, detail=""): + print(("ok " if ok else "FAIL ") + name + ("" if ok or not detail else f"\n | {detail}")) + if not ok: + failures.append(name) + + +def steps(job): + return job.get("steps", []) + + +def all_steps(): + for job_id, job in jobs.items(): + for step in steps(job): + yield job_id, step + + +# Actions run by commit, so a moved tag cannot change what runs (the release action holds a write +# token). Local actions and workflows are part of this repository. +unpinned = [] +for line in text.splitlines(): + m = re.match(r"\s*(?:-\s*)?uses:\s*(\S+)(.*)$", line) + if not m or m.group(1).startswith("./"): + continue + if not re.fullmatch(r"[\w.-]+/[\w./-]+@[0-9a-f]{40}", m.group(1)) or not re.match(r"\s*#\s*v\d", m.group(2)): + unpinned.append(m.group(1)) +check("external actions are pinned by commit SHA with a version comment", not unpinned, ", ".join(unpinned)) + +# Named secrets only: the signing secrets release-desktop.yml declares, nothing inherited. +declared = set(desktop[True]["workflow_call"]["secrets"]) +inherit = [j for j, job in jobs.items() if job.get("secrets") == "inherit"] +check("no job passes secrets: inherit", not inherit, ", ".join(inherit)) +wrong = [] +for job_id, job in jobs.items(): + if job.get("uses") == "./.github/workflows/release-desktop.yml": + passed = job.get("secrets") + if not isinstance(passed, dict) or set(passed) != declared or any( + v != "${{ secrets.%s }}" % k for k, v in passed.items() + ): + wrong.append(job_id) +check("release-desktop.yml gets exactly the secrets it declares", not wrong, ", ".join(wrong)) +check("FORK_PUSH_TOKEN appears nowhere", "FORK_PUSH_TOKEN" not in text) + +bad = [j for j, s in all_steps() if str(s.get("uses", "")).startswith("actions/checkout@") + and (s.get("with") or {}).get("persist-credentials") is not False] +check("every checkout sets persist-credentials: false", not bad, ", ".join(bad)) + +release_steps = [(j, s) for j, s in all_steps() if str(s.get("uses", "")).startswith("softprops/action-gh-release@")] +check("one release-action step", len(release_steps) == 1) +check("the release action fails on unmatched files", + all((s.get("with") or {}).get("fail_on_unmatched_files") is True for _, s in release_steps)) + +# The write token: only the publish job has it, and only its three release-writing steps use it. +write_jobs = [j for j, job in jobs.items() if (job.get("permissions") or {}).get("contents") == "write"] +check("only the publish job has contents: write", write_jobs == ["publish"], ", ".join(write_jobs)) +package_code = re.compile(r"(^|[\s;&|(])(vp|node|npm|npx|pnpm|bun)\s") +for job_id in write_jobs: + job_steps = steps(jobs[job_id]) + runs_packages = [s.get("name") for s in job_steps + if str(s.get("uses", "")).startswith("./") or package_code.search(str(s.get("run", "")))] + check(f"{job_id}: runs no package code", not runs_packages, ", ".join(map(str, runs_packages))) + token_steps = [s for s in job_steps if "github.token" in yaml.safe_dump(s) or "secrets." in yaml.safe_dump(s) + or str(s.get("uses", "")).startswith("softprops/")] + allowed = [s for s in token_steps if str(s.get("uses", "")).startswith("softprops/") + or re.fullmatch(r"bash \.github/scripts/fork-release\.sh (remove-drafts|publish) .*", str(s.get("run", "")).strip())] + check(f"{job_id}: the token reaches only the remove-drafts, create and publish steps", + len(token_steps) == len(allowed) == 3, ", ".join(str(s.get("name")) for s in token_steps)) + + def index(pred): + return next((i for i, s in enumerate(job_steps) if pred(s)), -1) + + remove = index(lambda s: "fork-release.sh remove-drafts" in str(s.get("run", ""))) + create = index(lambda s: str(s.get("uses", "")).startswith("softprops/")) + publish = index(lambda s: "fork-release.sh publish" in str(s.get("run", ""))) + check(f"{job_id}: refuse/remove drafts, then create the draft, then publish it", + -1 < remove < create < publish) + if create >= 0 and publish >= 0: + check(f"{job_id}: publishes the draft it created, by id", + job_steps[create].get("id") == "draft" + and "steps.draft.outputs.id" in yaml.safe_dump(job_steps[publish])) + +# Shell steps fail on any error in a pipeline. +lax = [] +for job_id, s in all_steps(): + run = s.get("run") + if run is None: + continue + lines = [l for l in run.strip().splitlines() if l.strip() and not l.strip().startswith("#")] + if s.get("shell") != "bash" or (len(lines) > 1 and lines[0].strip() != "set -euo pipefail"): + lax.append(f"{job_id}/{s.get('name')}") +check("run steps use bash and multi-line ones start with set -euo pipefail", not lax, "; ".join(lax)) + +runs = "\n".join(str(s.get("run", "")) for _, s in all_steps()) +check("preflight resolves the version through the guard script", + "fork-release.sh resolve" in "\n".join(str(s.get("run", "")) for s in steps(jobs["preflight"]))) +check("preflight runs the guard tests", "fork-release.test.sh" in runs) +check("the CLI archives are checked for the release repository", "fork-release.sh check-archives release-assets" in runs) +check("preflight runs this shape test", "fork-release-workflow.test.py" in + "\n".join(str(s.get("run", "")) for s in steps(jobs["preflight"]))) + +# The server bundle check skips dist/client, which names this repository on every Actions build. +bundle_steps = [s for s in steps(jobs["build_bundle"]) if "apps/server/dist" in str(s.get("run", ""))] +check("the server bundle is checked through check-bundle (without dist/client)", + [str(s.get("run", "")).strip() for s in bundle_steps] + == ["bash .github/scripts/fork-release.sh check-bundle apps/server/dist"]) + +# The build names this fork through the setting scripts/lib/release-repository.ts reads. +build = next((s for s in steps(jobs["build_bundle"]) if s.get("name") == "Build JS bundle"), {}) +check("the build sets T3CODE_DESKTOP_UPDATE_REPOSITORY to this repository", + (build.get("env") or {}).get("T3CODE_DESKTOP_UPDATE_REPOSITORY") == "${{ github.repository }}") +check("the former name T3CODE_RELEASE_REPOSITORY appears nowhere", "T3CODE_RELEASE_REPOSITORY" not in text) + +# The write job's guard script comes from the workflow's own commit, not the commit being built. +guard = [s for s in steps(jobs["publish"]) if str(s.get("uses", "")).startswith("actions/checkout@")] +check("publish checks out its guard script at github.workflow_sha", + len(guard) == 1 and (guard[0].get("with") or {}).get("ref") == "${{ github.workflow_sha }}") + +if failures: + print(f"{len(failures)} failed") + sys.exit(1) +print("all passed") diff --git a/.github/scripts/fork-release.sh b/.github/scripts/fork-release.sh new file mode 100755 index 0000000000000..62e62a4816736 --- /dev/null +++ b/.github/scripts/fork-release.sh @@ -0,0 +1,233 @@ +#!/usr/bin/env bash +# The guards of fork-release.yml, one subcommand each, so they can be tested without a run +# (fork-release.test.sh). Every refusal exits non-zero with a ::error:: line; nothing falls back. +# +# resolve Preflight: picks base tag, version and tag for HEAD (key=value lines). +# remove-drafts TAG Refuses a published TAG, then deletes drafts with TAG left by earlier runs. +# publish ID TAG VERSION Refuses a published TAG or a published release that is not below +# VERSION, then publishes draft ID as the latest release. +# check-bundle DIR The server bundle DIR (apps/server/dist) outside DIR/client must name +# REPOSITORY as its release repository. +# check-archives DIR The `t3` program of every CLI archive in DIR must name REPOSITORY. +# +# Environment: REPOSITORY (owner/name of this fork; GITHUB_REPOSITORY in a run), UPSTREAM +# (owner/name, resolve looks it up), UPSTREAM_URL (git URL of upstream, default GitHub), ORIGIN +# (git remote or URL of this fork, default origin). Output goes to $GITHUB_OUTPUT, else stdout. +set -euo pipefail + +REPOSITORY="${REPOSITORY:-${GITHUB_REPOSITORY:?REPOSITORY or GITHUB_REPOSITORY}}" +ORIGIN="${ORIGIN:-origin}" +OUTPUT="${GITHUB_OUTPUT:-/dev/stdout}" + +die() { + printf '::error::%s\n' "$*" >&2 + exit 1 +} + +stable_version_re='^v[0-9]+\.[0-9]+\.[0-9]+$' +fork_version_re='^v?[0-9]+\.[0-9]+\.[0-9]+-fork\.[0-9]+$' + +# version_gt A B: A sorts above B. Takes X.Y.Z or X.Y.Z-fork.N (leading v allowed). A fork +# release of X.Y.Z sorts above X.Y.Z itself here, which is what this fork's ordering needs. +version_gt() { + local a="${1#v}" b="${2#v}" i + local -a x y + IFS=. read -r -a x <<< "${a/-fork./.}" + IFS=. read -r -a y <<< "${b/-fork./.}" + for i in 0 1 2 3; do + if (( 10#${x[i]:-0} != 10#${y[i]:-0} )); then + (( 10#${x[i]:-0} > 10#${y[i]:-0} )) + return + fi + done + return 1 +} + +# Prints the releases of this fork through a jq filter; a failed listing stops everything. +releases() { + gh api "repos/$REPOSITORY/releases" --paginate --jq "$1" \ + || die "Could not list the releases of $REPOSITORY; nothing was changed." +} + +# A published (non-draft) release or a tag with this name means the version is taken: "Re-run failed +# jobs" reuses the preflight's version, and publishing again would replace a live release's files. +refuse_published() { + local tag="$1" published + if git ls-remote --exit-code --tags "$ORIGIN" "refs/tags/$tag" > /dev/null; then + die "Tag $tag already exists, so $tag is published or being published. Start a new run (Re-run all jobs) for the next number; nothing was changed." + else + # 2 means no such ref; anything else is a failed lookup, which must not read as "free". + [[ $? == 2 ]] || die "Could not list the tags of $ORIGIN." + fi + published="$(releases ".[] | select((.draft | not) and .tag_name == \"$tag\") | .id")" + if [[ -n "$published" ]]; then + die "A published release ($published) already has tag $tag. Start a new run (Re-run all jobs); nothing was changed." + fi +} + +# The server's updater (packages/shared/src/cliRelease.ts newestCliReleaseVersion) takes the +# newest-created non-draft release on its channel, not the highest version. So every new release +# must be above every published one, or `t3 update` would see a downgrade and stall until a higher +# build exists. Stable channel = any vX.Y.Z[-...] tag except -nightly./-preview. builds. +refuse_older() { + local version="$1" other published + published="$(releases '.[] | select(.draft | not) | .tag_name')" + for other in $published; do + [[ "$other" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]] || continue + [[ ! "$other" =~ -(nightly|preview)\. ]] || continue + [[ "$other" =~ $stable_version_re || "$other" =~ $fork_version_re ]] \ + || die "Published release $other is on the server's stable channel but has no X.Y.Z or X.Y.Z-fork.N version, so $version cannot be ordered against it; nothing was changed." + version_gt "$version" "$other" \ + || die "$other is published and not below $version. The server updates to the newest-created release, so publishing $version would show every server a downgrade. Build a newer upstream release instead; to go back, install the older release with t3 update --version X --allow-downgrade. Nothing was changed." + done +} + +cmd_resolve() { + local upstream="${UPSTREAM:-}" + if [[ -z "$upstream" ]]; then + upstream="$(gh api "repos/$REPOSITORY" --jq '.parent.full_name // empty')" + [[ -n "$upstream" ]] || die "$REPOSITORY is not a fork, so there is no upstream release to build on." + fi + local url="${UPSTREAM_URL:-https://github.com/$upstream.git}" + local head + head="$(git rev-parse HEAD)" + + # Read-only fetch of upstream's tags and default branch into refs this run alone uses. + git fetch --quiet --no-tags "$url" "+refs/tags/v*:refs/upstream-tags/v*" "+HEAD:refs/upstream-head" + + # Lists are read into variables first: a failure inside <(...) would go unnoticed. + local refs tag + local -a contained=() + refs="$(git for-each-ref --format='%(refname:strip=2)' refs/upstream-tags)" + for tag in $(grep -E "$stable_version_re" <<< "$refs" | sort -rV || true); do + if git merge-base --is-ancestor "refs/upstream-tags/$tag^{commit}" HEAD; then + contained+=("$tag") + fi + done + (( ${#contained[@]} > 0 )) || die "$head contains no stable $upstream release tag." + local base_tag="${contained[0]}" + local base + base="$(git rev-parse "refs/upstream-tags/$base_tag^{commit}")" + + # The base must be the newest stable tag in the series' history, not just the highest name: a + # stray tag on an old commit (say v1.0.0) would otherwise outrank every later real release. + for tag in "${contained[@]:1}"; do + git merge-base --is-ancestor "refs/upstream-tags/$tag^{commit}" "$base" \ + || die "$base_tag sorts highest but is not the newest stable $upstream tag in this history ($tag is not part of it). Delete or fix the stray tag; nothing was built." + done + + # Upstream's own ordering: never above the release upstream marks latest. + local upstream_latest + upstream_latest="$(gh api "repos/$upstream/releases/latest" --jq '.tag_name')" + [[ "$upstream_latest" =~ $stable_version_re ]] \ + || die "$upstream's latest release is '$upstream_latest', not a stable vX.Y.Z tag." + if version_gt "$base_tag" "$upstream_latest"; then + die "$base_tag sorts above $upstream's latest release $upstream_latest. Only released upstream versions are built." + fi + + # Releases only: every commit after the base tag must be the fork's own. Upstream commits there + # are unreleased upstream code (for example a branch that still equals upstream's default branch). + local total own + total="$(git rev-list --count "$base..HEAD")" + own="$(git rev-list --count "$base..HEAD" --not refs/upstream-head)" + if [[ "$total" != "$own" ]]; then + die "$head holds $((total - own)) unreleased $upstream commits after $base_tag. Build a branch of $base_tag plus the fork's own commits." + fi + + local version="${base_tag#v}" last + last="$(git ls-remote --tags --refs "$ORIGIN" "v$version-fork.*" \ + | sed -n "s|.*refs/tags/v$version-fork\.\([0-9]\+\)$|\1|p" | sort -n | tail -n1)" + version="$version-fork.$(( ${last:-0} + 1 ))" + refuse_older "$version" + { + echo "ref=$head" + echo "upstream=$upstream" + echo "base_tag=$base_tag" + echo "version=$version" + echo "tag=v$version" + } >> "$OUTPUT" + echo "Building $version from $(git rev-parse --short HEAD) on $upstream $base_tag." \ + | tee -a "${GITHUB_STEP_SUMMARY:-/dev/null}" >&2 +} + +cmd_remove_drafts() { + local tag="${1:?tag}" id + refuse_published "$tag" + local ids + ids="$(releases ".[] | select(.draft and .tag_name == \"$tag\") | .id")" + for id in $ids; do + gh api -X DELETE "repos/$REPOSITORY/releases/$id" > /dev/null + echo "Removed leftover draft $id for $tag." + done + [[ -n "$ids" ]] || echo "No leftover draft for $tag." +} + +cmd_publish() { + local id="${1:?release id}" tag="${2:?tag}" version="${3:?version}" + [[ "$version" =~ $fork_version_re ]] || die "'$version' is not a fork version." + refuse_published "$tag" + # Checked again here: a release published since preflight must not end up above this one. After + # this check VERSION is the highest release, so the server and the desktop updater agree on it. + refuse_older "$version" + gh api -X PATCH "repos/$REPOSITORY/releases/$id" -F draft=false -f make_latest=true > /dev/null + echo "Published $tag (latest: true)." + { + echo "published=true" + echo "latest=true" + } >> "$OUTPUT" +} + +# The web client (DIR/client) names this repository on every Actions build anyway: upstream's +# apps/web/vite.config.ts bakes GITHUB_REPOSITORY into it. Only the server code counts here. +cmd_check_bundle() { + local dir="${1:?directory}" file files + [[ -d "$dir" ]] || die "No server bundle at $dir." + files="$(find "$dir" -path "$dir/client" -prune -o -type f -print)" + [[ -n "$files" ]] || die "The server bundle $dir holds no files outside client/." + while IFS= read -r file; do + if grep -qaF "\"$REPOSITORY\"" "$file"; then + echo "The server bundle names $REPOSITORY (${file#"$dir"/})." + return 0 + fi + done <<< "$files" + die "The server bundle $dir (outside client/) does not name $REPOSITORY as its release repository, so it would update from elsewhere." +} + +cmd_check_archives() { + local dir="${1:?directory}" archive work name stem program found=0 + shopt -s nullglob + for archive in "$dir"/t3-*.tar.gz "$dir"/t3-*.zip; do + found=1 + work="$(mktemp -d)" + case "$archive" in + *.tar.gz) tar -xzf "$archive" -C "$work" ;; + *.zip) python3 -I -m zipfile -e "$archive" "$work" ;; + esac + # Only the `t3` program at / (scripts/build-cli-archive.ts): it bundles the server again, + # and its updater is what counts. client/ names this repository on every Actions build anyway. + name="$(basename "$archive")" + stem="${name%.tar.gz}" + stem="${stem%.zip}" + program="$work/$stem/t3" + [[ "$archive" != *.zip ]] || program="$work/$stem/t3.exe" + [[ -f "$program" ]] \ + || die "$name has no ${program#"$work"/}, so the server program in it cannot be checked." + grep -qaF "\"$REPOSITORY\"" "$program" \ + || die "${program#"$work"/} in $name does not name $REPOSITORY as its release repository, so it would update from elsewhere." + rm -rf "$work" + echo "${program#"$work"/} in $name names $REPOSITORY." + done + (( found )) || die "No CLI archive in $dir." +} + +command="${1:-}" +shift || true +case "$command" in + resolve) cmd_resolve "$@" ;; + remove-drafts) cmd_remove_drafts "$@" ;; + publish) cmd_publish "$@" ;; + check-bundle) cmd_check_bundle "$@" ;; + check-archives) cmd_check_archives "$@" ;; + version-gt) version_gt "$@" ;; + *) die "usage: $0 resolve | remove-drafts TAG | publish ID TAG VERSION | check-bundle DIR | check-archives DIR" ;; +esac diff --git a/.github/scripts/fork-release.test.sh b/.github/scripts/fork-release.test.sh new file mode 100755 index 0000000000000..2a1e2240ecba1 --- /dev/null +++ b/.github/scripts/fork-release.test.sh @@ -0,0 +1,294 @@ +#!/usr/bin/env bash +# Tests for fork-release.sh against local git repositories and a fake `gh`; no network. +# bash .github/scripts/fork-release.test.sh (FORK_RELEASE_SH picks another script) +set -euo pipefail + +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +script="$(realpath "${FORK_RELEASE_SH:-$here/fork-release.sh}")" +root="$(mktemp -d)" +trap 'rm -rf "$root"' EXIT + +# Upstream "up/t3code" and this fork "me/t3code" live under $root/gh; git reaches them through the +# github.com URLs the workflow uses. +export GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL="$root/gitconfig" +git config --global user.name test +git config --global user.email test@example.invalid +git config --global init.defaultBranch main +git config --global advice.detachedHead false +git config --global url."$root/gh/".insteadOf https://github.com/ +export REPOSITORY=me/t3code GITHUB_REPOSITORY=me/t3code +unset GITHUB_OUTPUT GITHUB_STEP_SUMMARY UPSTREAM UPSTREAM_URL ORIGIN + +# Fake gh: `gh api [-X M] PATH [--paginate] [--jq EXPR] [-f/-F k=v]...` served from $root/api. +mkdir -p "$root/bin" "$root/api" +cat > "$root/bin/gh" <<'GH' +#!/usr/bin/env bash +set -euo pipefail +api="$FAKE_API" +echo "gh $*" >> "$api/calls" +[[ "$1" == api ]] || { echo "fake gh: only api" >&2; exit 2; } +shift +method=GET path="" jq="" fields=() +while (( $# )); do + case "$1" in + -X) method="$2"; shift 2 ;; + --jq) jq="$2"; shift 2 ;; + --paginate) shift ;; + -f|-F) fields+=("$2"); shift 2 ;; + *) path="$1"; shift ;; + esac +done +case "$method $path" in + "GET repos/me/t3code") body='{"parent":{"full_name":"up/t3code"}}' ;; + "GET repos/up/t3code/releases/latest") body="{\"tag_name\":\"$(cat "$api/upstream_latest")\"}" ;; + "GET repos/me/t3code/releases") + [[ ! -e "$api/fail_list" ]] || { echo "HTTP 502: Bad Gateway" >&2; exit 1; } + body="$(cat "$api/releases.json")" ;; + "DELETE repos/me/t3code/releases/"*) + id="${path##*/}" + jq --argjson id "$id" 'map(select(.id != $id))' "$api/releases.json" > "$api/r.tmp" + mv "$api/r.tmp" "$api/releases.json" + echo "deleted $id" >> "$api/writes"; exit 0 ;; + "PATCH repos/me/t3code/releases/"*) + echo "patched ${path##*/} ${fields[*]}" >> "$api/writes"; exit 0 ;; + *) echo "fake gh: no route for $method $path" >&2; exit 1 ;; +esac +if [[ -n "$jq" ]]; then jq -r "$jq" <<< "$body"; else echo "$body"; fi +GH +chmod +x "$root/bin/gh" +export PATH="$root/bin:$PATH" FAKE_API="$root/api" + +failures=0 +pass() { echo "ok $1"; } +fail() { + echo "FAIL $1" + sed 's/^/ | /' "$root/out" 2> /dev/null || true + failures=$((failures + 1)) +} +run() { (cd "$1" && shift && "$script" "$@") > "$root/out" 2>&1; } + +reset_api() { + rm -f "$root/api"/* + echo '[]' > "$root/api/releases.json" + echo "${1:-v0.1.9}" > "$root/api/upstream_latest" +} + +# Upstream history: u1 (v0.1.8) - u2 (v0.1.9) - u3 (unreleased, upstream main). +new_upstream() { + rm -rf "$root/gh" "$root/upwork" + mkdir -p "$root/gh/up" "$root/gh/me" + git init -q --bare "$root/gh/up/t3code.git" + git init -q --bare "$root/gh/me/t3code.git" + git init -q "$root/upwork" + ( + cd "$root/upwork" + git commit -q --allow-empty -m u1 && git tag v0.1.8 + git commit -q --allow-empty -m u2 && git tag -a -m v0.1.9 v0.1.9 + git commit -q --allow-empty -m u3 + git push -q https://github.com/up/t3code.git main --tags + ) +} + +# The fork's checkout: $1 (an upstream rev) plus one fork commit, pushed as the fork's main. +new_fork() { + rm -rf "$root/work" + git clone -q https://github.com/up/t3code.git "$root/work" + ( + cd "$root/work" + git remote set-url origin https://github.com/me/t3code.git + git checkout -q -B main "$1" + [[ "${2:-}" == bare ]] || git commit -q --allow-empty -m "fork: own change" + git push -q --force origin main + ) +} + +fork_tag() { (cd "$root/work" && git tag "$1" && git push -q origin "refs/tags/$1"); } + +expect_resolved() { + local name="$1" want="$2" + if run "$root/work" resolve && grep -qx "version=$want" "$root/out"; then pass "$name"; else fail "$name"; fi +} +expect_refused() { + local name="$1" pattern="$2" + shift 2 + if ! run "$@" && grep -q "::error::.*$pattern" "$root/out"; then pass "$name"; else fail "$name"; fi +} + +# --- resolve ----------------------------------------------------------------------------------- +new_upstream +reset_api +new_fork v0.1.9 +expect_resolved "resolve: v0.1.9 plus a fork commit is 0.1.9-fork.1" 0.1.9-fork.1 +fork_tag v0.1.9-fork.1 +fork_tag v0.1.9-fork.x +expect_resolved "resolve: the next build counts the fork's numbered tags" 0.1.9-fork.2 + +new_fork main bare +expect_refused "resolve: refuses unreleased upstream commits (upstream main)" "unreleased" "$root/work" resolve +new_fork main +expect_refused "resolve: refuses unreleased upstream commits under fork commits" "unreleased" "$root/work" resolve + +(cd "$root/upwork" && git tag v1.0.0 v0.1.8 && git push -q https://github.com/up/t3code.git v1.0.0) +new_fork v0.1.9 +expect_refused "resolve: refuses a stray higher tag on an old commit" "not the newest" "$root/work" resolve + +new_upstream +reset_api v0.1.9 +(cd "$root/upwork" && git tag v0.1.10 main && git push -q https://github.com/up/t3code.git v0.1.10) +new_fork v0.1.10 +expect_refused "resolve: refuses a base above upstream's latest release" "above up/t3code's latest" "$root/work" resolve +echo v0.1.10 > "$root/api/upstream_latest" +expect_resolved "resolve: accepts it once upstream marks it latest" 0.1.10-fork.1 + +reset_api v0.1.10 +echo '[{"id":5,"draft":false,"prerelease":false,"tag_name":"v0.1.10-fork.3"}]' > "$root/api/releases.json" +new_fork v0.1.9 +expect_refused "resolve: refuses a build below a published release (older ref after a newer one)" \ + "v0.1.10-fork.3 is published and not below 0.1.9-fork.1" "$root/work" resolve +echo '[{"id":5,"draft":true,"prerelease":false,"tag_name":"v0.1.10-fork.3"}]' > "$root/api/releases.json" +expect_resolved "resolve: a higher draft does not block (updaters skip drafts)" 0.1.9-fork.1 + +# --- remove-drafts ----------------------------------------------------------------------------- +new_upstream +reset_api +new_fork v0.1.9 +echo '[{"id":7,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.1"}, + {"id":8,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.9"}]' > "$root/api/releases.json" +if run "$root/work" remove-drafts v0.1.9-fork.1 && grep -qx "deleted 7" "$root/api/writes" \ + && ! grep -q "deleted 8" "$root/api/writes" && grep -q "Removed leftover draft 7" "$root/out"; then + pass "remove-drafts: deletes only that tag's draft and says so" +else + fail "remove-drafts: deletes only that tag's draft and says so" +fi + +reset_api +touch "$root/api/fail_list" +expect_refused "remove-drafts: a failed release listing fails the step" "Could not list the releases" "$root/work" remove-drafts v0.1.9-fork.1 +[[ ! -e "$root/api/writes" ]] || fail "remove-drafts: nothing written after a failed listing" + +reset_api +fork_tag v0.1.9-fork.1 +expect_refused "remove-drafts: refuses a version whose tag exists (re-run failed jobs)" "already exists" \ + "$root/work" remove-drafts v0.1.9-fork.1 + +reset_api +echo '[{"id":5,"draft":false,"prerelease":false,"tag_name":"v0.1.9-fork.2"}]' > "$root/api/releases.json" +expect_refused "remove-drafts: refuses a version with a published release" "published release" \ + "$root/work" remove-drafts v0.1.9-fork.2 + +# --- publish ----------------------------------------------------------------------------------- +reset_api +echo '[{"id":5,"draft":false,"prerelease":false,"tag_name":"v0.1.9-fork.1"}, + {"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.2"}]' > "$root/api/releases.json" +if run "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2 && grep -qx "patched 9 draft=false make_latest=true" "$root/api/writes" \ + && grep -qx "published=true" "$root/out"; then + pass "publish: a version above every release is marked latest" +else + fail "publish: a version above every release is marked latest" +fi + +reset_api +echo '[{"id":5,"draft":false,"prerelease":false,"tag_name":"v0.1.10-fork.1"}, + {"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.2"}]' > "$root/api/releases.json" +expect_refused "publish: refuses a version below a published release (server takes the newest created)" \ + "v0.1.10-fork.1 is published and not below 0.1.9-fork.2" "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2 +[[ ! -e "$root/api/writes" ]] || fail "publish: nothing written for an older version" + +reset_api +echo '[{"id":5,"draft":false,"prerelease":true,"tag_name":"v0.1.10-fork.1"}, + {"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.2"}]' > "$root/api/releases.json" +expect_refused "publish: a higher prerelease also blocks (the server ignores the prerelease flag)" \ + "not below" "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2 + +reset_api +echo '[{"id":4,"draft":false,"prerelease":false,"tag_name":"v0.2.0-nightly.20261101.3"}, + {"id":6,"draft":false,"prerelease":false,"tag_name":"notes"}, + {"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.2"}]' > "$root/api/releases.json" +if run "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2 && grep -qx "patched 9 draft=false make_latest=true" "$root/api/writes"; then + pass "publish: nightly and non-version tags are other channels and do not block" +else + fail "publish: nightly and non-version tags are other channels and do not block" +fi + +reset_api +echo '[{"id":4,"draft":false,"prerelease":false,"tag_name":"v0.1.8-rc.1"}]' > "$root/api/releases.json" +expect_refused "publish: a stable-channel tag it cannot order fails loudly" "cannot be ordered" \ + "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2 + +reset_api +echo '[{"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.1"}]' > "$root/api/releases.json" +expect_refused "publish: re-checks the tag right before un-drafting" "already exists" "$root/work" publish 9 v0.1.9-fork.1 0.1.9-fork.1 +[[ ! -e "$root/api/writes" ]] || fail "publish: nothing written when the tag exists" + +reset_api +touch "$root/api/fail_list" +expect_refused "publish: a failed release listing fails the step" "Could not list the releases" "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2 +[[ ! -e "$root/api/writes" ]] || fail "publish: nothing written after a failed listing" + +# --- check-archives ---------------------------------------------------------------------------- +# Layout of scripts/build-cli-archive.ts: /t3 (t3.exe in the Windows zip) plus /client/. +# The web client names this fork on every Actions build (upstream's apps/web/vite.config.ts), so it +# must not count; only the program does. +stage() { # stage DIR STEM PROGRAM PROGRAM_REPO CLIENT_REPO + mkdir -p "$1/$2/client/assets" + printf 'x\0const repo = "%s";\0' "$4" > "$1/$2/$3" + printf 'const u = "%s";' "$5" > "$1/$2/client/assets/index.js" +} +pack() { # pack DIR STEM OUT + case "$3" in + *.tar.gz) tar -czf "$3" -C "$1" "$2" ;; + *.zip) (cd "$1" && python3 -I -m zipfile -c "$3" "$2") ;; + esac +} +lin=t3-0.1.9-fork.1-linux-x64 win=t3-0.1.9-fork.1-win-x64 +mkdir -p "$root/assets-good" "$root/assets-bad" "$root/assets-repro" "$root/assets-noprog" "$root/assets-none" +stage "$root/arch/good" "$lin" t3 me/t3code me/t3code +stage "$root/arch/good" "$win" t3.exe me/t3code me/t3code +pack "$root/arch/good" "$lin" "$root/assets-good/$lin.tar.gz" +pack "$root/arch/good" "$win" "$root/assets-good/$win.zip" +cp "$root/assets-good/$lin.tar.gz" "$root/assets-bad/" +stage "$root/arch/bad" "$win" t3.exe up/t3code up/t3code +pack "$root/arch/bad" "$win" "$root/assets-bad/$win.zip" +# The review's repro: t3 names upstream, the web client names the fork. +stage "$root/arch/repro" "$lin" t3 up/t3code me/t3code +pack "$root/arch/repro" "$lin" "$root/assets-repro/$lin.tar.gz" +# No program at all, but the client names the fork. +mkdir -p "$root/arch/noprog/$lin/client" && printf '"me/t3code"' > "$root/arch/noprog/$lin/client/x.js" +printf '"me/t3code"' > "$root/arch/noprog/$lin/t3.sh" +pack "$root/arch/noprog" "$lin" "$root/assets-noprog/$lin.tar.gz" +if run "$root" check-archives "$root/assets-good"; then pass "check-archives: archives whose program names this fork pass"; else fail "check-archives: archives whose program names this fork pass"; fi +expect_refused "check-archives: an archive naming upstream fails" "$win/t3.exe in $win.zip does not name me/t3code" "$root" check-archives "$root/assets-bad" +expect_refused "check-archives: t3 names upstream, client/ names the fork -> fails" "$lin/t3 in $lin.tar.gz does not name me/t3code" "$root" check-archives "$root/assets-repro" +expect_refused "check-archives: a missing program fails" "has no $lin/t3" "$root" check-archives "$root/assets-noprog" +expect_refused "check-archives: no archive at all fails" "No CLI archive" "$root" check-archives "$root/assets-none" + +# --- check-bundle (apps/server/dist with the web client in dist/client) ------------------------ +bundle() { # bundle NAME SERVER_REPO CLIENT_REPO + mkdir -p "$root/dist-$1/client/assets" + printf 'const repo = "%s";' "$2" > "$root/dist-$1/bin.mjs" + printf 'const u = "%s";' "$3" > "$root/dist-$1/client/assets/index.js" +} +bundle good me/t3code me/t3code +bundle repro up/t3code me/t3code +mkdir -p "$root/dist-clientonly/client" && printf '"me/t3code"' > "$root/dist-clientonly/client/x.js" +if run "$root" check-bundle "$root/dist-good"; then pass "check-bundle: a server bundle naming this fork passes"; else fail "check-bundle: a server bundle naming this fork passes"; fi +expect_refused "check-bundle: server names upstream, client/ names the fork -> fails" "outside client/) does not name me/t3code" "$root" check-bundle "$root/dist-repro" +expect_refused "check-bundle: only client/ files -> fails" "no files outside client/" "$root" check-bundle "$root/dist-clientonly" +expect_refused "check-bundle: a missing bundle fails" "No server bundle" "$root" check-bundle "$root/dist-missing" + +# --- version order ----------------------------------------------------------------------------- +check_gt() { + if (cd "$root" && "$script" version-gt "$1" "$2") 2> /dev/null; then got=gt; else got=not; fi + if [[ "$got" == "$3" ]]; then pass "version-gt $1 $2 is $3"; else fail "version-gt $1 $2 is $3"; fi +} +check_gt 0.1.9-fork.10 0.1.9-fork.9 gt +check_gt v0.1.10-fork.1 v0.1.9-fork.12 gt +check_gt 0.1.9-fork.2 0.1.9-fork.2 not +check_gt 0.1.9-fork.2 0.2.0-fork.1 not +check_gt v1.0.0 v0.1.10 gt + +if (( failures )); then + echo "$failures failed" + exit 1 +fi +echo "all passed" diff --git a/.github/scripts/fork-test-shards.cjs b/.github/scripts/fork-test-shards.cjs new file mode 100644 index 0000000000000..b345949dc32c7 --- /dev/null +++ b/.github/scripts/fork-test-shards.cjs @@ -0,0 +1,85 @@ +// Fork only: prints one Test shard's work (`fork-test-shards.cjs 1/2`): `split +// ` for a large package every shard runs a vitest slice of, `whole ` +// for the rest, heaviest first (by test files) onto the lightest shard. +// TEST_PACKAGES from `changes` limits the set; empty means every package. +const childProcess = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); + +const { readWorkspace } = require("./ci-changes.cjs"); + +// Tested by their own jobs (Test Server, Test Web) or not a package to test. +const OWN_JOB = new Set(["t3", "@t3tools/web", "@t3tools/monorepo"]); +const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/; +// One vitest run of this many files outlasts the rest of a shard. +const SPLIT_AT = 100; + +function assign(packages, count) { + const split = packages.filter((pkg) => pkg.splittable && pkg.weight >= SPLIT_AT); + const share = split.reduce((total, pkg) => total + pkg.weight, 0) / count; + const shards = Array.from({ length: count }, () => ({ weight: share, whole: [], split })); + const ordered = packages + .filter((pkg) => !split.includes(pkg)) + .toSorted((a, b) => b.weight - a.weight || a.name.localeCompare(b.name)); + for (const pkg of ordered) { + const lightest = shards.reduce((best, shard) => (shard.weight < best.weight ? shard : best)); + lightest.weight += pkg.weight; + lightest.whole.push(pkg); + } + return shards; +} + +function testFiles(dir) { + return childProcess + .execFileSync("git", ["ls-files", "-z", "--", dir], { encoding: "utf8", maxBuffer: 1 << 26 }) + .split("\0") + .filter((file) => TEST_FILE.test(file)).length; +} + +function main() { + const match = (process.argv[2] ?? "").match(/^(\d+)\/(\d+)$/); + if (!match || Number(match[1]) < 1 || Number(match[1]) > Number(match[2])) + throw new Error("usage: fork-test-shards.cjs /"); + const [index, count] = [Number(match[1]), Number(match[2])]; + const only = (process.env.TEST_PACKAGES ?? "").split(/\s+/).filter(Boolean); + const root = path.resolve(__dirname, "../.."); + const packages = readWorkspace() + .filter((pkg) => pkg.hasTest && !OWN_JOB.has(pkg.name)) + .filter((pkg) => only.length === 0 || only.includes(pkg.name)) + .map((pkg) => { + const manifest = JSON.parse( + fs.readFileSync(path.join(root, pkg.dir, "package.json"), "utf8"), + ); + return { + name: pkg.name, + dir: pkg.dir, + weight: Math.max(1, testFiles(pkg.dir)), + // Run in its directory with --shard, so the script must be vitest itself. + splittable: /^vp test run(\s|$)/.test(manifest.scripts.test), + }; + }); + const unknown = only.filter((name) => !packages.some((pkg) => pkg.name === name)); + if (unknown.length) + throw new Error(`TEST_PACKAGES names no tested package: ${unknown.join(" ")}`); + + const shard = assign(packages, count)[index - 1]; + for (const pkg of shard.split) console.log(`split ${pkg.dir}`); + for (const pkg of shard.whole) console.log(`whole ${pkg.name}`); + const summary = process.env.GITHUB_STEP_SUMMARY; + if (summary) { + const list = (pkgs) => pkgs.map((pkg) => `\`${pkg.name}\` (${pkg.weight})`).join(", "); + const lines = [`### Test shard ${index}/${count}`, ""]; + if (shard.split.length) lines.push(`Slice ${index}/${count} of ${list(shard.split)}.`, ""); + if (shard.whole.length) lines.push(`Whole: ${list(shard.whole)}.`, ""); + if (!shard.split.length && !shard.whole.length) + lines.push( + `Nothing to run: the ${packages.length} affected package(s) are on other shards.`, + "", + ); + fs.appendFileSync(summary, `${lines.join("\n")}\n`); + } +} + +module.exports = { assign, SPLIT_AT }; + +if (require.main === module) main(); diff --git a/.github/scripts/fork-test-shards.test.cjs b/.github/scripts/fork-test-shards.test.cjs new file mode 100644 index 0000000000000..81310927ed4a5 --- /dev/null +++ b/.github/scripts/fork-test-shards.test.cjs @@ -0,0 +1,38 @@ +const assert = require("node:assert/strict"); +const test = require("node:test"); + +const { assign, SPLIT_AT } = require("./fork-test-shards.cjs"); + +const pkg = (name, weight, splittable = true) => ({ + name, + dir: `packages/${name}`, + weight, + splittable, +}); +const whole = (shards) => shards.map((shard) => shard.whole.map((p) => p.name)); +const split = (shards) => shards.map((shard) => shard.split.map((p) => p.name)); + +test("places the heaviest package first on the lightest shard", () => { + const packages = [pkg("small", 1), pkg("big", 10), pkg("mid", 6), pkg("mid2", 5)]; + assert.deepEqual(whole(assign(packages, 2)), [ + ["big", "small"], + ["mid", "mid2"], + ]); +}); + +test("ties break by name, so every shard computes the same split", () => { + const packages = [pkg("b", 2), pkg("a", 2), pkg("c", 2)]; + assert.deepEqual(whole(assign(packages, 2)), [["a", "c"], ["b"]]); + assert.deepEqual(whole(assign(packages.toReversed(), 2)), [["a", "c"], ["b"]]); +}); + +test("a large vitest package is sliced on every shard, the rest stay whole", () => { + const packages = [pkg("large", SPLIT_AT + 50), pkg("script", SPLIT_AT, false), pkg("a", 3)]; + const shards = assign(packages, 2); + assert.deepEqual(split(shards), [["large"], ["large"]]); + assert.deepEqual(whole(shards), [["script"], ["a"]]); +}); + +test("every package lands on exactly one shard, and spare shards stay empty", () => { + assert.deepEqual(whole(assign([pkg("only", 3)], 3)), [["only"], [], []]); +}); diff --git a/.github/scripts/fork-tests-drift.cjs b/.github/scripts/fork-tests-drift.cjs new file mode 100644 index 0000000000000..d39e73267feee --- /dev/null +++ b/.github/scripts/fork-tests-drift.cjs @@ -0,0 +1,172 @@ +// Fork only: fails when upstream's ci.yml or release.yml test jobs change and +// .github/workflows/fork-tests.yml did not follow. Compares a digest of every +// job and step with .github/fork-tests-upstream.json; comments are ignored. +// After porting a change: node .github/scripts/fork-tests-drift.cjs --record +const crypto = require("node:crypto"); +const fs = require("node:fs"); +const path = require("node:path"); + +const root = path.resolve(__dirname, "../.."); +const recordPath = path.join(root, ".github/fork-tests-upstream.json"); + +// Upstream file -> jobs the fork copies (null = every job in the file). +const TRACKED = { + ".github/workflows/ci.yml": null, + ".github/workflows/release.yml": ["quality", "test", "test_web", "test_server"], +}; + +const digest = (lines) => + crypto.createHash("sha256").update(lines.join("\n")).digest("hex").slice(0, 16); + +const indentOf = (line) => line.length - line.trimStart().length; + +function parseJobs(text) { + // Drop blank lines, full-line comments and trailing spaces. + const lines = text + .split("\n") + .map((line) => line.replace(/\s+$/, "")) + .filter((line) => line.trim() !== "" && !line.trim().startsWith("#")); + const start = lines.findIndex((line) => line === "jobs:"); + if (start === -1) throw new Error("no top-level `jobs:` key"); + + const jobs = {}; + let job = null; + let inSteps = false; + let stepsIndent = 0; + let step = null; + for (const line of lines.slice(start + 1)) { + if (indentOf(line) === 0) break; + const jobKey = line.match(/^ {2}([A-Za-z0-9_-]+):$/); + if (jobKey) { + job = jobs[jobKey[1]] = { header: [], steps: [] }; + inSteps = false; + step = null; + continue; + } + if (!job) continue; + if (inSteps && indentOf(line) <= stepsIndent && !line.trimStart().startsWith("- ")) { + inSteps = false; + step = null; + } + if (!inSteps && /^\s+steps:$/.test(line)) { + inSteps = true; + stepsIndent = indentOf(line); + continue; + } + if (!inSteps) { + job.header.push(line); + continue; + } + if (indentOf(line) <= stepsIndent + 2 && line.trimStart().startsWith("- ")) { + step = { lines: [] }; + job.steps.push(step); + } + step?.lines.push(line); + } + + const result = {}; + for (const [name, { header, steps }] of Object.entries(jobs)) { + const seen = new Map(); + result[name] = { + header: digest(header), + steps: steps.map((s) => { + const named = s.lines + .map((line) => line.trim().replace(/^- /, "")) + .map((line) => line.match(/^(?:name|uses):\s*(.+)$/)) + .find(Boolean); + let label = named ? named[1].replace(/^["']|["']$/g, "") : "(unnamed step)"; + // Repeated labels get a counter so each step keeps one identity. + const count = (seen.get(label) ?? 0) + 1; + seen.set(label, count); + if (count > 1) label = `${label} #${count}`; + return { name: label, digest: digest(s.lines) }; + }), + }; + } + return result; +} + +function current() { + const out = {}; + for (const [file, only] of Object.entries(TRACKED)) { + const jobs = parseJobs(fs.readFileSync(path.join(root, file), "utf8")); + if (only) { + const missing = only.filter((name) => !jobs[name]); + out[file] = Object.fromEntries(only.map((name) => [name, jobs[name] ?? null])); + if (missing.length) console.error(`${file}: tracked jobs missing: ${missing.join(", ")}`); + } else { + out[file] = jobs; + } + } + return out; +} + +function compare(recorded, now) { + const changes = []; + for (const file of new Set([...Object.keys(recorded), ...Object.keys(now)])) { + const before = recorded[file] ?? {}; + const after = now[file] ?? {}; + for (const job of new Set([...Object.keys(before), ...Object.keys(after)])) { + const a = before[job]; + const b = after[job]; + if (!a && b) { + changes.push(`${file}: job \`${job}\` added upstream`); + continue; + } + if (a && !b) { + changes.push(`${file}: job \`${job}\` removed upstream`); + continue; + } + if (a.header !== b.header) + changes.push( + `${file}: job \`${job}\`: settings changed (runs-on, if, needs, matrix, env...)`, + ); + const oldSteps = new Map(a.steps.map((s) => [s.name, s.digest])); + const newSteps = new Map(b.steps.map((s) => [s.name, s.digest])); + for (const [name, d] of newSteps) { + if (!oldSteps.has(name)) changes.push(`${file}: job \`${job}\`: step "${name}" added`); + else if (oldSteps.get(name) !== d) + changes.push(`${file}: job \`${job}\`: step "${name}" changed`); + } + for (const name of oldSteps.keys()) + if (!newSteps.has(name)) changes.push(`${file}: job \`${job}\`: step "${name}" removed`); + const oldOrder = a.steps.map((s) => s.name).filter((n) => newSteps.has(n)); + const newOrder = b.steps.map((s) => s.name).filter((n) => oldSteps.has(n)); + if (oldOrder.join("\0") !== newOrder.join("\0")) + changes.push(`${file}: job \`${job}\`: steps reordered`); + } + } + return changes; +} + +function main() { + const now = current(); + if (process.argv.includes("--record")) { + fs.writeFileSync(recordPath, `${JSON.stringify(now, null, 2)}\n`); + console.log(`Recorded ${path.relative(root, recordPath)}`); + return; + } + const recorded = JSON.parse(fs.readFileSync(recordPath, "utf8")); + const changes = compare(recorded, now); + const summary = process.env.GITHUB_STEP_SUMMARY; + if (changes.length === 0) { + const msg = "Upstream test jobs match the copy in fork-tests.yml (recorded digest)."; + console.log(msg); + if (summary) fs.appendFileSync(summary, `### Upstream drift\n\n${msg}\n`); + return; + } + const report = + "### Upstream drift\n\n" + + "Upstream's test jobs changed since `.github/workflows/fork-tests.yml` last followed them:\n\n" + + changes.map((c) => `- ${c}`).join("\n") + + "\n\nPort the change into fork-tests.yml (or decide it does not apply and say why in the PR), then run " + + "`node .github/scripts/fork-tests-drift.cjs --record` and commit `.github/fork-tests-upstream.json`.\n"; + console.error(report); + if (summary) fs.appendFileSync(summary, report); + for (const c of changes) console.log(`::error title=Upstream drift::${c}`); + process.exitCode = 1; +} + +module.exports = { parseJobs, compare }; + +if (require.main === module) main(); diff --git a/.github/scripts/fork-tests-drift.test.cjs b/.github/scripts/fork-tests-drift.test.cjs new file mode 100644 index 0000000000000..401ab9fd396c1 --- /dev/null +++ b/.github/scripts/fork-tests-drift.test.cjs @@ -0,0 +1,68 @@ +const assert = require("node:assert/strict"); +const test = require("node:test"); + +const { parseJobs, compare } = require("./fork-tests-drift.cjs"); + +const base = `name: CI +on: push +jobs: + lint: + runs-on: ubuntu-latest + steps: + # comment + - name: Checkout + uses: actions/checkout@v6 + with: + sparse-checkout: | + /* + - uses: ./.github/actions/setup + - name: Check + run: | + vp check + test: + needs: [lint] + strategy: + matrix: + shard: [1, 2] + steps: + - name: Test + run: vp test +`; + +const wrap = (text) => ({ "ci.yml": parseJobs(text) }); + +test("parses jobs and steps, ignoring comments and blank lines", () => { + const jobs = parseJobs(base); + assert.deepEqual(Object.keys(jobs), ["lint", "test"]); + assert.deepEqual( + jobs.lint.steps.map((s) => s.name), + ["Checkout", "./.github/actions/setup", "Check"], + ); + const noisy = base.replace(" - name: Check", "\n # new comment\n - name: Check"); + assert.deepEqual(compare(wrap(base), wrap(noisy)), []); +}); + +test("reports added, removed, changed and reordered steps and jobs", () => { + const changed = base + .replace("vp check", "vp check --fix") + .replace(" - uses: ./.github/actions/setup\n", "") + .replace("shard: [1, 2]", "shard: [1, 2, 3]") + .concat(" rust:\n steps:\n - name: Cargo\n run: cargo test\n"); + assert.deepEqual(compare(wrap(base), wrap(changed)), [ + 'ci.yml: job `lint`: step "Check" changed', + 'ci.yml: job `lint`: step "./.github/actions/setup" removed', + "ci.yml: job `test`: settings changed (runs-on, if, needs, matrix, env...)", + "ci.yml: job `rust` added upstream", + ]); + const reordered = base.replace( + " - uses: ./.github/actions/setup\n - name: Check\n run: |\n vp check\n", + " - name: Check\n run: |\n vp check\n - uses: ./.github/actions/setup\n", + ); + assert.deepEqual(compare(wrap(base), wrap(reordered)), ["ci.yml: job `lint`: steps reordered"]); +}); + +test("repeated step names stay distinct", () => { + const twice = base.replace(" test:", " - name: Check\n run: echo again\n test:"); + const names = parseJobs(twice).lint.steps.map((s) => s.name); + assert.deepEqual(names.slice(-2), ["Check", "Check #2"]); +}); diff --git a/.github/scripts/pr-limits.cjs b/.github/scripts/pr-limits.cjs new file mode 100644 index 0000000000000..77c09785e4104 --- /dev/null +++ b/.github/scripts/pr-limits.cjs @@ -0,0 +1,320 @@ +const fs = require("node:fs"); + +const HOUR_MS = 60 * 60 * 1000; +const OPEN_LIMIT = 3; +const CONFLICT_IDLE_MS = 7 * 24 * HOUR_MS; +const NOTICE_MS = 72 * HOUR_MS; +// A first run meets the whole backlog. These keep one run from flooding watchers or GitHub's +// limit on how fast a token may comment. +const MAX_REQUESTS_PER_RUN = 100; +const MAX_CLOSES_PER_RUN = 50; +// A last look that ends in "not today" closes nothing, so the looks need a cap of their own. +const MAX_RECHECKS_PER_RUN = 150; +const WRITE_PAUSE_MS = 1_000; +// Measured here: about two and a half minutes until every open PR has an answer. +const MERGEABLE_WAIT_MS = 150_000; +const READ_ATTEMPTS = 4; +const READ_RETRY_MS = 5_000; +// GitHub stamps a label event and the PR's updatedAt a second or two apart. +const SAME_MOMENT_MS = 15_000; + +const REBASE_LABEL = "needs-rebase"; +const CLOSING_LABEL = "triage:closing"; +const KEEP_OPEN_LABEL = "triage:keep-open"; +const UNVOUCHED_LABEL = "vouch:unvouched"; +const WRITE_PERMISSIONS = new Set(["admin", "maintain", "write"]); +const EXEMPTIONS_PATH = ".github/TRIAGE_EXEMPTIONS.td"; +const VOUCHED_PATH = ".github/VOUCHED.td"; +const LOGIN_PATTERN = /^github:([A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38})$/; + +// `labels` matches a PR that carries any one of them. +const SWEEP_QUERY = ` + query ($owner: String!, $repo: String!, $labels: [String!], $cursor: String) { + repository(owner: $owner, name: $repo) { + pullRequests(states: OPEN, labels: $labels, first: 50, after: $cursor) { + pageInfo { hasNextPage endCursor } + nodes { + number + mergeable + baseRefName + updatedAt + author { login } + labels(first: 100) { nodes { name } } + timelineItems(itemTypes: [LABELED_EVENT], last: 20) { + nodes { ... on LabeledEvent { createdAt label { name } } } + } + } + } + } + }`; + +const RECHECK_QUERY = ` + query ($owner: String!, $repo: String!, $number: Int!) { + repository(owner: $owner, name: $repo) { + pullRequest(number: $number) { + state + mergeable + updatedAt + labels(first: 100) { nodes { name } } + } + } + }`; + +const AUTHOR_OPEN_PRS_QUERY = ` + query ($q: String!) { + search(query: $q, type: ISSUE, first: 50) { + nodes { ... on PullRequest { number } } + } + }`; + +const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); + +// GitHub answers a heavy list request with a 502 now and then, and one of those must not end the +// run. Only reads go through here: repeating a read is safe, repeating a comment is not. +async function read(github, query, variables) { + for (let attempt = 1; ; attempt += 1) { + try { + return await github.graphql(query, variables); + } catch (error) { + const transient = typeof error.status === "number" && error.status >= 500; + if (attempt === READ_ATTEMPTS || !transient) throw error; + await pause(attempt * READ_RETRY_MS); + } + } +} + +// Fails closed: a missing, empty, or malformed list must never read as "nobody is exempt". +function parseExemptions(text) { + const logins = new Set(); + for (const raw of text.split("\n")) { + const line = raw.trim(); + if (line === "" || line.startsWith("#")) continue; + const match = LOGIN_PATTERN.exec(line); + if (!match) throw new Error(`${EXEMPTIONS_PATH}: malformed entry "${line}"`); + const login = match[1].toLowerCase(); + if (logins.has(login)) throw new Error(`${EXEMPTIONS_PATH}: duplicate entry "${line}"`); + logins.add(login); + } + if (logins.size === 0) throw new Error(`${EXEMPTIONS_PATH}: no entries`); + return logins; +} + +// VOUCHED.td: one `github:login` per line, `#` comments, and `-github:login reason` to denounce. +function vouchedLogins(text) { + const logins = new Set(); + for (const raw of text.split("\n")) { + const entry = raw.trim().split(/\s+/)[0]; + if (entry.startsWith("github:")) logins.add(entry.slice("github:".length).toLowerCase()); + } + if (logins.size === 0) throw new Error(`${VOUCHED_PATH}: no entries`); + return logins; +} + +function labeledAt(pr, name) { + const last = pr.timelineItems.nodes.filter((event) => event.label?.name === name).at(-1); + return last ? Date.parse(last.createdAt) : undefined; +} + +// The whole policy for the two windows. Activity is anything that moves the PR's updatedAt: a +// push, a comment, a review, a label. Nobody can set that time, so nothing here trusts the author. +function decide(pr, exemptions, now) { + const labels = new Set(pr.labels.nodes.map((label) => label.name)); + if (labels.has(KEEP_OPEN_LABEL)) return "skip"; + const updatedAt = Date.parse(pr.updatedAt); + + if (labels.has(CLOSING_LABEL)) { + const since = labeledAt(pr, CLOSING_LABEL); + if (since === undefined) return "unknown-notice"; + // Any activity after the notice sends the PR back to triage. + if (updatedAt - since > SAME_MOMENT_MS) return "clear-notice"; + return now - since >= NOTICE_MS ? "close-notice" : "skip"; + } + + const exempt = exemptions.has((pr.author?.login ?? "").toLowerCase()); + const subject = labels.has(UNVOUCHED_LABEL) && !exempt; + if (labels.has(REBASE_LABEL)) { + if (!subject || pr.mergeable === "MERGEABLE") return "clear-rebase"; + // Activity restarts the seven days and keeps the label, so a PR is asked to rebase once. + const idle = now - updatedAt >= CONFLICT_IDLE_MS; + return idle && pr.mergeable === "CONFLICTING" ? "close-conflict" : "skip"; + } + return subject && pr.mergeable === "CONFLICTING" ? "request-rebase" : "skip"; +} + +function guideLink(context, anchor) { + return `https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md#${anchor}`; +} + +async function removeLabel(github, context, number, name) { + try { + await github.rest.issues.removeLabel({ ...context.repo, issue_number: number, name }); + } catch (error) { + if (error.status !== 404) throw error; + } +} + +async function closeWithComment(github, context, number, body) { + await github.rest.issues.createComment({ ...context.repo, issue_number: number, body }); + await github.rest.pulls.update({ ...context.repo, pull_number: number, state: "closed" }); +} + +async function sweep({ github, context, core, dryRun }) { + const exemptions = parseExemptions(fs.readFileSync(EXEMPTIONS_PATH, "utf8")); + const repo = { owner: context.repo.owner, repo: context.repo.repo }; + + const list = async () => { + const prs = []; + for (let cursor = null; ;) { + const page = ( + await read(github, SWEEP_QUERY, { + ...repo, + cursor, + labels: [UNVOUCHED_LABEL, REBASE_LABEL, CLOSING_LABEL], + }) + ).repository.pullRequests; + prs.push(...page.nodes); + if (!page.pageInfo.hasNextPage) return prs; + cursor = page.pageInfo.endCursor; + } + }; + // GitHub computes mergeability lazily and forgets it whenever the base moves. Asking starts the + // computation, so ask once more. A PR that is still unknown waits for tomorrow's run. + let prs = await list(); + if (prs.some((pr) => pr.mergeable === "UNKNOWN")) { + await pause(MERGEABLE_WAIT_MS); + prs = await list(); + } + + const now = Date.now(); + // Start further down the list each day. The step is no larger than a run's cap, so a cap that + // is reached cannot leave the same PRs waiting behind the same others every day. + const start = (Math.floor(now / (24 * HOUR_MS)) * MAX_RECHECKS_PER_RUN) % (prs.length || 1); + prs = [...prs.slice(start), ...prs.slice(0, start)]; + const count = {}; + let rechecks = 0; + for (const pr of prs) { + const { number } = pr; + let action = decide(pr, exemptions, now); + if (action === "skip") continue; + if (action === "unknown-notice") { + core.warning(`#${number}: cannot tell when ${CLOSING_LABEL} was applied, leaving it open.`); + continue; + } + if (action === "request-rebase" && (count[action] ?? 0) >= MAX_REQUESTS_PER_RUN) continue; + if (action.startsWith("close")) { + if ((count["close-conflict"] ?? 0) + (count["close-notice"] ?? 0) >= MAX_CLOSES_PER_RUN) { + continue; + } + if (rechecks >= MAX_RECHECKS_PER_RUN) continue; + rechecks += 1; + // The list is minutes old by now. Closing is the one step worth a second look. + const fresh = (await read(github, RECHECK_QUERY, { ...repo, number })).repository.pullRequest; + if (fresh.state !== "OPEN") continue; + // A merge to the base can resolve a conflict without touching the PR, so this is re-read + // too. An answer that is not ready yet reads as "not conflicting" and waits for tomorrow. + action = decide({ ...pr, ...fresh }, exemptions, now); + if (!action.startsWith("close")) continue; + } + + count[action] = (count[action] ?? 0) + 1; + core.info(`#${number} ${action}${dryRun ? " (dry run)" : ""}`); + if (dryRun) continue; + + if (action === "request-rebase") { + // The request goes first: a label without it would start a clock nobody was told about. + await github.rest.issues.createComment({ + ...context.repo, + issue_number: number, + body: [ + `This PR conflicts with \`${pr.baseRefName}\`. Rebase it or merge \`${pr.baseRefName}\` into it. If it still conflicts after 7 days with no activity, it will be closed automatically.`, + "", + `See the [conflict window](${guideLink(context, "conflict-window")}).`, + ].join("\n"), + }); + await github.rest.issues.addLabels({ + ...context.repo, + issue_number: number, + labels: [REBASE_LABEL], + }); + } else if (action === "clear-rebase") { + await removeLabel(github, context, number, REBASE_LABEL); + } else if (action === "clear-notice") { + await removeLabel(github, context, number, CLOSING_LABEL); + } else { + const conflict = action === "close-conflict"; + await closeWithComment( + github, + context, + number, + conflict + ? [ + `Closing: this PR still conflicts with \`${pr.baseRefName}\` and has had no activity for 7 days since the rebase request.`, + "", + `To continue, rebase the branch and open a new PR that links this one. See the [conflict window](${guideLink(context, "conflict-window")}).`, + ].join("\n") + : [ + "Closing: 72 hours have passed since the triage notice above with no activity on this PR.", + "", + `To ask for reconsideration, address the notice and comment here, or open a focused replacement PR that links this one. See [closure and reconsideration](${guideLink(context, "closure-and-reconsideration")}).`, + ].join("\n"), + ); + // Without this a maintainer's reopen would be closed again by the next run. + await removeLabel(github, context, number, conflict ? REBASE_LABEL : CLOSING_LABEL); + } + await pause(WRITE_PAUSE_MS); + } + + const summary = Object.entries(count).map(([action, n]) => `${n} ${action}`); + core.info( + `${dryRun ? "Dry run. " : ""}${prs.length} PRs read: ${summary.join(", ") || "nothing to do"}.`, + ); + return count; +} + +async function enforceOpenLimit({ github, context, core, dryRun }) { + const pr = context.payload.pull_request; + const author = pr.user.login; + // Who is trusted is decided here rather than by the vouch action, which reports its own failed + // lookups as "not vouched". Every read below throws on failure, and a throw closes nothing. + if (pr.user.type === "Bot") return; + if (parseExemptions(fs.readFileSync(EXEMPTIONS_PATH, "utf8")).has(author.toLowerCase())) return; + if (vouchedLogins(fs.readFileSync(VOUCHED_PATH, "utf8")).has(author.toLowerCase())) return; + const { data: access } = await github.rest.repos.getCollaboratorPermissionLevel({ + ...context.repo, + username: author, + }); + if (WRITE_PERMISSIONS.has(access.permission)) return; + if (pr.labels.some((label) => label.name === KEEP_OPEN_LABEL)) return; + // Someone else reopening a PR is a maintainer overriding the limit. + const reopened = context.payload.action === "reopened"; + if (reopened && context.payload.sender.login.toLowerCase() !== author.toLowerCase()) return; + + const q = `repo:${context.repo.owner}/${context.repo.repo} is:pr is:open author:${author} sort:created-asc`; + const { search } = await read(github, AUTHOR_OPEN_PRS_QUERY, { q }); + // A new PR counts only the older ones, so two opened together cannot close each other. + const others = search.nodes.filter( + (node) => node.number && (reopened ? node.number !== pr.number : node.number < pr.number), + ).length; + if (others < OPEN_LIMIT) { + core.info(`PR #${pr.number}: ${author} has ${others} other open PRs.`); + return; + } + if (dryRun) { + core.notice(`Dry run. PR #${pr.number} would close: ${author} has ${others} other open PRs.`); + return; + } + + await closeWithComment( + github, + context, + pr.number, + [ + `Closing: ${author} already has ${OPEN_LIMIT} or more open PRs here, which is the limit for contributors who are not vouched.`, + "", + `Once one of them is merged or closed, open this again. See the [open PR limit](${guideLink(context, "open-pr-limit")}).`, + ].join("\n"), + ); + core.info(`PR #${pr.number}: closed, ${author} has ${others} other open PRs.`); +} + +module.exports = { decide, enforceOpenLimit, parseExemptions, sweep }; diff --git a/.github/scripts/test-delta.cjs b/.github/scripts/test-delta.cjs new file mode 100644 index 0000000000000..c9789f644d272 --- /dev/null +++ b/.github/scripts/test-delta.cjs @@ -0,0 +1,78 @@ +// Counts the test cases a pull request adds and removes, from a zero-context diff, so PR Size can +// say when a change grows the suite. Counting declarations keeps the number deterministic, unlike +// CI timings, which move with runner load. +const MARKER = ""; +const NET_CASES_TO_REPORT = 20; +const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/; +// `<` admits type arguments, as in `it.each(...)`, which may span lines. +const TEST_CASE = /^\s*(?:it|test)(?:\.\w+)*\s*[(<]/; +const isBrowserTest = (path) => path.includes(".browser.test."); + +function kindOf(path) { + if (isBrowserTest(path)) return "browser"; + if (path.startsWith("apps/server/") || path.includes(".integration.")) return "server"; + return "unit"; +} + +/** @param {string} diff output of `git diff -U0 base...head` */ +function countTestDelta(diff) { + const kinds = { browser: 0, server: 0, unit: 0 }; + const newBrowserFiles = []; + let path = null; + // A browser test file is new when it is added, or renamed from a file that was not one. + let file = null; + const flush = () => { + if (file?.isNew && isBrowserTest(file.target)) newBrowserFiles.push(file.target); + }; + for (const line of diff.split("\n")) { + if (line.startsWith("diff --git ")) { + flush(); + path = null; + file = { target: line.replace(/^diff --git a\/\S+ b\//, ""), isNew: false }; + continue; + } + if (line.startsWith("new file mode") && file) file.isNew = true; + if (line.startsWith("rename from ") && file) file.isNew = !isBrowserTest(line.slice(12)); + if (line.startsWith("--- ")) { + const source = line.slice(4).replace(/^a\//, ""); + path = TEST_FILE.test(source) ? source : null; + continue; + } + if (line.startsWith("+++ ")) { + const target = line.slice(4).replace(/^b\//, ""); + // A deleted file's target is /dev/null; keep its old path to count the removed cases. + if (target !== "/dev/null") path = TEST_FILE.test(target) ? target : null; + continue; + } + if (line.startsWith("new file mode") || !path) continue; + const sign = line[0] === "+" ? 1 : line[0] === "-" ? -1 : 0; + if (sign !== 0 && TEST_CASE.test(line.slice(1))) kinds[kindOf(path)] += sign; + } + flush(); + return { kinds, net: kinds.browser + kinds.server + kinds.unit, newBrowserFiles }; +} + +/** Returns the comment body, or null when the change does not grow the suite enough to mention. */ +function render(delta) { + if (delta.net < NET_CASES_TO_REPORT && delta.newBrowserFiles.length === 0) return null; + const signed = (n) => (n > 0 ? `+${n}` : String(n)); + const lines = [ + MARKER, + `This PR changes the test suite by **${signed(delta.net)} test cases** ` + + `(browser ${signed(delta.kinds.browser)}, unit ${signed(delta.kinds.unit)}, server ${signed(delta.kinds.server)}).`, + ]; + if (delta.newBrowserFiles.length > 0) { + lines.push( + "", + `New browser test files: ${delta.newBrowserFiles.map((file) => `\`${file}\``).join(", ")}.`, + "Each browser test file costs CI seconds of module loading before its first test runs; a unit test costs milliseconds.", + ); + } + lines.push( + "", + "Keep tests that would fail for a real reason, and test logic below the UI where it can be. See [Testing](https://github.com/pingdotgg/t3code/blob/main/docs/internals/testing.md).", + ); + return lines.join("\n"); +} + +module.exports = { MARKER, countTestDelta, render }; diff --git a/.github/scripts/test-delta.test.cjs b/.github/scripts/test-delta.test.cjs new file mode 100644 index 0000000000000..82a3e00862d2f --- /dev/null +++ b/.github/scripts/test-delta.test.cjs @@ -0,0 +1,59 @@ +const assert = require("node:assert/strict"); +const test = require("node:test"); + +const { countTestDelta, render } = require("./test-delta.cjs"); + +const diff = `diff --git a/apps/web/src/Panel.browser.test.tsx b/apps/web/src/Panel.browser.test.tsx +new file mode 100644 +--- /dev/null ++++ b/apps/web/src/Panel.browser.test.tsx +@@ -0,0 +1,4 @@ ++it("opens", async () => {}); ++ it.each<{ n: number }>([{ n: 1 }])("renders $n", async () => {}); ++// it("is a comment, still counted only when it starts the line") +diff --git a/apps/server/src/thing.test.ts b/apps/server/src/thing.test.ts +--- a/apps/server/src/thing.test.ts ++++ b/apps/server/src/thing.test.ts +@@ -3,2 +3,1 @@ +-it.effect("old", () => {}); +-test("older", () => {}); ++ it.effect("new", () => {}); +diff --git a/packages/shared/src/gone.test.ts b/packages/shared/src/gone.test.ts +deleted file mode 100644 +--- a/packages/shared/src/gone.test.ts ++++ /dev/null +@@ -1,1 +0,0 @@ +-it("goes", () => {}); +diff --git a/apps/web/src/Menu.test.tsx b/apps/web/src/Menu.browser.test.tsx +similarity index 100% +rename from apps/web/src/Menu.test.tsx +rename to apps/web/src/Menu.browser.test.tsx +diff --git a/apps/web/src/Old.browser.test.tsx b/apps/web/src/New.browser.test.tsx +similarity index 100% +rename from apps/web/src/Old.browser.test.tsx +rename to apps/web/src/New.browser.test.tsx +diff --git a/apps/web/src/Panel.tsx b/apps/web/src/Panel.tsx +--- a/apps/web/src/Panel.tsx ++++ b/apps/web/src/Panel.tsx +@@ -1 +1 @@ ++it("is not a test file", () => {}); +`; + +test("counts cases by kind, including deleted files, and finds new or renamed browser files", () => { + assert.deepEqual(countTestDelta(diff), { + kinds: { browser: 2, server: -1, unit: -1 }, + net: 0, + newBrowserFiles: ["apps/web/src/Panel.browser.test.tsx", "apps/web/src/Menu.browser.test.tsx"], + }); +}); + +test("reports only growth worth a reviewer's attention", () => { + const quiet = { kinds: { browser: 0, server: 3, unit: 5 }, net: 8, newBrowserFiles: [] }; + assert.equal(render(quiet), null); + const growth = { kinds: { browser: 4, server: 10, unit: 12 }, net: 26, newBrowserFiles: [] }; + assert.match(render(growth), /\*\*\+26 test cases\*\* \(browser \+4, unit \+12, server \+10\)/); + assert.match( + render(countTestDelta(diff)), + /New browser test files: `apps\/web\/src\/Panel\.browser\.test\.tsx`/, + ); +}); diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5343dbb754ff8..6f75c92562d03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -326,7 +326,7 @@ jobs: run: python3 -B .github/scripts/stage-preview-bundle.test.py - name: Test release checks - run: node --test .github/scripts/check-nightly-release.test.cjs .github/scripts/vercel-deployment-output.test.cjs .github/scripts/mobile-preview-comment.test.cjs + run: node --test .github/scripts/check-nightly-release.test.cjs .github/scripts/vercel-deployment-output.test.cjs .github/scripts/mobile-preview-comment.test.cjs .github/scripts/test-delta.test.cjs - name: Finish installing browser secret helper build libraries timeout-minutes: 5 @@ -355,16 +355,22 @@ jobs: # The web suite is the largest outside the server. In the shared Test job it # started last and ran alone for about 40s after everything else finished. - # release.yml mirrors this test, test_web, and test_server split. + # Browser tests are bound by the Vite server transforming modules for each + # file, not by Chromium, so a second runner (and Vite server) halves the job + # that gated every run. release.yml mirrors this test, test_web, and test_server split. test_web: permissions: contents: read id-token: write - name: Test Web + name: Test Web ${{ matrix.shard }} needs: changes if: ${{ !cancelled() && needs.changes.outputs.test_web != 'false' }} runs-on: blacksmith-8vcpu-ubuntu-2404 timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + shard: [1, 2] steps: - name: Checkout uses: actions/checkout@v6 @@ -406,7 +412,7 @@ jobs: fi - name: Test - run: vp run --filter @t3tools/web test + run: vp run --filter @t3tools/web test --shard ${{ matrix.shard }}/${{ strategy.job-total }} # apps/server sets `fileParallelism: false`, so its test files run strictly # one at a time. Sharding spreads them over separate runners instead of @@ -481,6 +487,17 @@ jobs: node apps/server/node_modules/playwright-core/cli.js install-deps chromium fi + # Each server test file runs in its own Vitest process, and a fresh install starts + # Vitest's content-keyed module cache empty, so every file re-transformed its imports. + # Only pushes to main save it, so pull requests never evict each other's entries. + - name: Restore Vitest module cache + if: steps.changes.outputs.test_server != 'false' + uses: actions/cache/restore@v6 + with: + path: node_modules/.vitest-cache + key: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }} + restore-keys: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}- + - name: Test if: steps.changes.outputs.test_server != 'false' env: @@ -489,15 +506,14 @@ jobs: run: >- vp run test:cached -- --shard ${{ matrix.shard }}/${{ strategy.job-total }} --uncached apps/server/integration/transferBudgetV2.integration.test.ts - --verify-hits 1 --report "${{ runner.temp }}/test-cache-${{ matrix.shard }}.json" apps/server + --verify-hits 1 apps/server - - name: Upload test cache measurements - if: always() && steps.changes.outputs.test_server != 'false' - uses: actions/upload-artifact@v7 + - name: Save Vitest module cache + if: github.event_name == 'push' && steps.changes.outputs.test_server != 'false' + uses: actions/cache/save@v6 with: - name: test-cache-${{ matrix.shard }} - path: ${{ runner.temp }}/test-cache-${{ matrix.shard }}.json - if-no-files-found: error + path: node_modules/.vitest-cache + key: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }} # integration/transferBudgetV2.integration.test.ts writes the report; exactly one shard # produces these files. Gating the upload on their presence keeps a diff --git a/.github/workflows/fork-release.yml b/.github/workflows/fork-release.yml new file mode 100644 index 0000000000000..fb7e08d5ae4d1 --- /dev/null +++ b/.github/workflows/fork-release.yml @@ -0,0 +1,530 @@ +name: Fork release + +# Builds this fork's release `v-fork.`: upstream's tests, the Linux x64 server archive +# with SHA256SUMS, and the desktop apps (Linux x64, Windows x64, macOS arm64 and x64), all on +# GitHub-hosted runners and unsigned unless signing secrets exist. is the newest stable +# upstream tag the commit contains; counts the fork's earlier builds of it. +# +# Builds name this repository as their release repository (scripts/lib/release-repository.ts reads +# T3CODE_DESKTOP_UPDATE_REPOSITORY, else GITHUB_REPOSITORY in Actions), so the server's update and +# the desktop app's updater look only at this fork. Publishing makes a normal (not pre-) release, a +# draft until every file is uploaded, and only above every published release: the server's updater +# takes the newest-created release, so an older one published later would read as a downgrade. +# +# The guards live in .github/scripts/fork-release.sh (tests: fork-release.test.sh and +# fork-release-workflow.test.py, both run in preflight): only released upstream code, never a +# version that is already published or below a published one, no silent API failures. Actions are +# pinned by commit. Only the publish job holds a write token; it runs no package code, and its guard +# script comes from this workflow's own commit, not from the commit being built. +on: + workflow_dispatch: + inputs: + ref: + description: Commit or branch to build + required: false + default: main + type: string + publish: + description: Publish the release (off builds and keeps the files on the run only) + required: false + default: false + type: boolean + workflow_call: + inputs: + ref: + required: true + type: string + publish: + required: false + default: false + type: boolean + # Only the signing secrets release-desktop.yml declares; a caller passes these, never others. + secrets: + CSC_LINK: + required: false + CSC_KEY_PASSWORD: + required: false + APPLE_API_KEY: + required: false + APPLE_API_KEY_ID: + required: false + APPLE_API_ISSUER: + required: false + MACOS_PROVISIONING_PROFILE: + required: false + AZURE_TENANT_ID: + required: false + AZURE_CLIENT_ID: + required: false + AZURE_CLIENT_SECRET: + required: false + AZURE_TRUSTED_SIGNING_ENDPOINT: + required: false + AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: + required: false + AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: + required: false + AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: + required: false + outputs: + version: + value: ${{ jobs.preflight.outputs.version }} + tag: + value: ${{ jobs.preflight.outputs.tag }} + published: + value: ${{ jobs.publish.outputs.published == 'true' }} + +concurrency: + group: fork-release + cancel-in-progress: false + +permissions: + # The Windows desktop job reads this run's artifact list to wait for the Linux CLI archive. + actions: read + contents: read + +jobs: + preflight: + name: Preflight + runs-on: ubuntu-latest + timeout-minutes: 10 + outputs: + ref: ${{ steps.meta.outputs.ref }} + version: ${{ steps.meta.outputs.version }} + tag: ${{ steps.meta.outputs.tag }} + base_tag: ${{ steps.meta.outputs.base_tag }} + upstream: ${{ steps.meta.outputs.upstream }} + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + ref: ${{ inputs.ref }} + fetch-depth: 0 + filter: blob:none + persist-credentials: false + + - name: Test the release guards + shell: bash + run: bash .github/scripts/fork-release.test.sh + + - name: Test the workflow's shape + shell: bash + run: | + set -euo pipefail + python3 -c 'import yaml' 2> /dev/null || { sudo apt-get update && sudo apt-get install -y python3-yaml; } + python3 .github/scripts/fork-release-workflow.test.py + + # Refuses unreleased upstream commits, a stray upstream tag and a base above upstream's latest. + - id: meta + name: Resolve fork release version + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: bash .github/scripts/fork-release.sh resolve + + tests: + name: Tests + needs: [preflight] + uses: ./.github/workflows/fork-tests.yml + with: + ref: ${{ needs.preflight.outputs.ref }} + + build_bundle: + name: Build JS bundle + needs: [preflight] + runs-on: ubuntu-latest + timeout-minutes: 90 + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + ref: ${{ needs.preflight.outputs.ref }} + persist-credentials: false + sparse-checkout: | + /* + !/.repos/ + sparse-checkout-cone-mode: false + + - name: Setup dependencies + uses: ./.github/actions/setup-ci-deps + with: + install-args: --filter=t3... --filter=@t3tools/web... --filter=@t3tools/desktop... --filter=@t3tools/scripts... + + - name: Align package versions to release version + shell: bash + env: + VERSION: ${{ needs.preflight.outputs.version }} + run: node scripts/update-release-package-versions.ts "$VERSION" + + - name: Check bundle-only build support + id: bundle_build + shell: bash + run: | + set -euo pipefail + script="$(node -p "require('./package.json').scripts['build:desktop:bundle'] ? 'build:desktop:bundle' : 'build:desktop'")" + echo "script=$script" >> "$GITHUB_OUTPUT" + + - name: Install browser secret helper build libraries + if: steps.bundle_build.outputs.script == 'build:desktop' + shell: bash + run: sudo apt-get update && sudo apt-get install -y libsecret-1-dev pkg-config + + - name: Build JS bundle + shell: bash + env: + T3CODE_TELEMETRY_CHANNEL: dev + T3CODE_DESKTOP_UPDATE_REPOSITORY: ${{ github.repository }} + run: vp run ${{ steps.bundle_build.outputs.script }} + + # A build that still names upstream would update a fork install to upstream's releases. This + # is the server bundle without dist/client (the web client names this repository on every + # Actions build); the assemble job checks the `t3` program in each CLI archive. + - name: Check the server bundle names this repository + shell: bash + run: bash .github/scripts/fork-release.sh check-bundle apps/server/dist + + - name: Upload JS bundle + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: js-bundle + path: | + apps/server/dist + apps/desktop/dist-electron + if-no-files-found: error + retention-days: 3 + + desktop_linux_x64: + name: Desktop Linux x64 + needs: [preflight, build_bundle] + uses: ./.github/workflows/release-desktop.yml + secrets: + CSC_LINK: ${{ secrets.CSC_LINK }} + CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} + APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }} + APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }} + APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }} + MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} + AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }} + AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }} + AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }} + AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }} + with: + version: ${{ needs.preflight.outputs.version }} + ref: ${{ needs.preflight.outputs.ref }} + release_channel: stable + relay_client_tracing: false + clerk_publishable_key: "" + clerk_jwt_template: "" + clerk_cli_oauth_client_id: "" + relay_url: "" + label: Linux x64 + runner: ubuntu-latest + platform: linux + target: AppImage + arch: x64 + rust_target: x86_64-unknown-linux-gnu + resource_key: linux-x64 + cli_archive: true + launch_check: true + + desktop_win_x64: + name: Desktop Windows x64 + needs: [preflight, build_bundle] + uses: ./.github/workflows/release-desktop.yml + secrets: + CSC_LINK: ${{ secrets.CSC_LINK }} + CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} + APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }} + APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }} + APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }} + MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} + AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }} + AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }} + AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }} + AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }} + with: + version: ${{ needs.preflight.outputs.version }} + ref: ${{ needs.preflight.outputs.ref }} + release_channel: stable + relay_client_tracing: false + clerk_publishable_key: "" + clerk_jwt_template: "" + clerk_cli_oauth_client_id: "" + relay_url: "" + label: Windows x64 + runner: ubuntu-latest + verify_runner: windows-2025 + platform: win + target: nsis + arch: x64 + rust_target: x86_64-pc-windows-msvc + resource_key: win32-x64 + cli_archive: true + launch_check: false + + desktop_mac_arm64: + name: Desktop macOS arm64 + needs: [preflight, build_bundle] + uses: ./.github/workflows/release-desktop.yml + secrets: + CSC_LINK: ${{ secrets.CSC_LINK }} + CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} + APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }} + APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }} + APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }} + MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} + AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }} + AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }} + AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }} + AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }} + with: + version: ${{ needs.preflight.outputs.version }} + ref: ${{ needs.preflight.outputs.ref }} + release_channel: stable + relay_client_tracing: false + clerk_publishable_key: "" + clerk_jwt_template: "" + clerk_cli_oauth_client_id: "" + relay_url: "" + label: macOS arm64 + runner: ${{ vars.FORK_MACOS_RUNNER || 'macos-26' }} + platform: mac + target: dmg + arch: arm64 + rust_target: aarch64-apple-darwin + resource_key: darwin-arm64 + cli_archive: false + launch_check: true + + desktop_mac_x64: + name: Desktop macOS x64 + needs: [preflight, build_bundle] + uses: ./.github/workflows/release-desktop.yml + secrets: + CSC_LINK: ${{ secrets.CSC_LINK }} + CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} + APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }} + APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }} + APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }} + MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} + AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }} + AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }} + AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }} + AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }} + with: + version: ${{ needs.preflight.outputs.version }} + ref: ${{ needs.preflight.outputs.ref }} + release_channel: stable + relay_client_tracing: false + clerk_publishable_key: "" + clerk_jwt_template: "" + clerk_cli_oauth_client_id: "" + relay_url: "" + label: macOS x64 + runner: ${{ vars.FORK_MACOS_RUNNER || 'macos-26' }} + platform: mac + target: dmg + arch: x64 + rust_target: x86_64-apple-darwin + resource_key: darwin-x64 + cli_archive: false + launch_check: false + + # Collects and checks every release file with a read-only token; package code runs here only. + assemble: + name: Assemble release files + needs: + [preflight, tests, desktop_linux_x64, desktop_win_x64, desktop_mac_arm64, desktop_mac_x64] + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + ref: ${{ needs.preflight.outputs.ref }} + fetch-depth: 0 + filter: blob:none + persist-credentials: false + + - name: Setup dependencies + uses: ./.github/actions/setup-ci-deps + with: + install-args: --filter=@t3tools/scripts... + + - name: Download desktop builds + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: desktop-* + merge-multiple: true + path: release-assets + + - name: Download CLI archives + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: cli-* + merge-multiple: true + path: release-assets + + - name: Write CLI archive checksums + shell: bash + env: + VERSION: ${{ needs.preflight.outputs.version }} + run: | + set -euo pipefail + cd release-assets + shopt -s nullglob + archives=(t3-*.tar.gz t3-*.zip) + if [[ ! -f "t3-$VERSION-linux-x64.tar.gz" ]]; then + echo "::error::The Linux x64 server archive is missing." >&2 + exit 1 + fi + sha256sum "${archives[@]}" > SHA256SUMS + cat SHA256SUMS + + # The `t3` executable in each archive bundles the server again (release-desktop.yml build-exe). + - name: Check the CLI archives name this repository + shell: bash + run: bash .github/scripts/fork-release.sh check-archives release-assets + + - name: Merge macOS updater manifests + shell: bash + run: | + set -euo pipefail + shopt -s nullglob + for x64_manifest in release-assets/*-mac-x64.yml; do + arm64_manifest="${x64_manifest%-x64.yml}.yml" + if [[ -f "$arm64_manifest" ]]; then + node scripts/merge-update-manifests.ts --platform mac "$arm64_manifest" "$x64_manifest" + rm -f "$x64_manifest" + fi + done + + - name: Name the Windows updater manifest + shell: bash + run: | + set -euo pipefail + shopt -s nullglob + for x64_manifest in release-assets/*-win-x64.yml; do + mv "$x64_manifest" "${x64_manifest%-win-x64.yml}.yml" + done + + # The desktop app on each platform reads one of these from the latest release. + - name: Check updater manifests + shell: bash + run: | + set -euo pipefail + for manifest in latest.yml latest-mac.yml latest-linux.yml; do + if [[ ! -f "release-assets/$manifest" ]]; then + echo "::error::release-assets/$manifest is missing, so that platform's desktop app would find no update." + exit 1 + fi + done + + - name: Write release notes + shell: bash + env: + UPSTREAM: ${{ needs.preflight.outputs.upstream }} + BASE_TAG: ${{ needs.preflight.outputs.base_tag }} + REF: ${{ needs.preflight.outputs.ref }} + run: | + set -euo pipefail + git fetch --no-tags "https://github.com/$UPSTREAM.git" "refs/tags/$BASE_TAG:refs/upstream/$BASE_TAG" + { + echo "Upstream [$BASE_TAG](https://github.com/$UPSTREAM/releases/tag/$BASE_TAG) with this fork's changes on top:" + echo + git log --reverse --format='- %s (%h)' "refs/upstream/$BASE_TAG..$REF" + } > release-assets/release-notes.md + cat release-assets/release-notes.md >> "$GITHUB_STEP_SUMMARY" + + - name: Upload release files + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: release-files + path: release-assets + if-no-files-found: error + retention-days: 7 + + # The only job with a write token: it checks out just the guard script, from this workflow's own + # commit (a caller's commit for workflow_call), and runs no package code. + publish: + name: Publish release + needs: [preflight, assemble] + if: ${{ inputs.publish }} + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: write + outputs: + published: ${{ steps.publish.outputs.published }} + steps: + - name: Checkout the guard script + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + ref: ${{ github.workflow_sha }} + persist-credentials: false + sparse-checkout: .github/scripts + sparse-checkout-cone-mode: true + + - name: Download release files + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: release-files + path: release-assets + + - name: Move the release notes aside + shell: bash + run: mv release-assets/release-notes.md release-notes.md + + # "Re-run failed jobs" reuses the preflight's version: refuse it once a tag or published + # release has it. Drafts have no tag; one left by a stopped run of this version is removed. + - name: Refuse a published version, remove leftover drafts + shell: bash + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ needs.preflight.outputs.tag }} + run: bash .github/scripts/fork-release.sh remove-drafts "$TAG" + + - name: Create the release as a draft + id: draft + uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3.0.4 + with: + tag_name: ${{ needs.preflight.outputs.tag }} + target_commitish: ${{ needs.preflight.outputs.ref }} + name: T3 Code ${{ needs.preflight.outputs.tag }} + body_path: release-notes.md + draft: true + prerelease: false + fail_on_unmatched_files: true + files: | + release-assets/*.dmg + release-assets/*.zip + release-assets/*.AppImage + release-assets/*.exe + release-assets/*.blockmap + release-assets/*.yml + release-assets/*.tar.gz + release-assets/SHA256SUMS + + # Updaters skip drafts, so nobody sees a release until every file above is uploaded. The tag + # and "nothing published is as high" checks run again right before; it is then made latest. + - name: Publish the draft + id: publish + shell: bash + env: + GH_TOKEN: ${{ github.token }} + RELEASE_ID: ${{ steps.draft.outputs.id }} + TAG: ${{ needs.preflight.outputs.tag }} + VERSION: ${{ needs.preflight.outputs.version }} + run: bash .github/scripts/fork-release.sh publish "$RELEASE_ID" "$TAG" "$VERSION" diff --git a/.github/workflows/fork-tests.yml b/.github/workflows/fork-tests.yml new file mode 100644 index 0000000000000..1f6566c9690a1 --- /dev/null +++ b/.github/workflows/fork-tests.yml @@ -0,0 +1,924 @@ +name: Fork tests + +# Fork only. Upstream's CI checks (ci.yml) on GitHub-hosted runners, because the +# fork has none of upstream's runners and upstream's workflows are disabled here. +# Commands follow ci.yml step for step. Only the runners, time limits, apt +# setup and the task cache differ (kept with actions/cache instead of upstream's +# private remote cache), and Test and Test Web split over two runners each. +# Upstream's composite actions and change detector (.github/actions, +# .github/scripts/ci-changes.cjs) are used as they are, so a rebase brings their +# changes. The `workflows` job lints the fork workflows (actionlint) and fails +# when upstream's ci.yml or release.yml test jobs change and this copy did not +# follow (.github/scripts/fork-tests-drift.cjs). +# +# Require only `fork-ci-result` in a ruleset: it needs every other job, so jobs +# can be added, split or resharded without touching the ruleset. +# +# Runners: GitHub-hosted only, Ubuntu 24.04 like upstream's runners, so an OS +# upgrade is a reviewed change here, not a surprise from ubuntu-latest. Never +# add a self-hosted runner to this workflow: this repository is public, so a +# pull request from any fork would run its code on that machine. +# +# Two modes: +# - pull_request / push to main: CI. Jobs a change cannot affect are skipped by +# upstream's detector; every skip is named with its reason in the run summary. +# - workflow_call / workflow_dispatch with `ref`: release. Every Linux job runs +# on that commit, no path filter. Covers release.yml's quality, test, test_web +# and test_server (ci.yml checks a superset of them). +on: + pull_request: + push: + branches: + - main + workflow_call: + inputs: + ref: + description: Commit to test + required: true + type: string + workflow_dispatch: + inputs: + ref: + description: Commit or branch to test + required: true + type: string + +permissions: + contents: read + +# A new push to a pull request cancels its older run. Main and release runs finish. +# The event name keeps a release's workflow_call apart from its caller's group. +concurrency: + group: fork-tests-${{ github.event_name }}-${{ github.event.pull_request.number || inputs.ref || github.sha }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + changes: + name: Changes + runs-on: ubuntu-24.04 + timeout-minutes: 5 + outputs: + typecheck: ${{ steps.release.outputs.typecheck || steps.detect.outputs.typecheck }} + build: ${{ steps.release.outputs.build || steps.detect.outputs.build }} + desktop_launch: ${{ steps.release.outputs.desktop_launch || steps.detect.outputs.desktop_launch }} + test: ${{ steps.release.outputs.test || steps.detect.outputs.test }} + test_packages: ${{ steps.release.outputs.test_packages || steps.detect.outputs.test_packages }} + test_web: ${{ steps.release.outputs.test_web || steps.detect.outputs.test_web }} + test_server: ${{ steps.release.outputs.test_server || steps.detect.outputs.test_server }} + rust: ${{ steps.release.outputs.rust || steps.detect.outputs.rust }} + release_smoke: ${{ steps.release.outputs.release_smoke || steps.detect.outputs.release_smoke }} + mobile_native: ${{ steps.release.outputs.mobile_native || steps.fork.outputs.mobile_native }} + steps: + - name: Checkout + if: inputs.ref == '' + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + fetch-depth: 2 + sparse-checkout: | + /pnpm-workspace.yaml + /.github/scripts/ci-changes.cjs + /.github/actions/ci-changes/ + /*/package.json + /*/*/package.json + !/.repos/ + sparse-checkout-cone-mode: false + + - name: Detect affected jobs + id: detect + if: inputs.ref == '' + uses: ./.github/actions/ci-changes + + # ci-changes.cjs runs the macOS lint when upstream's ci.yml changes; the + # fork's copy of it counts the same. + - name: Fork workflow changes run the macOS lint + id: fork + if: inputs.ref == '' + env: + DETECTED: ${{ steps.detect.outputs.mobile_native }} + run: | + value="$DETECTED" + if grep -qxE '\.github/workflows/fork-tests\.yml' "$RUNNER_TEMP/changed-paths" 2>/dev/null; then + value=true + fi + echo "mobile_native=$value" >> "$GITHUB_OUTPUT" + + # Release runs test the whole commit. upstream's release.yml has no macOS lint. + - name: Release run checks everything + id: release + if: inputs.ref != '' + run: | + for gate in typecheck build desktop_launch test test_web test_server rust release_smoke; do + echo "$gate=true" >> "$GITHUB_OUTPUT" + done + echo "test_packages=" >> "$GITHUB_OUTPUT" + echo "mobile_native=false" >> "$GITHUB_OUTPUT" + + # A broken fork workflow is red on its own pull request, and the fork copy + # must follow upstream's test jobs: the drift check lists every job and step + # upstream changed since the copy was last recorded. + workflows: + name: Workflow lint and upstream drift + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + sparse-checkout: | + /.github/ + sparse-checkout-cone-mode: false + + # Pinned release, verified by checksum. Upstream's own workflows use runner + # labels this fork does not have, so only the fork's workflows are linted. + - name: Lint fork workflows (actionlint) + env: + VERSION: 1.7.12 + SHA256: 8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8 + run: | + archive="actionlint_${VERSION}_linux_amd64.tar.gz" + curl -fsSL --retry 3 -o "$RUNNER_TEMP/$archive" \ + "https://github.com/rhysd/actionlint/releases/download/v${VERSION}/${archive}" + echo "$SHA256 $RUNNER_TEMP/$archive" | sha256sum -c - + tar -xzf "$RUNNER_TEMP/$archive" -C "$RUNNER_TEMP" actionlint + "$RUNNER_TEMP/actionlint" -color .github/workflows/fork-*.yml + + # Every fork script test, checked against .github/fork-ci-tests.txt: an + # unlisted test or a listed one deleted from history fails, a listed one + # whose pull request has not merged yet is a note in the summary. + - name: Fork script tests + run: | + if compgen -G '.github/scripts/fork-*.test.py' >/dev/null && ! python3 -c 'import yaml' 2>/dev/null; then + sudo apt-get update -qq && sudo apt-get install -y -qq python3-yaml + fi + node .github/scripts/fork-ci-tests.cjs + + - name: Compare upstream's test jobs with the recorded copy + run: node .github/scripts/fork-tests-drift.cjs + + # Every commit a pull request or a push to main adds, history included: a + # secret committed and then deleted is still public. Release runs test a + # commit that already passed this on its way to main, so they skip it. + secrets: + name: Secret scan + if: ${{ inputs.ref == '' }} + runs-on: ubuntu-24.04 + timeout-minutes: 15 + steps: + # A pull request fetches only its own commits (plus the parent of the + # oldest, below). A push fetches history without file contents; + # gitleaks then reads only the pushed commits. + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} + fetch-depth: ${{ github.event_name == 'pull_request' && github.event.pull_request.commits || 0 }} + filter: ${{ github.event_name != 'pull_request' && 'blob:none' || '' }} + + - name: Install gitleaks + env: + VERSION: 8.30.1 + SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb + run: | + archive="gitleaks_${VERSION}_linux_x64.tar.gz" + curl -fsSL --retry 3 -o "$RUNNER_TEMP/$archive" \ + "https://github.com/gitleaks/gitleaks/releases/download/v${VERSION}/${archive}" + echo "$SHA256 $RUNNER_TEMP/$archive" | sha256sum -c - + tar -xzf "$RUNNER_TEMP/$archive" -C "$RUNNER_TEMP" gitleaks + + - name: Scan the added commits + env: + EVENT_NAME: ${{ github.event_name }} + COMMITS: ${{ github.event.pull_request.commits }} + BEFORE: ${{ github.event.before }} + run: | + if [[ "$EVENT_NAME" == pull_request ]]; then + # One more commit, so the oldest one is diffed against its parent + # instead of being read as a root that adds the whole tree. + git fetch --no-tags --quiet --deepen=1 origin "$(git rev-parse HEAD)" + range="--max-count=$COMMITS" + what="the pull request's $COMMITS commit(s)" + elif [[ -n "$BEFORE" && ! "$BEFORE" =~ ^0+$ ]] && git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then + range="$BEFORE..$GITHUB_SHA" + what="the commits pushed after ${BEFORE:0:12}" + else + range="--max-count=1" + what="the pushed commit (no earlier commit to compare with)" + fi + echo "Scanning $what" + set +e + "$RUNNER_TEMP/gitleaks" git --no-banner --redact --verbose --log-opts="$range" . + status=$? + set -e + if [[ $status -eq 0 ]]; then + echo "### Secret scan"$'\n\n'"No secrets found in $what." >> "$GITHUB_STEP_SUMMARY" + else + echo "### Secret scan"$'\n\n'"gitleaks found possible secrets in $what (values redacted; see the job log). Rotate any real secret: it is already public." >> "$GITHUB_STEP_SUMMARY" + fi + exit $status + + lint: + name: Lint + runs-on: ubuntu-24.04 + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + sparse-checkout: | + /* + !/.repos/ + !/apps/mobile/modules/t3-terminal/Vendor/**/*.a + sparse-checkout-cone-mode: false + + - name: Reject repository-owned PR assets + run: | + files="$(git ls-files .github/pr-assets)" + if test -n "$files"; then + printf 'PR evidence must be uploaded to GitHub, not committed:\n%s\n' "$files" >&2 + exit 1 + fi + + - name: Setup Vite+ + uses: ./.github/actions/setup-ci-deps + + - name: Cache Electron download + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: ~/.cache/electron + key: electron-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('node_modules/.pnpm/electron@*/node_modules/electron/package.json') }} + + - name: Ensure Electron runtime is installed + run: vp run --filter @t3tools/desktop ensure:electron + + - name: Check unused code + run: vp run knip:check + + - name: Check generated GitHub GraphQL operations + run: vp run --filter @t3tools/source-control-github generate --check + + - name: Check generated Expo GraphQL operations + run: vp run --filter t3 generate --check + + - name: Check + run: vp check + + build: + name: Build and Typecheck + needs: changes + if: ${{ !cancelled() && (needs.changes.outputs.build != 'false' || needs.changes.outputs.typecheck != 'false') }} + runs-on: ubuntu-24.04 + timeout-minutes: 20 + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + sparse-checkout: | + /* + !/.repos/ + !/apps/mobile/modules/t3-terminal/Vendor/**/*.a + sparse-checkout-cone-mode: false + + # Runs in the background while Vite+ installs; the step before the build waits for it. + # Xvfb is for the desktop launch check below. + - name: Start installing browser secret helper build libraries + if: needs.changes.outputs.build != 'false' + run: | + ( + set +e + sudo apt-get update -o Acquire::Languages=none \ + -o Acquire::IndexTargets::deb::DEP-11::DefaultEnabled=false \ + -o Acquire::IndexTargets::deb::CNF::DefaultEnabled=false && + sudo apt-get install -y libsecret-1-dev pkg-config xvfb + echo "$?" > "$RUNNER_TEMP/apt-status" + ) > "$RUNNER_TEMP/apt.log" 2>&1 < /dev/null & + + - name: Setup Vite+ + uses: ./.github/actions/setup-ci-deps + with: + # Lint saves the pnpm store; the others only restore it. + save-pnpm-store: false + + - name: Cache Electron download + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: ~/.cache/electron + key: electron-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('node_modules/.pnpm/electron@*/node_modules/electron/package.json') }} + + - name: Ensure Electron runtime is installed + id: electron + run: vp run --filter @t3tools/desktop ensure:electron + + # Upstream reads a private remote task cache (a secret the fork has not + # got). Here vp's local task cache is kept between runs instead: vp + # fingerprints each task's inputs, so a restored entry only replays a + # task whose inputs are unchanged. A new lockfile starts a fresh cache. + - name: Cache vp tasks + if: needs.changes.outputs.typecheck != 'false' + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: node_modules/.vite/task-cache + key: vp-tasks-v1-typecheck-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}-${{ github.sha }} + restore-keys: vp-tasks-v1-typecheck-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}- + + # Runs in the background while the build runs, and reports in the last + # step: neither result hides the other. + - name: Start typecheck + id: typecheck + if: ${{ !cancelled() && steps.electron.outcome == 'success' && needs.changes.outputs.typecheck != 'false' }} + run: | + ( + set +e + vpr typecheck + echo "$?" > "$RUNNER_TEMP/typecheck-status" + ) > "$RUNNER_TEMP/typecheck.log" 2>&1 < /dev/null & + + - name: Finish installing browser secret helper build libraries + id: apt + if: ${{ !cancelled() && needs.changes.outputs.build != 'false' }} + timeout-minutes: 5 + run: | + until test -s "$RUNNER_TEMP/apt-status"; do sleep 1; done + cat "$RUNNER_TEMP/apt.log" + exit "$(cat "$RUNNER_TEMP/apt-status")" + + - name: Build desktop pipeline + id: build + if: ${{ !cancelled() && steps.electron.outcome == 'success' && steps.apt.outcome == 'success' && needs.changes.outputs.build != 'false' }} + run: vp run build:desktop + + - name: Verify preload bundle output + if: ${{ !cancelled() && steps.build.outcome == 'success' }} + run: node apps/desktop/scripts/verify-preload-bundle.mjs + + - name: Open the seeded thread in the built desktop app + id: desktop_launch + if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.desktop_launch != 'false' }} + timeout-minutes: 4 + run: | + electron=$(node -p "require('./apps/desktop/node_modules/electron')") + xvfb-run -a node scripts/smoke-desktop-app.ts --executable "$electron" --app apps/desktop \ + --artifacts-dir "$RUNNER_TEMP/desktop-launch-check" + + - name: Upload desktop launch check + if: ${{ failure() && steps.desktop_launch.outcome == 'failure' }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: desktop-launch-check + path: ${{ runner.temp }}/desktop-launch-check + if-no-files-found: ignore + + - name: Resolve Playwright version + id: playwright_version + if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }} + run: echo "version=$(node -p "require('./apps/web/node_modules/playwright/package.json').version")" >> "$GITHUB_OUTPUT" + + - name: Cache Chromium + id: chromium_cache + if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }} + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: ~/.cache/ms-playwright + key: playwright-chromium-shell-${{ runner.os }}-${{ runner.arch }}-${{ steps.playwright_version.outputs.version }} + + - name: Install Chromium for the built web client boot check + if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' && steps.chromium_cache.outputs.cache-hit != 'true' }} + run: node apps/web/node_modules/playwright/cli.js install --only-shell chromium + + - name: Install missing Chromium system dependencies + if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }} + run: | + browser=$(find "$HOME/.cache/ms-playwright" -name chrome-headless-shell -type f -print -quit) + test -n "$browser" + if ldd "$browser" | grep '=> not found'; then + node apps/web/node_modules/playwright/cli.js install-deps chromium + fi + + - name: Boot the built web client + if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }} + timeout-minutes: 3 + run: node apps/web/scripts/verify-built-boot.ts + + - name: Typecheck + if: ${{ !cancelled() && steps.typecheck.outcome == 'success' }} + timeout-minutes: 10 + run: | + until test -s "$RUNNER_TEMP/typecheck-status"; do sleep 1; done + cat "$RUNNER_TEMP/typecheck.log" + exit "$(cat "$RUNNER_TEMP/typecheck-status")" + + # Everything except `t3` (apps/server) and the web app, which have their own jobs. + # Upstream runs this on one large runner; one 4-CPU runner took 6 minutes. + # Two runners split it (.github/scripts/fork-test-shards.cjs): each runs a + # vitest slice of every large package and half of the others, whole. + test: + name: Test ${{ matrix.shard }} + needs: changes + if: ${{ !cancelled() && needs.changes.outputs.test != 'false' }} + runs-on: ubuntu-24.04 + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + shard: [1, 2] + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + sparse-checkout: | + /* + !/.repos/ + !/apps/mobile/modules/t3-terminal/Vendor/**/*.a + sparse-checkout-cone-mode: false + + # A shard with nothing to run says so in the summary and stops here. + - name: Pick this shard's packages + id: shard + env: + TEST_PACKAGES: ${{ needs.changes.outputs.test_packages }} + run: | + work=$(node .github/scripts/fork-test-shards.cjs "${{ matrix.shard }}/${{ strategy.job-total }}") + whole=$(awk '$1 == "whole" { printf "%s ", $2 }' <<< "$work") + split=$(awk '$1 == "split" { printf "%s ", $2 }' <<< "$work") + { echo "whole=${whole% }"; echo "split=${split% }"; echo "any=$([[ -n "$work" ]] && echo true || echo false)"; } >> "$GITHUB_OUTPUT" + + # The desktop tests compile the browser secret helper. The install runs in + # the background while Vite+ installs; the step before the tests waits for it. + - name: Start installing browser secret helper build libraries + if: steps.shard.outputs.any == 'true' + run: | + ( + set +e + sudo apt-get update -o Acquire::Languages=none \ + -o Acquire::IndexTargets::deb::DEP-11::DefaultEnabled=false \ + -o Acquire::IndexTargets::deb::CNF::DefaultEnabled=false && + sudo apt-get install -y libsecret-1-dev pkg-config + echo "$?" > "$RUNNER_TEMP/apt-status" + ) > "$RUNNER_TEMP/apt.log" 2>&1 < /dev/null & + + - name: Setup Vite+ + if: steps.shard.outputs.any == 'true' + uses: ./.github/actions/setup-ci-deps + with: + # Lint saves the pnpm store; the others only restore it. + save-pnpm-store: false + + - name: Cache Electron download + if: steps.shard.outputs.any == 'true' + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: ~/.cache/electron + key: electron-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('node_modules/.pnpm/electron@*/node_modules/electron/package.json') }} + + - name: Ensure Electron runtime is installed + if: steps.shard.outputs.any == 'true' + run: vp run --filter @t3tools/desktop ensure:electron + + - name: Test preview artifact validation + if: matrix.shard == 1 + run: python3 -B .github/scripts/stage-preview-bundle.test.py + + - name: Test release checks + if: matrix.shard == 1 + run: node --test .github/scripts/check-nightly-release.test.cjs .github/scripts/vercel-deployment-output.test.cjs .github/scripts/mobile-preview-comment.test.cjs .github/scripts/test-delta.test.cjs + + - name: Finish installing browser secret helper build libraries + if: steps.shard.outputs.any == 'true' + timeout-minutes: 5 + run: | + until test -s "$RUNNER_TEMP/apt-status"; do sleep 1; done + cat "$RUNNER_TEMP/apt.log" + exit "$(cat "$RUNNER_TEMP/apt-status")" + + # Whole packages as upstream runs them; a large package's slice runs its + # own test script in its directory with vitest's --shard (`vp run` does + # not pass arguments through to vitest). + - name: Test + if: steps.shard.outputs.any == 'true' + env: + WHOLE: ${{ steps.shard.outputs.whole }} + SPLIT: ${{ steps.shard.outputs.split }} + SHARD: ${{ matrix.shard }}/${{ strategy.job-total }} + run: | + set -o pipefail + # The runner's trace writer can crash on surrogate pairs in test output. + ascii() { + python3 -u -c ' + import sys + for line in sys.stdin: + sys.stdout.write(line.encode("ascii", "backslashreplace").decode("ascii")) + ' + } + status=0 + if [[ -n "$WHOLE" ]]; then + filters=() + for package in $WHOLE; do filters+=(--filter "$package"); done + vp run --parallel --concurrency-limit 4 "${filters[@]}" test 2>&1 | ascii || status=1 + fi + for dir in $SPLIT; do + echo "::group::$dir slice $SHARD" + script=$(jq -r .scripts.test "$dir/package.json") + (cd "$dir" && eval "$script --shard=$SHARD") 2>&1 | ascii || status=1 + echo "::endgroup::" + done + exit "$status" + + # Upstream runs this on one large runner; on a 4-CPU runner the 548 files + # took 7.5 minutes, so two runners each take a vitest slice. + test_web: + name: Test Web ${{ matrix.shard }} + needs: changes + if: ${{ !cancelled() && needs.changes.outputs.test_web != 'false' }} + runs-on: ubuntu-24.04 + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + shard: [1, 2] + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + sparse-checkout: | + /* + !/.repos/ + !/apps/mobile/modules/t3-terminal/Vendor/**/*.a + sparse-checkout-cone-mode: false + + - name: Setup Vite+ + uses: ./.github/actions/setup-ci-deps + with: + # Lint saves the pnpm store; the others only restore it. + save-pnpm-store: false + + - name: Resolve Playwright version + id: playwright_version + run: echo "version=$(node -p "require('./apps/web/node_modules/playwright/package.json').version")" >> "$GITHUB_OUTPUT" + + - name: Cache Chromium + id: chromium_cache + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: ~/.cache/ms-playwright + key: playwright-chromium-shell-${{ runner.os }}-${{ runner.arch }}-${{ steps.playwright_version.outputs.version }} + + - name: Install Chromium for web browser tests + if: steps.chromium_cache.outputs.cache-hit != 'true' + run: node apps/web/node_modules/playwright/cli.js install --only-shell chromium + + - name: Install missing Chromium system dependencies + run: | + browser=$(find "$HOME/.cache/ms-playwright" -name chrome-headless-shell -type f -print -quit) + test -n "$browser" + if ldd "$browser" | grep '=> not found'; then + node apps/web/node_modules/playwright/cli.js install-deps chromium + fi + + # Upstream: `vp run --filter @t3tools/web test --shard N/total`. The same + # script, run in its directory with the slice, as on the Test shards. + # Upstream's release test_web also boots the built client on shard 1; + # here the Build job does that, for CI and release runs alike. + - name: Test + env: + SHARD: ${{ matrix.shard }}/${{ strategy.job-total }} + working-directory: apps/web + run: eval "$(jq -r .scripts.test package.json) --shard=$SHARD" + + # apps/server runs its test files one at a time; shards spread them over + # separate runners. The shards gate themselves instead of waiting for + # `changes`; a shard the change cannot affect says so in its summary. + test_server: + name: Test Server ${{ matrix.shard }} + runs-on: ubuntu-24.04 + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + shard: [1, 2, 3, 4, 5, 6, 7, 8] + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + fetch-depth: 2 + sparse-checkout: | + /* + !/.repos/ + !/apps/mobile/modules/t3-terminal/Vendor/**/*.a + sparse-checkout-cone-mode: false + + - name: Detect affected jobs + id: changes + if: inputs.ref == '' + uses: ./.github/actions/ci-changes + + - name: Report skip + if: steps.changes.outputs.test_server == 'false' + run: | + msg="Skipped: upstream's change detector found no change that affects t3 (apps/server)." + echo "::notice title=Test Server ${{ matrix.shard }} skipped::$msg" + echo "$msg" >> "$GITHUB_STEP_SUMMARY" + + - name: Setup Vite+ + if: steps.changes.outputs.test_server != 'false' + uses: ./.github/actions/setup-ci-deps + with: + # Lint saves the pnpm store; the others only restore it. + save-pnpm-store: false + + # Upstream reads a private remote task cache (a secret the fork has not + # got). Here vp's local task cache is kept between runs instead: vp + # fingerprints each task's inputs, so a restored entry only replays a + # task whose inputs are unchanged. A new lockfile starts a fresh cache. + - name: Cache vp tasks + if: steps.changes.outputs.test_server != 'false' + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: node_modules/.vite/task-cache + key: vp-tasks-v1-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}-${{ github.sha }} + restore-keys: vp-tasks-v1-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}- + + - name: Resolve Playwright version + id: playwright_version + if: steps.changes.outputs.test_server != 'false' + run: echo "version=$(node -p "require('./apps/server/node_modules/playwright-core/package.json').version")" >> "$GITHUB_OUTPUT" + + - name: Cache Chromium + id: chromium_cache + if: steps.changes.outputs.test_server != 'false' + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: ~/.cache/ms-playwright + key: playwright-chromium-shell-${{ runner.os }}-${{ runner.arch }}-${{ steps.playwright_version.outputs.version }} + + - name: Install Chromium for server browser integration tests + if: steps.changes.outputs.test_server != 'false' && steps.chromium_cache.outputs.cache-hit != 'true' + run: node apps/server/node_modules/playwright-core/cli.js install --only-shell chromium + + - name: Install missing Chromium system dependencies + if: steps.changes.outputs.test_server != 'false' + run: | + browser=$(find "$HOME/.cache/ms-playwright" -name chrome-headless-shell -type f -print -quit) + test -n "$browser" + if ldd "$browser" | grep '=> not found'; then + node apps/server/node_modules/playwright-core/cli.js install-deps chromium + fi + + # As upstream: Vitest's module cache, saved only by pushes to main so + # pull requests never evict each other's entries. + - name: Restore Vitest module cache + if: steps.changes.outputs.test_server != 'false' + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: node_modules/.vitest-cache + key: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }} + restore-keys: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}- + + - name: Test + if: steps.changes.outputs.test_server != 'false' + env: + T3CODE_TRANSFER_BUDGET_REPORT_PATH: ${{ runner.temp }}/t3code-transfer-budget.md + T3CODE_TRANSFER_BUDGET_RESULT_PATH: ${{ runner.temp }}/thread-transfer-result.json + run: >- + vp run test:cached -- --shard ${{ matrix.shard }}/${{ strategy.job-total }} + --uncached apps/server/integration/transferBudgetV2.integration.test.ts + --verify-hits 1 apps/server + + - name: Save Vitest module cache + if: github.event_name == 'push' && steps.changes.outputs.test_server != 'false' + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 + with: + path: node_modules/.vitest-cache + key: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }} + + # integration/transferBudgetV2.integration.test.ts writes the report; exactly one shard + # produces these files. + - name: Detect transfer budget report + id: transfer_budget + if: always() + run: | + if test -f "${{ runner.temp }}/thread-transfer-result.json"; then + echo "present=true" >> "$GITHUB_OUTPUT" + else + echo "present=false" >> "$GITHUB_OUTPUT" + fi + + - name: Publish transfer budget report + if: always() && steps.transfer_budget.outputs.present == 'true' + run: | + if test -f "${{ runner.temp }}/t3code-transfer-budget.md"; then + tee -a "$GITHUB_STEP_SUMMARY" < "${{ runner.temp }}/t3code-transfer-budget.md" + else + echo "Transfer budget report was not produced." >> "$GITHUB_STEP_SUMMARY" + fi + + - name: Upload thread transfer result + if: always() && steps.transfer_budget.outputs.present == 'true' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: thread-transfer-results + path: ${{ runner.temp }}/thread-transfer-result.json + if-no-files-found: ignore + retention-days: 30 + + rust: + name: Rust + needs: changes + if: ${{ !cancelled() && needs.changes.outputs.rust != 'false' }} + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + sparse-checkout: | + /* + !/.repos/ + !/apps/mobile/modules/t3-terminal/Vendor/**/*.a + sparse-checkout-cone-mode: false + + - name: Setup Rust + uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable + with: + components: rustfmt + + - name: Check Rust formatting + run: | + for crate in resource-monitor kde-snap-shot hyprland-snap-shot; do + cargo fmt --manifest-path "native/$crate/Cargo.toml" -- --check + done + + - name: Test Rust crates + run: | + for crate in resource-monitor kde-snap-shot hyprland-snap-shot; do + cargo test --locked --manifest-path "native/$crate/Cargo.toml" + done + + # Upstream runs this on macOS 26. GitHub-hosted macOS minutes are free on a + # public repository; it runs only for native mobile sources or a workflow change. + mobile_native_static_analysis: + name: Mobile Native Static Analysis + needs: changes + if: ${{ !cancelled() && needs.changes.outputs.mobile_native != 'false' }} + runs-on: macos-26 + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + sparse-checkout: | + /* + !/.repos/ + sparse-checkout-cone-mode: false + + - name: Setup Vite+ + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1 + with: + node-version-file: package.json + cache: true + run-install: | + args: + - --filter=@t3tools/scripts... + + - name: Install mobile native static analysis tools + run: brew bundle install --file apps/mobile/Brewfile + + - name: Lint mobile native sources + run: vp run lint:mobile + + release_smoke: + name: Release Smoke + needs: changes + if: ${{ !cancelled() && needs.changes.outputs.release_smoke != 'false' }} + runs-on: ubuntu-24.04 + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.ref }} + sparse-checkout: | + /* + !/.repos/ + !/apps/mobile/modules/t3-terminal/Vendor/**/*.a + sparse-checkout-cone-mode: false + + - name: Setup Vite+ + uses: ./.github/actions/setup-ci-deps + with: + # Lint saves the pnpm store; the others only restore it. + save-pnpm-store: false + + - name: Exercise release-only workflow steps + run: node scripts/release-smoke.ts + + # The one check a ruleset requires. Fails when any job fails or is cancelled, + # or is skipped without a reason: `changes` said its gates were not needed, + # or (secret scan) it is a release run. The summary lists every job, the + # reason for every skip, and each job's wall time. + # `always()` rather than `!cancelled()`: a skipped job reports success to + # branch protection, so a cancelled run must still produce a failing result. + fork_ci_result: + name: fork-ci-result + if: ${{ always() }} + needs: + [ + changes, + workflows, + secrets, + lint, + build, + test, + test_web, + test_server, + rust, + mobile_native_static_analysis, + release_smoke, + ] + runs-on: ubuntu-24.04 + timeout-minutes: 5 + # The job list API needs actions: read; nothing here checks out code. + permissions: + actions: read + steps: + - name: Require every job to pass + env: + RESULTS: ${{ toJSON(needs) }} + RELEASE_RUN: ${{ inputs.ref != '' }} + run: | + echo "$RESULTS" | jq -r 'to_entries[] | "\(.key): \(.value.result)"' + # A jq program: $release is jq's variable, not the shell's. + # shellcheck disable=SC2016 + why='{ + build: "the change affects neither desktop, server nor web, and no package needs a typecheck", + test: "the change affects no package this job tests", + test_web: "the change affects nothing @t3tools/web depends on", + rust: "the change touches none of the native Rust crates", + mobile_native_static_analysis: (if $release == "true" + then "release run: upstream release.yml has no macOS lint" + else "no native mobile source, Brewfile or CI workflow changed" end), + release_smoke: "the change does not affect scripts/", + secrets: "release run: the commit was scanned on its way to main" + }' + { + echo "### fork-ci-result" + echo + echo "| Job | Result | Why skipped |" + echo "| --- | --- | --- |" + echo "$RESULTS" | jq -r --arg release "$RELEASE_RUN" "$why as \$why + | to_entries[] + | \"| \(.key) | \(.value.result) | \(if .value.result == \"skipped\" then (\$why[.key] // \"no reason: fails\") else \"\" end) |\"" + if [[ "$(echo "$RESULTS" | jq -r '.changes.outputs.test_server')" == false ]]; then + echo + echo "Server shards passed without running tests: the change affects nothing t3 (apps/server) depends on." + fi + } >> "$GITHUB_STEP_SUMMARY" + # A job may skip only when `changes` said every gate it represents was + # not needed (gates are keyed by job name, except merged Build and the + # macOS lint), or, for the secret scan, in a release run. + echo "$RESULTS" | jq -e --arg release "$RELEASE_RUN" '.changes.outputs as $gates + | {build: ["build", "typecheck", "desktop_launch"], mobile_native_static_analysis: ["mobile_native"]} as $renamed + | all(to_entries[]; + .value.result == "success" + or (.value.result == "skipped" + and (if .key == "secrets" then $release == "true" + else (($renamed[.key] // [.key]) | all(.[]; $gates[.] == "false")) end)))' > /dev/null + + # A run whose server tests ran must have produced the transfer measurements. + - name: Require transfer measurements + if: needs.test_server.result == 'success' && needs.changes.outputs.test_server != 'false' + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 + with: + name: thread-transfer-results + path: ${{ runner.temp }}/thread-transfer + + # Information only: read from the run's job list, never fails the run. + - name: Job wall times + if: always() + env: + GH_TOKEN: ${{ github.token }} + run: | + jobs=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs?per_page=100") || { + echo "::warning::Job timings unavailable: the job list API call failed." + echo "Job timings unavailable." >> "$GITHUB_STEP_SUMMARY" + exit 0 + } + echo "Job timings for $(echo "$jobs" | jq '.jobs | length') jobs." + { + echo + echo "#### Job wall times" + echo + echo "| Job | Queued | Ran |" + echo "| --- | ---: | ---: |" + echo "$jobs" | jq -r '.jobs[] + | select(.completed_at != null and .started_at != null) + | ((.started_at | fromdateiso8601) - (.created_at | fromdateiso8601)) as $queued + | ((.completed_at | fromdateiso8601) - (.started_at | fromdateiso8601)) as $ran + | "| \(.name) | \($queued)s | \($ran / 60 | floor)m \($ran % 60)s |"' + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/pr-limits.yml b/.github/workflows/pr-limits.yml new file mode 100644 index 0000000000000..75943062735cd --- /dev/null +++ b/.github/workflows/pr-limits.yml @@ -0,0 +1,72 @@ +name: PR Limits + +# Deterministic PR rules from CONTRIBUTING.md: the open PR limit, the conflict +# window, and the 72 hour close window that follows a triage notice. +# +# Nothing is labeled, commented on, or closed until the repository variable +# PR_LIMITS_ENFORCE is "true". Until then every run logs what it would do. A +# sweep reads the variable once when it starts; to stop one, cancel the run. + +on: + pull_request_target: + types: [opened, reopened] + schedule: + - cron: "23 5 * * *" + workflow_dispatch: + inputs: + dry_run: + description: Log what the sweep would do without labeling, commenting, or closing. + type: boolean + default: true + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + open-limit: + name: Open PR limit + if: github.event_name == 'pull_request_target' + runs-on: ubuntu-24.04 + steps: + # pull_request_target has a write token. Load the script from the default + # branch and never run PR code. Cone mode also checks out the files beside + # .github/scripts, which is where TRIAGE_EXEMPTIONS.td and VOUCHED.td live. + - name: Checkout trusted scripts + uses: actions/checkout@v6 + with: + ref: ${{ github.event.repository.default_branch }} + sparse-checkout: .github/scripts + + - name: Close PRs over the limit + uses: actions/github-script@v8 + env: + DRY_RUN: ${{ vars.PR_LIMITS_ENFORCE != 'true' }} + with: + script: | + const limits = require("./.github/scripts/pr-limits.cjs"); + await limits.enforceOpenLimit({ github, context, core, dryRun: process.env.DRY_RUN === "true" }); + + sweep: + name: Conflict and close windows + if: github.event_name != 'pull_request_target' + runs-on: ubuntu-24.04 + concurrency: + group: pr-limits-sweep + cancel-in-progress: false + steps: + - name: Checkout trusted scripts + uses: actions/checkout@v6 + with: + ref: ${{ github.event.repository.default_branch }} + sparse-checkout: .github/scripts + + - name: Request rebases and close what went unanswered + uses: actions/github-script@v8 + env: + DRY_RUN: ${{ vars.PR_LIMITS_ENFORCE != 'true' || (github.event_name == 'workflow_dispatch' && inputs.dry_run) }} + with: + script: | + const limits = require("./.github/scripts/pr-limits.cjs"); + await limits.sweep({ github, context, core, dryRun: process.env.DRY_RUN === "true" }); diff --git a/.github/workflows/pr-size.yml b/.github/workflows/pr-size.yml index af557dff62df8..cb0c9637fcef7 100644 --- a/.github/workflows/pr-size.yml +++ b/.github/workflows/pr-size.yml @@ -293,3 +293,55 @@ jobs: core.info( `PR #${issueNumber}: ${nonTestChangedLines} non-test lines, ${testChangedLines} test lines, ${changedLines} effective lines -> ${nextLabelName} (${classification})`, ); + # Reads the script from the base checkout above; the PR's own commits are only diffed. + - name: Report test suite growth + uses: actions/github-script@v8 + with: + script: | + const { execFileSync } = require("node:child_process"); + const { MARKER, countTestDelta, render } = require( + `${process.env.GITHUB_WORKSPACE}/.github/scripts/test-delta.cjs`, + ); + + const issueNumber = context.payload.pull_request.number; + const diff = execFileSync( + "git", + ["diff", "-U0", `${context.payload.pull_request.base.sha}...refs/remotes/pr-size/${issueNumber}`], + { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 }, + ); + const delta = countTestDelta(diff); + const body = render(delta); + core.info(`PR #${issueNumber}: test cases ${JSON.stringify(delta.kinds)}, net ${delta.net}`); + + const comments = await github.paginate(github.rest.issues.listComments, { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + per_page: 100, + }); + const existing = comments.find( + (comment) => comment.user?.type === "Bot" && comment.body?.startsWith(MARKER), + ); + if (body && existing) { + if (existing.body !== body) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } + } else if (body) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + body, + }); + } else if (existing) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + }); + } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c56c76be7e0e7..8827876b3829f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -300,11 +300,15 @@ jobs: # Web browser tests time out when they share a runner with the other package # suites: Chromium gets too little CPU and diff workers miss their 10s start budget. test_web: - name: Release web tests + name: Release web tests ${{ matrix.shard }} needs: [preflight] if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' }} runs-on: blacksmith-8vcpu-ubuntu-2404 timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + shard: [1, 2] steps: - name: Checkout uses: actions/checkout@v6 @@ -344,10 +348,11 @@ jobs: fi - name: Test - run: vp run --filter @t3tools/web test + run: vp run --filter @t3tools/web test --shard ${{ matrix.shard }}/${{ strategy.job-total }} # Browser tests run source modules; this boots the production chunk graph. - name: Boot the built web client + if: matrix.shard == 1 run: | vp run --filter @t3tools/web build node apps/web/scripts/verify-built-boot.ts @@ -1482,7 +1487,18 @@ jobs: git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json pnpm-lock.yaml git commit --no-verify -m "chore(release): prepare $RELEASE_TAG" - git push origin HEAD:main + + # main moves while this job runs, so a rejected push rebases and retries. + for attempt in 1 2 3 4 5; do + if git push origin HEAD:main; then + exit 0 + fi + echo "Push rejected (attempt $attempt). Rebasing onto latest main." + git pull --rebase origin main + done + + echo "Could not push the version bump after 5 attempts." >&2 + exit 1 announce_discord: name: Announce release on Discord diff --git a/.macroscope/check-run-agents/ui-consistency.md b/.macroscope/check-run-agents/ui-consistency.md index 905823d1d1a9e..4326d4e8391b7 100644 --- a/.macroscope/check-run-agents/ui-consistency.md +++ b/.macroscope/check-run-agents/ui-consistency.md @@ -44,7 +44,7 @@ The reference for how this codebase wants UI built is the composer banner system - `ComposerBanner.tsx` exports one object of small slot components (`Root`, `Row`, `Icon`, `Content`, `Actions`, `Dismiss`, `Children`, and so on). Each slot owns its own Tailwind classes, exposes a `data-slot` attribute, takes `className` and spreads the rest of its props, and uses `cn` so callers can adjust without overriding. Variants and density are props on `Root`, not ad hoc class strings at call sites. Where a slot needs a real control it renders `Button` from `ui/` rather than a styled `