Skip to content

fix(connector): test verb fetches config via GetConnector before probing#19

Merged
bradfair merged 3 commits into
mainfrom
fix/connector-test-fetch-config
Apr 22, 2026
Merged

fix(connector): test verb fetches config via GetConnector before probing#19
bradfair merged 3 commits into
mainfrom
fix/connector-test-fetch-config

Conversation

@bradfair

@bradfair bradfair commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • ana connector test <id> previously sent {connectorId: <int>} which the server rejected (invalid value for string field connectorId and, after stringifying, config is required). The TestConnector RPC validates a full {config: {...}} body — it's a pre-create probe, not a test-by-id op.
  • The verb now does GetConnector first, rebuilds the config from the returned <dialect>Metadata block, and posts that to TestConnector. The CLI surface stays id-only.
  • GetConnector redacts secrets, so the dialect block gets password: "redacted" so config validation passes; the driver returns its real auth/dial error via the standard {error: ...} shape and the CLI surfaces it as FAIL: <msg> (unchanged contract).

Validation

Test plan

  • make lint
  • make cover (100.0%)
  • Live go test -v ./e2e/ -run TestConnectorTest$ against the demo org → PASS

Summary by CodeRabbit

  • Bug Fixes

    • connector test now retrieves full connector metadata before testing, improving validation and ensuring complete configuration is used.
    • Improved error handling for missing connector details and failed follow-up retrievals; errors are now clearer and wrapped.
    • Missing credentials are handled by inserting a safe placeholder during test construction.
  • Tests

    • Added tests covering retrieval failures, absent connector objects, missing connector types, and related error scenarios.

Server's TestConnector RPC validates a full `{config: {...}}` body — it's
a pre-create probe, not a test-existing op. The previous CLI sent a bare
`{connectorId}` which the server rejected with `config is required`
(typed-error 400) and, before that, with a string-vs-int field-type
mismatch on `connectorId`.

Behavior change:

- `ana connector test <id>` now does GetConnector → builds a config from
  the returned `<dialect>Metadata` block → posts to TestConnector. The
  CLI surface (id-only positional) is unchanged.
- `<dialect>Metadata` blocks omit secrets; we fill `password: "redacted"`
  so the dialect-specific config validates. The driver returns its
  auth/dial error via the standard `200 {error: ...}` shape, which the
  CLI surfaces as `FAIL: <msg>` — the same contract as before.

Coverage gate stays at 100% on `./internal/...`. The previous CATALOG
DEVIATION docstring is replaced with a CATALOG REALITY block describing
why the verb is forced through Get + Test.
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e485c14a-16e6-4698-b0d2-653499ffac0d

📥 Commits

Reviewing files that changed from the base of the PR and between 33d8c5e and 1d8c181.

📒 Files selected for processing (1)
  • internal/connector/test.go

📝 Walkthrough

Walkthrough

The connector test flow now calls GetConnector, builds a full connector config from the returned connector (converting each <dialect>Metadata into a <dialect> config and inserting password: "redacted" when missing), and then calls TestConnector with that config; errors are wrapped with connector test:.

Changes

Cohort / File(s) Summary
Test Command Logic
internal/connector/test.go
Reworked ana connector test to call GetConnector first, derive a full config map (shallow-copying <dialect>Metadata into <dialect> keys and injecting password: "redacted" if absent) via configFromGetConnector, change request payload from {ConnectorID int} to {Config map[string]any}, and wrap GetConnector/config errors as connector test: %w before calling TestConnector.
Test Coverage & Fakes
internal/connector/test_test.go
Added stubGetConnector helper and updated test fakes to route by RPC path (detecting .../GetConnector); added negative tests for unary call failure, missing connectorType, and missing connector object; adjusted remarshal-error test to stub GetConnector while keeping invalid subsequent-call payloads.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI Command
    participant GetConn as GetConnector RPC
    participant Extract as ConfigExtractor
    participant TestConn as TestConnector RPC

    CLI->>GetConn: GetConnector(connectorId)
    GetConn-->>CLI: ConnectorResponse (with <dialect>Metadata)
    CLI->>Extract: configFromGetConnector(response)
    Extract-->>CLI: Derived Config Map (dialect keys, ensure password:"redacted")
    CLI->>TestConn: TestConnector(config)
    TestConn-->>CLI: Test Result / Error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped to GetConnector, nibbling Metadata crumbs,

I trimmed the tails, stitched configs with hums,
If a secret was missing, "redacted" I wrote,
Then I leapt to TestConnector and cast my small vote,
A quick carrot dance for a tidy config stub.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(connector): test verb fetches config via GetConnector before probing' directly and clearly summarizes the main change: the test verb now fetches config via GetConnector before probing TestConnector.
Description check ✅ Passed The PR description comprehensively covers the summary, rationale, validation approach, and test plan. It explains the problem (TestConnector expects full config, not just id), the solution (fetch via GetConnector first), and validation results. The description follows the template's spirit with clear summary and validation sections, though the author used a custom format rather than strict template checkboxes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/connector-test-fetch-config

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/connector/test.go`:
- Around line 100-104: The code mutates the caller's map by writing "redacted"
into block inside the loop; to avoid surprising in-place mutation, clone the
block (a copy of the map derived from getRaw/raw) before modifying it in
configFromGetConnector so you write into the copy rather than the original;
locate the manipulation of variable block in configFromGetConnector (called
after getRaw) and create a shallow map copy, then perform the secret insertion
on that copy and use the copy for downstream logic.
🪄 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: 74db3685-03e6-4a76-b9b8-9e0692d7eac1

📥 Commits

Reviewing files that changed from the base of the PR and between c0f6494 and 2d1b9e8.

📒 Files selected for processing (2)
  • internal/connector/test.go
  • internal/connector/test_test.go

Avoid in-place mutation of the caller's map when inserting the
'redacted' password placeholder. The function is currently called
once with a fresh map, but defending against future reuse keeps
the helper a pure function.

Addresses CodeRabbit nit on PR #19.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/connector/test.go`:
- Around line 105-109: The redaction loop currently only injects a placeholder
for the "password" key (the slice literal in the for loop that iterates over
[]string{"password"} and writes to the out map), which misses other
dialect-specific secret fields; either expand that slice to include additional
known secret keys (e.g., "privateKey", "clientSecret", etc.) so test redaction
covers other connectors, or add a clear inline comment next to the for loop
explaining this limitation and that new dialects must extend the slice when
added; update the loop that writes out[secret] = "redacted" (and any tests
relying on it) accordingly.
🪄 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: 4f530511-e24a-4b7a-be6d-78b46e508e76

📥 Commits

Reviewing files that changed from the base of the PR and between 2d1b9e8 and 33d8c5e.

📒 Files selected for processing (1)
  • internal/connector/test.go

Comment thread internal/connector/test.go
Only "password" is placeholdered today. Postgres uses it; Snowflake's
non-password auth modes (keypair, oauth-sso, oauth-individual) use
privateKey / oauthClientSecret. Document that so a reader extending the
dialect matrix knows to update the slice.

Addresses PR #19 review nit.
@bradfair bradfair added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit e9f3616 Apr 22, 2026
10 checks passed
@bradfair bradfair deleted the fix/connector-test-fetch-config branch April 22, 2026 15:40
@hpt-bot hpt-bot Bot mentioned this pull request Apr 21, 2026
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.

1 participant