Skip to content

Commit 9413254

Browse files
OAGrclaude
andcommitted
test(crux): address CodeRabbit review comments on deployment and utils tests
- Add positive conversion test for convertSlugsToNumericIds using vi.resetModules() + dynamic import to get a fresh module instance (bypassing the module-level cache), seeding registry with E123→open-philanthropy and asserting both EntityLink id= and DataInfoBox entityId= are rewritten - Normalize path separators in getFilePath assertions with .replace(/\\/g, '/') before matching, so tests pass on Windows where path.join() returns backslashes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 87a5862 commit 9413254

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

crux/authoring/creator/deployment.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,42 @@ Some content without any entity links.
9090
const result = convertSlugsToNumericIds(content, '/fake/root');
9191
expect(result.converted).toBe(0);
9292
});
93+
94+
it('rewrites slug EntityLinks and DataInfoBox entityId to E## when registry is seeded', async () => {
95+
// Use vi.resetModules() + dynamic import to get a fresh module instance
96+
// where _slugToNumeric is null (not yet cached as empty by earlier tests).
97+
const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = require('fs');
98+
const { join } = require('path');
99+
100+
const tmpRoot = mkdtempSync('/tmp/test-slug-convert-');
101+
const dataDir = join(tmpRoot, 'apps', 'web', 'src', 'data');
102+
mkdirSync(dataDir, { recursive: true });
103+
writeFileSync(
104+
join(dataDir, 'database.json'),
105+
JSON.stringify({ idRegistry: { byNumericId: { E123: 'open-philanthropy' } } })
106+
);
107+
108+
try {
109+
vi.resetModules();
110+
const { convertSlugsToNumericIds: convert } = await import('./deployment.ts');
111+
112+
// EntityLink id rewrite
113+
const r1 = convert(
114+
'<EntityLink id="open-philanthropy">Open Philanthropy</EntityLink>',
115+
tmpRoot
116+
);
117+
expect(r1.content).toBe('<EntityLink id="E123">Open Philanthropy</EntityLink>');
118+
expect(r1.converted).toBe(1);
119+
120+
// DataInfoBox entityId rewrite
121+
const r2 = convert('<DataInfoBox entityId="open-philanthropy" />', tmpRoot);
122+
expect(r2.content).toBe('<DataInfoBox entityId="E123" />');
123+
expect(r2.converted).toBe(1);
124+
} finally {
125+
rmSync(tmpRoot, { recursive: true });
126+
vi.resetModules();
127+
}
128+
});
93129
});
94130

95131
// ---------------------------------------------------------------------------

crux/authoring/page-improver/utils-extra.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ function makeAnalysis(overrides: Partial<AnalysisResult> = {}): AnalysisResult {
5858
describe('getFilePath', () => {
5959
it('converts a page path to a .mdx filesystem path', () => {
6060
const result = getFilePath('knowledge-base/people/eliezer-yudkowsky');
61-
expect(result).toMatch(/content\/docs\/knowledge-base\/people\/eliezer-yudkowsky\.mdx$/);
61+
expect(result.replace(/\\/g, '/')).toMatch(
62+
/content\/docs\/knowledge-base\/people\/eliezer-yudkowsky\.mdx$/
63+
);
6264
});
6365

6466
it('strips leading slashes before joining', () => {
@@ -75,7 +77,7 @@ describe('getFilePath', () => {
7577

7678
it('handles a simple single-segment path', () => {
7779
const result = getFilePath('simple-page');
78-
expect(result).toMatch(/content\/docs\/simple-page\.mdx$/);
80+
expect(result.replace(/\\/g, '/')).toMatch(/content\/docs\/simple-page\.mdx$/);
7981
});
8082
});
8183

0 commit comments

Comments
 (0)