Files
wehub-resource-sync 719032b19f
Update Schema / Update configuration json schema (push) Has been cancelled
Memory Benchmark / Memory Test (Full Analysis) (push) Has been cancelled
CI Quality / Lint GitHub Actions (actionlint) (push) Has been cancelled
CI Quality / Lint GitHub Actions (zizmor) (push) Has been cancelled
CI Quality / Check typos (push) Has been cancelled
CI / Test coverage (push) Has been cancelled
CI / Test (22.x, windows-latest) (push) Has been cancelled
CI / Test (24.x, macos-latest) (push) Has been cancelled
CI / Test (24.x, ubuntu-latest) (push) Has been cancelled
CI / Test (24.x, windows-latest) (push) Has been cancelled
CI / Test (26.x, macos-latest) (push) Has been cancelled
CI / Test (26.x, ubuntu-latest) (push) Has been cancelled
CI / Test (26.x, windows-latest) (push) Has been cancelled
CI / Test with Bun (latest, macos-latest) (push) Has been cancelled
CI / Test with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Test with Bun (latest, windows-latest) (push) Has been cancelled
CI / Build and run (22.x, macos-latest) (push) Has been cancelled
CI / Build and run (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (22.x, windows-latest) (push) Has been cancelled
autofix.ci / autofix (push) Has been cancelled
CI Browser Extension / Lint Browser Extension (push) Has been cancelled
CI Browser Extension / Test Browser Extension (push) Has been cancelled
Memory Benchmark / Memory Test (push) Has been cancelled
CI Website / Lint Website Client (push) Has been cancelled
CI Website / Lint Website Server (push) Has been cancelled
CI Website / Test Website Server (push) Has been cancelled
CI Website / Bundle Website Server (push) Has been cancelled
CI / Lint Biome (push) Has been cancelled
CI / Lint oxlint (push) Has been cancelled
CI / Lint TypeScript (push) Has been cancelled
CI / Lint Secretlint (push) Has been cancelled
CI / Test (22.x, macos-latest) (push) Has been cancelled
CI / Test (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, macos-latest) (push) Has been cancelled
CI / Build and run (24.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, windows-latest) (push) Has been cancelled
CI / Build and run (26.x, macos-latest) (push) Has been cancelled
CI / Build and run (26.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (26.x, windows-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, macos-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Docker / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Docker / build (linux/arm/v7, ubuntu-24.04-arm) (push) Has been cancelled
Docker / build (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Docker / merge (push) Has been cancelled
Pack repository with Repomix / pack-repo (push) Has been cancelled
Performance Benchmark History / Benchmark (macos-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (ubuntu-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (windows-latest) (push) Has been cancelled
Performance Benchmark History / Store Results (push) Has been cancelled
Test Repomix Action / Test Node.js 22 (push) Has been cancelled
Test Repomix Action / Test Node.js 24 (push) Has been cancelled
Test Repomix Action / Test Node.js 26 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:37 +08:00

122 lines
4.3 KiB
TypeScript

import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { buildFileDisplayPath, buildRootLabels, joinDisplayPath } from '../../../src/core/packager/rootDisplayPath.js';
// Build absolute paths from a resolved virtual base so the tests stay
// deterministic and cross-platform (buildRootLabels uses path.resolve/relative).
const base = path.resolve('virtual-root-for-rootDisplayPath-test');
const cwd = path.join(base, 'work');
describe('rootDisplayPath', () => {
describe('buildRootLabels', () => {
it('uses basenames for distinct roots inside cwd', () => {
const roots = [path.join(cwd, 'frontend'), path.join(cwd, 'backend')];
expect(buildRootLabels(roots, cwd)).toEqual(['frontend', 'backend']);
});
it('uses the cwd-relative path for nested roots inside cwd', () => {
const roots = [path.join(cwd, 'packages', 'a'), path.join(cwd, 'packages', 'b')];
expect(buildRootLabels(roots, cwd)).toEqual(['packages/a', 'packages/b']);
});
it('uses only the basename for roots outside cwd (no parent leakage)', () => {
const roots = [path.join(base, 'other', 'foo'), path.join(base, 'other', 'bar')];
expect(buildRootLabels(roots, cwd)).toEqual(['foo', 'bar']);
});
it('falls back to a numeric suffix when outside-cwd basenames collide', () => {
const roots = [path.join(base, 'x', 'app'), path.join(base, 'y', 'app')];
expect(buildRootLabels(roots, cwd)).toEqual(['app', 'app-2']);
});
it('disambiguates a collision between an inside-cwd and an outside-cwd root', () => {
const roots = [path.join(cwd, 'app'), path.join(base, 'other', 'app')];
expect(buildRootLabels(roots, cwd)).toEqual(['app', 'app-2']);
});
it('returns the single label unchanged for one root', () => {
expect(buildRootLabels([path.join(cwd, 'frontend')], cwd)).toEqual(['frontend']);
});
});
describe('joinDisplayPath', () => {
it('joins a root label and file path with a posix separator', () => {
expect(joinDisplayPath('app', 'src/index.ts')).toBe('app/src/index.ts');
});
it('normalizes windows separators in the file path', () => {
expect(joinDisplayPath('app', `src${path.win32.sep}index.ts`)).toBe('app/src/index.ts');
});
it('trims redundant leading/trailing slashes', () => {
expect(joinDisplayPath('/app/', '/README.md')).toBe('app/README.md');
});
it('returns just the label when the file path is empty', () => {
expect(joinDisplayPath('app', '')).toBe('app');
});
it('falls back to "root" when the label is empty', () => {
expect(joinDisplayPath('', 'README.md')).toBe('root/README.md');
});
});
describe('buildFileDisplayPath', () => {
it('keeps target-relative paths unchanged for the default style', () => {
expect(
buildFileDisplayPath({
rootDir: path.join(base, 'other', 'core-library'),
filePath: 'src/core.py',
cwd,
filePathStyle: 'target-relative',
}),
).toBe('src/core.py');
});
it('uses a multi-root label for target-relative paths when provided', () => {
expect(
buildFileDisplayPath({
rootDir: path.join(base, 'other', 'core-library'),
filePath: 'src/core.py',
cwd,
filePathStyle: 'target-relative',
rootLabel: 'core-library',
}),
).toBe('core-library/src/core.py');
});
it('uses cwd-relative paths for roots outside cwd', () => {
expect(
buildFileDisplayPath({
rootDir: path.join(base, 'core-library'),
filePath: 'src/core.py',
cwd,
filePathStyle: 'cwd-relative',
}),
).toBe('../core-library/src/core.py');
});
it('uses cwd-relative paths for nested roots inside cwd', () => {
expect(
buildFileDisplayPath({
rootDir: path.join(cwd, 'packages', 'app'),
filePath: 'src/index.ts',
cwd,
filePathStyle: 'cwd-relative',
}),
).toBe('packages/app/src/index.ts');
});
it('normalizes cwd-relative paths to posix separators', () => {
expect(
buildFileDisplayPath({
rootDir: path.join(cwd, 'packages', 'app'),
filePath: `src${path.win32.sep}index.ts`,
cwd,
filePathStyle: 'cwd-relative',
}),
).toBe('packages/app/src/index.ts');
});
});
});