Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40624c1a71 | ||
|
|
5a994cd866 | ||
|
|
4c853e3714 | ||
|
|
7e7a18de0c |
No files matched your search
@@ -2,10 +2,8 @@ import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import * as ConfigProvider from "effect/ConfigProvider";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import * as HttpServer from "effect/unstable/http/HttpServer";
|
||||
import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
@@ -74,7 +72,6 @@ it.layer(NodeServices.layer)("AnalyticsService test", (it) => {
|
||||
const runtimeLayer = telemetryLayer.pipe(
|
||||
Layer.provide(configLayer),
|
||||
Layer.provideMerge(NodeHttpServer.layerTest),
|
||||
Layer.provideMerge(TestClock.layer()),
|
||||
);
|
||||
|
||||
yield* Effect.gen(function* () {
|
||||
@@ -120,64 +117,4 @@ it.layer(NodeServices.layer)("AnalyticsService test", (it) => {
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("periodic flush runs on the TestClock-controlled interval", () =>
|
||||
Effect.gen(function* () {
|
||||
const capturedRequests: Array<RecordedBatchRequest> = [];
|
||||
const receivedRequest = yield* Deferred.make<void>();
|
||||
const serverConfigLayer = ServerConfig.ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-telemetry-interval-",
|
||||
});
|
||||
|
||||
const telemetryLayer = AnalyticsService.layer.pipe(Layer.provideMerge(serverConfigLayer));
|
||||
const configLayer = ConfigProvider.layer(
|
||||
ConfigProvider.fromUnknown({
|
||||
T3CODE_TELEMETRY_ENABLED: true,
|
||||
T3CODE_POSTHOG_KEY: "phc_test_key",
|
||||
T3CODE_POSTHOG_HOST: "",
|
||||
T3CODE_TELEMETRY_FLUSH_BATCH_SIZE: 20,
|
||||
}),
|
||||
);
|
||||
const batchServerLayer = HttpServer.serve(
|
||||
Effect.gen(function* () {
|
||||
const request = yield* HttpServerRequest.HttpServerRequest;
|
||||
if (request.method !== "POST") {
|
||||
return HttpServerResponse.empty({ status: 404 });
|
||||
}
|
||||
|
||||
const payload = yield* request.json.pipe(
|
||||
Effect.map((body) => body as RecordedBatchRequest["body"]),
|
||||
Effect.orElseSucceed(() => null),
|
||||
);
|
||||
|
||||
capturedRequests.push({ path: request.url, body: payload });
|
||||
yield* Deferred.succeed(receivedRequest, undefined);
|
||||
|
||||
return HttpServerResponse.jsonUnsafe({});
|
||||
}),
|
||||
);
|
||||
const runtimeLayer = telemetryLayer.pipe(
|
||||
Layer.provide(configLayer),
|
||||
Layer.provideMerge(NodeHttpServer.layerTest),
|
||||
);
|
||||
|
||||
yield* Effect.gen(function* () {
|
||||
yield* Layer.launch(batchServerLayer).pipe(Effect.forkScoped);
|
||||
const analytics = yield* AnalyticsService.AnalyticsService;
|
||||
|
||||
yield* analytics.record("test.flush.interval", { index: 1 });
|
||||
assert.equal(capturedRequests.length, 0);
|
||||
|
||||
yield* TestClock.adjust(AnalyticsService.ANALYTICS_FLUSH_INTERVAL);
|
||||
yield* Deferred.await(receivedRequest).pipe(Effect.timeout("1 second"), TestClock.withLive);
|
||||
}).pipe(Effect.provide(runtimeLayer));
|
||||
|
||||
const batchRequests = capturedRequests.filter(
|
||||
(request): request is RecordedBatchRequest & { readonly body: RecordedBatchBody } =>
|
||||
Array.isArray(request.body?.batch),
|
||||
);
|
||||
assert.equal(batchRequests.length, 1);
|
||||
assert.equal(batchRequests[0]?.body.batch[0]?.event, "test.flush.interval");
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -10,7 +10,6 @@ import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/ho
|
||||
import * as Config from "effect/Config";
|
||||
import * as Context from "effect/Context";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
@@ -29,8 +28,6 @@ interface BufferedAnalyticsEvent {
|
||||
readonly capturedAt: string;
|
||||
}
|
||||
|
||||
export const ANALYTICS_FLUSH_INTERVAL = Duration.seconds(1);
|
||||
|
||||
const TelemetryEnvConfig = Config.all({
|
||||
posthogKey: Config.string("T3CODE_POSTHOG_KEY").pipe(
|
||||
Config.withDefault("phc_XOWci4oZP4VvLiEyrFqkFjP4CZn55mjYYBMREK5Wd6m"),
|
||||
@@ -175,7 +172,7 @@ export const make = Effect.gen(function* () {
|
||||
},
|
||||
);
|
||||
|
||||
yield* Effect.forever(Effect.sleep(ANALYTICS_FLUSH_INTERVAL).pipe(Effect.flatMap(() => flush)), {
|
||||
yield* Effect.forever(Effect.sleep(1000).pipe(Effect.flatMap(() => flush)), {
|
||||
disableYield: true,
|
||||
}).pipe(Effect.forkScoped);
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { FileFinder } from "@ff-labs/fff-node";
|
||||
import { it, afterEach, describe, expect } from "@effect/vitest";
|
||||
import { assert, it, afterEach, describe, expect } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
@@ -16,11 +14,6 @@ import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import * as WorkspaceEntries from "./WorkspaceEntries.ts";
|
||||
import * as WorkspacePaths from "./WorkspacePaths.ts";
|
||||
|
||||
vi.mock("node:fs/promises", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("node:fs/promises")>();
|
||||
return { ...actual, readdir: vi.fn(actual.readdir) };
|
||||
});
|
||||
|
||||
const TestLayer = Layer.empty.pipe(
|
||||
Layer.provideMerge(WorkspaceEntries.layer.pipe(Layer.provide(WorkspacePaths.layer))),
|
||||
Layer.provideMerge(WorkspacePaths.layer),
|
||||
@@ -378,16 +371,36 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceEntries", (it) => {
|
||||
|
||||
it.effect("returns an empty listing when the OS denies directory access", () =>
|
||||
Effect.gen(function* () {
|
||||
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-browse-eacces-" });
|
||||
|
||||
const denied = Object.assign(new Error("EACCES: permission denied"), { code: "EACCES" });
|
||||
vi.mocked(NodeFSP.readdir).mockRejectedValueOnce(denied);
|
||||
const denied = PlatformError.systemError({
|
||||
_tag: "PermissionDenied",
|
||||
module: "FileSystem",
|
||||
method: "readDirectory",
|
||||
pathOrDescriptor: cwd,
|
||||
description: "Test PermissionDenied readDirectory failure.",
|
||||
});
|
||||
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries.pipe(
|
||||
Effect.provide(
|
||||
WorkspaceEntries.layer.pipe(
|
||||
Layer.provide(WorkspacePaths.layer),
|
||||
Layer.provide(
|
||||
Layer.succeed(
|
||||
FileSystem.FileSystem,
|
||||
FileSystem.FileSystem.of({
|
||||
...fileSystem,
|
||||
readDirectory: () => Effect.fail(denied),
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const result = yield* workspaceEntries.browse({
|
||||
partialPath: yield* appendSeparator(cwd),
|
||||
});
|
||||
expect(result).toEqual({ parentPath: cwd, entries: [] });
|
||||
assert.deepEqual(result, { parentPath: cwd, entries: [] });
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
import * as NodeOS from "node:os";
|
||||
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as RcMap from "effect/RcMap";
|
||||
import * as Schema from "effect/Schema";
|
||||
@@ -133,6 +134,7 @@ const resolveBrowseTarget = Effect.fn("WorkspaceEntries.resolveBrowseTarget")(fu
|
||||
});
|
||||
|
||||
export const make = Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
|
||||
const workspaceSearchIndexes = yield* WorkspaceSearchIndex.WorkspaceSearchIndexMap;
|
||||
@@ -185,37 +187,34 @@ export const make = Effect.gen(function* () {
|
||||
const parentPath = endsWithSeparator ? resolvedInputPath : path.dirname(resolvedInputPath);
|
||||
const prefix = endsWithSeparator ? "" : path.basename(resolvedInputPath);
|
||||
|
||||
const dirents = yield* Effect.tryPromise({
|
||||
try: () => NodeFSP.readdir(parentPath, { withFileTypes: true }),
|
||||
catch: (cause) =>
|
||||
new WorkspaceEntriesReadDirectoryError({
|
||||
cwd: input.cwd,
|
||||
partialPath: input.partialPath,
|
||||
parentPath,
|
||||
cause,
|
||||
}),
|
||||
}).pipe(
|
||||
Effect.catchIf(
|
||||
(error) => {
|
||||
const code = (error.cause as NodeJS.ErrnoException | undefined)?.code;
|
||||
return code === "EACCES" || code === "EPERM";
|
||||
},
|
||||
() => Effect.succeed([]),
|
||||
const entryNames = yield* fileSystem.readDirectory(parentPath).pipe(
|
||||
Effect.catchTag("PlatformError", (cause) =>
|
||||
cause.reason._tag === "PermissionDenied"
|
||||
? Effect.succeed([])
|
||||
: Effect.fail(
|
||||
new WorkspaceEntriesReadDirectoryError({
|
||||
cwd: input.cwd,
|
||||
partialPath: input.partialPath,
|
||||
parentPath,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const showHidden = endsWithSeparator || prefix.startsWith(".");
|
||||
const lowerPrefix = prefix.toLowerCase();
|
||||
const entries: Array<{ readonly name: string; readonly fullPath: string }> = [];
|
||||
for (const dirent of dirents) {
|
||||
if (
|
||||
dirent.isDirectory() &&
|
||||
dirent.name.toLowerCase().startsWith(lowerPrefix) &&
|
||||
(showHidden || !dirent.name.startsWith("."))
|
||||
) {
|
||||
for (const name of entryNames) {
|
||||
if (name.toLowerCase().startsWith(lowerPrefix) && (showHidden || !name.startsWith("."))) {
|
||||
const fullPath = path.join(parentPath, name);
|
||||
const info = yield* fileSystem.stat(fullPath).pipe(Effect.option);
|
||||
if (Option.isNone(info) || info.value.type !== "Directory") {
|
||||
continue;
|
||||
}
|
||||
entries.push({
|
||||
name: dirent.name,
|
||||
fullPath: path.join(parentPath, dirent.name),
|
||||
name,
|
||||
fullPath,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,9 +186,8 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
|
||||
operationPath: resolvedPath,
|
||||
operation: "realpath-target",
|
||||
});
|
||||
assert.instanceOf(error.cause, PlatformError.PlatformError);
|
||||
expect(error.cause).toBeInstanceOf(PlatformError.PlatformError);
|
||||
assert.equal((error.cause as PlatformError.PlatformError).reason._tag, "NotFound");
|
||||
assert.equal((error.cause as PlatformError.PlatformError).reason.method, "realPath");
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
/**
|
||||
* WorkspaceFileSystem - Effect service contract for workspace file mutations.
|
||||
*
|
||||
@@ -7,8 +6,6 @@
|
||||
*
|
||||
* @module WorkspaceFileSystem
|
||||
*/
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
|
||||
import type {
|
||||
ProjectReadFileInput,
|
||||
ProjectReadFileResult,
|
||||
@@ -19,6 +16,7 @@ import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
@@ -140,32 +138,28 @@ export const make = Effect.gen(function* () {
|
||||
relativePath: input.relativePath,
|
||||
});
|
||||
|
||||
const realWorkspaceRoot = yield* fileSystem.realPath(input.cwd).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new WorkspaceFileSystemOperationError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: target.absolutePath,
|
||||
operationPath: input.cwd,
|
||||
operation: "realpath-workspace-root",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const realTargetPath = yield* fileSystem.realPath(target.absolutePath).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new WorkspaceFileSystemOperationError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: target.absolutePath,
|
||||
operationPath: target.absolutePath,
|
||||
operation: "realpath-target",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const toOperationError =
|
||||
(
|
||||
operation: WorkspaceFileSystemOperationError["operation"],
|
||||
operationPath: string,
|
||||
resolvedPath = target.absolutePath,
|
||||
) =>
|
||||
(cause: unknown) =>
|
||||
new WorkspaceFileSystemOperationError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath,
|
||||
operationPath,
|
||||
operation,
|
||||
cause,
|
||||
});
|
||||
|
||||
const realWorkspaceRoot = yield* fileSystem
|
||||
.realPath(input.cwd)
|
||||
.pipe(Effect.mapError(toOperationError("realpath-workspace-root", input.cwd)));
|
||||
const realTargetPath = yield* fileSystem
|
||||
.realPath(target.absolutePath)
|
||||
.pipe(Effect.mapError(toOperationError("realpath-target", target.absolutePath)));
|
||||
const relativeRealPath = path.relative(realWorkspaceRoot, realTargetPath);
|
||||
if (
|
||||
relativeRealPath.startsWith(`..${path.sep}`) ||
|
||||
@@ -180,84 +174,45 @@ export const make = Effect.gen(function* () {
|
||||
});
|
||||
}
|
||||
|
||||
return yield* Effect.acquireUseRelease(
|
||||
Effect.tryPromise({
|
||||
try: () => NodeFSP.open(realTargetPath, "r"),
|
||||
catch: (cause) =>
|
||||
new WorkspaceFileSystemOperationError({
|
||||
return yield* Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const handle = yield* fileSystem
|
||||
.open(realTargetPath, { flag: "r" })
|
||||
.pipe(Effect.mapError(toOperationError("open", realTargetPath, realTargetPath)));
|
||||
const stat = yield* handle.stat.pipe(
|
||||
Effect.mapError(toOperationError("stat", realTargetPath, realTargetPath)),
|
||||
);
|
||||
if (stat.type !== "File") {
|
||||
return yield* new WorkspacePathNotFileError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: realTargetPath,
|
||||
operationPath: realTargetPath,
|
||||
operation: "open",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
const byteLength = Number(stat.size);
|
||||
const bytesToRead = Math.min(byteLength, PROJECT_READ_FILE_MAX_BYTES);
|
||||
const fileBytes = Option.getOrElse(
|
||||
yield* handle
|
||||
.readAlloc(bytesToRead)
|
||||
.pipe(Effect.mapError(toOperationError("read", realTargetPath, realTargetPath))),
|
||||
() => new Uint8Array(0),
|
||||
);
|
||||
if (fileBytes.includes(0)) {
|
||||
return yield* new WorkspaceBinaryFileError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: realTargetPath,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
relativePath: target.relativePath,
|
||||
contents: new TextDecoder("utf-8").decode(fileBytes),
|
||||
byteLength,
|
||||
truncated: byteLength > PROJECT_READ_FILE_MAX_BYTES,
|
||||
};
|
||||
}),
|
||||
(handle) =>
|
||||
Effect.gen(function* () {
|
||||
const stat = yield* Effect.tryPromise({
|
||||
try: () => handle.stat(),
|
||||
catch: (cause) =>
|
||||
new WorkspaceFileSystemOperationError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: realTargetPath,
|
||||
operationPath: realTargetPath,
|
||||
operation: "stat",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
if (!stat.isFile()) {
|
||||
return yield* new WorkspacePathNotFileError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: realTargetPath,
|
||||
});
|
||||
}
|
||||
|
||||
const bytesToRead = Math.min(stat.size, PROJECT_READ_FILE_MAX_BYTES);
|
||||
const buffer = Buffer.alloc(bytesToRead);
|
||||
const { bytesRead } = yield* Effect.tryPromise({
|
||||
try: () => handle.read(buffer, 0, bytesToRead, 0),
|
||||
catch: (cause) =>
|
||||
new WorkspaceFileSystemOperationError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: realTargetPath,
|
||||
operationPath: realTargetPath,
|
||||
operation: "read",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
const fileBytes = buffer.subarray(0, bytesRead);
|
||||
if (fileBytes.includes(0)) {
|
||||
return yield* new WorkspaceBinaryFileError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: realTargetPath,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
relativePath: target.relativePath,
|
||||
contents: new TextDecoder("utf-8").decode(fileBytes),
|
||||
byteLength: stat.size,
|
||||
truncated: stat.size > PROJECT_READ_FILE_MAX_BYTES,
|
||||
};
|
||||
}),
|
||||
(handle) =>
|
||||
Effect.tryPromise({
|
||||
try: () => handle.close(),
|
||||
catch: (cause) =>
|
||||
new WorkspaceFileSystemOperationError({
|
||||
workspaceRoot: input.cwd,
|
||||
relativePath: input.relativePath,
|
||||
resolvedPath: realTargetPath,
|
||||
operationPath: realTargetPath,
|
||||
operation: "close",
|
||||
cause,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
|
||||
import { fnv1a32 } from "../lib/diffRendering";
|
||||
import { LRUCache } from "../lib/lruCache";
|
||||
import { useTheme } from "../hooks/useTheme";
|
||||
import { getClientSettings } from "../hooks/useSettings";
|
||||
import { useClientSettings } from "../hooks/useSettings";
|
||||
import {
|
||||
chatMarkdownClipboardPayload,
|
||||
serializeTableElementToCsv,
|
||||
@@ -293,14 +293,10 @@ function getHighlighterPromise(language: string): Promise<DiffsHighlighter> {
|
||||
return promise;
|
||||
}
|
||||
|
||||
function readInitialWordWrapSetting(): boolean {
|
||||
return getClientSettings().wordWrap;
|
||||
}
|
||||
|
||||
function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const tableRef = useRef<HTMLTableElement | null>(null);
|
||||
const [expanded, setExpanded] = useState(readInitialWordWrapSetting);
|
||||
const [expanded, setExpanded] = useState(useClientSettings((settings) => settings.wordWrap));
|
||||
const [copied, setCopied] = useState(false);
|
||||
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const expandLabel = expanded ? "Collapse table cells" : "Expand table cells";
|
||||
@@ -530,7 +526,7 @@ function MarkdownCodeBlock({
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [wrapped, setWrapped] = useState(readInitialWordWrapSetting);
|
||||
const [wrapped, setWrapped] = useState(useClientSettings((settings) => settings.wordWrap));
|
||||
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const wrapLabel = wrapped ? "Disable line wrap" : "Wrap lines";
|
||||
const copyLabel = copied ? "Copied" : "Copy code";
|
||||
|
||||
@@ -193,33 +193,6 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).toContain("Show full message");
|
||||
}, 20_000);
|
||||
|
||||
it("renders chips for standalone element-pick context messages", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
buildUserTimelineEntry(
|
||||
[
|
||||
"<element_context>",
|
||||
"- <SubmitButton> (Button.tsx:12):",
|
||||
" url: https://example.com/dashboard",
|
||||
" selector: button.submit",
|
||||
" source: /repo/src/Button.tsx:12:5",
|
||||
" html:",
|
||||
' <button class="submit">Save</button>',
|
||||
"</element_context>",
|
||||
].join("\n"),
|
||||
),
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("SubmitButton");
|
||||
expect(markup).not.toContain("<element_context");
|
||||
expect(markup).not.toContain("<element_context");
|
||||
});
|
||||
|
||||
it("keeps the copy button for collapsed long user messages", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
|
||||
@@ -448,10 +448,6 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
|
||||
visibleText = extracted.promptText;
|
||||
}
|
||||
const elementContextState = extractTrailingElementContexts(visibleText);
|
||||
const elementContexts = [
|
||||
...displayedUserMessage.elementContexts,
|
||||
...elementContextState.contexts,
|
||||
];
|
||||
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
|
||||
const regularImages = userImages.filter((image) => !image.name.startsWith("preview-annotation-"));
|
||||
const canRevertAgentWork = typeof row.revertTurnCount === "number";
|
||||
@@ -499,9 +495,9 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
|
||||
image={previewImages[index] ?? null}
|
||||
/>
|
||||
))}
|
||||
{elementContexts.length > 0 ? (
|
||||
{elementContextState.contexts.length > 0 ? (
|
||||
<div className="mb-2 flex flex-wrap gap-1.5">
|
||||
{elementContexts.map((context) => (
|
||||
{elementContextState.contexts.map((context) => (
|
||||
<UserMessageElementContextChip
|
||||
key={`${context.header}:${context.body}`}
|
||||
context={context}
|
||||
|
||||
Reference in new issue
Block a user