@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.
Files changed (133) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/AGENTS.md +1 -0
  3. package/dist/agentic/guides/module-facts.json +164 -164
  4. package/dist/agentic/guides/module-facts.v2.json +164 -164
  5. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  6. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  7. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  8. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  9. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  10. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  11. package/dist/agentic/guides/modules/auth/index.md +1 -1
  12. package/dist/agentic/guides/modules/availability/index.md +1 -1
  13. package/dist/agentic/guides/modules/backups/index.md +1 -1
  14. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  15. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  16. package/dist/agentic/guides/modules/cart/index.md +1 -1
  17. package/dist/agentic/guides/modules/catalog/index.md +1 -1
  18. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  19. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  20. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  21. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  22. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  23. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  24. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  25. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  26. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  27. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  28. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  29. package/dist/agentic/guides/modules/configs/index.md +1 -1
  30. package/dist/agentic/guides/modules/content/index.md +1 -1
  31. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  32. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  33. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  34. package/dist/agentic/guides/modules/customers/index.md +1 -1
  35. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  36. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  37. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  38. package/dist/agentic/guides/modules/devices/index.md +1 -1
  39. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  40. package/dist/agentic/guides/modules/directory/index.md +1 -1
  41. package/dist/agentic/guides/modules/documents/index.md +1 -1
  42. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  43. package/dist/agentic/guides/modules/entities/index.md +1 -1
  44. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  45. package/dist/agentic/guides/modules/events/index.md +1 -1
  46. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  47. package/dist/agentic/guides/modules/forms/index.md +1 -1
  48. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  49. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  50. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  51. package/dist/agentic/guides/modules/generators/index.md +1 -1
  52. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  53. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  54. package/dist/agentic/guides/modules/messages/index.md +1 -1
  55. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  56. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  57. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  58. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  59. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  60. package/dist/agentic/guides/modules/planner/index.md +1 -1
  61. package/dist/agentic/guides/modules/portal/index.md +1 -1
  62. package/dist/agentic/guides/modules/progress/index.md +1 -1
  63. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  64. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  65. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  66. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  67. package/dist/agentic/guides/modules/resources/index.md +1 -1
  68. package/dist/agentic/guides/modules/sales/index.md +1 -1
  69. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  70. package/dist/agentic/guides/modules/search/index.md +1 -1
  71. package/dist/agentic/guides/modules/security/index.md +1 -1
  72. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  73. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  74. package/dist/agentic/guides/modules/sso/index.md +1 -1
  75. package/dist/agentic/guides/modules/staff/index.md +1 -1
  76. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  77. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  78. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  79. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  80. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  81. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  82. package/dist/agentic/guides/modules/translations/index.md +1 -1
  83. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  84. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  85. package/dist/agentic/guides/modules/wms/index.md +1 -1
  86. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  87. package/dist/agentic/guides/reference-module-facts.json +1 -1
  88. package/dist/agentic/guides/upstream/manifest.json +1 -1
  89. package/dist/lib/generate-child-process.js +21 -3
  90. package/dist/lib/generate-child-process.js.map +2 -2
  91. package/dist/lib/generate-watch-events.js +135 -19
  92. package/dist/lib/generate-watch-events.js.map +2 -2
  93. package/dist/lib/generate-watch-plan.js +166 -0
  94. package/dist/lib/generate-watch-plan.js.map +7 -0
  95. package/dist/lib/generate-watch-runner.js +53 -0
  96. package/dist/lib/generate-watch-runner.js.map +7 -0
  97. package/dist/lib/generate-watch-structure.js +576 -203
  98. package/dist/lib/generate-watch-structure.js.map +3 -3
  99. package/dist/lib/generators/extensions/agent-files.js +1 -0
  100. package/dist/lib/generators/extensions/agent-files.js.map +2 -2
  101. package/dist/lib/generators/module-registry.js +148 -191
  102. package/dist/lib/generators/module-registry.js.map +3 -3
  103. package/dist/lib/generators/openapi.js +24 -1
  104. package/dist/lib/generators/openapi.js.map +2 -2
  105. package/dist/lib/generators/web-research-adapters.js +54 -22
  106. package/dist/lib/generators/web-research-adapters.js.map +2 -2
  107. package/dist/lib/in-process-generate-watcher.js +98 -75
  108. package/dist/lib/in-process-generate-watcher.js.map +2 -2
  109. package/dist/mercato.js +74 -46
  110. package/dist/mercato.js.map +2 -2
  111. package/package.json +7 -7
  112. package/src/lib/__tests__/generate-child-process.test.ts +30 -0
  113. package/src/lib/__tests__/generate-watch-events.test.ts +377 -8
  114. package/src/lib/__tests__/generate-watch-plan.test.ts +98 -0
  115. package/src/lib/__tests__/generate-watch-runner.test.ts +126 -0
  116. package/src/lib/__tests__/generate-watch-structure.test.ts +522 -1
  117. package/src/lib/__tests__/in-process-generate-watcher.test.ts +393 -6
  118. package/src/lib/__tests__/module-inspection.test.ts +17 -11
  119. package/src/lib/generate-child-process.ts +26 -3
  120. package/src/lib/generate-watch-events.ts +189 -17
  121. package/src/lib/generate-watch-plan.ts +177 -0
  122. package/src/lib/generate-watch-runner.ts +62 -0
  123. package/src/lib/generate-watch-structure.ts +666 -227
  124. package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
  125. package/src/lib/generators/__tests__/openapi.test.ts +91 -1
  126. package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
  127. package/src/lib/generators/extension.ts +2 -0
  128. package/src/lib/generators/extensions/agent-files.ts +1 -0
  129. package/src/lib/generators/module-registry.ts +168 -200
  130. package/src/lib/generators/openapi.ts +34 -0
  131. package/src/lib/generators/web-research-adapters.ts +76 -21
  132. package/src/lib/in-process-generate-watcher.ts +151 -96
  133. package/src/mercato.ts +85 -53
