@open-mercato/cli 0.6.7 → 0.6.8-develop.6875.1.871a4afc94
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 +4 -4
- package/build.mjs +24 -7
- package/dist/agentic/claude-code/hooks/entity-migration-check.ts +32 -88
- package/dist/agentic/codex/enforcement-rules.md +2 -16
- package/dist/agentic/cursor/hooks/entity-migration-check.mjs +19 -50
- package/dist/agentic/cursor/rules/entity-guard.mdc +9 -21
- package/dist/agentic/cursor/rules/generated-guard.mdc +3 -5
- package/dist/agentic/cursor/rules/open-mercato.mdc +3 -29
- package/dist/agentic/guides/ai-workflows.md +76 -0
- package/dist/agentic/guides/architecture.md +107 -0
- package/dist/agentic/guides/backend-ui.md +80 -0
- package/dist/agentic/guides/contracts.md +92 -0
- package/dist/agentic/guides/extensions.md +121 -0
- package/dist/agentic/guides/framework-extension-points.md +36 -0
- package/dist/agentic/guides/integrations.md +81 -0
- package/dist/agentic/guides/module-facts.json +115537 -3951
- package/dist/agentic/guides/module-system.md +12 -127
- package/dist/agentic/guides/modules/ai_assistant.md +227 -28
- package/dist/agentic/guides/modules/api_docs.md +58 -2
- package/dist/agentic/guides/modules/api_keys.md +92 -7
- package/dist/agentic/guides/modules/attachments.md +119 -14
- package/dist/agentic/guides/modules/audit_logs.md +131 -10
- package/dist/agentic/guides/modules/auth.md +276 -33
- package/dist/agentic/guides/modules/business_rules.md +149 -14
- package/dist/agentic/guides/modules/catalog.md +475 -43
- package/dist/agentic/guides/modules/channel_gmail.md +82 -3
- package/dist/agentic/guides/modules/channel_imap.md +82 -3
- package/dist/agentic/guides/modules/checkout.md +299 -27
- package/dist/agentic/guides/modules/communication_channels.md +315 -33
- package/dist/agentic/guides/modules/configs.md +104 -8
- package/dist/agentic/guides/modules/content.md +57 -2
- package/dist/agentic/guides/modules/currencies.md +152 -17
- package/dist/agentic/guides/modules/customer_accounts.md +387 -45
- package/dist/agentic/guides/modules/customers.md +746 -85
- package/dist/agentic/guides/modules/dashboards.md +155 -10
- package/dist/agentic/guides/modules/data_sync.md +149 -16
- package/dist/agentic/guides/modules/design_system.md +102 -0
- package/dist/agentic/guides/modules/dictionaries.md +107 -12
- package/dist/agentic/guides/modules/directory.md +148 -15
- package/dist/agentic/guides/modules/entities.md +145 -13
- package/dist/agentic/guides/modules/events.md +59 -2
- package/dist/agentic/guides/modules/feature_toggles.md +119 -9
- package/dist/agentic/guides/modules/gateway_stripe.md +92 -4
- package/dist/agentic/guides/modules/generators.md +45 -2
- package/dist/agentic/guides/modules/inbox_ops.md +207 -27
- package/dist/agentic/guides/modules/integrations.md +146 -16
- package/dist/agentic/guides/modules/messages.md +223 -24
- package/dist/agentic/guides/modules/notifications.md +96 -8
- package/dist/agentic/guides/modules/onboarding.md +77 -6
- package/dist/agentic/guides/modules/payment_gateways.md +164 -21
- package/dist/agentic/guides/modules/perspectives.md +77 -7
- package/dist/agentic/guides/modules/planner.md +136 -18
- package/dist/agentic/guides/modules/portal.md +93 -2
- package/dist/agentic/guides/modules/progress.md +104 -14
- package/dist/agentic/guides/modules/query_index.md +154 -15
- package/dist/agentic/guides/modules/record_locks.md +206 -21
- package/dist/agentic/guides/modules/resources.md +197 -30
- package/dist/agentic/guides/modules/sales.md +678 -84
- package/dist/agentic/guides/modules/scheduler.md +133 -14
- package/dist/agentic/guides/modules/search.md +170 -6
- package/dist/agentic/guides/modules/security.md +294 -35
- package/dist/agentic/guides/modules/shipping_carriers.md +134 -18
- package/dist/agentic/guides/modules/sso.md +151 -26
- package/dist/agentic/guides/modules/staff.md +369 -57
- package/dist/agentic/guides/modules/storage_s3.md +95 -5
- package/dist/agentic/guides/modules/sync_akeneo.md +85 -3
- package/dist/agentic/guides/modules/sync_excel.md +75 -6
- package/dist/agentic/guides/modules/system_status_overlays.md +60 -2
- package/dist/agentic/guides/modules/translations.md +104 -10
- package/dist/agentic/guides/modules/webhooks.md +203 -24
- package/dist/agentic/guides/modules/wms.md +441 -46
- package/dist/agentic/guides/modules/workflows.md +302 -43
- package/dist/agentic/guides/spec-delivery.md +22 -0
- package/dist/agentic/guides/testing-debugging.md +80 -0
- package/dist/agentic/guides/upstream/AGENTS.md +299 -0
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +316 -0
- package/dist/agentic/guides/upstream/manifest.json +8 -0
- package/dist/agentic/shared/AGENTS.md.template +124 -311
- package/dist/agentic/shared/ai/agentic.config.json +2 -0
- package/dist/agentic/shared/ai/harness/README.md +50 -0
- package/dist/agentic/shared/ai/harness/RELEASE.md +57 -0
- package/dist/agentic/shared/ai/harness/cases.json +13680 -0
- package/dist/agentic/shared/ai/harness/cases.schema.json +133 -0
- package/dist/agentic/shared/ai/harness/fixtures/index.json +49 -0
- package/dist/agentic/shared/ai/harness/fixtures/seeds.json +162 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-policy.md +21 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-response.schema.json +96 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-result.schema.json +172 -0
- package/dist/agentic/shared/ai/harness/release-matrix.json +158 -0
- package/dist/agentic/shared/ai/harness/release-result.schema.json +219 -0
- package/dist/agentic/shared/ai/harness/result.schema.json +76 -0
- package/dist/agentic/shared/ai/harness/routing-response.schema.json +12 -0
- package/dist/agentic/shared/ai/harness/target-validation-result.schema.json +73 -0
- package/dist/agentic/shared/ai/harness/validators.json +78 -0
- package/dist/agentic/shared/ai/harness/writable-ast-oracles.mjs +2121 -0
- package/dist/agentic/shared/ai/harness/writable-behavior-oracles.mjs +1096 -0
- package/dist/agentic/shared/ai/lessons/_template.md +16 -0
- package/dist/agentic/shared/ai/lessons.md +26 -3
- package/dist/agentic/shared/ai/review-checklist.md +36 -0
- package/dist/agentic/shared/ai/skills/om-auto-implement-spec/SKILL.md +21 -0
- package/dist/agentic/shared/ai/skills/om-auto-review-pr/SKILL.md +4 -0
- package/dist/agentic/shared/ai/skills/om-auto-upgrade-0.6.6-to-0.6.7/SKILL.md +98 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/SKILL.md +20 -241
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/crud-surfaces.md +16 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/frontend-and-design-system.md +53 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/page-and-navigation.md +13 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/quality-states.md +11 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/SKILL.md +30 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/activity-contracts.md +12 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/durability-and-progress.md +13 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/workflow-design.md +14 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/SKILL.md +28 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/attachments-and-overrides.md +12 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/module-agents-and-tools.md +22 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/orchestrator-agents.md +12 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/surface-selector.md +19 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/SKILL.md +16 -601
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/integrity-and-concurrency.md +19 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/migration-workflow.md +13 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/schema-design.md +14 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/sensitive-data.md +10 -0
- package/dist/agentic/shared/ai/skills/om-eject-and-customize/SKILL.md +14 -310
- package/dist/agentic/shared/ai/skills/om-eject-and-customize/references/decision-and-procedure.md +17 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/SKILL.md +29 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-template.md +100 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-workflow.md +16 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/owner-selection.md +17 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/SKILL.md +25 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/references/resolver-procedure.md +11 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/references/skew-and-escalation.md +13 -0
- package/dist/agentic/shared/ai/skills/om-help/SKILL.md +15 -97
- package/dist/agentic/shared/ai/skills/om-help/references/delivery-workflows.md +18 -0
- package/dist/agentic/shared/ai/skills/om-help/references/task-families.md +20 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/SKILL.md +33 -152
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/phases-and-gates.md +33 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/planning-and-progress.md +40 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/report-templates.md +27 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/spec-resolution.md +24 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/SKILL.md +24 -708
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/package-and-activation.md +16 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/provider-families.md +14 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/security-and-reliability.md +15 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/sync-and-files.md +12 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/SKILL.md +34 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/agents/openai.yaml +4 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/agentic-setup.md +11 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/input-normalization.md +31 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/judge-workflow.md +39 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/report-template.md +43 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/rules.md +11 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/SKILL.md +20 -820
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/api-and-domain.md +19 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/business-one-shot-blueprints.md +172 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/data-and-migrations.md +12 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/discovery-surface-catalog.md +83 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/module-surfaces.md +21 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/planning.md +11 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/runtime-cache-and-queues.md +22 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/verification.md +13 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/SKILL.md +41 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/agentic-setup.md +19 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/bundle-preparation.md +44 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/consent-and-review.md +39 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/publication.md +20 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/report-templates.md +57 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/rules.md +11 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/scripts/prepare-share-bundle.mjs +486 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +19 -843
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +18 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +27 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/read-write-roundtrip.md +13 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +41 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/verification.md +11 -0
- package/dist/agentic/shared/ai/skills/om-trim-unused-modules/SKILL.md +15 -63
- package/dist/agentic/shared/ai/skills/om-trim-unused-modules/references/dependency-and-redirect.md +15 -0
- package/dist/agentic/shared/ai/skills/om-troubleshooter/SKILL.md +16 -467
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnosis-map.md +16 -0
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/regression-oracles.md +14 -0
- package/dist/agentic/shared/ai/skills/tiers.json +143 -21
- package/dist/agentic/shared/ai/skills/tiers.schema.json +52 -40
- package/dist/agentic/shared/ai/specs/README.md +4 -3
- package/dist/agentic/shared/ai/specs/SPEC-000-template.md +226 -10
- package/dist/agentic/shared/ai/trackers/github.md +108 -4
- package/dist/agentic/shared/scripts/agent-harness-tool-server.mjs +187 -0
- package/dist/agentic/shared/scripts/check-lessons.mjs +178 -0
- package/dist/agentic/shared/scripts/evaluate-agent-harness.mjs +2958 -0
- package/dist/agentic/shared/scripts/execution-sandbox.mjs +329 -0
- package/dist/agentic/shared/scripts/framework-context.mjs +888 -0
- package/dist/agentic/shared/scripts/install-skills.mjs +1029 -0
- package/dist/agentic/shared/scripts/install-skills.sh +4 -694
- package/dist/agentic/shared/scripts/prepare-agent-harness-fixture.mjs +222 -0
- package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +1774 -0
- package/dist/bin.js +13 -1
- package/dist/bin.js.map +2 -2
- package/dist/lib/__integration__/TC-INT-008.spec.js +88 -8
- package/dist/lib/__integration__/TC-INT-008.spec.js.map +2 -2
- package/dist/lib/agentic-init.js +13 -3
- package/dist/lib/agentic-init.js.map +2 -2
- package/dist/lib/agentic-setup.js +434 -186
- package/dist/lib/agentic-setup.js.map +2 -2
- package/dist/lib/generators/extensions/injection-widgets.js +20 -0
- package/dist/lib/generators/extensions/injection-widgets.js.map +2 -2
- package/dist/lib/generators/module-extension-facts.js +1840 -0
- package/dist/lib/generators/module-extension-facts.js.map +7 -0
- package/dist/lib/generators/module-fact-sources.js +70 -0
- package/dist/lib/generators/module-fact-sources.js.map +7 -0
- package/dist/lib/generators/module-facts-discovery.js +41 -7
- package/dist/lib/generators/module-facts-discovery.js.map +2 -2
- package/dist/lib/generators/module-facts.js +1387 -45
- package/dist/lib/generators/module-facts.js.map +3 -3
- package/dist/lib/generators/module-override-targets.js +688 -0
- package/dist/lib/generators/module-override-targets.js.map +7 -0
- package/dist/lib/generators/module-registry.js +11 -5
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/load-env.js +24 -0
- package/dist/lib/load-env.js.map +7 -0
- package/dist/lib/resolver.js +2 -0
- package/dist/lib/resolver.js.map +2 -2
- package/dist/lib/telemetry-init.js +358 -0
- package/dist/lib/telemetry-init.js.map +7 -0
- package/dist/lib/testing/integration.js +5 -0
- package/dist/lib/testing/integration.js.map +2 -2
- package/dist/mercato.js +23 -1
- package/dist/mercato.js.map +2 -2
- package/package.json +13 -11
- package/src/bin.ts +33 -1
- package/src/lib/__integration__/TC-INT-008.spec.ts +107 -9
- package/src/lib/__tests__/agentic-init.test.ts +41 -5
- package/src/lib/__tests__/agentic-setup.ownership.test.ts +386 -0
- package/src/lib/__tests__/injection-widget-id-validation.test.ts +184 -0
- package/src/lib/__tests__/load-env.test.ts +65 -0
- package/src/lib/__tests__/telemetry-init.test.ts +298 -0
- package/src/lib/agentic-init.ts +15 -3
- package/src/lib/agentic-setup.ts +573 -222
- package/src/lib/generators/__tests__/activation-adapter-coverage.test.ts +92 -0
- package/src/lib/generators/__tests__/module-extension-activations.test.ts +762 -0
- package/src/lib/generators/__tests__/module-extension-facts.test.ts +404 -0
- package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +88 -2
- package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +1 -0
- package/src/lib/generators/__tests__/module-facts.discovery.test.ts +54 -10
- package/src/lib/generators/__tests__/module-facts.extension-hosts.test.ts +108 -0
- package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +561 -0
- package/src/lib/generators/__tests__/module-facts.source-links.test.ts +119 -0
- package/src/lib/generators/__tests__/module-override-targets.roundtrip.test.ts +149 -0
- package/src/lib/generators/__tests__/module-override-targets.test.ts +304 -0
- package/src/lib/generators/__tests__/module-subset.test.ts +18 -0
- package/src/lib/generators/extensions/injection-widgets.ts +51 -0
- package/src/lib/generators/module-extension-facts.ts +2365 -0
- package/src/lib/generators/module-fact-sources.ts +108 -0
- package/src/lib/generators/module-facts-discovery.ts +58 -7
- package/src/lib/generators/module-facts.ts +1851 -46
- package/src/lib/generators/module-override-targets.ts +863 -0
- package/src/lib/generators/module-registry.ts +16 -6
- package/src/lib/load-env.ts +30 -0
- package/src/lib/resolver.ts +3 -0
- package/src/lib/telemetry-init.ts +461 -0
- package/src/lib/testing/__tests__/integration.test.ts +4 -0
- package/src/lib/testing/integration.ts +5 -0
- package/src/mercato.ts +26 -1
- package/dist/agentic/guides/cache.md +0 -45
- package/dist/agentic/guides/core.md +0 -453
- package/dist/agentic/guides/events.md +0 -117
- package/dist/agentic/guides/queue.md +0 -53
- package/dist/agentic/guides/search.md +0 -115
- package/dist/agentic/guides/shared.md +0 -108
- package/dist/agentic/guides/ui.md +0 -347
- package/dist/agentic/shared/ai/skills/om-auto-continue-pr-loop/SKILL.md +0 -27
- package/dist/agentic/shared/ai/skills/om-auto-create-pr-loop/SKILL.md +0 -27
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/ui-components.md +0 -260
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/mikro-orm-cheatsheet.md +0 -146
- package/dist/agentic/shared/ai/skills/om-help/references/skills-catalog.md +0 -84
- package/dist/agentic/shared/ai/skills/om-help/references/workflow-sequences.md +0 -193
- package/dist/agentic/shared/ai/skills/om-integration-builder/STANDALONE.md +0 -34
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/adapter-contracts.md +0 -762
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/naming-conventions.md +0 -50
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/navigation-patterns.md +0 -97
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-contracts.md +0 -271
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnostic-commands.md +0 -101
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import os from 'node:os'
|
|
4
|
+
import * as ts from 'typescript'
|
|
5
|
+
import { runTelemetryInit } from '../telemetry-init'
|
|
6
|
+
|
|
7
|
+
const TEMPLATE_DIR = path.join(__dirname, '../../../../../packages/create-app/template')
|
|
8
|
+
const TEMPLATE_DISPATCHER = path.join(TEMPLATE_DIR, 'src/app/api/[...slug]/route.ts')
|
|
9
|
+
const TEMPLATE_NEXT_CONFIG = path.join(TEMPLATE_DIR, 'next.config.ts')
|
|
10
|
+
const TEMPLATE_INSTRUMENTATION = path.join(TEMPLATE_DIR, 'src/instrumentation.ts')
|
|
11
|
+
|
|
12
|
+
// The telemetry statements the shipped scaffold wires into the dispatcher — the
|
|
13
|
+
// oracle for "did the command reproduce the real wiring?". Read from the live
|
|
14
|
+
// template so this test fails loudly if the scaffold's wiring changes and the
|
|
15
|
+
// command doesn't keep up.
|
|
16
|
+
const TELEMETRY_DISPATCHER_LINES = [
|
|
17
|
+
"import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'",
|
|
18
|
+
'getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)',
|
|
19
|
+
'getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)',
|
|
20
|
+
'getTelemetryRuntime()?.reportError(error, {',
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
/** Assert a string is syntactically valid TypeScript (parse errors, not types). */
|
|
24
|
+
function assertParses(code: string, label: string): void {
|
|
25
|
+
const sf = ts.createSourceFile(`${label}.ts`, code, ts.ScriptTarget.Latest, true)
|
|
26
|
+
const diagnostics = (sf as unknown as { parseDiagnostics?: ts.Diagnostic[] }).parseDiagnostics ?? []
|
|
27
|
+
const messages = diagnostics.map((d) => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
|
|
28
|
+
expect({ label, messages }).toEqual({ label, messages: [] })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Turn the live wired template dispatcher back into a pre-telemetry one. */
|
|
32
|
+
function stripTelemetry(src: string): string {
|
|
33
|
+
return src
|
|
34
|
+
.replace(/\n[ \t]*getTelemetryRuntime\(\)\?\.reportError\(error, \{[\s\S]*?\n[ \t]*\}\)/, '')
|
|
35
|
+
.split('\n')
|
|
36
|
+
.filter(
|
|
37
|
+
(line) =>
|
|
38
|
+
!line.includes("from '@open-mercato/telemetry'") &&
|
|
39
|
+
!line.includes("from '@open-mercato/telemetry/nextjs'") &&
|
|
40
|
+
!line.includes("from '@open-mercato/shared/lib/telemetry/runtime'") &&
|
|
41
|
+
!line.includes('recordHttpDuration('),
|
|
42
|
+
)
|
|
43
|
+
.join('\n')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const NEXT_CONFIG = `import type { NextConfig } from 'next'
|
|
47
|
+
|
|
48
|
+
const nextConfig: NextConfig = {
|
|
49
|
+
serverExternalPackages: [
|
|
50
|
+
'esbuild',
|
|
51
|
+
],
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default nextConfig
|
|
55
|
+
`
|
|
56
|
+
|
|
57
|
+
function baseFixture(dir: string): void {
|
|
58
|
+
fs.mkdirSync(path.join(dir, 'src', 'app', 'api', '[...slug]'), { recursive: true })
|
|
59
|
+
fs.writeFileSync(path.join(dir, 'src', 'modules.ts'), 'export const enabledModules = []\n')
|
|
60
|
+
fs.writeFileSync(
|
|
61
|
+
path.join(dir, 'package.json'),
|
|
62
|
+
JSON.stringify({ name: 'my-app', dependencies: { '@open-mercato/shared': '1.2.3' } }, null, 2) + '\n',
|
|
63
|
+
)
|
|
64
|
+
fs.writeFileSync(path.join(dir, '.env.example'), 'DATABASE_URL=postgres://localhost/app\n')
|
|
65
|
+
fs.writeFileSync(path.join(dir, 'next.config.ts'), NEXT_CONFIG)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const SIMPLE_DISPATCHER = `import { NextResponse, type NextRequest } from 'next/server'
|
|
69
|
+
import { findApiRouteManifestMatch } from '@open-mercato/shared/modules/registry'
|
|
70
|
+
import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
71
|
+
|
|
72
|
+
async function handleRequest(method: string, req: NextRequest): Promise<Response> {
|
|
73
|
+
const startedAt = Date.now()
|
|
74
|
+
const match = { route: { path: '/api/thing' } }
|
|
75
|
+
try {
|
|
76
|
+
const finalResponse = NextResponse.json({ ok: true })
|
|
77
|
+
return finalResponse
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw error
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`
|
|
83
|
+
|
|
84
|
+
describe('mercato telemetry init', () => {
|
|
85
|
+
let tmpDir: string
|
|
86
|
+
let cwd: string
|
|
87
|
+
let logSpy: jest.SpyInstance
|
|
88
|
+
let errorSpy: jest.SpyInstance
|
|
89
|
+
|
|
90
|
+
beforeEach(() => {
|
|
91
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'telemetry-init-'))
|
|
92
|
+
cwd = process.cwd()
|
|
93
|
+
process.chdir(tmpDir)
|
|
94
|
+
logSpy = jest.spyOn(console, 'log').mockImplementation(() => {})
|
|
95
|
+
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
afterEach(() => {
|
|
99
|
+
process.chdir(cwd)
|
|
100
|
+
logSpy.mockRestore()
|
|
101
|
+
errorSpy.mockRestore()
|
|
102
|
+
fs.rmSync(tmpDir, { recursive: true, force: true })
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const read = (rel: string) => fs.readFileSync(path.join(tmpDir, rel), 'utf8')
|
|
106
|
+
const dispatcherPath = 'src/app/api/[...slug]/route.ts'
|
|
107
|
+
|
|
108
|
+
it('rejects a directory that is not an Open Mercato app', async () => {
|
|
109
|
+
const code = await runTelemetryInit([])
|
|
110
|
+
expect(code).toBe(1)
|
|
111
|
+
expect(errorSpy).toHaveBeenCalled()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('wires all files in a pre-telemetry app', async () => {
|
|
115
|
+
baseFixture(tmpDir)
|
|
116
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
|
|
117
|
+
const code = await runTelemetryInit([])
|
|
118
|
+
expect(code).toBe(0)
|
|
119
|
+
|
|
120
|
+
const pkg = JSON.parse(read('package.json'))
|
|
121
|
+
expect(pkg.dependencies['@open-mercato/telemetry']).toBe('1.2.3')
|
|
122
|
+
expect(pkg.optionalDependencies['bullmq-otel']).toBe('^1.3.1')
|
|
123
|
+
|
|
124
|
+
expect(read('.env.example')).toContain('TELEMETRY_BACKEND')
|
|
125
|
+
expect(read('.env.example')).toContain('OTEL_EXPORTER_OTLP_ENDPOINT')
|
|
126
|
+
expect(read('src/instrumentation.ts')).toContain('registerTelemetryForNextjs')
|
|
127
|
+
|
|
128
|
+
const nextConfig = read('next.config.ts')
|
|
129
|
+
expect(nextConfig).toContain('@open-mercato/telemetry/nextjs-config')
|
|
130
|
+
expect(nextConfig).toContain('...telemetryServerExternalPackages')
|
|
131
|
+
|
|
132
|
+
const route = read(dispatcherPath)
|
|
133
|
+
for (const line of TELEMETRY_DISPATCHER_LINES) expect(route).toContain(line)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('every patched file is syntactically valid TypeScript', async () => {
|
|
137
|
+
baseFixture(tmpDir)
|
|
138
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
|
|
139
|
+
await runTelemetryInit([])
|
|
140
|
+
assertParses(read('next.config.ts'), 'next.config')
|
|
141
|
+
assertParses(read('src/instrumentation.ts'), 'instrumentation')
|
|
142
|
+
assertParses(read(dispatcherPath), 'dispatcher')
|
|
143
|
+
JSON.parse(read('package.json')) // valid JSON
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('reproduces the live template dispatcher wiring (round-trip)', async () => {
|
|
147
|
+
baseFixture(tmpDir)
|
|
148
|
+
const wired = fs.readFileSync(TEMPLATE_DISPATCHER, 'utf8')
|
|
149
|
+
const preTelemetry = stripTelemetry(wired)
|
|
150
|
+
// sanity: the derived pre-telemetry file no longer imports telemetry but still parses
|
|
151
|
+
expect(preTelemetry).not.toContain('@open-mercato/telemetry')
|
|
152
|
+
assertParses(preTelemetry, 'stripped-template')
|
|
153
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), preTelemetry)
|
|
154
|
+
|
|
155
|
+
await runTelemetryInit([])
|
|
156
|
+
|
|
157
|
+
const patched = read(dispatcherPath)
|
|
158
|
+
assertParses(patched, 'patched-template')
|
|
159
|
+
for (const line of TELEMETRY_DISPATCHER_LINES) expect(patched).toContain(line)
|
|
160
|
+
// the success metric lands before the response return, the 500 funnel in the catch
|
|
161
|
+
expect(patched.indexOf('finalResponse.status, startedAt')).toBeLessThan(patched.indexOf('return finalResponse'))
|
|
162
|
+
expect(patched.indexOf('reportError(error, {')).toBeLessThan(patched.indexOf(', 500, startedAt'))
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('is a no-op on the real (already-wired) template files', async () => {
|
|
166
|
+
baseFixture(tmpDir)
|
|
167
|
+
fs.copyFileSync(TEMPLATE_DISPATCHER, path.join(tmpDir, dispatcherPath))
|
|
168
|
+
fs.copyFileSync(TEMPLATE_NEXT_CONFIG, path.join(tmpDir, 'next.config.ts'))
|
|
169
|
+
fs.copyFileSync(TEMPLATE_INSTRUMENTATION, path.join(tmpDir, 'src', 'instrumentation.ts'))
|
|
170
|
+
const before = {
|
|
171
|
+
route: read(dispatcherPath),
|
|
172
|
+
nextConfig: read('next.config.ts'),
|
|
173
|
+
instrumentation: read('src/instrumentation.ts'),
|
|
174
|
+
}
|
|
175
|
+
await runTelemetryInit([])
|
|
176
|
+
expect(read(dispatcherPath)).toBe(before.route)
|
|
177
|
+
expect(read('next.config.ts')).toBe(before.nextConfig)
|
|
178
|
+
expect(read('src/instrumentation.ts')).toBe(before.instrumentation)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
it('patches a recognizable-but-modified dispatcher (extra imports/code, anchors intact)', async () => {
|
|
182
|
+
baseFixture(tmpDir)
|
|
183
|
+
const modified = SIMPLE_DISPATCHER.replace(
|
|
184
|
+
"import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'",
|
|
185
|
+
"import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { auditLog } from '@/lib/audit'",
|
|
186
|
+
).replace('const match = { route: { path: \'/api/thing\' } }', 'const match = { route: { path: \'/api/thing\' } }\n auditLog(method)')
|
|
187
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), modified)
|
|
188
|
+
|
|
189
|
+
await runTelemetryInit([])
|
|
190
|
+
const patched = read(dispatcherPath)
|
|
191
|
+
assertParses(patched, 'modified-dispatcher')
|
|
192
|
+
for (const line of TELEMETRY_DISPATCHER_LINES) expect(patched).toContain(line)
|
|
193
|
+
expect(patched).toContain("import { auditLog } from '@/lib/audit'") // preserved custom code
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('leaves an unrecognizable dispatcher untouched and prints the manual snippet', async () => {
|
|
197
|
+
baseFixture(tmpDir)
|
|
198
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), `export async function GET() { return new Response('custom') }\n`)
|
|
199
|
+
await runTelemetryInit([])
|
|
200
|
+
const route = read(dispatcherPath)
|
|
201
|
+
expect(route).not.toContain('@open-mercato/telemetry')
|
|
202
|
+
expect(route).toBe(`export async function GET() { return new Response('custom') }\n`)
|
|
203
|
+
const printed = logSpy.mock.calls.flat().join('\n')
|
|
204
|
+
expect(printed).toContain('manual step for src/app/api/[...slug]/route.ts')
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
it('handles next.config variations (single-line array, no trailing comma) and stays valid', async () => {
|
|
208
|
+
baseFixture(tmpDir)
|
|
209
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
|
|
210
|
+
fs.writeFileSync(
|
|
211
|
+
path.join(tmpDir, 'next.config.ts'),
|
|
212
|
+
`import type { NextConfig } from 'next'\nconst nextConfig: NextConfig = { serverExternalPackages: ['esbuild'] }\nexport default nextConfig\n`,
|
|
213
|
+
)
|
|
214
|
+
await runTelemetryInit([])
|
|
215
|
+
const nextConfig = read('next.config.ts')
|
|
216
|
+
assertParses(nextConfig, 'single-line-next-config')
|
|
217
|
+
expect(nextConfig).toContain('...telemetryServerExternalPackages')
|
|
218
|
+
expect(nextConfig).toContain('@open-mercato/telemetry/nextjs-config')
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('migrates the legacy nextjs import before adding the missing spread', async () => {
|
|
222
|
+
baseFixture(tmpDir)
|
|
223
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
|
|
224
|
+
fs.writeFileSync(
|
|
225
|
+
path.join(tmpDir, 'next.config.ts'),
|
|
226
|
+
`import type { NextConfig } from 'next'\nimport { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs'\nconst nextConfig: NextConfig = { serverExternalPackages: ['esbuild', 'bullmq'] }\nexport default nextConfig\n`,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
await runTelemetryInit([])
|
|
230
|
+
|
|
231
|
+
const nextConfig = read('next.config.ts')
|
|
232
|
+
assertParses(nextConfig, 'legacy-next-config')
|
|
233
|
+
expect(nextConfig).toContain("from '@open-mercato/telemetry/nextjs-config'")
|
|
234
|
+
expect(nextConfig).not.toContain("from '@open-mercato/telemetry/nextjs'")
|
|
235
|
+
expect(nextConfig).toContain("['esbuild', 'bullmq', ...telemetryServerExternalPackages]")
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('flags next.config as manual when serverExternalPackages is absent', async () => {
|
|
239
|
+
baseFixture(tmpDir)
|
|
240
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
|
|
241
|
+
fs.writeFileSync(
|
|
242
|
+
path.join(tmpDir, 'next.config.ts'),
|
|
243
|
+
`import type { NextConfig } from 'next'\nconst nextConfig: NextConfig = { distDir: '.next' }\nexport default nextConfig\n`,
|
|
244
|
+
)
|
|
245
|
+
await runTelemetryInit([])
|
|
246
|
+
expect(read('next.config.ts')).not.toContain('telemetryServerExternalPackages')
|
|
247
|
+
const printed = logSpy.mock.calls.flat().join('\n')
|
|
248
|
+
expect(printed).toContain('manual step for next.config.ts')
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it('inserts into a pre-existing custom instrumentation.ts and preserves its body', async () => {
|
|
252
|
+
baseFixture(tmpDir)
|
|
253
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
|
|
254
|
+
fs.writeFileSync(
|
|
255
|
+
path.join(tmpDir, 'src', 'instrumentation.ts'),
|
|
256
|
+
`export async function register(): Promise<void> {\n console.log('custom warmup')\n}\n`,
|
|
257
|
+
)
|
|
258
|
+
await runTelemetryInit([])
|
|
259
|
+
const instrumentation = read('src/instrumentation.ts')
|
|
260
|
+
assertParses(instrumentation, 'custom-instrumentation')
|
|
261
|
+
expect(instrumentation).toContain('registerTelemetryForNextjs')
|
|
262
|
+
expect(instrumentation).toContain("console.log('custom warmup')") // preserved
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
it('is idempotent — a second run changes nothing and does not double-insert', async () => {
|
|
266
|
+
baseFixture(tmpDir)
|
|
267
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
|
|
268
|
+
await runTelemetryInit([])
|
|
269
|
+
const after1 = {
|
|
270
|
+
pkg: read('package.json'),
|
|
271
|
+
env: read('.env.example'),
|
|
272
|
+
instrumentation: read('src/instrumentation.ts'),
|
|
273
|
+
nextConfig: read('next.config.ts'),
|
|
274
|
+
route: read(dispatcherPath),
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
await runTelemetryInit([])
|
|
278
|
+
expect(read('package.json')).toBe(after1.pkg)
|
|
279
|
+
expect(read('.env.example')).toBe(after1.env)
|
|
280
|
+
expect(read('src/instrumentation.ts')).toBe(after1.instrumentation)
|
|
281
|
+
expect(read('next.config.ts')).toBe(after1.nextConfig)
|
|
282
|
+
expect(read(dispatcherPath)).toBe(after1.route)
|
|
283
|
+
|
|
284
|
+
const route = read(dispatcherPath)
|
|
285
|
+
expect((read('next.config.ts').match(/@open-mercato\/telemetry\/nextjs-config/g) ?? []).length).toBe(1)
|
|
286
|
+
expect((route.match(/from '@open-mercato\/shared\/lib\/telemetry\/runtime'/g) ?? []).length).toBe(1)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it('dry run writes nothing', async () => {
|
|
290
|
+
baseFixture(tmpDir)
|
|
291
|
+
fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
|
|
292
|
+
const before = read('next.config.ts')
|
|
293
|
+
await runTelemetryInit(['--dry-run'])
|
|
294
|
+
expect(read('next.config.ts')).toBe(before)
|
|
295
|
+
expect(fs.existsSync(path.join(tmpDir, 'src', 'instrumentation.ts'))).toBe(false)
|
|
296
|
+
expect(JSON.parse(read('package.json')).dependencies['@open-mercato/telemetry']).toBeUndefined()
|
|
297
|
+
})
|
|
298
|
+
})
|
package/src/lib/agentic-init.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { createInterface } from 'node:readline'
|
|
|
5
5
|
interface AgenticInitOptions {
|
|
6
6
|
tool?: string
|
|
7
7
|
force?: boolean
|
|
8
|
+
updateHarness?: boolean
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const TOOL_EXISTING_FILES: Record<string, string[]> = {
|
|
@@ -27,6 +28,8 @@ function parseArgs(args: string[]): AgenticInitOptions {
|
|
|
27
28
|
const arg = args[i]
|
|
28
29
|
if (arg === '--force' || arg === '-f') {
|
|
29
30
|
options.force = true
|
|
31
|
+
} else if (arg === '--update-harness') {
|
|
32
|
+
options.updateHarness = true
|
|
30
33
|
} else if (arg.startsWith('--tool=')) {
|
|
31
34
|
options.tool = arg.slice('--tool='.length)
|
|
32
35
|
} else if (arg === '--tool') {
|
|
@@ -59,6 +62,11 @@ export async function runAgenticInit(args: string[]): Promise<number> {
|
|
|
59
62
|
const targetDir = resolve('.')
|
|
60
63
|
const options = parseArgs(args)
|
|
61
64
|
|
|
65
|
+
if (options.force && options.updateHarness) {
|
|
66
|
+
console.error('❌ --force and --update-harness are mutually exclusive')
|
|
67
|
+
return 1
|
|
68
|
+
}
|
|
69
|
+
|
|
62
70
|
// Validate this is an Open Mercato app directory
|
|
63
71
|
if (!existsSync(join(targetDir, 'src', 'modules.ts'))) {
|
|
64
72
|
console.error('❌ Not an Open Mercato app directory (src/modules.ts not found)')
|
|
@@ -66,7 +74,7 @@ export async function runAgenticInit(args: string[]): Promise<number> {
|
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
// Check if agentic files already exist and warn unless --force
|
|
69
|
-
if (!options.force) {
|
|
77
|
+
if (!options.force && !options.updateHarness) {
|
|
70
78
|
const existingFiles = resolveRelevantAgenticFiles(options.tool)
|
|
71
79
|
.filter((relativePath) => existsSync(join(targetDir, relativePath)))
|
|
72
80
|
|
|
@@ -77,7 +85,7 @@ export async function runAgenticInit(args: string[]): Promise<number> {
|
|
|
77
85
|
console.log(` • ${f}`)
|
|
78
86
|
}
|
|
79
87
|
console.log('')
|
|
80
|
-
console.log('Run with --force to
|
|
88
|
+
console.log('Run with --update-harness to preserve local edits, or --force to replace generated files.')
|
|
81
89
|
console.log('')
|
|
82
90
|
return 0
|
|
83
91
|
}
|
|
@@ -92,7 +100,11 @@ export async function runAgenticInit(args: string[]): Promise<number> {
|
|
|
92
100
|
const ask = (q: string) => new Promise<string>((res) => rl.question(q, (a) => res(a.trim())))
|
|
93
101
|
|
|
94
102
|
try {
|
|
95
|
-
await runAgenticSetup(targetDir, ask, {
|
|
103
|
+
await runAgenticSetup(targetDir, ask, {
|
|
104
|
+
tool: options.tool,
|
|
105
|
+
force: options.force,
|
|
106
|
+
updateHarness: options.updateHarness,
|
|
107
|
+
})
|
|
96
108
|
} finally {
|
|
97
109
|
rl.close()
|
|
98
110
|
}
|