test(ci): [CI-TYPES-01] validate installed Audio and HLS types

This commit is contained in:
Harvey Zhao committed 2026-09-15 19:59:44 +08:00
1 parent 210484c443
commit 00c131bff1
16 files changed
+1246 -12

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
// eslint-disable-next-line test/no-import-node-test -- Exercises the repository's isolated compiler runner.
import { test } from 'node:test'
import { checkTypeFixture, typeMatrix } from '../scripts/consumers/types.ts'
import { consumerDirectory, removeConsumer } from '../scripts/package-consumer.mjs'
const source = `import { update } from 'fixture'
update('video.mp4')
// @ts-expect-error URL must stay a string.
update(123)
`
function setup(declaration = 'export declare function update(url: string): void') {
const dir = consumerDirectory()
const pkg = path.join(dir, 'node_modules/fixture')
fs.mkdirSync(pkg, { recursive: true })
fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify({ name: 'fixture', types: 'index.d.ts' }))
fs.writeFileSync(path.join(pkg, 'index.d.ts'), declaration)
return { dir, pkg }
}
test('Isolated consumer validates real declarations and each negative call in all five compiler modes', () => {
const { dir } = setup()
try {
for (const { compiler, mode } of typeMatrix) {
const result = checkTypeFixture(dir, source, compiler, mode)
assert.deepEqual(result.declarations, ['node_modules/fixture/index.d.ts'])
assert.deepEqual(result.negativeDiagnostics, [{ code: 2345, line: 4 }])
assert.equal(result.negativeStatements, 1)
}
}
finally { removeConsumer(dir) }
})
test('Missing declarations and accidental any widening fail installed consumer validation', () => {
const { dir, pkg } = setup()
const { compiler, mode } = typeMatrix[0]
try {
fs.rmSync(path.join(pkg, 'index.d.ts'))
assert.throws(() => checkTypeFixture(dir, source, compiler, mode), /Valid installed consumer failed/)
fs.writeFileSync(path.join(pkg, 'index.d.ts'), 'export declare function update(url: any): void')
assert.throws(() => checkTypeFixture(dir, source, compiler, mode), /Valid installed consumer failed/)
}
finally { removeConsumer(dir) }
})
test('A declaration reached through an external package link cannot silently satisfy the consumer', () => {
const { dir } = setup()
const external = consumerDirectory()
const { compiler, mode } = typeMatrix[0]
try {
fs.writeFileSync(path.join(external, 'index.d.ts'), 'export declare const value: string')
fs.symlinkSync(external, path.join(dir, 'node_modules/external'), process.platform === 'win32' ? 'junction' : 'dir')
assert.throws(() => checkTypeFixture(dir, `import { value } from 'external'\n${source}\nvoid value`, compiler, mode), /escaped installation/)
}
finally {
fs.unlinkSync(path.join(dir, 'node_modules/external'))
removeConsumer(dir)
removeConsumer(external)
}
})
+8 -1
View File
@@ -19,13 +19,20 @@ browser scope and the remaining package-specific release gates.
Run `yarn test:package` with the pinned Node and Yarn after a frozen install. The
default consumer scope is core and chapter. For the shared installed browser scope,
run `yarn test:package --browser`.
These four additional packages have reviewed published contracts and use the same
The additional packages have reviewed published contracts and use the same
source snapshot/build/pack/offline-install/frozen-reinstall pipeline. Installed
files are copied only after archive hash checks. The report explicitly separates
the core/chapter runtime/type scope from the additional browser package scope;
`--release` rejects additional packages until complete consumer coverage exists.
Other packages need a reviewed contract and their own consumers before inclusion.
Audio Track and HLS Control also run their complete `test/types/` fixtures against
the installed tarballs in five compiler modes, with every invalid call checked
again after removing error directives. `additionalTypeScope` and `pluginTypes`
record this separately from the original core/chapter checks. Other additional
packages still need their dedicated type consumers; no extra runtime scope is
implied. See [compiler module maintenance](../../scripts/consumers/README.md).
`scripts/package-check.mjs` copies source into an ignored build snapshot, rebuilds
all three formats and core languages using repository scripts, and runs Yarn pack.
It checks manifest targets, historical distribution files, archive members and