@open-mercato/cli 0.11.1-develop.8665.1.2455b2503c → 0.11.1-develop.8687.1.adb16f62b3

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 (157) hide show
  1. package/.turbo/turbo-build.log +4 -2
  2. package/dist/agentic/guides/module-facts.json +1819 -173
  3. package/dist/agentic/guides/module-facts.v2.json +1819 -173
  4. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  5. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  6. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  7. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  8. package/dist/agentic/guides/modules/assisted_selling/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/exact-override-targets.md +1 -1
  29. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  30. package/dist/agentic/guides/modules/communication_channels/workers.md +1 -1
  31. package/dist/agentic/guides/modules/configs/index.md +1 -1
  32. package/dist/agentic/guides/modules/content/index.md +1 -1
  33. package/dist/agentic/guides/modules/currencies/active-extension-bindings.md +11 -0
  34. package/dist/agentic/guides/modules/currencies/di-registrations-rich.md +1 -1
  35. package/dist/agentic/guides/modules/currencies/di-service-tokens.md +1 -1
  36. package/dist/agentic/guides/modules/currencies/exact-override-targets.md +1 -1
  37. package/dist/agentic/guides/modules/currencies/index.md +3 -2
  38. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  39. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  40. package/dist/agentic/guides/modules/customers/index.md +1 -1
  41. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  42. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  43. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  44. package/dist/agentic/guides/modules/devices/index.md +1 -1
  45. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  46. package/dist/agentic/guides/modules/directory/index.md +1 -1
  47. package/dist/agentic/guides/modules/documents/index.md +1 -1
  48. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  49. package/dist/agentic/guides/modules/entities/index.md +1 -1
  50. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  51. package/dist/agentic/guides/modules/events/index.md +1 -1
  52. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  53. package/dist/agentic/guides/modules/forms/index.md +1 -1
  54. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  55. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  56. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  57. package/dist/agentic/guides/modules/generators/index.md +1 -1
  58. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  59. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  60. package/dist/agentic/guides/modules/ledger/acl-features.md +16 -0
  61. package/dist/agentic/guides/modules/ledger/active-extension-bindings.md +11 -0
  62. package/dist/agentic/guides/modules/ledger/backend-pages.md +21 -0
  63. package/dist/agentic/guides/modules/ledger/domain-commands.md +22 -0
  64. package/dist/agentic/guides/modules/ledger/encryption.md +11 -0
  65. package/dist/agentic/guides/modules/ledger/entities.md +17 -0
  66. package/dist/agentic/guides/modules/ledger/events.md +19 -0
  67. package/dist/agentic/guides/modules/ledger/exact-override-targets.md +30 -0
  68. package/dist/agentic/guides/modules/ledger/index.md +22 -0
  69. package/dist/agentic/guides/modules/ledger/owned-contract-module-metadata.md +11 -0
  70. package/dist/agentic/guides/modules/ledger/setup.md +11 -0
  71. package/dist/agentic/guides/modules/ledger/umes-hosts.md +26 -0
  72. package/dist/agentic/guides/modules/messages/index.md +1 -1
  73. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  74. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  75. package/dist/agentic/guides/modules/payment_gateways/active-extension-bindings.md +1 -1
  76. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  77. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  78. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  79. package/dist/agentic/guides/modules/planner/index.md +1 -1
  80. package/dist/agentic/guides/modules/portal/index.md +1 -1
  81. package/dist/agentic/guides/modules/progress/index.md +1 -1
  82. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  83. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  84. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  85. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  86. package/dist/agentic/guides/modules/resources/index.md +1 -1
  87. package/dist/agentic/guides/modules/sales/index.md +1 -1
  88. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  89. package/dist/agentic/guides/modules/search/index.md +1 -1
  90. package/dist/agentic/guides/modules/security/index.md +1 -1
  91. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  92. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  93. package/dist/agentic/guides/modules/sso/index.md +1 -1
  94. package/dist/agentic/guides/modules/staff/index.md +1 -1
  95. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  96. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  97. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  98. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  99. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  100. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  101. package/dist/agentic/guides/modules/translations/index.md +1 -1
  102. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  103. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  104. package/dist/agentic/guides/modules/wms/index.md +1 -1
  105. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  106. package/dist/agentic/guides/reference-module-facts.json +1 -1
  107. package/dist/agentic/guides/upstream/manifest.json +1 -1
  108. package/dist/agentic/shared/AGENTS.md.template +1 -1
  109. package/dist/lib/scaffold/field-dsl.js +393 -0
  110. package/dist/lib/scaffold/field-dsl.js.map +7 -0
  111. package/dist/lib/scaffold/index.js +412 -0
  112. package/dist/lib/scaffold/index.js.map +7 -0
  113. package/dist/lib/scaffold/targets.js +42 -0
  114. package/dist/lib/scaffold/targets.js.map +7 -0
  115. package/dist/lib/scaffold/templates/create-page.js +52 -0
  116. package/dist/lib/scaffold/templates/create-page.js.map +7 -0
  117. package/dist/lib/scaffold/templates/detail-page.js +186 -0
  118. package/dist/lib/scaffold/templates/detail-page.js.map +7 -0
  119. package/dist/lib/scaffold/templates/form-config.js +42 -0
  120. package/dist/lib/scaffold/templates/form-config.js.map +7 -0
  121. package/dist/lib/scaffold/templates/index.js +27 -0
  122. package/dist/lib/scaffold/templates/index.js.map +7 -0
  123. package/dist/lib/scaffold/templates/list-page.js +190 -0
  124. package/dist/lib/scaffold/templates/list-page.js.map +7 -0
  125. package/dist/lib/scaffold/templates/metas.js +47 -0
  126. package/dist/lib/scaffold/templates/metas.js.map +7 -0
  127. package/dist/lib/scaffold/templates/module-files.js +85 -0
  128. package/dist/lib/scaffold/templates/module-files.js.map +7 -0
  129. package/dist/lib/testing/integration-discovery.js +32 -3
  130. package/dist/lib/testing/integration-discovery.js.map +2 -2
  131. package/dist/lib/testing/integration.js +232 -8
  132. package/dist/lib/testing/integration.js.map +2 -2
  133. package/dist/mercato.js +6 -1
  134. package/dist/mercato.js.map +2 -2
  135. package/package.json +7 -7
  136. package/src/lib/__tests__/agentic-workflows-ownership.test.ts +79 -0
  137. package/src/lib/scaffold/__tests__/__snapshots__/scaffold-golden.test.ts.snap +1742 -0
  138. package/src/lib/scaffold/__tests__/helpers.ts +75 -0
  139. package/src/lib/scaffold/__tests__/scaffold-ds-contract.test.ts +248 -0
  140. package/src/lib/scaffold/__tests__/scaffold-golden.test.ts +267 -0
  141. package/src/lib/scaffold/__tests__/scaffold-runtime.test.tsx +193 -0
  142. package/src/lib/scaffold/field-dsl.ts +491 -0
  143. package/src/lib/scaffold/index.ts +531 -0
  144. package/src/lib/scaffold/targets.ts +68 -0
  145. package/src/lib/scaffold/templates/create-page.ts +52 -0
  146. package/src/lib/scaffold/templates/detail-page.ts +190 -0
  147. package/src/lib/scaffold/templates/form-config.ts +42 -0
  148. package/src/lib/scaffold/templates/index.ts +27 -0
  149. package/src/lib/scaffold/templates/list-page.ts +190 -0
  150. package/src/lib/scaffold/templates/metas.ts +48 -0
  151. package/src/lib/scaffold/templates/module-files.ts +87 -0
  152. package/src/lib/testing/__tests__/integration-app-only-playwright.test.ts +225 -0
  153. package/src/lib/testing/__tests__/integration-app-only.test.ts +320 -0
  154. package/src/lib/testing/__tests__/integration-discovery.test.ts +45 -1
  155. package/src/lib/testing/integration-discovery.ts +32 -2
  156. package/src/lib/testing/integration.ts +293 -11
  157. package/src/mercato.ts +7 -1
