Skip to content

[APPS-2792] Add: dev:verify mode-aware routing for local execution (build-plugins half) - #490

Draft
tyffical wants to merge 1 commit into
tiffany.trinh/apps-2792-runtime-network-guardfrom
tiffany.trinh/apps-2792-dev-verify-cli
Draft

[APPS-2792] Add: dev:verify mode-aware routing for local execution (build-plugins half)#490
tyffical wants to merge 1 commit into
tiffany.trinh/apps-2792-runtime-network-guardfrom
tiffany.trinh/apps-2792-dev-verify-cli

Conversation

@tyffical

@tyffical tyffical commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • Part of APPS-2792 — local Node execution for App Builder backend functions. Milestone 3 in the Kickoff doc, build-plugins half. Stacked on the Sandboxing runtime guard ([APPS-2792] Add: runtime network/subprocess guard for local execution #484), which is itself stacked on Wiring into the dev server ([APPS-2792] Add: wire local execution into the real dev server #481) — needs the dual-endpoint split (/__dd/executeAction local, /__dd/executeActionViaCloud cloud) that [APPS-2792] Add: wire local execution into the real dev server #481 introduced.
  • Today, npm run dev:verify doesn't exist — pre-publish parity checking against the real cloud/Deno round trip requires a manual curl to /__dd/executeActionViaCloud. This PR makes the dev server itself mode-aware so a real dev:verify command (added to the scaffold template in a separate web-ui PR) can route through the same /__dd/executeAction URL the frontend already calls, without the frontend needing to know which mode it's in.
  • Considered and rejected: making the injected client-side transport (dev-server-transport.ts) mode-aware via import.meta.env.MODE. Verified directly against this repo's actual Jest setup (ts-jest, "module": "preserve") that import.meta has no CommonJS equivalent — introducing it breaks ts-jest's transform with SyntaxError: Cannot use 'import.meta' outside a module for any file that imports it, including the existing execute-backend-function.test.ts. Routing server-side, keyed off Vite's own resolved --mode, avoids this entirely and keeps the client transport unchanged.

Architecture

npm run dev              (--mode development, default)     npm run dev:verify        (--mode dev-verify)
         │                                                            │
         └──────────────────────┬─────────────────────────────────────┘
                                 ▼
                  Browser: executeBackendFunction()
                  → devServerTransport → POST /__dd/executeAction
                  (unchanged either way — the client never knows the mode)
                                 │
                                 ▼
                  createDevServerMiddleware's /__dd/executeAction branch
                  checks `mode` (threaded from `server.config.mode`,
                  Vite's own resolved --mode, read in configureServer)
                                 │
                  ┌──────────────┴───────────────┐
                  ▼ mode !== 'dev-verify'          ▼ mode === 'dev-verify'
          handleExecuteAction                handleExecuteActionViaCloud
          (local, in-process,                (bundle + real preview-async
           no bundling — #479/#480/#481)       round trip — unchanged, #481)

/__dd/executeActionViaCloud itself is untouched and still directly reachable — this PR only adds a second way to reach the same cloud behavior, gated by mode, at the URL the client already calls by default.

Changes

What changed File
New DEV_VERIFY_MODE constant ('dev-verify') — the Vite --mode value dev:verify will use. constants.ts
createDevServerMiddleware takes a new optional mode?: string parameter. When req.url === '/__dd/executeAction' and mode === DEV_VERIFY_MODE, delegates to the same cloud-execution logic /__dd/executeActionViaCloud uses (including the existing "auth not configured" 400 guard) instead of running locally. dev-server.ts
configureServer(server) now passes server.config.mode (Vite's own resolved mode, read via the plugin API — no import.meta.env involved) through to createDevServerMiddleware. vite/index.ts
New test: starting the middleware with mode: DEV_VERIFY_MODE and POSTing to /__dd/executeAction hits the real preview-async round trip (via nock) and never calls loadModule — confirming it takes the cloud path, not the local one, for the exact same URL the client always calls. dev-server.test.ts

QA Instructions

yarn install
yarn test:unit packages/plugins/apps/src/vite/dev-server.test.ts
# Expected: Test Suites: 1 passed / Tests: 28 passed ✅ VERIFIED
yarn test:unit packages/plugins/apps
# Expected: Test Suites: 25 passed / Tests: 343 passed ✅ VERIFIED
yarn workspace @dd/apps-plugin run typecheck
# Expected: no output, clean exit ✅ VERIFIED
npx eslint 'packages/plugins/apps/**/*.ts' --quiet
# Expected: no output, clean exit ✅ VERIFIED

Manual QA against a real scaffolded app (invoking vite dev --mode dev-verify directly, ahead of the web-ui half's dev:verify script landing), per the Testing and QA Guide:

npx vite dev --mode dev-verify --port 5185 --strictPort
# VITE v7.3.6  dev-verify  ready in 185 ms ✅ VERIFIED (mode banner confirms it's active)
curl -X POST http://localhost:5185/__dd/executeAction -d '{"functionName":"...example","args":[99]}'
# {"success":true,"result":{"data":{"doubled":198,"tripled":297}}} ✅ VERIFIED

Confirmed it's genuinely routing to the cloud, not local in-process execution: the customer function's own console.log did not print in the local terminal (unlike the same call under default npm run dev, where it does), and the server log shows the real round trip — Bundling backend function...Executing action via cloud...Calling Datadog API: https://api.datad0g.com/api/v2/app-builder/queries/preview-asyncQuery execution started with receipt: ...Long-poll attempt 1/10...Long-poll response, done: true.

Blast Radius

  • No behavior change for npm run dev (default mode) — mode defaults to undefined/'development', which never equals DEV_VERIFY_MODE, so the existing local-execution branch is unchanged.
  • /__dd/executeActionViaCloud is untouched.
  • Risk: low. Purely additive branch in the middleware; no new dependency, no client-side change, no new config surface exposed to customers (the mode comes from Vite's own --mode flag, which the web-ui template's dev:verify script will set — nothing customer-authored).

Out of Scope / Follow-ups

Item Status Next step
web-ui: add the dev:verify script (vite dev --mode dev-verify) and a minimal example backend function to the create-apps template Not started Separate PR, web-ui repo
Update onboarding docs to reference the real dev:verify command Not started After both halves land
Nudge/enforce dev:verify in the publish flow before datadog-apps publish Not started Separate follow-up, likely in the datadog-apps CLI

Documentation

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Friend, this PR adds mode-aware cloud verification routing to the Vite development server.

Changes:

  • Adds the dev-verify mode constant.
  • Routes the standard execution endpoint through cloud execution in verification mode.
  • Adds coverage for the new routing behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
constants.ts Defines the verification mode.
dev-server.ts Implements mode-aware routing.
dev-server.test.ts Tests cloud routing in verification mode.
index.ts Passes Vite’s resolved mode to the middleware.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/plugins/apps/src/vite/dev-server.ts Outdated
Comment thread packages/plugins/apps/src/vite/dev-server.ts Outdated
@chatgpt-codex-connector

This comment was marked as resolved.

@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 063d85e to 8edc949 Compare August 24, 2026 16:53
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 6822e55 to c37ab18 Compare August 24, 2026 16:57
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 8edc949 to c38e390 Compare August 24, 2026 18:47
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch 2 times, most recently from e979af2 to e30cf71 Compare August 24, 2026 19:16
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 2c6aa37 to a048f65 Compare August 24, 2026 19:24
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from e30cf71 to 2626d97 Compare August 24, 2026 19:29
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from a048f65 to 5193ab7 Compare August 24, 2026 20:07
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 2626d97 to 7ec3cae Compare August 24, 2026 20:13
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 5193ab7 to 8d94ddf Compare August 25, 2026 00:24
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 7ec3cae to 44b7d0c Compare August 25, 2026 00:30
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 8d94ddf to 51f9d73 Compare August 25, 2026 01:13
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 44b7d0c to 6f4c565 Compare August 25, 2026 01:17
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 51f9d73 to ceeece1 Compare August 25, 2026 04:41
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 6f4c565 to cb7626e Compare August 25, 2026 15:30
@tyffical
tyffical requested a balanced review from Copilot August 25, 2026 15:45

This comment was marked as resolved.

@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 8d82135 to 737ac66 Compare August 25, 2026 17:23
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from cb7626e to 5196d11 Compare August 25, 2026 18:39
@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Aug 25, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5e15df7 | Docs | View more details | Give us feedback!

@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 6720f6b to 07cca79 Compare August 26, 2026 01:46
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 5196d11 to 5ec8c6e Compare August 26, 2026 01:47
@DataDog DataDog deleted a comment from chatgpt-codex-connector Bot Aug 26, 2026
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch 2 times, most recently from ea84a47 to 4fd59b3 Compare August 26, 2026 02:35
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch 2 times, most recently from dee5a1b to 95dd7ba Compare August 26, 2026 02:38
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 4fd59b3 to cb79658 Compare August 26, 2026 04:32
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 95dd7ba to 9a46a92 Compare August 26, 2026 04:34
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from cb79658 to affa16b Compare August 26, 2026 16:15
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 9a46a92 to bd96b5c Compare August 26, 2026 16:19
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from affa16b to fbad040 Compare August 26, 2026 17:31
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from bd96b5c to af51e6d Compare August 26, 2026 17:32
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from fbad040 to 085afa1 Compare August 26, 2026 18:09
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from af51e6d to 9914c9e Compare August 26, 2026 18:13
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 085afa1 to 64e9169 Compare August 27, 2026 06:05
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 9914c9e to 68a703a Compare August 27, 2026 06:07
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-runtime-network-guard branch from 64e9169 to aff9ee7 Compare August 27, 2026 06:15
… mode

Reads Vite's own --mode value server-side (server.config.mode, not
import.meta.env.MODE, which breaks Jest's ts-jest transform) so
'npm run dev:verify' can exercise the real cloud execution path without the
client-side transport needing to know which mode it's running in.
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2792-dev-verify-cli branch from 68a703a to 5e15df7 Compare August 27, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants