2026-07-18 23:20:06 +08:00
|
|
|
import assert from "node:assert/strict"
|
|
|
|
|
import { readFile } from "node:fs/promises"
|
|
|
|
|
import test from "node:test"
|
|
|
|
|
|
|
|
|
|
const pagePath = new URL(
|
|
|
|
|
"../standalone-web/src/features/materials/AdvancedMaterialImportPage.vue",
|
|
|
|
|
import.meta.url,
|
|
|
|
|
)
|
|
|
|
|
const typesPath = new URL("../shared/types/advanced-material.ts", import.meta.url)
|
|
|
|
|
const endpointsPath = new URL("../shared/api/endpoints.ts", import.meta.url)
|
|
|
|
|
const appPath = new URL("../standalone-web/src/App.vue", import.meta.url)
|
2026-07-27 11:50:48 +08:00
|
|
|
const appCssPath = new URL("../standalone-web/src/styles/app.css", import.meta.url)
|
2026-07-18 23:20:06 +08:00
|
|
|
|
|
|
|
|
test("omits an unknown upload MIME type instead of claiming the image is PNG", async () => {
|
|
|
|
|
const [page, types] = await Promise.all([
|
|
|
|
|
readFile(pagePath, "utf8"),
|
|
|
|
|
readFile(typesPath, "utf8"),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
assert.match(types, /content_type\?: string/)
|
|
|
|
|
assert.match(types, /fidelity_score\?: number \| null/)
|
|
|
|
|
assert.match(page, /const declaredContentType = uploadFile\.value\.type\.trim\(\)/)
|
|
|
|
|
assert.match(
|
|
|
|
|
page,
|
|
|
|
|
/\.\.\.\(declaredContentType \? \{ content_type: declaredContentType \} : \{\}\)/,
|
|
|
|
|
)
|
|
|
|
|
assert.doesNotMatch(
|
|
|
|
|
page,
|
|
|
|
|
/content_type:\s*uploadFile\.value\.type\s*\|\|\s*["']image\/png["']/,
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("enables 2-8 image style sets without replacing the legacy single-image upload", async () => {
|
|
|
|
|
const [page, types, endpoints] = await Promise.all([
|
|
|
|
|
readFile(pagePath, "utf8"),
|
|
|
|
|
readFile(typesPath, "utf8"),
|
|
|
|
|
readFile(endpointsPath, "utf8"),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
assert.match(page, /const MIN_STYLE_IMAGES = 2/)
|
|
|
|
|
assert.match(page, /const MAX_STYLE_IMAGES = 8/)
|
|
|
|
|
assert.match(page, /styleSetUploadEnabled/)
|
|
|
|
|
assert.match(page, /endpoints\.advancedMaterialStyleSetUpload/)
|
|
|
|
|
assert.match(page, /endpoints\.advancedMaterialImportUpload/)
|
|
|
|
|
assert.match(page, /Promise\.all\(accepted\.map/)
|
|
|
|
|
assert.match(page, /0 张参考图/)
|
|
|
|
|
assert.match(page, /styleValidationCases\.value\.length === 3/)
|
|
|
|
|
assert.match(types, /interface AdvancedStyleSource/)
|
|
|
|
|
assert.match(types, /interface AdvancedStyleConsensus/)
|
|
|
|
|
assert.match(types, /interface AdvancedStyleValidationCase/)
|
|
|
|
|
assert.match(types, /images: AdvancedStyleSetUploadImage\[\]/)
|
|
|
|
|
assert.match(endpoints, /advancedMaterialStyleSetUpload: "advanced-material-imports\/style-set\/upload"/)
|
|
|
|
|
assert.match(endpoints, /style-validation-cases\/\$\{caseId\}\/retry/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("allows an unsealed import to be deleted after its queue row is removed", async () => {
|
|
|
|
|
const [page, endpoints] = await Promise.all([
|
|
|
|
|
readFile(pagePath, "utf8"),
|
|
|
|
|
readFile(endpointsPath, "utf8"),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
assert.match(endpoints, /advancedMaterialImportDelete/)
|
|
|
|
|
assert.match(page, /deleteJson<Record<string, unknown>>/)
|
|
|
|
|
assert.match(page, /确认删除导入/)
|
|
|
|
|
assert.match(page, /!selectedImport\.accepted_material_id/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("keeps queue cards at their natural height instead of compressing grid rows", async () => {
|
2026-07-27 11:50:48 +08:00
|
|
|
// Rules moved out of App.vue into the extracted global stylesheet.
|
|
|
|
|
const app = await readFile(appCssPath, "utf8")
|
2026-07-18 23:20:06 +08:00
|
|
|
|
|
|
|
|
assert.match(app, /\.queue-task-list\s*\{[^}]*display:\s*flex;[^}]*flex-direction:\s*column;/s)
|
|
|
|
|
assert.match(app, /\.queue-task-card\s*\{[^}]*flex:\s*0 0 auto;[^}]*min-height:\s*88px;/s)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("polls only active import state and keeps storage-backed media URLs stable", async () => {
|
|
|
|
|
const page = await readFile(pagePath, "utf8")
|
|
|
|
|
|
|
|
|
|
assert.match(page, /const pollBusy = ref\(false\)/)
|
|
|
|
|
assert.match(page, /void pollActiveState\(\)/)
|
|
|
|
|
assert.doesNotMatch(page, /setInterval\([\s\S]{0,500}void refreshAll\(true\)/)
|
|
|
|
|
assert.match(page, /if \(importId && selectedWasBusy\)/)
|
|
|
|
|
assert.match(page, /if \(!pairedUri \|\| !pairedUri\.startsWith\("storage:\/\/"\)\) signedUrls\.add\(value\)/)
|
|
|
|
|
assert.match(page, /mediaUrl\(item\.source_thumbnail_uri, item\.source_image_uri/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("routes style corrections and validation-content instructions separately", async () => {
|
|
|
|
|
const [page, types] = await Promise.all([
|
|
|
|
|
readFile(pagePath, "utf8"),
|
|
|
|
|
readFile(typesPath, "utf8"),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
assert.match(types, /style_adjustment_text\?: string/)
|
|
|
|
|
assert.match(types, /validation_instruction\?: string/)
|
|
|
|
|
assert.match(page, /const validationInstructionText = ref\(""\)/)
|
|
|
|
|
assert.match(page, /style_adjustment_text: selectedStyleSet\.value \? adjustment/)
|
|
|
|
|
assert.match(page, /validation_instruction: selectedStyleSet\.value \? validationInstruction/)
|
|
|
|
|
assert.match(page, /下一轮验证内容(选填)/)
|
|
|
|
|
assert.match(page, /已应用文字调整/)
|
|
|
|
|
assert.match(page, /应用文字调整并生成下一轮/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("recognizes canonical advanced style sets and renders all three validation images", async () => {
|
|
|
|
|
const page = await readFile(pagePath, "utf8")
|
|
|
|
|
|
|
|
|
|
assert.match(page, /workflowKind === "style_set" \|\| workflowKind === "advanced_style_set"/)
|
|
|
|
|
assert.match(page, /attempt\.validation_cases\?\.length/)
|
|
|
|
|
assert.match(page, /v-for="validationCase in attempt\.validation_cases"/)
|
|
|
|
|
assert.match(page, /class="advanced-attempt-history-images"/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("opens advanced-material thumbnails in the shared safe image preview dialog", async () => {
|
|
|
|
|
const page = await readFile(pagePath, "utf8")
|
|
|
|
|
|
|
|
|
|
assert.match(page, /import ImagePreviewDialog from "\.\.\/\.\.\/components\/ImagePreviewDialog\.vue"/)
|
|
|
|
|
assert.match(page, /const previewImageSrc = ref\(""\)/)
|
|
|
|
|
assert.match(page, /function validationCasePreviewUrl/)
|
|
|
|
|
assert.match(page, /@click="openImagePreview\(validationCasePreviewUrl\(validationCase\)/)
|
|
|
|
|
assert.match(page, /<ImagePreviewDialog/)
|
|
|
|
|
assert.match(page, /@close="closeImagePreview"/)
|
|
|
|
|
assert.match(page, /function styleValidationFidelityPercent/)
|
|
|
|
|
assert.match(page, /function styleValidationReviewSummary/)
|
|
|
|
|
assert.match(page, /title="点击查看大图"/)
|
|
|
|
|
})
|