mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
Consolidate cached and fetched Codex manual handling (#55342)
Share outline generation and status construction in `fetchCodexManual` after loading a verified cached manual or fetching and validating a fresh copy. Preserve cache status reporting and SHA-256 checks while removing the duplicated cache-hit return path. GitOrigin-RevId: 2dd2046a65e9a3adbca4d269827501d5ab175f36
This commit is contained in:
committed by
copyberry
parent
8f8e7a6e09
commit
982695cdbc
@@ -426,52 +426,31 @@ const fetchCodexManual = async ({
|
||||
const outlinePath = outlineFilePath(resolvedCacheDir);
|
||||
const checkedAt = new Date().toISOString();
|
||||
|
||||
const cachedManual = await readCachedManual(resolvedCacheDir, expectedSha256);
|
||||
if (cachedManual !== null) {
|
||||
const outline = buildOutline(cachedManual);
|
||||
const outlineText = outlineMarkdown(outline);
|
||||
await writeOutline(resolvedCacheDir, outlineText);
|
||||
let manualText = await readCachedManual(resolvedCacheDir, expectedSha256);
|
||||
const cacheStatus = manualText === null ? "updated" : "hit";
|
||||
if (manualText === null) {
|
||||
const getResponse = await requestManual(manualUrl, {
|
||||
cacheDir: resolvedCacheDir,
|
||||
method: "GET",
|
||||
timeoutMs,
|
||||
});
|
||||
const getHeaderSha256 = readHeaderSha(getResponse);
|
||||
if (getHeaderSha256 !== expectedSha256) {
|
||||
throw new ManualFetchError(
|
||||
`${HASH_HEADER} changed between HEAD and GET for ${manualUrl}.`,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
outlineText,
|
||||
status: {
|
||||
manualUrl,
|
||||
headerSha256: expectedSha256,
|
||||
fetchedManualSha256: expectedSha256,
|
||||
manualHashMatches: true,
|
||||
cacheStatus: "hit",
|
||||
cacheDir: resolvedCacheDir,
|
||||
manualPath,
|
||||
outlinePath,
|
||||
checkedAt,
|
||||
lineCount: outline.lineCount,
|
||||
headingCount: outline.headingCount,
|
||||
},
|
||||
};
|
||||
manualText = await getResponse.text();
|
||||
if (sha256(manualText) !== expectedSha256) {
|
||||
throw new ManualFetchError(
|
||||
`${HASH_HEADER} did not match the fetched manual body for ${manualUrl}.`,
|
||||
);
|
||||
}
|
||||
|
||||
await writeCachedManual(resolvedCacheDir, manualText);
|
||||
}
|
||||
|
||||
const getResponse = await requestManual(manualUrl, {
|
||||
cacheDir: resolvedCacheDir,
|
||||
method: "GET",
|
||||
timeoutMs,
|
||||
});
|
||||
const getHeaderSha256 = readHeaderSha(getResponse);
|
||||
if (getHeaderSha256 !== expectedSha256) {
|
||||
throw new ManualFetchError(
|
||||
`${HASH_HEADER} changed between HEAD and GET for ${manualUrl}.`,
|
||||
);
|
||||
}
|
||||
|
||||
const manualText = await getResponse.text();
|
||||
const actualSha256 = sha256(manualText);
|
||||
const manualHashMatches = actualSha256 === expectedSha256;
|
||||
if (!manualHashMatches) {
|
||||
throw new ManualFetchError(
|
||||
`${HASH_HEADER} did not match the fetched manual body for ${manualUrl}.`,
|
||||
);
|
||||
}
|
||||
|
||||
await writeCachedManual(resolvedCacheDir, manualText);
|
||||
const outline = buildOutline(manualText);
|
||||
const outlineText = outlineMarkdown(outline);
|
||||
await writeOutline(resolvedCacheDir, outlineText);
|
||||
@@ -481,9 +460,9 @@ const fetchCodexManual = async ({
|
||||
status: {
|
||||
manualUrl,
|
||||
headerSha256: expectedSha256,
|
||||
fetchedManualSha256: actualSha256,
|
||||
manualHashMatches,
|
||||
cacheStatus: "updated",
|
||||
fetchedManualSha256: expectedSha256,
|
||||
manualHashMatches: true,
|
||||
cacheStatus,
|
||||
cacheDir: resolvedCacheDir,
|
||||
manualPath,
|
||||
outlinePath,
|
||||
|
||||
Reference in New Issue
Block a user