@open-mercato/cli 0.6.7-develop.6795.1.8a3f27921c → 0.6.7-develop.6814.1.0627c7e9f1
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/.turbo/turbo-build.log +1 -1
- package/build.mjs +1 -1
- package/dist/agentic/guides/module-facts.json +90266 -20749
- package/dist/agentic/guides/modules/ai_assistant.md +170 -60
- package/dist/agentic/guides/modules/api_docs.md +26 -1
- package/dist/agentic/guides/modules/api_keys.md +57 -17
- package/dist/agentic/guides/modules/attachments.md +72 -19
- package/dist/agentic/guides/modules/audit_logs.md +95 -29
- package/dist/agentic/guides/modules/auth.md +218 -83
- package/dist/agentic/guides/modules/business_rules.md +108 -34
- package/dist/agentic/guides/modules/catalog.md +386 -157
- package/dist/agentic/guides/modules/channel_gmail.md +55 -6
- package/dist/agentic/guides/modules/channel_imap.md +55 -6
- package/dist/agentic/guides/modules/checkout.md +254 -129
- package/dist/agentic/guides/modules/communication_channels.md +280 -109
- package/dist/agentic/guides/modules/configs.md +68 -11
- package/dist/agentic/guides/modules/content.md +26 -1
- package/dist/agentic/guides/modules/currencies.md +109 -44
- package/dist/agentic/guides/modules/customer_accounts.md +350 -156
- package/dist/agentic/guides/modules/customers.md +642 -294
- package/dist/agentic/guides/modules/dashboards.md +122 -28
- package/dist/agentic/guides/modules/data_sync.md +117 -37
- package/dist/agentic/guides/modules/design_system.md +36 -2
- package/dist/agentic/guides/modules/dictionaries.md +78 -20
- package/dist/agentic/guides/modules/directory.md +110 -45
- package/dist/agentic/guides/modules/entities.md +95 -38
- package/dist/agentic/guides/modules/events.md +31 -1
- package/dist/agentic/guides/modules/feature_toggles.md +79 -12
- package/dist/agentic/guides/modules/gateway_stripe.md +61 -6
- package/dist/agentic/guides/modules/generators.md +17 -1
- package/dist/agentic/guides/modules/inbox_ops.md +171 -60
- package/dist/agentic/guides/modules/integrations.md +116 -30
- package/dist/agentic/guides/modules/messages.md +187 -66
- package/dist/agentic/guides/modules/notifications.md +64 -9
- package/dist/agentic/guides/modules/onboarding.md +47 -8
- package/dist/agentic/guides/modules/payment_gateways.md +133 -48
- package/dist/agentic/guides/modules/perspectives.md +50 -12
- package/dist/agentic/guides/modules/planner.md +102 -32
- package/dist/agentic/guides/modules/portal.md +58 -15
- package/dist/agentic/guides/modules/progress.md +78 -30
- package/dist/agentic/guides/modules/query_index.md +115 -53
- package/dist/agentic/guides/modules/record_locks.md +178 -59
- package/dist/agentic/guides/modules/resources.md +155 -78
- package/dist/agentic/guides/modules/sales.md +620 -257
- package/dist/agentic/guides/modules/scheduler.md +95 -19
- package/dist/agentic/guides/modules/search.md +124 -20
- package/dist/agentic/guides/modules/security.md +251 -105
- package/dist/agentic/guides/modules/shipping_carriers.md +106 -37
- package/dist/agentic/guides/modules/sso.md +121 -49
- package/dist/agentic/guides/modules/staff.md +314 -126
- package/dist/agentic/guides/modules/storage_s3.md +55 -6
- package/dist/agentic/guides/modules/sync_akeneo.md +54 -4
- package/dist/agentic/guides/modules/sync_excel.md +49 -11
- package/dist/agentic/guides/modules/system_status_overlays.md +33 -5
- package/dist/agentic/guides/modules/translations.md +76 -21
- package/dist/agentic/guides/modules/webhooks.md +166 -82
- package/dist/agentic/guides/modules/wms.md +383 -223
- package/dist/agentic/guides/modules/workflows.md +248 -112
- package/dist/agentic/guides/upstream/AGENTS.md +1 -1
- package/dist/agentic/guides/upstream/manifest.json +2 -2
- package/dist/agentic/shared/AGENTS.md.template +6 -5
- package/dist/agentic/shared/ai/harness/cases.json +3 -0
- package/dist/agentic/shared/ai/lessons/_template.md +16 -0
- package/dist/agentic/shared/ai/lessons.md +26 -3
- package/dist/agentic/shared/ai/skills/om-evolve-harness/SKILL.md +7 -6
- package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +4 -2
- package/dist/agentic/shared/scripts/check-lessons.mjs +178 -0
- package/dist/lib/agentic-setup.js +2 -2
- package/dist/lib/agentic-setup.js.map +2 -2
- package/dist/lib/generators/module-extension-facts.js +652 -24
- package/dist/lib/generators/module-extension-facts.js.map +3 -3
- package/dist/lib/generators/module-fact-sources.js +70 -0
- package/dist/lib/generators/module-fact-sources.js.map +7 -0
- package/dist/lib/generators/module-facts.js +1001 -26
- package/dist/lib/generators/module-facts.js.map +3 -3
- package/dist/lib/generators/module-override-targets.js +688 -0
- package/dist/lib/generators/module-override-targets.js.map +7 -0
- package/dist/lib/testing/integration.js +5 -0
- package/dist/lib/testing/integration.js.map +2 -2
- package/package.json +5 -5
- package/src/lib/__tests__/agentic-setup.ownership.test.ts +6 -0
- package/src/lib/agentic-setup.ts +6 -2
- package/src/lib/generators/__tests__/activation-adapter-coverage.test.ts +92 -0
- package/src/lib/generators/__tests__/module-extension-activations.test.ts +762 -0
- package/src/lib/generators/__tests__/module-extension-facts.test.ts +4 -2
- package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +37 -3
- package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +561 -0
- package/src/lib/generators/__tests__/module-override-targets.roundtrip.test.ts +149 -0
- package/src/lib/generators/__tests__/module-override-targets.test.ts +304 -0
- package/src/lib/generators/module-extension-facts.ts +923 -27
- package/src/lib/generators/module-fact-sources.ts +108 -0
- package/src/lib/generators/module-facts.ts +1360 -25
- package/src/lib/generators/module-override-targets.ts +863 -0
- package/src/lib/testing/__tests__/integration.test.ts +4 -0
- package/src/lib/testing/integration.ts +5 -0
|
@@ -93,7 +93,7 @@ describe('module extension facts', () => {
|
|
|
93
93
|
write(moduleRoot, 'data/enrichers.ts', `
|
|
94
94
|
const enricher = {
|
|
95
95
|
id: 'alpha.records.enricher', targetEntity: 'alpha:record', features: ['alpha.view'], timeout: 750,
|
|
96
|
-
fallback: {}, queryEngine: { engines: ['json'], applyOn: ['list'] },
|
|
96
|
+
fallback: {}, queryEngine: { enabled: true, engines: ['json'], applyOn: ['list'] },
|
|
97
97
|
async enrichOne() {}, async enrichMany() {},
|
|
98
98
|
}
|
|
99
99
|
export const enrichers = [enricher]
|
|
@@ -161,7 +161,9 @@ describe('module extension facts', () => {
|
|
|
161
161
|
}),
|
|
162
162
|
expect.objectContaining({
|
|
163
163
|
id: 'alpha.records.command',
|
|
164
|
-
targets: [expect.objectContaining({
|
|
164
|
+
targets: [expect.objectContaining({
|
|
165
|
+
factRef: { factSection: 'ownedContracts.command', factKey: 'alpha.records.update' },
|
|
166
|
+
})],
|
|
165
167
|
details: expect.objectContaining({ phases: ['before-execute', 'after-undo'] }),
|
|
166
168
|
}),
|
|
167
169
|
expect.objectContaining({ id: 'alpha.records.guard', details: expect.objectContaining({ optimisticLock: 'preserved' }) }),
|
|
@@ -44,10 +44,44 @@ describe('module-facts BC resolve guard (T2)', () => {
|
|
|
44
44
|
const markdownBytes = Object.values(markdownByModule)
|
|
45
45
|
.reduce((total, markdown) => total + Buffer.byteLength(markdown), Buffer.byteLength(frameworkMarkdown))
|
|
46
46
|
|
|
47
|
+
// Budget raised by the bidirectional-topology spec
|
|
48
|
+
// (2026-08-02-module-facts-extension-activation-and-incoming-index): the
|
|
49
|
+
// additive `activations`, cross-module `incoming`, and per-contribution
|
|
50
|
+
// `contributionResolutions` layers add ~210KB of compact references (no
|
|
51
|
+
// contribution payloads are duplicated). Incoming rows are cross-module only;
|
|
52
|
+
// resolution rows are required one-per-contribution by the spec's acceptance
|
|
53
|
+
// criteria and are the dominant term.
|
|
54
|
+
//
|
|
55
|
+
// JSON cap raised again by the exact-override-targets spec
|
|
56
|
+
// (2026-08-02-module-facts-exact-override-targets): the additive per-module
|
|
57
|
+
// `overrideTargets` project one exact key per real override entry (acl
|
|
58
|
+
// features, di tokens, subscribers, pages, workers, encryption, widgets,
|
|
59
|
+
// notifications, cli, setup, ai, interceptors/enrichers, page guards). These
|
|
60
|
+
// are required exhaustively by the spec's acceptance criteria; targets carry
|
|
61
|
+
// only compact structured path/key/factRef/source refs (no runtime values or
|
|
62
|
+
// contribution payloads). The delta cap is unchanged because `overrideTargets`
|
|
63
|
+
// live in both the complete and legacy renders (only `extensionSurfaces` is
|
|
64
|
+
// stripped for the legacy comparison).
|
|
65
|
+
//
|
|
66
|
+
// JSON cap raised a third time by the uniform provenance index
|
|
67
|
+
// (2026-08-02-module-facts-source-provenance-and-contract-inventory): every
|
|
68
|
+
// proven `(kind, id)` now reaches `factSources` (~630KB across the repo), so a
|
|
69
|
+
// consumer resolves any fact's origin through one lookup. Entries whose
|
|
70
|
+
// declaration site is already serialized inline (routes, pages, CLI commands,
|
|
71
|
+
// AI tools/agents, owned contracts, hosts, contributions) emit a typed
|
|
72
|
+
// `factRef` pointer instead of a duplicated source ref, and `factKey` is
|
|
73
|
+
// omitted when it equals the entry `id` — so the index costs references, never
|
|
74
|
+
// copied provenance payloads. The cap also covers the newly reachable
|
|
75
|
+
// framework-host activations (dashboard/menu/notification contributions now
|
|
76
|
+
// resolve as bound instead of silently falling back to capability-only).
|
|
47
77
|
expect(extractionCpuDurationMs).toBeLessThan(30_000)
|
|
48
|
-
expect(Buffer.byteLength(completeJson)).toBeLessThan(
|
|
49
|
-
expect(Buffer.byteLength(completeJson) - Buffer.byteLength(legacyJson)).toBeLessThan(
|
|
50
|
-
|
|
78
|
+
expect(Buffer.byteLength(completeJson)).toBeLessThan(3_500_000)
|
|
79
|
+
expect(Buffer.byteLength(completeJson) - Buffer.byteLength(legacyJson)).toBeLessThan(1_800_000)
|
|
80
|
+
// Markdown cap raised with the source-link contract: entities, events, ACL
|
|
81
|
+
// features, DI tokens, search entities, notifications, UMES hosts and UMES
|
|
82
|
+
// contributions all render a resolved Source cell, and contribution
|
|
83
|
+
// resolutions render as their own source-linked section.
|
|
84
|
+
expect(markdownBytes).toBeLessThan(1_550_000)
|
|
51
85
|
})
|
|
52
86
|
|
|
53
87
|
it('discovers a superset of the historical core modules', () => {
|
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { extractModuleFacts, renderModuleFactsMarkdown, toModuleFactsJsonEntry } from '../module-facts'
|
|
5
|
+
import type { ModuleFacts, ModuleOwnedContractFact } from '../module-facts'
|
|
6
|
+
import { buildFactSourceLookup } from '../module-fact-sources'
|
|
7
|
+
|
|
8
|
+
function writeFixture(root: string, relativePath: string, source: string): void {
|
|
9
|
+
const filePath = path.join(root, relativePath)
|
|
10
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true })
|
|
11
|
+
fs.writeFileSync(filePath, source)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function ownedById(
|
|
15
|
+
facts: ModuleFacts,
|
|
16
|
+
kind: keyof NonNullable<ModuleFacts['ownedContracts']>,
|
|
17
|
+
id: string,
|
|
18
|
+
): ModuleOwnedContractFact | undefined {
|
|
19
|
+
return facts.ownedContracts?.[kind]?.find((fact) => fact.id === id)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('module-facts owned contracts + provenance (Spec 1)', () => {
|
|
23
|
+
let temporaryRoot: string
|
|
24
|
+
let moduleRoot: string
|
|
25
|
+
let facts: ModuleFacts
|
|
26
|
+
|
|
27
|
+
beforeAll(() => {
|
|
28
|
+
temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'module-facts-owned-'))
|
|
29
|
+
moduleRoot = path.join(temporaryRoot, 'facts')
|
|
30
|
+
|
|
31
|
+
writeFixture(
|
|
32
|
+
moduleRoot,
|
|
33
|
+
'index.ts',
|
|
34
|
+
"export const metadata = { name: 'facts', title: 'Facts', version: '1.2.3', requires: ['auth', 'catalog'], ejectable: true }\n",
|
|
35
|
+
)
|
|
36
|
+
writeFixture(
|
|
37
|
+
moduleRoot,
|
|
38
|
+
'data/entities.ts',
|
|
39
|
+
"import { Entity, Property } from '@mikro-orm/core'\n"
|
|
40
|
+
+ "@Entity({ tableName: 'facts_widget' })\nexport class FactsWidget { updatedAt!: Date }\n",
|
|
41
|
+
)
|
|
42
|
+
writeFixture(
|
|
43
|
+
moduleRoot,
|
|
44
|
+
'events.ts',
|
|
45
|
+
"export const events = [{ id: 'facts.widget.created', category: 'facts' }]\n",
|
|
46
|
+
)
|
|
47
|
+
writeFixture(
|
|
48
|
+
moduleRoot,
|
|
49
|
+
'acl.ts',
|
|
50
|
+
"export const features = [{ id: 'facts.view' }, { id: 'facts.manage' }]\n",
|
|
51
|
+
)
|
|
52
|
+
writeFixture(
|
|
53
|
+
moduleRoot,
|
|
54
|
+
'search.ts',
|
|
55
|
+
"export const searchConfig = { entities: [{ entityId: 'facts:facts_widget' }] }\n",
|
|
56
|
+
)
|
|
57
|
+
writeFixture(
|
|
58
|
+
moduleRoot,
|
|
59
|
+
'notifications.ts',
|
|
60
|
+
"export const notificationTypes = [{ type: 'facts.alert' }]\n",
|
|
61
|
+
)
|
|
62
|
+
writeFixture(
|
|
63
|
+
moduleRoot,
|
|
64
|
+
'ce.ts',
|
|
65
|
+
"const systemEntities = [{ id: 'facts:facts_widget', label: 'Widget', fields: [] }]\nexport default systemEntities\n",
|
|
66
|
+
)
|
|
67
|
+
writeFixture(
|
|
68
|
+
moduleRoot,
|
|
69
|
+
'encryption.ts',
|
|
70
|
+
"export const defaultEncryptionMaps = [{ entityId: 'facts:facts_widget', fields: [{ field: 'secret_snapshot' }, { field: 'notes' }] }]\n",
|
|
71
|
+
)
|
|
72
|
+
writeFixture(
|
|
73
|
+
moduleRoot,
|
|
74
|
+
'setup.ts',
|
|
75
|
+
"export const setup = {\n"
|
|
76
|
+
+ " defaultRoleFeatures: { admin: ['facts.manage'], employee: ['facts.view'] },\n"
|
|
77
|
+
+ " async onTenantCreated() {},\n"
|
|
78
|
+
+ " seedDefaults: async () => {},\n"
|
|
79
|
+
+ "}\n",
|
|
80
|
+
)
|
|
81
|
+
writeFixture(
|
|
82
|
+
moduleRoot,
|
|
83
|
+
'backend/middleware.ts',
|
|
84
|
+
"export const middleware = [{ id: 'facts.backend.redirect', mode: 'backend', priority: 10, run() {} }]\n",
|
|
85
|
+
)
|
|
86
|
+
writeFixture(
|
|
87
|
+
moduleRoot,
|
|
88
|
+
'frontend/middleware.ts',
|
|
89
|
+
"export const middleware = [{ id: 'facts.frontend.guard', mode: 'frontend', run() {} }, { mode: 'frontend', run() {} }]\n",
|
|
90
|
+
)
|
|
91
|
+
writeFixture(
|
|
92
|
+
moduleRoot,
|
|
93
|
+
'backend/page.tsx',
|
|
94
|
+
"export const metadata = { requireAuth: true, requireFeatures: ['facts.view'], group: 'crm' }\nexport default function Page() { return null }\n",
|
|
95
|
+
)
|
|
96
|
+
// Commands: recursive discovery, plus a duplicate id declared in two files.
|
|
97
|
+
writeFixture(
|
|
98
|
+
moduleRoot,
|
|
99
|
+
'commands/root.ts',
|
|
100
|
+
"import { registerCommand } from '@open-mercato/shared'\nregisterCommand({ id: 'facts.sync' })\n",
|
|
101
|
+
)
|
|
102
|
+
writeFixture(
|
|
103
|
+
moduleRoot,
|
|
104
|
+
'commands/nested/deep.ts',
|
|
105
|
+
"import { registerCommand } from '@open-mercato/shared'\nregisterCommand({ id: 'facts.reindex' })\nregisterCommand({ id: 'facts.sync' })\n",
|
|
106
|
+
)
|
|
107
|
+
// Workers: recursive discovery, declared and derived ids, local-constant queues,
|
|
108
|
+
// a dynamic queue, and a worker runtime skips because it declares no queue.
|
|
109
|
+
writeFixture(
|
|
110
|
+
moduleRoot,
|
|
111
|
+
'workers/sync.ts',
|
|
112
|
+
"export const metadata = { id: 'facts:sync', queue: 'facts-sync', name: 'Sync', concurrency: 2 }\nexport default async function handle() {}\n",
|
|
113
|
+
)
|
|
114
|
+
writeFixture(
|
|
115
|
+
moduleRoot,
|
|
116
|
+
'workers/nested/deep.ts',
|
|
117
|
+
"export const metadata = { id: 'facts:deep', queue: 'facts-deep' }\nexport default async function handle() {}\n",
|
|
118
|
+
)
|
|
119
|
+
writeFixture(
|
|
120
|
+
moduleRoot,
|
|
121
|
+
'workers/reindex.ts',
|
|
122
|
+
"const REINDEX_QUEUE = 'facts-reindex'\nexport const metadata = { queue: REINDEX_QUEUE, concurrency: 4 }\nexport default async function handle() {}\n",
|
|
123
|
+
)
|
|
124
|
+
writeFixture(
|
|
125
|
+
moduleRoot,
|
|
126
|
+
'workers/nested/cleanup.ts',
|
|
127
|
+
"const CLEANUP_QUEUE = 'facts-cleanup'\nexport const metadata = { queue: CLEANUP_QUEUE }\nexport default async function handle() {}\n",
|
|
128
|
+
)
|
|
129
|
+
writeFixture(
|
|
130
|
+
moduleRoot,
|
|
131
|
+
'workers/queueless.ts',
|
|
132
|
+
"export const metadata = { id: 'facts:queueless' }\nexport default async function handle() {}\n",
|
|
133
|
+
)
|
|
134
|
+
writeFixture(
|
|
135
|
+
moduleRoot,
|
|
136
|
+
'workers/dynamic.ts',
|
|
137
|
+
"const QUEUE = computeQueue()\nexport const metadata = { queue: QUEUE }\nexport default async function handle() {}\n",
|
|
138
|
+
)
|
|
139
|
+
// Pages: companion metadata files (`page.meta.*`, then `meta.*`) win over the
|
|
140
|
+
// page component, exactly as runtime discovery resolves them.
|
|
141
|
+
writeFixture(
|
|
142
|
+
moduleRoot,
|
|
143
|
+
'backend/facts/config/page.tsx',
|
|
144
|
+
"export const metadata = { requireAuth: false, group: 'ignored' }\nexport default function ConfigPage() { return null }\n",
|
|
145
|
+
)
|
|
146
|
+
writeFixture(
|
|
147
|
+
moduleRoot,
|
|
148
|
+
'backend/facts/config/page.meta.ts',
|
|
149
|
+
"export const metadata = { requireAuth: true, requireFeatures: ['facts.configure'], pageGroup: 'settings-group', pageGroupKey: 'facts.settings', pageOrder: 30, pageContext: 'settings', navHidden: true }\n",
|
|
150
|
+
)
|
|
151
|
+
writeFixture(
|
|
152
|
+
moduleRoot,
|
|
153
|
+
'backend/facts/reports/page.tsx',
|
|
154
|
+
"export default function ReportsPage() { return null }\n",
|
|
155
|
+
)
|
|
156
|
+
writeFixture(
|
|
157
|
+
moduleRoot,
|
|
158
|
+
'backend/facts/reports/meta.ts',
|
|
159
|
+
"export const metadata = { requireAuth: true, order: 5, pageContext: 'admin', pageContextId: 'not-a-contract-key' }\n",
|
|
160
|
+
)
|
|
161
|
+
// Subscribers: nested directory must be discovered like runtime.
|
|
162
|
+
writeFixture(
|
|
163
|
+
moduleRoot,
|
|
164
|
+
'subscribers/nested/on-created.ts',
|
|
165
|
+
"export const metadata = { id: 'facts:on-created', event: 'facts.widget.created', persistent: false }\nexport default async function handle() {}\n",
|
|
166
|
+
)
|
|
167
|
+
// DI: cover function/class/value/alias/lifetime/injectionMode/spread/unresolved.
|
|
168
|
+
writeFixture(
|
|
169
|
+
moduleRoot,
|
|
170
|
+
'di.ts',
|
|
171
|
+
"import { asFunction, asClass, asValue, aliasTo } from 'awilix'\n"
|
|
172
|
+
+ "import { RealService } from './lib/realService'\n"
|
|
173
|
+
+ "const SENSITIVE_CONFIG = { apiKey: 'super-secret-value-9000' }\n"
|
|
174
|
+
+ "const baseRegistrations = {}\n"
|
|
175
|
+
+ "export function register(container) {\n"
|
|
176
|
+
+ " container.register({\n"
|
|
177
|
+
+ " ...baseRegistrations,\n"
|
|
178
|
+
+ " fnService: asFunction(makeService).singleton(),\n"
|
|
179
|
+
+ " ClassService: asClass(RealService).scoped().proxy(),\n"
|
|
180
|
+
+ " ValueToken: asValue(SENSITIVE_CONFIG),\n"
|
|
181
|
+
+ " aliasToken: aliasTo('ClassService'),\n"
|
|
182
|
+
+ " spreadFn: asFunction(() => 1).transient().classic(),\n"
|
|
183
|
+
+ " dynamicOne: someDynamicFactory(),\n"
|
|
184
|
+
+ " })\n"
|
|
185
|
+
+ "}\n",
|
|
186
|
+
)
|
|
187
|
+
// Generator plugins.
|
|
188
|
+
writeFixture(
|
|
189
|
+
moduleRoot,
|
|
190
|
+
'generators.ts',
|
|
191
|
+
"const pluginA = { id: 'facts.registry', conventionFile: 'facts.items.ts', outputFileName: 'facts-items.generated.ts' }\nexport const generatorPlugins = [pluginA]\n",
|
|
192
|
+
)
|
|
193
|
+
// AI agent extensions (file overrides).
|
|
194
|
+
writeFixture(
|
|
195
|
+
moduleRoot,
|
|
196
|
+
'ai-agents.ts',
|
|
197
|
+
"type AiAgentDefinition = { id: string }\nconst agent: AiAgentDefinition = { id: 'facts.assistant' }\nexport const aiAgents = [agent]\nexport const aiAgentExtensions = [defineAiAgentExtension({ targetAgentId: 'catalog.catalog_assistant', appendAllowedTools: ['facts.stats'] })]\nexport const aiAgentOverrides = { 'catalog.merchandising_assistant': replacementAgent, 'catalog.catalog_assistant': null }\nexport const aiToolOverrides = { 'legacy_tool': null }\nexport default aiAgents\n",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
facts = extractModuleFacts({
|
|
201
|
+
moduleId: 'facts',
|
|
202
|
+
moduleRoot,
|
|
203
|
+
sourcePackage: '@open-mercato/example',
|
|
204
|
+
sourceVersion: '1.0.0',
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
afterAll(() => {
|
|
209
|
+
fs.rmSync(temporaryRoot, { recursive: true, force: true })
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it('extracts module-metadata owned contract with only safe scalar fields', () => {
|
|
213
|
+
const fact = ownedById(facts, 'module-metadata', 'facts')
|
|
214
|
+
expect(fact).toBeDefined()
|
|
215
|
+
expect(fact?.metadata).toEqual({ name: 'facts', version: '1.2.3', requires: ['auth', 'catalog'], ejectable: true })
|
|
216
|
+
expect(fact?.source.sourcePath).toBe('node_modules/@open-mercato/example/src/modules/facts/index.ts')
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('discovers recursive domain commands and selects a canonical duplicate source with a diagnostic', () => {
|
|
220
|
+
const ids = (facts.ownedContracts?.command ?? []).map((fact) => fact.id)
|
|
221
|
+
expect(ids).toEqual(['facts.reindex', 'facts.sync'])
|
|
222
|
+
// facts.sync is declared in both commands/root.ts and commands/nested/deep.ts.
|
|
223
|
+
const sync = ownedById(facts, 'command', 'facts.sync')
|
|
224
|
+
expect(sync?.source.sourcePath).toBe('node_modules/@open-mercato/example/src/modules/facts/commands/nested/deep.ts')
|
|
225
|
+
const duplicate = facts.factDiagnostics?.find(
|
|
226
|
+
(diagnostic) => diagnostic.code === 'duplicate-source' && diagnostic.kind === 'command' && diagnostic.id === 'facts.sync',
|
|
227
|
+
)
|
|
228
|
+
expect(duplicate?.source?.sourcePath).toBe('node_modules/@open-mercato/example/src/modules/facts/commands/root.ts')
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it('matches runtime worker identity for declared, derived, and id-less workers', () => {
|
|
232
|
+
const sync = ownedById(facts, 'worker', 'facts:sync')
|
|
233
|
+
expect(sync?.metadata).toEqual({ queue: 'facts-sync', name: 'Sync', concurrency: 2 })
|
|
234
|
+
expect(ownedById(facts, 'worker', 'facts:deep')).toBeDefined()
|
|
235
|
+
|
|
236
|
+
// Runtime falls back to `<module>:workers:<...path>:<file>` when metadata.id is absent,
|
|
237
|
+
// at the root and in nested directories, and resolves a local-constant queue.
|
|
238
|
+
expect(ownedById(facts, 'worker', 'facts:workers:reindex')?.metadata).toEqual({
|
|
239
|
+
queue: 'facts-reindex',
|
|
240
|
+
concurrency: 4,
|
|
241
|
+
})
|
|
242
|
+
expect(ownedById(facts, 'worker', 'facts:workers:nested:cleanup')?.metadata).toEqual({
|
|
243
|
+
queue: 'facts-cleanup',
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it('reports workers whose required queue is missing or dynamic', () => {
|
|
248
|
+
const workerDiagnostics = (facts.factDiagnostics ?? []).filter(
|
|
249
|
+
(diagnostic) => diagnostic.code === 'unresolved-static-contract' && diagnostic.kind === 'worker',
|
|
250
|
+
)
|
|
251
|
+
expect(workerDiagnostics.map((diagnostic) => diagnostic.id).sort()).toEqual([
|
|
252
|
+
'facts:queueless',
|
|
253
|
+
'facts:workers:dynamic',
|
|
254
|
+
])
|
|
255
|
+
// A worker with no queue is never registered by runtime, so it is not a contract.
|
|
256
|
+
expect(ownedById(facts, 'worker', 'facts:queueless')).toBeUndefined()
|
|
257
|
+
// A dynamic queue still yields a worker contract, minus the unresolvable value.
|
|
258
|
+
expect(ownedById(facts, 'worker', 'facts:workers:dynamic')).toBeDefined()
|
|
259
|
+
expect(JSON.stringify(facts.ownedContracts?.worker)).not.toContain('QUEUE')
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('extracts page middleware for both surfaces and diagnoses id-less entries', () => {
|
|
263
|
+
expect(ownedById(facts, 'page-middleware', 'facts.backend.redirect')?.metadata).toEqual({
|
|
264
|
+
surface: 'backend',
|
|
265
|
+
mode: 'backend',
|
|
266
|
+
priority: 10,
|
|
267
|
+
})
|
|
268
|
+
expect(ownedById(facts, 'page-middleware', 'facts.frontend.guard')?.metadata).toMatchObject({ surface: 'frontend' })
|
|
269
|
+
expect(
|
|
270
|
+
facts.factDiagnostics?.some((diagnostic) => diagnostic.kind === 'page-middleware' && diagnostic.code === 'unresolved-static-contract'),
|
|
271
|
+
).toBe(true)
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('extracts setup hooks and role identifiers only', () => {
|
|
275
|
+
const setup = ownedById(facts, 'setup', 'facts:setup')
|
|
276
|
+
expect(setup?.metadata).toEqual({ hooks: ['onTenantCreated', 'seedDefaults'], roles: ['admin', 'employee'] })
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it('extracts encryption entity ids with declared field names', () => {
|
|
280
|
+
const encryption = ownedById(facts, 'encryption', 'facts:facts_widget')
|
|
281
|
+
expect(encryption?.metadata).toEqual({ fields: ['notes', 'secret_snapshot'] })
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
it('extracts custom entity ownership from ce.ts', () => {
|
|
285
|
+
expect((facts.ownedContracts?.['custom-entity'] ?? []).map((fact) => fact.id)).toEqual(['facts:facts_widget'])
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it('separates additive agent extensions from keyed agent and tool overrides', () => {
|
|
289
|
+
const aiFacts = facts.ownedContracts?.['ai-extension'] ?? []
|
|
290
|
+
expect(aiFacts.map((fact) => fact.id).sort()).toEqual([
|
|
291
|
+
'agent-extension:catalog.catalog_assistant',
|
|
292
|
+
'agent-override:catalog.catalog_assistant',
|
|
293
|
+
'agent-override:catalog.merchandising_assistant',
|
|
294
|
+
'tool-override:legacy_tool',
|
|
295
|
+
])
|
|
296
|
+
const byId = new Map(aiFacts.map((fact) => [fact.id, fact.metadata]))
|
|
297
|
+
expect(byId.get('agent-extension:catalog.catalog_assistant')).toEqual({
|
|
298
|
+
target: 'agent',
|
|
299
|
+
mode: 'extension',
|
|
300
|
+
targetAgentId: 'catalog.catalog_assistant',
|
|
301
|
+
})
|
|
302
|
+
expect(byId.get('agent-override:catalog.merchandising_assistant')).toEqual({
|
|
303
|
+
target: 'agent',
|
|
304
|
+
mode: 'override',
|
|
305
|
+
overrideKey: 'catalog.merchandising_assistant',
|
|
306
|
+
})
|
|
307
|
+
expect(byId.get('tool-override:legacy_tool')).toEqual({
|
|
308
|
+
target: 'tool',
|
|
309
|
+
mode: 'override',
|
|
310
|
+
overrideKey: 'legacy_tool',
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
// Override values (replacement definitions and `null` disables) are never serialized.
|
|
314
|
+
const serialized = JSON.stringify(aiFacts)
|
|
315
|
+
expect(serialized).not.toContain('replacementAgent')
|
|
316
|
+
expect(serialized).not.toContain('appendAllowedTools')
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
it('extracts generator plugin ownership with safe metadata', () => {
|
|
320
|
+
expect(ownedById(facts, 'generator-plugin', 'facts.registry')?.metadata).toEqual({
|
|
321
|
+
conventionFile: 'facts.items.ts',
|
|
322
|
+
outputFileName: 'facts-items.generated.ts',
|
|
323
|
+
})
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
it('classifies every supported DI registration form without leaking values', () => {
|
|
327
|
+
const di = facts.ownedContracts?.['di-registration'] ?? []
|
|
328
|
+
const byToken = new Map(di.map((fact) => [fact.id, fact.metadata]))
|
|
329
|
+
expect(byToken.get('fnService')).toEqual({ registrationKind: 'function', providerSymbol: 'makeService', lifetime: 'singleton' })
|
|
330
|
+
expect(byToken.get('ClassService')).toEqual({
|
|
331
|
+
registrationKind: 'class',
|
|
332
|
+
providerSymbol: 'RealService',
|
|
333
|
+
lifetime: 'scoped',
|
|
334
|
+
injectionMode: 'proxy',
|
|
335
|
+
})
|
|
336
|
+
expect(byToken.get('ValueToken')).toEqual({ registrationKind: 'value' })
|
|
337
|
+
expect(byToken.get('aliasToken')).toEqual({ registrationKind: 'alias', providerSymbol: 'ClassService' })
|
|
338
|
+
expect(byToken.get('spreadFn')).toEqual({ registrationKind: 'function', lifetime: 'transient', injectionMode: 'classic' })
|
|
339
|
+
// Dynamic registration is diagnosed, not fabricated.
|
|
340
|
+
expect(byToken.has('dynamicOne')).toBe(false)
|
|
341
|
+
expect(
|
|
342
|
+
facts.factDiagnostics?.some((diagnostic) => diagnostic.kind === 'di-registration' && diagnostic.id === 'dynamicOne'),
|
|
343
|
+
).toBe(true)
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('derives the legacy diTokens list from function/class registrations only, preserving order', () => {
|
|
347
|
+
expect(facts.diTokens).toEqual(['fnService', 'ClassService', 'spreadFn'])
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it('never leaks asValue payloads, secrets, config bodies, or absolute paths', () => {
|
|
351
|
+
const serialized = JSON.stringify(toModuleFactsJsonEntry(facts))
|
|
352
|
+
expect(serialized).not.toContain('SENSITIVE_CONFIG')
|
|
353
|
+
expect(serialized).not.toContain('super-secret-value-9000')
|
|
354
|
+
expect(serialized).not.toContain('apiKey')
|
|
355
|
+
expect(serialized).not.toContain('makeService(')
|
|
356
|
+
expect(serialized).not.toContain(temporaryRoot)
|
|
357
|
+
expect(serialized).not.toMatch(/"sourcePath":\s*"\//)
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
it('resolves every proven fact through the uniform provenance index', () => {
|
|
361
|
+
const resolve = buildFactSourceLookup(facts)
|
|
362
|
+
expect(resolve('entity', 'facts:facts_widget')?.sourcePath).toBe(
|
|
363
|
+
'node_modules/@open-mercato/example/src/modules/facts/data/entities.ts',
|
|
364
|
+
)
|
|
365
|
+
expect(resolve('event', 'facts.widget.created')?.sourcePath).toBe(
|
|
366
|
+
'node_modules/@open-mercato/example/src/modules/facts/events.ts',
|
|
367
|
+
)
|
|
368
|
+
expect(resolve('acl-feature', 'facts.view')?.sourcePath).toBe(
|
|
369
|
+
'node_modules/@open-mercato/example/src/modules/facts/acl.ts',
|
|
370
|
+
)
|
|
371
|
+
expect(resolve('search', 'facts:facts_widget')?.sourcePath).toBe(
|
|
372
|
+
'node_modules/@open-mercato/example/src/modules/facts/search.ts',
|
|
373
|
+
)
|
|
374
|
+
expect(resolve('notification', 'facts.alert')?.sourcePath).toBe(
|
|
375
|
+
'node_modules/@open-mercato/example/src/modules/facts/notifications.ts',
|
|
376
|
+
)
|
|
377
|
+
expect(resolve('subscriber', 'facts:on-created')?.sourcePath).toBe(
|
|
378
|
+
'node_modules/@open-mercato/example/src/modules/facts/subscribers/nested/on-created.ts',
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
// Kinds whose declaration site is already serialized inline are indexed as typed
|
|
382
|
+
// pointers, and still resolve to a real source through the same lookup.
|
|
383
|
+
const commandEntry = facts.factSources?.find(
|
|
384
|
+
(entry) => entry.kind === 'command' && entry.id === 'facts.sync',
|
|
385
|
+
)
|
|
386
|
+
expect(commandEntry?.source).toBeUndefined()
|
|
387
|
+
expect(commandEntry?.factRef).toEqual({ factSection: 'ownedContracts.command' })
|
|
388
|
+
expect(resolve('command', 'facts.sync')?.sourcePath).toBe(
|
|
389
|
+
'node_modules/@open-mercato/example/src/modules/facts/commands/nested/deep.ts',
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
const diEntry = facts.factSources?.find((entry) => entry.kind === 'di-registration')
|
|
393
|
+
expect(diEntry?.factRef?.factSection).toBe('ownedContracts.di-registration')
|
|
394
|
+
expect(resolve('di-registration', diEntry?.id as string)?.sourcePath).toBe(
|
|
395
|
+
'node_modules/@open-mercato/example/src/modules/facts/di.ts',
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
// Every emitted entry carries exactly one projection and resolves.
|
|
399
|
+
for (const entry of facts.factSources ?? []) {
|
|
400
|
+
expect(Boolean(entry.source) !== Boolean(entry.factRef)).toBe(true)
|
|
401
|
+
expect(resolve(entry.kind, entry.id)).not.toBeNull()
|
|
402
|
+
}
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
it('indexes every proven contract kind exactly once', () => {
|
|
406
|
+
const indexed = new Set((facts.factSources ?? []).map((entry) => `${entry.kind}:${entry.id}`))
|
|
407
|
+
expect(indexed.size).toBe((facts.factSources ?? []).length)
|
|
408
|
+
for (const route of facts.apiRoutes) expect(indexed.has(`api-route:${route.path}`)).toBe(true)
|
|
409
|
+
for (const page of facts.backendPages) expect(indexed.has(`backend-page:${page.path}`)).toBe(true)
|
|
410
|
+
for (const command of facts.cliCommands) expect(indexed.has(`cli-command:${command.command}`)).toBe(true)
|
|
411
|
+
for (const tool of facts.aiTools) expect(indexed.has(`ai-tool:${tool.name}`)).toBe(true)
|
|
412
|
+
for (const [kind, ownedFacts] of Object.entries(facts.ownedContracts ?? {})) {
|
|
413
|
+
for (const owned of ownedFacts ?? []) expect(indexed.has(`${kind}:${owned.id}`)).toBe(true)
|
|
414
|
+
}
|
|
415
|
+
for (const host of facts.extensionSurfaces?.hosts ?? []) {
|
|
416
|
+
expect(indexed.has(`extension-host:${host.key}`)).toBe(true)
|
|
417
|
+
}
|
|
418
|
+
for (const contribution of facts.extensionSurfaces?.contributions ?? []) {
|
|
419
|
+
expect(indexed.has(`extension-contribution:${contribution.id}`)).toBe(true)
|
|
420
|
+
}
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
it('keeps subscriber discovery aligned with runtime recursion', () => {
|
|
424
|
+
const subscriber = facts.extensionSurfaces?.contributions.find((contribution) => contribution.id === 'facts:on-created')
|
|
425
|
+
expect(subscriber?.kind).toBe('subscriber')
|
|
426
|
+
expect(subscriber?.source.path).toBe('node_modules/@open-mercato/example/src/modules/facts/subscribers/nested/on-created.ts')
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
it('attaches only statically-declared safe page metadata', () => {
|
|
430
|
+
const page = facts.backendPages.find((entry) => entry.path === '/backend/facts')
|
|
431
|
+
expect(page?.metadata).toEqual({ requireAuth: true, requireFeatures: ['facts.view'], navGroup: 'crm' })
|
|
432
|
+
expect(page?.metadataSourcePath).toBeUndefined()
|
|
433
|
+
})
|
|
434
|
+
|
|
435
|
+
it('reads page metadata from the runtime companion file convention', () => {
|
|
436
|
+
const companionPage = facts.backendPages.find((entry) => entry.path === '/backend/facts/config')
|
|
437
|
+
expect(companionPage?.metadataSourcePath).toBe(
|
|
438
|
+
'node_modules/@open-mercato/example/src/modules/facts/backend/facts/config/page.meta.ts',
|
|
439
|
+
)
|
|
440
|
+
expect(companionPage?.metadata).toEqual({
|
|
441
|
+
requireAuth: true,
|
|
442
|
+
requireFeatures: ['facts.configure'],
|
|
443
|
+
navGroup: 'settings-group',
|
|
444
|
+
navGroupKey: 'facts.settings',
|
|
445
|
+
navOrder: 30,
|
|
446
|
+
pageContext: 'settings',
|
|
447
|
+
navHidden: true,
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
// `meta.*` is the documented fallback name, and page-component metadata is
|
|
451
|
+
// ignored entirely when a companion exists (runtime imports only the companion).
|
|
452
|
+
const fallbackPage = facts.backendPages.find((entry) => entry.path === '/backend/facts/reports')
|
|
453
|
+
expect(fallbackPage?.metadataSourcePath).toBe(
|
|
454
|
+
'node_modules/@open-mercato/example/src/modules/facts/backend/facts/reports/meta.ts',
|
|
455
|
+
)
|
|
456
|
+
expect(fallbackPage?.metadata).toEqual({ requireAuth: true, navOrder: 5, pageContext: 'admin' })
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
it('emits portable POSIX source paths and is deterministic across runs', () => {
|
|
460
|
+
const resolve = buildFactSourceLookup(facts)
|
|
461
|
+
for (const entry of facts.factSources ?? []) {
|
|
462
|
+
const source = resolve(entry.kind, entry.id)
|
|
463
|
+
expect(source?.sourcePath.startsWith('node_modules/@open-mercato/example/')).toBe(true)
|
|
464
|
+
expect(source?.sourcePath.includes('\\')).toBe(false)
|
|
465
|
+
}
|
|
466
|
+
const rerun = extractModuleFacts({
|
|
467
|
+
moduleId: 'facts',
|
|
468
|
+
moduleRoot,
|
|
469
|
+
sourcePackage: '@open-mercato/example',
|
|
470
|
+
sourceVersion: '1.0.0',
|
|
471
|
+
})
|
|
472
|
+
expect(JSON.stringify(toModuleFactsJsonEntry(rerun))).toBe(JSON.stringify(toModuleFactsJsonEntry(facts)))
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
it('renders new owned-contract markdown sections with clickable source links', () => {
|
|
476
|
+
const markdown = renderModuleFactsMarkdown(facts)
|
|
477
|
+
expect(markdown).toContain('## Domain commands')
|
|
478
|
+
expect(markdown).toContain('## Workers')
|
|
479
|
+
expect(markdown).toContain('## Page middleware')
|
|
480
|
+
expect(markdown).toContain('## Setup')
|
|
481
|
+
expect(markdown).toContain('## Encryption')
|
|
482
|
+
expect(markdown).toContain('## DI registrations (rich)')
|
|
483
|
+
expect(markdown).toContain('## Generator plugins')
|
|
484
|
+
expect(markdown).toContain('(../../../node_modules/@open-mercato/example/src/modules/facts/di.ts')
|
|
485
|
+
// Empty-content sections are omitted rather than rendered blank.
|
|
486
|
+
expect(markdown).not.toMatch(/## Domain commands\n\n_none_/)
|
|
487
|
+
})
|
|
488
|
+
|
|
489
|
+
it('renders a resolved source link for every represented scalar fact', () => {
|
|
490
|
+
const markdown = renderModuleFactsMarkdown(facts)
|
|
491
|
+
const rowFor = (identifier: string): string => {
|
|
492
|
+
const row = markdown.split('\n').find((line) => line.startsWith(`| ${identifier} |`))
|
|
493
|
+
return row ?? ''
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
expect(markdown).toContain('| Entity ID | Class | Table | Editable | CustomFields | Source |')
|
|
497
|
+
expect(rowFor('facts:facts_widget')).toContain(
|
|
498
|
+
'(../../../node_modules/@open-mercato/example/src/modules/facts/data/entities.ts)',
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
expect(markdown).toContain('| ID | Category | Entity | Browser transport | Source |')
|
|
502
|
+
expect(rowFor('facts.widget.created')).toContain(
|
|
503
|
+
'(../../../node_modules/@open-mercato/example/src/modules/facts/events.ts)',
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
expect(markdown).toContain('| Feature | Source |')
|
|
507
|
+
expect(rowFor('facts.view')).toContain('(../../../node_modules/@open-mercato/example/src/modules/facts/acl.ts)')
|
|
508
|
+
|
|
509
|
+
expect(markdown).toContain('| Token | Source |')
|
|
510
|
+
expect(markdown).toContain('| Entity ID | Source |')
|
|
511
|
+
expect(markdown).toContain('| Notification ID | Source |')
|
|
512
|
+
expect(rowFor('facts.alert')).toContain(
|
|
513
|
+
'(../../../node_modules/@open-mercato/example/src/modules/facts/notifications.ts)',
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
// No represented scalar fact renders an unresolved source cell.
|
|
517
|
+
const scalarSections = ['## ACL features', '## DI service tokens', '## Search entities', '## Notifications']
|
|
518
|
+
for (const heading of scalarSections) {
|
|
519
|
+
const section = markdown.slice(markdown.indexOf(heading)).split('\n\n')[1] ?? ''
|
|
520
|
+
expect(section).not.toContain('| — |')
|
|
521
|
+
}
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
it('renders source columns on the extension-surface sections', () => {
|
|
525
|
+
const markdown = renderModuleFactsMarkdown(facts)
|
|
526
|
+
expect(markdown).toContain('## Contribution resolutions')
|
|
527
|
+
expect(markdown).toContain('| ID / pattern | Family | Supports | Context | Stability | Source |')
|
|
528
|
+
expect(markdown).toContain('| ID | Kind | Target | Phase / operations | Contract | Resolution | Source |')
|
|
529
|
+
})
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
describe('module-facts integration array/bundle coverage (Spec 1)', () => {
|
|
533
|
+
let temporaryRoot: string
|
|
534
|
+
|
|
535
|
+
afterAll(() => {
|
|
536
|
+
if (temporaryRoot) fs.rmSync(temporaryRoot, { recursive: true, force: true })
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
it('reads singular, array, and bundle integration declarations', () => {
|
|
540
|
+
temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'module-facts-integration-'))
|
|
541
|
+
const moduleRoot = path.join(temporaryRoot, 'shipments')
|
|
542
|
+
writeFixture(moduleRoot, 'index.ts', "export const metadata = { name: 'shipments' }\n")
|
|
543
|
+
writeFixture(
|
|
544
|
+
moduleRoot,
|
|
545
|
+
'integration.ts',
|
|
546
|
+
"export const integration = { id: 'shipments.primary' }\n"
|
|
547
|
+
+ "export const integrations = [{ id: 'shipments.alt' }, { id: 'shipments.legacy' }]\n"
|
|
548
|
+
+ "export const integrationBundle = { id: 'carriers', integrations: [{ id: 'shipments.bundled' }] }\n",
|
|
549
|
+
)
|
|
550
|
+
const facts = extractModuleFacts({
|
|
551
|
+
moduleId: 'shipments',
|
|
552
|
+
moduleRoot,
|
|
553
|
+
sourcePackage: '@open-mercato/example',
|
|
554
|
+
sourceVersion: '1.0.0',
|
|
555
|
+
})
|
|
556
|
+
const integrationIds = new Set(
|
|
557
|
+
(facts.factSources ?? []).filter((entry) => entry.kind === 'integration').map((entry) => entry.id),
|
|
558
|
+
)
|
|
559
|
+
expect(integrationIds).toEqual(new Set(['shipments.primary', 'shipments.alt', 'shipments.legacy', 'shipments.bundled']))
|
|
560
|
+
})
|
|
561
|
+
})
|