← Back to Pull requests

test(awx): Part 3 coverage for administration and main (AAP-72866) #3741

Merged
acruzgon merged 18 files (1002 lines) on Oct 12, 2026 22:09 UTC
View on GitHub
acruzgon acruzgon commented on Oct 12, 2026 15:29 UTC
Author

Summary

  • Add structural unit tests for all 19 AWX useAwx*Routes hooks (ids, paths, nested route ids).

  • Add useAwxNavigation structure tests for infrastructure, administration, access, and settings (superuser vs regular user).

  • Add column hook tests for execution environments, instance groups, and notification templates.

  • Introduce frontend/awx/test-utils/collectPageNavigationRoutes (mirrors platform pattern) for route tree assertions.
  • Part 3 of the awx coverage epic (AAP-70839); more administration hook/page tests will follow in subsequent PRs to reach the 90% target.

    Type of Change

  • Bug fix

  • Enhancement

  • Tests

  • Documentation

  • Other (please specify)
  • Risk Analysis - REQUIRED

  • High — Broad platform impact (e.g., SWR config, shared framework components, authentication, routing, API wrappers, build/bundler config). Changes affect multiple workspaces or could cause widespread regressions.

  • Medium — Scoped but cross-cutting (e.g., shared utility functions, changes to multiple pages within one workspace, component library updates, test infrastructure). Limited blast radius but touches common code paths.

  • Low — Narrowly scoped (e.g., single page fix, styling tweak, documentation, test-only changes, copy/string updates). Minimal risk of unintended side effects.
  • Dependencies

    None.

    Testing

    Ephemeral E2E Tests

    Once PR is ready and preliminary checks pass, trigger tests by posting a comment /run-playwright on this PR.

    Tests run against a fresh AAP instance (version based on branch).

    External Server E2E Runs

    N/A — test-only change.

    Manual Testing

  • cd frontend/awx && npx vitest run test-utils/collectPageNavigationRoutes.test.tsx main/routes/awxRouteHooks.test.tsx main/useAwxNavigation.structure.test.tsx administration/execution-environments/hooks/useExecutionEnvironmentsColumns.test.tsx administration/instance-groups/hooks/useInstanceGroupsColumns.test.tsx administration/notifiers/hooks/useNotifiersColumns.test.tsx
  • Screenshots

    N/A

    Made with Cursor

    Diff: 1002 lines (+999 / -3) across 18 files Reviewer: lgalis Review duration: 399m
    All Vouch review confidence checks passed
    Residual risk 0.13 = Change Risk (0.72) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.72 · 1002 lines diff across 18 files
    0.72
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.77 · 5 substantive comment(s)
    0.77
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    8 items
    lgalis lgalis commented on code on Oct 12, 2026 18:47 UTC
    Code Review
    frontend/awx/administration/activity-stream/hooks/useGetActivityStreamRoute.test.ts:1
    @@ -0,0 +1,34 @@
    +import { renderHook } from '@testing-library/react';
    +import { describe, expect, test } from 'vitest';
    +import { AwxRoute } from '../../../main/AwxRoutes';
    +import { useGetActivityStreamRoute } from './useGetActivityStreamRoute';
    +
    +function renderActivityStreamRoute(resource?: string | null) {
    +  return renderHook(() => useGetActivityStreamRoute(resource));
    +}
    +
    +describe('useGetActivityStreamRoute', () => {
    +  test('returns null when resource is missing', () => {
    +    expect(renderActivityStreamRoute(null).result.current).toBeNull();
    +    expect(renderActivityStreamRoute().result.current).toBeNull();
    +    expect(renderActivityStreamRoute('').result.current).toBeNull();
    +  });
    +
    +  test('maps known activity stream resources to detail routes', () => {

    useGetActivityStreamRoute maps many resources in the switch (workflow_job_template, inventory_source, execution_environment, workflow_approval, etc.), but this test only covers a handful plus schedule → null.

    A table-driven test over every case in the hook would better lock the mapping and document intentional nulls (including the commented-out schedule case).

    lgalis lgalis commented on code on Oct 12, 2026 18:47 UTC
    Code Review
    framework/test-utils/collectPageNavigationRoutes.ts:1
    @@ -0,0 +1,31 @@
    +import { PageNavigationItem } from '@ansible/ansible-ui-framework';
    +
    +export type PageNavigationRouteDescriptor = {
    +  id?: string;
    +  path: string;
    +};
    +
    +/** Flattens an AWX navigation tree for structural route assertions in tests. */
    +export function collectPageNavigationRoutes(

    This helper is identical to platform/test-utils/collectPageNavigationRoutes.ts. Fine for this PR and consistent with the platform route-hook tests, but we now have two copies that can drift.

    Optional follow-up: share one module (e.g. frontend/common or framework test-utils) and import from both workspaces.

    lgalis lgalis commented on code on Oct 12, 2026 18:47 UTC
    Code Review
    frontend/awx/main/routes/awxRouteHooks.test.tsx:1
    @@ -0,0 +1,321 @@
    +import { renderHook } from '@testing-library/react';
    +import { MemoryRouter } from 'react-router-dom';
    +import { describe, expect, test } from 'vitest';
    +import { collectPageNavigationRouteIds } from '../../test-utils/collectPageNavigationRoutes';
    +import { AwxRoute } from '../AwxRoutes';
    +import { useAwxActivityStreamRoutes } from './useAwxActivityStreamRoutes';
    +import { useAwxCredentialRoutes } from './useAwxCredentialRoutes';
    +import { useAwxCredentialTypesRoutes } from './useAwxCredentialTypesRoutes';
    +import { useAwxDeprecationsRoutes } from './useAwxDeprecationsRoutes';
    +import { useAwxExecutionEnvironmentRoutes } from './useAwxExecutionEnironmentRoutes';
    +import { useAwxHostRoutes } from './useAwxHostRoutes';
    +import { useAwxInstanceGroupsRoutes } from './useAwxInstanceGroupsRoutes';
    +import { useAwxInstancesRoutes } from './useAwxInstancesRoutes';
    +import { useAwxInventoryRoutes } from './useAwxInventoryRoutes';
    +import { useAwxJobsRoutes } from './useAwxJobsRoutes';
    +import { useAwxManagementJobsRoutes } from './useAwxManagementJobsRoutes';
    +import { useAwxNotificationsRoutes } from './useAwxNotificationsRoutes';
    +import { useAwxOrganizationRoutes } from './useAwxOrganizationsRoutes';
    +import { useAwxProjectRoutes } from './useAwxProjectRoutes';
    +import { useAwxSchedulesRoutes } from './useAwxSchedulesRoutes';
    +import { useAwxTeamsRoutes } from './useAwxTeamsRoutes';
    +import { useAwxTemplateRoutes } from './useAwxTemplateRoutes';
    +import { useAwxUsersRoutes } from './useAwxUsersRoutes';
    +import { useAwxWorkflowApprovalRoutes } from './useAwxWorkflowApprovalRoutes';
    +
    +function renderAwxRouteHook<T>(useRoutes: () => T) {
    +  return renderHook(useRoutes, {
    +    wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter>,
    +  });
    +}
    +
    +describe('AWX route definition hooks', () => {
    +  test('useAwxActivityStreamRoutes should define the activity stream route', () => {
    +    const { result } = renderAwxRouteHook(useAwxActivityStreamRoutes);
    +
    +    expect(result.current.id).toBe(AwxRoute.ActivityStream);
    +    expect(result.current.path).toBe('activity-stream');
    +    expect(collectPageNavigationRouteIds(result.current)).toEqual([AwxRoute.ActivityStream]);
    +  });
    +
    +  test('useAwxDeprecationsRoutes should define deprecation routes', () => {
    +    const { result } = renderAwxRouteHook(useAwxDeprecationsRoutes);
    +    const routeIds = collectPageNavigationRouteIds(result.current);
    +
    +    expect(result.current.id).toBe(AwxRoute.Deprecations);
    +    expect(result.current.path).toBe('deprecations');
    +    expect(routeIds).toEqual(
    +      expect.arrayContaining([

    Most route hooks assert nested IDs with expect.arrayContaining([...subset...]) (this deprecations case is representative). That catches missing listed routes but not duplicate ids in the tree, unexpected extra routes you might want to forbid, or removals of routes that were never part of the asserted subset.

    Consider exact sorted ID lists (like useAwxActivityStreamRoutes does with toEqual) or toHaveLength + full set for bounded trees so refactors can't silently drop unlisted routes.

    lgalis lgalis commented on code on Oct 12, 2026 18:47 UTC
    Code Review
    frontend/awx/administration/instance-groups/hooks/useInstanceGroupActions.test.tsx:1
    @@ -0,0 +1,73 @@
    +import { renderHook } from '@testing-library/react';
    +import { MemoryRouter, Route, Routes } from 'react-router-dom';
    +import { beforeEach, describe, expect, test, vi } from 'vitest';
    +import { PageActionType, usePageNavigate } from '@ansible/ansible-ui-framework';
    +import { useDeleteInstanceGroups } from './useDeleteInstanceGroups';
    +import {
    +  useInstanceGroupRowActions,
    +  useInstanceGroupToolbarActions,
    +} from './useInstanceGroupActions';
    +
    +vi.mock('./useDeleteInstanceGroups');
    +vi.mock('@ansible/common-ui/crud/useOptions', () => ({
    +  useOptions: () => ({ data: { actions: { POST: {} } } }),
    +}));
    +vi.mock('@ansible/ansible-ui-framework', async (importOriginal) => {
    +  const actual = await importOriginal<typeof import('@ansible/ansible-ui-framework')>();
    +  return {
    +    ...actual,
    +    usePageNavigate: vi.fn(),
    +  };
    +});
    +
    +function renderActionsHook<T>(useActions: (onComplete: () => void) => T) {
    +  const onComplete = vi.fn();
    +  return renderHook(() => useActions(onComplete), {
    +    wrapper: ({ children }) => (
    +      <MemoryRouter initialEntries={['/instance-groups/1']}>
    +        <Routes>
    +          <Route path="/instance-groups/:id" element={children} />
    +        </Routes>
    +      </MemoryRouter>
    +    ),
    +  });
    +}
    +
    +describe('useInstanceGroupActions', () => {
    +  const mockPageNavigate = vi.fn();
    +  const mockDelete = vi.fn();
    +
    +  beforeEach(() => {
    +    vi.clearAllMocks();
    +    vi.mocked(usePageNavigate).mockReturnValue(mockPageNavigate);
    +    vi.mocked(useDeleteInstanceGroups).mockReturnValue(mockDelete);
    +  });
    +
    +  test('useInstanceGroupToolbarActions exposes create and delete actions', () => {
    +    const { result } = renderActionsHook(useInstanceGroupToolbarActions);
    +
    +    expect(result.current[0]).toMatchObject({
    +      type: PageActionType.Dropdown,
    +      label: 'Create group',
    +    });
    +    expect(result.current[2]).toMatchObject({
    +      type: PageActionType.Button,
    +      label: 'Delete instance groups',
    +      isDanger: true,
    +    });
    +  });
    +
    +  test('useInstanceGroupRowActions exposes edit and delete row actions', () => {
    +    const { result } = renderActionsHook(useInstanceGroupRowActions);
    +
    +    expect(result.current[0]).toMatchObject({
    +      type: PageActionType.Button,
    +      label: 'Edit instance group',
    +    });
    +    expect(result.current[3]).toMatchObject({

    Toolbar/row assertions rely on fixed array indices ([0], [2], [3]), which break if dropdown/separator ordering changes without behavior change.

    Prefer finding actions by label (and type where needed), same pattern as other action hook tests in the repo.

    lgalis lgalis commented on Oct 12, 2026 18:48 UTC
    Reviewer

    Test-only PR looks good to merge from a product-risk perspective. Left four inline notes from review: tighter route ID assertions, broader useGetActivityStreamRoute cases, shared collectPageNavigationRoutes helper, and less index-based action tests.

    lgalis lgalis approved these changes on Oct 12, 2026 21:58 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    acruzgon acruzgon
    Labels
    risk: low confidence: 81.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.9% · Lower = rushed or shallow review
    81.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.9% · Safe to merge
    12.9%