Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/desktop/src/settings/DesktopClientSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const clientSettings: ClientSettings = {
confirmThreadDelete: false,
confirmWorktreeRemoval: true,
confirmThreadUnpin: false,
continueThreadsAfterServerUpdate: true,
contextWindowMeterEnabled: false,
dismissedProviderUpdateNotificationKeys: [],
diffIgnoreWhitespace: true,
environmentIdentificationMode: "artwork",
Expand Down
11 changes: 8 additions & 3 deletions apps/mobile/src/features/threads/ThreadComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ export const COMPOSER_LAYOUT_TRANSITION =
? undefined
: LinearTransition.duration(COMPOSER_TRANSITION_DURATION_MS).reduceMotion(ReduceMotion.System);

const COMPOSER_ATTACHMENT_ENTERING =
Platform.OS === "android"
? FadeIn.duration(160)
: FadeIn.delay(COMPOSER_TRANSITION_DURATION_MS).duration(160).reduceMotion(ReduceMotion.System);

const AnimatedGlassSurface = Animated.createAnimatedComponent(GlassSurface);

export function ComposerSurface(props: {
Expand Down Expand Up @@ -700,10 +705,10 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
onPickFiles={props.onPickDraftFiles}
/>
) : null}
{isExpanded ? (
{isExpanded && props.draftAttachments.length > 0 ? (
<Animated.View
className={props.draftAttachments.length > 0 ? "px-[14px] pb-2.5" : undefined}
entering={FadeIn.duration(160)}
className="px-[14px] pb-2.5"
entering={COMPOSER_ATTACHMENT_ENTERING}
exiting={FadeOut.duration(120)}
>
<ComposerAttachmentStrip
Expand Down
4 changes: 4 additions & 0 deletions apps/mobile/src/features/threads/ThreadFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ import {
import { MARKDOWN_IMAGE_MAX_WIDTH, resolveMarkdownImageDisplaySize } from "./markdownImageSize";

const WIDE_MARKDOWN_BLOCK_OPTIONS = {
// Native iOS blockquotes and adjacent selectable text are separate layout
// chunks. Giving their shrink-to-fit bubble a definite width keeps both
// chunks measured against the width at which UIKit draws them.
includeBlockquotes: Platform.OS === "ios",
includeOrderedLists: Platform.OS === "android",
} as const;

Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/lib/wideMarkdownBlocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ describe("hasWideMarkdownBlock", () => {
);
});

it("detects blockquotes only when the native renderer needs width pinning", () => {
expect(hasWideMarkdownBlock("> quoted", { includeBlockquotes: true })).toBe(true);
expect(hasWideMarkdownBlock(" > quoted", { includeBlockquotes: true })).toBe(true);
expect(hasWideMarkdownBlock("> quoted")).toBe(false);
expect(hasWideMarkdownBlock("prose > quoted", { includeBlockquotes: true })).toBe(false);
expect(hasWideMarkdownBlock(" > indented code", { includeBlockquotes: true })).toBe(false);
});

it("detects GFM tables", () => {
expect(hasWideMarkdownBlock("| a | b |\n| --- | --- |\n| 1 | 2 |")).toBe(true);
expect(hasWideMarkdownBlock("a | b\n:-- | --:\n1 | 2")).toBe(true);
Expand Down
13 changes: 11 additions & 2 deletions apps/mobile/src/lib/wideMarkdownBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Detects markdown that the JS renderer draws as a block requiring a definite
* user-bubble width — fenced code blocks, GFM tables, and ordered lists.
* Detects markdown that the renderer draws as a block requiring a definite
* user-bubble width: fenced code blocks, GFM tables, ordered lists, and
* blockquotes when requested by the caller.
*
* Fenced code blocks and tables report an intrinsic width equal to their
* widest line, which is effectively unbounded. A user bubble sizes itself
Expand Down Expand Up @@ -31,6 +32,7 @@ const BLOCKQUOTE_PREFIX = /^ {0,3}>[ \t]?/;

export interface WideMarkdownBlockOptions {
readonly includeOrderedLists?: boolean;
readonly includeBlockquotes?: boolean;
}

function stripBlockquotePrefixes(line: string): string {
Expand All @@ -41,6 +43,10 @@ function stripBlockquotePrefixes(line: string): string {
return content;
}

function hasBlockquote(text: string): boolean {
return text.split("\n").some((line) => BLOCKQUOTE_PREFIX.test(line));
}

function hasOrderedListItem(text: string): boolean {
let previousNonEmptyLine: string | null = null;

Expand Down Expand Up @@ -80,6 +86,9 @@ export function hasWideMarkdownBlock(
if (FENCED_CODE_BLOCK.test(text)) {
return true;
}
if (options.includeBlockquotes === true && hasBlockquote(text)) {
return true;
}
if (options.includeOrderedLists !== false && hasOrderedListItem(text)) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/state/use-thread-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
import {
createLinkedPullRequestDetailAtomFamily,
createLinkedPullRequestSummaryAtomFamily,
pullRequestDetailToVcsStatus,
} from "@t3tools/client-runtime/state/pull-requests";
import { Atom } from "effect/unstable/reactivity";
Expand All @@ -14,7 +14,7 @@ import { useEnvironmentQuery } from "./query";
import { presentThreadPr, type ThreadPrPresentation } from "./thread-pr-presentation";
import { vcsEnvironment } from "./vcs";

const linkedPullRequestDetailAtom = createLinkedPullRequestDetailAtomFamily(connectionAtomRuntime);
const linkedPullRequestDetailAtom = createLinkedPullRequestSummaryAtomFamily(connectionAtomRuntime);
const MAX_THREAD_PR_SNAPSHOTS = 500;

interface ThreadPrSnapshot {
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.identityClearClaim]: AuthOrchestrationOperateScope,
[WS_METHODS.pullRequestsList]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsListStats]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsSummary]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsDetail]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsActivity]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsThreadComments]: AuthOrchestrationReadScope,
Expand Down
217 changes: 217 additions & 0 deletions apps/server/src/cloud/selfUpdate.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import { ServerSelfUpdateError, ThreadId } from "@t3tools/contracts";
import { HostProcessExecutablePath } from "@t3tools/shared/hostProcess";
import * as Cause from "effect/Cause";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
Expand Down Expand Up @@ -104,6 +106,221 @@ const makeHarness = Effect.fn("test.make_self_update_harness")(function* (
});

it.layer(NodeServices.layer)("server self update", (it) => {
it.effect("marks running threads at the boot-service handoff", () =>
Effect.gen(function* () {
const events: string[] = [];
const selfUpdate = yield* ServerSelfUpdate.withRunningThreadContinuation({
mode: "web",
selfUpdate: {
update: (_input, reportProgress = () => Effect.void) =>
reportProgress("downloading").pipe(
Effect.andThen(reportProgress("installing")),
Effect.as({
targetVersion: "1.1.0",
method: "boot-service" as const,
updateId: "update-id",
}),
),
commitDesktopUpdate: () => Effect.never,
},
prepare: Effect.sync(() => {
events.push("prepare");
return [ThreadId.make("thread-running")];
}),
clear: () => Effect.sync(() => void events.push("clear")),
});

yield* selfUpdate.update({ targetVersion: "1.1.0", continueRunningThreads: true }, (stage) =>
Effect.sync(() => void events.push(stage)),
);

expect(events).toEqual(["downloading", "prepare", "installing"]);
}),
);

it.effect("marks desktop threads only when the prepared update commits", () =>
Effect.gen(function* () {
const threadId = ThreadId.make("thread-running-desktop");
const events: string[] = [];
const commitError = new ServerSelfUpdateError({ reason: "install failed" });
const selfUpdate = yield* ServerSelfUpdate.withRunningThreadContinuation({
mode: "desktop",
selfUpdate: {
update: (_input, reportProgress = () => Effect.void) =>
reportProgress("installing").pipe(
Effect.as({
targetVersion: "1.2.0",
method: "desktop-app" as const,
desktopUpdateToken: "desktop-token",
}),
),
commitDesktopUpdate: () =>
Effect.sync(() => events.push("commit")).pipe(Effect.andThen(Effect.fail(commitError))),
},
prepare: Effect.sync(() => {
events.push("prepare");
return [threadId];
}),
clear: (threadIds) => Effect.sync(() => void events.push(`clear:${threadIds.join(",")}`)),
});

yield* selfUpdate.update({ targetVersion: "1.2.0", continueRunningThreads: true }, (stage) =>
Effect.sync(() => void events.push(stage)),
);
expect(events).toEqual(["installing"]);
expect(yield* selfUpdate.commitDesktopUpdate("desktop-token").pipe(Effect.flip)).toBe(
commitError,
);
expect(events).toEqual(["installing", "prepare", "commit", `clear:${threadId}`]);
expect(yield* selfUpdate.commitDesktopUpdate("desktop-token").pipe(Effect.flip)).toBe(
commitError,
);
expect(events).toEqual([
"installing",
"prepare",
"commit",
`clear:${threadId}`,
"prepare",
"commit",
`clear:${threadId}`,
]);
}),
);

it.effect("reports a failed continuation-marker cleanup", () =>
Effect.gen(function* () {
const updateError = new ServerSelfUpdateError({ reason: "update failed" });
const clearError = new ServerSelfUpdateError({ reason: "marker cleanup failed" });
const selfUpdate = yield* ServerSelfUpdate.withRunningThreadContinuation({
mode: "web",
selfUpdate: {
update: (_input, reportProgress = () => Effect.void) =>
reportProgress("installing").pipe(Effect.andThen(Effect.fail(updateError))),
commitDesktopUpdate: () => Effect.never,
},
prepare: Effect.succeed([ThreadId.make("thread-cleanup-failure")]),
clear: () => Effect.fail(clearError),
});

expect(
yield* selfUpdate
.update({ targetVersion: "1.1.0", continueRunningThreads: true })
.pipe(Effect.flip),
).toBe(clearError);
}),
);

it.effect("keeps continuation markers after the boot-service handoff is accepted", () =>
Effect.gen(function* () {
const events: string[] = [];
const selfUpdate = yield* ServerSelfUpdate.withRunningThreadContinuation({
mode: "web",
selfUpdate: {
update: (
_input,
reportProgress = () => Effect.void,
onHandoffAccepted = () => Effect.void,
) =>
reportProgress("installing").pipe(
Effect.andThen(onHandoffAccepted()),
Effect.andThen(Effect.interrupt),
),
commitDesktopUpdate: () => Effect.never,
},
prepare: Effect.sync(() => {
events.push("prepare");
return [ThreadId.make("thread-accepted-boot-handoff")];
}),
clear: () => Effect.sync(() => void events.push("clear")),
});

const exit = yield* selfUpdate
.update({ targetVersion: "1.1.0", continueRunningThreads: true })
.pipe(Effect.exit);

expect(exit._tag).toBe("Failure");
expect(events).toEqual(["prepare"]);
}),
);

it.effect("keeps continuation markers after the desktop handoff is accepted", () =>
Effect.gen(function* () {
const events: string[] = [];
const selfUpdate = yield* ServerSelfUpdate.withRunningThreadContinuation({
mode: "desktop",
selfUpdate: {
update: () =>
Effect.succeed({
targetVersion: "1.2.0",
method: "desktop-app" as const,
desktopUpdateToken: "accepted-desktop-token",
}),
commitDesktopUpdate: (_requestId, onHandoffAccepted = () => Effect.void) =>
onHandoffAccepted().pipe(Effect.andThen(Effect.interrupt)),
},
prepare: Effect.sync(() => {
events.push("prepare");
return [ThreadId.make("thread-accepted-desktop-handoff")];
}),
clear: () => Effect.sync(() => void events.push("clear")),
});

yield* selfUpdate.update({
targetVersion: "1.2.0",
continueRunningThreads: true,
});
const exit = yield* selfUpdate
.commitDesktopUpdate("accepted-desktop-token")
.pipe(Effect.exit);

expect(exit._tag).toBe("Failure");
expect(events).toEqual(["prepare"]);
}),
);

it.effect("clears continuation markers for mixed failure and interrupt causes", () =>
Effect.gen(function* () {
const events: string[] = [];
const commitError = new ServerSelfUpdateError({ reason: "install failed" });
const selfUpdate = yield* ServerSelfUpdate.withRunningThreadContinuation({
mode: "desktop",
selfUpdate: {
update: () =>
Effect.succeed({
targetVersion: "1.2.0",
method: "desktop-app" as const,
desktopUpdateToken: "failed-desktop-token",
}),
commitDesktopUpdate: (_requestId, onHandoffAccepted = () => Effect.void) =>
onHandoffAccepted().pipe(
Effect.andThen(
Effect.failCause(
Cause.fromReasons([
Cause.makeFailReason(commitError),
Cause.makeInterruptReason(),
]),
),
),
),
},
prepare: Effect.sync(() => [ThreadId.make("thread-failed-desktop-install")]),
clear: () => Effect.sync(() => void events.push("clear")),
});

yield* selfUpdate.update({
targetVersion: "1.2.0",
continueRunningThreads: true,
});
const exit = yield* selfUpdate.commitDesktopUpdate("failed-desktop-token").pipe(Effect.exit);
expect(exit._tag).toBe("Failure");
if (exit._tag === "Failure") {
expect(Cause.hasInterrupts(exit.cause)).toBe(true);
expect(Cause.hasInterruptsOnly(exit.cause)).toBe(false);
}
expect(events).toEqual(["clear"]);
}),
);

it.effect("stages and preflights before asking the launcher for an update ID", () =>
Effect.gen(function* () {
const { selfUpdate, order } = yield* makeHarness();
Expand Down
Loading
Loading