Files
openmotion/tests/release-scan.test.mjs
open-design-crew[bot] 64fab318d4 Route OpenMotion community entries to the README Feishu and Discord invitations (#446)
* Route localized community links to Feishu

* Allow the current public Feishu invitation in release scans

The community-link change replaced the owner-approved public Feishu
invitation, so the pinned scanner digest and the gitleaks allowlist still
matched the expired token and the source, controls and distribution scans
rejected the new README URLs and the shared Studio community link.

Re-pin the approved invitation digest and the secret allowlist to the
current token, and scope the exemption to the product READMEs, the shared
community link module and its bundled Studio asset. Add focused coverage
for both scan paths so adjacent or changed invitations still fail.

Generated-By: looper 0.16.2 (runner=fixer, agent=pi)

* Move the Feishu community icon into the design system

The new Feishu artwork lived under the Studio feature directory, which put
a second application icon outside the shared asset boundary. Move the SVG
to packages/design-system/brand, register it in the package brand and
public asset contract, and consume it through a relative package import
like the other brand artwork.

Also describe the Simplified Chinese Feishu destination in the product
architecture and correct the community-link note in the UI review record,
which still explained the previous Discord-only decision.

Generated-By: looper 0.16.2 (runner=fixer, agent=pi)

* Match Studio community entries to the OpenMotion README invitations

---------

Co-authored-by: 孙庆雨 <sunqingyu@ElideMBP.lan>
Co-authored-by: 罗高 <luogao@users.noreply.github.com>
Co-authored-by: joeylee12629-star <236967869+joeylee12629-star@users.noreply.github.com>
2026-11-16 19:05:00 +08:00

122 lines
8.2 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { chmod, mkdtemp, mkdir, readFile, rm, symlink, writeFile } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { archivePaths, privacyFindings, scanSource, scanPackage, unpackChecked } from '../.github/scripts/motion-scan.mjs';
import { candidateFixture } from './release-fixture.mjs';
import { runFile, sha256, writeJSON } from '../scripts/runtime-assets.mjs';
test('privacy rules reject internal URLs, employee paths and private files without printing their values', () => {
for (const name of ['.env', 'nested/.env.production', '.npmrc', 'outputs/log.json', 'research/info.md', 'server.key']) assert(privacyFindings(name, '').length);
assert.equal(privacyFindings('.env.example', 'DUMMY=example').length, 0);
assert(privacyFindings('.env.example', '', 'package').length);
const url = 'https://' + 'workspace.' + 'feishu.cn/wiki/private';
const text = '/' + 'Users/' + 'employee/private/file';
assert.deepEqual(privacyFindings('README.md', url).map(x => x.rule), ['internal-link']);
assert.deepEqual(privacyFindings('README.md', text).map(x => x.rule), ['personal-path']);
assert(!JSON.stringify(privacyFindings('README.md', url)).includes('private'));
for (const name of ['../escape', '/absolute', 'C:/drive', 'safe/../../outside', 'bad\\file', 'bad\tname']) assert.throws(() => archivePaths(name));
});
test('only the approved public community invitation is permitted in product READMEs', async () => {
const text = await readFile(new URL('../README.md', import.meta.url), 'utf8');
const invite = text.match(/href="([^"\n]+add_by_link[^"\n]+)"/)[1];
const internal = 'https://' + 'workspace.' + 'feishu.cn/wiki/private';
for (const kind of ['source', 'package']) {
for (const name of ['README.md', 'README.zh-CN.md', 'docs/README.zh-CN.md', 'docs/README.ja.md']) {
assert.deepEqual(privacyFindings(name, `<a href="${invite}">Community</a>`, kind), []);
for (const value of [invite + 'x', invite + '&extra=1', invite.replace('https:', 'http:'), invite + ' ' + internal]) {
assert(privacyFindings(name, value, kind).some(hit => hit.rule === 'internal-link'));
}
}
for (const name of ['notes.md', 'nested/README.md', 'docs/install.md', 'nested/package/README.md', 'package/nested/README.md', 'package/package/README.md']) {
assert(privacyFindings(name, invite, kind).some(hit => hit.rule === 'internal-link'));
}
}
// The npm installer archive keeps the same product READMEs under its single `package/` root.
for (const name of ['package/README.md', 'package/README.zh-CN.md', 'package/docs/README.zh-CN.md', 'package/docs/README.ja.md']) {
assert.deepEqual(privacyFindings(name, `<a href="${invite}">Community</a>`, 'package'), []);
for (const value of [invite + 'x', invite + '&extra=1', invite.replace('https:', 'http:'), invite + ' ' + internal]) {
assert(privacyFindings(name, value, 'package').some(hit => hit.rule === 'internal-link'));
}
assert(privacyFindings(name, invite, 'source').some(hit => hit.rule === 'internal-link'));
}
});
test('the shared Studio community link may carry the same approved invitation in source and its bundled asset', async () => {
const text = await readFile(new URL('../README.md', import.meta.url), 'utf8');
const invite = text.match(/href="([^"\n]+add_by_link[^"\n]+)"/)[1];
const internal = 'https://' + 'workspace.' + 'feishu.cn/wiki/private';
for (const kind of ['source', 'package']) {
const prefix = kind === 'package' ? 'package/' : '';
for (const name of ['studio/src/motion/CommunityLink.tsx', 'studio/build/editor-assets/index-9f1c2d3e.js']) {
assert.deepEqual(privacyFindings(prefix + name, `const communityUrl = '${invite}';`, kind), []);
for (const value of [invite + 'x', invite + '&extra=1', invite + ' ' + internal]) {
assert(privacyFindings(prefix + name, value, kind).some(hit => hit.rule === 'internal-link'));
}
}
for (const name of ['studio/src/motion/Other.tsx', 'studio/build/index.js', 'studio/build/editor-assets/index-9f1c2d3e.css', 'nested/studio/src/motion/CommunityLink.tsx', 'nested/package/studio/build/editor-assets/index-9f1c2d3e.js']) {
assert(privacyFindings(prefix + name, invite, kind).some(hit => hit.rule === 'internal-link'));
}
}
});
async function scanner(t, findings = []) {
const work = await mkdtemp(path.join(os.tmpdir(), 'motion-scanner-test-')); t.after(() => rm(work, { recursive: true, force: true }));
const binary = path.join(work, 'scanner');
const script = `#!/usr/bin/env node\nimport{writeFileSync}from'node:fs'; const args=process.argv.slice(2); if(!args.includes('--redact')||!args.includes('--ignore-gitleaks-allow'))process.exit(2); writeFileSync(args[args.indexOf('--report-path')+1],JSON.stringify(${JSON.stringify(findings)}));process.exit(${findings.length ? 1 : 0});\n`;
await writeFile(binary, script); await chmod(binary, 0o755); return { work, binary };
}
test('tracked source is scanned without ignore-file bypasses; secret errors expose only rule/path/line', async t => {
const { work, binary } = await scanner(t, [{ File: 'source.txt', RuleID: 'fixture-secret', StartLine: 1, Secret: 'never-print-this' }]);
const source = path.join(work, 'source'); await mkdir(source);
await runFile('git', ['init', '-q', source]); await writeFile(path.join(source, 'source.txt'), 'synthetic fixture');
await runFile('git', ['add', '.'], { cwd: source });
await assert.rejects(scanSource(source, binary), error => error.message.includes('fixture-secret') && !error.message.includes('never-print-this'));
await symlink('source.txt', path.join(source, 'link')); await runFile('git', ['add', 'link'], { cwd: source });
await assert.rejects(scanSource(source, binary), /Tracked links/);
});
test('catalog source is scanned alongside gallery and product source without skipping its privacy checks', async t => {
const { work, binary } = await scanner(t);
const source = path.join(work, 'source');
const catalog = path.join(source, 'library/templates/catalog/demo/guide.md');
await mkdir(path.dirname(catalog), { recursive: true });
await mkdir(path.join(source, 'docs/readme'), { recursive: true });
await writeFile(path.join(source, 'README.md'), 'Public product');
await writeFile(path.join(source, 'docs/readme/gallery.md'), 'Public gallery');
await writeFile(catalog, 'https://' + 'workspace.' + 'feishu.cn/wiki/private');
await runFile('git', ['init', '-q', source]);
await runFile('git', ['add', '.'], { cwd: source });
await assert.rejects(scanSource(source, binary), /catalog\/demo\/guide.md.*internal-link/);
await writeFile(catalog, 'Public catalog');
const report = await scanSource(source, binary);
assert.equal(report.status, 'passed');
assert.equal(report.files, 3);
});
test('the scanner opens the nested application, rejects hidden private content and rejects linked archive entries', async t => {
const f = await candidateFixture(t), { binary } = await scanner(t);
assert.equal((await scanPackage(path.join(f.directory, f.candidate.tgz), binary)).status, 'passed');
const templates = path.join(f.app, 'shared/template-config.json');
await writeJSON(templates, { environment: 'prod' });
const appArchive = path.join(f.pkg, 'payload', f.manifest.application.url.slice(2));
const tgz = path.join(f.work, 'hidden.tgz');
const repack = async () => {
await runFile('tar', ['-czf', appArchive, '-C', f.app, '.']);
await writeJSON(path.join(f.pkg, 'payload/release-npm.json'), { ...f.manifest, application: { ...f.manifest.application, sha256: await sha256(appArchive) } });
await runFile('tar', ['-czf', tgz, '-C', f.work, 'package']);
};
await repack();
await assert.rejects(scanPackage(tgz, binary), /template defaults differ/);
await writeJSON(templates, { environment: 'dev' });
await writeFile(path.join(f.app, '.env'), 'EXAMPLE=not-a-real-secret');
await repack();
await assert.rejects(scanPackage(tgz, binary), /environment-file/);
await symlink('package.json', path.join(f.app, 'linked')); const linked = path.join(f.work, 'linked.tar.gz');
await runFile('tar', ['-czf', linked, '-C', f.app, '.']);
await assert.rejects(unpackChecked(linked, path.join(f.work, 'extracted')), /links and special/);
});