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: 1 addition & 1 deletion apps/api/src/routes/tasks/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HonoEnv } from "../../types";
import type { HonoEnv } from "#types";
import { isValidUnicodeVersion } from "@ucdjs-internal/shared";
import {
badGateway,
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/routes/v1_files/$wildcard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { UnicodeAssetOptions } from "#lib/files";
import type { HonoEnv } from "#types";
import type { OpenAPIHono } from "@hono/zod-openapi";
import type { StatusCode } from "hono/utils/http-status";
import type { UnicodeAssetOptions } from "../../lib/files";
import type { HonoEnv } from "../../types";
import { getUnicodeAsset } from "#lib/files";
import { createRoute, z } from "@hono/zod-openapi";
import { dedent } from "@luxass/utils";
import { customError, MAX_AGE_ONE_WEEK_SECONDS } from "@ucdjs-internal/worker-utils";
Expand All @@ -14,7 +15,6 @@ import {
} from "@ucdjs/env";
import { FileEntryListSchema } from "@ucdjs/schemas";
import { cache } from "hono/cache";
import { getUnicodeAsset } from "../../lib/files";
import { generateReferences, OPENAPI_TAGS } from "../../openapi";
import {
ORDER_QUERY_PARAM,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_files/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HonoEnv } from "../../types";
import type { HonoEnv } from "#types";
import { OpenAPIHono } from "@hono/zod-openapi";
import { V1_FILES_ROUTER_BASE_PATH } from "../../constants";
import { registerWildcardRoute } from "./$wildcard";
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_schemas/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HonoEnv } from "../../types";
import type { HonoEnv } from "#types";
import { tryOr } from "@ucdjs-internal/shared";
import { MAX_AGE_ONE_DAY_SECONDS } from "@ucdjs-internal/worker-utils";
import { LockfileSchema, SnapshotSchema } from "@ucdjs/schemas";
Expand Down
10 changes: 4 additions & 6 deletions apps/api/src/routes/v1_versions/$version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { HonoEnv } from "#types";
import type { OpenAPIHono } from "@hono/zod-openapi";
import type { UnicodeFileTree } from "@ucdjs/schemas";
import type { HonoEnv } from "../../types";
import { createLogger } from "#lib/logger";
import { captureUpstreamError, COMPONENTS } from "#lib/sentry";
import { VERSION_ROUTE_PARAM } from "#lib/shared-parameters";
import { createRoute } from "@hono/zod-openapi";
import { dedent } from "@luxass/utils";
import { isValidUnicodeVersion } from "@ucdjs-internal/shared";
Expand All @@ -9,15 +12,10 @@ import { UnicodeFileTreeSchema, UnicodeVersionDetailsSchema } from "@ucdjs/schem
import {
hasUCDFolderPath,
resolveUCDVersion,
UNICODE_DRAFT_VERSION,
UNICODE_STABLE_VERSION,
UNICODE_VERSION_METADATA,
} from "@unicode-utils/core";
import { traverse } from "apache-autoindex-parse/traverse";
import { cache } from "hono/cache";
import { createLogger } from "../../lib/logger";
import { captureUpstreamError, COMPONENTS } from "../../lib/sentry";
import { VERSION_ROUTE_PARAM } from "../../lib/shared-parameters";
import { generateReferences, OPENAPI_TAGS } from "../../openapi";
import { calculateStatistics, getVersionFromList } from "./utils";

Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/routes/v1_versions/list.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { HonoEnv } from "#types";
import type { OpenAPIHono } from "@hono/zod-openapi";
import type { HonoEnv } from "../../types";
import { createLogger } from "#lib/logger";
import { captureError, captureUpstreamError, COMPONENTS } from "#lib/sentry";
import { createRoute } from "@hono/zod-openapi";
import { dedent } from "@luxass/utils";
import { badGateway, MAX_AGE_ONE_DAY_SECONDS } from "@ucdjs-internal/worker-utils";
import { UnicodeVersionListSchema } from "@ucdjs/schemas";
import { cache } from "hono/cache";
import { createLogger } from "../../lib/logger";
import { captureError, captureUpstreamError, COMPONENTS } from "../../lib/sentry";
import { generateReferences, OPENAPI_TAGS } from "../../openapi";
import { getAllVersionsFromList } from "./utils";

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_versions/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HonoEnv } from "../../types";
import type { HonoEnv } from "#types";
import { OpenAPIHono } from "@hono/zod-openapi";
import { V1_VERSIONS_ROUTER_BASE_PATH } from "../../constants";
import { registerGetVersionRoute, registerVersionFileTreeRoute } from "./$version";
Expand Down
12 changes: 5 additions & 7 deletions apps/api/src/routes/v1_versions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { HonoEnv } from "#types";
import type { UnicodeVersion } from "@ucdjs/schemas";
import type { HonoEnv } from "../../types";
import { getRawUnicodeAsset } from "#lib/files";
import { createLogger } from "#lib/logger";
import { captureParseError, captureUpstreamError, COMPONENTS } from "#lib/sentry";
import { wrapTry } from "@ucdjs-internal/shared";
import {
getCurrentDraftVersion,
resolveUCDVersion,
} from "@unicode-utils/core";
import { getRawUnicodeAsset } from "../../lib/files";
import { createLogger } from "../../lib/logger";
import { captureParseError, captureUpstreamError, COMPONENTS } from "../../lib/sentry";

