Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(gfs): accept provenance-projected sources in shared merge core

Mb27efeee5b5f
diff --git a/packages/gfs-interaction-policy/inheritedAccess.cjs b/packages/gfs-interaction-policy/inheritedAccess.cjs
index bb740df36..a08a10d64 100644
--- a/packages/gfs-interaction-policy/inheritedAccess.cjs
+++ b/packages/gfs-interaction-policy/inheritedAccess.cjs
@@ -161,14 +161,16 @@ function mergeGfsInheritedAccessItem(current, contribution, folder) {
}
const next = {
...current,
- permissions: [...new Set([...current.permissions, ...contributionPermissions])],
- inheritedFrom: current.inheritedFrom.includes(folder.name)
- ? [...current.inheritedFrom]
- : [...current.inheritedFrom, folder.name],
- sources: current.sources.map(source => ({
+ permissions: [...new Set([...(current.permissions ?? []), ...contributionPermissions])],
+ inheritedFrom: (current.inheritedFrom ?? []).includes(folder.name)
+ ? [...(current.inheritedFrom ?? [])]
+ : [...(current.inheritedFrom ?? []), folder.name],
+ // Sources may arrive provenance-projected (an app adapter feeding its
+ // legacy-exact shape back in): treat missing optional fields as empty.
+ sources: (current.sources ?? []).map(source => ({
...source,
- shareIds: [...source.shareIds],
- shareEntries: source.shareEntries.map(entry => ({ ...entry })),
+ shareIds: [...(source.shareIds ?? [])],
+ shareEntries: (source.shareEntries ?? []).map(entry => ({ ...entry })),
})),
}
const sameFolder = next.sources.find(source => source.resourceId === folder.resourceId)
@@ -179,9 +181,9 @@ function mergeGfsInheritedAccessItem(current, contribution, folder) {
sameFolder.grantPermissions = [...contributionPermissions]
sameFolder.grantInherit = Boolean(contribution.inherit)
} else if (hasShareRow) {
- sameFolder.shareIds = [...new Set([...sameFolder.shareIds, contribution.rowId])]
+ sameFolder.shareIds = [...new Set([...(sameFolder.shareIds ?? []), contribution.rowId])]
sameFolder.shareEntries = [
- ...sameFolder.shareEntries.filter(entry => entry.rowId !== contribution.rowId),
+ ...(sameFolder.shareEntries ?? []).filter(entry => entry.rowId !== contribution.rowId),
{
rowId: contribution.rowId,
permissions: [...contributionPermissions],
diff --git a/packages/gfs-interaction-policy/inheritedAccess.test.cjs b/packages/gfs-interaction-policy/inheritedAccess.test.cjs
index 82999eadb..0b62e6857 100644
--- a/packages/gfs-interaction-policy/inheritedAccess.test.cjs
+++ b/packages/gfs-interaction-policy/inheritedAccess.test.cjs
@@ -122,6 +122,45 @@ describe('mergeGfsInheritedAccessItem', () => {
assert.deepEqual(item.sources[0].shareEntries, [])
})
+ it('folding a provenance-projected source back in is safe and idempotent', () => {
+ // App adapters feed their legacy-exact shape (no grantPermissions /
+ // grantInherit / shareEntries) back through the core; the core must treat
+ // those missing optional fields as empty rather than crash.
+ let item = mergeGfsInheritedAccessItem(
+ null,
+ grantContribution(userA, ['read'], 'g1', true),
+ folder('f1', 'Projects')
+ )
+ const projected = {
+ subject: item.subject,
+ permissions: [...item.permissions],
+ inheritedFrom: [...item.inheritedFrom],
+ sources: item.sources.map(source => ({
+ resourceId: source.resourceId,
+ name: source.name,
+ permissions: [...source.permissions],
+ grantId: source.grantId,
+ shareIds: [...source.shareIds],
+ })),
+ }
+ const refolded = mergeGfsInheritedAccessItem(
+ projected,
+ shareContribution(userA, ['read'], 's1', true),
+ folder('f1', 'Projects')
+ )
+ assert.equal(refolded.sources.length, 1)
+ assert.deepEqual(refolded.sources[0].shareIds, ['s1'])
+ assert.deepEqual(refolded.sources[0].shareEntries, [
+ { rowId: 's1', permissions: ['read'], includeDescendants: true },
+ ])
+ const again = mergeGfsInheritedAccessItem(
+ refolded,
+ shareContribution(userA, ['read'], 's1', true),
+ folder('f1', 'Projects')
+ )
+ assert.deepEqual(again, refolded)
+ })
+
it('rowless observations fold permissions without touching row ids or flags', () => {
let item = mergeGfsInheritedAccessItem(
null,