Skip to content

Commit 5259aeb

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(design): fail incomplete central source comparisons
1 parent 9d21f28 commit 5259aeb

2 files changed

Lines changed: 91 additions & 1 deletion

File tree

‎scripts/check-design-conformance-command.test.ts‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,88 @@ test('working-tree mode includes a changed central contract registry', () => {
672672
expect(report.findings.some((finding) => finding.file === file)).toBe(true)
673673
})
674674

675+
test.each(['before', 'after', 'rename', 'invalid-base', 'invalid-head', 'unresolved'])(
676+
'central inspection coverage preserves the CLI failure boundary: %s',
677+
(scenario) => {
678+
const { repo } = fixture()
679+
const file = 'packages/emcn/src/components/view.tsx'
680+
const renamed = 'packages/emcn/src/components/moved-view.tsx'
681+
const valid = 'const View=()=> <div/>'
682+
const extractionFailure =
683+
"import {constructor} from '../index';const View=()=> <div className={constructor}/>"
684+
const malformed = 'const View=()=> <div className={'
685+
const write = (name: string, source: string) => {
686+
mkdirSync(path.dirname(path.join(repo, name)), { recursive: true })
687+
writeFileSync(path.join(repo, name), source)
688+
}
689+
write(ui, valid)
690+
write('packages/emcn/src/index.ts', 'export {}')
691+
write(
692+
file,
693+
scenario === 'invalid-base'
694+
? malformed
695+
: ['before', 'rename'].includes(scenario)
696+
? extractionFailure
697+
: valid
698+
)
699+
const base = commit(repo)
700+
if (scenario === 'rename') git(repo, ['mv', file, renamed])
701+
else
702+
write(
703+
file,
704+
scenario === 'invalid-head'
705+
? malformed
706+
: scenario === 'after'
707+
? extractionFailure
708+
: scenario === 'unresolved'
709+
? "import {missing} from '../index';const View=()=> <div className={missing}/>"
710+
: valid
711+
)
712+
const head = commit(repo)
713+
const child = run(['--repo', repo, '--base', base, '--head', head, '--format', 'json'])
714+
const report = JSON.parse(child.stdout) as Report
715+
expect(child.status, child.stdout).toBe(scenario === 'unresolved' ? 0 : 2)
716+
expect(report.status).toBe(scenario === 'unresolved' ? 'completed' : 'failed')
717+
expect(report.flagged).toBe(scenario === 'unresolved' ? false : null)
718+
if (['before', 'after', 'rename'].includes(scenario)) {
719+
const expected =
720+
scenario === 'rename'
721+
? [
722+
{ file, side: 'before' },
723+
{ file: renamed, side: 'after' },
724+
]
725+
: [{ file, side: scenario }]
726+
expect(report.coverageFailures).toHaveLength(expected.length)
727+
expect(report.coverageFailures).toEqual(
728+
expect.arrayContaining(
729+
expected.map((origin) =>
730+
expect.objectContaining({
731+
...origin,
732+
reason: expect.stringMatching(/^Extraction failure:/),
733+
})
734+
)
735+
)
736+
)
737+
expect(report.unchecked).toEqual(
738+
expect.arrayContaining(
739+
expected.map((origin) =>
740+
expect.objectContaining({
741+
...origin,
742+
reason: expect.stringMatching(/^Extraction failure:/),
743+
})
744+
)
745+
)
746+
)
747+
} else if (scenario === 'unresolved') {
748+
expect(report.coverageFailures).toEqual([])
749+
expect(
750+
report.unchecked.some((note) => note.reason.includes('Imported styling input is unchecked'))
751+
).toBe(true)
752+
} else expect(report.error).toMatch(/parser failure|Extraction failure/i)
753+
},
754+
30_000
755+
)
756+
675757
test('text, JSON and output files preserve finding identity and normal command exit codes', () => {
676758
const { repo, base, head } = fixture()
677759
const args = ['--repo', repo, '--base', base]

‎scripts/design-conformance/conformance.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,15 @@ export class ConformanceLinter {
885885
['before', before],
886886
['after', after],
887887
] as const)
888-
for (const note of facts.unchecked) report.unchecked.push({ ...note, file, side })
888+
for (const note of facts.unchecked) {
889+
const diagnostic = {
890+
...note,
891+
file: side === 'before' ? (change.before?.path ?? file) : file,
892+
side,
893+
}
894+
report.unchecked.push(diagnostic)
895+
if (inspectionFailure(note.reason)) report.coverageFailures?.push(diagnostic)
896+
}
889897
const converted = (f: Facts, system: DesignSystem): Facts => ({
890898
...f,
891899
atoms: f.atoms.map((a) => compilationAtom(a, system)),

0 commit comments

Comments
 (0)