From b4b9807ea795c495b92d0f66223bbb137e23542f Mon Sep 17 00:00:00 2001 From: eust-w Date: Tue, 16 Jun 2026 20:06:00 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Standardize=20Playwright=20sourc?= =?UTF-8?q?e=20inference?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...view-playwright-validation-2026-04-15.html | 6 +++-- ...erview-playwright-validation-2026-04-15.md | 2 +- package.json | 2 +- scripts/lib/source-data-source.mjs | 14 +++++++++++ scripts/playwright-functional-check.mjs | 8 ++----- tests/frontend/source-data-source.test.mjs | 24 +++++++++++++++++++ 6 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 scripts/lib/source-data-source.mjs create mode 100644 tests/frontend/source-data-source.test.mjs diff --git a/docs/feature-overview-playwright-validation-2026-04-15.html b/docs/feature-overview-playwright-validation-2026-04-15.html index df8c91fc..4b691864 100644 --- a/docs/feature-overview-playwright-validation-2026-04-15.html +++ b/docs/feature-overview-playwright-validation-2026-04-15.html @@ -570,8 +570,10 @@ PLAYWRIGHT_SOURCE_PATH=<path-visible-to-operator-runner> BASE_URL=<deployed-api-base-url> node scripts/playwright-functional-check.mjs

- PLAYWRIGHT_SOURCE_PATH 必须指向 operator-runner 可读取的真实数据路径;BOS 来源需同时设置 - PLAYWRIGHT_SOURCE_DATA_SOURCE=BOS 并准备运行时访问配置。 + PLAYWRIGHT_SOURCE_PATH 必须指向 operator-runner 可读取的真实数据路径;脚本会把 + bos://bucket/prefix 自动识别为 BOS,其余文件系统或 PVC 路径识别为 + LOCAL。历史的 PLAYWRIGHT_SOURCE_DATA_SOURCE=FILESYSTEM 会归一为 + LOCAL;只有需要覆盖自动推断时才设置 PLAYWRIGHT_SOURCE_DATA_SOURCE。

diff --git a/docs/feature-overview-playwright-validation-2026-04-15.md b/docs/feature-overview-playwright-validation-2026-04-15.md index 62a0b8a6..0403081c 100644 --- a/docs/feature-overview-playwright-validation-2026-04-15.md +++ b/docs/feature-overview-playwright-validation-2026-04-15.md @@ -337,7 +337,7 @@ BASE_URL= \ node scripts/playwright-functional-check.mjs ``` -`PLAYWRIGHT_SOURCE_PATH` 必须指向 operator-runner 可读取的真实数据路径。默认按文件系统路径处理;如果确实要使用 BOS,可同时设置 `PLAYWRIGHT_SOURCE_DATA_SOURCE=BOS` 并确保运行时具备对应 BOS 访问配置。 +`PLAYWRIGHT_SOURCE_PATH` 必须指向 operator-runner 可读取的真实数据路径。脚本会把 `bos://bucket/prefix` 自动识别为 `BOS`,其余文件系统或 PVC 路径识别为 `LOCAL`;历史的 `PLAYWRIGHT_SOURCE_DATA_SOURCE=FILESYSTEM` 会归一为 `LOCAL`。只有需要覆盖自动推断时才设置 `PLAYWRIGHT_SOURCE_DATA_SOURCE`。 脚本文件位置: diff --git a/package.json b/package.json index 2d04108a..2053dcb0 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "lint": "npm run lint:web && npm run lint:go && npm run lint:scripts", "lint:web": "tsc --noEmit", "lint:go": "bash -lc 'test -z \"$(gofmt -l cmd internal)\"'", - "lint:scripts": "node --check scripts/*.mjs && python3 -m py_compile scripts/*.py", + "lint:scripts": "node --check scripts/*.mjs scripts/lib/*.mjs && python3 -m py_compile scripts/*.py", "format": "prettier --write \"src/**/*.{ts,tsx,css}\" \"tests/frontend/**/*.mjs\"", "format:check": "prettier --check \"src/**/*.{ts,tsx,css}\" \"tests/frontend/**/*.mjs\"", "test": "go test ./...", diff --git a/scripts/lib/source-data-source.mjs b/scripts/lib/source-data-source.mjs new file mode 100644 index 00000000..9f13cd5e --- /dev/null +++ b/scripts/lib/source-data-source.mjs @@ -0,0 +1,14 @@ +export function inferSourceDataSource(sourcePath, override = "") { + const explicit = String(override || "").trim().toUpperCase(); + if (explicit === "FILESYSTEM") { + return "LOCAL"; + } + if (explicit) { + return explicit; + } + const normalizedPath = String(sourcePath || "").trim().toLowerCase(); + if (!normalizedPath) { + return ""; + } + return normalizedPath.startsWith("bos://") ? "BOS" : "LOCAL"; +} diff --git a/scripts/playwright-functional-check.mjs b/scripts/playwright-functional-check.mjs index be7e922e..833c1e7e 100644 --- a/scripts/playwright-functional-check.mjs +++ b/scripts/playwright-functional-check.mjs @@ -1,6 +1,7 @@ import { chromium } from "playwright"; import fs from "node:fs"; import path from "node:path"; +import { inferSourceDataSource } from "./lib/source-data-source.mjs"; const baseURL = (process.env.BASE_URL || process.argv[2] || "http://127.0.0.1:3001").replace(/\/+$/, ""); const apiBaseURL = `${baseURL}`; @@ -10,12 +11,7 @@ const suffix = Date.now().toString(36); const scanBucket = (process.env.PLAYWRIGHT_SCAN_BUCKET || "").trim(); const scanPrefix = (process.env.PLAYWRIGHT_SCAN_PREFIX || "").trim().replace(/^\/+|\/+$/g, ""); const sourcePath = (process.env.PLAYWRIGHT_SOURCE_PATH || "").trim(); -const sourceDataSource = ( - process.env.PLAYWRIGHT_SOURCE_DATA_SOURCE || - (sourcePath.toLowerCase().startsWith("bos://") ? "BOS" : "FILESYSTEM") -) - .trim() - .toUpperCase(); +const sourceDataSource = inferSourceDataSource(sourcePath, process.env.PLAYWRIGHT_SOURCE_DATA_SOURCE); const names = { admin: `PW Admin ${suffix}`, adminEmail: `pw-admin-${suffix}@playwright.local`, diff --git a/tests/frontend/source-data-source.test.mjs b/tests/frontend/source-data-source.test.mjs new file mode 100644 index 00000000..5c6e1362 --- /dev/null +++ b/tests/frontend/source-data-source.test.mjs @@ -0,0 +1,24 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { inferSourceDataSource } from "../../scripts/lib/source-data-source.mjs"; + +test("infers BOS source from bos path", () => { + assert.equal(inferSourceDataSource("bos://datastorage/factory/output"), "BOS"); +}); + +test("infers LOCAL source from filesystem path", () => { + assert.equal(inferSourceDataSource("/workspace/datasets/factory/output"), "LOCAL"); +}); + +test("normalizes legacy FILESYSTEM override to LOCAL", () => { + assert.equal(inferSourceDataSource("/workspace/datasets/factory/output", "filesystem"), "LOCAL"); +}); + +test("keeps explicit source override when provided", () => { + assert.equal(inferSourceDataSource("bos://datastorage/factory/output", "upstream"), "UPSTREAM"); +}); + +test("returns empty source for empty path without override", () => { + assert.equal(inferSourceDataSource(""), ""); +});