Skip to content
Open
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
51 changes: 51 additions & 0 deletions src/__tests__/commands/scraper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,43 @@ describe('commands/scraper', ()=>{
{timing: undefined}, 600);
expect(mocks.post.mock.calls[0][2]).toEqual({message: false});
});

it('adds auto_save:true to the body when approving with '
+'autoSave set', async()=>{
mocks.post.mockResolvedValueOnce({ok: true});
mocks.poll_until.mockResolvedValue({
result: {status: 'done', completed_steps: []},
attempts: 1,
});
await resume_and_poll('api_key', 'c_abc', true,
{timing: undefined, autoSave: true}, 600);
expect(mocks.post.mock.calls[0][2]).toEqual({
message: true, auto_save: true,
});
});

it('omits auto_save when approving without autoSave', async()=>{
mocks.post.mockResolvedValueOnce({ok: true});
mocks.poll_until.mockResolvedValue({
result: {status: 'done', completed_steps: []},
attempts: 1,
});
await resume_and_poll('api_key', 'c_abc', true,
{timing: undefined}, 600);
expect(mocks.post.mock.calls[0][2]).toEqual({message: true});
});

it('never sends auto_save on reject, even if autoSave set',
async()=>{
mocks.post.mockResolvedValueOnce({ok: true});
mocks.poll_until.mockResolvedValue({
result: {status: 'done', completed_steps: []},
attempts: 1,
});
await resume_and_poll('api_key', 'c_abc', false,
{timing: undefined, autoSave: true}, 600);
expect(mocks.post.mock.calls[0][2]).toEqual({message: false});
});
});

describe('handle_approve_scraper', ()=>{
Expand Down Expand Up @@ -2142,5 +2179,19 @@ describe('commands/scraper', ()=>{
expect(heal.options.map(o=>o.long))
.toContain('--auto-approve');
});

it('approve exposes --auto-save', ()=>{
const approve = scraper_command.commands
.find(c=>c.name()=='approve')!;
expect(approve.options.map(o=>o.long))
.toContain('--auto-save');
});

it('heal exposes --auto-save', ()=>{
const heal = scraper_command.commands
.find(c=>c.name()=='heal')!;
expect(heal.options.map(o=>o.long))
.toContain('--auto-save');
});
});
});
15 changes: 13 additions & 2 deletions src/commands/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,18 @@ const resume_and_poll = async(
api_key: string,
collector_id: string,
approve: boolean,
opts: {timing?: boolean},
opts: {timing?: boolean; autoSave?: boolean},
timeout: number
): Promise<Poll_result<Ai_progress_response>>=>{
// auto_save only takes effect on approval (message:true); the API
// ignores it on reject, so we omit it there to keep the body minimal.
const resume_body = approve && opts.autoSave
? {message: approve, auto_save: true}
: {message: approve};
await post<unknown>(
api_key,
`/dca/collectors/${collector_id}/${RESUME_JOB_PATH}`,
{message: approve},
resume_body,
{timing: opts.timing, hints: SCRAPER_BODY_HINTS}
);
return poll_until<Ai_progress_response>({
Expand Down Expand Up @@ -1380,6 +1385,9 @@ const heal_subcommand = new Command('heal')
.option('--auto-approve',
'When the heal hits the approval gate, approve it automatically '
+'and poll through to done (default: stop and let you review).')
.option('--auto-save',
'With --auto-approve, also save the healed template automatically '
+'once the job completes (sent as auto_save to the resume call).')
.option('--timeout <seconds>',
'Polling timeout in seconds (default: 600)')
.option('--max-retries <n>',
Expand Down Expand Up @@ -1422,6 +1430,9 @@ const approve_subcommand = new Command('approve')
'Collector ID of the scraper whose heal is awaiting approval')
.option('--reject',
'Reject the proposed fix instead of approving it.')
.option('--auto-save',
'Save the approved template automatically once the job completes '
+'successfully (sent as auto_save to the resume call).')
.option('--url <url>',
'Verify target woven into the next-step hint on success.')
.option('--timeout <seconds>',
Expand Down
2 changes: 2 additions & 0 deletions src/types/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type Scraper_heal_opts = {
maxRetries?: string;
retry?: boolean;
autoApprove?: boolean;
autoSave?: boolean;
};

type Scraper_approve_opts = {
Expand All @@ -142,6 +143,7 @@ type Scraper_approve_opts = {
timing?: boolean;
apiKey?: string;
legacyOutput?: boolean;
autoSave?: boolean;
};

export type {
Expand Down