Repository navigation
feat(identity): first-run Builderlab account client — sign-in without a plugin session, kgoose reads, link/unlink, backup, saved communities — and its dev seed #1818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matt2e
wants to merge
1
commit into
onboarding/04-builderlab-tenants
Choose a base branch
from
onboarding/05-first-run-account-client
base: onboarding/04-builderlab-tenants
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,588
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { afterEach, expect, it, vi } from "vitest"; | ||
| import { invoke } from "@tauri-apps/api/core"; | ||
| import { bundledHost, firstRunCredential } from "./first-run"; | ||
| vi.mock("@tauri-apps/api/core", () => ({ | ||
| invoke: vi.fn(), | ||
| isTauri: vi.fn(() => true), | ||
| })); | ||
| afterEach(() => { | ||
| vi.resetAllMocks(); | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| it("requests under the bundled Builderlab grant without a plugin owner", async () => { | ||
| vi.mocked(invoke).mockResolvedValueOnce({ | ||
| status: 200, | ||
| headers: {}, | ||
| body: "{}", | ||
| }); | ||
| const request = { url: "https://app.builderlab.xyz/api/goose/v1/auth/me" }; | ||
| await bundledHost.request(request); | ||
| expect(invoke).toHaveBeenCalledWith("plugin_host_request", { | ||
| id: "block.builderlab", | ||
| revision: "bundled", | ||
| request, | ||
| }); | ||
| expect(await bundledHost.runCommand("any")).toBeNull(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ["the configured build URL", undefined, "https://builderlab.example"], | ||
| ["a tenant origin", "https://tenant.example", "https://tenant.example"], | ||
| ])( | ||
| "starts the native browser handoff at %s", | ||
| async (_label, origin, expected) => { | ||
| vi.stubEnv("VITE_BUZZ_BUILDERLAB_URL", "https://builderlab.example"); | ||
| // A refused listener ends the attempt before any exchange request. | ||
| vi.mocked(invoke).mockRejectedValueOnce("listener unavailable"); | ||
| await expect( | ||
| firstRunCredential(new AbortController().signal, origin), | ||
| ).rejects.toThrow("Could not complete"); | ||
| expect(invoke).toHaveBeenCalledTimes(1); | ||
| expect(invoke).toHaveBeenCalledWith( | ||
| "oauth_callback_begin", | ||
| expect.objectContaining({ | ||
| authorizationUrl: expect.stringMatching( | ||
| new RegExp(`^${expected}/api/goose/v1/auth/login\\?`), | ||
| ), | ||
| useState: true, | ||
| }), | ||
| ); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { invoke } from "@tauri-apps/api/core"; | ||
| import type { Host } from "../../../features/host/service"; | ||
| import manifest from "../manifest.json"; | ||
| import { browserCredential, type Credential, nativeBridge } from "./browser"; | ||
|
|
||
| /** | ||
| * First launch runs before this plugin can share its Settings session, so the | ||
| * welcome screen signs in through the same OAuth client under the bundled | ||
| * plugin's own native network grant. Native code grants that origin at build | ||
| * time; it does not depend on the plugin's JavaScript having started. | ||
| */ | ||
| export const bundledHost: Host = { | ||
| runCommand: () => Promise.resolve(null), | ||
| request: (request) => | ||
| invoke("plugin_host_request", { | ||
| id: manifest.id, | ||
| revision: "bundled", | ||
| request, | ||
| }), | ||
| }; | ||
|
|
||
| /** `origin`: a tenant's portal chosen from the community URL; default otherwise. */ | ||
| export const firstRunCredential = ( | ||
| signal: AbortSignal, | ||
| origin?: string, | ||
| ): Promise<Credential> => | ||
| browserCredential(bundledHost, signal, nativeBridge, origin); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 P2 — Handle a persisted disabled Builderlab plugin before first-run sign-in. This transport calls
plugin_host_request, whosehost_grantslookup requires the bundled plugin to be enabled (crates/plugin-manager/src/lib.rs:1112–1122). Disabling Builderlab is persisted, and ordinary sign-out retains that registry (src-tauri/src/sign_out.rs:665–669). Thus this first-run helper can finish browser authentication and then fail credential exchange locally on the next setup. Give the app-owned flow narrowly scoped access independent of Settings-plugin enablement, or explicitly handle the disabled state before opening login, retaining configured-origin enforcement. Cover disabled-plugin → plain sign-out → first-run login.