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
4 changes: 2 additions & 2 deletions src/core/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export function readProjectConfig(projectRoot: string): ProjectConfig | null {
if (raw.rules !== undefined) {
const rulesField = z.record(z.string(), z.array(z.string()));

// First check if it's an object structure
if (typeof raw.rules === 'object' && !Array.isArray(raw.rules)) {
// First check if it's an object structure (guard against null since typeof null === 'object')
if (typeof raw.rules === 'object' && raw.rules !== null && !Array.isArray(raw.rules)) {
const parsedRules: Record<string, string[]> = {};
let hasValidRules = false;

Expand Down
24 changes: 24 additions & 0 deletions test/core/project-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ rules: ["not", "an", "object"]
);
});

it('should handle rules: null without aborting config parsing', () => {
// YAML `rules:` with no value parses to null
const configDir = path.join(tempDir, 'openspec');
fs.mkdirSync(configDir, { recursive: true });
fs.writeFileSync(
path.join(configDir, 'config.yaml'),
`schema: spec-driven
context: Valid context
rules:
`
);

const config = readProjectConfig(tempDir);

// Should still parse schema and context despite null rules
expect(config).toEqual({
schema: 'spec-driven',
context: 'Valid context',
});
expect(consoleWarnSpy).toHaveBeenCalledWith(
expect.stringContaining("Invalid 'rules' field")
);
});

it('should filter out invalid rules for specific artifact', () => {
const configDir = path.join(tempDir, 'openspec');
fs.mkdirSync(configDir, { recursive: true });
Expand Down
Loading