@@ -0,0 +1,126 @@
1
+ import path from 'node:path'
2
+ import { runGenerateWatchSuite } from '../generate-watch-runner'
3
+ import type { GenerateWatchGroup, GenerateWatchPlan } from '../generate-watch-plan'
4
+ import { createResolver } from '../resolver'
5
+ import * as generators from '../generators'
6
+ import { getOpenApiGeneratorDependencies } from '../generators/openapi'
7
+
8
+ jest.mock('../resolver', () => ({ createResolver: jest.fn(() => ({ fixture: true })) }))
9
+ jest.mock('../generators/openapi', () => ({ getOpenApiGeneratorDependencies: jest.fn(() => []) }))
10
+ jest.mock('../generators', () => ({
11
+ generateEntityIds: jest.fn(),
12
+ generateModuleRegistries: jest.fn(),
13
+ generateModuleEntities: jest.fn(),
14
+ generateModuleDi: jest.fn(),
15
+ generateModulePackageSources: jest.fn(),
16
+ generateWebResearchAdapters: jest.fn(),
17
+ generateOpenApi: jest.fn(),
18
+ }))
19
+
20
+ const allGroups: GenerateWatchGroup[] = ['entity-ids', 'registry', 'entities', 'di', 'package-sources', 'web-research-adapters', 'openapi']
21
+ const calls: GenerateWatchGroup[] = []
22
+ const unchanged = { filesWritten: [], filesUnchanged: ['unchanged'], errors: [] }
23
+
24
+ function selectedPlan(groups: GenerateWatchGroup[], registryOutputs: string[] = []): GenerateWatchPlan {
25
+ return { mode: 'incremental', groups, registryOutputs, changes: [], reasons: [] }
26
+ }
27
+
28
+ describe('runGenerateWatchSuite', () => {
29
+ beforeEach(() => {
30
+ jest.clearAllMocks()
31
+ calls.length = 0
32
+ jest.mocked(generators.generateEntityIds).mockImplementation(async () => { calls.push('entity-ids'); return unchanged })
33
+ jest.mocked(getOpenApiGeneratorDependencies).mockReturnValue([])
34
+ jest.mocked(generators.generateModuleRegistries).mockImplementation(async () => { calls.push('registry'); return [unchanged] })
35
+ jest.mocked(generators.generateModuleEntities).mockImplementation(async () => { calls.push('entities'); return unchanged })
36
+ jest.mocked(generators.generateModuleDi).mockImplementation(async () => { calls.push('di'); return unchanged })
37
+ jest.mocked(generators.generateModulePackageSources).mockImplementation(async () => { calls.push('package-sources'); return unchanged })
38
+ jest.mocked(generators.generateWebResearchAdapters).mockImplementation(async () => { calls.push('web-research-adapters'); return unchanged })
39
+ jest.mocked(generators.generateOpenApi).mockImplementation(async () => { calls.push('openapi'); return unchanged })
40
+ })
41
+
42
+ it('runs only selected groups in canonical dependency order and limits registry outputs', async () => {
43
+ const resolver = createResolver()
44
+ const plan = selectedPlan(['openapi', 'di', 'registry', 'entity-ids'], ['api-routes'])
45
+ expect(await runGenerateWatchSuite(true, plan, resolver)).toBe(false)
46
+ expect(calls).toEqual(['entity-ids', 'registry', 'di', 'openapi'])
47
+ expect(generators.generateModuleRegistries).toHaveBeenCalledWith({ resolver, quiet: true, outputGroups: ['api-routes'] })
48
+ })
49
+
50
+ it('does not enter unrelated generators for a single DI edit', async () => {
51
+ await runGenerateWatchSuite(true, selectedPlan(['di']))
52
+ expect(calls).toEqual(['di'])
53
+ })
54
+
55
+ it.each(['explicit', 'fallback'])('runs the complete suite for %s generation without an output filter', async (mode) => {
56
+ const plan: GenerateWatchPlan | undefined = mode === 'explicit'
57
+ ? undefined
58
+ : { mode: 'full', groups: [], registryOutputs: ['api-routes'], changes: [], reasons: ['unknown source'] }
59
+ await runGenerateWatchSuite(true, plan)
60
+ expect(calls).toEqual(allGroups)
61
+ expect(generators.generateModuleRegistries).toHaveBeenCalledWith({ resolver: createResolver(), quiet: true })
62
+ })
63
+
64
+ it('does no resolver or generator work for a no-op plan', async () => {
65
+ expect(await runGenerateWatchSuite(true, { mode: 'none', groups: [], registryOutputs: [], changes: [], reasons: [] })).toBe(false)
66
+ expect(calls).toEqual([])
67
+ expect(createResolver).not.toHaveBeenCalled()
68
+ })
69
+
70
+ it('reports changed output bytes even if a later selected group is unchanged', async () => {
71
+ jest.mocked(generators.generateModuleDi).mockResolvedValueOnce({ ...unchanged, filesWritten: ['di.generated.ts'] })
72
+ expect(await runGenerateWatchSuite(true, selectedPlan(['di', 'openapi']))).toBe(true)
73
+ })
74
+
75
+ it('propagates a failed suite and never runs later dependent groups', async () => {
76
+ jest.mocked(generators.generateModuleRegistries).mockRejectedValueOnce(new Error('registry failed'))
77
+ await expect(runGenerateWatchSuite(true)).rejects.toThrow('registry failed')
78
+ expect(calls).toEqual(['entity-ids'])
79
+ expect(generators.generateModuleEntities).not.toHaveBeenCalled()
80
+ expect(generators.generateOpenApi).not.toHaveBeenCalled()
81
+ })
82
+
83
+ it('does not report a generator result containing errors as successful generation', async () => {
84
+ jest.mocked(generators.generateModuleDi).mockResolvedValueOnce({ ...unchanged, errors: ['unable to generate DI'] })
85
+ await expect(runGenerateWatchSuite(true, selectedPlan(['di', 'openapi']))).rejects.toThrow('unable to generate DI')
86
+ expect(generators.generateOpenApi).not.toHaveBeenCalled()
87
+ })
88
+
89
+ it('cascades a changed generated dependency using the graph captured before producer execution', async () => {
90
+ const generatedPath = path.resolve('/virtual/app/.mercato/generated/di.generated.ts')
91
+ jest.mocked(getOpenApiGeneratorDependencies).mockReturnValue([generatedPath])
92
+ jest.mocked(generators.generateModuleDi).mockImplementationOnce(async () => {
93
+ calls.push('di')
94
+ jest.mocked(getOpenApiGeneratorDependencies).mockReturnValue([])
95
+ return { ...unchanged, filesWritten: [generatedPath] }
96
+ })
97
+ const cascade = jest.fn()
98
+ expect(await runGenerateWatchSuite(true, selectedPlan(['di']), undefined, cascade)).toBe(true)
99
+ expect(calls).toEqual(['di', 'openapi'])
100
+ expect(cascade).toHaveBeenCalledTimes(1)
101
+ })
102
+
103
+ it('cascades deletion of a generated directory containing an imported entity field file', async () => {
104
+ const generatedDirectory = path.resolve('/virtual/app/.mercato/generated/entities/retired')
105
+ jest.mocked(getOpenApiGeneratorDependencies).mockReturnValue([path.join(generatedDirectory, 'index.ts')])
106
+ jest.mocked(generators.generateEntityIds).mockResolvedValueOnce({ ...unchanged, filesWritten: [generatedDirectory] })
107
+ await runGenerateWatchSuite(true, selectedPlan(['entity-ids']))
108
+ expect(generators.generateOpenApi).toHaveBeenCalledTimes(1)
109
+ })
110
+
111
+ it.each([{ dependencies: [] }, { dependencies: [path.resolve('/virtual/unrelated.ts')] }])('does not cascade unrelated byte changes with a known graph $dependencies', async ({ dependencies }) => {
112
+ jest.mocked(getOpenApiGeneratorDependencies).mockReturnValue(dependencies)
113
+ jest.mocked(generators.generateModuleDi).mockResolvedValueOnce({ ...unchanged, filesWritten: ['/virtual/di.generated.ts'] })
114
+ await runGenerateWatchSuite(true, selectedPlan(['di']))
115
+ expect(generators.generateOpenApi).not.toHaveBeenCalled()
116
+ })
117
+
118
+ it('conservatively cascades unknown graphs only after a producer changes output bytes', async () => {
119
+ jest.mocked(getOpenApiGeneratorDependencies).mockReturnValue(null)
120
+ await runGenerateWatchSuite(true, selectedPlan(['di']))
121
+ expect(generators.generateOpenApi).not.toHaveBeenCalled()
122
+ jest.mocked(generators.generateModuleDi).mockResolvedValueOnce({ ...unchanged, filesWritten: ['/virtual/di.generated.ts'] })
123
+ await runGenerateWatchSuite(true, selectedPlan(['di']))
124
+ expect(generators.generateOpenApi).toHaveBeenCalledTimes(1)
125
+ })
126
+ })
@@ -1,7 +1,14 @@
1
1
  import fs from 'node:fs'
