-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathgate-transition.test.ts
More file actions
266 lines (248 loc) · 9.45 KB
/
Copy pathgate-transition.test.ts
File metadata and controls
266 lines (248 loc) · 9.45 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import { describe, expect, it } from 'vitest';
import {
approvalIntentSignature,
evaluateProductionOperation,
nextAllowedProductionOperations,
projectApprovalIntent,
resolveGateTransition,
} from '../src/gates/index.js';
describe('resolveGateTransition', () => {
it('turns a visual-only draft revision into one bounded edit without another gate', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'gate_d',
decision: 'revise',
scope: 'visual_only',
recovery: 'not_available',
});
expect(result).toMatchObject({ next_action: 'edit_current_cycle', form: null });
expect(result.allowed_ops).toContain('ovs snapshot');
expect(result.prohibited_ops).toContain('emit_form');
});
it('uses one Gate B amendment and ignores recovery from the old signature', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'preview',
decision: 'revise',
scope: 'gate_b_payload',
recovery: 'available',
});
expect(result).toMatchObject({
next_action: 'open_gate_b_amendment',
form: { fields: ['gate_b_decision'] },
});
expect(result.prohibited_ops).toContain('reset_visual_qa_cycle');
expect(result.reason).toContain('production-plan payload');
expect(result.reason).not.toContain('Gate B payload');
});
it('uses the current visual revise decision to start a fresh automatic QA cycle', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'preview',
decision: 'revise',
scope: 'visual_only',
recovery: 'available',
});
expect(result).toMatchObject({
next_action: 'edit_and_restart_visual_qa',
form: null,
authorities: ['edit_current_artifact', 'restart_visual_qa_cycle'],
});
expect(result.allowed_ops).toContain('ovs draft');
expect(result.prohibited_ops).toContain('emit_form');
expect(result.reason).toContain('visual-preview or final-video revision');
});
it('does not treat an authorization error as proof that recovery is available', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'gate_d',
decision: 'revise',
scope: 'visual_only',
recovery: 'unknown',
errorCode: 'E_VISUAL_REVISION_EXPLICIT_AUTHORIZATION_REQUIRED',
});
expect(result).toMatchObject({ next_action: 'query_status', form: null });
expect(result.prohibited_ops).toContain('emit_form');
});
it('turns an exhausted QA cycle into a user fork, not a silent wait', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
recovery: 'available',
errorCode: 'E_VISUAL_REVISION_EXPLICIT_AUTHORIZATION_REQUIRED',
});
expect(result).toMatchObject({ next_action: 'present_findings_and_ask_user_direction', form: null });
expect(result.prohibited_ops).toContain('emit_form');
expect(result.prohibited_ops).toContain('edit_files');
expect(result.prohibited_ops).toContain('restart_visual_qa_cycle');
expect(result.reason).toMatch(/materially different edit/i);
});
it('offers the fork on bare exhausted recovery with no decision at all', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
recovery: 'available',
});
expect(result).toMatchObject({ next_action: 'present_findings_and_ask_user_direction', form: null });
expect(result.reason).toMatch(/waive|skipping/i);
});
it('applies a user-dictated amendment directly instead of re-confirming it', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'gate_b',
decision: 'revise',
scope: 'gate_b_payload',
origin: 'user',
});
expect(result).toMatchObject({ next_action: 'apply_user_instruction_then_approve_plan', form: null });
expect(result.authorities).toContain('approve_gate_b');
expect(result.reason).toMatch(/own words/i);
});
it('keeps the Gate B amendment for model-initiated or mixed changes', () => {
for (const origin of ['model', 'unknown'] as const) {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'gate_b',
decision: 'revise',
scope: 'gate_b_payload',
origin,
});
expect(result.next_action).toBe('open_gate_b_amendment');
}
});
it('rejects mixed current and legacy decision fields', () => {
expect(() => resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'preview',
decision: 'revise',
scope: 'visual_only',
recovery: 'available',
recoveryDecision: 'new_visual_revision',
})).toThrow(/cannot both describe the current turn/i);
});
it('consumes a legacy recovery decision without emitting another form', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
recovery: 'available',
recoveryDecision: 'new_visual_revision',
});
expect(result).toMatchObject({ next_action: 'edit_for_fresh_visual_qa', form: null });
expect(result.allowed_ops).toContain('ovs draft');
expect(result.prohibited_ops).toContain('emit_form');
});
it('continues from an existing approval for an unchanged artifact', () => {
const result = resolveGateTransition({
line: 'edit',
artifact: 'production',
gate: 'gate_b',
artifactState: 'unchanged',
approvalStatus: 'approved',
recovery: 'not_available',
});
expect(result).toMatchObject({ next_action: 'continue_from_existing_approval', form: null });
expect(result.prohibited_ops).toContain('emit_form');
});
it('maps an explicit preview approval to the real OVS draft operation', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'preview',
decision: 'approve',
scope: 'none',
recovery: 'not_available',
});
expect(result).toMatchObject({ next_action: 'render_approved_preview', allowed_ops: ['ovs draft'] });
});
it('lets a current Gate B amendment approval win over cached approval', () => {
const result = resolveGateTransition({
line: 'compose',
artifact: 'composition',
gate: 'gate_b',
decision: 'approve',
scope: 'gate_b_payload',
recovery: 'not_available',
artifactState: 'unchanged',
approvalStatus: 'approved',
});
expect(result).toMatchObject({
next_action: 'apply_approved_amendment_then_approve_plan',
authorities: ['edit_current_artifact', 'approve_gate_b'],
form: null,
});
expect(result.prohibited_ops).toContain('emit_form');
});
});
describe('approval intent identity', () => {
it('separates execution and catalog metadata from stable production intent', () => {
const base = {
segments: [{
id: 'shot-1',
prompt: 'A red product on a stone pedestal',
status: 'planned',
produced_path: 'outputs/old.mp4',
}],
tracks: {
narration: {
synthesis: {
route_ref: 'openai-compatible',
voice: 'nova',
display_name: 'Nova (old label)',
provider_label: 'Provider A',
language: 'en-US',
speed: 1,
},
},
},
_runtime: { cache_dir: '/tmp/a' },
};
const refreshed = structuredClone(base);
refreshed.segments[0].status = 'complete';
refreshed.segments[0].produced_path = 'outputs/new.mp4';
refreshed.tracks.narration.synthesis.display_name = 'Nova';
refreshed.tracks.narration.synthesis.provider_label = 'Provider B';
refreshed._runtime.cache_dir = '/tmp/b';
expect(projectApprovalIntent(refreshed)).toEqual(projectApprovalIntent(base));
expect(approvalIntentSignature(refreshed)).toBe(approvalIntentSignature(base));
refreshed.segments[0].prompt = 'A blue product on a stone pedestal';
expect(approvalIntentSignature(refreshed)).not.toBe(approvalIntentSignature(base));
});
it('does not ignore display_name outside a stable voice selection', () => {
expect(approvalIntentSignature({ display_name: 'First' }))
.not.toBe(approvalIntentSignature({ display_name: 'Second' }));
});
});
describe('fact-based production admission', () => {
it('keeps visual preview and repair available while narration is recovering', () => {
const facts = {
planApproved: true,
narrationRequired: true,
narrationMaterialized: false,
};
expect(evaluateProductionOperation('composition.snapshot', facts)).toEqual({ ok: true });
expect(evaluateProductionOperation('composition.approve_preview', facts)).toEqual({ ok: true });
expect(evaluateProductionOperation('composition.draft', facts)).toMatchObject({
ok: false,
errorCode: 'E_NARRATION_MATERIALIZATION_REQUIRED',
});
expect(nextAllowedProductionOperations(facts)).toContain('composition.snapshot');
expect(nextAllowedProductionOperations(facts)).not.toContain('composition.export');
});
it('requires current Gate B approval without consulting a compatibility stage', () => {
expect(evaluateProductionOperation('composition.prepare', {
planApproved: false,
narrationRequired: false,
narrationMaterialized: false,
})).toMatchObject({
ok: false,
errorCode: 'E_GATE_B_APPROVAL_REQUIRED',
});
});
});