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
3 changes: 3 additions & 0 deletions browser_tests/fixtures/networkIsolationFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@e2e/fixtures/utils/liveCloudBillingPolicy'
import type { NetworkPolicy } from '@e2e/fixtures/utils/networkPolicy'
import { assetPath } from '@e2e/fixtures/utils/paths'
import { mockDeploymentRolloutRefusal } from '@e2e/fixtures/utils/workspaceMocks'

dotenvConfig()

Expand Down Expand Up @@ -189,6 +190,8 @@ export const networkIsolationFixture = base.extend<{
networkPolicy,
liveCloudBillingConfig
)
} else {
await mockDeploymentRolloutRefusal(context)
}
await use(context)
restore()
Expand Down
7 changes: 6 additions & 1 deletion browser_tests/fixtures/utils/cloudBootMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
import { mockSystemStats } from '@e2e/fixtures/data/systemStats'
import { CloudAuthHelper } from '@e2e/fixtures/helpers/CloudAuthHelper'
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { mockWorkspace, workspace } from '@e2e/fixtures/utils/workspaceMocks'
import {
mockDeploymentRolloutRefusal,
mockWorkspace,
workspace
} from '@e2e/fixtures/utils/workspaceMocks'

interface CloudBootOptions {
/** Remote-config payload for `/api/features` (enables the flags under test). */
Expand All @@ -26,6 +30,7 @@ export async function mockCloudBootRoutes(
page: Page,
{ features, settings = {}, objectInfo }: CloudBootOptions
) {
await mockDeploymentRolloutRefusal(page)
await page.route('**/api/features', (r) => r.fulfill(jsonRoute(features)))
await page.route('**/api/system_stats', (r) =>
r.fulfill(jsonRoute(mockSystemStats))
Expand Down
12 changes: 12 additions & 0 deletions browser_tests/fixtures/utils/workspaceMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ export async function mockWorkspace(
)
)
}

/** Refuse the deployment listing the way a workspace outside the rollout sees it. */
export async function mockDeploymentRolloutRefusal(
routeTarget: Page | BrowserContext
): Promise<void> {
await routeTarget.route('**/api/workspaces/*/deployments', (route) =>
route.fulfill({
...jsonRoute({ error: 'Deployment selection is outside the rollout' }),
status: 403
})
)
}
29 changes: 19 additions & 10 deletions scripts/checkAssetsFlagArtifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,41 @@ describe('assertWidgetAssetPickerGate', () => {
}
)

it('accepts a Cloud gate folded to a static true', () => {
it('accepts a Cloud gate that excludes selected deployments', () => {
expect(() =>
assertWidgetAssetPickerGate(
['function isWidgetAssetPickerEnabled() {\n return true;\n}'],
[
'function isWidgetAssetPickerEnabled() {\n return !useDeploymentPickStore().bootDeployment;\n}'
],
'cloud'
)
).not.toThrow()
})

it('accepts a minified Cloud gate spelling true as !0', () => {
it('accepts a compact Cloud deployment gate', () => {
expect(() =>
assertWidgetAssetPickerGate(
['function isWidgetAssetPickerEnabled(){return!0}'],
[
'function isWidgetAssetPickerEnabled(){return!useDeploymentPickStore().bootDeployment}'
],
'cloud'
)
).not.toThrow()
})

it.for([
'function isWidgetAssetPickerEnabled() {\n track();\n return true;\n}',
'function isWidgetAssetPickerEnabled() {\n return isCloud;\n}'
])('rejects a Cloud gate that is not a static constant: %s', (gate) => {
expect(() => assertWidgetAssetPickerGate([gate], 'cloud')).toThrow(
'Built widget asset-picker gate is invalid for cloud'
)
})
'function isWidgetAssetPickerEnabled() {\n return isCloud;\n}',
'function isWidgetAssetPickerEnabled(){return!0}',
'function isWidgetAssetPickerEnabled(){return useDeploymentPickStore().bootDeployment}'
])(
'rejects a Cloud gate that ignores the selected deployment: %s',
(gate) => {
expect(() => assertWidgetAssetPickerGate([gate], 'cloud')).toThrow(
'Built widget asset-picker gate is invalid for cloud'
)
}
)

it.for([
'function isWidgetAssetPickerEnabled() {\n if (!api.getServerFeature("assets", false)) return false;\n return true;\n}',
Expand Down
19 changes: 1 addition & 18 deletions scripts/checkAssetsFlagArtifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,9 @@ const TEXT_ASSET_EXTENSIONS = new Set([
/** Sourcemaps carry the gate's own source, which would count as a second gate. */
const EXECUTABLE_ASSET_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.html'])

/**
* The widget asset-picker gate must compile to a static constant per
* distribution: `false`/`!1` off-cloud, meaning the feature is statically
* stripped, and `true`/`!0` on cloud.
*
* The two legs are deliberately asymmetric. `nonCloud` carries the real
* invariant: a body that folds to a constant `false` proves the picker is
* unreachable in a non-cloud artifact, which is what lets the bundler drop
* everything behind it. `cloud` is much weaker — it only proves some static
* truthy constant survived — but that is honest, because the gate is now
* nothing more than a build-time constant. Its job is to catch the gate
* regressing into a runtime read, not to constrain runtime behaviour.
*
* Both are anchored against the whole compiled body: a substring search would
* accept a `return true` sitting beside an extra statement. The alternations
* are the two spellings minification emits for each literal.
*/
const GATE_BODIES = {
nonCloud: /^return\s*(?:false|!1)\s*;?$/,
cloud: /^return\s*(?:true|!0)\s*;?$/
cloud: /^return\s*!useDeploymentPickStore\(\)\.bootDeployment\s*;?$/
} as const

function artifactFiles(directory: string): string[] {
Expand Down
Loading
Loading