import assert from 'node:assert/strict' import { promises as fs } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' import { createRequire } from 'node:module' import test from 'node:test' const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') const require = createRequire(path.join(root, 'package.json')) // Reuse the existing TypeScript parser and ignore matcher. This is a source-input gate for // the repository's current literal/glob rules, not a replacement for a real Docker build. const ts = require('typescript') const ignore = require('ignore') const expected = [ 'lib/desktop-client/template-packs/gj-desk-dnz0385-native-v1.json', 'lib/desktop-client/template-packs/yjd-desk-dnz0385-native-v1.json', ] const policy = await fs.readFile(path.join(root, '.dockerignore'), 'utf8') const sourcePath = 'lib/desktop-client/template-packs.ts' const source = ts.createSourceFile(sourcePath, await fs.readFile(path.join(root, sourcePath), 'utf8'), ts.ScriptTarget.Latest, true) const imports = source.statements .filter(item => ts.isImportDeclaration(item) && ts.isStringLiteral(item.moduleSpecifier) && item.moduleSpecifier.text.endsWith('.json')) .map(item => path.posix.normalize(path.posix.join(path.posix.dirname(sourcePath), item.moduleSpecifier.text))) .sort() const matcher = ignore().add(policy) test('each statically imported template package exists and survives the build-context rules', async () => { assert.deepEqual(imports, expected, 'Review any new template import and add only its precise build input') for (const file of imports) { assert.equal(matcher.ignores(file), false, `Template import excluded from build context: ${file}`) const info = await fs.stat(path.join(root, file)) assert.ok(info.isFile() && info.size > 0 && info.size <= 600_000, `Invalid template input: ${file}`) assert.equal(JSON.parse(await fs.readFile(path.join(root, file), 'utf8')).schemaVersion, 1) } }) test('the package exceptions name exact files instead of opening the template directory', () => { const exceptions = policy.split(/\r?\n/).map(line => line.trim()) .filter(line => line.startsWith('!') && line.includes('template-packs')) assert.deepEqual(exceptions, expected.map(file => '!' + file)) }) test('other JSON, local authorization, uploads and private task data stay excluded', () => { for (const file of [ 'lib/desktop-client/template-packs/unreviewed-template.json', 'lib/desktop-client/template-packs/customer-session.json', 'lib/desktop-client/private-credentials.json', 'output/template-slots-20261023/profile-local-qa/jiansun/settings.json', '.private/connection.json', 'detail-generator-private/project/request.json', 'uploads/product/source.json', '.env.production', 'apps/detail-photocraft/local-settings.json', ]) assert.equal(matcher.ignores(file), true, `Sensitive or unrelated input reopened: ${file}`) }) test('removing these exact exceptions reproduces the missing-package build input failure', () => { const before = ignore().add(policy.split(/\r?\n/).filter(line => !expected.some(file => line.trim() === '!' + file)).join('\n')) for (const file of imports) assert.equal(before.ignores(file), true) })