-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathoperation-runtime-metadata.test.ts
More file actions
106 lines (92 loc) · 4.57 KB
/
operation-runtime-metadata.test.ts
File metadata and controls
106 lines (92 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { describe, expect, test } from 'bun:test';
import { CLI_OPERATION_METADATA, CLI_OPERATION_OPTION_SPECS, type CliOperationId } from '../../cli';
import { getOperationRuntimeMetadata } from '../../lib/operation-runtime-metadata';
describe('operation runtime metadata', () => {
test('covers every CLI operation id', () => {
const operationIds = Object.keys(CLI_OPERATION_METADATA) as CliOperationId[];
for (const operationId of operationIds) {
const runtime = getOperationRuntimeMetadata(operationId);
expect(runtime.operationId).toBe(operationId);
expect(runtime.profile).toBeDefined();
expect(runtime.context).toBeDefined();
expect(runtime.traits).toBeDefined();
}
});
test('marks lifecycle and session admin operations explicitly', () => {
expect(getOperationRuntimeMetadata('doc.open').profile).toBe('lifecycle');
expect(getOperationRuntimeMetadata('doc.save').profile).toBe('lifecycle');
expect(getOperationRuntimeMetadata('doc.close').profile).toBe('lifecycle');
expect(getOperationRuntimeMetadata('doc.session.list').profile).toBe('sessionAdmin');
expect(getOperationRuntimeMetadata('doc.session.save').profile).toBe('sessionAdmin');
expect(getOperationRuntimeMetadata('doc.session.close').profile).toBe('sessionAdmin');
expect(getOperationRuntimeMetadata('doc.session.setDefault').profile).toBe('sessionAdmin');
});
test('derives mutation traits for text operations', () => {
const insert = getOperationRuntimeMetadata('doc.insert');
expect(insert.profile).toBe('mutation');
expect(insert.traits.supportsDryRun).toBe(true);
expect(insert.traits.supportsChangeMode).toBe(true);
expect(insert.traits.supportsExpectedRevision).toBe(true);
expect(insert.traits.requiresOutInStateless).toBe(true);
});
test('marks describe operations as stateless only', () => {
const describe = getOperationRuntimeMetadata('doc.describe');
const describeCommand = getOperationRuntimeMetadata('doc.describeCommand');
expect(describe.context.supportsStateless).toBe(true);
expect(describe.context.supportsSession).toBe(false);
expect(describeCommand.context.supportsStateless).toBe(true);
expect(describeCommand.context.supportsSession).toBe(false);
});
test('doc.open metadata includes userName and userEmail params', () => {
const openMeta = CLI_OPERATION_METADATA['doc.open'];
const paramNames = openMeta.params.map((p) => p.name);
expect(paramNames).toContain('userName');
expect(paramNames).toContain('userEmail');
});
test('doc.open option specs include user-name and user-email flags', () => {
const openOptions = CLI_OPERATION_OPTION_SPECS['doc.open'];
const optionNames = openOptions.map((o) => o.name);
expect(optionNames).toContain('user-name');
expect(optionNames).toContain('user-email');
});
test('doc.open metadata includes password param', () => {
const openMeta = CLI_OPERATION_METADATA['doc.open'];
const paramNames = openMeta.params.map((p) => p.name);
expect(paramNames).toContain('password');
});
test('doc.open password param is not agent-visible', () => {
const openMeta = CLI_OPERATION_METADATA['doc.open'];
const passwordParam = openMeta.params.find((p) => p.name === 'password');
expect(passwordParam).toBeDefined();
expect(passwordParam!.agentVisible).toBe(false);
});
test('doc.open option specs include password flag', () => {
const openOptions = CLI_OPERATION_OPTION_SPECS['doc.open'];
const optionNames = openOptions.map((o) => o.name);
expect(optionNames).toContain('password');
});
test('doc.open metadata includes trackChanges JSON param', () => {
const openMeta = CLI_OPERATION_METADATA['doc.open'];
const trackChangesParam = openMeta.params.find((p) => p.name === 'trackChanges');
expect(trackChangesParam).toBeDefined();
expect(trackChangesParam!.kind).toBe('jsonFlag');
expect(trackChangesParam!.type).toBe('json');
expect(trackChangesParam!.flag).toBe('track-changes-json');
expect(trackChangesParam!.schema).toEqual({
type: 'object',
properties: {
replacements: {
type: 'string',
enum: ['paired', 'independent'],
description: 'Tracked replacement grouping mode.',
},
},
});
});
test('doc.open option specs include track-changes-json flag', () => {
const openOptions = CLI_OPERATION_OPTION_SPECS['doc.open'];
const trackChangesOption = openOptions.find((o) => o.name === 'track-changes-json');
expect(trackChangesOption).toBeDefined();
expect(trackChangesOption!.type).toBe('string');
});
});