✨ feat(vscode): 历史会话可换 profile 恢复
This commit is contained in:
1 parent
1c3e66bdc7
commit
07b2bf75a0
9 files changed
+177
-34
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { decideManagedResumeProfile } from './managedResumeProfile'
|
||||
|
||||
describe('decideManagedResumeProfile', () => {
|
||||
it('override 非空时用 override,与 stored 不同则写回', () => {
|
||||
expect(decideManagedResumeProfile({
|
||||
storedProfile: '/profiles/grok-4.5.json',
|
||||
overrideProfile: '/profiles/opus.json',
|
||||
inferredProfile: '/profiles/from-jsonl.json',
|
||||
})).toEqual({
|
||||
effective: '/profiles/opus.json',
|
||||
persist: '/profiles/opus.json',
|
||||
})
|
||||
})
|
||||
|
||||
it('override 与 stored trim 后相同则不写回,且忽略 inferred', () => {
|
||||
expect(decideManagedResumeProfile({
|
||||
storedProfile: ' /profiles/grok-4.5.json ',
|
||||
overrideProfile: '/profiles/grok-4.5.json',
|
||||
inferredProfile: '/profiles/from-jsonl.json',
|
||||
})).toEqual({
|
||||
effective: '/profiles/grok-4.5.json',
|
||||
persist: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('空白 override 视为未提供,回落到 stored', () => {
|
||||
expect(decideManagedResumeProfile({
|
||||
storedProfile: '/profiles/grok-4.5.json',
|
||||
overrideProfile: ' ',
|
||||
inferredProfile: '/profiles/from-jsonl.json',
|
||||
})).toEqual({
|
||||
effective: '/profiles/grok-4.5.json',
|
||||
persist: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('无 override 时用 stored,不写回也不用 inferred', () => {
|
||||
expect(decideManagedResumeProfile({
|
||||
storedProfile: '/profiles/grok-4.5.json',
|
||||
overrideProfile: undefined,
|
||||
inferredProfile: '/profiles/from-jsonl.json',
|
||||
})).toEqual({
|
||||
effective: '/profiles/grok-4.5.json',
|
||||
persist: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('override 与 stored 都空时用 inferred 并写回', () => {
|
||||
expect(decideManagedResumeProfile({
|
||||
storedProfile: ' ',
|
||||
overrideProfile: undefined,
|
||||
inferredProfile: '/profiles/from-jsonl.json',
|
||||
})).toEqual({
|
||||
effective: '/profiles/from-jsonl.json',
|
||||
persist: '/profiles/from-jsonl.json',
|
||||
})
|
||||
})
|
||||
|
||||
it('三者都空则 effective 与 persist 都为 undefined', () => {
|
||||
expect(decideManagedResumeProfile({
|
||||
storedProfile: undefined,
|
||||
overrideProfile: '',
|
||||
inferredProfile: null,
|
||||
})).toEqual({
|
||||
effective: undefined,
|
||||
persist: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
export function decideManagedResumeProfile(input: {
|
||||
storedProfile: string | undefined
|
||||
overrideProfile: string | undefined
|
||||
inferredProfile: string | null
|
||||
}): { effective: string | undefined, persist: string | undefined } {
|
||||
const override = input.overrideProfile?.trim() || undefined
|
||||
const stored = input.storedProfile?.trim() || undefined
|
||||
|
||||
if (override) { // ① 行内覆盖:与 store 不同才写回;忽略 jsonl 推断
|
||||
return {
|
||||
effective: override,
|
||||
persist: override !== stored ? override : undefined,
|
||||
}
|
||||
}
|
||||
if (stored) // ② store 已有 → 沿用,不写回
|
||||
return { effective: stored, persist: undefined }
|
||||
if (input.inferredProfile) // ③ 缺 profile 才用 jsonl 回填并写回
|
||||
return { effective: input.inferredProfile, persist: input.inferredProfile }
|
||||
return { effective: undefined, persist: undefined }
|
||||
}
|
||||
Reference in new issue
Block a user