import { server, handlers } from '../chunk-7XKCG5CT.js';
export { handlers, server } from '../chunk-7XKCG5CT.js';
import { mockWorkOSUser, mockUseAuth, mockUnauthenticatedUser, mockAuthenticatedUser, mockAuthLoading, createMockUseAuth } from '../chunk-DRQPEMJI.js';
export { createMockUseAuth, mockAuthLoading, mockAuthenticatedUser, mockUnauthenticatedUser, mockUseAuth, mockWorkOSUser } from '../chunk-DRQPEMJI.js';
import '../chunk-4UA62IDF.js';
import { ApiClientProvider } from '../chunk-7Q5THR43.js';
import '../chunk-DD3CCMCZ.js';
import '../chunk-XOPLS4S6.js';
import '../chunk-FVOMKZ7S.js';
import '../chunk-KRWALB24.js';
import { ElevasisServiceProvider } from '../chunk-2FTX4WO2.js';
import '../chunk-MQZE7SUI.js';
import '../chunk-TVTSASST.js';
import { __export, __reExport } from '../chunk-I2KLQ2HA.js';
import { MantineProvider } from '@mantine/core';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import * as react_star from '@testing-library/react';
import { render, renderHook } from '@testing-library/react';
import { jsx } from 'react/jsx-runtime';

// src/test-utils/index.ts
var test_utils_exports = {};
__export(test_utils_exports, {
  TestProviders: () => TestProviders,
  assertOrgOsUiRouteContract: () => assertOrgOsUiRouteContract,
  collectOrgOsUiRouteContractIssues: () => collectOrgOsUiRouteContractIssues,
  createMockUseAuth: () => createMockUseAuth,
  createTestQueryClient: () => createTestQueryClient,
  createTestWrapper: () => createTestWrapper,
  extractOrgOsRouteTreeFullPaths: () => extractOrgOsRouteTreeFullPaths,
  formatOrgOsUiRouteContractFailure: () => formatOrgOsUiRouteContractFailure,
  formatOrgOsUiRouteContractIssue: () => formatOrgOsUiRouteContractIssue,
  handlers: () => handlers,
  mockAuthLoading: () => mockAuthLoading,
  mockAuthenticatedUser: () => mockAuthenticatedUser,
  mockUnauthenticatedUser: () => mockUnauthenticatedUser,
  mockUseAuth: () => mockUseAuth,
  mockWorkOSUser: () => mockWorkOSUser,
  normalizeOrgOsRoutePath: () => normalizeOrgOsRoutePath,
  ownsOrgOsSystem: () => ownsOrgOsSystem,
  render: () => renderWithProviders,
  renderHookWithProviders: () => renderHookWithProviders,
  renderWithProviders: () => renderWithProviders,
  server: () => server
});

// src/test-utils/render.tsx
var render_exports = {};
__export(render_exports, {
  TestProviders: () => TestProviders,
  createTestQueryClient: () => createTestQueryClient,
  createTestWrapper: () => createTestWrapper,
  render: () => renderWithProviders,
  renderHookWithProviders: () => renderHookWithProviders,
  renderWithProviders: () => renderWithProviders
});
__reExport(render_exports, react_star);
var mockApiRequest = async () => ({});
function createTestQueryClient() {
  return new QueryClient({
    defaultOptions: {
      queries: {
        retry: false,
        gcTime: 0,
        staleTime: 0
      },
      mutations: {
        retry: false
      }
    }
  });
}
var mockGetAccessToken = async () => "test-token";
function TestProviders({
  children,
  queryClient,
  getAccessToken = mockGetAccessToken,
  organizationId = "test-org-id",
  isOrganizationReady = true,
  apiRequest = mockApiRequest,
  isServiceReady
}) {
  const client = queryClient ?? createTestQueryClient();
  const serviceReady = isServiceReady ?? isOrganizationReady;
  return /* @__PURE__ */ jsx(MantineProvider, { children: /* @__PURE__ */ jsx(QueryClientProvider, { client, children: /* @__PURE__ */ jsx(
    ApiClientProvider,
    {
      getAccessToken,
      getOrganizationId: () => organizationId ?? null,
      organizationId,
      isOrganizationReady,
      children: /* @__PURE__ */ jsx(
        ElevasisServiceProvider,
        {
          apiRequest,
          workOSOrganizationId: organizationId ?? null,
          isReady: serviceReady,
          children
        }
      )
    }
  ) }) });
}
function renderWithProviders(ui, options) {
  const {
    queryClient,
    getAccessToken,
    organizationId,
    isOrganizationReady,
    apiRequest,
    isServiceReady,
    ...renderOptions
  } = options ?? {};
  return render(ui, {
    wrapper: ({ children }) => /* @__PURE__ */ jsx(
      TestProviders,
      {
        queryClient,
        getAccessToken,
        organizationId,
        isOrganizationReady,
        apiRequest,
        isServiceReady,
        children
      }
    ),
    ...renderOptions
  });
}
function renderHookWithProviders(hook, options) {
  const {
    queryClient,
    getAccessToken,
    organizationId,
    isOrganizationReady,
    apiRequest,
    isServiceReady,
    ...renderHookOptions
  } = options ?? {};
  return renderHook(hook, {
    wrapper: ({ children }) => /* @__PURE__ */ jsx(
      TestProviders,
      {
        queryClient,
        getAccessToken,
        organizationId,
        isOrganizationReady,
        apiRequest,
        isServiceReady,
        children
      }
    ),
    ...renderHookOptions
  });
}
function createTestWrapper(options) {
  return function Wrapper({ children }) {
    return /* @__PURE__ */ jsx(TestProviders, { ...options, children });
  };
}

