Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from 'node:assert/strict';
import { test } from 'vitest';
import { attachSessionAddressHints } from '../daemon-client-lifecycle.ts';

test('remote fill recording errors give a recovery path the remote client supports', () => {
const response = {
ok: false as const,
error: {
code: 'INVALID_ARGS',
message:
'fill --record-as requires an armed script recording. Start a fresh session with open --save-script, then retry the fill.',
details: { reason: 'fill_record_as_requires_armed_recording' },
},
};
const settings = { remoteBaseUrl: 'https://device.example' } as never;

const remote = attachSessionAddressHints(response, {} as never, settings);
assert.equal(remote.ok, false);
if (remote.ok) return;
assert.match(remote.error.message, /remote clients cannot start one/);
assert.match(remote.error.message, /Connect to a local daemon/);
assert.equal(remote.error.details?.reason, 'fill_record_as_requires_armed_recording');

const local = attachSessionAddressHints(response, {} as never, {} as never);
assert.equal(local, response);
});
13 changes: 13 additions & 0 deletions packages/daemon-client/src/daemon-client-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ export function attachSessionAddressHints(
settings: DaemonClientSettings,
): DaemonResponse {
if (!response.ok) {
if (
settings.remoteBaseUrl &&
response.error.details?.reason === 'fill_record_as_requires_armed_recording'
) {
return {
...response,
error: {
...response.error,
message:
'fill --record-as requires an armed script recording, but remote clients cannot start one. Connect to a local daemon, start a fresh session with open --save-script, then retry the fill, or omit --record-as.',
},
};
}
return settings.ownedStateDir && isHeldRepairDivergence(response)
? attachRepairSessionAddressHint(response, settings.paths.baseDir)
: response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ test.each([
});

test('--record-as keeps requiring an armed recording when the text came from stdin', () => {
expect(() => check({ textStdin: true, recordAs: 'PASSWORD' }, false)).toThrow(
/requires an armed script recording/,
);
let caught: unknown;
try {
check({ textStdin: true, recordAs: 'PASSWORD' }, false);
} catch (error) {
caught = error;
}
expect(caught).toBeInstanceOf(AppError);
expect((caught as AppError).code).toBe('INVALID_ARGS');
expect((caught as AppError).details?.reason).toBe('fill_record_as_requires_armed_recording');
Comment thread
nikitabhagat2307-prog marked this conversation as resolved.
Resolved
expect((caught as AppError).message).toMatch(/open --save-script/);
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function assertRecordedFillParameterization(params: {
throw new AppError(
'INVALID_ARGS',
'fill --record-as requires an armed script recording. Start a fresh session with open --save-script, then retry the fill.',
{ reason: 'fill_record_as_requires_armed_recording' },
);
}
}
Expand Down
Loading