Machine-produced by `pnpm run rescope-vendor --apply` plus the regeneration it prints: `pnpm install` for the lockfile, `pnpm run gen-third-party-notices`, `verify-translation-pairing --write` for the touched bilingual pairs, `gen-doc-graphs`, and one typert snapshot whose ids embed character offsets. `pnpm run rescope-vendor --check` verifies the result. Renames nine vendored packages (cordis, cosmokit, schemastery and the six @cordisjs plugins) and every reference that resolves them: manifest names and dependency keys, module specifiers including declare-module merges, cordis.yml plugin names, tsconfig paths, every Markdown fence, and `docs/` prose. Directory names, upstream versions, and dependency ranges are unchanged, so vendor/README.md still reads as an upstream snapshot; its manifest table gains an upstream-name column so THIRD_PARTY_NOTICES keeps MIT attribution pointed at each fork's origin. The tutorial tier follows the rename end to end: its yaml fences named plugins the Loader can no longer resolve, its `ts ignore-check` fences disagreed with the compiled fences beside them, and its prose quoted both. The contracts that told readers to keep upstream names — the root convention and the vendoring cookbook's tree comment and manifest invariant — now say to rescope instead. Two rules read `@deepseek-ai/` as "another workspace plugin": the client bundle purity gate now names the vendored libraries a browser bundle inlines, and the files where a bare `cordis` is an agent-preset id keep that product data.
89 lines
3.6 KiB
TypeScript
89 lines
3.6 KiB
TypeScript
import { Context } from '@deepseek-ai/cordis'
|
|
import SystemPrompt, { renderPrompt } from '@deepseek-ai/dsh-system-prompt'
|
|
import { createScope, type ScopeKey } from '@deepseek-ai/dsh-scope'
|
|
import { describe, expect, it } from 'vitest'
|
|
import * as Persona from '@deepseek-ai/dsh-persona'
|
|
import { PERSONA_SECTION } from '@deepseek-ai/dsh-persona'
|
|
|
|
async function harness(deploymentPersona: string): Promise<Context> {
|
|
const ctx = new Context()
|
|
await ctx.plugin(SystemPrompt, { persona: deploymentPersona })
|
|
return ctx
|
|
}
|
|
|
|
/** The rendered text of the persona slot as one scope sees it. */
|
|
async function personaText(ctx: Context, scope?: ScopeKey): Promise<string | undefined> {
|
|
const assembly = await ctx.systemPrompt.assemble(scope === undefined ? {} : { scope })
|
|
return assembly.sections.find(section => section.name === PERSONA_SECTION)?.text
|
|
}
|
|
|
|
describe('the persona row', () => {
|
|
it('rejects an unscoped mount, which would collide with the registry default', async () => {
|
|
const ctx = await harness('deployment identity')
|
|
|
|
await expect(ctx.plugin(Persona, { text: 'composition identity' }))
|
|
.rejects.toThrow(/"deployment:persona" is already registered/)
|
|
})
|
|
|
|
it('shadows the deployment default for one scope only', async () => {
|
|
const ctx = await harness('deployment identity')
|
|
const key: ScopeKey = { agent: 'a1' }
|
|
const scope = createScope(ctx, key)
|
|
|
|
await scope.ctx.plugin(Persona, { text: 'preset identity' })
|
|
|
|
expect(await personaText(ctx, key)).toBe('preset identity')
|
|
expect(await personaText(ctx)).toBe('deployment identity')
|
|
})
|
|
|
|
it('gives two scopes independent personas', async () => {
|
|
const ctx = await harness('')
|
|
const first: ScopeKey = { agent: 'a1' }
|
|
const second: ScopeKey = { agent: 'a2' }
|
|
|
|
await createScope(ctx, first).ctx.plugin(Persona, { text: 'first identity' })
|
|
await createScope(ctx, second).ctx.plugin(Persona, { text: 'second identity' })
|
|
|
|
expect(await personaText(ctx, first)).toBe('first identity')
|
|
expect(await personaText(ctx, second)).toBe('second identity')
|
|
})
|
|
|
|
it('shadows the deployment persona away entirely when its text is empty', async () => {
|
|
const ctx = await harness('deployment identity')
|
|
const key: ScopeKey = { agent: 'a1' }
|
|
|
|
await createScope(ctx, key).ctx.plugin(Persona, { text: '' })
|
|
|
|
// The slot is still occupied, so the deployment persona is gone for this
|
|
// agent; an empty section is dropped when the prompt renders.
|
|
expect(await personaText(ctx, key)).toBe('')
|
|
expect(await personaText(ctx)).toBe('deployment identity')
|
|
})
|
|
|
|
it('restores the shadowed default when its fiber unloads', async () => {
|
|
const ctx = await harness('deployment identity')
|
|
const key: ScopeKey = { agent: 'a1' }
|
|
const scope = createScope(ctx, key)
|
|
const fiber = await scope.ctx.plugin(Persona, { text: 'preset identity' })
|
|
expect(await personaText(ctx, key)).toBe('preset identity')
|
|
|
|
await fiber.dispose()
|
|
|
|
expect(await personaText(ctx, key)).toBe('deployment identity')
|
|
})
|
|
|
|
it('interpolates prompt variables strictly, like any other section', async () => {
|
|
const ctx = await harness('')
|
|
const key: ScopeKey = { agent: 'a1' }
|
|
ctx.systemPrompt.variable('model', () => 'deepseek-v4-pro')
|
|
|
|
await createScope(ctx, key).ctx.plugin(Persona, { text: 'You run on {{model}}.' })
|
|
|
|
// `assemble()` keeps section text uninterpolated; `renderPrompt()` is the
|
|
// stage that resolves `{{…}}` against the assembly's variables.
|
|
expect(await personaText(ctx, key)).toBe('You run on {{model}}.')
|
|
expect(renderPrompt(await ctx.systemPrompt.assemble({ scope: key })))
|
|
.toContain('You run on deepseek-v4-pro.')
|
|
})
|
|
})
|