Skip to content

Commit d6d0b1d

Browse files
authored
chore: sync with upstream pingdotgg/t3code main (#54)
2 parents ada8049 + 6af6e9f commit d6d0b1d

295 files changed

Lines changed: 6064 additions & 6030 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.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 workflow = readFileSync(join(__dirname, "../workflows/release.yml"), "utf8");
9+
const step = workflow.match(
10+
/- name: Read production relay tracing config\n[\s\S]*? run: \|\n((?: .*\n|\n)+)/,
11+
);
12+
assert.ok(step, "Could not find the relay state workflow step");
13+
const script = step[1].replace(/^ /gm, "");
14+
const config = {
15+
clientTracingUrl: "https://example.invalid/traces",
16+
clientTracingDataset: "fixture-dataset",
17+
clientTracingToken: { __redacted__: "fixture-token" },
18+
};
19+
const json = JSON.stringify(config, null, 2);
20+
21+
function runStep(stdout, exitCode = 0) {
22+
const runnerTemp = mkdtempSync(join(tmpdir(), "t3-relay-state-test-"));
23+
try {
24+
const result = spawnSync(
25+
"bash",
26+
["-c", 'npx() { printf "%s\\n" "$FIXTURE_STDOUT"; return "$FIXTURE_EXIT"; }\n' + script],
27+
{
28+
encoding: "utf8",
29+
env: {
30+
PATH: process.env.PATH,
31+
RUNNER_TEMP: runnerTemp,
32+
FIXTURE_STDOUT: stdout,
33+
FIXTURE_EXIT: String(exitCode),
34+
},
35+
},
36+
);
37+
assert.ifError(result.error);
38+
const envPath = join(runnerTemp, "relay-client-tracing.env");
39+
return {
40+
...result,
41+
envFile: existsSync(envPath) ? readFileSync(envPath, "utf8") : undefined,
42+
};
43+
} finally {
44+
rmSync(runnerTemp, { recursive: true, force: true });
45+
}
46+
}
47+
48+
for (const prefix of [
49+
"",
50+
"• Refreshing Cloudflare State Store credentials\n✓ Refreshing Cloudflare State Store credentials\n",
51+
]) {
52+
test(`extracts tracing config ${prefix ? "after progress output" : "from plain JSON"}`, () => {
53+
const result = runStep(prefix + json);
54+
assert.equal(result.status, 0, result.stderr);
55+
assert.equal(result.stdout, "::add-mask::fixture-token\n");
56+
assert.equal(
57+
result.envFile,
58+
"T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://example.invalid/traces\n" +
59+
"T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=fixture-dataset\n" +
60+
"T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=fixture-token\n",
61+
);
62+
});
63+
}
64+
65+
for (const [name, stdout, exitCode] of [
66+
["failed CLI even with valid JSON", json, 1],
67+
["missing JSON", "Refreshing credentials...", 0],
68+
["malformed JSON", "{not JSON", 0],
69+
["missing token", JSON.stringify({ ...config, clientTracingToken: null }, null, 2), 0],
70+
]) {
71+
test(`rejects ${name} without writing config`, () => {
72+
const result = runStep(stdout, exitCode);
73+
assert.notEqual(result.status, 0);
74+
assert.equal(result.envFile, undefined);
75+
});
76+
}

‎.github/workflows/mobile-fingerprint-check.yml‎

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,9 @@ name: Mobile Fingerprint Check
1313
# pnpm), so the comparison is self-consistent; no EXPO_TOKEN needed.
1414
on:
1515
pull_request:
16-
paths:
17-
- apps/mobile/**
18-
- packages/client-runtime/**
19-
- packages/contracts/**
20-
- packages/shared/**
21-
- assets/**
22-
- scripts/**
23-
- patches/**
24-
- pnpm-lock.yaml
25-
- pnpm-workspace.yaml
26-
- .github/workflows/mobile-fingerprint-check.yml
16+
# Run even when a rebase or base change removes every native input from the
17+
# diff, so the label can be cleared without installing Expo dependencies.
18+
types: [opened, synchronize, reopened, edited]
2719

2820
concurrency:
2921
group: mobile-fingerprint-check-${{ github.event.pull_request.number }}
@@ -44,12 +36,29 @@ jobs:
4436
- name: Checkout
4537
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
4638
with:
47-
# Default pull_request checkout is the merge commit (PR applied on
48-
# top of base), so the "head" fingerprint is the state main would
49-
# actually be in after merging — stale branches compare cleanly.
50-
fetch-depth: 0
39+
# The merge ref can advance after the event is queued. Pin its commit
40+
# and compare against its first parent, rather than the event's base.
41+
ref: ${{ github.sha }}
42+
fetch-depth: 2
43+
44+
- id: changes
45+
name: Detect native fingerprint inputs
46+
run: |
47+
base_sha=$(git rev-parse HEAD^1)
48+
echo "base_sha=$base_sha" >> "$GITHUB_OUTPUT"
49+
paths=$(git diff --no-renames --name-only "$base_sha" HEAD -- \
50+
apps/mobile/ packages/client-runtime/ packages/contracts/ packages/shared/ \
51+
assets/ scripts/ patches/ package.json pnpm-lock.yaml pnpm-workspace.yaml \
52+
.github/workflows/mobile-fingerprint-check.yml)
53+
if [[ -n "$paths" ]]; then
54+
echo "relevant=true" >> "$GITHUB_OUTPUT"
55+
else
56+
echo "relevant=false" >> "$GITHUB_OUTPUT"
57+
echo "No native fingerprint inputs changed; clearing any stale native change label." >> "$GITHUB_STEP_SUMMARY"
58+
fi
5159
5260
- name: Setup Vite+
61+
if: steps.changes.outputs.relevant == 'true'
5362
uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1.15.0
5463
with:
5564
node-version-file: package.json
@@ -59,13 +68,15 @@ jobs:
5968
- --filter=@t3tools/mobile...
6069
6170
- name: Expose pnpm
71+
if: steps.changes.outputs.relevant == 'true'
6272
run: |
6373
pnpm_version="$(node --print "require('./package.json').packageManager.split('@').pop()")"
6474
vp_pnpm_bin="$HOME/.vite-plus/package_manager/pnpm/$pnpm_version/pnpm/bin"
6575
echo "$vp_pnpm_bin" >> "$GITHUB_PATH"
6676
"$vp_pnpm_bin/pnpm" --version
6777
6878
- name: Fingerprint merge result
79+
if: steps.changes.outputs.relevant == 'true'
6980
working-directory: apps/mobile
7081
run: |
7182
mkdir -p "$RUNNER_TEMP/fp/head" "$RUNNER_TEMP/fp/base"
@@ -74,8 +85,11 @@ jobs:
7485
done
7586
7687
- name: Fingerprint base
88+
if: steps.changes.outputs.relevant == 'true'
89+
env:
90+
BASE_SHA: ${{ steps.changes.outputs.base_sha }}
7791
run: |
78-
git checkout --quiet "${{ github.event.pull_request.base.sha }}"
92+
git checkout --quiet "$BASE_SHA"
7993
# Re-sync node_modules to the base commit's lockfile before
8094
# fingerprinting — a dep-changing PR must not fingerprint the base
8195
# against head's installed packages.
@@ -87,6 +101,7 @@ jobs:
87101
88102
- id: compare
89103
name: Compare fingerprints
104+
if: steps.changes.outputs.relevant == 'true'
90105
run: |
91106
changed=""
92107
{

‎.github/workflows/release.yml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,18 @@ jobs:
324324
- --filter=t3code-relay...
325325
326326
# The deployed stack's outputs, read from Alchemy's state store without
327-
# planning or applying. Redacted values are persisted as
327+
# planning or applying. Select the backend explicitly to avoid loading
328+
# the stack's unrelated provider credentials; suppress informational logs
329+
# and strip the credential-refresh progress prefix before parsing JSON.
330+
# Redacted values are persisted as
328331
# {"__redacted__": "<value>"}; the token is masked before it is written.
329332
- name: Read production relay tracing config
330333
if: steps.creds.outputs.configured == 'true'
331334
shell: bash
332335
working-directory: infra/relay
333336
run: |
334337
set -euo pipefail
335-
output="$(npx alchemy state read T3CodeRelay/prod/output --no-input)"
338+
output="$(npx alchemy state read T3CodeRelay/prod/output --backend cloudflare --log-level error --no-input | sed -n '/^{/,$p')"
336339
field() {
337340
jq -er --arg key "$1" '.[$key] | if type == "object" then .__redacted__ else . end | select(. != null and . != "")' <<<"$output" \
338341
|| { echo "Relay stack output is missing $1" >&2; exit 1; }

‎apps/desktop/src/app/DesktopAppIdentity.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ const makeElectronAppLayer = (calls: ElectronAppCalls) =>
5757
}),
5858
setAppUserModelId: () => Effect.void,
5959
getAppMetrics: Effect.succeed([]),
60-
isDefaultProtocolClient: () => Effect.succeed(false),
6160
setAsDefaultProtocolClient: () => Effect.succeed(true),
6261
setDesktopName: () => Effect.void,
6362
setDockIcon: (iconPath) =>

‎apps/desktop/src/app/DesktopConnectionCatalogStore.test.ts‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { assert, describe, it } from "@effect/vitest";
33
import { ConnectionCatalogDocument } from "@t3tools/client-runtime/platform";
44
import { EnvironmentId, type PersistedSavedEnvironmentRecord } from "@t3tools/contracts";
55
import * as Effect from "effect/Effect";
6+
import * as Encoding from "effect/Encoding";
67
import * as FileSystem from "effect/FileSystem";
78
import * as Path from "effect/Path";
89
import * as Layer from "effect/Layer";
@@ -22,6 +23,11 @@ const textEncoder = new TextEncoder();
2223
const decodeConnectionCatalog = Schema.decodeEffect(
2324
Schema.fromJsonString(ConnectionCatalogDocument),
2425
);
26+
const encodeLegacySavedEnvironments = Schema.encodeEffect(
27+
Schema.fromJsonString(
28+
Schema.Struct({ version: Schema.Literal(1), records: Schema.Array(Schema.Unknown) }),
29+
),
30+
);
2531
function makeSafeStorageLayer(available: boolean, failDecrypt: Ref.Ref<boolean> | null = null) {
2632
return Layer.succeed(ElectronSafeStorage.ElectronSafeStorage, {
2733
isEncryptionAvailable: Effect.succeed(available),
@@ -125,7 +131,8 @@ describe("DesktopConnectionCatalogStore", () => {
125131
withStore(
126132
Effect.gen(function* () {
127133
const store = yield* DesktopConnectionCatalogStore.DesktopConnectionCatalogStore;
128-
const savedEnvironments = yield* DesktopSavedEnvironments.DesktopSavedEnvironments;
134+
const environment = yield* DesktopEnvironment.DesktopEnvironment;
135+
const fileSystem = yield* FileSystem.FileSystem;
129136
const records: readonly PersistedSavedEnvironmentRecord[] = [
130137
{
131138
environmentId: EnvironmentId.make("relay-environment"),
@@ -159,11 +166,21 @@ describe("DesktopConnectionCatalogStore", () => {
159166
lastConnectedAt: null,
160167
},
161168
];
162-
yield* savedEnvironments.setRegistry(records);
163-
assert.isTrue(
164-
yield* savedEnvironments.setSecret({
165-
environmentId: EnvironmentId.make("bearer-environment"),
166-
secret: "legacy-token",
169+
yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true });
170+
yield* fileSystem.writeFileString(
171+
environment.savedEnvironmentRegistryPath,
172+
yield* encodeLegacySavedEnvironments({
173+
version: 1,
174+
records: records.map((record) =>
175+
record.environmentId === "bearer-environment"
176+
? {
177+
...record,
178+
encryptedBearerToken: Encoding.encodeBase64(
179+
textEncoder.encode("encrypted:legacy-token"),
180+
),
181+
}
182+
: record,
183+
),
167184
}),
168185
);
169186

@@ -218,7 +235,10 @@ describe("DesktopConnectionCatalogStore", () => {
218235
assert.equal(catalog.credentials[0].credential.token, "legacy-token");
219236
}
220237

221-
yield* savedEnvironments.setRegistry([]);
238+
yield* fileSystem.writeFileString(
239+
environment.savedEnvironmentRegistryPath,
240+
'{"version":1,"records":[]}',
241+
);
222242
assert.deepEqual(yield* store.get, migrated);
223243
}),
224244
),

‎apps/desktop/src/app/DesktopLifecycle.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function makeElectronAppLayer(
4343
setAboutPanelOptions: () => Effect.void,
4444
setAppUserModelId: () => Effect.void,
4545
getAppMetrics: Effect.succeed([]),
46-
isDefaultProtocolClient: () => Effect.succeed(false),
4746
setAsDefaultProtocolClient: () => Effect.succeed(true),
4847
setDesktopName: () => Effect.void,
4948
setDockIcon: () => Effect.void,

0 commit comments

Comments
 (0)