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
12 changes: 12 additions & 0 deletions packages/account/src/core/billing/billingContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
* copy: a command matches it against its own closed set, and a host stores it
* where it already keeps `WorkspaceApiError.code`.
*/
import type { SessionClient } from '../session.js'

/**
* The session members the billing core reaches for. A host's client is typed
* for its own user, and the identity seam is contravariant in that user, so
* requiring the full client would reject every host whose user is more
* specific than the base.
*/
export type BillingSession = Pick<

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.

Severity: Note

What: Nothing inside packages/account pins that a SessionClient typed for a narrower user is assignable to BillingSession.

Why this is an issue: attachIdentity is the only member carrying the user in a parameter position, so restoring it or a member shaped like it to the Pick would silently reintroduce the rejection this change removes, and the first failure would surface in a consumer typecheck rather than here.

Proposed Fix: Add one expectTypeOf<SessionClient<NarrowUser>>().toMatchTypeOf<BillingSession>() beside the billing suites.

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.

Accepted and written: packages/account/src/core/billing/billingContracts.test.ts pins expectTypeOf<SessionClient<WorkspaceUser>>().toExtend<BillingSession>(), plus .not.toExtend<SessionClient>() so the file records the rejection the Pick exists to route around, not only the assignability. Verified load-bearing rather than decorative: putting attachIdentity back into the Pick fails the first assertion with TS2344, and vue-tsc --noEmit over packages/account is clean without it. 39 files / 590 tests pass.

It is not on this PR, though. This went into the merge queue (position 1) three minutes after your approval, so the push was rejected by the queue, and dequeuing to add a test you filed as a Note would also dismiss your approval on re-entry. The pin lands as a follow-up against main (commit 677379f29f) and this PR stays type-only exactly as you reviewed it.

SessionClient,
'getSnapshot' | 'subscribe' | 'ensureFresh' | 'remint'
>

/**
* The failure buckets a billing request can produce, extracted from what the
Expand Down
6 changes: 3 additions & 3 deletions packages/account/src/core/billing/billingScope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SessionClient } from '../session.js'
import type { BillingSession } from './billingContracts.js'
import type { AccountCredential } from '../sessionContracts.js'

export interface BillingScope {
Expand Down Expand Up @@ -27,7 +27,7 @@ export function sameBillingScope(a: BillingScope, b: BillingScope): boolean {
}

export function createBillingScopeTracker(
session: SessionClient,
session: BillingSession,
onChange: () => void
): BillingScopeTracker {
let scope = readBillingScope(session)
Expand Down Expand Up @@ -59,7 +59,7 @@ export function createBillingScopeTracker(
}
}

function readBillingScope(session: SessionClient): BillingScope | undefined {
function readBillingScope(session: BillingSession): BillingScope | undefined {
const state = session.getSnapshot()
if (state.user === null || state.session === undefined) return undefined
return {
Expand Down
9 changes: 6 additions & 3 deletions packages/account/src/core/billing/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import {
} from '@comfyorg/ingest-types/zod'
import { z } from 'zod'

import type { SessionClient } from '../session.js'
import type { BillingResult, BillingTransport } from './billingContracts.js'
import type {
BillingResult,
BillingSession,
BillingTransport
} from './billingContracts.js'
import type { BillingScope, BillingScopeContext } from './billingScope.js'
import { createBillingScopeTracker, sameBillingScope } from './billingScope.js'
import type { CapabilityDenials } from './capabilityDenials.js'
Expand Down Expand Up @@ -110,7 +113,7 @@ export interface CapabilitiesReader {

export interface CapabilitiesReaderOptions {
readonly transport: BillingTransport
readonly session: SessionClient
readonly session: BillingSession
readonly now?: () => number
}

Expand Down
9 changes: 6 additions & 3 deletions packages/account/src/core/billing/credits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import { zBillingBalanceResponse } from '@comfyorg/ingest-types/zod'
import type { z } from 'zod'

import type { SessionClient } from '../session.js'
import type { BillingResult, BillingTransport } from './billingContracts.js'
import type {
BillingResult,
BillingSession,
BillingTransport
} from './billingContracts.js'
import type { BillingScope, BillingScopeContext } from './billingScope.js'
import { createBillingScopeTracker } from './billingScope.js'
import {
Expand Down Expand Up @@ -53,7 +56,7 @@ export interface CreditsReader {

export interface CreditsReaderOptions {
readonly transport: BillingTransport
readonly session: SessionClient
readonly session: BillingSession
readonly now?: () => number
}

Expand Down
1 change: 1 addition & 0 deletions packages/account/src/core/billing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type {
BillingHttpResponse,
BillingRequest,
BillingResult,
BillingSession,
BillingTransport
} from './billingContracts.js'
export type { SessionBillingTransportOptions } from './transport.js'
Expand Down
4 changes: 2 additions & 2 deletions packages/account/src/core/billing/operationLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import { zBillingOpStatusResponse } from '@comfyorg/ingest-types/zod'

import { BILLING_OPERATION_TELEMETRY_EVENT } from '../../telemetry.js'
import type { SessionClient } from '../session.js'
import type {
BillingFailure,
BillingResult,
BillingSession,
BillingTransport
} from './billingContracts.js'
import type { BillingScope, BillingScopeContext } from './billingScope.js'
Expand Down Expand Up @@ -100,7 +100,7 @@ export type PresentationSwitchOutcome =

export interface BillingOperationLifecycleOptions {
readonly transport: BillingTransport
readonly session: SessionClient
readonly session: BillingSession
/** The Phase 2 status reader; consulted before every start and recovery. */
readonly statusReader: BillingStatusReader
/** Tab-local storage for the operation pointer; absent means nothing survives a reload. */
Expand Down
9 changes: 6 additions & 3 deletions packages/account/src/core/billing/status.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { zBillingStatusResponse } from '@comfyorg/ingest-types/zod'
import type { z } from 'zod'

import type { SessionClient } from '../session.js'
import type { BillingResult, BillingTransport } from './billingContracts.js'
import type {
BillingResult,
BillingSession,
BillingTransport
} from './billingContracts.js'
import type { BillingScope, BillingScopeContext } from './billingScope.js'
import { createBillingScopeTracker } from './billingScope.js'
import {
Expand Down Expand Up @@ -37,7 +40,7 @@ export interface BillingStatusReader {

export interface BillingStatusReaderOptions {
readonly transport: BillingTransport
readonly session: SessionClient
readonly session: BillingSession
readonly now?: () => number
}

Expand Down
5 changes: 3 additions & 2 deletions packages/account/src/core/billing/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* reported as SUPERSEDED instead of being handed to a caller that would
* attribute it to the wrong account.
*/
import type { SessionClient, SessionRequestOptions } from '../session.js'
import type { SessionRequestOptions } from '../session.js'
import type {
AccountCredential,
SessionErrorCode,
Expand All @@ -27,6 +27,7 @@ import type {
BillingHttpResponse,
BillingRequest,
BillingResult,
BillingSession,
BillingTransport
} from './billingContracts.js'

Expand Down Expand Up @@ -54,7 +55,7 @@ function startRequestBudget(
}

export interface SessionBillingTransportOptions {
readonly session: SessionClient
readonly session: BillingSession
/**
* Resolves a route to an absolute URL. The cloud app's own resolver
* (`workspaceApiUrl`) differs per distribution, so the host owns it.
Expand Down
Loading