Harden remote connect and subscription handling
- Scope cleartext mobile config to development - Fix stale loads, ordering, and terminal reuse - Clean up terminal metadata subscriptions on failure
This commit is contained in:
1 parent
4ac2618403
commit
7f03f4d19a
15 files changed
+276
-47
No files matched your search
@@ -59,4 +59,35 @@ describe("applyDiffRangesToTokens", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("skips exhausted ranges when later tokens start after the last range", () => {
|
||||
const tokens = [
|
||||
{
|
||||
content: "a",
|
||||
color: "#fff",
|
||||
fontStyle: null,
|
||||
},
|
||||
{
|
||||
content: "b",
|
||||
color: "#fff",
|
||||
fontStyle: null,
|
||||
},
|
||||
];
|
||||
|
||||
const nextTokens = applyDiffRangesToTokens(tokens, [{ start: 0, end: 1 }]);
|
||||
|
||||
expect(nextTokens).toEqual([
|
||||
{
|
||||
content: "a",
|
||||
color: "#fff",
|
||||
fontStyle: null,
|
||||
diffHighlight: true,
|
||||
},
|
||||
{
|
||||
content: "b",
|
||||
color: "#fff",
|
||||
fontStyle: null,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -208,7 +208,7 @@ export function applyDiffRangesToTokens(
|
||||
return;
|
||||
}
|
||||
|
||||
while ((ranges[rangeIndex]?.end ?? 0) <= tokenStart) {
|
||||
while (rangeIndex < ranges.length && ranges[rangeIndex]!.end <= tokenStart) {
|
||||
rangeIndex += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DEFAULT_TERMINAL_ID, type EnvironmentId, type ThreadId } from "@t3tools/contracts";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import { memo, useCallback, useEffect, useState } from "react";
|
||||
import { memo, useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Pressable, View } from "react-native";
|
||||
|
||||
import { AppText as Text } from "../../components/AppText";
|
||||
@@ -41,6 +41,8 @@ export const ThreadTerminalPanel = memo(function ThreadTerminalPanel(
|
||||
cols: DEFAULT_TERMINAL_COLS,
|
||||
rows: DEFAULT_TERMINAL_ROWS,
|
||||
});
|
||||
const lastGridSizeRef = useRef(lastGridSize);
|
||||
lastGridSizeRef.current = lastGridSize;
|
||||
|
||||
const terminalKey = `${props.environmentId}:${props.threadId}:${terminalId}`;
|
||||
const isRunning = terminal.status === "running" || terminal.status === "starting";
|
||||
@@ -73,13 +75,11 @@ export const ThreadTerminalPanel = memo(function ThreadTerminalPanel(
|
||||
terminalId,
|
||||
cwd: props.cwd,
|
||||
worktreePath: props.worktreePath,
|
||||
cols: lastGridSize.cols,
|
||||
rows: lastGridSize.rows,
|
||||
cols: lastGridSizeRef.current.cols,
|
||||
rows: lastGridSizeRef.current.rows,
|
||||
},
|
||||
});
|
||||
}, [
|
||||
lastGridSize.cols,
|
||||
lastGridSize.rows,
|
||||
props.cwd,
|
||||
props.environmentId,
|
||||
props.threadId,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import type {
|
||||
EnvironmentId,
|
||||
@@ -152,6 +152,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
const [workspaceMode, setWorkspaceMode] = useState<WorkspaceMode>("local");
|
||||
const [selectedBranchName, setSelectedBranchName] = useState<string | null>(null);
|
||||
const [selectedWorktreePath, setSelectedWorktreePath] = useState<string | null>(null);
|
||||
const branchLoadVersionRef = useRef(0);
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const [attachments, setAttachments] = useState<ReadonlyArray<DraftComposerImageAttachment>>([]);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
@@ -329,11 +330,16 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
}, [availableBranches, branchQuery]);
|
||||
|
||||
const setProject = useCallback((project: EnvironmentScopedProjectShell) => {
|
||||
const nextProjectKey = scopedProjectKey(project.environmentId, project.id);
|
||||
branchLoadVersionRef.current += 1;
|
||||
setSelectedEnvironmentId(project.environmentId);
|
||||
setSelectedProjectKey(scopedProjectKey(project.environmentId, project.id));
|
||||
setSelectedProjectKey(nextProjectKey);
|
||||
setSelectedBranchName(null);
|
||||
setSelectedWorktreePath(null);
|
||||
}, []);
|
||||
|
||||
const selectEnvironment = useCallback((environmentId: EnvironmentId) => {
|
||||
branchLoadVersionRef.current += 1;
|
||||
setSelectedEnvironmentId(environmentId);
|
||||
setSelectedProjectKey(null);
|
||||
setSelectedBranchName(null);
|
||||
@@ -355,12 +361,17 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
return;
|
||||
}
|
||||
|
||||
const loadVersion = ++branchLoadVersionRef.current;
|
||||
const projectKey = scopedProjectKey(selectedProject.environmentId, selectedProject.id);
|
||||
try {
|
||||
const result = await vcsRefManager.load({
|
||||
environmentId: selectedProject.environmentId,
|
||||
cwd: selectedProject.workspaceRoot,
|
||||
query: null,
|
||||
});
|
||||
if (loadVersion !== branchLoadVersionRef.current || selectedProjectKey !== projectKey) {
|
||||
return;
|
||||
}
|
||||
setPendingConnectionError(null);
|
||||
const branches = pipe(
|
||||
result?.refs ?? [],
|
||||
@@ -377,9 +388,12 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
if (loadVersion !== branchLoadVersionRef.current) {
|
||||
return;
|
||||
}
|
||||
setPendingConnectionError("Failed to load branches.");
|
||||
}
|
||||
}, [selectedBranchName, selectedProject, workspaceMode]);
|
||||
}, [selectedBranchName, selectedProject, selectedProjectKey, workspaceMode]);
|
||||
|
||||
const value = useMemo<NewTaskFlowContextValue>(
|
||||
() => ({
|
||||
|
||||
@@ -108,10 +108,74 @@ describe("groupProjectsByRepository", () => {
|
||||
threadCount: 2,
|
||||
});
|
||||
expect(
|
||||
groups[0]?.projects
|
||||
.map((entry) => entry.project.environmentId)
|
||||
.toSorted((left, right) => left.localeCompare(right)),
|
||||
).toEqual(["env-local", "env-staging"]);
|
||||
groups[0]?.projects.map((entry) => ({
|
||||
environmentId: entry.project.environmentId,
|
||||
latestActivityAt: entry.latestActivityAt,
|
||||
threads: entry.threads.map((thread) => thread.id),
|
||||
})),
|
||||
).toEqual([
|
||||
{
|
||||
environmentId: "env-local",
|
||||
latestActivityAt: "2026-04-03T12:00:00.000Z",
|
||||
threads: ["thread-1"],
|
||||
},
|
||||
{
|
||||
environmentId: "env-staging",
|
||||
latestActivityAt: "2026-04-02T12:00:00.000Z",
|
||||
threads: ["thread-2"],
|
||||
},
|
||||
]);
|
||||
expect(groups[0]?.latestActivityAt).toBe("2026-04-03T12:00:00.000Z");
|
||||
});
|
||||
|
||||
it("orders threads, projects, and repository groups by latest activity", () => {
|
||||
const projects = [
|
||||
makeProject({
|
||||
environmentId: EnvironmentId.make("env-local"),
|
||||
id: ProjectId.make("older-project"),
|
||||
title: "Older",
|
||||
}),
|
||||
makeProject({
|
||||
environmentId: EnvironmentId.make("env-local"),
|
||||
id: ProjectId.make("newer-project"),
|
||||
title: "Newer",
|
||||
}),
|
||||
];
|
||||
|
||||
const threads = [
|
||||
makeThread({
|
||||
environmentId: EnvironmentId.make("env-local"),
|
||||
id: ThreadId.make("older-thread"),
|
||||
projectId: ProjectId.make("older-project"),
|
||||
title: "Older thread",
|
||||
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
|
||||
updatedAt: "2026-04-02T12:00:00.000Z",
|
||||
}),
|
||||
makeThread({
|
||||
environmentId: EnvironmentId.make("env-local"),
|
||||
id: ThreadId.make("newer-thread"),
|
||||
projectId: ProjectId.make("older-project"),
|
||||
title: "Newer thread",
|
||||
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
|
||||
updatedAt: "2026-04-04T12:00:00.000Z",
|
||||
}),
|
||||
makeThread({
|
||||
environmentId: EnvironmentId.make("env-local"),
|
||||
id: ThreadId.make("newest-thread"),
|
||||
projectId: ProjectId.make("newer-project"),
|
||||
title: "Newest thread",
|
||||
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
|
||||
updatedAt: "2026-04-05T12:00:00.000Z",
|
||||
}),
|
||||
];
|
||||
|
||||
const groups = groupProjectsByRepository({ projects, threads });
|
||||
|
||||
expect(groups.map((group) => group.title)).toEqual(["Newer", "Older"]);
|
||||
expect(groups[1]?.projects[0]?.threads.map((thread) => thread.id)).toEqual([
|
||||
"newer-thread",
|
||||
"older-thread",
|
||||
]);
|
||||
});
|
||||
|
||||
it("falls back to a scoped project key when repository identity is unavailable", () => {
|
||||
|
||||
@@ -8,6 +8,8 @@ import {
|
||||
EnvironmentScopedThreadShell,
|
||||
} from "@t3tools/client-runtime";
|
||||
|
||||
const DateDescending = Order.flip(Order.Date);
|
||||
|
||||
export interface MobileRepositoryProjectGroup {
|
||||
readonly key: string;
|
||||
readonly project: EnvironmentScopedProjectShell;
|
||||
@@ -83,7 +85,7 @@ export function groupProjectsByRepository(input: {
|
||||
const threads = Arr.sortWith(
|
||||
threadsByProjectKey.get(projectKey) ?? [],
|
||||
(s) => new Date(s.updatedAt ?? s.createdAt),
|
||||
Order.Date,
|
||||
DateDescending,
|
||||
);
|
||||
|
||||
const latestActivityAt = deriveProjectLatestActivity(project, threads);
|
||||
@@ -123,10 +125,10 @@ export function groupProjectsByRepository(input: {
|
||||
projects: Arr.sortWith(
|
||||
[...existing.projects, projectGroup],
|
||||
(s) => new Date(s.latestActivityAt),
|
||||
Order.Date,
|
||||
DateDescending,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
return Arr.sortWith([...grouped.values()], (s) => new Date(s.latestActivityAt), Order.Date);
|
||||
return Arr.sortWith(grouped.values(), (s) => new Date(s.latestActivityAt), DateDescending);
|
||||
}
|
||||
Reference in new issue
Block a user