e0a5f57793
Vendor the rebranded BoosAPI Desktop client (Tauri + Vue) into metapi as a monorepo subdirectory under desktop/. Source only — node_modules, dist, Cargo target and the upstream .git history are excluded. desktop/ keeps its own independent Cargo workspace (desktop/src-tauri with crates/*); it is not part of the backend boosapi crate, so a `cargo check` at the metapi root still compiles only the backend. Build the desktop app from desktop/src-tauri per desktop/README.md. Note: app icons are still placeholder assets pending the final BoosAPI logo. The updater signing keys live outside the repo and are not included.
96 lines
2.8 KiB
TypeScript
96 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
clearHeightEstimationExperiment,
|
|
estimateCodeBlockHeight,
|
|
getHeightEstimationExperiment,
|
|
getHeightEstimationRendererController,
|
|
registerHeightEstimationRendererController,
|
|
setHeightEstimationExperiment,
|
|
} from '../src/internal/heightEstimationExperiment'
|
|
|
|
describe('height estimation experiment internals', () => {
|
|
it('stores config per custom id', () => {
|
|
setHeightEstimationExperiment('test-height-exp', {
|
|
enabled: true,
|
|
textEstimation: true,
|
|
codeBlockEstimation: false,
|
|
})
|
|
|
|
expect(getHeightEstimationExperiment('test-height-exp')).toEqual({
|
|
enabled: true,
|
|
textEstimation: true,
|
|
codeBlockEstimation: false,
|
|
})
|
|
|
|
clearHeightEstimationExperiment('test-height-exp')
|
|
expect(getHeightEstimationExperiment('test-height-exp')).toBeNull()
|
|
})
|
|
|
|
it('registers and removes renderer controllers', () => {
|
|
const controller = {
|
|
captureRestoreAnchor: () => ({ nodeIndex: 4, offsetWithinNodePx: 12 }),
|
|
restoreAnchor: () => {},
|
|
getAnchorDrift: () => 0,
|
|
getReport: () => ({
|
|
totalNodes: 1,
|
|
measuredCount: 1,
|
|
estimatedCount: 0,
|
|
averageNodeHeight: 20,
|
|
topSpacerHeight: 0,
|
|
bottomSpacerHeight: 0,
|
|
estimatedTotalHeight: 20,
|
|
width: 320,
|
|
nodes: [],
|
|
}),
|
|
}
|
|
|
|
const cleanup = registerHeightEstimationRendererController('test-height-controller', controller)
|
|
expect(getHeightEstimationRendererController('test-height-controller')).toBe(controller)
|
|
cleanup()
|
|
expect(getHeightEstimationRendererController('test-height-controller')).toBeNull()
|
|
})
|
|
|
|
it('estimates markdown code block height deterministically', () => {
|
|
const estimated = estimateCodeBlockHeight(
|
|
{
|
|
type: 'code_block',
|
|
language: 'ts',
|
|
code: 'one\ntwo\nthree',
|
|
raw: '```ts\none\ntwo\nthree\n```',
|
|
} as any,
|
|
{
|
|
rendererKind: 'markdown',
|
|
showHeader: true,
|
|
},
|
|
)
|
|
|
|
expect(estimated?.kind).toBe('code-block')
|
|
expect(estimated?.rendererKind).toBe('markdown')
|
|
expect(estimated?.contentHeight).toBeGreaterThan(0)
|
|
expect(estimated?.height).toBeGreaterThan(estimated?.contentHeight ?? 0)
|
|
})
|
|
|
|
it('caps monaco estimate by max height', () => {
|
|
const estimated = estimateCodeBlockHeight(
|
|
{
|
|
type: 'code_block',
|
|
language: 'ts',
|
|
code: new Array(120).fill('console.log("x")').join('\n'),
|
|
raw: '```ts\n...\n```',
|
|
} as any,
|
|
{
|
|
rendererKind: 'monaco',
|
|
monacoOptions: {
|
|
fontSize: 13,
|
|
lineHeight: 30,
|
|
MAX_HEIGHT: 320,
|
|
},
|
|
showHeader: true,
|
|
},
|
|
)
|
|
|
|
expect(estimated?.contentHeight).toBe(320)
|
|
expect(estimated?.height).toBe(360)
|
|
})
|
|
})
|