Skip to content

Commit 72f05a8

Browse files
fix: add output-dir to cache, use it if found W-17919149 (#104)
* fix: add output-dir to cache, use it if found * test: fix UT stub * chore: fix cached ID * chore: add result format to cache
1 parent f4437bc commit 72f05a8

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

src/agentTestCache.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import { Global, SfError, TTLConfig } from '@salesforce/core';
99
import { Duration } from '@salesforce/kit';
1010

11+
type ResultFormat = 'json' | 'human' | 'junit' | 'tap';
12+
1113
type CacheContents = {
1214
runId: string;
1315
name: string;
16+
outputDir?: string;
17+
resultFormat?: ResultFormat;
1418
};
1519

1620
export class AgentTestCache extends TTLConfig<TTLConfig.Options, CacheContents> {
@@ -28,10 +32,15 @@ export class AgentTestCache extends TTLConfig<TTLConfig.Options, CacheContents>
2832
};
2933
}
3034

31-
public async createCacheEntry(runId: string, name: string): Promise<void> {
35+
public async createCacheEntry(
36+
runId: string,
37+
name: string,
38+
outputDir?: string,
39+
resultFormat?: ResultFormat
40+
): Promise<void> {
3241
if (!runId) throw new SfError('runId is required to create a cache entry');
3342

34-
this.set(runId, { runId, name });
43+
this.set(runId, { runId, name, outputDir, resultFormat });
3544
await this.write();
3645
}
3746

@@ -49,7 +58,10 @@ export class AgentTestCache extends TTLConfig<TTLConfig.Options, CacheContents>
4958
return this.get(key);
5059
}
5160

52-
public useIdOrMostRecent(runId: string | undefined, useMostRecent: boolean): { runId: string; name?: string } {
61+
public useIdOrMostRecent(
62+
runId: string | undefined,
63+
useMostRecent: boolean
64+
): { runId: string; name?: string; outputDir?: string; resultFormat?: ResultFormat } {
5365
if (runId && useMostRecent) {
5466
throw new SfError('Cannot specify both a runId and use most recent flag');
5567
}
@@ -59,7 +71,7 @@ export class AgentTestCache extends TTLConfig<TTLConfig.Options, CacheContents>
5971
}
6072

6173
if (runId) {
62-
return { runId };
74+
return this.has(runId) ? this.get(runId) : { runId };
6375
}
6476

6577
return this.resolveFromCache();

src/commands/agent/test/resume.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export default class AgentTestResume extends SfCommand<AgentTestRunResult> {
5050
const { flags } = await this.parse(AgentTestResume);
5151

5252
const agentTestCache = await AgentTestCache.create();
53-
const { name, runId } = agentTestCache.useIdOrMostRecent(flags['job-id'], flags['use-most-recent']);
53+
const { name, runId, outputDir, resultFormat } = agentTestCache.useIdOrMostRecent(
54+
flags['job-id'],
55+
flags['use-most-recent']
56+
);
5457

5558
const mso = new TestStages({
5659
title: `Agent Test Run: ${name ?? runId}`,
@@ -66,10 +69,10 @@ export default class AgentTestResume extends SfCommand<AgentTestRunResult> {
6669

6770
await handleTestResults({
6871
id: runId,
69-
format: flags['result-format'],
72+
format: resultFormat ?? flags['result-format'],
7073
results: response,
7174
jsonEnabled: this.jsonEnabled(),
72-
outputDir: flags['output-dir'],
75+
outputDir: outputDir ?? flags['output-dir'],
7376
});
7477

7578
return { ...response!, runId, status: 'COMPLETED' };

src/commands/agent/test/run.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default class AgentTestRun extends SfCommand<AgentTestRunResult> {
9696
this.mso.update({ id: response.runId });
9797

9898
const agentTestCache = await AgentTestCache.create();
99-
await agentTestCache.createCacheEntry(response.runId, apiName);
99+
await agentTestCache.createCacheEntry(response.runId, apiName, flags['output-dir'], flags['result-format']);
100100

101101
if (flags.wait?.minutes) {
102102
const { completed, response: detailsResponse } = await this.mso.poll(agentTester, response.runId, flags.wait);

test/agentTestCache.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ describe('AgentTestCache', () => {
8585
expect(result).to.deep.equal({ runId: '123' });
8686
});
8787

88+
it('should return the provided runId', () => {
89+
sinon.stub(cache, 'has').returns(true);
90+
sinon.stub(cache, 'get').returns({ runId: '123', name: 'testName', outputDir: 'myCachedOutput' });
91+
const result = cache.useIdOrMostRecent('123', false);
92+
expect(result).to.deep.equal({
93+
name: 'testName',
94+
outputDir: 'myCachedOutput',
95+
runId: '123',
96+
});
97+
});
98+
8899
it('should return the most recent cache entry', async () => {
89100
sinon.stub(cache, 'resolveFromCache').returns({ runId: '123', name: 'testName' });
90101
const result = cache.useIdOrMostRecent(undefined, true);

0 commit comments

Comments
 (0)