Skip to content

refactor: Relocate external API source conversion functions - #3450

Merged
kodiakhq[bot] merged 2 commits into
mainfrom
drew/move-source-converters
Oct 23, 2026
Merged

kodiakhq[bot] merged 2 commits into
mainfrom
drew/move-source-converters

Conversation

@pulpdrew

Copy link
Copy Markdown
Contributor

Summary

This PR moves some external API source conversion functions into common-utils, so that they can be re-used in non-api contexts. This is a pure refactor, no behavior changes are expected.

@changeset-bot

changeset-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 79b9093

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Oct 23, 2026 1:56pm UTC
hyperdx-storybook Ready Ready Preview Oct 23, 2026 1:56pm UTC

Request Review

@github-actions github-actions Bot added the review/tier-4 Critical — deep review + domain expert sign-off label Oct 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔴 Tier 4 — Critical

Touches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI.

Why this tier:

  • Critical-path files (1) — tenancy, public API, or shipped database config:
    • packages/api/src/routers/external-api/v2/sources.ts
  • Cross-layer change: touches backend (packages/api) + shared utils (packages/common-utils)

Review process: Deep review from a domain expert. Synchronous walkthrough may be required.
SLA: Schedule synchronous review within 2 business days.

Stats
  • Production files changed: 2
  • Production lines changed: 190 (+ 8 in test files, excluded from tier calculation)
  • Critical-path lines changed: 94
  • Branch: drew/move-source-converters
  • Author: pulpdrew

To override this classification, remove the review/tier-4 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

1 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 1 minor

None could be anchored to changed lines; they are listed below.

Findings outside the changed lines

1 minor
  • 🔵 packages/api/src/routers/external-api/__tests__/sources.int.test.ts:675 — Tests for the relocated common-utils helpers stay in the API integration suite, and toExternalSource has no unit test → Move the External API v2 Sources Mapping block into a new packages/common-utils/src/__tests__/externalSource.test.ts and add unit tests for toExternalSource there. It needs cases for the Session timestampValueExpression backfill, the short-form minGranularity/metadataMaterializedViews.granularity mapping, and the stripping of unknown fields. Right now the only test of the new exported entry point goes through the API's Mongo-backed *.int.test.ts. A non-API caller (the stated purpose of this PR) gets no coverage from the package that owns the code.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 114 in total (1.41%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable behavior changes were found.

Summary

Moves external API source conversion helpers into common-utils for reuse outside the API.

  • Source format conversion now lives in common-utils.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into drew/move-sourc..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

Scope: 3 files (packages/common-utils/src/externalSource.ts new, packages/api/src/routers/external-api/v2/sources.ts, sources.int.test.ts) vs base 89ad276.
Intent: Relocate external-API source conversion helpers into common-utils for reuse outside the api package. Behavior-preserving move.

The correctness reviewer confirmed the moved functions are byte-identical to the originals; applyLegacyDefaults was hardened (Record<string,unknown> → unknown with typeof/in guards) but stays behavior-equivalent on the real call path, and the toExternalSource result object preserves the caller's success/error branches including parseResult.error logging. The @hyperdx/common-utils/dist/externalSource import path and src/ placement match existing conventions, and tsup's src/**/*.ts entry emits the module.

✅ No critical issues found.

🟡 P2 -- recommended

  • packages/common-utils/src/externalSource.ts:88 -- The moved conversion logic now lives in common-utils but has no co-located unit test; the metadataMaterializedViews branch of mapGranularitiesToExternalFormat and the applyLegacyDefaults Session default are only reached transitively through the api package's integration test, so an edit here can regress while common-utils' own suite stays green.
    • Fix: Add packages/common-utils/src/__tests__/externalSource.test.ts covering toExternalSource, the metadataMaterializedViews branch, and the Session timestampValueExpression default.
    • testing, maintainability, kieran-typescript
🔵 P3 nitpicks (3)
  • packages/common-utils/src/externalSource.ts:88 -- toExternalSource is now an exported package boundary but relies on an inferred return type for its {success,data}|{success,error} discriminated union.
    • Fix: Add an explicit return-type annotation so an accidental shape change is caught at the definition site rather than flowing silently into the emitted .d.ts.
    • kieran-typescript, maintainability
  • packages/common-utils/src/externalSource.ts:41 -- mapGranularitiesToExternalFormat takes and returns a whole TSource (passing non-materialized-view sources through unchanged), so the name reads narrower than the signature; the prior mapSourceToExternalSource conveyed the input/output shape better.
    • Fix: Consider a name that reflects the source-to-source transform, or leave as-is since it is a private helper.
  • .changeset/ -- changeset-bot flags no changeset for a change touching @hyperdx/api and @hyperdx/common-utils; the behavior-neutral refactor plausibly falls under the "does not warrant a release" carve-out, but common-utils is independently versioned and a reviewer could read the new export as release-relevant.
    • Fix: Dismiss the bot with a one-line reply confirming no behavior change, or add a patch changeset if the relocation is treated as release-relevant.

Reviewers (5): correctness, testing, maintainability, kieran-typescript, project-standards.

Testing gaps: metadataMaterializedViews branch and applyLegacyDefaults Session default are not directly asserted; common-utils has no co-located test for the moved module.

Note: the 2 prior PR comments are automated bot notices (changeset-bot, vercel) with no human review feedback to verify.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 458 passed • 1 skipped • 1701s

Status Count
✅ Passed 458
❌ Failed 0
⚠️ Flaky 1
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@kodiakhq
kodiakhq Bot merged commit 7a656a8 into main Oct 23, 2026
29 checks passed
@kodiakhq
kodiakhq Bot deleted the drew/move-source-converters branch October 23, 2026 14:03

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 79b9093e Deployed Oct 23, 2026 by vercel[bot]
Preview – hyperdx-storybook — 79b9093e Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge review/tier-4 Critical — deep review + domain expert sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants