ci: install PyMuPDF in runner; skip PDF text assertions when fitz is unavailable
build-extension / build (push) Failing after 20s

This commit is contained in:
2026-08-19 03:08:46 +08:00
parent 92a7408100
commit 41e7a4b81e
2 changed files with 21 additions and 1 deletions
+3
View File
@@ -21,6 +21,9 @@ jobs:
- name: Install dev dependencies
run: npm ci || npm install
- name: Install PyMuPDF (PDF text assertions)
run: python3 -m pip install --quiet pymupdf
- name: Run tests
run: npm test
+18 -1
View File
@@ -38,7 +38,19 @@ function extractPdfText(bytes) {
return execFileSync('python3', ['-c', script], { encoding: 'utf8' });
}
test('buildStudyLoadPdf returns valid PDF bytes', async () => {
// PyMuPDF (fitz) is only needed for the text-extraction assertions below. It is
// installed in CI, but if it is missing locally we skip those assertions rather
// than hard-failing.
function fitzAvailable() {
try {
execFileSync('python3', ['-c', 'import fitz'], { stdio: 'ignore' });
return true;
} catch {
return false;
}
}
test('buildStudyLoadPdf returns valid PDF bytes', async (t) => {
const bytes = await buildStudyLoadPdf(sampleData);
assert.ok(bytes instanceof Uint8Array);
const head = Buffer.from(bytes.slice(0, 5)).toString('latin1');
@@ -46,6 +58,11 @@ test('buildStudyLoadPdf returns valid PDF bytes', async () => {
const doc = await PDFLib.PDFDocument.load(bytes);
assert.strictEqual(doc.getPageCount(), 1);
if (!fitzAvailable()) {
t.skip('PyMuPDF (fitz) not available; skipping PDF text assertions');
return;
}
const text = extractPdfText(bytes);
assert.ok(text.includes('CIS 2101'), 'PDF text should contain course code CIS 2101');
assert.ok(text.includes("STUDENT'S STUDY LOAD"), 'PDF text should contain the title');