Skip to content

Add project data source - #13

Merged
IlyaasK merged 1 commit into
browser-pool-importfrom
project-data-source
Jul 2, 2026
Merged

Add project data source#13
IlyaasK merged 1 commit into
browser-pool-importfrom
project-data-source

Conversation

@IlyaasK

@IlyaasK IlyaasK commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • Add the read-only kernel_project data source.
  • Register kernel_project with the provider.
  • Add a narrow durable kernelclient.ListProjectPage wrapper for org-scoped project list pagination.
  • Keep Terraform exact-name, zero-match, and ambiguous-match policy inside internal/datasources/project.
  • Validate required project response fields before writing Terraform state.

Intentionally unsupported

  • No kernel_profile, kernel_proxy, or kernel_extension data sources in this PR.
  • No browser/session runtime operations: acquire, release, flush, logs, screenshots, live view, recovery, or force-release.
  • No resource mutation behavior in the project data source.

Tests run

  • GOCACHE=/private/tmp/terraform-provider-kernel-go-cache go test ./internal/datasources/project ./internal/kernelclient ./internal/provider
  • GOCACHE=/private/tmp/terraform-provider-kernel-go-cache go test ./...
  • GOCACHE=/private/tmp/terraform-provider-kernel-go-cache go vet ./...
  • git diff --check browser-pool-import..HEAD

Review gates

All five review gates passed after fixes:

  • deslop
  • autoreview
  • thermo-nuclear-code-quality-review
  • dave-cheney-go-review
  • eblog-code-review

Note

Low Risk
Read-only Terraform data source and org-scoped list pagination; no resource mutations or auth changes.

Overview
Adds the read-only kernel_project data source so Terraform can look up project metadata by id, exact name, or the provider’s default project_id.

Name lookup paginates through org project lists via a new ListProjectPage client wrapper that reads X-Next-Offset and rejects non-advancing pagination. The data source enforces mutual exclusion of id/name, zero/ambiguous exact-name matches, and validates required API fields (via SDK JSON metadata) before writing state.

The provider registers kernel_project as its first data source; unit tests cover the data source, client pagination, and provider registration.

Reviewed by Cursor Bugbot for commit 7c0b29f. Bugbot is set up for automated code reviews on this repo. Configure here.

@firetiger-agent

Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

PRs in the kernel, infra, hypeman, and hypeship repos. kernel is a ~mono repo with many logical services underneath, ensure to focus on the implicated service for the PR

Reason: PR repository cannot be determined from provided information; please specify which repo (kernel, infra, hypeman, or hypeship) this PR is in, or manually opt in to deploy monitoring.

To monitor this PR anyway, reply with @firetiger monitor this.

Comment thread internal/datasources/project/datasource.go
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from f315485 to 1087b8a Compare June 10, 2026 20:13
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 7f11cd1 to 87e666f Compare June 10, 2026 20:13
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from 1087b8a to 99bdb13 Compare June 11, 2026 14:26
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 87e666f to 2b6927d Compare June 11, 2026 14:26
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from 99bdb13 to ea97cc1 Compare June 12, 2026 14:55
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 2b6927d to 999e100 Compare June 12, 2026 14:55
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from ea97cc1 to b97905c Compare June 15, 2026 19:22
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 999e100 to 026d2cf Compare June 15, 2026 19:22
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from b97905c to 21c77fa Compare June 22, 2026 14:16
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 026d2cf to 855072b Compare June 22, 2026 14:16
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from 21c77fa to a677bdf Compare June 22, 2026 15:03
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 855072b to 2324adc Compare June 22, 2026 15:03
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from a677bdf to 89d33af Compare June 22, 2026 18:29
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 2324adc to 1732b67 Compare June 22, 2026 18:29
@linear-code linear-code Bot mentioned this pull request Jun 26, 2026
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from 89d33af to f4e8bbc Compare June 26, 2026 14:59
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 1732b67 to ef1bca7 Compare June 26, 2026 14:59

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ef1bca7. Configure here.

"Unknown Project Selector",
"Project id and name must be known before reading the data source.",
)
return projectSelectorProvider, diags

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unknown selector blocks known sibling

Medium Severity

resolveProjectSelector rejects the read when either id or name is unknown, even if the other selector is a known non-empty value. A config with a fixed id and an unknown name (or the reverse) fails with “Unknown Project Selector” instead of using the known selector for GetProject or name lookup.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ef1bca7. Configure here.

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.

