Skip to content

Commit 6d4d152

Browse files
fix: resolve mobile validation regressions and stabilize platform tests (#111)
* fix(mobile): preserve fork signing and honor inspector platform behavior * fix(server): settle memory startup failures and preserve SQLite arrays * test: isolate host dependencies and select the correct runners * perf(web): keep streaming cache and minimap updates local * test(peer): surface the failure when a chosen machine cannot link * fix(persistence): repair previously serialized model options Add migration 097 to repair model option arrays that migration 026 already stored as JSON strings in projections and affected event payloads. Preserve canonical values and unrelated data, including invalid non-array strings. Cover already-migrated databases, v2 project baselines, boolean and empty arrays, repeat startup, and byte-identical canonical records. Implemented and reviewed with GPT-6 Astra Pro in ChatGPT. * test(persistence): include model option repair in preview upgrades
1 parent 1c4c054 commit 6d4d152

27 files changed

Lines changed: 800 additions & 451 deletions

‎apps/mobile/README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID=com.example.t3code.dev \
9393
vp run ios:dev
9494
```
9595

96-
Build and install a self-contained Release app that does not need Metro:
96+
Build and install a self-contained Release app that does not need Metro. Select your device
97+
when prompted. Signing uses Xcode automatic signing and its Keychain certificate and cached
98+
provisioning profile. Set `T3CODE_IOS_TEAM_ID` in the root's Git-ignored `.env.local` to select
99+
your own Apple team; keep the same team and bundle ID when updating an installed app.
97100

98101
```bash
99102
vp run ios:release

‎apps/mobile/app.config.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import assetLinks from "../web/public/.well-known/assetlinks.json";
1010
vi.mock("../../scripts/lib/public-config.ts", () => ({
1111
loadRepoEnv: () => ({
1212
APP_VARIANT: process.env.APP_VARIANT,
13+
T3CODE_IOS_TEAM_ID: process.env.T3CODE_IOS_TEAM_ID,
14+
T3CODE_IOS_PERSONAL_TEAM: process.env.T3CODE_IOS_PERSONAL_TEAM,
15+
T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID: process.env.T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID,
1316
T3CODE_MOBILE_UPDATES_ENABLED: process.env.T3CODE_MOBILE_UPDATES_ENABLED,
1417
T3CODE_MOBILE_EAS_PROJECT_ID: process.env.T3CODE_MOBILE_EAS_PROJECT_ID,
1518
T3CODE_MOBILE_EAS_OWNER: process.env.T3CODE_MOBILE_EAS_OWNER,
@@ -27,6 +30,9 @@ async function loadConfig(
2730
vi.resetModules();
2831
vi.stubEnv("APP_VARIANT", variant);
2932
for (const name of [
33+
"T3CODE_IOS_TEAM_ID",
34+
"T3CODE_IOS_PERSONAL_TEAM",
35+
"T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID",
3036
"T3CODE_MOBILE_UPDATES_ENABLED",
3137
"T3CODE_MOBILE_EAS_PROJECT_ID",
3238
"T3CODE_MOBILE_EAS_OWNER",
@@ -131,3 +137,21 @@ async function nativeUpdatesConfig(config: Awaited<ReturnType<typeof loadConfig>
131137
);
132138
return { ios, android };
133139
}
140+
141+
it("preserves the installed fork identity for direct iPhone updates", async () => {
142+
const config = await loadConfig("preview", {
143+
T3CODE_IOS_TEAM_ID: "EXAMPLE123",
144+
T3CODE_IOS_PERSONAL_TEAM: "1",
145+
T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID: "com.example.t3code",
146+
});
147+
expect(config.ios?.appleTeamId).toBe("EXAMPLE123");
148+
expect(config.ios?.bundleIdentifier).toBe("com.example.t3code");
149+
expect(config.ios?.entitlements?.["keychain-access-groups"]).toEqual([
150+
"$(AppIdentifierPrefix)com.t3tools.t3code.preview",
151+
]);
152+
expect(config.extra?.iosPersonalTeamBuild).toBe(true);
153+
expect(config.plugins).toContainEqual([
154+
"expo-notifications",
155+
expect.objectContaining({ mode: "development" }),
156+
]);
157+
});

‎apps/mobile/app.config.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const config: ExpoConfig = {
263263
requireFullScreen: process.env.T3_SHOWCASE_CAPTURE_BUILD === "1",
264264
bundleIdentifier: iosBundleIdentifier,
265265
// Avoid Personal Team fallback: it cannot sign App Groups, Apple sign-in or push entitlements.
266-
appleTeamId: "ARK85ZXQ4Z",
266+
appleTeamId: repoEnv.T3CODE_IOS_TEAM_ID?.trim() || "ARK85ZXQ4Z",
267267
associatedDomains: [
268268
`applinks:${variant.relyingParty}`,
269269
`webcredentials:${variant.relyingParty}`,
@@ -367,7 +367,8 @@ const config: ExpoConfig = {
367367
{
368368
icon: variant.assets.androidNotificationIcon,
369369
color: variant.assets.androidNotificationColor,
370-
mode: APP_VARIANT === "development" ? "development" : "production",
370+
mode:
371+
isIosPersonalTeamBuild || APP_VARIANT === "development" ? "development" : "production",
371372
},
372373
],
373374
// Gate Clerk here: withoutIosPersonalTeamCapabilities runs too early to strip its entitlement.

‎apps/mobile/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"ios:dev": "APP_VARIANT=development EXPO_NO_GIT_STATUS=1 expo prebuild --clean --platform ios && expo run:ios",
2828
"ios:preview": "APP_VARIANT=preview EXPO_NO_GIT_STATUS=1 expo prebuild --clean --platform ios && expo run:ios",
2929
"ios:prod": "APP_VARIANT=production EXPO_NO_GIT_STATUS=1 expo prebuild --clean --platform ios && expo run:ios",
30-
"ios:release": "APP_VARIANT=production EXPO_NO_GIT_STATUS=1 expo prebuild --clean --platform ios && expo run:ios --configuration Release --no-bundler",
30+
"ios:release": "EXPO_NO_GIT_STATUS=1 expo prebuild --clean --platform ios && expo run:ios --configuration Release --no-bundler",
3131
"eas:ios:dev": "eas build --profile development -p ios",
3232
"eas:ios:preview": "eas build --profile preview -p ios",
3333
"eas:ios:preview:dev": "eas build --profile preview:dev -p ios",

‎apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as NodePath from "node:path";
22
import * as NodeModule from "node:module";
33
import * as React from "react";
4+
import { Platform } from "react-native";
45
import { act, useLayoutEffect } from "react";
56
import { createRoot } from "react-dom/client";
67
import { expect, it, vi } from "vite-plus/test";
@@ -11,7 +12,7 @@ const harness = vi.hoisted(() => ({
1112
getRoute: (): unknown => undefined,
1213
}));
1314

14-
vi.mock("react-native", () => ({ Platform: { OS: "ios" } }));
15+
vi.mock("react-native", () => ({ Platform: { OS: process.env.T3_MOBILE_TEST_PLATFORM ?? "ios" } }));
1516
vi.mock("../layout/AdaptiveWorkspaceLayout", () => ({
1617
useWorkspacePaneState: () => ({ fileInspector: { supported: true } }),
1718
}));
@@ -107,7 +108,14 @@ it("opens a subagent from the Agents sheet without replacing the parent thread",
107108
environmentId: screen.source.environmentId,
108109
threadId: "child",
109110
} as const;
110-
screen.open(inspector);
111+
const originalState = screen.state;
112+
const opened = screen.open(inspector);
113+
if (Platform.OS === "android") {
114+
expect(opened).toBe(false);
115+
expect(screen.state).toEqual(originalState);
116+
return;
117+
}
118+
expect(opened).toBe(true);
111119
expect(screen.state.routes.map((route) => route.name)).toEqual(["Home", "Thread"]);
112120
expect(screen.state.routes.at(-1)).toMatchObject({
113121
key: screen.parentKey,
@@ -124,6 +132,15 @@ it("opens a subagent from the Agents sheet without replacing the parent thread",
124132
it("opens a completion link in the parent inspector", () => {
125133
using screen = setup(false);
126134
screen.openLinked("child");
135+
if (Platform.OS === "android") {
136+
expect(screen.state.routes).toHaveLength(3);
137+
expect(screen.state.routes.at(-1)).toMatchObject({
138+
name: "Thread",
139+
params: { environmentId: screen.source.environmentId, threadId: "child" },
140+
});
141+
expect(screen.state.routes[1]).toMatchObject({ key: screen.parentKey, params: screen.source });
142+
return;
143+
}
127144
expect(screen.state.routes).toHaveLength(2);
128145
expect(screen.state.routes.at(-1)).toMatchObject({
129146
key: screen.parentKey,
@@ -138,7 +155,14 @@ it("switches between subagents and devices in the same parent route", () => {
138155
using screen = setup(false);
139156
screen.open({ type: "thread", environmentId: screen.source.environmentId, threadId: "child" });
140157
const inspector = { type: "device", ...screen.source } as const;
141-
screen.open(inspector);
158+
const originalState = screen.state;
159+
const opened = screen.open(inspector);
160+
if (Platform.OS === "android") {
161+
expect(opened).toBe(false);
162+
expect(screen.state).toEqual(originalState);
163+
return;
164+
}
165+
expect(opened).toBe(true);
142166
expect(screen.state.routes).toHaveLength(2);
143167
expect(screen.state.routes.at(-1)).toMatchObject({
144168
key: screen.parentKey,

‎apps/server/scripts/migrate-dev-db.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ const pruneSnapshot = Effect.fn("pruneDevDbSnapshot")(function* (input: RunMigra
382382
OR (aggregate_kind = 'project'
383383
AND stream_id NOT IN (SELECT project_id FROM kept_projects))`;
384384
yield* sql`UPDATE orchestration_v2_projection_threads
385-
SET payload_json = json_set(payload_json, '$.pullRequests', (
385+
SET payload_json = json_set(payload_json, '$.pullRequests', json((
386386
SELECT json_group_array(json_remove(link.value, '$.watch') ORDER BY link.key)
387-
FROM json_each(payload_json, '$.pullRequests') AS link))
387+
FROM json_each(payload_json, '$.pullRequests') AS link)))
388388
WHERE EXISTS (
389389
SELECT 1 FROM json_each(payload_json, '$.pullRequests') AS link
390390
WHERE json_extract(link.value, '$.watch') IS NOT NULL)`;

‎apps/server/src/device/sshDeviceScript.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ it.effect("finds Android Studio Java for a non-interactive SSH session", () =>
2424
"#!/bin/sh\necho test-java\n",
2525
{ mode: 0o755 },
2626
);
27-
const result = await exec("/bin/sh", ["-c", `${remoteDeviceEnvironment}\njava`], {
28-
env: { HOME: home, PATH: "/nonexistent", JAVA_HOME: "" },
29-
});
27+
const result = await exec(
28+
"/bin/sh",
29+
["-c", `command() { return 1; }\n${remoteDeviceEnvironment}\nunset -f command\njava`],
30+
{
31+
env: { HOME: home, PATH: "/nonexistent", JAVA_HOME: "" },
32+
},
33+
);
3034
expect(result.stdout.trim()).toBe("test-java");
3135
} finally {
3236
await NodeFSP.rm(home, { recursive: true, force: true });

‎apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,57 @@ effectIt.effect.each(["superseded", "stopped", "account failover"] as const)(
23722372
}),
23732373
);
23742374

2375+
effectIt.effect("settles stale selected knowledge before native startup", () =>
2376+
Effect.gen(function* () {
2377+
const record = {
2378+
version: 1 as const,
2379+
kind: "project-knowledge" as const,
2380+
contextId: ComposerContextId.make("project-knowledge"),
2381+
label: "Project knowledge",
2382+
knowledge: {
2383+
environmentId: EnvironmentId.make("test"),
2384+
projectId: ProjectId.make("project-native-account-command"),
2385+
selections: [{ kind: "fact" as const, factId: ProjectFactId.make("fact"), revision: 1 }],
2386+
maxBytes: 48000,
2387+
},
2388+
};
2389+
const harness = makeLocalCommandHarness({
2390+
text: `Preserve my question. ${formatComposerContextReference(record)}`,
2391+
previousTurn: { runStatus: "completed", turnStatus: "completed" },
2392+
resolveKnowledge: (context) =>
2393+
Effect.fail(
2394+
new ProjectKnowledgeError({
2395+
reason: "stale_context",
2396+
projectId: context.projectId,
2397+
}),
2398+
),
2399+
});
2400+
const projection = harness.projection();
2401+
harness.setProjection({
2402+
...projection,
2403+
messages: projection.messages.map((message) => ({
2404+
...message,
2405+
context: { version: 1, records: [record] },
2406+
})),
2407+
});
2408+
yield* harness.start;
2409+
yield* harness.start;
2410+
expect(harness.startRootRun).not.toHaveBeenCalled();
2411+
expect(harness.nativeStart).not.toHaveBeenCalled();
2412+
const failed = harness.projection();
2413+
expect(failed.runs.find((run) => run.id === projection.runs.at(-1)?.id)?.status).toBe("failed");
2414+
expect(failed.turnItems).toContainEqual(
2415+
expect.objectContaining({
2416+
type: "error",
2417+
failure: expect.objectContaining({
2418+
message: expect.stringContaining("Selected knowledge changed"),
2419+
}),
2420+
}),
2421+
);
2422+
expect(harness.settledRuns).toHaveLength(1);
2423+
}),
2424+
);
2425+
23752426
effectIt.effect.each([false, true, "with-recall"] as const)(
23762427
"rehydrates selected knowledge at native delivery, stale=%s",
23772428
(stale) =>
@@ -3232,6 +3283,10 @@ effectIt.effect("records an over-budget mandatory attachment without starting th
32323283
yield* harness.start.pipe(Effect.result);
32333284
expect(harness.nativeStart).not.toHaveBeenCalled();
32343285
expect(harness.knowledgeDeliveries.at(-1)?.omissions[0]?.reason).toBe("over_budget");
3286+
expect(harness.projection().runs.at(-1)?.status).toBe("failed");
3287+
expect(harness.projection().turnItems).toContainEqual(
3288+
expect.objectContaining({ type: "error" }),
3289+
);
32353290
}),
32363291
);
32373292

0 commit comments

Comments
 (0)