2
2
  import os from 'node:os'
3
3
  import path from 'node:path'
4
- import { calculateGenerateWatchStructureChecksum } from '../generate-watch-structure'
4
+ import {
5
+ calculateGenerateWatchStructureChecksum,
6
+ collectGenerateWatchStructureSnapshot,
7
+ createGenerateWatchStructureCache,
8
+ diffGenerateWatchStructureSnapshots,
9
+ type GenerateWatchStructureOptions,
10
+ } from '../generate-watch-structure'
11
+ import { planGenerateWatchChanges, type GenerateWatchSnapshot } from '../generate-watch-plan'
5
12
 
6
13
  function write(filePath: string, content: string): void {
7
14
  fs.mkdirSync(path.dirname(filePath), { recursive: true })
@@ -374,3 +381,517 @@ describe('calculateGenerateWatchStructureChecksum', () => {
374
381
  expect(checksumModule(modulesFile, appModule, distModule)).not.toBe(before)
375
382
  })
376
383
  })
384
+
385
+ describe('structured generator inputs', () => {
386
+ let root: string
387
+ let pkg: string
388
+ let app: string
389
+ let options: GenerateWatchStructureOptions
390
+
391
+ beforeEach(() => {
392
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'om-watch-snapshot-'))
393
+ pkg = path.join(root, 'packages/core/src/modules/customers')
394
+ app = path.join(root, 'app/src/modules/customers')
395
+ fs.mkdirSync(pkg, { recursive: true })
396
+ fs.mkdirSync(app, { recursive: true })
397
+ options = { modulesFile: path.join(root, 'app/src/modules.ts'), moduleRoots: [{ appBase: app, pkgBase: pkg }] }
398
+ write(options.modulesFile, 'export const enabledModules = []')
399
+ })
400
+
401
+ afterEach(() => {
402
+ jest.restoreAllMocks()
403
+ fs.rmSync(root, { recursive: true, force: true })
404
+ })
405
+
406
+ function capture(): GenerateWatchSnapshot {
407
+ return collectGenerateWatchStructureSnapshot(options)
408
+ }
409
+
410
+ function changesSince(previous: GenerateWatchSnapshot) {
411
+ const next = capture()
412
+ return { next, changes: diffGenerateWatchStructureSnapshots(previous, next) }
413
+ }
414
+
415
+ it('reuses cached content until stat identity changes or the file is deleted', () => {
416
+ const route = path.join(pkg, 'api/items/route.ts')
417
+ const helper = path.join(pkg, 'api/items/helper.ts')
418
+ write(route, 'import { value } from "./helper"; export const GET = () => value')
419
+ write(helper, 'export const value = 1')
420
+ const cache = createGenerateWatchStructureCache()
421
+ const readSpy = jest.spyOn(fs, 'readFileSync')
422
+
423
+ collectGenerateWatchStructureSnapshot(options, cache)
424
+ const readsAfterFirstCapture = readSpy.mock.calls.length
425
+ collectGenerateWatchStructureSnapshot(options, cache)
426
+ expect(readSpy).toHaveBeenCalledTimes(readsAfterFirstCapture)
427
+
428
+ write(helper, 'export const value = 200')
429
+ collectGenerateWatchStructureSnapshot(options, cache)
430
+ expect(readSpy.mock.calls.length).toBeGreaterThan(readsAfterFirstCapture)
431
+ const readsAfterChange = readSpy.mock.calls.length
432
+
433
+ fs.rmSync(helper)
434
+ collectGenerateWatchStructureSnapshot(options, cache)
435
+ write(helper, 'export const value = 300')
436
+ collectGenerateWatchStructureSnapshot(options, cache)
437
+ expect(readSpy.mock.calls.length).toBeGreaterThan(readsAfterChange)
438
+ })
439
+
440
+ it('preserves unreachable cache entries only for uncertain captures and prunes them after authoritative removal', () => {
441
+ const route = path.join(pkg, 'api/items/route.ts')
442
+ const helper = path.join(pkg, 'api/items/helper.ts')
443
+ write(route, 'import { value } from "./helper"; export const GET = () => value')
444
+ write(helper, 'export const value = 1')
445
+ const cache = createGenerateWatchStructureCache()
446
+ const readSpy = jest.spyOn(fs, 'readFileSync')
447
+ const moduleRoots = options.moduleRoots
448
+
449
+ collectGenerateWatchStructureSnapshot(options, cache)
450
+ expect(readSpy.mock.calls.filter(([file]) => file === helper)).toHaveLength(1)
451
+
452
+ options.moduleRoots = []
453
+ options.webResearchAdapterFullReasons = ['Cannot scan adapter packages']
454
+ collectGenerateWatchStructureSnapshot(options, cache)
455
+ options.moduleRoots = moduleRoots
456
+ delete options.webResearchAdapterFullReasons
457
+ collectGenerateWatchStructureSnapshot(options, cache)
458
+ expect(readSpy.mock.calls.filter(([file]) => file === helper)).toHaveLength(1)
459
+
460
+ options.moduleRoots = []
461
+ collectGenerateWatchStructureSnapshot(options, cache)
462
+ options.moduleRoots = moduleRoots
463
+ collectGenerateWatchStructureSnapshot(options, cache)
464
+ expect(readSpy.mock.calls.filter(([file]) => file === helper)).toHaveLength(2)
465
+ })
466
+
467
+ it('includes deterministic adapter scan uncertainty in snapshot full fallback reasons', () => {
468
+ options.webResearchAdapterFullReasons = [
469
+ 'Cannot scan web-research adapter packages: /z',
470
+ 'Cannot scan web-research adapter packages: /a',
471
+ 'Cannot scan web-research adapter packages: /z',
472
+ ]
473
+
474
+ const snapshot = capture()
475
+
476
+ expect(snapshot.fullReasons).toEqual([
477
+ 'Cannot scan web-research adapter packages: /a',
478
+ 'Cannot scan web-research adapter packages: /z',
479
+ ])
480
+ expect(planGenerateWatchChanges([], snapshot.fullReasons).mode).toBe('full')
481
+ })
482
+
483
+ it('preserves module identity when an identical route moves between existing roots', () => {
484
+ const second = path.join(root, 'packages/core/src/modules/sales')
485
+ fs.mkdirSync(second, { recursive: true })
486
+ options.moduleRoots.push({ appBase: path.join(root, 'app/src/modules/sales'), pkgBase: second })
487
+ const route = 'api/items/route.ts'
488
+ write(path.join(pkg, route), 'export const GET = () => null')
489
+ const before = capture()
490
+ fs.renameSync(path.join(pkg, route), path.join(second, 'route.tmp'))
491
+ write(path.join(second, route), 'export const GET = () => null')
492
+ fs.rmSync(path.join(second, 'route.tmp'))
493
+ const { changes } = changesSince(before)
494
+ expect(changes).toEqual(expect.arrayContaining([
495
+ expect.objectContaining({ kind: 'delete', category: 'api-route', path: path.join(pkg, route) }),
496
+ expect.objectContaining({ kind: 'add', category: 'api-route', path: path.join(second, route) }),
497
+ ]))
498
+ expect(planGenerateWatchChanges(changes).registryOutputs).toEqual(['main', 'runtime', 'api-routes'])
499
+ })
500
+
501
+ it('detects identical cli conventions moving between modules', () => {
502
+ const second = path.join(root, 'packages/core/src/modules/sales')
503
+ fs.mkdirSync(second, { recursive: true })
504
+ options.moduleRoots.push({ appBase: path.join(root, 'app/src/modules/sales'), pkgBase: second })
505
+ write(path.join(pkg, 'cli.ts'), 'export default []')
506
+ const before = capture()
507
+ fs.renameSync(path.join(pkg, 'cli.ts'), path.join(second, 'cli.ts'))
508
+ const { changes } = changesSince(before)
509
+ expect(changes).toEqual(expect.arrayContaining([
510
+ expect.objectContaining({ kind: 'delete', category: 'cli', path: path.join(pkg, 'cli.ts') }),
511
+ expect.objectContaining({ kind: 'add', category: 'cli', path: path.join(second, 'cli.ts') }),
512
+ ]))
513
+ })
514
+
515
+ it('keeps source additions, compiled arrival, edits and deletions as separate transitions', () => {
516
+ const source = path.join(root, 'node_modules/@example/pkg/src/modules/customers')
517
+ const dist = path.join(root, 'node_modules/@example/pkg/dist/modules/customers')
518
+ fs.mkdirSync(source, { recursive: true })
519
+ fs.mkdirSync(dist, { recursive: true })
520
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
521
+ const sourceRoute = path.join(source, 'api/items/route.ts')
522
+ const runtimeRoute = path.join(dist, 'api/items/route.js')
523
+ let before = capture()
524
+ write(sourceRoute, 'export const GET = () => null')
525
+ let result = changesSince(before)
526
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'add', path: sourceRoute, category: 'api-route' }))
527
+ before = result.next
528
+ write(runtimeRoute, 'export const GET = () => null')
529
+ result = changesSince(before)
530
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'add', path: runtimeRoute, category: 'api-route' }))
531
+ before = result.next
532
+ write(runtimeRoute, 'export const POST = () => null')
533
+ result = changesSince(before)
534
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'change', path: runtimeRoute, category: 'api-route' }))
535
+ before = result.next
536
+ fs.rmSync(runtimeRoute)
537
+ result = changesSince(before)
538
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'delete', path: runtimeRoute, category: 'api-route' }))
539
+ write(runtimeRoute, 'export const POST = () => null')
540
+ before = capture()
541
+ fs.rmSync(sourceRoute)
542
+ result = changesSince(before)
543
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'delete', path: sourceRoute, category: 'api-route' }))
544
+ expect([...result.next.records.values()].filter((record) => record.category === 'api-route')).toEqual([])
545
+ })
546
+
547
+ it.each(['cli', 'di', 'search', 'events'] as const)(
548
+ 'retains cached standalone %s runtime inputs after source-mirror convention deletion',
549
+ (category) => {
550
+ const source = path.join(root, 'node_modules/pkg/src/modules/customers')
551
+ const dist = path.join(root, 'node_modules/pkg/dist/modules/customers')
552
+ fs.mkdirSync(source, { recursive: true })
553
+ fs.mkdirSync(dist, { recursive: true })
554
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
555
+ const sourceFile = path.join(source, `${category}.ts`)
556
+ const runtimeFile = path.join(dist, `${category}.js`)
557
+ const cache = createGenerateWatchStructureCache()
558
+ const snapshot = () => collectGenerateWatchStructureSnapshot(options, cache)
559
+ const empty = snapshot()
560
+
561
+ write(sourceFile, 'export const metadata = { value: 1 }')
562
+ const sourceOnly = snapshot()
563
+ expect(diffGenerateWatchStructureSnapshots(empty, sourceOnly)).toContainEqual(
564
+ expect.objectContaining({ category, path: sourceFile, kind: 'add' }),
565
+ )
566
+ write(runtimeFile, 'export const metadata = { value: 1 }')
567
+ const paired = snapshot()
568
+ expect(diffGenerateWatchStructureSnapshots(sourceOnly, paired)).toContainEqual(
569
+ expect.objectContaining({ category, path: runtimeFile, kind: 'add' }),
570
+ )
571
+
572
+ fs.rmSync(sourceFile)
573
+ const runtimeOnly = snapshot()
574
+ const removedSource = diffGenerateWatchStructureSnapshots(paired, runtimeOnly)
575
+ expect(removedSource).toContainEqual(expect.objectContaining({ category, path: sourceFile, kind: 'delete' }))
576
+ expect(removedSource).not.toContainEqual(expect.objectContaining({ path: runtimeFile, kind: 'delete' }))
577
+ expect([...runtimeOnly.records.values()]).toContainEqual(expect.objectContaining({
578
+ category, path: runtimeFile, key: expect.stringContaining(':runtime'),
579
+ }))
580
+ expect(runtimeOnly.fullReasons).toEqual([])
581
+ const readSpy = jest.spyOn(fs, 'readFileSync')
582
+ expect(snapshot().checksum).toBe(runtimeOnly.checksum)
583
+ expect(readSpy).not.toHaveBeenCalled()
584
+ readSpy.mockRestore()
585
+
586
+ write(runtimeFile, 'export const metadata = { value: 2 }')
587
+ const editedRuntime = snapshot()
588
+ const changes = diffGenerateWatchStructureSnapshots(runtimeOnly, editedRuntime)
589
+ expect(changes).toContainEqual(expect.objectContaining({ category, path: runtimeFile, kind: 'change' }))
590
+ expect(changes.every((change) => change.category === category)).toBe(true)
591
+ expect(planGenerateWatchChanges(changes).mode).toBe('incremental')
592
+
593
+ fs.rmSync(runtimeFile)
594
+ const removedRuntime = snapshot()
595
+ expect(diffGenerateWatchStructureSnapshots(editedRuntime, removedRuntime)).toContainEqual(
596
+ expect.objectContaining({ category, path: runtimeFile, kind: 'delete' }),
597
+ )
598
+ expect(removedRuntime.checksum).toBe(empty.checksum)
599
+ },
600
+ )
601
+
602
+ it('shadows stale compiled conventions with app overrides and inherits runtime helper categories', () => {
603
+ const source = path.join(root, 'node_modules/pkg/src/modules/customers')
604
+ const dist = path.join(root, 'node_modules/pkg/dist/modules/customers')
605
+ fs.mkdirSync(source, { recursive: true })
606
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
607
+ const runtimeFile = path.join(dist, 'cli.js')
608
+ const helper = path.join(dist, 'lib/cli-options.js')
609
+ const appFile = path.join(app, 'cli.ts')
610
+ write(runtimeFile, 'import { value } from "./lib/cli-options"; export default value')
611
+ write(helper, 'export const value = 1')
612
+ write(appFile, 'export default []')
613
+ const overridden = capture()
614
+
615
+ write(runtimeFile, 'import { value } from "./lib/cli-options"; export default [value]')
616
+ write(helper, 'export const value = 2')
617
+ expect(capture().checksum).toBe(overridden.checksum)
618
+
619
+ fs.rmSync(appFile)
620
+ const revealed = capture()
621
+ expect(diffGenerateWatchStructureSnapshots(overridden, revealed)).toContainEqual(
622
+ expect.objectContaining({ category: 'cli', path: runtimeFile, kind: 'add' }),
623
+ )
624
+ write(helper, 'export const value = 3')
625
+ const { changes } = changesSince(revealed)
626
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'cli', path: helper, kind: 'change' }))
627
+ expect(planGenerateWatchChanges(changes).registryOutputs).toEqual(['main', 'cli'])
628
+ })
629
+
630
+ it('handles dist-only modules and source-mirror authority appearing later', () => {
631
+ const dist = path.join(root, 'node_modules/pkg/dist/modules/customers')
632
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
633
+ write(path.join(dist, 'workers/job.js'), 'export default async function job() {}')
634
+ const before = capture()
635
+ const source = path.join(root, 'node_modules/pkg/src/modules/customers')
636
+ fs.mkdirSync(source, { recursive: true })
637
+ const { changes } = changesSince(before)
638
+ expect(changes).toContainEqual(expect.objectContaining({ kind: 'delete', category: 'workers' }))
639
+ expect(planGenerateWatchChanges(changes).mode).toBe('full')
640
+ })
641
+
642
+ it('honors app overrides across extensions and reveals package inputs on deletion', () => {
643
+ write(path.join(pkg, 'workers/job.js'), 'export default async function job() {}')
644
+ const before = capture()
645
+ write(path.join(app, 'workers/job.ts'), 'export default async function job() {}')
646
+ const overridden = capture()
647
+ expect(diffGenerateWatchStructureSnapshots(before, overridden)).toContainEqual(
648
+ expect.objectContaining({ category: 'workers', path: path.join(app, 'workers/job.ts') }),
649
+ )
650
+ write(path.join(pkg, 'workers/job.js'), 'export default async function hiddenJob() {}')
651
+ expect(capture().checksum).toBe(overridden.checksum)
652
+ fs.rmSync(path.join(app, 'workers/job.ts'))
653
+ const { changes } = changesSince(overridden)
654
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'workers', path: path.join(pkg, 'workers/job.js') }))
655
+ })
656
+
657
+ it('tracks command ids and deletion while excluding command helpers and tests', () => {
658
+ const before = capture()
659
+ for (const file of ['index.ts', 'shared.ts', 'factory.ts', 'save.test.ts', 'save.d.ts']) {
660
+ write(path.join(pkg, 'commands', file), 'export const ignored = true')
661
+ }
662
+ expect(capture().checksum).toBe(before.checksum)
663
+ const command = path.join(pkg, 'commands/nested/save.ts')
664
+ write(command, 'export const command = { id: \"customers.save\" }')
665
+ const added = capture()
666
+ write(command, 'export const command = { id: \"customers.update\" }')
667
+ expect(changesSince(added).changes).toContainEqual(expect.objectContaining({ category: 'commands', kind: 'change', path: command }))
668
+ fs.rmSync(command)
669
+ expect(changesSince(added).changes).toContainEqual(expect.objectContaining({ category: 'commands', kind: 'delete', path: command }))
670
+ })
671
+
672
+ it('tracks legacy method APIs and preserves the command-interceptor overlap', () => {
673
+ const before = capture()
674
+ write(path.join(pkg, 'api/get/items.ts'), 'export default function handler() {}')
675
+ write(path.join(pkg, 'commands/interceptors.ts'), 'export const interceptors = []')
676
+ const { changes } = changesSince(before)
677
+ const plan = planGenerateWatchChanges(changes)
678
+ expect(plan.mode).toBe('incremental')
679
+ expect(plan.groups).toEqual(['registry', 'openapi'])
680
+ expect(plan.registryOutputs).toEqual(['main', 'runtime', 'api-routes', 'commands', 'registry.command-interceptors'])
681
+ })
682
+
683
+ it('uses locale membership and merge-side identity without hashing translation values', () => {
684
+ const locale = path.join(pkg, 'i18n/en.json')
685
+ write(locale, '{\"hello\":\"Hello\"}')
686
+ const before = capture()
687
+ write(locale, '{\"hello\":\"Hi\"}')
688
+ expect(capture().checksum).toBe(before.checksum)
689
+ write(path.join(app, 'i18n/en.json'), '{\"hello\":\"Custom\"}')
690
+ expect(changesSince(before).changes).toContainEqual(expect.objectContaining({ category: 'i18n', kind: 'add', path: path.join(app, 'i18n/en.json') }))
691
+ const merged = capture()
692
+ fs.rmSync(locale)
693
+ expect(changesSince(merged).changes).toContainEqual(expect.objectContaining({ category: 'i18n', kind: 'delete', path: locale }))
694
+ })
695
+
696
+ it('reads built-in-style static plugin descriptors and watches arbitrary nested contributions', () => {
697
+ write(path.join(pkg, 'generators.ts'), `
698
+ import type { GeneratorPlugin } from '@open-mercato/shared/modules/generators'
699
+ const file = 'custom/nested.items.ts'
700
+ const plugin: GeneratorPlugin = { id: 'test.items', conventionFile: file, buildOutput: () => '' }
701
+ export const generatorPlugins = [plugin]
702
+ export default generatorPlugins
703
+ `)
704
+ const before = capture()
705
+ expect(before.fullReasons).toEqual([])
706
+ write(path.join(pkg, 'custom/nested.items.ts'), 'export default [\"entry\"]')
707
+ const { changes } = changesSince(before)
708
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'generator-plugin', kind: 'add' }))
709
+ expect(planGenerateWatchChanges(changes).mode).toBe('full')
710
+ const contributed = capture()
711
+ fs.rmSync(path.join(pkg, 'generators.ts'))
712
+ expect(planGenerateWatchChanges(changesSince(contributed).changes).mode).toBe('full')
713
+ })
714
+
715
+ it('falls back explicitly for dynamic plugin descriptors instead of missing contributions', () => {
716
+ write(path.join(pkg, 'generators.ts'), 'export const generatorPlugins = makePlugins()')
717
+ const snapshot = capture()
718
+ expect(snapshot.fullReasons).toEqual([])
719
+ expect(planGenerateWatchChanges(diffGenerateWatchStructureSnapshots(snapshot, capture())).mode).toBe('none')
720
+ const contribution = path.join(pkg, 'custom/unknown.items.ts')
721
+ write(contribution, 'export const items = [\"new\"]')
722
+ const { changes } = changesSince(snapshot)
723
+ const plan = planGenerateWatchChanges(changes)
724
+ expect(plan.mode).toBe('full')
725
+ expect(plan.reasons).toContain(`Generator plugin dependency changed: ${contribution}`)
726
+ })
727
+
728
+ it('inherits backend-page planning through transitive metadata helpers', () => {
729
+ write(path.join(pkg, 'backend/page.tsx'), 'export default function Page() { return null }')
730
+ write(path.join(pkg, 'backend/page.meta.ts'), 'import { label } from "../lib/label"; export const metadata = { label }')
731
+ write(path.join(pkg, 'lib/label.ts'), 'export { label } from "./nested"')
732
+ write(path.join(pkg, 'lib/nested.ts'), 'export const label = "First"')
733
+ const before = capture()
734
+ write(path.join(pkg, 'components/Unrelated.tsx'), 'export default () => null')
735
+ expect(capture().checksum).toBe(before.checksum)
736
+ const nested = path.join(pkg, 'lib/nested.ts')
737
+ write(nested, 'export const label = "Second"')
738
+ const { changes } = changesSince(before)
739
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'backend-page', path: nested }))
740
+ const plan = planGenerateWatchChanges(changes)
741
+ expect(plan.mode).toBe('incremental')
742
+ expect(plan.registryOutputs).toEqual(['main', 'runtime', 'app', 'backend-routes'])
743
+ })
744
+
745
+ it('tracks page default-export shape without treating ordinary page rendering edits as structural', () => {
746
+ const page = path.join(pkg, 'backend/page.tsx')
747
+ write(page, 'export default function Page() { return null }')
748
+ const before = capture()
749
+ write(page, 'export default function Page() { return \"Updated render\" }')
750
+ expect(capture().checksum).toBe(before.checksum)
751
+ write(page, 'export function Page() { return null }')
752
+ expect(changesSince(before).changes).toContainEqual(expect.objectContaining({ category: 'backend-page', kind: 'change' }))
753
+ })
754
+
755
+ it('tracks entity override and legacy schema selection candidates', () => {
756
+ const before = capture()
757
+ write(path.join(pkg, 'db/schema.ts'), 'export class Customer {}')
758
+ write(path.join(app, 'data/entities.override.ts'), 'export class CustomCustomer {}')
759
+ const { changes } = changesSince(before)
760
+ expect(changes.every((change) => change.category === 'entities')).toBe(true)
761
+ expect(planGenerateWatchChanges(changes).groups).toEqual(['entity-ids', 'entities'])
762
+ })
763
+
764
+ it('tracks standalone package-generated entity metadata as an entity input', () => {
765
+ const packageRoot = path.join(root, 'node_modules/pkg')
766
+ const dist = path.join(packageRoot, 'dist/modules/customers')
767
+ fs.mkdirSync(dist, { recursive: true })
768
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
769
+ const before = capture()
770
+ const ids = path.join(packageRoot, 'dist/generated/entities.ids.generated.js')
771
+ write(ids, 'export const E = { customers: { person: \"customers:person\" } }')
772
+ const { changes } = changesSince(before)
773
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'entities', path: ids }))
774
+ expect(planGenerateWatchChanges(changes).groups).toEqual(['entity-ids', 'entities'])
775
+ const usingDist = capture()
776
+ const direct = path.join(packageRoot, 'generated')
777
+ expect([...usingDist.records.values()]).toContainEqual(expect.objectContaining({
778
+ category: 'entities', path: direct, fingerprint: 'missing',
779
+ }))
780
+ fs.mkdirSync(direct)
781
+ const switched = changesSince(usingDist)
782
+ expect(switched.changes).toContainEqual(expect.objectContaining({ category: 'entities', path: direct, kind: 'change' }))
783
+ expect(switched.changes).toContainEqual(expect.objectContaining({ category: 'entities', path: ids, kind: 'delete' }))
784
+ })
785
+
786
+ it('does not broaden API plans when OpenAPI also reports the same route input', () => {
787
+ const route = path.join(pkg, 'api/items/route.ts')
788
+ write(route, 'export const GET = () => null')
789
+ options.openapiInputs = [route]
790
+ const before = capture()
791
+ write(route, 'export const POST = () => null')
792
+ expect(planGenerateWatchChanges(changesSince(before).changes).groups).toEqual(['registry', 'openapi'])
793
+ })
794
+
795
+ it('unions inherited categories and extension identity when seeds share a helper', () => {
796
+ const search = path.join(pkg, 'search.ts')
797
+ const notifications = path.join(pkg, 'notifications.ts')
798
+ const helper = path.join(pkg, 'lib/search-options.ts')
799
+ write(search, 'import { enabled } from "./lib/search-options"; export const searchConfig = { enabled }')
800
+ write(notifications, 'import { enabled } from "./lib/search-options"; export const handlers = enabled ? [] : []')
801
+ write(helper, 'export const enabled = false')
802
+ options.openapiInputs = [search]
803
+ const before = capture()
804
+ write(helper, 'export const enabled = true')
805
+ const changes = changesSince(before).changes
806
+ expect(changes.filter((change) => change.path === helper).map((change) => change.category).sort())
807
+ .toEqual(['extension', 'openapi', 'search'])
808
+ expect(changes).toContainEqual(expect.objectContaining({
809
+ category: 'extension', extensionId: 'registry.notifications', path: helper,
810
+ }))
811
+ const plan = planGenerateWatchChanges(changes)
812
+ expect(plan.mode).toBe('incremental')
813
+ expect(plan.groups).toEqual(['registry', 'openapi'])
814
+ expect(plan.registryOutputs).toEqual(['registry.search', 'registry.notifications'])
815
+ })
816
+
817
+ it('plans OpenAPI helpers and adapter manifests without a full fallback', () => {
818
+ const openapiInput = path.join(root, 'app/src/openapi.ts')
819
+ const openapiHelper = path.join(root, 'app/src/openapi-helper.ts')
820
+ const adapterManifest = path.join(root, 'packages/adapter/package.json')
821
+ write(openapiInput, 'export { schema } from "./openapi-helper"')
822
+ write(openapiHelper, 'export const schema = { version: 1 }')
823
+ write(adapterManifest, '{"name":"adapter","openMercato":{"webResearchAdapter":{"id":"first"}}}')
824
+ options.openapiInputs = [openapiInput]
825
+ options.webResearchAdapterInputs = [adapterManifest]
826
+ const manifestReadSpy = jest.spyOn(fs, 'readFileSync')
827
+ const before = capture()
828
+ expect(manifestReadSpy.mock.calls.some(([file]) => file === adapterManifest)).toBe(false)
829
+ manifestReadSpy.mockRestore()
830
+ write(openapiHelper, 'export const schema = { version: 2 }')
831
+ write(adapterManifest, '{"name":"adapter","openMercato":{"webResearchAdapter":{"id":"second"}}}')
832
+ const changes = changesSince(before).changes
833
+ expect(changes).toEqual(expect.arrayContaining([
834
+ expect.objectContaining({ category: 'openapi', path: openapiHelper }),
835
+ expect.objectContaining({ category: 'web-research-adapters', path: adapterManifest }),
836
+ ]))
837
+ const plan = planGenerateWatchChanges(changes)
838
+ expect(plan.mode).toBe('incremental')
839
+ expect(plan.groups).toEqual(['web-research-adapters', 'openapi'])
840
+ })
841
+
842
+ it('detects supervisor override calls outside module conventions without tracking unrelated component edits', () => {
843
+ const file = path.join(root, 'app/src/components/Setup.tsx')
844
+ write(file, 'export const setup = () => null')
845
+ const before = capture()
846
+ write(file, 'import { applyWorkerOverrides as apply } from \"@open-mercato/shared/modules/overrides\"; apply({})')
847
+ const { changes } = changesSince(before)
848
+ expect(planGenerateWatchChanges(changes).registryOutputs).toEqual(['supervisor'])
849
+ })
850
+
851
+ it('normalizes root property ordering while retaining module order as configuration', () => {
852
+ const before = capture()
853
+ options.moduleRoots = [{ pkgBase: pkg, appBase: app }]
854
+ expect(capture().checksum).toBe(before.checksum)
855
+ const second = { appBase: path.join(root, 'app/src/modules/sales'), pkgBase: path.join(root, 'packages/core/src/modules/sales') }
856
+ options.moduleRoots.push(second)
857
+ const ordered = capture()
858
+ options.moduleRoots.reverse()
859
+ const { changes } = changesSince(ordered)
860
+ expect(planGenerateWatchChanges(changes).mode).toBe('full')
861
+ expect(changes).toEqual(expect.arrayContaining([expect.objectContaining({ category: 'configuration' })]))
862
+ })
863
+
864
+ it('observes compiled page metadata updates independently of source edits', () => {
865
+ const source = path.join(root, 'node_modules/pkg/src/modules/customers')
866
+ const dist = path.join(root, 'node_modules/pkg/dist/modules/customers')
867
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
868
+ write(path.join(source, 'backend/page.tsx'), 'export default function Page() { return null }')
869
+ write(path.join(source, 'backend/page.meta.ts'), 'export const metadata = { label: "First" }')
870
+ write(path.join(dist, 'backend/page.js'), 'export default function Page() { return null }')
871
+ const compiledMeta = path.join(dist, 'backend/page.meta.js')
872
+ write(compiledMeta, 'export const metadata = { label: "First" }')
873
+ let before = capture()
874
+ write(path.join(source, 'backend/page.meta.ts'), 'export const metadata = { label: "Second" }')
875
+ let result = changesSince(before)
876
+ expect(planGenerateWatchChanges(result.changes).registryOutputs).toEqual(['main', 'runtime', 'app', 'backend-routes'])
877
+ before = result.next
878
+ write(compiledMeta, 'export const metadata = { label: "Second" }')
879
+ result = changesSince(before)
880
+ expect(result.changes).toContainEqual(expect.objectContaining({ category: 'backend-page', path: compiledMeta, kind: 'change' }))
881
+ })
882
+
883
+ it('does not interpret read and scan failures as authoritative deletion', () => {
884
+ write(path.join(pkg, 'workers/job.ts'), 'export default () => null')
885
+ const before = capture()
886
+ const readSpy = jest.spyOn(fs, 'readFileSync').mockImplementation(() => { throw new Error('denied') })
887
+ const unreadable = capture()
888
+ readSpy.mockRestore()
889
+ expect(planGenerateWatchChanges(diffGenerateWatchStructureSnapshots(before, unreadable), unreadable.fullReasons).mode).toBe('full')
890
+ expect(unreadable.fullReasons).toEqual(expect.arrayContaining([expect.stringContaining('Cannot read generator input:')]))
891
+ const scanSpy = jest.spyOn(fs, 'readdirSync').mockImplementation(() => { throw new Error('denied') })
892
+ const unscannable = capture()
893
+ scanSpy.mockRestore()
894
+ expect(planGenerateWatchChanges(diffGenerateWatchStructureSnapshots(before, unscannable), unscannable.fullReasons).mode).toBe('full')
895
+ expect(unscannable.fullReasons).toEqual(expect.arrayContaining([expect.stringContaining('Cannot scan generator inputs:')]))
896
+ })
897
+ })