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
5 changes: 4 additions & 1 deletion src/lib/provision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ function normalizeAccount(raw: unknown): CloudAccount {
return account;
}
if (typeof account.cloud_name === 'string' && account.cloud_name !== '') {
account.product_environments = [account];
// Copy, not a self-reference: the account must stay JSON-serializable
// (--json output stringifies it).
const { product_environments: _omit, ...env } = account;
account.product_environments = [env];
return account;
}
throw new ProvisionError(
Expand Down
18 changes: 18 additions & 0 deletions test/provision.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ test('normalizes the flattened response shape', async () => {
);
});

test('flattened response normalizes without circular references (--json serializes it)', async () => {
await withStub(
(req, res) => {
req.on('data', () => {});
req.on('end', () => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(FLAT_RESPONSE));
});
},
async host => {
const account = await provisionCloud({}, { apiHost: host });
const serialized = JSON.parse(JSON.stringify(account));
assert.equal(serialized.product_environments[0].cloud_name, 'cloud-flat');
assert.equal(serialized.product_environments[0].product_environments, undefined);
},
);
});

test('unrecognized success shape throws with the raw response preserved', async () => {
await withStub(
(req, res) => {
Expand Down
Loading