Skip to content

Commit 60b53c9

Browse files
committed
test(sdk): 覆盖 endpoint/template 实例 get 的 _config fallback 分支
之前在 fix(sdk): 修复方法级 config 在调用链中被悄悄丢弃中给 AgentRuntimeEndpoint.get 与 Template.get 的实例方法补了 config ?? this._config fallback,但没有相应的测试覆盖两个分支, 导致 agent-runtime 分支覆盖率从 ≥95% 跌到 93.64%、sandbox 跌到 90%,未能通过覆盖率门禁。 补两组等价的 case 分别命中两个分支: - tests/unittests/agent-runtime/agent-runtime.test.ts: 新增 describe('get (instance)'),分别验证 endpoint.get({ config }) 时透传 params.config,以及 endpoint.get() 时回落到构造时传入的 instance _config - tests/unittests/sandbox/template.test.ts: 同构地为 Template 实例 get 增加 params.config 与 _config fallback 两个 case 补完后覆盖率:agent-runtime 分支 95.45%、sandbox 分支 100%、全量 分支 97.37%,重新跨过 95% 门槛。 Change-Id: I61ddc203253722378e83abe4eef639932bda8b64 Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent 20486f7 commit 60b53c9

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

tests/unittests/agent-runtime/agent-runtime.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,55 @@ describe('Agent Runtime Module', () => {
15681568
});
15691569
});
15701570

1571+
describe('get (instance)', () => {
1572+
it('should fetch using params.config when provided', async () => {
1573+
mockControlApi.getAgentRuntimeEndpoint.mockResolvedValue({
1574+
agentRuntimeEndpointId: 'endpoint-123',
1575+
agentRuntimeEndpointName: 'test-endpoint',
1576+
status: 'READY',
1577+
});
1578+
1579+
const instanceConfig = new Config({ accountId: 'instance-acc' });
1580+
const callConfig = new Config({ accountId: 'call-acc' });
1581+
1582+
const endpoint = new AgentRuntimeEndpoint(
1583+
{
1584+
agentRuntimeId: 'runtime-123',
1585+
agentRuntimeEndpointId: 'endpoint-123',
1586+
},
1587+
instanceConfig
1588+
);
1589+
1590+
await endpoint.get({ config: callConfig });
1591+
1592+
expect(mockControlApi.getAgentRuntimeEndpoint).toHaveBeenCalledWith(
1593+
expect.objectContaining({ config: callConfig })
1594+
);
1595+
});
1596+
1597+
it('should fall back to instance _config when params.config is missing', async () => {
1598+
mockControlApi.getAgentRuntimeEndpoint.mockResolvedValue({
1599+
agentRuntimeEndpointId: 'endpoint-123',
1600+
});
1601+
1602+
const instanceConfig = new Config({ accountId: 'instance-acc' });
1603+
1604+
const endpoint = new AgentRuntimeEndpoint(
1605+
{
1606+
agentRuntimeId: 'runtime-123',
1607+
agentRuntimeEndpointId: 'endpoint-123',
1608+
},
1609+
instanceConfig
1610+
);
1611+
1612+
await endpoint.get();
1613+
1614+
expect(mockControlApi.getAgentRuntimeEndpoint).toHaveBeenCalledWith(
1615+
expect.objectContaining({ config: instanceConfig })
1616+
);
1617+
});
1618+
});
1619+
15711620
describe('waitUntilReady', () => {
15721621
it('should wait until status is READY', async () => {
15731622
let callCount = 0;

tests/unittests/sandbox/template.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,44 @@ describe('Template', () => {
725725
});
726726
});
727727

728+
describe('get (instance)', () => {
729+
// eslint-disable-next-line @typescript-eslint/no-var-requires
730+
const { Config } = require('../../../src/utils/config');
731+
732+
it('should fetch using params.config when provided', async () => {
733+
mockClientGetTemplate.mockResolvedValue({
734+
templateId: 'template-123',
735+
templateName: 'test-template',
736+
});
737+
738+
const instanceConfig = new Config({ accountId: 'instance-acc' });
739+
const callConfig = new Config({ accountId: 'call-acc' });
740+
741+
const template = new Template({ templateName: 'test-template' }, instanceConfig);
742+
await template.get({ config: callConfig });
743+
744+
expect(mockClientGetTemplate).toHaveBeenCalledWith(
745+
expect.objectContaining({ config: callConfig })
746+
);
747+
});
748+
749+
it('should fall back to instance _config when params.config is missing', async () => {
750+
mockClientGetTemplate.mockResolvedValue({
751+
templateId: 'template-123',
752+
templateName: 'test-template',
753+
});
754+
755+
const instanceConfig = new Config({ accountId: 'instance-acc' });
756+
const template = new Template({ templateName: 'test-template' }, instanceConfig);
757+
758+
await template.get();
759+
760+
expect(mockClientGetTemplate).toHaveBeenCalledWith(
761+
expect.objectContaining({ config: instanceConfig })
762+
);
763+
});
764+
});
765+
728766
describe('waitUntilReady', () => {
729767
it('should return immediately if already ready', async () => {
730768
mockClientGetTemplate.mockResolvedValue({

0 commit comments

Comments
 (0)