Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(desktop): add the shared GFS drop-refusal presenter
Mcf51832c726a
diff --git a/desktop-app/ui/src/gfs/__tests__/dropVerdict.test.ts b/desktop-app/ui/src/gfs/__tests__/dropVerdict.test.tsnew file mode 100644index 000000000..8696cb102--- /dev/null+++ b/desktop-app/ui/src/gfs/__tests__/dropVerdict.test.ts@@ -0,0 +1,217 @@+import { describe, expect, it } from 'vitest'+import type { GfsDropRejection } from '../dragSession.types'+import {+ GFS_DROP_SESSION_LOST_MESSAGE,+ gfsDropReasonSentence,+ gfsDropReasonTone,+ gfsDropVerdictAnnouncement,+ gfsDropVerdictReason,+ presentGfsDropRefusal,+ sameGfsDropVerdict,+} from '../dropVerdict'++const names = { source: 'live tests', target: 'Assets' }++describe('gfsDropReasonTone — deny=error, no-op=info, unknown=warn (matrix §5.2)', () => {+ it('maps the no-op same-parent reason to info', () => {+ expect(gfsDropReasonTone('same-parent')).toBe('info')+ })++ it('maps the unverifiable family to warn', () => {+ expect(gfsDropReasonTone('unavailable')).toBe('warn')+ expect(gfsDropReasonTone('target-unavailable')).toBe('warn')+ expect(gfsDropReasonTone('source-location-unknown')).toBe('warn')+ })++ it('maps structural and permission denies to error', () => {+ for (const reason of [+ 'self',+ 'descendant',+ 'root-source',+ 'cross-drive',+ 'root-target',+ 'destination-write',+ 'source-write',+ 'source-delete',+ 'session-lost',+ ] as const) {+ expect(gfsDropReasonTone(reason)).toBe('error')+ }+ })+})++describe('gfsDropReasonSentence — one honest sentence per reason (matrix §3/§6)', () => {+ it('names the destination and its missing edit access (A6)', () => {+ expect(gfsDropReasonSentence('destination-write', names)).toBe(+ 'You don’t have permission to move items into Assets. You need edit access to the destination folder.'+ )+ })++ it('names the folder that contains the item for the missing source write bit (A7)', () => {+ const sentence = gfsDropReasonSentence('source-write', names)+ expect(sentence).toBe(+ 'You can’t move live tests out of its current folder because you don’t have edit access to the folder that contains it.'+ )+ expect(sentence).toContain('the folder that contains it')+ })++ it('names the folder that contains the item for the missing source delete bit (A8)', () => {+ expect(gfsDropReasonSentence('source-delete', names)).toBe(+ 'You can’t move live tests out of its current folder because you don’t have delete access to the folder that contains it.'+ )+ })++ it('states the no-op as "already in", never as "cannot" (A4)', () => {+ const sentence = gfsDropReasonSentence('same-parent', names)+ expect(sentence).toBe('live tests is already in Assets.')+ expect(sentence).not.toContain('cannot')+ expect(sentence).not.toContain('can’t')+ })++ it('covers the structural refuses with their own wording', () => {+ expect(gfsDropReasonSentence('self', names)).toBe('You cannot move live tests into itself.')+ expect(gfsDropReasonSentence('descendant', names)).toBe(+ 'You can’t move live tests into a folder inside itself.'+ )+ expect(gfsDropReasonSentence('root-source', names)).toBe(+ 'This location is the top level — it can’t be moved.'+ )+ expect(gfsDropReasonSentence('cross-drive', names)).toBe(+ 'Moving between drives isn’t supported.'+ )+ })++ it('never implies the move was forbidden when it merely could not be verified (A10)', () => {+ expect(gfsDropReasonSentence('unavailable', names)).toBe(+ 'EvenDrive couldn’t verify this move. Check your connection and try again.'+ )+ expect(gfsDropReasonSentence('target-unavailable', names)).toBe(+ 'This folder is no longer available.'+ )+ expect(gfsDropReasonSentence('source-location-unknown', names)).toBe(+ 'EvenDrive cannot verify this item’s current location. Refresh and try again.'+ )+ })++ it('carries the persistent session-lost banner copy (A11)', () => {+ expect(gfsDropReasonSentence('session-lost', names)).toBe(GFS_DROP_SESSION_LOST_MESSAGE)+ })++ it('sanitizes externally-controlled names before they reach the sentence', () => {+ expect(gfsDropReasonSentence('same-parent', { source: 'Reports', target: 'A' })).toBe(+ 'Reports is already in A.'+ )+ })++ it('falls back to honest placeholders for empty names', () => {+ expect(gfsDropReasonSentence('same-parent', { source: '', target: '' })).toBe(+ 'This item is already in this folder.'+ )+ })+})++describe('gfsDropVerdictAnnouncement — RP-026 one wording per reason (matrix §5.4)', () => {+ it('keeps the per-state sentences for allowed/checking/unavailable', () => {+ expect(gfsDropVerdictAnnouncement('allowed', 'Assets')).toBe('You can move into Assets.')+ expect(gfsDropVerdictAnnouncement('checking', 'Assets')).toBe(+ 'Checking whether you can move into Assets…'+ )+ expect(gfsDropVerdictAnnouncement('unavailable', 'Assets')).toBe(+ 'EvenDrive could not confirm whether you can move into Assets.'+ )+ })++ it('announces the full reason sentence for a denied verdict', () => {+ expect(gfsDropVerdictAnnouncement('denied', 'Assets', 'source-write', 'live tests')).toBe(+ 'You can’t move live tests out of its current folder because you don’t have edit access to the folder that contains it.'+ )+ expect(gfsDropVerdictAnnouncement('denied', 'Assets', 'same-parent', 'live tests')).toBe(+ 'live tests is already in Assets.'+ )+ })++ it('keeps the generic denied sentence without a reason', () => {+ expect(gfsDropVerdictAnnouncement('denied', 'Assets')).toBe('You cannot move into Assets.')+ })+})++describe('gfsDropVerdictReason / sameGfsDropVerdict — reason retention (matrix §5.1)', () => {+ it('extracts the reason only from verdicts that carry one', () => {+ expect(gfsDropVerdictReason(undefined)).toBeUndefined()+ expect(gfsDropVerdictReason({ state: 'checking' })).toBeUndefined()+ expect(gfsDropVerdictReason({ state: 'allowed' })).toBeUndefined()+ expect(gfsDropVerdictReason({ state: 'denied', reason: 'same-parent' })).toBe('same-parent')+ expect(gfsDropVerdictReason({ state: 'unavailable', reason: 'transport' })).toBe('transport')+ })++ it('treats a same-state reason change as a different verdict', () => {+ expect(+ sameGfsDropVerdict(+ { state: 'denied', reason: 'destination-write' },+ { state: 'denied', reason: 'self' }+ )+ ).toBe(false)+ })++ it('treats equal states without reasons, and equal reasons, as unchanged', () => {+ expect(sameGfsDropVerdict({ state: 'checking' }, { state: 'checking' })).toBe(true)+ expect(sameGfsDropVerdict({ state: 'allowed' }, { state: 'allowed' })).toBe(true)+ expect(+ sameGfsDropVerdict({ state: 'denied', reason: 'self' }, { state: 'denied', reason: 'self' })+ ).toBe(true)+ expect(sameGfsDropVerdict(undefined, undefined)).toBe(true)+ expect(sameGfsDropVerdict(undefined, { state: 'checking' })).toBe(false)+ })+})++describe('presentGfsDropRefusal — the drop-time presentation', () => {+ it('coaches the self release while the sentence stays spoken (A1)', () => {+ expect(presentGfsDropRefusal({ allowed: false, reason: 'self' }, names)).toEqual({+ message: 'You dropped live tests onto itself. Pick a destination folder.',+ tone: 'error',+ })+ })++ it('presents the no-op as info with the "already in" copy (A4)', () => {+ expect(presentGfsDropRefusal({ allowed: false, reason: 'same-parent' }, names)).toEqual({+ message: 'live tests is already in Assets.',+ tone: 'info',+ })+ })++ it('presents the unknown family as a warning, keeping the vetted server message', () => {+ expect(+ presentGfsDropRefusal(+ {+ allowed: false,+ reason: 'unavailable',+ message: 'Too many file requests — try again in 7s.',+ },+ names+ )+ ).toEqual({ message: 'Too many file requests — try again in 7s.', tone: 'warn' })+ })++ it('falls back to the matrix sentence when the unknown family carries no message', () => {+ expect(presentGfsDropRefusal({ allowed: false, reason: 'unavailable' }, names)).toEqual({+ message: 'EvenDrive couldn’t verify this move. Check your connection and try again.',+ tone: 'warn',+ })+ })++ it('carries the persistent banner copy for a dead session (A11)', () => {+ expect(presentGfsDropRefusal({ allowed: false, reason: 'session-lost' }, names)).toEqual({+ message: GFS_DROP_SESSION_LOST_MESSAGE,+ tone: 'error',+ })+ })++ it('presents permission denies with their exact-reason copy', () => {+ const rejection: GfsDropRejection = { allowed: false, reason: 'source-delete' }+ expect(presentGfsDropRefusal(rejection, names)).toEqual({+ message:+ 'You can’t move live tests out of its current folder because you don’t have delete access to the folder that contains it.',+ tone: 'error',+ })+ })+})diff --git a/desktop-app/ui/src/gfs/dropVerdict.ts b/desktop-app/ui/src/gfs/dropVerdict.tsindex 2e54ecd8e..38b64eed1 100644--- a/desktop-app/ui/src/gfs/dropVerdict.ts+++ b/desktop-app/ui/src/gfs/dropVerdict.ts@@ -1,29 +1,184 @@-import type { GfsDropVerdict } from './dragSession.types'+import { sanitizeAppTabTitle } from '@lib/sanitizeAppTabTitle'+import type { GfsDropDenialReason, GfsDropRejection, GfsDropVerdict } from './dragSession.types'/**- * The spoken form of a drop verdict (RP-026).+ * The spoken + written form of a drop verdict (RP-026, refusal UX matrix §5).*- * The verdict itself is painted on the target row — a border tint and a- * `data-drop-state` attribute — which a screen reader never announces. The- * user dragging with a keyboard or a screen reader therefore gets no feedback- * at all about whether the folder under the pointer accepts the move.- *- * One wording for every surface, so the sidebar and the Files page announce- * the same thing for the same verdict.+ * The verdict itself is painted on the target row — a tone-keyed tint, a+ * `data-drop-state` and a `data-drop-reason` attribute — which a screen+ * reader never announces. This module is the ONE browser-safe presenter for+ * the reason copy and its tone: hover tooltips, the live-region+ * announcements, and the drop-time refusal toast/banner all render the same+ * sentence for the same reason on every surface. A GFS name is externally+ * controlled input, so every interpolated name is sanitized here before it+ * reaches a visible string.+ */++/** Presentation tones (matrix §5.2): deny=error, no-op=info, unknown=warn. */+export type GfsDropFeedbackTone = 'error' | 'info' | 'warn'++/** A11: the drop-refusal surface for a dead session — a persistent banner,+ * never a one-shot toast (matrix §5.3). */+export const GFS_DROP_SESSION_LOST_MESSAGE =+ 'Your session ended. Sign in again to continue moving files.'++/** The refusal family that is NOT a deny: the move could not be verified, so+ * it must neither wear error-red nor imply the move was forbidden (A10). */+export function isGfsDropUnknownReason(reason: GfsDropDenialReason): boolean {+ return (+ reason === 'unavailable' ||+ reason === 'target-unavailable' ||+ reason === 'source-location-unknown'+ )+}++export function gfsDropReasonTone(reason: GfsDropDenialReason): GfsDropFeedbackTone {+ if (reason === 'same-parent') return 'info'+ if (isGfsDropUnknownReason(reason)) return 'warn'+ return 'error'+}++function displaySource(name: string | undefined): string {+ return sanitizeAppTabTitle(name ?? '') || 'This item'+}++function displayTarget(name: string | undefined): string {+ return sanitizeAppTabTitle(name ?? '') || 'this folder'+}++export interface GfsDropReasonNames {+ source: string+ target: string+}++/**+ * One sentence per reason (matrix §3/§6): names the missing access as+ * "edit access"/"delete access" (never the wire bit), and distinguishes the+ * three places a move touches — the item, the folder it leaves ("the folder+ * that contains it"), and the folder it enters.+ */+export function gfsDropReasonSentence(+ reason: GfsDropDenialReason,+ names: GfsDropReasonNames+): string {+ const source = displaySource(names.source)+ const target = displayTarget(names.target)+ switch (reason) {+ case 'self':+ return `You cannot move ${source} into itself.`+ case 'descendant':+ return `You can’t move ${source} into a folder inside itself.`+ case 'same-parent':+ return `${source} is already in ${target}.`+ case 'root-source':+ return 'This location is the top level — it can’t be moved.'+ case 'cross-drive':+ return 'Moving between drives isn’t supported.'+ case 'root-target':+ return `You can’t move items into ${target}.`+ case 'destination-write':+ return `You don’t have permission to move items into ${target}. You need edit access to the destination folder.`+ case 'source-write':+ return `You can’t move ${source} out of its current folder because you don’t have edit access to the folder that contains it.`+ case 'source-delete':+ return `You can’t move ${source} out of its current folder because you don’t have delete access to the folder that contains it.`+ case 'source-location-unknown':+ return 'EvenDrive cannot verify this item’s current location. Refresh and try again.'+ case 'target-unavailable':+ return 'This folder is no longer available.'+ case 'unavailable':+ return 'EvenDrive couldn’t verify this move. Check your connection and try again.'+ case 'session-lost':+ return GFS_DROP_SESSION_LOST_MESSAGE+ }+}++/**+ * The spoken form of a drop verdict (RP-026). Extended per the refusal UX+ * matrix §5.4: a denied verdict now announces its full reason sentence, so+ * the same wording reaches the screen reader on every surface. Without a+ * reason the generic per-state sentences remain.*/export function gfsDropVerdictAnnouncement(state: GfsDropVerdict['state'],- targetName: string+ targetName: string,+ reason?: GfsDropDenialReason,+ sourceName?: string): string {- const target = targetName.trim() || 'this folder'+ const target = displayTarget(targetName)switch (state) {case 'allowed':return `You can move into ${target}.`case 'denied':- return `You cannot move into ${target}.`+ return reason+ ? gfsDropReasonSentence(reason, { source: sourceName ?? '', target: targetName })+ : `You cannot move into ${target}.`case 'unavailable':return `EvenDrive could not confirm whether you can move into ${target}.`default:return `Checking whether you can move into ${target}…`}}++/** The verdict's machine-readable reason, when it carries one. */+export function gfsDropVerdictReason(+ verdict: GfsDropVerdict | undefined+): GfsDropDenialReason | 'rate-limit' | 'transport' | 'session' | undefined {+ if (!verdict) return undefined+ if (verdict.state === 'denied' || verdict.state === 'unavailable') return verdict.reason+ return undefined+}++/** The live-region sentence for a FULL verdict: a denied verdict announces its+ * reason; the other states keep their per-state sentences. */+export function gfsDropVerdictLiveAnnouncement(+ verdict: GfsDropVerdict,+ targetName: string,+ sourceName?: string+): string {+ if (verdict.state === 'denied') {+ return gfsDropVerdictAnnouncement(verdict.state, targetName, verdict.reason, sourceName)+ }+ return gfsDropVerdictAnnouncement(verdict.state, targetName)+}++/** Structural equality that does not collapse a same-state reason change. */+export function sameGfsDropVerdict(+ left: GfsDropVerdict | undefined,+ right: GfsDropVerdict | undefined+): boolean {+ if (left === right) return true+ if (!left || !right || left.state !== right.state) return false+ if (left.state === 'checking' || left.state === 'allowed') return true+ return left.reason === (right as typeof left).reason+}++export interface GfsDropRefusalPresentation {+ message: string+ tone: GfsDropFeedbackTone+}++/**+ * Present a drop-time refusal (matrix §3). The unavailable family keeps the+ * vetted server-derived message when the adjudicator produced one (e.g. a+ * parsed rate-limit window) and only falls back to the matrix sentence;+ * `session-lost` carries the persistent-banner copy — the caller renders it+ * as a banner, not a toast.+ */+export function presentGfsDropRefusal(+ rejection: GfsDropRejection,+ names: GfsDropReasonNames+): GfsDropRefusalPresentation {+ const tone = gfsDropReasonTone(rejection.reason)+ if (isGfsDropUnknownReason(rejection.reason) && rejection.message) {+ return { message: rejection.message, tone }+ }+ if (rejection.reason === 'self') {+ // A1's drop copy coaches the release; the sentence above stays spoken.+ return {+ message: `You dropped ${displaySource(names.source)} onto itself. Pick a destination folder.`,+ tone,+ }+ }+ return { message: gfsDropReasonSentence(rejection.reason, names), tone }+}