Skip to content

Commit 654336d

Browse files
claude: Add test framework support for keep-typ/keep-tex in projects
The keep-typ and keep-tex options place intermediate files alongside the source file, not in the output directory. In project contexts (websites, books), the test framework now correctly locates these files. - Add inputFile parameter to verification functions - Distinguish keep-typ: true from output-ext: typ (different locations) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6c261fc commit 654336d

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

‎tests/smoke/smoke-all.test.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,23 @@ function resolveTestSpecs(
276276
throw new Error(`Using ensureLatexFileRegexMatches requires setting 'keep-tex: true' in file ${input}`);
277277
}
278278
}
279-
279+
280+
// keep-typ/keep-tex files are alongside source, so pass input path
281+
// But output-ext: typ puts files in output directory, so don't pass input path
282+
const usesKeepTyp = key === "ensureTypstFileRegexMatches" &&
283+
(metadata.format?.typst?.['keep-typ'] || metadata['keep-typ']) &&
284+
!(metadata.format?.typst?.['output-ext'] === 'typ' || metadata['output-ext'] === 'typ');
285+
const usesKeepTex = key === "ensureLatexFileRegexMatches" &&
286+
(metadata.format?.pdf?.['keep-tex'] || metadata['keep-tex']);
287+
const needsInputPath = usesKeepTyp || usesKeepTex;
280288
if (typeof value === "object" && Array.isArray(value)) {
281-
// Only use spread operator for arrays
282-
verifyFns.push(verifyMap[key](outputFile.outputPath, ...value));
289+
// value is [matches, noMatches?] - ensure inputFile goes in the right position
290+
const matches = value[0];
291+
const noMatches = value[1];
292+
const inputFile = needsInputPath ? input : undefined;
293+
verifyFns.push(verifyMap[key](outputFile.outputPath, matches, noMatches, inputFile));
283294
} else {
284-
verifyFns.push(verifyMap[key](outputFile.outputPath, value));
295+
verifyFns.push(verifyMap[key](outputFile.outputPath, value, undefined, needsInputPath ? input : undefined));
285296
}
286297
} else {
287298
throw new Error(`Unknown verify function used: ${key} in file ${input} for format ${format}`) ;

‎tests/verify.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,16 @@ export const ensureFileRegexMatches = (
586586

587587
// Use this function to Regex match text in the intermediate kept file
588588
// FIXME: do this properly without resorting on file having keep-*
589+
// Note: keep-typ/keep-tex places files alongside source, not in output dir
589590
export const verifyKeepFileRegexMatches = (
590591
toExt: string,
591592
keepExt: string,
592-
): (file: string, matchesUntyped: (string | RegExp)[], noMatchesUntyped?: (string | RegExp)[]) => Verify => {
593-
return (file: string, matchesUntyped: (string | RegExp)[], noMatchesUntyped?: (string | RegExp)[]) => {
594-
const keptFile = file.replace(`.${toExt}`, `.${keepExt}`);
593+
): (file: string, matchesUntyped: (string | RegExp)[], noMatchesUntyped?: (string | RegExp)[], inputFile?: string) => Verify => {
594+
return (file: string, matchesUntyped: (string | RegExp)[], noMatchesUntyped?: (string | RegExp)[], inputFile?: string) => {
595+
// Kept files are alongside source, so derive from inputFile if provided
596+
const keptFile = inputFile
597+
? join(dirname(inputFile), basename(file).replace(`.${toExt}`, `.${keepExt}`))
598+
: file.replace(`.${toExt}`, `.${keepExt}`);
595599
const keptFileChecker = async (file: string, matches: RegExp[], noMatches: RegExp[] | undefined) => {
596600
try {
597601
await regexChecker(file, matches, noMatches);
@@ -608,17 +612,19 @@ export const ensureTypstFileRegexMatches = (
608612
file: string,
609613
matchesUntyped: (string | RegExp)[],
610614
noMatchesUntyped?: (string | RegExp)[],
615+
inputFile?: string,
611616
): Verify => {
612-
return(verifyKeepFileRegexMatches("pdf", "typ")(file, matchesUntyped, noMatchesUntyped));
617+
return(verifyKeepFileRegexMatches("pdf", "typ")(file, matchesUntyped, noMatchesUntyped, inputFile));
613618
};
614619

615620
// FIXME: do this properly without resorting on file having keep-tex
616621
export const ensureLatexFileRegexMatches = (
617622
file: string,
618623
matchesUntyped: (string | RegExp)[],
619624
noMatchesUntyped?: (string | RegExp)[],
625+
inputFile?: string,
620626
): Verify => {
621-
return(verifyKeepFileRegexMatches("pdf", "tex")(file, matchesUntyped, noMatchesUntyped));
627+
return(verifyKeepFileRegexMatches("pdf", "tex")(file, matchesUntyped, noMatchesUntyped, inputFile));
622628
};
623629

624630
// Use this function to Regex match text in a rendered PDF file

0 commit comments

Comments
 (0)