mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(webui): compact config viewer, clear unknown helper sel, harness port guard
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { filterSections, splitConfigSections } from '@/lib/config-sections'
|
||||
import { filterSections, initialFold, splitConfigSections } from '@/lib/config-sections'
|
||||
|
||||
const YAML = ['admin:', ' enabled: true', 'agents:', ' a:', ' url: x', ' b:', ' url: y', '"odd/key":', ' v: 1', 'redis:', ' addr: r'].join('\n')
|
||||
|
||||
@@ -42,3 +42,21 @@ describe('filterSections', () => {
|
||||
expect(filterSections(s, 'zzz')).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('initialFold', () => {
|
||||
const big = (key: string, n: number) => [`${key}:`, ...Array.from({ length: n - 1 }, (_, i) => ` k${i}: v`)].join('\n')
|
||||
const secs = splitConfigSections([big('small', 8), big('medium', 9), big('large', 40)].join('\n'))
|
||||
|
||||
it('collapses sections over 8 lines and keeps small ones open', () => {
|
||||
expect([...initialFold(secs, {})].sort()).toEqual(['large', 'medium'])
|
||||
})
|
||||
it('keeps the hash target open', () => {
|
||||
expect([...initialFold(secs, { target: 'large' })]).toEqual(['medium'])
|
||||
})
|
||||
it('keeps filter matches open', () => {
|
||||
expect([...initialFold(secs, { filter: 'med' })]).toEqual(['large'])
|
||||
})
|
||||
it('ignores a blank filter and an unknown target', () => {
|
||||
expect([...initialFold(secs, { filter: ' ', target: 'nope' })].sort()).toEqual(['large', 'medium'])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -38,3 +38,14 @@ export function filterSections(sections: ConfigSection[], query: string): Config
|
||||
const q = query.trim().toLowerCase()
|
||||
return q === '' ? sections : sections.filter((s) => s.key.toLowerCase().includes(q))
|
||||
}
|
||||
|
||||
const SMALL_SECTION_LINES = 8
|
||||
|
||||
/** Keys of the sections that start collapsed: all but small ones, filter matches and the jump target. */
|
||||
export function initialFold(sections: ConfigSection[], opts: { filter?: string; target?: string }): Set<string> {
|
||||
const matched = new Set(filterSections(sections, opts.filter ?? '').map((s) => s.key))
|
||||
const filtering = (opts.filter ?? '').trim() !== ''
|
||||
return new Set(
|
||||
sections.filter((s) => s.lineCount > SMALL_SECTION_LINES && s.key !== opts.target && !(filtering && matched.has(s.key))).map((s) => s.key),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { HELPER_IDS, HELPER_LABEL, formatHelperSel, parseHelperSel } from '@/lib/helper-forms'
|
||||
import { HELPER_IDS, HELPER_LABEL, formatHelperSel, isStaleHelperSel, parseHelperSel } from '@/lib/helper-forms'
|
||||
|
||||
describe('helper selection', () => {
|
||||
it('round-trips every helper id', () => {
|
||||
@@ -22,3 +22,14 @@ describe('helper selection', () => {
|
||||
for (const id of HELPER_IDS) expect(HELPER_LABEL[id]).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('isStaleHelperSel', () => {
|
||||
it('is false when absent or a valid helper', () => {
|
||||
expect(isStaleHelperSel(undefined)).toBe(false)
|
||||
expect(isStaleHelperSel('helper:router')).toBe(false)
|
||||
})
|
||||
it('is true for an unknown helper id or a foreign sel the Config page cannot open', () => {
|
||||
expect(isStaleHelperSel('helper:bogus')).toBe(true)
|
||||
expect(isStaleHelperSel('user:alice')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -25,3 +25,8 @@ export function parseHelperSel(v: string | undefined): HelperId | null {
|
||||
const id = v.slice(PREFIX.length + 1)
|
||||
return (HELPER_IDS as readonly string[]).includes(id) ? (id as HelperId) : null
|
||||
}
|
||||
|
||||
/** True when `sel` is set but opens no helper form; the Config page has no other sheet, so it clears such a value. */
|
||||
export function isStaleHelperSel(v: string | undefined): boolean {
|
||||
return v !== undefined && parseHelperSel(v) === null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user