mirror of
https://github.com/garrytan/gstack.git
synced 2026-12-02 12:54:04 +01:00
make-pdf now prints in a bold Swiss-style layout by default: black bars for section headings, small red sub-headings in a left column beside the text, a large cover title, and a shorter, easier line. Generated documents should look designed, not default; Garry picked this look over today's in two rounds of blind comparisons. Nothing to do: pass `--style plain` to get exactly the PDF you got before. Word output always uses the plain look. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=red-team Review-Finding: p1/specialist-batched#2 reader=design-checklist Review-Finding: p2/red-team#1 reader=red-team Review-Finding: p2/outside-voice#1 reader=outside-voice Review-Finding: p2/outside-voice#2 reader=outside-voice Review-Finding: p2/outside-voice#3 reader=outside-voice Review-Finding: p2/outside-voice#4 reader=outside-voice Review-Finding: p2/adversarial-native#3 reader=adversarial-native Review-Finding: p2/specialist-batched#1 reader=specialist-batched
79 lines
3.5 KiB
TypeScript
79 lines
3.5 KiB
TypeScript
/**
|
|
* Combined-features copy-paste gate — the P0 CI gate.
|
|
*
|
|
* This test runs the compiled `make-pdf/dist/pdf` binary against a fixture
|
|
* that has every v1 typography feature on (smartypants, hyphens, chapter
|
|
* breaks, bold/italic, inline code, blockquote, lists, headings). It then
|
|
* pipes the output through pdftotext and asserts the extracted text
|
|
* matches the handwritten expected.txt.
|
|
*
|
|
* Codex round 2 told us this (not per-feature gates) is the real gate a
|
|
* user actually cares about — features interact, and the combined
|
|
* extraction is what predicts production quality.
|
|
*
|
|
* Gating: only runs when the compiled binary + a browser (Aside or browse) + pdftotext
|
|
* are all available. Skipped cleanly otherwise (local dev, CI runners).
|
|
*/
|
|
|
|
import { describe, expect, test } from "bun:test";
|
|
import { execFileSync } from "node:child_process";
|
|
import * as fs from "node:fs";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
|
|
import { copyPasteGate, resolvePdftotext } from "../../src/pdftotext";
|
|
import { browserAvailable, NO_BROWSER_REASON } from "../../../test/helpers/browser-available";
|
|
|
|
const FIXTURE = path.resolve(__dirname, "../fixtures/combined-gate.md");
|
|
const EXPECTED = path.resolve(__dirname, "../fixtures/combined-gate.expected.txt");
|
|
const ROOT = path.resolve(__dirname, "../../..");
|
|
const PDF_BIN = path.join(ROOT, "make-pdf/dist/pdf");
|
|
|
|
function prerequisitesAvailable(): { ok: true } | { ok: false; reason: string } {
|
|
if (!fs.existsSync(PDF_BIN)) return { ok: false, reason: `make-pdf binary missing (${PDF_BIN}). Run bun run build.` };
|
|
// Aside (macOS) or gstack's own browse binary (what CI builds) — a skip only when neither exists.
|
|
if (!browserAvailable()) return { ok: false, reason: NO_BROWSER_REASON };
|
|
if (!fs.existsSync(FIXTURE)) return { ok: false, reason: `fixture missing (${FIXTURE}).` };
|
|
if (!fs.existsSync(EXPECTED)) return { ok: false, reason: `expected.txt missing (${EXPECTED}).` };
|
|
try { resolvePdftotext(); } catch (err: any) { return { ok: false, reason: err.message }; }
|
|
return { ok: true };
|
|
}
|
|
|
|
describe("combined-features copy-paste gate", () => {
|
|
const avail = prerequisitesAvailable();
|
|
|
|
// Both looks extract the same text in the same order: swiss moves sub-headings
|
|
// into a left field and paints bars, and copy-paste must not notice.
|
|
for (const style of ["swiss", "plain"]) {
|
|
test.skipIf(!avail.ok)(`${style}: fixture PDF extracts cleanly through pdftotext`, () => {
|
|
if (!avail.ok) return; // satisfies the type checker
|
|
const outputPdf = path.join(os.tmpdir(), `make-pdf-combined-gate-${style}-${process.pid}.pdf`);
|
|
try {
|
|
execFileSync(PDF_BIN, ["generate", FIXTURE, outputPdf, "--quiet", "--style", style], {
|
|
encoding: "utf8",
|
|
timeout: 60_000,
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
expect(fs.existsSync(outputPdf)).toBe(true);
|
|
|
|
const expected = fs.readFileSync(EXPECTED, "utf8");
|
|
const result = copyPasteGate(outputPdf, expected);
|
|
if (!result.ok) {
|
|
// Attach the extracted text so CI logs make the failure diagnosable
|
|
process.stderr.write(`\n--- EXTRACTED ---\n${result.extracted}\n--- END ---\n\n`);
|
|
process.stderr.write(`--- REASONS ---\n${result.reasons.join("\n")}\n--- END ---\n`);
|
|
}
|
|
expect(result.ok).toBe(true);
|
|
} finally {
|
|
try { fs.unlinkSync(outputPdf); } catch { /* ignore */ }
|
|
}
|
|
}, 60000);
|
|
}
|
|
|
|
if (!avail.ok) {
|
|
test("prerequisites check", () => {
|
|
console.warn(`[skip] ${avail.reason}`);
|
|
});
|
|
}
|
|
});
|