diff --git a/hub/deploy/deploy_fleet_release.sh b/hub/deploy/deploy_fleet_release.sh index 53d2148..2d52e9b 100755 --- a/hub/deploy/deploy_fleet_release.sh +++ b/hub/deploy/deploy_fleet_release.sh @@ -82,11 +82,11 @@ REMOTE rsync -az --delete \ --exclude node_modules --exclude dist --exclude .env \ --exclude admin-web/node_modules --exclude admin-web/build --exclude admin-web/.svelte-kit \ - --exclude database-admin/node_modules --exclude database-admin/build --exclude database-admin/.svelte-kit \ + --exclude filelib-web/node_modules --exclude filelib-web/build --exclude filelib-web/.svelte-kit \ -e "ssh ${SSH_OPTS[*]}" \ "$REPO_ROOT/hub/" "$DEPLOY_USER@$HOST:$HUB_DIR/" - echo "[fleet] npm ci + build (tsc + admin-web & database-admin SPAs)" + echo "[fleet] npm ci + build (tsc + admin-web & filelib-web SPAs)" ssh "${SSH_OPTS[@]}" "$DEPLOY_USER@$HOST" bash -s < { expect(isSiloHttpRateLimitExempt("/admin/org/para-26071100/members")).toBe(true); }); + it("exempts the filelib-web SPA assets and both of its mount prefixes", () => { + // appDir 改名为 `_filelib`(见 src/database/static.ts):同一份产物服务 + // 老师端 /app 与管理后台 /database。 + expect(isSiloHttpRateLimitExempt("/_filelib/version.json")).toBe(true); + expect(isSiloHttpRateLimitExempt("/_filelib/immutable/chunks/foo.js?v=1")).toBe(true); + expect(isSiloHttpRateLimitExempt("/app")).toBe(true); + expect(isSiloHttpRateLimitExempt("/app/dev-login-teacher")).toBe(true); + expect(isSiloHttpRateLimitExempt("/database")).toBe(true); + expect(isSiloHttpRateLimitExempt("/database/dashboard/users")).toBe(true); + }); + it("still rate-limits APIs and auth", () => { expect(isSiloHttpRateLimitExempt("/api/me")).toBe(false); expect(isSiloHttpRateLimitExempt("/api/org/x/members")).toBe(false); diff --git a/hub/test/unit/spa-route-registration.test.ts b/hub/test/unit/spa-route-registration.test.ts new file mode 100644 index 0000000..38f6cdb --- /dev/null +++ b/hub/test/unit/spa-route-registration.test.ts @@ -0,0 +1,43 @@ +/** + * 两套 SPA 静态托管共存于同一个 Fastify 实例。 + * + * 这是 ADR-0029 的承重约束的回归测试:filelib-web 的 appDir 若用 SvelteKit 默认的 + * `_app`,就会与 admin-web 在根上注册的 `/_app/*` 撞成重复路由,Fastify 启动即抛错。 + * 改名为 `_filelib` 后两者共存 —— 这里把两个注册函数挂到同一实例上验证。 + */ +import Fastify from "fastify"; +import { describe, expect, it } from "vitest"; +import { registerStaticSpa } from "../../src/admin/static.js"; +import { registerDatabaseSpa } from "../../src/database/static.js"; + +describe("SPA static route registration", () => { + it("admin-web and filelib-web shells coexist without duplicate routes", async () => { + const app = Fastify({ logger: false }); + await registerStaticSpa(app); + await registerDatabaseSpa(app); + await expect(app.ready()).resolves.toBeDefined(); + await app.close(); + }); + + it("serves the same index.html at /app and /database, and assets under /_filelib", async () => { + const app = Fastify({ logger: false }); + await registerDatabaseSpa(app); + await app.ready(); + + const appShell = await app.inject({ method: "GET", url: "/app" }); + const dbShell = await app.inject({ method: "GET", url: "/database/dashboard/users" }); + + // 前置:构建产物必须存在。缺失时 registerDatabaseSpa 只 warn 不注册路由, + // 断言会全部落到 404 —— 那说明该先跑 `npm run build --prefix filelib-web`, + // 不是测试不适用,所以这里不跳过而是直接失败。 + expect(appShell.statusCode).toBe(200); + expect(dbShell.statusCode).toBe(200); + // 同一份字节:SPA 回退不读请求(ADR-0029)。 + expect(dbShell.body).toBe(appShell.body); + expect(appShell.headers["content-type"]).toContain("text/html"); + // 资源用绝对路径引用(paths.relative=false),否则深层 URL 下会解析错。 + expect(appShell.body).toContain("/_filelib/"); + + await app.close(); + }); +});