Won't fix — intentional. Terraform core defers data-source reads to apply time while config values are unknown, so Read seeing an unknown here is a defensive shouldn't-happen guard, and failing loud is the safe response. Honoring the known sibling would also be wrong: if id is known and name is configured-but-unknown, both selectors are configured, so the config must fail the only-one-of conflict check once name resolves — reading with just id would mask a config that has to be rejected anyway. (This helper is replaced by the shared datasources.ResolveIDNameSelector in #14 with the same semantics.)

if match == nil {
matched := project
match = &matched
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ambiguity counts duplicate rows

Low Severity

Name lookup increments count for every list row whose name equals the query string, without deduplicating by project id. If pagination or the API returns the same project more than once, the data source can report an ambiguous name when only one distinct project exists.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ef1bca7. Configure here.

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.

Fixed (via the stack): the project scan this points at is deleted in #14 (name lookup becomes a single server-resolved GetProject(name), no counting at all). The same hazard in the profile (#14) and proxy (#15) scans is fixed directly: matches are now deduplicated by id before counting, so a row repeated by offset-pagination skew is one match, not a false ambiguity (commits b97c471 / 88fbea9, with TestReadDeduplicatesRepeated{Profile,Proxy}LookupRows).

@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from f4e8bbc to f2792ef Compare June 26, 2026 17:19
@IlyaasK
IlyaasK force-pushed the project-data-source branch from ef1bca7 to c05ef4a Compare June 26, 2026 17:19
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from f2792ef to e44e04f Compare June 29, 2026 13:43
@IlyaasK
IlyaasK force-pushed the project-data-source branch 2 times, most recently from aa9269d to 6dda104 Compare June 29, 2026 13:49
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from e44e04f to 6723f0b Compare June 29, 2026 13:49
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 6dda104 to 8e8be50 Compare June 29, 2026 14:03
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch 2 times, most recently from 09f44a0 to b741ad9 Compare June 29, 2026 14:29
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 8e8be50 to 905f042 Compare June 29, 2026 14:29
@IlyaasK
IlyaasK force-pushed the project-data-source branch from 905f042 to f78a750 Compare June 29, 2026 19:14
@IlyaasK
IlyaasK requested review from Sayan- and tnsardesai June 29, 2026 20:53
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from 153b98a to ed777ad Compare July 2, 2026 02:34
@IlyaasK
IlyaasK force-pushed the project-data-source branch from f78a750 to b05c00b Compare July 2, 2026 02:34
Add the read-only kernel_project data source as the first data-source slice. Keep exact lookup and ambiguity policy in the Terraform data source while kernelclient exposes only a durable paged project-list primitive.
@IlyaasK
IlyaasK force-pushed the browser-pool-import branch from ed777ad to 6f90aab Compare July 2, 2026 02:48
@IlyaasK
IlyaasK force-pushed the project-data-source branch from b05c00b to 7c0b29f Compare July 2, 2026 02:48

@tnsardesai tnsardesai 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.

reviewed — solid PR overall. one thing worth a look:

Possible bug

  • internal/datasources/project/datasource.go:210 — name validation runs on every project in the page before the project.Name != name filter, so one unrelated project with a malformed/empty name (returned by the fuzzy query) aborts the whole lookup even when a valid exact match exists. consider validating only after the name matches, or skipping (not erroring on) invalid non-matches.

@IlyaasK

IlyaasK commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @tnsardesai — valid finding, and it ended up improving two other data sources.

For kernel_project specifically: not fixed in this PR because the flagged code is deleted one PR up the stack — #14 removes findProjectsByName/ListProjectPage entirely and switches name lookup to a single server-resolved GetProject(name) (the API resolves the GET path param by id-or-name since project names are unique per org, kernel/kernel#2455). No list scan means no unrelated rows to trip over, so the failure mode you describe can't ship.

But the same pattern survived in the profile (#14) and proxy (#15) scans in a narrower form: rows with absent names were already skipped, but a row with a present-yet-inconsistent raw name JSON still aborted the whole lookup even when it wasn't the requested name — worst for kernel_proxy, whose list has no server-side name filter at all (proxy names aren't unique), so one corrupt unrelated row would brick every name lookup in the project. Fixed both exactly as you suggested: filter on the decoded name first, and run the raw-consistency validation only on rows that claim the requested name (still fail-loud there — a corrupt row we'd actually return is a broken API response). Pinned with TestReadSkipsMalformedUnrelatedProfileLookupRows / TestReadSkipsMalformedUnrelatedProxyLookupRows, plus repurposed the old invalid-candidate tests to assert the fail-loud-on-match behavior.

Heads: #14 9bac0d1, #15 9e373f4. go vet ./... + full datasource tests green on every open branch in the stack.

@IlyaasK
IlyaasK merged commit e1ff114 into browser-pool-import Jul 2, 2026
1 check passed
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