Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .changeset/canonical-workspace-paths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fission-ai/openspec": patch
---

### Fixed

- Preserve workspace planning detection when Windows short paths or symlink aliases resolve to a canonical workspace root.
4 changes: 3 additions & 1 deletion src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface WorkflowPromptMeta {

interface WorkspaceConfigProfileContext {
root: string;
commandCwd: string;
}

const WORKFLOW_PROMPT_META: Record<string, WorkflowPromptMeta> = {
Expand Down Expand Up @@ -205,6 +206,7 @@ async function resolveWorkspaceConfigProfileContext(

return {
root: workspaceRoot,
commandCwd: cwd,
};
}

Expand Down Expand Up @@ -680,7 +682,7 @@ export function registerConfigCommand(program: Command): void {
try {
execSync('npx openspec workspace update', {
stdio: 'inherit',
cwd: workspaceContext.root,
cwd: workspaceContext.commandCwd,
});
console.log('Run `openspec workspace update` in your other workspaces to apply.');
} catch {
Expand Down
3 changes: 2 additions & 1 deletion src/core/planning-home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function getSearchStartDirectory(startPath: string): string {

try {
const stats = fs.statSync(resolved);
return stats.isDirectory() ? resolved : path.dirname(resolved);
const searchStart = stats.isDirectory() ? resolved : path.dirname(resolved);
return FileSystemUtils.canonicalizeExistingPath(searchStart);
} catch {
return resolved;
}
Expand Down
23 changes: 23 additions & 0 deletions test/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenSpec Test Guidance

Applies to tests under `test/`.

## Running Tests

- Focused file: `pnpm exec vitest run test/path/to/file.test.ts`
- Focused case: `pnpm exec vitest run test/path/to/file.test.ts -t "case name"`
- Full suite: `pnpm test`
- Run `pnpm run build` before focused CLI tests when implementation changes may leave `dist/` stale.

## Path Canonicalization

Path identity is a recurring CI failure mode: Windows short/long paths, symlink or
junction aliases, and case-insensitive file systems can spell the same existing
directory differently.

When asserting existing filesystem paths as identities, canonicalize both actual
and expected paths first. Prefer `FileSystemUtils.canonicalizeExistingPath()` in
project code and `fs.realpathSync.native()` in test-only expectations.

Add an alias-path regression when touching path identity logic. If preserving
user-typed path spelling is intentional, assert it separately from identity comparisons.
42 changes: 41 additions & 1 deletion test/core/planning-home.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { describe, expect, it } from 'vitest';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';

import { afterEach, describe, expect, it } from 'vitest';

import {
type PlanningHome,
formatChangeLocation,
getChangeDir,
resolveCurrentPlanningHomeSync,
} from '../../src/core/planning-home.js';

describe('planning home paths', () => {
const tempDirs: string[] = [];

afterEach(() => {
for (const tempDir of tempDirs.splice(0)) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
});

it('builds workspace change paths with the planning home path style', () => {
const workspacePlanningHome: PlanningHome = {
kind: 'workspace',
Expand All @@ -26,4 +39,31 @@ describe('planning home paths', () => {
'changes\\cross-repo-login'
);
});

it('keeps a canonical workspace root comparable with an aliased start path', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'openspec-planning-home-'));
tempDirs.push(tempDir);
const realWorkspaceRoot = path.join(tempDir, 'real-workspace');
const aliasWorkspaceRoot = path.join(tempDir, 'alias-workspace');

fs.mkdirSync(path.join(realWorkspaceRoot, '.openspec-workspace'), { recursive: true });
fs.writeFileSync(
path.join(realWorkspaceRoot, '.openspec-workspace', 'workspace.yaml'),
'version: 1\nname: platform\nlinks: {}\n',
'utf-8'
);
fs.symlinkSync(
realWorkspaceRoot,
aliasWorkspaceRoot,
process.platform === 'win32' ? 'junction' : 'dir'
);

const planningHome = resolveCurrentPlanningHomeSync({
startPath: aliasWorkspaceRoot,
allowImplicitRepoRoot: false,
});

expect(planningHome.kind).toBe('workspace');
expect(planningHome.root).toBe(fs.realpathSync.native(realWorkspaceRoot));
});
});
Loading