Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cloud/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ export class CloudAuthenticationProvider

const sessions = await this.getSessions()
const session = sessions[0]

window.showInformationMessage(
`Signed in to FastAPI Cloud as ${session.account.label}`,
)

this._onDidChangeSessions.fire({
added: [session],
removed: [],
Expand Down
51 changes: 51 additions & 0 deletions src/test/cloud/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,57 @@ suite("cloud/auth", () => {
await provider.dispose()
})

test("shows notification after device code sign-in", async () => {
fsStub.fake.readFile.rejects(new Error("File not found"))

const token = validToken()
const fetchStub = sinon.stub(globalThis, "fetch")
fetchStub.onFirstCall().resolves(
mockResponse({
device_code: "dev123",
user_code: "USER-CODE",
verification_uri: "https://auth.example.com/device",
verification_uri_complete:
"https://auth.example.com/device?code=USER-CODE",
interval: 1,
}),
)
fetchStub.onSecondCall().resolves(mockResponse({ access_token: token }))
fetchStub
.onThirdCall()
.resolves(
mockResponse({ email: "new@example.com", full_name: "New" }),
)

sinon.stub(vscode.env, "openExternal")
sinon
.stub(vscode.window, "withProgress")
.callsFake(async (_opts, task) => {
const cancellationToken = {
isCancellationRequested: false,
onCancellationRequested: sinon.stub(),
}
return task({ report: sinon.stub() }, cancellationToken as any)
})
const infoStub = sinon.stub(vscode.window, "showInformationMessage")

fsStub.fake.createDirectory.resolves()
fsStub.fake.writeFile.callsFake(async () => {
fsStub.fake.readFile.resolves(
Buffer.from(JSON.stringify({ access_token: token })),
)
})

const { provider } = createProvider()
await provider.createSession()

assert.ok(
infoStub.calledWith("Signed in to FastAPI Cloud as new@example.com"),
)

await provider.dispose()
})

test("wraps network error with friendly message", async () => {
fsStub.fake.readFile.rejects(new Error("File not found"))

Expand Down
Loading