Skip to content

Commit 2cefba2

Browse files
t3dotggclaude
andcommitted
Merge branch 'main' into fix/claude-mcp-deadline-after-boot
Co-Authored-By: Claude Fable 5.2 <[email protected]>
2 parents 8afe10b + 4ea32cb commit 2cefba2

1,452 files changed

Lines changed: 239852 additions & 97211 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.

‎.agents/skills/test-t3-mobile/SKILL.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ vp run mobile:install <ios|android> <device-id>
3636

3737
This installs the dev client for the checkout's native fingerprint: from the
3838
device, the local cache, or the shared cache in seconds, building once only
39-
when no machine has that fingerprint yet (5-15 minutes, logged to the file it
40-
names). The device id may be omitted when exactly one device is booted. It
39+
when no machine has that fingerprint yet: in the `Mobile Dev Client` workflow
40+
on Blacksmith when HEAD is pushed and `gh` may dispatch it (the command waits),
41+
otherwise here (5-15 minutes, logged to the file it names). The device id may be omitted when exactly one device is booted. It
4142
prints one JSON line; on failure it names the next command. Mobile verification
4243
includes that step unless the user prohibits it.
4344

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// The Android half of the mobile preview comment. The android job writes the fingerprint and
2+
// the update; the android-build job adds the client's install link a few minutes later. Each
3+
// run merges what it knows into the state kept in the comment's first line.
4+
const MARKER = "mobile-preview-android";
5+
const PROJECT_ID = "d763fcb8-d37c-41ea-a773-b54a0ab4a454";
6+
const APP_SCHEME = "t3-code";
7+
8+
function readState(body) {
9+
const match = new RegExp(`^<!-- ${MARKER} (\\{.*\\}) -->`).exec(body ?? "");
10+
if (!match) return null;
11+
try {
12+
const state = JSON.parse(match[1]);
13+
const text = (value) => (typeof value === "string" ? value : "");
14+
return {
15+
fingerprint: text(state.fingerprint),
16+
client: text(state.client),
17+
group: text(state.group),
18+
};
19+
} catch {
20+
return null;
21+
}
22+
}
23+
24+
/**
25+
* New values win; a new fingerprint drops the old fingerprint's client. A build that finishes
26+
* after the PR moved to another fingerprint changes nothing: its client cannot run the update
27+
* the comment now shows.
28+
*/
29+
function mergeState(previous, next) {
30+
const buildOnly = Boolean(next.client) && !next.group;
31+
if (
32+
buildOnly &&
33+
previous?.fingerprint &&
34+
next.fingerprint &&
35+
previous.fingerprint !== next.fingerprint
36+
) {
37+
return previous;
38+
}
39+
const fingerprint = next.fingerprint || previous?.fingerprint || "";
40+
const sameFingerprint = !previous?.fingerprint || previous.fingerprint === fingerprint;
41+
return {
42+
fingerprint,
43+
client: next.client || (sameFingerprint ? (previous?.client ?? "") : ""),
44+
group: next.group || previous?.group || "",
45+
};
46+
}
47+
48+
function render(state, runUrl) {
49+
const qr = `https://qr.expo.dev/eas-update?appScheme=${APP_SCHEME}&projectId=${PROJECT_ID}&groupId=${state.group}`;
50+
const rows = [
51+
`<!-- ${MARKER} ${JSON.stringify(state)} -->`,
52+
"🤖 Android preview",
53+
"",
54+
"&nbsp; | 🤖 Android",
55+
"--- | ---",
56+
`Fingerprint | ${state.fingerprint || "n/a"}`,
57+
`Dev client | ${state.client ? `[Install](${state.client})` : `Building on Blacksmith ([run](${runUrl})); this comment gets the install link when it finishes`}`,
58+
];
59+
if (state.group) {
60+
rows.push(
61+
`Update Details | [Update Permalink](https://expo.dev/projects/${PROJECT_ID}/updates/${state.group})`,
62+
`Update QR | <a href="${qr}"><img src="${qr}" width="250px" height="250px" /></a>`,
63+
);
64+
}
65+
return rows.join("\n");
66+
}
67+
68+
async function github(path, init = {}) {
69+
const response = await fetch(`https://api.github.com${path}`, {
70+
...init,
71+
headers: {
72+
authorization: `Bearer ${process.env.GH_TOKEN}`,
73+
accept: "application/vnd.github+json",
74+
"content-type": "application/json",
75+
...init.headers,
76+
},
77+
});
78+
if (!response.ok) {
79+
throw new Error(
80+
`GitHub ${init.method ?? "GET"} ${path}: ${response.status} ${await response.text()}`,
81+
);
82+
}
83+
return response.json();
84+
}
85+
86+
async function main() {
87+
const repository = process.env.GITHUB_REPOSITORY;
88+
const pr = process.env.PR;
89+
if (!repository || !pr || !process.env.GH_TOKEN) {
90+
throw new Error("GITHUB_REPOSITORY, PR and GH_TOKEN are required.");
91+
}
92+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${repository}/actions/runs/${process.env.GITHUB_RUN_ID}`;
93+
let existing = null;
94+
for (let page = 1; existing === null; page++) {
95+
const comments = await github(
96+
`/repos/${repository}/issues/${pr}/comments?per_page=100&page=${page}`,
97+
);
98+
// Only this workflow's own comment: anyone can post the marker, and nobody else's is editable.
99+
existing =
100+
comments.find(
101+
(comment) =>
102+
comment.user?.login === "github-actions[bot]" && readState(comment.body) !== null,
103+
) ?? null;
104+
if (comments.length < 100) break;
105+
}
106+
const state = mergeState(readState(existing?.body), {
107+
fingerprint: process.env.FINGERPRINT ?? "",
108+
client: process.env.CLIENT ?? "",
109+
group: process.env.GROUP ?? "",
110+
});
111+
const body = JSON.stringify({ body: render(state, runUrl) });
112+
if (existing) {
113+
await github(`/repos/${repository}/issues/comments/${existing.id}`, { method: "PATCH", body });
114+
} else {
115+
await github(`/repos/${repository}/issues/${pr}/comments`, { method: "POST", body });
116+
}
117+
}
118+
119+
if (require.main === module) {
120+
main().catch((error) => {
121+
console.error(error);
122+
process.exitCode = 1;
123+
});
124+
}
125+
126+
module.exports = { mergeState, readState, render };
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const assert = require("node:assert/strict");
2+
const test = require("node:test");
3+
4+
const { mergeState, readState, render } = require("./mobile-preview-comment.cjs");
5+
6+
const fingerprint = "c31608b37a8a2dca35ccee39cfd2ec7305042629";
7+
const run = "https://github.com/pingdotgg/t3code/actions/runs/1";
8+
9+
test("the comment round-trips its state", () => {
10+
const state = { fingerprint, client: "", group: "8e413a0a" };
11+
const body = render(state, run);
12+
assert.deepEqual(readState(body), state);
13+
assert.match(
14+
body,
15+
/Building on Blacksmith \(\[run\]\(https:\/\/github\.com\/pingdotgg\/t3code\/actions\/runs\/1\)\)/,
16+
);
17+
assert.match(
18+
body,
19+
/qr\.expo\.dev\/eas-update\?appScheme=t3-code&projectId=[0-9a-f-]+&groupId=8e413a0a/,
20+
);
21+
assert.equal(readState("🚀 Expo continuous deployment is ready!"), null);
22+
});
23+
24+
test("the build job adds the install link without losing the update", () => {
25+
const first = mergeState(null, { fingerprint, client: "", group: "8e413a0a" });
26+
const built = mergeState(first, { fingerprint, client: "https://expo.dev/a/b", group: "" });
27+
assert.deepEqual(built, { fingerprint, client: "https://expo.dev/a/b", group: "8e413a0a" });
28+
assert.match(render(built, run), /Dev client \| \[Install\]\(https:\/\/expo\.dev\/a\/b\)/);
29+
});
30+
31+
test("a new fingerprint drops the old client; the same one keeps it", () => {
32+
const built = { fingerprint, client: "https://expo.dev/a/b", group: "old" };
33+
assert.deepEqual(mergeState(built, { fingerprint, client: "", group: "new" }), {
34+
fingerprint,
35+
client: "https://expo.dev/a/b",
36+
group: "new",
37+
});
38+
assert.deepEqual(mergeState(built, { fingerprint: "f".repeat(40), client: "", group: "new" }), {
39+
fingerprint: "f".repeat(40),
40+
client: "",
41+
group: "new",
42+
});
43+
});
44+
45+
test("a build that finishes after the PR moved to another fingerprint changes nothing", () => {
46+
const current = { fingerprint: "f".repeat(40), client: "", group: "new" };
47+
assert.deepEqual(
48+
mergeState(current, { fingerprint, client: "https://expo.dev/a/b", group: "" }),
49+
current,
50+
);
51+
});
52+
53+
test("state from the comment is always three strings", () => {
54+
assert.deepEqual(
55+
readState('<!-- mobile-preview-android {"fingerprint":5,"client":null} -->\nx'),
56+
{
57+
fingerprint: "",
58+
client: "",
59+
group: "",
60+
},
61+
);
62+
});

‎.github/scripts/test-delta.cjs‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Counts the test cases a pull request adds and removes, from a zero-context diff, so PR Size can
2+
// say when a change grows the suite. Counting declarations keeps the number deterministic, unlike
3+
// CI timings, which move with runner load.
4+
const MARKER = "<!-- test-delta -->";
5+
const NET_CASES_TO_REPORT = 20;
6+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
7+
// `<` admits type arguments, as in `it.each<Row>(...)`, which may span lines.
8+
const TEST_CASE = /^\s*(?:it|test)(?:\.\w+)*\s*[(<]/;
9+
const isBrowserTest = (path) => path.includes(".browser.test.");
10+
11+
function kindOf(path) {
12+
if (isBrowserTest(path)) return "browser";
13+
if (path.startsWith("apps/server/") || path.includes(".integration.")) return "server";
14+
return "unit";
15+
}
16+
17+
/** @param {string} diff output of `git diff -U0 base...head` */
18+
function countTestDelta(diff) {
19+
const kinds = { browser: 0, server: 0, unit: 0 };
20+
const newBrowserFiles = [];
21+
let path = null;
22+
// A browser test file is new when it is added, or renamed from a file that was not one.
23+
let file = null;
24+
const flush = () => {
25+
if (file?.isNew && isBrowserTest(file.target)) newBrowserFiles.push(file.target);
26+
};
27+
for (const line of diff.split("\n")) {
28+
if (line.startsWith("diff --git ")) {
29+
flush();
30+
path = null;
31+
file = { target: line.replace(/^diff --git a\/\S+ b\//, ""), isNew: false };
32+
continue;
33+
}
34+
if (line.startsWith("new file mode") && file) file.isNew = true;
35+
if (line.startsWith("rename from ") && file) file.isNew = !isBrowserTest(line.slice(12));
36+
if (line.startsWith("--- ")) {
37+
const source = line.slice(4).replace(/^a\//, "");
38+
path = TEST_FILE.test(source) ? source : null;
39+
continue;
40+
}
41+
if (line.startsWith("+++ ")) {
42+
const target = line.slice(4).replace(/^b\//, "");
43+
// A deleted file's target is /dev/null; keep its old path to count the removed cases.
44+
if (target !== "/dev/null") path = TEST_FILE.test(target) ? target : null;
45+
continue;
46+
}
47+
if (line.startsWith("new file mode") || !path) continue;
48+
const sign = line[0] === "+" ? 1 : line[0] === "-" ? -1 : 0;
49+
if (sign !== 0 && TEST_CASE.test(line.slice(1))) kinds[kindOf(path)] += sign;
50+
}
51+
flush();
52+
return { kinds, net: kinds.browser + kinds.server + kinds.unit, newBrowserFiles };
53+
}
54+
55+
/** Returns the comment body, or null when the change does not grow the suite enough to mention. */
56+
function render(delta) {
57+
if (delta.net < NET_CASES_TO_REPORT && delta.newBrowserFiles.length === 0) return null;
58+
const signed = (n) => (n > 0 ? `+${n}` : String(n));
59+
const lines = [
60+
MARKER,
61+
`This PR changes the test suite by **${signed(delta.net)} test cases** ` +
62+
`(browser ${signed(delta.kinds.browser)}, unit ${signed(delta.kinds.unit)}, server ${signed(delta.kinds.server)}).`,
63+
];
64+
if (delta.newBrowserFiles.length > 0) {
65+
lines.push(
66+
"",
67+
`New browser test files: ${delta.newBrowserFiles.map((file) => `\`${file}\``).join(", ")}.`,
68+
"Each browser test file costs CI seconds of module loading before its first test runs; a unit test costs milliseconds.",
69+
);
70+
}
71+
lines.push(
72+
"",
73+
"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).",
74+
);
75+
return lines.join("\n");
76+
}
77+
78+
module.exports = { MARKER, countTestDelta, render };
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const assert = require("node:assert/strict");
2+
const test = require("node:test");
3+
4+
const { countTestDelta, render } = require("./test-delta.cjs");
5+
6+
const diff = `diff --git a/apps/web/src/Panel.browser.test.tsx b/apps/web/src/Panel.browser.test.tsx
7+
new file mode 100644
8+
--- /dev/null
9+
+++ b/apps/web/src/Panel.browser.test.tsx
10+
@@ -0,0 +1,4 @@
11+
+it("opens", async () => {});
12+
+ it.each<{ n: number }>([{ n: 1 }])("renders $n", async () => {});
13+
+// it("is a comment, still counted only when it starts the line")
14+
diff --git a/apps/server/src/thing.test.ts b/apps/server/src/thing.test.ts
15+
--- a/apps/server/src/thing.test.ts
16+
+++ b/apps/server/src/thing.test.ts
17+
@@ -3,2 +3,1 @@
18+
-it.effect("old", () => {});
19+
-test("older", () => {});
20+
+ it.effect("new", () => {});
21+
diff --git a/packages/shared/src/gone.test.ts b/packages/shared/src/gone.test.ts
22+
deleted file mode 100644
23+
--- a/packages/shared/src/gone.test.ts
24+
+++ /dev/null
25+
@@ -1,1 +0,0 @@
26+
-it("goes", () => {});
27+
diff --git a/apps/web/src/Menu.test.tsx b/apps/web/src/Menu.browser.test.tsx
28+
similarity index 100%
29+
rename from apps/web/src/Menu.test.tsx
30+
rename to apps/web/src/Menu.browser.test.tsx
31+
diff --git a/apps/web/src/Old.browser.test.tsx b/apps/web/src/New.browser.test.tsx
32+
similarity index 100%
33+
rename from apps/web/src/Old.browser.test.tsx
34+
rename to apps/web/src/New.browser.test.tsx
35+
diff --git a/apps/web/src/Panel.tsx b/apps/web/src/Panel.tsx
36+
--- a/apps/web/src/Panel.tsx
37+
+++ b/apps/web/src/Panel.tsx
38+
@@ -1 +1 @@
39+
+it("is not a test file", () => {});
40+
`;
41+
42+
test("counts cases by kind, including deleted files, and finds new or renamed browser files", () => {
43+
assert.deepEqual(countTestDelta(diff), {
44+
kinds: { browser: 2, server: -1, unit: -1 },
45+
net: 0,
46+
newBrowserFiles: ["apps/web/src/Panel.browser.test.tsx", "apps/web/src/Menu.browser.test.tsx"],
47+
});
48+
});
49+
50+
test("reports only growth worth a reviewer's attention", () => {
51+
const quiet = { kinds: { browser: 0, server: 3, unit: 5 }, net: 8, newBrowserFiles: [] };
52+
assert.equal(render(quiet), null);
53+
const growth = { kinds: { browser: 4, server: 10, unit: 12 }, net: 26, newBrowserFiles: [] };
54+
assert.match(render(growth), /\*\*\+26 test cases\*\* \(browser \+4, unit \+12, server \+10\)/);
55+
assert.match(
56+
render(countTestDelta(diff)),
57+
/New browser test files: `apps\/web\/src\/Panel\.browser\.test\.tsx`/,
58+
);
59+
});

0 commit comments

Comments
 (0)