Skip to content

Commit 7a14c35

Browse files
Merge branch 'main' into factory/issue-35648
2 parents 0b8e794 + c60aa1a commit 7a14c35

162 files changed

Lines changed: 8459 additions & 1797 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/scripts/check-nightly-release.cjs‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,54 @@ async function resolveLatestNightlyCommit({ github, context, core }) {
121121
return { tag, sha: commit.sha, version };
122122
}
123123

124+
// The two places a nightly install looks for an update: the `update-feed` pointer, and
125+
// releases.atom, which holds the 10 newest git tags of any kind. Older installs take the first
126+
// nightly in the feed. Reports what each names beside the newest published nightly.
127+
async function readNightlyUpdateFeed({ github, context, fetch = globalThis.fetch }) {
128+
const latest = await findLatestNightly({ github, context });
129+
if (!latest) return {};
130+
131+
const base = `https://github.com/${context.repo.owner}/${context.repo.repo}`;
132+
// Only a missing or malformed pointer is stale. Rewriting deletes the old file first, so a
133+
// GitHub outage must not look like one.
134+
// Node waits five minutes for a stalled response, which is this job's whole time limit.
135+
const signal = () => AbortSignal.timeout(30_000);
136+
const pointer = await fetch(`${base}/releases/download/update-feed/nightly.json`, {
137+
signal: signal(),
138+
});
139+
if (!pointer.ok && pointer.status !== 404) {
140+
throw new Error(`The update-feed pointer answered HTTP ${pointer.status}.`);
141+
}
142+
let pointerTag;
143+
if (pointer.ok) {
144+
// A body that fails to arrive throws here; only one that is not JSON counts as malformed.
145+
const body = await pointer.text();
146+
try {
147+
pointerTag = JSON.parse(body)?.tag_name;
148+
} catch {}
149+
}
150+
151+
// An unreadable feed leaves `feedTags` unset, so the pointer is still repaired. An error page
152+
// can answer HTTP 200, so only an Atom document counts as read.
153+
let feedTags;
154+
try {
155+
const feed = await fetch(`${base}/releases.atom`, { signal: signal() });
156+
const body = feed.ok ? await feed.text() : "";
157+
if (/<feed[\s>]/.test(body)) {
158+
feedTags = Array.from(body.matchAll(/href="[^"]*\/releases\/tag\/([^"]+)"/g), (match) =>
159+
decodeURIComponent(match[1]),
160+
);
161+
}
162+
} catch {}
163+
const feedNightly = feedTags?.find((tag) => /^v?\d+\.\d+\.\d+-nightly\./.test(tag));
164+
165+
return { tag: latest.tagName, pointerTag, feedNightly, feedTags };
166+
}
167+
124168
module.exports = {
125169
assertCommitOnDefaultBranch,
126170
assertReleaseSource,
127171
shouldReleaseNightly,
128172
resolveLatestNightlyCommit,
173+
readNightlyUpdateFeed,
129174
};

‎.github/scripts/check-nightly-release.test.cjs‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,81 @@ test("stable releases fail when no nightly is published", async () => {
237237
const { options } = nightlyCommitFixture({ releases: [nightly(1, { tagName: "v1.0.0" })] });
238238
await assert.rejects(resolveLatestNightlyCommit(options), /No published nightly found/);
239239
});
240+
241+
const { readNightlyUpdateFeed } = require("./check-nightly-release.cjs");
242+
243+
// GitHub percent-encodes tag names in the feed, and any tag in the repository takes a slot.
244+
const atomEntry = (tag) =>
245+
`<entry><link rel="alternate" type="text/html" href="https://github.com/example/app/releases/tag/${encodeURIComponent(tag)}"/></entry>`;
246+
const atomFeed = (tags) => new Response(`<feed>${tags.map(atomEntry).join("")}</feed>`);
247+
const NEWEST = "v1.0.1-nightly.20260905.123";
248+
const OLDER = "v1.0.1-nightly.20260905.100";
249+
250+
function updateFeedFixture({ feed, pointer }) {
251+
const { options } = fixture({
252+
releases: [nightly(1), nightly(0, { tagName: "v1.0.2-preview.1" })],
253+
});
254+
options.fetch = async (url) =>
255+
url === "https://github.com/example/app/releases.atom"
256+
? feed
257+
: url === "https://github.com/example/app/releases/download/update-feed/nightly.json"
258+
? pointer
259+
: assert.fail(`unexpected fetch ${url}`);
260+
return options;
261+
}
262+
263+
const missing = () => new Response("Not Found", { status: 404 });
264+
// HTTP 200, then the connection drops before the body arrives.
265+
const brokenBody = () =>
266+
new Response(new ReadableStream({ start: (controller) => controller.error(new Error("reset")) }));
267+
for (const [name, { feed, pointer }, expected] of [
268+
[
269+
"a nightly crowded out of the feed and a missing pointer",
270+
{ feed: atomFeed(["v1.0.2-preview.1", "mobile-android-build/2.3.0/abc"]), pointer: missing() },
271+
{ pointerTag: undefined, feedNightly: undefined },
272+
],
273+
[
274+
"the first nightly in the feed, which is the one older installs take",
275+
{ feed: atomFeed(["update-feed", OLDER, NEWEST]), pointer: Response.json({ tag_name: OLDER }) },
276+
{ pointerTag: OLDER, feedNightly: OLDER },
277+
],
278+
[
279+
"a malformed pointer as stale and an unreadable feed as naming nothing",
280+
{ feed: new Response("", { status: 503 }), pointer: Response.json(null) },
281+
{ pointerTag: undefined, feedNightly: undefined, unreadable: true },
282+
],
283+
[
284+
"an HTML page with release links as an unreadable feed",
285+
{
286+
feed: new Response(
287+
`<html><feedback-form></feedback-form><a href="/example/app/releases/tag/${OLDER}">x</a></html>`,
288+
),
289+
pointer: Response.json({ tag_name: NEWEST }),
290+
},
291+
{ pointerTag: NEWEST, feedNightly: undefined, unreadable: true },
292+
],
293+
[
294+
"the pointer when the feed's body fails to arrive",
295+
{ feed: brokenBody(), pointer: Response.json({ tag_name: NEWEST }) },
296+
{ pointerTag: NEWEST, feedNightly: undefined, unreadable: true },
297+
],
298+
]) {
299+
test(`update feed check reports ${name}`, async () => {
300+
const { tag, pointerTag, feedNightly, feedTags } = await readNightlyUpdateFeed(
301+
updateFeedFixture({ feed, pointer }),
302+
);
303+
const { unreadable = false, ...named } = expected;
304+
assert.deepEqual({ tag, pointerTag, feedNightly }, { tag: NEWEST, ...named });
305+
assert.equal(feedTags === undefined, unreadable);
306+
});
307+
}
308+
309+
for (const [name, pointer, error] of [
310+
["answers with an error", () => new Response("", { status: 503 }), /pointer answered HTTP 503/],
311+
["drops the connection", brokenBody, /reset/],
312+
]) {
313+
test(`update feed check does not call a pointer stale when GitHub ${name}`, async () => {
314+
const options = updateFeedFixture({ feed: atomFeed([NEWEST]), pointer: pointer() });
315+
await assert.rejects(readNightlyUpdateFeed(options), error);
316+
});
317+
}

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,9 @@ jobs:
504504
T3CODE_TRANSFER_BUDGET_REPORT_PATH: ${{ runner.temp }}/t3code-transfer-budget.md
505505
T3CODE_TRANSFER_BUDGET_RESULT_PATH: ${{ runner.temp }}/thread-transfer-result.json
506506
T3CODE_TRANSFER_BUDGET_SCENARIOS_PATH: ${{ runner.temp }}/thread-transfer-scenarios.json
507+
# One process per file spends ~2s starting before its tests run; one file per vCPU overlaps that.
507508
run: >-
508-
vp run test:cached -- --shard ${{ matrix.shard }}/${{ strategy.job-total }}
509+
vp run test:cached -- --shard ${{ matrix.shard }}/${{ strategy.job-total }} --concurrency 4
509510
--uncached apps/server/integration/transferBudgetV2.integration.test.ts
510511
--verify-hits 1 apps/server
511512

‎.github/workflows/release.yml‎

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ jobs:
4949
# published nightly, so stable only ever ships a build that nightly users
5050
# have already run. Scheduled runs also decide here whether a nightly is due.
5151
# The PAUSE_NIGHTLY repository variable skips scheduled runs only; every later
52-
# job needs this one, so a skip here skips the whole run.
52+
# job needs this one, so a skip here skips the whole run. `update_feed` runs
53+
# without it and checks the variable itself.
5354
resolve_commit:
5455
name: Resolve release commit
5556
if: github.repository == 'pingdotgg/t3code' && (github.event_name != 'schedule' || vars.PAUSE_NIGHTLY != 'true')
@@ -165,14 +166,12 @@ jobs:
165166
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
166167
echo "make_latest=false" >> "$GITHUB_OUTPUT"
167168
elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && "${DISPATCH_CHANNEL:-preview}" == "preview" ]]; then
168-
# Manual-only test train: exercises the whole release flow for a
169-
# commit end users must never receive. Never scheduled.
169+
# Manual-only test train: exercises the release flow up to a draft
170+
# release for a commit end users must never receive. Never scheduled.
170171
# Same versioning as nightly under its own prerelease identifier.
171-
# A preview release is reachable only by asking for it: npm gets it
172-
# under the `preview` dist-tag, which nothing resolves by default,
173-
# its desktop builds carry no update feed, and no updater manifest
174-
# is attached to the release, so neither stable nor nightly
175-
# installs can ever be offered one.
172+
# A preview release stays a draft (see "Publish prerelease"), its
173+
# desktop builds carry no update feed, no updater manifest is
174+
# attached, and npm gets nothing, so no install can be offered one.
176175
nightly_date="$(date -u -d "$NIGHTLY_DATE" +%Y%m%d)"
177176
178177
node scripts/resolve-nightly-release.ts \
@@ -183,7 +182,6 @@ jobs:
183182
--github-output
184183
185184
echo "release_channel=preview" >> "$GITHUB_OUTPUT"
186-
echo "cli_dist_tag=preview" >> "$GITHUB_OUTPUT"
187185
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
188186
echo "make_latest=false" >> "$GITHUB_OUTPUT"
189187
else
@@ -1038,22 +1036,93 @@ jobs:
10381036
# The action keeps a stable release a draft until its assets finish uploading, but publishes a
10391037
# prerelease first. Desktop clients update connected servers from the CLI archives as soon as
10401038
# they see the release, so a prerelease also goes public only once every asset is attached.
1039+
# Previews stay drafts, because a draft has no git tag. releases.atom lists the 10 newest tags,
1040+
# a day's `preview` tags can sort above its `nightly` ones, and older updaters find nightlies only there.
10411041
- name: Publish prerelease
1042-
if: needs.preflight.outputs.is_prerelease == 'true'
1042+
if: needs.preflight.outputs.is_prerelease == 'true' && needs.preflight.outputs.release_channel != 'preview'
10431043
env:
10441044
GH_TOKEN: ${{ github.token }}
10451045
GH_REPO: ${{ github.repository }}
10461046
RELEASE_TAG: ${{ needs.preflight.outputs.tag }}
10471047
run: gh release edit "$RELEASE_TAG" --draft=false
10481048

