@elevasis/core 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2330 -2391
- package/dist/index.js +2322 -1147
- package/dist/knowledge/index.d.ts +702 -1136
- package/dist/knowledge/index.js +9 -9
- package/dist/organization-model/index.d.ts +2330 -2391
- package/dist/organization-model/index.js +2322 -1147
- package/dist/test-utils/index.d.ts +703 -1106
- package/dist/test-utils/index.js +1735 -1089
- package/package.json +1 -1
- package/src/__tests__/template-core-compatibility.test.ts +11 -79
- package/src/_gen/__tests__/__snapshots__/contracts.md.snap +360 -98
- package/src/business/acquisition/api-schemas.test.ts +2 -2
- package/src/business/acquisition/api-schemas.ts +7 -9
- package/src/business/acquisition/build-templates.test.ts +4 -4
- package/src/business/acquisition/build-templates.ts +72 -30
- package/src/business/acquisition/crm-state-actions.test.ts +13 -11
- package/src/business/acquisition/types.ts +7 -3
- package/src/execution/engine/agent/core/types.ts +1 -1
- package/src/execution/engine/workflow/types.ts +2 -2
- package/src/knowledge/README.md +8 -7
- package/src/knowledge/__tests__/queries.test.ts +74 -73
- package/src/knowledge/format.ts +10 -9
- package/src/knowledge/index.ts +1 -1
- package/src/knowledge/published.ts +1 -1
- package/src/knowledge/queries.ts +26 -25
- package/src/organization-model/README.md +66 -26
- package/src/organization-model/__tests__/content-kinds-registry.test.ts +210 -0
- package/src/organization-model/__tests__/defaults.test.ts +72 -98
- package/src/organization-model/__tests__/domains/actions.test.ts +56 -0
- package/src/organization-model/__tests__/domains/customers.test.ts +299 -295
- package/src/organization-model/__tests__/domains/entities.test.ts +56 -0
- package/src/organization-model/__tests__/domains/goals.test.ts +493 -479
- package/src/organization-model/__tests__/domains/identity.test.ts +280 -279
- package/src/organization-model/__tests__/domains/navigation.test.ts +268 -212
- package/src/organization-model/__tests__/domains/offerings.test.ts +414 -419
- package/src/organization-model/__tests__/domains/policies.test.ts +323 -0
- package/src/organization-model/__tests__/domains/resource-mappings.test.ts +271 -271
- package/src/organization-model/__tests__/domains/resources.test.ts +159 -37
- package/src/organization-model/__tests__/domains/roles.test.ts +147 -86
- package/src/organization-model/__tests__/domains/statuses.test.ts +246 -243
- package/src/organization-model/__tests__/domains/systems.test.ts +67 -51
- package/src/organization-model/__tests__/flatten-additive-merge.test.ts +361 -0
- package/src/organization-model/__tests__/foundation.test.ts +74 -102
- package/src/organization-model/__tests__/get-resources-for-system.test.ts +144 -0
- package/src/organization-model/__tests__/graph.test.ts +899 -71
- package/src/organization-model/__tests__/knowledge.test.ts +173 -52
- package/src/organization-model/__tests__/lookup-helpers.test.ts +438 -0
- package/src/organization-model/__tests__/migration-helpers.test.ts +591 -0
- package/src/organization-model/__tests__/prospecting-ssot.test.ts +36 -27
- package/src/organization-model/__tests__/recursive-system-schema.test.ts +520 -0
- package/src/organization-model/__tests__/resolve.test.ts +174 -23
- package/src/organization-model/__tests__/schema.test.ts +291 -114
- package/src/organization-model/__tests__/surface-projection.test.ts +207 -97
- package/src/organization-model/catalogs/lead-gen.ts +144 -0
- package/src/organization-model/content-kinds/config.ts +36 -0
- package/src/organization-model/content-kinds/index.ts +74 -0
- package/src/organization-model/content-kinds/pipeline.ts +68 -0
- package/src/organization-model/content-kinds/registry.ts +44 -0
- package/src/organization-model/content-kinds/status.ts +71 -0
- package/src/organization-model/content-kinds/template.ts +83 -0
- package/src/organization-model/content-kinds/types.ts +117 -0
- package/src/organization-model/contracts.ts +13 -3
- package/src/organization-model/defaults.ts +488 -96
- package/src/organization-model/domains/actions.ts +239 -0
- package/src/organization-model/domains/customers.ts +78 -75
- package/src/organization-model/domains/entities.ts +144 -0
- package/src/organization-model/domains/goals.ts +83 -80
- package/src/organization-model/domains/knowledge.ts +74 -16
- package/src/organization-model/domains/navigation.ts +107 -384
- package/src/organization-model/domains/offerings.ts +71 -66
- package/src/organization-model/domains/policies.ts +102 -0
- package/src/organization-model/domains/projects.ts +14 -48
- package/src/organization-model/domains/prospecting.ts +62 -181
- package/src/organization-model/domains/resources.ts +81 -24
- package/src/organization-model/domains/roles.ts +13 -10
- package/src/organization-model/domains/sales.ts +10 -219
- package/src/organization-model/domains/shared.ts +57 -57
- package/src/organization-model/domains/statuses.ts +339 -130
- package/src/organization-model/domains/systems.ts +186 -29
- package/src/organization-model/foundation.ts +54 -67
- package/src/organization-model/graph/build.ts +682 -54
- package/src/organization-model/graph/link.ts +1 -1
- package/src/organization-model/graph/schema.ts +24 -9
- package/src/organization-model/graph/types.ts +20 -7
- package/src/organization-model/helpers.ts +231 -26
- package/src/organization-model/index.ts +116 -5
- package/src/organization-model/migration-helpers.ts +249 -0
- package/src/organization-model/organization-graph.mdx +16 -15
- package/src/organization-model/organization-model.mdx +89 -41
- package/src/organization-model/published.ts +120 -18
- package/src/organization-model/resolve.ts +117 -54
- package/src/organization-model/schema.ts +561 -140
- package/src/organization-model/surface-projection.ts +116 -122
- package/src/organization-model/types.ts +102 -21
- package/src/platform/constants/versions.ts +1 -1
- package/src/platform/registry/__tests__/command-view.test.ts +6 -8
- package/src/platform/registry/__tests__/resource-link.test.ts +13 -8
- package/src/platform/registry/__tests__/resource-registry.integration.test.ts +16 -31
- package/src/platform/registry/__tests__/resource-registry.nested-systems.test.ts +245 -0
- package/src/platform/registry/__tests__/resource-registry.test.ts +9 -7
- package/src/platform/registry/__tests__/validation.test.ts +15 -11
- package/src/platform/registry/resource-registry.ts +20 -8
- package/src/platform/registry/serialization.ts +7 -7
- package/src/platform/registry/types.ts +3 -3
- package/src/platform/registry/validation.ts +17 -15
- package/src/reference/_generated/contracts.md +362 -99
- package/src/reference/glossary.md +18 -18
- package/src/supabase/database.types.ts +60 -0
- package/src/test-utils/test-utils.test.ts +1 -6
- package/src/organization-model/__tests__/domains/operations.test.ts +0 -203
- package/src/organization-model/domains/features.ts +0 -31
- package/src/organization-model/domains/operations.ts +0 -85
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
import {
|
|
3
3
|
DEFAULT_ORGANIZATION_MODEL_SYSTEMS,
|
|
4
4
|
SystemEntrySchema,
|
|
5
5
|
SystemKindSchema,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
SystemStatusSchema,
|
|
7
|
+
SystemsDomainSchema
|
|
8
8
|
} from '../../domains/systems'
|
|
9
9
|
import { resolveOrganizationModel } from '../../resolve'
|
|
10
10
|
|
|
11
11
|
const VALID_SYSTEM = {
|
|
12
12
|
id: 'sys.lead-gen',
|
|
13
|
+
order: 10,
|
|
13
14
|
title: 'Lead Generation Pipeline',
|
|
14
15
|
description: 'Coordinates prospecting, enrichment, qualification, and outreach preparation.',
|
|
15
|
-
kind: 'operational' as const
|
|
16
|
-
status: 'active' as const
|
|
16
|
+
kind: 'operational' as const
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
describe('SystemEntrySchema - positive parse', () => {
|
|
@@ -53,6 +53,24 @@ describe('SystemEntrySchema - positive parse', () => {
|
|
|
53
53
|
expect(result.data.description).toBe('Owns relationship and deal pipeline operations.')
|
|
54
54
|
}
|
|
55
55
|
})
|
|
56
|
+
|
|
57
|
+
it('accepts deprecated status and maps it to lifecycle for one-cycle compatibility', () => {
|
|
58
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
|
|
59
|
+
|
|
60
|
+
const result = SystemEntrySchema.safeParse({
|
|
61
|
+
...VALID_SYSTEM,
|
|
62
|
+
status: 'deprecated'
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
expect(result.success).toBe(true)
|
|
66
|
+
if (result.success) {
|
|
67
|
+
expect(result.data.status).toBe('deprecated')
|
|
68
|
+
expect(result.data.lifecycle).toBe('deprecated')
|
|
69
|
+
}
|
|
70
|
+
expect(warn).toHaveBeenCalledWith('[organization-model] System.status is deprecated; use System.lifecycle instead.')
|
|
71
|
+
|
|
72
|
+
warn.mockRestore()
|
|
73
|
+
})
|
|
56
74
|
})
|
|
57
75
|
|
|
58
76
|
describe('SystemEntrySchema - negative parse', () => {
|
|
@@ -64,7 +82,7 @@ describe('SystemEntrySchema - negative parse', () => {
|
|
|
64
82
|
expect(SystemEntrySchema.safeParse({ ...VALID_SYSTEM, kind: 'sales' }).success).toBe(false)
|
|
65
83
|
})
|
|
66
84
|
|
|
67
|
-
it('rejects an unknown system status', () => {
|
|
85
|
+
it('rejects an unknown deprecated system status', () => {
|
|
68
86
|
expect(SystemEntrySchema.safeParse({ ...VALID_SYSTEM, status: 'paused' }).success).toBe(false)
|
|
69
87
|
})
|
|
70
88
|
|
|
@@ -74,11 +92,11 @@ describe('SystemEntrySchema - negative parse', () => {
|
|
|
74
92
|
})
|
|
75
93
|
|
|
76
94
|
describe('SystemsDomainSchema', () => {
|
|
77
|
-
it('accepts an empty systems
|
|
78
|
-
expect(SystemsDomainSchema.safeParse({
|
|
95
|
+
it('accepts an empty systems record', () => {
|
|
96
|
+
expect(SystemsDomainSchema.safeParse({}).success).toBe(true)
|
|
79
97
|
})
|
|
80
98
|
|
|
81
|
-
it('defaults systems to an empty
|
|
99
|
+
it('defaults systems to an empty record when omitted', () => {
|
|
82
100
|
const result = SystemsDomainSchema.safeParse({})
|
|
83
101
|
|
|
84
102
|
expect(result.success).toBe(true)
|
|
@@ -88,58 +106,58 @@ describe('SystemsDomainSchema', () => {
|
|
|
88
106
|
})
|
|
89
107
|
})
|
|
90
108
|
|
|
91
|
-
describe('SystemKindSchema
|
|
109
|
+
describe('SystemKindSchema', () => {
|
|
92
110
|
it.each(['product', 'operational', 'platform', 'diagnostic'] as const)('accepts kind "%s"', (kind) => {
|
|
93
111
|
expect(SystemKindSchema.safeParse(kind).success).toBe(true)
|
|
94
112
|
})
|
|
113
|
+
})
|
|
95
114
|
|
|
96
|
-
|
|
115
|
+
describe('SystemStatusSchema', () => {
|
|
116
|
+
it.each(['active', 'deprecated', 'archived'] as const)('accepts deprecated status "%s"', (status) => {
|
|
97
117
|
expect(SystemStatusSchema.safeParse(status).success).toBe(true)
|
|
98
118
|
})
|
|
99
119
|
})
|
|
100
120
|
|
|
101
121
|
describe('resolveOrganizationModel - systems domain integration', () => {
|
|
102
|
-
it('omitting systems
|
|
122
|
+
it('omitting systems keeps default system entries', () => {
|
|
103
123
|
const model = resolveOrganizationModel({})
|
|
104
124
|
|
|
105
|
-
expect(model.systems).
|
|
125
|
+
expect(Object.keys(model.systems).length).toBeGreaterThan(Object.keys(DEFAULT_ORGANIZATION_MODEL_SYSTEMS).length)
|
|
126
|
+
expect(model.systems['sales.crm']?.path).toBe('/crm')
|
|
106
127
|
})
|
|
107
128
|
|
|
108
129
|
it('accepts valid responsible role, knowledge, and goal references', () => {
|
|
109
130
|
expect(() =>
|
|
110
131
|
resolveOrganizationModel({
|
|
111
|
-
roles: {
|
|
132
|
+
roles: {
|
|
133
|
+
'role.sales-ops': { id: 'role.sales-ops', order: 10, title: 'Sales Ops' }
|
|
134
|
+
},
|
|
112
135
|
goals: {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
]
|
|
136
|
+
'goal.pipeline-coverage': {
|
|
137
|
+
id: 'goal.pipeline-coverage',
|
|
138
|
+
order: 10,
|
|
139
|
+
description: 'Improve sales pipeline coverage',
|
|
140
|
+
periodStart: '2026-01-01',
|
|
141
|
+
periodEnd: '2026-12-31'
|
|
142
|
+
}
|
|
121
143
|
},
|
|
122
144
|
knowledge: {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
]
|
|
145
|
+
'knowledge.lead-gen-playbook': {
|
|
146
|
+
id: 'knowledge.lead-gen-playbook',
|
|
147
|
+
kind: 'playbook',
|
|
148
|
+
title: 'Lead Gen Playbook',
|
|
149
|
+
summary: 'How lead generation is governed.',
|
|
150
|
+
body: '## Lead Gen',
|
|
151
|
+
updatedAt: '2026-05-08'
|
|
152
|
+
}
|
|
133
153
|
},
|
|
134
154
|
systems: {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
]
|
|
155
|
+
'sys.lead-gen': {
|
|
156
|
+
...VALID_SYSTEM,
|
|
157
|
+
responsibleRoleId: 'role.sales-ops',
|
|
158
|
+
governedByKnowledge: ['knowledge.lead-gen-playbook'],
|
|
159
|
+
drivesGoals: ['goal.pipeline-coverage']
|
|
160
|
+
}
|
|
143
161
|
}
|
|
144
162
|
})
|
|
145
163
|
).not.toThrow()
|
|
@@ -149,23 +167,21 @@ describe('resolveOrganizationModel - systems domain integration', () => {
|
|
|
149
167
|
expect(() =>
|
|
150
168
|
resolveOrganizationModel({
|
|
151
169
|
systems: {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
]
|
|
170
|
+
'sys.lead-gen': VALID_SYSTEM,
|
|
171
|
+
'sys.lead-gen-dup': {
|
|
172
|
+
...VALID_SYSTEM,
|
|
173
|
+
id: 'sys.lead-gen'
|
|
174
|
+
}
|
|
159
175
|
}
|
|
160
176
|
})
|
|
161
|
-
).toThrow(
|
|
177
|
+
).toThrow()
|
|
162
178
|
})
|
|
163
179
|
|
|
164
180
|
it('throws when responsibleRoleId references an unknown role', () => {
|
|
165
181
|
expect(() =>
|
|
166
182
|
resolveOrganizationModel({
|
|
167
183
|
systems: {
|
|
168
|
-
|
|
184
|
+
'sys.lead-gen': { ...VALID_SYSTEM, responsibleRoleId: 'role.missing' }
|
|
169
185
|
}
|
|
170
186
|
})
|
|
171
187
|
).toThrow(/unknown responsibleRoleId \\"role\.missing\\"/)
|
|
@@ -175,7 +191,7 @@ describe('resolveOrganizationModel - systems domain integration', () => {
|
|
|
175
191
|
expect(() =>
|
|
176
192
|
resolveOrganizationModel({
|
|
177
193
|
systems: {
|
|
178
|
-
|
|
194
|
+
'sys.lead-gen': { ...VALID_SYSTEM, governedByKnowledge: ['knowledge.missing'] }
|
|
179
195
|
}
|
|
180
196
|
})
|
|
181
197
|
).toThrow(/unknown knowledge node \\"knowledge\.missing\\"/)
|
|
@@ -185,7 +201,7 @@ describe('resolveOrganizationModel - systems domain integration', () => {
|
|
|
185
201
|
expect(() =>
|
|
186
202
|
resolveOrganizationModel({
|
|
187
203
|
systems: {
|
|
188
|
-
|
|
204
|
+
'sys.lead-gen': { ...VALID_SYSTEM, drivesGoals: ['goal.missing'] }
|
|
189
205
|
}
|
|
190
206
|
})
|
|
191
207
|
).toThrow(/unknown goal \\"goal\.missing\\"/)
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { DEFAULT_ORGANIZATION_MODEL } from '../defaults'
|
|
3
|
+
import { listDomain } from '../helpers'
|
|
4
|
+
import { resolveOrganizationModel } from '../resolve'
|
|
5
|
+
import type { DeepPartial, OrganizationModel } from '../types'
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Step 5 of om-flatten-single-array-domains: lock in additive-by-id merge
|
|
9
|
+
// across all 9 flattened domains.
|
|
10
|
+
//
|
|
11
|
+
// Before the flatten, every domain was `{ field: Entry[] }` and deepMerge's
|
|
12
|
+
// array branch (`Array.isArray(base) -> return override`) caused tenant
|
|
13
|
+
// overrides to wholesale-replace the array. The systems domain needed a
|
|
14
|
+
// special-case mergeSystemsById helper (sidebar-regression-fix.mdx OD1) to
|
|
15
|
+
// produce additive behavior.
|
|
16
|
+
//
|
|
17
|
+
// After the flatten, every domain is `Record<string, Entry>` keyed by id, so
|
|
18
|
+
// deepMerge's object branch (`isPlainObject(base) && isPlainObject(override)
|
|
19
|
+
// -> deepMerge per key`) gives additive-by-id semantics for free.
|
|
20
|
+
//
|
|
21
|
+
// These tests pin that semantic in place. If anyone re-introduces array shape
|
|
22
|
+
// on these domains, or special-cases merge logic, these tests will surface it.
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
describe('flatten: deepMerge produces additive-by-id behavior across all 9 flattened domains', () => {
|
|
26
|
+
// Phase 4 (D1): 'statuses' top-level field removed from OrganizationModel.
|
|
27
|
+
// Status data moved into system.content as (schema:status-flow) / (schema:status) nodes.
|
|
28
|
+
// The remaining 8 domains are all Record<string, Entry> after the flatten.
|
|
29
|
+
const FLATTENED_DOMAINS = [
|
|
30
|
+
'systems',
|
|
31
|
+
'roles',
|
|
32
|
+
'goals',
|
|
33
|
+
'customers',
|
|
34
|
+
'actions',
|
|
35
|
+
'offerings',
|
|
36
|
+
'resources',
|
|
37
|
+
'policies'
|
|
38
|
+
] as const
|
|
39
|
+
|
|
40
|
+
it.each(FLATTENED_DOMAINS)('%s domain shape is Record<string, Entry>, not an array wrapper', (domain) => {
|
|
41
|
+
const value = DEFAULT_ORGANIZATION_MODEL[domain]
|
|
42
|
+
expect(Array.isArray(value)).toBe(false)
|
|
43
|
+
expect(typeof value).toBe('object')
|
|
44
|
+
expect(value).not.toBeNull()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('adds a tenant system to the merged record without dropping defaults', () => {
|
|
48
|
+
const baseSize = Object.keys(DEFAULT_ORGANIZATION_MODEL.systems).length
|
|
49
|
+
|
|
50
|
+
const model = resolveOrganizationModel({
|
|
51
|
+
systems: {
|
|
52
|
+
'tenant.workspace': {
|
|
53
|
+
id: 'tenant.workspace',
|
|
54
|
+
order: 10000,
|
|
55
|
+
label: 'Tenant Workspace',
|
|
56
|
+
lifecycle: 'active',
|
|
57
|
+
path: '/tenant'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
expect(Object.keys(model.systems)).toHaveLength(baseSize + 1)
|
|
63
|
+
expect(model.systems['tenant.workspace']?.label).toBe('Tenant Workspace')
|
|
64
|
+
// Default systems survive
|
|
65
|
+
expect(model.systems['dashboard']).toBeDefined()
|
|
66
|
+
expect(model.systems['operations']).toBeDefined()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('merges a tenant role additively without clobbering default roles', () => {
|
|
70
|
+
const baseSize = Object.keys(DEFAULT_ORGANIZATION_MODEL.roles).length
|
|
71
|
+
|
|
72
|
+
const model = resolveOrganizationModel({
|
|
73
|
+
roles: {
|
|
74
|
+
'role.tenant-lead': {
|
|
75
|
+
id: 'role.tenant-lead',
|
|
76
|
+
order: 10000,
|
|
77
|
+
title: 'Tenant Lead'
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
expect(Object.keys(model.roles)).toHaveLength(baseSize + 1)
|
|
83
|
+
expect(model.roles['role.tenant-lead']?.title).toBe('Tenant Lead')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('merges a tenant action additively while preserving the default 13 lead-gen actions', () => {
|
|
87
|
+
const baseSize = Object.keys(DEFAULT_ORGANIZATION_MODEL.actions).length
|
|
88
|
+
expect(baseSize).toBe(13)
|
|
89
|
+
|
|
90
|
+
const model = resolveOrganizationModel({
|
|
91
|
+
actions: {
|
|
92
|
+
'tenant.custom-action': {
|
|
93
|
+
id: 'tenant.custom-action',
|
|
94
|
+
order: 10000,
|
|
95
|
+
label: 'Custom Action',
|
|
96
|
+
scope: 'global',
|
|
97
|
+
resourceId: 'tenant-workflow'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
expect(Object.keys(model.actions)).toHaveLength(baseSize + 1)
|
|
103
|
+
expect(model.actions['tenant.custom-action']?.label).toBe('Custom Action')
|
|
104
|
+
expect(model.actions['lead-gen.company.source']).toBeDefined()
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('overrides an existing system by id (last write wins on the same map key)', () => {
|
|
108
|
+
const model = resolveOrganizationModel({
|
|
109
|
+
systems: {
|
|
110
|
+
dashboard: {
|
|
111
|
+
id: 'dashboard',
|
|
112
|
+
order: 10,
|
|
113
|
+
label: 'Tenant Dashboard',
|
|
114
|
+
lifecycle: 'active',
|
|
115
|
+
path: '/'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
expect(model.systems['dashboard']?.label).toBe('Tenant Dashboard')
|
|
121
|
+
// Other defaults remain
|
|
122
|
+
expect(model.systems['operations']).toBeDefined()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('merges nested fields within a single entry deeply (not replacing the whole entry)', () => {
|
|
126
|
+
// Overriding only `label` on a default system preserves its other fields.
|
|
127
|
+
const defaultDashboard = DEFAULT_ORGANIZATION_MODEL.systems['dashboard']
|
|
128
|
+
expect(defaultDashboard).toBeDefined()
|
|
129
|
+
|
|
130
|
+
const model = resolveOrganizationModel({
|
|
131
|
+
systems: {
|
|
132
|
+
dashboard: {
|
|
133
|
+
id: 'dashboard',
|
|
134
|
+
order: defaultDashboard!.order,
|
|
135
|
+
label: 'Renamed'
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const merged = model.systems['dashboard']
|
|
141
|
+
expect(merged?.label).toBe('Renamed')
|
|
142
|
+
// Path from defaults survives because object merge is deep per-key.
|
|
143
|
+
expect(merged?.path).toBe(defaultDashboard!.path)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('confirms no special-case mergeSystemsById helper exists in resolve.ts', async () => {
|
|
147
|
+
// The OD1 special case from sidebar-regression-fix.mdx is superseded by
|
|
148
|
+
// this flatten. If anyone reintroduces it under any of these names,
|
|
149
|
+
// surface that drift.
|
|
150
|
+
const source = await import('node:fs/promises').then((fs) =>
|
|
151
|
+
fs.readFile(new URL('../resolve.ts', import.meta.url), 'utf-8')
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
expect(source).not.toMatch(/mergeSystemsById/)
|
|
155
|
+
expect(source).not.toMatch(/mergeById/)
|
|
156
|
+
expect(source).not.toMatch(/mergeRecordById/)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('multiple flattened domains receive independent additive merges in one call', () => {
|
|
160
|
+
const baseSystems = Object.keys(DEFAULT_ORGANIZATION_MODEL.systems).length
|
|
161
|
+
const baseRoles = Object.keys(DEFAULT_ORGANIZATION_MODEL.roles).length
|
|
162
|
+
const baseActions = Object.keys(DEFAULT_ORGANIZATION_MODEL.actions).length
|
|
163
|
+
|
|
164
|
+
const model = resolveOrganizationModel({
|
|
165
|
+
systems: {
|
|
166
|
+
'tenant.a': { id: 'tenant.a', order: 10000, label: 'A', lifecycle: 'active', path: '/a' }
|
|
167
|
+
},
|
|
168
|
+
roles: {
|
|
169
|
+
'role.a': { id: 'role.a', order: 10000, title: 'A' }
|
|
170
|
+
},
|
|
171
|
+
actions: {
|
|
172
|
+
'tenant.a': {
|
|
173
|
+
id: 'tenant.a',
|
|
174
|
+
order: 10000,
|
|
175
|
+
label: 'A Action',
|
|
176
|
+
scope: 'global',
|
|
177
|
+
resourceId: 'a-workflow'
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
expect(Object.keys(model.systems)).toHaveLength(baseSystems + 1)
|
|
183
|
+
expect(Object.keys(model.roles)).toHaveLength(baseRoles + 1)
|
|
184
|
+
expect(Object.keys(model.actions)).toHaveLength(baseActions + 1)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
// Override merge edge cases
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
it('order override on existing entry takes precedence and re-sorts the listed domain', () => {
|
|
192
|
+
const override: DeepPartial<OrganizationModel> = {
|
|
193
|
+
systems: {
|
|
194
|
+
dashboard: {
|
|
195
|
+
id: 'dashboard',
|
|
196
|
+
order: 1000,
|
|
197
|
+
label: 'Dashboard',
|
|
198
|
+
lifecycle: 'active',
|
|
199
|
+
path: '/'
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const resolved = resolveOrganizationModel(override)
|
|
205
|
+
|
|
206
|
+
expect(resolved.systems['dashboard']!.order).toBe(1000)
|
|
207
|
+
|
|
208
|
+
const listed = listDomain(resolved.systems)
|
|
209
|
+
const dashboardIndex = listed.findIndex((s) => s.id === 'dashboard')
|
|
210
|
+
const systemsBefore = listed.filter((s) => s.order < 1000)
|
|
211
|
+
expect(dashboardIndex).toBeGreaterThan(systemsBefore.length - 1)
|
|
212
|
+
// All entries with order < 1000 must appear before dashboard in the sorted list
|
|
213
|
+
systemsBefore.forEach((s) => {
|
|
214
|
+
expect(listed.indexOf(s)).toBeLessThan(dashboardIndex)
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('override entry omitting order preserves the base order value', () => {
|
|
219
|
+
const baseOrder = DEFAULT_ORGANIZATION_MODEL.systems['dashboard']!.order
|
|
220
|
+
|
|
221
|
+
const override: DeepPartial<OrganizationModel> = {
|
|
222
|
+
systems: {
|
|
223
|
+
dashboard: {
|
|
224
|
+
id: 'dashboard',
|
|
225
|
+
label: 'Renamed Dashboard'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const resolved = resolveOrganizationModel(override)
|
|
231
|
+
|
|
232
|
+
expect(resolved.systems['dashboard']!.order).toBe(baseOrder)
|
|
233
|
+
expect(resolved.systems['dashboard']!.label).toBe('Renamed Dashboard')
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('throws when system map key does not match the entry id', () => {
|
|
237
|
+
const badOverride: DeepPartial<OrganizationModel> = {
|
|
238
|
+
systems: {
|
|
239
|
+
'wrong-key': {
|
|
240
|
+
id: 'different-id',
|
|
241
|
+
order: 10,
|
|
242
|
+
label: 'Mismatch',
|
|
243
|
+
lifecycle: 'active',
|
|
244
|
+
path: '/mismatch'
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
expect(() => resolveOrganizationModel(badOverride)).toThrow(/map key/)
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it('replaces nested arrays rather than merging them', () => {
|
|
253
|
+
// sales.lead-gen has a top-level `actions` array field on the entry.
|
|
254
|
+
// deepMerge hits Array.isArray(existing) => returns override value directly.
|
|
255
|
+
const singleRef = [{ actionId: 'lead-gen.company.source', intent: 'exposes' as const }]
|
|
256
|
+
|
|
257
|
+
const override: DeepPartial<OrganizationModel> = {
|
|
258
|
+
systems: {
|
|
259
|
+
'sales.lead-gen': {
|
|
260
|
+
id: 'sales.lead-gen',
|
|
261
|
+
order: DEFAULT_ORGANIZATION_MODEL.systems['sales.lead-gen']!.order,
|
|
262
|
+
label: 'Lead Gen',
|
|
263
|
+
actions: singleRef
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const resolved = resolveOrganizationModel(override)
|
|
269
|
+
const entry = resolved.systems['sales.lead-gen']!
|
|
270
|
+
|
|
271
|
+
expect(entry.actions).toHaveLength(1)
|
|
272
|
+
expect(entry.actions).toEqual(singleRef)
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
it('empty systems override produces same systems domain as no override', () => {
|
|
276
|
+
const withEmpty = resolveOrganizationModel({ systems: {} })
|
|
277
|
+
const withNone = resolveOrganizationModel()
|
|
278
|
+
|
|
279
|
+
expect(withEmpty.systems).toEqual(withNone.systems)
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
it('field set to undefined in override is skipped and retains the base value', () => {
|
|
283
|
+
const basePath = DEFAULT_ORGANIZATION_MODEL.systems['dashboard']!.path
|
|
284
|
+
|
|
285
|
+
const override: DeepPartial<OrganizationModel> = {
|
|
286
|
+
systems: {
|
|
287
|
+
dashboard: {
|
|
288
|
+
id: 'dashboard',
|
|
289
|
+
order: DEFAULT_ORGANIZATION_MODEL.systems['dashboard']!.order,
|
|
290
|
+
label: 'Dashboard',
|
|
291
|
+
path: undefined
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const resolved = resolveOrganizationModel(override)
|
|
297
|
+
|
|
298
|
+
expect(resolved.systems['dashboard']!.path).toBe(basePath)
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
it('simultaneous override of systems, roles, and actions merges each domain independently without cross-contamination', () => {
|
|
302
|
+
const baseSystems = Object.keys(DEFAULT_ORGANIZATION_MODEL.systems).length
|
|
303
|
+
const baseRoles = Object.keys(DEFAULT_ORGANIZATION_MODEL.roles).length
|
|
304
|
+
const baseActions = Object.keys(DEFAULT_ORGANIZATION_MODEL.actions).length
|
|
305
|
+
const baseCustomers = DEFAULT_ORGANIZATION_MODEL.customers
|
|
306
|
+
const baseGoals = DEFAULT_ORGANIZATION_MODEL.goals
|
|
307
|
+
|
|
308
|
+
const model = resolveOrganizationModel({
|
|
309
|
+
systems: {
|
|
310
|
+
'multi.sys': { id: 'multi.sys', order: 50000, label: 'Multi Sys', lifecycle: 'active', path: '/multi-sys' }
|
|
311
|
+
},
|
|
312
|
+
roles: {
|
|
313
|
+
'multi.role': { id: 'multi.role', order: 50000, title: 'Multi Role' }
|
|
314
|
+
},
|
|
315
|
+
actions: {
|
|
316
|
+
'multi.action': {
|
|
317
|
+
id: 'multi.action',
|
|
318
|
+
order: 50000,
|
|
319
|
+
label: 'Multi Action',
|
|
320
|
+
scope: 'global',
|
|
321
|
+
resourceId: 'multi-workflow'
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
expect(Object.keys(model.systems)).toHaveLength(baseSystems + 1)
|
|
327
|
+
expect(model.systems['multi.sys']).toBeDefined()
|
|
328
|
+
|
|
329
|
+
expect(Object.keys(model.roles)).toHaveLength(baseRoles + 1)
|
|
330
|
+
expect(model.roles['multi.role']).toBeDefined()
|
|
331
|
+
|
|
332
|
+
expect(Object.keys(model.actions)).toHaveLength(baseActions + 1)
|
|
333
|
+
expect(model.actions['multi.action']).toBeDefined()
|
|
334
|
+
|
|
335
|
+
expect(model.customers).toEqual(baseCustomers)
|
|
336
|
+
expect(model.goals).toEqual(baseGoals)
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
it('override sets top-level array field on entry to single-element array replacing the original', () => {
|
|
340
|
+
// The `invocations` field on an action entry is a top-level array.
|
|
341
|
+
// deepMerge sees Array.isArray(existing) and returns override directly.
|
|
342
|
+
const replacementInvocations = [{ kind: 'slash-command' as const, command: '/custom-source' }]
|
|
343
|
+
|
|
344
|
+
const override: DeepPartial<OrganizationModel> = {
|
|
345
|
+
actions: {
|
|
346
|
+
'lead-gen.company.source': {
|
|
347
|
+
id: 'lead-gen.company.source',
|
|
348
|
+
order: DEFAULT_ORGANIZATION_MODEL.actions['lead-gen.company.source']!.order,
|
|
349
|
+
label: 'Source companies',
|
|
350
|
+
invocations: replacementInvocations
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const resolved = resolveOrganizationModel(override)
|
|
356
|
+
const entry = resolved.actions['lead-gen.company.source']!
|
|
357
|
+
|
|
358
|
+
expect(entry.invocations).toHaveLength(1)
|
|
359
|
+
expect(entry.invocations).toEqual(replacementInvocations)
|
|
360
|
+
})
|
|
361
|
+
})
|