🧪 Standardize Playwright source inference

This commit is contained in:
eust-w 2026-06-16 20:06:00 +08:00
parent e440c000c2
commit b4b9807ea7
6 changed files with 46 additions and 10 deletions

View File

@ -570,8 +570,10 @@
<code>PLAYWRIGHT_SOURCE_PATH=&lt;path-visible-to-operator-runner&gt; BASE_URL=&lt;deployed-api-base-url&gt; node scripts/playwright-functional-check.mjs</code>
</p>
<p class="small">
<code>PLAYWRIGHT_SOURCE_PATH</code> 必须指向 operator-runner 可读取的真实数据路径;BOS 来源需同时设置
<code>PLAYWRIGHT_SOURCE_DATA_SOURCE=BOS</code> 并准备运行时访问配置。
<code>PLAYWRIGHT_SOURCE_PATH</code> 必须指向 operator-runner 可读取的真实数据路径;脚本会把
<code>bos://bucket/prefix</code> 自动识别为 <code>BOS</code>,其余文件系统或 PVC 路径识别为
<code>LOCAL</code>。历史的 <code>PLAYWRIGHT_SOURCE_DATA_SOURCE=FILESYSTEM</code> 会归一为
<code>LOCAL</code>;只有需要覆盖自动推断时才设置 <code>PLAYWRIGHT_SOURCE_DATA_SOURCE</code>。
</p>
</section>

View File

@ -337,7 +337,7 @@ BASE_URL=<deployed-api-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`。
脚本文件位置:

View File

@ -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 ./...",

View File

@ -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";
}

View File

@ -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`,

View File

@ -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(""), "");
});