mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
build(site): [SITE-07] verify Node path origin and preserve complete notices
This commit is contained in:
1 parent
d2b2f76db8
commit
d3aa4bbfe4
24 files changed
+4050
-5
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import fs from 'node:fs'
|
||||
import { expect, test } from './fixtures.js'
|
||||
|
||||
const cases = JSON.parse(fs.readFileSync('refactor/baselines/monaco-node-path-fixtures.json', 'utf8'))
|
||||
|
||||
test('docs Monaco path port preserves frozen Node path results in both namespaces', async ({ page }, testInfo) => {
|
||||
await page.goto('/test/player.html?core=candidate&chapter=published')
|
||||
await page.addScriptTag({ url: '/assets/js/vs/loader.js' })
|
||||
const result = await page.evaluate(async (cases) => {
|
||||
window.require.config({ paths: { vs: '/assets/js/vs' } })
|
||||
const load = ids => new Promise((resolve, reject) => window.require(ids, (...modules) => resolve(modules), reject))
|
||||
await load(['vs/editor/editor.main'])
|
||||
const [paths, process] = await load(['vs/base/common/path', 'vs/base/common/process'])
|
||||
const values = cases.map(entry => paths[entry.namespace][entry.method](...entry.args))
|
||||
const namespace = process.platform === 'win32' ? 'win32' : 'posix'
|
||||
const sample = namespace === 'win32' ? 'C:\\a\\..\\b' : '/a/../b'
|
||||
let invalid
|
||||
try {
|
||||
paths.normalize(42)
|
||||
}
|
||||
catch (error) {
|
||||
invalid = { name: error.name, code: error.code }
|
||||
}
|
||||
return { values, namespace, alias: paths.normalize(sample) === paths[namespace].normalize(sample), invalid }
|
||||
}, cases)
|
||||
expect(result.values).toEqual(cases.map(entry => entry.expected))
|
||||
expect(result.alias).toBe(true)
|
||||
// This is the retained VS Code Error subclass, not Node's TypeError wrapper.
|
||||
expect(result.invalid).toEqual({ name: 'Error', code: 'ERR_INVALID_ARG_TYPE' })
|
||||
await testInfo.attach('monaco-path-results', { contentType: 'application/json', body: JSON.stringify({ cases: cases.length, ...result }) })
|
||||
})
|
||||
@@ -25,6 +25,7 @@ test('mobile vConsole shows logs and upstream site notice texts are served uncha
|
||||
{ path: '/licenses/console/react-pure-render/ATTRIBUTION.md', count: 2 },
|
||||
{ path: '/licenses/monaco-editor/language-services/ATTRIBUTION.md', count: 12 },
|
||||
{ path: '/licenses/monaco-editor/core-origins/ATTRIBUTION.md', count: 3 },
|
||||
{ path: '/licenses/monaco-editor/core-path/ATTRIBUTION.md', count: 1 },
|
||||
]) {
|
||||
const attribution = await request.get(path)
|
||||
expect(attribution.status()).toBe(200)
|
||||
|
||||
@@ -9,6 +9,7 @@ import { inventoryCoreMap, readCoreNls, restoreCoreMapComment } from '../scripts
|
||||
import { adaptCoreOrigin } from '../scripts/site-vendor/monaco/core-origins.ts'
|
||||
import { coreStyleOrder, prepareCoreStyles } from '../scripts/site-vendor/monaco/css.ts'
|
||||
import { aliasModule, moduleIds, nameModule, verifyWorkerSources } from '../scripts/site-vendor/monaco/languages.ts'
|
||||
import { nodePathResults, preparePathSource } from '../scripts/site-vendor/monaco/node-path.ts'
|
||||
import { browserTypeScript, verifyTypeScriptSource } from '../scripts/site-vendor/monaco/typescript.ts'
|
||||
|
||||
const contributionGroups = ['typescript', 'css', 'json', 'html', 'languages'].map((name) => {
|
||||
@@ -16,6 +17,18 @@ const contributionGroups = ['typescript', 'css', 'json', 'html', 'languages'].ma
|
||||
return { name: `monaco-${name}`, modulePrefix, contrib: `${modulePrefix}/monaco.contribution` }
|
||||
})
|
||||
|
||||
test('Path source preparation removes only the six explicit unused top-level exports', () => {
|
||||
const source = ['isAbsolute', 'join', 'format', 'parse', 'toNamespacedPath', 'delimiter'].map(name => `export const ${name} = (process.platform === 'win32' ? win32.${name} : posix.${name});\n`).join('')
|
||||
assert.equal(preparePathSource(`${source}export const retained = 1;\n`), 'export const retained = 1;\n')
|
||||
assert.throws(() => preparePathSource(source + source), /repeated unused path export/)
|
||||
assert.throws(() => preparePathSource(source.replace('win32.join', 'win32.other')), /unused path export: join/)
|
||||
})
|
||||
|
||||
test('Node reference path fixtures reject filesystem imports and environment-dependent cwd', () => {
|
||||
assert.throws(() => nodePathResults('require("fs")', []), /Unexpected Node path import/)
|
||||
assert.throws(() => nodePathResults('process.cwd()', []), /Non-deterministic path cwd/)
|
||||
})
|
||||
|
||||
test('Core CSS inventory follows registration order instead of the module-name table order', () => {
|
||||
const source = 'var names = ["vs/css!vs/editor/editor.main","vs/css!vs/a","vs/css!vs/b"]; define(names[2],[],{}); define(names[1],[],{});'
|
||||
assert.deepEqual(coreStyleOrder(source), ['vs/b', 'vs/a'])
|
||||
|
||||
@@ -9,11 +9,23 @@ import process from 'node:process'
|
||||
import test from 'node:test'
|
||||
import { verifyConsoleNoticeSources } from '../scripts/site-vendor/console/notices.ts'
|
||||
import { verifyMonacoCoreNotices } from '../scripts/site-vendor/monaco/core-origins.ts'
|
||||
import { verifyMonacoPathNotices } from '../scripts/site-vendor/monaco/node-path.ts'
|
||||
import { verifyMonacoLanguageNoticeArchives, verifyMonacoLanguageNotices } from '../scripts/site-vendor/monaco/notices.ts'
|
||||
import { generateNotices, writeOrCheckNotices } from '../scripts/site-vendor/notices.ts'
|
||||
|
||||
const hash = bytes => createHash('sha256').update(bytes).digest('hex')
|
||||
|
||||
test('Node path attribution covers both editor and worker and keeps the original terms', () => {
|
||||
const original = JSON.parse(fs.readFileSync('scripts/site-vendor/manifest.json', 'utf8'))
|
||||
assert.doesNotThrow(() => verifyMonacoPathNotices(process.cwd(), original))
|
||||
const missingWorker = structuredClone(original)
|
||||
missingWorker.groups.find(group => group.name === 'monaco-editor').components.find(component => component.name === 'nodejs path (Monaco core)').assets.pop()
|
||||
assert.throws(() => verifyMonacoPathNotices(process.cwd(), missingWorker), /Node path notice binding/)
|
||||
const missingTerms = structuredClone(original)
|
||||
missingTerms.groups.find(group => group.name === 'monaco-editor').notices = missingTerms.groups.find(group => group.name === 'monaco-editor').notices.filter(notice => !notice.target.endsWith('/ThirdPartyNotices.txt'))
|
||||
assert.throws(() => verifyMonacoPathNotices(process.cwd(), missingTerms), /Missing Node path notice/)
|
||||
})
|
||||
|
||||
test('Monaco core notices cannot replace DOMPurify terms with the Markdown parser license', () => {
|
||||
const original = JSON.parse(fs.readFileSync('scripts/site-vendor/manifest.json', 'utf8'))
|
||||
assert.doesNotThrow(() => verifyMonacoCoreNotices(process.cwd(), original))
|
||||
|
||||
Reference in new issue
Block a user