const log = createLogger("ucd:api:v1_versions:utils");

Expand Down Expand Up @@ -71,10 +71,8 @@ export async function getAllVersionsFromList() {
throw error;
}

const text: string = await getDraftVersionText();

const draft = await getCurrentDraftVersion({
text,
text: await getDraftVersionText(),
onError(error) {
log.error("Error fetching current draft version", { error });
let tmpError: Error;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/well-known/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HonoEnv } from "../../types";
import type { HonoEnv } from "#types";
import { OpenAPIHono } from "@hono/zod-openapi";
import { WELL_KNOWN_ROUTER_BASE_PATH } from "../../constants";
import { registerUcdConfigRoute } from "./ucd-config.json";
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/well-known/ucd-config.json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HonoEnv } from "#types";
import type { OpenAPIHono } from "@hono/zod-openapi";
import type { HonoEnv } from "../../types";
import { createRoute } from "@hono/zod-openapi";
import { dedent } from "@luxass/utils";
import { badGateway, MAX_AGE_ONE_DAY_SECONDS } from "@ucdjs-internal/worker-utils";
Expand Down
63 changes: 62 additions & 1 deletion apps/api/test/routes/v1_versions/list.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { UnicodeVersion } from "@ucdjs/schemas";
import { getRawUnicodeAsset } from "#lib/files";
import { HttpResponse, mockFetch } from "#test-utils/msw";
import { getCurrentDraftVersion, resolveUCDVersion } from "@unicode-utils/core";
import { env } from "cloudflare:workers";
Expand All @@ -16,11 +17,15 @@ vi.mock("@unicode-utils/core", async (importOriginal) => {

return {
...original,
getCurrentDraftVersion: vi.fn(() => original.getCurrentDraftVersion()),
getCurrentDraftVersion: vi.fn((...args) => original.getCurrentDraftVersion(...args)),
resolveUCDVersion: vi.fn((version) => original.resolveUCDVersion(version)),
};
});

vi.mock("#lib/files", () => ({
getRawUnicodeAsset: vi.fn((path) => getRawUnicodeAsset(path)),
}));

Comment on lines +25 to +28
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

The mock implementation creates a circular reference by calling the imported getRawUnicodeAsset function. This defeats the purpose of mocking since the mock is trying to call the real implementation, which is from the module being mocked. The mock should either return a function that doesn't call the real implementation, or use importOriginal similar to how the @unicode-utils/core mock is set up above.

Suggested change
vi.mock("#lib/files", () => ({
getRawUnicodeAsset: vi.fn((path) => getRawUnicodeAsset(path)),
}));
vi.mock("#lib/files", async (importOriginal) => {
const original = await importOriginal<typeof import("#lib/files")>();
return {
...original,
getRawUnicodeAsset: vi.fn((path) => original.getRawUnicodeAsset(path)),
};
});

Copilot uses AI. Check for mistakes.
beforeEach(() => {
vi.resetAllMocks();
});
Expand Down Expand Up @@ -52,6 +57,14 @@ describe("v1_versions", () => {
it("should return unicode versions with proper structure", async () => {
vi.mocked(getCurrentDraftVersion).mockResolvedValue(null);
vi.mocked(resolveUCDVersion).mockImplementation((version) => version);
vi.mocked(getRawUnicodeAsset).mockResolvedValue({
ok: true,
status: 200,
response: new Response("Mock draft ReadMe content"),
url: "https://unicode.org/Public/draft/ReadMe.txt?F=2",
normalizedPath: "draft/ReadMe.txt",
extension: "txt",
});

mockFetch([
["GET", "https://www.unicode.org/versions/enumeratedversions.html", () => {
Expand Down Expand Up @@ -85,6 +98,14 @@ describe("v1_versions", () => {
it("should handle draft versions correctly", async () => {
vi.mocked(getCurrentDraftVersion).mockResolvedValue("17.0.0");
vi.mocked(resolveUCDVersion).mockImplementation((version) => version);
vi.mocked(getRawUnicodeAsset).mockResolvedValue({
ok: true,
status: 200,
response: new Response("Mock draft ReadMe content"),
url: "https://unicode.org/Public/draft/ReadMe.txt?F=2",
normalizedPath: "draft/ReadMe.txt",
extension: "txt",
});

mockFetch([
["GET", "https://www.unicode.org/versions/enumeratedversions.html", () => {
Expand Down Expand Up @@ -117,6 +138,14 @@ describe("v1_versions", () => {
if (version === "15.0.0") return "15.0.0-Update1"; // Different mapping
return version;
});
vi.mocked(getRawUnicodeAsset).mockResolvedValue({
ok: true,
status: 200,
response: new Response("Mock draft ReadMe content"),
url: "https://unicode.org/Public/draft/ReadMe.txt?F=2",
normalizedPath: "draft/ReadMe.txt",
extension: "txt",
});

mockFetch([
["GET", "https://www.unicode.org/versions/enumeratedversions.html", () => {
Expand Down Expand Up @@ -215,6 +244,14 @@ describe("v1_versions", () => {
it("should handle getCurrentDraftVersion throwing error", async () => {
vi.mocked(getCurrentDraftVersion).mockRejectedValue(new Error("Draft version fetch failed"));
vi.mocked(resolveUCDVersion).mockImplementation((version) => version);
vi.mocked(getRawUnicodeAsset).mockResolvedValue({
ok: true,
status: 200,
response: new Response("Mock draft ReadMe content"),
url: "https://unicode.org/Public/draft/ReadMe.txt?F=2",
normalizedPath: "draft/ReadMe.txt",
extension: "txt",
});

mockFetch([
["GET", "https://www.unicode.org/versions/enumeratedversions.html", () => {
Expand All @@ -237,6 +274,14 @@ describe("v1_versions", () => {
it("should set proper cache headers", async () => {
vi.mocked(getCurrentDraftVersion).mockResolvedValue(null);
vi.mocked(resolveUCDVersion).mockImplementation((version) => version);
vi.mocked(getRawUnicodeAsset).mockResolvedValue({
ok: true,
status: 200,
response: new Response("Mock draft ReadMe content"),
url: "https://unicode.org/Public/draft/ReadMe.txt?F=2",
normalizedPath: "draft/ReadMe.txt",
extension: "txt",
});

mockFetch([
["GET", "https://www.unicode.org/versions/enumeratedversions.html", () => {
Expand All @@ -256,6 +301,14 @@ describe("v1_versions", () => {
it("should sort versions correctly (newest first)", async () => {
vi.mocked(getCurrentDraftVersion).mockResolvedValue(null);
vi.mocked(resolveUCDVersion).mockImplementation((version) => version);
vi.mocked(getRawUnicodeAsset).mockResolvedValue({
ok: true,
status: 200,
response: new Response("Mock draft ReadMe content"),
url: "https://unicode.org/Public/draft/ReadMe.txt?F=2",
normalizedPath: "draft/ReadMe.txt",
extension: "txt",
});

mockFetch([
["GET", "https://www.unicode.org/versions/enumeratedversions.html", () => {
Expand All @@ -279,6 +332,14 @@ describe("v1_versions", () => {
it("should handle versions with mixed year formats", async () => {
vi.mocked(getCurrentDraftVersion).mockResolvedValue(null);
vi.mocked(resolveUCDVersion).mockImplementation((version) => version);
vi.mocked(getRawUnicodeAsset).mockResolvedValue({
ok: true,
status: 200,
response: new Response("Mock draft ReadMe content"),
url: "https://unicode.org/Public/draft/ReadMe.txt?F=2",
normalizedPath: "draft/ReadMe.txt",
extension: "txt",
});

mockFetch([
["GET", "https://www.unicode.org/versions/enumeratedversions.html", () => {
Expand Down
Loading