@@ -2,7 +2,8 @@ import type { ChildProcess, StdioOptions } from 'node:child_process'
2
2
  import { spawnSync } from 'node:child_process'
3
3
  import { createServer } from 'node:net'
4
4
  import { existsSync, readFileSync } from 'node:fs'
5
- import { mkdir, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises'
5
+ import { mkdir, mkdtemp, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises'
6
+ import os from 'node:os'
6
7
  import { createHash, randomBytes } from 'node:crypto'
7
8
  import path from 'node:path'
8
9
  import { createInterface, type Interface } from 'node:readline/promises'
@@ -13,7 +14,13 @@ import { isUnsafeJwtSecret } from '@open-mercato/shared/lib/auth/jwt'
13
14
  import { resolveEnvironment } from '../resolver'
14
15
  import { resolveInitSuperadminCredentials } from '../init-secrets'
15
16
  import { resolveSpawnCommand } from '../spawn'
16
- import { discoverIntegrationSpecFiles as discoverIntegrationSpecFilesShared } from './integration-discovery'
17
+ import {
18
+ APP_ONLY_INTEGRATION_ENV_VAR,
19
+ SKIP_METADATA_FILTERS_INTEGRATION_ENV_VAR,
20
+ DISCOVERY_SELECTION_REPORT_INTEGRATION_ENV_VAR,
21
+ discoverIntegrationSpecFiles as discoverIntegrationSpecFilesShared,
22
+ isAppOwnedIntegrationSpecPath,
23
+ } from './integration-discovery'
17
24
  import { resolveDockerHostFromContext, runCommandAndCapture } from './runtime-utils'
18
25
 
19
26
  type EphemeralRuntimeOptions = {
@@ -47,7 +54,37 @@ type IntegrationOptions = {
47
54
  verbose: boolean
48
55
  forceRebuild: boolean
49
56
  reuseExisting: boolean
50
- }
57
+ appOnly: boolean
58
+ help: boolean
59
+ }
60
+
61
+ type IntegrationSuiteOptions = IntegrationOptions & {
62
+ appOnlySpecPaths: string[] | null
63
+ }
64
+
65
+ export const NO_APP_OWNED_INTEGRATION_SPECS_MESSAGE = 'No app-owned integration specs found'
66
+ export const UNREPORTED_APP_OWNED_INTEGRATION_SPECS_MESSAGE =
67
+ 'the Playwright config does not report its spec files through discoverIntegrationSpecFiles, so app-owned specs are resolved after the environment starts'
68
+ export const NO_RUNNABLE_APP_OWNED_INTEGRATION_SPECS_MESSAGE =
69
+ 'No app-owned integration specs are runnable in the ephemeral environment: every one is skipped by its requiredModules/requiredEnvVars metadata'
70
+
71
+ export const INTEGRATION_TEST_USAGE = [
72
+ 'Usage: mercato test:integration [filter] [options]',
73
+ '',
74
+ 'Boots an ephemeral environment (Postgres, built app) and runs the Playwright integration suite.',
75
+ '',
76
+ 'Options:',
77
+ ' --filter <pattern> Run only specs matching the pattern (also accepted as a bare first argument)',
78
+ ' --app-only Run only app-owned specs (outside node_modules/). Exits 0 without starting',
79
+ ' anything when the app has none',
80
+ ' --keep Leave the app and database running after the suite finishes',
81
+ ' --screenshots Capture screenshots for every test (default outside CI)',
82
+ ' --no-screenshots Capture screenshots only on failure (default in CI)',
83
+ ' --verbose Stream build and server output',
84
+ ' --force-rebuild Rebuild the app even when cached build artifacts are fresh',
85
+ ' --no-reuse-env Always boot a fresh ephemeral environment',
86
+ ' -h, --help Show this help',
87
+ ].join('\n')
51
88
 
52
89
  type EphemeralAppOptions = {
53
90
  verbose: boolean
@@ -2454,6 +2491,8 @@ export function parseOptions(rawArgs: string[]): IntegrationOptions {
2454
2491
  let verbose = false
2455
2492
  let forceRebuild = false
2456
2493
  let reuseExisting = true
2494
+ let appOnly = false
2495
+ let help = false
2457
2496
 
2458
2497
  for (let index = 0; index < rawArgs.length; index += 1) {
2459
2498
  const argument = rawArgs[index]
@@ -2461,6 +2500,14 @@ export function parseOptions(rawArgs: string[]): IntegrationOptions {
2461
2500
  keep = true
2462
2501
  continue
2463
2502
  }
2503
+ if (argument === '--app-only') {
2504
+ appOnly = true
2505
+ continue
2506
+ }
2507
+ if (argument === '--help' || argument === '-h') {
2508
+ help = true
2509
+ continue
2510
+ }
2464
2511
  if (argument === '--screenshots') {
2465
2512
  captureScreenshots = true
2466
2513
  continue
@@ -2515,9 +2562,42 @@ export function parseOptions(rawArgs: string[]): IntegrationOptions {
2515
2562
  verbose,
2516
2563
  forceRebuild,
2517
2564
  reuseExisting,
2565
+ appOnly,
2566
+ help,
2518
2567
  }
2519
2568
  }
2520
2569
 
2570
+ function matchesPlaywrightFileFilter(relativePath: string, filter: string): boolean {
2571
+ let pattern: RegExp
2572
+ try {
2573
+ pattern = new RegExp(filter, 'i')
2574
+ } catch {
2575
+ return relativePath.toLowerCase().includes(filter.toLowerCase())
2576
+ }
2577
+ return pattern.test(relativePath)
2578
+ }
2579
+
2580
+ export function resolveAppOwnedIntegrationSpecPaths(
2581
+ discoveredSpecs: ReadonlyArray<{ path: string }>,
2582
+ filter: string | null,
2583
+ ): string[] {
2584
+ const appOwned = discoveredSpecs
2585
+ .map((entry) => entry.path)
2586
+ .filter((specPath) => isAppOwnedIntegrationSpecPath(specPath))
2587
+ if (!filter) {
2588
+ return appOwned
2589
+ }
2590
+ const matching = appOwned.filter((specPath) => matchesPlaywrightFileFilter(specPath, filter))
2591
+ if (appOwned.length > 0 && matching.length === 0) {
2592
+ throw new Error(`No app-owned integration specs match filter "${filter}"`)
2593
+ }
2594
+ return matching
2595
+ }
2596
+
2597
+ export function buildAppOnlyPlaywrightFileFilters(specPaths: readonly string[]): string[] {
2598
+ return specPaths.map((specPath) => `/${specPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`)
2599
+ }
2600
+
2521
2601
  export function parseEphemeralAppOptions(rawArgs: string[]): EphemeralAppOptions {
2522
2602
  let verbose = false
2523
2603
  let captureScreenshots: boolean | null = null
@@ -2815,6 +2895,166 @@ async function discoverIntegrationSpecFiles(): Promise<DiscoveredIntegrationSpec
2815
2895
  return discoverIntegrationSpecFilesShared(projectRootDirectory, LEGACY_INTEGRATION_TEST_ROOT)
2816
2896
  }
2817
2897
 
2898
+ export type PlaywrightSpecLister = (environment: NodeJS.ProcessEnv, fileFilters: readonly string[]) => Promise<string[]>
2899
+
2900
+ export type PlaywrightConfigSelectionLister = (environment: NodeJS.ProcessEnv) => Promise<string[] | null>
2901
+
2902
+ function isRecord(value: unknown): value is Record<string, unknown> {
2903
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
2904
+ }
2905
+
2906
+ export function parsePlaywrightListedSpecPaths(report: unknown, projectRoot: string): string[] {
2907
+ if (!isRecord(report) || !Array.isArray(report.suites)) {
2908
+ throw new Error('[internal] Playwright --list report has no suites')
2909
+ }
2910
+ const rootDir = isRecord(report.config) && typeof report.config.rootDir === 'string'
2911
+ ? report.config.rootDir
2912
+ : projectRoot
2913
+ const listed = new Set<string>()
2914
+ for (const suite of report.suites) {
2915
+ if (!isRecord(suite) || typeof suite.file !== 'string' || suite.file.length === 0) continue
2916
+ listed.add(normalizePath(path.relative(projectRoot, path.resolve(rootDir, suite.file))))
2917
+ }
2918
+ return Array.from(listed).sort((left, right) => left.localeCompare(right))
2919
+ }
2920
+
2921
+ function runQuietNpxCommand(args: string[], environment: NodeJS.ProcessEnv, cwd: string): Promise<void> {
2922
+ const binary = process.platform === 'win32' ? 'npx.cmd' : 'npx'
2923
+ return new Promise((resolve, reject) => {
2924
+ const resolvedSpawn = resolveSpawnCommand(binary, args)
2925
+ const command = spawn(resolvedSpawn.command, resolvedSpawn.args, {
2926
+ cwd,
2927
+ env: environment,
2928
+ stdio: ['ignore', 'ignore', 'pipe'],
2929
+ ...resolvedSpawn.spawnOptions,
2930
+ })
2931
+ let stderr = ''
2932
+ command.stderr?.on('data', (chunk: Buffer | string) => {
2933
+ stderr += chunk.toString()
2934
+ })
2935
+ command.on('error', reject)
2936
+ command.on('exit', (code) => {
2937
+ if (code === 0) {
2938
+ resolve()
2939
+ return
2940
+ }
2941
+ reject(new Error(`Command failed: npx ${args.join(' ')} (exit ${code ?? 'unknown'})\n${stderr.trim()}`))
2942
+ })
2943
+ })
2944
+ }
2945
+
2946
+ export function parseDiscoverySelectionReport(report: unknown, projectRoot: string): string[] {
2947
+ if (!isRecord(report) || !Array.isArray(report.paths)) {
2948
+ throw new Error('[internal] Integration discovery selection report has no paths')
2949
+ }
2950
+ const reportRoot = typeof report.projectRoot === 'string' ? report.projectRoot : projectRoot
2951
+ const selected = new Set<string>()
2952
+ for (const entry of report.paths) {
2953
+ if (typeof entry !== 'string' || entry.length === 0) continue
2954
+ selected.add(normalizePath(path.relative(projectRoot, path.resolve(reportRoot, entry))))
2955
+ }
2956
+ return Array.from(selected).sort((left, right) => left.localeCompare(right))
2957
+ }
2958
+
2959
+ export type PlaywrightListTarget = {
2960
+ projectRoot: string
2961
+ configPath: string
2962
+ }
2963
+
2964
+ const DEFAULT_PLAYWRIGHT_LIST_TARGET: PlaywrightListTarget = {
2965
+ projectRoot: projectRootDirectory,
2966
+ configPath: PLAYWRIGHT_INTEGRATION_CONFIG_PATH,
2967
+ }
2968
+
2969
+ const PLAYWRIGHT_NO_SPEC_FILE_FILTER = '/__om_app_only_preflight_no_spec__$'
2970
+
2971
+ async function runPlaywrightList<T>(
2972
+ environment: NodeJS.ProcessEnv,
2973
+ fileFilters: readonly string[],
2974
+ target: PlaywrightListTarget,
2975
+ readResult: (files: { listFile: string; selectionFile: string }) => Promise<T>,
2976
+ ): Promise<T> {
2977
+ const outputDirectory = await mkdtemp(path.join(os.tmpdir(), 'om-integration-list-'))
2978
+ const files = {
2979
+ listFile: path.join(outputDirectory, 'list.json'),
2980
+ selectionFile: path.join(outputDirectory, 'selection.json'),
2981
+ }
2982
+ try {
2983
+ await runQuietNpxCommand(
2984
+ ['playwright', 'test', '--config', target.configPath, '--list', '--reporter=json', '--pass-with-no-tests', ...fileFilters],
2985
+ {
2986
+ ...environment,
2987
+ PLAYWRIGHT_JSON_OUTPUT_FILE: files.listFile,
2988
+ [DISCOVERY_SELECTION_REPORT_INTEGRATION_ENV_VAR]: files.selectionFile,
2989
+ },
2990
+ target.projectRoot,
2991
+ )
2992
+ return await readResult(files)
2993
+ } finally {
2994
+ await rm(outputDirectory, { recursive: true, force: true }).catch(() => undefined)
2995
+ }
2996
+ }
2997
+
2998
+ export function listPlaywrightSelectedSpecPaths(
2999
+ environment: NodeJS.ProcessEnv,
3000
+ fileFilters: readonly string[] = [],
3001
+ target: PlaywrightListTarget = DEFAULT_PLAYWRIGHT_LIST_TARGET,
3002
+ ): Promise<string[]> {
3003
+ return runPlaywrightList(environment, fileFilters, target, async ({ listFile }) =>
3004
+ parsePlaywrightListedSpecPaths(JSON.parse(await readFile(listFile, 'utf8')), target.projectRoot),
3005
+ )
3006
+ }
3007
+
3008
+ export function listPlaywrightConfigSelectedSpecPaths(
3009
+ environment: NodeJS.ProcessEnv,
3010
+ target: PlaywrightListTarget = DEFAULT_PLAYWRIGHT_LIST_TARGET,
3011
+ ): Promise<string[] | null> {
3012
+ return runPlaywrightList(environment, [PLAYWRIGHT_NO_SPEC_FILE_FILTER], target, async ({ selectionFile }) =>
3013
+ existsSync(selectionFile)
3014
+ ? parseDiscoverySelectionReport(JSON.parse(await readFile(selectionFile, 'utf8')), target.projectRoot)
3015
+ : null,
3016
+ )
3017
+ }
3018
+
3019
+ function buildAppOnlyEnvironment(environment: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
3020
+ return { ...environment, [APP_ONLY_INTEGRATION_ENV_VAR]: '1' }
3021
+ }
3022
+
3023
+ export async function listAppOwnedIntegrationSpecCandidates(
3024
+ listConfigSelection: PlaywrightConfigSelectionLister = listPlaywrightConfigSelectedSpecPaths,
3025
+ ): Promise<Array<{ path: string }> | null> {
3026
+ const environment = { ...buildAppOnlyEnvironment(process.env), [SKIP_METADATA_FILTERS_INTEGRATION_ENV_VAR]: '1' }
3027
+ const selected = await listConfigSelection(environment)
3028
+ return selected ? selected.map((specPath) => ({ path: specPath })) : null
3029
+ }
3030
+
3031
+ export type AppOnlySuiteRun = {
3032
+ fileFilters: string[]
3033
+ commandEnvironment: NodeJS.ProcessEnv
3034
+ }
3035
+
3036
+ export async function resolveAppOnlySuiteRun(
3037
+ appOnlySpecPaths: readonly string[] | null,
3038
+ environment: Pick<EphemeralEnvironmentHandle, 'commandEnvironment'>,
3039
+ listSpecs: PlaywrightSpecLister = listPlaywrightSelectedSpecPaths,
3040
+ filter: string | null = null,
3041
+ ): Promise<AppOnlySuiteRun | null> {
3042
+ const commandEnvironment = buildAppOnlyEnvironment(environment.commandEnvironment)
3043
+ const fileFilters = appOnlySpecPaths ? buildAppOnlyPlaywrightFileFilters(appOnlySpecPaths) : filter ? [filter] : []
3044
+ const listed = await listSpecs(commandEnvironment, fileFilters)
3045
+ const runnable = new Set(listed)
3046
+ const selected = appOnlySpecPaths
3047
+ ? appOnlySpecPaths.filter((specPath) => runnable.has(specPath))
3048
+ : resolveAppOwnedIntegrationSpecPaths(listed.map((specPath) => ({ path: specPath })), null)
3049
+ if (selected.length === 0) {
3050
+ if (!appOnlySpecPaths && filter) {
3051
+ throw new Error(`No app-owned integration specs match filter "${filter}"`)
3052
+ }
3053
+ return null
3054
+ }
3055
+ return { fileFilters: buildAppOnlyPlaywrightFileFilters(selected), commandEnvironment }
3056
+ }
3057
+
2818
3058
  async function extractSpecDescription(relativePath: string): Promise<string> {
2819
3059
  const absolutePath = path.join(projectRootDirectory, relativePath)
2820
3060
  try {
@@ -3365,13 +3605,27 @@ type IntegrationTestRunResult = {
3365
3605
 
3366
3606
  async function runIntegrationTestSuiteOnce(
3367
3607
  environment: EphemeralEnvironmentHandle,
3368
- options: IntegrationOptions,
3608
+ options: IntegrationSuiteOptions,
3369
3609
  ): Promise<void> {
3370
3610
  const testArgs = ['test:integration']
3371
- if (options.filter) {
3611
+ let commandEnvironment = environment.commandEnvironment
3612
+ if (options.appOnly) {
3613
+ const appOnlyRun = await resolveAppOnlySuiteRun(
3614
+ options.appOnlySpecPaths,
3615
+ environment,
3616
+ listPlaywrightSelectedSpecPaths,
3617
+ options.filter,
3618
+ )
3619
+ if (!appOnlyRun) {
3620
+ console.log(`[integration] ${NO_RUNNABLE_APP_OWNED_INTEGRATION_SPECS_MESSAGE}.`)
3621
+ return
3622
+ }
3623
+ testArgs.push(...appOnlyRun.fileFilters)
3624
+ commandEnvironment = appOnlyRun.commandEnvironment
3625
+ } else if (options.filter) {
3372
3626
  testArgs.push(options.filter)
3373
3627
  }
3374
- await runYarnCommandWithOutputMonitoring(testArgs, environment.commandEnvironment, {
3628
+ await runYarnCommandWithOutputMonitoring(testArgs, commandEnvironment, {
3375
3629
  detectEnvironmentUnavailable: true,
3376
3630
  abortOnEnvironmentUnavailable: true,
3377
3631
  playwrightFailureHealthCheck: {
@@ -3398,7 +3652,7 @@ function normalizeError(error: unknown): Error {
3398
3652
 
3399
3653
  async function runIntegrationTestAttempt(
3400
3654
  environment: EphemeralEnvironmentHandle,
3401
- integrationOptions: IntegrationOptions,
3655
+ integrationOptions: IntegrationSuiteOptions,
3402
3656
  prepareTestEnvironment: (environment: EphemeralEnvironmentHandle) => Promise<void>,
3403
3657
  ): Promise<Error | null> {
3404
3658
  try {
@@ -3426,7 +3680,7 @@ async function detectEnvironmentFailure(
3426
3680
 
3427
3681
  async function runIntegrationTestSuiteWithRecovery(
3428
3682
  startOptions: Pick<EphemeralRuntimeOptions, 'verbose' | 'captureScreenshots' | 'forceRebuild' | 'reuseExisting'>,
3429
- integrationOptions: IntegrationOptions,
3683
+ integrationOptions: IntegrationSuiteOptions,
3430
3684
  prepareTestEnvironment: (environment: EphemeralEnvironmentHandle) => Promise<void>,
3431
3685
  ): Promise<{
3432
3686
  environment: EphemeralEnvironmentHandle
@@ -3905,8 +4159,36 @@ async function keepEnvironmentRunningForever(): Promise<void> {
3905
4159
  await new Promise<void>(() => {})
3906
4160
  }
3907
4161
 
3908
- export async function runIntegrationTestsInEphemeralEnvironment(rawArgs: string[]): Promise<void> {
4162
+ export type IntegrationTestRunDependencies = {
4163
+ discoverSpecs?: () => Promise<ReadonlyArray<{ path: string }> | null>
4164
+ runSuiteWithRecovery?: typeof runIntegrationTestSuiteWithRecovery
4165
+ }
4166
+
4167
+ export async function runIntegrationTestsInEphemeralEnvironment(
4168
+ rawArgs: string[],
4169
+ dependencies: IntegrationTestRunDependencies = {},
4170
+ ): Promise<void> {
3909
4171
  const options = parseOptions(rawArgs)
4172
+ if (options.help) {
4173
+ console.log(INTEGRATION_TEST_USAGE)
4174
+ return
4175
+ }
4176
+ let appOnlySpecPaths: string[] | null = null
4177
+ if (options.appOnly) {
4178
+ const discoverSpecs = dependencies.discoverSpecs ?? (() => listAppOwnedIntegrationSpecCandidates())
4179
+ const candidates = await discoverSpecs()
4180
+ if (candidates) {
4181
+ appOnlySpecPaths = resolveAppOwnedIntegrationSpecPaths(candidates, options.filter)
4182
+ if (appOnlySpecPaths.length === 0) {
4183
+ console.log(NO_APP_OWNED_INTEGRATION_SPECS_MESSAGE)
4184
+ return
4185
+ }
4186
+ console.log(`[integration] --app-only enabled: running ${appOnlySpecPaths.length} app-owned spec file(s).`)
4187
+ } else {
4188
+ console.log(`[integration] --app-only enabled: ${UNREPORTED_APP_OWNED_INTEGRATION_SPECS_MESSAGE}.`)
4189
+ }
4190
+ }
4191
+ const runSuiteWithRecovery = dependencies.runSuiteWithRecovery ?? runIntegrationTestSuiteWithRecovery
3910
4192
  const startOptions: Pick<EphemeralRuntimeOptions, 'verbose' | 'captureScreenshots' | 'forceRebuild' | 'reuseExisting'> = {
3911
4193
  verbose: options.verbose,
3912
4194
  captureScreenshots: options.captureScreenshots,
@@ -3923,9 +4205,9 @@ export async function runIntegrationTestsInEphemeralEnvironment(rawArgs: string[
3923
4205
  } else {
3924
4206
  console.log('[integration] --no-reuse-env enabled: always booting a fresh ephemeral environment.')
3925
4207
  }
3926
- const environmentState = await runIntegrationTestSuiteWithRecovery(
4208
+ const environmentState = await runSuiteWithRecovery(
3927
4209
  startOptions,
3928
- options,
4210
+ { ...options, appOnlySpecPaths },
3929
4211
  async (runtimeEnvironment) => {
3930
4212
  console.log('[integration] Ensuring Playwright Chromium is installed...')
3931
4213
  await runNpxCommand(['playwright', 'install', 'chromium'], runtimeEnvironment.commandEnvironment)
package/src/mercato.ts CHANGED
@@ -1571,12 +1571,13 @@ export async function run(argv = process.argv) {
1571
1571
  const commandArgs = remaining.filter(Boolean)
1572
1572
 
1573
1573
  if (!subcommand || subcommand === 'help' || subcommand === '--help' || subcommand === '-h') {
1574
- console.log('Usage: yarn mercato module <add|enable|eject|search|info> ...')
1574
+ console.log('Usage: yarn mercato module <add|enable|eject|search|info|scaffold> ...')
1575
1575
  console.log(' yarn mercato module add <packageSpec> [--module <moduleId>] [--eject] [--allow-third-party]')
1576
1576
  console.log(' yarn mercato module enable <packageName> [--module <moduleId>] [--eject] [--allow-third-party]')
1577
1577
  console.log(' yarn mercato module eject <moduleId>')
1578
1578
  console.log(' yarn mercato module search [<query>] [--category <id>] [--kind <kind>] [--all-lines] [--limit <n>] [--json]')
1579
1579
  console.log(' yarn mercato module info <package-or-module-id> [--json]')
1580
+ console.log(' yarn mercato module scaffold <moduleId> --entity <entity> --fields "<fields>" [--with-ui] [--target app|packages/core] [--features-prefix <prefix>] [--dry-run]')
1580
1581
  return 0
1581
1582
  }
1582
1583
 
@@ -1621,6 +1622,11 @@ export async function run(argv = process.argv) {
1621
1622
  return handleDirectEjectCommand(commandArgs)
1622
1623
  }
1623
1624
 
1625
+ if (subcommand === 'scaffold') {
1626
+ const { runModuleScaffold } = await import('./lib/scaffold')
1627
+ return await runModuleScaffold(commandArgs)
1628
+ }
1629
+
1624
1630
  console.error(`Unknown module subcommand "${subcommand}".`)
1625
1631
  return 1
1626
1632
  } catch (error: unknown) {