mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-15 18:23:12 +00:00
fix(config): merge legacy and unified continuity maps
- combine continuity.inherit_from_account with legacy continuity_inherit_from_account - prefer unified continuity entries on key collisions - add regression coverage for mixed-key merge behavior
This commit is contained in:
@@ -260,20 +260,22 @@ function normalizeContinuityInheritanceMap(value: unknown): Record<string, strin
|
|||||||
* Supports legacy root key: continuity_inherit_from_account.
|
* Supports legacy root key: continuity_inherit_from_account.
|
||||||
*/
|
*/
|
||||||
function normalizeContinuityConfig(partial: Partial<UnifiedConfig>): ContinuityConfig | undefined {
|
function normalizeContinuityConfig(partial: Partial<UnifiedConfig>): ContinuityConfig | undefined {
|
||||||
const continuityMap = normalizeContinuityInheritanceMap(partial.continuity?.inherit_from_account);
|
|
||||||
if (continuityMap) {
|
|
||||||
return { inherit_from_account: continuityMap };
|
|
||||||
}
|
|
||||||
|
|
||||||
const legacyMap = normalizeContinuityInheritanceMap(
|
const legacyMap = normalizeContinuityInheritanceMap(
|
||||||
(partial as Partial<UnifiedConfig> & { continuity_inherit_from_account?: unknown })
|
(partial as Partial<UnifiedConfig> & { continuity_inherit_from_account?: unknown })
|
||||||
.continuity_inherit_from_account
|
.continuity_inherit_from_account
|
||||||
);
|
);
|
||||||
if (legacyMap) {
|
const continuityMap = normalizeContinuityInheritanceMap(partial.continuity?.inherit_from_account);
|
||||||
return { inherit_from_account: legacyMap };
|
|
||||||
|
if (!legacyMap && !continuityMap) {
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return {
|
||||||
|
inherit_from_account: {
|
||||||
|
...(legacyMap ?? {}),
|
||||||
|
...(continuityMap ?? {}),
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -226,4 +226,43 @@ describe('continuity-inheritance-config', () => {
|
|||||||
fs.rmSync(tempHome, { recursive: true, force: true });
|
fs.rmSync(tempHome, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('merges continuity.inherit_from_account with legacy continuity_inherit_from_account', () => {
|
||||||
|
const originalCcsHome = process.env.CCS_HOME;
|
||||||
|
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-continuity-merge-home-'));
|
||||||
|
const ccsDir = path.join(tempHome, '.ccs');
|
||||||
|
fs.mkdirSync(ccsDir, { recursive: true });
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(ccsDir, 'config.yaml'),
|
||||||
|
[
|
||||||
|
'version: 8',
|
||||||
|
'continuity:',
|
||||||
|
' inherit_from_account:',
|
||||||
|
' glm: team-a',
|
||||||
|
' copilot: work',
|
||||||
|
'continuity_inherit_from_account:',
|
||||||
|
' glm: legacy',
|
||||||
|
' km: account-kimi',
|
||||||
|
'',
|
||||||
|
].join('\n')
|
||||||
|
);
|
||||||
|
|
||||||
|
process.env.CCS_HOME = tempHome;
|
||||||
|
try {
|
||||||
|
const config = loadOrCreateUnifiedConfig();
|
||||||
|
expect(config.continuity?.inherit_from_account).toEqual({
|
||||||
|
glm: 'team-a',
|
||||||
|
copilot: 'work',
|
||||||
|
km: 'account-kimi',
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
if (originalCcsHome === undefined) {
|
||||||
|
delete process.env.CCS_HOME;
|
||||||
|
} else {
|
||||||
|
process.env.CCS_HOME = originalCcsHome;
|
||||||
|
}
|
||||||
|
fs.rmSync(tempHome, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user