Skip to content

Commit 65d68e9

Browse files
SakshiKoli-CSclaude
andcommitted
fix(core): stop isRecord from accepting arrays
isRecord returned true for an array, so unwrap let { project: [] } through as a Project and the file-framework guard returned [] as a DetectedFramework instead of raising the malformed-response error. No caller wants an array to count as a record, so exclude arrays in the helper and cover both boundaries with an array case. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b4ec390 commit 65d68e9

4 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎src/core/values.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('input value helpers', () => {
55
it.each([
66
[{}, true],
77
[{ a: 1 }, true],
8-
[[], true],
8+
[[], false],
99
[null, false],
1010
[undefined, false],
1111
['', false],

‎src/core/values.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UsageError } from './errors';
22

33
export function isRecord(value: unknown): value is Record<string, unknown> {
4-
return typeof value === 'object' && value !== null;
4+
return typeof value === 'object' && value !== null && !Array.isArray(value);
55
}
66

77
export function messageOf(error: unknown): string {

‎src/projects/projects.api.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ describe('ProjectsApi create and detection endpoints', () => {
568568
});
569569
});
570570

571-
it('raises a malformed-response error when a framework response is not an object', async () => {
572-
const { client } = fakeRestClient(null);
571+
it.each([[null], [[]]])('raises a malformed-response error when a framework response is %p, not an object', async (body) => {
572+
const { client } = fakeRestClient(body);
573573

574574
await expect(new ProjectsApi(client).fileFramework({ org: 'org1', uploadUid: 'u' })).rejects.toThrow(
575575
'The Launch API returned a framework response that was not an object.',

‎src/transport/envelope.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('response envelope', () => {
3333
[{}],
3434
[{ project: null }],
3535
[{ project: 'p1' }],
36+
[{ project: [] }],
3637
])('refuses %p as an envelope that carries no project', (response) => {
3738
const error = failureFrom(() => unwrap(response, 'project', 'project response'));
3839

0 commit comments

Comments
 (0)