Skip to content

Commit fbe3dec

Browse files
committed
fix: reject project belonging to multiple workspaces
Validate during config parsing that each project appears in at most one workspace. Previously the last workspace silently won, causing the project's data to end up in the wrong DB.
1 parent 67f79e2 commit fbe3dec

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/lib/multi-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,18 @@ export function loadMultiConfig(yamlPath: string): MultiConfig {
594594
// --- Workspaces ---
595595
const workspaces = new Map<string, WorkspaceConfig>();
596596

597+
const projectToWorkspace = new Map<string, string>();
597598
if (validated.workspaces) {
598599
for (const [wsId, raw] of Object.entries(validated.workspaces)) {
599600
for (const projId of raw.projects) {
600601
if (!projects.has(projId)) {
601602
throw new Error(`Workspace "${wsId}" references unknown project "${projId}"`);
602603
}
604+
const existing = projectToWorkspace.get(projId);
605+
if (existing) {
606+
throw new Error(`Project "${projId}" belongs to multiple workspaces: "${existing}" and "${wsId}"`);
607+
}
608+
projectToWorkspace.set(projId, wsId);
603609
}
604610

605611
const firstProject = projects.get(raw.projects[0])!;

src/tests/multi-config.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,24 @@ workspaces:
352352
expect(() => loadMultiConfig(yamlPath)).toThrow('unknown project "nonexistent"');
353353
});
354354

355+
it('throws when project belongs to multiple workspaces', () => {
356+
const yamlPath = tmpYaml(`
357+
projects:
358+
a:
359+
projectDir: /tmp/a
360+
b:
361+
projectDir: /tmp/b
362+
workspaces:
363+
ws1:
364+
projects: [a]
365+
graphMemory: /tmp/ws1
366+
ws2:
367+
projects: [a, b]
368+
graphMemory: /tmp/ws2
369+
`);
370+
expect(() => loadMultiConfig(yamlPath)).toThrow('multiple workspaces: "ws1" and "ws2"');
371+
});
372+
355373
it('workspace defaults graphMemory to first project dir', () => {
356374
const yamlPath = tmpYaml(`
357375
projects:

0 commit comments

Comments
 (0)