mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
fix(docsync): read the retry limit back out, debounce the webhook, and cover the UI
The attempt counter and the backoff were written on every failure and never consulted when planning the next run: rows were found in a live database at 46 attempts against a limit of 6, so a document a provider refuses — one it reads as corrupt, a type it will not take, a full quota — was re-uploaded on every cron tick forever. planReconcile now skips a row that is shelved or still inside its window, and a manual run clears the counters, which is what "waits for a person" has to mean. The webhook had the same shape of bug: WEBHOOK_NUDGE_DEBOUNCE_SECONDS existed, with a comment explaining it, and nothing read it. Providers fire once per document, so twenty files dropped into a watched folder were twenty runs — the in-flight guard answered `busy` to nineteen of them, throwing away nineteen announcements, and the one run that did start had begun before most of the changes landed. A burst now folds into one trailing run, and the binding is re-read when the timer fires so a sync switched off in between does not get a last run out of a stale row. Four defects the new suites turned up, all fixed: the sync button lost its accessible name below sm, where its label is hidden; the stored address was never shown in the connect dialog although the form kept submitting it; the allow-self-signed switch only read the connection at mount, so a stored "on" showed as off and the next save wrote that back; and a refused folder create escaped as an unhandled rejection with nothing said to anybody. Also here: the phone shell gets the same feature (one sheet, four views, the same hook as the desktop), the marks come from the product's own icon files rather than redrawn approximations, and the 22 non-English locales carry the new keys. ADMIN-SVC-069 asserted that `documents` has no MCP surface. It does now, so the test takes its example from MCP_GATED_ADDON_IDS instead of naming one.
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
// FE-DOCSYNC-ICONS-001 to FE-DOCSYNC-ICONS-014
|
||||
|
||||
/**
|
||||
* The document providers' marks, and TREK's own.
|
||||
*
|
||||
* These are static files, so the only things worth holding still are the ones a
|
||||
* person would notice if they slipped: a provider the server seeds but the
|
||||
* client has no glyph for (the row renders nothing at all), a mark that keeps a
|
||||
* brand colour and so stays black on a dark background, and the sizing contract
|
||||
* the callers rely on — `size` for the bare lucide-sized rows, a `className`
|
||||
* everywhere the surrounding Tailwind box decides how big the glyph is.
|
||||
*/
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { DOCUMENT_PROVIDER_IDS } from '@trek/shared'
|
||||
import { render } from '../../../tests/helpers/render'
|
||||
import { DOCUMENT_PROVIDER_ICONS } from './DocumentProviderIcons'
|
||||
import TrekMark from './TrekMark'
|
||||
|
||||
const marks = Object.entries(DOCUMENT_PROVIDER_ICONS)
|
||||
|
||||
/** The svg plus everything drawn inside it. */
|
||||
function allElements(svg: SVGElement): Element[] {
|
||||
return [svg, ...Array.from(svg.querySelectorAll('*'))]
|
||||
}
|
||||
|
||||
function renderMark(Icon: (typeof marks)[number][1], props: Record<string, unknown> = {}): SVGElement {
|
||||
const { container } = render(<Icon {...props} />)
|
||||
const svg = container.querySelector('svg')
|
||||
if (!svg) throw new Error('no svg rendered')
|
||||
return svg as unknown as SVGElement
|
||||
}
|
||||
|
||||
describe('DOCUMENT_PROVIDER_ICONS', () => {
|
||||
it('FE-DOCSYNC-ICONS-001: carries exactly one mark per provider the server seeds', () => {
|
||||
// A provider seeded without a glyph here renders an empty slot in the
|
||||
// connect modal and the addon shelf; a glyph with no provider is dead code.
|
||||
expect(Object.keys(DOCUMENT_PROVIDER_ICONS).sort()).toEqual([...DOCUMENT_PROVIDER_IDS].sort())
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-002: resolves each id the way the panels look one up', () => {
|
||||
for (const id of DOCUMENT_PROVIDER_IDS) {
|
||||
expect(typeof DOCUMENT_PROVIDER_ICONS[id], id).toBe('function')
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-003: renders an svg for every provider', () => {
|
||||
for (const [id, Icon] of marks) {
|
||||
const { container } = render(<Icon />)
|
||||
expect(container.querySelector('svg'), id).not.toBeNull()
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-004: draws only in currentColor, so the mark inverts with the theme', () => {
|
||||
const hex = /#[0-9a-f]{3}/i
|
||||
|
||||
for (const [id, Icon] of marks) {
|
||||
const svg = renderMark(Icon)
|
||||
const painted: string[] = []
|
||||
|
||||
for (const el of allElements(svg)) {
|
||||
for (const attr of Array.from(el.attributes)) {
|
||||
expect(attr.value, `${id} ${attr.name}`).not.toMatch(hex)
|
||||
if (attr.name === 'fill' || attr.name === 'stroke') painted.push(attr.value)
|
||||
}
|
||||
}
|
||||
|
||||
expect(painted.length, id).toBeGreaterThan(0)
|
||||
for (const value of painted) expect(['currentColor', 'none'], id).toContain(value)
|
||||
expect(painted, id).toContain('currentColor')
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-005: keeps a viewBox, so the glyph scales instead of cropping', () => {
|
||||
for (const [id, Icon] of marks) {
|
||||
expect(renderMark(Icon).getAttribute('viewBox'), id).toMatch(/^0 0 \d+ \d+$/)
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-006: stays out of the accessibility tree — the provider name is next to it', () => {
|
||||
for (const [id, Icon] of marks) {
|
||||
expect(renderMark(Icon).getAttribute('aria-hidden'), id).toBe('true')
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-007: sizes itself to 20px when nothing says otherwise', () => {
|
||||
for (const [id, Icon] of marks) {
|
||||
const svg = renderMark(Icon)
|
||||
expect(svg.getAttribute('width'), id).toBe('20')
|
||||
expect(svg.getAttribute('height'), id).toBe('20')
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-008: honours an explicit size', () => {
|
||||
for (const [id, Icon] of marks) {
|
||||
const svg = renderMark(Icon, { size: 32 })
|
||||
expect(svg.getAttribute('width'), id).toBe('32')
|
||||
expect(svg.getAttribute('height'), id).toBe('32')
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-009: drops its own width and height once a className sizes it', () => {
|
||||
// Callers pass utility classes (`h-6 w-6`); a width attribute would win over
|
||||
// them on some of these and leave a 20px glyph in a 24px box.
|
||||
for (const [id, Icon] of marks) {
|
||||
const svg = renderMark(Icon, { className: 'h-6 w-6', size: 32 })
|
||||
expect(svg.getAttribute('width'), id).toBeNull()
|
||||
expect(svg.getAttribute('height'), id).toBeNull()
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-010: puts the caller className on the svg', () => {
|
||||
for (const [id, Icon] of marks) {
|
||||
expect(renderMark(Icon, { className: 'h-6 w-6 text-content' }).getAttribute('class'), id).toBe(
|
||||
'h-6 w-6 text-content',
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('TrekMark', () => {
|
||||
it('FE-DOCSYNC-ICONS-011: renders TREK\u2019s mark in currentColor', () => {
|
||||
const { container } = render(<TrekMark />)
|
||||
const svg = container.querySelector('svg')
|
||||
|
||||
expect(svg).not.toBeNull()
|
||||
expect(svg!.getAttribute('viewBox')).toBe('0 0 512 512')
|
||||
expect(svg!.querySelectorAll('path[fill="currentColor"]').length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-012: takes a className, which is the only thing that sizes it', () => {
|
||||
const { container } = render(<TrekMark className="h-6 w-6 text-content" />)
|
||||
const svg = container.querySelector('svg')!
|
||||
|
||||
expect(svg.getAttribute('class')).toBe('h-6 w-6 text-content')
|
||||
expect(svg.getAttribute('width')).toBeNull()
|
||||
expect(svg.getAttribute('height')).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-013: forwards the rest of its svg props', () => {
|
||||
const { container } = render(<TrekMark data-testid="trek-mark" role="img" />)
|
||||
const svg = container.querySelector('svg')!
|
||||
|
||||
expect(svg.getAttribute('data-testid')).toBe('trek-mark')
|
||||
expect(svg.getAttribute('role')).toBe('img')
|
||||
})
|
||||
|
||||
it('FE-DOCSYNC-ICONS-014: is decorative by default and can be unhidden by the caller', () => {
|
||||
const { container } = render(<TrekMark />)
|
||||
expect(container.querySelector('svg')!.getAttribute('aria-hidden')).toBe('true')
|
||||
|
||||
const labelled = render(<TrekMark aria-hidden={false} aria-label="TREK" />)
|
||||
const svg = labelled.container.querySelector('svg')!
|
||||
expect(svg.getAttribute('aria-hidden')).toBe('false')
|
||||
expect(svg.getAttribute('aria-label')).toBe('TREK')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,137 @@
|
||||
import React from 'react'
|
||||
|
||||
/**
|
||||
* The document providers' marks, redrawn as single-colour glyphs.
|
||||
*
|
||||
* `currentColor` rather than the brands' own palettes, and that is the point:
|
||||
* they sit in a row of lucide icons and in a list of addon toggles, where a
|
||||
* full-colour badge among line icons reads as the one thing that is switched
|
||||
* on. Following the text colour also means they invert with the theme without a
|
||||
* second asset — black on light, white on dark.
|
||||
*
|
||||
* Not in `public/brands/` beside AirTrail and Dawarich, because those are the
|
||||
* files each project ships, served unmodified. These are deliberately modified:
|
||||
* a recoloured logo is a different logo, and the trade is made knowingly here
|
||||
* for legibility in a monochrome row.
|
||||
*/
|
||||
|
||||
interface GlyphProps {
|
||||
size?: number
|
||||
className?: string
|
||||
}
|
||||
|
||||
function frame(size: number, className: string | undefined) {
|
||||
return {
|
||||
width: className ? undefined : size,
|
||||
height: className ? undefined : size,
|
||||
className,
|
||||
viewBox: '0 0 512 512',
|
||||
fill: 'none' as const,
|
||||
xmlns: 'http://www.w3.org/2000/svg',
|
||||
style: { flexShrink: 0, display: 'block' as const },
|
||||
'aria-hidden': true,
|
||||
}
|
||||
}
|
||||
|
||||
/** Paperless-ngx: the leaf, with the shoot curling out of its stem. */
|
||||
export function PaperlessIcon({ size = 20, className }: GlyphProps): React.ReactElement {
|
||||
return (
|
||||
<svg {...frame(size, className)}>
|
||||
<path
|
||||
d="M470 18c-38 62-104 104-179 149-63 38-119 77-146 135-25 55-17 119 8 174l-49 76"
|
||||
stroke="currentColor"
|
||||
strokeWidth="46"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
<path
|
||||
d="M470 18c14 96 2 195-45 273-46 76-124 129-217 146-25-55-33-119-8-174 27-58 83-97 146-135 45-27 88-54 124-86z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M52 214c-24 47-30 106-10 158 15 39 44 70 79 90"
|
||||
stroke="currentColor"
|
||||
strokeWidth="44"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
<path
|
||||
d="M52 214c33 36 66 76 82 122 12 35 12 73-3 106"
|
||||
stroke="currentColor"
|
||||
strokeWidth="30"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
/** Papra: a sheet with a folded corner and its lines of text. */
|
||||
export function PapraIcon({ size = 20, className }: GlyphProps): React.ReactElement {
|
||||
return (
|
||||
<svg {...frame(size, className)}>
|
||||
<path
|
||||
d="M104 24h164l140 140v264a56 56 0 0 1-56 56H104a56 56 0 0 1-56-56V80a56 56 0 0 1 56-56z"
|
||||
stroke="currentColor"
|
||||
strokeWidth="56"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
<path
|
||||
d="M268 24v112a28 28 0 0 0 28 28h112"
|
||||
stroke="currentColor"
|
||||
strokeWidth="56"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
<path d="M140 216h32" stroke="currentColor" strokeWidth="56" strokeLinecap="round" />
|
||||
<path d="M140 330h216" stroke="currentColor" strokeWidth="56" strokeLinecap="round" />
|
||||
<path d="M140 442h216" stroke="currentColor" strokeWidth="56" strokeLinecap="round" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
/** Nextcloud: the three rings. */
|
||||
export function NextcloudIcon({ size = 20, className }: GlyphProps): React.ReactElement {
|
||||
return (
|
||||
<svg {...frame(size, className)}>
|
||||
<circle cx="256" cy="256" r="97" stroke="currentColor" strokeWidth="42" />
|
||||
<circle cx="74" cy="256" r="56" stroke="currentColor" strokeWidth="38" />
|
||||
<circle cx="438" cy="256" r="56" stroke="currentColor" strokeWidth="38" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
/** OpenCloud: the open hexagon with the junction inside it. */
|
||||
export function OpenCloudIcon({ size = 20, className }: GlyphProps): React.ReactElement {
|
||||
return (
|
||||
<svg {...frame(size, className)}>
|
||||
<path d="M26 128 256 8l230 120v72L256 80 26 200z" fill="currentColor" />
|
||||
<path d="M26 384 256 504l230-120v-72L256 432 26 312z" fill="currentColor" />
|
||||
<path
|
||||
d="M140 212v32l100 58v100l16 10 16-10V302l100-58v-32l-16-10-100 58-100-58z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
/** Synology Drive: the wordmark's own glyph, as the addon list already draws it. */
|
||||
export function SynologyDriveIcon({ size = 20, className }: GlyphProps): React.ReactElement {
|
||||
return (
|
||||
<svg
|
||||
width={className ? undefined : size}
|
||||
height={className ? undefined : size}
|
||||
className={className}
|
||||
viewBox="0 0 24 24"
|
||||
style={{ flexShrink: 0, display: 'block' }}
|
||||
aria-hidden
|
||||
>
|
||||
<path d="M17.895 11.927a3.196 3.196 0 0 1 .394-1.53l-.008.017a2.677 2.677 0 0 1 1.075-1.108l.014-.007a3.181 3.181 0 0 1 1.523-.382h.05-.003q1.346 0 2.2.871.854.871.86 2.203c0 .895-.29 1.635-.867 2.226s-1.306.886-2.183.886c-.566 0-1.1-.137-1.571-.379l.019.009a2.535 2.535 0 0 1-1.115-1.067l-.007-.013q-.38-.708-.381-1.726zm1.593.083c0 .591.138 1.043.42 1.349a1.365 1.365 0 0 0 2.066.002l.001-.002c.275-.307.413-.764.413-1.357s-.138-1.033-.413-1.342a1.371 1.371 0 0 0-2.066-.001l-.001.002c-.281.306-.42.758-.42 1.345zm-1.602 2.941H16.33v-3.015c0-.635-.032-1.044-.101-1.234a.876.876 0 0 0-.328-.435l-.003-.002a.938.938 0 0 0-.521-.156h-.027.001-.012c-.27 0-.521.084-.727.228l.004-.003a1.115 1.115 0 0 0-.444.576l-.002.008c-.083.248-.121.696-.121 1.359v2.673H12.5V9.027h1.439v.867c.518-.656 1.167-.98 1.952-.98h.021c.335 0 .655.067.946.189l-.016-.006c.261.105.48.268.648.475l.002.003c.141.185.247.404.304.643l.002.012c.057.278.089.597.089.924l-.002.135v-.007zM6.413 9.028h1.654l1.412 4.204 1.376-4.204h1.611l-2.067 5.693-.38 1.038a4.158 4.158 0 0 1-.4.807l.01-.017a1.637 1.637 0 0 1-.422.443l-.005.003c-.17.113-.367.203-.578.26l-.014.003c-.232.064-.499.1-.774.1h-.025.001a4.13 4.13 0 0 1-.911-.105l.028.005-.129-1.229c.198.046.426.074.659.077h.002c.36 0 .628-.106.8-.318a2.27 2.27 0 0 0 .395-.807l.004-.016zM0 12.29l1.592-.149q.147.802.586 1.181.439.379 1.192.375c.528 0 .927-.113 1.197-.335.27-.222.4-.486.4-.782v-.024a.751.751 0 0 0-.167-.474l.001.001c-.113-.132-.309-.252-.59-.347-.193-.074-.631-.191-1.312-.365-.882-.216-1.496-.486-1.85-.804A2.147 2.147 0 0 1 .3 8.936v-.019V8.908c0-.431.132-.831.358-1.163l-.005.007a2.226 2.226 0 0 1 1.003-.826l.015-.005c.442-.184.973-.281 1.602-.281q1.529 0 2.304.676c.516.457.785 1.057.811 1.809l-1.649.055c-.073-.413-.219-.714-.452-.899-.233-.185-.579-.276-1.034-.276-.476 0-.85.098-1.118.298a.59.59 0 0 0-.261.49v.011-.001.002c0 .201.095.379.242.493l.001.001c.205.179.709.36 1.507.546.798.186 1.388.387 1.769.59.374.196.678.48.893.825l.006.01c.214.345.326.786.326 1.305 0 .489-.146.944-.396 1.325l.006-.009c-.264.408-.64.724-1.084.908l-.016.006c-.475.194-1.065.298-1.772.298-1.029 0-1.819-.241-2.373-.722-.554-.481-.879-1.177-.986-2.091z" fill="currentColor" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
/** Keyed by the provider ids in `document_providers`. */
|
||||
export const DOCUMENT_PROVIDER_ICONS: Record<string, React.ComponentType<GlyphProps>> = {
|
||||
paperless: PaperlessIcon,
|
||||
papra: PapraIcon,
|
||||
nextcloud: NextcloudIcon,
|
||||
opencloud: OpenCloudIcon,
|
||||
synologydrive: SynologyDriveIcon,
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user