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
6 changes: 3 additions & 3 deletions apps/web/src/components/workflows/WorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ const COPY_PATH = "copy-path";
const WorkflowDefinitionEditor = lazy(() => import("./WorkflowDefinitionEditor"));

export interface WorkflowsSearch extends WorkflowPaneState {
readonly env?: string;
readonly run?: string;
readonly env?: string | undefined;
readonly run?: string | undefined;
/** Show the definition files instead of the runs: all of them, or `file` in the editor. */
readonly definitions?: boolean;
readonly file?: string;
readonly file?: string | undefined;
}

export function WorkflowsPage() {
Expand Down
16 changes: 16 additions & 0 deletions apps/web/src/components/workflows/workflowsRouteSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ describe("workflows route search", () => {
).toMatchObject({ env, run });
});

it("drops a blank or numeric env, run and file instead of keeping the raw search value", () => {
for (const url of [
"/workflows?env=123&run=456&file=789",
"/workflows?env=%20&run=%20&file=%20",
]) {
const search = matchedSearch(url);
expect(search?.env).toBeUndefined();
expect(search?.run).toBeUndefined();
expect(search?.file).toBeUndefined();
}
const blankUntilTheLimit = `${"%20".repeat(200)}x`;
const search = matchedSearch(`/workflows?env=${blankUntilTheLimit}&run=${blankUntilTheLimit}`);
expect(search?.env).toBeUndefined();
expect(search?.run).toBeUndefined();
});

it("keeps a long workflow file name whole instead of naming a shorter file", () => {
const short = `${"a".repeat(197)}.ts`;
const long = `${short}.ts`;
Expand Down
13 changes: 9 additions & 4 deletions apps/web/src/routes/_chat.workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import { createFileRoute } from "@tanstack/react-router";
import { readWorkflowPane } from "../components/workflows/workflowPane.logic";
import { WorkflowsPage, type WorkflowsSearch } from "../components/workflows/WorkflowsPage";

const sliceParam = (value: string) => value.slice(0, splitsSurrogatePair(value, 200) ? 199 : 200);
const sliceParam = (value: unknown) => {
if (typeof value !== "string") return undefined;
const sliced = value.slice(0, splitsSurrogatePair(value, 200) ? 199 : 200);
return sliced.trim() ? sliced : undefined;
};

export const Route = createFileRoute("/_chat/workflows")({
validateSearch: (raw: Record<string, unknown>): WorkflowsSearch => ({
...(typeof raw.env === "string" && raw.env ? { env: sliceParam(raw.env) } : {}),
...(typeof raw.run === "string" && raw.run ? { run: sliceParam(raw.run) } : {}),
// Always set so a number or blank in the URL cannot fall through from the unvalidated search.
env: sliceParam(raw.env),
run: sliceParam(raw.run),
...readWorkflowPane(raw.pane, raw.tab),
...(raw.definitions === true || raw.definitions === "true" ? { definitions: true } : {}),
// Kept whole: a cut name would open, and save over, a different file.
...(typeof raw.file === "string" && raw.file ? { file: raw.file } : {}),
file: typeof raw.file === "string" && raw.file.trim() ? raw.file : undefined,
}),
component: WorkflowsPage,
});
Loading