Use static terminal update announcements
This commit is contained in:
@@ -38,10 +38,9 @@ export function runTests() {
|
||||
const middlewareSource = fs.readFileSync(path.join(projectRoot, "middleware.ts"), "utf8");
|
||||
|
||||
assert(fs.existsSync(componentPath), "terminal must have a compact update announcement component");
|
||||
assert(fs.existsSync(nextRoutePath), "frontend must proxy the public update announcement API");
|
||||
assert(!fs.existsSync(nextRoutePath), "update announcements should not depend on an admin-managed API proxy");
|
||||
|
||||
const componentSource = fs.readFileSync(componentPath, "utf8");
|
||||
const routeSource = fs.readFileSync(nextRoutePath, "utf8");
|
||||
|
||||
assert(
|
||||
dashboardSource.includes("UpdateAnnouncementButton") &&
|
||||
@@ -50,43 +49,41 @@ export function runTests() {
|
||||
"terminal header must render a bilingual update announcement entry beside the dashboard title",
|
||||
);
|
||||
assert(
|
||||
componentSource.includes("/api/system/update-announcement") &&
|
||||
componentSource.includes("STATIC_UPDATE_ANNOUNCEMENTS") &&
|
||||
componentSource.includes("expiresAt") &&
|
||||
componentSource.includes("Date.now()") &&
|
||||
componentSource.includes("Megaphone") &&
|
||||
componentSource.includes("zh") &&
|
||||
componentSource.includes("en") &&
|
||||
!componentSource.includes("fetch(") &&
|
||||
!componentSource.includes("/api/system/update-announcement") &&
|
||||
!componentSource.includes("setInterval("),
|
||||
"announcement component must fetch the public announcement once, support zh/en content, and avoid aggressive polling",
|
||||
"announcement component must use hardcoded zh/en release notes with an expiry time and no backend polling",
|
||||
);
|
||||
assert(
|
||||
routeSource.includes(`${"api/system/update-announcement"}`) &&
|
||||
routeSource.includes("cache: \"no-store\""),
|
||||
"Next.js announcement proxy must call the backend public endpoint without caching stale admin content",
|
||||
!middlewareSource.includes("/api/system/update-announcement"),
|
||||
"middleware should not keep a public announcement API entry after announcements move into frontend code",
|
||||
);
|
||||
assert(
|
||||
middlewareSource.includes('pathname === "/api/system/update-announcement"'),
|
||||
"update announcement proxy must stay public because it only returns non-sensitive release notes",
|
||||
!opsConfigSource.includes("公告类配置") &&
|
||||
!opsConfigSource.includes("multiline") &&
|
||||
!opsConfigSource.includes("<textarea"),
|
||||
"ops config page should not expose update announcement editing controls",
|
||||
);
|
||||
assert(
|
||||
opsConfigSource.includes("multiline") &&
|
||||
opsConfigSource.includes("<textarea") &&
|
||||
opsConfigSource.includes("DB 持久化"),
|
||||
"ops config page must support persistent multiline announcement fields",
|
||||
!opsApiSource.includes("POLYWEATHER_UPDATE_ANNOUNCEMENT") &&
|
||||
!opsApiSource.includes("_RUNTIME_CONFIG_KEYS"),
|
||||
"ops API must not expose editable update announcement keys",
|
||||
);
|
||||
assert(
|
||||
opsApiSource.includes("POLYWEATHER_UPDATE_ANNOUNCEMENT_TITLE_ZH") &&
|
||||
opsApiSource.includes("POLYWEATHER_UPDATE_ANNOUNCEMENT_BODY_EN") &&
|
||||
opsApiSource.includes("_RUNTIME_CONFIG_KEYS"),
|
||||
"ops API must expose editable zh/en announcement keys through the runtime config store",
|
||||
!systemApiSource.includes("get_public_update_announcement") &&
|
||||
!systemRouterSource.includes("/api/system/update-announcement"),
|
||||
"backend must not expose a runtime update announcement endpoint",
|
||||
);
|
||||
assert(
|
||||
systemApiSource.includes("get_public_update_announcement") &&
|
||||
systemRouterSource.includes("/api/system/update-announcement"),
|
||||
"backend must expose a public read-only update announcement endpoint",
|
||||
);
|
||||
assert(
|
||||
dbSource.includes("CREATE TABLE IF NOT EXISTS runtime_config") &&
|
||||
dbSource.includes("set_runtime_config") &&
|
||||
dbSource.includes("get_runtime_config_value"),
|
||||
"database manager must persist non-sensitive runtime config independently from runtime secrets",
|
||||
!dbSource.includes("CREATE TABLE IF NOT EXISTS runtime_config") &&
|
||||
!dbSource.includes("set_runtime_config") &&
|
||||
!dbSource.includes("get_runtime_config_value"),
|
||||
"database manager should not keep a runtime_config table only for update announcements",
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user