返回 CodeWhale
creator-pin.test.mjs
根目录 / crates / engine / extension-host / test / creator-pin.test.mjs
1 import assert from 'node:assert/strict'
2 import { createHash } from 'node:crypto'
3 import { readFileSync, readdirSync, statSync } from 'node:fs'
4 import { dirname, join, relative, sep } from 'node:path'
5 import { test } from 'node:test'
6 import { fileURLToPath } from 'node:url'
7
8 const here = dirname(fileURLToPath(import.meta.url))
9 const pin = join(here, '..', 'src', 'dsh', 'upstream', 'creator')
10 const manifest = JSON.parse(readFileSync(join(pin, 'UPSTREAM.json'), 'utf8'))
11 const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex')
12
13 function walk(dir) {
14 return readdirSync(dir).flatMap((name) => {
15 const path = join(dir, name)
16 return statSync(path).isDirectory() ? walk(path) : [path]
17 })
18 }
19
20 test('every pinned creator file equals its recorded hash and is verbatim or marked excerpt', () => {
21 assert.equal(manifest.version, '0.2.2-rc.1')
22 assert.equal((manifest.pending ?? []).length, 0)
23 assert.ok(manifest.files.length >= 3)
24 for (const entry of manifest.files) {
25 const bytes = readFileSync(join(pin, entry.path))
26 assert.equal(bytes.length, entry.bytes, `${entry.path} size`)
27 assert.equal(sha256(bytes), entry.sha256, `${entry.path} hash`)
28 assert.ok(!bytes.includes(13), `${entry.path} must keep LF line endings`)
29 if (entry.verbatim) continue
30 assert.equal(entry.excerpt, true, entry.path)
31 const text = bytes.toString('utf8')
32 for (const range of entry.lines) {
33 assert.ok(text.includes(`// ---- VERBATIM ${entry.package}@${manifest.version} ${entry.upstream_path}:${range} ----`), `${entry.path} missing start marker for ${range}`)
34 }
35 assert.equal(text.match(/\/\/ ---- END VERBATIM ----/g)?.length, entry.lines.length, `${entry.path} end markers`)
36 }
37 })
38
39 test('the pin directory holds exactly the files the manifest lists', () => {
40 const listed = new Set([...manifest.files.map((entry) => entry.path), 'UPSTREAM.json', 'LICENSE', 'README.md'])
41 const present = walk(pin).map((path) => relative(pin, path).split(sep).join('/'))
42 assert.deepEqual(present.sort(), [...listed].sort())
43 })
44
45 test('the licence is the MIT text the four packages ship', () => {
46 const license = readFileSync(join(pin, 'LICENSE'))
47 assert.equal(sha256(license), manifest.license_sha256)
48 assert.match(license.toString('utf8'), /^MIT License\n\nCopyright \(c\) 2026 DeepSeek\n/)
49 assert.deepEqual(manifest.packages.sort(), [
50 '@deepseek-ai/dsh-agent-preset',
51 '@deepseek-ai/dsh-plugin-manager',
52 '@deepseek-ai/dsh-sandbox',
53 '@deepseek-ai/dsh-tool-cordis',
54 ])
55 })
56
56 lines Plain Text