Repository navigation
Expand file tree
/
Copy patherror.test.ts
More file actions
189 lines (161 loc) · 7.05 KB
/
Copy patherror.test.ts
File metadata and controls
189 lines (161 loc) · 7.05 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
import assert from 'node:assert/strict';
import { test } from 'vitest';
import { AppError } from '@agent-device/kernel/errors';
import { withCapturedStderrAsync } from '../../__tests__/test-utils/stream-capture.ts';
import { printHumanError } from './error.ts';
test('printHumanError renders a structured cause unconditionally', async () => {
const err = new AppError(
'COMMAND_FAILED',
'The daemon failed to fetch the app source',
undefined,
Object.assign(new Error('connect ECONNREFUSED 10.0.0.1:443'), {
code: 'ECONNREFUSED',
}),
);
const output = await captureStderr(() => printHumanError(err));
assert.match(output, /Cause: ECONNREFUSED connect ECONNREFUSED 10\.0\.0\.1:443/);
});
async function captureStderr(run: () => void | Promise<void>): Promise<string> {
return await withCapturedStderrAsync(async () => {
await run();
});
}
// --- ADR 0012 migration step 2: replay divergence compact text report ---
test('printHumanError renders a compact divergence report unconditionally (not gated behind --debug)', async () => {
const err = new AppError(
'REPLAY_DIVERGENCE',
'Replay failed at step 2 (click "Save"): not hittable',
{
divergence: {
version: 1,
kind: 'action-failure',
step: { index: 2, source: { path: '/tmp/flow.ad', line: 5 } },
action: 'click "Save"',
cause: { code: 'COMMAND_FAILED', message: 'not hittable' },
screen: {
state: 'available',
refsGeneration: 3,
refs: [{ ref: 'e5', role: 'button', label: 'Save' }],
},
suggestions: [
{ selector: 'id="save"', basis: 'id', ref: 'e5', role: 'button', label: 'Save' },
],
suggestionCount: 1,
resume: { allowed: false, reason: 'resume not yet supported' },
// ADR 0012 decision 6: always present, and must survive every
// projection — this is the "daemon text summary" (CLI) projection.
repairHint: 'record-and-heal',
},
},
);
const output = await captureStderr(() => printHumanError(err));
assert.match(output, /Divergence at step 2 \(\/tmp\/flow\.ad:5\)/);
assert.match(output, /Screen: 1 actionable ref\(s\) captured \(refsGeneration 3\)/);
assert.match(output, /@e5 \[button\] "Save"/);
assert.match(output, /Suggestions:/);
assert.match(output, /\[id\] "Save" id="save"/);
assert.match(output, /Repair hint: record-and-heal/);
// Not gated behind --debug: showDetails defaults to false/undefined here.
});
// --- #2560: run-level warnings ride the failed response to the human surface ---
test('printHumanError renders run-level warnings carried in error details', async () => {
const err = new AppError('REPLAY_DIVERGENCE', 'Replay failed at step 2 (tapOn "Save")', {
step: 2,
warnings: ['Optional Maestro assertVisible skipped at line 1: no match', 7],
});
const output = await captureStderr(() => printHumanError(err));
assert.match(
output,
/Error \(REPLAY_DIVERGENCE\)[\s\S]*^Warning: Optional Maestro assertVisible skipped at line 1: no match$/m,
);
assert.equal(output.includes('Warning: 7'), false);
});
test('printHumanError prints no Warning lines without a warnings channel', async () => {
const err = new AppError('COMMAND_FAILED', 'tap failed');
const output = await captureStderr(() => printHumanError(err));
assert.equal(output.includes('Warning:'), false);
});
// --- #1597: AMBIGUOUS_MATCH candidates print unconditionally, capped at 5 ---
test('printHumanError lists AMBIGUOUS_MATCH candidates unconditionally, not gated behind --debug', async () => {
const err = new AppError(
'AMBIGUOUS_MATCH',
'find matched 3 elements for text "Follow". Use a more specific locator or selector.',
{
locator: 'text',
query: 'Follow',
matches: 3,
candidates: ['@e2 [button] "Follow"', '@e5 [button] "Follow"', '@e9 [button] "Follow"'],
},
);
// This is the exact old-message shape the bug reported: the human render
// used to stop at "Error (...): ...\nHint: ...", so an agent reading it had
// no @ref to act on. Asserting the candidate lines appear proves this red
// against that shape (it would fail before candidate views were wired into
// printHumanError).
const output = await captureStderr(() => printHumanError(err));
assert.match(output, /^Error \(AMBIGUOUS_MATCH\): find matched 3 elements/);
assert.match(
output,
/Candidates:\n {2}@e2 \[button\] "Follow"\n {2}@e5 \[button\] "Follow"\n {2}@e9 \[button\] "Follow"/,
);
// 3 candidates for 3 matches: nothing was capped, so no "+N more" marker.
assert.equal(/\+\d+ more/.test(output), false);
// Not gated behind --debug: showDetails defaults to false/undefined here.
});
test('printHumanError appends a "+N more" marker when candidates were capped', async () => {
const err = new AppError('AMBIGUOUS_MATCH', 'find matched 7 elements for text "Row". ...', {
matches: 7,
candidates: [
'@e2 [button] "Row"',
'@e3 [button] "Row"',
'@e4 [button] "Row"',
'@e5 [button] "Row"',
'@e6 [button] "Row"',
],
});
const output = await captureStderr(() => printHumanError(err));
assert.match(output, /@e6 \[button\] "Row"\n {2}\+2 more/);
});
// The device-domain resolvers (findBootedAppleSimulatorWithApp,
// -device/device-selection/dispatch-resolve) key their candidate list `devices`, so the CLI
// renders the udids the "pass --udid" hint asks for. The structured candidate
// view comes from @agent-device/kernel/errors and formatting stays local here.
test('printHumanError lists device candidates for the device-domain resolvers', async () => {
const err = new AppError(
'AMBIGUOUS_MATCH',
'Multiple booted iOS simulators have com.example.app installed',
{
appTarget: 'com.example.app',
devices: [
{ id: 'SIM-001', name: 'iPhone 17 Pro' },
{ id: 'SIM-002', name: 'iPhone 17' },
],
hint: 'Pass --udid to select the intended simulator explicitly.',
},
);
const output = await captureStderr(() => printHumanError(err));
assert.match(output, /Devices:\n {2}SIM-001 {2}iPhone 17 Pro\n {2}SIM-002 {2}iPhone 17/);
assert.equal(output.includes('[object Object]'), false);
});
test('printHumanError shows an unavailable screen reason and omitted suggestions hint', async () => {
const err = new AppError('REPLAY_DIVERGENCE', 'Replay failed at step 1', {
divergence: {
version: 1,
kind: 'action-failure',
step: { index: 1, source: { path: '/tmp/flow.ad', line: 1 } },
action: 'click "Save"',
cause: { code: 'COMMAND_FAILED', message: 'not hittable' },
screen: {
state: 'unavailable',
reason: 'capture-failed',
hint: 'take a snapshot to observe the result.',
},
suggestions: [],
suggestionCount: 2,
resume: { allowed: false, reason: 'resume not yet supported' },
},
});
const output = await captureStderr(() => printHumanError(err));
assert.match(output, /Screen: unavailable \(capture-failed\)\. take a snapshot/);
assert.match(output, /Suggestions: 2 available \(omitted at this response level/);
});