Skip to content

fix(cli): case-insensitive built-in integration ID filtering - #399

Closed
muunkky wants to merge 2 commits into
deepnote:mainfrom
muunkky:fix/case-insensitive-builtin-integration-ids
Closed

muunkky wants to merge 2 commits into
deepnote:mainfrom
muunkky:fix/case-insensitive-builtin-integration-ids

Conversation

@muunkky

@muunkky muunkky commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Note

Maintainers — CI needs your approval to run. As a first-time contributor from a fork, the GitHub Actions workflows on this PR are held in the action_required state and won't run until a maintainer clicks “Approve and run workflows.” Could someone kick them off when you have a moment? 🙏

In the meantime I reproduced the CI jobs locally against this branch:

  • pnpm lintAndFormat → ✅ pass (Biome + Prettier; only the pre-existing runtime-core console warning, untouched here)
  • pnpm spell-check → ✅ no issues on the changed files
  • pnpm --filter @deepnote/cli test → ✅ 25/25 on the touched suites (constants, collect-integrations, analysis), incl. the regression test for CodeRabbit's catch
  • tsc --noEmit (cli) → ✅ clean

(The unrelated pre-existing diff.test.ts cwd/fixture failure is untouched by this PR.)


Closes #325

The constraint

The CLI decides whether a SQL block's sql_integration_id refers to a built-in engine (no external credentials, never linted as "missing") or an external integration (collected as required, checked by lint). That decision is a case-sensitive set membership test. BUILTIN_INTEGRATIONS holds canonical lowercase IDs (deepnote-dataframe-sql, pandas-dataframe), and two call sites query it with raw Set.has(integrationId):

  • packages/cli/src/integrations/collect-integrations.ts:17
  • packages/cli/src/utils/analysis.ts:522

A notebook is just data, and sql_integration_id is whatever the author typed. A built-in referenced as Pandas-DataFrame or Deepnote-DataFrame-SQL does not match the lowercase set, so it silently falls through the built-in filter and is treated as external. There's no crash — the block is added to the required-integration set (triggering credential fetches it doesn't need), and deepnote lint reports a bogus missing-integration error:

lint: SQL block references integration "Pandas-DataFrame" but no matching env var is configured

The inconsistency is local to this filter: the codebase already normalizes integration IDs to lowercase when matching elsewhere (integrations/fetch-and-merge-integrations.ts). The built-in check predates that convention and was never reconciled with it.

What's now possible

A built-in integration is recognized as built-in regardless of how it was capitalized. isBuiltinIntegration('Pandas-DataFrame'), 'PANDAS-DATAFRAME', and 'pandas-dataframe' all return true; a genuine external ID returns false. A built-in referenced in non-canonical casing is never collected as a required external integration and never flagged as missing by lint. Authors stop having to remember the exact canonical casing to avoid a false lint failure.

Why this design

The minimal patch would be to drop .toLowerCase() at each has() call site. We rejected that because it duplicates the normalization rule across two files, and a third future call site would silently reintroduce the bug — the same drift that caused this issue in the first place. Instead the casing rule lives in one exported predicate, isBuiltinIntegration(), and both call sites route through it, so the built-in check has a single source of truth that call sites cannot diverge from. This mirrors the lowercase-normalization convention already used in fetch-and-merge-integrations.ts, keeping the package internally consistent. The price: one extra function-call indirection over a bare Set.has, and one more symbol exported from constants.ts — cheap relative to a correctness check that two (and growing) call sites depend on.

What it looks like

// packages/cli/src/constants.ts
/** Built-in integrations that don't require external configuration. Canonical IDs are lowercase. */
export const BUILTIN_INTEGRATIONS = new Set(['deepnote-dataframe-sql', 'pandas-dataframe'])

/**
 * Determine whether an integration ID refers to a built-in integration.
 * The comparison is case-insensitive ... single source of truth for the
 * built-in check so call sites cannot drift.
 */
export function isBuiltinIntegration(integrationId: string): boolean {
  return BUILTIN_INTEGRATIONS.has(integrationId.toLowerCase())
}

Both call sites now read through the predicate instead of touching the set directly:

