Skip to content
Open
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
9 changes: 7 additions & 2 deletions src/pages/listConverters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Elysia from "elysia";
import { BaseHtml } from "../components/base";
import { Header } from "../components/header";
import { getAllInputs, getAllTargets } from "../converters/main";
import { ALLOW_UNAUTHENTICATED, WEBROOT } from "../helpers/env";
import { ALLOW_UNAUTHENTICATED, HIDE_HISTORY, WEBROOT } from "../helpers/env";
import { userService } from "./user";

export const listConverters = new Elysia().use(userService).get(
Expand All @@ -11,7 +11,12 @@ export const listConverters = new Elysia().use(userService).get(
return (
<BaseHtml webroot={WEBROOT} title="ConvertX | Converters">
<>
<Header webroot={WEBROOT} allowUnauthenticated={ALLOW_UNAUTHENTICATED} loggedIn />
<Header
webroot={WEBROOT}
allowUnauthenticated={ALLOW_UNAUTHENTICATED}
hideHistory={HIDE_HISTORY}
loggedIn
/>
<main
class={`
w-full flex-1 px-2
Expand Down
9 changes: 7 additions & 2 deletions src/pages/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Header } from "../components/header";
import db from "../db/db";
import { Filename, Jobs } from "../db/types";
import { buildDownloadUrl } from "../helpers/buildDownloadUrl";
import { ALLOW_UNAUTHENTICATED, WEBROOT } from "../helpers/env";
import { ALLOW_UNAUTHENTICATED, HIDE_HISTORY, WEBROOT } from "../helpers/env";
import { DownloadIcon } from "../icons/download";
import { DeleteIcon } from "../icons/delete";
import { EyeIcon } from "../icons/eye";
Expand Down Expand Up @@ -163,7 +163,12 @@ export const results = new Elysia()
return (
<BaseHtml webroot={WEBROOT} title="ConvertX | Result">
<>
<Header webroot={WEBROOT} allowUnauthenticated={ALLOW_UNAUTHENTICATED} loggedIn />
<Header
webroot={WEBROOT}
allowUnauthenticated={ALLOW_UNAUTHENTICATED}
hideHistory={HIDE_HISTORY}
loggedIn
/>
<main
class={`
w-full flex-1 px-2
Expand Down
38 changes: 38 additions & 0 deletions tests/pages/listConverters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// The converters page is behind auth and reads HIDE_HISTORY at module load, so the
// env is set and a valid session cookie is minted before the page is imported below.
// The assertion is only about the header: with HIDE_HISTORY set, the History nav link
// must not render on this page, which previously omitted the hideHistory prop.
const JWT_SECRET = "test-secret";
process.env.DB_PATH = ":memory:";
process.env.JWT_SECRET = JWT_SECRET;
process.env.HIDE_HISTORY = "true";
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
process.env.WEBROOT = "";

import { createHmac } from "node:crypto";
import { expect, test } from "bun:test";

const { listConverters } = await import("../../src/pages/listConverters");

// Minimal HS256 JWT so the authenticated route renders; @elysiajs/jwt verifies it.
function sessionCookie(): string {
const b64url = (value: string) => Buffer.from(value).toString("base64url");
const payload = `${b64url(JSON.stringify({ alg: "HS256", typ: "JWT" }))}.${b64url(
JSON.stringify({ id: "1", exp: Math.floor(Date.now() / 1000) + 3600 }),
)}`;
const signature = createHmac("sha256", JWT_SECRET).update(payload).digest("base64url");
return `auth=${payload}.${signature}`;
}

// Regression test for #556.
test("converters page hides the History link when HIDE_HISTORY is set", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The PR's primary reported scenario is the results page (#556, the header shown right after a conversion), yet this regression test only covers the converters page. tests/pages/results.test.ts only exercises buildDownloadUrl and never renders the results page, so the hideHistory={HIDE_HISTORY} fix on results.tsx ships with no test guarding it. Add an equivalent page-rendering test for the results route (inserting a job row into the in-memory DB and asserting the History link is absent), or the results regression can silently return.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/pages/listConverters.test.ts, line 26:

<comment>The PR's primary reported scenario is the results page (#556, the header shown right after a conversion), yet this regression test only covers the converters page. `tests/pages/results.test.ts` only exercises `buildDownloadUrl` and never renders the results page, so the `hideHistory={HIDE_HISTORY}` fix on `results.tsx` ships with no test guarding it. Add an equivalent page-rendering test for the results route (inserting a job row into the in-memory DB and asserting the History link is absent), or the results regression can silently return.</comment>

<file context>
@@ -0,0 +1,37 @@
+}
+
+// Regression test for #556.
+test("converters page hides the History link when HIDE_HISTORY is set", async () => {
+  const res = await listConverters.handle(
+    new Request("http://localhost/converters", { headers: { Cookie: sessionCookie() } }),
</file context>

const res = await listConverters.handle(
new Request("http://localhost/converters", { headers: { Cookie: sessionCookie() } }),
);
expect(res.status).toBe(200);

const html = await res.text();
// Sanity: the authenticated header actually rendered.
expect(html).toContain('href="/account"');
// The History link must be gone.
expect(html).not.toContain('href="/history"');
});
43 changes: 43 additions & 0 deletions tests/pages/results.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
// The results page is behind auth and reads HIDE_HISTORY at module load, so the env is
// set and a session cookie minted before the page is imported below. buildDownloadUrl
// has no env dependency, so importing it statically above is safe.
const JWT_SECRET = "test-secret";
process.env.DB_PATH = ":memory:";
process.env.JWT_SECRET = JWT_SECRET;
process.env.HIDE_HISTORY = "true";
process.env.WEBROOT = "";

import { createHmac } from "node:crypto";
import { expect, test } from "bun:test";
import { buildDownloadUrl } from "../../src/helpers/buildDownloadUrl";

const { default: db } = await import("../../src/db/db");
const { results } = await import("../../src/pages/results");

test("encodes reserved characters in download filenames", () => {
expect(buildDownloadUrl("", "1/2/", "clip #1?.gif")).toBe("/download/1/2/clip%20%231%3F.gif");
});
Expand All @@ -10,3 +23,33 @@ test("preserves output path segments while encoding the filename", () => {
"/convertx/download/user/job/%E5%A0%B1%E5%91%8A%20100%25.pdf",
);
});

// Minimal HS256 JWT so the authenticated route renders; @elysiajs/jwt verifies it.
function sessionCookie(): string {
const b64url = (value: string) => Buffer.from(value).toString("base64url");
const payload = `${b64url(JSON.stringify({ alg: "HS256", typ: "JWT" }))}.${b64url(
JSON.stringify({ id: "1", exp: Math.floor(Date.now() / 1000) + 3600 }),
)}`;
const signature = createHmac("sha256", JWT_SECRET).update(payload).digest("base64url");
return `auth=${payload}.${signature}`;
}

// Regression test for #556 on the results page (the scenario in the report: the header
// shown right after a conversion). Previously this page omitted the hideHistory prop.
test("results page hides the History link when HIDE_HISTORY is set", async () => {
db.query("INSERT INTO users (id, email, password) VALUES (1, 'test@example.com', 'x')").run();
db.query(
"INSERT INTO jobs (id, user_id, date_created, status, num_files) VALUES (1, 1, '2026-01-01', 'done', 0)",
).run();

const res = await results.handle(
new Request("http://localhost/results/1", { headers: { Cookie: sessionCookie() } }),
);
expect(res.status).toBe(200);

const html = await res.text();
// Sanity: the authenticated header actually rendered.
expect(html).toContain('href="/account"');
// The History link must be gone.
expect(html).not.toContain('href="/history"');
});
Loading