// src/test-utils/index.ts
__reExport(test_utils_exports, render_exports);

// src/test-utils/orgOsUiRouteContract.ts
function normalizeOrgOsRoutePath(path) {
  const trimmed = path.trim();
  if (!trimmed || trimmed === "/") return "/";
  return trimmed.replace(/\/+$/, "") || "/";
}
function extractOrgOsRouteTreeFullPaths(routeTreeSource) {
  const paths = [...routeTreeSource.matchAll(/fullPath:\s*'([^']+)'/g)].map((match) => match[1]).filter((path) => Boolean(path)).map(normalizeOrgOsRoutePath);
  return new Set(paths);
}
function ownsOrgOsSystem(ownerSystemId, systemId) {
  return systemId === ownerSystemId || systemId.startsWith(`${ownerSystemId}.`);
}
function getOrgOsRouteContractSystems(organizationModel) {
  const { systems } = organizationModel;
  const arraySystems = systems.systems;
  if (Array.isArray(arraySystems)) return arraySystems;
  const result = [];
  const visit = (entries, prefix = "") => {
    for (const [key, system] of Object.entries(entries)) {
      const id = prefix ? `${prefix}.${key}` : system.id || key;
      result.push({ ...system, id });
      if (system.systems) visit(system.systems, id);
      if (system.subsystems) visit(system.subsystems, id);
    }
  };
  visit(systems);
  return result;
}
function collectOrgOsUiRouteContractIssues(options) {
  const { target, organizationModel, mode = "production" } = options;
  const routePaths = options.routePaths ?? (options.routeTreeSource ? extractOrgOsRouteTreeFullPaths(options.routeTreeSource) : void 0);
  if (!routePaths) {
    throw new Error("Org OS UI route contract requires either routeTreeSource or routePaths.");
  }
  const normalizedRoutePaths = new Set([...routePaths].map(normalizeOrgOsRoutePath));
  const systems = getOrgOsRouteContractSystems(organizationModel);
  const modelSystemIds = new Set(systems.map((system) => system.id));
  const issues = [];
  let checkedPathCount = 0;
  for (const systemId of target.systemIds) {
    if (!modelSystemIds.has(systemId)) {
      issues.push({
        target,
        kind: "missing-system",
        systemId
      });
    }
  }
  for (const system of systems) {
    const path = system.ui?.path ?? system.path;
    if (!path || system.enabled === false) continue;
    if (system.lifecycle === "archived" || system.lifecycle === "deprecated") continue;
    if (system.devOnly && mode === "production") continue;
    const ownerSystemId = target.systemIds.find((candidate) => ownsOrgOsSystem(candidate, system.id));
    if (!ownerSystemId) continue;
    checkedPathCount += 1;
    const normalizedPath = normalizeOrgOsRoutePath(path);
    if (!normalizedRoutePaths.has(normalizedPath)) {
      issues.push({
        target,
        kind: "missing-route",
        systemId: system.id,
        ownerSystemId,
        path: normalizedPath
      });
    }
  }
  return { issues, checkedPathCount };
}
function formatOrgOsUiRouteContractIssue(issue) {
  if (issue.kind === "missing-system") {
    return [
      `[missing-system] Registered SystemModule "${issue.systemId}" is not present in ${issue.target.orgModelSource}.`,
      "Fix:",
      `- If the system should ship in ${issue.target.name}, add it to the organization model.`,
      `- If it should not ship, remove that SystemModule from ${issue.target.shellSource}.`
    ].join("\n");
  }
  return [
    `[missing-route] System "${issue.systemId}" points to "${issue.path}", but ${issue.target.routeTreePath} does not contain that path.`,
    `Owner SystemModule: ${issue.ownerSystemId}`,
    "Fix one source of truth:",
    `- Add or rename the TanStack route file under ${issue.target.name}/src/routes so routeTree.gen.ts contains "${issue.path}".`,
    `- Or update ${issue.target.orgModelSource} so OrganizationModel.systems[].path matches the route that actually exists.`,
    `- Or disable/remove the system for ${issue.target.name} if this app intentionally does not ship it.`
  ].join("\n");
}
function formatOrgOsUiRouteContractFailure(issues) {
  const lines = [
    `Org OS UI route contract failed with ${issues.length} issue(s).`,
    "",
    "This check is derived from app-level contracts, not a route allowlist:",
    "- OrganizationModel.systems[].path is the expected path source.",
    "- routeTree.gen.ts fullPath entries are the actual generated routes.",
    "- SystemModule.systemId values define which Org OS branches this shell propagates.",
    "",
    "Do not add route-specific exceptions. Fix the route file, the Org model path, or the app system registration.",
    ""
  ];
  for (const issue of issues) {
    lines.push(`Target: ${issue.target.name}`, formatOrgOsUiRouteContractIssue(issue), "");
  }
  return lines.join("\n");
}
function assertOrgOsUiRouteContract(options) {
  const result = collectOrgOsUiRouteContractIssues(options);
  if (result.issues.length > 0) {
    throw new Error(formatOrgOsUiRouteContractFailure(result.issues));
  }
  return result;
}

export { TestProviders, assertOrgOsUiRouteContract, collectOrgOsUiRouteContractIssues, createTestQueryClient, createTestWrapper, extractOrgOsRouteTreeFullPaths, formatOrgOsUiRouteContractFailure, formatOrgOsUiRouteContractIssue, normalizeOrgOsRoutePath, ownsOrgOsSystem, renderWithProviders as render, renderHookWithProviders, renderWithProviders };