-        if (integrationId && !BUILTIN_INTEGRATIONS.has(integrationId)) {
+        if (integrationId && !isBuiltinIntegration(integrationId)) {
           ids.add(integrationId)
         }
-    if (!integrationId || BUILTIN_INTEGRATIONS.has(integrationId)) {
+    if (!integrationId || isBuiltinIntegration(integrationId)) {
       continue
     }

Note the collection path still adds integrationId (the original string) to the set — only the membership test is normalized, so genuine external IDs keep their original casing in the result.

How we know it works

Developed test-first: the failing test was written and confirmed red before the predicate existed, then went green with the fix. Coverage lands at all three layers:

Test file What it pins
constants.test.ts (new) isBuiltinIntegration returns true for canonical, all-upper, and mixed casing of both built-ins; false for a genuine external ID and for an ID that differs from a built-in only by suffix
collect-integrations.test.ts (new) a mixed-case built-in is not collected; a genuine external ID is collected with its original casing preserved
analysis.test.ts (additions) the missing-integration check does not flag a mixed-case built-in

The capstone case is exercised in collect-integrations.test.ts — a file with one mixed-case built-in block (Deepnote-DataFrame-SQL) and one external block (my-warehouse):

it('capstone: returns exactly the external ID when a mixed-case built-in and an external block coexist', () => {
  const file = makeFileWithSqlBlocks(['Deepnote-DataFrame-SQL', 'my-warehouse'])
  expect(collectRequiredIntegrationIds(file)).toEqual(['my-warehouse'])
})

The built-in is filtered out and exactly my-warehouse is collected / flagged.

Validation

pnpm --filter @deepnote/cli test run — the integration-ID files all pass: constants.test.ts (4), collect-integrations.test.ts (3), analysis.test.ts (17). The wider cli suite has one pre-existing, unrelated failure in src/commands/diff.test.ts (a working-directory / fixture-path issue that calls process.exit(2) independent of this change) — it fails identically on the unmodified base and is not touched by this PR.

Risks and limitations

Behavior-preserving for canonical-cased IDs: any ID already matching the lowercase set continues to match. The change only widens what counts as built-in (to other casings of the same IDs), so the only directional shift is that a block which previously linted as a missing external integration purely because of casing now correctly does not — the intended fix.

Rollback

Pure, side-effect-free predicate change, no migration and no runtime state. Revert the commit to restore prior behavior.

Scope

No .gitban/ or .claude/ files are included — this branch is the six-file code change under packages/cli/ only.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Built-in integrations are now recognized case-insensitively, improving detection accuracy for missing integrations.
    • Added type validation for SQL integration metadata to prevent crashes with non-string values.
  • Tests

    • Added comprehensive test coverage for case-insensitive built-in integration matching and SQL integration ID handling across multiple test suites.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR centralizes case-insensitive built-in integration detection by adding export isBuiltinIntegration (lowercases input and checks BUILTIN_INTEGRATIONS). collectRequiredIntegrationIds and checkMissingIntegrations are updated to use the helper; checkMissingIntegrations also type-guards sql_integration_id to strings. New tests verify mixed-case built-ins are recognized, external IDs are preserved, and non-string metadata does not crash analysis.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Updates Docs ⚠️ Warning PR implements case-insensitive built-in integration filtering but packages/cli/README.md and CHANGELOG were not updated; only inline JSDoc comments document the feature. Update packages/cli/README.md to document the isBuiltinIntegration() function and add/update CHANGELOG entry for this case-insensitivity fix.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely describes the main change: introducing case-insensitive filtering for built-in integration IDs.
Linked Issues check ✅ Passed The PR fully addresses issue #325: adds case-insensitive built-in integration checking via isBuiltinIntegration helper, preserves original casing in results, and includes comprehensive tests.
Out of Scope Changes check ✅ Passed All changes are scoped to case-insensitive built-in integration handling; no extraneous modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli/src/utils/analysis.ts`:
- Around line 519-523: The metadata.sql_integration_id value is not being
type-checked so a non-string truthy value can crash inside isBuiltinIntegration
(which calls .toLowerCase()); update the guard around integrationId (the
variable assigned from block.metadata) to ensure it's a string before calling
isBuiltinIntegration—e.g., check typeof integrationId === 'string' (or coerce
safely) and continue when it's missing or not a string or when
isBuiltinIntegration(integrationId) returns true; adjust the condition that
currently reads using integrationId and isBuiltinIntegration to short-circuit
non-string values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 513ddd31-54d4-4f5d-b0e8-cdfbaa855c16

📥 Commits

Reviewing files that changed from the base of the PR and between d921be7 and 8cec4d3.

📒 Files selected for processing (6)
  • packages/cli/src/constants.test.ts
  • packages/cli/src/constants.ts
  • packages/cli/src/integrations/collect-integrations.test.ts
  • packages/cli/src/integrations/collect-integrations.ts
  • packages/cli/src/utils/analysis.test.ts
  • packages/cli/src/utils/analysis.ts

Comment thread packages/cli/src/utils/analysis.ts Resolved
muunkky added a commit to muunkky/deepnote that referenced this pull request Jun 10, 2026
Card 234rnd (done) — fix shipped as draft PR deepnote#399 (Closes deepnote#325).
Roadmap m1/s4/.../case-insensitive-id-filtering marked done; all five features
of story m1/s4 now complete. Out-of-scope external-ID case-insensitivity
captured as backlog card ca0ios.
@muunkky
muunkky marked this pull request as ready for review June 10, 2026 03:28
@muunkky
muunkky requested a review from a team as a code owner June 10, 2026 03:28
A truthy non-string sql_integration_id in file metadata reached
isBuiltinIntegration() and crashed on .toLowerCase(). Guard the type at
the call site (mirroring the zod parse in collect-integrations.ts) so
malformed metadata is ignored rather than throwing. Adds a regression test.
@muunkky

muunkky commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Self-review (high-effort pass) — findings & resolutions

Ran a multi-angle review of this PR. Summary: the core fix is sound; one real regression was found (by CodeRabbit, now fixed) plus two low-severity notes.

1. 🟠 Crash on non-string sql_integration_id — FIXED (0d7c471)

packages/cli/src/utils/analysis.ts cast metadata.sql_integration_id as string | undefined. A truthy non-string value would reach isBuiltinIntegration() and throw on .toLowerCase() — a crash path this PR introduced (the old Set.has() returned false for non-strings without throwing). Guarded the type at the call site (mirroring the zod parse in collect-integrations.ts) and added a regression test. See the resolved thread above.

2. ℹ️ External-integration ID matching remains case-sensitive — deferred (out of scope)

This PR makes the built-in check case-insensitive (the subject of #325). External-ID collection (collectRequiredIntegrationIds) and the missing-integration check still key on raw casing, so two blocks referencing the same external integration as my-warehouse vs My-Warehouse produce two distinct required/missing entries even though both map to one env var (SQL_MY_WAREHOUSE). This is pre-existing (unchanged by this PR) and is intentionally left out to keep the PR scoped to #325 — happy to follow up separately if you'd like external matching normalized to match the fetch-and-merge-integrations.ts convention.

3. ℹ️ Minor test-fixture duplication — kept as-is

makeFileWithSqlBlocks in collect-integrations.test.ts overlaps with createTestFile in analysis.test.ts. Left as small self-contained per-file fixtures rather than introducing a shared test-helper module (and its build/lint include config) in a tightly-scoped bugfix PR. Easy to consolidate if you'd prefer.

Validation

analysis.test.ts 18/18, constants.test.ts 4/4, collect-integrations.test.ts 3/3; tsc --noEmit clean; biome clean on changed files. (The unrelated pre-existing diff.test.ts cwd/fixture failure is untouched by this PR.)

@muunkky

muunkky commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai resolve

muunkky added a commit to muunkky/deepnote that referenced this pull request Jun 10, 2026
CodeRabbit found a non-string sql_integration_id crash regression; fixed
in code commit 0d7c471 on the PR branch. Two low-sev self-review notes
resolved (external-casing deferred to ca0ios; fixture dup kept).
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved and changes approved.

@muunkky

muunkky commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing this in favor of a single consolidated PR that ships the complete fix (built-in and external case-insensitive integration-ID handling) in one coherent change.

@muunkky muunkky closed this Jun 10, 2026
muunkky added a commit to muunkky/deepnote that referenced this pull request Jul 22, 2026
Adapt the superpowers `contributing` skill (cp'd from ../superpowers) into a
deepnote-specific upstream-contribution method, grounded in a measured baseline
of deepnote/deepnote — not a relabel of obra-specific data.

Key retargets:
- Method kept (never-post-directly gate, socialize-first, clean code-only branch
  off upstream/main, groundedness, credibility ledger); obra threat-catalogue
  voice and empirical case-studies dropped as miscalibrated for deepnote.
- Baseline (CREDIBILITY.md) rebuilt from real gh queries: ~325 merges, ~2%
  external-merge rate, median external merge +7 lines, features close as
  "already in-house / please fork", CodeRabbit reviews every PR, no AI/disclosure
  policy, sign-commits bar. Real footprint logged (deepnote#399/deepnote#400 closed, deepnote#401/deepnote#402
  open, jamesbhobbs engaged deepnote#401).
- Scripts rewritten + shellcheck-clean + selftest 30/30: fork-setup verifies
  deepnote's tracked-board model (not superpowers' invisible-artifact guardrail);
  preflight targets `main`, disclosure optional; check-upstream flags maintainers
  from MAINTAINERS.txt; selftest recalibrated.
- Reconciliation: skill owns METHOD, .claude/CLAUDE.md owns deepnote CONVENTIONS
  (branch names, Discussion #5, showcase spec); each cross-references the other.
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.

Normalize built-in integration ID filtering to be case-insensitive

1 participant