Skip to content

[APPS] Refactor backend discovery AST parsing#345

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit intomasterfrom
sdkennedy2/refactor-discovery-ast-parsing
May 7, 2026
Merged

[APPS] Refactor backend discovery AST parsing#345
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit intomasterfrom
sdkennedy2/refactor-discovery-ast-parsing

Conversation

@sdkennedy2
Copy link
Copy Markdown
Collaborator

@sdkennedy2 sdkennedy2 commented May 7, 2026

Motivation

This is the first PR in the regenerated backend connection ID analysis stack. The existing backend discovery module mixes the core BackendFunction data model, ESTree/Rollup AST type narrowing, export discovery, and callable export validation in one file. Splitting those concerns first gives the later connection ID extraction PRs a stable AST parsing home and keeps their reviews focused on behavior changes instead of file movement.

Related planning context: plan 014, created after build-plugins#338 established the backend manifest upload plumbing.

Changes

This PR is intended to be behavior-neutral. It moves the core backend function datatype into backend/types.ts and moves the existing AST export discovery implementation into backend/ast-parsing/extract-backend-functions.ts.

The old backend/discovery.ts barrel was removed in response to review feedback. Existing callers now import from the owning modules directly: core backend types from backend/types.ts, and AST discovery helpers from backend/ast-parsing/*.

enumerateBackendExports(ast, filePath) now returns a stricter discriminated union instead of optional metadata fields:

type BackendExport = BackendLocalExport | BackendReExport;

interface BackendLocalExport {
    kind: 'local';
    name: string;
    localName: string;
}

interface BackendReExport {
    kind: 're-export';
    name: string;
    localName: string;
    source: string;
}

extractExportedFunctions(ast, filePath) continues to return the same string array as before. Existing validation semantics for unsupported backend export shapes are preserved.

QA Instructions

Focused tests:

NODE_OPTIONS=--experimental-vm-modules ~/.yarn/switch/bin/yarn workspace @dd/tests jest --config jest.config.ts ../plugins/apps/src/backend/discovery.test.ts --runInBand
~/.yarn/switch/bin/yarn workspace @dd/apps-plugin typecheck
~/.yarn/switch/bin/yarn lint
~/.yarn/switch/bin/yarn workspace @dd/tests test:e2e src/e2e/appsPlugin/appsPlugin.spec.ts

Manual linked-app verification against /Users/scott.kennedy/dd/test-action-catalog-app/:

~/.yarn/switch/bin/yarn cli prepare-link
~/.yarn/switch/bin/yarn workspace @datadog/vite-plugin build
DATADOG_API_KEY=fake DATADOG_APP_KEY=fake npm run build
DATADOG_API_KEY=fake DATADOG_APP_KEY=fake npx vite --host 127.0.0.1 --port 5178

The linked test app discovered and proxied all three imported backend functions, built all three backend bundles, produced the dry-run archive, and served generated backend proxy code in dev mode. prepare-link --revert was run afterward.

Blast Radius

This PR affects High Code Apps backend function discovery in @dd/apps-plugin. It should not change runtime behavior, manifest shape, dev preview payloads, backend proxy generation, or backend bundling. The main risk is an accidental import/export wiring regression from the module split, covered by the focused tests and apps-plugin E2E suite.

Documentation

Copy link
Copy Markdown
Collaborator Author

sdkennedy2 commented May 7, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sdkennedy2 sdkennedy2 changed the title Refactor backend discovery AST parsing [APPS][WIP] Refactor backend discovery AST parsing May 7, 2026
@sdkennedy2
Copy link
Copy Markdown
Collaborator Author

@codex review
@cursor review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sdkennedy2 sdkennedy2 changed the title [APPS][WIP] Refactor backend discovery AST parsing [APPS] Refactor backend discovery AST parsing May 7, 2026
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/refactor-discovery-ast-parsing branch from e3d487d to 8a9e82f Compare May 7, 2026 14:37
@sdkennedy2 sdkennedy2 marked this pull request as ready for review May 7, 2026 14:41
@sdkennedy2 sdkennedy2 requested review from a team and yoannmoinet as code owners May 7, 2026 14:41
Copy link
Copy Markdown
Member

@yoannmoinet yoannmoinet left a comment

Choose a reason for hiding this comment

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

Just some nit, not blocking for them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Not a fan of barrel files in general, unless there is a very good reason for it. In this occurrence, the reason isn't particularly good IMO.
This usually leads to confusion, misdirection and build complexity.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking it could reduce the number of changes in the initial PR. My plan was to remove the reference in the next PR but you're right the total number of references to this file are now very small. I'll remove this file 👍

Comment on lines +7 to +8
localName?: string;
source?: string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Using optionals is often revealing some smells 😃
Can't we have this stricter?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Backend functions are either defined within the *.backend.ts or they are imported then exported. I could probably break this down into a discriminated type union for the two cases.

@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/refactor-discovery-ast-parsing branch from 8a9e82f to e869c8d Compare May 7, 2026 17:58
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit e22d3bc into master May 7, 2026
6 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the sdkennedy2/refactor-discovery-ast-parsing branch May 7, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants