fix(cli): prepare fonts for RPC diagnostics

This commit is contained in:
Danila Poyarkov 2026-09-01 11:43:37 +03:00
parent 73cb945cbc
commit 41f445ebab
2 changed files with 10 additions and 6 deletions

View file

@ -1,6 +1,6 @@
import type { SceneGraph, SceneNode } from '@open-pencil/scene-graph'
import { documentFontStatus, type DocumentFontStatus } from '#core/text/font/status'
import { prepareGraphFonts } from '#core/text/prepare'
import { queryByXPath } from '#core/xpath'
import type { RPCCommand } from './types'
@ -79,7 +79,10 @@ export const infoCommand: RPCCommand<void, InfoResult> = {
export const fontStatusCommand: RPCCommand<void, DocumentFontStatus> = {
name: 'font-status',
execute: (graph) => documentFontStatus(graph, graph.getPages()[0]?.id ?? graph.rootId)
execute: async (graph) => {
const pageId = graph.getPages()[0]?.id ?? graph.rootId
return prepareGraphFonts(graph, pageId, [pageId])
}
}
// ── pages ──

View file

@ -4,6 +4,7 @@ import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { BUILTIN_IO_FORMATS, IORegistry } from '@open-pencil/core/io'
import type { DocumentFontStatus } from '@open-pencil/core/text'
import { runOpenPencilCLI } from '#tests/helpers/cli'
import { repoPath, requireBuiltWorkspacePackages } from '#tests/helpers/paths'
@ -34,9 +35,9 @@ test('reports bundled fonts as available', async () => {
const { stdout, stderr, exitCode } = await runOpenPencilCLI(['fonts', GOLD, '--json'])
expect(stderr).toBe('')
expect(exitCode).toBe(0)
const data = JSON.parse(stdout)
const data: DocumentFontStatus = JSON.parse(stdout)
expect(data.faithful).toBe(true)
expect(data.faces.every((face: { source: string }) => face.source === 'bundled')).toBe(true)
expect(data.faces.every((face) => face.source === 'bundled')).toBe(true)
})
heavy('fonts CLI', () => {
@ -45,10 +46,10 @@ heavy('fonts CLI', () => {
const { stdout, stderr, exitCode } = await runOpenPencilCLI(['fonts', fixture, '--json'])
expect(stderr).toBe('')
expect(exitCode).toBe(0)
const data = JSON.parse(stdout)
const data: DocumentFontStatus = JSON.parse(stdout)
expect(data.faithful).toBe(false)
expect(data.issues.length).toBeGreaterThan(0)
expect(data.issues.every((face: { status: string }) => face.status === 'unresolved')).toBe(true)
expect(data.issues.every((face) => face.status === 'unresolved')).toBe(true)
})
test('uses the standard human-readable formatter', async () => {
const { stdout, stderr, exitCode } = await runOpenPencilCLI(['fonts', GOLD])