Skip to content

Commit b566f7e

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
Merge branch 'codex/design-diff-engine' into codex/design-diff-benchmark-v3
2 parents 6cc31ee + 309054c commit b566f7e

3 files changed

Lines changed: 40 additions & 15 deletions

File tree

scripts/design-diff/ast.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ export function canonical(value: unknown): Data {
4343
return canonical(node.expression)
4444
const result: Record<string, Data> = Object.create(null)
4545
for (const key of Object.keys(node).sort()) {
46+
/** Babel builders and parsed nodes spell absent optional fields differently. */
47+
if (
48+
(key === 'optional' && /Expression$/.test(String(node.type)) && !node[key]) ||
49+
(key === 'method' && node.type === 'ObjectProperty' && node[key] === false) ||
50+
(['id', 'generator', 'expression'].includes(key) &&
51+
node.type === 'ArrowFunctionExpression' &&
52+
!node[key])
53+
)
54+
continue
4655
if (
4756
[
4857
'start',

scripts/design-diff/refactors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export function normalizeLiteralAliases(ast: t.File, visit: typeof traverse): vo
132132
}
133133
visit(ast, {
134134
Expression(path) {
135+
if (path.key === 'id') return
135136
if (path.parentPath.isExportSpecifier()) return
136137
if (path.findParent((parent) => parent.isTSType())) return
137138
if (!(path.isReferencedIdentifier() || path.isObjectExpression() || path.isArrayExpression()))

scripts/design-diff/tests/precision.test.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,24 @@ it('preserves helper switch selection conditions', async () => {
200200
expect(report.flagged).toBe(true)
201201
})
202202

203-
it('preserves the audited Object.entries reducer to fromEntries refactor', async () => {
204-
const before =
205-
'export const copy=(blocks)=>Object.entries(blocks).reduce((acc,[id,block])=>({...acc,[id]:{...block,value:structuredClone(block.value)}}),{})'
206-
const after =
207-
'export const copy=(blocks)=>Object.fromEntries(Object.entries(blocks).map(([id,block])=>[id,{...block,value:structuredClone(block.value)}]))'
208-
const report = await compareFiles(
209-
{
210-
[data]: before,
211-
[view]: 'import {copy} from "./data";export const Page=()=> <Panel data={copy(blocks)}/>',
212-
},
213-
{ [data]: after },
214-
settings
215-
)
216-
expect(report.flagged).toBe(false)
217-
})
203+
it.each([1, 24])(
204+
'preserves the audited record-map refactor at resolution depth %s',
205+
async (resolutionDepth) => {
206+
const before =
207+
'export const copy=(blocks)=>Object.entries(blocks).reduce((acc,[id,block])=>({...acc,[id]:{...block,value:structuredClone(block.value)}}),{})'
208+
const after =
209+
'export const copy=(blocks)=>Object.fromEntries(Object.entries(blocks).map(([id,block])=>[id,{...block,value:structuredClone(block.value)}]))'
210+
const report = await compareFiles(
211+
{
212+
[data]: before,
213+
[view]: 'import {copy} from "./data";export const Page=()=> <Panel data={copy(blocks)}/>',
214+
},
215+
{ [data]: after },
216+
{ ...settings, limits: { ...settings.limits, resolutionDepth } }
217+
)
218+
expect(report.flagged).toBe(false)
219+
}
220+
)
218221

219222
it('keeps selected environment evidence narrow after exhausting expression depth', async () => {
220223
const source = (size: number) =>
@@ -284,3 +287,15 @@ it('leaves type queries over literal constants erased and parseable', async () =
284287
.some((reason) => /parser|extraction failed/i.test(reason))
285288
).toBe(false)
286289
})
290+
291+
it('preserves value/type names shared by generated schema declarations', async () => {
292+
const source = (text: string) =>
293+
`const Kind={ONE:1};type Kind=typeof Kind;export const Page=()=> <div>${text}</div>`
294+
const report = await compareFiles({ [view]: source('a') }, { [view]: source('b') }, settings)
295+
expect(report.flagged).toBe(true)
296+
expect(
297+
report.findings
298+
.flatMap((finding) => finding.limitations)
299+
.some((reason) => /parser|extraction failed/i.test(reason))
300+
).toBe(false)
301+
})

0 commit comments

Comments
 (0)