@open-mercato/cli 0.11.1-develop.8589.1.db1a76ea60 → 0.11.1-develop.8593.1.50784dae35
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/AGENTS.md +1 -0
- package/dist/agentic/guides/module-facts.json +164 -164
- package/dist/agentic/guides/module-facts.v2.json +164 -164
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/manifest.json +1 -1
- package/dist/lib/generate-child-process.js +21 -3
- package/dist/lib/generate-child-process.js.map +2 -2
- package/dist/lib/generate-watch-events.js +135 -19
- package/dist/lib/generate-watch-events.js.map +2 -2
- package/dist/lib/generate-watch-plan.js +166 -0
- package/dist/lib/generate-watch-plan.js.map +7 -0
- package/dist/lib/generate-watch-runner.js +53 -0
- package/dist/lib/generate-watch-runner.js.map +7 -0
- package/dist/lib/generate-watch-structure.js +576 -203
- package/dist/lib/generate-watch-structure.js.map +3 -3
- package/dist/lib/generators/extensions/agent-files.js +1 -0
- package/dist/lib/generators/extensions/agent-files.js.map +2 -2
- package/dist/lib/generators/module-registry.js +148 -191
- package/dist/lib/generators/module-registry.js.map +3 -3
- package/dist/lib/generators/openapi.js +24 -1
- package/dist/lib/generators/openapi.js.map +2 -2
- package/dist/lib/generators/web-research-adapters.js +54 -22
- package/dist/lib/generators/web-research-adapters.js.map +2 -2
- package/dist/lib/in-process-generate-watcher.js +98 -75
- package/dist/lib/in-process-generate-watcher.js.map +2 -2
- package/dist/mercato.js +74 -46
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/lib/__tests__/generate-child-process.test.ts +30 -0
- package/src/lib/__tests__/generate-watch-events.test.ts +377 -8
- package/src/lib/__tests__/generate-watch-plan.test.ts +98 -0
- package/src/lib/__tests__/generate-watch-runner.test.ts +126 -0
- package/src/lib/__tests__/generate-watch-structure.test.ts +522 -1
- package/src/lib/__tests__/in-process-generate-watcher.test.ts +393 -6
- package/src/lib/__tests__/module-inspection.test.ts +17 -11
- package/src/lib/generate-child-process.ts +26 -3
- package/src/lib/generate-watch-events.ts +189 -17
- package/src/lib/generate-watch-plan.ts +177 -0
- package/src/lib/generate-watch-runner.ts +62 -0
- package/src/lib/generate-watch-structure.ts +666 -227
- package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
- package/src/lib/generators/__tests__/openapi.test.ts +91 -1
- package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
- package/src/lib/generators/extension.ts +2 -0
- package/src/lib/generators/extensions/agent-files.ts +1 -0
- package/src/lib/generators/module-registry.ts +168 -200
- package/src/lib/generators/openapi.ts +34 -0
- package/src/lib/generators/web-research-adapters.ts +76 -21
- package/src/lib/in-process-generate-watcher.ts +151 -96
- package/src/mercato.ts +85 -53
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/cli",
|
|
3
|
-
"version": "0.11.1-develop.
|
|
3
|
+
"version": "0.11.1-develop.8593.1.50784dae35",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@mikro-orm/decorators": "^7.1.14",
|
|
61
61
|
"@mikro-orm/migrations": "^7.1.14",
|
|
62
62
|
"@mikro-orm/postgresql": "^7.1.14",
|
|
63
|
-
"@open-mercato/events": "0.11.1-develop.
|
|
64
|
-
"@open-mercato/queue": "0.11.1-develop.
|
|
65
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
66
|
-
"@open-mercato/telemetry": "0.11.1-develop.
|
|
63
|
+
"@open-mercato/events": "0.11.1-develop.8593.1.50784dae35",
|
|
64
|
+
"@open-mercato/queue": "0.11.1-develop.8593.1.50784dae35",
|
|
65
|
+
"@open-mercato/shared": "0.11.1-develop.8593.1.50784dae35",
|
|
66
|
+
"@open-mercato/telemetry": "0.11.1-develop.8593.1.50784dae35",
|
|
67
67
|
"cross-spawn": "^7.0.6",
|
|
68
68
|
"minisearch": "7.2.0",
|
|
69
69
|
"pg": "8.23.0",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
"typescript-js": "npm:typescript@6.0.3"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
78
|
+
"@open-mercato/shared": "0.11.1-develop.8593.1.50784dae35"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
81
|
+
"@open-mercato/shared": "0.11.1-develop.8593.1.50784dae35",
|
|
82
82
|
"@types/jest": "^30.0.0",
|
|
83
83
|
"jest": "^30.4.2",
|
|
84
84
|
"ts-jest": "^29.4.12"
|
|
@@ -183,3 +183,33 @@ it('preserves real generated metadata, callbacks and plugins across dependency e
|
|
|
183
183
|
]))
|
|
184
184
|
}
|
|
185
185
|
}, 120_000)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
it('passes incremental plans through stdin to a disposable generator and consumes the private marker', async () => {
|
|
189
|
+
const binary = write('generate.mjs', `
|
|
190
|
+
import fs from 'node:fs'
|
|
191
|
+
const { readGenerateWatchRequest } = await import(process.env.CHILD_HELPER_SOURCE)
|
|
192
|
+
fs.writeFileSync('result.json', JSON.stringify({
|
|
193
|
+
request: readGenerateWatchRequest(),
|
|
194
|
+
marker: process.env.OM_INTERNAL_GENERATE_WATCH_REQUEST ?? null,
|
|
195
|
+
secondRead: readGenerateWatchRequest() ?? null,
|
|
196
|
+
}))
|
|
197
|
+
`)
|
|
198
|
+
const watchRequest = {
|
|
199
|
+
plan: {
|
|
200
|
+
mode: 'incremental' as const,
|
|
201
|
+
groups: ['di' as const], registryOutputs: [], reasons: [],
|
|
202
|
+
changes: [{ kind: 'change' as const, category: 'di' as const, key: 'probe/di', path: '/probe/di.ts' }],
|
|
203
|
+
},
|
|
204
|
+
logCascade: true,
|
|
205
|
+
}
|
|
206
|
+
await runGenerateChildProcess({
|
|
207
|
+
mercatoBin: binary, cwd: directory, watchRequest,
|
|
208
|
+
env: {
|
|
209
|
+
...process.env,
|
|
210
|
+
NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ''} --import=${pathToFileURL(require.resolve('tsx')).href}`,
|
|
211
|
+
CHILD_HELPER_SOURCE: pathToFileURL(path.resolve(__dirname, '../generate-child-process.ts')).href,
|
|
212
|
+
},
|
|
213
|
+
})
|
|
214
|
+
expect(readResult()).toEqual({ request: watchRequest, marker: null, secondRead: null })
|
|
215
|
+
})
|
|
@@ -6,10 +6,11 @@ import {
|
|
|
6
6
|
resolveGenerateWatchTargets,
|
|
7
7
|
type GenerateWatchTarget,
|
|
8
8
|
} from '../generate-watch-events'
|
|
9
|
+
import type { GenerateWatchSnapshot } from '../generate-watch-plan'
|
|
9
10
|
|
|
10
11
|
type RegisteredWatcher = {
|
|
11
12
|
target: GenerateWatchTarget
|
|
12
|
-
onChange: () => void
|
|
13
|
+
onChange: (fileName?: string) => void
|
|
13
14
|
onError: () => void
|
|
14
15
|
close: jest.Mock
|
|
15
16
|
}
|
|
@@ -19,7 +20,7 @@ function createWatchHarness(initialTargets: GenerateWatchTarget[]) {
|
|
|
19
20
|
const registered: RegisteredWatcher[] = []
|
|
20
21
|
const watchDirectory = jest.fn((
|
|
21
22
|
target: GenerateWatchTarget,
|
|
22
|
-
onChange: () => void,
|
|
23
|
+
onChange: (fileName?: string) => void,
|
|
23
24
|
onError: () => void,
|
|
24
25
|
) => {
|
|
25
26
|
const watcher = { target, onChange, onError, close: jest.fn() }
|
|
@@ -172,7 +173,8 @@ describe('createGenerateWatchChangeSignal', () => {
|
|
|
172
173
|
|
|
173
174
|
existing.add(packageModulesDir)
|
|
174
175
|
await signal.refresh()
|
|
175
|
-
|
|
176
|
+
// Its possible source mirror remains missing and must stay discoverable.
|
|
177
|
+
expect(signal.hasSkippedTargets?.()).toBe(true)
|
|
176
178
|
expect(registered).toContain(packageModulesDir)
|
|
177
179
|
await signal.close()
|
|
178
180
|
})
|
|
@@ -249,13 +251,23 @@ describe('createGenerateWatchChangeSignal', () => {
|
|
|
249
251
|
}
|
|
250
252
|
})
|
|
251
253
|
|
|
252
|
-
it('
|
|
253
|
-
const
|
|
254
|
-
const {
|
|
254
|
+
it('collapses duplicate and nested roots while retaining exact file targets', async () => {
|
|
255
|
+
const root = { directory: './modules', recursive: true }
|
|
256
|
+
const nested = { directory: './modules/orders', recursive: true }
|
|
257
|
+
const exact = { directory: './modules/orders', recursive: false, fileName: 'helper.ts' }
|
|
258
|
+
const { signal, registered, watchDirectory } = createWatchHarness([
|
|
259
|
+
nested,
|
|
260
|
+
exact,
|
|
261
|
+
root,
|
|
262
|
+
root,
|
|
263
|
+
])
|
|
255
264
|
|
|
256
265
|
await signal.refresh()
|
|
257
|
-
expect(watchDirectory).toHaveBeenCalledTimes(
|
|
258
|
-
expect(registered
|
|
266
|
+
expect(watchDirectory).toHaveBeenCalledTimes(2)
|
|
267
|
+
expect(registered.map((watcher) => watcher.target)).toEqual([
|
|
268
|
+
{ directory: path.resolve('./modules'), recursive: true },
|
|
269
|
+
{ directory: path.resolve('./modules/orders'), recursive: false, fileName: 'helper.ts' },
|
|
270
|
+
])
|
|
259
271
|
expect(signal.currentVersion()).toBe(0)
|
|
260
272
|
|
|
261
273
|
registered[0].onChange()
|
|
@@ -322,4 +334,361 @@ describe('createGenerateWatchChangeSignal', () => {
|
|
|
322
334
|
await signal.close()
|
|
323
335
|
expect(registered[0].close).toHaveBeenCalledTimes(1)
|
|
324
336
|
})
|
|
337
|
+
|
|
338
|
+
it('tracks a not-yet-installed source mirror and observes partial missing-root recovery', async () => {
|
|
339
|
+
const packageBase = path.resolve('/virtual/node_modules/example/dist/modules/orders')
|
|
340
|
+
const sourceModules = path.resolve('/virtual/node_modules/example/src/modules')
|
|
341
|
+
const targets = resolveGenerateWatchTargets({
|
|
342
|
+
modulesFile: '/virtual/src/modules.ts',
|
|
343
|
+
moduleRoots: [{ appBase: '/virtual/src/modules/orders', pkgBase: packageBase, watchPackageBase: true }],
|
|
344
|
+
resolveSourceMirrorBase: () => null,
|
|
345
|
+
additionalInputs: ['/virtual/package.json'],
|
|
346
|
+
})
|
|
347
|
+
const existing = new Set(['/virtual/src', path.dirname(packageBase)])
|
|
348
|
+
const watchers: GenerateWatchTarget[] = []
|
|
349
|
+
const signal = createGenerateWatchChangeSignal({
|
|
350
|
+
getWatchTargets: () => targets,
|
|
351
|
+
directoryExists: (directory) => existing.has(directory),
|
|
352
|
+
watchDirectory: (target) => { watchers.push(target); return { close: jest.fn() } },
|
|
353
|
+
})
|
|
354
|
+
await signal.refresh()
|
|
355
|
+
const baselineVersion = signal.currentVersion()
|
|
356
|
+
existing.add(sourceModules)
|
|
357
|
+
await signal.refresh()
|
|
358
|
+
expect(watchers).toContainEqual({ directory: sourceModules, recursive: true })
|
|
359
|
+
expect(signal.currentVersion()).toBeGreaterThan(baselineVersion)
|
|
360
|
+
expect(signal.hasSkippedTargets?.()).toBe(true)
|
|
361
|
+
expect(targets).toContainEqual({ directory: '/virtual', recursive: false, fileName: 'package.json' })
|
|
362
|
+
await signal.close()
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
it('reports only unattributed events newer than the acknowledged version', async () => {
|
|
366
|
+
const { signal, registered } = createWatchHarness([{ directory: './modules', recursive: true }])
|
|
367
|
+
await signal.refresh()
|
|
368
|
+
registered[0].onChange('orders/di.ts')
|
|
369
|
+
expect(signal.fullGenerationReasonSince?.(0)).toBeUndefined()
|
|
370
|
+
registered[0].onChange()
|
|
371
|
+
expect(signal.fullGenerationReasonSince?.(1)).toBeDefined()
|
|
372
|
+
expect(signal.fullGenerationReasonSince?.(2)).toBeUndefined()
|
|
373
|
+
await signal.close()
|
|
374
|
+
registered[0].onChange()
|
|
375
|
+
registered[0].onError()
|
|
376
|
+
expect(signal.currentVersion()).toBe(2)
|
|
377
|
+
expect(signal.usesPollingFallback()).toBe(false)
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
it('filters attributed generated-output events from coarse recursive roots', async () => {
|
|
381
|
+
const projectRoot = path.resolve('/virtual/watch-output-filter')
|
|
382
|
+
const packageRoot = path.join(projectRoot, 'packages', 'fixture')
|
|
383
|
+
const appOutput = path.join(packageRoot, 'app', '.mercato', 'generated')
|
|
384
|
+
const packageOutput = path.join(packageRoot, '.mercato', 'generated')
|
|
385
|
+
const packageManifest = path.join(packageRoot, 'package.json')
|
|
386
|
+
const externalHelper = path.join(projectRoot, 'external', 'helper.ts')
|
|
387
|
+
const snapshot: GenerateWatchSnapshot = {
|
|
388
|
+
checksum: 'fixture',
|
|
389
|
+
fullReasons: [],
|
|
390
|
+
records: new Map([
|
|
391
|
+
['app-output', {
|
|
392
|
+
key: 'app-output',
|
|
393
|
+
path: path.join(appOutput, 'modules.generated.ts'),
|
|
394
|
+
category: 'unknown',
|
|
395
|
+
fingerprint: 'fixture',
|
|
396
|
+
}],
|
|
397
|
+
['package-output', {
|
|
398
|
+
key: 'package-output',
|
|
399
|
+
path: path.join(packageOutput, 'entities.generated.ts'),
|
|
400
|
+
category: 'unknown',
|
|
401
|
+
fingerprint: 'fixture',
|
|
402
|
+
}],
|
|
403
|
+
]),
|
|
404
|
+
}
|
|
405
|
+
const sharedOptions = {
|
|
406
|
+
modulesFile: path.join(projectRoot, 'app', 'src', 'modules.ts'),
|
|
407
|
+
moduleRoots: [],
|
|
408
|
+
resolveSourceMirrorBase: () => null,
|
|
409
|
+
additionalInputs: [packageManifest, externalHelper],
|
|
410
|
+
appSourceDir: packageRoot,
|
|
411
|
+
outputDir: appOutput,
|
|
412
|
+
snapshot,
|
|
413
|
+
}
|
|
414
|
+
const targets = resolveGenerateWatchTargets({
|
|
415
|
+
...sharedOptions,
|
|
416
|
+
outputDirectories: [packageOutput, appOutput, packageOutput],
|
|
417
|
+
})
|
|
418
|
+
const reversedTargets = resolveGenerateWatchTargets({
|
|
419
|
+
...sharedOptions,
|
|
420
|
+
outputDirectories: [appOutput, packageOutput],
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
expect(targets).toEqual(reversedTargets)
|
|
424
|
+
expect(targets.some((target) => (
|
|
425
|
+
[appOutput, packageOutput].some((output) => (
|
|
426
|
+
target.directory === output || target.directory.startsWith(`${output}${path.sep}`)
|
|
427
|
+
))
|
|
428
|
+
))).toBe(false)
|
|
429
|
+
|
|
430
|
+
const { signal, registered } = createWatchHarness(targets)
|
|
431
|
+
await signal.refresh()
|
|
432
|
+
const packageWatcher = registered.find((watcher) => (
|
|
433
|
+
watcher.target.directory === packageRoot && watcher.target.recursive
|
|
434
|
+
))
|
|
435
|
+
const helperWatcher = registered.find((watcher) => watcher.target.fileName === 'helper.ts')
|
|
436
|
+
expect(packageWatcher?.target.excludedDirectories).toEqual([packageOutput, appOutput])
|
|
437
|
+
expect(helperWatcher).toBeDefined()
|
|
438
|
+
|
|
439
|
+
const baselineVersion = signal.currentVersion()
|
|
440
|
+
packageWatcher?.onChange(path.join('.mercato', 'generated', 'entities.generated.ts'))
|
|
441
|
+
packageWatcher?.onChange(path.join(appOutput, 'modules.generated.ts'))
|
|
442
|
+
expect(signal.currentVersion()).toBe(baselineVersion)
|
|
443
|
+
packageWatcher?.onChange('package.json')
|
|
444
|
+
expect(signal.currentVersion()).toBe(baselineVersion + 1)
|
|
445
|
+
helperWatcher?.onChange('helper.ts')
|
|
446
|
+
expect(signal.currentVersion()).toBe(baselineVersion + 2)
|
|
447
|
+
|
|
448
|
+
packageWatcher?.onChange()
|
|
449
|
+
expect(signal.currentVersion()).toBe(baselineVersion + 3)
|
|
450
|
+
expect(signal.fullGenerationReasonSince?.(baselineVersion + 2)).toBeDefined()
|
|
451
|
+
await signal.close()
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
it('replaces a watcher when its normalized output exclusions change', async () => {
|
|
455
|
+
const root = path.resolve('/virtual/watch-exclusion-identity')
|
|
456
|
+
const firstOutput = path.join(root, 'z-generated')
|
|
457
|
+
const secondOutput = path.join(root, 'a-generated')
|
|
458
|
+
const harness = createWatchHarness([{
|
|
459
|
+
directory: root,
|
|
460
|
+
recursive: true,
|
|
461
|
+
excludedDirectories: [firstOutput, secondOutput, firstOutput],
|
|
462
|
+
}])
|
|
463
|
+
|
|
464
|
+
await harness.signal.refresh()
|
|
465
|
+
expect(harness.registered[0].target.excludedDirectories).toEqual([secondOutput, firstOutput])
|
|
466
|
+
|
|
467
|
+
harness.setTargets([{
|
|
468
|
+
directory: root,
|
|
469
|
+
recursive: true,
|
|
470
|
+
excludedDirectories: [firstOutput],
|
|
471
|
+
}])
|
|
472
|
+
await harness.signal.refresh()
|
|
473
|
+
expect(harness.registered[0].close).toHaveBeenCalledTimes(1)
|
|
474
|
+
expect(harness.registered[1].target.excludedDirectories).toEqual([firstOutput])
|
|
475
|
+
await harness.signal.close()
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
it('never opens subscriptions when an asynchronous target lookup completes after close', async () => {
|
|
479
|
+
let resolveTargets!: (targets: GenerateWatchTarget[]) => void
|
|
480
|
+
const pendingTargets = new Promise<GenerateWatchTarget[]>((resolve) => { resolveTargets = resolve })
|
|
481
|
+
const watchDirectory = jest.fn(() => ({ close: jest.fn() }))
|
|
482
|
+
const signal = createGenerateWatchChangeSignal({
|
|
483
|
+
getWatchTargets: () => pendingTargets,
|
|
484
|
+
directoryExists: () => true,
|
|
485
|
+
watchDirectory,
|
|
486
|
+
})
|
|
487
|
+
const refreshing = signal.refresh()
|
|
488
|
+
await signal.close()
|
|
489
|
+
resolveTargets([{ directory: './modules', recursive: true }])
|
|
490
|
+
await refreshing
|
|
491
|
+
expect(watchDirectory).not.toHaveBeenCalled()
|
|
492
|
+
expect(signal.currentVersion()).toBe(0)
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
it('watches adapter scan roots without recursion and never one watcher per manifest', () => {
|
|
496
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'mercato-bounded-watch-'))
|
|
497
|
+
const appSource = path.join(root, 'app', 'src')
|
|
498
|
+
const outputDir = path.join(root, 'app', '.mercato', 'generated')
|
|
499
|
+
const scanRoots = [
|
|
500
|
+
path.join(root, 'research', 'first'),
|
|
501
|
+
path.join(root, 'research', 'second'),
|
|
502
|
+
]
|
|
503
|
+
const helper = path.join(root, 'external', 'helper.ts')
|
|
504
|
+
const config = path.join(root, 'config', 'generate.ts')
|
|
505
|
+
for (const directory of [appSource, outputDir, ...scanRoots, path.dirname(helper), path.dirname(config)]) {
|
|
506
|
+
fs.mkdirSync(directory, { recursive: true })
|
|
507
|
+
}
|
|
508
|
+
for (const file of [helper, config]) fs.writeFileSync(file, 'export const value = 1')
|
|
509
|
+
|
|
510
|
+
const manifestPaths = Array.from({ length: 5_000 }, (_, index) => (
|
|
511
|
+
path.join(scanRoots[index % scanRoots.length], `provider-${index}`, 'manifest.json')
|
|
512
|
+
))
|
|
513
|
+
const ownOutput = path.join(outputDir, 'modules.generated.ts')
|
|
514
|
+
const discoveredPaths = [...manifestPaths, manifestPaths[0], helper, ownOutput]
|
|
515
|
+
const snapshot: GenerateWatchSnapshot = {
|
|
516
|
+
checksum: 'forward',
|
|
517
|
+
fullReasons: [],
|
|
518
|
+
records: new Map(discoveredPaths.map((file, index) => [String(index), {
|
|
519
|
+
key: String(index), path: file,
|
|
520
|
+
category: file.endsWith('manifest.json') ? 'web-research-adapters' : 'unknown',
|
|
521
|
+
fingerprint: 'fixture',
|
|
522
|
+
}])),
|
|
523
|
+
}
|
|
524
|
+
const reversedSnapshot: GenerateWatchSnapshot = {
|
|
525
|
+
checksum: 'reverse',
|
|
526
|
+
fullReasons: [],
|
|
527
|
+
records: new Map([...discoveredPaths].reverse().map((file, index) => [String(index), {
|
|
528
|
+
key: String(index), path: file,
|
|
529
|
+
category: file.endsWith('manifest.json') ? 'web-research-adapters' : 'unknown',
|
|
530
|
+
fingerprint: 'fixture',
|
|
531
|
+
}])),
|
|
532
|
+
}
|
|
533
|
+
const sharedOptions = {
|
|
534
|
+
modulesFile: path.join(appSource, 'modules.ts'),
|
|
535
|
+
moduleRoots: [],
|
|
536
|
+
resolveSourceMirrorBase: () => null,
|
|
537
|
+
additionalInputs: [config],
|
|
538
|
+
appSourceDir: appSource,
|
|
539
|
+
outputDir,
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
try {
|
|
543
|
+
const targets = resolveGenerateWatchTargets({
|
|
544
|
+
...sharedOptions,
|
|
545
|
+
snapshot,
|
|
546
|
+
shallowDirectories: [
|
|
547
|
+
path.join(scanRoots[1], 'nested'),
|
|
548
|
+
scanRoots[0],
|
|
549
|
+
scanRoots[1],
|
|
550
|
+
scanRoots[0],
|
|
551
|
+
],
|
|
552
|
+
})
|
|
553
|
+
const reversedTargets = resolveGenerateWatchTargets({
|
|
554
|
+
...sharedOptions,
|
|
555
|
+
snapshot: reversedSnapshot,
|
|
556
|
+
shallowDirectories: [
|
|
557
|
+
scanRoots[1],
|
|
558
|
+
scanRoots[0],
|
|
559
|
+
path.join(scanRoots[1], 'nested'),
|
|
560
|
+
],
|
|
561
|
+
})
|
|
562
|
+
|
|
563
|
+
expect(targets).toEqual(reversedTargets)
|
|
564
|
+
expect(targets).toHaveLength(7)
|
|
565
|
+
expect(targets.filter((target) => (
|
|
566
|
+
scanRoots.some((scanRoot) => (
|
|
567
|
+
target.directory === scanRoot || target.directory.startsWith(`${scanRoot}${path.sep}`)
|
|
568
|
+
))
|
|
569
|
+
))).toEqual([
|
|
570
|
+
{ directory: scanRoots[0], recursive: false },
|
|
571
|
+
{ directory: scanRoots[1], recursive: false },
|
|
572
|
+
{ directory: path.join(scanRoots[1], 'nested'), recursive: false },
|
|
573
|
+
])
|
|
574
|
+
expect(targets).toContainEqual({
|
|
575
|
+
directory: path.dirname(helper),
|
|
576
|
+
recursive: false,
|
|
577
|
+
fileName: path.basename(helper),
|
|
578
|
+
})
|
|
579
|
+
expect(targets).toContainEqual({
|
|
580
|
+
directory: path.dirname(config),
|
|
581
|
+
recursive: false,
|
|
582
|
+
fileName: path.basename(config),
|
|
583
|
+
})
|
|
584
|
+
expect(targets.some((target) => target.directory === outputDir)).toBe(false)
|
|
585
|
+
} finally {
|
|
586
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
587
|
+
}
|
|
588
|
+
})
|
|
589
|
+
|
|
590
|
+
it('observes standalone package-generated entity metadata without watching node_modules recursively', async () => {
|
|
591
|
+
const projectRoot = path.resolve('/virtual/standalone-generated-input')
|
|
592
|
+
const nodeModules = path.join(projectRoot, 'node_modules')
|
|
593
|
+
const packageGenerated = path.join(nodeModules, '@open-mercato', 'core', 'generated')
|
|
594
|
+
const appOutput = path.join(projectRoot, '.mercato', 'generated')
|
|
595
|
+
const entityIds = path.join(packageGenerated, 'entities.ids.generated.js')
|
|
596
|
+
const snapshot: GenerateWatchSnapshot = {
|
|
597
|
+
checksum: 'fixture',
|
|
598
|
+
fullReasons: [],
|
|
599
|
+
records: new Map([['package-entity-ids', {
|
|
600
|
+
key: 'package-entity-ids',
|
|
601
|
+
path: entityIds,
|
|
602
|
+
category: 'entities',
|
|
603
|
+
fingerprint: 'fixture',
|
|
604
|
+
}]]),
|
|
605
|
+
}
|
|
606
|
+
const targets = resolveGenerateWatchTargets({
|
|
607
|
+
modulesFile: path.join(projectRoot, 'src', 'modules.ts'),
|
|
608
|
+
moduleRoots: [],
|
|
609
|
+
resolveSourceMirrorBase: () => null,
|
|
610
|
+
shallowDirectories: [nodeModules],
|
|
611
|
+
outputDir: appOutput,
|
|
612
|
+
outputDirectories: [appOutput],
|
|
613
|
+
snapshot,
|
|
614
|
+
})
|
|
615
|
+
const { signal, registered } = createWatchHarness(targets)
|
|
616
|
+
|
|
617
|
+
await signal.refresh()
|
|
618
|
+
expect(registered.some((watcher) => watcher.target.directory === nodeModules && watcher.target.recursive)).toBe(false)
|
|
619
|
+
const entityWatcher = registered.find((watcher) => (
|
|
620
|
+
watcher.target.directory === packageGenerated && watcher.target.fileName === path.basename(entityIds)
|
|
621
|
+
))
|
|
622
|
+
expect(entityWatcher).toBeDefined()
|
|
623
|
+
const version = signal.currentVersion()
|
|
624
|
+
entityWatcher?.onChange(path.basename(entityIds))
|
|
625
|
+
expect(signal.currentVersion()).toBe(version + 1)
|
|
626
|
+
await signal.close()
|
|
627
|
+
})
|
|
628
|
+
|
|
629
|
+
it('subscribes to shallow adapter roots and precise external helpers without watching its own outputs', async () => {
|
|
630
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'mercato-discovered-watch-'))
|
|
631
|
+
const appSource = path.join(root, 'app', 'src')
|
|
632
|
+
const outputDir = path.join(root, 'app', '.mercato', 'generated')
|
|
633
|
+
const packageRoot = path.join(root, 'node_modules', 'fixture')
|
|
634
|
+
const packageGenerated = path.join(packageRoot, 'generated')
|
|
635
|
+
const helper = path.join(root, 'external', 'helper.ts')
|
|
636
|
+
const missingHelper = path.join(root, 'future', 'nested', 'helper')
|
|
637
|
+
const entityFields = path.join(packageGenerated, 'entities', 'customer', 'index.ts')
|
|
638
|
+
const ownOutput = path.join(outputDir, 'modules.generated.ts')
|
|
639
|
+
for (const directory of [appSource, outputDir, path.dirname(helper), path.dirname(entityFields)]) {
|
|
640
|
+
fs.mkdirSync(directory, { recursive: true })
|
|
641
|
+
}
|
|
642
|
+
for (const file of [helper, entityFields, ownOutput]) fs.writeFileSync(file, 'export const value = 1')
|
|
643
|
+
const discoveredPaths = [helper, missingHelper, packageGenerated, entityFields, ownOutput]
|
|
644
|
+
const snapshot: GenerateWatchSnapshot = {
|
|
645
|
+
checksum: 'fixture',
|
|
646
|
+
fullReasons: [],
|
|
647
|
+
records: new Map(discoveredPaths.map((file) => [file, {
|
|
648
|
+
key: file, path: file, category: 'unknown', fingerprint: 'fixture',
|
|
649
|
+
}])),
|
|
650
|
+
}
|
|
651
|
+
const registered: GenerateWatchTarget[] = []
|
|
652
|
+
const signal = createGenerateWatchChangeSignal({
|
|
653
|
+
getWatchTargets: () => resolveGenerateWatchTargets({
|
|
654
|
+
modulesFile: path.join(appSource, 'modules.ts'),
|
|
655
|
+
moduleRoots: [],
|
|
656
|
+
resolveSourceMirrorBase: () => null,
|
|
657
|
+
appSourceDir: appSource,
|
|
658
|
+
outputDir,
|
|
659
|
+
snapshot,
|
|
660
|
+
shallowDirectories: [path.dirname(packageRoot)],
|
|
661
|
+
}),
|
|
662
|
+
watchDirectory: (target) => {
|
|
663
|
+
registered.push(target)
|
|
664
|
+
return { close: jest.fn() }
|
|
665
|
+
},
|
|
666
|
+
})
|
|
667
|
+
try {
|
|
668
|
+
await signal.refresh()
|
|
669
|
+
expect(registered).toEqual(expect.arrayContaining([
|
|
670
|
+
{ directory: appSource, recursive: true },
|
|
671
|
+
{ directory: path.dirname(helper), recursive: false, fileName: 'helper.ts' },
|
|
672
|
+
{ directory: path.dirname(packageRoot), recursive: false },
|
|
673
|
+
{ directory: packageGenerated, recursive: true },
|
|
674
|
+
{ directory: root, recursive: false },
|
|
675
|
+
]))
|
|
676
|
+
expect(registered.some((target) => target.directory === outputDir)).toBe(false)
|
|
677
|
+
expect(registered.filter((target) => (
|
|
678
|
+
target.directory === path.dirname(packageRoot)
|
|
679
|
+
|| target.directory.startsWith(`${path.dirname(packageRoot)}${path.sep}`)
|
|
680
|
+
))).toEqual([
|
|
681
|
+
{ directory: path.dirname(packageRoot), recursive: false },
|
|
682
|
+
{ directory: packageGenerated, recursive: true },
|
|
683
|
+
])
|
|
684
|
+
const version = signal.currentVersion()
|
|
685
|
+
fs.mkdirSync(path.dirname(missingHelper), { recursive: true })
|
|
686
|
+
await signal.refresh()
|
|
687
|
+
expect(registered).toContainEqual({ directory: path.dirname(missingHelper), recursive: false })
|
|
688
|
+
expect(signal.currentVersion()).toBeGreaterThan(version)
|
|
689
|
+
} finally {
|
|
690
|
+
await signal.close()
|
|
691
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
692
|
+
}
|
|
693
|
+
})
|
|
325
694
|
})
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { planGenerateWatchChanges, type GenerateWatchChange } from '../generate-watch-plan'
|
|
2
|
+
|
|
3
|
+
function change(category: GenerateWatchChange['category'], path: string, extensionId?: string): GenerateWatchChange {
|
|
4
|
+
return { kind: 'change', key: path, category, path, ...(extensionId ? { extensionId } : {}) }
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
describe('planGenerateWatchChanges', () => {
|
|
8
|
+
it('selects only API consumers for API changes, including deletion', () => {
|
|
9
|
+
const plan = planGenerateWatchChanges([{ ...change('api-route', '/customers/api/items/route.ts'), kind: 'delete' }])
|
|
10
|
+
expect(plan.mode).toBe('incremental')
|
|
11
|
+
expect(plan.groups).toEqual(['registry', 'openapi'])
|
|
12
|
+
expect(plan.registryOutputs).toEqual(['main', 'runtime', 'api-routes'])
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('unions page consumers without bootstrap, CLI or independent extensions', () => {
|
|
16
|
+
const plan = planGenerateWatchChanges([
|
|
17
|
+
change('frontend-page', '/customers/frontend/page.tsx'),
|
|
18
|
+
change('backend-page', '/customers/backend/page.meta.ts'),
|
|
19
|
+
])
|
|
20
|
+
expect(plan.groups).toEqual(['registry'])
|
|
21
|
+
expect(plan.registryOutputs).toEqual(['main', 'runtime', 'app', 'frontend-routes', 'backend-routes'])
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('preserves suite order while selecting independent entity, DI and extension work', () => {
|
|
25
|
+
const changes = [
|
|
26
|
+
change('di', '/customers/di.ts'), change('search', '/customers/search.ts'),
|
|
27
|
+
change('entities', '/customers/data/entities.ts'),
|
|
28
|
+
]
|
|
29
|
+
const plan = planGenerateWatchChanges(changes)
|
|
30
|
+
expect(plan.groups).toEqual(['entity-ids', 'registry', 'entities', 'di'])
|
|
31
|
+
expect(plan.registryOutputs).toEqual(['registry.search'])
|
|
32
|
+
expect(planGenerateWatchChanges([...changes].reverse())).toEqual(plan)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('includes only proven extension shared-import and command-loader consumers', () => {
|
|
36
|
+
const plan = planGenerateWatchChanges([
|
|
37
|
+
change('extension', '/customers/analytics.ts', 'registry.analytics'),
|
|
38
|
+
change('extension', '/customers/commands/interceptors.ts', 'registry.command-interceptors'),
|
|
39
|
+
change('extension', '/customers/notifications.client.ts', 'registry.notifications'),
|
|
40
|
+
])
|
|
41
|
+
expect(plan.groups).toEqual(['registry'])
|
|
42
|
+
expect(plan.registryOutputs).toEqual(['main', 'commands', 'registry.notifications', 'registry.analytics', 'registry.command-interceptors'])
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('keeps injection tables and widgets in one aggregate but not unrelated widget outputs', () => {
|
|
46
|
+
expect(planGenerateWatchChanges([change('injection-widgets', '/customers/widgets/injection-table.ts')]).registryOutputs)
|
|
47
|
+
.toEqual(['registry.injection-widgets'])
|
|
48
|
+
expect(planGenerateWatchChanges([change('dashboard-widgets', '/customers/widgets/dashboard/stats/widget.ts')]).registryOutputs)
|
|
49
|
+
.toEqual(['main', 'app', 'bootstrap', 'cli', 'registry.dashboard-widgets'])
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('retains worker supervisor and i18n helper dependencies', () => {
|
|
53
|
+
const plan = planGenerateWatchChanges([change('workers', '/customers/workers/job.ts')])
|
|
54
|
+
expect(plan.registryOutputs).toEqual(['main', 'runtime', 'app', 'bootstrap', 'cli', 'i18n', 'supervisor'])
|
|
55
|
+
expect(plan.groups).toEqual(['registry'])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('distinguishes vector-only CLI configuration from shared registry conventions', () => {
|
|
59
|
+
expect(planGenerateWatchChanges([change('registry-convention', '/customers/vector.js')]).registryOutputs).toEqual(['cli'])
|
|
60
|
+
expect(planGenerateWatchChanges([change('registry-convention', '/customers/runtime.ts')]).registryOutputs)
|
|
61
|
+
.toEqual(['main', 'runtime', 'app', 'bootstrap', 'cli'])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('updates supervisor CLI state only for the scheduler convention', () => {
|
|
65
|
+
expect(planGenerateWatchChanges([change('cli', '/customers/cli.ts')]).registryOutputs).toEqual(['main', 'cli'])
|
|
66
|
+
expect(planGenerateWatchChanges([change('cli', '/scheduler/cli.ts')]).registryOutputs).toEqual(['main', 'cli', 'supervisor'])
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('maps OpenAPI and web-research inputs directly to their narrow generator groups', () => {
|
|
70
|
+
const plan = planGenerateWatchChanges([
|
|
71
|
+
change('openapi', '/app/src/openapi.ts'),
|
|
72
|
+
change('web-research-adapters', '/packages/adapter/package.json'),
|
|
73
|
+
])
|
|
74
|
+
expect(plan.mode).toBe('incremental')
|
|
75
|
+
expect(plan.groups).toEqual(['web-research-adapters', 'openapi'])
|
|
76
|
+
expect(plan.registryOutputs).toEqual([])
|
|
77
|
+
expect(plan.reasons).toEqual([])
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it.each(['configuration', 'generator-plugin', 'unknown'] as const)('lets %s fallback dominate narrow work and reports why', (category) => {
|
|
81
|
+
const path = '/customers/dependency.ts'
|
|
82
|
+
const plan = planGenerateWatchChanges([change('api-route', '/customers/api/route.ts'), change(category, path)])
|
|
83
|
+
expect(plan.mode).toBe('full')
|
|
84
|
+
expect(plan.groups).toEqual(['entity-ids', 'registry', 'entities', 'di', 'package-sources', 'web-research-adapters', 'openapi'])
|
|
85
|
+
expect(plan.reasons).toEqual([expect.stringContaining(path)])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('does not narrow an unknown extension to an unrecognized output group', () => {
|
|
89
|
+
const plan = planGenerateWatchChanges([change('extension', '/customers/custom.ts', 'third-party.dynamic')])
|
|
90
|
+
expect(plan.mode).toBe('full')
|
|
91
|
+
expect(plan.reasons).toEqual(['Unknown generator extension dependency: /customers/custom.ts'])
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('treats scan uncertainty as full even without a diff, but clean empty diffs as no work', () => {
|
|
95
|
+
expect(planGenerateWatchChanges([], ['Cannot scan generator inputs: /customers']).mode).toBe('full')
|
|
96
|
+
expect(planGenerateWatchChanges([])).toEqual({ mode: 'none', groups: [], registryOutputs: [], changes: [], reasons: [] })
|
|
97
|
+
})
|
|
98
|
+
})
|