feat(bgm): support role= on code block info strings

Parse role.type#id from the fence info string and merge it into each
parsed object, erroring on conflicts with the content. id on the info
string can't combine with $variants. Auto-named blocks now hash their
content instead of the info string, so identical blocks dedupe.
This commit is contained in:
2026-08-10 16:09:12 +08:00
parent c41c266ac1
commit aab0b66ee8
7 changed files with 207 additions and 10 deletions
+14
View File
@@ -86,4 +86,18 @@ describe('collectPackages', () => {
defMap.defs.set(tokensKey.replace('tokens.yaml', 'dup.yaml'), [tokens[0]!]);
expect(() => collectPackages(defMap, fixtureRoot)).toThrow(/Duplicate part/);
});
it('throws when an info-string id combines with $variants', () => {
const defMap = loadDefs('', fixtureRoot);
// A part whose `id` comes from $variants rows, but with an info-string id.
const tokensKey = [...defMap.defs.keys()].find((k) => k.endsWith('parts/tokens.yaml'))!;
const tokens = defMap.defs.get(tokensKey)!;
const variant = {
...tokens[0]!,
value: { ...tokens[0]!.value, id: undefined, $variants: './parts/seats.csv' },
role: { role: 'part', type: 'token', id: 'wood' },
};
defMap.defs.set(tokensKey.replace('tokens.yaml', 'dup.yaml'), [variant]);
expect(() => collectPackages(defMap, fixtureRoot)).toThrow(/can't combine with \$variants/);
});
});