Skip to content

Commit 866e273

Browse files
Merge origin/main into fix/issue-16815
2 parents fdbd4b4 + 9179178 commit 866e273

87 files changed

Lines changed: 2618 additions & 235 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/ci-changes.cjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// node ci-changes.cjs --paths <file> --full run every Linux job, gate only the macOS lint
66
// node ci-changes.cjs changed paths unknown: run everything
77
//
8+
// scripts/check-changed.ts requires the same decisions so local runs match CI.
9+
//
810
// Every changed path maps to workspace packages, which then pull in their
911
// dependents from package.json. A path this file does not recognize runs
1012
// everything, so a new root file or directory can only cost minutes.
@@ -201,4 +203,6 @@ function main() {
201203
for (const [key, value] of Object.entries(outputs)) console.log(`${key}=${value}`);
202204
}
203205

204-
main();
206+
module.exports = { readWorkspace, decide };
207+
208+
if (require.main === module) main();

‎.github/scripts/ci-changes.d.cts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
interface WorkspacePackage {
2+
readonly name: string;
3+
readonly dir: string;
4+
readonly hasTest: boolean;
5+
readonly deps: ReadonlyArray<string>;
6+
}
7+
8+
export function readWorkspace(): Array<WorkspacePackage>;
9+
10+
export function decide(
11+
files: ReadonlyArray<string> | null,
12+
packages: ReadonlyArray<WorkspacePackage>,
13+
full: boolean,
14+
): {
15+
affected: Array<string>;
16+
outputs: {
17+
typecheck: boolean;
18+
build: boolean;
19+
test: boolean;
20+
test_packages: string;
21+
test_web: boolean;
22+
test_server: boolean;
23+
rust: boolean;
24+
release_smoke: boolean;
25+
mobile_native: boolean;
26+
};
27+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const assert = require("node:assert/strict");
2+
const { spawnSync } = require("node:child_process");
3+
const { mkdtempSync, readFileSync, rmSync, existsSync } = require("node:fs");
4+
const { tmpdir } = require("node:os");
5+
const { join } = require("node:path");
6+
const { test } = require("node:test");
7+
8+
const release = readFileSync(join(__dirname, "../workflows/release.yml"), "utf8");
9+
const preview = readFileSync(join(__dirname, "../workflows/web-preview.yml"), "utf8");
10+
const stepPattern =
11+
/ name: (?:Build staged deployment|Deploy preview)\n shell: bash\n run: \|\n((?: .*\n|\n)+)/g;
12+
const steps = [
13+
...Array.from(release.matchAll(stepPattern), (match, index) => [
14+
index === 0 ? "hosted web" : "marketing",
15+
match[1],
16+
]),
17+
...Array.from(preview.matchAll(stepPattern), (match) => ["web preview", match[1]]),
18+
];
19+
assert.equal(steps.length, 3, "Expected both release steps and the preview step");
20+
21+
const url = "https://t3code-fixture-pinglabs.vercel.app";
22+
const warning = 'Error while parsing config file: "/runner/t3code/pnpm-lock.yaml"';
23+
24+
function runStep(script, stdout, exitCode = 0) {
25+
const directory = mkdtempSync(join(tmpdir(), "t3-vercel-output-"));
26+
const outputFile = join(directory, "output");
27+
try {
28+
const result = spawnSync(
29+
"bash",
30+
[
31+
"-c",
32+
'vp() { printf "%s\\n" "$FIXTURE_STDOUT"; return "$FIXTURE_EXIT"; }\n' +
33+
'curl() { printf \'{"id":"fixture-project"}\\n\'; }\n' +
34+
script.replace(/^ /gm, "").replace(/\$\{\{.*?\}\}/g, "fixture"),
35+
],
36+
{
37+
encoding: "utf8",
38+
env: {
39+
PATH: process.env.PATH,
40+
VERCEL_TOKEN: "fixture-token",
41+
VERCEL_ORG_ID: "fixture-org",
42+
VERCEL_PROJECT_ID: "fixture-project",
43+
GITHUB_OUTPUT: outputFile,
44+
FIXTURE_STDOUT: stdout,
45+
FIXTURE_EXIT: String(exitCode),
46+
},
47+
},
48+
);
49+
assert.ifError(result.error);
50+
return {
51+
...result,
52+
output: existsSync(outputFile) ? readFileSync(outputFile, "utf8") : "",
53+
};
54+
} finally {
55+
rmSync(directory, { recursive: true, force: true });
56+
}
57+
}
58+
59+
for (const [name, script] of steps) {
60+
for (const [label, stdout] of [
61+
["plain URL", url],
62+
["lockfile warning", `${warning}\n${url}`],
63+
["trailing diagnostic", `${url}\nDone`],
64+
]) {
65+
test(`${name}: saves one deployment URL after ${label}`, () => {
66+
const result = runStep(script, stdout);
67+
assert.equal(result.status, 0, result.stderr);
68+
assert.deepEqual(
69+
result.output.split("\n").filter((line) => !line.startsWith("project_id=")),
70+
[`deployment_url=${url}`, ""],
71+
);
72+
});
73+
}
74+
75+
for (const [label, stdout, exitCode] of [
76+
["missing URL", warning, 0],
77+
["invalid URL", "https://example.invalid/deployment", 0],
78+
["multiple URLs", `${url}\nhttps://other.vercel.app`, 0],
79+
["failed deployment", url, 1],
80+
]) {
81+
test(`${name}: rejects ${label} without saving output`, () => {
82+
const result = runStep(script, stdout, exitCode);
83+
assert.notEqual(result.status, 0);
84+
assert.equal(result.output, "");
85+
});
86+
}
87+
}

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ jobs:
253253
run: python3 -B .github/scripts/stage-preview-bundle.test.py
254254

255255
- name: Test release checks
256-
run: node --test .github/scripts/check-nightly-release.test.cjs
256+
run: node --test .github/scripts/check-nightly-release.test.cjs .github/scripts/vercel-deployment-output.test.cjs
257257

258258
- name: Finish installing browser secret helper build libraries
259259
timeout-minutes: 5

‎.github/workflows/release.yml‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ jobs:
10721072
fi
10731073
10741074
echo "Building hosted web app for $channel_name channel."
1075-
deployment_url="$(
1075+
deployment_output="$(
10761076
vp dlx [email protected] deploy \
10771077
--archive=tgz \
10781078
--prod \
@@ -1091,6 +1091,13 @@ jobs:
10911091
--build-env "VITE_HOSTED_APP_URL=$router_url" \
10921092
--build-env "VITE_HOSTED_APP_CHANNEL=$channel_name"
10931093
)"
1094+
printf '%s\n' "$deployment_output"
1095+
# Vercel can print lockfile warnings to stdout before the deployment URL.
1096+
deployment_url="$(printf '%s\n' "$deployment_output" | grep -E '^https://[[:alnum:].-]+\.vercel\.app$')"
1097+
if [[ "$deployment_url" == *$'\n'* ]]; then
1098+
echo "Vercel returned multiple deployment URLs." >&2
1099+
exit 1
1100+
fi
10941101
echo "Staged $deployment_url."
10951102
echo "deployment_url=$deployment_url" >> "$GITHUB_OUTPUT"
10961103
@@ -1219,7 +1226,7 @@ jobs:
12191226
)"
12201227
export VERCEL_PROJECT_ID
12211228
1222-
deployment_url="$(
1229+
deployment_output="$(
12231230
vp dlx [email protected] deploy \
12241231
--archive=tgz \
12251232
--prod \
@@ -1228,6 +1235,13 @@ jobs:
12281235
--token "$VERCEL_TOKEN" \
12291236
--scope "${VERCEL_TEAM_SLUG:-$VERCEL_ORG_ID}"
12301237
)"
1238+
printf '%s\n' "$deployment_output"
1239+
# Vercel can print lockfile warnings to stdout before the deployment URL.
1240+
deployment_url="$(printf '%s\n' "$deployment_output" | grep -E '^https://[[:alnum:].-]+\.vercel\.app$')"
1241+
if [[ "$deployment_url" == *$'\n'* ]]; then
1242+
echo "Vercel returned multiple deployment URLs." >&2
1243+
exit 1
1244+
fi
12311245
echo "Staged $deployment_url."
12321246
echo "deployment_url=$deployment_url" >> "$GITHUB_OUTPUT"
12331247
echo "project_id=$VERCEL_PROJECT_ID" >> "$GITHUB_OUTPUT"

