* fix(draw-image): conditional slot bg + optional subtitle in buildSvg * test(draw-image): optional badge/subtitle unit+integration+e2e * feat(docker): self-healing entrypoint shim + .dockerignore * test(draw-image): pytest assert --subtitle omitted when absent * docs(handoff): optional badge/subtitle + docker entrypoint handoff+ADR * docs(handoff): set PR number 144 * docs(project-map): fix PR refs 143 to 144 --------- Co-authored-by: opencode-agent <agent@opencode.local>
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { describe, test, expect, beforeAll } from "vitest"
|
|
import { existsSync, readFileSync, rmSync, mkdirSync } from "node:fs"
|
|
import path from "node:path"
|
|
import { fileURLToPath } from "node:url"
|
|
import { spawnSync } from "node:child_process"
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
const DRAW_IMAGE_DIR = path.resolve(__dirname, "..")
|
|
const TMP = "/tmp/draw-image-optional-e2e"
|
|
const TMP_SVG = path.join(DRAW_IMAGE_DIR, ".tmp-render.svg")
|
|
|
|
beforeAll(() => {
|
|
if (existsSync(TMP)) rmSync(TMP, { recursive: true, force: true })
|
|
mkdirSync(TMP, { recursive: true })
|
|
})
|
|
|
|
function runCli(args: string[]): { status: number; stdout: string; stderr: string } {
|
|
return spawnSync("node", ["--experimental-strip-types", path.join(DRAW_IMAGE_DIR, "cli.ts"), ...args], {
|
|
encoding: "utf-8",
|
|
cwd: DRAW_IMAGE_DIR,
|
|
})
|
|
}
|
|
|
|
function assertPng(filePath: string) {
|
|
expect(existsSync(filePath), `PNG not found: ${filePath}`).toBe(true)
|
|
const buf = readFileSync(filePath)
|
|
expect(buf.length).toBeGreaterThan(1000)
|
|
expect(buf[0]).toBe(0x89)
|
|
expect(buf[1]).toBe(0x50)
|
|
expect(buf[2]).toBe(0x4e)
|
|
expect(buf[3]).toBe(0x47)
|
|
}
|
|
|
|
describe("e2e — optional subtitle and badge via CLI", () => {
|
|
test("render with title only → exit 0, valid PNG, svg has no empty badge and no subtitle", () => {
|
|
const out = path.join(TMP, "optional.png")
|
|
const r = runCli(["render", "cover", "--title", "Test", "--out", out])
|
|
expect(r.status, `stderr: ${r.stderr}`).toBe(0)
|
|
assertPng(out)
|
|
|
|
const svg = readFileSync(TMP_SVG, "utf-8")
|
|
expect(svg).not.toContain('x="780" y="780"')
|
|
expect(svg).not.toContain('y="930"')
|
|
expect(svg).not.toContain("{{subtitle}}")
|
|
})
|
|
})
|