Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d507a5c
fix(bestax-migrate): keep href on the anchor, and as inside its union
allxsmith Sep 11, 2026
9f938fa
docs: name the href and as rules the codemod now applies
allxsmith Sep 11, 2026
65c1864
fix(bestax-migrate): drop an href on the targets that declare none
allxsmith Sep 12, 2026
a1de6c1
test(bestax-migrate): hold RBC's TODO rules to its skill reference too
allxsmith Sep 12, 2026
dfc68e8
docs: correct two href claims the references make
allxsmith Sep 12, 2026
10209e5
fix(bestax-migrate): decide the href from the element, not the leftovers
allxsmith Sep 12, 2026
d6e923f
fix(bestax-migrate): read the element a target renders, not the type …
allxsmith Sep 12, 2026
78a2017
fix(bestax-migrate): take the anchor's other attributes with it, and …
allxsmith Sep 12, 2026
6ece337
fix(bestax-migrate): give the TODO the remedy that works on the targe…
allxsmith Sep 12, 2026
1d0fba3
fix(bestax-migrate): judge every link attribute against the element, …
allxsmith Sep 12, 2026
f0f2563
fix(bestax-migrate): keep a TODO on one line, and correct the link-at…
allxsmith Sep 12, 2026
0fb251e
fix(bestax-migrate): bound the link attributes by the component too, …
allxsmith Sep 12, 2026
c793554
test(bestax-migrate): fail a case that never migrated, instead of che…
allxsmith Sep 12, 2026
68e705f
fix(bestax-migrate): run the link cleanup on react-bulma-components' …
allxsmith Sep 12, 2026
766eed7
test(bestax-migrate): assert the three sources agree on the same shape
allxsmith Sep 12, 2026
d335daf
fix(bestax-migrate): the component and the element must both allow th…
allxsmith Sep 12, 2026
4e4a198
fix(bestax-migrate): plain markup keeps the href its own tag accepts
allxsmith Sep 12, 2026
b94d4c9
test(bestax-migrate): pin the last table, which was wrong the moment …
allxsmith Sep 12, 2026
5cf4e86
docs: make every rule the link pass can emit greppable
allxsmith Sep 12, 2026
98bf245
test(bestax-migrate): assert the premise behind the one-row exception
allxsmith Sep 13, 2026
c5465f0
fix(bestax-migrate): judge props against the component they will end …
allxsmith Sep 13, 2026
3f844b6
fix(bestax-migrate): widen the element universe until it disagreed, a…
allxsmith Sep 13, 2026
b184236
test(bestax-migrate): check the rows against all of HTML, not a list …
allxsmith Sep 13, 2026
04af8cc
fix(bestax-migrate): announce the one removal that was still silent
allxsmith Sep 13, 2026
321143b
fix(bestax-migrate): trust an `as` a spread cannot overwrite, and sto…
allxsmith Sep 13, 2026
0324455
fix(bestax-migrate): a spread hides the element, not the component
allxsmith Sep 13, 2026
b807790
test(bestax-migrate): assert HREF_OK names the right targets, not jus…
allxsmith Sep 13, 2026
8b14c92
fix(bestax-migrate): only rbx's spread can carry an `as`
allxsmith Sep 13, 2026
9e73145
docs(bestax-migrate): settle the bare-spread reading
allxsmith Sep 13, 2026
77ae350
fix(bestax-migrate): keep an href the plain tag takes, and quieten th…
allxsmith Sep 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bestax-mcp/data/skills.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
{
"id": "bloomer-prop-map",
"file": "references/bloomer/prop-map.md",
"bytes": 22758
"bytes": 24475
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
},
{
"id": "bloomer-unmappables",
"file": "references/bloomer/unmappables.md",
"bytes": 12915
"bytes": 14807
},
{
"id": "css-migration",
Expand All @@ -113,12 +113,12 @@
{
"id": "rbx-prop-map",
"file": "references/rbx/prop-map.md",
"bytes": 10585
"bytes": 11653
},
{
"id": "rbx-unmappables",
"file": "references/rbx/unmappables.md",
"bytes": 10931
"bytes": 12333
},
{
"id": "react-bulma-components-component-map",
Expand All @@ -128,12 +128,12 @@
{
"id": "react-bulma-components-prop-map",
"file": "references/react-bulma-components/prop-map.md",
"bytes": 6363
"bytes": 7334
},
{
"id": "react-bulma-components-unmappables",
"file": "references/react-bulma-components/unmappables.md",
"bytes": 6715
"bytes": 8337
}
],
"examples": []
Expand Down
179 changes: 179 additions & 0 deletions bestax-migrate/e2e/as-unions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/**
* `AS_UNIONS` decides which `as` values survive a migration, and it is a hand
* written copy of unions that live in bulma-ui. A copy that drifts is worse
* than no table at all: too narrow, and the codemod TODOs an `as` that would
* have worked; too wide, and it emits output the user's project cannot
* compile — which is the defect that #662 was.
*
* bulma-ui exports these as types, not as runtime constants, so no runtime
* diff can check them. This generates one type assertion per row and hands it
* to `tsc` against the built library, which makes drift in either direction a
* failure here rather than in someone's project.
*/

import {
AS_ANY_TARGETS,
AS_UNIONS,
HREF_TABLE,
declaresAs,
} from '../src/sources/_shared/polymorphic.js';
import { typecheckTsx } from './support/typecheck-tsx.js';

const TARGETS = Object.keys(AS_UNIONS).sort();

/** `Level.Item` is reached through the `Level` its mapping target names. */
const importRoots = [...new Set(TARGETS.map(t => t.split('.')[0]))].sort();

function buildSource(): string {
const rows = TARGETS.map((target, i) => {
const union = AS_UNIONS[target].map(v => `'${v}'`).join(' | ');
return `type _${i} = Assert<Exact<${union}, AsOf<typeof ${target}>>>; // ${target}`;
});
return [
"import type { JSXElementConstructor } from 'react';",
`import { ${importRoots.join(', ')} } from '@allxsmith/bestax-bulma';`,
'',
// Reach `as` through the props rather than `ComponentProps<C>['as']`:
// several of these components type their props as a UNION of shapes, and
// the `infer` distributes over it where an index access cannot.
'type AsOf<C> = C extends JSXElementConstructor<infer P>',
' ? P extends { as?: infer A } ? NonNullable<A> : never',
' : never;',
'type Exact<A, B> = [A] extends [B] ? ([B] extends [A] ? true : false) : false;',
'type Assert<T extends true> = T;',
'',
...rows,
'',
'export {};',
].join('\n');
}

/**
* tsc reports a row by line number, and a bare "Type 'false' does not satisfy
* the constraint 'true'" says nothing about which component drifted. Quote
* the generated line beside each diagnostic so the failure names the target.
*/
function annotate(diagnostics: string, source: string): string {
const lines = source.split('\n');
return diagnostics
.split('\n')
.map(line => {
const at = /check\.tsx\((\d+),/.exec(line);
const row = at && lines[Number(at[1]) - 1];
return row ? `${line}\n ↳ ${row.trim()}` : line;
})
.join('\n');
}

describe('AS_UNIONS matches the `as` each bestax component declares', () => {
it('asserts every row against the library, in both directions', () => {
const source = buildSource();
const { status, diagnostics } = typecheckTsx(source, 'as-unions');
expect({ status, diagnostics: annotate(diagnostics, source) }).toEqual({
status: 0,
diagnostics: '',
});
});

it('covers every component the mappings can hand a narrowed `as`', () => {
// A row removed by accident would make the assertion above pass while
// the transform stopped guarding that component, so pin the set itself.
expect(TARGETS).toEqual([
'Control',
'Dropdown.Item',
'Footer',
'Image',
'Level.Item',
'Media',
'Media.Left',
'SubTitle',
'Title',
]);
});
});

/**
* `HREF_TABLE` and `AS_ANY_TARGETS` are the other two hand-written mirrors of
* bulma-ui's types, and the more dangerous ones: they say what the codemod may
* KEEP, so a row that is wrong in either direction ships output that does not
* compile, or deletes an attribute that did.
*
* A type assertion cannot express "this element accepts this attribute", so
* these assert by USE -- each row becomes the JSX it licenses, and tsc accepts
* or rejects it exactly as a migrated project would.
*/
function buildHrefSource(): string {
const rows: string[] = [];
const roots = new Set<string>();
for (const [target, defaultEl] of Object.entries(HREF_TABLE)) {
roots.add(target.split('.')[0]);
const i = rows.length;
// Only where the component declares an `as` at all -- `Pagination.Link`
// and `Panel.Block` are anchors outright and take no such prop.
if (declaresAs(target)) {
rows.push(
`export const h${i} = <${target} as="a" href="#">{'x'}</${target}>; // ${target}: as="a"`
);
}
if (defaultEl === 'a') {
rows.push(
`export const b${i} = <${target} href="#">{'x'}</${target}>; // ${target}: bare`
);
}
}
for (const target of AS_ANY_TARGETS) {
roots.add(target.split('.')[0]);
const i = rows.length;
rows.push(
`export const a${i} = <${target} as="span">{'x'}</${target}>; // ${target}: any`
);
Comment thread
Copilot marked this conversation as resolved.
Resolved
}
return [
`import { ${[...roots].sort().join(', ')} } from '@allxsmith/bestax-bulma';`,
'',
...rows,
'',
].join('\n');
}

describe('the href and `as` tables match what the library accepts', () => {
it('licenses exactly the shapes the tables claim', () => {
const source = buildHrefSource();
const { status, diagnostics } = typecheckTsx(source, 'href-table');
expect({ status, diagnostics: annotate(diagnostics, source) }).toEqual({
status: 0,
diagnostics: '',
});
});

it('pins the set of href-capable targets, and what each renders', () => {
// The table says where an `href` may stay; everything absent from it loses
// the attribute. A row added by accident is how #662 shipped, and a row
// missed is how `Pagination.Next` did — it is reached through a `special`
// rather than a `target:` line, so reading the mappings does not find it.
// The typecheck above cannot pin the default element: `Level.Item`
// declares `href` at every `as`, so the bare form compiles even though it
// renders a <div> and drops the attribute. That row is held here and by
// the comment on the table, which cites the line in bulma-ui.
expect(HREF_TABLE).toEqual({
Button: 'button',
'Level.Item': 'div',
'Menu.Item': 'a',
'Navbar.Item': 'a',
'Navbar.Link': 'a',
'Pagination.Link': 'a',
'Pagination.Next': 'a',
'Pagination.Previous': 'a',
'Panel.Block': 'a',
});
});

it('pins the targets whose `as` takes any element', () => {
expect(AS_ANY_TARGETS).toEqual([
'Button',
'Menu.Item',
'Navbar.Item',
'Navbar.Link',
]);
});
});
17 changes: 16 additions & 1 deletion bestax-migrate/e2e/bloomer-kitchen-sink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ describe('bloomer kitchen-sink e2e', () => {
'component:DropdownContent',
'component:Icon',
'prop:tag',
'prop:as',
'prop:href',
'prop:render',
'prop:isGrid',
'prop:hasAddons',
Expand Down Expand Up @@ -298,6 +300,19 @@ describe('bloomer kitchen-sink e2e', () => {
const backticked = new Set(
[...refs.matchAll(/`([A-Za-z][\w.-]*)`/g)].map(m => m[1])
);
// A `prop:` rule gets a stricter reading: only a heading or a table row
// counts. Matching a backtick anywhere made that fallback near vacuous --
// `\`as\`` occurs in ordinary prose in every one of these files, so
// `prop:as` read as documented in all three sources whether a recipe
// existed or not, which is how RBC shipped without one. Rules with no
// `prop:`/`component:` prefix (`deps`, `peer-deps`) stay loose: they are
// explained in SKILL.md's prose, which is the right home for them.
const inHeadingOrRow = new Set(
refs
.split('\n')
.filter(l => l.startsWith('|') || l.startsWith('#'))
.flatMap(l => [...l.matchAll(/`([A-Za-z][\w.-]*)`/g)].map(m => m[1]))
);

const documented = (rule: string): boolean => {
if (tokens.has(rule)) return true;
Expand All @@ -309,7 +324,7 @@ describe('bloomer kitchen-sink e2e', () => {
);
}
if (rule.startsWith('prop:')) {
return backticked.has(rule.slice('prop:'.length));
return inHeadingOrRow.has(rule.slice('prop:'.length));
}
return backticked.has(rule);
};
Expand Down
79 changes: 78 additions & 1 deletion bestax-migrate/e2e/kitchen-sink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const tmpDir = fs.mkdtempSync(path.join(tmpRoot, 'kitchen-sink-'));

interface MigratedApp {
todosByFile: Map<string, TodoEntry[]>;
/** TODOs from the manifest pass, which belongs to no source file. */
depTodos: TodoEntry[];
files: string[];
}

Expand Down Expand Up @@ -100,7 +102,7 @@ function migrateKitchenSink(): MigratedApp {
fs.writeFileSync(pkgPath, `${JSON.stringify(pkgNext, null, 2)}\n`);
}

return { todosByFile, files };
return { todosByFile, files, depTodos: pkgTodos };
}

describe('kitchen-sink e2e', () => {
Expand Down Expand Up @@ -213,6 +215,8 @@ describe('kitchen-sink e2e', () => {
expect(rules).toContain('prop:remove');
expect(rules).toContain('prop:subtitle');
expect(rules).toContain('prop:heading');
expect(rules).toContain('prop:as');
expect(rules).toContain('prop:href');
expect(todos.length).toBeGreaterThanOrEqual(10);
const migrated = fs.readFileSync(
path.join(tmpDir, 'src', 'leftovers.tsx'),
Expand All @@ -225,6 +229,79 @@ describe('kitchen-sink e2e', () => {
);
});

it('documents every TODO rule it emits in the skill reference', () => {
// A rule with no recipe is a dead end for the user reading the report.
// rbx and bloomer have had this guard for a while; RBC did not, which is
// how `prop:as` and `prop:href` reached its output on #662 with no entry
// in its `unmappables.md` while both siblings gained one.
const skillDir = path.join(packageRoot, '..', 'skills', 'bestax-migrate');
const refsDir = path.join(skillDir, 'references', 'react-bulma-components');
const refs = [
...fs
.readdirSync(refsDir)
.filter(f => f.endsWith('.md'))
.map(f => path.join(refsDir, f)),
path.join(skillDir, 'SKILL.md'),
]
.map(f => fs.readFileSync(f, 'utf8'))
.join('\n');

const emitted = new Set<string>();
for (const todos of app.todosByFile.values()) {
for (const todo of todos) emitted.add(todo.rule);
}
for (const todo of app.depTodos) emitted.add(todo.rule);
expect(emitted.size).toBeGreaterThan(0);

// Match documented rule TOKENS, not substrings. `refs.includes(rule)`
// let `component:List` pass off the text of `component:List.Item`, and
// the prop fallback matched any backticked occurrence of the word
// anywhere in prose — so the guard could pass while the rule it was
// meant to pin went undocumented.
const tokens = new Set(
[...refs.matchAll(/(?:component|prop):[A-Za-z][\w.*]*/g)].map(m => m[0])
);
// A prop rule may instead be written bare in a row that names the
// component beside it (`| \`expanded\` on \`Field\` |`).
const backticked = new Set(
[...refs.matchAll(/`([A-Za-z][\w.-]*)`/g)].map(m => m[1])
);
// A `prop:` rule gets a stricter reading: only a heading or a table row
// counts. Matching a backtick anywhere made that fallback near vacuous --
// `\`as\`` occurs in ordinary prose in every one of these files, so
// `prop:as` read as documented in all three sources whether a recipe
// existed or not, which is how RBC shipped without one. Rules with no
// `prop:`/`component:` prefix (`deps`, `peer-deps`) stay loose: they are
// explained in SKILL.md's prose, which is the right home for them.
const inHeadingOrRow = new Set(
refs
.split('\n')
.filter(l => l.startsWith('|') || l.startsWith('#'))
.flatMap(l => [...l.matchAll(/`([A-Za-z][\w.-]*)`/g)].map(m => m[1]))
);

const documented = (rule: string): boolean => {
if (tokens.has(rule)) return true;
if (rule.startsWith('component:')) {
// A dotted part may be covered by its parent's section, which the
// reference writes as `component:File.*` or as a section for the
// parent component itself.
const parent = rule.slice('component:'.length).split('.')[0];
return (
tokens.has(`component:${parent}.*`) ||
tokens.has(`component:${parent}`)
);
}
if (rule.startsWith('prop:')) {
return inHeadingOrRow.has(rule.slice('prop:'.length));
}
return backticked.has(rule);
};

const undocumented = [...emitted].sort().filter(r => !documented(r));
expect(undocumented).toEqual([]);
});

it('typechecks the migrated output against @allxsmith/bestax-bulma', () => {
fs.writeFileSync(
path.join(tmpDir, 'global.d.ts'),
Expand Down
Loading
Loading