‎.github/workflows/web-preview.yml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,20 @@ jobs:
7777
7878
vercel_scope="${VERCEL_TEAM_SLUG:-$VERCEL_ORG_ID}"
7979
80-
deployment_url="$(
80+
deployment_output="$(
8181
vp dlx [email protected] deploy \
8282
--archive=tgz \
8383
--yes \
8484
--token "$VERCEL_TOKEN" \
8585
--scope "$vercel_scope"
8686
)"
87+
printf '%s\n' "$deployment_output"
88+
# Vercel can print lockfile warnings to stdout before the deployment URL.
89+
deployment_url="$(printf '%s\n' "$deployment_output" | grep -E '^https://[[:alnum:].-]+\.vercel\.app$')"
90+
if [[ "$deployment_url" == *$'\n'* ]]; then
91+
echo "Vercel returned multiple deployment URLs." >&2
92+
exit 1
93+
fi
8794
8895
echo "Deployed $deployment_url"
8996
echo "deployment_url=$deployment_url" >> "$GITHUB_OUTPUT"

‎.vercelignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Vercel's default .pnp* rule also excludes pnpm's hook, whose checksum is in the lockfile.
2+
!/.pnpmfile.cjs

‎AGENTS.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
9898

9999
## Verifying
100100

101-
- Smallest proof that the change works. `vp test run <files>` for the tests you touched (`-t "<name>"` in big files), `vp lint <files>`, and `vp run typecheck` in the package you changed. Not `npx tsc`; it is 3x slower than tsc-rs.
102-
- Run `vp run knip:check` (about 35 s) when you add, remove, or rename exports, files, or dependencies.
101+
- Before you push, run `vp run check:changed`. It runs CI's fast checks for changed files: format, lint, knip, typecheck of affected packages and dependents, and tests beside changes. CI still runs the full test suites.
102+
- While you iterate, run `vp test run <files>`. For big files, add `-t "<name>"`.
103+
- Do not use `npx tsc`. Use `vp run typecheck`; it uses tsc-rs, which is 3x faster.
103104
- Run `node -e` snippets from `apps/server` or the owning package. `effect` does not resolve from the repo root.
104105
- Test meaningful logic or observable behavior. Do not render components to static markup to assert props or attributes, or add tests that merely assert callback wiring or mirror the implementation.
105106
- **Do not run repo-wide checks.** No `vp check`, no `vp run -r test`, no `vp run -r typecheck` unless I ask. CI owns the full suite.
106107
- Backend behavior changes ship with focused tests for that behavior.
108+
- Proof for a bug fix depends on the bug. Logic, data, state, and protocol bugs get a failing test first (the fewest that fail on `main` for that reason, in the module's existing test file), then the fix. Purely visual bugs (spacing, colour, alignment, a layout shift) get before/after captures as their proof and no test: do not add UI tests for nitpicks, and do not ask for one in review when a capture already shows it. A server-only fix with no visible surface ships the test plus a short runtime transcript.
107109
- The server is event-sourced, and side effects run after the command commits. In tests, drain the effect worker (`OrchestrationEffectWorkerV2.drain`) or await the specific persisted event or `Deferred` that marks the milestone. Never wait on sleeps or polling. A test that needs a timeout to pass is wrong. Concretely:
108110
- `it.effect` runs on a `TestClock`; `Effect.sleep` only advances through `TestClock.adjust`. `it.live` is wall-clock and only for subprocess or network fixtures.
109111
- No `yieldNow` or `sleep` polling loops. Await the `Deferred`, take from the `Queue`, or drain the worker.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { assert, describe, it } from "@effect/vitest";
2+
3+
import { createClerkOAuthCancel } from "./clerkOAuthCancel.ts";
4+
5+
const deferredOpen = () => {
6+
const resolvers: Array<(value: { callbackUrl: string }) => void> = [];
7+
const opened: Array<Promise<{ callbackUrl: string }>> = [];
8+
const open = (_url: string) => {
9+
const promise = new Promise<{ callbackUrl: string }>((resolve) => {
10+
resolvers.push(resolve);
11+
});
12+
opened.push(promise);
13+
return promise;
14+
};
15+
return { open, resolvers, opened };
16+
};
17+
18+
const outcome = (promise: Promise<{ callbackUrl: string }>) =>
19+
promise.then(
20+
({ callbackUrl }) => `resolved ${callbackUrl}`,
21+
(error: Error) => `rejected ${error.message}`,
22+
);
23+
24+
describe("createClerkOAuthCancel", () => {
25+
it("cancel rejects the pending flow and reports it is no longer pending", async () => {
26+
const oauth = createClerkOAuthCancel();
27+
const changes: boolean[] = [];
28+
oauth.onPendingChange((pending) => changes.push(pending));
29+
const { open } = deferredOpen();
30+
31+
const flow = outcome(oauth.wrapOpen(open)("https://accounts.example/a"));
32+
assert.isTrue(oauth.isPending());
33+
oauth.cancel();
34+
35+
assert.strictEqual(await flow, "rejected Clerk: OAuth flow was cancelled.");
36+
assert.isFalse(oauth.isPending());
37+
assert.deepStrictEqual(changes, [true, false]);
38+
});
39+
40+
it("a new attempt replaces the pending one, and the old result cannot clear it", async () => {
41+
const oauth = createClerkOAuthCancel();
42+
const { open, resolvers, opened } = deferredOpen();
43+
const wrapped = oauth.wrapOpen(open);
44+
45+
const first = outcome(wrapped("https://accounts.example/a"));
46+
const second = outcome(wrapped("https://accounts.example/b"));
47+
assert.strictEqual(await first, "rejected Clerk: OAuth flow was cancelled.");
48+
49+
resolvers[0]?.({ callbackUrl: "t3code://app/?a" });
50+
// Two hops, so the wrapper's own `.then().finally()` on this result has run.
51+
await opened[0]?.then(() => undefined).then(() => undefined);
52+
assert.isTrue(oauth.isPending());
53+
54+
resolvers[1]?.({ callbackUrl: "t3code://app/?b" });
55+
assert.strictEqual(await second, "resolved t3code://app/?b");
56+
assert.isFalse(oauth.isPending());
57+
});
58+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
type OAuthOpen = (url: string) => Promise<{ callbackUrl: string }>;
2+
3+
/**
4+
* Lets the app cancel the Clerk OAuth flow the renderer is waiting on. The
5+
* system browser never reports a closed tab, so an abandoned sign-in would
6+
* otherwise keep Clerk's sheet spinning until Clerk's 180s timeout.
7+
*
8+
* Pass `wrapOpen` to `exposeClerkBridge` as `wrapOAuthOpen`. Cancelling only
9+
* rejects the renderer's promise; the patched main process replaces the stale
10+
* flow when the next attempt starts.
11+
*/
12+
export function createClerkOAuthCancel() {
13+
let cancelPending: (() => void) | null = null;
14+
const listeners = new Set<(pending: boolean) => void>();
15+
const setCancelPending = (cancel: (() => void) | null) => {
16+
cancelPending = cancel;
17+
for (const listener of listeners) listener(cancel !== null);
18+
};
19+
20+
return {
21+
wrapOpen:
22+
(open: OAuthOpen): OAuthOpen =>
23+
(url) => {
24+
cancelPending?.();
25+
return new Promise((resolve, reject) => {
26+
const settle = () => {
27+
if (cancelPending === cancel) setCancelPending(null);
28+
};
29+
const cancel = () => {
30+
settle();
31+
reject(new Error("Clerk: OAuth flow was cancelled."));
32+
};
33+
setCancelPending(cancel);
34+
open(url).then(resolve, reject).finally(settle);
35+
});
36+
},
37+
isPending: () => cancelPending !== null,
38+
onPendingChange: (listener: (pending: boolean) => void) => {
39+
listeners.add(listener);
40+
return () => {
41+
listeners.delete(listener);
42+
};
43+
},
44+
cancel: () => cancelPending?.(),
45+
};
46+
}

0 commit comments

Comments
 (0)