mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-18 02:21:20 -08:00
build(site): [SITE-07] preserve exact Stack Overflow revision and attribution
This commit is contained in:
1 parent
3136eb2402
commit
0503fe8aa8
30 files changed
+1941
-27
No files matched your search
@@ -38,6 +38,7 @@ test('mobile vConsole shows logs and upstream site notice texts are served uncha
|
||||
expect(await index.text()).toContain('Included component: stylis (Emotion fork)')
|
||||
expect(await index.text()).toContain('Included component: murmurhash-js (Gary Court)')
|
||||
expect(await index.text()).toContain('Included component: murmurhash2 (Austin Appleby)')
|
||||
expect(await index.text()).toContain('stackoverflow-custom-stringify answer 48254637 revision 5 (CC BY-SA 4.0)')
|
||||
expect(await index.text()).toContain('Embedded attribution review is still incomplete')
|
||||
await page.evaluate(() => {
|
||||
window.vConsole.destroy()
|
||||
|
||||
@@ -7,7 +7,7 @@ import process from 'node:process'
|
||||
import test from 'node:test'
|
||||
import ts from 'typescript'
|
||||
import { decodeGitSource, verifyForkOutput, verifyGitSource } from '../scripts/site-vendor/console/attribution.ts'
|
||||
import { generateConsole, moduleRanges, obsoleteMap, upstreamSha256 } from '../scripts/site-vendor/console/build.ts'
|
||||
import { attributionBanner, generateConsole, moduleRanges, obsoleteMap, upstreamSha256 } from '../scripts/site-vendor/console/build.ts'
|
||||
import { extractNotice } from '../scripts/site-vendor/console/embedded-notices.ts'
|
||||
import { verifyMappedSources, verifyTransformedSources } from '../scripts/site-vendor/console/embedded-sources.ts'
|
||||
import { hash, parcelModules, verifyArchive, verifyModules, verifyPackageEdges } from '../scripts/site-vendor/console/provenance.ts'
|
||||
@@ -15,6 +15,22 @@ import { reconstructModule, verifyPrelude } from '../scripts/site-vendor/console
|
||||
import { errorArgument } from '../scripts/site-vendor/console/runtime/errors.ts'
|
||||
import { css } from '../scripts/site-vendor/console/runtime/style.ts'
|
||||
import { createSubscriptions } from '../scripts/site-vendor/console/runtime/subscriptions.ts'
|
||||
import { moduleStatement, revisionSnippet } from '../scripts/site-vendor/console/stackoverflow.ts'
|
||||
|
||||
test('Stack Overflow provenance rejects another revision, license or changed snippet', () => {
|
||||
const record = JSON.parse(fs.readFileSync('refactor/baselines/console-stackoverflow-provenance.json', 'utf8'))
|
||||
const response = fs.readFileSync(record.response.source)
|
||||
assert.equal(revisionSnippet(response, record.revision), fs.readFileSync(record.source, 'utf8'))
|
||||
for (const patch of [{ revision_number: 1 }, { content_license: 'CC BY-SA 3.0' }, { creation_date: 0 }, { body: 'changed' }]) {
|
||||
const data = JSON.parse(response)
|
||||
Object.assign(data.items[0], patch)
|
||||
assert.throws(() => revisionSnippet(Buffer.from(JSON.stringify(data)), record.revision), /identity changed|body changed/)
|
||||
}
|
||||
assert.throws(() => revisionSnippet(Buffer.from('{"items":[]}'), record.revision), /one fixed/)
|
||||
assert.equal(moduleStatement('var before = 0;\nvar customStringify = function () {};\nvar after = 2;', 'customStringify'), 'var customStringify = function () {};')
|
||||
assert.throws(() => moduleStatement('var other = 0;', 'customStringify'), /one module/)
|
||||
assert.throws(() => moduleStatement('var customStringify; var customStringify;', 'customStringify'), /one module/)
|
||||
})
|
||||
|
||||
test('Immutable Git attribution verifies original blob identity and rejects altered API content', () => {
|
||||
const record = JSON.parse(fs.readFileSync('refactor/baselines/console-derived-attribution.json', 'utf8'))
|
||||
@@ -234,7 +250,7 @@ test('Console error adaptation keeps existing stacks and arbitrary objects, and
|
||||
assert.equal(errorArgument(error), error)
|
||||
})
|
||||
|
||||
test('Console build changes only the two owned module bodies and is deterministic', async () => {
|
||||
test('Console build changes only owned bodies and a license comment and is deterministic', async () => {
|
||||
const source = fs.readFileSync('refactor/baselines/site-vendor/console-original.js', 'utf8')
|
||||
assert.equal(createHash('sha256').update(source).digest('hex'), upstreamSha256)
|
||||
const mask = (text) => {
|
||||
@@ -253,7 +269,8 @@ test('Console build changes only the two owned module bodies and is deterministi
|
||||
}
|
||||
visit(view)
|
||||
assert.deepEqual(styles, [css])
|
||||
assert.equal(mask(candidate), mask(source).slice(0, -obsoleteMap.length))
|
||||
assert.equal(mask(candidate), mask(source).slice(0, -obsoleteMap.length) + attributionBanner)
|
||||
assert.match(attributionBanner, /^\n\/\*![\s\S]*\*\/\n$/)
|
||||
assert.equal(candidate, await generateConsole(process.cwd()))
|
||||
assert.notEqual(candidate, source)
|
||||
assert.throws(() => moduleRanges('var unrelated = 1'), /Missing owned/)
|
||||
|
||||
@@ -111,7 +111,7 @@ test('Console notice CLI rejects omitted package or embedded attribution before
|
||||
const manifestPath = path.join(root, 'scripts/site-vendor/manifest.json')
|
||||
fs.mkdirSync(path.dirname(manifestPath), { recursive: true })
|
||||
const original = JSON.parse(fs.readFileSync('scripts/site-vendor/manifest.json', 'utf8'))
|
||||
for (const name of ['console-feed', 'parcel-bundler', 'styled-components', 'chromium-string-utils', 'stylis-rule-sheet', '@babel/runtime (react-inspector embedded)', 'regenerator-runtime', 'simple-html-tokenizer', 'replicator (console-feed fork)', 'stylis (Emotion fork)', 'murmurhash-js (Gary Court)', 'murmurhash2 (Austin Appleby)']) {
|
||||
for (const name of ['console-feed', 'parcel-bundler', 'styled-components', 'chromium-string-utils', 'stylis-rule-sheet', '@babel/runtime (react-inspector embedded)', 'regenerator-runtime', 'simple-html-tokenizer', 'replicator (console-feed fork)', 'stylis (Emotion fork)', 'murmurhash-js (Gary Court)', 'murmurhash2 (Austin Appleby)', 'stackoverflow-custom-stringify']) {
|
||||
for (const field of ['components', 'notices']) {
|
||||
const manifest = structuredClone(original)
|
||||
const group = manifest.groups.find(group => group.name === 'console')
|
||||
|
||||
Reference in new issue
Block a user