Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { createSecrets } from '../src/secrets'
3import {
4 defineWorkspace,
5 gitSkill,
6 localSource,
7 mcpSkill,
8} from '../src/workspace'
9
10describe('gitSkill', () => {
11 it('returns a git WorkspaceSkill with repo and secret', () => {
12 const secrets = createSecrets({ GH_TOKEN: 'tok' })
13 const skill = gitSkill({ repo: 'me/x', secret: secrets.GH_TOKEN })
14 expect(skill).toEqual({
15 kind: 'git',
16 repo: 'me/x',
17 secret: secrets.GH_TOKEN,
18 })
19 })
20
21 it('returns a git WorkspaceSkill without secret when omitted', () => {
22 const skill = gitSkill({ repo: 'me/public' })
23 expect(skill).toEqual({ kind: 'git', repo: 'me/public' })
24 })
25
26 it('includes into when provided', () => {
27 const skill = gitSkill({ repo: 'me/x', into: 'skills/x' })
28 expect(skill).toEqual({ kind: 'git', repo: 'me/x', into: 'skills/x' })
29 })
30})
31
32describe('defineWorkspace', () => {
33 it('round-trips instructions', () => {
34 const ws = defineWorkspace({
35 source: localSource('/workspace'),
36 instructions: 'You are a helpful agent.',
37 })
38 expect(ws.instructions).toBe('You are a helpful agent.')
39 })
40
41 it('round-trips plugins', () => {
42 const ws = defineWorkspace({
43 source: localSource('/workspace'),
44 plugins: ['@anthropic/plugin-foo', '@anthropic/plugin-bar'],
45 })
46 expect(ws.plugins).toEqual([
47 '@anthropic/plugin-foo',
48 '@anthropic/plugin-bar',
49 ])
50 })
51
52 it('round-trips secrets (Secrets object)', () => {
53 const secrets = createSecrets({ API_KEY: 'secret-value' })
54 const ws = defineWorkspace({
55 source: localSource('/workspace'),
56 secrets,
57 })
58 expect(ws.secrets).toBe(secrets)
59 // The SecretRef is accessible by name — use the typed local directly
60 expect(secrets.API_KEY.__secretName).toBe('API_KEY')
61 })
62})
63
64describe('mcpSkill', () => {
65 it('keeps a SecretRef in the descriptor without resolving it', () => {
66 const secrets = createSecrets({ AUTH_TOKEN: 'bearer-value' })
67 const secretRef = secrets.AUTH_TOKEN
68 const skill = mcpSkill('my-server', {
69 headers: { Authorization: secretRef },
70 })
71 expect(skill.kind).toBe('mcp')
72 if (skill.kind !== 'mcp') return
73 expect(skill.name).toBe('my-server')
74 // The header value must still be the unresolved SecretRef
75 const authHeader = skill.config.headers?.['Authorization']
76 expect(authHeader).toBe(secretRef)
77 expect(authHeader).toEqual({ __secretName: 'AUTH_TOKEN' })
78 })
79})