refactor(test): 三份 helper 迁移共享
Task 6 审查遗留①(schema 再演进防漂移):makeWork / seedPublishedSite / cleanupSiteRows 三件套自 build-snapshot / build-pipeline / build-gates / preview-server 四文件(Task 6 审查时三份,Task 7 又落一份)迁 tests/integration/helpers.ts 共享——清场清单(21 语句 FK 反序 + 不可变 触发器开关)此后只改一处。 - makeWork 保持签名;媒体种子载荷改由 prefix 派生(bytes 仍随机唯一, 魔数校验只看 PNG 签名——行为等价);shared Work 统一携带 pngA/pngB - seedPublishedSite 增 keyPrefix 参数(各文件沿用原站点 key 派生前缀 sfbuild/sfpipe/sfgate/sfpreview);succeeded_with_issues 与 publishedCount=3 断言随迁(gallery 203/204 悬空语义文件无关) - import 域短清单清场与 publish 域各自形状不同,不共用——保留原处 零行为变更由 408 测试守护(全绿:根 382 + 主题 26);lint/typecheck 五段过。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -26,22 +26,19 @@ import { isRouteManifest, ROUTE_MANIFEST_VERSION } from '@sf/contracts'
|
||||
import { canonicalJson } from '../../apps/api/src/common/canonical.js'
|
||||
import { runBuildPipeline, themeDistDir } from '../../apps/api/src/modules/build/pipeline.js'
|
||||
import { createBuildJob } from '../../apps/api/src/modules/build/build.service.js'
|
||||
import { createImportJob } from '../../apps/api/src/modules/import/import.service.js'
|
||||
import { publishSiteContent } from '../../apps/api/src/modules/publish/publish.service.js'
|
||||
import { registerSource } from '../../apps/api/src/modules/source/register.service.js'
|
||||
import {
|
||||
cleanupSiteRows,
|
||||
createSiteFixture,
|
||||
makeWork,
|
||||
rand,
|
||||
rejectionMessage,
|
||||
withImmutableCleanup,
|
||||
seedPublishedSite,
|
||||
withTestDb,
|
||||
type Db,
|
||||
} from './helpers.js'
|
||||
|
||||
/** 本文件位于 <repo>/tests/integration/ → 上两级是仓库根 */
|
||||
const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../..')
|
||||
const FIXTURES_ROOT = fileURLToPath(new URL('../fixtures', import.meta.url))
|
||||
const WXR_FIXTURE = resolve(FIXTURES_ROOT, 'wxr', 'mini.xml')
|
||||
const THEME_SRC = join(REPO_ROOT, 'themes', 'pilot-minimal', 'src')
|
||||
const THEME_FIXTURE_INPUT = join(REPO_ROOT, 'themes', 'pilot-minimal', 'test', 'fixtures', 'render-input')
|
||||
|
||||
@@ -105,78 +102,12 @@ async function scanThemeSrc(): Promise<Map<string, string>> {
|
||||
return out
|
||||
}
|
||||
|
||||
/** 本文件写入的行清场:validation 域先行(FK 链 validation_issues→validation_runs→
|
||||
* build_jobs;Task 6 起成功构建必落 validation_runs 行)+ 构建域 + 全链反序 */
|
||||
async function cleanupSiteRows(db: Db, siteId: string): Promise<void> {
|
||||
await db.execute(`delete from validation_issues where validation_run_id in
|
||||
(select id from validation_runs where site_id = '${siteId}')`)
|
||||
await db.execute(`delete from validation_runs where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from build_artifacts where build_job_id in
|
||||
(select id from build_jobs where site_id = '${siteId}')`)
|
||||
await withImmutableCleanup(db, 'build_input_snapshots', 'build_input_snapshots_immutable', `site_id = '${siteId}'`)
|
||||
await db.execute(`delete from build_jobs where site_id = '${siteId}'`)
|
||||
await withImmutableCleanup(db, 'audit_logs', 'audit_logs_immutable', `site_id = '${siteId}'`)
|
||||
await db.execute(`delete from site_config_revisions where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from route_registry where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from media_usages where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from media_assets where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from content_terms where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from terms where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from taxonomies where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from source_records where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from entry_locales where site_id = '${siteId}'`)
|
||||
await withImmutableCleanup(db, 'content_revisions', 'content_revisions_immutable', `site_id = '${siteId}'`)
|
||||
await db.execute(`delete from content_entries where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from import_jobs where site_id = '${siteId}'`)
|
||||
await withImmutableCleanup(db, 'source_snapshots', 'source_snapshots_immutable', `site_id = '${siteId}'`)
|
||||
await db.execute(`delete from source_connections where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from sites where id = '${siteId}'`)
|
||||
}
|
||||
|
||||
interface Work {
|
||||
work: string
|
||||
storageRoot: string
|
||||
allowedRoots: string[]
|
||||
pngA: Buffer
|
||||
pngB: Buffer
|
||||
}
|
||||
|
||||
async function makeWork(prefix: string): Promise<Work> {
|
||||
const work = await mkdtemp(join(tmpdir(), `${prefix}-`))
|
||||
const mediaDir = join(work, 'media')
|
||||
await mkdir(join(mediaDir, '2026', '10'), { recursive: true })
|
||||
const pngA = mediaBytes(`pipe-a-${rand()}`)
|
||||
const pngB = mediaBytes(`pipe-b-${rand()}`)
|
||||
await writeFile(join(mediaDir, '2026', '10', 'fixture-a.png'), pngA)
|
||||
await writeFile(join(mediaDir, '2026', '10', 'fixture-b.png'), pngB)
|
||||
return { work, storageRoot: join(work, 'storage'), allowedRoots: [FIXTURES_ROOT, work], pngA, pngB }
|
||||
}
|
||||
|
||||
/** mini 全链(register wxr+media → import → publish):3 条 published + 2 ready 媒体 */
|
||||
async function seedPublishedSite(db: Db, w: Work): Promise<{ key: string; siteId: string }> {
|
||||
const key = `sfpipe-${rand()}`
|
||||
const reg = await registerSource(db, {
|
||||
siteKey: key,
|
||||
wxrPath: WXR_FIXTURE,
|
||||
mediaDir: join(w.work, 'media'),
|
||||
allowedRoots: w.allowedRoots,
|
||||
storageRoot: w.storageRoot,
|
||||
reportRoot: join(w.work, 'artifacts', 'register'),
|
||||
})
|
||||
const result = await createImportJob(db, { siteKey: key, reportRoot: join(w.work, 'artifacts', 'import') })
|
||||
expect(result.status).toBe('succeeded_with_issues')
|
||||
const dry = await publishSiteContent(db, { siteKey: key, dryRun: true })
|
||||
const run = await publishSiteContent(db, { siteKey: key, confirmToken: dry.confirmToken! })
|
||||
expect(run.publishedCount).toBe(3)
|
||||
return { key, siteId: reg.siteId }
|
||||
}
|
||||
|
||||
describe('构建管线全链(mini 夹具 DB 物化输入)', () => {
|
||||
it('状态机含 building;dist target_file 权威落盘 + 媒体 sha256 全量 + sitemap/robots + route-manifest §12.1 + build_artifacts 三行', { timeout: 300_000 }, async () => {
|
||||
await withTestDb(async (db) => {
|
||||
const w = await makeWork('sf-pipe-full')
|
||||
try {
|
||||
const { key, siteId } = await seedPublishedSite(db, w)
|
||||
const { key, siteId } = await seedPublishedSite(db, w, 'sfpipe')
|
||||
try {
|
||||
const statuses: string[] = []
|
||||
const result = await createBuildJob(db, {
|
||||
@@ -338,7 +269,7 @@ describe('构建管线全链(mini 夹具 DB 物化输入)', () => {
|
||||
await withTestDb(async (db) => {
|
||||
const w = await makeWork('sf-pipe-fail')
|
||||
try {
|
||||
const { key, siteId } = await seedPublishedSite(db, w)
|
||||
const { key, siteId } = await seedPublishedSite(db, w, 'sfpipe')
|
||||
try {
|
||||
const artifactsRoot = join(w.work, 'artifacts')
|
||||
let failingJobId = ''
|
||||
@@ -598,7 +529,7 @@ describe('五禁断言(主题构建期纪律)', () => {
|
||||
process.env.DATABASE_URL = ''
|
||||
process.env.NODE_OPTIONS = `--import ${pathToFileURL(stub).href}`
|
||||
try {
|
||||
const { key, siteId } = await seedPublishedSite(db, w)
|
||||
const { key, siteId } = await seedPublishedSite(db, w, 'sfpipe')
|
||||
try {
|
||||
const result = await createBuildJob(db, {
|
||||
siteKey: key,
|
||||
|
||||
Reference in New Issue
Block a user