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
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ describe('the connect dialog in both themes', () => {
await i18n.changeLanguage('en');
renderDialog();
const dialog = await screen.findByRole('dialog');
// The dialog and its overlay fade in, and axe reads the opacity of
// every ancestor: an audit that starts a few frames in judges the text
// at a few percent. The waiting dot pulses for good, so only the
// animations that end are awaited.
await Promise.allSettled(
document
.getAnimations()
.filter(
(animation) =>
animation.effect?.getComputedTiming().iterations !== Infinity,
)
.map((animation) => animation.finished),
);
const result = await axe.run(dialog, {
runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21aa'] },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,59 @@ vi.mock('@tanstack/react-router', async (importOriginal) => ({
<a href="/fixture-owner">{children}</a>
),
}));
// Each read keeps one identity across renders, as the cache's own data does: a
// fresh object per call would change the table's column definitions on every
// render, and a changed definition remounts every cell under an open row menu.
const reads = vi.hoisted(() => {
const refetch = vi.fn();
const read = (data: unknown) => ({
data,
isLoading: false,
isFetching: false,
isError: false,
refetch,
});
return {
sessions: read({
sessions: [
{
sessionId: 'owned',
ownerType: 'project_agent',
ownerId: 'agent-alice',
ownerLabel: 'Alice',
worker: { number: 1, scope: 'agent' },
createdBy: 'system:task-agent',
status: 'active',
createdAt: 1_750_000_000_000,
pinned: false,
busy: true,
totalSpentCents: 0,
currentOp: null,
runningOps: [],
},
],
waitingRuns: { total: 0, byReason: {} },
}),
limits: read({ status: 'available', maxSessions: 16 }),
usage: read([]),
devices: read({ devices: [], hub: 'available', serverVersion: '0.5.60' }),
policy: read(null),
other: read({ status: 'unavailable', reason: 'not_configured' }),
};
});
vi.mock('@/app/hooks/use-backend-query', () => ({
useBackendQuery: (name: string) => ({
data: name.endsWith(':listSandboxesForOrg')
? {
sessions: [
{
sessionId: 'owned',
ownerType: 'project_agent',
ownerId: 'agent-alice',
ownerLabel: 'Alice',
worker: { number: 1, scope: 'agent' },
createdBy: 'system:task-agent',
status: 'active',
createdAt: 1_750_000_000_000,
pinned: false,
busy: true,
totalSpentCents: 0,
currentOp: null,
runningOps: [],
},
],
waitingRuns: { total: 0, byReason: {} },
}
useBackendQuery: (name: string) =>
name.endsWith(':listSandboxesForOrg')
? reads.sessions
: name.endsWith(':getSandboxDeploymentLimits')
? { status: 'available', maxSessions: 16 }
? reads.limits
: name.endsWith(':getSandboxQuotaUsage')
? []
? reads.usage
: name === 'sandbox_devices/queries:list'
? { devices: [], hub: 'available', serverVersion: '0.5.60' }
? reads.devices
: name === 'governance/queries:getPolicy'
? null
: { status: 'unavailable', reason: 'not_configured' },
isLoading: false,
isFetching: false,
isError: false,
refetch: vi.fn(),
}),
? reads.policy
: reads.other,
}));

const refusalCopy = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ export function SandboxesSettings({ organizationId }: SandboxesSettingsProps) {
'node_only/sandbox/session_admin_actions:setSandboxPinned',
{ errorToast: false },
);
// `useMutation` returns a new object on every render, but its async trigger
// stays the same. The column definitions below depend on the triggers, not
// the objects: a changed definition remounts every cell, and an open row
// menu closes with it.
const stopTask = stop.mutateAsync;
const setSandboxPinned = setPinned.mutateAsync;

// Reconcile business allocation records on mount. Physical runtime state
// comes from the separate infrastructure snapshot below.
Expand Down Expand Up @@ -371,7 +377,7 @@ export function SandboxesSettings({ organizationId }: SandboxesSettingsProps) {
void run(
s.sessionId,
() =>
stop.mutateAsync({
stopTask({
organizationId,
sessionId: s.sessionId,
}),
Expand All @@ -390,7 +396,7 @@ export function SandboxesSettings({ organizationId }: SandboxesSettingsProps) {
void run(
s.sessionId,
() =>
setPinned.mutateAsync({
setSandboxPinned({
organizationId,
sessionId: s.sessionId,
pinned: !s.pinned,
Expand All @@ -415,7 +421,16 @@ export function SandboxesSettings({ organizationId }: SandboxesSettingsProps) {
},
},
],
[t, organizationId, pendingId, stop, setPinned, run, snapshot, devicesView],
[
t,
organizationId,
pendingId,
stopTask,
setSandboxPinned,
run,
snapshot,
devicesView,
],
);

if ((canManage && data === null) || (!abilityLoading && !canRead)) {
Expand Down