Skip to content

Commit f529b25

Browse files
authored
test: align path assertions with canonical helper (#975)
1 parent 93f7b79 commit f529b25

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

test/commands/artifact-workflow.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { promises as fs } from 'fs';
33
import path from 'path';
44
import os from 'os';
55
import { runCLI } from '../helpers/run-cli.js';
6+
import { FileSystemUtils } from '../../src/utils/file-system.js';
67

78
describe('artifact-workflow CLI commands', () => {
89
let tempDir: string;
910
let changesDir: string;
1011

12+
const canonical = (targetPath: string): string => FileSystemUtils.canonicalizeExistingPath(targetPath);
13+
1114
beforeEach(async () => {
1215
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'openspec-artifact-workflow-'));
1316
changesDir = path.join(tempDir, 'openspec', 'changes');
@@ -411,10 +414,8 @@ describe('artifact-workflow CLI commands', () => {
411414
expect(result.stderr).toBe('');
412415

413416
const json = JSON.parse(result.stdout);
414-
const expectedProposalPath = await fs.realpath(path.join(changesDir, 'json-apply', 'proposal.md'));
415-
const expectedSpecPath = await fs.realpath(
416-
path.join(changesDir, 'json-apply', 'specs', 'test-spec.md')
417-
);
417+
const expectedProposalPath = canonical(path.join(changesDir, 'json-apply', 'proposal.md'));
418+
const expectedSpecPath = canonical(path.join(changesDir, 'json-apply', 'specs', 'test-spec.md'));
418419
expect(json.changeName).toBe('json-apply');
419420
expect(json.schemaName).toBe('spec-driven');
420421
expect(json.state).toBe('ready');
@@ -472,7 +473,7 @@ apply:
472473
);
473474
expect(applyResult.exitCode).toBe(0);
474475
const applyJson = JSON.parse(applyResult.stdout);
475-
const resolvedSpecPath = await fs.realpath(specPath);
476+
const resolvedSpecPath = canonical(specPath);
476477
expect(applyJson.state).toBe('ready');
477478
expect(applyJson.missingArtifacts).toBeUndefined();
478479
expect(applyJson.contextFiles).toEqual({

test/core/artifact-graph/outputs.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import * as fs from 'node:fs';
33
import * as path from 'node:path';
44
import * as os from 'node:os';
5+
import { FileSystemUtils } from '../../../src/utils/file-system.js';
56
import { artifactOutputExists, resolveArtifactOutputs } from '../../../src/core/artifact-graph/outputs.js';
67

78
describe('artifact-graph/outputs', () => {
89
let tempDir: string;
910

11+
const canonical = (targetPath: string): string => FileSystemUtils.canonicalizeExistingPath(targetPath);
12+
1013
beforeEach(() => {
1114
tempDir = path.join(os.tmpdir(), `openspec-outputs-test-${Date.now()}`);
1215
fs.mkdirSync(tempDir, { recursive: true });
@@ -20,7 +23,7 @@ describe('artifact-graph/outputs', () => {
2023
const filePath = path.join(tempDir, 'proposal.md');
2124
fs.writeFileSync(filePath, 'content');
2225

23-
expect(resolveArtifactOutputs(tempDir, 'proposal.md')).toEqual([fs.realpathSync(filePath)]);
26+
expect(resolveArtifactOutputs(tempDir, 'proposal.md')).toEqual([canonical(filePath)]);
2427
expect(artifactOutputExists(tempDir, 'proposal.md')).toBe(true);
2528
});
2629

@@ -38,7 +41,7 @@ describe('artifact-graph/outputs', () => {
3841
fs.mkdirSync(nestedDir, { recursive: true });
3942
fs.writeFileSync(filePath, 'content');
4043

41-
expect(resolveArtifactOutputs(tempDir, 'specs/*/spec.md')).toEqual([fs.realpathSync(filePath)]);
44+
expect(resolveArtifactOutputs(tempDir, 'specs/*/spec.md')).toEqual([canonical(filePath)]);
4245
expect(artifactOutputExists(tempDir, 'specs/*/spec.md')).toBe(true);
4346
});
4447

@@ -50,7 +53,7 @@ describe('artifact-graph/outputs', () => {
5053
fs.writeFileSync(matching, 'content');
5154
fs.writeFileSync(nonMatching, 'content');
5255

53-
expect(resolveArtifactOutputs(tempDir, 'specs/foo*.md')).toEqual([fs.realpathSync(matching)]);
56+
expect(resolveArtifactOutputs(tempDir, 'specs/foo*.md')).toEqual([canonical(matching)]);
5457
});
5558

5659
it('supports question-mark glob patterns', () => {
@@ -60,7 +63,7 @@ describe('artifact-graph/outputs', () => {
6063
fs.writeFileSync(matching, 'content');
6164
fs.writeFileSync(path.join(specsDir, 'a10.md'), 'content');
6265

63-
expect(resolveArtifactOutputs(tempDir, 'specs/a?.md')).toEqual([fs.realpathSync(matching)]);
66+
expect(resolveArtifactOutputs(tempDir, 'specs/a?.md')).toEqual([canonical(matching)]);
6467
});
6568

6669
it('supports character class glob patterns', () => {
@@ -73,8 +76,8 @@ describe('artifact-graph/outputs', () => {
7376
fs.writeFileSync(path.join(specsDir, 'c.md'), 'content');
7477

7578
expect(resolveArtifactOutputs(tempDir, 'specs/[ab].md')).toEqual([
76-
fs.realpathSync(aPath),
77-
fs.realpathSync(bPath),
79+
canonical(aPath),
80+
canonical(bPath),
7881
]);
7982
});
8083

@@ -92,10 +95,10 @@ describe('artifact-graph/outputs', () => {
9295
fs.symlinkSync(realChangeDir, aliasChangeDir, process.platform === 'win32' ? 'junction' : 'dir');
9396

9497
expect(resolveArtifactOutputs(aliasChangeDir, 'proposal.md')).toEqual([
95-
fs.realpathSync(proposalPath),
98+
canonical(proposalPath),
9699
]);
97100
expect(resolveArtifactOutputs(aliasChangeDir, 'specs/*/spec.md')).toEqual([
98-
fs.realpathSync(specPath),
101+
canonical(specPath),
99102
]);
100103
});
101104

0 commit comments

Comments
 (0)