Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added first-run setup end-to-end test; fixed setup screen reloading in new projects (#14747)
Damian Legawieca0151c15a268
diff --git a/.changeset/stable-route-tree-paths.md b/.changeset/stable-route-tree-paths.mdnew file mode 100644index 0000000000..2633844ceb--- /dev/null+++ b/.changeset/stable-route-tree-paths.md@@ -0,0 +1,8 @@+---+"@spree/dashboard-core": patch+"@spree/dashboard": patch+"@spree/seller-dashboard": patch+"@spree/cli": patch+---++Fixed the setup screen of a new project reloading while the merchant was filling it in. The generated route file now refers to installed packages by their stable location, and `spree add` generates it right after installing, so the first dev start has nothing to rewrite. Upgrades also no longer rewrite every line of that file, so its diff shows only the pages an upgrade added.diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.ymlindex c3dd2275ec..ea2e34116d 100644--- a/.github/workflows/packages.yml+++ b/.github/workflows/packages.yml@@ -189,6 +189,16 @@ jobs:E2E_PREVIEW: "1"run: pnpm test:e2e --shard=${{ matrix.shard }}/4+ # First-run setup needs a stack with no admin, which the main suite's+ # never has — it brings up its own Rails and database. One shard is+ # enough; it runs even when the main suite failed.+ - name: Run first-run setup E2E tests+ if: ${{ !cancelled() && matrix.shard == 1 }}+ working-directory: packages/dashboard+ env:+ E2E_PREVIEW: "1"+ run: pnpm test:e2e:first-run+- name: Upload Playwright reportif: failure()uses: actions/upload-artifact@v7@@ -197,6 +207,8 @@ jobs:path: |packages/dashboard/playwright-report/packages/dashboard/test-results/+ packages/dashboard/playwright-report-first-run/+ packages/dashboard/test-results-first-run/retention-days: 14# Stable single-status roll-up of the shard matrix, keeping the check namediff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.tsindex a167079037..dee9c255e4 100644--- a/packages/cli/src/commands/add.ts+++ b/packages/cli/src/commands/add.ts@@ -145,6 +145,7 @@ export async function addApp(try {await execa(pm, ['install'], { cwd: appDir })s.stop('Dependencies installed.')+ await generateRouteTree(appDir)} catch (err) {s.stop(pc.yellow(`${pm} install failed — run it manually in apps/${app.dir}/.`))p.log.warn(err instanceof Error ? err.message : String(err))@@ -194,6 +195,28 @@ function resolveBundledTemplate(app: AppSpec): string {process.exit(1)}+/**+ * Writes the app's `src/routeTree.gen.ts` for the packages just installed.+ *+ * The template's copy was generated in the monorepo, so the first dev start+ * would rewrite it — and Vite reloads the open page when it notices, which is+ * the setup screen a new project opens straight into. Loading the app's own+ * Vite config runs the same generator, with the same extensions, without+ * starting a server, so that first start finds nothing to change.+ */+async function generateRouteTree(appDir: string): Promise<void> {+ // Best effort: the dev server generates the file on start regardless.+ await execa(+ 'node',+ [+ '--input-type=module',+ '-e',+ "const { resolveConfig } = await import('vite'); await resolveConfig({}, 'serve')",+ ],+ { cwd: appDir, reject: false },+ )+}+/*** The bundled template ships its `.gitignore` as `gitignore.template`* (npm never packs `.gitignore` files) — restore the real name on scaffold.diff --git a/packages/cli/tests/add-dashboard.test.ts b/packages/cli/tests/add-dashboard.test.tsindex a8a3e5594e..bda8558408 100644--- a/packages/cli/tests/add-dashboard.test.ts+++ b/packages/cli/tests/add-dashboard.test.ts@@ -1,10 +1,13 @@import fs from 'node:fs'import os from 'node:os'import path from 'node:path'-import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { execa } from 'execa'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { addApp, ensureDashboardDevEnv } from '../src/commands/add.js'import type { ProjectContext } from '../src/types.js'+vi.mock('execa', () => ({ execa: vi.fn(async () => ({})) }))+// The two apps `spree add` scaffolds. Both go through addApp, so the same// battery runs against each — the seller panel is not a second-class path.const APPS = [@@ -78,6 +81,20 @@ describe.each(APPS)('addApp — $dir', (app) => {expect(fs.existsSync(path.join(dashboardDir, 'gitignore.template'))).toBe(false)})+ // The template's route file comes from the monorepo, so the first dev+ // start would rewrite it and reload the page the new merchant is on.+ it('generates the route file for the installed packages right after installing', async () => {+ vi.mocked(execa).mockClear()+ await addApp(ctx(), app, { template: templateDir, install: true, quiet: true })++ const appDir = path.join(projectDir, 'apps', app.dir)+ const calls = vi.mocked(execa).mock.calls+ expect(calls[0]).toEqual(['pnpm', ['install'], { cwd: appDir }])+ expect(calls[1][0]).toBe('node')+ expect((calls[1][1] as string[]).join(' ')).toContain("resolveConfig({}, 'serve')")+ expect(calls[1][2]).toMatchObject({ cwd: appDir, reject: false })+ })+it('is a no-op when the app directory already exists', async () => {await addApp(ctx(), app, { template: templateDir, install: false })const marker = path.join(projectDir, 'apps', app.dir, 'src', 'custom.ts')diff --git a/packages/dashboard-core/src/vite/discover.ts b/packages/dashboard-core/src/vite/discover.tsindex be38668f9d..099f27c363 100644--- a/packages/dashboard-core/src/vite/discover.ts+++ b/packages/dashboard-core/src/vite/discover.ts@@ -71,7 +71,9 @@ export function discoverDashboardPluginManifests(const routes = pkg.spree?.dashboard?.routesmanifests.push({name,- routesDir: routes ? path.resolve(path.dirname(manifestPath), routes) : undefined,+ routesDir: routes+ ? linkedPackagePath(root, name, path.resolve(path.dirname(manifestPath), routes))+ : undefined,})}return manifests@@ -125,6 +127,37 @@ export function discoverDashboardPlugins({ root, onWarn }: DiscoverOptions): strreturn discovered}+/**+ * Re-expresses a path inside an installed package through the package's+ * `node_modules/<name>` link, rather than the real location Node resolves to.+ *+ * Under pnpm the real location is `node_modules/.pnpm/<name>@<version>_<hash>/…`,+ * which changes with every install. The route generator writes these paths+ * into the host's committed `routeTree.gen.ts`, so a real location made the+ * file differ on a new project's first dev start and after every upgrade —+ * and each rewrite reloaded the open page. The link stays put across installs+ * and is the same inside the monorepo, so the file only changes when the+ * routes do.+ *+ * @param root host project root+ * @param packageName the package the path belongs to+ * @param resolvedPath a path inside that package, as Node resolved it+ * @returns the same path through the link, or `resolvedPath` when no link+ * leads to it (the package resolving itself, an unusual layout)+ */+export function linkedPackagePath(root: string, packageName: string, resolvedPath: string): string {+ const realPath = fs.realpathSync(resolvedPath)+ for (let dir = root; ; dir = path.dirname(dir)) {+ const link = path.join(dir, 'node_modules', packageName)+ if (fs.existsSync(path.join(link, 'package.json'))) {+ const inside = path.relative(fs.realpathSync(link), realPath)+ if (inside.startsWith('..') || path.isAbsolute(inside)) return resolvedPath+ return path.join(link, inside)+ }+ if (path.dirname(dir) === dir) return resolvedPath+ }+}+interface HostManifest {dependencies?: Record<string, string>devDependencies?: Record<string, string>diff --git a/packages/dashboard-core/tests/discover.test.ts b/packages/dashboard-core/tests/discover.test.tsindex 76832f06e2..d2dacc150f 100644--- a/packages/dashboard-core/tests/discover.test.ts+++ b/packages/dashboard-core/tests/discover.test.ts@@ -2,7 +2,7 @@ import fs from 'node:fs'import os from 'node:os'import path from 'node:path'import { afterEach, beforeEach, describe, expect, it } from 'vitest'-import { discoverDashboardPlugins } from '../src/vite/discover'+import { discoverDashboardPluginManifests, discoverDashboardPlugins } from '../src/vite/discover'/*** Each test builds a tiny fixture project on disk:@@ -154,3 +154,44 @@ describe('discoverDashboardPlugins', () => {expect(discoverDashboardPlugins({ root: fixture.root })).toEqual(['@acme/foo'])})})++describe('discoverDashboardPluginManifests', () => {+ let fixture: Fixture++ beforeEach(() => {+ fixture = makeFixture()+ })++ afterEach(() => {+ fixture.cleanup()+ })++ // pnpm's layout: the package really lives under a versioned `.pnpm/`+ // directory, reached through a `node_modules/<name>` link. The routes path+ // ends up in the host's committed route tree, so it must name the link —+ // the versioned directory changes with every install.+ it('reports routes through the node_modules link, not the versioned store path', () => {+ const store = path.join(+ fixture.root,+ 'node_modules/.pnpm/@[email protected]_abc123/node_modules/@acme/plugin',+ )+ fs.mkdirSync(path.join(store, 'src/routes'), { recursive: true })+ fs.writeFileSync(+ path.join(store, 'package.json'),+ JSON.stringify({+ name: '@acme/plugin',+ version: '1.0.0',+ main: 'index.js',+ spree: { dashboard: { plugin: true, routes: './src/routes' } },+ }),+ )+ fs.writeFileSync(path.join(store, 'index.js'), '')+ fs.mkdirSync(path.join(fixture.root, 'node_modules/@acme'), { recursive: true })+ fs.symlinkSync(store, path.join(fixture.root, 'node_modules/@acme/plugin'), 'dir')+ fixture.writeHost({ '@acme/plugin': '1.0.0' })++ const [manifest] = discoverDashboardPluginManifests({ root: fixture.root })++ expect(manifest.routesDir).toBe(path.join(fixture.root, 'node_modules/@acme/plugin/src/routes'))+ })+})diff --git a/packages/dashboard-starter/src/routeTree.gen.ts b/packages/dashboard-starter/src/routeTree.gen.tsindex 84ad6d2c65..47d18c2c9c 100644--- a/packages/dashboard-starter/src/routeTree.gen.ts+++ b/packages/dashboard-starter/src/routeTree.gen.ts@@ -8,106 +8,106 @@// You should NOT make any changes in this file as it will be overwritten.// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.-import { Route as rootRouteImport } from './../../dashboard/src/routes/__root'-import { Route as setupRouteImport } from './../../dashboard/src/routes/setup'-import { Route as resetPasswordRouteImport } from './../../dashboard/src/routes/reset-password'-import { Route as loginRouteImport } from './../../dashboard/src/routes/login'-import { Route as forgotPasswordRouteImport } from './../../dashboard/src/routes/forgot-password'-import { Route as authenticatedRouteImport } from './../../dashboard/src/routes/_authenticated'-import { Route as authenticatedIndexRouteImport } from './../../dashboard/src/routes/_authenticated/index'-import { Route as acceptInvitationDotinvitationIdRouteImport } from './../../dashboard/src/routes/accept-invitation.$invitationId'-import { Route as authenticatedStoreIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId'-import { Route as IndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/index'-import { Route as SuppliersRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/suppliers'-import { Route as SettingsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings'-import { Route as ReturnsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/returns'-import { Route as GettingStartedRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/getting-started'-import { Route as ExchangesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/exchanges'-import { Route as ClaimsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/claims'-import { Route as SplatRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/$'-import { Route as TransfersIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/transfers/index'-import { Route as SettingsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/index'-import { Route as SellersIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/sellers/index'-import { Route as ReportsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/reports/index'-import { Route as PurchaseOrdersIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/purchase-orders/index'-import { Route as PromotionsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/promotions/index'-import { Route as ProductsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/index'-import { Route as OrdersIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/orders/index'-import { Route as InventoryIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/inventory/index'-import { Route as CustomersIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/customers/index'-import { Route as CompaniesIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/companies/index'-import { Route as BrandsDotindexRouteImport } from './../../dashboard-plugin-example/src/routes/brands.index'-import { Route as TransfersNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/transfers/new'-import { Route as SettingsTaxRatesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/tax-rates'-import { Route as SettingsTaxCategoriesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/tax-categories'-import { Route as SettingsStoreRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/store'-import { Route as SettingsStockLocationsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/stock-locations'-import { Route as SettingsStaffRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/staff'-import { Route as SettingsSellerRequirementsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/seller-requirements'-import { Route as SettingsRolesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/roles'-import { Route as SettingsReasonsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/reasons'-import { Route as SettingsProductTypesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/product-types'-import { Route as SettingsPoliciesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/policies'-import { Route as SettingsPayoutsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/payouts'-import { Route as SettingsPaymentMethodsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/payment-methods'-import { Route as SettingsPackageTypesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/package-types'-import { Route as SettingsMarketsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/markets'-import { Route as SettingsMarketplaceRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/marketplace'-import { Route as SettingsIntegrationsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/integrations'-import { Route as SettingsEmailsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/emails'-import { Route as SettingsCustomFieldDefinitionsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/custom-field-definitions'-import { Route as SettingsCommissionRatesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/commission-rates'-import { Route as SettingsChannelsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/channels'-import { Route as SettingsApiKeysRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/api-keys'-import { Route as SettingsAllowedOriginsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/allowed-origins'-import { Route as SellersTransfersRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/sellers/transfers'-import { Route as SellersCommissionRatesRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/sellers/commission-rates'-import { Route as SellersSellerIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/sellers/$sellerId'-import { Route as ReportsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/reports/new'-import { Route as ReportsReportIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/reports/$reportId'-import { Route as PurchaseOrdersNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/purchase-orders/new'-import { Route as PromotionsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/promotions/new'-import { Route as PromotionsGiftCardsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/promotions/gift-cards'-import { Route as PromotionsPromotionIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/promotions/$promotionId'-import { Route as ProductsTranslationsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/translations'-import { Route as ProductsOptionsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/options'-import { Route as ProductsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/new'-import { Route as ProductsMediaRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/media'-import { Route as ProductsProductIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/$productId'-import { Route as OrdersNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/orders/new'-import { Route as OrdersDraftsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/orders/drafts'-import { Route as LoyaltyStoreCreditsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/loyalty/store-credits'-import { Route as LoyaltyGiftCardsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards'-import { Route as CustomersGroupsRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/customers/groups'-import { Route as CustomersCustomerIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/customers/$customerId'-import { Route as CompaniesCompanyIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/companies/$companyId'-import { Route as BrandsDotbrandIdRouteImport } from './../../dashboard-plugin-example/src/routes/brands.$brandId'-import { Route as TransfersTransferIdIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/transfers/$transferId/index'-import { Route as SettingsWebhooksIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/webhooks/index'-import { Route as SettingsImportsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/imports/index'-import { Route as SettingsDeliveryProfilesIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/index'-import { Route as SellersPayoutsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/sellers/payouts/index'-import { Route as PurchaseOrdersPurchaseOrderIdIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/purchase-orders/$purchaseOrderId/index'-import { Route as ProductsPriceListsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/price-lists/index'-import { Route as ProductsCollectionsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/collections/index'-import { Route as ProductsCategoriesIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/categories/index'-import { Route as ProductsCatalogsIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/catalogs/index'-import { Route as OrdersOrderIdIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/orders/$orderId/index'-import { Route as TransfersTransferIdEditRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/transfers/$transferId/edit'-import { Route as SettingsWebhooksWebhookEndpointIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/webhooks/$webhookEndpointId'-import { Route as SellersPayoutsPayoutIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId'-import { Route as PurchaseOrdersPurchaseOrderIdEditRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/purchase-orders/$purchaseOrderId/edit'-import { Route as ProductsPriceListsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/price-lists/new'-import { Route as ProductsCollectionsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/collections/new'-import { Route as ProductsCollectionsCollectionIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/collections/$collectionId'-import { Route as ProductsCategoriesNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/categories/new'-import { Route as ProductsCategoriesCategoryIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/categories/$categoryId'-import { Route as ProductsCatalogsCatalogIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId'-import { Route as OrdersOrderIdEditRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit'-import { Route as SettingsDeliveryProfilesProfileIdIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/index'-import { Route as ProductsPriceListsPriceListIdIndexRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/products/price-lists/$priceListId/index'-import { Route as SettingsDeliveryProfilesProfileIdMethodsNewRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/methods/new'-import { Route as SettingsDeliveryProfilesProfileIdMethodsMethodIdRouteImport } from './../../dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/methods/$methodId'+import { Route as rootRouteImport } from './../node_modules/@spree/dashboard/src/routes/__root'+import { Route as setupRouteImport } from './../node_modules/@spree/dashboard/src/routes/setup'+import { Route as resetPasswordRouteImport } from './../node_modules/@spree/dashboard/src/routes/reset-password'+import { Route as loginRouteImport } from './../node_modules/@spree/dashboard/src/routes/login'+import { Route as forgotPasswordRouteImport } from './../node_modules/@spree/dashboard/src/routes/forgot-password'+import { Route as authenticatedRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated'+import { Route as authenticatedIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/index'+import { Route as acceptInvitationDotinvitationIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/accept-invitation.$invitationId'+import { Route as authenticatedStoreIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId'+import { Route as IndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/index'+import { Route as SuppliersRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/suppliers'+import { Route as SettingsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings'+import { Route as ReturnsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/returns'+import { Route as GettingStartedRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/getting-started'+import { Route as ExchangesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/exchanges'+import { Route as ClaimsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/claims'+import { Route as SplatRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/$'+import { Route as TransfersIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/transfers/index'+import { Route as SettingsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/index'+import { Route as SellersIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/sellers/index'+import { Route as ReportsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/reports/index'+import { Route as PurchaseOrdersIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/purchase-orders/index'+import { Route as PromotionsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/promotions/index'+import { Route as ProductsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/index'+import { Route as OrdersIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/orders/index'+import { Route as InventoryIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/inventory/index'+import { Route as CustomersIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/customers/index'+import { Route as CompaniesIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/companies/index'+import { Route as BrandsDotindexRouteImport } from './../node_modules/@spree/dashboard-plugin-example/src/routes/brands.index'+import { Route as TransfersNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/transfers/new'+import { Route as SettingsTaxRatesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/tax-rates'+import { Route as SettingsTaxCategoriesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/tax-categories'+import { Route as SettingsStoreRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/store'+import { Route as SettingsStockLocationsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/stock-locations'+import { Route as SettingsStaffRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/staff'+import { Route as SettingsSellerRequirementsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/seller-requirements'+import { Route as SettingsRolesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/roles'+import { Route as SettingsReasonsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/reasons'+import { Route as SettingsProductTypesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/product-types'+import { Route as SettingsPoliciesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/policies'+import { Route as SettingsPayoutsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/payouts'+import { Route as SettingsPaymentMethodsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/payment-methods'+import { Route as SettingsPackageTypesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/package-types'+import { Route as SettingsMarketsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/markets'+import { Route as SettingsMarketplaceRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/marketplace'+import { Route as SettingsIntegrationsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/integrations'+import { Route as SettingsEmailsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/emails'+import { Route as SettingsCustomFieldDefinitionsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/custom-field-definitions'+import { Route as SettingsCommissionRatesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/commission-rates'+import { Route as SettingsChannelsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/channels'+import { Route as SettingsApiKeysRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/api-keys'+import { Route as SettingsAllowedOriginsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/allowed-origins'+import { Route as SellersTransfersRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/sellers/transfers'+import { Route as SellersCommissionRatesRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/sellers/commission-rates'+import { Route as SellersSellerIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/sellers/$sellerId'+import { Route as ReportsNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/reports/new'+import { Route as ReportsReportIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/reports/$reportId'+import { Route as PurchaseOrdersNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/purchase-orders/new'+import { Route as PromotionsNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/promotions/new'+import { Route as PromotionsGiftCardsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/promotions/gift-cards'+import { Route as PromotionsPromotionIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/promotions/$promotionId'+import { Route as ProductsTranslationsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/translations'+import { Route as ProductsOptionsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/options'+import { Route as ProductsNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/new'+import { Route as ProductsMediaRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/media'+import { Route as ProductsProductIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/$productId'+import { Route as OrdersNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/orders/new'+import { Route as OrdersDraftsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/orders/drafts'+import { Route as LoyaltyStoreCreditsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/loyalty/store-credits'+import { Route as LoyaltyGiftCardsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards'+import { Route as CustomersGroupsRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/customers/groups'+import { Route as CustomersCustomerIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/customers/$customerId'+import { Route as CompaniesCompanyIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/companies/$companyId'+import { Route as BrandsDotbrandIdRouteImport } from './../node_modules/@spree/dashboard-plugin-example/src/routes/brands.$brandId'+import { Route as TransfersTransferIdIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/transfers/$transferId/index'+import { Route as SettingsWebhooksIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/webhooks/index'+import { Route as SettingsImportsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/imports/index'+import { Route as SettingsDeliveryProfilesIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/index'+import { Route as SellersPayoutsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/index'+import { Route as PurchaseOrdersPurchaseOrderIdIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/purchase-orders/$purchaseOrderId/index'+import { Route as ProductsPriceListsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/price-lists/index'+import { Route as ProductsCollectionsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/collections/index'+import { Route as ProductsCategoriesIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/categories/index'+import { Route as ProductsCatalogsIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/catalogs/index'+import { Route as OrdersOrderIdIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/index'+import { Route as TransfersTransferIdEditRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/transfers/$transferId/edit'+import { Route as SettingsWebhooksWebhookEndpointIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/webhooks/$webhookEndpointId'+import { Route as SellersPayoutsPayoutIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId'+import { Route as PurchaseOrdersPurchaseOrderIdEditRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/purchase-orders/$purchaseOrderId/edit'+import { Route as ProductsPriceListsNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/price-lists/new'+import { Route as ProductsCollectionsNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/collections/new'+import { Route as ProductsCollectionsCollectionIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/collections/$collectionId'+import { Route as ProductsCategoriesNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/categories/new'+import { Route as ProductsCategoriesCategoryIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/categories/$categoryId'+import { Route as ProductsCatalogsCatalogIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId'+import { Route as OrdersOrderIdEditRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit'+import { Route as SettingsDeliveryProfilesProfileIdIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/index'+import { Route as ProductsPriceListsPriceListIdIndexRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/products/price-lists/$priceListId/index'+import { Route as SettingsDeliveryProfilesProfileIdMethodsNewRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/methods/new'+import { Route as SettingsDeliveryProfilesProfileIdMethodsMethodIdRouteImport } from './../node_modules/@spree/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/methods/$methodId'const setupRoute = setupRouteImport.update({id: '/setup',diff --git a/packages/dashboard/.gitignore b/packages/dashboard/.gitignoreindex daa2dde29d..4357572048 100644--- a/packages/dashboard/.gitignore+++ b/packages/dashboard/.gitignore@@ -27,6 +27,10 @@ dist-ssr# Playwright/test-results//playwright-report/+/playwright-report-first-run/+/test-results-first-run//playwright/.cache//e2e/.credentials.json/e2e/.rails.pid+/e2e/.first-run.json+/e2e/.first-run-rails.piddiff --git a/packages/dashboard/e2e/first-run/global-setup.ts b/packages/dashboard/e2e/first-run/global-setup.tsnew file mode 100644index 0000000000..55ea7c83f5--- /dev/null+++ b/packages/dashboard/e2e/first-run/global-setup.ts@@ -0,0 +1,39 @@+import { writeFileSync } from 'node:fs'+import { resolve } from 'node:path'+import { FIRST_RUN_CREDENTIALS_FILE, FIRST_RUN_RAILS_PID_FILE } from '../paths'+import { API_GEM_DIR, rmIfExists, runRailsBootstrap, startRails } from '../rails'++export const FIRST_RUN_RAILS_PORT = process.env.E2E_FIRST_RUN_RAILS_PORT || '3011'+export const FIRST_RUN_VITE_PORT = process.env.E2E_FIRST_RUN_VITE_PORT || '5176'++// A database of its own: setup only opens while no admin exists, and the main+// suite's database always has one.+const SQLITE = resolve(API_GEM_DIR, 'spec/dummy/db/spree_test_first_run.sqlite3')++const RAILS_ENV = {+ ...process.env,+ RAILS_ENV: 'test',+ PORT: FIRST_RUN_RAILS_PORT,+ DATABASE_URL: `sqlite3:${SQLITE}`,+ // The setup link is built from this, so the spec opens exactly the link an+ // install prints rather than one it assembles itself.+ SPREE_DASHBOARD_URL: `http://localhost:${FIRST_RUN_VITE_PORT}`,+}++// Seeds the way a fresh install does, which leaves no admin and a setup token+// on the default store.+const BOOTSTRAP_RUBY = [+ "load Rails.root.join('db', 'schema.rb').to_s",+ 'Spree::Seeds::All.call',+ 'require "json"',+ 'raise "the seed created an admin, so setup is closed" if Spree.admin_user_class.exists?',+ 'puts JSON.generate(setup_url: Spree::Store.default.setup_url)',+].join('; ')++export default async function globalSetup() {+ rmIfExists(SQLITE)++ writeFileSync(FIRST_RUN_CREDENTIALS_FILE, runRailsBootstrap(BOOTSTRAP_RUBY, RAILS_ENV))++ await startRails(FIRST_RUN_RAILS_PORT, RAILS_ENV, FIRST_RUN_RAILS_PID_FILE)+}diff --git a/packages/dashboard/e2e/first-run/global-teardown.ts b/packages/dashboard/e2e/first-run/global-teardown.tsnew file mode 100644index 0000000000..dfc132a011--- /dev/null+++ b/packages/dashboard/e2e/first-run/global-teardown.ts@@ -0,0 +1,6 @@+import { FIRST_RUN_RAILS_PID_FILE } from '../paths'+import { stopRails } from '../rails'++export default async function globalTeardown() {+ await stopRails(FIRST_RUN_RAILS_PID_FILE)+}diff --git a/packages/dashboard/e2e/first-run/setup.spec.ts b/packages/dashboard/e2e/first-run/setup.spec.tsnew file mode 100644index 0000000000..e59c4f0840--- /dev/null+++ b/packages/dashboard/e2e/first-run/setup.spec.ts@@ -0,0 +1,109 @@+import { readFileSync } from 'node:fs'+import { expect, type Page, test } from '@playwright/test'+import { FIRST_RUN_CREDENTIALS_FILE } from '../paths'++// The link the seed printed, token included — the one a new merchant opens.+const { setup_url: setupUrl } = JSON.parse(readFileSync(FIRST_RUN_CREDENTIALS_FILE, 'utf-8')) as {+ setup_url: string+}++const merchant = {+ storeName: `First Run Store ${Date.now()}`,+ firstName: 'Ada',+ lastName: 'Merchant',+ email: `owner-${Date.now()}@example.com`,+ password: 'first-run-123',+}++async function fillSetupForm(page: Page) {+ await expect(page.getByRole('heading', { name: 'Set up Spree' })).toBeVisible()++ await page.getByLabel('Store name').fill(merchant.storeName)++ // Picking a country brings its currency and language with it.+ await page.getByLabel('Country').click()+ await page.getByPlaceholder('Search countries').fill('Poland')+ await page.getByRole('option', { name: /Poland/ }).click()+ await expect(page.getByLabel('Currency')).toContainText('PLN')+ await expect(page.getByLabel('Language')).toContainText('Polish')++ // The admin's dashboard follows this language, and the rest of the spec+ // reads English copy.+ await page.getByLabel('Language').click()+ await page.getByRole('option', { name: 'English' }).click()+ await expect(page.getByLabel('Currency')).toContainText('PLN')++ await page.getByLabel('First name').fill(merchant.firstName)+ await page.getByLabel('Last name').fill(merchant.lastName)+ await page.getByLabel('Email').fill(merchant.email)+ await page.getByLabel('Password', { exact: true }).fill(merchant.password)+ await page.getByLabel('Confirm password').fill(merchant.password)++ // Sample data downloads product images for minutes — not part of this flow.+ await page.getByRole('checkbox', { name: 'Load sample data' }).uncheck()+}++// Serial and in order: completing setup closes it for the rest of the run.+test.describe+ .serial('first-run setup', () => {+ test('the sign-in page points a fresh installation to setup', async ({ page }) => {+ await page.goto('/login')++ await expect(page.getByText("This installation isn't set up yet")).toBeVisible()+ await page.getByRole('link', { name: 'Go to setup' }).click()++ // That link carries no token — only the printed one does.+ await expect(page.getByRole('heading', { name: 'Setup link required' })).toBeVisible()+ })++ test('refuses a setup link with the wrong token', async ({ page }) => {+ await page.goto(setupUrl.replace(/token=[^&]+/, 'token=not-the-token'))+ await fillSetupForm(page)+ await page.getByRole('button', { name: 'Complete setup' }).click()++ await expect(+ page.getByText(+ 'This installation is already set up. Sign in with your admin account instead.',+ ),+ ).toBeVisible()+ await expect(page).toHaveURL(/\/setup/)+ })++ test('creates the admin account, sets up the store and signs the merchant in', async ({+ page,+ }) => {+ await page.goto(setupUrl)+ await fillSetupForm(page)+ await page.getByRole('button', { name: 'Complete setup' }).click()++ await expect(page.getByText('Welcome, your store is now ready!')).toBeVisible({+ timeout: 20_000,+ })+ await expect(page).toHaveURL(/\/getting-started/)+ await expect(page.getByRole('heading', { name: 'Getting Started' })).toBeVisible()+ await expect(page.getByText(merchant.storeName).first()).toBeVisible()++ await page.getByRole('button', { name: 'User menu' }).click()+ await page.getByRole('menuitem', { name: 'Log out' }).click()+ await expect(page).toHaveURL(/\/login/)+ })++ test('closes setup once an admin exists', async ({ page }) => {+ await page.goto('/login')+ await expect(page.getByRole('heading', { name: 'Welcome back' })).toBeVisible()+ await expect(page.getByText("This installation isn't set up yet")).toBeHidden()++ await page.goto(setupUrl)+ await expect(page.getByRole('heading', { name: 'Setup is not available' })).toBeVisible()+ })++ test('the new admin signs in with the account created during setup', async ({ page }) => {+ await page.goto('/login')+ await page.getByLabel('Email').fill(merchant.email)+ await page.getByLabel('Password').fill(merchant.password)+ await page.getByRole('button', { name: 'Sign in' }).click()++ await expect(page).not.toHaveURL(/\/login/, { timeout: 15_000 })+ await expect(page.getByText(merchant.storeName).first()).toBeVisible()+ })+ })diff --git a/packages/dashboard/e2e/global-setup.ts b/packages/dashboard/e2e/global-setup.tsindex ff137acce6..ab74c033e3 100644--- a/packages/dashboard/e2e/global-setup.ts+++ b/packages/dashboard/e2e/global-setup.ts@@ -1,5 +1,4 @@-import { type ChildProcess, spawn, spawnSync } from 'node:child_process'-import { unlinkSync, writeFileSync } from 'node:fs'+import { writeFileSync } from 'node:fs'import { resolve } from 'node:path'import {FIXTURE_BULK_CATEGORY,@@ -40,9 +39,9 @@ import {FIXTURE_TRANSFER_SKU,FIXTURE_TRANSFER_SOURCE,} from './helpers'-import { ASYNC_JOBS_INITIALIZER, CREDENTIALS_FILE, E2E_DIR, RAILS_PID_FILE } from './paths'+import { ASYNC_JOBS_INITIALIZER, CREDENTIALS_FILE, RAILS_PID_FILE } from './paths'+import { API_GEM_DIR, rmIfExists, runRailsBootstrap, startRails } from './rails'-const API_GEM_DIR = resolve(E2E_DIR, '../../../spree/api')const PORT = process.env.E2E_RAILS_PORT || '3010'// Mirrors `spec/dummy/config/database.yml`.const TEST_SQLITE = resolve(API_GEM_DIR, 'spec/dummy/db/spree_test.sqlite3')@@ -156,30 +155,6 @@ const BOOTSTRAP_RUBY = ['puts JSON.generate(api_url: "http://localhost:#{port}", admin_email: admin.email, admin_password: "spree123", store_id: s.prefixed_id, store_name: s.name)',].join('; ')-function rmIfExists(path: string) {- try {- unlinkSync(path)- } catch (e) {- if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e- }-}--async function waitForServer(url: string, timeoutMs = 30_000): Promise<void> {- const start = Date.now()- while (Date.now() - start < timeoutMs) {- try {- const res = await fetch(url)- if (res.status < 500) return- } catch {- /* not ready */- }- await new Promise((r) => setTimeout(r, 500))- }- throw new Error(`Server did not start within ${timeoutMs}ms at ${url}`)-}--let serverProcess: ChildProcess | null = null-export default async function globalSetup() {rmIfExists(TEST_SQLITE)@@ -197,36 +172,8 @@ export default async function globalSetup() {].join('\n'),)- // Pass the script via argv to sidestep shell quoting (the Ruby contains- // both single and double quotes).- const result = spawnSync('bundle', ['exec', 'spec/dummy/bin/rails', 'runner', BOOTSTRAP_RUBY], {- cwd: API_GEM_DIR,- encoding: 'utf-8',- timeout: 120_000,- maxBuffer: 10 * 1024 * 1024,- env: RAILS_ENV,- })- if (result.status !== 0) {- throw new Error(`Bootstrap runner failed:\n${result.stderr}\n${result.stdout}`)- }- const jsonMatch = result.stdout.match(/\{.*\}\s*$/)- if (!jsonMatch) {- throw new Error(`Failed to parse credentials from runner output:\n${result.stdout}`)- }- writeFileSync(CREDENTIALS_FILE, jsonMatch[0])-- serverProcess = spawn(- 'bundle',- ['exec', 'spec/dummy/bin/rails', 'server', '-p', PORT, '-e', 'test'],- { cwd: API_GEM_DIR, stdio: ['ignore', 'pipe', 'pipe'], env: RAILS_ENV },- )-- serverProcess.stderr?.on('data', (data: Buffer) => {- const msg = data.toString()- if (msg.includes('Error') || msg.includes('error')) console.error('[rails]', msg)- })-- if (serverProcess.pid) writeFileSync(RAILS_PID_FILE, String(serverProcess.pid))+ const credentials = runRailsBootstrap(BOOTSTRAP_RUBY, RAILS_ENV)+ writeFileSync(CREDENTIALS_FILE, credentials)- await waitForServer(`http://localhost:${PORT}/api/v3/admin/me`)+ await startRails(PORT, RAILS_ENV, RAILS_PID_FILE)}diff --git a/packages/dashboard/e2e/global-teardown.ts b/packages/dashboard/e2e/global-teardown.tsindex 821829c414..9656186a23 100644--- a/packages/dashboard/e2e/global-teardown.ts+++ b/packages/dashboard/e2e/global-teardown.ts@@ -1,30 +1,7 @@-import { readFileSync, unlinkSync } from 'node:fs'import { ASYNC_JOBS_INITIALIZER, RAILS_PID_FILE } from './paths'+import { rmIfExists, stopRails } from './rails'export default async function globalTeardown() {- try {- unlinkSync(ASYNC_JOBS_INITIALIZER)- } catch (e) {- if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e- }-- let pid: number- try {- pid = Number.parseInt(readFileSync(RAILS_PID_FILE, 'utf-8'), 10)- } catch (e) {- if ((e as NodeJS.ErrnoException).code === 'ENOENT') return- throw e- }-- try {- process.kill(pid, 'SIGTERM')- } catch {- // Process already dead.- }-- try {- unlinkSync(RAILS_PID_FILE)- } catch (e) {- if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e- }+ rmIfExists(ASYNC_JOBS_INITIALIZER)+ await stopRails(RAILS_PID_FILE)}diff --git a/packages/dashboard/e2e/paths.ts b/packages/dashboard/e2e/paths.tsindex 544bb4a8d9..5531d84839 100644--- a/packages/dashboard/e2e/paths.ts+++ b/packages/dashboard/e2e/paths.ts@@ -10,3 +10,7 @@ export const ASYNC_JOBS_INITIALIZER = resolve(E2E_DIR,'../../../spree/api/spec/dummy/config/initializers/zz_dashboard_e2e_async_jobs.rb',)+// The first-run setup suite runs its own Rails against its own database, so+// its state files live apart from the main suite's.+export const FIRST_RUN_CREDENTIALS_FILE = resolve(E2E_DIR, '.first-run.json')+export const FIRST_RUN_RAILS_PID_FILE = resolve(E2E_DIR, '.first-run-rails.pid')diff --git a/packages/dashboard/e2e/rails.ts b/packages/dashboard/e2e/rails.tsnew file mode 100644index 0000000000..b906d0fffa--- /dev/null+++ b/packages/dashboard/e2e/rails.ts@@ -0,0 +1,133 @@+import { type ChildProcess, spawn, spawnSync } from 'node:child_process'+import { readFileSync, unlinkSync, writeFileSync } from 'node:fs'+import { createServer } from 'node:net'+import { resolve } from 'node:path'+import { E2E_DIR } from './paths'++export const API_GEM_DIR = resolve(E2E_DIR, '../../../spree/api')++export function rmIfExists(path: string) {+ try {+ unlinkSync(path)+ } catch (e) {+ if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e+ }+}++/**+ * Runs Ruby in the dummy app and returns the JSON object it prints last —+ * whatever the script needs to hand back to the specs.+ */+export function runRailsBootstrap(ruby: string, env: NodeJS.ProcessEnv): string {+ // The script goes through argv to sidestep shell quoting (the Ruby contains+ // both single and double quotes).+ const result = spawnSync('bundle', ['exec', 'spec/dummy/bin/rails', 'runner', ruby], {+ cwd: API_GEM_DIR,+ encoding: 'utf-8',+ timeout: 120_000,+ maxBuffer: 10 * 1024 * 1024,+ env,+ })+ if (result.status !== 0) {+ throw new Error(`Bootstrap runner failed:\n${result.stderr}\n${result.stdout}`)+ }+ const jsonMatch = result.stdout.match(/\{.*\}\s*$/)+ if (!jsonMatch) {+ throw new Error(`Failed to parse bootstrap output:\n${result.stdout}`)+ }+ return jsonMatch[0]+}++// Anything already listening on the port would answer the readiness probe+// long before Rails boots, handing the suite someone else's database.+async function assertPortFree(port: string): Promise<void> {+ await new Promise<void>((resolvePromise, reject) => {+ const probe = createServer()+ probe.once('error', () =>+ reject(new Error(`Port ${port} is already in use — stop whatever is listening on it`)),+ )+ probe.listen(Number(port), () => probe.close(() => resolvePromise()))+ })+}++// A server that exits before answering fails the start instead of timing out.+async function waitForServer(+ url: string,+ serverProcess: ChildProcess,+ timeoutMs = 30_000,+): Promise<void> {+ let exitCode: number | null = null+ serverProcess.once('exit', (code) => {+ exitCode = code ?? -1+ })++ const deadline = Date.now() + timeoutMs+ while (Date.now() < deadline) {+ if (exitCode !== null)+ throw new Error(`Rails exited with code ${exitCode} before ${url} answered`)+ try {+ const res = await fetch(url, {+ signal: AbortSignal.timeout(Math.max(deadline - Date.now(), 1)),+ })+ if (exitCode === null && res.status < 500) return+ } catch {+ /* not ready */+ }+ await new Promise((r) => setTimeout(r, 500))+ }+ throw new Error(`Server did not start within ${timeoutMs}ms at ${url}`)+}++export async function startRails(port: string, env: NodeJS.ProcessEnv, pidFile: string) {+ await assertPortFree(port)++ const serverProcess: ChildProcess = spawn(+ 'bundle',+ ['exec', 'spec/dummy/bin/rails', 'server', '-p', port, '-e', 'test'],+ { cwd: API_GEM_DIR, stdio: ['ignore', 'pipe', 'pipe'], env },+ )++ serverProcess.stderr?.on('data', (data: Buffer) => {+ const msg = data.toString()+ if (msg.includes('Error') || msg.includes('error')) console.error('[rails]', msg)+ })++ if (serverProcess.pid) writeFileSync(pidFile, String(serverProcess.pid))++ await waitForServer(`http://localhost:${port}/api/v3/admin/me`, serverProcess)+}++function isRunning(pid: number): boolean {+ try {+ process.kill(pid, 0)+ return true+ } catch {+ return false+ }+}++// Waits for the server to exit, so a run started straight after this one+// cannot find the old server still holding its port or database.+export async function stopRails(pidFile: string, timeoutMs = 15_000) {+ let pid: number+ try {+ pid = Number.parseInt(readFileSync(pidFile, 'utf-8'), 10)+ } catch (e) {+ if ((e as NodeJS.ErrnoException).code === 'ENOENT') return+ throw e+ }++ try {+ process.kill(pid, 'SIGTERM')+ } catch {+ // Process already dead.+ }++ const deadline = Date.now() + timeoutMs+ while (isRunning(pid) && Date.now() < deadline) {+ await new Promise((r) => setTimeout(r, 200))+ }+ if (isRunning(pid)) process.kill(pid, 'SIGKILL')++ rmIfExists(pidFile)+}diff --git a/packages/dashboard/package.json b/packages/dashboard/package.jsonindex 54a43a0e92..5529849c95 100644--- a/packages/dashboard/package.json+++ b/packages/dashboard/package.json@@ -53,6 +53,7 @@"test:watch": "vitest","test:e2e": "playwright test","test:e2e:ui": "playwright test --ui",+ "test:e2e:first-run": "playwright test -c playwright.first-run.config.ts","test:e2e:install": "playwright install chromium","prepublishOnly": "tsup"},diff --git a/packages/dashboard/playwright.config.ts b/packages/dashboard/playwright.config.tsindex b225565cf8..94927199ec 100644--- a/packages/dashboard/playwright.config.ts+++ b/packages/dashboard/playwright.config.ts@@ -18,6 +18,8 @@ const PREVIEW = process.env.E2E_PREVIEW === '1'export default defineConfig({testDir: './e2e',+ // Needs a stack with no admin — see playwright.first-run.config.ts.+ testIgnore: 'first-run/**',// Sequential per machine — the global Rails server + SQLite test DB are// shared across specs, and the suite mutates server state (store settings,// the admin profile, creating + accepting invitations), so concurrentdiff --git a/packages/dashboard/playwright.first-run.config.ts b/packages/dashboard/playwright.first-run.config.tsnew file mode 100644index 0000000000..5c2c099b9d--- /dev/null+++ b/packages/dashboard/playwright.first-run.config.ts@@ -0,0 +1,49 @@+import { defineConfig, devices } from '@playwright/test'+import { FIRST_RUN_RAILS_PORT, FIRST_RUN_VITE_PORT } from './e2e/first-run/global-setup'++const PREVIEW = process.env.E2E_PREVIEW === '1'++// First-run setup only opens on an installation with no admin, and the main+// suite's stack always has one. This suite gets its own Rails, database and+// Vite on their own ports, so it can run next to the main suite. Completing+// setup closes it for good, so every run starts from a fresh database.+export default defineConfig({+ testDir: './e2e/first-run',+ fullyParallel: false,+ workers: 1,++ // Own output folders: CI runs this after the main suite on the same machine+ // and uploads both reports.+ reporter: process.env.CI+ ? [['github'], ['html', { open: 'never', outputFolder: 'playwright-report-first-run' }]]+ : 'list',+ outputDir: 'test-results-first-run',+ // A retry would meet a database that setup has already closed.+ retries: 0,+ timeout: 60_000,+ expect: { timeout: 10_000 },++ use: {+ baseURL: `http://localhost:${FIRST_RUN_VITE_PORT}`,+ trace: 'retain-on-failure',+ screenshot: 'only-on-failure',+ video: 'retain-on-failure',+ },++ projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],++ globalSetup: './e2e/first-run/global-setup.ts',+ globalTeardown: './e2e/first-run/global-teardown.ts',++ webServer: {+ command: PREVIEW+ ? `pnpm preview --port ${FIRST_RUN_VITE_PORT} --strictPort`+ : `pnpm dev --port ${FIRST_RUN_VITE_PORT} --strictPort`,+ url: `http://localhost:${FIRST_RUN_VITE_PORT}`,+ reuseExistingServer: false,+ timeout: 60_000,+ stdout: 'ignore',+ stderr: 'pipe',+ env: { VITE_API_PROXY_TARGET: `http://localhost:${FIRST_RUN_RAILS_PORT}` },+ },+})diff --git a/packages/dashboard/src/vite/index.ts b/packages/dashboard/src/vite/index.tsindex 67b02de523..d3bccbf3b9 100644--- a/packages/dashboard/src/vite/index.ts+++ b/packages/dashboard/src/vite/index.ts@@ -19,7 +19,10 @@ import {type SpreeDashboardPluginOptions as CoreOptions,spreeDashboardPlugin as spreeDashboardCorePlugin,} from '@spree/dashboard-core/vite'-import { discoverDashboardPluginManifests } from '@spree/dashboard-core/vite/discover'+import {+ discoverDashboardPluginManifests,+ linkedPackagePath,+} from '@spree/dashboard-core/vite/discover'import { TanStackRouterVite } from '@tanstack/router-plugin/vite'import { index, layout, physical, rootRoute, route } from '@tanstack/virtual-file-routes'import type { PluginOption } from 'vite'@@ -69,7 +72,11 @@ function dashboardRouterPlugin(hostRoot: string, options: SpreeDashboardPluginOp// `@spree/dashboard` lives (workspace symlink or npm install). The `.`// export maps to a file in src/, so `routes/` is its sibling directory.const shellEntry = fromHost.resolve('@spree/dashboard')- const shellRoutesDir = path.join(path.dirname(shellEntry), 'routes')+ const shellRoutesDir = linkedPackagePath(+ hostRoot,+ '@spree/dashboard',+ path.join(path.dirname(shellEntry), 'routes'),+ )const manifests = discoverDashboardPluginManifests({ root: hostRoot, onWarn: (msg) => console.warn(`[@spree/dashboard/vite] ${msg}`) },diff --git a/packages/seller-dashboard-starter/src/routeTree.gen.ts b/packages/seller-dashboard-starter/src/routeTree.gen.tsindex acf4378291..2ebeb09b76 100644--- a/packages/seller-dashboard-starter/src/routeTree.gen.ts+++ b/packages/seller-dashboard-starter/src/routeTree.gen.ts@@ -8,32 +8,32 @@// You should NOT make any changes in this file as it will be overwritten.// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.-import { Route as rootRouteImport } from './../../seller-dashboard/src/routes/__root'-import { Route as resetPasswordRouteImport } from './../../seller-dashboard/src/routes/reset-password'-import { Route as loginRouteImport } from './../../seller-dashboard/src/routes/login'-import { Route as forgotPasswordRouteImport } from './../../seller-dashboard/src/routes/forgot-password'-import { Route as authenticatedRouteImport } from './../../seller-dashboard/src/routes/_authenticated'-import { Route as authenticatedIndexRouteImport } from './../../seller-dashboard/src/routes/_authenticated/index'-import { Route as acceptInvitationDotinvitationIdRouteImport } from './../../seller-dashboard/src/routes/accept-invitation.$invitationId'-import { Route as authenticatedSellerIdRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId'-import { Route as IndexRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/index'-import { Route as SettingsRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/settings'-import { Route as ProfileRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/profile'-import { Route as OnboardingRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/onboarding'-import { Route as SettingsIndexRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/settings/index'-import { Route as ProductsIndexRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/products/index'-import { Route as PayoutsIndexRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/payouts/index'-import { Route as OrdersIndexRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/orders/index'-import { Route as EarningsIndexRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/earnings/index'-import { Route as SettingsTeamRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/settings/team'-import { Route as SettingsStockLocationsRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/settings/stock-locations'-import { Route as SettingsPoliciesRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/settings/policies'-import { Route as SettingsPackageTypesRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/settings/package-types'-import { Route as SettingsDeliveryMethodsRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/settings/delivery-methods'-import { Route as ProductsNewRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/products/new'-import { Route as ProductsProductIdRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/products/$productId'-import { Route as PayoutsPayoutIdRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/payouts/$payoutId'-import { Route as OrdersOrderIdRouteImport } from './../../seller-dashboard/src/routes/_authenticated/$sellerId/orders/$orderId'+import { Route as rootRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/__root'+import { Route as resetPasswordRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/reset-password'+import { Route as loginRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/login'+import { Route as forgotPasswordRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/forgot-password'+import { Route as authenticatedRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated'+import { Route as authenticatedIndexRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/index'+import { Route as acceptInvitationDotinvitationIdRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/accept-invitation.$invitationId'+import { Route as authenticatedSellerIdRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId'+import { Route as IndexRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/index'+import { Route as SettingsRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/settings'+import { Route as ProfileRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/profile'+import { Route as OnboardingRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/onboarding'+import { Route as SettingsIndexRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/settings/index'+import { Route as ProductsIndexRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/products/index'+import { Route as PayoutsIndexRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/payouts/index'+import { Route as OrdersIndexRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/orders/index'+import { Route as EarningsIndexRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/earnings/index'+import { Route as SettingsTeamRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/settings/team'+import { Route as SettingsStockLocationsRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/settings/stock-locations'+import { Route as SettingsPoliciesRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/settings/policies'+import { Route as SettingsPackageTypesRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/settings/package-types'+import { Route as SettingsDeliveryMethodsRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/settings/delivery-methods'+import { Route as ProductsNewRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/products/new'+import { Route as ProductsProductIdRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/products/$productId'+import { Route as PayoutsPayoutIdRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/payouts/$payoutId'+import { Route as OrdersOrderIdRouteImport } from './../node_modules/@spree/seller-dashboard/src/routes/_authenticated/$sellerId/orders/$orderId'const resetPasswordRoute = resetPasswordRouteImport.update({id: '/reset-password',diff --git a/packages/seller-dashboard/src/vite/index.ts b/packages/seller-dashboard/src/vite/index.tsindex 29b5df0c06..79e90215cd 100644--- a/packages/seller-dashboard/src/vite/index.ts+++ b/packages/seller-dashboard/src/vite/index.ts@@ -4,6 +4,7 @@ import {type SpreeDashboardPluginOptions as CoreOptions,spreeDashboardPlugin as spreeDashboardCorePlugin,} from '@spree/dashboard-core/vite'+import { linkedPackagePath } from '@spree/dashboard-core/vite/discover'import { TanStackRouterVite } from '@tanstack/router-plugin/vite'import { index, layout, physical, rootRoute, route } from '@tanstack/virtual-file-routes'import type { PluginOption } from 'vite'@@ -60,7 +61,11 @@ function sellerRouterPlugin(hostRoot: string, options: SpreeSellerDashboardPlugi// `@spree/seller-dashboard` lives (workspace symlink or npm install). The// `.` export maps to a file in src/, so `routes/` is its sibling.const shellEntry = fromHost.resolve('@spree/seller-dashboard')- const shellRoutesDir = path.join(path.dirname(shellEntry), 'routes')+ const shellRoutesDir = linkedPackagePath(+ hostRoot,+ '@spree/seller-dashboard',+ path.join(path.dirname(shellEntry), 'routes'),+ )const virtualRouteConfig = rootRoute('__root.tsx', [route('/login', 'login.tsx'),