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
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export function splitKnownFileExtension(
};
}

/** Config discovery depends on each candidate name matching the source that is returned. */
export function requiresExactPublishedPath(apiPath: string): boolean {
return /(?:^|\/)veryfront\.config\.(?:js|ts|mjs)$/.test(apiPath);
}

export function isNotFoundLikeError(error: unknown): boolean {
if (typeof error === "object" && error !== null) {
const status = Object.getOwnPropertyDescriptor(error, "status");
Expand Down
59 changes: 59 additions & 0 deletions src/platform/adapters/fs/veryfront/read-operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,30 @@ describe("ReadOperations", () => {
["pages/home.tsx", true],
]);
});

it("does not substitute another extension for a published config candidate", async () => {
const exactCalls: string[] = [];
const readOps = createReadyReadOps(
createMockClient({
getPublishedFileContentBytesWithinLimit: (path: string) => {
exactCalls.push(path);
if (path === "veryfront.config.ts") {
return Promise.resolve(new Uint8Array([7]));
}
return Promise.reject(API_CLIENT_ERROR.create({ detail: "not found", status: 404 }));
},
}),
false,
createReleaseContext("release-config"),
);

await assertRejects(
() => readOps.readFileBytesWithinLimit("veryfront.config.js", 1),
Error,
"404 Not Found: veryfront.config.js",
);
assertEquals(exactCalls, ["veryfront.config.js"]);
});
});

describe("readTextFile", () => {
Expand Down Expand Up @@ -729,6 +753,41 @@ describe("ReadOperations", () => {
assertEquals(publishedFetchPaths, ["pages/landing.tsx"]);
});

it("does not substitute another extension for a published config candidate", async () => {
const publishedFetchPaths: string[] = [];
let resolveCallCount = 0;
const client = createMockClient({
getPublishedFileContent: (path: string) => {
publishedFetchPaths.push(path);
if (path === "veryfront.config.ts") return Promise.resolve("typescript config");
return Promise.reject(
API_CLIENT_ERROR.create({ detail: "not found", status: 404 }),
);
},
resolveFileWithExtension: () => {
resolveCallCount++;
return Promise.resolve({
path: "veryfront.config.ts",
content: "typescript config",
});
},
});

const readOps = createReadyReadOps(
client,
false,
createReleaseContext("release-config"),
);

const error = await assertRejects(
() => readOps.readTextFile("veryfront.config.js"),
Error,
);
assertEquals((error as Error & { code?: string }).code, "ENOENT");
assertEquals(publishedFetchPaths, ["veryfront.config.js"]);
assertEquals(resolveCallCount, 0);
});

it("should fall back in parallel when pattern search fails for published 404", async () => {
let resolveCallCount = 0;
const publishedFetchPaths: string[] = [];
Expand Down
6 changes: 6 additions & 0 deletions src/platform/adapters/fs/veryfront/read-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getResolvedCacheKey,
isNotFoundLikeError,
READ_OPERATION_EXTENSION_PRIORITY as EXTENSION_PRIORITY,
requiresExactPublishedPath,
splitKnownFileExtension,
} from "./read-operations-helpers.ts";
import type { ResolvedContentContext } from "./types.ts";
Expand Down Expand Up @@ -119,6 +120,7 @@ export class ReadOperations {
return await this.readExactApiPath(apiPath, admittedLimit, isPublished, context);
} catch (error) {
if (!isPublished || !isNotFoundLikeError(error)) throw error;
if (requiresExactPublishedPath(apiPath)) throw error;
const split = splitKnownFileExtension(apiPath);
if (!split) throw error;
for (const extension of EXTENSION_PRIORITY) {
Expand Down Expand Up @@ -735,6 +737,10 @@ export class ReadOperations {
throw error;
}

if (requiresExactPublishedPath(apiPath)) {
throw createNotFoundLikeError(normalizedPath);
}

const fallbackContent = await this.tryFallbackExtensions(
apiPath,
cacheKey,
Expand Down