/** * The composition seam between ACRYL's coding capabilities and the product surfaces that compose them (spec 034, spec 051 T021). The table * below is the contract: a change to it is a change to what a surface boots with, so it is asserted per surface rather than inferred from * whichever surface happens to run. It must name exactly the Blueprint vocabulary the runtime parses; the last test holds both ways. */ import { describe, expect, it } from 'vitest' import type { AcrylSurface } from '../src/index.ts' import { CODING_CAPABILITY_COMPOSITIONS, createAcrylCodingCapabilityPatches, acrylCodingCapabilityPackages, createAcrylShellCapabilityPatches, } from '../src/index.ts' type PatchShape = { readonly idRows: readonly string[] readonly insertedIds: readonly string[] } const SURFACES: readonly AcrylSurface[] = ['tui', 'web', 'desktop'] /** * Exact composed rows per surface, measured from the real function below. * `tui` is the only surface that composes ACRYL's persona, roster and * session-stat rows: `web`/`desktop` build on `dsh-web-app`, which already * composes its own. Every surface composes the authorization service. */ const expectedComposition: Record = { tui: { idRows: ['system-prompt', 'deepseek-account'], insertedIds: ['agent-preset-registry', 'session-stats', 'authorization', 'acryl-settings', 'acryl-sign-in-account-callback'], }, web: { idRows: [], insertedIds: ['authorization', 'acryl-settings', 'acryl-app-shell', 'acryl-workspace', 'acryl-plugin-admin', 'acryl-sign-in', 'acryl-launcher-desktop', 'acryl-support', 'acryl-agent-control'] }, desktop: { idRows: [], insertedIds: ['authorization', 'acryl-settings', 'acryl-app-shell', 'acryl-workspace', 'acryl-plugin-admin', 'acryl-sign-in', 'acryl-launcher-desktop', 'acryl-agent-control'] }, } function shapeOf(patches: readonly unknown[]): PatchShape { const idRows: string[] = [] const insertedIds: string[] = [] for (const patch of patches) { const candidate = patch as { id?: unknown; insert?: { id?: unknown }[] } if (typeof candidate.id === 'string') idRows.push(candidate.id) for (const row of candidate.insert ?? []) { if (typeof row.id === 'string') insertedIds.push(row.id) } } return { idRows, insertedIds } } describe('CODING_CAPABILITY_COMPOSITIONS declarations', () => { it('declares every capability for at least one surface, with unique ids and stable order', () => { const ids = CODING_CAPABILITY_COMPOSITIONS.map(capability => capability.id) expect(new Set(ids).size).toBe(ids.length) for (const capability of CODING_CAPABILITY_COMPOSITIONS) { expect(capability.surfaces.length).toBeGreaterThan(0) expect(capability.loaderPatches.length).toBeGreaterThan(0) for (const surface of capability.surfaces) expect(SURFACES).toContain(surface) } }) it('declares authorization for every product surface', () => { const authorization = CODING_CAPABILITY_COMPOSITIONS.find(capability => capability.id === 'authorization') expect(authorization?.surfaces).toEqual(['tui', 'web', 'desktop']) expect(JSON.stringify(authorization?.loaderPatches)).toContain('@deepseek-ai/dsh-authorization') }) it('keeps the persona out of the tui-only capability set for the surfaces dsh-web-app covers', () => { const persona = CODING_CAPABILITY_COMPOSITIONS.find(capability => capability.id === 'persona') expect(persona?.surfaces).toEqual(['tui']) expect(persona?.loaderPatches).toEqual([ expect.objectContaining({ id: 'system-prompt', name: '@deepseek-ai/dsh-system-prompt', config: { persona: 'You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}.', }, }), ]) expect(JSON.stringify(createAcrylCodingCapabilityPatches(new Set(['web'])))).not.toContain('system-prompt') expect(JSON.stringify(createAcrylCodingCapabilityPatches(new Set(['desktop'])))).not.toContain('system-prompt') }) it('declares the agent roster through the 0.2 preset registry with its default preset', () => { // DETACHED root (spec 001 R25): `dsh-agent-presets` became `dsh-agent-preset-registry`, whose presets come from bundle patches rather // than a `roots` list, so the TUI roster declares only the default until ACRYL's own roots are re-declared. const roster = CODING_CAPABILITY_COMPOSITIONS.find(capability => capability.id === 'agent-roster') const inserted = roster?.loaderPatches.flatMap(patch => ('insert' in patch ? patch.insert ?? [] : [])) ?? [] const registry = inserted.find(row => row.id === 'agent-preset-registry') expect(registry?.name).toBe('@deepseek-ai/dsh-agent-preset-registry') expect(registry?.config).toEqual({ default: 'standard' }) }) }) describe('createAcrylCodingCapabilityPatches', () => { it.each(SURFACES)('composes exactly the declared rows for %s', (surface) => { expect(shapeOf(createAcrylCodingCapabilityPatches(new Set([surface])))).toEqual(expectedComposition[surface]) }) it('composes each row only for surfaces that declare it', () => { for (const surface of SURFACES) { const patches = createAcrylCodingCapabilityPatches(new Set([surface])) const composedIds = Object.values(shapeOf(patches)).flat() const declaredForSurface = new Set( CODING_CAPABILITY_COMPOSITIONS .filter(capability => capability.surfaces.includes(surface) && capability.shellMode === undefined) .flatMap(capability => capability.loaderPatches.flatMap((patch) => { const rows = [ ...('id' in patch && typeof patch.id === 'string' ? [patch.id] : []), ...('insert' in patch ? (patch.insert ?? []).map(row => row.id) : []), ] return rows })), ) expect(new Set(composedIds)).toEqual(declaredForSurface) } }) it('unions multiple requested surfaces without duplicating a row', () => { const both = shapeOf(createAcrylCodingCapabilityPatches(new Set(['web', 'desktop']))) expect(both.insertedIds).toEqual(['authorization', 'acryl-settings', 'acryl-app-shell', 'acryl-workspace', 'acryl-plugin-admin', 'acryl-sign-in', 'acryl-launcher-desktop', 'acryl-support', 'acryl-agent-control']) const all = shapeOf(createAcrylCodingCapabilityPatches(new Set(SURFACES))) expect(all.idRows).toEqual(['system-prompt', 'deepseek-account']) expect(all.insertedIds).toEqual(['agent-preset-registry', 'session-stats', 'authorization', 'acryl-settings', 'acryl-app-shell', 'acryl-workspace', 'acryl-plugin-admin', 'acryl-sign-in', 'acryl-launcher-desktop', 'acryl-sign-in-account-callback', 'acryl-support', 'acryl-agent-control']) }) it('composes nothing for a surface set no capability declares', () => { expect(createAcrylCodingCapabilityPatches(new Set())).toEqual([]) }) it('drops an insert whose id the profile already composes (spec 034 T008)', () => { // A profile booted through the tui flavor is not necessarily tui-shaped: // `--profile ` can point at one created with Desktop/Web's own // richer bundle, which already carries agent-presets/session-stats // natively. Composing the tui capabilities on top of that used to insert // the same row id a second time and throw `duplicate loader entry id` at // boot - the existingRowIds filter is what this test guards. const withoutExisting = shapeOf(createAcrylCodingCapabilityPatches(new Set(['tui']))) expect(withoutExisting.insertedIds).toEqual(['agent-preset-registry', 'session-stats', 'authorization', 'acryl-settings', 'acryl-sign-in-account-callback']) const withExisting = shapeOf( createAcrylCodingCapabilityPatches(new Set(['tui']), new Set(['agent-preset-registry'])), ) expect(withExisting.insertedIds).toEqual(['session-stats', 'authorization', 'acryl-settings', 'acryl-sign-in-account-callback']) }) it('drops every insert of a fully-provided capability, not just its first row', () => { const allProvided = shapeOf( createAcrylCodingCapabilityPatches( new Set(['tui']), new Set(['agent-preset-registry', 'session-stats', 'authorization', 'acryl-settings', 'acryl-sign-in-account-callback']), ), ) expect(allProvided).toEqual({ idRows: ['system-prompt', 'deepseek-account'], insertedIds: [] }) }) it('still inserts a row existingRowIds does not name', () => { const patches = shapeOf(createAcrylCodingCapabilityPatches(new Set(['tui']), new Set(['some-other-row']))) expect(patches.insertedIds).toEqual(['agent-preset-registry', 'session-stats', 'authorization', 'acryl-settings', 'acryl-sign-in-account-callback']) }) it('returns fresh patches a caller may mutate without affecting the next surface', () => { const first = createAcrylCodingCapabilityPatches(new Set(['tui'])) const [firstPatch] = first if (firstPatch === undefined) throw new Error('expected at least one coding capability patch') firstPatch.id = 'mutated-system-prompt' const second = createAcrylCodingCapabilityPatches(new Set(['tui'])) expect(second[0]?.id).toBe('system-prompt') expect(JSON.stringify(CODING_CAPABILITY_COMPOSITIONS)).not.toContain('mutated-system-prompt') }) }) describe('the workspace and the ACRYL shell are shared by Web and Desktop (spec 040, surface sharing)', () => { it('declares the workspace for exactly the surfaces that render it, never TUI', () => { const workspace = CODING_CAPABILITY_COMPOSITIONS.find(capability => capability.id === 'workspace') expect(workspace?.surfaces).toEqual(['desktop', 'web']) expect(workspace?.requiresPackages).toEqual(['@acryldev/app-shell', '@acryldev/workspace']) expect(createAcrylCodingCapabilityPatches(new Set(['tui'])).flatMap(p => 'insert' in p ? p.insert ?? [] : []).map(r => r.id)).not.toContain('acryl-workspace') }) it('composes the identical workspace rows and the identical shell patches on Web and Desktop', () => { // Web alone adds `@acryldev/support` (log files and the diagnostics download), because Desktop already has both natively. const rows = (surface: AcrylSurface): unknown => { const shape = shapeOf(createAcrylCodingCapabilityPatches(new Set([surface]))) return { ...shape, insertedIds: shape.insertedIds.filter(id => id !== 'acryl-support') } } expect(rows('web')).toEqual(rows('desktop')) expect(shapeOf(createAcrylCodingCapabilityPatches(new Set(['web']))).insertedIds).toContain('acryl-support') expect(shapeOf(createAcrylCodingCapabilityPatches(new Set(['desktop']))).insertedIds).not.toContain('acryl-support') expect(shapeOf(createAcrylCodingCapabilityPatches(new Set(['web']))).insertedIds).toContain('acryl-sign-in') const shell = (surface: AcrylSurface): unknown => createAcrylShellCapabilityPatches(new Set([surface]), 'advanced') expect(shell('web')).toEqual(shell('desktop')) expect(shell('web')).toEqual([ { id: 'ui-layout', disabled: true }, { id: 'ui-sidebar', disabled: false }, { id: 'ui-conversation', disabled: false }, ]) }) it('composes no shell patches for compatibility mode or for TUI', () => { expect(createAcrylShellCapabilityPatches(new Set(['desktop']), 'compatibility')).toEqual([]) expect(createAcrylShellCapabilityPatches(new Set(['tui']), 'advanced')).toEqual([]) // Shell-mode capabilities never leak into the plain composition, whatever the surface. for (const surface of SURFACES) { expect(JSON.stringify(createAcrylCodingCapabilityPatches(new Set([surface])))).not.toContain('ui-layout') } }) it('names the ACRYL packages each surface must make resolvable, the same on Web and Desktop', () => { expect(acrylCodingCapabilityPackages(new Set(['web']))).toEqual(['@acryldev/settings', '@acryldev/app-shell', '@acryldev/workspace', '@acryldev/plugin-admin', '@acryldev/sign-in', '@acryldev/launcher-desktop', '@acryldev/support', '@acryldev/agent-control']) expect(acrylCodingCapabilityPackages(new Set(['desktop']))).toEqual(['@acryldev/settings', '@acryldev/app-shell', '@acryldev/workspace', '@acryldev/plugin-admin', '@acryldev/sign-in', '@acryldev/launcher-desktop', '@acryldev/agent-control']) expect(acrylCodingCapabilityPackages(new Set(['tui']))).toEqual(['@acryldev/settings', '@acryldev/sign-in']) }) it('returns fresh objects each call so one surface cannot edit the next one\'s patches', () => { const first = createAcrylShellCapabilityPatches(new Set(['web']), 'advanced') ;(first[0] as { disabled?: boolean }).disabled = false expect(createAcrylShellCapabilityPatches(new Set(['web']), 'advanced')[0]).toEqual({ id: 'ui-layout', disabled: true }) }) })