Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(gfs): add shared drag move policy to gfs-interaction-policy
Mefd2e91b0656
diff --git a/packages/gfs-interaction-policy/dragPolicy.cjs b/packages/gfs-interaction-policy/dragPolicy.cjsnew file mode 100644index 000000000..66453220f--- /dev/null+++ b/packages/gfs-interaction-policy/dragPolicy.cjs@@ -0,0 +1,208 @@+'use strict'++/**+ * Pure, browser-safe drag-and-drop move policy shared by Control UI and+ * Desktop. Transport-free by contract: every function takes observed facts+ * (IDs, held permission bits, canonical server paths, known cache links) and+ * returns a verdict or plan. React, fetch, Electron IPC, TanStack Query and+ * credentials stay outside this module.+ *+ * Server authority: every verdict here is FEEDBACK, not enforcement. The move+ * PATCH re-validates structure (cycle/self guard), destination kind and+ * parent permissions atomically; `server-check-required` deliberately defers+ * unproved ancestry to that guard instead of denying ordinary users whose+ * grants start below the drive root.+ */++/** Structural deny reasons (shared across both apps). */+const DRAG_STRUCTURE_DENY_REASONS = ['self', 'descendant', 'same-parent', 'root-source', 'cross-drive']++/** Sufficient negative observations — "not in the subtree, as far as current facts prove". */+const DRAG_STRUCTURE_EVIDENCES = ['file', 'common-anchor', 'known-chain', 'fresh-path']++/**+ * Maximum move PATCH attempts per user gesture (numbered-name conflicts),+ * within the existing absolute GFS_UPLOAD_NAME_RETRY_LIMIT name ceiling.+ */+const GFS_MOVE_MAX_NETWORK_ATTEMPTS = 3++function isNonEmptyString(value) {+ return typeof value === 'string' && value.length > 0+}++/**+ * Fast structural decision for an internal drag (rev-2 §3.1).+ *+ * Facts (all observations, never guesses):+ * - source.resourceId / drive / kind / parentKnown / parentResourceId+ * - target.resourceId / drive (target is a directory row or node)+ * - targetAncestorIds: ancestors of the TARGET from a currently loaded tree+ * chain or readable breadcrumb, nearest-first. Optional.+ * - knownSourceAncestorIds: currently known ancestors of the SOURCE (its+ * physical parent and any breadcrumb above it). Optional.+ *+ * Rules:+ * 1. same id → deny 'self'+ * 2. drive mismatch → deny 'cross-drive'+ * 3. observed physical root source (parentKnown && null parent) → deny 'root-source'+ * 4. observed same parent → deny 'same-parent'+ * 5. files have no descendants → observed-safe 'file'+ * 6. source appears in the target's known chain → deny 'descendant'+ * 7. the chain reaches a known ancestor of the source without passing the+ * source → observed-safe 'common-anchor' (a path out of the source's+ * subtree must cross an ancestor of the source before/above it)+ * 8. anything unproved → 'server-check-required' (drop stays possible; the+ * server cycle guard is the authority)+ */+function decideDragStructure(input) {+ const source = input?.source+ const target = input?.target+ if (!source || !target) throw new TypeError('decideDragStructure requires source and target facts')+ if (!isNonEmptyString(source.resourceId) || !isNonEmptyString(target.resourceId)) {+ throw new TypeError('decideDragStructure requires non-empty resource ids')+ }+ if (source.resourceId === target.resourceId) return { kind: 'deny', reason: 'self' }+ if (source.drive !== target.drive) return { kind: 'deny', reason: 'cross-drive' }+ if (source.parentKnown === true && source.parentResourceId == null) {+ return { kind: 'deny', reason: 'root-source' }+ }+ if (+ source.parentKnown === true &&+ source.parentResourceId === target.resourceId+ ) {+ return { kind: 'deny', reason: 'same-parent' }+ }+ if (source.kind === 'file') return { kind: 'observed-safe', evidence: 'file' }++ const chain = Array.isArray(input.targetAncestorIds) ? input.targetAncestorIds : []+ const knownSourceAncestors =+ input.knownSourceAncestorIds instanceof Set ? input.knownSourceAncestorIds : new Set()+ for (const ancestorId of chain) {+ if (ancestorId === source.resourceId) return { kind: 'deny', reason: 'descendant' }+ if (knownSourceAncestors.has(ancestorId)) return { kind: 'observed-safe', evidence: 'common-anchor' }+ }+ if (chain.length > 0 && chain[chain.length - 1] === null) {+ // The observation walked to the physical root without meeting the source:+ // equivalent to the common-anchor proof (root is an ancestor of source).+ return { kind: 'observed-safe', evidence: 'known-chain' }+ }+ return { kind: 'server-check-required' }+}++/** Normalize a server-returned canonical path for comparison ('' → null). */+function normalizeCanonicalPath(value) {+ if (typeof value !== 'string') return null+ if (value.length === 0) return null+ if (value === '/') return '/'+ let normalized = value+ if (!normalized.startsWith('/')) normalized = `/${normalized}`+ while (normalized.length > 1 && normalized.endsWith('/')) {+ normalized = normalized.slice(0, -1)+ }+ return normalized+}++/** Parent path of a canonical path; null for the root itself, undefined when unknown. */+function parentPathOf(canonicalPath) {+ const normalized = normalizeCanonicalPath(canonicalPath)+ if (normalized === null) return undefined+ if (normalized === '/') return null+ const lastSlash = normalized.lastIndexOf('/')+ return lastSlash === 0 ? '/' : normalized.slice(0, lastSlash)+}++/**+ * Control UI structural decision from canonical server paths (rev-2 §3.2).+ * Paths must come from current authorized views (resolve/by-path); a null or+ * absent path never certifies structure — it yields server-check-required.+ */+function decideDragPathStructure(input) {+ const sourcePath = normalizeCanonicalPath(input?.sourcePath)+ const targetPath = normalizeCanonicalPath(input?.targetPath)+ if (sourcePath === null || targetPath === null) return { kind: 'server-check-required' }+ if (sourcePath === targetPath) return { kind: 'deny', reason: 'self' }+ if (sourcePath === '/') return { kind: 'deny', reason: 'root-source' }+ if (targetPath === parentPathOf(sourcePath)) return { kind: 'deny', reason: 'same-parent' }+ if (targetPath === `${sourcePath}/` || targetPath.startsWith(`${sourcePath}/`)) {+ return { kind: 'deny', reason: 'descendant' }+ }+ return { kind: 'observed-safe', evidence: 'fresh-path' }+}++/**+ * Exact move-authority decision (rev-2 §3.3). MOVE needs write AND delete on+ * the physical source parent plus write on the destination; bits are+ * independent and each may arrive from direct/inherited grants, shares or+ * team membership. Operators are intrinsic (pass all bits; the app decides).+ *+ * `held` arrays mirror the affordances wire shape; null means "not yet known"+ * (checking). `unavailable` reports a probe that could not answer.+ */+function decideDragAuthority(input) {+ if (input?.unavailable) {+ return { kind: 'unavailable', reason: input.unavailable }+ }+ const sourceParentHeld = input?.sourceParentHeld ?? null+ const destinationHeld = input?.destinationHeld ?? null+ if (sourceParentHeld === null || destinationHeld === null) return { kind: 'checking' }+ const sourceBits = sourceParentHeld instanceof Set ? sourceParentHeld : new Set(sourceParentHeld)+ const destinationBits =+ destinationHeld instanceof Set ? destinationHeld : new Set(destinationHeld)+ if (!sourceBits.has('write')) return { kind: 'deny', reason: 'source-write' }+ if (!sourceBits.has('delete')) return { kind: 'deny', reason: 'source-delete' }+ if (!destinationBits.has('write')) return { kind: 'deny', reason: 'destination-write' }+ return { kind: 'observed-allowed', checkedAt: input.checkedAt ?? 0 }+}++/**+ * Pure refresh plan after a committed move (rev-2 §6). Given the receipt and+ * the currently known parent links from cached listings (child resourceId →+ * parent folder resourceId), produce the selective convergence sets:+ * - refetchChildIds: old + new parent (deduped, null-free) whose children+ * listings are immediately stale.+ * - staleResourceIds: the moved resource plus every KNOWN descendant reached+ * through cached parent links (an observation, never a claim that the set+ * covers the whole physical subtree).+ */+function planMoveConvergence(receipt, known) {+ const resourceId = receipt?.resourceId+ if (!isNonEmptyString(resourceId)) {+ throw new TypeError('planMoveConvergence requires a receipt resourceId')+ }+ const refetchChildIds = []+ for (const parentId of [receipt.oldParentId, receipt.newParentId]) {+ if (isNonEmptyString(parentId) && !refetchChildIds.includes(parentId)) {+ refetchChildIds.push(parentId)+ }+ }+ const childParentByResourceId =+ known?.childParentByResourceId instanceof Map ? known.childParentByResourceId : new Map()+ const staleResourceIds = [resourceId]+ const seen = new Set([resourceId])+ // Breadth-first over cached links; bounded by the known-cache size.+ let frontier = [resourceId]+ while (frontier.length > 0) {+ const next = []+ for (const parentId of frontier) {+ for (const [childId, parentOfChild] of childParentByResourceId) {+ if (parentOfChild === parentId && !seen.has(childId)) {+ seen.add(childId)+ staleResourceIds.push(childId)+ next.push(childId)+ }+ }+ }+ frontier = next+ }+ return { refetchChildIds, staleResourceIds }+}++module.exports = {+ GFS_MOVE_MAX_NETWORK_ATTEMPTS,+ decideDragAuthority,+ decideDragPathStructure,+ decideDragStructure,+ normalizeCanonicalPath,+ parentPathOf,+ planMoveConvergence,+}diff --git a/packages/gfs-interaction-policy/dragPolicy.d.ts b/packages/gfs-interaction-policy/dragPolicy.d.tsnew file mode 100644index 000000000..7e9d73702--- /dev/null+++ b/packages/gfs-interaction-policy/dragPolicy.d.ts@@ -0,0 +1,99 @@+export type GfsDragStructureDenyReason =+ | 'self'+ | 'descendant'+ | 'same-parent'+ | 'root-source'+ | 'cross-drive'++export type GfsDragStructureEvidence = 'file' | 'common-anchor' | 'known-chain' | 'fresh-path'++export type GfsDragStructureVerdict =+ | { kind: 'deny'; reason: GfsDragStructureDenyReason }+ | { kind: 'observed-safe'; evidence: GfsDragStructureEvidence }+ | { kind: 'server-check-required' }++export type GfsDragAuthorityDenyReason = 'source-write' | 'source-delete' | 'destination-write'++export type GfsDragAuthorityUnavailability = 'rate-limit' | 'transport' | 'session'++export type GfsDragAuthorityVerdict =+ | { kind: 'checking' }+ | { kind: 'observed-allowed'; checkedAt: number }+ | { kind: 'deny'; reason: GfsDragAuthorityDenyReason }+ | { kind: 'unavailable'; reason: GfsDragAuthorityUnavailability }++/** Maximum move PATCH attempts per gesture within GFS_UPLOAD_NAME_RETRY_LIMIT. */+export declare const GFS_MOVE_MAX_NETWORK_ATTEMPTS: number++export interface GfsDragStructureSourceFact {+ resourceId: string+ drive: string+ kind: 'file' | 'directory'+ /** True only when the physical parent is observed (listing/breadcrumb). */+ parentKnown: boolean+ parentResourceId: string | null+}++export interface GfsDragStructureTargetFact {+ resourceId: string+ drive: string+}++export interface GfsDragStructureInput {+ source: GfsDragStructureSourceFact+ target: GfsDragStructureTargetFact+ /** Ancestors of the target from a currently loaded chain, nearest-first. */+ targetAncestorIds?: readonly string[]+ /** Currently known ancestors of the source (physical parent and above). */+ knownSourceAncestorIds?: ReadonlySet<string>+}++export declare function decideDragStructure(input: GfsDragStructureInput): GfsDragStructureVerdict++export declare function normalizeCanonicalPath(value: unknown): string | null++/** Parent path of a canonical path; null for root, undefined when unknown. */+export declare function parentPathOf(canonicalPath: string): string | null | undefined++export interface GfsDragPathStructureInput {+ /** Canonical server path of the source from a current authorized view. */+ sourcePath: string | null | undefined+ /** Canonical server path of the target from a current authorized view. */+ targetPath: string | null | undefined+}++export declare function decideDragPathStructure(input: GfsDragPathStructureInput): GfsDragStructureVerdict++export interface GfsDragAuthorityInput {+ /** Held bits on the physical source parent (affordances `held`), or null when unknown. */+ sourceParentHeld?: readonly string[] | ReadonlySet<string> | null+ /** Held bits on the destination folder, or null when unknown. */+ destinationHeld?: readonly string[] | ReadonlySet<string> | null+ /** A probe that could not answer; wins over bit evaluation. */+ unavailable?: GfsDragAuthorityUnavailability | null+ /** Observation time of the supplied bits (epoch ms). */+ checkedAt?: number+}++export declare function decideDragAuthority(input: GfsDragAuthorityInput): GfsDragAuthorityVerdict++export interface GfsMoveReceiptLike {+ resourceId: string+ oldParentId?: string | null+ newParentId?: string | null+}++export interface GfsMoveConvergenceKnown {+ /** Known child→parent links from cached listings. */+ childParentByResourceId?: ReadonlyMap<string, string | null>+}++export interface GfsMoveConvergencePlan {+ refetchChildIds: string[]+ staleResourceIds: string[]+}++export declare function planMoveConvergence(+ receipt: GfsMoveReceiptLike,+ known?: GfsMoveConvergenceKnown+): GfsMoveConvergencePlandiff --git a/packages/gfs-interaction-policy/dragPolicy.test.cjs b/packages/gfs-interaction-policy/dragPolicy.test.cjsnew file mode 100644index 000000000..ae8b4d4c2--- /dev/null+++ b/packages/gfs-interaction-policy/dragPolicy.test.cjs@@ -0,0 +1,368 @@+'use strict'++const assert = require('node:assert/strict')+const { describe, it } = require('node:test')+const policy = require('./dragPolicy.cjs')+const {+ GFS_MOVE_MAX_NETWORK_ATTEMPTS,+ decideDragAuthority,+ decideDragPathStructure,+ decideDragStructure,+ normalizeCanonicalPath,+ parentPathOf,+ planMoveConvergence,+} = policy++const PROPERTY_RUNS = 300+const PROPERTY_SEED = 0x5eed_2026++function createSeededRandom(seed) {+ let state = seed >>> 0 || 0x6d2b79f5+ return () => {+ state = (Math.imul(state, 1664525) + 1013904223) >>> 0+ return state / 0x100000000+ }+}++function randomInteger(random, minInclusive, maxInclusive) {+ return minInclusive + Math.floor(random() * (maxInclusive - minInclusive + 1))+}++// ── random tree fixture for structural properties ────────────────────────────++/** Nodes 0..n-1; parent[i] < i (so node 0 is the root); 'x' marks unrelated drive roots. */+function randomTree(random, size) {+ const parentOf = [null]+ for (let index = 1; index < size; index += 1) {+ parentOf.push(randomInteger(random, 0, index - 1))+ }+ return parentOf+}++function ancestorsOf(parentOf, nodeId) {+ const chain = []+ let current = parentOf[nodeId]+ while (current !== null && current !== undefined) {+ chain.push(String(current))+ current = parentOf[current]+ }+ return chain+}++function isDescendant(parentOf, candidateId, ancestorId) {+ let current = parentOf[candidateId]+ while (current !== null && current !== undefined) {+ if (String(current) === String(ancestorId)) return true+ current = parentOf[current]+ }+ return false+}++describe('dragPolicy: decideDragStructure — unit behavior', () => {+ const source = (overrides = {}) => ({+ resourceId: 'S',+ drive: 'main',+ kind: 'directory',+ parentKnown: true,+ parentResourceId: 'P',+ ...overrides,+ })+ const target = (overrides = {}) => ({ resourceId: 'T', drive: 'main', ...overrides })++ it('denies self, cross-drive, root-source and same-parent in that priority', () => {+ assert.deepEqual(decideDragStructure({ source: source(), target: target({ resourceId: 'S' }) }), {+ kind: 'deny',+ reason: 'self',+ })+ assert.deepEqual(+ decideDragStructure({ source: source({ drive: 'other' }), target: target() }),+ { kind: 'deny', reason: 'cross-drive' }+ )+ assert.deepEqual(+ decideDragStructure({ source: source({ parentResourceId: null }), target: target() }),+ { kind: 'deny', reason: 'root-source' }+ )+ assert.deepEqual(+ decideDragStructure({ source: source({ parentResourceId: 'T' }), target: target() }),+ { kind: 'deny', reason: 'same-parent' }+ )+ })++ it('files are structurally safe without any ancestor traversal', () => {+ assert.deepEqual(+ decideDragStructure({+ source: source({ kind: 'file' }),+ target: target(),+ targetAncestorIds: ['S', 'X'],+ }),+ { kind: 'observed-safe', evidence: 'file' }+ )+ })++ it('unknown parent is distinct from root and never fabricates a structural fact', () => {+ assert.deepEqual(+ decideDragStructure({+ source: source({ parentKnown: false, parentResourceId: null }),+ target: target(),+ }),+ { kind: 'server-check-required' }+ )+ // An unknown parent cannot certify same-parent even when ids coincide.+ assert.deepEqual(+ decideDragStructure({+ source: source({ parentKnown: false, parentResourceId: 'T' }),+ target: target(),+ }),+ { kind: 'server-check-required' }+ )+ })++ it('a loaded chain containing the source denies descendant', () => {+ assert.deepEqual(+ decideDragStructure({+ source: source(),+ target: target(),+ targetAncestorIds: ['T-child', 'S'],+ }),+ { kind: 'deny', reason: 'descendant' }+ )+ })++ it('a common anchor above the source proves the negative observation', () => {+ assert.deepEqual(+ decideDragStructure({+ source: source(),+ target: target(),+ targetAncestorIds: ['T-parent', 'P'],+ knownSourceAncestorIds: new Set(['P', 'ROOT']),+ }),+ { kind: 'observed-safe', evidence: 'common-anchor' }+ )+ })++ it('an unproved chain defers to the server check instead of denying', () => {+ assert.deepEqual(+ decideDragStructure({ source: source(), target: target(), targetAncestorIds: ['Q'] }),+ { kind: 'server-check-required' }+ )+ assert.deepEqual(decideDragStructure({ source: source(), target: target() }), {+ kind: 'server-check-required',+ })+ })++ it('a chain walked to the physical root without meeting the source is safe', () => {+ assert.deepEqual(+ decideDragStructure({+ source: source(),+ target: target(),+ targetAncestorIds: ['A', 'B', null],+ }),+ { kind: 'observed-safe', evidence: 'known-chain' }+ )+ })++ it('exposes the network-attempt cap', () => {+ assert.equal(typeof GFS_MOVE_MAX_NETWORK_ATTEMPTS, 'number')+ assert.ok(GFS_MOVE_MAX_NETWORK_ATTEMPTS >= 1)+ })+})++describe('dragPolicy: decideDragStructure — properties on random trees', () => {+ const random = createSeededRandom(PROPERTY_SEED)++ for (let run = 0; run < PROPERTY_RUNS; run += 1) {+ const size = randomInteger(random, 2, 24)+ const parentOf = randomTree(random, size)+ const sourceId = randomInteger(random, 0, size - 1)+ const targetId = randomInteger(random, 0, size - 1)+ const chain = ancestorsOf(parentOf, targetId)+ const sourceAncestors = new Set(ancestorsOf(parentOf, sourceId))+ const verdict = decideDragStructure({+ source: {+ resourceId: String(sourceId),+ drive: 'main',+ kind: sourceId === 0 ? 'directory' : 'directory',+ parentKnown: true,+ parentResourceId: parentOf[sourceId] === null ? null : String(parentOf[sourceId]),+ },+ target: { resourceId: String(targetId), drive: 'main' },+ targetAncestorIds: chain,+ knownSourceAncestorIds: sourceAncestors,+ })++ it(`run ${run}: tree=${size} source=${sourceId} target=${targetId} verdict=${verdict.kind}`, () => {+ if (sourceId === targetId) {+ assert.equal(verdict.kind, 'deny')+ assert.equal(verdict.reason, 'self')+ return+ }+ if (sourceId === 0) {+ // Root source.+ assert.equal(verdict.kind, 'deny')+ assert.equal(verdict.reason, 'root-source')+ return+ }+ if (parentOf[sourceId] === targetId) {+ assert.deepEqual(verdict, { kind: 'deny', reason: 'same-parent' })+ return+ }+ const targetInsideSource = isDescendant(parentOf, targetId, sourceId)+ if (verdict.kind === 'deny' && verdict.reason === 'descendant') {+ // A deny is only allowed when the target truly is inside the subtree.+ assert.equal(targetInsideSource, true)+ } else if (verdict.kind === 'observed-safe') {+ // Soundness: never certify a target that is truly inside the subtree.+ assert.equal(targetInsideSource, false)+ } else {+ assert.equal(verdict.kind, 'server-check-required')+ }+ })+ }+})++describe('dragPolicy: canonical path helpers and path guard', () => {+ it('normalizes only real server strings; everything else is unknown', () => {+ assert.equal(normalizeCanonicalPath('/A/B'), '/A/B')+ assert.equal(normalizeCanonicalPath('A/B'), '/A/B')+ assert.equal(normalizeCanonicalPath('/A/B/'), '/A/B')+ assert.equal(normalizeCanonicalPath('/'), '/')+ assert.equal(normalizeCanonicalPath(''), null)+ assert.equal(normalizeCanonicalPath(null), null)+ assert.equal(normalizeCanonicalPath(undefined), null)+ })++ it('parentPathOf: root has none, top folders have root, deeper folders trim', () => {+ assert.equal(parentPathOf('/'), null)+ assert.equal(parentPathOf('/A'), '/')+ assert.equal(parentPathOf('/A/B'), '/A')+ })++ it('guards the /A versus /AB segment boundary', () => {+ assert.deepEqual(decideDragPathStructure({ sourcePath: '/A', targetPath: '/AB' }), {+ kind: 'observed-safe',+ evidence: 'fresh-path',+ })+ assert.deepEqual(decideDragPathStructure({ sourcePath: '/A', targetPath: '/A/B' }), {+ kind: 'deny',+ reason: 'descendant',+ })+ assert.deepEqual(decideDragPathStructure({ sourcePath: '/A', targetPath: '/A' }), {+ kind: 'deny',+ reason: 'self',+ })+ })++ it('root source and same-parent detection via canonical paths', () => {+ assert.deepEqual(decideDragPathStructure({ sourcePath: '/', targetPath: '/A' }), {+ kind: 'deny',+ reason: 'root-source',+ })+ assert.deepEqual(decideDragPathStructure({ sourcePath: '/A', targetPath: '/' }), {+ kind: 'deny',+ reason: 'same-parent',+ })+ assert.deepEqual(decideDragPathStructure({ sourcePath: '/P/X', targetPath: '/P' }), {+ kind: 'deny',+ reason: 'same-parent',+ })+ })++ it('null or stale paths never certify structure', () => {+ assert.deepEqual(decideDragPathStructure({ sourcePath: null, targetPath: '/A' }), {+ kind: 'server-check-required',+ })+ assert.deepEqual(decideDragPathStructure({ sourcePath: '/A', targetPath: null }), {+ kind: 'server-check-required',+ })+ })+})++describe('dragPolicy: decideDragAuthority', () => {+ it('unknown bits stay checking; independent bits are evaluated separately', () => {+ assert.deepEqual(decideDragAuthority({}), { kind: 'checking' })+ assert.deepEqual(+ decideDragAuthority({ sourceParentHeld: ['read', 'write'], destinationHeld: ['write'] }),+ { kind: 'deny', reason: 'source-delete' }+ )+ assert.deepEqual(+ decideDragAuthority({ sourceParentHeld: ['read'], destinationHeld: ['write'] }),+ { kind: 'deny', reason: 'source-write' }+ )+ assert.deepEqual(+ decideDragAuthority({ sourceParentHeld: ['write', 'delete'], destinationHeld: ['read'] }),+ { kind: 'deny', reason: 'destination-write' }+ )+ assert.deepEqual(+ decideDragAuthority({ sourceParentHeld: ['write', 'delete'], destinationHeld: ['write'] }),+ { kind: 'observed-allowed', checkedAt: 0 }+ )+ assert.deepEqual(+ decideDragAuthority({+ sourceParentHeld: ['write', 'delete'],+ destinationHeld: ['write'],+ checkedAt: 42,+ }),+ { kind: 'observed-allowed', checkedAt: 42 }+ )+ })++ it('an unanswerable probe is unavailable, never a denial', () => {+ for (const reason of ['rate-limit', 'transport', 'session']) {+ assert.deepEqual(+ decideDragAuthority({ sourceParentHeld: ['write'], destinationHeld: [], unavailable: reason }),+ { kind: 'unavailable', reason }+ )+ }+ })++ it('evaluate source-write before source-delete (message order matches the UX matrix)', () => {+ assert.deepEqual(+ decideDragAuthority({ sourceParentHeld: [], destinationHeld: ['write'] }),+ { kind: 'deny', reason: 'source-write' }+ )+ })+})++describe('dragPolicy: planMoveConvergence', () => {+ it('refetches exactly the old and new parent listings, deduped', () => {+ assert.deepEqual(+ planMoveConvergence({ resourceId: 'M', oldParentId: 'A', newParentId: 'B' }),+ { refetchChildIds: ['A', 'B'], staleResourceIds: ['M'] }+ )+ assert.deepEqual(+ planMoveConvergence({ resourceId: 'M', oldParentId: 'A', newParentId: 'A' }),+ { refetchChildIds: ['A'], staleResourceIds: ['M'] }+ )+ assert.deepEqual(+ planMoveConvergence({ resourceId: 'M', oldParentId: null, newParentId: 'B' }),+ { refetchChildIds: ['B'], staleResourceIds: ['M'] }+ )+ })++ it('marks the moved resource plus its KNOWN cached descendants stale', () => {+ const links = new Map([+ ['c1', 'M'],+ ['c2', 'c1'],+ ['d1', 'B'],+ ['c3', null],+ ])+ const plan = planMoveConvergence(+ { resourceId: 'M', oldParentId: 'A', newParentId: 'B' },+ { childParentByResourceId: links }+ )+ assert.deepEqual(plan.refetchChildIds, ['A', 'B'])+ assert.deepEqual([...plan.staleResourceIds].sort(), ['M', 'c1', 'c2'])+ })++ it('never claims unknown descendants: unlinked rows stay untouched', () => {+ const plan = planMoveConvergence(+ { resourceId: 'M', oldParentId: 'A', newParentId: 'B' },+ { childParentByResourceId: new Map([['x', 'y'], ['y', null]]) }+ )+ assert.deepEqual(plan.staleResourceIds, ['M'])+ })++ it('requires a receipt resourceId', () => {+ assert.throws(() => planMoveConvergence({}), TypeError)+ })+})diff --git a/packages/gfs-interaction-policy/index.cjs b/packages/gfs-interaction-policy/index.cjsindex 8a12475a6..4efb1d660 100644--- a/packages/gfs-interaction-policy/index.cjs+++ b/packages/gfs-interaction-policy/index.cjs@@ -181,6 +181,7 @@ function createGfsUploadNameReservationBook() {module.exports = {...require('./fileClassifier.cjs'),...require('./fileReference.cjs'),+ ...require('./dragPolicy.cjs'),GFS_RESOURCE_NAME_MAX_LENGTH,GFS_UPLOAD_NAME_EXHAUSTED_MESSAGE,GFS_UPLOAD_NAME_RETRY_LIMIT,diff --git a/packages/gfs-interaction-policy/index.d.ts b/packages/gfs-interaction-policy/index.d.tsindex 1fe02cff2..e54516128 100644--- a/packages/gfs-interaction-policy/index.d.ts+++ b/packages/gfs-interaction-policy/index.d.ts@@ -1,5 +1,6 @@export * from './fileClassifier'export * from './fileReference'+export * from './dragPolicy'export declare const GFS_RESOURCE_NAME_MAX_LENGTH: numberexport declare const GFS_UPLOAD_NAME_RETRY_LIMIT: numberdiff --git a/packages/gfs-interaction-policy/package.json b/packages/gfs-interaction-policy/package.jsonindex 327cf32bd..a828a401b 100644--- a/packages/gfs-interaction-policy/package.json+++ b/packages/gfs-interaction-policy/package.json@@ -8,6 +8,8 @@"files": ["index.cjs","index.d.ts",+ "dragPolicy.cjs",+ "dragPolicy.d.ts","fileClassifier.cjs","fileClassifier.d.ts","fileReference.cjs",@@ -21,8 +23,8 @@}},"scripts": {- "build": "node --check index.cjs && node --check fileClassifier.cjs && node --check fileReference.cjs",- "test": "node --test index.test.cjs fileReference.test.cjs fileClassifier.test.cjs"+ "build": "node --check index.cjs && node --check dragPolicy.cjs && node --check fileClassifier.cjs && node --check fileReference.cjs",+ "test": "node --test index.test.cjs dragPolicy.test.cjs fileReference.test.cjs fileClassifier.test.cjs"},"license": "MIT"}