Skip to content
Closed
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
9 changes: 8 additions & 1 deletion src/app/dashboard/[teamSlug]/terminal/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import type { components as InfraComponents } from '@/core/shared/contracts/infr
import { createSandboxManagementAuth } from '@/core/shared/sandbox-management-auth.server'
import { SandboxIdSchema } from '@/core/shared/schemas/api'
import DashboardTerminal from '@/features/dashboard/terminal/dashboard-terminal'
import { normalizeTerminalTemplate } from '@/features/dashboard/terminal/template'
import {
isPublicTemplateReference,
normalizeTerminalTemplate,
} from '@/features/dashboard/terminal/template'
import { Button } from '@/ui/primitives/button'

export const metadata: Metadata = {
Expand Down Expand Up @@ -192,6 +195,10 @@ async function isTerminalTemplateAvailable({
return { ok: true as const, available: true }
}

if (isPublicTemplateReference(template)) {
return { ok: true as const, available: true }
}

const defaultTemplatesRepository = createDefaultTemplatesRepository({
accessToken,
})
Expand Down
6 changes: 6 additions & 0 deletions src/features/dashboard/terminal/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export function normalizeTerminalTemplate(template?: string) {
return value
}

export function isPublicTemplateReference(template: string) {
const [owner, name, ...rest] = template.split('/')

return Boolean(owner && name && rest.length === 0)
}

export function resolveTerminalTemplateOverride(
template: string | undefined,
fallback: string
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/dashboard-terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
writeStoredTerminalSession,
} from '@/features/dashboard/terminal/storage'
import {
isPublicTemplateReference,
normalizeTerminalTemplate,
resolveTerminalTemplateOverride,
} from '@/features/dashboard/terminal/template'
Expand Down Expand Up @@ -85,6 +86,21 @@ describe('dashboard terminal helpers', () => {
})
})

describe('isPublicTemplateReference', () => {
it('detects owner-qualified public template references', () => {
expect(isPublicTemplateReference('team-slug/python:default')).toBe(true)
expect(
isPublicTemplateReference('aiengineer-d56d/aiengineer-guide')
).toBe(true)
})

it('does not treat bare or multi-path template names as public references', () => {
expect(isPublicTemplateReference('base')).toBe(false)
expect(isPublicTemplateReference('python_3.12-dev')).toBe(false)
expect(isPublicTemplateReference('owner/nested/template')).toBe(false)
})
})

describe('resolveTerminalTemplateOverride', () => {
it('preserves the current template when no override is provided', () => {
expect(resolveTerminalTemplateOverride(undefined, 'python')).toBe(
Expand Down
Loading