From dbb20c7cdb34b86e2ff99a41d0305a0d7ed1c325 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 12 Nov 2026 19:01:35 +0000 Subject: [PATCH 1/4] fix(import): keep staged category folders inside the temp directory Remote category titles were used as the first path segment under the import staging directory. On Windows, path.join treats backslashes as separators, so a title like ..\..\Users\Public\poc wrote stubs outside the mkdtemp dir. Rewrite unsafe segments to kebab-case and run every stageOrganized write through the staging containment check. Co-authored-by: Jon Ursenbach --- src/commands/import.js | 58 ++++++++++++-- test/commands/import/staging.test.js | 113 +++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 8 deletions(-) diff --git a/src/commands/import.js b/src/commands/import.js index dc20b04..c5465a5 100644 --- a/src/commands/import.js +++ b/src/commands/import.js @@ -4898,6 +4898,14 @@ function filterUrlPagesTree(pages, predicate) { * Writes _order.yaml per directory so sidebar order matches input order. */ function stageOrganized(organized, stagingDir, opts = {}) { + // Category titles become directory names. Reject any resolved path that leaves + // this temp dir (Windows `path.join` treats `\` as a separator and collapses `..`). + const assertContained = makeContainment(stagingDir, { label: 'staging directory' }); + const writeContained = (absPath, contents) => { + assertContained(absPath); + fs.mkdirSync(path.dirname(absPath), { recursive: true }); + fs.writeFileSync(absPath, contents); + }; const pickIcon = makeIconPicker(); const byDir = new Map(); const subDirsByTopDir = new Map(); @@ -4988,8 +4996,7 @@ function stageOrganized(organized, stagingDir, opts = {}) { } const absPath = path.join(stagingDir, relFilePath); - fs.mkdirSync(path.dirname(absPath), { recursive: true }); - fs.writeFileSync(absPath, toFrontmatter(frontmatter)); + writeContained(absPath, toFrontmatter(frontmatter)); counts.fileCount++; // The sidebar entry is `slug` for both leaves (`.md`) and parents @@ -5011,7 +5018,9 @@ function stageOrganized(organized, stagingDir, opts = {}) { // Namespace every NESTED category folder by its ancestor path so its basename // (and thus slug) is globally unique, and back it with an `index.md` so it's a // real titled parent. Top-level categories are matched by title, not slug, so - // their folders are left untouched. + // a safe display title is left untouched. Separators, `..`, drive prefixes, and + // Windows device names are rewritten first — on win32 a raw `..\` title would + // otherwise resolve outside this staging directory. const usedContainerSlugs = new Set(slugFor.values()); const segRename = new Map(); // original path prefix -> unique folder name const nestedContainers = new Map(); // renamed dir (rel to stagingDir) -> display title @@ -5030,7 +5039,13 @@ function stageOrganized(organized, stagingDir, opts = {}) { const out = []; for (let i = 0; i < segs.length; i++) { if (i === 0) { - out.push(segs[0]); + const safe = safeCategorySegment(segs[0]); + // A rewritten name can collide with a real category or a page slug. + // A display title that needed no rewrite keeps its spelling, including + // when two categories share it. + const name = safe === segs[0] ? safe : uniqueContainerName(safe); + if (name === segs[0] && !usedContainerSlugs.has(name)) usedContainerSlugs.add(name); + out.push(name); continue; } const origPrefix = segs.slice(0, i + 1).join('/'); @@ -5062,10 +5077,10 @@ function stageOrganized(organized, stagingDir, opts = {}) { // these are pure nav containers, so the body stays empty and format skips them. for (const [relDir, title] of nestedContainers) { const idxPath = path.join(stagingDir, relDir, 'index.md'); + assertContained(idxPath); if (fs.existsSync(idxPath)) continue; - fs.mkdirSync(path.dirname(idxPath), { recursive: true }); const fm = { title, icon: formatIconClass(pickIcon(path.basename(relDir), title)) }; - fs.writeFileSync(idxPath, toFrontmatter(fm)); + writeContained(idxPath, toFrontmatter(fm)); counts.fileCount++; } @@ -5073,14 +5088,14 @@ function stageOrganized(organized, stagingDir, opts = {}) { for (const [dir, slugs] of byDir) { const orderPath = path.join(stagingDir, dir, '_order.yaml'); const body = `${slugs.map(s => `- ${yamlSafeSlug(s)}`).join('\n')}\n`; - fs.writeFileSync(orderPath, body); + writeContained(orderPath, body); } // Top-level _order.yaml (e.g. docs/_order.yaml) lists category subfolders. for (const [topDir, subs] of subDirsByTopDir) { const orderPath = path.join(stagingDir, topDir, '_order.yaml'); const body = `${subs.map(s => `- ${yamlSafeSlug(s)}`).join('\n')}\n`; - fs.writeFileSync(orderPath, body); + writeContained(orderPath, body); } return { fileCount: counts.fileCount, dirCount: byDir.size, skippedApiRef: counts.skippedApiRef }; @@ -5407,6 +5422,33 @@ function kebabCase(s) { ); } +// Windows device names are paths, not directories (`CON`, `NUL`, `COM1`, …). +const WINDOWS_RESERVED_SEGMENT = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\.|$)/i; + +/** + * Folder name for one category-title segment. + * + * Display titles stay as authored (`Guides`, `API Docs`). Anything `path.win32` + * would treat as a separator, a parent segment, a drive prefix, or a device + * name is folded to kebab-case so `path.join(stagingDir, …)` cannot leave the + * staging directory. Trailing dots and spaces are stripped because Windows + * ignores them and can turn `.. ` into `..`. + * + * @param {string} segment A single `/`-separated piece of a category title. + * @returns {string} + */ +function safeCategorySegment(segment) { + const seg = String(segment); + // Strip trailing dots and spaces first: Windows drops them, so `.. ` is `..`. + const stripped = seg.replace(/[.\s]+$/g, ''); + const reserved = WINDOWS_RESERVED_SEGMENT.test(stripped); + const traverses = stripped === '' || /[\\/\0-\x1f:]/.test(seg); + if (!traverses && !reserved) return stripped; + + const slug = kebabCase(seg); + return WINDOWS_RESERVED_SEGMENT.test(slug) ? `${slug}-section` : slug; +} + // Keyword → FontAwesome icon. Ported from v1 (most-specific entries first). // Each rule maps to an ordered list of candidates; the first unused-in-this-dir // icon wins so sibling pages don't all share the same icon. diff --git a/test/commands/import/staging.test.js b/test/commands/import/staging.test.js index c4ec7bf..46192aa 100644 --- a/test/commands/import/staging.test.js +++ b/test/commands/import/staging.test.js @@ -6,6 +6,7 @@ import { Command } from 'commander'; import { afterEach, test, expect } from 'vitest'; import { args, __test__ } from '../../../src/commands/import.js'; +import { PathEscapeError } from '../../../src/utils/containment.js'; import { parseFrontmatter, toFrontmatter } from '../../../src/utils/markdown.js'; const { stageOrganized, finalizeChangelogs, allocateChangelogFilenames } = __test__; @@ -29,6 +30,36 @@ function readFm(filePath) { return parseFrontmatter(fs.readFileSync(filePath, 'utf8')).data; } +function listFiles(dir) { + const out = []; + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const full = path.join(dir, entry.name); + if (entry.isDirectory()) out.push(...listFiles(full)); + else out.push(full); + } + return out; +} + +/** Re-join staged paths with Windows path semantics and require they stay put. */ +function expectContainedOnWin32(stagingDir) { + const winRoot = 'C:\\Users\\dev\\AppData\\Local\\Temp\\readme-import-abc123'; + const rootReal = fs.realpathSync(stagingDir); + const files = listFiles(stagingDir); + expect(files.length).toBeGreaterThan(0); + for (const file of files) { + const rel = path.relative(rootReal, fs.realpathSync(file)); + expect(rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)).toBe(false); + for (const part of rel.split(path.sep)) { + expect(part).not.toBe('..'); + expect(part).not.toBe('.'); + expect(part).not.toContain('\\'); + } + const winAbs = path.win32.join(winRoot, rel.split(path.sep).join(path.win32.sep)); + const winRel = path.win32.relative(winRoot, winAbs); + expect(winRel === '..' || winRel.startsWith(`..${path.win32.sep}`) || path.win32.isAbsolute(winRel)).toBe(false); + } +} + test('stageOrganized writes parent pages as index.md and leaves as slug.md', () => { withStaging(stagingDir => { const parent = { @@ -205,6 +236,88 @@ test('import command has no conditional changelog layout option', () => { expect(cmd.options.some(option => option.long === '--separate-changelog')).toBe(false); }); +test('stageOrganized keeps hostile category titles inside staging on win32', () => { + withStaging(stagingDir => { + const backslash = '..\\..\\..\\..\\..\\..\\..\\Users\\Public\\poc'; + const pages = n => + Array.from({ length: n }, (_, i) => ({ + title: `Page ${i + 1}`, + url: `https://example.com/docs/bs-${i + 1}`, + })); + + stageOrganized( + { + categories: [ + { title: 'Guides', pages: [{ title: 'Pricing', url: 'https://example.com/docs/pricing' }] }, + { title: backslash, pages: pages(5) }, + { title: '..\\poc', pages: [{ title: 'Near', url: 'https://example.com/docs/near' }] }, + { title: '..\\..\\poc', pages: [{ title: 'Far', url: 'https://example.com/docs/far' }] }, + { + title: 'C:\\Users\\Public\\poc-drive', + pages: [{ title: 'Drive', url: 'https://example.com/docs/drive' }], + }, + { + title: '\\\\server\\share\\poc', + pages: [{ title: 'Unc', url: 'https://example.com/docs/unc' }], + }, + { + title: '../../../../../../../../tmp/rm19530-slash-escape', + pages: [ + { title: 'Slash', url: 'https://example.com/docs/slash-1' }, + { title: 'Slash 2', url: 'https://example.com/docs/slash-2' }, + ], + }, + { + title: '..\\..\\..\\outside/Nested group', + pages: [{ title: 'Mixed', url: 'https://example.com/docs/mixed' }], + }, + { title: 'CON', pages: [{ title: 'Device', url: 'https://example.com/docs/device' }] }, + ], + }, + stagingDir, + ); + + expect(fs.existsSync(path.join(stagingDir, 'docs', 'Guides', 'pricing.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'users-public-poc', 'bs-1.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'users-public-poc', 'bs-5.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'users-public-poc', '_order.yaml'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'poc', 'near.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'poc-2', 'far.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'c-users-public-poc-drive', 'drive.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'server-share-poc', 'unc.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'outside', 'outside-nested-group', 'mixed.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'con-section', 'device.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'page'))).toBe(true); + + const names = fs.readdirSync(path.join(stagingDir, 'docs')); + expect(names.some(name => name.includes('\\') || name === '..' || name === '.')).toBe(false); + expect(fs.readFileSync(path.join(stagingDir, 'docs', '_order.yaml'), 'utf8')).toContain('users-public-poc'); + expect(readFm(path.join(stagingDir, 'docs', 'users-public-poc', 'bs-1.md'))['x-import']).toBe( + 'https://example.com/docs/bs-1', + ); + + expectContainedOnWin32(stagingDir); + }); +}); + +test('stageOrganized refuses a slug that resolves outside staging', () => { + withStaging(stagingDir => { + const probe = path.join(path.dirname(stagingDir), 'rm19530-escape-probe.md'); + fs.rmSync(probe, { force: true }); + const page = { title: 'Escape', url: 'https://example.com/docs/escape' }; + try { + expect(() => + stageOrganized({ categories: [{ title: 'Guides', pages: [page] }] }, stagingDir, { + slugFor: new Map([[page, '../../../rm19530-escape-probe']]), + }), + ).toThrow(PathEscapeError); + expect(fs.existsSync(probe)).toBe(false); + } finally { + fs.rmSync(probe, { force: true }); + } + }); +}); + test('stageOrganized quotes YAML-unsafe slugs in _order.yaml', () => { withStaging(stagingDir => { stageOrganized( From be51aa3836bd95621eae268cf1ac2588da47185a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 12 Nov 2026 19:09:09 +0000 Subject: [PATCH 2/4] fix(import): reuse a rewritten category root across sibling sections SDK: Java/Setup/Windows and SDK: Java/Setup/Linux both kebab the shared root to sdk-java. Allocating that name on every call split the tree and reused the child slug under a second parent. Cache the first segment by its original text, the same way later segments already are. A safe display title is returned unchanged, so a trailing period is no longer treated as a rewrite. Co-authored-by: Jon Ursenbach --- src/commands/import.js | 51 ++++++++++++++-------------- test/commands/import/staging.test.js | 33 ++++++++++++++++-- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/commands/import.js b/src/commands/import.js index c5465a5..f62a5e2 100644 --- a/src/commands/import.js +++ b/src/commands/import.js @@ -5018,11 +5018,11 @@ function stageOrganized(organized, stagingDir, opts = {}) { // Namespace every NESTED category folder by its ancestor path so its basename // (and thus slug) is globally unique, and back it with an `index.md` so it's a // real titled parent. Top-level categories are matched by title, not slug, so - // a safe display title is left untouched. Separators, `..`, drive prefixes, and - // Windows device names are rewritten first — on win32 a raw `..\` title would - // otherwise resolve outside this staging directory. + // a safe display title is left untouched. A segment Windows would treat as + // `..` or as a separator is rewritten first, or a raw `..\` title would + // resolve outside this staging directory. const usedContainerSlugs = new Set(slugFor.values()); - const segRename = new Map(); // original path prefix -> unique folder name + const segRename = new Map(); // original path prefix -> folder name const nestedContainers = new Map(); // renamed dir (rel to stagingDir) -> display title const uniqueContainerName = base => { let name = base || 'section'; @@ -5039,12 +5039,19 @@ function stageOrganized(organized, stagingDir, opts = {}) { const out = []; for (let i = 0; i < segs.length; i++) { if (i === 0) { - const safe = safeCategorySegment(segs[0]); - // A rewritten name can collide with a real category or a page slug. - // A display title that needed no rewrite keeps its spelling, including - // when two categories share it. - const name = safe === segs[0] ? safe : uniqueContainerName(safe); - if (name === segs[0] && !usedContainerSlugs.has(name)) usedContainerSlugs.add(name); + // Same original root must stay one folder. `SDK: Java/Setup/Windows` + // and `SDK: Java/Setup/Linux` both rewrite to `sdk-java`; allocating + // the second call would split the tree and reuse the child slug. + let name = segRename.get(segs[0]); + if (!name) { + const folder = safeCategorySegment(segs[0]); + // Equality with the raw segment means "display title, unchanged". + // Two categories may share that spelling. A rewritten name is + // suffixed when it collides with a different title or a page slug. + name = folder === segs[0] ? folder : uniqueContainerName(folder); + if (name === segs[0]) usedContainerSlugs.add(name); + segRename.set(segs[0], name); + } out.push(name); continue; } @@ -5422,31 +5429,23 @@ function kebabCase(s) { ); } -// Windows device names are paths, not directories (`CON`, `NUL`, `COM1`, …). -const WINDOWS_RESERVED_SEGMENT = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\.|$)/i; - /** * Folder name for one category-title segment. * - * Display titles stay as authored (`Guides`, `API Docs`). Anything `path.win32` - * would treat as a separator, a parent segment, a drive prefix, or a device - * name is folded to kebab-case so `path.join(stagingDir, …)` cannot leave the - * staging directory. Trailing dots and spaces are stripped because Windows - * ignores them and can turn `.. ` into `..`. + * Returns `segment` unchanged when it is safe to use as a path segment, so + * callers can treat equality with the input as "display title, not rewritten". + * Windows drops trailing dots and spaces, which turns `.. ` into `..`, and + * `path.win32` treats `\`, `/`, and `:` as separators. Those become a kebab + * slug. `Guides` and `API Docs` stay as authored. * * @param {string} segment A single `/`-separated piece of a category title. * @returns {string} */ function safeCategorySegment(segment) { const seg = String(segment); - // Strip trailing dots and spaces first: Windows drops them, so `.. ` is `..`. - const stripped = seg.replace(/[.\s]+$/g, ''); - const reserved = WINDOWS_RESERVED_SEGMENT.test(stripped); - const traverses = stripped === '' || /[\\/\0-\x1f:]/.test(seg); - if (!traverses && !reserved) return stripped; - - const slug = kebabCase(seg); - return WINDOWS_RESERVED_SEGMENT.test(slug) ? `${slug}-section` : slug; + const trimmed = seg.replace(/[.\s]+$/g, ''); + const escapes = trimmed === '' || trimmed === '.' || trimmed === '..' || /[\\/\0-\x1f:]/.test(seg); + return escapes ? kebabCase(seg) : seg; } // Keyword → FontAwesome icon. Ported from v1 (most-specific entries first). diff --git a/test/commands/import/staging.test.js b/test/commands/import/staging.test.js index 46192aa..82e1f33 100644 --- a/test/commands/import/staging.test.js +++ b/test/commands/import/staging.test.js @@ -271,7 +271,7 @@ test('stageOrganized keeps hostile category titles inside staging on win32', () title: '..\\..\\..\\outside/Nested group', pages: [{ title: 'Mixed', url: 'https://example.com/docs/mixed' }], }, - { title: 'CON', pages: [{ title: 'Device', url: 'https://example.com/docs/device' }] }, + { title: 'v2.', pages: [{ title: 'Release', url: 'https://example.com/docs/v2-notes' }] }, ], }, stagingDir, @@ -286,7 +286,7 @@ test('stageOrganized keeps hostile category titles inside staging on win32', () expect(fs.existsSync(path.join(stagingDir, 'docs', 'c-users-public-poc-drive', 'drive.md'))).toBe(true); expect(fs.existsSync(path.join(stagingDir, 'docs', 'server-share-poc', 'unc.md'))).toBe(true); expect(fs.existsSync(path.join(stagingDir, 'docs', 'outside', 'outside-nested-group', 'mixed.md'))).toBe(true); - expect(fs.existsSync(path.join(stagingDir, 'docs', 'con-section', 'device.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'v2.', 'v2-notes.md'))).toBe(true); expect(fs.existsSync(path.join(stagingDir, 'docs', 'page'))).toBe(true); const names = fs.readdirSync(path.join(stagingDir, 'docs')); @@ -300,6 +300,35 @@ test('stageOrganized keeps hostile category titles inside staging on win32', () }); }); +test('stageOrganized keeps one folder for a shared rewritten category root', () => { + withStaging(stagingDir => { + stageOrganized( + { + categories: [ + { + title: 'SDK: Java/Setup/Windows', + pages: [{ title: 'Win', url: 'https://example.com/docs/sdk-win' }], + }, + { + title: 'SDK: Java/Setup/Linux', + pages: [{ title: 'Lin', url: 'https://example.com/docs/sdk-lin' }], + }, + ], + }, + stagingDir, + ); + + const setup = path.join(stagingDir, 'docs', 'sdk-java', 'sdk-java-setup'); + expect(fs.existsSync(path.join(setup, 'sdk-java-setup-windows', 'sdk-win.md'))).toBe(true); + expect(fs.existsSync(path.join(setup, 'sdk-java-setup-linux', 'sdk-lin.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'sdk-java-2'))).toBe(false); + expect(readFm(path.join(setup, 'index.md')).title).toBe('Setup'); + expect(readFm(path.join(setup, 'sdk-java-setup-windows', 'index.md')).title).toBe('Windows'); + expect(readFm(path.join(setup, 'sdk-java-setup-linux', 'index.md')).title).toBe('Linux'); + expectContainedOnWin32(stagingDir); + }); +}); + test('stageOrganized refuses a slug that resolves outside staging', () => { withStaging(stagingDir => { const probe = path.join(path.dirname(stagingDir), 'rm19530-escape-probe.md'); From 81a6c4e1e76ba1cb31bf6eccf4981b466b8bbba6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 12 Nov 2026 21:41:16 +0000 Subject: [PATCH 3/4] fix(import): drop unreachable parent-segment checks Windows trims trailing dots and spaces before the path is used, so ".", "..", and ".. " are already empty by the time safeCategorySegment looks at them. The "." and ".." comparisons never ran. Co-authored-by: Jon Ursenbach --- src/commands/import.js | 8 ++++---- test/commands/import/staging.test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/commands/import.js b/src/commands/import.js index f62a5e2..afd9068 100644 --- a/src/commands/import.js +++ b/src/commands/import.js @@ -5434,9 +5434,9 @@ function kebabCase(s) { * * Returns `segment` unchanged when it is safe to use as a path segment, so * callers can treat equality with the input as "display title, not rewritten". - * Windows drops trailing dots and spaces, which turns `.. ` into `..`, and - * `path.win32` treats `\`, `/`, and `:` as separators. Those become a kebab - * slug. `Guides` and `API Docs` stay as authored. + * Windows drops trailing dots and spaces, so `.`, `..`, and `.. ` all trim to + * empty and are rewritten. `path.win32` also treats `\`, `/`, and `:` as + * separators. `Guides` and `API Docs` stay as authored. * * @param {string} segment A single `/`-separated piece of a category title. * @returns {string} @@ -5444,7 +5444,7 @@ function kebabCase(s) { function safeCategorySegment(segment) { const seg = String(segment); const trimmed = seg.replace(/[.\s]+$/g, ''); - const escapes = trimmed === '' || trimmed === '.' || trimmed === '..' || /[\\/\0-\x1f:]/.test(seg); + const escapes = trimmed === '' || /[\\/\0-\x1f:]/.test(seg); return escapes ? kebabCase(seg) : seg; } diff --git a/test/commands/import/staging.test.js b/test/commands/import/staging.test.js index 82e1f33..de069e6 100644 --- a/test/commands/import/staging.test.js +++ b/test/commands/import/staging.test.js @@ -300,6 +300,32 @@ test('stageOrganized keeps hostile category titles inside staging on win32', () }); }); +test('stageOrganized rewrites a parent segment that trims to empty', () => { + withStaging(stagingDir => { + stageOrganized( + { + categories: [ + { title: '.', pages: [{ title: 'Dot', url: 'https://example.com/docs/dot' }] }, + { title: '..', pages: [{ title: 'Up', url: 'https://example.com/docs/up' }] }, + // routeCategory trims the whole title, so the trailing space has to + // sit on an earlier segment to survive until the folder name. + { title: '.. /Notes', pages: [{ title: 'Note', url: 'https://example.com/docs/note' }] }, + ], + }, + stagingDir, + ); + + expect(fs.existsSync(path.join(stagingDir, 'docs', 'page', 'dot.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'page-2', 'up.md'))).toBe(true); + expect(fs.existsSync(path.join(stagingDir, 'docs', 'page-3', 'notes', 'note.md'))).toBe(true); + const names = fs.readdirSync(path.join(stagingDir, 'docs')); + expect(names).not.toContain('.'); + expect(names).not.toContain('..'); + expect(names).not.toContain('.. '); + expectContainedOnWin32(stagingDir); + }); +}); + test('stageOrganized keeps one folder for a shared rewritten category root', () => { withStaging(stagingDir => { stageOrganized( From 8e984ada59ff7074d585c836d69789eccb48ceca Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 12 Nov 2026 21:45:06 +0000 Subject: [PATCH 4/4] test(import): point containment failures at the caller Wrap expectContainedOnWin32 in vi.defineHelper so a failed Windows path assertion is reported on the test line that called it. Co-authored-by: Jon Ursenbach --- test/commands/import/staging.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/commands/import/staging.test.js b/test/commands/import/staging.test.js index de069e6..ed3f702 100644 --- a/test/commands/import/staging.test.js +++ b/test/commands/import/staging.test.js @@ -3,7 +3,7 @@ import os from 'node:os'; import path from 'node:path'; import { Command } from 'commander'; -import { afterEach, test, expect } from 'vitest'; +import { afterEach, expect, test, vi } from 'vitest'; import { args, __test__ } from '../../../src/commands/import.js'; import { PathEscapeError } from '../../../src/utils/containment.js'; @@ -41,7 +41,8 @@ function listFiles(dir) { } /** Re-join staged paths with Windows path semantics and require they stay put. */ -function expectContainedOnWin32(stagingDir) { +// oxlint-disable vitest/no-standalone-expect -- expects belong to the helper's caller +const expectContainedOnWin32 = vi.defineHelper(stagingDir => { const winRoot = 'C:\\Users\\dev\\AppData\\Local\\Temp\\readme-import-abc123'; const rootReal = fs.realpathSync(stagingDir); const files = listFiles(stagingDir); @@ -58,7 +59,8 @@ function expectContainedOnWin32(stagingDir) { const winRel = path.win32.relative(winRoot, winAbs); expect(winRel === '..' || winRel.startsWith(`..${path.win32.sep}`) || path.win32.isAbsolute(winRel)).toBe(false); } -} +}); +// oxlint-enable vitest/no-standalone-expect test('stageOrganized writes parent pages as index.md and leaves as slug.md', () => { withStaging(stagingDir => {