Files
open-design/apps/web/tests/runtime/design-system-package-audit.test.ts
Ethan GuoandGitHub b3e338ddb2 test(web): cover zip encoder, design-system audit, chat-events, mentions, utils (#2451)
* test(web): cover stored-mode ZIP encoder CRC and central directory

* test(web): cover design-system audit repair-actions and chat-events dedup

* test(web): cover @mention parsing and agent label normalization

* test(web): cover error flattener, prompt-template categories, design-system sentinel

* fix(web): set ZIP UTF-8 filename flag (bit 11) for non-ASCII names

buildZip wrote UTF-8 filename bytes (TextEncoder) but left the
general-purpose bit flag at 0 in both the local and central headers, so
readers fall back to CP437 and mis-decode non-ASCII names like 日本.md.

Set general-purpose bit 11 (0x0800, EFS) in both headers when the
filename contains a non-ASCII byte; pure-ASCII archives are unchanged
(ASCII == CP437 == UTF-8), matching how Python/Go zip encoders behave.

Strengthen the UTF-8 test to assert the flag + filename in BOTH the
local and central-directory headers (parsed via EOCD), and add a case
asserting pure-ASCII names do not set the flag.

Addresses review feedback on #2451.
2026-07-02 09:29:28 +00:00

84 lines
3.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
buildDesignSystemPackageAuditRepairPrompt,
designSystemPackageAuditHasFindings,
summarizeDesignSystemPackageAudit,
} from '../../src/runtime/design-system-package-audit';
import type {
DesignSystemPackageAudit,
DesignSystemPackageAuditIssue,
} from '../../src/types';
function audit(
errors: DesignSystemPackageAuditIssue[] = [],
warnings: DesignSystemPackageAuditIssue[] = [],
filesInspected = 12,
): DesignSystemPackageAudit {
return { ok: errors.length === 0, projectPath: '/tmp/p', filesInspected, errors, warnings };
}
const issue = (
code: string,
severity: 'error' | 'warning' = 'error',
path?: string,
): DesignSystemPackageAuditIssue => ({ severity, code, message: `${code} detail`, path });
describe('summarizeDesignSystemPackageAudit', () => {
it('reports inspected file count using singular/plural label when there are no findings', () => {
expect(summarizeDesignSystemPackageAudit(audit([], [], 1))).toBe(
'Package audit passed (1 file inspected).',
);
expect(summarizeDesignSystemPackageAudit(audit([], [], 3))).toBe(
'Package audit passed (3 files inspected).',
);
});
it('lists up to five findings and appends a +N more tail', () => {
const errs = Array.from({ length: 7 }, (_, i) => issue(`code_${i}`));
const text = summarizeDesignSystemPackageAudit(audit(errs));
expect(text).toContain('7 errors');
expect(text).toContain('code_0');
expect(text).toContain('code_4');
expect(text).toContain('+2 more');
});
it('joins error and warning counts with "and" and includes path tags when present', () => {
const text = summarizeDesignSystemPackageAudit(
audit([issue('missing_skill_frontmatter', 'error', 'SKILL.md')], [issue('readme_thin', 'warning')]),
);
expect(text).toContain('1 error and 1 warning');
expect(text).toContain('missing_skill_frontmatter (SKILL.md)');
expect(text).toContain('readme_thin');
});
});
describe('buildDesignSystemPackageAuditRepairPrompt', () => {
it('returns null when the audit has no findings', () => {
expect(buildDesignSystemPackageAuditRepairPrompt(audit())).toBeNull();
});
it('emits a targeted UI-kit repair action when ui_kit codes appear', () => {
const prompt = buildDesignSystemPackageAuditRepairPrompt(
audit([issue('ui_kit_index_missing_runtime_bootstrap')]),
);
expect(prompt).not.toBeNull();
expect(prompt!).toContain('Targeted repair actions:');
expect(prompt!).toContain('ui_kits/app/index.html');
});
it('truncates the findings list at 16 entries with a more-N suffix', () => {
const errs = Array.from({ length: 20 }, (_, i) => issue(`c_${i}`));
const prompt = buildDesignSystemPackageAuditRepairPrompt(audit(errs))!;
expect(prompt).toContain('...and 4 more audit finding(s).');
});
});
describe('designSystemPackageAuditHasFindings', () => {
it('returns true when there are errors or warnings, false otherwise', () => {
expect(designSystemPackageAuditHasFindings(audit())).toBe(false);
expect(designSystemPackageAuditHasFindings(audit([issue('x')]))).toBe(true);
expect(designSystemPackageAuditHasFindings(audit([], [issue('y', 'warning')]))).toBe(true);
});
});