1049+
# A nightly install finds updates in releases.atom, which holds the 10 newest git tags of any
1050+
# kind, so a burst of other tags hides every nightly. The `update-feed` release is the fixed URL
1051+
# newer installs also read. Every unpaused scheduled tick and every nightly repairs it, then fails when
1052+
# the feed's first nightly is not the newest one. See docs/operations/release.md#update-feed.
1053+
update_feed:
1054+
name: Check the update feed
1055+
needs: [preflight, release]
1056+
if: ${{ !cancelled() && github.repository == 'pingdotgg/t3code' && ((github.event_name == 'schedule' && vars.PAUSE_NIGHTLY != 'true') || needs.preflight.outputs.release_channel == 'nightly') }}
1057+
runs-on: blacksmith-2vcpu-ubuntu-2404
1058+
timeout-minutes: 5
1059+
permissions:
1060+
contents: write
1061+
steps:
1062+
- name: Checkout
1063+
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
1064+
with:
1065+
sparse-checkout: .github/scripts
1066+
1067+
- id: feed
1068+
name: Read the update feed
1069+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
1070+
with:
1071+
retries: 3
1072+
script: |
1073+
const { readNightlyUpdateFeed } = require('./.github/scripts/check-nightly-release.cjs');
1074+
const { tag, pointerTag, feedNightly, feedTags } = await readNightlyUpdateFeed({ github, context });
1075+
if (!tag) return;
1076+
core.info(`Newest nightly: ${tag}. Pointer: ${pointerTag}. Feed: ${feedTags?.join(', ')}.`);
1077+
core.setOutput('tag', tag);
1078+
core.setOutput('pointer_stale', pointerTag !== tag);
1079+
core.setOutput('feed', feedTags === undefined ? 'unreadable' : feedNightly === tag ? 'ok' : 'hidden');
1080+
1081+
- name: Point the update feed at the newest nightly
1082+
if: steps.feed.outputs.pointer_stale == 'true'
1083+
env:
1084+
GH_TOKEN: ${{ github.token }}
1085+
GH_REPO: ${{ github.repository }}
1086+
RELEASE_TAG: ${{ steps.feed.outputs.tag }}
1087+
run: |
1088+
gh api "repos/$GH_REPO/releases/tags/$RELEASE_TAG" --jq '{tag_name, name, body}' > nightly.json
1089+
gh release view update-feed > /dev/null 2>&1 ||
1090+
gh release create update-feed --prerelease --latest=false --title "Update feed" \
1091+
--notes "The desktop updater reads this release to find the newest nightly. Do not delete it. See docs/operations/release.md."
1092+
gh release upload update-feed nightly.json --clobber
1093+
1094+
# Every run, because the pointer can be current while the release's flags are wrong. A draft's
1095+
# files are not public, and a release marked "latest" is the one stable installs update to.
1096+
- name: Keep the update feed release public and never latest
1097+
if: steps.feed.outputs.tag != ''
1098+
env:
1099+
GH_TOKEN: ${{ github.token }}
1100+
GH_REPO: ${{ github.repository }}
1101+
run: gh release edit update-feed --draft=false --prerelease --latest=false
1102+
1103+
# An unreadable feed says nothing about its tags and the next tick reads it again, so only a
1104+
# feed that was read and names another nightly first fails the run.
1105+
- name: Fail when the feed hides the newest nightly
1106+
if: steps.feed.outputs.tag != '' && steps.feed.outputs.feed != 'ok'
1107+
env:
1108+
RELEASE_TAG: ${{ steps.feed.outputs.tag }}
1109+
FEED: ${{ steps.feed.outputs.feed }}
1110+
run: |
1111+
if [[ "$FEED" == "unreadable" ]]; then
1112+
echo "::warning::releases.atom could not be read, so this run did not check it."
1113+
exit 0
1114+
fi
1115+
echo "::error::The first nightly in releases.atom is not $RELEASE_TAG. Nightly installs older than 0.1.10-nightly.20261112.4603 cannot reach it, and neither can later builds that do not read the pointer when the feed names an older nightly. A preview from a branch not rebased onto main is the usual cause. See docs/operations/release.md#update-feed."
1116+
exit 1
1117+
10491118
# The `t3` npm package is a launcher that downloads this version's CLI
10501119
# archive from the GitHub Release, so it publishes only once that release
1051-
# exists. Preview publishes too, under the `preview` dist-tag, which
1052-
# nothing resolves unless asked for by name.
1120+
# exists. A preview release stays a draft, whose files are not public, so
1121+
# a preview never publishes the launcher.
10531122
publish_cli:
10541123
name: Publish CLI to npm
10551124
needs: [preflight, build_bundle, release]
1056-
if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.release.result == 'success' }}
1125+
if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.release.result == 'success' && needs.preflight.outputs.release_channel != 'preview' }}
10571126
runs-on: ubuntu-24.04 # blacksmith-8vcpu-ubuntu-2404
10581127
timeout-minutes: 15
10591128
permissions:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import type { PreviewAnnotationPoint } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import {
5+
addStrokePoint,
6+
openStrokePath,
7+
startStroke,
8+
strokeBounds,
9+
STROKE_SEGMENTS_PER_PATH,
10+
} from "./AnnotationStroke.ts";
11+
12+
// The Draw tool used to rebuild the whole path and rescan every point on each move.
13+
const fullPath = (points: ReadonlyArray<PreviewAnnotationPoint>): string => {
14+
let path = `M ${points[0]!.x} ${points[0]!.y}`;
15+
for (let index = 1; index < points.length - 1; index += 1) {
16+
const current = points[index]!;
17+
const next = points[index + 1]!;
18+
path += ` Q ${current.x} ${current.y} ${(current.x + next.x) / 2} ${(current.y + next.y) / 2}`;
19+
}
20+
const last = points[points.length - 1]!;
21+
return `${path} L ${last.x} ${last.y}`;
22+
};
23+
24+
const fullBounds = (points: ReadonlyArray<PreviewAnnotationPoint>, width: number) => {
25+
const xs = points.map((point) => point.x);
26+
const ys = points.map((point) => point.y);
27+
const padding = width + 3;
28+
const left = Math.min(...xs) - padding;
29+
const top = Math.min(...ys) - padding;
30+
const right = Math.max(...xs) + padding;
31+
const bottom = Math.max(...ys) + padding;
32+
return { x: left, y: top, width: right - left, height: bottom - top };
33+
};
34+
35+
// Each later path starts with a move to where the previous one ended.
36+
const joinPaths = (paths: ReadonlyArray<string>): string =>
37+
paths
38+
.map((path, index) => {
39+
if (index === 0) return path;
40+
const resume = path.match(/^M (\S+ \S+)/)![1]!;
41+
expect(paths[index - 1]!.endsWith(` ${resume}`)).toBe(true);
42+
return path.slice(`M ${resume}`.length);
43+
})
44+
.join("");
45+
46+
describe("stroke geometry", () => {
47+
it("draws the same curve and bounds as a full rescan at every length", () => {
48+
const points = Array.from({ length: STROKE_SEGMENTS_PER_PATH * 2 + 30 }, (_, index) => ({
49+
x: index * 3 + ((index * 7) % 11),
50+
y: 200 + ((index * 13) % 29) - index,
51+
}));
52+
const geometry = startStroke(points[0]!);
53+
const closedPaths: string[] = [];
54+
for (let index = 1; index < points.length; index += 1) {
55+
const closedPath = addStrokePoint(geometry, points[index]!);
56+
if (closedPath !== null) closedPaths.push(closedPath);
57+
const drawn = points.slice(0, index + 1);
58+
expect(joinPaths([...closedPaths, openStrokePath(geometry)])).toBe(fullPath(drawn));
59+
expect(strokeBounds(geometry, 4)).toEqual(fullBounds(drawn, 4));
60+
}
61+
expect(closedPaths).toHaveLength(2);
62+
expect(geometry.points).toEqual(points);
63+
});
64+
65+
it("keeps the rewritten path short for a stroke past the engine's argument limit", () => {
66+
const geometry = startStroke({ x: 0, y: 0 });
67+
for (let index = 1; index < 250_000; index += 1) {
68+
addStrokePoint(geometry, { x: index % 800, y: index % 600 });
69+
}
70+
expect(strokeBounds(geometry, 4)).toEqual({ x: -7, y: -7, width: 813, height: 613 });
71+
expect(openStrokePath(geometry).length).toBeLessThan(STROKE_SEGMENTS_PER_PATH * 40);
72+
});
73+
});

0 commit comments

Comments
 (0)